An object that mimics the functionality of the Ctxt object, and acts as a convenient entry point for inputting/encoding data which is to be encrypted.
More...
#include <Ptxt.h>
Public Types | |
| using | SlotType = typename Scheme::SlotType |
| Alias for type to be stored in the slots. More... | |
Public Member Functions | |
| Ptxt () | |
Default constructor results in invalid Ptxt object which throws if used. More... | |
| Ptxt (const Context &context) | |
Context only constructor, defaults all slots to 0. More... | |
| Ptxt (const PubKey &pk) | |
Public key only constructor, defaults all slots to 0. More... | |
| Ptxt (const Context &context, const SlotType &value) | |
Single slot constructor, set all slots to value. More... | |
| template<typename U = Scheme, std::enable_if_t< std::is_same< U, BGV >::value > * = nullptr> | |
| Ptxt (const Context &context, const NTL::ZZX &value) | |
BGV plaintext polynomial constructor, set all slots to the value polynomial. More... | |
| Ptxt (const Context &context, const std::vector< SlotType > &data) | |
| Slot vector constructor. More... | |
| template<typename T > | |
| Ptxt (const Context &context, const std::vector< T > &data) | |
| Generic slot vector constructor. More... | |
| Ptxt (const Ptxt< Scheme > &other)=default | |
| Default copy constructor. More... | |
| Ptxt (Ptxt< Scheme > &&other) noexcept=default | |
| Default move constructor. More... | |
| Ptxt< Scheme > & | operator= (const Ptxt< Scheme > &v)=default |
Copy assignment operator with other Ptxt. More... | |
| Ptxt< Scheme > & | operator= (Ptxt< Scheme > &&v) noexcept=default |
Move assignment operator with other Ptxt. More... | |
| ~Ptxt ()=default | |
| Default destructor. More... | |
| bool | isValid () const |
Check if a Ptxt is valid. More... | |
| size_t | size () const |
Returns the size (number of slots) of a Ptxt. More... | |
| long | lsize () const |
Returns the size (number of slots) of a Ptxt as long. More... | |
| const Context & | getContext () const |
Returns the context used to initialize the Ptxt More... | |
| void | setData (const std::vector< SlotType > &data) |
| Set the data. More... | |
| void | setData (const SlotType &value) |
| Set the data replicating the input on all slots. More... | |
| template<typename T = Scheme, typename std::enable_if_t< std::is_same< T, BGV >::value > * = nullptr> | |
| void | setData (const NTL::ZZX &value) |
Set the Ptxt data replicating the input polynomial on all slots. More... | |
| template<typename T = Scheme, typename std::enable_if_t< std::is_same< T, BGV >::value > * = nullptr> | |
| void | decodeSetData (const NTL::ZZX &data) |
Set the Ptxt slots using values from decoding data to slot representation. More... | |
| void | clear () |
Sets all slots to 0. More... | |
| Ptxt< Scheme > & | random () |
| Populate slots with random data. More... | |
| const std::vector< SlotType > & | getSlotRepr () const |
Get the data held in the slots as a std::vector<SlotType>. More... | |
| NTL::ZZX | getPolyRepr () const |
Converts the slot data in this to its single polynomial representation. More... | |
| void | encode (EncodedPtxt &eptxt, double mag=-1, OptLong prec=OptLong()) const |
Converts the slot data in this to a corresponding EncodedPtxt object. mag,prec must be defaulted for BGV (runtime error if not). More... | |
| SlotType & | operator[] (long i) |
| Square bracket accessor operator. More... | |
| SlotType | operator[] (long i) const |
const square bracket accessor operator. More... | |
| SlotType & | at (long i) |
at accessor operator. More... | |
| SlotType | at (long i) const |
const at accessor operator. More... | |
| bool | operator== (const Ptxt< Scheme > &other) const |
Equals operator between two Ptxt objects. More... | |
| bool | operator!= (const Ptxt< Scheme > &other) const |
Not equals operator between two Ptxt objects. More... | |
| Ptxt< Scheme > | operator* (const Ptxt< Scheme > &rhs) const |
| Infix multiplication operator. More... | |
| Ptxt< Scheme > | operator+ (const Ptxt< Scheme > &rhs) const |
| Infix addition operator. More... | |
| Ptxt< Scheme > | operator- (const Ptxt< Scheme > &rhs) const |
| Infix subtraction operator. More... | |
| Ptxt< Scheme > & | operator*= (const Ptxt< Scheme > &otherPtxt) |
Times equals operator with another Ptxt. More... | |
| Ptxt< Scheme > & | operator*= (const SlotType &scalar) |
Times equals operator with a single SlotType. More... | |
| template<typename Scalar > | |
| Ptxt< Scheme > & | operator*= (const Scalar &scalar) |
| Times equals operator with a scalar. More... | |
| Ptxt< Scheme > & | operator+= (const Ptxt< Scheme > &otherPtxt) |
Plus equals operator with another Ptxt. More... | |
| Ptxt< Scheme > & | operator+= (const SlotType &scalar) |
Plus equals operator with a single SlotType. More... | |
| template<typename Scalar > | |
| Ptxt< Scheme > & | operator+= (const Scalar &scalar) |
| Plus equals operator with a scalar. More... | |
| Ptxt< Scheme > & | operator-= (const Ptxt< Scheme > &otherPtxt) |
Minus equals operator with another Ptxt. More... | |
| Ptxt< Scheme > & | operator-= (const SlotType &scalar) |
Minus equals operator with a single SlotType. More... | |
| template<typename Scalar > | |
| Ptxt< Scheme > & | operator-= (const Scalar &scalar) |
| Minus equals operator with a scalar. More... | |
| Ptxt< Scheme > & | negate () |
Negate a Ptxt. More... | |
| template<typename T = Scheme, typename Scalar , typename std::enable_if_t< std::is_same< T, BGV >::value > * = nullptr> | |
| Ptxt< Scheme > & | addConstant (const Scalar &scalar) |
Add a constant to a BGV Ptxt. More... | |
| template<typename T = Scheme, typename Scalar , typename std::enable_if_t< std::is_same< T, CKKS >::value > * = nullptr> | |
| Ptxt< Scheme > & | addConstantCKKS (const Scalar &scalar) |
Add a constant to a CKKS Ptxt. More... | |
| Ptxt< Scheme > & | multiplyBy (const Ptxt< Scheme > &otherPtxt) |
Multiplication function between two Ptxt objects. More... | |
| Ptxt< Scheme > & | multiplyBy2 (const Ptxt &otherPtxt1, const Ptxt &otherPtxt2) |
Multiplication function between three Ptxt objects. More... | |
| Ptxt< Scheme > & | square () |
Square operation on a Ptxt. More... | |
| Ptxt< Scheme > & | cube () |
Cube operation on a Ptxt. More... | |
| Ptxt< Scheme > & | power (long e) |
Power operation to raise a Ptxt to an arbitrary non-negative power. More... | |
| Ptxt< Scheme > & | rotate (long amount) |
Rotate slots right by specified amount (slot i goes to slot i+1 mod size). More... | |
| Ptxt< Scheme > & | rotate1D (long dim, long amount) |
| Rotate slots right by specified amount along a specific dimension. More... | |
| Ptxt< Scheme > & | shift (long amount) |
Shifts slots right by specified amount with 0 fill (slot i goes to slot i+1 mod size). More... | |
| Ptxt< Scheme > & | shift1D (long dim, long amount) |
Shift slots right in one dimension of the hypercube structure with 0 fill. More... | |
| Ptxt< Scheme > & | automorph (long k) |
| Apply the automorphism a(X) -> a(X^k) mod Phi_m(X). More... | |
| template<typename T = Scheme, std::enable_if_t< std::is_same< T, BGV >::value > * = nullptr> | |
| Ptxt< Scheme > & | frobeniusAutomorph (long j) |
| Apply the frobenius automorphism a(X) -> a(X^(p^j)) mod Phi_m(X). More... | |
| Ptxt< Scheme > & | replicate (long pos) |
| Replicate single slot across all slots. More... | |
| std::vector< Ptxt< Scheme > > | replicateAll () const |
| Generate a vector of plaintexts with each slot replicated in each plaintext. More... | |
| template<typename T = Scheme, std::enable_if_t< std::is_same< T, CKKS >::value > * = nullptr> | |
| Ptxt< Scheme > & | complexConj () |
Apply complex conjugate of complex numbers in slots of a CKKS Ptxt object. More... | |
| template<typename T = Scheme, std::enable_if_t< std::is_same< T, CKKS >::value > * = nullptr> | |
| Ptxt< Scheme > | real () const |
| Extract the real part of a CKKS plaintext. More... | |
| template<typename T = Scheme, std::enable_if_t< std::is_same< T, CKKS >::value > * = nullptr> | |
| Ptxt< Scheme > | imag () const |
| Extract the imaginary part of a CKKS plaintext. More... | |
| Ptxt< Scheme > & | runningSums () |
| Compute the running sum (each slot is the sum of the previous slots). More... | |
| Ptxt< Scheme > & | totalSums () |
| Compute the total sum (each slot contains the total sum of every slot). More... | |
| Ptxt< Scheme > & | incrementalProduct () |
| Compute the incremental product (each slot is the product of the previous slots). More... | |
| Ptxt< Scheme > & | totalProduct () |
| Compute the total product (each slot contains the total product of every slot). More... | |
| Ptxt< Scheme > & | mapTo01 () |
Map all non-zero slots to 1, keeping zero slots as zero. More... | |
| void | writeToJSON (std::ostream &os) const |
Function to serialize this Ptxt<Scheme>. More... | |
| JsonWrapper | writeToJSON () const |
Function to serialize this Ptxt<Scheme>. More... | |
| void | readJSON (std::istream &is) |
In-place function to deserialize a Ptxt<Scheme> from a JSON stream. More... | |
| void | readJSON (const JsonWrapper &jw) |
In-place function to deserialize a Ptxt<Scheme> from a JsonWrapper object. More... | |
| Ptxt< Scheme > & | cleanUp () |
To be inline with the Ctxt interface. However for Ptxt this means do nothing. More... | |
| PolyMod | convertToSlot (const Context &context, long slot) |
| std::complex< double > | convertToSlot (const Context &, long slot) |
| void | setData (const NTL::ZZX &value) |
| Ptxt (const Context &context, const NTL::ZZX &value) | |
| void | decodeSetData (const NTL::ZZX &data) |
| NTL::ZZX | getPolyRepr () const |
BGV specialisation of the getPolyRepr function. More... | |
| void | encode (EncodedPtxt &eptxt, double mag, OptLong prec) const |
| void | encode (EncodedPtxt &eptxt, double mag, OptLong prec) const |
CKKS specialisation of the getPolyRepr function. More... | |
| Ptxt< BGV > & | automorph (long k) |
| Ptxt< CKKS > & | automorph (long k) |
| Ptxt< BGV > & | frobeniusAutomorph (long j) |
| Ptxt< CKKS > & | complexConj () |
| Ptxt< CKKS > | real () const |
| Ptxt< CKKS > | imag () const |
Static Public Member Functions | |
| static Ptxt< Scheme > | readFromJSON (std::istream &is, const Context &context) |
Function to deserialize and return a Ptxt<Scheme> from a JSON stream. More... | |
| static Ptxt< Scheme > | readFromJSON (const JsonWrapper &jw, const Context &context) |
Function to deserialize and return a Ptxt<Scheme> from a JsonWrapper object. More... | |
| static SlotType | convertToSlot (const Context &context, long slot) |
Conversion function from long to SlotType. More... | |
Static Public Attributes | |
| static constexpr std::string_view | typeName = "Ptxt" |
| Class label to be added to JSON serialization as object type information. More... | |
Friends | |
| std::istream & | operator>> (std::istream &is, Ptxt &ptxt) |
Input shift operator. Uses the deserialize function internally. More... | |
| std::ostream & | operator (std::ostream &os, const Ptxt &ptxt) |
Detailed Description
template<typename Scheme>
class helib::Ptxt< Scheme >
An object that mimics the functionality of the Ctxt object, and acts as a convenient entry point for inputting/encoding data which is to be encrypted.
Ptxt is templated on Scheme, which may be CKKS or BGV.
In the BGV case, Ptxt can be considered to be an element of
viewed as a vector of slots with values each in
where G is one of the irreducible factors of
, and all operations are performed entry-wise.
General usage:
Internally, Ptxt objects store their data as a std::vector<helib::PolyMod>, where PolyMod is a convenience type representing an element of the above ring,
. The PolyMod type can be easily converted via static_cast to more convenient types such as long and NTL::ZZX.
In the CKKS case, the slot type is std::complex<double>, and has sensible operator overloads supporting operations with other Ptxt<CKKS>, Ctxt, and std::complex<double> objects, as well as performing all operations slot-wise.
A large number of operator overloads are defined so that Ptxt objects should easily inter-operate, as well as providing interoperability with other logically compatible types e.g. long and NTL::ZZX in the BGV case, std::complex<double> in the CKKS case, and helib::Ctxt in both cases.
Member Typedef Documentation
◆ SlotType
| using helib::Ptxt< Scheme >::SlotType = typename Scheme::SlotType |
Alias for type to be stored in the slots.
std::complex<double> for CKKS, helib::PolyMod for BGV.
Constructor & Destructor Documentation
◆ Ptxt() [1/10]
| helib::Ptxt< Scheme >::Ptxt |
Default constructor results in invalid Ptxt object which throws if used.
◆ Ptxt() [2/10]
|
explicit |
◆ Ptxt() [3/10]
|
inlineexplicit |
Public key only constructor, defaults all slots to 0.
- Parameters
-
pk The public key used as a proxy to the context.
- Note
- This is needed to match calls to
Ctxt.
◆ Ptxt() [4/10]
| helib::Ptxt< Scheme >::Ptxt | ( | const Context & | context, |
| const SlotType & | value | ||
| ) |
Single slot constructor, set all slots to value.
- Parameters
-
context Contextto use.value Value to set all slots to.
◆ Ptxt() [5/10]
| helib::Ptxt< Scheme >::Ptxt | ( | const Context & | context, |
| const NTL::ZZX & | value | ||
| ) |
◆ Ptxt() [6/10]
| helib::Ptxt< Scheme >::Ptxt | ( | const Context & | context, |
| const std::vector< SlotType > & | data | ||
| ) |
Slot vector constructor.
- Parameters
-
context Contextto use.data Data to populate the slots.
◆ Ptxt() [7/10]
|
inline |
Generic slot vector constructor.
- Parameters
-
context Contextto use.data Data to populate the slots, must be convertible to SlotType.
◆ Ptxt() [8/10]
|
default |
Default copy constructor.
- Parameters
-
other Ptxtobject to copy.
◆ Ptxt() [9/10]
|
defaultnoexcept |
Default move constructor.
- Parameters
-
other Ptxtto copy.
◆ ~Ptxt()
|
default |
Default destructor.
◆ Ptxt() [10/10]
| helib::Ptxt< BGV >::Ptxt | ( | const Context & | context, |
| const NTL::ZZX & | value | ||
| ) |
Member Function Documentation
◆ addConstant()
|
inline |
◆ addConstantCKKS()
|
inline |
◆ at() [1/2]
| Ptxt< Scheme >::SlotType & helib::Ptxt< Scheme >::at | ( | long | i | ) |
at accessor operator.
- Parameters
-
i Index of the desired Ptxtslot.
- Returns
- Reference to the data held at slot
i.
- Note
- throws if
iis out of range.
◆ at() [2/2]
| Ptxt< Scheme >::SlotType helib::Ptxt< Scheme >::at | ( | long | i | ) | const |
const at accessor operator.
- Parameters
-
i Index of the desired Ptxtslot.
- Returns
- Copy of the data held at slot
i.
- Note
- throws if
iis out of range.
◆ automorph() [1/3]
| Ptxt<Scheme>& helib::Ptxt< Scheme >::automorph | ( | long | k | ) |
Apply the automorphism a(X) -> a(X^k) mod Phi_m(X).
- Parameters
-
k Exponent of the automorphism to apply.
- Returns
- Reference to
*thispost automorphism application.
- Note
kmust be an element of Zm*
◆ automorph() [2/3]
| Ptxt< BGV > & helib::Ptxt< BGV >::automorph | ( | long | k | ) |
◆ automorph() [3/3]
| Ptxt< CKKS > & helib::Ptxt< CKKS >::automorph | ( | long | k | ) |
◆ cleanUp()
|
inline |
◆ clear()
| void helib::Ptxt< Scheme >::clear |
Sets all slots to 0.
◆ complexConj() [1/2]
| Ptxt<Scheme>& helib::Ptxt< Scheme >::complexConj | ( | ) |
◆ complexConj() [2/2]
| Ptxt< CKKS > & helib::Ptxt< CKKS >::complexConj | ( | ) |
◆ convertToSlot() [1/3]
| std::complex< double > helib::Ptxt< CKKS >::convertToSlot | ( | const Context & | , |
| long | slot | ||
| ) |
◆ convertToSlot() [2/3]
|
static |
Conversion function from long to SlotType.
- Parameters
-
context Context which may be needed to extract algebraic info. slot Datum to be converted to a SlotType.
- Returns
- Converted slot.
◆ convertToSlot() [3/3]
| PolyMod helib::Ptxt< BGV >::convertToSlot | ( | const Context & | context, |
| long | slot | ||
| ) |
◆ cube()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::cube |
Cube operation on a Ptxt.
- Returns
- Reference to
*thispost cube operation.
◆ decodeSetData() [1/2]
| void helib::Ptxt< Scheme >::decodeSetData | ( | const NTL::ZZX & | data | ) |
◆ decodeSetData() [2/2]
| void helib::Ptxt< BGV >::decodeSetData | ( | const NTL::ZZX & | data | ) |
◆ encode() [1/3]
| void helib::Ptxt< BGV >::encode | ( | EncodedPtxt< Scheme > & | eptxt, |
| double | mag, | ||
| OptLong | prec | ||
| ) | const |
◆ encode() [2/3]
| void helib::Ptxt< CKKS >::encode | ( | EncodedPtxt< Scheme > & | eptxt, |
| double | mag, | ||
| OptLong | prec | ||
| ) | const |
◆ encode() [3/3]
| void helib::Ptxt< Scheme >::encode | ( | EncodedPtxt< Scheme > & | eptxt, |
| double | mag = -1, |
||
| OptLong | prec = OptLong() |
||
| ) | const |
Converts the slot data in this to a corresponding EncodedPtxt object. mag,prec must be defaulted for BGV (runtime error if not).
◆ frobeniusAutomorph() [1/2]
| Ptxt<Scheme>& helib::Ptxt< Scheme >::frobeniusAutomorph | ( | long | j | ) |
Apply the frobenius automorphism a(X) -> a(X^(p^j)) mod Phi_m(X).
- Parameters
-
j Exponent of the automorphism to apply.
- Returns
- Reference to
*thispost frobenius automorphism application.
- Note
- Only valid for the
BGVscheme.
◆ frobeniusAutomorph() [2/2]
| Ptxt< BGV > & helib::Ptxt< BGV >::frobeniusAutomorph | ( | long | j | ) |
◆ getContext()
|
inline |
Returns the context used to initialize the Ptxt
- Returns
- The
context.
◆ getPolyRepr() [1/2]
| NTL::ZZX helib::Ptxt< Scheme >::getPolyRepr | ( | ) | const |
Converts the slot data in this to its single polynomial representation.
- Returns
- Single encoded polynomial.
- Note
NTL::ZZXrepresentation loses some precision in theCKKScase.
◆ getPolyRepr() [2/2]
| NTL::ZZX helib::Ptxt< BGV >::getPolyRepr | ( | ) | const |
◆ getSlotRepr()
| const std::vector< typename Ptxt< Scheme >::SlotType > & helib::Ptxt< Scheme >::getSlotRepr |
Get the data held in the slots as a std::vector<SlotType>.
- Returns
- Constant reference to the slot vector.
◆ imag() [1/2]
| Ptxt<Scheme> helib::Ptxt< Scheme >::imag | ( | ) | const |
◆ imag() [2/2]
| Ptxt< CKKS > helib::Ptxt< CKKS >::imag | ( | ) | const |
◆ incrementalProduct()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::incrementalProduct |
Compute the incremental product (each slot is the product of the previous slots).
- Returns
- Reference to
*thispost multiplication.
◆ isValid()
| bool helib::Ptxt< Scheme >::isValid |
Check if a Ptxt is valid.
- Returns
trueif valid,falseotherwise.
◆ lsize()
| long helib::Ptxt< Scheme >::lsize |
◆ mapTo01()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::mapTo01 |
Map all non-zero slots to 1, keeping zero slots as zero.
- Returns
- Reference to
*thispost mapping.
◆ multiplyBy()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::multiplyBy | ( | const Ptxt< Scheme > & | otherPtxt | ) |
Multiplication function between two Ptxt objects.
- Parameters
-
otherPtxt Right hand side of multiplication.
- Returns
- Reference to
*thispost multiplication.
- Note
- This function is equivalent to operator
*=.
◆ multiplyBy2()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::multiplyBy2 | ( | const Ptxt< Scheme > & | otherPtxt1, |
| const Ptxt< Scheme > & | otherPtxt2 | ||
| ) |
◆ negate()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::negate |
Negate a Ptxt.
- Returns
- Reference to
*thispost negation.
◆ operator!=()
| bool helib::Ptxt< Scheme >::operator!= | ( | const Ptxt< Scheme > & | other | ) | const |
◆ operator*()
| Ptxt< Scheme > helib::Ptxt< Scheme >::operator* | ( | const Ptxt< Scheme > & | rhs | ) | const |
Infix multiplication operator.
- Parameters
-
rhs Right hand side of multiplication.
- Returns
- Product of the two
Ptxtobjects.
◆ operator*=() [1/3]
| Ptxt< Scheme > & helib::Ptxt< Scheme >::operator*= | ( | const Ptxt< Scheme > & | otherPtxt | ) |
Times equals operator with another Ptxt.
- Parameters
-
otherPtxt Right hand side of multiplication.
- Returns
- Reference to
*thispost multiplication.
◆ operator*=() [2/3]
|
inline |
Times equals operator with a scalar.
- Parameters
-
scalar Element to be added across all slots.
- Returns
- Reference to
*thispost scalar multiplication.
◆ operator*=() [3/3]
| Ptxt< Scheme > & helib::Ptxt< Scheme >::operator*= | ( | const SlotType & | scalar | ) |
Times equals operator with a single SlotType.
- Parameters
-
scalar Element to be multiplied across all slots.
- Returns
- Reference to
*thispost multiplication.
◆ operator+()
| Ptxt< Scheme > helib::Ptxt< Scheme >::operator+ | ( | const Ptxt< Scheme > & | rhs | ) | const |
Infix addition operator.
- Parameters
-
rhs Right hand side of addition.
- Returns
- Sum of the two
Ptxtobjects.
◆ operator+=() [1/3]
| Ptxt< Scheme > & helib::Ptxt< Scheme >::operator+= | ( | const Ptxt< Scheme > & | otherPtxt | ) |
Plus equals operator with another Ptxt.
- Parameters
-
otherPtxt Right hand side of addition.
- Returns
- Reference to
*thispost addition.
◆ operator+=() [2/3]
|
inline |
Plus equals operator with a scalar.
- Parameters
-
scalar Element to be added across all slots.
- Returns
- Reference to
*thispost scalar addition.
◆ operator+=() [3/3]
| Ptxt< Scheme > & helib::Ptxt< Scheme >::operator+= | ( | const SlotType & | scalar | ) |
Plus equals operator with a single SlotType.
- Parameters
-
scalar Element to be added across all slots.
- Returns
- Reference to
*thispost addition.
◆ operator-()
| Ptxt< Scheme > helib::Ptxt< Scheme >::operator- | ( | const Ptxt< Scheme > & | rhs | ) | const |
Infix subtraction operator.
- Parameters
-
rhs Right hand side of subtraction.
- Returns
- Difference of the two
Ptxtobjects.
◆ operator-=() [1/3]
| Ptxt< Scheme > & helib::Ptxt< Scheme >::operator-= | ( | const Ptxt< Scheme > & | otherPtxt | ) |
Minus equals operator with another Ptxt.
- Parameters
-
otherPtxt Right hand side of subtraction.
- Returns
- Reference to
*thispost subtraction.
◆ operator-=() [2/3]
|
inline |
Minus equals operator with a scalar.
- Parameters
-
scalar Element to be subtracted across all slots.
- Returns
- Reference to
*thispost scalar subtraction.
◆ operator-=() [3/3]
| Ptxt< Scheme > & helib::Ptxt< Scheme >::operator-= | ( | const SlotType & | scalar | ) |
Minus equals operator with a single SlotType.
- Parameters
-
scalar Element to be subtracted across all slots.
- Returns
- Reference to
*thispost subtraction.
◆ operator=() [1/2]
|
default |
◆ operator=() [2/2]
|
defaultnoexcept |
◆ operator==()
| bool helib::Ptxt< Scheme >::operator== | ( | const Ptxt< Scheme > & | other | ) | const |
◆ operator[]() [1/2]
| Ptxt< Scheme >::SlotType & helib::Ptxt< Scheme >::operator[] | ( | long | i | ) |
Square bracket accessor operator.
- Parameters
-
i Index of the desired Ptxtslot.
- Returns
- Reference to the data held at slot
i.
◆ operator[]() [2/2]
| Ptxt< Scheme >::SlotType helib::Ptxt< Scheme >::operator[] | ( | long | i | ) | const |
const square bracket accessor operator.
- Parameters
-
i Index of the desired Ptxtslot.
- Returns
- Copy of the data held at slot
i.
◆ power()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::power | ( | long | e | ) |
◆ random()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::random |
Populate slots with random data.
- Returns
- Reference to
*thispost population.
◆ readFromJSON() [1/2]
|
static |
Function to deserialize and return a Ptxt<Scheme> from a JsonWrapper object.
- Parameters
-
jw JsonWrappercontaining the serialized object.
- Exceptions
-
IOError if the JsonWrapperobject does not contains a valid serialization of aPtxt<Scheme>.Ptxt<BGV> my_ptxt = Ptxt<BGV>::readFromJSON(..., context);static Ptxt< Scheme > readFromJSON(std::istream &is, const Context &context)Function to deserialize and return a Ptxt<Scheme> from a JSON stream.Definition: Ptxt.cpp:979
The JsonWrapper must contain a valid Ptxt<scheme> serialization.
Each element of the content list will be deserialized as a slot of the type determined by the scheme.
If the number of tokens in the slot list is less than the number of slots, the remaining slots will be padded by 0.
For example a slot list '['slot0', 'slot1', 'slot2']' will be deserialized as a plaintext ptxt where ptxt[0]=slot0, ptxt[1]=slot1, ptxt[2]=slot2 and ptxt[i]=0 for i>2.
◆ readFromJSON() [2/2]
|
static |
Function to deserialize and return a Ptxt<Scheme> from a JSON stream.
- Parameters
-
is Input std::istream.
- Exceptions
-
IOError if the stream is badly formatted (i.e. it does not contain a valid JSON). Ptxt<BGV> my_ptxt = Ptxt<BGV>::readFromJSON(std::cin, context);
The input stream has to contain a valid typed JSON value.
Each element of the content list will be deserialized as a slot of the type determined by the scheme.
If the number of tokens in the slot list is less than the number of slots, the remaining slots will be padded by 0.
For example a slot list '['slot0', 'slot1', 'slot2']' will be deserialized as a plaintext ptxt where ptxt[0]=slot0, ptxt[1]=slot1, ptxt[2]=slot2 and ptxt[i]=0 for i>2.
◆ readJSON() [1/2]
| void helib::Ptxt< Scheme >::readJSON | ( | const JsonWrapper & | jw | ) |
In-place function to deserialize a Ptxt<Scheme> from a JsonWrapper object.
- Parameters
-
jw JsonWrappercontaining the serialized object.
- Exceptions
-
IOError if the JsonWrapperobject does not contains a valid serialization of aPtxt<Scheme>.
- Note
thismust be constructed with an appropriate context BEFORE calling this function. For example,Ptxt my_ptxt(context);my_ptxt.readJSON(...);Ptxt()Default constructor results in invalid Ptxt object which throws if used.Definition: Ptxt.cpp:35
The JsonWrapper must contain a valid Ptxt<scheme> serialization.
Each element of the content list will be deserialized as a slot of the type determined by the scheme.
If the number of tokens in the slot list is less than the number of slots, the remaining slots will be padded by 0.
For example a slot list '['slot0', 'slot1', 'slot2']' will be deserialized as a plaintext ptxt where ptxt[0]=slot0, ptxt[1]=slot1, ptxt[2]=slot2 and ptxt[i]=0 for i>2.
◆ readJSON() [2/2]
| void helib::Ptxt< Scheme >::readJSON | ( | std::istream & | is | ) |
In-place function to deserialize a Ptxt<Scheme> from a JSON stream.
- Parameters
-
is Input std::istream.
- Exceptions
-
IOError if the stream is badly formatted (i.e. it does not contain a valid JSON).
- Note
thismust be constructed with an appropriate context BEFORE calling this function. For example,Ptxt my_ptxt(context);my_ptxt.readJSON(std::cin);
The input stream has to contain a valid typed JSON value.
Each element of the content list will be deserialized as a slot of the type determined by the scheme.
If the number of tokens in the slot list is less than the number of slots, the remaining slots will be padded by 0.
For example a slot list '['slot0', 'slot1', 'slot2']' will be deserialized as a plaintext ptxt where ptxt[0]=slot0, ptxt[1]=slot1, ptxt[2]=slot2 and ptxt[i]=0 for i>2.
◆ real() [1/2]
| Ptxt<Scheme> helib::Ptxt< Scheme >::real | ( | ) | const |
◆ real() [2/2]
| Ptxt< CKKS > helib::Ptxt< CKKS >::real | ( | ) | const |
◆ replicate()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::replicate | ( | long | pos | ) |
Replicate single slot across all slots.
- Parameters
-
pos Position of the slot to replicate.
- Returns
- Reference to
*thispost replication.
◆ replicateAll()
| std::vector< Ptxt< Scheme > > helib::Ptxt< Scheme >::replicateAll |
Generate a vector of plaintexts with each slot replicated in each plaintext.
- Returns
- Vector of replicated plaintext slots. The order of the return vector agrees with the order of the slots. i.e. the i-th plaintext in the return value is a replication of
*this[i].
◆ rotate()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::rotate | ( | long | amount | ) |
Rotate slots right by specified amount (slot i goes to slot i+1 mod size).
- Parameters
-
amount Number of slots to rotate by.
- Returns
- Reference to
*thispost rotation.
◆ rotate1D()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::rotate1D | ( | long | dim, |
| long | amount | ||
| ) |
Rotate slots right by specified amount along a specific dimension.
- Parameters
-
dim Dimension in which to rotate. amount Number of slots to rotate by.
- Returns
- Reference to
*thispost rotation.
◆ runningSums()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::runningSums |
Compute the running sum (each slot is the sum of the previous slots).
- Returns
- Reference to
*thispost summation.
◆ setData() [1/4]
| void helib::Ptxt< Scheme >::setData | ( | const NTL::ZZX & | value | ) |
◆ setData() [2/4]
| void helib::Ptxt< BGV >::setData | ( | const NTL::ZZX & | value | ) |
◆ setData() [3/4]
| void helib::Ptxt< Scheme >::setData | ( | const SlotType & | value | ) |
Set the data replicating the input on all slots.
- Parameters
-
value valueto set all slots to.
◆ setData() [4/4]
| void helib::Ptxt< Scheme >::setData | ( | const std::vector< SlotType > & | data | ) |
Set the data.
- Parameters
-
data Vector of SlotTypeto populate the slots.
◆ shift()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::shift | ( | long | amount | ) |
Shifts slots right by specified amount with 0 fill (slot i goes to slot i+1 mod size).
- Parameters
-
amount Number of slots to shift by.
- Returns
- Reference to
*thispost shift.
◆ shift1D()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::shift1D | ( | long | dim, |
| long | amount | ||
| ) |
Shift slots right in one dimension of the hypercube structure with 0 fill.
- Parameters
-
dim Dimension in which to shift. amount Amount by which to shift.
- Returns
- Reference to
*thispost shift.
◆ size()
| size_t helib::Ptxt< Scheme >::size |
◆ square()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::square |
Square operation on a Ptxt.
- Returns
- Reference to
*thispost squaring.
◆ totalProduct()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::totalProduct |
Compute the total product (each slot contains the total product of every slot).
- Returns
- Reference to
*thispost multiplication.
◆ totalSums()
| Ptxt< Scheme > & helib::Ptxt< Scheme >::totalSums |
Compute the total sum (each slot contains the total sum of every slot).
- Returns
- Reference to
*thispost summation.
◆ writeToJSON() [1/2]
| JsonWrapper helib::Ptxt< Scheme >::writeToJSON |
Function to serialize this Ptxt<Scheme>.
- Returns
- The
JsonWrappercontaining the serialization.
- Note
Ptxtcontextis not serialized, see note ofreadJSON.
The output JsonWrapper will be a JSON where the Ptxt content will be serialized in the slots field.
Each slot of ptxt will be serialized in an element of such list by the JSON serializer function determined by the scheme.
For example if we have a plaintext ptxt such that ptxt[0]=slot0, ptxt[1]=slot1, ptxt[2]=slot2, and ptxt[i]=0 for i>2, it will be serialized as '['slot0', 'slot1', 'slot2', 0, 0, ...]'.
◆ writeToJSON() [2/2]
| void helib::Ptxt< Scheme >::writeToJSON | ( | std::ostream & | os | ) | const |
Function to serialize this Ptxt<Scheme>.
- Parameters
-
os Output std::ostream.
- Note
Ptxtcontextis not serialized, see note ofreadJSON.
The output stream will be a JSON where the Ptxt content will be serialized in the slots field.
Each slot of ptxt will be serialized in an element of such list by the JSON serializer function determined by the scheme.
For example if we have a plaintext ptxt such that ptxt[0]=slot0, ptxt[1]=slot1, ptxt[2]=slot2, and ptxt[i]=0 for i>2, it will be serialized as '['slot0', 'slot1', 'slot2', 0, 0 ...]'.
Friends And Related Function Documentation
◆ operator
|
friend |
◆ operator>>
|
friend |
Input shift operator. Uses the deserialize function internally.
- Parameters
-
is Input std::istream.ptxt Destination Ptxtobject.
- Returns
- Input
std::istreampost reading.
- Note
ptxtmust be constructed with an appropriate context BEFORE calling this function. For example,Ptxt my_ptxt(context);std::cin >> my_ptxt;
The input stream has to be formatted as a comma-separated list surrounded by '[' and ']'.
Each element of the list will be deserialized as a slot of the type determined by the scheme.
If the number of tokens in the list is less than the number of slots, the remaining slots will be padded by 0.
For example '['slot0', 'slot1', 'slot2']' will be deserialized as a plaintext ptxt where ptxt[0]=slot0, ptxt[1]=slot1, ptxt[2]=slot2 and ptxt[i]=0 for i>2.
Member Data Documentation
◆ typeName
|
staticconstexpr |
Class label to be added to JSON serialization as object type information.
1.9.1