forked from cvxr/TFOCS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtfocs_zeros.m
59 lines (53 loc) · 2.08 KB
/
tfocs_zeros.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function z = tfocs_zeros( y )
switch class( y ),
case 'double',
% SRB: this was the old code. This function was intended
% to be called as tfocs_zeros( size(y) )
% But, for packSVD, I'd prefer to call it as tfocs_zeros(y)
% so that we can look at the type of y and pass it off
% accordingly (see 'packSVD' section below).
% This would break old code. But, it appears that all
% calls of this use the { [n1,n2], [m1,m2] } form of sz
% (as opposed to the [m1,n1] convention), so
% I don't think this will break anything.
% Old code:
% z = zeros( y );
% New code:
% Try to catch cases where we thing y = [m,n] is a size:
% if numel(y) == 2 && isint(y(1)) && isint(y(2))
% March 2011, fixing this to work with 3D arrays
% If you want to use 4D arrays, you must modify this in a similar
% fasion; we don't do that before hand since it makes it more likely
% that the wrong case is picked.
if (numel(y) == 2 || numel(y) == 3) && all(isint(y))
z = zeros( y );
else
z = zeros( size(y) );
end
case 'single'
if (numel(y) == 2 || numel(y) == 3) && all(isint(y))
z = zeros( y ,'single');
else
z = zeros( size(y) ,'single');
end
case 'cell',
if isa( y{1}, 'function_handle' ),
z = y{1}( y{2:end} );
else
for k = 1 : numel(y),
y{k} = tfocs_zeros( y{k} );
end
z = tfocs_tuple( y );
end
case 'packSVD'
%z = packSVD>tfocs_zeros(y);
z = packSVD_zeros(y);
otherwise
error('TFOCS_ZEROS: cannot handle this type of object');
end
% do NOT use "isinteger" because that tests for the integer data type.
function h = isint(y)
h = abs( round(y) - y ) < 10*abs(y)*eps;
% TFOCS v1.3 by Stephen Becker, Emmanuel Candes, and Michael Grant.
% Copyright 2013 California Institute of Technology and CVX Research.
% See the file LICENSE for full license information.