annotate test/logical-index.tst @ 19010:3fb030666878 draft default tip dspies

Added special-case logical-indexing function * logical-index.h (New file) : Logical-indexing function. May be called on octave_value types via call_bool_index * nz-iterators.h : Add base-class nz_iterator for iterator types. Array has template bool for whether to internally store row-col or compute on the fly Add skip_ahead method which skips forward to the next nonzero after its argument Add flat_index for computing octave_idx_type index of current position (with assertion failure in the case of overflow) Move is_zero to separate file * ov-base-diag.cc, ov-base-mat.cc, ov-base-sparse.cc, ov-perm.cc (do_index_op): Add call to call_bool_index in logical-index.h * Array.h : Move forward-declaration for array_iterator to separate header file * dim-vector.cc (dim_max): Refers to idx-bounds.h (max_idx) * array-iter-decl.h (New file): Header file for forward declaration of array-iterator * direction.h : Add constants fdirc and bdirc to avoid having to reconstruct them * dv-utils.h, dv-utils.cc (New files) : Utility functions for querying and constructing dim-vectors * idx-bounds.h (New file) : Utility constants and functions for determining whether things will overflow the maximum allowed bounds * interp-idx.h (New function : to_flat_idx) : Converts row-col pair to linear index of octave_idx_type * is-zero.h (New file) : Function for determining whether an element is zero * logical-index.tst : Add tests for correct return-value dimensions and large sparse matrix behavior
author David Spies <dnspies@gmail.com>
date Fri, 25 Jul 2014 13:39:31 -0600
parents d63878346099
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 16030
diff changeset
1 ## Copyright (C) 2006-2013 John W. Eaton
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
2 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
3 ## This file is part of Octave.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
4 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
6 ## under the terms of the GNU General Public License as published by
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
8 ## your option) any later version.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
9 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
13 ## General Public License for more details.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
14 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
15 ## You should have received a copy of the GNU General Public License
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
17 ## <http://www.gnu.org/licenses/>.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5781
diff changeset
18
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
19 %!test
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
20 %! a = [];
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
21 %! fail ("a(0);");
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
22
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
23 %!shared a
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
24 %! a = 2;
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
25 %!assert (a(1), 2);
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
26 %!error id=Octave:index-out-of-bounds a(logical ([1,1]))
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
27
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
28 %!shared a
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
29 %! a = [9,8,7,6];
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
30 %!assert (isempty (a(logical ([0,0,0,0]))))
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
31 %!assert (a(logical ([1,1,1,1])), [9,8,7,6])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
32 %!assert (a(logical ([0,1,1,0])), [8,7])
19010
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
33 %!assert (a(logical ([0;1;1;0])), [8,7])
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
34 %!assert (a(logical ([1,1])), [9,8])
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
35
19010
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
36 %! a = permute(a,[1,3,2]);
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
37 %!assert (a(logical ([0,1,1,0])), permute([8,7],[1,3,2]))
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
38
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
39 %!shared a
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
40 %! a = [9,8;7,6];
19010
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
41 %!assert (a(logical ([0,0,0,0])), zeros(1,0))
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
42 %!assert (a(logical ([1,1,1,1])), [9,7,8,6])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
43 %!assert (a(logical ([0,1,1,0])), [7,8])
19010
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
44 %!assert (a(logical ([0;1;1;0])), [7;8])
14131
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
45 %!assert (a(logical (0:1),logical (0:1)), 6)
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
46 %!assert (a(logical (0:1),2:-1:1), [6,7])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
47 %!assert (a(logical (0:1),logical ([0,1])), 6)
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
48 %!assert (a(logical (0:1),[2,1]), [6,7])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
49 %!assert (a(logical (0:1),:), [7,6])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
50 %!assert (a(logical (0:1),1), 7)
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
51 %!assert (a(logical (0:1),logical ([1,1])), [7,6])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
52 %!assert (a(2:-1:1,logical (0:1)), [6;8])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
53 %!assert (a(2:-1:1,logical ([0,1])), [6;8])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
54 %!assert (a(2:-1:1,logical ([1,1])), [7,6;9,8])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
55 %!assert (a(logical ([0,1]),logical (0:1)), 6)
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
56 %!assert (a(logical ([0,1]),2:-1:1), [6,7])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
57 %!assert (a(logical ([0,1]),logical ([0,1])), 6)
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
58 %!assert (a(logical ([0,1]),[2,1]), [6,7])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
59 %!assert (a(logical ([0,1]),:), [7,6])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
60 %!assert (a(logical ([0,1]),1), 7)
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
61 %!assert (a(logical ([0,1]),logical ([1,1])), [7,6])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
62 %!assert (a([2,1],logical (0:1)), [6;8])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
63 %!assert (a([2,1],logical ([0,1])), [6;8])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
64 %!assert (a([2,1],logical ([1,1])), [7,6;9,8])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
65 %!assert (a(:,logical (0:1)), [8;6])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
66 %!assert (a(:,logical ([0,1])), [8;6])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
67 %!assert (a(:,logical ([1,1])), [9,8;7,6])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
68 %!assert (a(1,logical (0:1)), 8)
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
69 %!assert (a(1,logical ([0,1])), 8)
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
70 %!assert (a(1,logical ([1,1])), [9,8])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
71 %!assert (a(logical ([1,1]),logical (0:1)), [8;6])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
72 %!assert (a(logical ([1,1]),2:-1:1), [8,9;6,7])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
73 %!assert (a(logical ([1,1]),logical ([0,1])), [8;6])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
74 %!assert (a(logical ([1,1]),[2,1]), [8,9;6,7])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
75 %!assert (a(logical ([1,1]),:), [9,8;7,6])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
76 %!assert (a(logical ([1,1]),1), [9;7])
c3309e1ec50d test: Use Octave coding and spacing conventions for fixed test scripts
Rik <octave@nomad.inbox5.com>
parents: 14125
diff changeset
77 %!assert (a(logical ([1,1]),logical ([1,1])), [9,8;7,6])
5590
1ad66ea35fe5 [project @ 2006-01-06 00:24:05 by jwe]
jwe
parents:
diff changeset
78
19010
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
79 %!assert (a(logical (permute([1,1,1,1],[1,3,2]))), [9;7;8;6])
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
80 %!assert (a(logical (permute([0,1,1,0],[1,3,2]))), [7;8])
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
81 %!assert (a(logical([])), [])
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
82 %!assert (a(false), [])
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
83 %!assert (a(false(0,0,1)), [])
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
84 %!assert (a(false(2,2)),zeros(0,1))
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
85 %!assert (a(false(1,4)),zeros(1,0))
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
86 %!assert (a(false(4,1)),zeros(0,1))
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
87 %!assert (a(false(1,1,4)),zeros(0,1))
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
88
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
89 %!shared v,a,b,c
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
90 %! v = sparse((1:100000).');
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
91 %! v = v .* mod(v,2);
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
92 %! a = sparse(diag(v));
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
93 %! b = logical(speye(100000));
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
94 %! c = [b(:,1:2:end); b(:,2:2:end)];
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
95 %!assert (a(b), v)
3fb030666878 Added special-case logical-indexing function
David Spies <dnspies@gmail.com>
parents: 17744
diff changeset
96 %!assert (a(c), v)