da4ml.cmvm.util package

Submodules

da4ml.cmvm.util.bit_decompose module

da4ml.cmvm.util.bit_decompose.csd_decompose(arr: ndarray[tuple[int, ...], dtype[_ScalarType_co]], center=True)

Convert an 2D array to CSD representation.

Parameters:
  • arr (ndarray) – Input array to be converted.

  • center (bool, optional) – If True, the array is centered before conversion. Default is True. If False, the function may accept non-2D arrays.

Returns:

  • csd (ndarray) – CSD representation of the input array after centering, if center is True.

  • shift0 (ndarray) – Shift values for the first axis.

  • shift1 (ndarray) – Shift values for the second axis.

da4ml.cmvm.util.bit_decompose.shift_centering(arr: ndarray[tuple[int, ...], dtype[_ScalarType_co]], axis: int)

da4ml.cmvm.util.mat_decompose module

da4ml.cmvm.util.mat_decompose.kernel_decompose(kernel: ndarray, dc: int = -2)

Decompose a 2D kernel matrix into two matrices with the delay-constrained approx MST.

Parameters:
  • kernel (np.ndarray) – The input kernel matrix to decompose.

  • dc (int, optional) –

    Delay constraint, by default -1 If -2, no delay constraint is applied. If -1, return trivial decomposition (m0 = kernel, m1 = I).

    The delay constraint limits the maximum latency (hops) of the decomposed multiplication structure.

Returns:

The decomposed matrices (m0, m1): kernel = m0 @ m1

Return type:

tuple[np.ndarray, np.ndarray]

da4ml.cmvm.util.mat_decompose.prim_mst_dc(cost_mat: ndarray, dc: int = -1)

Minimum Spanning Tree (MST) using Prim’s algorithm with a delay constraint. May not be optimal. Always start from the root node (0).

Parameters:
  • cost_mat (np.ndarray) – The adjacency matrix of the graph, where cost_mat[i, j] is the cost of the edge between i and j.

  • dc (int, optional) –

    The delay constraint, by default -1 If -1, no delay constraint is applied.

    Delay of each edge is ceiling(log2(cost_mat[i, j])).

    Delay from the root node to any node is the maximum latency of each edge connecting in between, plus ceiling(log2(#number of connection edges)). Latency is NOT the sum of the latencies.

Returns:

The adjacency list of the MST, where each row is a pair of nodes (parent, child).

Return type:

np.ndarray

Module contents

da4ml.cmvm.util.csd_decompose(arr: ndarray[tuple[int, ...], dtype[_ScalarType_co]], center=True)

Convert an 2D array to CSD representation.

Parameters:
  • arr (ndarray) – Input array to be converted.

  • center (bool, optional) – If True, the array is centered before conversion. Default is True. If False, the function may accept non-2D arrays.

Returns:

  • csd (ndarray) – CSD representation of the input array after centering, if center is True.

  • shift0 (ndarray) – Shift values for the first axis.

  • shift1 (ndarray) – Shift values for the second axis.

da4ml.cmvm.util.kernel_decompose(kernel: ndarray, dc: int = -2)

Decompose a 2D kernel matrix into two matrices with the delay-constrained approx MST.

Parameters:
  • kernel (np.ndarray) – The input kernel matrix to decompose.

  • dc (int, optional) –

    Delay constraint, by default -1 If -2, no delay constraint is applied. If -1, return trivial decomposition (m0 = kernel, m1 = I).

    The delay constraint limits the maximum latency (hops) of the decomposed multiplication structure.

Returns:

The decomposed matrices (m0, m1): kernel = m0 @ m1

Return type:

tuple[np.ndarray, np.ndarray]