@@ -3,6 +3,7 @@ namespace GraphBLAS.FSharp.Tests
33open Expecto
44open FsCheck
55open GraphBLAS.FSharp
6+ open MathNet.Numerics
67
78type OperationCase = {
89 VectorCase: VectorType
@@ -11,25 +12,25 @@ type OperationCase = {
1112}
1213
1314type MatrixMultiplicationPair =
14- static member DimensionGen2 () =
15+ static member DimensionGen2 () =
1516 fun size ->
1617 Gen.choose ( 0 , size |> float |> sqrt |> int)
1718 |> Gen.two
1819 |> Gen.sized
1920 |> Arb.fromGen
2021
21- static member DimensionGen3 () =
22+ static member DimensionGen3 () =
2223 fun size ->
2324 Gen.choose ( 0 , size |> float |> sqrt |> int)
2425 |> Gen.three
2526 |> Gen.sized
2627 |> Arb.fromGen
2728
28- static member FloatSparseMatrixVectorPair () =
29+ static member FloatSparseMatrixVectorPair () =
2930 fun size ->
3031 let floatSparseGenerator =
3132 Gen.oneof [
32- Arb.Default.NormalFloat () |> Arb.toGen |> Gen.map float
33+ Arb.Default.NormalFloat() |> Arb.toGen |> Gen.map float
3334 Gen.constant 0.
3435 ]
3536
@@ -74,8 +75,9 @@ module VxmTests =
7475 })
7576
7677 [<Tests>]
77- let vxmTestList =
78- testList " Vector-matrix multiplication tests" (
78+ let vxmTestsInStandardSemiring =
79+ let stdSemiring = Predefined.FloatSemiring.addMult
80+ ptestList " Float vector-matrix multiplication tests" (
7981 List.collect ( fun case ->
8082 let matrixBackend =
8183 match case.MatrixCase with
@@ -94,17 +96,31 @@ module VxmTests =
9496
9597 [
9698 testPropertyWithConfig config " Dimensional mismatch should raise an exception" <|
97- // тут просто размерности генерить и создавать пустые объекты
9899 fun matrixRowCount matrixColumnCount vectorSize ->
99100 let emptyMatrix = Matrix.ZeroCreate( matrixRowCount, matrixColumnCount, matrixBackend)
100101 let emptyVector = zeroVectorConstructor vectorSize
101102
102103 Expect.throwsT< System.ArgumentException>
103- ( fun () -> ( emptyVector @. emptyMatrix) Mask1D.none Predefined.FloatSemiring.addMult |> ignore)
104- " sss??? "
104+ ( fun () -> ( emptyVector @. emptyMatrix) Mask1D.none stdSemiring |> ignore)
105+ ( sprintf " 1x %i @ %i x %i " vectorSize matrixRowCount matrixColumnCount )
105106
106107 testPropertyWithConfig config " Operation should have correct semantic" <|
107- fun ( matrix : float [,]) ( vector : float [,]) -> ()
108+ fun ( denseMatrix : float [,]) ( denseVector : float []) ->
109+ let matrix = Matrix.Build( denseMatrix, 0. , matrixBackend)
110+ let vector = vectorConstructor denseVector
111+ let result = ( vector @. matrix) Mask1D.none stdSemiring
112+ let a = LinearAlgebra.DenseMatrix.ofArray2 denseMatrix
113+ let b = LinearAlgebra.DenseVector.ofArray denseVector
114+ let c = b * a
115+ let elementWiseDifference =
116+ ( result |> Vector.toSeq, c.AsArray() |> Seq.ofArray)
117+ ||> Seq.zip
118+ |> Seq.map ( fun ( a , b ) -> a - b)
119+
120+ Expect.all
121+ elementWiseDifference
122+ ( fun diff -> abs diff < Accuracy.medium.absolute)
123+ ( sprintf " %A @ %A = %A " vector matrix result)
108124
109125 ptestPropertyWithConfig config " Explicit zeroes after operation should be dropped" <|
110126 fun a b -> a + b = b + a
0 commit comments