From 35591e6b4ebb55286b5d534317e0e9d6e1a9e48d Mon Sep 17 00:00:00 2001 From: Stephen Becker Date: Thu, 23 May 2019 13:54:51 -0600 Subject: [PATCH] Improving support for single precision --- @tfocs_tuple/tfocs_normsq.m | 11 ++++++++++- linop_dot.m | 2 +- private/tfocs_zeros.m | 7 ++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/@tfocs_tuple/tfocs_normsq.m b/@tfocs_tuple/tfocs_normsq.m index d49e89e..9441e6d 100644 --- a/@tfocs_tuple/tfocs_normsq.m +++ b/@tfocs_tuple/tfocs_normsq.m @@ -5,7 +5,16 @@ % must be preserved. However, an object may overload % TFOCS_NORMSQ to compute its value more efficiently. -v = sum( cellfun( @tfocs_normsq, x.value_ ) ); +if ~all( cellfun('isclass',x.value_,'double') ) + tmp = cellfun( @tfocs_normsq, x.value_,'UniformOutput',false ); + % encapsulates each in a cell array + v = 0; + for i = 1:length(tmp) + v = v + tmp{i}; % might convert singles to doubles + end +else + v = sum( cellfun( @tfocs_normsq, x.value_ ) ); +end % TFOCS v1.3 by Stephen Becker, Emmanuel Candes, and Michael Grant. % Copyright 2013 California Institute of Technology and CVX Research. diff --git a/linop_dot.m b/linop_dot.m index 4a582ff..db88bb4 100644 --- a/linop_dot.m +++ b/linop_dot.m @@ -5,7 +5,7 @@ % OP = LINOP_DOT( A, 1 ) returns the adjoint of that operator. switch class( A ), - case 'double', + case {'double','single'} sz = { size(A), [1,1] }; case 'cell', A = tfocs_tuple(A); diff --git a/private/tfocs_zeros.m b/private/tfocs_zeros.m index c8bf8f0..1787470 100644 --- a/private/tfocs_zeros.m +++ b/private/tfocs_zeros.m @@ -26,7 +26,12 @@ 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} );