Mentions légales du service

Skip to content
Snippets Groups Projects
Commit fb426cc9 authored by hhakim's avatar hhakim
Browse files

Add a Jupyter Notebook to introduce the different ways to create a pyfaust.Faust.

parent 419d593c
Branches
Tags 2.4.3 2.4.4
No related merge requests found
Pipeline #833874 skipped
......@@ -87,7 +87,9 @@ if(BUILD_DOCUMENTATION)
file(REMOVE ${PROJECT_BINARY_DIR}/doc/README_install_part.html)
configure_file(${FAUST_DOC_SRC_DIR}/bin_pkgs/README_template.md ${PROJECT_BINARY_DIR}/doc/README.md)
configure_file(${FAUST_DOC_SRC_DIR}/faq.md ${PROJECT_BINARY_DIR}/doc/faq.md)
endif(BUILD_DOCUMENTATION)
configure_file(${FAUST_DOC_SRC_DIR}/Faust_creation.ipynb ${PROJECT_BINARY_DIR}/doc/html/Faust_creation.ipynb COPYONLY)
configure_file(${FAUST_DOC_SRC_DIR}/Faust_creation.html ${PROJECT_BINARY_DIR}/doc/html/Faust_creation.html COPYONLY)
endif(BUILD_DOCUMENTATION)
......
This diff is collapsed.
%% Cell type:markdown id: tags:
# How to Create a Faust
### 1. Setting the factors manually
Let's start by creating a Faust manually, that is factor by factor.
Below is a creation of a Faust containing 5 factors, alternating sparse and dense 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 the scipy.sparse module documentation.
https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.html
https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csc_matrix.html
%% Cell type:code id: tags:
``` python
from pyfaust import FaustFactory, 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)
```
%% Cell type:code id: tags:
``` python
F
```
%% Cell type:markdown id: tags:
As you noticed, the Faust output contains the list of factors and their features but also a header describing the Faust operator itself: its size, its density, the number of nonzeros it contains (nnz_sum) along all its factors.
You can also call **[F.display()](https://faustgrp.gitlabpages.inria.fr/faust/last-doc/html/classpyfaust_1_1Faust.html#a34bdc939e28dd9d1cd102ad715e6fb91)** to get these informations.
%% Cell type:code id: tags:
``` python
F.display()
```
%% Cell type:markdown id: tags:
### 2. Faust File Loading
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.
%% Cell type:code id: tags:
``` python
F.save('F.mat')
```
%% Cell type:markdown id: tags:
Now let's get it back from file.
%% Cell type:code id: tags:
``` python
file_F = Faust(filepath='F.mat')
file_F
```
%% Cell type:markdown id: tags:
The format used is matlab v7. This format allows the compatibility between pyfaust and matfaust, the matlab wrapper. You can easily reload the F.mat file from matfaust.
%% Cell type:markdown id: tags:
### 3. Generating a random Faust
The pyfaust package provides a class called FaustFactory responsible for generating Faust objects by many manners.
One noticeable function of this class is [rand()](https://faustgrp.gitlabpages.inria.fr/faust/last-doc/html/classpyfaust_1_1FaustFactory.html#a92535c4d3532acdc60847e5f86c63394). This function allows to generate a random Faust defined under certain constraints; the number of factors, the size of these factors, the density, the scalar type, etc.
Below are an example of random generations.
%% Cell type:code id: tags:
``` python
from pyfaust import FaustFactory as FF
F = FF.rand(2, 10, .5, field='complex')
G = FF.rand([2, 5], [10, 20], .5, fac_type="dense")
```
%% Cell type:markdown id: tags:
F is a complex Faust. Its factors are of the both formats (dense or sparse) with a half of nonzeros coefficients (density of .5).
%% Cell type:code id: tags:
``` python
F
```
%% Cell type:markdown id: tags:
G is a real Faust (the default scalar type). The first argument ([2, 5]) in the [rand()](https://faustgrp.gitlabpages.inria.fr/faust/last-doc/html/classpyfaust_1_1FaustFactory.html#a92535c4d3532acdc60847e5f86c63394) call is the bounds in which we want the number of factors to be and likewise the second argument defines the bounds in which to randomly choose the sizes of the two dimensions of each factor composing the Faust.
%% Cell type:code id: tags:
``` python
G
```
%% Cell type:markdown id: tags:
### 4. Other Ways of Creation
There exist many ways to create a Faust, please look the [FaustFactory](https://faustgrp.gitlabpages.inria.fr/faust/last-doc/html/classpyfaust_1_1FaustFactory.html) to get insights of all these methods.
It will be the topic of another notebook!
......@@ -4,4 +4,5 @@ This documentation details the [API](annotated.html) of those frontends (a.k.a.
Please refer to this [README](./md_README.html) for a quick guide on how to install and use FAµST wrappers.
You might also be interested in this introduction through Jupyter Notebook:
- [How to Create a Faust with pyfaust](./Faust_creation.html) (Here for [downloading it](./Faust_creation.ipynb))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment