Skip to content

Commit b48705e

Browse files
committed
SparseVector instead of COO, tuples deleted
1 parent 36b3be4 commit b48705e

1 file changed

Lines changed: 17 additions & 65 deletions

File tree

Lines changed: 17 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
namespace GraphBLAS.FSharp.Backend
1+
namespace GraphBLAS.FSharp.Backend
22

33
open Brahma.FSharp
44
open GraphBLAS.FSharp.Backend
55
open GraphBLAS.FSharp.Backend.ArraysExtensions
66

77
type VectorFormat =
8-
| COO
8+
| Sparse
99
| Dense
1010

11-
type COOVector<'a> =
11+
type SparseVector<'a> =
1212
{ Indices: int []
1313
Values: 'a []
1414
Size: int }
@@ -43,62 +43,9 @@ type COOVector<'a> =
4343
|> Array.ofSeq
4444
|> Array.unzip
4545

46-
COOVector.FromTuples(indices, vals, array.Length)
46+
SparseVector.FromTuples(indices, vals, array.Length)
4747

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> =
10249
{ Context: ClContext
10350
Indices: ClArray<int>
10451
Values: ClArray<'a>
@@ -127,32 +74,37 @@ and ClTuplesVector<'a> =
12774
member this.Dispose(q) = (this :> IDeviceMemObject).Dispose(q)
12875

12976
type Vector<'a when 'a: struct> =
130-
| VectorCOO of COOVector<'a>
77+
| VectorSparse of SparseVector<'a>
13178
| VectorDense of 'a option []
13279
member this.Size =
13380
match this with
134-
| VectorCOO vector -> vector.Size
81+
| VectorSparse vector -> vector.Size
13582
| VectorDense vector -> vector.Size
13683

84+
override this.ToString() =
85+
match this with
86+
| VectorSparse vector -> vector.ToString()
87+
| VectorDense vector -> DenseVectorToString vector
88+
13789
member this.ToDevice(context: ClContext) =
13890
match this with
139-
| VectorCOO vector -> ClVectorCOO <| vector.ToDevice(context)
91+
| VectorSparse vector -> ClVectorSparse <| vector.ToDevice(context)
14092
| VectorDense vector -> ClVectorDense <| vector.ToDevice(context)
14193

14294
and ClVector<'a when 'a: struct> =
143-
| ClVectorCOO of ClCooVector<'a>
95+
| ClVectorSparse of ClSparseVector<'a>
14496
| ClVectorDense of ClArray<'a option>
14597
member this.Size =
14698
match this with
147-
| ClVectorCOO vector -> vector.Size
99+
| ClVectorSparse vector -> vector.Size
148100
| ClVectorDense vector -> vector.Size
149101

150102
member this.ToHost(q: MailboxProcessor<_>) =
151103
match this with
152-
| ClVectorCOO vector -> VectorCOO <| vector.ToHost(q)
104+
| ClVectorSparse vector -> VectorSparse <| vector.ToHost(q)
153105
| ClVectorDense vector -> VectorDense <| vector.ToHost(q)
154106

155107
member this.Dispose(q) =
156108
match this with
157-
| ClVectorCOO vector -> vector.Dispose(q)
109+
| ClVectorSparse vector -> vector.Dispose(q)
158110
| ClVectorDense vector -> vector.Dispose(q)

0 commit comments

Comments
 (0)