Package dk.alexandra.fresco.stat.utils
Class VectorUtils
Object
VectorUtils
public class VectorUtils extends Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceVectorUtils.EntrywiseBinaryOp<A,B,C>static interfaceVectorUtils.EntrywiseUnaryOp<A,C> -
Constructor Summary
Constructors Constructor Description VectorUtils() -
Method Summary
Modifier and Type Method Description static List<DRes<SFixed>>add(List<DRes<SFixed>> a, List<DRes<SFixed>> b, ProtocolBuilderNumeric builder)Add two secret vectors.static ArrayList<DRes<SFixed>>div(List<DRes<SFixed>> vector, DRes<SFixed> scalar, ProtocolBuilderNumeric builder)Divide all values in the given vector by the scalar.static <A, B, C> ArrayList<C>entrywiseBinaryOp(List<A> a, List<B> b, VectorUtils.EntrywiseBinaryOp<A,B,C> op, ProtocolBuilderNumeric builder)static <A, C> ArrayList<C>entrywiseUnaryOp(List<A> a, VectorUtils.EntrywiseUnaryOp<A,C> op, ProtocolBuilderNumeric builder)static DRes<SFixed>innerProductWithBitvector(List<DRes<SInt>> a, List<DRes<SFixed>> b, ProtocolBuilderNumeric builder)Compute the inner product of a secret vector with a secret bit vector.static DRes<SFixed>innerProductWithBitvectorPublic(List<DRes<SInt>> a, List<Double> b, ProtocolBuilderNumeric builder)Compute the inner product of a public vector with a secret bit vector.static ArrayList<DRes<SInt>>input(List<BigInteger> list, int party, ProtocolBuilderNumeric builder)static <T> ArrayList<T>listBuilder(int size, IntFunction<T> generator)Build a list of the given size using a generator.static List<DRes<SInt>>mult(List<DRes<SInt>> a, List<DRes<SInt>> b, ProtocolBuilderNumeric protocolBuilderNumeric)Subtract two secret vectors.static ArrayList<DRes<SInt>>negate(List<DRes<SInt>> a, ProtocolBuilderNumeric builder)Compute the entry-wise binary negation of a secret vectorstatic ArrayList<DRes<BigInteger>>open(List<DRes<SInt>> a, ProtocolBuilderNumeric builder)static ArrayList<DRes<SFixed>>scale(List<DRes<SFixed>> vector, double scalar, ProtocolBuilderNumeric builder)Scale all values in the given vector by the scalar.static ArrayList<DRes<SFixed>>scale(List<DRes<SFixed>> vector, DRes<SFixed> scalar, ProtocolBuilderNumeric builder)Scale all values in the given vector by the scalar.static ArrayList<DRes<SInt>>scaleInt(List<DRes<SInt>> vector, DRes<SInt> scalar, ProtocolBuilderNumeric builder)Scale all values in the given vector by the scalar.static ArrayList<DRes<SFixed>>sub(List<DRes<SFixed>> a, List<DRes<SFixed>> b, ProtocolBuilderNumeric builder)Subtract two secret vectors.static List<DRes<SFixed>>sum(List<List<DRes<SFixed>>> a, ProtocolBuilderNumeric builder)Add a list of secret vectors.
-
Constructor Details
-
VectorUtils
public VectorUtils()
-
-
Method Details
-
innerProductWithBitvectorPublic
public static DRes<SFixed> innerProductWithBitvectorPublic(List<DRes<SInt>> a, List<Double> b, ProtocolBuilderNumeric builder)Compute the inner product of a public vector with a secret bit vector.- Parameters:
a- A secret bit vectorb- A public vectorbuilder- The builder to use.- Returns:
- The inner product of a and b.
-
innerProductWithBitvector
public static DRes<SFixed> innerProductWithBitvector(List<DRes<SInt>> a, List<DRes<SFixed>> b, ProtocolBuilderNumeric builder)Compute the inner product of a secret vector with a secret bit vector.- Parameters:
a- A secret bit vectorb- A secret vectorbuilder- The builder to use.- Returns:
- The inner product of a and b.
-
listBuilder
Build a list of the given size using a generator. Note that this is not lazy -- the generator is called for all indices when this is called.- Type Parameters:
T-- Parameters:
size- The size of the list.generator- The generator used to create the entries.- Returns:
- A list containg the created elements.
-
scale
public static ArrayList<DRes<SFixed>> scale(List<DRes<SFixed>> vector, DRes<SFixed> scalar, ProtocolBuilderNumeric builder)Scale all values in the given vector by the scalar.- Parameters:
vector- A secret vector.scalar- A secret scalar.builder- The builder to use.- Returns:
- A scaled vector.
-
scale
public static ArrayList<DRes<SFixed>> scale(List<DRes<SFixed>> vector, double scalar, ProtocolBuilderNumeric builder)Scale all values in the given vector by the scalar.- Parameters:
vector- A secret vector.scalar- A public scalar.builder- The builder to use.- Returns:
- A scaled vector.
-
scaleInt
public static ArrayList<DRes<SInt>> scaleInt(List<DRes<SInt>> vector, DRes<SInt> scalar, ProtocolBuilderNumeric builder)Scale all values in the given vector by the scalar.- Parameters:
vector- A secret vector.scalar- A public scalar.builder- The builder to use.- Returns:
- A scaled vector.
-
div
public static ArrayList<DRes<SFixed>> div(List<DRes<SFixed>> vector, DRes<SFixed> scalar, ProtocolBuilderNumeric builder)Divide all values in the given vector by the scalar.- Parameters:
vector- A secret vector.scalar- A secret scalar.builder- The builder to use.- Returns:
-
add
public static List<DRes<SFixed>> add(List<DRes<SFixed>> a, List<DRes<SFixed>> b, ProtocolBuilderNumeric builder)Add two secret vectors.- Parameters:
a- A secret vector.b- A secret scalar.builder- The builder to use.- Returns:
- a+b
-
sum
Add a list of secret vectors.- Parameters:
a- A list of secret vectors.builder- The builder to use.- Returns:
- sum(a)
-
sub
public static ArrayList<DRes<SFixed>> sub(List<DRes<SFixed>> a, List<DRes<SFixed>> b, ProtocolBuilderNumeric builder)Subtract two secret vectors.- Parameters:
a- A secret vector.b- A secret scalar.builder- The builder to use.- Returns:
- a-b
-
negate
Compute the entry-wise binary negation of a secret vector- Parameters:
a- A secret 0-1-vector.builder- The builder to use.- Returns:
- not a
-
open
-
mult
public static List<DRes<SInt>> mult(List<DRes<SInt>> a, List<DRes<SInt>> b, ProtocolBuilderNumeric protocolBuilderNumeric)Subtract two secret vectors.- Parameters:
a- A secret vector.b- A secret scalar.protocolBuilderNumeric- The builder to use.- Returns:
- a.*b
-
entrywiseBinaryOp
public static <A, B, C> ArrayList<C> entrywiseBinaryOp(List<A> a, List<B> b, VectorUtils.EntrywiseBinaryOp<A,B,C> op, ProtocolBuilderNumeric builder) -
entrywiseUnaryOp
public static <A, C> ArrayList<C> entrywiseUnaryOp(List<A> a, VectorUtils.EntrywiseUnaryOp<A,C> op, ProtocolBuilderNumeric builder) -
input
public static ArrayList<DRes<SInt>> input(List<BigInteger> list, int party, ProtocolBuilderNumeric builder)
-