Skip to content

Commit bb8fa6d

Browse files
authored
Merge pull request #5 from artemgl/mask
Mask
2 parents 82d327f + 38fdbdc commit bb8fa6d

10 files changed

Lines changed: 532 additions & 252 deletions

File tree

.github/workflows/build.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: FAKE Build
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
win-build:
10+
name: Windows Build
11+
runs-on: windows-latest
12+
defaults:
13+
run:
14+
shell: cmd
15+
steps:
16+
- name: System Info
17+
run: systeminfo
18+
19+
- uses: actions/checkout@v2
20+
21+
- name: Setup .NET Core
22+
uses: actions/setup-dotnet@v1
23+
with:
24+
dotnet-version: 3.1.302
25+
26+
- name: Install OpenCL
27+
run: |
28+
set NUGETDIR=C:\NUGET
29+
nuget install opencl-nug -Version 0.777.77 -OutputDirectory %NUGETDIR%
30+
dir %NUGETDIR%\opencl-nug.0.777.77\build\native\
31+
set OCL_ROOT=%NUGETDIR%\opencl-nug.0.777.77\build\native
32+
# Install OpenCL Runtime
33+
choco install opencl-intel-cpu-runtime
34+
35+
- name: Download "clinfo.exe"
36+
uses: carlosperate/download-file-action@v1.0.3
37+
with:
38+
file-url: https://ci.appveyor.com/api/projects/oblomov/clinfo/artifacts/clinfo.exe?job=platform:+x64
39+
file-name: clinfo.exe
40+
41+
- name: OpenCL Info
42+
run: clinfo.exe
43+
44+
- name: Build
45+
run: ./build.cmd
46+
env:
47+
CI: true

paket.dependencies

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,52 @@ nuget Expecto 8.13.1
99
nuget YoloDev.Expecto.TestSdk 0.8.0
1010
nuget Microsoft.NET.Test.Sdk 15.7.2
1111
nuget altcover ~> 6
12-
nuget Brahma.FSharp
13-
nuget FsUnit.xUnit
14-
nuget FsCheck.Xunit
15-
nuget xunit
16-
nuget xunit.runner.visualstudio
17-
nuget coverlet.collector
18-
nuget FSharpx.Collections 1.15.1
12+
13+
nuget System.Collections.Immutable 5.0
14+
nuget ExtraConstraints.Fody 1.14.0
15+
nuget Microsoft.Build.Framework 16.6.0
16+
nuget System.CodeDom 4.7.0
17+
nuget FSharp.Quotations.Evaluator 2.1.0
18+
nuget FSharpx.Collections 2.1.3
19+
nuget FSharpx.Text.StructuredFormat 2.3.0
20+
nuget Brahma.FSharp.OpenCL.WorkflowBuilder
1921

2022
// [ FAKE GROUP ]
2123
group Build
22-
storage: none
23-
source https://www.nuget.org/api/v2
24-
source https://api.nuget.org/v3/index.json
25-
nuget Fake.IO.FileSystem 5.20.0
26-
nuget Fake.Core.Target 5.20.0
27-
nuget Fake.Core.ReleaseNotes 5.20.0
28-
nuget FAKE.Core.Environment 5.20.0
29-
nuget Fake.DotNet.Cli 5.20.0
30-
nuget FAKE.Core.Process 5.20.0
31-
nuget Fake.DotNet.AssemblyInfoFile 5.20.0
32-
nuget Fake.Tools.Git 5.20.0
33-
nuget Fake.DotNet.Paket 5.20.0
34-
nuget Fake.Api.GitHub 5.20.0
35-
nuget Fake.BuildServer.AppVeyor 5.20.0
36-
nuget Fake.BuildServer.Travis 5.20.0
37-
nuget Fantomas
38-
nuget Argu
24+
storage: none
25+
source https://www.nuget.org/api/v2
26+
source https://api.nuget.org/v3/index.json
27+
nuget Fake.IO.FileSystem 5.20.0
28+
nuget Fake.Core.Target 5.20.0
29+
nuget Fake.Core.ReleaseNotes 5.20.0
30+
nuget FAKE.Core.Environment 5.20.0
31+
nuget Fake.DotNet.Cli 5.20.0
32+
nuget FAKE.Core.Process 5.20.0
33+
nuget Fake.DotNet.AssemblyInfoFile 5.20.0
34+
nuget Fake.Tools.Git 5.20.0
35+
nuget Fake.DotNet.Paket 5.20.0
36+
nuget Fake.Api.GitHub 5.20.0
37+
nuget Fake.BuildServer.AppVeyor 5.20.0
38+
nuget Fake.BuildServer.Travis 5.20.0
39+
nuget Fantomas
40+
nuget Argu
3941

