Documentation ¶
Overview ¶
vector offers a set of utility function relating to slices of field element and that are commonly used as part of the repo.
Index ¶
- Constants
- func Add(res, a, b []fext.Element, extras ...[]fext.Element)
- func AddExt(res, a, b []fext.Element, extras ...[]fext.Element)
- func DeepCopy(pol []fext.Element) []fext.Element
- func Equal(a, b []fext.Element) bool
- func Fill(v []fext.Element, val fext.Element)
- func ForTest(xs ...int) []fext.Element
- func ForTestFromPairs(xs ...int) []fext.Element
- func ForTestFromVect(xs ...[fext.ExtensionDegree]int) []fext.Element
- func Interleave(vecs ...[]fext.Element) []fext.Element
- func IntoGnarkAssignment(msgData []fext.Element) []gnarkfext.Variable
- func MulElementWise(res, a, b []fext.Element)
- func PowerVec(x fext.Element, n int) []fext.Element
- func Prettify(a []fext.Element) string
- func PseudoRand(rng *rand.Rand, size int) []fext.Element
- func Rand(n int) []fext.Element
- func Repeat(x fext.Element, n int) []fext.Element
- func Reverse(v []fext.Element)
- func ScalarMul(res, vec []fext.Element, scalar fext.Element)
- func ScalarProd(a, b []fext.Element) fext.Element
- func Sub(res, a, b []fext.Element)
- func ZeroPad(v []fext.Element, newLen int) []fext.Element
- type Vector
- func (vector *Vector) Add(a, b Vector)
- func (vector *Vector) AsyncReadFrom(r io.Reader) (int64, error, chan error)
- func (vector *Vector) InnerProduct(other Vector) (res fext.Element)
- func (vector Vector) Len() int
- func (vector Vector) Less(i, j int) bool
- func (vector *Vector) MarshalBinary() (data []byte, err error)
- func (vector *Vector) Mul(a, b Vector)
- func (vector *Vector) ReadFrom(r io.Reader) (int64, error)
- func (vector *Vector) ScalarMul(a Vector, b *fext.Element)
- func (vector Vector) String() string
- func (vector *Vector) Sub(a, b Vector)
- func (vector *Vector) Sum() (res fext.Element)
- func (vector Vector) Swap(i, j int)
- func (vector *Vector) UnmarshalBinary(data []byte) error
- func (vector *Vector) WriteTo(w io.Writer) (int64, error)
Constants ¶
const (
Bytes = 64 // number of bytes needed to represent a Element
)
Variables ¶
This section is empty.
Functions ¶
func Add ¶
Add adds two vectors `a` and `b` and put the result in `res` `res` must be pre-allocated by the caller and res, a and b must all have the same size. res == a or res == b or both is valid assignment.
func Equal ¶
Equal compares a and b and returns a boolean indicating whether they contain the same value. The function assumes that a and b have the same length. It panics otherwise.
func ForTestFromPairs ¶
ForTestFromPairs groups the input into pairs. Each pair populates the first two coordinates of a field extension, and the function then returns a vector instantiated these field extension elements.
func ForTestFromVect ¶
func ForTestFromVect(xs ...[fext.ExtensionDegree]int) []fext.Element
ForTestFromVect computes a vector of field extensions, where each field extension is populated using one vector of size fext.ExtensionDegree
func Interleave ¶
Interleave interleave two vectors:
(a, a, a, a), (b, b, b, b) -> (a, b, a, b, a, b, a, b)
The vecs[i] vectors must all have the same length
func IntoGnarkAssignment ¶
IntoGnarkAssignment converts an array of field.Element into an array of frontend.Variable that can be used to assign a vector of frontend.Variable in a circuit or to generate a vector of constant in the circuit definition.
func MulElementWise ¶
MulElementWise multiplies two vectors element wise and write the result in res. res = a is a valid assignment.
func PowerVec ¶
PowerVec allocates and returns a vector of size n consisting of consecutive powers of x, starting from x^0 = 1 and ending on x^{n-1}. The function panics if given x=0 and returns an empty vector if n=0.
func PseudoRand ¶
PseudoRand generates a vector of field element with a given size using the provided random number generator
func ScalarMul ¶
ScalarMul multiplies a vector by a scalar - in place. The result should be preallocated or it is going to panic. res = vec is a valid parameter assignment.
func ScalarProd ¶
ScalarProd returns the scalar (inner) product of a and b. The function panics if a and b do not have the same size. If they have both empty vectors, the function returns 0.
func Sub ¶
Sub substracts two vectors `a` and `b` and put the result in `res` `res` must be pre-allocated by the caller and res, a and b must all have the same size. res == a or res == b or both is valid assignment.
Types ¶
type Vector ¶
Vector represents a slice of Element.
It implements the following interfaces:
- Stringer
- io.WriterTo
- io.ReaderFrom
- encoding.BinaryMarshaler
- encoding.BinaryUnmarshaler
- sort.Interface
func (*Vector) Add ¶
Add adds two vectors element-wise and stores the result in self. It panics if the vectors don't have the same length.
func (*Vector) AsyncReadFrom ¶
AsyncReadFrom reads a vector of big endian encoded Element. Length of the vector must be encoded as a uint32 on the first 4 bytes. It consumes the needed bytes from the reader and returns the number of bytes read and an error if any. It also returns a channel that will be closed when the validation is done. The validation consist of checking that the elements are smaller than the modulus, and converting them to montgomery form.
func (*Vector) InnerProduct ¶
InnerProduct computes the inner product of two vectors. It panics if the vectors don't have the same length.
func (Vector) Less ¶
Less reports whether the element with index i should sort before the element with index j.
func (*Vector) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler
func (*Vector) Mul ¶
Mul multiplies two vectors element-wise and stores the result in self. It panics if the vectors don't have the same length.
func (*Vector) ReadFrom ¶
ReadFrom implements io.ReaderFrom and reads a vector of big endian encoded Element. Length of the vector must be encoded as a uint32 on the first 4 bytes.
func (*Vector) ScalarMul ¶
ScalarMul multiplies a vector by a scalar element-wise and stores the result in self. It panics if the vectors don't have the same length.
func (*Vector) Sub ¶
Sub subtracts two vectors element-wise and stores the result in self. It panics if the vectors don't have the same length.
func (*Vector) UnmarshalBinary ¶
UnmarshalBinary implements encoding.BinaryUnmarshaler