Copying container conversions and dtype casts.
More...
Go to the source code of this file.
Copying container conversions and dtype casts.
Definition in file Conversion.hpp.
◆ astype()
Casts every element of a Stratax array to another dtype.
The result preserves the source container category and shape while replacing its element type with To. Each element is converted with static_cast<To>, so the standard C++ rules for narrowing, truncation, signedness conversion, boolean conversion, and precision loss apply.
The returned array owns storage independent of arr.
- Template Parameters
-
| To | Destination Stratax dtype for which static_cast from each source value is valid. |
| A | Owning Stratax array with a RebindArray specialization. |
- Parameters
-
| arr | Array whose elements are converted. |
- Returns
- Owning array with the same container category and shape as
arr, with element type To.
- Exceptions
-
- Complexity
- O(arr.size() + arr.rank()).
Definition at line 248 of file Conversion.hpp.
◆ is_matrix_shape()
Determines whether a shape can be represented by a Matrix.
Every rank-two shape is accepted. Shapes of any other rank are accepted only when exactly two dimensions are different from one. Only dimensions of size one are removed; zero extents are retained.
- Parameters
-
- Returns
true when shape is matrix-compatible; otherwise false.
- Complexity
- O(shape.rank()).
Definition at line 66 of file Conversion.hpp.
◆ is_vector_shape()
Determines whether a shape can be represented by a Vector.
Every rank-one shape is accepted. Higher-rank shapes are accepted only when exactly one dimension is different from one. Only dimensions of size one are removed; zero extents are retained.
- Parameters
-
- Returns
true when shape is vector-compatible; otherwise false.
- Complexity
- O(shape.rank()).
Definition at line 34 of file Conversion.hpp.
◆ matrix_shape()
Produces the rank-two shape used by a matrix conversion.
Rank-two shapes are returned unchanged. For other ranks, dimensions different from one are retained in their original order while singleton dimensions are removed. Callers must first establish matrix compatibility with is_matrix_shape().
- Parameters
-
| shape | Matrix-compatible source shape. |
- Returns
- Two-dimensional shape used by the resulting Matrix.
- Exceptions
-
| std::bad_alloc | If storage for the filtered dimensions cannot be allocated. |
- Complexity
- O(shape.rank()).
Definition at line 100 of file Conversion.hpp.
◆ to_matrix()
Copies a matrix-compatible Stratax array into a Matrix.
Rank-two sources retain their shape. For other ranks, singleton dimensions are removed and the two remaining non-singleton dimensions form the result shape. Values retain flat row-major iterator order, and the result owns independent storage.
- Template Parameters
-
| A | Stratax array type satisfying Array. |
- Parameters
-
| arr | Source array to convert. |
- Returns
- Owning Matrix with the same value type as
arr.
- Exceptions
-
- Complexity
- O(arr.size() + arr.rank()) for owning arrays; O((arr.size() + 1) * arr.rank()) for views.
Definition at line 177 of file Conversion.hpp.
◆ to_tensor()
Copies a Stratax array into a Tensor of the same shape.
Values retain flat row-major iterator order. The returned tensor preserves the source shape exactly and owns storage independent of arr.
- Template Parameters
-
| A | Stratax array type satisfying Array. |
- Parameters
-
| arr | Source array to convert. |
- Returns
- Owning Tensor with the same value type, shape, and values as
arr.
- Exceptions
-
- Complexity
- O(arr.size() + arr.rank()) for owning arrays; O((arr.size() + 1) * arr.rank()) for views.
Definition at line 214 of file Conversion.hpp.
◆ to_vector()
Copies a vector-compatible Stratax array into a Vector.
The result contains the source elements in flat row-major iterator order and owns storage independent of arr. Rank-one sources are always compatible; other ranks must contain exactly one dimension different from one.
- Template Parameters
-
| A | Stratax array type satisfying Array. |
- Parameters
-
| arr | Source array to convert. |
- Returns
- Owning Vector with the same value type and element count as
arr.
- Exceptions
-
- Complexity
- O(arr.size() + arr.rank()) for owning arrays; O((arr.size() + 1) * arr.rank()) for views.
Definition at line 140 of file Conversion.hpp.