4042
group Docs
41-
storage: none
42-
source https://www.nuget.org/api/v2
43-
source https://api.nuget.org/v3/index.json
44-
nuget Argu
45-
nuget FSharp.Core
46-
nuget Fake.IO.FileSystem
47-
nuget FAKE.Core.Environment
48-
nuget Fake.DotNet.Cli
49-
nuget FSharp.Formatting 4.0.0-rc1
50-
nuget FSharp.Literate 4.0.0-rc1
51-
nuget Fable.React
52-
nuget Dotnet.ProjInfo.Workspace.FCS
53-
nuget FSharp.Compiler.Service 34.1.1
43+
storage: none
44+
source https://www.nuget.org/api/v2
45+
source https://api.nuget.org/v3/index.json
46+
nuget Argu
47+
nuget FSharp.Core
48+
nuget Fake.IO.FileSystem
49+
nuget FAKE.Core.Environment
50+
nuget Fake.DotNet.Cli
51+
nuget FSharp.Formatting 4.0.0-rc1
52+
nuget FSharp.Literate 4.0.0-rc1
53+
nuget Fable.React
54+
nuget Dotnet.ProjInfo.Workspace.FCS
55+
nuget FSharp.Compiler.Service 34.1.1
5456

5557
group Analyzers
5658
source https://www.nuget.org/api/v2
5759
source https://api.nuget.org/v3/index.json
58-
nuget BinaryDefense.FSharp.Analyzers.Hashing 0.1.0
60+
nuget BinaryDefense.FSharp.Analyzers.Hashing 0.1.0

paket.lock

Lines changed: 332 additions & 139 deletions
Large diffs are not rendered by default.

src/GraphBLAS-sharp/CSRMatrix.fs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type CSRMatrix<'a when 'a : struct and 'a : equality>(csrTuples: CSRFormat<'a>)
2525
let rowCount = csrTuples.RowPointers.Length - 1
2626
let columnCount = csrTuples.ColumnCount
2727

28-
let spMV (vector: Vector<'a>) (mask: Mask1D<'a>) (context: Semiring<'a>) : Vector<'a> =
28+
let spMV (vector: Vector<'a>) (mask: Mask1D) (context: Semiring<'a>) : Vector<'a> =
2929
let csrMatrixRowCount = rowCount
3030
let csrMatrixColumnCount = columnCount
3131
let vectorLength = vector.Length
@@ -69,7 +69,7 @@ type CSRMatrix<'a when 'a : struct and 'a : equality>(csrTuples: CSRFormat<'a>)
6969
currentContext.CommandQueue.Add (resultVector.ToHost currentContext.Provider) |> ignore
7070
currentContext.CommandQueue.Finish () |> ignore
7171

72-
upcast DenseVector(resultVector)
72+
upcast DenseVector(resultVector, context.PlusMonoid)
7373

7474
new() = CSRMatrix(CSRFormat.ZeroCreate())
7575

@@ -80,24 +80,27 @@ type CSRMatrix<'a when 'a : struct and 'a : equality>(csrTuples: CSRFormat<'a>)
8080
override this.RowCount = rowCount
8181
override this.ColumnCount = columnCount
8282

