Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 6a67f8cb authored by hhakim's avatar hhakim
Browse files

Replace the workaround in FaustCore by a copy argument and use it in...

Replace the workaround in FaustCore by a copy argument and use it in butterfly, hierarchical and palm4msa.

cf. 7f38af8f for the bug to workaround.
parent 33ec1ac0
Branches
Tags
No related merge requests found
......@@ -222,14 +222,14 @@ function F = butterfly(M, varargin)
end
if(strcmp(class(M), 'single'))
core_obj = mexButterflyRealFloat(M, type, perm);
F = Faust(core_obj, isreal(M), 'cpu', 'float');
F = Faust(core_obj, isreal(M), 'cpu', 'float', true); % 4th arg is for copying
else
if(isreal(M))
core_obj = mexButterflyReal(M, type, perm);
else
core_obj = mexButterflyCplx(M, type, perm);
end
F = Faust(core_obj, isreal(M));
F = Faust(core_obj, isreal(M), 'cpu', 'double', true); % 4th arg is for copying
end
end
......
......@@ -321,7 +321,7 @@ function varargout = hierarchical(M, p, varargin)
else
[lambda, core_obj] = mexHierarchical_factCplx(M, mex_params);
end
F = Faust(core_obj, isreal(M), 'cpu', dtype);
F = Faust(core_obj, isreal(M), 'cpu', dtype, true); % 4th arg to copy factors
elseif(backend == 2020)
if(isreal(M))
if(gpu)
......@@ -344,7 +344,7 @@ function varargout = hierarchical(M, p, varargin)
[lambda, core_obj] = mexHierarchical2020Cplx(M, mex_params);
end
end
F = Faust(core_obj, isreal(M), 'cpu', dtype);
F = Faust(core_obj, isreal(M), 'cpu', dtype, true); % 4th arg to copy factors
end
varargout = {F, lambda, p};
end
......@@ -121,5 +121,5 @@ function [F,lambda] = palm4msa(M, p, varargin)
end
end
end
F = Faust(core_obj, isreal(M), 'cpu', dtype);
F = Faust(core_obj, isreal(M), 'cpu', dtype, true); % 4 args to copy factors
end
......@@ -307,7 +307,12 @@ classdef Faust
else
F.dtype = 'double';
end
F.matrix = FaustCore(varargin{1}, F.is_real, F.dev, F.dtype);
if(nargin >= 5)
F.matrix = FaustCore(varargin{1}, F.is_real, F.dev, F.dtype, varargin{5});
else
% default copy value is false
F.matrix = FaustCore(varargin{1}, F.is_real, F.dev, F.dtype);
end
% hack to raise an error in case of non-consistent handle and is_real arg.
try
n = numfactors(F);
......
......@@ -52,7 +52,7 @@ classdef FaustCore < handle
methods
%% Constructor - Create a new C++ class instance
function this = FaustCore(varargin)
if(nargin == 4) && ~iscell(varargin{1}) %&& isa(varargin{1}, 'handle'))
if(nargin >= 4) && ~iscell(varargin{1}) %&& isa(varargin{1}, 'handle'))
%if(~ isvalid(varargin{1}))
% error('FaustCore: invalid handle to copy passed to the constructor.')
%end
......@@ -63,21 +63,21 @@ classdef FaustCore < handle
this.isRealFlag = varargin{2};
this.dev = varargin{3};
this.dtype = varargin{4};
if ~ strcmp(this.dtype, 'float')
onGPU = startsWith(this.dev, 'gpu');
% TODO: the copy of factors shouldn't be necessary
% it's here to fix a bug when for instance calling
% matfaust.fact.hierarchical/butterfly, the returned Faust is
% ok but F-M (for example) leads to a crash
% (it's probably because of matrix reference manager that is
% duplicated in static memory of different shared
% libraries/mexs -- still to verify. All Faust object must be
% managed by mexFaustReal/Cplx/Float, hence the copy)
% we don't use this workaround for single precision Faust
% because sparse matrices in single precision aren't supported
% by matlab which lead to buffer type error
% (double instead of float in the cpp mexcode)
if nargin > 4
if ~ islogical(varargin{5})
error('FaustCore arg. 5 must be a logical')
end
copy = varargin{5};
else
copy = false;
end
if copy && strcmp(this.dtype, 'float')
warning('FaustCore: even if copy is true, it won''t be used because the factors are in single precision and matlab does''nt support single sparse matrices.')
end
if copy && ~ strcmp(this.dtype, 'float')
% don't use the copy for 'float' because matlab doesn't support
% single precision sparse matrices
onGPU = startsWith(this.dev, 'gpu')
nf = call_mex(this, 'numfactors');
facts = cell(1, nf);
for i=1:nf
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment