helayers::CTile Class Reference

A class representing a ciphertext. More...

#include <CTile.h>

Public Member Functions

 CTile (HeContext &he)
 Constructs an empty object. More...
 
 CTile (const CTile &src)
 Copy constructor. More...
 
CTileoperator= (const CTile &src)
 Copy from another object. More...
 
void saveToFile (const std::string &fileName) const
 Saves this CTile to a file in binary form. More...
 
void loadFromFile (const std::string &fileName)
 Loads this CTile from a file saved by saveToFile() More...
 
std::streamoff save (std::ostream &stream) const
 Saves this CTile to a stream in binary form. More...
 
std::streamoff load (std::istream &stream)
 Loads this CTile from a file saved by save() More...
 
void conjugate ()
 Conjugates contents of this CTile in place, elementwise. More...
 
void conjugateRaw ()
 See conjugate().
 
void rotate (int n)
 Rotate left. More...
 
void add (const CTile &other)
 Add content of another ciphertext to this one, elementwise. More...
 
void addRaw (const CTile &other)
 See add()
 
void sub (const CTile &other)
 Subtract content of another ciphertext from this one, elementwise. More...
 
void subRaw (const CTile &other)
 See sub()
 
void multiply (const CTile &other)
 Multiply another ciphertext with this one, elementwise. More...
 
void multiplyRaw (const CTile &other)
 see multiply()
 
void addPlain (const PTile &plain)
 Add content of another PTile to this one, elementwise. More...
 
void addPlainRaw (const PTile &plain)
 See addPlain()
 
void subPlain (const PTile &plain)
 Subtract content of another PTile from this one, elementwise. More...
 
void subPlainRaw (const PTile &plain)
 See subPlain()
 
void multiplyPlain (const PTile &plain)
 Multiply a PTile with this CTile, elementwise. More...
 
void multiplyPlainRaw (const PTile &plain)
 See multiplyPlain()
 
void square ()
 Square content of this ciphertext, elementwise. More...
 
void squareRaw ()
 See square()
 
void multiplyByChangingScale (double factor)
 Multiply this ciphertext by a scalar double value, elementwise, by a light-weight scale changing. More...
 
void addScalar (int scalar)
 Adds an int scalar value to all slots in this ciphertext. More...
 
void addScalar (double scalar)
 Adds a double scalar value to all slots in this ciphertext. More...
 
void multiplyScalar (int scalar)
 Multiplies all slots in this ciphertext with an int scalar value. More...
 
void multiplyScalar (double scalar)
 Multiplies all slots in this ciphertext with a double scalar value. More...
 
void relinearize ()
 Performs a relinearize operation (reducing ciphertext size after multiplication) The non-raw version of multiplication takes care of this automatically when needed. More...
 
void rescale ()
 Performs a rescale operation (reducing ciphertext modulus bits and attached meta data scale). More...
 
void rescaleRaw ()
 See rescale()
 
void negate ()
 Negates content of this ciphertext.
 
void setScale (double scale)
 Sets the attached meta data scale of the ciphertext. More...
 
double getScale () const
 Returns the attached meta data scale of the ciphertext.
 
void reduceChainIndex ()
 Reduces the chain-index property of the ciphertext by 1. More...
 
void setChainIndex (const CTile &other)
 Sets the chain-index property of this object to equal other object. More...
 
void setChainIndex (int chainIndex)
 Sets the chain-index property of this object to equal the specified value. More...
 
int getChainIndex () const
 Returns the value of the chain-index property of this object, which is a non-negative integer. More...
 
int slotCount () const
 A CTile represents a ciphertext consisting of multuple slots. More...
 
void innerSum (int rot1, int rot2, bool reverse=false)
 Computes the inner sum of some of the ciphertext's slots. More...
 
void sumExpBySquaringLeftToRight (int n)
 Summarizes n slots of this ciphertext. More...
 
void sumExpBySquaringRightToLeft (int n)
 Summarizes n slots of this ciphertext. More...
 
bool isEmpty () const
 Returns true if this CTile does not include an encryption of any value, and false otherwise.
 
void debugPrint (const std::string &title="", int maxElements=4, int verbose=0, std::ostream &out=std::cout) const
 Prints information regarding this object for debug purposes. More...
 
const AbstractCiphertextgetImpl () const
 Reserved for debugging and internal use.
 

Friends

class Encoder
 
class BitwiseEvaluator
 
class NativeFunctionEvaluator
 

Detailed Description

A class representing a ciphertext.

It's called a CTile because from a high-level point of view we'll usually use several of these combined for holding a more complicated object such as a matrix. For a lower level documentation of different functionalities (such as the effect on chainIndex), see documentation of the underlying encryption scheme.

Constructor & Destructor Documentation

◆ CTile() [1/2]

helayers::CTile::CTile ( HeContext he)

Constructs an empty object.

Parameters
[in]hethe underlying context.

◆ CTile() [2/2]

helayers::CTile::CTile ( const CTile src)

Copy constructor.

Parameters
[in]srcObject to copy.

Member Function Documentation

◆ add()

void helayers::CTile::add ( const CTile other)

Add content of another ciphertext to this one, elementwise.

Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use addRaw() to get the scheme's raw addition operation.

Parameters
[in]otherother ciphertext to add.

◆ addPlain()

void helayers::CTile::addPlain ( const PTile plain)

Add content of another PTile to this one, elementwise.

Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use addPlainRaw() to get the scheme's raw addition operation.

Parameters
[in]otherPTile to add.

◆ addScalar() [1/2]

void helayers::CTile::addScalar ( double  scalar)

Adds a double scalar value to all slots in this ciphertext.

Parameters
[in]scalarvalue to add.

◆ addScalar() [2/2]

void helayers::CTile::addScalar ( int  scalar)

Adds an int scalar value to all slots in this ciphertext.

Parameters
[in]scalarvalue to add.

◆ conjugate()

void helayers::CTile::conjugate ( )

Conjugates contents of this CTile in place, elementwise.

For non-complex numbers this has no effect. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use conjugateRaw() to get the scheme's raw conjugate operation.

◆ debugPrint()

void helayers::CTile::debugPrint ( const std::string &  title = "",
int  maxElements = 4,
int  verbose = 0,
std::ostream &  out = std::cout 
) const

Prints information regarding this object for debug purposes.

Parameters
[in]titleA title to be included in the printing.
[in]maxElementsThe number of elements/slots to be included in the printing.
[in]verboseLevel of vebosity.
[in]outAn output stream to print the information into.

◆ getChainIndex()

int helayers::CTile::getChainIndex ( ) const

Returns the value of the chain-index property of this object, which is a non-negative integer.

Returns a negative value if not supported.

◆ innerSum()

void helayers::CTile::innerSum ( int  rot1,
int  rot2,
bool  reverse = false 
)

Computes the inner sum of some of the ciphertext's slots.

Performs the computation by repeated rotations and additions, with rotations rot1, 2*rot1, 4*rot2, up to rot2 (exclusive). Using this method properly is complicated, and is used by some higher level algorithms.

Parameters
rot1First rotation in the rotate-and-add loop
rot2Last rotation (exclusive) in the rotate-and-add loop
reverseIf true, flips all rotations (left to right and vice versa)

◆ load()

streamoff helayers::CTile::load ( std::istream &  stream)

Loads this CTile from a file saved by save()

Parameters
[in]streaminput stream to read from

◆ loadFromFile()

void helayers::CTile::loadFromFile ( const std::string &  fileName)

Loads this CTile from a file saved by saveToFile()

Parameters
[in]fileNamename of file to read from

◆ multiply()

void helayers::CTile::multiply ( const CTile other)

Multiply another ciphertext with this one, elementwise.

Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use multiplyRaw() to get the scheme's raw addition operation.

Parameters
[in]otherother ciphertext to multiply.

◆ multiplyByChangingScale()

void helayers::CTile::multiplyByChangingScale ( double  factor)

Multiply this ciphertext by a scalar double value, elementwise, by a light-weight scale changing.

This multiplies every slot by the given factor. The operation is done by changing the scale meta-data combined with this ciphertext, and is therefore extermely fast. It is not available for all underlying schemes, and also may cause difficulties down the line due to mismatching scales.

Parameters
[in]factorfactor to multiply with.
Exceptions
runtime_errorIf not supported

◆ multiplyPlain()

void helayers::CTile::multiplyPlain ( const PTile plain)

Multiply a PTile with this CTile, elementwise.

Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use multiplyPlainRaw() to get the scheme's raw multiplication operation.

Parameters
[in]otherPTile to multiply with.

◆ multiplyScalar() [1/2]

void helayers::CTile::multiplyScalar ( double  scalar)

Multiplies all slots in this ciphertext with a double scalar value.

Parameters
[in]scalarvalue to multiply.

◆ multiplyScalar() [2/2]

void helayers::CTile::multiplyScalar ( int  scalar)

Multiplies all slots in this ciphertext with an int scalar value.

Parameters
[in]scalarvalue to multiply.

