]> Creatis software - CreaPhase.git/blob - octave_packages/linear-algebra-2.2.0/@blksparse/minus.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / linear-algebra-2.2.0 / @blksparse / minus.m
1 ## Copyright (C) 2010 VZLU Prague
2 ## 
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 3 of the License, or
6 ## (at your option) any later version.
7 ## 
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 ## GNU General Public License for more details.
12 ## 
13 ## You should have received a copy of the GNU General Public License
14 ## along with Octave; see the file COPYING.  If not, see
15 ## <http://www.gnu.org/licenses/>.
16
17 function s = minus (s1, s2)
18   if (isa (s1, "blksparse") && isa (s2, "blksparse"))
19     ## Conformance check.
20     siz1 = s1.siz;
21     bsiz1 = s1.bsiz;
22     siz2 = s2.siz;
23     bsiz2 = s2.bsiz;
24     if (bsiz1(2) != bsiz2(1))
25       gripe_nonconformant (bsiz1, bsiz2, "block sizes");
26     elseif (siz1(2) != siz2(1))
27       gripe_nonconformant (bsiz1.*siz1, bsiz2.*siz2);
28     endif
29
30     ## Stupid & simple.
31     s = blksparse ([s1.i; s2.i], [s1.j; s2.j], cat (3, s1.sv, -s2.sv), siz1(1), siz1(2));
32   else
33     error ("blksparse: only blksparse - blksparse implemented");
34   endif
35 endfunction
36
37 function gripe_nonconformant (s1, s2, what = "arguments")
38   error ("Octave:nonconformant-args", ...
39   "nonconformant %s (op1 is %dx%d, op2 is %dx%d)", what, s1, s2);
40 endfunction