pub struct MatrixBuilder<T>(/* private fields */);Expand description
Fluent builder for two-dimensional matrices.
All methods are associated functions (no new() required), making them
trivially discoverable via IDE autocomplete when typing MatrixBuilder::.
§Type Parameter
T must be numeric. Common choices: f64, f32, i32, i64, u64.
§Examples
use scirs2_core::builders::MatrixBuilder;
// Identity matrix
let eye = MatrixBuilder::<f64>::eye(3);
assert_eq!(eye[[0, 0]], 1.0);
assert_eq!(eye[[0, 1]], 0.0);
// Zeros / ones
let z = MatrixBuilder::<f64>::zeros(2, 3);
let o = MatrixBuilder::<f64>::ones(2, 3);
// From closure — computed element-by-element
let computed = MatrixBuilder::from_fn(3, 3, |r, c| (r * 3 + c) as f64);
assert_eq!(computed[[1, 2]], 5.0);Implementations§
Source§impl<T> MatrixBuilder<T>
impl<T> MatrixBuilder<T>
Sourcepub fn zeros(rows: usize, cols: usize) -> Array2<T>
pub fn zeros(rows: usize, cols: usize) -> Array2<T>
Create a matrix of all zeros with shape (rows, cols).
use scirs2_core::builders::MatrixBuilder;
let m = MatrixBuilder::<f64>::zeros(3, 4);
assert_eq!(m.shape(), &[3, 4]);
assert_eq!(m[[0, 0]], 0.0);Sourcepub fn from_vec(data: Vec<T>, rows: usize, cols: usize) -> CoreResult<Array2<T>>
pub fn from_vec(data: Vec<T>, rows: usize, cols: usize) -> CoreResult<Array2<T>>
Build a matrix from a flat Vec of elements in row-major order.
Returns an error if the number of elements does not match rows * cols.
use scirs2_core::builders::MatrixBuilder;
let m = MatrixBuilder::from_vec(vec![1.0f64, 2.0, 3.0, 4.0], 2, 2)
.expect("element count matches");
assert_eq!(m[[0, 0]], 1.0);
assert_eq!(m[[1, 1]], 4.0);Source§impl<T> MatrixBuilder<T>
impl<T> MatrixBuilder<T>
Source§impl<T> MatrixBuilder<T>where
T: Clone,
impl<T> MatrixBuilder<T>where
T: Clone,
Sourcepub fn full(rows: usize, cols: usize, value: T) -> Array2<T>
pub fn full(rows: usize, cols: usize, value: T) -> Array2<T>
Create a matrix filled with a single constant value.
use scirs2_core::builders::MatrixBuilder;
let m = MatrixBuilder::full(3, 3, 7_i32);
assert_eq!(m[[0, 0]], 7);
assert_eq!(m[[2, 2]], 7);Sourcepub fn from_fn<F>(rows: usize, cols: usize, f: F) -> Array2<T>
pub fn from_fn<F>(rows: usize, cols: usize, f: F) -> Array2<T>
Create a matrix where each element is produced by calling f(row, col).
use scirs2_core::builders::MatrixBuilder;
let m = MatrixBuilder::from_fn(3, 3, |r, c| (r * 3 + c) as f64);
assert_eq!(m[[0, 0]], 0.0);
assert_eq!(m[[2, 2]], 8.0);Source§impl<T> MatrixBuilder<T>
impl<T> MatrixBuilder<T>
Sourcepub fn rand(rows: usize, cols: usize, seed: u64) -> Array2<T>
pub fn rand(rows: usize, cols: usize, seed: u64) -> Array2<T>
Create a matrix populated with uniform random values in [0, 1) using a seeded
ChaCha8 RNG for reproducibility.
The seed parameter lets callers produce deterministic results in tests
and benchmarks while still getting varied values in production by passing
different seeds.
use scirs2_core::builders::MatrixBuilder;
let m = MatrixBuilder::<f64>::rand(3, 3, 42);
assert_eq!(m.shape(), &[3, 3]);
// All values should be in [0, 1)
assert!(m.iter().all(|&v| v >= 0.0 && v < 1.0));Auto Trait Implementations§
impl<T> Freeze for MatrixBuilder<T>
impl<T> RefUnwindSafe for MatrixBuilder<T>where
T: RefUnwindSafe,
impl<T> Send for MatrixBuilder<T>where
T: Send,
impl<T> Sync for MatrixBuilder<T>where
T: Sync,
impl<T> Unpin for MatrixBuilder<T>where
T: Unpin,
impl<T> UnsafeUnpin for MatrixBuilder<T>
impl<T> UnwindSafe for MatrixBuilder<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T> StrictAs for T
impl<T> StrictAs for T
Source§fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
Source§impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
Source§fn strict_cast_from(src: Src) -> Dst
fn strict_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.