bgtrees.finite_gpufields package
Subpackages
- bgtrees.finite_gpufields.cuda_operators package
Submodules
bgtrees.finite_gpufields.finite_fields_tf module
TensorFlow extension to FiniteFields. This is a (partial) port of https://github.com/GDeLaurentis/pyadic/blob/main/pyadic/finite_field.py with some modifications geared towards the usage of GPUs.
The TensorFlow ExtensionType FiniteField act as a container. Any operation between two FiniteField will result in another FiniteField
Note: all operations between two FiniteField assume that p is going to always be prime and the same. Any checks should have occured before getting to this function.
- class bgtrees.finite_gpufields.finite_fields_tf.FiniteField(n, p=None)
Bases:
ExtensionType
TF implementation of Finite Fields Finite Fields are integer tensor which override certain methods
- n: Tensor
- p: int
- reshape_ff(new_shape)
Reshape the tensor contained in this FF
- property shape
- transpose_ff(permutation)
- property values
- zero_panning(front=True, m=4)
Pan with 0s the finite Field this can only be used (hence the experimental) when the shape of the values is (n, 1) or (1, n) and n < m, the panning happens in the n dimension up to m
- bgtrees.finite_gpufields.finite_fields_tf.finite_field_expand_dims(input, axis, name=None)
Override expand dims for FiniteField containers
- bgtrees.finite_gpufields.finite_fields_tf.finite_field_reduce_prod(input_tensor, axis=None, keepdims=False, name=None)
Override the reduce_sum operation for a FiniteField container
- bgtrees.finite_gpufields.finite_fields_tf.finite_field_reduce_sum(input_tensor, axis=None, keepdims=False, name=None)
Override the reduce_sum operation for a FiniteField container
- bgtrees.finite_gpufields.finite_fields_tf.finite_field_squeeze(input, axis, name=None)
Override squeeze for FiniteField containers
- bgtrees.finite_gpufields.finite_fields_tf.finite_field_unary_operations(api_func, x)
- bgtrees.finite_gpufields.finite_fields_tf.finite_field_unstack(value, num=None, axis=0, name='unstack')
Override the unstack function to act on a FiniteField container Returns a list of FiniteFields where the value of the FF is unstacked
- bgtrees.finite_gpufields.finite_fields_tf.generate_finite_field(list_of_ints, cardinality)
This function generates a finite field given a list of ints and the cardinality of the field Note that list_of_ints could also be a list of longs coming from C++ in principle np.array should be able to deal with both Returns a FiniteField which in C++ can be taken as a PyObject* and passed around
- bgtrees.finite_gpufields.finite_fields_tf.get_imaginary_for(p)
Get the value of sqrt(ModP(-1, p))
- bgtrees.finite_gpufields.finite_fields_tf.test_me(a, b)
This function takes two finite fields (which in principle might be coming from C++) performs and operaton on them and then converts the result to a numpy array so that it can be easily parsed by TensorFlow
bgtrees.finite_gpufields.operations module
Collections of operation that can be performed with batched finite fields. In all cases, the batch dimension is denoted as r in the einsum-string.
When the operation can be passed through tf.einsum safely (i.e., a simple permutation of indices), it will be done in this way.
- bgtrees.finite_gpufields.operations.ff_dot_product(x, y, rank_x=None, rank_y=None)
Perform a dot product between two batched Finite Fields Uses a CUDA kernel underneath
Equivalent einsum string: “rij,rjk->rik”
- bgtrees.finite_gpufields.operations.ff_dot_product_single_batch(x, y, rank_x=None, rank_y=None)
Perform a dot product between one batch (x) and unbatched (y) Finite Fields Uses a CUDA kernel underneath
Equivalent einsum string: “rij,jk->rik”
- bgtrees.finite_gpufields.operations.ff_dot_product_tris(x, y, rank_x=None, rank_y=None)
Wrapper for a product rijk->rklmn with k contracted.
This function reshapes the input and then applies wrapper_dot_product. It is a transitional function during development.
TODO: Make all functions into one that is able to dispatch the right operation upon receiving an einsum string.
- It assumes both x and y are batched, i.e., the equivalent operation is:
rijk, rklm -> rijlm
It works by: - collapsing the ij and lm axes, - performing the operation rAk, rkB -> rAB, - and then unrolling back A and B.
- bgtrees.finite_gpufields.operations.ff_dot_product_tris_single_batch(x, y, rank_x=None, rank_y=None)
Single batched version of ff_dot_product_tris TODO: it should eventually go as well
- bgtrees.finite_gpufields.operations.ff_einsum_generic(einstr, *args)
Tries to automagically select the right operation given the einstr.
Currently only works for: - ff_tensor_product - ff_index_permutation
- bgtrees.finite_gpufields.operations.ff_tensor_product(einstr, x, y)
- Wrapper to apply the tensor product for Finite Fields
A_ijk…B_lmn… = C_ijk…lmn…
- It allows batched operation, i.e.,
A_rijk…B_lmn… = C_rijk…lmn…
- or
A_rijk…B_rlmn… = C_rijk…lmn…
It uses tf.einsum underneath, but checks that it is a tensor product and hence it is safe to be used with finite fields. The main use case is to perform a tensor product where one (or both) tensors are actually batched
Module contents
The finite_gpufields module provides primitives to utilize the FiniteField type.