|
Stratax 0.3.1
|
Concise reference for the public Python API exported from stratax.
Python containers currently expose double-based storage. Slicing, reshaping, flattening, and conversions return independent containers.
| API | Description |
|---|---|
Shape() | Create an empty shape. |
Shape(other) | Copy another Shape. |
Shape([d0, d1, ...]) | Create a shape from dimensions. |
shape.rank | Number of dimensions. |
shape.elements | Product of all dimensions. |
shape.empty | Whether the shape has rank 0. |
len(shape) | Number of dimensions. |
shape[i] | Dimension at index i. |
list(shape) | Dimensions as a Python list. |
Vector, Matrix, and Tensor share the same basic container operations.
| API | Vector | Matrix | Tensor |
|---|---|---|---|
| Empty constructor | Vector() | Matrix() | Tensor() |
| Copy constructor | Vector(v) | Matrix(m) | Tensor(t) |
| Shape constructor | Vector(Shape([n])) | Matrix(Shape([r, c])) | Tensor(Shape([...])) |
| Filled constructor | Vector(n, value) | Matrix(r, c, value) | Tensor(shape, value) |
| Iterable constructor | Vector([...]) | Matrix([[...]]) | Tensor([...]) |
| Size | .size | .size | .size |
| Rank | .rank | .rank | .rank |
| Empty check | .empty | .empty | .empty |
| Shape | .shape | .shape | .shape |
| Row-major strides | .strides | .strides | .strides |
| Fill | .fill(value) | .fill(value) | .fill(value) |
| Convert to lists | .tolist() | .tolist() | .tolist() |
Tensor.tolist() returns nested Python lists matching the tensor shape rather than flattening values into storage order. Boolean tensor masks follow the same rule. | Reshape | .reshape(shape) | .reshape(shape) | .reshape(shape) | | Flatten | .flatten() | .flatten() | .flatten() |
Matrix also exposes .rows and .cols.
Negative indexes and slice steps are supported. Slice results are independent copies.
Containers support element-wise arithmetic with matching containers or scalars:
| Operation | Methods |
|---|---|
| Addition | a + b, a += b |
| Subtraction | a - b, a -= b |
| Multiplication | a * b, a *= b |
| Division | a / b, a /= b |
| Unary | +a, -a |
| Comparison | a == b, a != b, a < b, a <= b, a > b, a >= b |
Container-to-container arithmetic uses NumPy-style trailing-dimension broadcasting. Corresponding dimensions must be equal or one of them must be 1; incompatible shapes raise BroadcastError. Comparisons are element-wise, support broadcasting and scalars, and return BoolVector, BoolMatrix, or BoolTensor.
Each comparison is also available as a module-level named function: equal, not_equal, less, less_equal, greater, and greater_equal. These functions accept arrays or scalars in either operand order.
| Function | Description |
|---|---|
zeros(shape) / zeros(size) / zeros(rows, cols) | Zero-filled Tensor, Vector, or Matrix. |
ones(shape) / ones(size) / ones(rows, cols) | One-filled Tensor, Vector, or Matrix. |
full(shape, value) / full(size, value) / full(rows, cols, value) | Constant-filled Tensor, Vector, or Matrix. |
identity(size) | Identity Matrix with shape [size, size]. |
Passing a Shape creates a Tensor, one integer size creates a Vector, and two integer dimensions create a Matrix.
| Function | Description |
|---|---|
to_vector(arr) | Convert a compatible Vector, Matrix, or Tensor to Vector. |
to_matrix(arr) | Convert a compatible Vector, Matrix, or Tensor to Matrix. |
to_tensor(arr) | Convert a Vector, Matrix, or Tensor to Tensor. |
Conversions return new containers.
| Function | Result without axis | Result with axis |
|---|---|---|
sum(arr) / sum(arr, axis, keepdims=False) | float | Tensor |
prod(arr) / prod(arr, axis, keepdims=False) | float | Tensor |
max(arr) / max(arr, axis, keepdims=False) | float | Tensor |
min(arr) / min(arr, axis, keepdims=False) | float | Tensor |
argmax(arr) / argmax(arr, axis, keepdims=False) | int | Tensor |
argmin(arr) / argmin(arr, axis, keepdims=False) | int | Tensor |
mean(arr) / mean(arr, axis, keepdims=False) | float | Tensor |
var(arr) / var(arr, axis, keepdims=False) | float | Tensor |
std(arr) / std(arr, axis, keepdims=False) | float | Tensor |
Axes may be negative. keepdims=True preserves the reduced axis with length 1.
Stratax exports these exception types:
| Exception | Typical use |
|---|---|
StrataxError | Base exception for Stratax errors. |
ShapeError | Invalid or incompatible shape. |
DimensionError | Invalid dimension count. |
IndexError | Out-of-range index. |
TypeError | Unsupported argument type. |
BroadcastError | Reserved for broadcasting-related shape failures. |
ZeroDivisionError | Division by zero. |