Skip to content

Commit 39e8c0e

Browse files
committed
add: Matrix.map2
1 parent 98e7271 commit 39e8c0e

4 files changed

Lines changed: 70 additions & 74 deletions

File tree

src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@
3535
<Compile Include="Predefined/PrefixSum.fs" />
3636
<!--Compile Include="Matrices.fs" /-->
3737
<Compile Include="Matrix/Common.fs" />
38-
<Compile Include="Matrix\COOMatrix\Map2.fs" />
39-
<Compile Include="Matrix\COOMatrix\Map2AtLeastOne.fs" />
40-
<Compile Include="Matrix\COOMatrix\Matrix.fs" />
41-
<Compile Include="Matrix\CSRMatrix\Map2AtLeastOne.fs" />
38+
<Compile Include="Matrix/COOMatrix/Map2.fs" />
39+
<Compile Include="Matrix/COOMatrix/Map2AtLeastOne.fs" />
40+
<Compile Include="Matrix/COOMatrix/Matrix.fs" />
41+
<Compile Include="Matrix/CSRMatrix/Map2AtLeastOne.fs" />
4242
<Compile Include="Matrix/CSRMatrix/SpGEMM.fs" />
43-
<Compile Include="Matrix\CSRMatrix\Matrix.fs" />
43+
<Compile Include="Matrix/CSRMatrix/Matrix.fs" />
4444
<Compile Include="Matrix/Matrix.fs" />
45-
<Compile Include="Vector\SparseVector\Common.fs" />
45+
<Compile Include="Vector/SparseVector/Common.fs" />
4646
<Compile Include="Vector/SparseVector/Map2.fs" />
47-
<Compile Include="Vector\SparseVector\Map2AtLeastOne.fs" />
47+
<Compile Include="Vector/SparseVector/Map2AtLeastOne.fs" />
4848
<Compile Include="Vector/SparseVector/SparseVector.fs" />
4949
<Compile Include="Vector/DenseVector/DenseVector.fs" />
5050
<Compile Include="Vector/Vector.fs" />

src/GraphBLAS-sharp.Backend/Matrix/COOMatrix/Map2.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module internal Map2 =
3838
let preparePositions<'a, 'b, 'c> (clContext: ClContext) workGroupSize opAdd =
3939

4040
let preparePositions (op: Expr<'a option -> 'b option -> 'c option>) =
41-
<@ fun (ndRange: Range1D) rowCount columnCount length (leftValues: ClArray<'a>) (leftRows: ClArray<int>) (leftColumns: ClArray<int>) (rightValues: ClArray<'b>) (rightRows: ClArray<int>) (rightColumn: ClArray<int>) (resultBitmap: ClArray<int>) (resultValues: ClArray<'c>) (resultRows: ClArray<int>) (resultColumns: ClArray<int>) ->
41+
<@ fun (ndRange: Range1D) rowCount columnCount leftValuesLength rightValuesLength (leftValues: ClArray<'a>) (leftRows: ClArray<int>) (leftColumns: ClArray<int>) (rightValues: ClArray<'b>) (rightRows: ClArray<int>) (rightColumn: ClArray<int>) (resultBitmap: ClArray<int>) (resultValues: ClArray<'c>) (resultRows: ClArray<int>) (resultColumns: ClArray<int>) ->
4242

4343
let gid = ndRange.GlobalID0
4444

@@ -50,10 +50,10 @@ module internal Map2 =
5050
let index = (uint64 rowIndex <<< 32) ||| (uint64 columnIndex)
5151

5252
let leftValue =
53-
(%binSearch) length index leftRows leftColumns leftValues
53+
(%binSearch) leftValuesLength index leftRows leftColumns leftValues
5454

5555
let rightValue =
56-
(%binSearch) length index rightRows rightColumn rightValues
56+
(%binSearch) rightValuesLength index rightRows rightColumn rightValues
5757

5858
match (%op) leftValue rightValue with
5959
| Some value ->
@@ -95,6 +95,7 @@ module internal Map2 =
9595
rowCount
9696
columnCount
9797
leftValues.Length
98+
rightValues.Length
9899
leftValues
99100
leftRows
100101
leftColumns

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,7 @@ module Matrix =
207207
map2CSR processor allocationMode m1 m2
208208
|> ClMatrix.CSR
209209
| ClMatrix.CSC m1, ClMatrix.CSC m2 ->
210-
let resT =
211-
map2CSR processor allocationMode m1.ToCSR m2.ToCSR
212-
213-
{ Context = resT.Context
214-
RowCount = resT.ColumnCount
215-
ColumnCount = resT.RowCount
216-
Rows = resT.Columns
217-
ColumnPointers = resT.RowPointers
218-
Values = resT.Values }
210+
(map2CSR processor allocationMode m1.ToCSR m2.ToCSR).ToCSC
219211
|> ClMatrix.CSC
220212
| _ -> failwith "Matrix formats are not matching"
221213

tests/GraphBLAS-sharp.Tests/Program.fs

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,71 @@
11
open Expecto
22
open GraphBLAS.FSharp.Tests.Backend
33

4-
// let matrixTests =
5-
// testList
6-
// "Matrix tests"
7-
// [ Matrix.Convert.tests
8-
// Matrix.Map2.addTests
9-
// Matrix.Map2.addAtLeastOneTests
10-
// Matrix.Map2.mulAtLeastOneTests
11-
// Matrix.Map2.addAtLeastOneToCOOTests
12-
// Matrix.Mxm.tests
13-
// Matrix.Transpose.tests ]
14-
// |> testSequenced
15-
//
16-
// let commonTests =
17-
// let clArrayTests =
18-
// testList
19-
// "ClArray"
20-
// [ Common.ClArray.PrefixSum.tests
21-
// Common.ClArray.RemoveDuplicates.tests
22-
// Common.ClArray.Copy.tests
23-
// Common.ClArray.Replicate.tests
24-
// Common.ClArray.Exists.tests
25-
// Common.ClArray.Map.tests
26-
// Common.ClArray.Map2.addTests
27-
// Common.ClArray.Map2.mulTests
28-
// Common.ClArray.Choose.tests ]
29-
//
30-
// testList
31-
// "Common tests"
32-
// [ clArrayTests
33-
// Common.BitonicSort.tests
34-
// Common.Scatter.tests
35-
// Common.Reduce.tests
36-
// Common.Sum.tests ]
37-
// |> testSequenced
4+
let matrixTests =
5+
testList
6+
"Matrix tests"
7+
[ Matrix.Convert.tests
8+
Matrix.Map2.addTests
9+
Matrix.Map2.addAtLeastOneTests
10+
Matrix.Map2.mulAtLeastOneTests
11+
Matrix.Map2.addAtLeastOneToCOOTests
12+
Matrix.Mxm.tests
13+
Matrix.Transpose.tests ]
14+
|> testSequenced
15+
16+
let commonTests =
17+
let clArrayTests =
18+
testList
19+
"ClArray"
20+
[ Common.ClArray.PrefixSum.tests
21+
Common.ClArray.RemoveDuplicates.tests
22+
Common.ClArray.Copy.tests
23+
Common.ClArray.Replicate.tests
24+
Common.ClArray.Exists.tests
25+
Common.ClArray.Map.tests
26+
Common.ClArray.Map2.addTests
27+
Common.ClArray.Map2.mulTests
28+
Common.ClArray.Choose.tests ]
3829

39-
// let vectorTests =
40-
// testList
41-
// "Vector tests"
42-
// [ Vector.SpMV.tests
43-
// Vector.ZeroCreate.tests
44-
// Vector.OfList.tests
45-
// Vector.Copy.tests
46-
// Vector.Convert.tests
47-
// Vector.Map2.addTests
48-
// Vector.Map2.mulTests
49-
// Vector.Map2.addAtLeastOneTests
50-
// Vector.Map2.mulAtLeastOneTests
51-
// Vector.Map2.complementedGeneralTests
52-
// Vector.AssignByMask.tests
53-
// Vector.AssignByMask.complementedTests
54-
// Vector.Reduce.tests ]
55-
// |> testSequenced
30+
testList
31+
"Common tests"
32+
[ clArrayTests
33+
Common.BitonicSort.tests
34+
Common.Scatter.tests
35+
Common.Reduce.tests
36+
Common.Sum.tests ]
37+
|> testSequenced
5638

57-
// let algorithmsTests =
58-
// testList "Algorithms tests" [ Algorithms.BFS.tests ]
59-
// |> testSequenced
39+
let vectorTests =
40+
testList
41+
"Vector tests"
42+
[ Vector.SpMV.tests
43+
Vector.ZeroCreate.tests
44+
Vector.OfList.tests
45+
Vector.Copy.tests
46+
Vector.Convert.tests
47+
Vector.Map2.addTests
48+
Vector.Map2.mulTests
49+
Vector.Map2.addAtLeastOneTests
50+
Vector.Map2.mulAtLeastOneTests
51+
Vector.Map2.complementedGeneralTests
52+
Vector.AssignByMask.tests
53+
Vector.AssignByMask.complementedTests
54+
Vector.Reduce.tests ]
55+
|> testSequenced
56+
57+
let algorithmsTests =
58+
testList "Algorithms tests" [ Algorithms.BFS.tests ]
59+
|> testSequenced
6060

6161
[<Tests>]
6262
let allTests =
6363
testList
6464
"All tests"
65-
[ Matrix.Map2.addTests ]
65+
[ matrixTests
66+
commonTests
67+
vectorTests
68+
algorithmsTests ]
6669
|> testSequenced
6770

6871
[<EntryPoint>]

0 commit comments

Comments
 (0)