Repository navigation
Conversation
Implement: - Vector.filter / Matrix.filter - Vector.exists / Vector.forall (short-circuit || / &&) - Matrix.exists / Matrix.forall (short-circuit || / &&) Tests (64 total): - Vector.filter: 9 - Vector.exists: 12 - Vector.forall: 12 - Matrix.filter: 9 - Matrix.exists: 11 - Matrix.forall: 11 Benchmarks: - Filters.fs: Vector/Matrix filter (dense + sparse), N=64,256,4096 - Exists.fs: Vector/Matrix exists (dense + sparse), N=64,256,4096 - Forall.fs: Vector/Matrix forall (dense + sparse), N=64,256,4096 - Register in BenchmarkSwitcher and .fsproj
|
Правда ли, что то, что Вы сделали, не выражается через map тривиальным образом, |
filter выразить можно, но это было одной из моих задач в проекте |
… test suite (188 tests)
| ) | ||
| | Error e -> failwithf "unexpected error %A" e | ||
|
|
||
| [<Fact>] |
There was a problem hiding this comment.
А чего ни одного Property-based теста?
| Assert.Equal(Ok(Some 11), get result 0UL<rowindex> 0UL<colindex>) | ||
| Assert.Equal(Ok(Some 121), get result 1UL<rowindex> 1UL<colindex>) | ||
|
|
||
| [<Fact>] |
| (Leaf(UserValue(res)), nnz) |> Ok | ||
| let get (matrix: SparseMatrix<'a>) (row: uint64<rowindex>) (col: uint64<colindex>) : Result<option<'a>, Error> = | ||
| if uint64 row >= uint64 matrix.nrows || uint64 col >= uint64 matrix.ncols then | ||
| Error Error.InvalidElementIndex |
There was a problem hiding this comment.
Посмотрите, как обычно называется такая ситуация в .NET
| | LeftValuesOnlyIndexed of (uint64<rowindex> -> uint64<colindex> -> 'a -> Option<'b> -> Option<'c>) | ||
|
|
||
| let private applyBinary | ||
| (op: BinaryOp<'a, 'b, 'c>) |
There was a problem hiding this comment.
А нельзя ли всё это дело как-то не копировать?
…ds access, deduplicate applyBinary
…COO to COOArray - COOArray: walk the sorted array with a cursor in full-cell cooMap/cooMapi paths and buffer results in ResizeArray instead of building a lookup Map; rewrite mergeBinary as a two-pointer merge over sorted arrays - COOArray/COOList: strengthen mxmcoo optimization detection by probing all distinct values rather than only the first entry - COOList: replace Map-based lookup in full-cell cooMap/cooMap2 with a pointer walk over the sorted list - Tests: add FsCheck property tests for mxmcoo against a naive reference and cross-checks between the array and list implementations - Benchmark: add list-backed get/set cases (COOLIST_get/set, resultListVal) to Format, DenseFormat and RealMatrix benchmarks - Rename module COO to COOArray for consistency with COOList: file rename, fsproj entries, open statements, test module, and Fantomas formatting
890008d to
4631871
Compare
|
|
||
| [<Benchmark(Description = "Dense_COO_mxm")>] | ||
| member this.DenseCooMxm() = | ||
| let op_add x y = |
There was a problem hiding this comment.
А можно не делать миллион копий одинаковых функций? Это уже не первое дублирование кода. Проверьте весь код на аккуртаность.
gsvgit
left a comment
There was a problem hiding this comment.
Перечитайте ВЕСЬ код. У Вас дубликатов море. И заодно порешайте концликты и коммиты подпишите.
gsvgit
left a comment
There was a problem hiding this comment.
Всё ещё тонны дублирующегося кода.
| let nrows = uint64 coo.nrows * 1UL<rowindex> | ||
| let ncols = uint64 coo.ncols * 1UL<colindex> | ||
|
|
||
| let cooGetThrows = |
There was a problem hiding this comment.
I hope, there is a conventional way to check whether method throws particular exception.
| let toArray<'T> isArray (m: obj) : COOEntry<'T> array = | ||
| let listProp = m.GetType().GetProperty("list") | ||
|
|
||
| if listProp <> null then |
| else | ||
| Result.map box (COOList.cooMap2iValues (unbox m1) (unbox m2) f) | ||
|
|
||
| let cooMap2iLeftValues isArray (m1: obj) (m2: obj) f = |
…rt.Throws, reuse OptionMonoid - Replace untyped obj, box/unbox and runtime reflection in Formats test helper with strictly typed type COO<'T> = Array | List discriminated union. - Fix all 42 compiler warnings (FS0686, FS0064) in Tests.COOFormats.fs by adding explicit generic type parameters and equality constraints. - Replace manual try/with boilerplate in PropertyTests out-of-bounds test with idiomatic Assert.Throws<ArgumentOutOfRangeException>. - Remove duplicated local definitions of opAdd and opMul in PropertyTests.fs in favor of canonical OptionMonoid.op_add and OptionMonoid.op_mult.
|
поменял try ... with на идиоматичный в F# Assert.Throws |
|
|
||
| type Error = | ||
| | EdgesCalculationProblem of LinearAlgebra.Error | ||
| | CEdgesCalculationProblem of Vector.Error |
There was a problem hiding this comment.
But why? What the reason of such changes?
|
|
||
| type Error = | ||
| | NewFrontierCalculationProblem of LinearAlgebra.Error | ||
| | FrontierCalculationProblem of Vector.Error |
There was a problem hiding this comment.
But why? What the reason of such changes?
|
|
||
| let cooGet (coo: ArrayCOO<'a>, rowindex: uint64<rowindex>, colindex: uint64<colindex>) : Result<option<'a>, Error> = | ||
| if uint64 rowindex >= uint64 coo.nrows then | ||
| raise (System.ArgumentOutOfRangeException("rowindex", "Row index is outside the matrix bounds.")) |
|
|
||
| i <- i + 1UL | ||
|
|
||
| let cooGet (coo: ArrayCOO<'a>, rowindex: uint64<rowindex>, colindex: uint64<colindex>) : Result<option<'a>, Error> = |
| let private cooMapInner (coo: ArrayCOO<'a>) (op: UnaryOp<'a, 'b>) : ArrayCOO<'b> = | ||
| match op with | ||
| | UnaryOp.ValuesOnly f -> | ||
| let buf = ResizeArray<COOEntry<'b>>(coo.list.Length) |
| | UnaryOp.ValuesOnly f -> | ||
| let buf = ResizeArray<COOEntry<'b>>(coo.list.Length) | ||
|
|
||
| for (i, j, v) in coo.list do |
|
|
||
| let cooGet (coo: ListCOO<'a>, rowindex: uint64<rowindex>, colindex: uint64<colindex>) : Result<option<'a>, Error> = | ||
| if uint64 rowindex >= uint64 coo.nrows then | ||
| raise (System.ArgumentOutOfRangeException("rowindex", "Row index is outside the matrix bounds.")) |
| (pr + halfSize * 1UL<rowindex>, pc), // SOUTH WEST | ||
| (pr + halfSize * 1UL<rowindex>, pc + halfSize * 1UL<colindex>) // SOUTH EAST | ||
| [<Struct>] | ||
| type ArrayCOO<'value> = |
…es, ResizeArray and loops
…ies field, and Option.isNone
- Matrix: return Error.InconsistentSizeOfArguments in get and set instead of raising ArgumentOutOfRangeException - COOArray: use array instead of seq in constructors/SortEntries, clone before sort, check op_add None None in canOptimize - COOList: remove unused range function, check op_add None None in canOptimize - Tests: update get/set test assertions to expect Error and add mxmcoo semiring fallback test
…yCOO and ListCOO - In ArrayCOO: added bounds validation, stable deduplication (last occurrence wins), and TryCreate returning Result<_, Error>. - In ListCOO: added sorting, deduplication, and bounds validation on construction, preventing silent None misses in findEntry. - Internal operations now construct via CreatePresorted with DEBUG assertions. - Added comprehensive unit tests in Tests.COOFormats.fs.
…, and optimize COO formats - Normalize in-bounds Dummy leaves to UserValue None in mapInner and map2Inner - Check storage.size equality before quadtree traversal in map2Inner - Add Int32 overflow guard before dense materialization in COOArray.cooMap2 - Replace entryComparer and Unchecked.defaultof with pure tail-recursive binary search in COOArray - Deduplicate array truncation logic and remove unused m1ByRow in COOList - Restrict CreatePresorted accessibility to internal in ArrayCOO and ListCOO - Add regression tests for overflow checks, storage size mismatches, and Dummy padding
…e comparison and monoid validation - Add compareCoords, entryCoordCompare, isAddNeutral and canMergeOpAdd helpers to Common.fs - Deduplicate cooMapInner and cooMap2Inner dense traversals using advanceCursor and runDense in COOList and COOArray - Unify coordinate comparisons across all sorting and search functions - Unify leaf nnz calculation in Matrix.fs with leafNnz helper and remove unreachable pattern FS0026
…low safety, and hot-path allocations - Align map2Inner Dummy handling with mapInner: handle boundary-spanning quadrants via recursive splitting and correct leafNnz calculation - Guard against Int32 overflow in COOArray.cooMapInner and COOList.cooMap2Inner on large dense operations - Add m2.nrows overflow check to COOArray.mxmcoo canOptimize - Unbox coordinates in COOList.mxmcoo reduceAdjacent to eliminate hot-path tuple allocations - Deduplicate applyBinary emission in mergeBinary across COOList and COOArray - Simplify delta calculation in Matrix.set and remove dead code
…nchmark accumulator
|
У большинства операций скорость не просела, даже увеличилась прикрепляю замеры |
gsvgit
left a comment
There was a problem hiding this comment.
За счёт чего производительность улучшилась?
|
|
||
| type Error = | ||
| | NewFrontierCalculationProblem of LinearAlgebra.Error | ||
| | FrontierCalculationProblem of Vector.Error |
There was a problem hiding this comment.
Зачем убрали специфичность ошибки? Причём везде. Тип ошибки позволяет понять, где она произошла.
|
Кстати, а чего отчёт не обновили? |
|
обновил локально, сейчас открою PR |
убрал ResizeArray заменив быстрым предподсчётом и аллокацией памяти 1 раз в начале |
- Restore domain-specific Matrix.Error, Vector.Error, and LinearAlgebra.Error - Restore diagnostic error contexts in BFS, SSSP, Boruvka, MST, and TriangleCount - Move checkBounds to Matrix.fs and remove generic Common.Error
gsvgit/1_year_practice_2026_reports#42 |
Implement:
Tests (64 total):
Benchmarks: