In [1]:

```
from pyfaust import Faust
import numpy as np
from scipy import sparse
factors = []
is_sparse = False
for i in range(0,5):
if(is_sparse):
factors += [ sparse.random(100,100, dtype=np.float64, format='csr',
density=0.1)]
else:
factors += [ np.random.rand(100, 100).astype(np.float64) ]
is_sparse = not is_sparse
F = Faust(factors)
```

Note that sparse factors are in CSR format but you can also use CSC format (other formats for sparse matrices are not supported).

It can be interesting to look at the scipy.sparse module documentation, in particular: csr_matrix, csc_matrix.

In [2]:

```
F
```

Out[2]:

Faust size 100x100, density 3.2, nnz_sum 32000, 5 factor(s): - FACTOR 0 (double) DENSE, size 100x100, density 1, nnz 10000 - FACTOR 1 (double) SPARSE, size 100x100, density 0.1, nnz 1000 - FACTOR 2 (double) DENSE, size 100x100, density 1, nnz 10000 - FACTOR 3 (double) SPARSE, size 100x100, density 0.1, nnz 1000 - FACTOR 4 (double) DENSE, size 100x100, density 1, nnz 10000

`nnz_sum`

) along with all its factors.

You can also call **F.display()** or simply `print(F)`

to get all the information.

In [3]:

```
F.display()
print(F)
```

`F`

anymore, you can delete it with the instruction `del F`

. Normally, that's the role of the garbage collector but it might happen that your Faust is very eager in memory and a manual deletion with a manual garbage collection is necessary (calling `gc.collect()`

after one or several `del`

).

It's really handy to create a Faust and retrieve it from a file later. Let's see in the code below how to proceed.

First save the Faust.

In [4]:

```
F.save('F.mat')
```

Now let's get it back from file.

In [5]:

```
file_F = Faust(filepath='F.mat')
file_F
```

Out[5]:

`F.mat`

file from matfaust.

The pyfaust package provides functions for generating Faust objects by many manners. One noticeable function of this package is rand(). This function allows to generate a random Faust satisfying certain constraints; the number of factors, the size of these factors, the density, the scalar type, etc.

Below are examples of (pseudo-)random generations.

In [6]:

```
from pyfaust import rand
F = rand(2, 10, num_factors=2, density=.5, dtype='complex')
G = rand(10, 20, num_factors=[2, 5], dim_sizes=[10, 20], density=.5, fac_type='dense')
```

*each factor*, is about 0.5. Since the `fac_type`

argument is not set, each factor is sparse.

In [7]:

```
F
```

Out[7]:

Faust size 2x10, density 0.6, nnz_sum 12, 2 factor(s): - FACTOR 0 (complex) SPARSE, size 2x2, density 0.5, nnz 2 - FACTOR 1 (complex) SPARSE, size 2x10, density 0.5, nnz 10

`num_factors`

value (`[2, 5]`

) defines the bounds in which we want the number of factors to be and likewise the `dim_sizes`

argument defines the bounds in which to randomly choose the sizes of the two dimensions of each intermediary factor composing the Faust. The sizes are chosen to keep G consistent though, this is a matrix product!

In [8]:

```
G
```

Out[8]:

Faust size 10x20, density 1.4, nnz_sum 280, 2 factor(s): - FACTOR 0 (double) DENSE, size 10x19, density 0.473684, nnz 90 - FACTOR 1 (double) DENSE, size 19x20, density 0.5, nnz 190

There exist many ways to create a Faust, please look at the package documentation for more information. It would be the topic of another notebook! If you want, for example, to learn about Faust generation based on the FAµST's factorization algorithms, check this notebook: Using the FAµST Factorization Wrappers.

**Note**: this notebook was executed using the following pyfaust version:

In [9]:

```
import pyfaust
pyfaust.version()
```

Out[9]:

'3.38.9'