annotate libinterp/corefcn/Cell.cc @ 33617:ec2635a02328 bytecode-interpreter tip

maint: Merge default to bytecode-interpreter.
author Markus Mützel <markus.muetzel@gmx.de>
date Tue, 21 May 2024 18:29:03 +0200
parents f53ac65ffba6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31771
diff changeset
3 // Copyright (C) 1999-2024 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
27 # include "config.h"
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
28 #endif
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
29
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
30 #include "idx-vector.h"
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
31
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
32 #include "Cell.h"
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
33 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20980
diff changeset
34 #include "errwarn.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20831
diff changeset
35 #include "ovl.h"
8579
7e0f36dfefbe implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
36
7e0f36dfefbe implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
37 Cell::Cell (const octave_value_list& ovl)
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9415
diff changeset
38 : Array<octave_value> (ovl.cell_value ())
22417
48c00363dc74 maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents: 22407
diff changeset
39 { }
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
40
5805
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
41 Cell::Cell (const string_vector& sv, bool trim)
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9415
diff changeset
42 : Array<octave_value> ()
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
43 {
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
44 octave_idx_type n = sv.numel ();
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
45
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
46 if (n > 0)
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
47 {
4625
87c01a296263 [project @ 2003-11-15 12:51:20 by jwe]
jwe
parents: 4587
diff changeset
48 resize (dim_vector (n, 1));
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
49
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
50 for (octave_idx_type i = 0; i < n; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
51 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
52 std::string s = sv[i];
5805
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
53
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
54 if (trim)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
55 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
56 std::size_t pos = s.find_last_not_of (' ');
5805
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
57
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
58 s = (pos == std::string::npos) ? "" : s.substr (0, pos+1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
59 }
5805
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
60
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29655
diff changeset
61 elem (i, 0) = s;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
62 }
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
63 }
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
64 }
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3353
diff changeset
65
28431
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
66 Cell::Cell (const std::list<std::string>& sl)
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
67 : Array<octave_value> ()
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
68 {
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
69 octave_idx_type n = sl.size ();
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
70
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
71 if (n > 0)
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
72 {
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
73 resize (dim_vector (n, 1));
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
74
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
75 octave_value *dst = rwdata ();
28431
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
76 auto p = sl.begin ();
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
77
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
78 for (octave_idx_type i = 0; i < n; i++)
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
79 dst[i] = *p++;
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
80 }
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
81 }
0ffae065ca03 new cellstring constructor
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
82
8732
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
83 Cell::Cell (const Array<std::string>& sa)
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9415
diff changeset
84 : Array<octave_value> (sa.dims ())
8732
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
85 {
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
86 octave_idx_type n = sa.numel ();
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
87
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
88 octave_value *dst = rwdata ();
8732
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
89 const std::string *src = sa.data ();
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
90
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
91 for (octave_idx_type i = 0; i < n; i++)
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
92 dst[i] = src[i];
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
93 }
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
94
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
95 // Set size to DV, filling with []. Then fill with as many elements of
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
96 // SV as possible.
7209
f06b8150fe56 [project @ 2007-11-28 05:46:58 by jwe]
jwe
parents: 7017
diff changeset
97
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
98 Cell::Cell (const dim_vector& dv, const string_vector& sv, bool trim)
14616
13cc11418393 improve handling of default resize fill value for arrays
John W. Eaton <jwe@octave.org>
parents: 14557
diff changeset
99 : Array<octave_value> (dv, Matrix ())
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
100 {
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19697
diff changeset
101 octave_idx_type n = sv.numel ();
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
102
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
103 if (n > 0)
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
104 {
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
105 octave_idx_type m = numel ();
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
106
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23355
diff changeset
107 octave_idx_type len = (n > m ? m : n);
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
108
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
109 for (octave_idx_type i = 0; i < len; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
110 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
111 std::string s = sv[i];
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
112
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
113 if (trim)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
114 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
115 std::size_t pos = s.find_last_not_of (' ');
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
116
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
117 s = (pos == std::string::npos) ? "" : s.substr (0, pos+1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
118 }
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
119
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
120 elem(i) = s;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
121 }
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
122 }
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
123 }
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
124
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
125 bool
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
126 Cell::iscellstr () const
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
127 {
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
128 bool retval = true;
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
129
10065
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
130 octave_idx_type n = numel ();
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
131
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
132 for (octave_idx_type i = 0; i < n; i++)
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
133 {
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
134 if (! elem(i).is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
135 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
136 retval = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
137 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
138 }
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
139 }
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
140
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
141 return retval;
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
142 }
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
143
10065
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
144 Array<std::string>
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
145 Cell::cellstr_value () const
10065
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
146 {
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
147 Array<std::string> retval (dims ());
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
148
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
149 octave_idx_type n = numel ();
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
150
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
151 for (octave_idx_type i = 0; i < n; i++)
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
152 retval.xelem (i) = elem (i).string_value ();
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
153
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
154 return retval;
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
155 }
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
156
23355
08db4e9dd149 * Cell.h, Cell.cc (Cell::string_vector_value): New function.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
157 string_vector
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
158 Cell::string_vector_value () const
23355
08db4e9dd149 * Cell.h, Cell.cc (Cell::string_vector_value): New function.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
159 {
08db4e9dd149 * Cell.h, Cell.cc (Cell::string_vector_value): New function.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
160 octave_idx_type n = numel ();
08db4e9dd149 * Cell.h, Cell.cc (Cell::string_vector_value): New function.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
161
08db4e9dd149 * Cell.h, Cell.cc (Cell::string_vector_value): New function.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
162 string_vector retval (n);
08db4e9dd149 * Cell.h, Cell.cc (Cell::string_vector_value): New function.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
163
08db4e9dd149 * Cell.h, Cell.cc (Cell::string_vector_value): New function.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
164 for (octave_idx_type i = 0; i < n; i++)
08db4e9dd149 * Cell.h, Cell.cc (Cell::string_vector_value): New function.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
165 retval.xelem (i) = elem (i).string_value ();
08db4e9dd149 * Cell.h, Cell.cc (Cell::string_vector_value): New function.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
166
08db4e9dd149 * Cell.h, Cell.cc (Cell::string_vector_value): New function.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
167 return retval;
08db4e9dd149 * Cell.h, Cell.cc (Cell::string_vector_value): New function.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
168 }
08db4e9dd149 * Cell.h, Cell.cc (Cell::string_vector_value): New function.
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
169
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
170 Cell
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4513
diff changeset
171 Cell::index (const octave_value_list& idx_arg, bool resize_ok) const
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
172 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
173 Cell retval;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
174
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
175 octave_idx_type n = idx_arg.length ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
176
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
177 // If we catch an indexing error in index_vector, we flag an error
27956
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
178 // in index k. Ensure it is the right value before each idx_vector
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
179 // call. Same variable as used in for loop in default case.
5539
b800ae36fc6a [project @ 2005-11-16 18:45:32 by jwe]
jwe
parents: 5307
diff changeset
180
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
181 octave_idx_type k = 0;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
182
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
183 try
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
184 {
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
185 switch (n)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
186 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
187 case 0:
27061
d61825e693f2 warn about indexing values with () (bug #56167)
John W. Eaton <jwe@octave.org>
parents: 27060
diff changeset
188 warn_empty_index ("cell array");
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
189 retval = *this;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
190 break;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
191
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
192 case 1:
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
193 {
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
194 octave::idx_vector i = idx_arg(0).index_vector ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
195
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
196 retval = Array<octave_value>::index (i, resize_ok, Matrix ());
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
197 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
198 break;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
199
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
200 case 2:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
201 {
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
202 octave::idx_vector i = idx_arg(0).index_vector ();
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
203
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
204 k = 1;
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
205 octave::idx_vector j = idx_arg(1).index_vector ();
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
206
20667
8742e0b1cc49 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
207 retval = Array<octave_value>::index (i, j, resize_ok, Matrix ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
208 }
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
209 break;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
210
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
211 default:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
212 {
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
213 Array<octave::idx_vector> iv (dim_vector (n, 1));
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
214
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
215 for (k = 0; k < n; k++)
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
216 iv(k) = idx_arg(k).index_vector ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
217
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
218 retval = Array<octave_value>::index (iv, resize_ok, Matrix ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
219 }
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
220 break;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
221 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
222 }
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28907
diff changeset
223 catch (octave::index_exception& ie)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
224 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
225 // Rethrow to allow more info to be reported later.
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28907
diff changeset
226 ie.set_pos_if_unset (n, k+1);
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
227 throw;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
228 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
229
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
230 return retval;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
231 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
232
19140
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
233 /*
27060
3140380861ce error for x{} for cell array objects (bug #56167)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
234 %% This behavior is required for Matlab compatibility.
3140380861ce error for x{} for cell array objects (bug #56167)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
235 %!shared a
19140
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
236 %! a = {"foo", "bar"};
28907
11f1207111c5 maint: Don't use semicolon at end of single-line BIST tests.
Rik <rik@octave.org>
parents: 28431
diff changeset
237 %!assert (a(), a)
27060
3140380861ce error for x{} for cell array objects (bug #56167)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
238 %!error <invalid empty index expression> a{}
19140
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
239 */
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
240
10649
64472dd48517 cosmetic changes in Cell interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
241 void
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4513
diff changeset
242 Cell::assign (const octave_value_list& idx_arg, const Cell& rhs,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
243 const octave_value& fill_val)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
244
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
245 {
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
246 octave_idx_type len = idx_arg.length ();
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
247
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
248 Array<octave::idx_vector> ra_idx (dim_vector (len, 1));
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
249
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
250 for (octave_idx_type i = 0; i < len; i++)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
251 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
252 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
253 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
254 ra_idx(i) = idx_arg(i).index_vector ();
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
255 }
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28907
diff changeset
256 catch (octave::index_exception& ie)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
257 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
258 // Rethrow to allow more info to be reported later.
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28907
diff changeset
259 ie.set_pos (len, i+1);
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
260 throw;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
261 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
262 }
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
263
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
264 Array<octave_value>::assign (ra_idx, rhs, fill_val);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
265 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
266
10649
64472dd48517 cosmetic changes in Cell interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
267 void
8175
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
268 Cell::delete_elements (const octave_value_list& idx_arg)
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
269
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
270 {
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
271 octave_idx_type len = idx_arg.length ();
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
272
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
273 Array<octave::idx_vector> ra_idx (dim_vector (len, 1));
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
274
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
275 for (octave_idx_type i = 0; i < len; i++)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
276 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
277 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
278 ra_idx.xelem (i) = idx_arg(i).index_vector ();
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20232
diff changeset
279 }
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28907
diff changeset
280 catch (octave::index_exception& ie)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
281 {
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
282 // Rethrow to allow more info to be reported later.
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 28907
diff changeset
283 ie.set_pos (len, i+1);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
284 throw;
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
285 }
8175
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
286
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
287 Array<octave_value>::delete_elements (ra_idx);
8175
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
288 }
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
289
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
290 octave_idx_type
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
291 Cell::nnz () const
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
292 {
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20980
diff changeset
293 err_wrong_type_arg ("nnz", "cell array");
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
294 }
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
295
19140
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
296 /*
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
297 %!error <wrong type argument 'cell array'> nnz ({0, 1, 2})
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
298 %!error <wrong type argument 'cell array'> nnz (cell ())
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
299 %!error <wrong type argument 'cell array'> nnz ({"foo", "bar"})
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
300 */
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
301
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
302 Cell
5570
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
303 Cell::column (octave_idx_type i) const
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
304 {
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
305 Cell retval;
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
306
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
307 if (ndims () > 2)
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
308 error ("Cell::column: requires 2-D cell array");
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
309
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
310 if (i < 0 || i >= cols ())
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
311 error ("invalid column selection");
5570
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
312
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
313 octave_idx_type nr = rows ();
5570
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
314
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
315 retval.resize (dim_vector (nr, 1));
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
316
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
317 for (octave_idx_type j = 0; j < nr; j++)
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20940
diff changeset
318 retval.xelem (j) = elem (j, i);
5570
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
319
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
320 return retval;
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
321 }
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
322
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
323 Cell
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
324 Cell::concat (const Cell& rb, const Array<octave_idx_type>& ra_idx)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4625
diff changeset
325 {
5073
e71be9c548f2 [project @ 2004-11-09 18:31:25 by jwe]
jwe
parents: 4919
diff changeset
326 return insert (rb, ra_idx);
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
327 }
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
328
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
329 Cell&
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
330 Cell::insert (const Cell& a, octave_idx_type r, octave_idx_type c)
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
331 {
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
332 Array<octave_value>::insert (a, r, c);
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
333 return *this;
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
334 }
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
335
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
336 Cell&
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
337 Cell::insert (const Cell& a, const Array<octave_idx_type>& ra_idx)
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
338 {
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
339 Array<octave_value>::insert (a, ra_idx);
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
340 return *this;
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4625
diff changeset
341 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4625
diff changeset
342
7530
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
343 Cell
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
344 Cell::map (ctype_mapper fcn) const
7530
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
345 {
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
346 Cell retval (dims ());
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32632
diff changeset
347 octave_value *r = retval.rwdata ();
7530
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
348
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
349 const octave_value *p = data ();
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
350
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
351 for (octave_idx_type i = 0; i < numel (); i++)
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
352 r[i] = ((p++)->*fcn) ();
7530
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
353
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
354 return retval;
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
355 }
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
356
21573
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
357 octave_value
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
358 Cell::resize_fill_value () const
21573
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
359 {
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
360 static octave_value rfv = octave_value (Matrix ());
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
361 return rfv;
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
362 }
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
363
7618
3209a584e1ac Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents: 7530
diff changeset
364 Cell
3209a584e1ac Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents: 7530
diff changeset
365 Cell::diag (octave_idx_type k) const
3209a584e1ac Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents: 7530
diff changeset
366 {
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9415
diff changeset
367 return Array<octave_value>::diag (k);
7618
3209a584e1ac Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents: 7530
diff changeset
368 }
14557
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
369
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
370 Cell
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
371 Cell::diag (octave_idx_type m, octave_idx_type n) const
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
372 {
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
373 return Array<octave_value>::diag (m, n);
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
374 }