tfga package

Submodules

tfga.blades module

Blade-related definitions and functions used across the library.

class tfga.blades.BladeKind(value)[source]

Bases: enum.Enum

Kind of blade depending on its degree.

BIVECTOR = 'bivector'
EVEN = 'even'
MV = 'mv'
ODD = 'odd'
PSEUDOBIVECTOR = 'pseudobivector'
PSEUDOSCALAR = 'pseudoscalar'
PSEUDOTRIVECTOR = 'pseudotrivector'
PSEUDOVECTOR = 'pseudovector'
SCALAR = 'scalar'
TRIVECTOR = 'trivector'
VECTOR = 'vector'
tfga.blades.get_blade_indices_from_names(blade_names: List[str], all_blade_names: List[str]) tensorflow.python.framework.ops.Tensor[source]

Finds blade signs and indices for given blade names in a list of blade names. Blade names can be unnormalized and their correct sign will be returned.

Args:

blade_names: Blade names to return indices for. May be unnormalized. all_blade_names: Blade names to use as index

Returns:

blade_signs: signs for the passed blades in same order as passed blade_indices: blade indices in the same order as passed

tfga.blades.get_blade_of_kind_indices(blade_degrees: tensorflow.python.framework.ops.Tensor, kind: tfga.blades.BladeKind, max_degree: int, invert: bool = False) tensorflow.python.framework.ops.Tensor[source]

Finds a boolean mask for whether blades are of a given kind.

Args:

blade_degrees: List of blade degrees kind: kind of blade for which the mask will be true max_degree: maximum blade degree in the algebra invert: whether to invert the result

Returns:

boolean mask for whether blades are of a given kind

tfga.blades.get_blade_repr(blade_name: str) str[source]

Returns the representation to use for a given blade.

Examples: - “12” -> “e_12” - “” -> “1”

Args:

blade_name: name of the blade in the algebra (eg. “12”)

Returns:

Representation to use for a given blade

tfga.blades.get_normal_ordered(blade_name: str) Tuple[int, str][source]

Returns the normal ordered blade name and its sign. Example: 21 => -1, 12

Args:

blade_name: Blade name for which to return normal ordered name and sign

Returns:

sign: sign of the blade blade_name: normalized name of the blade

tfga.blades.invert_blade_indices(num_blades: int, blade_indices: tensorflow.python.framework.ops.Tensor) tensorflow.python.framework.ops.Tensor[source]

Returns all blade indices except for the given ones.

Args:

num_blades: Total number of blades in the algebra blade_indices: blade indices to exclude

Returns:

All blade indices except for the given ones

tfga.blades.is_blade_kind()[source]

Finds a boolean mask for whether blade degrees are of a given kind.

Args:

blade_degrees: list of blade degrees kind: kind of blade to check for max_degree: maximum blade degree in the algebra

Returns:

boolean mask for whether blade degrees are of a given kind

tfga.cayley module

Operations for constructing the cayley 3-tensor needed for the geometric product. Used internally.

tfga.cayley.blades_from_bases(vector_bases)[source]
tfga.cayley.get_cayley_tensor(metric, bases, blades)[source]

tfga.layers module

Provides Geometric Algebra Keras layers.

class tfga.layers.GeometricAlgebraExp(*args, **kwargs)[source]

Bases: tfga.layers.GeometricAlgebraLayer

Calculates the exponential function of the input. Input must square to a scalar.

Args:

algebra: GeometricAlgebra instance to use square_scalar_tolerance: Tolerance to use for the square scalar check

or None if the check should be skipped

call(inputs)[source]

This is where the layer’s logic lives.

Note here that call() method in tf.keras is little bit different from keras API. In keras API, you can pass support masking for layers as additional arguments. Whereas tf.keras has compute_mask() method to support masking.

Args:

inputs: Input tensor, or list/tuple of input tensors. *args: Additional positional arguments. Currently unused. **kwargs: Additional keyword arguments. Currently unused.

Returns:

A tensor or list/tuple of tensors.

compute_output_shape(input_shape)[source]

Computes the output shape of the layer.

If the layer has not been built, this method will call build on the layer. This assumes that the layer will later be used with inputs that match the input shape provided here.

Args:
input_shape: Shape tuple (tuple of integers)

or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns:

An input shape tuple.

get_config()[source]

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

class tfga.layers.GeometricAlgebraLayer(*args, **kwargs)[source]