◆ operator=()

CTile & helayers::CTile::operator= ( const CTile src)

Copy from another object.

Parameters
[in]srcObject to copy.

◆ reduceChainIndex()

void helayers::CTile::reduceChainIndex ( )

Reduces the chain-index property of the ciphertext by 1.

Ignored if not supported.

Exceptions
runtime_errorIf chain index is already at lowest value

◆ relinearize()

void helayers::CTile::relinearize ( )

Performs a relinearize operation (reducing ciphertext size after multiplication) The non-raw version of multiplication takes care of this automatically when needed.

Ignored if not needed or not supported.

◆ rescale()

void helayers::CTile::rescale ( )

Performs a rescale operation (reducing ciphertext modulus bits and attached meta data scale).

The non-raw version of multiplication takes care of this automatically. Ignored if not needed or not supported. Note that depending on scheme, this method may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use rescaleRaw() to get the scheme's raw rescale operation.

◆ rotate()

void helayers::CTile::rotate ( int  n)

Rotate left.

For an offset of n, the element at slots 10 will move to slot 10-n. The first n elements are rotated back to be last.

Parameters
[in]nrotate offset

◆ save()

streamoff helayers::CTile::save ( std::ostream &  stream) const

Saves this CTile to a stream in binary form.

Parameters
[in]streamoutput stream to write to

◆ saveToFile()

void helayers::CTile::saveToFile ( const std::string &  fileName) const

Saves this CTile to a file in binary form.

Parameters
[in]fileNamename of file to write to

◆ setChainIndex() [1/2]

void helayers::CTile::setChainIndex ( const CTile other)

Sets the chain-index property of this object to equal other object.

Can only be used if other object's chain index is less than or equal to the chain index of this object. Ignored if not supported.

Parameters
[in]otherobject to get chain index from
Exceptions
runtime_errorIf chain index of other higher than this

◆ setChainIndex() [2/2]

void helayers::CTile::setChainIndex ( int  chainIndex)

Sets the chain-index property of this object to equal the specified value.

Can only be used if the specified value is less than or equal to the chain index of this object. Ignored if not supported.

Parameters
[in]chainIndexThe terget value to set the chain index to
Exceptions
runtime_errorIf the specified chain index is higher than this

◆ setScale()

void helayers::CTile::setScale ( double  scale)

Sets the attached meta data scale of the ciphertext.

This may change the way its content are interpreted.

Parameters
[in]scalethe new scale
Exceptions
runtime_errorIf not supported

◆ slotCount()

int helayers::CTile::slotCount ( ) const

A CTile represents a ciphertext consisting of multuple slots.

This method returns the number of slots in this object.

◆ square()

void helayers::CTile::square ( )

Square content of this ciphertext, elementwise.

Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use squareRaw() to get the scheme's raw square operation.

◆ sub()

void helayers::CTile::sub ( const CTile other)

Subtract content of another ciphertext from this one, elementwise.

Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use subRaw() to get the scheme's raw subtraction operation.

Parameters
[in]otherother ciphertext to subtract.

◆ subPlain()

void helayers::CTile::subPlain ( const PTile plain)

Subtract content of another PTile from this one, elementwise.

Result is stored in place. Depending on scheme, this may perform some additional light-weight tasks allowing for a smooth sequence of operations. Use subPlainRaw() to get the scheme's raw subtract operation.

Parameters
[in]otherPTile to subtract.

◆ sumExpBySquaringLeftToRight()

void helayers::CTile::sumExpBySquaringLeftToRight ( int  n)

Summarizes n slots of this ciphertext.

After summing, slot i will contain the sum of slots i, i+1, i+2, . . ., i+n-1, where indices are cyclic, i.e., roll back to the start if run out over the edge. Summation is done similar to left-to-right repeated squaring algorithm.

Parameters
[in]nnumber of elements to summarize

◆ sumExpBySquaringRightToLeft()

void helayers::CTile::sumExpBySquaringRightToLeft ( int  n)

Summarizes n slots of this ciphertext.

After summing, slot i will contain the sum of slots i, i+1, i+2, . . ., i+n-1, where indices are cyclic, i.e., roll back to the start if run out over the edge. Summation is done similar to right-to-left repeated squaring algorithm.

Parameters
[in]nnumber of elements to summarize

The documentation for this class was generated from the following files:
  • /opt/IBM/FHE-distro/ML-HElib/src/helayers/hebase/CTile.h
  • /opt/IBM/FHE-distro/ML-HElib/src/helayers/hebase/CTile.cpp