-
Notifications
You must be signed in to change notification settings - Fork 5
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
Open
Brulevich-Nikita
wants to merge
20
commits into
Lamagraph:main
Choose a base branch
from
Brulevich-Nikita:brulevich-n-work
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
182b0c4
Compilable version of Maggs-Plotkin MST.
gsvgit 6ac040e
Tests on Maggs-Plotkin MST.
gsvgit 588f407
Formatted
gsvgit ac44fe0
Maggs-Plotkin: handle edges with identical weights correctly.
gsvgit 8bcd91a
MST tests fixed. In progress.
gsvgit 86b2e89
Simple test on Boruvka to investigate what goes wrong.
gsvgit 1937a67
Fixed cycles in Boruvka MST
gsvgit 0243914
Added information about Maggs-Plotkin MSF.
gsvgit 069d6b9
First vrsion of parent BFS.
gsvgit a8f2a7a
Fixed vxmi.
gsvgit 98aa4b2
More tests on BFS.
gsvgit 1b6479e
Added Parent-BFS
gsvgit a09b299
Formatted.
gsvgit 43047ed
add slice in Vector.fs and Matrix.fs, add reduceRows and reduceCols i…
Brulevich-Nikita f62ef2f
add Kronecker product to Matrix.fs with tests, fix tests, duplicate h…
Brulevich-Nikita a8c2df2
fix: returned failwith to benchmarks, fix SSSP, LinearAlgebra, MST, B…
Brulevich-Nikita 5feffed
add Benchmarks, their results, fix: slice logic
Brulevich-Nikita 54a24ad
refactor benchmarks
Brulevich-Nikita fbf3454
add fantomas to refactored benchmarks
Brulevich-Nikita c5f8bcb
refactor: Vector and Matrix functions and Benchmarks
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(100, 150)>] | ||
| member val SizeA = 0 with get, set | ||
|
|
||
| [<Params(100, 150, 200)>] | ||
| 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)>] | ||
| 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
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("g7jac010sc", | ||
| "g7jac020", | ||
| "g7jac020sc", | ||
| "g7jac040", | ||
| "g7jac040sc", | ||
| "g7jac050sc", | ||
| "g7jac060", | ||
| "g7jac060sc", | ||
| "g7jac080", | ||
| "g7jac100", | ||
| "g7jac100sc", | ||
| "g7jac120", | ||
| "g7jac120sc", | ||
| "g7jac140", | ||
| "g7jac140sc", | ||
| "g7jac160", | ||
| "jan99jac020", | ||
| "jan99jac020sc", | ||
| "mark3jac020", | ||
| "mark3jac020sc", | ||
| "mesh2e1", | ||
| "mesh3em5", | ||
| "pwt", | ||
| "shuttle_eddy", | ||
| "tandem_vtx", | ||
| "bcsstk01", | ||
| "cavity01", | ||
| "cavity05", | ||
| "cavity10", | ||
| "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 "Не найден корень проекта (папка data)" | ||
| else | ||
| findProjectRoot parent.FullName | ||
|
|
||
| let projectRoot = findProjectRoot __SOURCE_DIRECTORY__ | ||
|
|
||
| let path = | ||
| Path.Combine(projectRoot, "data", "Reduce_matrices", $"{this.MatrixName}.mtx") | ||
|
|
||
| if not (File.Exists path) then | ||
| failwithf "Файл не найден: %s\nИщем в: %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 "Не удалось загрузить %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
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,54 @@ | ||
| namespace QuadTree.Benchmarks.VectorSlice | ||
|
|
||
| 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(1000000, 2000000, 2500000, 4000000, 5000000, 7500000)>] | ||
| member val Size = 0 with get, set | ||
|
|
||
| [<Params(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 Vector = Unchecked.defaultof<Vector.SparseVector<double>> with get, set | ||
|
|
||
| member private this.GenerateVector(size: int, density: float, rng: Random) = | ||
| let coords = | ||
| [ for i in 0 .. size - 1 do | ||
| if rng.NextDouble() < density then | ||
| let value = double (rng.Next(1, 4)) | ||
| yield (uint64 i * 1UL<Vector.index>, value) ] | ||
|
|
||
| match Vector.fromCoordinateList (Vector.CoordinateList(uint64 size * 1UL<Vector.dataLength>, coords)) with | ||
| | Ok v -> v | ||
| | Error msg -> failwithf "Failed to create vector: %s" msg | ||
|
|
||
| [<GlobalSetup>] | ||
| member this.Setup() = | ||
| let rng = Random(this.Seed) | ||
| this.Vector <- this.GenerateVector(this.Size, this.Density, rng) | ||
|
|
||
| member private this.SliceMiddle(v: Vector.SparseVector<double>) = | ||
| let n = int v.length | ||
| let start = n / 4 | ||
| let last = 3 * n / 4 - 1 | ||
|
|
||
| match Vector.slice start last v with | ||
| | Ok res -> res | ||
| | Error msg -> failwithf "Slice failed: %s" msg | ||
|
|
||
| [<Benchmark>] | ||
| member this.Slice() = this.SliceMiddle(this.Vector) |> 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну и так про все бенчи. Тут уже лучше ронять, чтобы было видно, что что-то пошло не так.