Template Class Matrix
Defined in File matrix.h
Inheritance Relationships
Base Type
public lbcrypto::Serializable
(Class Serializable)
Template Parameter Order
class Element
Class Documentation
-
template<class Element>
class lbcrypto::Matrix : public lbcrypto::Serializable Inheritence diagram for lbcrypto::Matrix:
Collaboration diagram for lbcrypto::Matrix:
Public Types
Public Functions
-
inline Matrix(alloc_func allocZero, size_t rows, size_t cols)
Constructor that initializes matrix values using a zero allocator
- Parameters
&allocZero – lambda function for zero initialization.
&rows – number of rows.
&rows – number of columns.
-
Matrix(alloc_func allocZero, size_t rows, size_t cols, alloc_func allocGen)
Constructor that initializes matrix values using a distribution generation allocator
- Parameters
&allocZero – lambda function for zero initialization (used for initializing derived matrix objects)
&rows – number of rows.
&rows – number of columns.
&allocGen – lambda function for initialization using a distribution generator.
-
inline explicit Matrix(alloc_func allocZero = 0)
Constructor of an empty matrix. SetSize must be called on this matrix to use it SetAlloc needs to be called if 0 passed to constructor This mostly exists to support deserializing
- Parameters
&allocZero – lambda function for zero initialization.
-
inline void SetSize(size_t rows, size_t cols)
Set the size of a matrix, elements are zeroed out
- Parameters
rows – number of rows
cols – number of colums
-
inline void SetAllocator(alloc_func allocZero)
SetAllocator - set the function to allocate a zero; basically only required for deserializer
- Parameters
allocZero –
-
inline Matrix(const Matrix<Element> &other)
Copy constructor
- Parameters
&other – the matrix object to be copied
-
Matrix<Element> &operator=(const Matrix<Element> &other)
Assignment operator
- Parameters
&other – the matrix object whose values are to be copied
- Returns
the resulting matrix
-
inline Matrix<Element> &Ones()
In-place change of the current matrix to a matrix of all ones
- Returns
the resulting matrix
-
Matrix<Element> &ModEq(const Element &modulus)
In-place modulo reduction
- Returns
the resulting matrix
-
Matrix<Element> &ModSubEq(Matrix<Element> const &b, const Element &modulus)
modular subtraction
- Returns
the resulting matrix
-
Matrix<Element> &Fill(const Element &val)
Fill matrix using the same element
- Parameters
&val – the element the matrix is filled by
- Returns
the resulting matrix
-
inline Matrix<Element> &Identity()
In-place change of the current matrix to Identity matrix
- Returns
the resulting matrix
-
template<typename T = Element, typename std::enable_if<!std::is_same<T, M2DCRTPoly>::value && !std::is_same<T, M4DCRTPoly>::value && !std::is_same<T, M6DCRTPoly>::value, bool>::type = true>
inline Matrix<T> GadgetVector(int64_t base = 2) const Sets the first row to be powers of two for when the base is two
- Parameters
base – is the base the digits of the matrix are represented in
- Returns
the resulting matrix
-
template<typename T = Element, typename std::enable_if<std::is_same<T, M2DCRTPoly>::value || std::is_same<T, M4DCRTPoly>::value || std::is_same<T, M6DCRTPoly>::value, bool>::type = true>
inline Matrix<T> GadgetVector(int64_t base = 2) const
-
template<typename T = Element, typename std::enable_if<std::is_same<T, double>::value || std::is_same<T, int>::value || std::is_same<T, int64_t>::value || std::is_same<T, Field2n>::value, bool>::type = true>
inline double Norm() const Computes the infinity norm
- Returns
the norm in double format
-
template<typename T = Element, typename std::enable_if<!std::is_same<T, double>::value && !std::is_same<T, int>::value && !std::is_same<T, int64_t>::value && !std::is_same<T, Field2n>::value, bool>::type = true>
inline double Norm() const
-
Matrix<Element> Mult(Matrix<Element> const &other) const
Matrix multiplication
- Parameters
&other – the multiplier matrix
- Returns
the result of multiplication
-
inline Matrix<Element> operator*(Matrix<Element> const &other) const
Operator for matrix multiplication
- Parameters
&other – the multiplier matrix
- Returns
the result of multiplication
-
inline Matrix<Element> ScalarMult(Element const &other) const
Multiplication of matrix by a scalar
- Parameters
&other – the multiplier element
- Returns
the result of multiplication
-
inline Matrix<Element> operator*(Element const &other) const
Operator for scalar multiplication
- Parameters
&other – the multiplier element
- Returns
the result of multiplication
-
inline bool Equal(Matrix<Element> const &other) const
Equality check
- Parameters
&other – the matrix object to compare to
- Returns
the boolean result
-
inline bool operator==(Matrix<Element> const &other) const
Operator for equality check
- Parameters
&other – the matrix object to compare to
- Returns
the boolean result
-
inline bool operator!=(Matrix<Element> const &other) const
Operator for non-equality check
- Parameters
&other – the matrix object to compare to
- Returns
the boolean result
-
inline const data_t &GetData() const
Get property to access the data as a vector of vectors
- Returns
the data as vector of vectors
-
inline size_t GetRows() const
Get property to access the number of rows in the matrix
- Returns
the number of rows
-
inline size_t GetCols() const
Get property to access the number of columns in the matrix
- Returns
the number of columns
-
inline alloc_func GetAllocator() const
Get property to access the zero allocator for the matrix
- Returns
the lambda function corresponding to the element zero allocator
-
void SetFormat(Format format)
Sets the evaluation or coefficient representation for all ring elements that support the SetFormat method
- Parameters
&format – the enum value corresponding to coefficient or evaluation representation
-
inline Matrix<Element> Add(Matrix<Element> const &other) const
Matrix addition
- Parameters
&other – the matrix to be added
- Returns
the resulting matrix
-
inline Matrix<Element> operator+(Matrix<Element> const &other) const
Operator for matrix addition
- Parameters
&other – the matrix to be added
- Returns
the resulting matrix
-
Matrix<Element> &operator+=(Matrix<Element> const &other)
Operator for in-place addition
- Parameters
&other – the matrix to be added
- Returns
the resulting matrix (same object)
-
inline Matrix<Element> Sub(Matrix<Element> const &other) const
Matrix substraction
- Parameters
&other – the matrix to be substracted
- Returns
the resulting matrix
-
inline Matrix<Element> operator-(Matrix<Element> const &other) const
Operator for matrix substraction
- Parameters
&other – the matrix to be substracted
- Returns
the resulting matrix
-
Matrix<Element> &operator-=(Matrix<Element> const &other)
Operator for in-place matrix substraction
- Parameters
&other – the matrix to be substracted
- Returns
the resulting matrix (same object)
-
void Determinant(Element *result) const
Matrix determinant - found using Laplace formula with complexity O(d!), where d is the dimension
- Parameters
*result – where the result is stored
-
Matrix<Element> CofactorMatrix() const
Cofactor matrix - the matrix of determinants of the minors A_{ij} multiplied by -1^{i+j}
- Returns
the cofactor matrix for the given matrix
-
Matrix<Element> &VStack(Matrix<Element> const &other)
Add rows to bottom of the matrix
- Parameters
&other – the matrix to be added to the bottom of current matrix
- Returns
the resulting matrix
-
inline Matrix<Element> &HStack(Matrix<Element> const &other)
Add columns the right of the matrix
- Parameters
&other – the matrix to be added to the right of current matrix
- Returns
the resulting matrix
-
inline Element &operator()(size_t row, size_t col)
Matrix indexing operator - writeable instance of the element
- Parameters
&row – row index
&col – column index
- Returns
the element at the index
-
inline Element const &operator()(size_t row, size_t col) const
Matrix indexing operator - read-only instance of the element
- Parameters
&row – row index
&col – column index
- Returns
the element at the index
-
inline Matrix<Element> ExtractRow(size_t row) const
Matrix row extractor
- Parameters
&row – row index
- Returns
the row at the index
-
inline Matrix<Element> ExtractCol(size_t col) const
Matrix column extractor
- Parameters
&col – col index
- Returns
the col at the index
-
inline Matrix<Element> ExtractRows(size_t row_start, size_t row_end) const
Matrix rows extractor in a range from row_start to row_and; inclusive
- Parameters
&row_start – &row_end row indices
- Returns
the rows in the range delimited by indices inclusive
-
void SwitchFormat()
Call switch format for each (ring) element
-
inline virtual std::string SerializedObjectName() const override
-
Matrix<NativeInteger> &ModEq(const NativeInteger &element)
-
Matrix<BigInteger> &ModEq(const BigInteger &element)
-
Matrix<NativeInteger> &ModSubEq(Matrix<NativeInteger> const &b, const NativeInteger &element)
-
Matrix<BigInteger> &ModSubEq(Matrix<BigInteger> const &b, const BigInteger &element)
Public Static Functions
-
static inline uint32_t SerializedVersion()
-
inline Matrix(alloc_func allocZero, size_t rows, size_t cols)