algos/mst/utils.py
def array_to_bits(matrix: np.array, bits: int, n_ints = None):
    """
    Transform an array of numbers from decimal representation to binary.

    Reference: Yan, Yujun, et al. "Neural execution engines: Learning to execute subroutines." arXiv preprint arXiv:2006.08084 (2020).
    https://arxiv.org/pdf/2006.08084.pdf
    Page 4, Bitwise Embeddings

    :param matrix: array of integers
    :param bits: number of bits for the binary representation.
    :param n_ints: number of decimal places to consider for floating point numbers.
    :return: an tensor of numbers on binary.
    """
    if n_ints is not None:
        matrix = (matrix * n_ints).astype(int)
    n_samples, n_features = matrix.shape
    get_bin = lambda n, z: np.array(list(format(n, 'b').zfill(z))).astype(int)
    x_train_bits = np.stack([get_bin(num, bits) for num_list in matrix for num in num_list])
    return torch.FloatTensor(x_train_bits).view(n_samples, n_features, bits)

    Transform an array of numbers from decimal representation to binary.

    Reference: Yan, Yujun, et al. "Neural execution engines: Learning to execute subroutines." arXiv preprint arXiv:2006.08084 (2020).
    https://arxiv.org/pdf/2006.08084.pdf
    Page 4, Bitwise Embeddings

    :param matrix: array of integers
    :param bits: number of bits for the binary representation.
    :param n_ints: number of decimal places to consider for floating point numbers.
    :return: an tensor of numbers on binary.
    
Transform an array of numbers from decimal representation to binary.
Reference: Yan, Yujun, et al. "Neural execution engines: Learning to execute subroutines." arXiv preprint arXiv:2006.08084 (2020).
Transform an array of numbers from decimal representation to binary . Reference : Yan Yujun et al . " Neural execution engines : Learning to execute subroutines . " arXiv preprint arXiv : 2006 . 08084 ( 2020 ) .
def array_to_bits(matrix: np.array, bits: int, n_ints = None):
    if n_ints is not None:
        matrix = (matrix * n_ints).astype(int)
    n_samples, n_features = matrix.shape
    get_bin = lambda n, z: np.array(list(format(n, 'b').zfill(z))).astype(int)
    x_train_bits = np.stack([get_bin(num, bits) for num_list in matrix for num in num_list])
    return torch.FloatTensor(x_train_bits).view(n_samples, n_features, bits)
def array_to_bits ( matrix : np . array , bits : int , n_ints = None ) : if n_ints is not None : matrix = ( matrix * n_ints ) . astype ( int ) n_samples , n_features = matrix . shape get_bin = lambda n , z : np . array ( list ( format ( n , 'b' ) . zfill ( z ) ) ) . astype ( int ) x_train_bits = np . stack ( [ get_bin ( num , bits ) for num_list in matrix for num in num_list ] ) return torch . FloatTensor ( x_train_bits ) . view ( n_samples , n_features , bits )
Transform an array of numbers from decimal representation to binary.
Transform an array of numbers from decimal representation to binary .
"""
    Transform an array of numbers from decimal representation to binary.

    Reference: Yan, Yujun, et al. "Neural execution engines: Learning to execute subroutines." arXiv preprint arXiv:2006.08084 (2020).
    https://arxiv.org/pdf/2006.08084.pdf
    Page 4, Bitwise Embeddings

    :param matrix: array of integers
    :param bits: number of bits for the binary representation.
    :param n_ints: number of decimal places to consider for floating point numbers.
    :return: an tensor of numbers on binary.
    """
an tensor of numbers on binary.
an tensor of numbers on binary .
matrix
np.array
array of integers
array of integers
bits
int
number of bits for the binary representation.
number of bits for the binary representation .
n_ints
number of decimal places to consider for floating point numbers.
number of decimal places to consider for floating point numbers .