Skip to content

feat: add Coordinate List (COO) sparse matrix with get/map/mapi/set/mxm - #20

Open
narysh wants to merge 14 commits into
Lamagraph:mainfrom
narysh:narysev-work
Open

narysh wants to merge 14 commits into
Lamagraph:mainfrom
narysh:narysev-work

Conversation

@narysh

@narysh narysh commented Jun 12, 2026

Copy link
Copy Markdown

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

narysh added 2 commits June 12, 2026 22:04
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
@gsvgit

gsvgit commented Jun 13, 2026

Copy link
Copy Markdown
Member

Правда ли, что то, что Вы сделали, не выражается через map тривиальным образом,

@narysh

narysh commented Jun 13, 2026

Copy link
Copy Markdown
Author

Правда ли, что то, что вы сделали, нельзя выразить через map тривиальным образом?

filter выразить можно, но это было одной из моих задач в проекте
forall и exists можно выразить через аналог fold, но тогда он пройдёт всё дерево, а forall и exists это оптимизируют и полный обход случится, только в худшем случае.
Я понимаю, что этого мало. Остальные задачи, которые у меня были изначально, вы уже реализовали, может вы можете тогда подсказать другие функции, которые нужно реализовать?

@narysh narysh changed the title feat(quadtree): add filter, exists, forall with tests and benchmarks feat: add Coordinate List (COO) sparse matrix with get/map/mapi/set/mxm Sep 17, 2026
)
| Error e -> failwithf "unexpected error %A" e

[<Fact>]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А чего ни одного 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>]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И тут property не проверяете.

Comment thread QuadTree/Matrix.fs Outdated
(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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Посмотрите, как обычно называется такая ситуация в .NET

Comment thread QuadTree/Matrix.fs
| LeftValuesOnlyIndexed of (uint64<rowindex> -> uint64<colindex> -> 'a -> Option<'b> -> Option<'c>)

let private applyBinary
(op: BinaryOp<'a, 'b, 'c>)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А нельзя ли всё это дело как-то не копировать?

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants