Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
faust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
faust group
faust
Commits
b5dc5030
Commit
b5dc5030
authored
3 years ago
by
hhakim
Browse files
Options
Downloads
Patches
Plain Diff
Add mex code for permutation argument of matfaust.fact.butterfly.
parent
ab20e3c8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wrapper/matlab/src/mexButterfly.cpp.in
+54
-4
54 additions, 4 deletions
wrapper/matlab/src/mexButterfly.cpp.in
with
54 additions
and
4 deletions
wrapper/matlab/src/mexButterfly.cpp.in
+
54
−
4
View file @
b5dc5030
...
@@ -76,15 +76,65 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
...
@@ -76,15 +76,65 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
}
}
try
try
{
{
ButterflyFactDir dir = RIGHT;
if(nrhs >= 2)
dir = static_cast<ButterflyFactDir>(static_cast<int>(mxGetScalar(prhs[1])));
TransformHelper<SCALAR, Cpu>* F = nullptr;
TransformHelper<SCALAR, Cpu>* F = nullptr;
Faust::MatDense<SCALAR,Cpu> matrix;
Faust::MatDense<SCALAR,Cpu> matrix;
MatSparse<SCALAR,Cpu> *perm_mat = nullptr;
mxArray2FaustMat(prhs[0], matrix);
mxArray2FaustMat(prhs[0], matrix);
F = Faust::butterfly_hierarchical(matrix, dir);
ButterflyFactDir dir = RIGHT;
if(nrhs >= 2)
dir = static_cast<ButterflyFactDir>(static_cast<int>(mxGetScalar(prhs[1])));
if(nrhs >= 3)
{
#ifndef MX_HAS_INTERLEAVED_COMPLEX
#error perm argument compiling isn't supported for Matlab versions prior to R2018a
#endif
auto perm_inds = prhs[2];
if(mxIsSparse(perm_inds))
mexErrMsgTxt("The matrix of indices must be dense");
else
{
// build a MatSparse perm_mat from permutation column indices
const size_t pnrows = mxGetM(perm_inds);
const size_t pncols = mxGetN(perm_inds);
const size_t perm_size = matrix.getNbCol();
// if [] was passed for perm, it means no perm at all
if(pnrows != 0 && pncols != 0)
{
assert(perm_size == pnrows || perm_size == pncols);
if (mxGetNumberOfDimensions(perm_inds) != 2)
mexErrMsgTxt("The matrix of indices must be two-dimensional");
if(mxIsComplex(perm_inds))
mexErrMsgTxt("The permutionation indices can't be complex");
SCALAR* ptr_data = nullptr;
newMxGetData(ptr_data, perm_inds);
unsigned int *row_ids = new unsigned int[perm_size];
unsigned int *ucol_ids = new unsigned int[perm_size];
for(int i=0;i < perm_size;i++)
ucol_ids[i] = (unsigned int) ptr_data[i]-1; // matlab is one-base indexed
std::iota(row_ids, row_ids+perm_size, 0);
SCALAR *ones = new SCALAR[perm_size];
std::fill(ones, ones+perm_size, SCALAR(1));
perm_mat = new Faust::MatSparse<SCALAR, Cpu>((unsigned int*)row_ids, ucol_ids, ones, perm_size, perm_size, perm_size);
delete[] row_ids;
delete[] ucol_ids;
delete[] ones;
}
}
}
F = butterfly_hierarchical(matrix, dir, perm_mat);
plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR, Cpu>>(F);
plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR, Cpu>>(F);
if(perm_mat != nullptr)
delete perm_mat;
}
}
catch (const std::exception& e)
catch (const std::exception& e)
{
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment