@@ -9,9 +9,8 @@ type VectorFormat =
99
1010type COOVector < 'a > =
1111 { Indices: int []
12- Values: 'a [] }
13-
14- member this.Size = this.Indices.Length
12+ Values: 'a []
13+ Size: int }
1514
1615 override this.ToString () =
1716 [ sprintf " Sparse Vector\n "
@@ -26,9 +25,13 @@ type COOVector<'a> =
2625
2726 { Context = context
2827 Indices = indices
29- Values = values }
28+ Values = values
29+ Size = this.Size }
3030
31- static member FromTuples ( indices : int [], values : 'a []) = { Indices = indices; Values = values }
31+ static member FromTuples ( indices : int [], values : 'a [], size : int ) =
32+ { Indices = indices
33+ Values = values
34+ Size = size }
3235
3336 static member FromArray ( array : 'a [], isZero : 'a -> bool ) =
3437 let ( indices , vals ) =
@@ -39,14 +42,13 @@ type COOVector<'a> =
3942 |> Array.ofSeq
4043 |> Array.unzip
4144
42- COOVector.FromTuples( indices, vals)
45+ COOVector.FromTuples( indices, vals, array.Length )
4346
4447and ClCooVector < 'a > =
4548 { Context: ClContext
4649 Indices: ClArray < int >
47- Values: ClArray < 'a > }
48-
49- member this.Size = this.Indices.Length
50+ Values: ClArray < 'a >
51+ Size: int }
5052
5153 member this.ToHost ( q : MailboxProcessor < _ >) =
5254 let indices = Array.zeroCreate this.Indices.Length
@@ -58,7 +60,9 @@ and ClCooVector<'a> =
5860 let _ =
5961 q.PostAndReply( fun ch -> Msg.CreateToHostMsg( this.Values, values, ch))
6062
61- { Indices = indices; Values = values }
63+ { Indices = indices
64+ Values = values
65+ Size = this.Size }
6266
6367 interface IDeviceMemObject with
6468 member this.Dispose ( q ) =
@@ -112,32 +116,34 @@ and ClDenseVector<'a> =
112116
113117type TuplesVector < 'a > =
114118 { Indices: int []
115- Values: 'a [] }
119+ Values: 'a []
120+ Size: int }
116121
117122 override this.ToString () =
118123 [ sprintf " Tuples Vector\n "
119124 sprintf " Indices: %A \n " this.Indices
120125 sprintf " Values: %A \n " this.Values ]
121126 |> String.concat " "
122127
123- member this.Size = this.Indices.Length
124-
125128 member this.ToDevice ( context : ClContext ) =
126129 let indices = context.CreateClArray this.Indices
127130 let values = context.CreateClArray this.Values
128131
129132 { Context = context
130133 Indices = indices
131- Values = values }
134+ Values = values
135+ Size = this.Size }
132136
133- static member FromTuples ( indices : int [], values : 'a []) = { Indices = indices; Values = values }
137+ static member FromTuples ( indices : int [], values : 'a [], size : int ) =
138+ { Indices = indices
139+ Values = values
140+ Size = size }
134141
135142and ClTuplesVector < 'a > =
136143 { Context: ClContext
137144 Indices: ClArray < int >
138- Values: ClArray < 'a > }
139-
140- member this.Size = this.Indices.Length
145+ Values: ClArray < 'a >
146+ Size: int }
141147
142148 member this.ToHost ( q : MailboxProcessor < _ >) =
143149 let indices = Array.zeroCreate this.Indices.Length
@@ -149,7 +155,9 @@ and ClTuplesVector<'a> =
149155 let _ =
150156 q.PostAndReply( fun ch -> Msg.CreateToHostMsg( this.Values, values, ch))
151157
152- { Indices = indices; Values = values }
158+ { Indices = indices
159+ Values = values
160+ Size = this.Size }
153161
154162 interface IDeviceMemObject with
155163 member this.Dispose ( q ) =
0 commit comments