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§
sourcefn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Get the array as a mutable Any reference
sourcefn create(&self, shape: &[usize]) -> Box<dyn Array>
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.
sourcefn copy(&self) -> Box<dyn Array>
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.)
sourcefn data(&mut self) -> &mut [f64]
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.
sourcefn swap_axes(&mut self, axis_1: usize, axis_2: usize)
fn swap_axes(&mut self, axis_1: usize, axis_2: usize)
Swap the axes axis_1 and axis_2 in this array
sourcefn move_samples_from(
&mut self,
input: &dyn Array,
samples: &[mts_sample_mapping_t],
properties: Range<usize>
)
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.