cicada.arithmetic module
Functionality for working with field arithmetic.
- class cicada.arithmetic.Field(order=None)[source]
Bases:
objectPerforms arithmetic in an integer field.
Field arrays are
numpy.ndarrayinstances containing Python integers.- Parameters:
order (
int, optional) – Field size. Defaults to the largest prime less than \(2^{64}\).
- __call__(object)[source]
Create a field array from an array-like object.
- Parameters:
object (array-like, required) – The array to be converted.
- Returns:
array – The corresponding field array.
- Return type:
- add(lhs, rhs)[source]
Element-wise addition of two field arrays.
- Parameters:
lhs (
numpy.ndarray, required) – First operand.rhs (
numpy.ndarray, required) – Second operand.
- Returns:
sum – The sum of the two operands.
- Return type:
- property bits
Return the number of bits required to store field values.
- property bytes
Return the number of bytes required to store field values.
- property dtype
Return the
numpy.dtypeused for field arrays.
- full_like(other, fill_value)[source]
Return a field array of values with the same shape as another array.
- Parameters:
other (array-like, required) – The result will have the same shape as this array.
fill_value (
int, required) – Field value that will be assigned to every element in the result array.
- Returns:
array – Field array of fill_value with the same shape as other.
- Return type:
- inplace_add(lhs, rhs)[source]
Add field arrays in-place.
- Parameters:
lhs (
numpy.ndarray, required) – First operand.rhs (
numpy.ndarray, required) – Second operand. This value will be added in-place to lhs.
- inplace_subtract(lhs, rhs)[source]
Subtract field arrays in-place.
- Parameters:
lhs (
numpy.ndarray, required) – First operand.rhs (
numpy.ndarray, required) – Second operand. This value will be subtracted in-place from lhs.
- multiply(lhs, rhs)[source]
Element-wise multiplication of two field arrays.
- Parameters:
lhs (
numpy.ndarray, required) – First operand.rhs (
numpy.ndarray, required) – Second operand.
- Returns:
product – Element-wise product of lhs and rhs.
- Return type:
- negative(array)[source]
Element-wise negation of a field array.
- Parameters:
array (
numpy.ndarray, required) – The array to negate.- Returns:
negated – Array with the same shape as array, containing the negated elements.
- Return type:
- ones(shape)[source]
Return a field array containing ones.
- Parameters:
shape (
tuple, required) – The shape of the output array.- Returns:
array – Field array of ones with shape shape.
- Return type:
- ones_like(other)[source]
Return a field array of ones with the same shape as another array.
- Parameters:
other (array-like, required) – The result will have the same shape as this array.
- Returns:
array – Field array of zeros with the same shape as other.
- Return type:
- property order
Return the field order.
- property posbound
Return the boundary between positive and negative values.
- subtract(lhs, rhs)[source]
Return the element-wise difference between two field arrays.
- Parameters:
lhs (
numpy.ndarray, required) – First operand.rhs (
numpy.ndarray, required) – Second operand.
- Returns:
dif – The difference between the two operands.
- Return type:
- sum(operand)[source]
Sum the elements of a field array.
- Parameters:
operand (
numpy.ndarray, required) – Operand.- Returns:
sum – The sum of the input array elements.
- Return type:
- uniform(*, size, generator)[source]
Return a random field array, uniformly distributed over the field.
- Parameters:
size (
tuple, required) – A tuple defining the shape of the output array.generator (
numpy.random.Generator, required) – A psuedorandom number generator for sampling.
- Returns:
random – Field array containing uniform random values with shape size.
- Return type:
- zeros(shape)[source]
Return a field array containing zeros.
- Parameters:
shape (
tuple, required) – The shape of the output array.- Returns:
array – Field array of zeros with shape shape.
- Return type:
- zeros_like(other)[source]
Return a field array of zeros with the same shape as another array.
- Parameters:
other (array-like, required) – The result will have the same shape as this array.
- Returns:
array – Field array of zeros with the same shape as other.
- Return type: