plainUtils

package
v0.0.0-...-9e2d205 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

utils for plaintext operations and poc for block matrices

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddConst

func AddConst(m *mat.Dense, c float64) *mat.Dense

func ApplyFunc

func ApplyFunc(Bm *BMatrix, f func(x float64) float64)

func ApplyFuncDense

func ApplyFuncDense(f func(v float64) float64, a *mat.Dense) *mat.Dense

func ComplexToReal

func ComplexToReal(v []complex128) []float64

func DenseToMatrix

func DenseToMatrix(m *mat.Dense) [][]float64

func Distance

func Distance(a, b []float64) float64

func ExpandBlocks

func ExpandBlocks(Bm *BMatrix) *mat.Dense

Reconstruct a matrix from block representation

func Eye

func Eye(n int) *mat.Dense

eye returns a new identity matrix of size n×n.

func MatToArray

func MatToArray(m *mat.Dense) [][]float64

func MatrixForDebug

func MatrixForDebug(r, c int) *mat.Dense

returns a matrix useful for debug. E.g if r,c = 3,3 -> returns | 1 2 3 | | 4 5 6 | | 7 8 9 |

func Max

func Max(a, b int) int

func Min

func Min(a, b int) int

func MulByConst

func MulByConst(m *mat.Dense, c float64) *mat.Dense

func MulByi

func MulByi(v []float64) []complex128

func NewDense

func NewDense(X [][]float64) *mat.Dense

func NumCols

func NumCols(m *mat.Dense) int

func NumRows

func NumRows(m *mat.Dense) int

func Pad

func Pad(v []float64, n int) []float64

pads v with n 0s

func PadDense

func PadDense(m *mat.Dense, rowPad, colPad int) *mat.Dense

func PrintBlocks

func PrintBlocks(bm *BMatrix)

func PrintDense

func PrintDense(m *mat.Dense)

func RandMatrix

func RandMatrix(r, c int) *mat.Dense

func RealToComplex

func RealToComplex(v []float64) []complex128

func ReplicateComplexArray

func ReplicateComplexArray(v []complex128, n int) []complex128

replicates v with n copies

func ReplicateRealArray

func ReplicateRealArray(v []float64, n int) []float64

replicates v with n copies

func ReplicateValue

func ReplicateValue(v float64, n int) []float64

replicates v ,n times

func RotateComplexArray

func RotateComplexArray(v []complex128, k int) []complex128

rotates v of k positions to the left or to the right if k < 0

func RotateRealArray

func RotateRealArray(v []float64, k int) []float64

rotates v of k positions to the left or to the right if k < 0

func RowFlatten

func RowFlatten(m *mat.Dense) []float64

func TransposeDense

func TransposeDense(m *mat.Dense) (mt *mat.Dense)

func Vectorize

func Vectorize(X [][]float64, transpose bool) []float64

Input: matrix X Output: column array of vectorized X Example:

X = |a b|

|c d|

if tranpose false:

output = [a ,b, c, d] column vector

else:

output = [a ,c, b, d] column vector

for reference: https://en.wikipedia.org/wiki/Vectorization_(mathematics)

Types

type BMatrix

type BMatrix struct {
	Blocks               [][]*mat.Dense
	RowP, ColP           int //num of partitions
	InnerRows, InnerCols int //size of sub-matrixes
	RealRows, RealCols   int //size of original matrix with no padding
}

block matrix

func AddBlocks

func AddBlocks(A, B *BMatrix) (*BMatrix, error)

func MultiPlyBlocks

func MultiPlyBlocks(A, B *BMatrix) (*BMatrix, error)

func MultiplyBlocksByConst

func MultiplyBlocksByConst(A *BMatrix, c float64) *BMatrix

func PartitionMatrix

func PartitionMatrix(m *mat.Dense, rowP, colP int) (*BMatrix, error)

Partitions m into a rowPxcolP Block Matrix where each sub-matrix is row(m)/rowP x col(m)/colP

func PartitionMatrixSquare

func PartitionMatrixSquare(m *mat.Dense, rowP, colP, d int) (*BMatrix, error)

Partitions m into a rowPxcolP Block Matrix where each sub-matrix is a square dxd matrix (eventually with padding)

func TransposeBlocks

func TransposeBlocks(Bm *BMatrix) *BMatrix

Tranpose the blocks partition of the matrix, but leaves untouched the inner matrix of each block In other words, it changes the arrangment the blocks

type Padding

type Padding struct {
	//see func below
	P1 [][]float64
	P2 [][]float64
	// contains filtered or unexported fields
}

func GenPaddingMatrixes

func GenPaddingMatrixes(inputDim, padding int) *Padding
	Returns P1 and P2 matrixes such that:
		P2 * X * P1 = padded X, where * is the matrix product
	E.g is X = |a b|
               |c d|
	if pad = 1, X becomes |0 0 0 0|
                          |0 a b 0|
						  |0 c d 0|
                          |0 0 0 0|

Jump to

Keyboard shortcuts

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