Skip to content

Commit 15ea08a

Browse files
committed
refactor: Vector.{VectorFormat}
1 parent 4e01885 commit 15ea08a

10 files changed

Lines changed: 24 additions & 23 deletions

File tree

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,24 @@ and ClSparseVector<'a> =
7272

7373
member this.Dispose(q) = (this :> IDeviceMemObject).Dispose(q)
7474

75+
[<RequireQualifiedAccess>]
7576
type Vector<'a when 'a: struct> =
76-
| VectorSparse of SparseVector<'a>
77-
| VectorDense of 'a option []
77+
| Sparse of SparseVector<'a>
78+
| Dense of 'a option []
7879
member this.Size =
7980
match this with
80-
| VectorSparse vector -> vector.Size
81-
| VectorDense vector -> vector.Size
81+
| Sparse vector -> vector.Size
82+
| Dense vector -> vector.Size
8283

8384
override this.ToString() =
8485
match this with
85-
| VectorSparse vector -> vector.ToString()
86-
| VectorDense vector -> DenseVectorToString vector
86+
| Sparse vector -> vector.ToString()
87+
| Dense vector -> DenseVectorToString vector
8788

8889
member this.ToDevice(context: ClContext) =
8990
match this with
90-
| VectorSparse vector -> ClVectorSparse <| vector.ToDevice(context)
91-
| VectorDense vector -> ClVectorDense <| vector.ToDevice(context)
91+
| Sparse vector -> ClVectorSparse <| vector.ToDevice(context)
92+
| Dense vector -> ClVectorDense <| vector.ToDevice(context)
9293

9394
and ClVector<'a when 'a: struct> =
9495
| ClVectorSparse of ClSparseVector<'a>
@@ -100,8 +101,8 @@ and ClVector<'a when 'a: struct> =
100101

101102
member this.ToHost(q: MailboxProcessor<_>) =
102103
match this with
103-
| ClVectorSparse vector -> VectorSparse <| vector.ToHost(q)
104-
| ClVectorDense vector -> VectorDense <| vector.ToHost(q)
104+
| ClVectorSparse vector -> Vector.Sparse <| vector.ToHost(q)
105+
| ClVectorDense vector -> Vector.Dense <| vector.ToHost(q)
105106

106107
member this.Dispose(q) =
107108
match this with

tests/GraphBLAS-sharp.Tests/Algorithms/BFS.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ let testFixtures (testContext: TestContext) =
5151
res.Dispose queue
5252

5353
match resHost with
54-
| VectorDense resHost ->
54+
| Vector.Dense resHost ->
5555
let actual = resHost |> Utils.unwrapOptionArray 0
5656

5757
Expect.sequenceEqual actual expected "Sequences must be equal"

tests/GraphBLAS-sharp.Tests/Helpers.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,10 @@ module Utils =
668668
let createVectorFromArray vectorCase array isZero =
669669
match vectorCase with
670670
| VectorFormat.Sparse ->
671-
VectorSparse
671+
Vector.Sparse
672672
<| SparseVector.FromArray(array, isZero)
673673
| VectorFormat.Dense ->
674-
VectorDense
674+
Vector.Dense
675675
<| ArraysExtensions.DenseVectorFromArray(array, isZero)
676676

677677
let createArrayFromDictionary size zero (dictionary: System.Collections.Generic.Dictionary<int, 'a>) =

tests/GraphBLAS-sharp.Tests/Vector/Copy.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ let checkResult (isEqual: 'a -> 'a -> bool) (actual: Vector<'a>) (expected: Vect
1818
Expect.equal actual.Size expected.Size "The size should be the same"
1919

2020
match actual, expected with
21-
| VectorDense actual, VectorDense expected ->
21+
| Vector.Dense actual, Vector.Dense expected ->
2222
let isEqual left right =
2323
match left, right with
2424
| Some left, Some right -> isEqual left right
2525
| None, None -> true
2626
| _, _ -> false
2727

2828
compareArrays isEqual actual expected "The values array must contain the default value"
29-
| VectorSparse actual, VectorSparse expected ->
29+
| Vector.Sparse actual, Vector.Sparse expected ->
3030
compareArrays isEqual actual.Values expected.Values "The values array must contain the default value"
3131
compareArrays (=) actual.Indices expected.Indices "The index array must contain the 0"
3232
| _, _ -> failwith "Copy format must be the same"

tests/GraphBLAS-sharp.Tests/Vector/ElementWiseAtLeasOne.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let checkResult
3535
expectedArray.[i] <- op leftArray.[i] rightArray.[i]
3636

3737
match actual with
38-
| VectorSparse actual ->
38+
| Vector.Sparse actual ->
3939
let actualArray =
4040
Array.create expectedArrayLength resultZero
4141

tests/GraphBLAS-sharp.Tests/Vector/Elementwise.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ let checkResult isEqual resultZero (op: 'a -> 'b -> 'c) (actual: Vector<'c>) (le
2828
for i in 0 .. expectedArrayLength - 1 do
2929
expectedArray.[i] <- op leftArray.[i] rightArray.[i]
3030

31-
let (VectorDense expected) =
31+
let (Vector.Dense expected) =
3232
createVectorFromArray Dense expectedArray (isEqual resultZero)
3333

3434
match actual with
35-
| VectorDense actual ->
35+
| Vector.Dense actual ->
3636
"arrays must have the same values"
3737
|> Expect.equal actual expected
3838
| _ -> failwith "Vector format must be Sparse."

tests/GraphBLAS-sharp.Tests/Vector/FillSubVector.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ let checkResult
4747
expectedArray.[i] <- vector.[i]
4848

4949
match actual with
50-
| VectorSparse actual ->
50+
| Vector.Sparse actual ->
5151
let actualArray = Array.create vector.Length vectorZero
5252

5353
for i in 0 .. actual.Indices.Length - 1 do

tests/GraphBLAS-sharp.Tests/Vector/OfList.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let checkResult
2323
Expect.equal actual.Size actualSize "lengths must be the same"
2424

2525
match actual with
26-
| VectorSparse actual ->
26+
| Vector.Sparse actual ->
2727
compareArrays (=) actual.Indices expectedIndices "indices must be the same"
2828
compareArrays isEqual actual.Values expectedValues "values must be the same"
2929
| _ -> failwith "Vector format must be Sparse."

tests/GraphBLAS-sharp.Tests/Vector/SpMV.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ let correctnessGenericTest
6464
let m = mtx.ToBackend testContext.ClContext
6565

6666
match vtr, m with
67-
| VectorDense vtr, ClMatrix.CSR m ->
67+
| Vector.Dense vtr, ClMatrix.CSR m ->
6868
let v = vtr.ToDevice testContext.ClContext
6969

7070
let res = spMV testContext.Queue m v

tests/GraphBLAS-sharp.Tests/Vector/ZeroCreate.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ let checkResult size (actual: Vector<'a>) =
1616
Expect.equal actual.Size size "The size should be the same"
1717

1818
match actual with
19-
| VectorDense vector ->
19+
| Vector.Dense vector ->
2020
Array.iter
2121
<| (fun item -> Expect.equal item None "values must be None")
2222
<| vector
23-
| VectorSparse vector ->
23+
| Vector.Sparse vector ->
2424
Expect.equal vector.Values [| Unchecked.defaultof<'a> |] "The values array must contain the default value"
2525
Expect.equal vector.Indices [| 0 |] "The index array must contain the 0"
2626

0 commit comments

Comments
 (0)