-
Notifications
You must be signed in to change notification settings - Fork 4
add slice in Vector.fs and Matrix.fs, add reduceRows and reduceCols in Matrix.fs, add tests #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
af0357b
Compilable version of Maggs-Plotkin MST.
gsvgit 9cb6b1e
Tests on Maggs-Plotkin MST.
gsvgit c0dcef1
Formatted
gsvgit 2bf90ff
Maggs-Plotkin: handle edges with identical weights correctly.
gsvgit 7ac73ce
MST tests fixed. In progress.
gsvgit 2a4c757
Simple test on Boruvka to investigate what goes wrong.
gsvgit 9ce3bd4
Fixed cycles in Boruvka MST
gsvgit 56e18ef
Added information about Maggs-Plotkin MSF.
gsvgit 8f9a425
First vrsion of parent BFS.
gsvgit d83962d
Fixed vxmi.
gsvgit 64fb06e
More tests on BFS.
gsvgit a44e451
Added Parent-BFS
gsvgit 1dbe80f
Formatted.
gsvgit 1ec2aae
add slice in Vector.fs and Matrix.fs, add reduceRows and reduceCols i…
Brulevich-Nikita 2ae01e4
add Kronecker product to Matrix.fs with tests, fix tests, duplicate h…
Brulevich-Nikita 8c015a0
fix: returned failwith to benchmarks, fix SSSP, LinearAlgebra, MST, B…
Brulevich-Nikita 46959c9
add Benchmarks, their results, fix: slice logic
Brulevich-Nikita 4bc87b4
refactor benchmarks
Brulevich-Nikita 2c9e35c
add fantomas to refactored benchmarks
Brulevich-Nikita b119e6b
refactor: Vector and Matrix functions and Benchmarks
Brulevich-Nikita 2f0f92e
refactor: Kronecker, Benchmarks
Brulevich-Nikita 6dac273
add: matricies for ReduceComparison benchmark, translate errors to En…
Brulevich-Nikita File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| namespace QuadTree.Benchmarks.Kronecker | ||
|
|
||
| open System | ||
| open BenchmarkDotNet.Attributes | ||
| open QuadTree.Benchmarks.Utils | ||
|
|
||
| [<Config(typeof<MyConfig>)>] | ||
| [<MemoryDiagnoser>] | ||
| type Benchmark() = | ||
|
|
||
| [<Params(150, 200, 250, 300)>] | ||
| member val SizeA = 0 with get, set | ||
|
|
||
| [<Params(150, 200, 250, 300)>] | ||
| member val SizeB = 0 with get, set | ||
|
|
||
| [<Params(0.005, 0.01, 0.05, 0.1)>] | ||
| member val DensityB = 0.0 with get, set | ||
|
|
||
| [<Params(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)>] | ||
| member val Seed = 0 with get, set | ||
|
|
||
| member val A = Unchecked.defaultof<Matrix.SparseMatrix<double>> with get, set | ||
| member val B = Unchecked.defaultof<Matrix.SparseMatrix<double>> with get, set | ||
|
|
||
| member private this.GenerateMatrix(size: int, density: float, rng: Random) = | ||
| let coords = | ||
| [ for i in 0 .. size - 1 do | ||
| for j in 0 .. size - 1 do | ||
| if rng.NextDouble() < density then | ||
| let value = double (rng.Next(1, 4)) | ||
| yield (uint64 i * 1UL<Matrix.rowindex>, uint64 j * 1UL<Matrix.colindex>, value) ] | ||
|
|
||
| match | ||
| Matrix.fromCoordinateList ( | ||
| Matrix.CoordinateList(uint64 size * 1UL<Matrix.nrows>, uint64 size * 1UL<Matrix.ncols>, coords) | ||
| ) | ||
| with | ||
| | Ok m -> m | ||
| | Error msg -> failwithf "Failed to create matrix: %s" msg | ||
|
|
||
| [<GlobalSetup>] | ||
| member this.Setup() = | ||
| let rng = Random(this.Seed) | ||
| this.A <- this.GenerateMatrix(this.SizeA, 0.01, rng) | ||
| this.B <- this.GenerateMatrix(this.SizeB, this.DensityB, rng) | ||
|
|
||
| [<Benchmark>] | ||
| member this.Kronecker() = | ||
| match Matrix.kroneckerProduct this.A this.B (fun a b -> Some(a * b)) with | ||
| | Ok res -> res | ||
| | Error msg -> failwithf "Kronecker failed: %s" msg | ||
| |> ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| namespace QuadTree.Benchmarks.MatrixSlice | ||
|
|
||
| open System | ||
| open BenchmarkDotNet.Attributes | ||
| open BenchmarkDotNet.Configs | ||
| open BenchmarkDotNet.Jobs | ||
| open QuadTree.Benchmarks.Utils | ||
|
|
||
| type RealConfig() = | ||
| inherit ManualConfig() | ||
| do base.AddJob(Job.Default.WithWarmupCount(5).WithIterationCount(10)) |> ignore | ||
|
|
||
| [<Config(typeof<RealConfig>)>] | ||
| [<MemoryDiagnoser>] | ||
| type Benchmark() = | ||
|
|
||
| [<Params(1000, 2000, 3000, 4000, 5000, 6000, 7000)>] | ||
| member val Size = 0 with get, set | ||
|
|
||
| [<Params(0.001, 0.005, 0.01, 0.05, 0.1, 0.5)>] | ||
| member val Density = 0.0 with get, set | ||
|
|
||
| [<Params(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)>] | ||
| member val Seed = 0 with get, set | ||
|
|
||
| member val Matrix = Unchecked.defaultof<Matrix.SparseMatrix<double>> with get, set | ||
|
|
||
| member private this.GenerateMatrix(size: int, density: float, rng: Random) = | ||
| let coords = | ||
| [ for i in 0 .. size - 1 do | ||
| for j in 0 .. size - 1 do | ||
| if rng.NextDouble() < density then | ||
| let value = double (rng.Next(1, 4)) | ||
| yield (uint64 i * 1UL<Matrix.rowindex>, uint64 j * 1UL<Matrix.colindex>, value) ] | ||
|
|
||
| match | ||
| Matrix.fromCoordinateList ( | ||
| Matrix.CoordinateList(uint64 size * 1UL<Matrix.nrows>, uint64 size * 1UL<Matrix.ncols>, coords) | ||
| ) | ||
| with | ||
| | Ok m -> m | ||
| | Error msg -> failwithf "Failed to create matrix: %s" msg | ||
|
|
||
| [<GlobalSetup>] | ||
| member this.Setup() = | ||
| let rng = Random(this.Seed) | ||
| this.Matrix <- this.GenerateMatrix(this.Size, this.Density, rng) | ||
|
|
||
| member private this.SliceMiddle(m: Matrix.SparseMatrix<double>) = | ||
| let n = int m.nrows | ||
| let start = n / 4 | ||
| let last = 3 * n / 4 - 1 | ||
|
|
||
| match Matrix.slice m start last start last with | ||
| | Ok res -> res | ||
| | Error msg -> failwithf "Slice failed: %s" msg | ||
|
|
||
| [<Benchmark>] | ||
| member this.Slice() = this.SliceMiddle(this.Matrix) |> ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| namespace QuadTree.Benchmarks.MatrixSliceAlign | ||
|
|
||
| open System | ||
| open BenchmarkDotNet.Attributes | ||
| open QuadTree.Benchmarks.Utils | ||
| open Matrix | ||
| open QuadTree | ||
|
|
||
| [<Config(typeof<MyConfig>)>] | ||
| [<MemoryDiagnoser>] | ||
| type Benchmark() = | ||
|
|
||
| [<Params(4096)>] | ||
| member val Size = 0 with get, set | ||
|
|
||
| [<Params(0.001, 0.005, 0.01, 0.05, 0.1, 0.5)>] | ||
| member val Density = 0.0 with get, set | ||
|
|
||
| [<Params(0)>] | ||
| member val Seed = 0 with get, set | ||
|
|
||
| [<Params(2048)>] | ||
| member val SliceSize = 0 with get, set | ||
|
|
||
| [<Params(0, 512, 1024, 1536, 2048, 1)>] | ||
| member val StartOffset = 0 with get, set | ||
|
|
||
| member val Matrix = Unchecked.defaultof<Matrix.SparseMatrix<double>> with get, set | ||
|
|
||
| member private this.GenerateMatrix(size: int, density: float, rng: Random) = | ||
| let coords = | ||
| [ for i in 0 .. size - 1 do | ||
| for j in 0 .. size - 1 do | ||
| if rng.NextDouble() < density then | ||
| let value = double (rng.Next(1, 4)) | ||
| yield (uint64 i * 1UL<Matrix.rowindex>, uint64 j * 1UL<Matrix.colindex>, value) ] | ||
|
|
||
| match | ||
| Matrix.fromCoordinateList ( | ||
| Matrix.CoordinateList(uint64 size * 1UL<Matrix.nrows>, uint64 size * 1UL<Matrix.ncols>, coords) | ||
| ) | ||
| with | ||
| | Ok m -> m | ||
| | Error msg -> failwithf "Failed to create matrix: %s" msg | ||
|
|
||
| [<GlobalSetup>] | ||
| member this.Setup() = | ||
| let rng = Random(this.Seed) | ||
| this.Matrix <- this.GenerateMatrix(this.Size, this.Density, rng) | ||
|
|
||
| member private this.SliceWithOffset(m: Matrix.SparseMatrix<double>) = | ||
| let n = int m.nrows | ||
| let start = this.StartOffset | ||
| let last = start + this.SliceSize - 1 | ||
|
|
||
| if last >= n then | ||
| failwithf "Slice out of bounds: start=%d, last=%d, n=%d" start last n | ||
|
|
||
| match Matrix.slice m start last start last with | ||
| | Ok res -> res | ||
| | Error msg -> failwithf "Slice failed: %s" msg | ||
|
|
||
| [<Benchmark>] | ||
| member this.Slice() = | ||
| this.SliceWithOffset(this.Matrix) |> ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| namespace QuadTree.Benchmarks.ReduceComparison | ||
|
|
||
| open System | ||
| open System.IO | ||
| open BenchmarkDotNet.Attributes | ||
| open QuadTree.Benchmarks.Utils | ||
|
|
||
| [<Config(typeof<MyConfig>)>] | ||
| [<MemoryDiagnoser>] | ||
| type Benchmark() = | ||
|
|
||
| let add x y = | ||
| match x, y with | ||
| | Some a, Some b -> Some(a + b) | ||
| | Some a, None | ||
| | None, Some a -> Some a | ||
| | _ -> None | ||
|
|
||
| [<Params("bcsstk01", | ||
| "bcsstk02", | ||
| "bcsstk03", | ||
| "bcsstk04", | ||
| "bcsstk05", | ||
| "bcsstk06", | ||
| "bcsstk07", | ||
| "bcsstk08", | ||
| "bcsstk09", | ||
| "bcsstk10", | ||
| "bcsstk11", | ||
| "bcsstk12", | ||
| "bcsstk13", | ||
| "bcsstk14", | ||
| "bcsstk15", | ||
| "bcsstk16", | ||
| "bcsstk17", | ||
| "bcsstk18", | ||
| "bcsstk29", | ||
| "bcsstk30", | ||
| "bcsstk31", | ||
| "cavity01", | ||
| "cavity05", | ||
| "cavity10", | ||
| "mesh2e1", | ||
| "mesh3em5", | ||
| "pwt", | ||
| "shuttle_eddy", | ||
| "tandem_vtx", | ||
| "email-Eu-core")>] | ||
| member val MatrixName = "" with get, set | ||
|
|
||
| member val Matrix = Unchecked.defaultof<Matrix.SparseMatrix<double>> with get, set | ||
| member val Size = 0 with get, set | ||
| member val Density = 0.0 with get, set | ||
| member val IsSymmetric = false with get, set | ||
|
|
||
| member private this.CheckSymmetric(m: Matrix.SparseMatrix<double>) = | ||
| let coo = Matrix.toCoordinateList m | ||
| let dict = System.Collections.Generic.Dictionary<string, double>() | ||
|
|
||
| for (i, j, v) in coo.list do | ||
| let key = $"{uint64 i},{uint64 j}" | ||
| dict.[key] <- v | ||
|
|
||
| let mutable sym = true | ||
|
|
||
| for (i, j, v) in coo.list do | ||
| let key = $"{uint64 j},{uint64 i}" | ||
|
|
||
| match dict.TryGetValue(key) with | ||
| | true, v2 when v = v2 -> () | ||
| | _ -> sym <- false | ||
|
|
||
| sym | ||
|
|
||
| [<GlobalSetup>] | ||
| member this.Setup() = | ||
| let rec findProjectRoot (dir: string) = | ||
| if Directory.Exists(Path.Combine(dir, "data")) then | ||
| dir | ||
| else | ||
| let parent = Directory.GetParent(dir) | ||
|
|
||
| if parent = null then | ||
| failwith "Project root not found (data directory is missing)" | ||
| else | ||
| findProjectRoot parent.FullName | ||
|
|
||
| let projectRoot = findProjectRoot __SOURCE_DIRECTORY__ | ||
|
|
||
| let path = | ||
| Path.Combine(projectRoot, "data", this.MatrixName, $"{this.MatrixName}.mtx") | ||
|
|
||
| if not (File.Exists path) then | ||
| failwithf "File not found: %s\nSearched in: %s" path projectRoot | ||
|
|
||
| match QuadTree.Benchmarks.Utils.readMtx path false with | ||
| | Ok m -> | ||
| this.Matrix <- m | ||
| this.Size <- int m.nrows | ||
| this.Density <- float m.nvals / (float m.nrows * float m.ncols) | ||
| this.IsSymmetric <- this.CheckSymmetric(m) | ||
| | Error msg -> failwithf "Failed to load %s: %s" this.MatrixName msg | ||
|
|
||
| [<Benchmark>] | ||
| member this.ReduceCols_Original() = Matrix.reduceCols add this.Matrix | ||
|
|
||
| [<Benchmark>] | ||
| member this.ReduceCols_ViaTranspose() = | ||
| let transposed = Matrix.transpose this.Matrix | ||
| Matrix.reduceRows add transposed | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.