83+
override this.Mask = failwith "Not implemented"
84+
override this.Complemented = failwith "Not implemented"
85+
8386
override this.Item
84-
with get (mask: Mask2D<'a>) : Matrix<'a> = failwith "Not Implemented"
85-
and set (mask: Mask2D<'a>) (value: Matrix<'a>) = failwith "Not Implemented"
87+
with get (mask: Mask2D option) : Matrix<'a> = failwith "Not Implemented"
88+
and set (mask: Mask2D option) (value: Matrix<'a>) = failwith "Not Implemented"
8689
override this.Item
87-
with get (vectorMask: Mask1D<'a>, colIdx: int) : Vector<'a> = failwith "Not Implemented"
88-
and set (vectorMask: Mask1D<'a>, colIdx: int) (value: Vector<'a>) = failwith "Not Implemented"
90+
with get (vectorMask: Mask1D option, colIdx: int) : Vector<'a> = failwith "Not Implemented"
91+
and set (vectorMask: Mask1D option, colIdx: int) (value: Vector<'a>) = failwith "Not Implemented"
8992
override this.Item
90-
with get (rowIdx: int, vectorMask: Mask1D<'a>) : Vector<'a> = failwith "Not Implemented"
91-
and set (rowIdx: int, vectorMask: Mask1D<'a>) (value: Vector<'a>) = failwith "Not Implemented"
93+
with get (rowIdx: int, vectorMask: Mask1D option) : Vector<'a> = failwith "Not Implemented"
94+
and set (rowIdx: int, vectorMask: Mask1D option) (value: Vector<'a>) = failwith "Not Implemented"
9295
override this.Item
9396
with get (rowIdx: int, colIdx: int) : Scalar<'a> = failwith "Not Implemented"
9497
and set (rowIdx: int, colIdx: int) (value: Scalar<'a>) = failwith "Not Implemented"
9598
override this.Item
96-
with set (mask: Mask2D<'a>) (value: Scalar<'a>) = failwith "Not Implemented"
99+
with set (mask: Mask2D option) (value: Scalar<'a>) = failwith "Not Implemented"
97100
override this.Item
98-
with set (vectorMask: Mask1D<'a>, colIdx: int) (value: Scalar<'a>) = failwith "Not Implemented"
101+
with set (vectorMask: Mask1D option, colIdx: int) (value: Scalar<'a>) = failwith "Not Implemented"
99102
override this.Item
100-
with set (rowIdx: int, vectorMask: Mask1D<'a>) (value: Scalar<'a>) = failwith "Not Implemented"
103+
with set (rowIdx: int, vectorMask: Mask1D option) (value: Scalar<'a>) = failwith "Not Implemented"
101104

102105
override this.Mxm a b c = failwith "Not Implemented"
103106
override this.Mxv a b c = failwith "Not Implemented"

src/GraphBLAS-sharp/DenseVector.fs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11
namespace GraphBLAS.FSharp
22

3-
type DenseVector<'a when 'a : struct and 'a : equality>(vector: 'a[]) =
3+
type DenseVector<'a when 'a : struct and 'a : equality>(vector: 'a[], monoid: Monoid<'a>) =
44
inherit Vector<'a>()
55

6-
new() = DenseVector(Array.zeroCreate<'a> 0)
7-
new(listOfIndices: int list) = DenseVector(Array.zeroCreate<'a> 0)
6+
new(monoid: Monoid<'a>) = DenseVector(Array.zeroCreate<'a> 0, monoid)
7+
new(listOfIndices: int list, monoid: Monoid<'a>) = DenseVector(Array.zeroCreate<'a> 0, monoid)
8+
9+
member this.Monoid = monoid
10+
member this.Values = vector
811

912
override this.Length = failwith "Not Implemented"
1013
override this.AsArray = failwith "Not Implemented"
1114

15+
override this.Mask =
16+
let indices =
17+
[| for i in 0 .. this.Length - 1 do
18+
if this.Values.[i] <> this.Monoid.Zero then yield i |]
19+
Some <| Mask1D(indices, this.Length, false)
20+
21+
override this.Complemented =
22+
let indices =
23+
[| for i in 0 .. this.Length - 1 do
24+
if this.Values.[i] <> this.Monoid.Zero then yield i |]
25+
Some <| Mask1D(indices, this.Length, true)
26+
1227
override this.Item
13-
with get (mask: Mask1D<'a>) : Vector<'a> = failwith "Not Implemented"
14-
and set (mask: Mask1D<'a>) (value: Vector<'a>) = failwith "Not Implemented"
28+
with get (mask: Mask1D option) : Vector<'a> = failwith "Not Implemented"
29+
and set (mask: Mask1D option) (value: Vector<'a>) = failwith "Not Implemented"
1530
override this.Item
16-
with get (rowIdx: int, colIdx: int) : Scalar<'a> = failwith "Not Implemented"
17-
and set (rowIdx: int, colIdx: int) (value: Scalar<'a>) = failwith "Not Implemented"
31+
with get (idx: int) : Scalar<'a> = failwith "Not Implemented"
32+
and set (idx: int) (value: Scalar<'a>) = failwith "Not Implemented"
1833
override this.Item
19-
with set (mask: Mask1D<'a>) (value: Scalar<'a>) = failwith "Not Implemented"
34+
with set (mask: Mask1D option) (value: Scalar<'a>) = failwith "Not Implemented"
2035

2136
override this.Vxm a b c = failwith "Not Implemented"
2237
override this.EWiseAdd a b c = failwith "Not Implemented"

src/GraphBLAS-sharp/MatrixAndVector.fs

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,29 @@ type Matrix<'a when 'a : struct and 'a : equality>() =
55
abstract RowCount: int
66
abstract ColumnCount: int
77

8-
abstract Item: Mask2D<'a> -> Matrix<'a> with get, set
9-
abstract Item: Mask1D<'a> * int -> Vector<'a> with get, set
10-
abstract Item: int * Mask1D<'a> -> Vector<'a> with get, set
8+
abstract Mask: Mask2D option
9+
abstract Complemented: Mask2D option
10+
11+
abstract Item: Mask2D option -> Matrix<'a> with get, set
12+
abstract Item: Mask1D option * int -> Vector<'a> with get, set
13+
abstract Item: int * Mask1D option -> Vector<'a> with get, set
1114
abstract Item: int * int -> Scalar<'a> with get, set
12-
abstract Item: Mask2D<'a> -> Scalar<'a> with set
13-
abstract Item: Mask1D<'a> * int -> Scalar<'a> with set
14-
abstract Item: int * Mask1D<'a> -> Scalar<'a> with set
15-
16-
abstract Mxm: Matrix<'a> -> Mask2D<'a> -> Semiring<'a> -> Matrix<'a>
17-
abstract Mxv: Vector<'a> -> Mask1D<'a> -> Semiring<'a> -> Vector<'a>
18-
abstract EWiseAdd: Matrix<'a> -> Mask2D<'a> -> Semiring<'a> -> Matrix<'a>
19-
abstract EWiseMult: Matrix<'a> -> Mask2D<'a> -> Semiring<'a> -> Matrix<'a>
20-
abstract Apply: Mask1D<'a> -> UnaryOp<'a, 'b> -> Matrix<'b>
21-
abstract ReduceIn: Mask1D<'a> -> Monoid<'a> -> Vector<'a>
22-
abstract ReduceOut: Mask1D<'a> -> Monoid<'a> -> Vector<'a>
15+
abstract Item: Mask2D option -> Scalar<'a> with set
16+
abstract Item: Mask1D option * int -> Scalar<'a> with set
17+
abstract Item: int * Mask1D option -> Scalar<'a> with set
18+
19+
abstract Mxm: Matrix<'a> -> Mask2D option -> Semiring<'a> -> Matrix<'a>
20+
abstract Mxv: Vector<'a> -> Mask1D option -> Semiring<'a> -> Vector<'a>
21+
abstract EWiseAdd: Matrix<'a> -> Mask2D option -> Semiring<'a> -> Matrix<'a>
22+
abstract EWiseMult: Matrix<'a> -> Mask2D option -> Semiring<'a> -> Matrix<'a>
23+
abstract Apply: Mask1D option -> UnaryOp<'a, 'b> -> Matrix<'b>
24+
abstract ReduceIn: Mask1D option -> Monoid<'a> -> Vector<'a>
25+
abstract ReduceOut: Mask1D option -> Monoid<'a> -> Vector<'a>
2326
abstract T: Matrix<'a>
2427

25-
abstract EWiseAddInplace: Matrix<'a> -> Mask2D<'a> -> Semiring<'a> -> unit
26-
abstract EWiseMultInplace: Matrix<'a> -> Mask2D<'a> -> Semiring<'a> -> unit
27-
abstract ApplyInplace: Mask2D<'a> -> UnaryOp<'a, 'b> -> unit
28+
abstract EWiseAddInplace: Matrix<'a> -> Mask2D option -> Semiring<'a> -> unit
29+
abstract EWiseMultInplace: Matrix<'a> -> Mask2D option -> Semiring<'a> -> unit
30+
abstract ApplyInplace: Mask2D option -> UnaryOp<'a, 'b> -> unit
2831

2932
static member inline (+) (x: Matrix<'a>, y: Matrix<'a>) = x.EWiseAdd y
3033
static member inline (*) (x: Matrix<'a>, y: Matrix<'a>) = x.EWiseMult y
@@ -37,32 +40,47 @@ and [<AbstractClass>] Vector<'a when 'a : struct and 'a : equality>() =
3740
abstract Length: int
3841
abstract AsArray: 'a[]
3942

40-
abstract Item: Mask1D<'a> -> Vector<'a> with get, set
41-
abstract Item: int * int -> Scalar<'a> with get, set
42-
abstract Item: Mask1D<'a> -> Scalar<'a> with set
43+
abstract Mask: Mask1D option
44+
abstract Complemented: Mask1D option
45+
46+
abstract Item: Mask1D option -> Vector<'a> with get, set
47+
abstract Item: int -> Scalar<'a> with get, set
48+
abstract Item: Mask1D option -> Scalar<'a> with set
4349

44-
abstract Vxm: Matrix<'a> -> Mask1D<'a> -> Semiring<'a> -> Vector<'a>
45-
abstract EWiseAdd: Vector<'a> -> Mask1D<'a> -> Semiring<'a> -> Vector<'a>
46-
abstract EWiseMult: Vector<'a> -> Mask1D<'a> -> Semiring<'a> -> Vector<'a>
47-
abstract Apply: Mask1D<'a> -> UnaryOp<'a, 'b> -> Vector<'b>
50+
abstract Vxm: Matrix<'a> -> Mask1D option -> Semiring<'a> -> Vector<'a>
51+
abstract EWiseAdd: Vector<'a> -> Mask1D option -> Semiring<'a> -> Vector<'a>
52+
abstract EWiseMult: Vector<'a> -> Mask1D option -> Semiring<'a> -> Vector<'a>
53+
abstract Apply: Mask1D option -> UnaryOp<'a, 'b> -> Vector<'b>
4854
abstract Reduce: Monoid<'a> -> Scalar<'a>
4955

50-
abstract EWiseAddInplace: Vector<'a> -> Mask1D<'a> -> Semiring<'a> -> unit
51-
abstract EWiseMultInplace: Vector<'a> -> Mask1D<'a> -> Semiring<'a> -> unit
52-
abstract ApplyInplace: Mask1D<'a> -> UnaryOp<'a, 'b> -> unit
56+
abstract EWiseAddInplace: Vector<'a> -> Mask1D option -> Semiring<'a> -> unit
57+
abstract EWiseMultInplace: Vector<'a> -> Mask1D option -> Semiring<'a> -> unit
58+
abstract ApplyInplace: Mask1D option -> UnaryOp<'a, 'b> -> unit
5359

5460
static member inline (+) (x: Vector<'a>, y: Vector<'a>) = x.EWiseAdd y
5561
static member inline (*) (x: Vector<'a>, y: Vector<'a>) = x.EWiseMult y
5662
static member inline (+.*) (x: Vector<'a>, y: Matrix<'a>) = x.Vxm y
5763
static member inline (.+) (x: Vector<'a>, y: Vector<'a>) = x.EWiseAddInplace y
5864
static member inline (.*) (x: Vector<'a>, y: Vector<'a>) = x.EWiseMultInplace y
5965

60-
and Mask1D<'a when 'a : struct and 'a : equality> =
61-
| Mask1D of Vector<'a>
62-
| Complemented1D of Vector<'a>
63-
| None
66+
and Mask1D(indices: int[], length: int, isComplemented: bool) =
67+
member this.IsComplemented = isComplemented
68+
69+
member this.Indices = indices
70+
member this.Length = length
71+
72+
member this.Item
73+
with get (idx: int) : bool =
74+
this.Indices |> Array.exists ( ( = ) idx) |> ( <> ) this.IsComplemented
75+
76+
and Mask2D(indices: (int * int)[], rowCount: int, columnCount: int, isComplemented: bool) =
77+
member this.IsComplemented = isComplemented
78+
79+
member this.Rows = indices |> Array.unzip |> fst
80+
member this.Columns = indices |> Array.unzip |> snd
81+
member this.RowCount = rowCount
82+
member this.ColumnCount = columnCount
6483

65-
and Mask2D<'a when 'a : struct and 'a : equality> =
66-
| Mask2D of Matrix<'a>
67-
| Complemented2D of Matrix<'a>
68-
| None
84+
member this.Item
85+
with get (rowIdx: int, colIdx: int) : bool =
86+
Array.zip this.Rows this.Columns |> Array.exists ( ( = ) (rowIdx, colIdx)) |> ( <> ) this.IsComplemented

src/GraphBLAS-sharp/paket.references

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ FSharp.Core
22
Microsoft.SourceLink.GitHub
33
Microsoft.NETFramework.ReferenceAssemblies
44

5-
Brahma.FSharp
5+
Brahma.FSharp
6+
Brahma.FSharp.OpenCL.WorkflowBuilder

tests/GraphBLAS-sharp.Tests/CSRMatrixTests.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
namespace CSRMultiplication.Tests
22

3-
open System
4-
open Xunit
5-
open FsUnit.Xunit
6-
open FsCheck
7-
open FsCheck.Xunit
8-
open GraphBLAS.FSharp
3+
// open System
4+
// open Xunit
5+
// open FsUnit.Xunit
6+
// open FsCheck
7+
// open FsCheck.Xunit
8+
// open GraphBLAS.FSharp
99

1010
// [<Properties(Verbose=true, MaxTest=100, EndSize=2500)>]
1111
module CSRMatrixTests =

0 commit comments

Comments
 (0)