@immut.Vector
API baseline for @immut.Vector in the current 0.4.7 repository state.
Overview
@immut.Vectoris the repository's value-oriented vector type.- The public type is also exported under the package alias
VecLib[T]. - Storage is backed by the immutable core vector alias
VecCore[T]. - Operations such as
set,map,left_scale, andright_scalealways return a new vector. - The package does not expose in-place updates or a dot-product helper.
Core API
Vector::from_array(arr)Builds a vector from a mutableArray[T].Vector::make(n, elem)/Vector::makei(n, f)Create a constant vector or generate one from indices.length()Returns the vector length.v[i]Reads one element. Bounds follow the underlying immutable vector contract.set(i, x)Returns a new vector with one replaced element.iter()Exposes an iterator over the elements in order.
Value Transforms
map(f)/zip_with(other, f)Return transformed vectors without mutating the original.add_constant(cst)Adds the same scalar to every element.left_scale(scalar)/right_scale(scalar)Apply scalar multiplication and return a new vector.lerp(other, alpha)Computes(1 - alpha) * self + alpha * other.+,*, unary-Element-wise addition, Hadamard multiplication, and negation.lin_comb(scalar_a, self, scalar_b, other)Top-level helper for a two-vector linear combination.
Length mismatches for shared element-wise operations follow the underlying vector contract and abort.
Matrix Conversions
to_col_matrix()/to_row_matrix()Materialize the vector as ann x 1or1 x nmatrix.scaled_matrix()Builds a diagonal matrix with the vector on the main diagonal.tensor_product(other)Computes the outer product and returns a matrix.
Guidance
- Use
@immut.Vectorwhen downstream code benefits from explicit value semantics. - Use
@mutable.Vectorinstead when you need in-place updates or the publicdot()helper. backends/default.ImmutableDenseVectoris a wrapper around this concrete implementation. If you want the trait-oriented default backend entry point, see thebackends/defaultAPI.