0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 function Z = DSA_BD_ops(X,operand,Y,alpha,X2,Y2,alpha2)
0030
0031
0032 if (nargin == 2)
0033 if strcmp(operand,'norm');
0034 if ~iscell(X);
0035 Z = full(norm(X,'fro'));
0036 else
0037 Z = 0;
0038 for p = 1:length(X); Z = Z + norm(X{p},'fro')^2;end;
0039 Z = sqrt(Z);
0040 end
0041
0042 elseif strcmp(operand,'zeros')
0043 if ~iscell(X)
0044 Z = sparse(size(X,1),size(X,2));
0045 else
0046 Z = cell(size(X));
0047 for p = 1:length(X)
0048 Z{p} = sparse(size(X{p},1),size(X{p},2));
0049 end
0050 end
0051 end
0052 end
0053
0054 if (nargin == 3)
0055 if strcmp(operand,'+') || strcmp(operand,'-') || ...
0056 strcmp(operand,'/') || strcmp(operand,'./') || ...
0057 strcmp(operand,'*') || strcmp(operand,'.*') || ...
0058 strcmp(operand,'.^')
0059 if (~iscell(X) && ~iscell(Y))
0060 eval(['Z = X',operand,'Y;']);
0061 elseif (iscell(X) && iscell(Y))
0062 Z = cell(size(X));
0063 for p = 1:length(X)
0064 if (size(X{p},2) == 1) && (size(Y{p},2) == 1) && ...
0065 (strcmp(operand,'*') || strcmp(operand,'/'))
0066 eval(['Z{p} = X{p}.',operand,'Y{p};']);
0067 else
0068 eval(['Z{p} = X{p} ',operand,'Y{p};']);
0069 end;
0070 end;
0071 elseif (iscell(X) && ~iscell(Y))
0072 Z = cell(size(X));
0073 for p = 1:length(X);
0074 eval(['Z{p} = X{p}',operand,'Y;']);
0075 end
0076 elseif (~iscell(X) && iscell(Y))
0077 Z = cell(size(Y));
0078 for p = 1:length(Y);
0079 eval(['Z{p} = X',operand,'Y{p};']);
0080 end
0081 end
0082 elseif strcmp(operand,'diffnorm')
0083 if ~iscell(X);
0084 Z = full(norm(X-Y,'fro'));
0085 else
0086 Z = 0;
0087 for p = 1:length(X); Z = Z + norm(X{p}-Y{p},'fro')^2;end;
0088 Z = sqrt(Z);
0089 end
0090 else
0091 error([operand,' is not available, check input arguments']);
0092 end
0093 end
0094
0095 if (nargin == 4)
0096 if strcmp(operand,'calc2')
0097 if (~iscell(X) )
0098 Z = -X+Y+alpha;
0099 else
0100 Z = cell(size(X));
0101 for p = 1:length(X)
0102 Z{p} = -X{p}+Y{p}+alpha{p};
0103 end;
0104 end
0105
0106 elseif strcmp(operand,'calc8')
0107 if (~iscell(X) )
0108 Z = (X-Y)/alpha;
0109 else
0110 Z = cell(size(X));
0111 for p = 1:length(X)
0112 Z{p} = (X{p}-Y{p})/alpha;
0113 end;
0114 end
0115 else
0116 error([operand,' is not available']);
0117 end
0118 end
0119
0120 if (nargin == 5)
0121 if strcmp(operand,'calc3')
0122 if (~iscell(X) )
0123 Z = X-((Y-X2)*alpha);
0124 else
0125 Z = cell(size(X));
0126 for p = 1:length(X)
0127 Z{p} = X{p}-((Y{p}-X2{p})*alpha);
0128 end;
0129 end
0130
0131 elseif strcmp(operand,'calc5')
0132 if (~iscell(X) )
0133 Z = X-((Y-X2)*alpha);
0134 else
0135 Z = cell(size(X));
0136 for p = 1:length(X)
0137 Z{p} = X{p}-((Y{p}-X2{p})*alpha);
0138 end;
0139 end
0140
0141 elseif strcmp(operand,'calc7')
0142 if (~iscell(X) )
0143 Z = (1-Y/alpha)*X+(Y/alpha)*X2;
0144 else
0145 Z = cell(size(X));
0146 for p = 1:length(X)
0147 Z{p} = (1-Y/alpha)*X{p}+(Y/alpha)*X2{p};
0148 end;
0149 end
0150
0151 end
0152 end
0153
0154 if (nargin == 6)
0155 if strcmp(operand,'calc1')
0156 if (~iscell(X) )
0157 Z = (((X-Y)/alpha) + X2-Y2);
0158 else
0159 Z = cell(size(X));
0160 for p = 1:length(X)
0161 Z{p} = (((X{p}-Y{p})/alpha)+X2{p}-Y2{p});
0162 end;
0163 end
0164 elseif strcmp(operand,'calc4')
0165 if (~iscell(X) )
0166 Z = (X/Y)+(((X2-Y2)/alpha));
0167 else
0168 Z = cell(size(X));
0169 for p = 1:length(X)
0170 Z{p} = (X{p}/Y)+(((X2{p}-Y2{p})/alpha));
0171 end;
0172 end
0173 end
0174 end
0175
0176 if (nargin == 7)
0177 if strcmp(operand,'calc6')
0178 if (~iscell(X) )
0179 Z = ((X*(1-Y/alpha))+((X2*Y/alpha)-(Y2*alpha2)));
0180 else
0181 Z = cell(size(X));
0182 for p = 1:length(X)
0183 Z{p} = ((X{p}*(1-Y/alpha))+((X2{p}*Y/alpha)-(Y2{p}*alpha2)));
0184 end;
0185 end
0186 end
0187 end
0188