Mentions légales du service

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

Update matfaust.wht to support CPU and GPU float type.

parent ce811c09
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
%> @param n the power of two exponent for a Hadamard matrix of order n and a factorization into log2(n) factors. %> @param n the power of two exponent for a Hadamard matrix of order n and a factorization into log2(n) factors.
%> @param 'normed',bool: (optional) true (by default) to normalize the returned Faust as if Faust.normalize() was called, false otherwise. %> @param 'normed',bool: (optional) true (by default) to normalize the returned Faust as if Faust.normalize() was called, false otherwise.
%> @param 'dev',str: (optional) 'cpu' to create a CPU Faust (default choice) and 'gpu' for a GPU Faust. %> @param 'dev',str: (optional) 'cpu' to create a CPU Faust (default choice) and 'gpu' for a GPU Faust.
%> @param 'dtype', 'double' (by default) or 'float' (optional) to select the scalar type used for the Faust generated.
%> %>
%> @retval H the Faust implementing the Hadamard transform of dimension n. %> @retval H the Faust implementing the Hadamard transform of dimension n.
%> %>
...@@ -54,6 +55,7 @@ function H = wht(n, varargin) ...@@ -54,6 +55,7 @@ function H = wht(n, varargin)
end end
normed = true; % normalization by default normed = true; % normalization by default
dev = 'cpu'; dev = 'cpu';
dtype = 'double';
argc = length(varargin); argc = length(varargin);
if(argc > 0) if(argc > 0)
for i=1:2:argc for i=1:2:argc
...@@ -74,22 +76,36 @@ function H = wht(n, varargin) ...@@ -74,22 +76,36 @@ function H = wht(n, varargin)
else else
dev = tmparg; dev = tmparg;
end end
case 'dtype'
if(argc == i || ~ strcmp(tmparg, 'float') && ~ strcmp(tmparg, 'double'))
error('dtype keyword argument is not followed by a valid value: float, double.')
else
dtype = tmparg;
end
otherwise otherwise
if((isstr(varargin{i}) || ischar(varargin{i})) && ~ strcmp(tmparg, 'cpu') && ~ startsWith(tmparg, 'gpu')) if((isstr(varargin{i}) || ischar(varargin{i})) && ~ strcmp(tmparg, 'cpu') && ~ startsWith(tmparg, 'gpu') && ~ strcmp(tmparg, 'float') && ~ strcmp(tmparg, 'double'))
error([ tmparg ' unrecognized argument']) error([ tmparg ' unrecognized argument'])
end end
end end
end end
end end
if(strcmp(dev, 'cpu')) if(strcmp(dev, 'cpu'))
core_obj = mexFaustReal('hadamard', log2n, normed); if(strcmp(dtype, 'double'))
core_obj = mexFaustReal('hadamard', log2n, normed);
else % float
core_obj = mexFaustRealFloat('hadamard', log2n, normed);
end
else else
core_obj = mexFaustGPUReal('hadamard', log2n, normed); if(strcmp(dtype, 'double'))
core_obj = mexFaustGPUReal('hadamard', log2n, normed);
else % float
core_obj = mexFaustGPURealFloat('hadamard', log2n, normed);
end
end end
is_real = true; is_real = true;
e = MException('FAUST:OOM', 'Out of Memory'); e = MException('FAUST:OOM', 'Out of Memory');
if(core_obj == 0) if(core_obj == 0)
throw(e) throw(e)
end end
H = matfaust.Faust(core_obj, is_real, dev); H = matfaust.Faust(core_obj, is_real, dev, dtype);
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment