forked from cvxr/TFOCS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5a572cc
Showing
223 changed files
with
16,947 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
hide | ||
.dropbox | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
function v = tfocs_dot( x, y ) | ||
% TFOCS_DOT Dot product <x,y>. Returns real(x'*y) | ||
% For matrices, this is the inner product that induces the Frobenius | ||
% norm, i.e. <x,y> = tr(x'*y), and not matrix multiplication. | ||
|
||
% Note: this is real(x'*y) and not real(x.'*y) | ||
|
||
if isempty( x ) || isempty( y ), | ||
v = 0; | ||
return; | ||
end | ||
|
||
% Allow scalar times vector multiplies: | ||
if isscalar(x) && ~isscalar(y) | ||
if ~x, | ||
v = 0; | ||
return; | ||
else | ||
% x = repmat(x,size(y,1),size(y,2) ); % doesn't work if y is a cell | ||
% The above code fails if y is multi-dimensional. Also, not | ||
% memory efficient. Switching to this (10/9/2013) | ||
% (Thanks to Graham Coleman for finding this bug, btw) | ||
if issparse(y) | ||
v = real( x * sum(nonzeros(y)) ); | ||
else | ||
v = real( x * sum(y(:)) ); | ||
end | ||
return; | ||
end | ||
elseif isscalar(y) && ~isscalar(x) | ||
if ~y | ||
v = 0; | ||
return; | ||
else | ||
y = repmat(y,size(x,1),size(x,2) ); | ||
if issparse(x) | ||
v = real( y * sum(nonzeros(x)) ); | ||
else | ||
v = real( y * sum(x(:)) ); | ||
end | ||
return; | ||
|
||
end | ||
end | ||
|
||
if isreal( x ) || isreal( y ), | ||
if issparse( x ) || issparse( y ), | ||
v = sum( nonzeros( real(x) .* real(y) ) ); | ||
else | ||
% Split this into two cases (first case could be handled by | ||
% second case, but we're trying to make it very fast since | ||
% this code is called very often) | ||
if ndims(x)==2 && ndims(y)==2 && size(x,2) == 1 && size(y,2) == 1 && isreal(x) && isreal(y) | ||
v = sum( x'*y ); % do we really need 'sum' ? | ||
else | ||
% Take real part first (since one of x and y is real anyhow) | ||
% in order to save some computation: | ||
v = real(x(:))' * real(y(:)); | ||
end | ||
end | ||
else | ||
if issparse( x ) || issparse( y ), | ||
v = sum( nonzeros( real(x) .* real(y) ) ) + ... | ||
sum( nonzeros( imag(x) .* imag(y) ) ); | ||
else | ||
% SRB: this is very slow: | ||
% v = sum( real(x(:))' * real(y(:)) ) + ... | ||
% sum( imag(x(:))' * imag(y(:)) ); | ||
if ndims(x)==2 && ndims(y)==2 && size(x,2) == 1 && size(y,2) == 1 | ||
v = sum(real( x'*y ) ); | ||
else | ||
% This is the most generic code. | ||
v = real( x(:)'*y(:) ); | ||
end | ||
end | ||
end | ||
|
||
% 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function v = tfocs_size( x ) | ||
|
||
% SIZE TFOCS-friendly size operator. | ||
|
||
v = { @zeros, m, n }; | ||
|
||
% 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function v = vec( x ) | ||
|
||
% VEC Vectorize. | ||
|
||
v = reshape( x, numel(x), 1 ); | ||
|
||
% 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. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
function v = tfocs_dot( x, y ) | ||
% TFOCS_DOT Dot product <x,y>. Returns real(x'*y) | ||
% For matrices, this is the inner product that induces the Frobenius | ||
% norm, i.e. <x,y> = tr(x'*y), and not matrix multiplication. | ||
|
||
% Note: this is real(x'*y) and not real(x.'*y) | ||
|
||
if isempty( x ) || isempty( y ), | ||
v = 0; | ||
return; | ||
end | ||
|
||
% Allow scalar times vector multiplies: | ||
if isscalar(x) && ~isscalar(y) | ||
if ~x, | ||
v = 0; | ||
return; | ||
else | ||
% x = repmat(x,size(y,1),size(y,2) ); % doesn't work if y is a cell | ||
% The above code fails if y is multi-dimensional. Also, not | ||
% memory efficient. Switching to this (10/9/2013) | ||
% (Thanks to Graham Coleman for finding this bug, btw) | ||
if issparse(y) | ||
v = real( x * sum(nonzeros(y)) ); | ||
else | ||
v = real( x * sum(y(:)) ); | ||
end | ||
return; | ||
end | ||
elseif isscalar(y) && ~isscalar(x) | ||
if ~y | ||
v = 0; | ||
return; | ||
else | ||
y = repmat(y,size(x,1),size(x,2) ); | ||
if issparse(x) | ||
v = real( y * sum(nonzeros(x)) ); | ||
else | ||
v = real( y * sum(x(:)) ); | ||
end | ||
return; | ||
|
||
end | ||
end | ||
|
||
if isreal( x ) || isreal( y ), | ||
if issparse( x ) || issparse( y ), | ||
v = sum( nonzeros( real(x) .* real(y) ) ); | ||
else | ||
% Split this into two cases (first case could be handled by | ||
% second case, but we're trying to make it very fast since | ||
% this code is called very often) | ||
if ndims(x)==2 && ndims(y)==2 && size(x,2) == 1 && size(y,2) == 1 && isreal(x) && isreal(y) | ||
v = sum( x'*y ); % do we really need 'sum' ? | ||
else | ||
% Take real part first (since one of x and y is real anyhow) | ||
% in order to save some computation: | ||
v = real(x(:))' * real(y(:)); | ||
end | ||
end | ||
else | ||
if issparse( x ) || issparse( y ), | ||
v = sum( nonzeros( real(x) .* real(y) ) ) + ... | ||
sum( nonzeros( imag(x) .* imag(y) ) ); | ||
else | ||
% SRB: this is very slow: | ||
% v = sum( real(x(:))' * real(y(:)) ) + ... | ||
% sum( imag(x(:))' * imag(y(:)) ); | ||
if ndims(x)==2 && ndims(y)==2 && size(x,2) == 1 && size(y,2) == 1 | ||
v = sum(real( x'*y ) ); | ||
else | ||
% This is the most generic code. | ||
v = real( x(:)'*y(:) ); | ||
end | ||
end | ||
end | ||
|
||
% 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function v = tfocs_size( x ) | ||
|
||
% SIZE TFOCS-friendly size operator. | ||
|
||
v = { @zeros, m, n }; | ||
|
||
% 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function v = vec( x ) | ||
|
||
% VEC Vectorize. | ||
|
||
v = reshape( x, numel(x), 1 ); | ||
|
||
% 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. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function x = abs( x ) | ||
|
||
% ABS Absolute value. | ||
|
||
n = numel( x.value_ ); | ||
for k = 1 : n, | ||
x.value_{k} = abs( x.value_{k} ); | ||
end | ||
|
||
% 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function v = cell( x ) | ||
|
||
% CELL Conversion to a cell array. | ||
|
||
v = x.value_; | ||
|
||
% 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function disp( x, prefix, inpname, nohead ) | ||
|
||
% DISP Manual display. DISP(x,prefix) adds the string prefix to each | ||
% line of the display output. | ||
|
||
if nargin < 3, inpname = ''; end | ||
if nargin < 2, prefix = ''; end | ||
n = numel( x.value_ ); | ||
if nargin < 4, | ||
fprintf( '%stfocs tuple object:\n', prefix ); | ||
prefix = [ prefix, ' ' ]; | ||
end | ||
for k = 1 : n, | ||
ss = x.value_{k}; | ||
inpname2 = sprintf( '%s{%d}', inpname, k ); | ||
if isnumeric( ss ), | ||
cls = class( ss ); | ||
sz = size( ss ); | ||
temp = sprintf( '%dx', sz ); | ||
if all( sz == 1 ), | ||
fprintf( '%s%s: [%g]\n', prefix, inpname2, ss ); | ||
elseif isreal(ss), | ||
fprintf( '%s%s: [%s %s]\n', prefix, inpname2, temp(1:end-1), cls ); | ||
else | ||
fprintf( '%s%s: [%s %s complex]\n', prefix, inpname2, temp(1:end-1), cls ); | ||
end | ||
elseif isa( ss, 'tfocs_tuple' ), | ||
fprintf( '%s%s: tfocs tuple object\n', prefix, inpname2 ); | ||
disp( ss, [ prefix, inpname2 ], '', 1 ); | ||
else | ||
fprintf( '%s%s: %s\n', prefix, inpname2, class(ss) ); | ||
end | ||
end | ||
|
||
% 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function display( x ) | ||
|
||
% DISPLAY Automatic display. | ||
|
||
long = ~isequal(get(0,'FormatSpacing'),'compact'); | ||
if long, disp( ' ' ); end | ||
disp([inputname(1) ' =']); | ||
if long, disp( ' ' ); end | ||
disp(x,' ',inputname(1)) | ||
if long, disp( ' ' ); end | ||
|
||
% 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function y = get( x, ndxs ) | ||
if nargin == 0, | ||
y = x.value_; | ||
elseif numel(ndxs) == 1, | ||
y = x.value_{ndxs}; | ||
else | ||
y = x.value_(ndxs); | ||
end | ||
|
||
% 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function z = max( x, y ) | ||
|
||
% MAX Maximum, z = max(x,y) | ||
|
||
if isa(x,'tfocs_tuple') | ||
z = x; | ||
if isa(y,'tfocs_tuple') | ||
z.value_ = cellfun( @max, x.value_, y.value_, 'UniformOutput', false ); | ||
elseif isscalar(y) | ||
z.value_ = cellfun( @max, x.value_, {y}, 'UniformOutput', false ); | ||
else | ||
z.value_ = cellfun( @max, x.value_, {y}, 'UniformOutput', false ); | ||
end | ||
else | ||
z = y; | ||
if isscalar(x) | ||
z.value_ = cellfun( @max, {x}, y.value_, 'UniformOutput', false ); | ||
else | ||
z.value_ = cellfun( @max, {x}, y.value_, 'UniformOutput', false ); | ||
end | ||
end | ||
|
||
% 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function z = min( x, y ) | ||
|
||
% MAX Minimum, z = min(x,y) | ||
|
||
if isa(x,'tfocs_tuple') | ||
z = x; | ||
if isa(y,'tfocs_tuple') | ||
z.value_ = cellfun( @min, x.value_, y.value_, 'UniformOutput', false ); | ||
elseif isscalar(y) | ||
z.value_ = cellfun( @min, x.value_, {y}, 'UniformOutput', false ); | ||
else | ||
z.value_ = cellfun( @min, x.value_, {y}, 'UniformOutput', false ); | ||
end | ||
else | ||
z = y; | ||
if isscalar(x) | ||
z.value_ = cellfun( @min, {x}, y.value_, 'UniformOutput', false ); | ||
else | ||
z.value_ = cellfun( @min, {x}, y.value_, 'UniformOutput', false ); | ||
end | ||
end | ||
|
||
% 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function x = minus( x, y ) | ||
|
||
% MINUS Subtraction. | ||
|
||
if isnumeric( x ) && isscalar( x ) && x == 0, | ||
x = -y; | ||
elseif ~isnumeric( y ) || numel( y ) ~= 1 || y ~= 0 | ||
x.value_ = cellfun( @minus, x.value_, y.value_, 'UniformOutput', false ); | ||
end | ||
|
||
% 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function y = mtimes( x, y ) | ||
|
||
% MTIMES Multiplication. TFOCS_TUPLE objects may only be left-multiplied | ||
% by real scalars. | ||
|
||
for k = 1 : numel( y.value_ ), | ||
y.value_{k} = x * y.value_{k}; | ||
end | ||
|
||
% 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function ans = nnz( x ) | ||
ans = sum( cellfun( @nnz, x.value_ ) ); | ||
|
||
% 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function v = numel( x, varargin ) | ||
|
||
% NUMEL Number of elements. | ||
|
||
v = numel( x.value_, varargin{:} ); | ||
|
||
% 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. |
Oops, something went wrong.