Skip to content

Comments

Add tensor#120

Merged
jsallay merged 41 commits intognuradio:mainfrom
jsallay:add-tensor
Sep 9, 2025
Merged

Add tensor#120
jsallay merged 41 commits intognuradio:mainfrom
jsallay:add-tensor

Conversation

@jsallay
Copy link
Collaborator

@jsallay jsallay commented Sep 9, 2025

No description provided.

jsallay and others added 30 commits November 28, 2022 21:00
Some aspects of flatbuffers are really slow (like construction) and we
weren't really using flatbuffers in the way that they were intended
anyway.

This is a complete rewrite of the PMTs using std::variants.  The code is
much simpler and the performance is better (and in some cases an order
of magnitude better).

The code now requires c++20 as well.

Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: Josh Morman <jmorman@gnuradio.org>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: Josh Morman <jmorman@gnuradio.org>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
 * switch to C++23 (README, meson cpp_std=c++23; default werror=false).

 * Tensor<T> expansion:
   * PMR-backed storage for extents and data; optional MR in ctors/ops.
   * disambiguation for std::size_t ranges via tags: extents_from / data_from.
   * ctors: extents+data ranges, init-lists, count+value, iterator pairs, std::vector/std::pmr::vector; CTAD guides.
   * safe size computation with overflow detection; zero-extent dims → total size 0.
   * row-major indexing helpers: unchecked operator[](...) (variadic), checked at(...) (variadic/span), index_of(...), bounds_check(...).
  * std::vector-like API: capacity/reserve/shrink_to_fit/clear/push_back/emplace_back/pop_back/front/back/assign/fill/swap.
  * conversions and comparisons with std::vector/std::pmr::vector; <=> implemented.
  * shape ops: resize(...), resize_dim(dim, n), reshape(...); strides() (row-major).
  * std::mdspan if available (TENSOR_HAVE_MDSPAN), otherwise a lightweight view (data/extents/strides).
  * minor code/warning clean-ups

 Note:
  * drops Tensor1d tag; use data_from for 1-D construction (or pass a vector), and extents_from to force shape.
  * push_back on multi-dim tensors flattens to 1-D by design.

Signed-off-by: rstein <r.steinhagen@gsi.de>
... static-storage specialisation, PMR clean-ups, test expansion

* Make `Tensor<ElementType, Ex...>` constexpr/consteval friendly:

  * Static extents: zero-overhead layout using `std::array<T, product(Ex...)>` and a zero-sized `no_extents_t`.
  * Dynamic / semi-static: PMR-backed `std::pmr::vector` for extents/data; allocator propagated across ctors/ops.
  * Add `rank()`/`size()` `consteval` for static tensors; `extent<idx>()` `consteval`; `stride()`/`strides()` helpers.

* API polish / changes:

  * Unify indexing and access: `operator[](...)/at(...)` now support static and dynamic paths; `index_of(...)` constexpr.
  * Iterators/pointers use `std::to_address`; add `pointer` typedefs and `container_data()` helpers.
  * Rename `view()` → `to_mdspan()` (and matching lightweight View); drop `extentsSpan()`, provide `extents()` (span for dynamic, `std::array` for static).
  * Add `fill()` `constexpr`; guard mutating ops with `requires (!_all_static)` (`clear/reshape/resize_dim`).
  * Add static factory `identity()` (square, static tensors).
  * Equality now templated across `OtherT, OtherEx...` with structural checks.
  * CTAD guides for flat and nested init-lists, and `std::array`.

* Construction & conversion:

  * Rich set of ctors: extents range, data range, (extents,data), init-lists (flat/2D/3D), count+value, iterator pair, `std::vector`/`std::pmr::vector`.
  * Cross-type/cross-shape conversion ctors and assignments with dimension validation and allocator preservation.
  * Move from `pmr::vector` handles allocator mismatch via copy-move fallback.

* Tests: large suite uplift to exercise constexpr/static behaviour and error paths:

  * Static constexpr construction, size/rank/extents `static_assert`s; memory-layout checks.
  * Conversion/assignment (static↔dynamic, cross-type), self/chained assignment, PMR propagation.
  * Boundary/edge cases: high-rank, single-element, zero extents, indexing/stride corners, allocator failure, overflow detection.
  * Nested init-lists (2D/3D), iterator category checks.
  * Replace `view()` with `to_mdspan()` in tests; add small constexpr `det` for 2×2/3×3; use `<print>` for diagnostics.

Notes:

* Behavioural changes: `view()` renamed to `to_mdspan()`, `extentsSpan()` removed; some mutators unavailable for static tensors.
* ABI: fully static tensors are exactly the size of their element storage; dynamic/semi-static carry PMR state.

Signed-off-by: rstein <r.steinhagen@gsi.de>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
jsallay and others added 11 commits September 8, 2025 19:28
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
Signed-off-by: John Sallay <jasallay@gmail.com>
…tensor

Signed-off-by: John Sallay <jasallay@gmail.com>
@jsallay jsallay had a problem deploying to github-action-autobuild September 9, 2025 16:32 — with GitHub Actions Failure
@jsallay jsallay had a problem deploying to github-action-autobuild September 9, 2025 16:32 — with GitHub Actions Failure
@jsallay jsallay merged commit a420d46 into gnuradio:main Sep 9, 2025
1 of 3 checks passed
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.

3 participants