Bases: tensorflow.python.keras.engine.base_layer.Layer

classmethod from_config(config)[source]

Creates a layer from its config.

This method is the reverse of get_config, capable of instantiating the same layer from the config dictionary. It does not handle layer connectivity (handled by Network), nor weights (handled by set_weights).

Args:
config: A Python dictionary, typically the

output of get_config.

Returns:

A layer instance.

get_config()[source]

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

class tfga.layers.GeometricProductConv1D(*args, **kwargs)[source]

Bases: tfga.layers.GeometricAlgebraLayer

Analagous to Keras’ Conv1D layer but using multivector-valued kernels instead of scalar ones and geometric product instead of standard multiplication.

Args:

algebra: GeometricAlgebra instance to use for the parameters filters: How many channels the output will have kernel_size: Size for the convolution kernel stride: Stride to use for the convolution padding: “SAME” (zero-pad input length so output

length == input length / stride) or “VALID” (no padding)

blade_indices_kernel: Blade indices to use for the kernel parameter blade_indices_bias: Blade indices to use for the bias parameter (if used)

build(input_shape: tensorflow.python.framework.tensor_shape.TensorShape)[source]

Creates the variables of the layer (optional, for subclass implementers).

This is a method that implementers of subclasses of Layer or Model can override if they need a state-creation step in-between layer instantiation and layer call.

This is typically used to create the weights of Layer subclasses.

Args:
input_shape: Instance of TensorShape, or list of instances of

TensorShape if the layer expects a list of inputs (one instance per input).

call(inputs)[source]

This is where the layer’s logic lives.

Note here that call() method in tf.keras is little bit different from keras API. In keras API, you can pass support masking for layers as additional arguments. Whereas tf.keras has compute_mask() method to support masking.

Args:

inputs: Input tensor, or list/tuple of input tensors. *args: Additional positional arguments. Currently unused. **kwargs: Additional keyword arguments. Currently unused.

Returns:

A tensor or list/tuple of tensors.

get_config()[source]

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

class tfga.layers.GeometricProductDense(*args, **kwargs)[source]

Bases: tfga.layers.GeometricAlgebraLayer

Analagous to Keras’ Dense layer but using multivector-valued matrices instead of scalar ones and geometric multiplication instead of standard multiplication.

Args:

algebra: GeometricAlgebra instance to use for the parameters blade_indices_kernel: Blade indices to use for the kernel parameter blade_indices_bias: Blade indices to use for the bias parameter (if used)

build(input_shape: tensorflow.python.framework.tensor_shape.TensorShape)[source]

Creates the variables of the layer (optional, for subclass implementers).

This is a method that implementers of subclasses of Layer or Model can override if they need a state-creation step in-between layer instantiation and layer call.

This is typically used to create the weights of Layer subclasses.

Args:
input_shape: Instance of TensorShape, or list of instances of

TensorShape if the layer expects a list of inputs (one instance per input).

call(inputs)[source]

This is where the layer’s logic lives.

Note here that call() method in tf.keras is little bit different from keras API. In keras API, you can pass support masking for layers as additional arguments. Whereas tf.keras has compute_mask() method to support masking.

Args:

inputs: Input tensor, or list/tuple of input tensors. *args: Additional positional arguments. Currently unused. **kwargs: Additional keyword arguments. Currently unused.

Returns:

A tensor or list/tuple of tensors.

compute_output_shape(input_shape)[source]

Computes the output shape of the layer.

If the layer has not been built, this method will call build on the layer. This assumes that the layer will later be used with inputs that match the input shape provided here.

Args:
input_shape: Shape tuple (tuple of integers)

or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns:

An input shape tuple.

get_config()[source]

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

class tfga.layers.GeometricProductElementwise(*args, **kwargs)[source]

Bases: tfga.layers.GeometricAlgebraLayer

Performs the elementwise geometric product with a list of multivectors with as many elements as there are input units.

Args:

algebra: GeometricAlgebra instance to use for the parameters blade_indices_kernel: Blade indices to use for the kernel parameter blade_indices_bias: Blade indices to use for the bias parameter (if used)

build(input_shape: tensorflow.python.framework.tensor_shape.TensorShape)[source]

Creates the variables of the layer (optional, for subclass implementers).

This is a method that implementers of subclasses of Layer or Model can override if they need a state-creation step in-between layer instantiation and layer call.

This is typically used to create the weights of Layer subclasses.

Args:
input_shape: Instance of TensorShape, or list of instances of

TensorShape if the layer expects a list of inputs (one instance per input).

call(inputs)[source]

This is where the layer’s logic lives.

Note here that call() method in tf.keras is little bit different from keras API. In keras API, you can pass support masking for layers as additional arguments. Whereas tf.keras has compute_mask() method to support masking.

Args:

inputs: Input tensor, or list/tuple of input tensors. *args: Additional positional arguments. Currently unused. **kwargs: Additional keyword arguments. Currently unused.

Returns:

A tensor or list/tuple of tensors.

compute_output_shape(input_shape)[source]

Computes the output shape of the layer.

If the layer has not been built, this method will call build on the layer. This assumes that the layer will later be used with inputs that match the input shape provided here.

Args:
input_shape: Shape tuple (tuple of integers)

or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns:

An input shape tuple.

get_config()[source]

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

class tfga.layers.GeometricSandwichProductDense(*args, **kwargs)[source]

Bases: tfga.layers.GeometricProductDense

Analagous to Keras’ Dense layer but using multivector-valued matrices instead of scalar ones and geometric sandwich multiplication instead of standard multiplication.

Args:

algebra: GeometricAlgebra instance to use for the parameters blade_indices_kernel: Blade indices to use for the kernel parameter blade_indices_bias: Blade indices to use for the bias parameter (if used)

call(inputs)[source]

This is where the layer’s logic lives.

Note here that call() method in tf.keras is little bit different from keras API. In keras API, you can pass support masking for layers as additional arguments. Whereas tf.keras has compute_mask() method to support masking.

Args:

inputs: Input tensor, or list/tuple of input tensors. *args: Additional positional arguments. Currently unused. **kwargs: Additional keyword arguments. Currently unused.

Returns:

A tensor or list/tuple of tensors.

class tfga.layers.GeometricSandwichProductElementwise(*args, **kwargs)[source]

Bases: tfga.layers.GeometricProductElementwise

Performs the elementwise geometric sandwich product with a list of multivectors with as many elements as there are input units.

Args:

algebra: GeometricAlgebra instance to use for the parameters blade_indices_kernel: Blade indices to use for the kernel parameter blade_indices_bias: Blade indices to use for the bias parameter (if used)

call(inputs)[source]

This is where the layer’s logic lives.

Note here that call() method in tf.keras is little bit different from keras API. In keras API, you can pass support masking for layers as additional arguments. Whereas tf.keras has compute_mask() method to support masking.

Args:

inputs: Input tensor, or list/tuple of input tensors. *args: Additional positional arguments. Currently unused. **kwargs: Additional keyword arguments. Currently unused.

Returns:

A tensor or list/tuple of tensors.

class tfga.layers.GeometricToTensor(*args, **kwargs)[source]

Bases: tfga.layers.GeometricAlgebraLayer

Layer for extracting given blades from geometric algebra tensors.

Args:

algebra: GeometricAlgebra instance to use blade_indices: blade indices to extract

call(inputs)[source]

This is where the layer’s logic lives.

Note here that call() method in tf.keras is little bit different from keras API. In keras API, you can pass support masking for layers as additional arguments. Whereas tf.keras has compute_mask() method to support masking.

Args:

inputs: Input tensor, or list/tuple of input tensors. *args: Additional positional arguments. Currently unused. **kwargs: Additional keyword arguments. Currently unused.

Returns:

A tensor or list/tuple of tensors.

compute_output_shape(input_shape)[source]

Computes the output shape of the layer.

If the layer has not been built, this method will call build on the layer. This assumes that the layer will later be used with inputs that match the input shape provided here.

Args:
input_shape: Shape tuple (tuple of integers)

or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns:

An input shape tuple.

get_config()[source]

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

class tfga.layers.GeometricToTensorWithKind(*args, **kwargs)[source]

Bases: tfga.layers.GeometricToTensor

Layer for extracting blades of a kind from geometric algebra tensors.

Args:

algebra: GeometricAlgebra instance to use kind: blade indices of kind to extract

class tfga.layers.TensorToGeometric(*args, **kwargs)[source]

Bases: tfga.layers.GeometricAlgebraLayer

Layer for converting tensors with given blade indices to geometric algebra tensors.

Args:

algebra: GeometricAlgebra instance to use blade_indices: blade indices to interpret the last axis of the input tensor as

call(inputs)[source]

