-
Notifications
You must be signed in to change notification settings - Fork 29
/
opMinus.m
94 lines (76 loc) · 2.97 KB
/
opMinus.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
classdef opMinus < opSpot
%OPMINUS Difference of two operators.
%
% opMinus(OP1,OP2) creates a compound operator representing OP1-OP2.
%
% See also opSum.
% Copyright 2009, Ewout van den Berg and Michael P. Friedlander
% See the file COPYING.txt for full copyright information.
% Use the command 'spot.gpl' to locate this file.
% http://www.cs.ubc.ca/labs/scl/spot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Constructor
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function op = opMinus(A,B)
if nargin ~= 2
error('Exactly two operators must be specified.')
end
% Input matrices are immediately cast as opMatrix's.
if isa(A,'numeric'), A = opMatrix(A); end
if isa(B,'numeric'), B = opMatrix(B); end
% Check that the input operators are valid.
if ~( isa(A,'opSpot') && isa(B,'opSpot') )
error('One of the operators is not a valid input.')
end
% Check operator consistency and complexity
[mA, nA] = size(A);
[mB, nB] = size(B);
compatible = ((mA == mB) && (nA == nB));
if ~compatible
error('Operators are not compatible in size.');
end
% Determine size
m = mA; n = nA;
% Construct operator
op = op@opSpot('Minus', m, n);
op.cflag = A.cflag | B.cflag;
op.linear = A.linear | B.linear;
op.sweepflag = A.sweepflag & B.sweepflag;
op.children = {A, B};
op.precedence = 4;
end % Constructor
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Display
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function str = char(op)
% Get operators
op1 = op.children{1};
op2 = op.children{2};
% Format first operator
str1 = char(op1);
if op1.precedence > op.precedence
str1 = ['(',str1,')'];
end
% Format second operator
str2 = char(op2);
if op2.precedence > op.precedence
str2 = ['(',str2,')'];
end
% Combine
str = [str1, ' - ', str2];
end
end % Methods
methods ( Access = protected )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Multiply
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function y = multiply(op,x,mode)
y = applyMultiply(op.children{1},x,mode);
y = y - applyMultiply(op.children{2},x,mode);
end % Multiply
end % Methods
end % Classdef