Skip to content

Commit

Permalink
Changes for additional print functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dsuponitskiy-duality committed Nov 28, 2024
1 parent 11e1319 commit 5a4da31
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 45 deletions.
3 changes: 2 additions & 1 deletion src/core/include/lattice/hal/default/ildcrtparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class ILDCRTParams final : public ElemParams<IntType> {
return 1;
}

private:
protected:
std::ostream& doprint(std::ostream& out) const override {
out << "ILDCRTParams ";
ElemParams<IntType>::doprint(out);
Expand All @@ -355,6 +355,7 @@ class ILDCRTParams final : public ElemParams<IntType> {
return out << std::endl;
}

private:
// array of smaller ILParams
std::vector<std::shared_ptr<ILNativeParams>> m_params;
};
Expand Down
2 changes: 1 addition & 1 deletion src/core/include/lattice/hal/default/ilparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class ILParamsImpl final : public ElemParams<IntType> {
return 1;
}

private:
protected:
std::ostream& doprint(std::ostream& out) const override {
out << "ILParams ";
ElemParams<IntType>::doprint(out);
Expand Down
48 changes: 24 additions & 24 deletions src/pke/include/encoding/encodingparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class EncodingParamsImpl : public lbcrypto::Serializable {
/**
* Destructor.
*/
virtual ~EncodingParamsImpl() {}
virtual ~EncodingParamsImpl() = default;

// ACCESSORS

Expand Down Expand Up @@ -253,29 +253,6 @@ class EncodingParamsImpl : public lbcrypto::Serializable {
return !(*this == other);
}

private:
std::ostream& doprint(std::ostream& out) const {
out << "[p=" << m_plaintextModulus << " rootP =" << m_plaintextRootOfUnity << " bigP =" << m_plaintextBigModulus
<< " rootBigP =" << m_plaintextBigRootOfUnity << " g=" << m_plaintextGenerator << " L=" << m_batchSize
<< "]";
return out;
}

// plaintext modulus that is used by all schemes
PlaintextModulus m_plaintextModulus;
// root of unity for plaintext modulus
NativeInteger m_plaintextRootOfUnity;
// big plaintext modulus that is used for arbitrary cyclotomics
NativeInteger m_plaintextBigModulus;
// root of unity for big plaintext modulus
NativeInteger m_plaintextBigRootOfUnity;
// plaintext generator is used for packed encoding (to find the correct
// automorphism index)
uint32_t m_plaintextGenerator;
// maximum batch size used by EvalSumKeyGen for packed encoding
uint32_t m_batchSize;

public:
template <class Archive>
void save(Archive& ar, std::uint32_t const version) const {
ar(::cereal::make_nvp("m", m_plaintextModulus));
Expand Down Expand Up @@ -306,6 +283,29 @@ class EncodingParamsImpl : public lbcrypto::Serializable {
static uint32_t SerializedVersion() {
return 1;
}

protected:
std::ostream& doprint(std::ostream& out) const {
out << "[p=" << m_plaintextModulus << " rootP =" << m_plaintextRootOfUnity << " bigP =" << m_plaintextBigModulus
<< " rootBigP =" << m_plaintextBigRootOfUnity << " g=" << m_plaintextGenerator << " L=" << m_batchSize
<< "]";
return out;
}

private:
// plaintext modulus that is used by all schemes
PlaintextModulus m_plaintextModulus;
// root of unity for plaintext modulus
NativeInteger m_plaintextRootOfUnity;
// big plaintext modulus that is used for arbitrary cyclotomics
NativeInteger m_plaintextBigModulus;
// root of unity for big plaintext modulus
NativeInteger m_plaintextBigRootOfUnity;
// plaintext generator is used for packed encoding (to find the correct
// automorphism index)
uint32_t m_plaintextGenerator;
// maximum batch size used by EvalSumKeyGen for packed encoding
uint32_t m_batchSize;
};

inline std::ostream& operator<<(std::ostream& out, const std::shared_ptr<EncodingParamsImpl>& o) {
Expand Down
22 changes: 11 additions & 11 deletions src/pke/include/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,11 @@ class Metadata {
}

/**
* A method that prints the contents of metadata objects.
* Please override in subclasses to print all members.
*/
virtual std::ostream& print(std::ostream& out) const {
out << "[ ]" << std::endl;
return out;
}

/**
* << operator implements by calling member method print.
* << operator implements by calling member method PrintMetadata.
* This is a friend method and cannot be overriden by subclasses.
*/
friend std::ostream& operator<<(std::ostream& out, const Metadata& m) {
m.print(out);
m.PrintMetadata(out);
return out;
}

Expand Down Expand Up @@ -139,6 +130,15 @@ class Metadata {
static uint32_t SerializedVersion() {
return 1;
}

protected:
/**
* A method that prints the contents of metadata objects.
* Please override in subclasses to print all members.
*/
virtual std::ostream& PrintMetadata(std::ostream& out) const {
OPENFHE_THROW("Not implemented");
}
};

} // end namespace lbcrypto
Expand Down
16 changes: 8 additions & 8 deletions src/pke/unittest/utils/UnitTestMetadataTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,6 @@ class MetadataTest : public Metadata {
}
}

/**
* Defines how to print the contents of objects of this class.
*/
std::ostream& print(std::ostream& out) const {
out << "[ " << m_s << " ]";
return out;
}

/**
* save method for serialization
*/
Expand Down Expand Up @@ -201,6 +193,14 @@ class MetadataTest : public Metadata {
}

protected:
/**
* Defines how to print the contents of objects of this class.
*/
std::ostream& PrintMetadata(std::ostream& out) const override {
out << "[ " << m_s << " ]";
return out;
}

std::string m_s;
};

Expand Down

0 comments on commit 5a4da31

Please sign in to comment.