1 ## Copyright (C) 2010 VZLU Prague
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.
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.
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/>.
17 function ss = subsref (s, subs)
18 if (length (subs) != 1)
19 error ("blksparse: invalid index chain");
21 if (strcmp (subs(1).type, "()"))
23 if (length (ind) == 2)
24 idx = make_block_index (ind{1}, s.bsiz(1));
25 jdx = make_block_index (ind{2}, s.bsiz(2));
26 ## Use sparse indexing to solve it all.
27 sn = sparse (s.i, s.j, 1:size (s.sv, 3), s.siz(1), s.siz (2));
29 [i, j, k] = find (sn);
36 error ("blksparse: linear indexing is not supported");
39 error ("blksparse: only supports () indexing");
44 function bi = make_block_index (i, bs)
48 if (rem (numel (i), bs) == 0)
49 ba = reshape (i, bs, []);
51 if (any (rem (bi, bs) != 1) || any ((ba != bsxfun (@plus, bi, [0:bs-1].'))(:)))
52 error ("blksparse: index must preserve block structure");
57 error ("blksparse: index must preserve block structure");