This is where the layer’s logic lives.

Note here that call() method in tf.keras is little bit different from keras API. In keras API, you can pass support masking for layers as additional arguments. Whereas tf.keras has compute_mask() method to support masking.

Args:

inputs: Input tensor, or list/tuple of input tensors. *args: Additional positional arguments. Currently unused. **kwargs: Additional keyword arguments. Currently unused.

Returns:

A tensor or list/tuple of tensors.

compute_output_shape(input_shape)[source]

Computes the output shape of the layer.

If the layer has not been built, this method will call build on the layer. This assumes that the layer will later be used with inputs that match the input shape provided here.

Args:
input_shape: Shape tuple (tuple of integers)

or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns:

An input shape tuple.

get_config()[source]

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

class tfga.layers.TensorWithKindToGeometric(*args, **kwargs)[source]

Bases: tfga.layers.GeometricAlgebraLayer

Layer for converting tensors with given blade kind to geometric algebra tensors.

Args:

algebra: GeometricAlgebra instance to use kind: blade kind indices to interpret the last axis of the input tensor as

call(inputs)[source]

This is where the layer’s logic lives.

Note here that call() method in tf.keras is little bit different from keras API. In keras API, you can pass support masking for layers as additional arguments. Whereas tf.keras has compute_mask() method to support masking.

Args:

inputs: Input tensor, or list/tuple of input tensors. *args: Additional positional arguments. Currently unused. **kwargs: Additional keyword arguments. Currently unused.

Returns:

A tensor or list/tuple of tensors.

compute_output_shape(input_shape)[source]

Computes the output shape of the layer.

If the layer has not been built, this method will call build on the layer. This assumes that the layer will later be used with inputs that match the input shape provided here.

Args:
input_shape: Shape tuple (tuple of integers)

or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns:

An input shape tuple.

get_config()[source]

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

tfga.mv module

Defines the MultiVector class which is used as a convenience wrapper for GeometricAlgebra operations.

class tfga.mv.MultiVector(blade_values: tf.Tensor, algebra: GeometricAlgebra)[source]

Bases: object

Wrapper for geometric algebra tensors using GeometricAlgebra operations in a less verbose way using operators.

property algebra

GeometricAlgebra instance this multivector belongs to.

approx_exp(order: int = 50) self[source]

Approximate exponential. See GeometricAlgebra.approx_exp().

approx_log(order: int = 50) self[source]

Approximate logarithm. See GeometricAlgebra.approx_log().

property batch_shape

Batch shape of the multivector (ie. the shape of all axes except for the last one in the geometric algebra tensor).

conjugation() self[source]

Conjugation. See GeometricAlgebra.conjugation().

dual() self[source]

Dual. See GeometricAlgebra.dual().

exp(square_scalar_tolerance: Union[float, None] = 0.0001) self[source]

Exponential. See GeometricAlgebra.exp().

geom_conv1d(kernel: self, stride: int, padding: str, dilations: Union[int, None] = None) self[source]

1D convolution. See GeometricAlgebra.geom_conv1d().

grade_automorphism() self[source]

Grade automorphism. See GeometricAlgebra.grade_automorphism().

inverse() self[source]

Inverse. See GeometricAlgebra.inverse().

is_pure_kind(kind: tfga.blades.BladeKind) bool[source]

Whether the MultiVector is of a pure kind.

simple_inverse() self[source]

Simple inverse. See GeometricAlgebra.simple_inverse().

property tensor

Geometric algebra tensor holding the values of this multivector.

tfga.mv_ops module

Operations on geometric algebra tensors used internally.

tfga.mv_ops.mv_conv1d(a_blade_values: tensorflow.python.framework.ops.Tensor, k_blade_values: tensorflow.python.framework.ops.Tensor, cayley: tensorflow.python.framework.ops.Tensor, stride: int, padding: str, dilations: Optional[int] = None) tensorflow.python.framework.ops.Tensor[source]
tfga.mv_ops.mv_grade_automorphism(a_blade_values, algebra_blade_degrees)[source]
tfga.mv_ops.mv_multiply(a_blade_values: tensorflow.python.framework.ops.Tensor, b_blade_values: tensorflow.python.framework.ops.Tensor, cayley: tensorflow.python.framework.ops.Tensor) tensorflow.python.framework.ops.Tensor[source]
tfga.mv_ops.mv_reversion(a_blade_values, algebra_blade_degrees)[source]

tfga.tfga module

Provides classes and operations for performing geometric algebra with TensorFlow.

The GeometricAlgebra class is used to construct the algebra given a metric. It exposes methods for operating on tf.Tensor instances where their last axis is interpreted as blades of the algebra.

class tfga.tfga.GeometricAlgebra(metric: List[float])[source]

Bases: object

Class used for performing geometric algebra operations on tf.Tensor instances. Exposes methods for operating on tf.Tensor instances where their last axis is interpreted as blades of the algebra. Holds the metric and other quantities derived from it.

approx_exp(a: tensorflow.python.framework.ops.Tensor, order: int = 50) tensorflow.python.framework.ops.Tensor[source]

Returns an approximation of the exponential using a centered taylor series.

Args:

a: Geometric algebra tensor to return exponential for order: order of the approximation

Returns:

Approximation of exp(a)

approx_log(a: tensorflow.python.framework.ops.Tensor, order: int = 50) tensorflow.python.framework.ops.Tensor[source]

Returns an approximation of the natural logarithm using a centered taylor series. Only converges for multivectors where ||mv - 1|| < 1.

Args:

a: Geometric algebra tensor to return logarithm for order: order of the approximation

Returns:

Approximation of log(a)

property basis_mvs: tensorflow.python.framework.ops.Tensor

List of basis vectors as tf.Tensor.

property blade_degrees: tensorflow.python.framework.ops.Tensor

List of blade-degree for each blade in the algebra.

property blade_mvs: tensorflow.python.framework.ops.Tensor

List of all blade tensors in the algebra.

property blades: List[str]

List of all blade names.

Blades are all possible independent combinations of basis vectors. Basis vectors are named starting from “0” and counting up. The scalar blade is the empty string “”.

Example - Bases: [“0”, “1”, “2”] - Blades: [“”, “0”, “1”, “2”, “01”, “02”, “12”, “012”]

property cayley: tensorflow.python.framework.ops.Tensor

MxMxM tensor where M is the number of basis blades in the algebra. Used for calculating the geometric product:

a_i, b_j, cayley_ijk -> c_k

property cayley_inner: tensorflow.python.framework.ops.Tensor

Analagous to cayley but for inner product.

property cayley_outer: tensorflow.python.framework.ops.Tensor

Analagous to cayley but for outer product.

conjugation(tensor: tensorflow.python.framework.ops.Tensor) tensorflow.python.framework.ops.Tensor[source]

Combines reversion and grade automorphism. See https://en.wikipedia.org/wiki/Paravector#Clifford_conjugation.

Args:

tensor: Geometric algebra tensor to return conjugate for

Returns:

Geometric algebra tensor after reversion() and grade_automorphism()

dual(tensor: tensorflow.python.framework.ops.Tensor) tensorflow.python.framework.ops.Tensor[source]

Returns the dual of the geometric algebra tensor.

Args:

tensor: Geometric algebra tensor to return dual for

Returns:

Dual of the geometric algebra tensor

property dual_blade_indices: tensorflow.python.framework.ops.Tensor

Indices of the dual blades for each blade.

property dual_blade_signs: tensorflow.python.framework.ops.Tensor

Signs of the dual blades for each blade.

e(*blades: List[str]) tensorflow.python.framework.ops.Tensor[source]

Returns a geometric algebra tf.Tensor with the given blades set to 1.

Args:

blades: list of blade names, can be unnormalized

Returns:

tf.Tensor with blades set to 1

exp(a: tensorflow.python.framework.ops.Tensor, square_scalar_tolerance: Optional[float] = 0.0001) tensorflow.python.framework.ops.Tensor[source]

Returns the exponential of the passed geometric algebra tensor. Only works for multivectors that square to scalars.

Args:

a: Geometric algebra tensor to return exponential for square_scalar_tolerance: Tolerance to use for the square scalar check

or None if the check should be skipped

Returns:

exp(a)

ext_prod(a: tensorflow.python.framework.ops.Tensor, b: tensorflow.python.framework.ops.Tensor) tensorflow.python.framework.ops.Tensor[source]

Returns the exterior product of two geometric algebra tensors.

Args:

a: Geometric algebra tensor on the left hand side of the exterior product b: Geometric algebra tensor on the right hand side of the exterior product

Returns:

exterior product of a and b

from_scalar(scalar: numbers.Number) tensorflow.python.framework.ops.Tensor[source]

