Mentions légales du service

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

Stop passing transpose flag argument from matfaust.Faust.mtimes* to C++ core.

mtimes_trans wasn't actually used (in fact F.'*M means calling transpose
and then mtimes) but it is left for not breaking some tests.
Faust.mtimes_trans was emptied and now depends on mtimes (it was the reverse before) which is called after a simple transpose F.' if the transpose bool is true.
parent 1a20325e
No related branches found
No related tags found
No related merge requests found
Pipeline #834092 skipped
...@@ -790,56 +790,20 @@ classdef Faust ...@@ -790,56 +790,20 @@ classdef Faust
%> <p>@b See @b also Faust.Faust, Faust.rcg, Faust.ctranspose, Faust.complex %> <p>@b See @b also Faust.Faust, Faust.rcg, Faust.ctranspose, Faust.complex
%> %>
%====================================================================== %======================================================================
function G = mtimes(F,A) function C = mtimes(F,A)
G = mtimes_trans(F, A, 0); trans = false;
end
%======================================================================
%> @brief Multiplies the Faust F by A.' or A which is a dense matrix or a Faust object.
%>
%> This function overloads a Matlab built-in function.
%>
%> @warning if A is a matrix the function costs numfactors(F) matrix multiplications.
%> In that case its use is discouraged except for test purpose. However if A is a Faust object,
%> it costs the same that a Faust initialization with a number of factors equal to
%> F.numfactors()+A.numfactors() (like you can do directly with Faust.Faust).
%>
%> @param F the Faust object.
%> @param A The dense matrix to multiply or a Faust object.
%> @param trans equals 1 to calculate C=F'*A
%> or 0 to calculate C=F*A.
%>
%> @retval C The multiplication result (a dense matrix or a Faust object depending on what A is).
%>
%> <p> @b See @b also mtimes.
%======================================================================
function C = mtimes_trans(F,A,trans)
%%
if ~isreal(trans)
error('invalid argument trans, must be equal to 0 or 1');
end
if (trans ~= 1) && (trans ~= 0)
error('invalid argument trans, must be equal to 0 or 1');
end
% TODO: take trans into account when mul F to a scal or a Faust
% it's not a serious issue because mtimes_trans() shouldn't be called by final user
% (func's doc is filtered out in doxydoc)
if(isa(A, 'matfaust.Faust') && ~ isa(F, 'matfaust.Faust')) if(isa(A, 'matfaust.Faust') && ~ isa(F, 'matfaust.Faust'))
if(ismatrix(F)) if(ismatrix(F))
C = mtimes_trans(A', F', 0)'; C = mtimes(A', F')';
else else
C = mtimes_trans(A, F, 0); % F is scalar or something else (in which case it'll fail later) C = mtimes(A, F); % F is scalar or something else (in which case it'll fail later)
end end
elseif(isa(A,'matfaust.Faust')) elseif(isa(A,'matfaust.Faust'))
if (F.is_real) if (F.is_real)
if(isreal(A)) if(isreal(A))
C = matfaust.Faust(F, call_mex(F, 'mul_faust', A.matrix.objectHandle)); C = matfaust.Faust(F, call_mex(F, 'mul_faust', A.matrix.objectHandle));
else else
C = mtimes_trans(complex(F), A, trans); C = mtimes(complex(F), A);
end end
else else
if(A.is_real) if(A.is_real)
...@@ -852,27 +816,56 @@ classdef Faust ...@@ -852,27 +816,56 @@ classdef Faust
if(isreal(A)) if(isreal(A))
C = matfaust.Faust(F, call_mex(F, 'mul_scalar', A)); C = matfaust.Faust(F, call_mex(F, 'mul_scalar', A));
else else
C = mtimes_trans(complex(F), A, trans); C = mtimes(complex(F), A);
end end
else else
C = matfaust.Faust(F, call_mex(F, 'mul_scalar', A)); C = matfaust.Faust(F, call_mex(F, 'mul_scalar', A));
end end
elseif (F.is_real) % A is not a Faust, not a scalar (should be a matrix) elseif (F.is_real) % A is not a Faust, not a scalar (should be a matrix)
if (isreal(A)) if (isreal(A))
C = call_mex(F, 'multiply', A, trans); C = call_mex(F, 'multiply', A);
else else
C_real = call_mex(F, 'multiply', real(A), trans); C_real = call_mex(F, 'multiply', real(A));
C_imag = call_mex(F, 'multiply', imag(A), trans); C_imag = call_mex(F, 'multiply', imag(A));
C = C_real + 1i * C_imag; C = C_real + 1i * C_imag;
end end
else % F is complex and A is most likely a matrix else % F is complex and A is most likely a matrix
if(isreal(A)) if(isreal(A))
C = call_mex(F, 'multiply', F.convertFactorToComplex(A), trans); C = call_mex(F, 'multiply', F.convertFactorToComplex(A));
else else
% A is not necessarily a complex array, it could be a bsr matrix (a cell) % A is not necessarily a complex array, it could be a bsr matrix (a cell)
C = call_mex(F, 'multiply', F.convertFactorToComplex(A), trans); C = call_mex(F, 'multiply', F.convertFactorToComplex(A));
end end
end end
end
%======================================================================
%> @brief Multiplies the Faust F by A.' or A which is a dense matrix or a Faust object.
%>
%> This function overloads a Matlab built-in function.
%>
%> @warning if A is a matrix the function costs numfactors(F) matrix multiplications.
%> In that case its use is discouraged except for test purpose. However if A is a Faust object,
%> it costs the same that a Faust initialization with a number of factors equal to
%> F.numfactors()+A.numfactors() (like you can do directly with Faust.Faust).
%>
%> @param F the Faust object.
%> @param A The dense matrix to multiply or a Faust object.
%> @param trans equals 1 to calculate C=F'*A
%> or 0 to calculate C=F*A.
%>
%> @retval C The multiplication result (a dense matrix or a Faust object depending on what A is).
%>
%> <p> @b See @b also mtimes.
%======================================================================
function C = mtimes_trans(F, A, trans)
%%
if trans
F = F.'
end
mtimes(F, A)
end end
%====================================================================== %======================================================================
......
...@@ -4,15 +4,9 @@ template <typename SCALAR, FDevice DEV> ...@@ -4,15 +4,9 @@ template <typename SCALAR, FDevice DEV>
void faust_multiply(const mxArray **prhs, const int nrhs, mxArray **plhs, const int nlhs) void faust_multiply(const mxArray **prhs, const int nrhs, mxArray **plhs, const int nlhs)
{ {
Faust::TransformHelper<SCALAR,DEV>* core_ptr = convertMat2Ptr<Faust::TransformHelper<SCALAR,DEV> >(prhs[1]); Faust::TransformHelper<SCALAR,DEV>* core_ptr = convertMat2Ptr<Faust::TransformHelper<SCALAR,DEV> >(prhs[1]);
if (nlhs > 1 || nrhs != 4) if (nlhs > 1 || nrhs != 3)
mexErrMsgTxt("Multiply: Unexcepted number of arguments."); mexErrMsgTxt("Multiply: Unexcepted number of arguments.");
mwSize nelem = mxGetNumberOfElements(prhs[3]);
if (nelem != 1)
mexErrMsgTxt("invalid char argument.");
// boolean flag to know if the faust needs to be transposed
bool transpose_flag = (bool) mxGetScalar(prhs[3]);
// input matrix or vector from MATLAB // input matrix or vector from MATLAB
const mxArray * inMatlabMatrix = prhs[2]; const mxArray * inMatlabMatrix = prhs[2];
...@@ -21,7 +15,7 @@ void faust_multiply(const mxArray **prhs, const int nrhs, mxArray **plhs, const ...@@ -21,7 +15,7 @@ void faust_multiply(const mxArray **prhs, const int nrhs, mxArray **plhs, const
Faust::MatSparse<SCALAR,Cpu> spA; Faust::MatSparse<SCALAR,Cpu> spA;
mxArray2FaustspMat<SCALAR>(inMatlabMatrix, spA); mxArray2FaustspMat<SCALAR>(inMatlabMatrix, spA);
Faust::MatDense<SCALAR,Cpu> B; Faust::MatDense<SCALAR,Cpu> B;
B = (*core_ptr).multiply(spA, transpose_flag); B = (*core_ptr).multiply(spA);
plhs[0] = FaustMat2mxArray(B); plhs[0] = FaustMat2mxArray(B);
} }
else else
...@@ -30,15 +24,14 @@ void faust_multiply(const mxArray **prhs, const int nrhs, mxArray **plhs, const ...@@ -30,15 +24,14 @@ void faust_multiply(const mxArray **prhs, const int nrhs, mxArray **plhs, const
const size_t nbColA = mxGetN(inMatlabMatrix); const size_t nbColA = mxGetN(inMatlabMatrix);
const size_t nbRowOp = core_ptr->getNbRow(); const size_t nbRowOp = core_ptr->getNbRow();
const size_t nbColOp = core_ptr->getNbCol(); // getNbRow() and getNbCol is tranpose aware const size_t nbColOp = core_ptr->getNbCol(); // getNbRow() and getNbCol is tranpose aware
const size_t nbRowB = transpose_flag?nbColOp:nbRowOp; const size_t nbRowB = nbRowOp;
const size_t nbColB = nbColA; const size_t nbColB = nbColA;
/** Check parameters **/ /** Check parameters **/
//check dimension match //check dimension match
if (mxGetNumberOfDimensions(inMatlabMatrix) != 2 if (mxGetNumberOfDimensions(inMatlabMatrix) != 2 || nbRowA != nbColOp)
|| nbRowA != nbColOp && ! transpose_flag || nbRowA != nbRowOp && transpose_flag)
mexErrMsgTxt("Multiply : Wrong number of dimensions for the input vector or matrix (third argument)."); mexErrMsgTxt("Multiply : Wrong number of dimensions for the input vector or matrix (third argument).");
...@@ -61,15 +54,13 @@ void faust_multiply(const mxArray **prhs, const int nrhs, mxArray **plhs, const ...@@ -61,15 +54,13 @@ void faust_multiply(const mxArray **prhs, const int nrhs, mxArray **plhs, const
mwSize out_dims[2] = {nbRowB, 1}; mwSize out_dims[2] = {nbRowB, 1};
plhs[0] = helperCreateNumMxArray<SCALAR>(out_dims); plhs[0] = helperCreateNumMxArray<SCALAR>(out_dims);
newMxGetData(ptr_out, plhs[0]); newMxGetData(ptr_out, plhs[0]);
core_ptr->multiply(ptr_data, ptr_out, transpose_flag); core_ptr->multiply(ptr_data, ptr_out);
#else #else
Faust::Vect<SCALAR,Cpu> A(nbRowA, ptr_data); Faust::Vect<SCALAR,Cpu> A(nbRowA, ptr_data);
Faust::Vect<SCALAR,Cpu> B(nbRowB); Faust::Vect<SCALAR,Cpu> B(nbRowB);
B = (*core_ptr).multiply(A, transpose_flag); B = (*core_ptr).multiply(A);
plhs[0]=FaustVec2mxArray(B); plhs[0]=FaustVec2mxArray(B);
#endif #endif
} }
else else
{ // applying the Faust to a matrix { // applying the Faust to a matrix
...@@ -78,12 +69,12 @@ void faust_multiply(const mxArray **prhs, const int nrhs, mxArray **plhs, const ...@@ -78,12 +69,12 @@ void faust_multiply(const mxArray **prhs, const int nrhs, mxArray **plhs, const
mwSize out_dims[2] = {nbRowB, nbColA}; mwSize out_dims[2] = {nbRowB, nbColA};
plhs[0] = helperCreateNumMxArray<SCALAR>(out_dims); plhs[0] = helperCreateNumMxArray<SCALAR>(out_dims);
newMxGetData(ptr_out, plhs[0]); newMxGetData(ptr_out, plhs[0]);
core_ptr->multiply(ptr_data, nbColA, ptr_out, transpose_flag); core_ptr->multiply(ptr_data, nbColA, ptr_out);
#else #else
Faust::MatDense<SCALAR,Cpu> A(ptr_data, nbRowA, nbColA); Faust::MatDense<SCALAR,Cpu> A(ptr_data, nbRowA, nbColA);
Faust::MatDense<SCALAR,Cpu> B(nbRowB, nbColA); Faust::MatDense<SCALAR,Cpu> B(nbRowB, nbColA);
B = (*core_ptr).multiply(A, transpose_flag); B = (*core_ptr).multiply(A);
plhs[0]=FaustMat2mxArray(B); plhs[0]=FaustMat2mxArray(B);
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment