Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<Authors>YaccConstructor</Authors>
<RepositoryUrl>https://github.com/YaccConstructor/GraphBLAS-sharp</RepositoryUrl>
<!-- owners is not supported in MSBuild -->
<DisableFody>true</DisableFody>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nuget System.CodeDom 4.7.0
nuget FSharp.Quotations.Evaluator 2.1.0
nuget FSharpx.Collections 2.1.3
nuget FSharpx.Text.StructuredFormat 2.3.0
nuget Brahma.FSharp.OpenCL.WorkflowBuilder
nuget Brahma.FSharp.OpenCL.WorkflowBuilder 2.0.0-alpha4
nuget BenchmarkDotNet
nuget MathNet.Numerics.FSharp

Expand Down
50 changes: 24 additions & 26 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,34 @@ NUGET
System.Threading.Tasks.Extensions (>= 4.5.2) - restriction: >= netstandard2.0
System.ValueTuple (>= 4.5) - restriction: >= netstandard2.0
BenchmarkDotNet.Annotations (0.12.1) - restriction: >= netstandard2.0
Brahma.FSharp (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Printer (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Translator (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Printer (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Translator (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netstandard2.1)
FSharp.Quotations.Evaluator (>= 2.1) - restriction: || (>= net461) (>= netstandard2.1)
YC.Brahma (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
YC.Brahma.OpenCL (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
YC.OpenCL.NET (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.AST (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
YC.Brahma (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
YC.Brahma.OpenCL (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
YC.OpenCL.NET (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.AST (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Extensions (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Extensions (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netstandard2.1)
YC.Brahma.OpenCL (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
YC.OpenCL.NET (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Printer (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.AST (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Translator (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
YC.Brahma.OpenCL (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
YC.OpenCL.NET (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Printer (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.AST (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Translator (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netstandard2.1)
FSharpx.Collections (>= 2.1.3) - restriction: || (>= net461) (>= netstandard2.1)
FSharpx.Text.StructuredFormat (>= 2.3) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Translator (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.AST (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Extensions (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Translator (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.AST (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Extensions (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netstandard2.1)
FSharpx.Collections (>= 2.1.3) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.WorkflowBuilder (2.0.0-alpha3)
Brahma.FSharp (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Extensions (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.WorkflowBuilder (2.0.0-alpha4)
Brahma.FSharp (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
Brahma.FSharp.OpenCL.Extensions (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netstandard2.1)
Chessie (0.6) - restriction: >= netcoreapp1.0
FSharp.Core (>= 4.0.1.7-alpha) - restriction: >= netstandard1.6
Expand Down Expand Up @@ -521,7 +521,6 @@ NUGET
System.Runtime.InteropServices (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (>= netstandard1.1) (< netstandard2.0) (< win8) (< wpa81) (< xamarintvos) (< xamarinwatchos)
System.Net.Http (4.3.4) - restriction: || (&& (< net45) (>= net46) (< netstandard1.4) (>= netstandard1.6)) (&& (< net45) (< netstandard1.2) (>= netstandard1.6) (< win8)) (&& (< net45) (< netstandard1.3) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (< netstandard1.4) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (< netstandard1.5) (>= netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (>= netstandard1.6) (< netstandard2.0) (< win8) (< wpa81)) (&& (>= netcoreapp5.0) (< netstandard2.0)) (&& (< netstandard1.5) (>= netstandard1.6) (>= uap10.0))
Microsoft.NETCore.Platforms (>= 1.1.1) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (>= netcoreapp5.0)
Microsoft.Win32.Primitives (>= 4.3) - restriction: && (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)
runtime.native.System (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (< netcoreapp5.0) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
runtime.native.System.Net.Http (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (< netcoreapp5.0) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3.2) - restriction: && (< monoandroid) (< monotouch) (< net45) (< netcoreapp5.0) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
Expand All @@ -532,7 +531,6 @@ NUGET
System.Globalization (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (>= netcoreapp5.0)
System.Globalization.Extensions (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (< netcoreapp5.0) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
System.IO (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.1) (< netstandard1.3) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (>= netcoreapp5.0)
System.IO.Compression (>= 4.3) - restriction: && (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)
System.IO.FileSystem (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net45) (< netcoreapp5.0) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
System.Net.Primitives (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.1) (< netstandard1.3) (< win8) (< wpa81)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (>= netcoreapp5.0)
System.Resources.ResourceManager (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.6) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.3) (< netstandard1.6) (< win8) (< wpa81)) (>= netcoreapp5.0)
Expand Down Expand Up @@ -921,11 +919,11 @@ NUGET
System.Threading (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.3) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (>= netcoreapp5.0)
System.Xml.ReaderWriter (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.3) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.3) (< win8) (< wp8) (< wpa81)) (>= netcoreapp5.0)
System.Xml.XmlDocument (>= 4.3) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.3) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (>= netcoreapp5.0)
YC.Brahma (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
YC.Brahma.OpenCL (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
YC.Brahma (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
YC.OpenCL.NET (>= 2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
YC.OpenCL.NET (2.0.0-alpha3) - restriction: || (>= net461) (>= netstandard2.1)
YC.Brahma (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
YC.Brahma.OpenCL (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
YC.Brahma (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
YC.OpenCL.NET (>= 2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
YC.OpenCL.NET (2.0.0-alpha4) - restriction: || (>= net461) (>= netstandard2.1)
ExtraConstraints.Fody (>= 1.14) - restriction: >= netstandard2.0
Microsoft.Build.Framework (>= 16.6) - restriction: >= netstandard2.0
System.CodeDom (>= 4.7) - restriction: >= netstandard2.0
Expand Down
110 changes: 58 additions & 52 deletions src/GraphBLAS-sharp/Abstracts.fs
Original file line number Diff line number Diff line change
@@ -1,83 +1,89 @@
namespace GraphBLAS.FSharp

open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation

[<AbstractClass>]
type Matrix<'a when 'a : struct and 'a : equality>(nrow: int, ncol: int) =
abstract RowCount: int
abstract ColumnCount: int
default this.RowCount = nrow
default this.ColumnCount = ncol

abstract Mask: Mask2D option
abstract Complemented: Mask2D option

abstract Item: Mask2D option -> Matrix<'a> with get, set
abstract Item: Mask1D option * int -> Vector<'a> with get, set
abstract Item: int * Mask1D option -> Vector<'a> with get, set
abstract Item: int * int -> Scalar<'a> with get, set
abstract Fill: Mask2D option -> Scalar<'a> with set
abstract Fill: Mask1D option * int -> Scalar<'a> with set
abstract Fill: int * Mask1D option -> Scalar<'a> with set

abstract Mxm: Matrix<'a> -> Mask2D option -> Semiring<'a> -> Matrix<'a>
abstract Mxv: Vector<'a> -> Mask1D option -> Semiring<'a> -> Vector<'a>
abstract EWiseAdd: Matrix<'a> -> Mask2D option -> Monoid<'a> -> Matrix<'a>
abstract EWiseMult: Matrix<'a> -> Mask2D option -> Monoid<'a> -> Matrix<'a>
abstract Apply: Mask1D option -> UnaryOp<'a, 'b> -> Matrix<'b>
abstract ReduceIn: Mask1D option -> Monoid<'a> -> Vector<'a>
abstract ReduceOut: Mask1D option -> Monoid<'a> -> Vector<'a>
abstract Reduce: Monoid<'a> -> Scalar<'a>
abstract T: Matrix<'a>
abstract Clear: unit -> OpenCLEvaluation<unit>
abstract Copy: unit -> OpenCLEvaluation<Matrix<'a>>
abstract Resize: int -> int -> OpenCLEvaluation<Matrix<'a>>
abstract GetNNZ: unit -> OpenCLEvaluation<int>
abstract GetTuples: unit -> OpenCLEvaluation<{| Rows: int[]; Columns: int[]; Values: 'a[] |}>
abstract GetMask: ?isComplemented: bool -> OpenCLEvaluation<Mask2D option>

abstract Extract: Mask2D option -> OpenCLEvaluation<Matrix<'a>>
abstract Extract: (Mask1D option * int) -> OpenCLEvaluation<Vector<'a>>
abstract Extract: (int * Mask1D option) -> OpenCLEvaluation<Vector<'a>>
abstract Extract: (int * int) -> OpenCLEvaluation<Scalar<'a>>
abstract Assign: Mask2D option * Matrix<'a> -> OpenCLEvaluation<unit>
abstract Assign: (Mask1D option * int) * Vector<'a> -> OpenCLEvaluation<unit>
abstract Assign: (int * Mask1D option) * Vector<'a> -> OpenCLEvaluation<unit>
abstract Assign: (int * int) * Scalar<'a> -> OpenCLEvaluation<unit>
abstract Assign: Mask2D option * Scalar<'a> -> OpenCLEvaluation<unit>
abstract Assign: (Mask1D option * int) * Scalar<'a> -> OpenCLEvaluation<unit>
abstract Assign: (int * Mask1D option) * Scalar<'a> -> OpenCLEvaluation<unit>

abstract Mxm: Matrix<'a> -> Mask2D option -> Semiring<'a> -> OpenCLEvaluation<Matrix<'a>>
abstract Mxv: Vector<'a> -> Mask1D option -> Semiring<'a> -> OpenCLEvaluation<Vector<'a>>
abstract EWiseAdd: Matrix<'a> -> Mask2D option -> Semiring<'a> -> OpenCLEvaluation<Matrix<'a>>
abstract EWiseMult: Matrix<'a> -> Mask2D option -> Semiring<'a> -> OpenCLEvaluation<Matrix<'a>>
abstract Apply: Mask2D option -> UnaryOp<'a, 'b> -> OpenCLEvaluation<Matrix<'b>>
abstract Prune: Mask2D option -> UnaryOp<'a, bool> -> OpenCLEvaluation<Matrix<'a>>
abstract ReduceIn: Mask1D option -> Monoid<'a> -> OpenCLEvaluation<Vector<'a>>
abstract ReduceOut: Mask1D option -> Monoid<'a> -> OpenCLEvaluation<Vector<'a>>
abstract Reduce: Monoid<'a> -> OpenCLEvaluation<Scalar<'a>>
abstract Transpose: unit -> OpenCLEvaluation<Matrix<'a>>
abstract Kronecker: Matrix<'a> -> Mask2D option -> Semiring<'a> -> OpenCLEvaluation<Matrix<'a>>

static member inline (+) (x: Matrix<'a>, y: Matrix<'a>) = x.EWiseAdd y
static member inline (*) (x: Matrix<'a>, y: Matrix<'a>) = x.EWiseMult y
static member inline (@.) (x: Matrix<'a>, y: Matrix<'a>) = x.Mxm y
static member inline (@.) (x: Matrix<'a>, y: Vector<'a>) = x.Mxv y

and [<AbstractClass>] Vector<'a when 'a : struct and 'a : equality>(length: int) =
abstract Length: int
default this.Length = length

abstract AsArray: 'a[]
abstract Clear: unit -> unit
and [<AbstractClass>] Vector<'a when 'a : struct and 'a : equality>(size: int) =
abstract Size: int
default this.Size = size

abstract Mask: Mask1D option
abstract Complemented: Mask1D option
abstract Clear: unit -> OpenCLEvaluation<unit>
abstract Copy: unit -> OpenCLEvaluation<Vector<'a>>
abstract Resize: int -> OpenCLEvaluation<Vector<'a>>
abstract GetNNZ: unit -> OpenCLEvaluation<int>
abstract GetTuples: unit -> OpenCLEvaluation<{| Indices: int[]; Values: 'a[] |}>
abstract GetMask: ?isComplemented: bool -> OpenCLEvaluation<Mask1D option>

abstract Item: Mask1D option -> Vector<'a> with get, set
abstract Item: int -> Scalar<'a> with get, set
abstract Fill: Mask1D option -> Scalar<'a> with set
abstract Extract: Mask1D option -> OpenCLEvaluation<Vector<'a>>
abstract Extract: int -> OpenCLEvaluation<Scalar<'a>>
abstract Assign: Mask1D option * Vector<'a> -> OpenCLEvaluation<unit>
abstract Assign: int * Scalar<'a> -> OpenCLEvaluation<unit>
abstract Assign: Mask1D option * Scalar<'a> -> OpenCLEvaluation<unit>

abstract Vxm: Matrix<'a> -> Mask1D option -> Semiring<'a> -> Vector<'a>
abstract EWiseAdd: Vector<'a> -> Mask1D option -> Monoid<'a> -> Vector<'a>
abstract EWiseMult: Vector<'a> -> Mask1D option -> Monoid<'a> -> Vector<'a>
abstract Apply: Mask1D option -> UnaryOp<'a, 'b> -> Vector<'b>
abstract Reduce: Monoid<'a> -> Scalar<'a>
abstract Vxm: Matrix<'a> -> Mask1D option -> Semiring<'a> -> OpenCLEvaluation<Vector<'a>>
abstract EWiseAdd: Vector<'a> -> Mask1D option -> Semiring<'a> -> OpenCLEvaluation<Vector<'a>>
abstract EWiseMult: Vector<'a> -> Mask1D option -> Semiring<'a> -> OpenCLEvaluation<Vector<'a>>
abstract Apply: Mask1D option -> UnaryOp<'a, 'b> -> OpenCLEvaluation<Vector<'b>>
abstract Prune: Mask1D option -> UnaryOp<'a, bool> -> OpenCLEvaluation<Vector<'a>>
abstract Reduce: Monoid<'a> -> OpenCLEvaluation<Scalar<'a>>

static member inline (+) (x: Vector<'a>, y: Vector<'a>) = x.EWiseAdd y
static member inline (*) (x: Vector<'a>, y: Vector<'a>) = x.EWiseMult y
static member inline (@.) (x: Vector<'a>, y: Matrix<'a>) = x.Vxm y

and Mask1D(indices: int[], length: int, isComplemented: bool) =

and Mask1D(indices: int[], size: int, isComplemented: bool) =
member this.Indices = indices
member this.Length = length
member this.Size = size
member this.IsComplemented = isComplemented

member this.Item
with get (idx: int) : bool =
this.Indices
|> Array.exists ((=) idx)
|> (<>) this.IsComplemented

and Mask2D(indices: (int * int)[], rowCount: int, columnCount: int, isComplemented: bool) =
member this.Rows = indices |> Array.unzip |> fst
member this.Columns = indices |> Array.unzip |> snd
and Mask2D(rowIndices: int[], columnIndices: int[], rowCount: int, columnCount: int, isComplemented: bool) =
member this.RowIndices = rowIndices
member this.ColumnIndices = columnIndices
member this.RowCount = rowCount
member this.ColumnCount = columnCount
member this.IsComplemented = isComplemented

member this.Item
with get (rowIdx: int, colIdx: int) : bool =
(this.Rows, this.Columns)
||> Array.zip
|> Array.exists ((=) (rowIdx, colIdx))
|> (<>) this.IsComplemented
Loading