Skip to content

Commit 0c9739b

Browse files
committed
refactor: Vector.elementwise* -> .map2*
1 parent fbb4585 commit 0c9739b

8 files changed

Lines changed: 64 additions & 69 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/VectorEWiseAddGen.fs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,53 +159,53 @@ type VectorEWiseBenchmarksWithDataTransfer<'elem when 'elem : struct>(
159159
type VectorEWiseBenchmarks4FloatSparseWithoutDataTransfer() =
160160

161161
inherit VectorEWiseBenchmarksWithoutDataTransfer<float>(
162-
(fun context -> Vector.elementwise context ArithmeticOperations.floatSum),
162+
(fun context -> Vector.map2 context ArithmeticOperations.floatSum),
163163
VectorGenerator.floatPair Sparse)
164164

165165
type VectorEWiseBenchmarks4Int32SparseWithoutDataTransfer() =
166166

167167
inherit VectorEWiseBenchmarksWithoutDataTransfer<int32>(
168-
(fun context -> Vector.elementwise context ArithmeticOperations.intSum),
168+
(fun context -> Vector.map2 context ArithmeticOperations.intSum),
169169
VectorGenerator.intPair Sparse)
170170

171171
/// General
172172
173173
type VectorEWiseGeneralBenchmarks4FloatSparseWithoutDataTransfer() =
174174

175175
inherit VectorEWiseBenchmarksWithoutDataTransfer<float>(
176-
(fun context -> Vector.elementwiseGeneral context ArithmeticOperations.floatSum),
176+
(fun context -> Vector.map2General context ArithmeticOperations.floatSum),
177177
VectorGenerator.floatPair Sparse)
178178

179179
type VectorEWiseGeneralBenchmarks4Int32SparseWithoutDataTransfer() =
180180

181181
inherit VectorEWiseBenchmarksWithoutDataTransfer<int32>(
182-
(fun context -> Vector.elementwiseGeneral context ArithmeticOperations.intSum),
182+
(fun context -> Vector.map2General context ArithmeticOperations.intSum),
183183
VectorGenerator.intPair Sparse)
184184

185185
/// With data transfer
186186
187187
type VectorEWiseBenchmarks4FloatSparseWithDataTransfer() =
188188

189189
inherit VectorEWiseBenchmarksWithDataTransfer<float>(
190-
(fun context -> Vector.elementwise context ArithmeticOperations.floatSum),
190+
(fun context -> Vector.map2 context ArithmeticOperations.floatSum),
191191
VectorGenerator.floatPair Sparse)
192192

193193
type VectorEWiseBenchmarks4Int32SparseWithDataTransfer() =
194194

195195
inherit VectorEWiseBenchmarksWithDataTransfer<int32>(
196-
(fun context -> Vector.elementwise context ArithmeticOperations.intSum),
196+
(fun context -> Vector.map2 context ArithmeticOperations.intSum),
197197
VectorGenerator.intPair Sparse)
198198

199199
/// General with data transfer
200200
201201
type VectorEWiseGeneralBenchmarks4FloatSparseWithDataTransfer() =
202202

203203
inherit VectorEWiseBenchmarksWithDataTransfer<float>(
204-
(fun context -> Vector.elementwiseGeneral context ArithmeticOperations.floatSum),
204+
(fun context -> Vector.map2General context ArithmeticOperations.floatSum),
205205
VectorGenerator.floatPair Sparse)
206206

207207
type VectorEWiseGeneralBenchmarks4Int32SparseWithDataTransfer() =
208208

209209
inherit VectorEWiseBenchmarksWithDataTransfer<int32>(
210-
(fun context -> Vector.elementwiseGeneral context ArithmeticOperations.intSum),
210+
(fun context -> Vector.map2General context ArithmeticOperations.intSum),
211211
VectorGenerator.intPair Sparse)

src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module BFS =
2828
let ofList = Vector.ofList clContext workGroupSize
2929

3030
let maskComplementedTo =
31-
DenseVector.elementWiseTo clContext Mask.complementedMaskOp workGroupSize
31+
DenseVector.map2To clContext Mask.complementedMaskOp workGroupSize
3232

3333
let fillSubVectorTo =
3434
DenseVector.standardFillSubVectorTo<int, int> clContext workGroupSize

src/GraphBLAS-sharp.Backend/Vector/DenseVector/DenseVector.fs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ open GraphBLAS.FSharp.Backend.Objects.ClVector
99
open GraphBLAS.FSharp.Backend.Objects.ClContext
1010

1111
module DenseVector =
12-
let elementWiseTo<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct>
12+
let map2To<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct>
1313
(clContext: ClContext)
1414
(opAdd: Expr<'a option -> 'b option -> 'c option>)
1515
workGroupSize
@@ -39,14 +39,13 @@ module DenseVector =
3939

4040
processor.Post(Msg.CreateRunMsg<_, _>(kernel))
4141

42-
let elementwise<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct>
42+
let map2<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct>
4343
(clContext: ClContext)
4444
(opAdd: Expr<'a option -> 'b option -> 'c option>)
4545
workGroupSize
4646
=
4747

48-
let elementWiseTo =
49-
elementWiseTo clContext opAdd workGroupSize
48+
let elementWiseTo = map2To clContext opAdd workGroupSize
5049

5150
fun (processor: MailboxProcessor<_>) allocationMode (leftVector: ClArray<'a option>) (rightVector: ClArray<'b option>) ->
5251
let resultVector =
@@ -56,8 +55,8 @@ module DenseVector =
5655

5756
resultVector
5857

59-
let elementWiseAtLeastOne clContext op workGroupSize =
60-
elementwise clContext (Convert.atLeastOneToOption op) workGroupSize
58+
let map2AtLeastOne clContext op workGroupSize =
59+
map2 clContext (Convert.atLeastOneToOption op) workGroupSize
6160

6261
let fillSubVectorTo<'a, 'b when 'a: struct and 'b: struct>
6362
(clContext: ClContext)

src/GraphBLAS-sharp.Backend/Vector/SparseVector/SparseVector.fs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,7 @@ module SparseVector =
9595

9696
resultBitmap, resultValues, resultIndices
9797

98-
let elementwiseGeneral<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct>
99-
(clContext: ClContext)
100-
op
101-
workGroupSize
102-
=
98+
let map2General<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct> (clContext: ClContext) op workGroupSize =
10399

104100
let prepare =
105101
preparePositionsGeneral<'a, 'b, 'c> clContext workGroupSize op
@@ -219,7 +215,7 @@ module SparseVector =
219215
///<param name="clContext">.</param>
220216
///<param name="op">.</param>
221217
///<param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
222-
let elementwise<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct> (clContext: ClContext) op workGroupSize =
218+
let map2<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct> (clContext: ClContext) op workGroupSize =
223219

224220
let merge = merge clContext workGroupSize
225221

@@ -252,8 +248,8 @@ module SparseVector =
252248
Indices = resultIndices
253249
Size = max leftVector.Size rightVector.Size }
254250

255-
let elementWiseAtLeastOne (clContext: ClContext) opAdd workGroupSize allocationMode =
256-
elementwise clContext (Convert.atLeastOneToOption opAdd) workGroupSize allocationMode
251+
let map2AtLeastOne (clContext: ClContext) opAdd workGroupSize allocationMode =
252+
map2 clContext (Convert.atLeastOneToOption opAdd) workGroupSize allocationMode
257253

258254
let private preparePositionsFillSubVector<'a, 'b when 'a: struct and 'b: struct>
259255
(clContext: ClContext)

src/GraphBLAS-sharp.Backend/Vector/Vector.fs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ module Vector =
127127
ClVector.Dense
128128
<| toDense processor allocationMode vector
129129

130-
let elementWiseAtLeastOne (clContext: ClContext) (opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>) workGroupSize =
130+
let map2AtLeastOne (clContext: ClContext) (opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>) workGroupSize =
131131
let addSparse =
132-
SparseVector.elementWiseAtLeastOne clContext opAdd workGroupSize
132+
SparseVector.map2AtLeastOne clContext opAdd workGroupSize
133133

134134
let addDense =
135-
DenseVector.elementWiseAtLeastOne clContext opAdd workGroupSize
135+
DenseVector.map2AtLeastOne clContext opAdd workGroupSize
136136

137137
fun (processor: MailboxProcessor<_>) allocationMode (leftVector: ClVector<'a>) (rightVector: ClVector<'b>) ->
138138
match leftVector, rightVector with
@@ -144,12 +144,12 @@ module Vector =
144144
<| addDense processor allocationMode left right
145145
| _ -> failwith "Vector formats are not matching."
146146

147-
let elementwise (clContext: ClContext) (opAdd: Expr<'a option -> 'b option -> 'c option>) workGroupSize =
147+
let map2 (clContext: ClContext) (opAdd: Expr<'a option -> 'b option -> 'c option>) workGroupSize =
148148
let addDense =
149-
DenseVector.elementwise clContext opAdd workGroupSize
149+
DenseVector.map2 clContext opAdd workGroupSize
150150

151151
let addSparse =
152-
SparseVector.elementwise clContext opAdd workGroupSize
152+
SparseVector.map2 clContext opAdd workGroupSize
153153

154154
fun (processor: MailboxProcessor<_>) allocationMode (leftVector: ClVector<'a>) (rightVector: ClVector<'b>) ->
155155
match leftVector, rightVector with
@@ -161,17 +161,17 @@ module Vector =
161161
<| addSparse processor allocationMode left right
162162
| _ -> failwith "Vector formats are not matching."
163163

164-
let elementwiseGeneral<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct>
164+
let map2General<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct>
165165
(clContext: ClContext)
166166
(opAdd: Expr<'a option -> 'b option -> 'c option>)
167167
workGroupsSize
168168
=
169169

170170
let sparseEWise =
171-
SparseVector.elementwiseGeneral clContext opAdd workGroupsSize
171+
SparseVector.map2General clContext opAdd workGroupsSize
172172

173173
let denseEWise =
174-
DenseVector.elementwise clContext opAdd workGroupsSize
174+
DenseVector.map2 clContext opAdd workGroupsSize
175175

176176
fun (processor: MailboxProcessor<_>) allocationMode (leftVector: ClVector<'a>) (rightVector: ClVector<'b>) ->
177177
match leftVector, rightVector with

tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<Compile Include="Vector/FillSubVector.fs" />
3535
<Compile Include="Vector/Convert.fs" />
3636
<Compile Include="Vector/Reduce.fs" />
37-
<Compile Include="Vector/Elementwise.fs" />
37+
<Compile Include="Vector\Map2.fs" />
3838
<Compile Include="Vector/SpMV.fs" />
3939
<Compile Include="Algorithms/BFS.fs" />
4040
<Compile Include="Matrix/Convert.fs" />

tests/GraphBLAS-sharp.Tests/Program.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ let vectorTests =
3535
Vector.OfList.tests
3636
Vector.Copy.tests
3737
Vector.Convert.tests
38-
Vector.Elementwise.addTests
39-
Vector.Elementwise.mulTests
40-
Vector.Elementwise.addAtLeastOneTests
41-
Vector.Elementwise.mulAtLeastOneTests
42-
Vector.Elementwise.addGeneralTests
43-
Vector.Elementwise.mulGeneralTests
44-
Vector.Elementwise.complementedGeneralTests
38+
Vector.Map2.addTests
39+
Vector.Map2.mulTests
40+
Vector.Map2.addAtLeastOneTests
41+
Vector.Map2.mulAtLeastOneTests
42+
Vector.Map2.addGeneralTests
43+
Vector.Map2.mulGeneralTests
44+
Vector.Map2.complementedGeneralTests
4545
Vector.FillSubVector.tests
4646
Vector.FillSubVector.complementedTests
4747
Vector.Reduce.tests ]

0 commit comments

Comments
 (0)