Mentions légales du service

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

Add the wrapper matfaust.opt_butterfly_faust to optimize any butterfly Faust...

Add the wrapper matfaust.opt_butterfly_faust to optimize any butterfly Faust (in addition to the DFT).

    #275.
parent c2185ab0
Branches
Tags
No related merge requests found
...@@ -31,7 +31,7 @@ if(BUILD_DOCUMENTATION) ...@@ -31,7 +31,7 @@ if(BUILD_DOCUMENTATION)
string(CONCAT DOXYGEN_FILE_PATTERNS "*.cpp *.hpp *.h *.cu *.hu") string(CONCAT DOXYGEN_FILE_PATTERNS "*.cpp *.hpp *.h *.cu *.hu")
endif() endif()
if(BUILD_WRAPPER_MATLAB) if(BUILD_WRAPPER_MATLAB)
string(CONCAT DOXYGEN_FILE_PATTERNS ${DOXYGEN_FILE_PATTERNS} " Faust.m FaustMulMode.m StoppingCriterion.m ConstraintGeneric.m ConstraintMat.m ConstraintReal.m ConstraintInt.m ConstraintName.m ParamsFact.m ParamsHierarchical.m ParamsPalm4MSA.m FaustFactory.m hadamard.m quickstart.m fft.m bsl.m runtimecmp.m runall.m version.m faust_fact.m ParamsHierarchicalSquareMat.m ParamsHierarchicalRectMat.m license.m omp.m wht.m dft.m eye.m rand.m rand_bsr.m eigtj.m hierarchical.m fact.m palm4msa.m fgft_givens.m fgft_palm.m svdtj.m splin.m spcol.m proj_gen.m sp.m const.m supp.m hankel.m toeplitz.m circ.m normcol.m normlin.m splincol.m blockdiag.m skperm.m enable_gpu_mod.m is_gpu_mod_enabled.m isFaust.m poly.m basis.m next.m expm_multiply.m FaustPoly.m MHTPParams.m palm4msa_mhtp.m hierarchical_mhtp.m butterfly.m ParamsHierarchicalDFT.m create_bsr.m ParamsPalm4msaWHT.m proj_id.m ParamsHierarchicalNoResCons.m ParamsHierarchicalWHTNoResCons.m ParamsHierarchicalRectMatNoResCons.m circ.m anticirc.m toeplitz.m dct.m dst.m rand_butterfly.m ") # warning: the space on the end matters string(CONCAT DOXYGEN_FILE_PATTERNS ${DOXYGEN_FILE_PATTERNS} " Faust.m FaustMulMode.m StoppingCriterion.m ConstraintGeneric.m ConstraintMat.m ConstraintReal.m ConstraintInt.m ConstraintName.m ParamsFact.m ParamsHierarchical.m ParamsPalm4MSA.m FaustFactory.m hadamard.m quickstart.m fft.m bsl.m runtimecmp.m runall.m version.m faust_fact.m ParamsHierarchicalSquareMat.m ParamsHierarchicalRectMat.m license.m omp.m wht.m dft.m eye.m rand.m rand_bsr.m eigtj.m hierarchical.m fact.m palm4msa.m fgft_givens.m fgft_palm.m svdtj.m splin.m spcol.m proj_gen.m sp.m const.m supp.m hankel.m toeplitz.m circ.m normcol.m normlin.m splincol.m blockdiag.m skperm.m enable_gpu_mod.m is_gpu_mod_enabled.m isFaust.m poly.m basis.m next.m expm_multiply.m FaustPoly.m MHTPParams.m palm4msa_mhtp.m hierarchical_mhtp.m butterfly.m ParamsHierarchicalDFT.m create_bsr.m ParamsPalm4msaWHT.m proj_id.m ParamsHierarchicalNoResCons.m ParamsHierarchicalWHTNoResCons.m ParamsHierarchicalRectMatNoResCons.m circ.m anticirc.m toeplitz.m dct.m dst.m rand_butterfly.m opt_butterfly_faust.m ") # warning: the space on the end matters
endif() endif()
if(BUILD_WRAPPER_PYTHON) if(BUILD_WRAPPER_PYTHON)
string(CONCAT DOXYGEN_FILE_PATTERNS ${DOXYGEN_FILE_PATTERNS} "__init__.py factparams.py demo.py tools.py fact.py proj.py poly.py") string(CONCAT DOXYGEN_FILE_PATTERNS ${DOXYGEN_FILE_PATTERNS} "__init__.py factparams.py demo.py tools.py fact.py proj.py poly.py")
......
...@@ -3423,6 +3423,32 @@ classdef Faust ...@@ -3423,6 +3423,32 @@ classdef Faust
end end
methods(Static) methods(Static)
%================================================================
%> Optimizes any Faust composed of butterfly factors.
%===
%> The returned Faust will be more efficient if multiplied by a vector or a
%> matrix.
%> This optimization is based on the diagonals of each butterfly factor.
%> Multiplying a butterfly factor B by a vector x (y = B*x) is equivalent to forming
%> two diagonals D1 and D2 from B and compute y' = D1*x + D2*x(I) where I is
%> set in the proper order to obtain y' = y.
%>
%> @param F: The Faust to optimize. If the factors of F are not set according to
%> a butterfly structure, the result is not defined.
%>
%> @retval G the optimized Faust.
%>
%> @b See @b also: matfaust.fact.butterfly, matfaust.dft, matfaust.rand_butterfly.
%>
%================================================================
function G = opt_butterfly(F)
if ~ matfaust.isFaust(F)
error('F must be a Faust.')
end
G = matfaust.Faust(F, call_mex(F, 'opt_butterfly'));
end
%================================================================ %================================================================
%> Returns true if obj is a Faust object, false otherwise. %> Returns true if obj is a Faust object, false otherwise.
%=== %===
......
%=================================
%> See matfaust.Faust.opt_butterfly alias.
%>
%=================================
function G = opt_butterfly_faust(F)
import matfaust.Faust;
G = Faust.opt_butterfly(F)
% if ~ matfaust.isFaust(F)
% error('F must be a Faust.')
% end
% G = matfaust.Faust(F, call_mex(F, 'opt_butterfly', F.matrix.objectHandle));
% func_name = 'opt_butterfly';
% if (strcmp(F.dev, 'cpu'))
% if(F.is_real)
% if(strcmp(F.dtype, 'double'))
% G = matfaust.Faust(F, mexFaustReal(func_name, F.matrix.objectHandle));
% else % float
% G = matfaust.Faust(F, mexFaustRealFloat(func_name, F.matrix.objectHandle));
% end
% else
% G = matfaust.Faust(F, mexFaustCplx(func_name, F.matrix.objectHandle));
% end
% elseif(startsWith(F.dev, 'gpu'))
% if(F.is_real)
% if(strcmp(F.dtype, 'double'))
% G = matfaust.Faust(F, mexFaustGPUReal(func_name, F.matrix.objectHandle));
% else % float
% G = matfaust.Faust(F, mexFaustGPURealFloat(func_name, F.matrix.objectHandle));
% end
% else
% G = matfaust.Faust(F, mexFaustGPUCplx(func_name, F.matrix.objectHandle));
% end
% end
end
/****************************************************************************/
/* Description: */
/* file where the C++ class Faust::TransformHelper is interfaced */
/* with Matlab */
/* */
/* For more information on the FAuST Project, please visit the website */
/* of the project : <http://faust.inria.fr> */
/* */
/* License: */
/* Copyright (2022): Hakim HADJ-DJILANI */
/* 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 */
/* Hakim hadj-djilani : hakim.hadj-djilani@inria.fr */
/* Remi Gribonval : remi.gribonval@inria.fr */
/* */
/* References: */
/* [1] Le Magoarou L. and Gribonval R., "Flexible multi-layer sparse */
/* approximations of matrices and applications", Journal of Selected */
/* Topics in Signal Processing, 2016. */
/* <https://hal.archives-ouvertes.fr/hal-01167948v1> */
#ifndef __MEX_FAUST_OPT_BUTTERFLY__
#define __MEX_FAUST_OPT_BUTTERFLY__
template <typename SCALAR, FDevice DEV>
void faust_opt_butterfly(const mxArray **prhs, const int nrhs, mxArray **plhs, const int nlhs);
#include "faust_opt_butterfly.hpp"
#endif
#include "class_handle.hpp"
#include "faust_TransformHelper.h"
#include "faust_TransformHelperButterfly.h"
#ifdef USE_GPU_MOD
#include "faust_TransformHelperButterfly_gpu.h"
#endif
template <typename SCALAR, FDevice DEV>
void faust_opt_butterfly(const mxArray **prhs, const int nrhs, mxArray **plhs, const int nlhs)
{
auto F = convertMat2Ptr<Faust::TransformHelper<SCALAR, DEV>>(prhs[1]);
auto oF = Faust::TransformHelperButterfly<SCALAR, DEV>::optFaust(F);
plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR,DEV>>(oF);
}
...@@ -102,6 +102,7 @@ ...@@ -102,6 +102,7 @@
#include "faust_double.h" #include "faust_double.h"
#include "faust_fourier.h" #include "faust_fourier.h"
#include "faust_hadamard.h" #include "faust_hadamard.h"
#include "faust_opt_butterfly.h"
#include "faust_eye.h" #include "faust_eye.h"
#cmakedefine DEV @DEV@ #cmakedefine DEV @DEV@
#cmakedefine DEV_IS_CPU #cmakedefine DEV_IS_CPU
...@@ -244,6 +245,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -244,6 +245,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
faust_fourier<SCALAR,DEV>(prhs, nrhs, plhs, nlhs); faust_fourier<SCALAR,DEV>(prhs, nrhs, plhs, nlhs);
else if(!strcmp("hadamard", cmd)) else if(!strcmp("hadamard", cmd))
faust_hadamard<SCALAR,DEV>(prhs, nrhs, plhs, nlhs); faust_hadamard<SCALAR,DEV>(prhs, nrhs, plhs, nlhs);
else if(!strcmp("opt_butterfly", cmd))
faust_opt_butterfly<SCALAR, DEV>(prhs, nrhs, plhs, nlhs);
else if(!strcmp("eye", cmd)) else if(!strcmp("eye", cmd))
faust_eye<SCALAR,DEV>(prhs, nrhs, plhs, nlhs); faust_eye<SCALAR,DEV>(prhs, nrhs, plhs, nlhs);
#ifdef DEV_IS_CPU #ifdef DEV_IS_CPU
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment