pub struct Spensor { /* private fields */ }Expand description
A tensor class that can be either dense or sparse with flexible data types.
The tensor can store data as floats, complex numbers, or symbolic expressions. Tensors have an associated structure that defines their shape and index properties.
§Examples
from symbolica.community.spenso import Tensor, TensorIndices, Representation structure = TensorIndices(Representation.euc(4)(1)) data = [1.0, 2.0, 3.0, 4.0] tensor = Tensor.dense(structure, data) sparse_tensor = Tensor.sparse(structure, float)
Implementations§
Source§impl Spensor
impl Spensor
pub fn structure(&self) -> SpensoIndices
Sourcepub fn sparse(
structure: ConvertibleToStructure,
type_info: Bound<'_, PyType>,
) -> PyResult<Spensor>
pub fn sparse( structure: ConvertibleToStructure, type_info: Bound<'_, PyType>, ) -> PyResult<Spensor>
Create a new sparse empty tensor with the given structure and data type.
§Parameters
structure : TensorIndices or list of Slots
The tensor structure defining shape and index properties
type_info : type
The data type - either float or Expression class
§Returns
Tensor A new sparse tensor with all elements initially zero
§Examples
from symbolica.community.spenso import Tensor, TensorIndices, Representation as R structure = TensorIndices(R.euc(3)(1), R.euc(3)(2)) sparse_float = Tensor.sparse(structure, float) sparse_sym = Tensor.sparse(structure, symbolica.Expression)
Sourcepub fn dense(
structure: ConvertibleToStructure,
data: AtomsOrFloats,
) -> PyResult<Spensor>
pub fn dense( structure: ConvertibleToStructure, data: AtomsOrFloats, ) -> PyResult<Spensor>
Create a new dense tensor with the given structure and data.
§Parameters
structure : TensorIndices or list of Slots The tensor structure defining shape and index properties data : list of float, complex, or Expression The tensor data in row-major order
§Returns
Tensor A new dense tensor with the specified data
§Examples
from symbolica import S from symbolica.community.spenso import Tensor, TensorIndices, Representation as R structure = TensorIndices(R.euc(2)(1), R.euc(2)(2)) data = [1.0, 2.0, 3.0, 4.0] tensor = Tensor.dense(structure, data) x, y = S(“x”, “y”) sym_data = [x, y, x * y, x + y] sym_tensor = Tensor.dense(structure, sym_data)
Sourcepub fn evaluator(
&self,
constants: HashMap<PythonExpression, PythonExpression>,
funs: HashMap<(PolyVariable, String, Vec<PolyVariable>), PythonExpression>,
params: Vec<PythonExpression>,
iterations: usize,
n_cores: usize,
verbose: bool,
) -> PyResult<SpensoExpressionEvaluator>
pub fn evaluator( &self, constants: HashMap<PythonExpression, PythonExpression>, funs: HashMap<(PolyVariable, String, Vec<PolyVariable>), PythonExpression>, params: Vec<PythonExpression>, iterations: usize, n_cores: usize, verbose: bool, ) -> PyResult<SpensoExpressionEvaluator>
Create an optimized evaluator for symbolic tensor expressions.
Create an optimized evaluator for symbolic tensor expressions.
Compiles the symbolic expressions in this tensor into an optimized evaluation tree that can efficiently compute numerical values for different parameter inputs.
§Parameters
constants : dict Dict mapping symbolic expressions to their constant numerical values funs : dict Dict mapping function signatures to their symbolic definitions params : list of Expression List of symbolic parameters that will be varied during evaluation iterations : int, optional Number of optimization iterations for Horner scheme (default: 100) n_cores : int, optional Number of CPU cores to use for optimization (default: 4) verbose : bool, optional Whether to print optimization progress (default: False)
§Returns
TensorEvaluator An optimized evaluator for efficient numerical evaluation
§Examples
from symbolica import S from symbolica.community.spenso import Tensor, TensorIndices, Representation as R x, y = S(“x”, “y”) structure = TensorIndices(R.euc(2)(1)) tensor = Tensor.dense(structure, [x * y, x + y]) evaluator = tensor.evaluator(constants={}, funs={}, params=[x, y], iterations=50) results = evaluator.evaluate_complex([[1.0, 2.0], [3.0, 4.0]])
Trait Implementations§
Source§impl Deref for Spensor
impl Deref for Spensor
Source§type Target = ParamOrConcrete<RealOrComplexTensor<f64, NamedStructure<Symbol, Vec<Atom>>>, NamedStructure<Symbol, Vec<Atom>>>
type Target = ParamOrConcrete<RealOrComplexTensor<f64, NamedStructure<Symbol, Vec<Atom>>>, NamedStructure<Symbol, Vec<Atom>>>
impl DerefToPyAny for Spensor
impl ExtractPyClassWithClone for Spensor
Source§impl From<DataTensor<Complex<f64>, NamedStructure<Symbol, Vec<Atom>>>> for Spensor
impl From<DataTensor<Complex<f64>, NamedStructure<Symbol, Vec<Atom>>>> for Spensor
Source§fn from(
value: DataTensor<Complex<f64>, ShadowedStructure<AbstractIndex>>,
) -> Self
fn from( value: DataTensor<Complex<f64>, ShadowedStructure<AbstractIndex>>, ) -> Self
Source§impl From<DataTensor<f64, NamedStructure<Symbol, Vec<Atom>>>> for Spensor
impl From<DataTensor<f64, NamedStructure<Symbol, Vec<Atom>>>> for Spensor
Source§fn from(value: DataTensor<f64, ShadowedStructure<AbstractIndex>>) -> Self
fn from(value: DataTensor<f64, ShadowedStructure<AbstractIndex>>) -> Self
Source§impl From<ParamOrConcrete<RealOrComplexTensor<f64, NamedStructure<Symbol, Vec<Atom>>>, NamedStructure<Symbol, Vec<Atom>>>> for Spensor
impl From<ParamOrConcrete<RealOrComplexTensor<f64, NamedStructure<Symbol, Vec<Atom>>>, NamedStructure<Symbol, Vec<Atom>>>> for Spensor
Source§fn from(value: MixedTensor<f64, ShadowedStructure<AbstractIndex>>) -> Self
fn from(value: MixedTensor<f64, ShadowedStructure<AbstractIndex>>) -> Self
Source§impl<'py> IntoPyObject<'py> for Spensor
impl<'py> IntoPyObject<'py> for Spensor
Source§type Output = Bound<'py, <Spensor as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <Spensor as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClassImpl for Spensor
impl PyClassImpl for Spensor
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = /// A tensor class that can be either dense or sparse with flexible data types.
///
/// The tensor can store data as floats, complex numbers, or symbolic expressions.
/// Tensors have an associated structure that defines their shape and index properties.
///
/// Examples
/// --------
/// >>> from symbolica.community.spenso import Tensor, TensorIndices, Representation
/// >>> structure = TensorIndices(Representation.euc(4)(1))
/// >>> data = [1.0, 2.0, 3.0, 4.0]
/// >>> tensor = Tensor.dense(structure, data)
/// >>> sparse_tensor = Tensor.sparse(structure, float)
const RAW_DOC: &'static CStr = /// A tensor class that can be either dense or sparse with flexible data types. /// /// The tensor can store data as floats, complex numbers, or symbolic expressions. /// Tensors have an associated structure that defines their shape and index properties. /// /// Examples /// -------- /// >>> from symbolica.community.spenso import Tensor, TensorIndices, Representation /// >>> structure = TensorIndices(Representation.euc(4)(1)) /// >>> data = [1.0, 2.0, 3.0, 4.0] /// >>> tensor = Tensor.dense(structure, data) /// >>> sparse_tensor = Tensor.sparse(structure, float)
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<Spensor>
type ThreadChecker = SendablePyClass<Spensor>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyMethods<Spensor> for PyClassImplCollector<Spensor>
impl PyMethods<Spensor> for PyClassImplCollector<Spensor>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for Spensor
impl PyTypeInfo for Spensor
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Source§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
Auto Trait Implementations§
impl Freeze for Spensor
impl RefUnwindSafe for Spensor
impl Send for Spensor
impl Sync for Spensor
impl Unpin for Spensor
impl UnsafeUnpin for Spensor
impl UnwindSafe for Spensor
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<'a, 'py, T> FromPyObject<'a, 'py> for T
impl<'a, 'py, T> FromPyObject<'a, 'py> for T
impl<'py, T> FromPyObjectOwned<'py> for Twhere
T: for<'a> FromPyObject<'a, 'py>,
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<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
Source§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.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> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
Source§impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
Source§const NAME: &'static str = T::NAME
const NAME: &'static str = T::NAME
Use ::classinfo_object() instead and format the type name at runtime. Note that using built-in cast features is often better than manual PyTypeCheck usage.
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> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.