Table of Contents

Class MatrixCompressionMetadata<T>

Namespace
AiDotNet.ModelCompression
Assembly
AiDotNet.dll

Metadata for matrix compression operations that wraps the underlying vector compression metadata.

public class MatrixCompressionMetadata<T> : ICompressionMetadata<T>

Type Parameters

T

The numeric type used for calculations (e.g., float, double).

Inheritance
MatrixCompressionMetadata<T>
Implements
Inherited Members

Remarks

MatrixCompressionMetadata stores the information needed to decompress a 2D weight matrix that was compressed by first flattening it to a vector. It preserves the original matrix dimensions and delegates the actual compression metadata to an inner ICompressionMetadata instance.

For Beginners: When compressing a 2D matrix (like weights in a fully connected layer), we need to remember:

  1. The original shape - how many rows and columns the matrix had
  2. How the flattened data was compressed (the inner compression details)

Think of it like folding a shirt to pack in a suitcase:

  • You flatten the shirt (2D to 1D)
  • You compress it in a vacuum bag (apply compression algorithm)
  • You need to remember the original shirt size to unfold it properly later

This metadata class keeps track of all that information so we can perfectly restore the original matrix shape after decompression.

Constructors

MatrixCompressionMetadata(int, int, ICompressionMetadata<T>)

Initializes a new instance of the MatrixCompressionMetadata class.

public MatrixCompressionMetadata(int originalRows, int originalColumns, ICompressionMetadata<T> innerMetadata)

Parameters

originalRows int

The number of rows in the original matrix.

originalColumns int

The number of columns in the original matrix.

innerMetadata ICompressionMetadata<T>

The compression metadata from the underlying vector compression.

Remarks

For Beginners: When creating matrix compression metadata, you specify:

  • originalRows: How tall the matrix was (e.g., 100 for a 100x50 matrix)
  • originalColumns: How wide the matrix was (e.g., 50 for a 100x50 matrix)
  • innerMetadata: The details of how the flattened weights were compressed

This information is essential for restoring the matrix to its exact original shape.

Exceptions

ArgumentOutOfRangeException

Thrown when rows or columns are not positive.

ArgumentNullException

Thrown when innerMetadata is null.

Properties

InnerMetadata

Gets the inner compression metadata from the underlying vector compression algorithm.

public ICompressionMetadata<T> InnerMetadata { get; }

Property Value

ICompressionMetadata<T>

Remarks

For Beginners: This contains the actual compression details from whatever algorithm was used (weight clustering, Huffman encoding, etc.). The matrix compression is just a wrapper that remembers the shape; the real compression work is tracked here.

OriginalColumns

Gets the number of columns in the original matrix.

public int OriginalColumns { get; }

Property Value

int

Remarks

For Beginners: The column count of the original weight matrix before compression. In neural networks, this often corresponds to the number of output neurons in a layer.

OriginalLength

Gets the original total number of elements in the flattened matrix.

public int OriginalLength { get; }

Property Value

int

Remarks

For Beginners: This is the total count of weight values in the original matrix, calculated as rows multiplied by columns. For example, a 100x50 matrix has 5,000 elements. This is needed to allocate the right amount of memory when decompressing.

OriginalRows

Gets the number of rows in the original matrix.

public int OriginalRows { get; }

Property Value

int

Remarks

For Beginners: The row count of the original weight matrix before compression. In neural networks, this often corresponds to the number of input features or neurons.

Type

Gets the compression type from the underlying compression algorithm.

public CompressionType Type { get; }

Property Value

CompressionType

Remarks

For Beginners: This returns the actual compression algorithm type (like WeightClustering or HuffmanEncoding) that was used to compress the flattened matrix data. The matrix metadata itself is just a shape container - it delegates to the inner metadata for the real compression type.

Methods

GetMetadataSize()

Gets the total size in bytes of this metadata structure, including the inner metadata.

public long GetMetadataSize()

Returns

long

The metadata size in bytes.

Remarks

For Beginners: When calculating the total compressed size, you need to include the metadata overhead. This method calculates:

  • The size of the shape information (2 integers for rows and columns = 8 bytes)
  • Plus the size of the inner compression metadata

This gives an accurate picture of the total storage needed for decompression.