Utilities¶
ablina.utils
¶
A module providing utility functions for linear algebra operations.
symbols(names, field=None, **kwargs)
¶
Return sympy symbols with the specified names and field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
str
|
The names of the symbols to create. |
required |
field
|
(R, C)
|
The field to constrain the symbols to. If |
R
|
**kwargs
|
Any
|
Additional keyword arguments to pass to sympy.symbols. |
{}
|
Returns:
| Type | Description |
|---|---|
Symbol or tuple of Symbol
|
The created symbol(s) with the specified constraints. |
Source code in ablina/utils.py
is_linear(expr, vars=None)
¶
Check whether an expression is linear with respect to the given variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
Expr
|
The expression to check. |
required |
vars
|
iterable of Symbol
|
The variables to check linearity with respect to. If None, all
variables in |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the expression is linear with respect to the variables, otherwise False. |
Source code in ablina/utils.py
is_empty(matrix)
¶
Check whether a matrix is empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
Matrix
|
The matrix to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the matrix contains no elements, otherwise False. |
Source code in ablina/utils.py
is_invertible(matrix)
¶
Check whether a matrix is invertible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
Matrix
|
The matrix to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the matrix is invertible, otherwise False. |
Source code in ablina/utils.py
is_orthogonal(matrix)
¶
Check whether a matrix is orthogonal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
Matrix
|
The matrix to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the matrix is orthogonal, otherwise False. |
See Also
is_unitary
Source code in ablina/utils.py
is_unitary(matrix)
¶
Check whether a matrix is unitary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
Matrix
|
The matrix to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the matrix is unitary, otherwise False. |
See Also
is_orthogonal
Source code in ablina/utils.py
is_normal(matrix)
¶
Check whether a matrix is normal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
Matrix
|
The matrix to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the matrix is normal, otherwise False. |
Source code in ablina/utils.py
rref(matrix, remove=False)
¶
Compute the reduced row echelon form of a matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
Matrix
|
The matrix to compute the rref of. |
required |
remove
|
bool
|
If True, all zero rows are removed from the result. |
False
|
Returns:
| Type | Description |
|---|---|
Matrix
|
The reduced row echelon form of the matrix. |
Source code in ablina/utils.py
of_arity(func, arity)
¶
Check whether a function can accept a given number of positional arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
callable
|
The function to check. |
required |
arity
|
int
|
The number of positional arguments to check for. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the function can accept |
Source code in ablina/utils.py
add_attributes(cls, *attributes)
¶
Dynamically create a subclass with additional attributes.
Creates a new class that inherits from the given class and adds the specified attributes as class attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
type
|
The base class to subclass. |
required |
*attributes
|
Any
|
The attributes to add to the new class. |
()
|
Returns:
| Type | Description |
|---|---|
type
|
A new subclass with the added attributes. |
Source code in ablina/utils.py
ablina.vs_utils
¶
A module providing utility functions for vector space operations.
to_ns_matrix(n, constraints)
¶
Return the matrix representation of the given linear constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The dimension of the vector space (length of vectors). |
required |
constraints
|
list of str
|
The list of linear constraints. |
required |
Returns:
| Type | Description |
|---|---|
Matrix
|
A matrix with the linear constraints as rows. |
Raises:
| Type | Description |
|---|---|
ConstraintError
|
If any constraint has an invalid format. |
Source code in ablina/vs_utils.py
to_complement(matrix)
¶
Return the complement of a matrix.
This function works bidirectionally: if given a null space matrix, it returns a row space matrix, and if given a row space matrix, it returns a null space matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
Matrix
|
The matrix to take the complement of. |
required |
Returns:
| Type | Description |
|---|---|
Matrix
|
The complement of |
Source code in ablina/vs_utils.py
ablina.parser
¶
A module for parsing and processing mathematical expressions and constraints.
sympify(expr, allowed_vars=None)
¶
Return the sympy representation of the given expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
str
|
The expression to convert to a sympy representation. |
required |
allowed_vars
|
iterable
|
The set of allowed variables in the expression. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The sympy representation of |
Raises:
| Type | Description |
|---|---|
ParsingError
|
If |
Source code in ablina/parser.py
split_constraint(constraint)
¶
Split a constraint with multiple relational operators into separate relations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraint
|
str
|
The constraint string to split, containing one or more "==" operators. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
relations |
set of str
|
A set of relation strings, each representing one equality from the constraint. |