Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 4612a6b2 authored by Nicolas Bellot's avatar Nicolas Bellot Committed by hhakim
Browse files

wrapper Python ajout fontionnalite slicing F(2:3,4:7)

parent 84b2e826
Branches
Tags
No related merge requests found
......@@ -43,7 +43,7 @@ sys.path.append(FaustPath)
import numpy as np
#import PyFaust
import FaustPy
dim1 = 3
dim1 = 4
dim2 = 5
dim3 = 7
nb_factor = 3
......@@ -215,7 +215,61 @@ print "Ok"
######################################
print "*** SLICING ***"
for i in range(dim1):
for j in range(dim2):
F_i_j=F[i,j]
F_trans_j_i=F_trans[j,i]
if F_i_j != F_dense[i,j]:
raise ValueError('invalid value')
if F_i_j != F_trans_dense[j,i]:
raise ValueError('invalid value')
F_dense_slice = F[...,...]
if not (F_dense_slice.shape == (dim1, dim2)) :
print "expected size : "+str([dim1, dim2])
print "got : "+str(F_dense_slice.shape)
raise ValueError('invalid size of the dense matrix')
if not (F_dense==F_dense_slice).all():
raise ValueError('invalid value')
F_trans_dense_slice = F_trans[...,...]
if not (F_trans_dense_slice.shape == (dim2, dim1)) :
print "expected size : "+str([dim2, dim1])
print "got : "+str(F_trans_dense_slice.shape)
raise ValueError('invalid size of the dense matrix')
if not (F_trans_dense==F_trans_dense_slice).all():
raise ValueError('invalid value')
F_dense_slice_1 = F[0:dim1,0:dim2]
if not (F_dense_slice_1.shape == (dim1, dim2)) :
print "expected size : "+str([dim1, dim2])
print "got : "+str(F_dense_slice_1.shape)
raise ValueError('invalid size of the dense matrix')
if not (F_dense==F_dense_slice_1).all():
raise ValueError('invalid value')
#~ slice_row=dim1:0:-1
#~ slice_col=dim2:0:-1
#~ F_dense_slice_2 = F[slice_row,slice_col]
F_dense_slice_2 = F[::-1,::-1]
if not (F_dense_slice_2.shape == (dim1, dim2)) :
print "expected size : "+str([dim1, dim2])
print "got : "+str(F_dense_slice_2.shape)
print F_dense_slice_2
print ""
print F_dense
raise ValueError('invalid size of the dense matrix')
if not (F_dense[::-1,::-1]==F_dense_slice_2).all():
raise ValueError('invalid value')
##############################################################################
## Description: ##
## ##
## FaustPy is class wrapping a C++ class ##
## ##
## For more information on the FAuST Project, please visit the website ##
## of the project : <http://faust.gforge.inria.fr> ##
## ##
## License: ##
## Copyright (2016): Nicolas Bellot, Adrien Leman, Thomas Gautrais, ##
## Luc Le Magoarou, Remi Gribonval ##
## INRIA Rennes, FRANCE ##
## http://www.inria.fr/ ##
## ##
## The FAuST Toolbox is distributed under the terms of the GNU Affero ##
## General Public License. ##
## This program is free software: you can redistribute it and/or modify ##
## it under the terms of the GNU Affero General Public License as ##
## published by the Free Software Foundation. ##
## ##
## This program is distributed in the hope that it will be useful, but ##
## WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ##
## See the GNU Affero General Public License for more details. ##
## ##
## You should have received a copy of the GNU Affero General Public ##
## License along with this program. ##
## If not, see <http://www.gnu.org/licenses/>. ##
## ##
## Contacts: ##
## Nicolas Bellot : nicolas.bellot@inria.fr ##
## Adrien Leman : adrien.leman@inria.fr ##
## Thomas Gautrais : thomas.gautrais@inria.fr ##
## Luc Le Magoarou : luc.le-magoarou@inria.fr ##
## Remi Gribonval : remi.gribonval@inria.fr ##
## ##
##############################################################################
#import sys
#FaustPath='/home/nbellot/Documents/faust_root/faust/trunk/devcpp/build/wrapper/python'
#sys.path.append(FaustPath)
......@@ -50,38 +88,24 @@ class Faust:
return self_dense
#~ dim1 = 5
#~ dim2 = 10
#~ dim3 = 7
#~ nb_factor = 2
#~ int_max= 100
#~ print('**** CONFIG FAUST F ****');
#~ print 'dim1 : '+str(dim1)
#~ print 'dim2 : '+str(dim2)
#~ print 'nb_factor : '+str(nb_factor)
#~ #initialisation de la liste des facteurs
#~ list_factor=[0]*nb_factor
#~ for i in range(nb_factor):
#~ list_factor[i]=np.random.randint(int_max, size=(dim1,dim1))
#~ list_factor[nb_factor-1]=np.random.randint(int_max, size=(dim1,dim2))
def __getitem__(self,list_index):
#check if list_index has a 2 index (row and column)
if (len(list_index) != 2):
raise ValueError('list_index must contains 2 elements, the row index and the col index')
#check if the index are slice or integer or Ellipsis
for id in list_index:
if (not isinstance(id, slice)) and (not isinstance(id,int) and (id !=Ellipsis)):
raise ValueError('list_index must contains slice (1:n) or Ellipsis (...) or int (2)')
keyCol=list_index[1]
keyRow=list_index[0]
identity=np.eye(self.getNbCol(),self.getNbCol());
identity=identity[...,keyCol]
submatrix=self*identity
submatrix=submatrix[keyRow,:]
return submatrix
#~ print "*** CONTRUCTOR ***"
#~ F = FaustPy(list_factor)
#~ print "Ok"
#~ print("dim : "+str(F.shape))
#~ Fbis=F.transpose()
#~ print("**** F ****")
#~ F.afficher()
#~ print("**** F trans ****")
#~ Fbis.afficher()
#~ print("**** attributs F ****")
#~ print(F.__dict__)
#~ dir(Fbis)
......@@ -2,7 +2,7 @@
## Description: ##
## ##
## Cython source file making the links between : ##
## the Cython module CyFaust and Python ##
## the Cython module FaustCoreCy and Python ##
## ##
## For more information on the FAuST Project, please visit the website ##
## of the project : <http://faust.gforge.inria.fr> ##
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment