Skip to main content

DataArray

Struct DataArray 

Source
pub struct DataArray<T: Scalar> { /* private fields */ }
Expand description

A contiguous array of tuples, where each tuple has num_components values.

This is the fundamental data container, analogous to VTK’s vtkDataArray. Uses Arc<Vec<T>> for zero-copy clone with copy-on-write semantics.

§Examples

use crate::data::DataArray;

// Create a 3-component array (e.g., for normals or positions)
let mut normals = DataArray::<f64>::new("Normals", 3);
normals.push_tuple(&[0.0, 0.0, 1.0]);
normals.push_tuple(&[0.0, 1.0, 0.0]);
assert_eq!(normals.num_tuples(), 2);

// Create from a Vec
let scalars = DataArray::<f64>::from_vec("Temperature", vec![10.0, 20.0, 30.0], 1);
assert_eq!(scalars.num_tuples(), 3);

Implementations§

Source§

impl<T: Scalar> DataArray<T>

Source

pub fn new(name: impl Into<String>, num_components: usize) -> Self

Source

pub fn from_vec( name: impl Into<String>, data: Vec<T>, num_components: usize, ) -> Self

Source

pub fn from_slice( name: impl Into<String>, data: &[T], num_components: usize, ) -> Self

Create from a borrowed slice (copies data).

Source

pub fn name(&self) -> &str

Source

pub fn set_name(&mut self, name: impl Into<String>)

Source

pub fn scalar_type(&self) -> ScalarType

Source

pub fn num_components(&self) -> usize

Source

pub fn num_tuples(&self) -> usize

Source

pub fn tuple(&self, idx: usize) -> &[T]

Source

pub fn tuple_mut(&mut self, idx: usize) -> &mut [T]

Source

pub fn push_tuple(&mut self, values: &[T])

Source

pub fn as_slice(&self) -> &[T]

Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Source

pub fn into_vec(self) -> Vec<T>

Source

pub fn is_empty(&self) -> bool

Source

pub fn from_fn( name: impl Into<String>, count: usize, f: impl Fn(usize) -> T, ) -> Self

Create a 1-component DataArray by evaluating a function for each index.

Source

pub fn from_fn_components( name: impl Into<String>, count: usize, num_components: usize, f: impl Fn(usize) -> Vec<T>, ) -> Self

Create a multi-component DataArray from a function returning a slice.

Source

pub fn filled( name: impl Into<String>, value: T, count: usize, num_components: usize, ) -> Self

Create a DataArray filled with a constant value.

Source

pub fn len(&self) -> usize

Number of total scalar values (tuples * components).

Source

pub fn map_in_place(&mut self, f: impl Fn(T) -> T)

Apply a function to each scalar value in-place.

Source

pub fn map(&self, name: impl Into<String>, f: impl Fn(T) -> T) -> Self

Create a new DataArray by mapping each scalar value.

Source

pub fn map_tuples( &self, name: impl Into<String>, f: impl Fn(&[T]) -> T, ) -> DataArray<T>

Create a new 1-component DataArray from a per-tuple function.

Source

pub fn clear(&mut self)

Source

pub fn is_shared(&self) -> bool

Returns true if this array shares storage with another clone.

Source

pub fn make_unique(&mut self)

Ensure exclusive ownership. Call before tight mutation loops to avoid per-call Arc::make_mut atomic checks.

Source

pub fn iter_tuples(&self) -> DataArrayTupleIter<'_, T>

Iterate over tuples as slices.

Source§

impl DataArray<f64>

Source

pub fn scale(&mut self, factor: f64)

Scale all values by a factor.

Source

pub fn normalize(&mut self) -> (f64, f64)

Normalize all values to [0, 1] range. Returns the original (min, max) range.

Source

pub fn min_value(&self) -> f64

Compute min value (first component only for multi-component).

Source

pub fn max_value(&self) -> f64

Compute max value (first component only for multi-component).

Source

pub fn magnitude(&self, name: impl Into<String>) -> DataArray<f64>

Compute magnitude for each tuple (Euclidean norm of components).

Source§

impl DataArray<f64>

Source

pub fn extract_component( &self, component: usize, name: impl Into<String>, ) -> DataArray<f64>

Extract a single component as a new 1-component array.

Source

pub fn concat(&self, other: &DataArray<f64>) -> DataArray<f64>

Concatenate two arrays with the same number of components.

Source

pub fn extend(&mut self, other: &DataArray<f64>)

Append another array’s tuples to this array.

Source

pub fn compose( name: impl Into<String>, components: &[&DataArray<f64>], ) -> DataArray<f64>

Create a new array by combining components from multiple 1-component arrays.

Source§

impl DataArray<f32>

Source

pub fn scale(&mut self, factor: f32)

Scale all values by a factor.

Trait Implementations§

Source§

impl<T: Scalar> Clone for DataArray<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Scalar> Debug for DataArray<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<DataArray<f32>> for AnyDataArray

Source§

fn from(a: DataArray<f32>) -> Self

Converts to this type from the input type.
Source§

impl From<DataArray<f64>> for AnyDataArray

Source§

fn from(a: DataArray<f64>) -> Self

Converts to this type from the input type.
Source§

impl From<DataArray<i16>> for AnyDataArray

Source§

fn from(a: DataArray<i16>) -> Self

Converts to this type from the input type.
Source§

impl From<DataArray<i32>> for AnyDataArray

Source§

fn from(a: DataArray<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<DataArray<i64>> for AnyDataArray

Source§

fn from(a: DataArray<i64>) -> Self

Converts to this type from the input type.
Source§

impl From<DataArray<i8>> for AnyDataArray

Source§

fn from(a: DataArray<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<DataArray<u16>> for AnyDataArray

Source§

fn from(a: DataArray<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<DataArray<u32>> for AnyDataArray

Source§

fn from(a: DataArray<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<DataArray<u64>> for AnyDataArray

Source§

fn from(a: DataArray<u64>) -> Self

Converts to this type from the input type.
Source§

impl From<DataArray<u8>> for AnyDataArray

Source§

fn from(a: DataArray<u8>) -> Self

Converts to this type from the input type.
Source§

impl<T: Scalar> Index<usize> for DataArray<T>

Index by tuple index, returns the tuple slice.

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, idx: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: Scalar> PartialEq for DataArray<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T> Freeze for DataArray<T>

§

impl<T> RefUnwindSafe for DataArray<T>
where T: RefUnwindSafe,

§

impl<T> Send for DataArray<T>

§

impl<T> Sync for DataArray<T>

§

impl<T> Unpin for DataArray<T>

§

impl<T> UnsafeUnpin for DataArray<T>

§

impl<T> UnwindSafe for DataArray<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.