SymbolicCoeffs¶
- class zixy.container.coeffs.SymbolicCoeffs(data=None, indexer=slice(None, None, None))[source]¶
-
A collection of
Expr.A resizable vector-like container of coefficients that may be an owning instance referencing a contiguous Rust-bound data object, or a view on a slice of the elements in another collection.
- __getitem__(indexer: int | slice) CoeffT | Self¶
- Overloads:
self, indexer (int) → CoeffT
self, indexer (builtins.slice) → Self
Get the element or elements selected by
indexer.- Parameters:
indexer – Index or slice selecting the coefficient(s) to return.
- Returns:
Coefficient or slice selected by
indexer.
- __imul__(rhs: int | float | complex | Sign | ComplexSign | Expr | Iterable[int | float | complex | Sign | ComplexSign | Expr]) Self¶
Multiply
selfbyrhsin-place.- Raises:
ValueError – If the result of the multiplication cannot be represented by the type of
self.
- __init__(data=None, indexer=slice(None, None, None))¶
Initialize the coefficient vector.
- Parameters:
data – Rust-bound object storing a vector of coefficients. If
None, an empty vector of the appropriate type is initialized.indexer – Slice over which the data is to be viewed.
- __setitem__(indexer: int | slice, source: CoeffT | Coeffs[CoeffT] | None = None) None¶
Set the indexed element(s) to the given value(s).
- Parameters:
indexer – Index or slice of coefficient(s) within
selfto assign.source – Value(s) specifying the coefficient(s) to assign.
- allclose(other: Coeffs[Any], rtol: float = 1e-05, atol: float = 1e-08) bool¶
Check whether
selfandotherare within a certain tolerance.- Parameters:
other – Other instance to compare to.
rtol – Relative tolerance.
atol – Absolute tolerance.
- Returns:
Whether
selfandotherare within the given tolerances of each other.
Note
This method operates by comparing the NumPy arrays returned by
np_array.
- append(value: CoeffT) None¶
Append
valueto the end ofself.- Parameters:
value – Value to append.
Note
This method operates in-place.
- append_n(n: int, value: CoeffT) None¶
Append
valueto the end ofselfntimes.- Parameters:
n – Number of times to repeatedly append
value.value – Value to append.
Note
This method operates in-place.
- as_view() Self¶
Return a view of
self.- Returns:
If
selfis owning, a new view on the same underlying data, otherwiseself.
- coeffs_type¶
alias of
ExprListWrapper
- count(value) integer -- return number of occurrences of value¶
- diff(variable: Symbol | str) SymbolicCoeffs[source]¶
Differentiate partially with respect to
variableout of place.- Parameters:
variable – Symbol or name of symbol by which to differentiate the viewed symbolic expressions.
- Returns:
A new contiguously stored instance with the differentiation applied.
- extend(other: Self) None[source]¶
Append the elements of
otherto the end ofself.- Parameters:
other – Other instance whose elements are appended to
self.
Note
This method operates in-place.
- fill(coeff: CoeffT) None¶
Set all the coefficients in the vector to the given value.
- Parameters:
coeff – Coefficient value to which to set all coefficients in the vector.
- property free_symbols: set[Symbol]¶
Get the set of free (unsubstituted) symbols in
self.- Returns:
Union of the sets of free symbols across all coefficients in
self.
- classmethod from_scalar(coeff: CoeffT, n: int = 1) Self¶
Get a new instance of
clswith the given scalar repeatedntimes.- Parameters:
coeff – Coefficient value.
n – Number of times to repeat
coeff.
- Returns:
New instance with
coeffrepeatedntimes.
- classmethod from_sequence(source: Sequence[CoeffT]) Self¶
Get a new instance from a sequence of coefficients.
- Parameters:
source – Sequence of coefficients.
- Returns:
New instance with elements set according to
source.
- classmethod from_size(n: int) Self¶
Create a new instance of
clswith the given size.- Parameters:
n – The size of the new instance.
- Returns:
An instance of
clswith the given size.
- classmethod from_view(source: Self) Self¶
Create a new instance of
clsfrom a view.- Parameters:
source – View to clone into the new instance.
- Returns:
An owning clone of
source.
- idiff(variable: Symbol | str) None[source]¶
Differentiate partially with respect to
variablein-place.- Parameters:
variable – Symbol or name of symbol by which to differentiate the viewed symbolic expressions.
Note
This method operates in-place.
- into(t: type[OutT]) OutT¶
Clone
selfinto a new related container of typet.- Parameters:
t – Type of the new container to create.
- Returns:
A new instance of
tcontaining the same data asself.
- isubs(values: dict[Symbol | str, int | float | complex | Expr]) None[source]¶
Apply a partial substitution of the symbols in-place.
- Parameters:
values – Map from a symbol or symbol name to its new expression or numeric value.
Note
This method operates in-place.
- map_index(index: int) int¶
Map an index in
selfto an index in the underlying data.- Parameters:
index – Index in
self.- Returns:
Corresponding index in the underlying data.
- property np_array: NDArray[float64 | complex128]¶
Get the contents of
selfcopied as a flat NumPy array.- Returns:
NumPy array containing all elements of
self.
- classmethod parse(source: str) Self[source]¶
Construct an instance of
clsfrom a string representation.- Parameters:
source – The string to read from.
- Returns:
An instance of
clsrepresented bysource.
- reordered(inds: Sequence[int]) Self¶
Get a new instance with the elements of
selfin a new order.- Parameters:
inds – Sequence of indices defining the new order. Should be a permutation of
range(len(self)).- Returns:
A new instance with the reordered elements.
- resize(n: int) Self¶
Resize the underlying container.
- Parameters:
n – The new size of the container.
Note
This method operates in-place.
- Raises:
ValueError – If the container is a view.
- scale(scalar: int | float | complex | Sign | ComplexSign | Expr) None¶
Scale all elements by a given factor.
- Parameters:
scalar – Scalar factor by which to scale all elements.
Note
This method operates in-place.
- set(source: Iterable[CoeffT]) None¶
Assign the viewed coefficients according to the values yielded by the given iterable.
- Parameters:
source – Iterable containing the values to be assigned to the viewed coefficients of
self.
- subs(values: dict[Symbol | str, int | float | complex | Expr]) SymbolicCoeffs[source]¶
Apply a partial substitution of the symbols out of place.
- Parameters:
values – Map from a symbol or symbol name to its new expression or numeric value.
- Returns:
A new contiguously stored instance with the substitution applied.
- swap_remove(index: int) None¶
Set the element at
indexto the final element, then delete the final element.- Parameters:
index – Element index to remove.
Note
This method operates in-place.
- try_to_complex() ComplexCoeffs[source]¶
Try to evaluate
selfas a vector of complex coefficients.- Returns:
An instance of
ComplexCoeffswith the evaluated coefficients.- Raises:
TypeError – A coefficient is not representable as complex or there are free symbols.
- try_to_real() RealCoeffs[source]¶
Try to evaluate
selfas a vector of real coefficients.- Returns:
An instance of
RealCoeffswith the evaluated coefficients.- Raises:
TypeError – A coefficient is not representable as real or there are free symbols.