-  3.39.25
pyfaust.FaustMulMode Class Reference

Enumeration class of all matrix chain multiplication methods available to multiply a Faust to a matrix or to compute Faust.toarray(). More...

Static Public Attributes

int DEFAULT_L2R = 0
 The default method, it computes the product from the right to the left. More...
 
int DYNPROG = 5
 This method implements the classic dynamic programming solution to the chain matrix problem. More...
 
int TORCH_CPU_L2R = 8
 This method computes the product of the matrix chain from the left to the right using the Torch C++ library (CPU backend). More...
 
int TORCH_CPU_GREEDY = 9
 This method is implemented using the Torch library and follows a greedy principle: it chooses to multiply the less costly product of two matrices at each step of the whole product computation. More...
 
int TORCH_CPU_DENSE_DYNPROG_SPARSE_L2R = 10
 The same as TORCH_CPU_L2R except that torch::chain_matmul is used to compute in one call the intermediary product of dense contiguous factors, then the result is multiplied by sparse factors if any remains. More...
 

Detailed Description

Enumeration class of all matrix chain multiplication methods available to multiply a Faust to a matrix or to compute Faust.toarray().

These methods are used by Faust.optimize_time().

Note
it's not advisable to use these methods directly. The user should use Faust.optimize_time() but the access is left open for experimental purpose.

Examples

>>> from pyfaust import rand as frand, seed as fseed, FaustMulMode
>>> from numpy.random import rand, seed
>>> fseed(42) # just for reproducibility
>>> seed(42)
>>> F = frand(100, 100, 5, [100, 1024])
>>> F.m_faust.set_FM_mul_mode(FaustMulMode.DYNPROG) # method used to compute Faust-matrix product or Faust.toarray()
>>> F @ rand(F.shape[1], 512) # Faust-matrix mul. using method DYNPROG
array([[34.29346113, 33.5135258 , 31.83862847, ..., 32.89901332,
36.90417709, 32.20140406],
[45.40983901, 42.52512058, 42.14810308, ..., 44.2648802 ,
48.4027215 , 40.55809844],
[27.12859996, 28.26596387, 25.898984 , ..., 27.47460378,
29.35053152, 25.24167465],
...,
[48.42899773, 47.4001851 , 43.96370573, ..., 47.25218683,
53.03379773, 46.12690926],
[39.9583232 , 40.778263 , 36.65671168, ..., 40.69390161,
43.55280684, 40.37781963],
[26.92859133, 28.40176389, 24.73304576, ..., 27.72648267,
28.78612539, 25.82727371]])
>>> F.toarray() # using the same method
array([[1.13340453, 0.94853857, 0.60713635, ..., 1.29155048, 0.98107444,
0.30254208],
[1.92753189, 0.45268035, 0.72474175, ..., 0.43439703, 1.21532731,
0.50115957],
[1.35028724, 0.30557493, 0.15632569, ..., 0.80602032, 0.56741856,
0.58193385],
...,
[0.63172715, 1.0883051 , 1.2760964 , ..., 0.45745425, 0.85951258,
0.25173183],
[0.85748924, 0.68716077, 0.96293286, ..., 1.09480206, 0.8219215 ,
0.83602967],
[0.5461995 , 0.36918089, 0.4556373 , ..., 0.57842966, 0.52784458,
0.30465166]])

Member Data Documentation

◆ DEFAULT_L2R

int pyfaust.FaustMulMode.DEFAULT_L2R = 0
static

The default method, it computes the product from the right to the left.

◆ DYNPROG

int pyfaust.FaustMulMode.DYNPROG = 5
static

This method implements the classic dynamic programming solution to the chain matrix problem.

See https://en.wikipedia.org/wiki/Matrix_chain_multiplication#A_dynamic_programming_algorithm. Note that the standard method is extended in order to take into account the complexity of multiplications including a sparse matrix (because that's not the same cost than multiplying dense matrices).

◆ TORCH_CPU_DENSE_DYNPROG_SPARSE_L2R

int pyfaust.FaustMulMode.TORCH_CPU_DENSE_DYNPROG_SPARSE_L2R = 10
static

The same as TORCH_CPU_L2R except that torch::chain_matmul is used to compute in one call the intermediary product of dense contiguous factors, then the result is multiplied by sparse factors if any remains.

torch::chain_matmul follows the dynamic programming principle as DYNPROG method does (but the former handles only dense matrices).

References: https://pytorch.org/cppdocs/api/function_namespaceat_1aee491a9ff453b6033b4106516bc61a9d.html?highlight=chain_matmul https://pytorch.org/docs/stable/generated/torch.chain_matmul.html?highlight=chain_matmul#torch.chain_matmul This method is only available for the specific packages pyfaust_torch.

◆ TORCH_CPU_GREEDY

int pyfaust.FaustMulMode.TORCH_CPU_GREEDY = 9
static

This method is implemented using the Torch library and follows a greedy principle: it chooses to multiply the less costly product of two matrices at each step of the whole product computation.

The computational cost depends on the matrix dimensions and the number of nonzeros (when a matrix is in sparse format). This method is only available for the specific packages pyfaust_torch.

◆ TORCH_CPU_L2R

int pyfaust.FaustMulMode.TORCH_CPU_L2R = 8
static

This method computes the product of the matrix chain from the left to the right using the Torch C++ library (CPU backend).

This method is only available for the specific packages pyfaust_torch.


The documentation for this class was generated from the following file:
pyfaust.seed
def seed(s)
(Re)Initializes the pyfaust pseudo-random generator.
Definition: __init__.py:5334
pyfaust.rand
def rand(num_rows, num_cols, num_factors=None, dim_sizes=None, density=None, fac_type='sparse', per_row=True, dev='cpu', dtype='float64', field=None, seed=0)
Generates a random Faust.
Definition: __init__.py:5016