Creates a geometric algebra tf.Tensor with scalar elements.

Args:

scalar: Elements to be used as scalars

Returns:

Geometric algebra tf.Tensor from scalars

from_tensor(tensor: tensorflow.python.framework.ops.Tensor, blade_indices: tensorflow.python.framework.ops.Tensor) tensorflow.python.framework.ops.Tensor[source]

Creates a geometric algebra tf.Tensor from a tf.Tensor and blade indices. The blade indices have to align with the last axis of the tensor.

Args:

tensor: tf.Tensor to take as values for the geometric algebra tensor blade_indices: Blade indices corresponding to the tensor. Can be obtained from blade names eg. using get_kind_blade_indices() or as indices from the blades list property.

Returns:

Geometric algebra tf.Tensor from tensor and blade indices

from_tensor_with_kind(tensor: tensorflow.python.framework.ops.Tensor, kind: tfga.blades.BladeKind) tensorflow.python.framework.ops.Tensor[source]

Creates a geometric algebra tf.Tensor from a tf.Tensor and a kind. The kind’s blade indices have to align with the last axis of the tensor.

Args:

tensor: tf.Tensor to take as values for the geometric algebra tensor kind: Kind corresponding to the tensor

Returns:

Geometric algebra tf.Tensor from tensor and kind

geom_conv1d(a: tensorflow.python.framework.ops.Tensor, k: tensorflow.python.framework.ops.Tensor, stride: int, padding: str, dilations: Optional[int] = None) tensorflow.python.framework.ops.Tensor[source]

Returns the 1D convolution of a sequence with a geometric algebra tensor kernel. The convolution is performed using the geometric product.

Args:
a: Input geometric algebra tensor of shape

[…, Length, ChannelsIn, Blades]

k: Geometric algebra tensor for the convolution kernel of shape

[KernelSize, ChannelsIn, ChannelsOut, Blades]

stride: Stride to use for the convolution padding: “SAME” (zero-pad input length so output

length == input length / stride) or “VALID” (no padding)

Returns:

Geometric algbra tensor of shape […, OutputLength, ChannelsOut, Blades] representing a convolved with k

geom_prod(a: tensorflow.python.framework.ops.Tensor, b: tensorflow.python.framework.ops.Tensor) tensorflow.python.framework.ops.Tensor[source]

Returns the geometric product of two geometric algebra tensors.

Args:

a: Geometric algebra tensor on the left hand side of the geometric product b: Geometric algebra tensor on the right hand side of the geometric product

Returns:

geometric product of a and b

get_blade_indices_of_degree(degree: int) tensorflow.python.framework.ops.Tensor[source]

Find all indices of blades of the given degree.

Args:

degree: degree to return blades for

Returns:

indices of blades with the given degree in the algebra

get_kind_blade_indices(kind: tfga.blades.BladeKind, invert: bool = False) tensorflow.python.framework.ops.Tensor[source]

Find all indices of blades of a given kind in the algebra.

Args:

kind: kind of blade to give indices for invert: whether to return all blades not of the kind

Returns:

indices of blades of a given kind in the algebra

grade_automorphism(tensor: tensorflow.python.framework.ops.Tensor) tensorflow.python.framework.ops.Tensor[source]

Returns the geometric algebra tensor with odd grades negated. See https://en.wikipedia.org/wiki/Paravector#Grade_automorphism.

Args:

tensor: Geometric algebra tensor to return grade automorphism for

Returns:

Geometric algebra tensor with odd grades negated

inner_prod(a: tensorflow.python.framework.ops.Tensor, b: tensorflow.python.framework.ops.Tensor) tensorflow.python.framework.ops.Tensor[source]

Returns the inner product of two geometric algebra tensors.

Args:

a: Geometric algebra tensor on the left hand side of the inner product b: Geometric algebra tensor on the right hand side of the inner product

Returns:

inner product of a and b

int_pow(a: tensorflow.python.framework.ops.Tensor, n: int) tensorflow.python.framework.ops.Tensor[source]

Returns the geometric algebra tensor to the power of an integer using repeated multiplication.

Args:

a: Geometric algebra tensor to raise n: integer power to raise the multivector to

Returns:

a to the power of n

inverse(a: tensorflow.python.framework.ops.Tensor) tensorflow.python.framework.ops.Tensor[source]

Returns the inverted geometric algebra tensor X^-1 such that X * X^-1 = 1.

