Trait metatensor::Array

source ·
pub trait Array: Any + Send + Sync {
    // Required methods
    fn as_any(&self) -> &dyn Any;
    fn as_any_mut(&mut self) -> &mut dyn Any;
    fn create(&self, shape: &[usize]) -> Box<dyn Array>;
    fn copy(&self) -> Box<dyn Array>;
    fn data(&mut self) -> &mut [f64];
    fn shape(&self) -> &[usize];
    fn reshape(&mut self, shape: &[usize]);
    fn swap_axes(&mut self, axis_1: usize, axis_2: usize);
    fn move_samples_from(
        &mut self,
        input: &dyn Array,
        samples: &[mts_sample_mapping_t],
        properties: Range<usize>
    );
}
Expand description

The Array trait is used by metatensor to manage different kind of data array with a single API. Metatensor only knows about Box<dyn Array>, and manipulate the data through the functions on this trait.

This corresponds to the mts_array_t struct in metatensor-core.

Required Methods§

source

fn as_any(&self) -> &dyn Any

Get the array as a Any reference

source

fn as_any_mut(&mut self) -> &mut dyn Any

Get the array as a mutable Any reference

source

fn create(&self, shape: &[usize]) -> Box<dyn Array>

Create a new array with the same options as the current one (data type, data location, etc.) and the requested shape.

The new array should be filled with zeros.

source

fn copy(&self) -> Box<dyn Array>

Make a copy of this array

The new array is expected to have the same data origin and parameters (data type, data location, etc.)

source

fn data(&mut self) -> &mut [f64]

Get the underlying data storage as a contiguous slice

This function is allowed to panic if the data is not accessible in RAM, not stored as 64-bit floating point values, or not stored as a C-contiguous array.

source

fn shape(&self) -> &[usize]

Get the shape of the array

source

fn reshape(&mut self, shape: &[usize])

Change the shape of the array to the given shape

source

fn swap_axes(&mut self, axis_1: usize, axis_2: usize)

Swap the axes axis_1 and axis_2 in this array

source

fn move_samples_from( &mut self, input: &dyn Array, samples: &[mts_sample_mapping_t], properties: Range<usize> )

Set entries in self taking data from the input array.

The output array is guaranteed to be created by calling mts_array_t::create with one of the arrays in the same block or tensor map as the input.

The samples indicate where the data should be moved from input to output.

This function should copy data from input[sample.input, ..., :] to array[sample.output, ..., properties] for each sample in samples. All indexes are 0-based.

Implementations on Foreign Types§

source§

impl Array for ArrayD<f64>

source§

fn as_any(&self) -> &dyn Any

source§

fn as_any_mut(&mut self) -> &mut dyn Any

source§

fn create(&self, shape: &[usize]) -> Box<dyn Array>

source§

fn copy(&self) -> Box<dyn Array>

source§

fn data(&mut self) -> &mut [f64]

source§

fn shape(&self) -> &[usize]

source§

fn reshape(&mut self, shape: &[usize])

source§

fn swap_axes(&mut self, axis_1: usize, axis_2: usize)

source§

fn move_samples_from( &mut self, input: &dyn Array, samples: &[mts_sample_mapping_t], property: Range<usize> )

Implementors§