@@ -7,42 +7,105 @@ open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
77open GraphBLAS.FSharp .Objects .ClVectorExtensions
88
99module MatrixExtensions =
10+ // Matrix.Free
11+ type ClMatrix.COO < 'a when 'a : struct > with
12+ member this.Free ( q : MailboxProcessor < _ >) =
13+ this.Columns.Free q
14+ this.Values.Free q
15+ this.Rows.Free q
16+
17+ member this.ToHost ( q : MailboxProcessor < _ >) =
18+ { RowCount = this.RowCount
19+ ColumnCount = this.ColumnCount
20+ Rows = this.Rows.ToHost q
21+ Columns = this.Columns.ToHost q
22+ Values = this.Values.ToHost q }
23+
24+ member this.ToHostAndFree ( q : MailboxProcessor < _ >) =
25+ let result = this.ToHost q
26+ this.Free q
27+
28+ result
29+
30+ type ClMatrix.CSR < 'a when 'a : struct > with
31+ member this.Free ( q : MailboxProcessor < _ >) =
32+ this.Values.Free q
33+ this.Columns.Free q
34+ this.RowPointers.Free q
35+
36+ member this.ToHost ( q : MailboxProcessor < _ >) =
37+ { RowCount = this.RowCount
38+ ColumnCount = this.ColumnCount
39+ RowPointers = this.RowPointers.ToHost q
40+ ColumnIndices = this.Columns.ToHost q
41+ Values = this.Values.ToHost q }
42+
43+ member this.ToHostAndFree ( q : MailboxProcessor < _ >) =
44+ let result = this.ToHost q
45+ this.Free q
46+
47+ result
48+
49+ type ClMatrix.CSC < 'a when 'a : struct > with
50+ member this.Free ( q : MailboxProcessor < _ >) =
51+ this.Values.Free q
52+ this.Rows.Free q
53+ this.ColumnPointers.Free q
54+
55+ member this.ToHost ( q : MailboxProcessor < _ >) =
56+ { RowCount = this.RowCount
57+ ColumnCount = this.ColumnCount
58+ RowIndices = this.Rows.ToHost q
59+ ColumnPointers = this.ColumnPointers.ToHost q
60+ Values = this.Values.ToHost q }
61+
62+ member this.ToHostAndFree ( q : MailboxProcessor < _ >) =
63+ let result = this.ToHost q
64+ this.Free q
65+
66+ result
67+
68+ type ClMatrix.LIL < 'a when 'a : struct > with
69+ member this.Free ( q : MailboxProcessor < _ >) =
70+ this.Rows
71+ |> List.iter ( Option.iter ( fun row -> row.Dispose q))
72+
73+ member this.ToHost ( q : MailboxProcessor < _ >) =
74+ { RowCount = this.RowCount
75+ ColumnCount = this.ColumnCount
76+ Rows =
77+ this.Rows
78+ |> List.map ( Option.map ( fun row -> row.ToHost q))
79+ NNZ = this.NNZ }
80+
81+ member this.ToHostAndFree ( q : MailboxProcessor < _ >) =
82+ let result = this.ToHost q
83+ this.Free q
84+
85+ result
86+
1087 type ClMatrix < 'a when 'a: struct > with
1188 member this.ToHost ( q : MailboxProcessor < _ >) =
1289 match this with
13- | ClMatrix.COO m ->
14- { RowCount = m.RowCount
15- ColumnCount = m.ColumnCount
16- Rows = m.Rows.ToHost q
17- Columns = m.Columns.ToHost q
18- Values = m.Values.ToHost q }
19- |> Matrix.COO
20- | ClMatrix.CSR m ->
21- { RowCount = m.RowCount
22- ColumnCount = m.ColumnCount
23- RowPointers = m.RowPointers.ToHost q
24- ColumnIndices = m.Columns.ToHost q
25- Values = m.Values.ToHost q }
26- |> Matrix.CSR
27- | ClMatrix.CSC m ->
28- { RowCount = m.RowCount
29- ColumnCount = m.ColumnCount
30- RowIndices = m.Rows.ToHost q
31- ColumnPointers = m.ColumnPointers.ToHost q
32- Values = m.Values.ToHost q }
33- |> Matrix.CSC
34- | ClMatrix.LIL m ->
35- { RowCount = m.RowCount
36- ColumnCount = m.ColumnCount
37- Rows =
38- m.Rows
39- |> List.map ( Option.map ( fun row -> row.ToHost q))
40- NNZ = m.NNZ }
41- |> Matrix.LIL
42-
43- member this.ToHostAndDispose ( processor : MailboxProcessor < _ >) =
90+ | ClMatrix.COO m -> m.ToHost q |> Matrix.COO
91+ | ClMatrix.CSR m -> m.ToHost q |> Matrix.CSR
92+ | ClMatrix.CSC m -> m.ToHost q |> Matrix.CSC
93+ | ClMatrix.LIL m -> m.ToHost q |> Matrix.LIL
94+
95+ member this.Free ( q : MailboxProcessor < _ >) =
96+ match this with
97+ | ClMatrix.COO m -> m.Free q
98+ | ClMatrix.CSR m -> m.Free q
99+ | ClMatrix.CSC m -> m.Free q
100+ | ClMatrix.LIL m -> m.Free q
101+
102+ member this.FreeAndWait ( processor : MailboxProcessor < _ >) =
103+ this.Free processor
104+ processor.PostAndReply( MsgNotifyMe)
105+
106+ member this.ToHostAndFree ( processor : MailboxProcessor < _ >) =
44107 let result = this.ToHost processor
45108
46- this.Dispose processor
109+ this.Free processor
47110
48111 result
0 commit comments