Mila 0.13.48
Deep Neural Network Library
Loading...
Searching...
No Matches
Mila::Dnn::Serialization::SerializationMetadata Class Referenceexport

Type-safe metadata container for component serialization. More...

Public Member Functions

 SerializationMetadata ()=default
bool empty () const noexcept
 Check if metadata is empty.
bool getBool (const std::string &key) const
 Get boolean value.
double getDouble (const std::string &key) const
 Get double value.
std::vector< double > getDoubleVector (const std::string &key) const
 Get double vector value.
int64_t getInt (const std::string &key) const
 Get integer value.
std::vector< int64_t > getIntVector (const std::string &key) const
 Get integer vector value.
shape_t getShape (const std::string &key) const
 Get shape value.
std::string getString (const std::string &key) const
 Get string value.
std::vector< std::string > getStringVector (const std::string &key) const
 Get string vector value.
bool has (const std::string &key) const
 Check if key exists in metadata.
std::vector< std::string > keys () const
 Get all keys in metadata.
SerializationMetadataset (const std::string &key, bool value)
 Set boolean value.
SerializationMetadataset (const std::string &key, const char *value)
 Set string value from C-string literal.
SerializationMetadataset (const std::string &key, const shape_t &value)
 Set shape value.
SerializationMetadataset (const std::string &key, const std::string &value)
 Set string value.
SerializationMetadataset (const std::string &key, const std::vector< double > &value)
 Set double vector value.
SerializationMetadataset (const std::string &key, const std::vector< std::string > &value)
 Set string vector value.
SerializationMetadataset (const std::string &key, double value)
 Set floating-point value (double).
SerializationMetadataset (const std::string &key, float value)
 Set floating-point value (float).
SerializationMetadataset (const std::string &key, int64_t value)
 Set integer value.
SerializationMetadataset (const std::string &key, MetadataValue value)
 Set metadata value with automatic type deduction.
size_t size () const noexcept
 Get number of metadata entries.
json toJson () const
 Convert to JSON representation (internal use only).
std::optional< bool > tryGetBool (const std::string &key) const noexcept
 Get optional boolean value.
std::optional< double > tryGetDouble (const std::string &key) const noexcept
 Get optional double value.
std::optional< float > tryGetFloat (const std::string &key) const noexcept
 Get optional float value.
std::optional< int64_t > tryGetInt (const std::string &key) const noexcept
 Get optional integer value.
std::optional< shape_ttryGetShape (const std::string &key) const noexcept
 Get optional shape value.
std::optional< std::string > tryGetString (const std::string &key) const noexcept
 Get optional string value.

Static Public Member Functions

static SerializationMetadata fromJson (const json &j)
 Construct from JSON representation (internal use only).

Private Member Functions

const MetadataValuegetValue (const std::string &key) const

Private Attributes

std::map< std::string, MetadataValuedata_

Detailed Description

Type-safe metadata container for component serialization.

Provides fluent API for building and reading component metadata without exposing JSON implementation details. Internally uses JSON for serialization but can be swapped with other formats without breaking user code.

Examples
/__w/Mila/Mila/Mila/Src/Dnn/Components/Activations/Gelu/Gelu.ixx, /__w/Mila/Mila/Mila/Src/Dnn/Core/ComponentFactory.ixx, and /__w/Mila/Mila/Mila/Src/Dnn/Core/NetworkFactory.ixx.

Constructor & Destructor Documentation

◆ SerializationMetadata()

Mila::Dnn::Serialization::SerializationMetadata::SerializationMetadata ( )
default
Here is the caller graph for this function:

Member Function Documentation

◆ empty()

bool Mila::Dnn::Serialization::SerializationMetadata::empty ( ) const
inlinenoexcept

Check if metadata is empty.

Returns
true if no metadata entries

◆ fromJson()

SerializationMetadata Mila::Dnn::Serialization::SerializationMetadata::fromJson ( const json & j)
inlinestatic

Construct from JSON representation (internal use only).

Used by ModelArchive to deserialize metadata. Not intended for direct user consumption.

Parameters
jJSON object
Returns
SerializationMetadata instance
Examples
/__w/Mila/Mila/Mila/Src/Dnn/Serialization/ModelArchive.ixx.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBool()

bool Mila::Dnn::Serialization::SerializationMetadata::getBool ( const std::string & key) const
inline

Get boolean value.

Parameters
keyMetadata key
Returns
Boolean value
Exceptions
std::runtime_errorif key not found or type mismatch
Here is the call graph for this function:

◆ getDouble()

double Mila::Dnn::Serialization::SerializationMetadata::getDouble ( const std::string & key) const
inline

Get double value.

Parameters
keyMetadata key
Returns
Double value
Exceptions
std::runtime_errorif key not found or type mismatch
Here is the call graph for this function:

◆ getDoubleVector()

std::vector< double > Mila::Dnn::Serialization::SerializationMetadata::getDoubleVector ( const std::string & key) const
inline

Get double vector value.

Parameters
keyMetadata key
Returns
Double vector
Exceptions
std::runtime_errorif key not found or type mismatch
Here is the call graph for this function:

◆ getInt()

int64_t Mila::Dnn::Serialization::SerializationMetadata::getInt ( const std::string & key) const
inline

Get integer value.

Parameters
keyMetadata key
Returns
Integer value
Exceptions
std::runtime_errorif key not found or type mismatch
Examples
/__w/Mila/Mila/Mila/Src/Dnn/Components/Activations/Gelu/Gelu.ixx, and /__w/Mila/Mila/Mila/Src/Dnn/Core/ComponentFactory.ixx.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getIntVector()

std::vector< int64_t > Mila::Dnn::Serialization::SerializationMetadata::getIntVector ( const std::string & key) const
inline

Get integer vector value.

Parameters
keyMetadata key
Returns
Integer vector
Exceptions
std::runtime_errorif key not found or type mismatch
Here is the call graph for this function:

◆ getShape()

shape_t Mila::Dnn::Serialization::SerializationMetadata::getShape ( const std::string & key) const
inline

Get shape value.

Constructs a TensorShape from the stored wire-format integer vector.

Parameters
keyMetadata key
Returns
shape_t value
Exceptions
std::runtime_errorif key not found or type mismatch
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getString()

std::string Mila::Dnn::Serialization::SerializationMetadata::getString ( const std::string & key) const
inline

Get string value.

Parameters
keyMetadata key
Returns
String value
Exceptions
std::runtime_errorif key not found or type mismatch
Examples
/__w/Mila/Mila/Mila/Src/Dnn/Core/ComponentFactory.ixx, and /__w/Mila/Mila/Mila/Src/Dnn/Core/NetworkFactory.ixx.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getStringVector()

std::vector< std::string > Mila::Dnn::Serialization::SerializationMetadata::getStringVector ( const std::string & key) const
inline

Get string vector value.

Parameters
keyMetadata key
Returns
String vector
Exceptions
std::runtime_errorif key not found or type mismatch
Here is the call graph for this function:

◆ getValue()

const MetadataValue & Mila::Dnn::Serialization::SerializationMetadata::getValue ( const std::string & key) const
inlineprivate
Here is the caller graph for this function:

◆ has()

bool Mila::Dnn::Serialization::SerializationMetadata::has ( const std::string & key) const
inline

Check if key exists in metadata.

Parameters
keyMetadata key
Returns
true if key exists
Examples
/__w/Mila/Mila/Mila/Src/Dnn/Core/ComponentFactory.ixx, and /__w/Mila/Mila/Mila/Src/Dnn/Core/NetworkFactory.ixx.
Here is the caller graph for this function:

◆ keys()

std::vector< std::string > Mila::Dnn::Serialization::SerializationMetadata::keys ( ) const
inline

Get all keys in metadata.

Returns
Vector of metadata keys

◆ set() [1/10]

SerializationMetadata & Mila::Dnn::Serialization::SerializationMetadata::set ( const std::string & key,
bool value )
inline

Set boolean value.

Parameters
keyMetadata key
valueBoolean value
Returns
Reference to this for method chaining
Here is the call graph for this function:

◆ set() [2/10]

SerializationMetadata & Mila::Dnn::Serialization::SerializationMetadata::set ( const std::string & key,
const char * value )
inline

Set string value from C-string literal.

Parameters
keyMetadata key
valueC-string value
Returns
Reference to this for method chaining
Here is the call graph for this function:

◆ set() [3/10]

SerializationMetadata & Mila::Dnn::Serialization::SerializationMetadata::set ( const std::string & key,
const shape_t & value )
inline

Set shape value.

Converts TensorShape to the wire format (std::vector<int64_t>) for JSON serialization. getShape() performs the inverse conversion on load.

Parameters
keyMetadata key
valueShape value
Returns
Reference to this for method chaining
Here is the call graph for this function:

◆ set() [4/10]

SerializationMetadata & Mila::Dnn::Serialization::SerializationMetadata::set ( const std::string & key,
const std::string & value )
inline

Set string value.

Parameters
keyMetadata key
valueString value
Returns
Reference to this for method chaining
Here is the call graph for this function:

◆ set() [5/10]

SerializationMetadata & Mila::Dnn::Serialization::SerializationMetadata::set ( const std::string & key,
const std::vector< double > & value )
inline

Set double vector value.

Parameters
keyMetadata key
valueDouble vector
Returns
Reference to this for method chaining
Here is the call graph for this function:

◆ set() [6/10]

SerializationMetadata & Mila::Dnn::Serialization::SerializationMetadata::set ( const std::string & key,
const std::vector< std::string > & value )
inline

Set string vector value.

Parameters
keyMetadata key
valueString vector
Returns
Reference to this for method chaining
Here is the call graph for this function:

◆ set() [7/10]

SerializationMetadata & Mila::Dnn::Serialization::SerializationMetadata::set ( const std::string & key,
double value )
inline

Set floating-point value (double).

Parameters
keyMetadata key
valueDouble value
Returns
Reference to this for method chaining
Here is the call graph for this function:

◆ set() [8/10]

SerializationMetadata & Mila::Dnn::Serialization::SerializationMetadata::set ( const std::string & key,
float value )
inline

Set floating-point value (float).

Stores the float as double in the internal representation for consistent handling by the metadata container.

Parameters
keyMetadata key
valueFloat value
Returns
Reference to this for method chaining
Here is the call graph for this function:

◆ set() [9/10]

SerializationMetadata & Mila::Dnn::Serialization::SerializationMetadata::set ( const std::string & key,
int64_t value )
inline

Set integer value.

Parameters
keyMetadata key
valueInteger value
Returns
Reference to this for method chaining
Here is the call graph for this function:

◆ set() [10/10]

SerializationMetadata & Mila::Dnn::Serialization::SerializationMetadata::set ( const std::string & key,
MetadataValue value )
inline

Set metadata value with automatic type deduction.

Parameters
keyMetadata key
valueMetadata value (string, int64_t, double, bool, vector, shape_t)
Returns
Reference to this for method chaining
Examples
/__w/Mila/Mila/Mila/Src/Dnn/Components/Activations/Gelu/Gelu.ixx.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

size_t Mila::Dnn::Serialization::SerializationMetadata::size ( ) const
inlinenoexcept

Get number of metadata entries.

Returns
Entry count

◆ toJson()

json Mila::Dnn::Serialization::SerializationMetadata::toJson ( ) const
inline

Convert to JSON representation (internal use only).

Used by ModelArchive to serialize metadata. Not intended for direct user consumption.

Returns
JSON object
Here is the caller graph for this function:

◆ tryGetBool()

std::optional< bool > Mila::Dnn::Serialization::SerializationMetadata::tryGetBool ( const std::string & key) const
inlinenoexcept

Get optional boolean value.

Parameters
keyMetadata key
Returns
Boolean value or std::nullopt if not found or type mismatch
Here is the caller graph for this function:

◆ tryGetDouble()

std::optional< double > Mila::Dnn::Serialization::SerializationMetadata::tryGetDouble ( const std::string & key) const
inlinenoexcept

Get optional double value.

Parameters
keyMetadata key
Returns
Double value or std::nullopt if not found or type mismatch

◆ tryGetFloat()

std::optional< float > Mila::Dnn::Serialization::SerializationMetadata::tryGetFloat ( const std::string & key) const
inlinenoexcept

Get optional float value.

Converts stored integer or double metadata to float when possible.

Parameters
keyMetadata key
Returns
Float value or std::nullopt if not found or type mismatch
Here is the caller graph for this function:

◆ tryGetInt()

std::optional< int64_t > Mila::Dnn::Serialization::SerializationMetadata::tryGetInt ( const std::string & key) const
inlinenoexcept

Get optional integer value.

Parameters
keyMetadata key
Returns
Integer value or std::nullopt if not found or type mismatch
Examples
/__w/Mila/Mila/Mila/Src/Dnn/Components/Activations/Gelu/Gelu.ixx.
Here is the caller graph for this function:

◆ tryGetShape()

std::optional< shape_t > Mila::Dnn::Serialization::SerializationMetadata::tryGetShape ( const std::string & key) const
inlinenoexcept

Get optional shape value.

Constructs a TensorShape from the stored wire-format integer vector.

Parameters
keyMetadata key
Returns
shape_t or std::nullopt if not found or type mismatch
Here is the caller graph for this function:

◆ tryGetString()

std::optional< std::string > Mila::Dnn::Serialization::SerializationMetadata::tryGetString ( const std::string & key) const
inlinenoexcept

Get optional string value.

Parameters
keyMetadata key
Returns
String value or std::nullopt if not found or type mismatch
Examples
/__w/Mila/Mila/Mila/Src/Dnn/Components/Activations/Gelu/Gelu.ixx, and /__w/Mila/Mila/Mila/Src/Dnn/Core/ComponentFactory.ixx.
Here is the caller graph for this function:

Member Data Documentation

◆ data_

std::map<std::string, MetadataValue> Mila::Dnn::Serialization::SerializationMetadata::data_
private

The documentation for this class was generated from the following file: