Skip to content

Commit c3f8f55

Browse files
committed
Fix some algorithms, add one test case
1 parent 6b14acb commit c3f8f55

15 files changed

Lines changed: 175 additions & 74 deletions

File tree

global.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"sdk": {
3-
"version": "3.1.302-2"
3+
"version": "3.1.302",
4+
"rollForward": "latestFeature"
45
}
56
}

paket.dependencies

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ nuget FSharp.Core 4.3.4
66
nuget Microsoft.SourceLink.GitHub prerelease copy_local: true
77
nuget Microsoft.NETFramework.ReferenceAssemblies copy_local: true
88
nuget Expecto 8.13.1
9+
nuget Expecto.FsCheck 8.13.1
910
nuget YoloDev.Expecto.TestSdk 0.8.0
1011
nuget Microsoft.NET.Test.Sdk 15.7.2
1112
nuget altcover ~> 6

paket.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@ NUGET
6868
Expecto (8.13.1)
6969
FSharp.Core (>= 4.3.4) - restriction: || (>= net461) (>= netstandard2.0)
7070
Mono.Cecil (>= 0.11) - restriction: || (>= net461) (>= netstandard2.0)
71+
Expecto.FsCheck (8.13.1)
72+
Expecto (>= 8.13.1) - restriction: || (>= net461) (>= netstandard2.0)
73+
FsCheck (>= 2.14) - restriction: || (>= net461) (>= netstandard2.0)
7174
ExtraConstraints.Fody (1.14)
7275
Fody (>= 6.0) - restriction: || (>= net452) (>= netstandard1.4)
7376
NETStandard.Library (>= 1.6.1) - restriction: && (< net452) (>= netstandard1.4)
7477
Fody (6.3) - restriction: || (>= net452) (>= netstandard1.4)
78+
FsCheck (2.14.3) - restriction: || (>= net461) (>= netstandard2.0)
79+
FSharp.Core (>= 4.2.3) - restriction: || (>= net452) (>= netstandard1.6)
7580
FSharp.Core (4.3.4)
7681
System.Collections (>= 4.0.11) - restriction: && (< net45) (>= netstandard1.6) (< netstandard2.0)
7782
System.Console (>= 4.0) - restriction: && (< net45) (>= netstandard1.6) (< netstandard2.0)

src/GraphBLAS-sharp/Algorithms/BFS.fs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,28 @@ module BFS =
99
let levelBFS (matrix: Matrix<bool>) (source: int) : Vector<int> =
1010
let vertexCount = matrix.RowCount
1111
let levels = DenseVector(Array.zeroCreate vertexCount, IntegerMonoid.plus)
12+
1213
let frontier = SparseVector(vertexCount, [source, true])
1314

1415
let mutable currentLevel = 1
15-
while !> (frontier.Reduce BooleanMonoid.any) && currentLevel <= vertexCount do
16+
while !> (frontier.Reduce BooleanMonoid.any) && currentLevel < vertexCount do
1617
levels.Fill(Mask1D.regular frontier) <- Scalar currentLevel
1718
frontier.Clear()
1819
frontier.[Mask1D.complemented levels] <- (frontier .@ matrix) (Mask1D.complemented levels) BooleanSemiring.anyAll
1920
currentLevel <- currentLevel + 1
2021

2122
upcast levels
2223

23-
let parentBFS (matrix: Matrix<bool>) (source: int) : Vector<int> =
24-
let vertexCount = matrix.RowCount
25-
let id = DenseVector(Array.init vertexCount id, IntegerMonoid.plus)
26-
let frontier = SparseVector(vertexCount, [source, source])
27-
let parents = SparseVector(vertexCount, [source, -1])
24+
// let parentBFS (matrix: Matrix<bool>) (source: int) : Vector<int> =
25+
// let vertexCount = matrix.RowCount
26+
// let parents = SparseVector(vertexCount, [source, -1])
27+
28+
// let id = DenseVector(Array.init vertexCount id, IntegerMonoid.plus)
29+
// let frontier = SparseVector(vertexCount, [source, source])
2830

29-
for i in 0 .. vertexCount - 1 do
30-
frontier.[Mask1D.complemented parents] <- (frontier .@ matrix) (Mask1D.complemented parents) IntegerSemiring.minFirst
31-
parents.[Mask1D.regular frontier] <- frontier
32-
frontier.[Mask1D.regular frontier] <- id
31+
// for _ in 1 .. vertexCount - 1 do
32+
// frontier.[Mask1D.complemented parents] <- (frontier .@ matrix) (Mask1D.complemented parents) IntegerSemiring.minFirst
33+
// parents.[Mask1D.regular frontier] <- frontier
34+
// frontier.[Mask1D.regular frontier] <- id
3335

