general

package
v0.0.0-...-db52ea4 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CPMatMult0

func CPMatMult0(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, B *mat.Dense) crypto.CipherMatrix

Cheat to compute ground truth

func CPMatMult1

func CPMatMult1(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, B *mat.Dense) crypto.CipherMatrix

All-pairwise inner product version

func CPMatMult2

func CPMatMult2(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, B *mat.Dense) crypto.CipherMatrix

Duplicate individual elements in A

func CPMatMult2F

func CPMatMult2F(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, B *mat.Dense) crypto.CipherMatrix

Duplicate individual elements in A

func CPMatMult3

func CPMatMult3(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, B *mat.Dense) crypto.CipherMatrix

Pre-rotate A, all shifts, mult with diagonals from B

func CPMatMult4

func CPMatMult4(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, B *mat.Dense, maxLevel int) crypto.CipherMatrix

Pre-rotate A, baby step giant step version, mult with diagonals from B

func CPMatMult4CachedB

func CPMatMult4CachedB(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, CachedB PlainMatrixDiagCache) crypto.CipherMatrix

func CPMatMult4V2CachedB

func CPMatMult4V2CachedB(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, maxLevel int, CachedB PlainMatrixDiagCache) crypto.CipherMatrix

Generalized to levels >= 2

func CPMultAccWithoutMRedV1

func CPMultAccWithoutMRedV1(cryptoParams *crypto.CryptoParams, X crypto.CipherVector, Y crypto.PlainVector, Acc CipherVectorAccV1)

Multiply X and Y to add to Acc without modular reduction

func CPMultAccWithoutMRedV2

func CPMultAccWithoutMRedV2(X crypto.CipherVector, Y crypto.PlainVector, Acc CipherVectorAccV2)

func DCMatMulAAtB

func DCMatMulAAtB(cryptoParams *crypto.CryptoParams, mpcObj *mpc.MPC, A crypto.CipherMatrix, B crypto.CipherMatrix,
	nrows []int, ncol_out int, innerFn matmulInnerFn) crypto.CipherMatrix

func DCMatMulAAtBPlain

func DCMatMulAAtBPlain(cryptoParams *crypto.CryptoParams, mpcObj *mpc.MPC, A crypto.CipherMatrix, B crypto.PlainMatrix,
	nrows []int, ncol_out int, innerFn matmulPlainInnerFn) crypto.CipherMatrix

func EncodeDiag

func EncodeDiag(cryptoParams *crypto.CryptoParams, X BlockVector, index int, nrot int, level int) (crypto.PlainVector, bool)

index specifies which diagonal to extract applies right-rotation by nrot positions before encoding

func EncodeDiagBool

func EncodeDiagBool(X BlockVector, index int, slots int) bool

Return if a diagonal vector exists without extracting/encoding the vectors

func EncodeDiagWithEncoder

func EncodeDiagWithEncoder(cryptoParams *crypto.CryptoParams, X BlockVector, index int, nrot int, level int, enc ckks.Encoder) (crypto.PlainVector, bool)

func GetDiag

func GetDiag(dst []float64, X Block, dim int, index int) bool

index 0 is the main diagonal max size of Block is dim by dim and index ranges from 0 to dim-1 (mod dim) If given diagonal does not overlap with X (matrix might be smaller), returns false

func GetDiagBool

func GetDiagBool(X Block, dim int, index int) bool

Return if a diagonal vector exists without extracting elements

func MForm

func MForm(a, q uint64, u []uint64) (r uint64)

func MFormLvl

func MFormLvl(r *ring.Ring, level int, p1, p2 *ring.Poly)

func MatMult4StreamCompute

func MatMult4StreamCompute(cryptoParams *crypto.CryptoParams, A crypto.CipherMatrix, maxLevel int, cacheFilePrefix string) crypto.CipherMatrix

func Min

func Min(a int, b int) int

func Mod

func Mod(n int, modulus int) int

func ModularReduceV1

func ModularReduceV1(cryptoParams *crypto.CryptoParams, cva CipherVectorAccV1, outScale float64) crypto.CipherVector

func ModularReduceV2

func ModularReduceV2(cryptoParams *crypto.CryptoParams, cva CipherVectorAccV2, outScale float64) crypto.CipherVector

func MulCoeffsAndAdd128

func MulCoeffsAndAdd128(a, b []uint64, c []uint128)

func NetDQRenc

func NetDQRenc(cryptoParams *crypto.CryptoParams, mpcObj *mpc.MPC, A crypto.CipherMatrix, nrowsAll []int) crypto.CipherMatrix

Since required precision scales with 1/sqrt(n) maintain sqrt(n)*v for unit vectors v

func NetDQRplain

func NetDQRplain(cryptoParams *crypto.CryptoParams, mpcObj *mpc.MPC, A crypto.PlainMatrix, nrowsAll []int) crypto.CipherMatrix

NetDQRplain returns Q all zeros (or nil) (for pid=0), else returns share of Q for each party

func QXLazyNormStream

func QXLazyNormStream(cps *crypto.CryptoParams, mpcObj *mpc.MPC, Q crypto.CipherMatrix, Xcachefile string, XMean, XStdInv crypto.CipherVector, numInd int) (out crypto.CipherMatrix)

Multiply Q (kp by nsnp) with X (nsnp by nind) with lazy normalization of X Compute Q * S * (X - m * 1^T) as (Q * S) * X - ((Q * S) * m) * 1^T S: diagonal matrix containing 1/stdev of each SNP, m: column vector containing mean of each SNP

func QXtLazyNormStream

func QXtLazyNormStream(cps *crypto.CryptoParams, mpcObj *mpc.MPC, Q crypto.CipherMatrix, XTcachefile string, XMean, XStdInv crypto.CipherVector) (out crypto.CipherMatrix)

Multiply Q (kp by nind) with X^T (nind by nsnp) with lazy normalization of X Compute Q * (X^T - 1 * m^T) * S as ((Q * X^T) - ((Q * 1) * m^T)) * S S: diagonal matrix containing 1/stdev of each SNP, m: column vector containing mean of each SNP TODO: multiply with S AFTER aggregation across parties, that way bootstrap once for all

func ReduceAndAddUint128

func ReduceAndAddUint128(in []uint128, out []uint64, qInv, q uint64)

func SaveIntVectorToFile

func SaveIntVectorToFile(filename string, x []int)

func SaveMatrixToFile

func SaveMatrixToFile(cps *crypto.CryptoParams, mpcObj *mpc.MPC, cm crypto.CipherMatrix, nElemCol int, sourcePid int, filename string)

func ToMontgomeryForm

func ToMontgomeryForm(cryptoParams *crypto.CryptoParams, pt crypto.PlainVector)

func TransposeMatrixFile

func TransposeMatrixFile(inputFile string, nrows, ncols int, outputFile string, dtype string)

Types

type Block

type Block interface {
	At(int, int) float64
	Dims() (int, int)
}

type BlockI8

type BlockI8 struct {
	Data [][]float64
	// contains filtered or unexported fields
}

func NewBlockI8

func NewBlockI8(r, c int) BlockI8

func (BlockI8) At

func (b BlockI8) At(i, j int) float64

func (BlockI8) Dims

func (b BlockI8) Dims() (int, int)

type BlockMatrix

type BlockMatrix []BlockVector

func ToBlockMatrix

func ToBlockMatrix(A *mat.Dense, d int) BlockMatrix

type BlockVector

type BlockVector []Block

type CipherAccV1

type CipherAccV1 struct {
	// contains filtered or unexported fields
}

type CipherAccV2

type CipherAccV2 struct {
	// contains filtered or unexported fields
}

type CipherVectorAccV1

type CipherVectorAccV1 []CipherAccV1

func NewCipherVectorAccV1

func NewCipherVectorAccV1(cryptoParams *crypto.CryptoParams, n int) CipherVectorAccV1

type CipherVectorAccV2

type CipherVectorAccV2 struct {
	Val []CipherAccV2
}

func NewCipherVectorAccV2

func NewCipherVectorAccV2(cryptoParams *crypto.CryptoParams, n int, level int) CipherVectorAccV2

type DiagCacheStream

type DiagCacheStream struct {
	// contains filtered or unexported fields
}

func NewDiagCacheStream

func NewDiagCacheStream(cryptoParams *crypto.CryptoParams, filePrefix string, blockRowIndex int, isWrite bool) (*DiagCacheStream, bool)

Second output is a flag indicating whether write is attempted when the file already exists

func (*DiagCacheStream) Close

func (dcs *DiagCacheStream) Close()

func (*DiagCacheStream) GetIndexTables

func (dcs *DiagCacheStream) GetIndexTables() ([]bool, []bool)

func (*DiagCacheStream) ReadDiag

func (dcs *DiagCacheStream) ReadDiag() (pv crypto.PlainVector, shift int)

func (*DiagCacheStream) ResetRead

func (dcs *DiagCacheStream) ResetRead()

func (*DiagCacheStream) SetIndexTables

func (dcs *DiagCacheStream) SetIndexTables(babyTable, giantTable []bool)

func (*DiagCacheStream) WriteDiag

func (dcs *DiagCacheStream) WriteDiag(pv crypto.PlainVector, shift uint32)

type PlainMatrixDiagCache

type PlainMatrixDiagCache [][]crypto.PlainVector

Cache structure for MatMult4 First index corresponds to row index of blocks of size slots-by-slots Second index of indexMap corresponds to index of diagonals (0..slots-1), The table maps a diag index to the encoded PlainVector If a given index has empty data, stored element is nil

func MatMult4TransformB

func MatMult4TransformB(cryptoParams *crypto.CryptoParams, B *mat.Dense) PlainMatrixDiagCache

Jump to

Keyboard shortcuts

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