vector

package
v0.0.0-...-18b2cfc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

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

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(res, a, b []field.Element, extras ...[]field.Element)

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 DeepCopy

func DeepCopy(pol []field.Element) []field.Element

DeepCopy deep-copies the input vector

func Equal

func Equal(a, b []field.Element) bool

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 Fill

func Fill(v []field.Element, val field.Element)

Fill a vector `vec` in place with the given value `val`.

func ForTest

func ForTest(xs ...int) []field.Element

ForTest returns a vector instantiated from a list of integers.

func Interleave

func Interleave(vecs ...[]field.Element) []field.Element

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

func IntoGnarkAssignment(msgData []field.Element) []frontend.Variable

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

func MulElementWise(res, a, b []field.Element)

MulElementWise multiplies two vectors element wise and write the result in res. res = a is a valid assignment.

func PowerVec

func PowerVec(x field.Element, n int) []field.Element

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 Prettify

func Prettify(a []field.Element) string

Prettify returns a string representing `a` in a human-readable fashion

func PseudoRand

func PseudoRand(rng *rand.Rand, size int) []field.Element

PseudoRand generates a vector of field element with a given size using the provided random number generator

func Rand

func Rand(n int) []field.Element

Rand creates a random vector of size n

func Repeat

func Repeat(x field.Element, n int) []field.Element

Repeat returns a vector of size n whose values are all equal to x.

func Reverse

func Reverse(v []field.Element)

Reverse the elements of a vector inplace

func ScalarMul

func ScalarMul(res, vec []field.Element, scalar field.Element)

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

func ScalarProd(a, b []field.Element) field.Element

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

func Sub(res, a, b []field.Element)

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.

func ZeroPad

func ZeroPad(v []field.Element, newLen int) []field.Element

ZeroPad pads a vector to a given length. If the newLen is smaller than len(v), the function panic. It pads to the right (appending, not prepending) The resulting slice is allocated by the function, so it can be safely modified by the caller after the function returns.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL