|
Stratax 0.4.0rc1
|
Header: include/stratax/algorithms/Creation.hpp.
Functions are available under stratax::creation. T must satisfy DType, which includes bool.
| Call | Owning result | Initialization |
|---|---|---|
zeros<T>(shape) / ones<T>(shape) | Tensor | T{} / T{1} |
zeros<T>(size) / ones<T>(size) | Vector | T{} / T{1} |
zeros<T>(rows, cols) / ones<T>(rows, cols) | Matrix | T{} / T{1} |
full<T>(shape, value) | Tensor | Copies value |
full<T>(size, value) | Vector | Copies value |
full<T>(rows, cols, value) | Matrix | Copies value |
identity<T>(size) | Matrix | Ones on diagonal, zeros elsewhere |
Shape overloads preserve all dimensions, including zero extents. Rank-zero Shape creates an empty Tensor. Identity has shape {size, size}; size zero produces an empty rank-two Matrix. All results own their storage.
Shape element/stride overflow raises Exceptions::DimensionError. Allocation can raise std::bad_alloc or std::bad_array_new_length for an unrepresentable storage byte count. Python dimensions are checked before unsigned conversion.
Initialization takes O(n + r) time and storage for n elements and rank r. Identity takes O(size squared) element work. Python offers the same overload selection for double containers; see Python API Reference.