Using Shirokov’s inverse algorithm that works in arbitrary dimensions, see https://arxiv.org/abs/2005.04015 Theorem 4.

Args:

a: Geometric algebra tensor to return inverse for

Returns:

inverted geometric algebra tensor

is_pure(tensor: tensorflow.python.framework.ops.Tensor, blade_indices: tensorflow.python.framework.ops.Tensor) bool[source]

Returns whether the given tensor is purely of the given blades and has no non-zero values for blades not in the given blades.

Args:

tensor: tensor to check purity for blade_indices: blade indices to check purity for

Returns:

Whether the tensor is purely of the given blades and has no non-zero values for blades not in the given blades

is_pure_kind(tensor: tensorflow.python.framework.ops.Tensor, kind: tfga.blades.BladeKind) bool[source]

Returns whether the given tensor is purely of a given kind and has no non-zero values for blades not of the kind.

Args:

tensor: tensor to check purity for kind: kind of blade to check purity for

Returns:

Whether the tensor is purely of a given kind and has no non-zero values for blades not of the kind

keep_blades(a: tensorflow.python.framework.ops.Tensor, blade_indices: List[int]) tensorflow.python.framework.ops.Tensor[source]

Takes a geometric algebra tensor and returns it with only the given blade_indices as non-zeros.

Args:

a: Geometric algebra tensor to copy blade_indices: Indices for blades to keep

Returns:

a with only blade_indices components as non-zeros

keep_blades_with_name(a: tensorflow.python.framework.ops.Tensor, blade_names: Union[List[str], str]) tensorflow.python.framework.ops.Tensor[source]

Takes a geometric algebra tensor and returns it with only the given blades as non-zeros.

Args:

a: Geometric algebra tensor to copy blade_names: Blades to keep

Returns:

a with only blade_names components as non-zeros

property max_degree: int

Highest blade degree in the algebra.

property metric: tensorflow.python.framework.ops.Tensor

Metric list which contains the number that each basis vector in the algebra squares to (ie. the diagonal of the metric tensor).

mv_repr(a: tensorflow.python.framework.ops.Tensor) str[source]

Returns a string representation for the given geometric algebra tensor.

Args:

a: Geometric algebra tensor to return the representation for

Returns:

string representation for a

property num_blades: int

Total number of blades in the algebra.

print(*args, **kwargs)[source]

Same as the default print function but formats tf.Tensor instances that have as many elements on their last axis as the algebra has blades using mv_repr().

reg_prod(a: tensorflow.python.framework.ops.Tensor, b: tensorflow.python.framework.ops.Tensor) tensorflow.python.framework.ops.Tensor[source]

Returns the regressive product of two geometric algebra tensors.

Args:

a: Geometric algebra tensor on the left hand side of the regressive product b: Geometric algebra tensor on the right hand side of the regressive product

Returns:

regressive product of a and b

reversion(tensor: tensorflow.python.framework.ops.Tensor) tensorflow.python.framework.ops.Tensor[source]

Returns the grade-reversed geometric algebra tensor. See https://en.wikipedia.org/wiki/Paravector#Reversion_conjugation.

Args:

tensor: Geometric algebra tensor to return grade-reversion for

Returns:

Grade-reversed geometric algebra tensor

select_blades(a: tensorflow.python.framework.ops.Tensor, blade_indices: List[int]) tensorflow.python.framework.ops.Tensor[source]

Takes a geometric algebra tensor and returns a tf.Tensor with the blades in blade_indices on the last axis.

Args:

a: Geometric algebra tensor to copy blade_indices: Indices for blades to select

Returns:

tf.Tensor based on a with blade_indices on last axis.

select_blades_with_name(a: tensorflow.python.framework.ops.Tensor, blade_names: Union[List[str], str]) tensorflow.python.framework.ops.Tensor[source]

Takes a geometric algebra tensor and returns a tf.Tensor with the blades in blade_names on the last axis.

Args:

a: Geometric algebra tensor to copy blade_names: Blades to keep

Returns:

tf.Tensor based on a with blade_names on last axis.

simple_inverse(a: tensorflow.python.framework.ops.Tensor) tensorflow.python.framework.ops.Tensor[source]

Returns the inverted geometric algebra tensor X^-1 such that X * X^-1 = 1. Only works for elements that square to scalars. Faster than the general inverse.

Args:

a: Geometric algebra tensor to return inverse for

Returns:

inverted geometric algebra tensor

Module contents