Mentions légales du service

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

Integrate python quickstart script into pyfaust.demo module.

Consequently updating the doc, cmake build and test commands.
parent b772ea99
Branches
No related tags found
No related merge requests found
......@@ -201,7 +201,16 @@ Otherwise it works but you’ll need to set the `export' command manually in
<p>In the same spirit than the Matlab tutorial showed in the previous section, you can execute the quick start script for Python.</p>
<pre><code>$ python2.7 @CMAKE_INSTALL_PREFIX@/python/quickstart.py
<pre><code>$ python2.7 -c "from pyfaust.demo import quickstart; quickstart.run()"
dimension of the Faust : (1000, 2000)
multiplication SPEED-UP using Faust
Faust is 1.83845941093 faster than a full matrix
Faust nnz: 300000
Faust density: 0.15
Faust RCG: 6.66666666667
Faust norm: 55156456.373
Faust nb of factors: 2
end quickstart.py
</code></pre>
<p>You can also go through the Python terminal to build a FAµST product and call its object methods.</p>
......
......@@ -176,7 +176,17 @@ Note that the doxygen documentation for the Matlab API is also available locally
In the same spirit than the Matlab tutorial showed in the previous section, you can execute the quick start script for Python.
$ python2.7 @CMAKE_INSTALL_PREFIX@/python/quickstart.py
$ python2.7 -c "from pyfaust.demo import quickstart; quickstart.run()"
dimension of the Faust : (1000, 2000)
multiplication SPEED-UP using Faust
Faust is 1.83845941093 faster than a full matrix
Faust nnz: 300000
Faust density: 0.15
Faust RCG: 6.66666666667
Faust norm: 55156456.373
Faust nb of factors: 2
end quickstart.py
You can also go through the Python terminal to build a FAµST product and call its object methods.
......
......@@ -250,7 +250,7 @@ if (BUILD_WRAPPER_PYTHON)
if(PYTHON_MODULE_SCIPY)
add_test(NAME PYTHON${PY_VER}_FAUST_TIME COMMAND ${PYTHON_EXE} ${FAUST_SRC_TEST_SRC_PYTHON_DIR}/test_pyFaust_time.py ${FAUST_PYTHON_BIN_DIR} ${FAUST_BIN_TEST_FIG_DIR})
add_test(NAME PYTHON${PY_VER}_FAUST_DEMO_INSTALL COMMAND ${PYTHON_EXE} ${FAUST_PYTHON_BIN_DIR}/quickstart.py)
add_test(NAME PYTHON${PY_VER}_FAUST_DEMO_INSTALL COMMAND ${PYTHON_EXE} -c "from pyfaust.demo import quickstart; quickstart.run()")
add_test(NAME PYTHON${PY_VER}_FAUST_UNIT_TESTS COMMAND ${PYTHON_EXE} ${FAUST_SRC_TEST_SRC_PYTHON_DIR}/test_FaustPy.py ${FAUST_PYTHON_BIN_DIR}) # second arg. is the FaustPy's dir. to add to PYTHONPATH
endif(PYTHON_MODULE_SCIPY)
endif()
......
......@@ -40,9 +40,6 @@ if(BUILD_OPENBLAS)
set(FAUST_PYTHON_LIBS "${FAUST_PYTHON_LIBS},'openblas'")
endif(BUILD_OPENBLAS)
#move quickstart demo file
configure_file(${FAUST_PYTHON_SRC_DIR}/quickstart.py ${FAUST_PYTHON_BIN_DIR}/quickstart.py COPYONLY)
# configure the setup.py.in into setup.py (equivalent of Makefile for Python)
configure_file(${FAUST_PYTHON_SRC_DIR}/setup.py.in ${FAUST_PYTHON_BIN_DIR}/setup.py @ONLY)
configure_file(${FAUST_PYTHON_SRC_SRC_DIR}/FaustCorePy.pyx ${FAUST_PYTHON_BIN_DIR}/FaustCorePy.pyx COPYONLY)
......
......@@ -4,6 +4,108 @@ from pylab import *
import os,sys
class quickstart:
@staticmethod
def run():
#import the pyfaust package
import pyfaust;
# import module to generate data
import scipy
from scipy import sparse as sp
import numpy as np
# generate the factors of the Faust
dim1 = 1000;
dim2 = 2000;
nb_factor = 2;
list_factor_sparse=[0]*nb_factor
list_factor=[0]*nb_factor
int_max = 120
density_per_fact=0.1;
list_factor_sparse[0]=int_max*sp.random(dim1,dim1,density=density_per_fact,format='csr',dtype=np.float64);
list_factor[0]=list_factor_sparse[0].toarray();
list_factor_sparse[1]=int_max*sp.random(dim1,dim2,density=density_per_fact,format='csr',dtype=np.float64);
list_factor[1]=list_factor_sparse[1].toarray();
#print(list_factor[0])
#print(list_factor[1])
# create a Faust named F from its factors
A = pyfaust.Faust(list_factor)
# get the size of the Faust
print("dimension of the Faust : ", A.shape)
# transpose a Faust
A_trans = A.transpose()
# multiplication a Numpy matrix by a Faust
x = np.random.randint(int_max, size=(dim2,1))
y = A * x
# convert a faust to numpy matrix
A_numpy = A.toarray()
# slicing
coeff = A[0,0]
col_2nd = A[:,1];
submatrix_A = A[3:5,2:3]
# speed-up multiplication
import time
nb_mult = 100
t_dense = 0.0;
t_faust = 0.0;
for i in range(nb_mult):
x=np.random.randint(int_max, size=(dim2,1))
t_begin = time.time()
y_dense = A_numpy.dot(x)
t_elapsed = time.time() - t_begin
t_dense += t_elapsed
t_begin = time.time()
y_faust=A*x;
t_elapsed = time.time()-t_begin
t_faust += t_elapsed
print("multiplication SPEED-UP using Faust")
print("Faust is "+str(t_dense/t_faust)+" faster than a full matrix")
print("Faust nnz: "+str(A.nnz_sum()))
print("Faust density: "+str(A.density()))
print("Faust RCG: "+str(A.rcg()))
print("Faust norm: "+str(A.norm()))
print("Faust nb of factors: "+str(A.get_num_factors()))
for i in range(0,A.get_num_factors()):
#print("Faust size of factor ",i,"=",A.get_factor(i).shape)
# test Faust gets back the same sparse factors given at init
assert((A.get_factor(i).toarray() == list_factor_sparse[i]).all())
#print(A.get_factor(i))
# test Faust saving
A.save("A.mat")
As = pyfaust.Faust(filepath="A.mat")
assert((A.get_factor(0).toarray() == As.get_factor(0).toarray()).all())
assert((A.get_factor(1).toarray() == As.get_factor(1).toarray()).all())
# test Faust transpose
#print(A.get_factor(0))
tA = A.transpose()
tf1 = tA.get_factor(1).toarray()
#print(tf1)
f1 = np.transpose(tf1)
assert(not (tf1 == A.get_factor(0).toarray()).all() or (tf1 == f1).all())
assert((f1 == A.get_factor(0).toarray()).all())
print("end quickstart.py")
class fft:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment