|
1 | 1 | namespace GraphBLAS.FSharp |
2 | 2 |
|
| 3 | +open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation |
| 4 | + |
3 | 5 | [<AbstractClass>] |
4 | 6 | type Matrix<'a when 'a : struct and 'a : equality>(nrow: int, ncol: int) = |
5 | 7 | abstract RowCount: int |
6 | 8 | abstract ColumnCount: int |
7 | 9 | default this.RowCount = nrow |
8 | 10 | default this.ColumnCount = ncol |
9 | 11 |
|
10 | | - abstract Mask: Mask2D option |
11 | | - abstract Complemented: Mask2D option |
12 | | - |
13 | | - abstract Item: Mask2D option -> Matrix<'a> with get, set |
14 | | - abstract Item: Mask1D option * int -> Vector<'a> with get, set |
15 | | - abstract Item: int * Mask1D option -> Vector<'a> with get, set |
16 | | - abstract Item: int * int -> Scalar<'a> with get, set |
17 | | - abstract Fill: Mask2D option -> Scalar<'a> with set |
18 | | - abstract Fill: Mask1D option * int -> Scalar<'a> with set |
19 | | - abstract Fill: int * Mask1D option -> Scalar<'a> with set |
20 | | - |
21 | | - abstract Mxm: Matrix<'a> -> Mask2D option -> Semiring<'a> -> Matrix<'a> |
22 | | - abstract Mxv: Vector<'a> -> Mask1D option -> Semiring<'a> -> Vector<'a> |
23 | | - abstract EWiseAdd: Matrix<'a> -> Mask2D option -> Monoid<'a> -> Matrix<'a> |
24 | | - abstract EWiseMult: Matrix<'a> -> Mask2D option -> Monoid<'a> -> Matrix<'a> |
25 | | - abstract Apply: Mask1D option -> UnaryOp<'a, 'b> -> Matrix<'b> |
26 | | - abstract ReduceIn: Mask1D option -> Monoid<'a> -> Vector<'a> |
27 | | - abstract ReduceOut: Mask1D option -> Monoid<'a> -> Vector<'a> |
28 | | - abstract Reduce: Monoid<'a> -> Scalar<'a> |
29 | | - abstract T: Matrix<'a> |
| 12 | + abstract Clear: unit -> OpenCLEvaluation<unit> |
| 13 | + abstract Copy: unit -> OpenCLEvaluation<Matrix<'a>> |
| 14 | + abstract Resize: int -> int -> OpenCLEvaluation<Matrix<'a>> |
| 15 | + abstract GetNNZ: unit -> OpenCLEvaluation<int> |
| 16 | + abstract GetTuples: unit -> OpenCLEvaluation<{| Rows: int[]; Columns: int[]; Values: 'a[] |}> |
| 17 | + abstract GetMask: ?isComplemented: bool -> OpenCLEvaluation<Mask2D option> |
| 18 | + |
| 19 | + abstract Extract: Mask2D option -> OpenCLEvaluation<Matrix<'a>> |
| 20 | + abstract Extract: (Mask1D option * int) -> OpenCLEvaluation<Vector<'a>> |
| 21 | + abstract Extract: (int * Mask1D option) -> OpenCLEvaluation<Vector<'a>> |
| 22 | + abstract Extract: (int * int) -> OpenCLEvaluation<Scalar<'a>> |
| 23 | + abstract Assign: Mask2D option * Matrix<'a> -> OpenCLEvaluation<unit> |
| 24 | + abstract Assign: (Mask1D option * int) * Vector<'a> -> OpenCLEvaluation<unit> |
| 25 | + abstract Assign: (int * Mask1D option) * Vector<'a> -> OpenCLEvaluation<unit> |
| 26 | + abstract Assign: (int * int) * Scalar<'a> -> OpenCLEvaluation<unit> |
| 27 | + abstract Assign: Mask2D option * Scalar<'a> -> OpenCLEvaluation<unit> |
| 28 | + abstract Assign: (Mask1D option * int) * Scalar<'a> -> OpenCLEvaluation<unit> |
| 29 | + abstract Assign: (int * Mask1D option) * Scalar<'a> -> OpenCLEvaluation<unit> |
| 30 | + |
| 31 | + abstract Mxm: Matrix<'a> -> Mask2D option -> Semiring<'a> -> OpenCLEvaluation<Matrix<'a>> |
| 32 | + abstract Mxv: Vector<'a> -> Mask1D option -> Semiring<'a> -> OpenCLEvaluation<Vector<'a>> |
| 33 | + abstract EWiseAdd: Matrix<'a> -> Mask2D option -> Semiring<'a> -> OpenCLEvaluation<Matrix<'a>> |
| 34 | + abstract EWiseMult: Matrix<'a> -> Mask2D option -> Semiring<'a> -> OpenCLEvaluation<Matrix<'a>> |
| 35 | + abstract Apply: Mask2D option -> UnaryOp<'a, 'b> -> OpenCLEvaluation<Matrix<'b>> |
| 36 | + abstract Prune: Mask2D option -> UnaryOp<'a, bool> -> OpenCLEvaluation<Matrix<'a>> |
| 37 | + abstract ReduceIn: Mask1D option -> Monoid<'a> -> OpenCLEvaluation<Vector<'a>> |
| 38 | + abstract ReduceOut: Mask1D option -> Monoid<'a> -> OpenCLEvaluation<Vector<'a>> |
| 39 | + abstract Reduce: Monoid<'a> -> OpenCLEvaluation<Scalar<'a>> |
| 40 | + abstract Transpose: unit -> OpenCLEvaluation<Matrix<'a>> |
| 41 | + abstract Kronecker: Matrix<'a> -> Mask2D option -> Semiring<'a> -> OpenCLEvaluation<Matrix<'a>> |
30 | 42 |
|
31 | 43 | static member inline (+) (x: Matrix<'a>, y: Matrix<'a>) = x.EWiseAdd y |
32 | 44 | static member inline (*) (x: Matrix<'a>, y: Matrix<'a>) = x.EWiseMult y |
33 | 45 | static member inline (@.) (x: Matrix<'a>, y: Matrix<'a>) = x.Mxm y |
34 | 46 | static member inline (@.) (x: Matrix<'a>, y: Vector<'a>) = x.Mxv y |
35 | 47 |
|
36 | | -and [<AbstractClass>] Vector<'a when 'a : struct and 'a : equality>(length: int) = |
37 | | - abstract Length: int |
38 | | - default this.Length = length |
39 | 48 |
|
40 | | - abstract AsArray: 'a[] |
41 | | - abstract Clear: unit -> unit |
| 49 | +and [<AbstractClass>] Vector<'a when 'a : struct and 'a : equality>(size: int) = |
| 50 | + abstract Size: int |
| 51 | + default this.Size = size |
42 | 52 |
|
43 | | - abstract Mask: Mask1D option |
44 | | - abstract Complemented: Mask1D option |
| 53 | + abstract Clear: unit -> OpenCLEvaluation<unit> |
| 54 | + abstract Copy: unit -> OpenCLEvaluation<Vector<'a>> |
| 55 | + abstract Resize: int -> OpenCLEvaluation<Vector<'a>> |
| 56 | + abstract GetNNZ: unit -> OpenCLEvaluation<int> |
| 57 | + abstract GetTuples: unit -> OpenCLEvaluation<{| Indices: int[]; Values: 'a[] |}> |
| 58 | + abstract GetMask: ?isComplemented: bool -> OpenCLEvaluation<Mask1D option> |
45 | 59 |
|
46 | | - abstract Item: Mask1D option -> Vector<'a> with get, set |
47 | | - abstract Item: int -> Scalar<'a> with get, set |
48 | | - abstract Fill: Mask1D option -> Scalar<'a> with set |
| 60 | + abstract Extract: Mask1D option -> OpenCLEvaluation<Vector<'a>> |
| 61 | + abstract Extract: int -> OpenCLEvaluation<Scalar<'a>> |
| 62 | + abstract Assign: Mask1D option * Vector<'a> -> OpenCLEvaluation<unit> |
| 63 | + abstract Assign: int * Scalar<'a> -> OpenCLEvaluation<unit> |
| 64 | + abstract Assign: Mask1D option * Scalar<'a> -> OpenCLEvaluation<unit> |
49 | 65 |
|
50 | | - abstract Vxm: Matrix<'a> -> Mask1D option -> Semiring<'a> -> Vector<'a> |
51 | | - abstract EWiseAdd: Vector<'a> -> Mask1D option -> Monoid<'a> -> Vector<'a> |
52 | | - abstract EWiseMult: Vector<'a> -> Mask1D option -> Monoid<'a> -> Vector<'a> |
53 | | - abstract Apply: Mask1D option -> UnaryOp<'a, 'b> -> Vector<'b> |
54 | | - abstract Reduce: Monoid<'a> -> Scalar<'a> |
| 66 | + abstract Vxm: Matrix<'a> -> Mask1D option -> Semiring<'a> -> OpenCLEvaluation<Vector<'a>> |
| 67 | + abstract EWiseAdd: Vector<'a> -> Mask1D option -> Semiring<'a> -> OpenCLEvaluation<Vector<'a>> |
| 68 | + abstract EWiseMult: Vector<'a> -> Mask1D option -> Semiring<'a> -> OpenCLEvaluation<Vector<'a>> |
| 69 | + abstract Apply: Mask1D option -> UnaryOp<'a, 'b> -> OpenCLEvaluation<Vector<'b>> |
| 70 | + abstract Prune: Mask1D option -> UnaryOp<'a, bool> -> OpenCLEvaluation<Vector<'a>> |
| 71 | + abstract Reduce: Monoid<'a> -> OpenCLEvaluation<Scalar<'a>> |
55 | 72 |
|
56 | 73 | static member inline (+) (x: Vector<'a>, y: Vector<'a>) = x.EWiseAdd y |
57 | 74 | static member inline (*) (x: Vector<'a>, y: Vector<'a>) = x.EWiseMult y |
58 | 75 | static member inline (@.) (x: Vector<'a>, y: Matrix<'a>) = x.Vxm y |
59 | 76 |
|
60 | | -and Mask1D(indices: int[], length: int, isComplemented: bool) = |
| 77 | + |
| 78 | +and Mask1D(indices: int[], size: int, isComplemented: bool) = |
61 | 79 | member this.Indices = indices |
62 | | - member this.Length = length |
| 80 | + member this.Size = size |
63 | 81 | member this.IsComplemented = isComplemented |
64 | 82 |
|
65 | | - member this.Item |
66 | | - with get (idx: int) : bool = |
67 | | - this.Indices |
68 | | - |> Array.exists ((=) idx) |
69 | | - |> (<>) this.IsComplemented |
70 | 83 |
|
71 | | -and Mask2D(indices: (int * int)[], rowCount: int, columnCount: int, isComplemented: bool) = |
72 | | - member this.Rows = indices |> Array.unzip |> fst |
73 | | - member this.Columns = indices |> Array.unzip |> snd |
| 84 | +and Mask2D(rowIndices: int[], columnIndices: int[], rowCount: int, columnCount: int, isComplemented: bool) = |
| 85 | + member this.RowIndices = rowIndices |
| 86 | + member this.ColumnIndices = columnIndices |
74 | 87 | member this.RowCount = rowCount |
75 | 88 | member this.ColumnCount = columnCount |
76 | 89 | member this.IsComplemented = isComplemented |
77 | | - |
78 | | - member this.Item |
79 | | - with get (rowIdx: int, colIdx: int) : bool = |
80 | | - (this.Rows, this.Columns) |
81 | | - ||> Array.zip |
82 | | - |> Array.exists ((=) (rowIdx, colIdx)) |
83 | | - |> (<>) this.IsComplemented |
|
0 commit comments