@@ -98,6 +98,88 @@ module Operations =
9898 |> Some
9999 | _ -> failwith " Vector formats are not matching."
100100
101+ /// <summary >
102+ /// Applying the given function to the corresponding elements of the two given arrays pairwise.
103+ /// Stores the result in the left vector.
104+ /// </summary >
105+ /// <remarks >
106+ /// The two input arrays must have the same lengths.
107+ /// </remarks >
108+ /// <param name =" map " >The function to transform the pairs of the input elements.</param >
109+ /// <param name =" clContext " >OpenCL context.</param >
110+ /// <param name =" workGroupSize " >Should be a power of 2 and greater than 1.</param >
111+ let map2InPlace ( map : Expr < 'a option -> 'b option -> 'a option >) ( clContext : ClContext ) workGroupSize =
112+ let map2Dense =
113+ Dense.Vector.map2InPlace map clContext workGroupSize
114+
115+ fun ( processor : MailboxProcessor < _ >) ( leftVector : ClVector < 'a >) ( rightVector : ClVector < 'b >) ->
116+ match leftVector, rightVector with
117+ | ClVector.Dense left, ClVector.Dense right -> map2Dense processor left right left
118+ | _ -> failwith " Unsupported vector format"
119+
120+ /// <summary >
121+ /// Applying the given function to the corresponding elements of the two given arrays pairwise.
122+ /// Stores the result in the given vector.
123+ /// </summary >
124+ /// <remarks >
125+ /// The two input arrays must have the same lengths.
126+ /// </remarks >
127+ /// <param name =" map " >The function to transform the pairs of the input elements.</param >
128+ /// <param name =" clContext " >OpenCL context.</param >
129+ /// <param name =" workGroupSize " >Should be a power of 2 and greater than 1.</param >
130+ let map2To ( map : Expr < 'a option -> 'b option -> 'c option >) ( clContext : ClContext ) workGroupSize =
131+ let map2Dense =
132+ Dense.Vector.map2InPlace map clContext workGroupSize
133+
134+ fun ( processor : MailboxProcessor < _ >) ( leftVector : ClVector < 'a >) ( rightVector : ClVector < 'b >) ( resultVector : ClVector < 'c >) ->
135+ match leftVector, rightVector, resultVector with
136+ | ClVector.Dense left, ClVector.Dense right, ClVector.Dense result -> map2Dense processor left right result
137+ | _ -> failwith " Unsupported vector format"
138+
139+ /// <summary >
140+ /// Applying the given function to the corresponding elements of the two given arrays pairwise.
141+ /// Returns new vector.
142+ /// </summary >
143+ /// <remarks >
144+ /// The two input arrays must have the same lengths.
145+ /// </remarks >
146+ /// <param name =" map " >The function to transform the pairs of the input elements.</param >
147+ /// <param name =" clContext " >OpenCL context.</param >
148+ /// <param name =" workGroupSize " >Should be a power of 2 and greater than 1.</param >
149+ let map2Dense ( map : Expr < 'a option -> 'b option -> 'a option >) ( clContext : ClContext ) workGroupSize =
150+ let map2Dense =
151+ Dense.Vector.map2 map clContext workGroupSize
152+
153+ fun ( processor : MailboxProcessor < _ >) allocationFlag ( leftVector : ClVector < 'a >) ( rightVector : ClVector < 'b >) ->
154+ match leftVector, rightVector with
155+ | ClVector.Dense left, ClVector.Dense right -> map2Dense processor allocationFlag left right
156+ | _ -> failwith " Unsupported vector format"
157+
158+ /// <summary >
159+ /// Applying the given function to the corresponding elements of the two given arrays pairwise.
160+ /// Returns new vector as option.
161+ /// </summary >
162+ /// <remarks >
163+ /// The two input arrays must have the same lengths.
164+ /// </remarks >
165+ /// <param name =" map " >The function to transform the pairs of the input elements.</param >
166+ /// <param name =" clContext " >OpenCL context.</param >
167+ /// <param name =" workGroupSize " >Should be a power of 2 and greater than 1.</param >
168+ let map2Sparse ( map : Expr < 'a option -> 'b option -> 'a option >) ( clContext : ClContext ) workGroupSize =
169+ let map2Sparse =
170+ Sparse.Map2.run map clContext workGroupSize
171+
172+ let map2SparseDense =
173+ Sparse.Map2.runSparseDense map clContext workGroupSize
174+
175+ fun ( processor : MailboxProcessor < _ >) allocationFlag ( leftVector : ClVector < 'a >) ( rightVector : ClVector < 'b >) ->
176+ match leftVector, rightVector with
177+ | ClVector.Sparse left, ClVector.Sparse right ->
178+ Option.map ClVector.Sparse ( map2Sparse processor allocationFlag left right)
179+ | ClVector.Sparse left, ClVector.Dense right ->
180+ Option.map ClVector.Sparse ( map2SparseDense processor allocationFlag left right)
181+ | _ -> failwith " Unsupported vector format"
182+
101183 module Matrix =
102184 /// <summary >
103185 /// Builds a new matrix whose elements are the results of applying the given function
@@ -374,3 +456,43 @@ module Operations =
374456
375457 run processor allocationMode resultCapacity leftMatrix rightMatrix
376458 | _ -> failwith " Matrix formats are not matching"
459+
460+ module COO =
461+ /// <summary >
462+ /// Generalized matrix-matrix multiplication. Left matrix should be in COO format.
463+ /// </summary >
464+ /// <param name =" opAdd " >Type of binary function to reduce entries.</param >
465+ /// <param name =" opMul " >Type of binary function to combine entries.</param >
466+ /// <param name =" clContext " >OpenCL context.</param >
467+ /// <param name =" workGroupSize " >Should be a power of 2 and greater than 1.</param >
468+ let expand
469+ ( opAdd : Expr < 'c -> 'c -> 'c option >)
470+ ( opMul : Expr < 'a -> 'b -> 'c option >)
471+ ( clContext : ClContext )
472+ workGroupSize
473+ =
474+
475+ let run =
476+ SpGeMM.Expand.COO.run opAdd opMul clContext workGroupSize
477+
478+ fun ( processor : MailboxProcessor < _ >) allocationMode ( leftMatrix : ClMatrix < 'a >) ( rightMatrix : ClMatrix < 'b >) ->
479+ match leftMatrix, rightMatrix with
480+ | ClMatrix.COO leftMatrix, ClMatrix.CSR rightMatrix ->
481+ let allocCapacity =
482+ List.max [ sizeof< 'a>
483+ sizeof< 'c>
484+ sizeof< 'b> ]
485+ |> uint64
486+ |> (*) 1 UL< Byte>
487+
488+ let resultCapacity =
489+ ( clContext.MaxMemAllocSize / allocCapacity) / 3 UL
490+
491+ let resultCapacity =
492+ ( min
493+ <| uint64 System.Int32.MaxValue
494+ <| resultCapacity)
495+ |> int
496+
497+ run processor allocationMode resultCapacity leftMatrix rightMatrix
498+ | _ -> failwith " Matrix formats are not matching"
0 commit comments