pub struct Tensor {
pub shape: Vec<usize>,
pub dtype: Symbol,
pub data: Vec<Value>,
}Expand description
The uniform tensor value: an n-dimensional array of scalar number cells.
A tensor is row-major (last axis varies fastest) and homogeneous: every cell
shares the dtype number domain. An empty shape
denotes a rank-0 scalar holding a single cell. Tensors are the value backing
the numbers/tensor domain and are constructed through
build_tensor_value rather than parsed from literals.
Fields§
§shape: Vec<usize>Length of each axis, outermost first. Empty for a rank-0 scalar.
dtype: SymbolThe shared scalar number domain of every cell (for example
numbers/i64 or numbers/f64).
data: Vec<Value>Row-major cell storage; its length equals the product of shape
(one for a scalar).
Implementations§
Source§impl Tensor
impl Tensor
Sourcepub fn flat_offset(shape: &[usize], indices: &[usize]) -> Result<usize>
pub fn flat_offset(shape: &[usize], indices: &[usize]) -> Result<usize>
Computes the row-major flat offset into data for a
multi-dimensional indices coordinate against shape.
Returns an error if the index rank does not match shape or any
component is out of bounds.
§Examples
use sim_lib_numbers_tensor::Tensor;
// Row-major 2x3 tensor: element (1, 2) is at flat offset 5.
assert_eq!(Tensor::flat_offset(&[2, 3], &[1, 2]).unwrap(), 5);
assert_eq!(Tensor::flat_offset(&[2, 3], &[0, 0]).unwrap(), 0);
// Out-of-bounds and rank-mismatched indices are rejected.
assert!(Tensor::flat_offset(&[2, 3], &[2, 0]).is_err());
assert!(Tensor::flat_offset(&[2, 3], &[0]).is_err());Trait Implementations§
Source§impl Citizen for Tensor
impl Citizen for Tensor
Source§fn citizen_symbol() -> Symbol
fn citizen_symbol() -> Symbol
namespace/name class symbol.Source§fn citizen_version() -> u32
fn citizen_version() -> u32
Source§fn citizen_arity() -> usize
fn citizen_arity() -> usize
Source§fn citizen_fields() -> &'static [&'static str]
fn citizen_fields() -> &'static [&'static str]
Source§impl NumberValue for Tensor
impl NumberValue for Tensor
Source§fn number_domain(&self, _cx: &mut Cx) -> Result<Symbol>
fn number_domain(&self, _cx: &mut Cx) -> Result<Symbol>
Source§fn number_literal(&self, _cx: &mut Cx) -> Result<Option<NumberLiteral>, Error>
fn number_literal(&self, _cx: &mut Cx) -> Result<Option<NumberLiteral>, Error>
Ok(None) when not representable.Source§impl Object for Tensor
impl Object for Tensor
Source§fn display(&self, cx: &mut Cx) -> Result<String>
fn display(&self, cx: &mut Cx) -> Result<String>
Source§fn header(&self) -> &ObjectHeader
fn header(&self) -> &ObjectHeader
Source§fn op(&self, _key: &OpKey) -> Option<&dyn Op>
fn op(&self, _key: &OpKey) -> Option<&dyn Op>
key, if any.Source§impl ObjectCompat for Tensor
impl ObjectCompat for Tensor
Source§fn class(&self, cx: &mut Cx) -> Result<ClassRef>
fn class(&self, cx: &mut Cx) -> Result<ClassRef>
Source§fn as_expr(&self, cx: &mut Cx) -> Result<Expr>
fn as_expr(&self, cx: &mut Cx) -> Result<Expr>
Source§fn as_table(&self, cx: &mut Cx) -> Result<Value>
fn as_table(&self, cx: &mut Cx) -> Result<Value>
Source§fn as_number_value(&self) -> Option<&dyn NumberValue>
fn as_number_value(&self) -> Option<&dyn NumberValue>
Source§fn as_object_encoder(&self) -> Option<&dyn ObjectEncode>
fn as_object_encoder(&self) -> Option<&dyn ObjectEncode>
Source§fn as_callable(&self) -> Option<&dyn Callable>
fn as_callable(&self) -> Option<&dyn Callable>
Source§fn as_read_constructor(&self) -> Option<&dyn ReadConstructor>
fn as_read_constructor(&self) -> Option<&dyn ReadConstructor>
Source§fn as_number_domain(&self) -> Option<&(dyn NumberDomain + 'static)>
fn as_number_domain(&self) -> Option<&(dyn NumberDomain + 'static)>
Source§fn as_eval_fabric(&self) -> Option<&dyn EvalFabric>
fn as_eval_fabric(&self) -> Option<&dyn EvalFabric>
Source§fn as_sequence(&self) -> Option<&dyn Sequence>
fn as_sequence(&self) -> Option<&dyn Sequence>
Source§fn as_list(&self) -> Option<&(dyn ListValue + 'static)>
fn as_list(&self) -> Option<&(dyn ListValue + 'static)>
Source§fn as_table_impl(&self) -> Option<&(dyn Table + 'static)>
fn as_table_impl(&self) -> Option<&(dyn Table + 'static)>
Source§fn as_dir(&self) -> Option<&(dyn Dir + 'static)>
fn as_dir(&self) -> Option<&(dyn Dir + 'static)>
Source§impl ObjectEncode for Tensor
impl ObjectEncode for Tensor
Source§fn object_encoding(&self, cx: &mut Cx) -> Result<ObjectEncoding>
fn object_encoding(&self, cx: &mut Cx) -> Result<ObjectEncoding>
ObjectEncoding this object should be rendered as.