34-
upcast parents
36+
// upcast parents

src/GraphBLAS-sharp/Algorithms/SSSP.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ module SSSP =
88
let SSSP (matrix: Matrix<float>) (source: int) : Vector<float> =
99
let vertexCount = matrix.RowCount
1010
let distance = SparseVector(vertexCount, [source, 0.])
11-
for i in 0 .. vertexCount - 1 do
11+
12+
for _ in 1 .. vertexCount - 1 do
1213
distance.[Mask1D.none] <- (distance .@ matrix) Mask1D.none FloatSemiring.minPlus
1314

1415
upcast distance

src/GraphBLAS-sharp/Algorithms/TriangleCounting.fs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ open GraphBLAS.FSharp
55

66
[<AutoOpen>]
77
module TriangleCounting =
8-
let sandiaTriangleCount (lowerTriangular: Matrix<bool>) =
9-
let c = (lowerTriangular .@ lowerTriangular.T) (Mask2D.regular lowerTriangular) BooleanSemiring.anyAll
10-
c.Reduce BooleanMonoid.any
8+
// нужна проекция в инт
9+
// let sandiaTriangleCount (lowerTriangular: Matrix<bool>) =
10+
// let c = (lowerTriangular .@ lowerTriangular.T) (Mask2D.regular lowerTriangular) BooleanSemiring.anyAll
11+
// c.Reduce BooleanMonoid.any
12+
()

src/GraphBLAS-sharp/Backend.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace GraphBLAS.FSharp
2+
3+
module Backend =
4+
type Matrix<'a when 'a : struct and 'a : equality> with
5+
static member Build(matrix: 'b[,], matrixType: MatrixBackendFormat) : Matrix<'b> = failwith "Not Implemented"
6+
static member ZeroCreate(rowCount: int, columnCount: int, matrixType: MatrixBackendFormat) : Matrix<'b> = failwith "Not Implemented"
7+
8+
// type Vector<'a when 'a : struct and 'a : equality> with
9+
// static member ZeroCreate

src/GraphBLAS-sharp/GraphBLAS-sharp.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<Compile Include="Scalar.fs" />
1717
<Compile Include="Abstracts.fs" />
1818
<Compile Include="Implementations.fs" />
19+
<Compile Include="Backend.fs" />
1920
<Compile Include="Matrix.fs" />
2021
<Compile Include="Vector.fs" />
2122
<Compile Include="Masks.fs" />

src/GraphBLAS-sharp/Matrix.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
namespace GraphBLAS.FSharp
22

3+
open Backend
4+
35
[<AutoOpen>]
46
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
57
module Matrix =
68
type Matrix<'a when 'a : struct and 'a : equality> with
7-
static member Build (filename: string) : Matrix<'b> = failwith "Not Implemented"
9+
static member Build(matrix: 'b[,]) : Matrix<'b> = Matrix.Build(matrix, matrixBackendFormat)
10+
static member Build(filename: string) : Matrix<'b> = failwith "Not Implemented"
11+
static member ZeroCreate(rowCount: int, columnCount: int) : Matrix<'b> = Matrix.ZeroCreate(rowCount, columnCount)
12+

src/GraphBLAS-sharp/Predefined/Float.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,22 @@ namespace GraphBLAS.FSharp.Predefined
33
open GraphBLAS.FSharp
44

55
module FloatMonoid =
6+
let plus: Monoid<float> = {
7+
Zero = 0.
8+
Append = BinaryOp <@ ( + ) @>
9+
}
10+
611
let min: Monoid<float> = {
712
Zero = System.Double.PositiveInfinity
813
Append = BinaryOp <@ fun x y -> System.Math.Min(x, y) @>
914
}
1015

1116
module FloatSemiring =
17+
let plusTimes: Semiring<float> = {
18+
PlusMonoid = FloatMonoid.plus
19+
Times = BinaryOp <@ ( * ) @>
20+
}
21+
1222
let minPlus: Semiring<float> = {
1323
PlusMonoid = FloatMonoid.min
1424
Times = BinaryOp <@ ( + ) @>

0 commit comments

Comments
 (0)