|
1 | | -namespace GraphBLAS.FSharp.Backend |
| 1 | +namespace GraphBLAS.FSharp.Backend |
2 | 2 |
|
3 | 3 | open Brahma.FSharp |
4 | 4 | open GraphBLAS.FSharp.Backend |
5 | 5 | open GraphBLAS.FSharp.Backend.ArraysExtensions |
6 | 6 |
|
7 | 7 | type VectorFormat = |
8 | | - | COO |
| 8 | + | Sparse |
9 | 9 | | Dense |
10 | 10 |
|
11 | | -type COOVector<'a> = |
| 11 | +type SparseVector<'a> = |
12 | 12 | { Indices: int [] |
13 | 13 | Values: 'a [] |
14 | 14 | Size: int } |
@@ -43,62 +43,9 @@ type COOVector<'a> = |
43 | 43 | |> Array.ofSeq |
44 | 44 | |> Array.unzip |
45 | 45 |
|
46 | | - COOVector.FromTuples(indices, vals, array.Length) |
| 46 | + SparseVector.FromTuples(indices, vals, array.Length) |
47 | 47 |
|
48 | | -and ClCooVector<'a> = |
49 | | - { Context: ClContext |
50 | | - Indices: ClArray<int> |
51 | | - Values: ClArray<'a> |
52 | | - Size: int } |
53 | | - |
54 | | - member this.ToHost(q: MailboxProcessor<_>) = |
55 | | - let indices = Array.zeroCreate this.Indices.Length |
56 | | - let values = Array.zeroCreate this.Values.Length |
57 | | - |
58 | | - let _ = |
59 | | - q.Post(Msg.CreateToHostMsg(this.Indices, indices)) |
60 | | - |
61 | | - let _ = |
62 | | - q.PostAndReply(fun ch -> Msg.CreateToHostMsg(this.Values, values, ch)) |
63 | | - |
64 | | - { Indices = indices |
65 | | - Values = values |
66 | | - Size = this.Size } |
67 | | - |
68 | | - interface IDeviceMemObject with |
69 | | - member this.Dispose(q) = |
70 | | - q.Post(Msg.CreateFreeMsg<_>(this.Values)) |
71 | | - q.Post(Msg.CreateFreeMsg<_>(this.Indices)) |
72 | | - q.PostAndReply(Msg.MsgNotifyMe) |
73 | | - |
74 | | - member this.Dispose(q) = (this :> IDeviceMemObject).Dispose(q) |
75 | | - |
76 | | -type TuplesVector<'a> = |
77 | | - { Indices: int [] |
78 | | - Values: 'a [] |
79 | | - Size: int } |
80 | | - |
81 | | - override this.ToString() = |
82 | | - [ sprintf "Tuples Vector\n" |
83 | | - sprintf "Indices: %A \n" this.Indices |
84 | | - sprintf "Values: %A \n" this.Values ] |
85 | | - |> String.concat "" |
86 | | - |
87 | | - member this.ToDevice(context: ClContext) = |
88 | | - let indices = context.CreateClArray this.Indices |
89 | | - let values = context.CreateClArray this.Values |
90 | | - |
91 | | - { Context = context |
92 | | - Indices = indices |
93 | | - Values = values |
94 | | - Size = this.Size } |
95 | | - |
96 | | - static member FromTuples(indices: int [], values: 'a [], size: int) = |
97 | | - { Indices = indices |
98 | | - Values = values |
99 | | - Size = size } |
100 | | - |
101 | | -and ClTuplesVector<'a> = |
| 48 | +and ClSparseVector<'a> = |
102 | 49 | { Context: ClContext |
103 | 50 | Indices: ClArray<int> |
104 | 51 | Values: ClArray<'a> |
@@ -127,32 +74,37 @@ and ClTuplesVector<'a> = |
127 | 74 | member this.Dispose(q) = (this :> IDeviceMemObject).Dispose(q) |
128 | 75 |
|
129 | 76 | type Vector<'a when 'a: struct> = |
130 | | - | VectorCOO of COOVector<'a> |
| 77 | + | VectorSparse of SparseVector<'a> |
131 | 78 | | VectorDense of 'a option [] |
132 | 79 | member this.Size = |
133 | 80 | match this with |
134 | | - | VectorCOO vector -> vector.Size |
| 81 | + | VectorSparse vector -> vector.Size |
135 | 82 | | VectorDense vector -> vector.Size |
136 | 83 |
|
| 84 | + override this.ToString() = |
| 85 | + match this with |
| 86 | + | VectorSparse vector -> vector.ToString() |
| 87 | + | VectorDense vector -> DenseVectorToString vector |
| 88 | + |
137 | 89 | member this.ToDevice(context: ClContext) = |
138 | 90 | match this with |
139 | | - | VectorCOO vector -> ClVectorCOO <| vector.ToDevice(context) |
| 91 | + | VectorSparse vector -> ClVectorSparse <| vector.ToDevice(context) |
140 | 92 | | VectorDense vector -> ClVectorDense <| vector.ToDevice(context) |
141 | 93 |
|
142 | 94 | and ClVector<'a when 'a: struct> = |
143 | | - | ClVectorCOO of ClCooVector<'a> |
| 95 | + | ClVectorSparse of ClSparseVector<'a> |
144 | 96 | | ClVectorDense of ClArray<'a option> |
145 | 97 | member this.Size = |
146 | 98 | match this with |
147 | | - | ClVectorCOO vector -> vector.Size |
| 99 | + | ClVectorSparse vector -> vector.Size |
148 | 100 | | ClVectorDense vector -> vector.Size |
149 | 101 |
|
150 | 102 | member this.ToHost(q: MailboxProcessor<_>) = |
151 | 103 | match this with |
152 | | - | ClVectorCOO vector -> VectorCOO <| vector.ToHost(q) |
| 104 | + | ClVectorSparse vector -> VectorSparse <| vector.ToHost(q) |
153 | 105 | | ClVectorDense vector -> VectorDense <| vector.ToHost(q) |
154 | 106 |
|
155 | 107 | member this.Dispose(q) = |
156 | 108 | match this with |
157 | | - | ClVectorCOO vector -> vector.Dispose(q) |
| 109 | + | ClVectorSparse vector -> vector.Dispose(q) |
158 | 110 | | ClVectorDense vector -> vector.Dispose(q) |
0 commit comments