transformations (clifford.transformations
)¶
New in version 1.3.0.
This module may in future become the home for optimized rotor transformations, or non-linear transformations.
See the Linear transformations tutorial for an introduction to how to use parts of this module.
Base classes¶
- clifford.transformations.Transformation¶
A callable mapping one MultiVector to another.
alias of
Callable
[[clifford._multivector.MultiVector
],clifford._multivector.MultiVector
]
- class clifford.transformations.Linear(*args, **kwds)[source]¶
A transformation which is linear, such that for scalar \(a_i\), \(f(a_1 x_1 + a_2 x_2) = a_1 f(x_1) + a_2 f(x_2)\).
- class clifford.transformations.FixedLayout(layout_src: clifford._layout.Layout, layout_dst: Optional[clifford._layout.Layout] = None)[source]¶
A transformation with a fixed source and destination layout.
Matrix-backed implementations¶
- class clifford.transformations.LinearMatrix(matrix, layout_src: clifford._layout.Layout, layout_dst: Optional[clifford._layout.Layout] = None)[source]¶
Linear transformation implemented by a matrix
Transformations need not be grade preserving.
- Parameters
matrix ((2**D, 2**S) array_like) – A matrix that transforms multivectors from layout_src with \(2^S\) elements to multivectors in layout_dst with \(2^D\) elements, by left-multiplication.
layout_src (Layout of S dimensions) – Passed on to
FixedLayout
.layout_dst (Layout of D dimensions) – Passed on to
FixedLayout
.
See also
clifford.BladeMap
A faster but less general approach that works on basis blades
- property adjoint: clifford.transformations.LinearMatrix¶
The adjoint transformation
- classmethod from_function(func: Callable[[clifford._multivector.MultiVector], clifford._multivector.MultiVector], layout_src: clifford._layout.Layout, layout_dst: Optional[clifford._layout.Layout] = None) → clifford.transformations.LinearMatrix[source]¶
Build a linear transformation from the result of a function applied to each basis blade.
- Parameters
func – A function taking basis blades from layout_src that produces multivectors in layout_dst.
layout_src (Layout of S dimensions) – The layout to pass into the generating function
layout_dst (Layout of D dimensions) – The layout the generating function is expected to produce. If not passed, this is inferred.
Example
>>> from clifford import transformations, Layout >>> l = Layout([1, 1]) >>> e1, e2 = l.basis_vectors_lst >>> rot_90 = transformations.LinearMatrix.from_function(lambda x: (1 + e1*e2)*x*(1 - e1*e2)/2, l) >>> rot_90(e1) (1.0^e2) >>> rot_90(e2) -(1.0^e1) >>> rot_90(e1*e2) (1.0^e12)
See also
LinearMatrix.from_rotor
a shorter way to spell the above example
clifford.linear_operator_as_matrix
a lower-level function for working with a subset of basis blades
- classmethod from_rotor(rotor: clifford._multivector.MultiVector) → clifford.transformations.LinearMatrix[source]¶
Build a linear transformation from the result of applying a rotor sandwich.
The resulting transformation operates within the algebra of the provided rotor.
- Parameters
rotor – The rotor to apply
Example
>>> from clifford import transformations, Layout >>> l = Layout([1, 1]) >>> e1, e2 = l.basis_vectors_lst >>> rot_90 = transformations.LinearMatrix.from_rotor(1 + e1*e2) >>> rot_90(e1) (1.0^e2) >>> rot_90(e2) -(1.0^e1) >>> rot_90(e1*e2) (1.0^e12)
- class clifford.transformations.OutermorphismMatrix(matrix, layout_src: clifford._layout.Layout, layout_dst: Optional[clifford._layout.Layout] = None)[source]¶
A generalization of a linear transformation to vectors via the outer product.
Namely, given a linear transformation \(F(u) \to v\), this generalizes to the blades by outermorphism, \(F(u_1 \wedge u_2) \to F(u_1) \wedge F(u_2)\), and to the multivectors by distributivity.
Such a transformation is grade preserving.
See [DFM09] Chapter 4 for more information
- Parameters
matrix ((D, S) array_like) – A matrix that transforms vectors from layout_src of size S to vectors in layout_dst of size D by left-multiplication.
layout_src (Layout of S dimensions) – Passed on to
FixedLayout
.layout_dst (Layout of D dimensions) – Passed on to
FixedLayout
.
Example
We can construct a simple transformation that permutes and non-uniformly scales the basis vectors:
>>> from clifford import transformations, Layout >>> layout = Layout([1, 1, 1]) >>> e1, e2, e3 = layout.basis_vectors_lst >>> layout_new = Layout([1, 1, 1], names='f') >>> m = np.array([[0, 1, 0], ... [0, 0, 2], ... [3, 0, 0]]) >>> lt = transformations.OutermorphismMatrix(m, layout, layout_new)
Applying it to some multivectors:
>>> # the transformation we specified >>> lt(e1), lt(e2), lt(e3) ((3^f3), (1^f1), (2^f2)) >>> # the one deduced by outermorphism >>> lt(e1^e2), lt(e2^e3), lt(e1^e3) (-(3^f13), (2^f12), -(6^f23)) >>> # and by distributivity >>> lt(1 + (e1^e2^e3)) 1 + (6^f123)
Helper functions¶
- clifford.transformations.between_basis_vectors(layout_src: clifford._layout.Layout, layout_dst: clifford._layout.Layout, mapping: Optional[Dict[Any, Any]] = None) → clifford.transformations.OutermorphismMatrix[source]¶
Construct an outermorphism that maps basis vectors from one layout to basis vectors in another.
- Parameters
layout_src (Layout) – Passed on to
FixedLayout
.layout_dst (Layout) – Passed on to
FixedLayout
.mapping – If provided, a dictionary mapping the ids of source basis vectors to the ids of destination basis vectors. For example,
{1: 2, 2: 3, 3: 1}
would permute the basis vectors ofclifford.g3
.
Example
See the tutorial on Working with custom algebras for a motivating example.