annotate libinterp/corefcn/Cell.cc @ 20574:dd6345fd8a97

use exceptions for better invalid index error reporting (bug #45957) * lo-array-gripes.h, lo-array-gripes.cc (index_exception): New base class for indexing errors. (invalid_index, out_of_range): New classes. (gripe_index_out_of_range): New overloaded function. (gripe_invalid_index): New overloaded functions. Delete version with no arguments. (gripe_invalid_assignment_size, gripe_assignment_dimension_mismatch): Delete. Change uses of gripe functions as needed. * Cell.cc (Cell::index, Cell::assign, Cell::delete_elements): Use exceptions to collect error info about and handle indexing errors. * data.cc (Fnth_element, do_accumarray_sum, F__accumarray_sum__, do_accumarray_minmax, do_accumarray_minmax_fun, F__accumdim_sum__): Likewise. * oct-map.cc (octave_map::index, octave_map::assign, octave_map::delete_elements): Likewise. * sparse.cc (Fsparse): Likewise. * sub2ind.cc (Fsub2ind, Find2sub): Likewise. New tests. * utils.cc (dims_to_numel): Likewise. * ov-base-diag.cc (octave_base_diag<DMT, MT>::do_index_op, octave_base_diag<DMT, MT>::subsasgn): Likewise. * ov-base-mat.cc (octave_base_matrix<MT>::subsref, octave_base_matrix<MT>::assign): Likewise. * ov-base-sparse.cc (octave_base_sparse<T>::do_index_op, octave_base_sparse<T>::assign, octave_base_sparse<MT>::delete_elements): Likewise. * ov-classdef.cc (cdef_object_array::subsref, cdef_object_array::subsasgn): Likewise. * ov-java.cc (make_java_index): Likewise. * ov-perm.cc (octave_perm_matrix::do_index_op): Likewise. * ov-range.cc (octave_range::do_index_op): Likewise. * ov-re-diag.cc (octave_diag_matrix::do_index_op): Likewise. * ov-str-mat.cc (octave_char_matrix_str::do_index_op_internal): Likewise. * pt-assign.cc (tree_simple_assignment::rvalue1): Likewise. * pt-idx.cc (tree_index_expression::rvalue, tree_index_expression::lvalue): Likewise. * Array-util.cc (sub2ind): Likewise. * toplev.cc (main_loop): Also catch unhandled index_exception exceptions. * ov-base.cc (octave_base_value::index_vector): Improve error message. * ov-re-sparse.cc (octave_sparse_matrix::index_vector): Likewise. * ov-complex.cc (complex_index): New class. (gripe_complex_index): New function. (octave_complex::index_vector): Use it. * pt-id.h, pt-id.cc (tree_identifier::is_variable, tree_black_hole::is_variable): Now const. * pt-idx.cc (final_index_error): New static function. (tree_index_expression::rvalue, tree_index_expression::lvalue): Use it. * index.tst: New tests.
author Lachlan Andrew <lachlanbis@gmail.com>
date Fri, 02 Oct 2015 15:07:37 -0400
parents a9574e3c6e9e
children f90c8372b7ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
1 /*
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
2
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19174
diff changeset
3 Copyright (C) 1999-2015 John W. Eaton
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11037
diff changeset
4 Copyright (C) 2009-2010 VZLU Prague
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
5
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
7
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6116
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6116
diff changeset
11 option) any later version.
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
12
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
16 for more details.
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
17
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6116
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6116
diff changeset
20 <http://www.gnu.org/licenses/>.
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
21
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
22 */
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
23
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
26 #endif
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
27
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
28 #include "idx-vector.h"
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
29
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
30 #include "Cell.h"
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
31 #include "error.h"
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
32 #include "gripes.h"
8579
7e0f36dfefbe implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
33 #include "oct-obj.h"
7e0f36dfefbe implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
34
7e0f36dfefbe implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
35 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
36 : Array<octave_value> (ovl.cell_value ())
8579
7e0f36dfefbe implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
37 {
7e0f36dfefbe implement octave_value_list using Array
Jaroslav Hajek <highegg@gmail.com>
parents: 8290
diff changeset
38 }
3353
6b36317855ff [project @ 1999-11-16 16:13:49 by jwe]
jwe
parents:
diff changeset
39
5805
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
40 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
41 : Array<octave_value> ()
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
42 {
20267
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19731
diff changeset
43 octave_idx_type n = sv.numel ();
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
44
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
45 if (n > 0)
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
46 {
4625
87c01a296263 [project @ 2003-11-15 12:51:20 by jwe]
jwe
parents: 4587
diff changeset
47 resize (dim_vector (n, 1));
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
48
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
49 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
50 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
51 std::string s = sv[i];
5805
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
52
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
53 if (trim)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
54 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
55 size_t pos = s.find_last_not_of (' ');
5805
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
56
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
57 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
58 }
5805
5bfb24f90bdd [project @ 2006-05-10 21:15:37 by jwe]
jwe
parents: 5602
diff changeset
59
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
60 elem(i,0) = s;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
61 }
4216
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
62 }
e613ffa9f0e6 [project @ 2002-12-04 17:37:09 by jwe]
jwe
parents: 4192
diff changeset
63 }
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3353
diff changeset
64
11037
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
65 Cell::Cell (const std::list<std::string>& lst)
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
66 : Array<octave_value> ()
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
67 {
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
68 size_t n = lst.size ();
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
69
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
70 if (n > 0)
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
71 {
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
72 resize (dim_vector (n, 1));
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
73
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
74 octave_idx_type i = 0;
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
75
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
76 for (std::list<std::string>::const_iterator it = lst.begin ();
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
77 it != lst.end (); it++)
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
78 {
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
79 elem(i++,0) = *it;
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
80 }
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
81 }
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
82 }
e7864673c31f new Cell (std::list<std::string>&) constructor
John W. Eaton <jwe@octave.org>
parents: 10649
diff changeset
83
8732
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
84 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
85 : Array<octave_value> (sa.dims ())
8732
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
86 {
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
87 octave_idx_type n = sa.numel ();
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
88
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
89 octave_value *dst = fortran_vec ();
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
90 const std::string *src = sa.data ();
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
91
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
92 for (octave_idx_type i = 0; i < n; i++)
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
93 dst[i] = src[i];
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
94 }
a669df7beb73 [mq]: x
John W. Eaton <jwe@octave.org>
parents: 8679
diff changeset
95
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
96 // 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
97 // SV as possible.
7209
f06b8150fe56 [project @ 2007-11-28 05:46:58 by jwe]
jwe
parents: 7017
diff changeset
98
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
99 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
100 : Array<octave_value> (dv, Matrix ())
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
101 {
20267
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 19731
diff changeset
102 octave_idx_type n = sv.numel ();
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
103
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
104 if (n > 0)
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
105 {
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
106 octave_idx_type m = numel ();
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
107
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
108 octave_idx_type len = n > m ? m : n;
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
109
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
110 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
111 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
112 std::string s = sv[i];
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
113
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
114 if (trim)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
115 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
116 size_t pos = s.find_last_not_of (' ');
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
117
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
118 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
119 }
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
120
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
121 elem(i) = s;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
122 }
6116
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
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
126 bool
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
127 Cell::is_cellstr (void) const
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
128 {
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
129 bool retval = true;
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
130
10065
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
131 octave_idx_type n = numel ();
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
132
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
133 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
134 {
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
135 if (! elem(i).is_string ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
136 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
137 retval = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
138 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
139 }
6116
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
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
142 return retval;
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
143 }
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 5814
diff changeset
144
10065
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
145 Array<std::string>
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
146 Cell::cellstr_value (void) const
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
147 {
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
148 Array<std::string> retval (dims ());
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
149
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
150 octave_idx_type n = numel ();
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
151
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
152 for (octave_idx_type i = 0; i < n; i++)
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
153 retval.xelem (i) = elem (i).string_value ();
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
154
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
155 return retval;
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
156 }
64a06079cae4 improve cellstr cache implementation
Jaroslav Hajek <highegg@gmail.com>
parents: 9813
diff changeset
157
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
158 Cell
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4513
diff changeset
159 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
160 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
161 Cell retval;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
162
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
163 octave_idx_type n = idx_arg.length ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
164
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
165 // If we catch an indexing error in index_vector, we flag an error
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
166 // in index k. Ensure it is the right value befor each idx_vector
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
167 // 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
168
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
169 octave_idx_type k = 0;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
170
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
171 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
172 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
173 switch (n)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
174 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
175 case 0:
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
176 retval = *this;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
177 break;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
178
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
179 case 1:
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
180 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
181 idx_vector i = idx_arg(0).index_vector ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
182
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
183 if (! error_state)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
184 retval = Array<octave_value>::index (i, resize_ok, Matrix ());
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
185 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
186 break;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
187
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
188 case 2:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
189 {
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
190 idx_vector i = idx_arg(0).index_vector ();
4919
a1073eef650c [project @ 2004-07-27 15:22:50 by jwe]
jwe
parents: 4915
diff changeset
191
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
192 if (! error_state)
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
193 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
194 k = 1;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
195 idx_vector j = idx_arg(1).index_vector ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
196
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
197 if (! error_state)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
198 retval = Array<octave_value>::index (i, j, resize_ok, Matrix ());
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
199 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
200 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
201 break;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
202
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
203 default:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
204 {
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
205 Array<idx_vector> iv (dim_vector (n, 1));
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
206
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
207 for (k = 0; k < n; k++)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
208 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
209 iv(k) = idx_arg(k).index_vector ();
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
210
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
211 if (error_state)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
212 break;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
213 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
214 if (!error_state)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
215 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
216 }
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
217 break;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
218 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
219 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
220 catch (index_exception& e)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
221 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
222 // Rethrow to allow more info to be reported later.
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
223 e.set_pos_if_unset (n, k+1);
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
224 throw;
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
225 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
226
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
227 return retval;
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
19174
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
230 /*
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
231 %!test
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
232 %! a = {"foo", "bar"};
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
233 %! assert (a(), a)
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
234 */
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
235
10649
64472dd48517 cosmetic changes in Cell interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
236 void
4587
7b957b442818 [project @ 2003-11-10 15:50:39 by jwe]
jwe
parents: 4513
diff changeset
237 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
238 const octave_value& fill_val)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
239
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
240 {
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
241 octave_idx_type len = idx_arg.length ();
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
242
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
243 Array<idx_vector> ra_idx (dim_vector (len, 1));
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
244
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
245 for (octave_idx_type i = 0; i < len; i++)
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
246 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
247 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
248 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
249 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: 20267
diff changeset
250 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
251 catch (index_exception& e)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
252 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
253 // Rethrow to allow more info to be reported later.
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
254 e.set_pos (len, i+1);
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
255 throw;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
256 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
257 }
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
258
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
259 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
260 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4216
diff changeset
261
10649
64472dd48517 cosmetic changes in Cell interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
262 void
8175
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
263 Cell::delete_elements (const octave_value_list& idx_arg)
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
264
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
265 {
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
266 octave_idx_type len = idx_arg.length ();
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
267
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
268 Array<idx_vector> ra_idx (dim_vector (len, 1));
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
269
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
270 for (octave_idx_type i = 0; i < len; i++)
20574
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
271 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
272 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
273 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: 20267
diff changeset
274 }
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
275 catch (index_exception& e)
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
276 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
277 // Rethrow to allow more info to be reported later.
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
278 e.set_pos (len, i+1);
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
279 throw;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20267
diff changeset
280 }
8175
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
281
8290
7cbe01c21986 improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents: 8179
diff changeset
282 Array<octave_value>::delete_elements (ra_idx);
8175
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
283 }
977d5204cf67 fix null assignment for structs
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
284
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
285 octave_idx_type
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
286 Cell::nnz (void) const
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
287 {
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
288 gripe_wrong_type_arg ("nnz", "cell array");
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
289 return -1;
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
290 }
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5570
diff changeset
291
19174
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
292 /*
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
293 %!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
294 %!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
295 %!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
296 */
b5a0f11db158 Cell.cc: add tests for Cell::nnz
Carnë Draug <carandraug+dev@gmail.com>
parents: 17744
diff changeset
297
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4806
diff changeset
298 Cell
5570
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
299 Cell::column (octave_idx_type i) const
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
300 {
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
301 Cell retval;
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
302
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
303 if (ndims () < 3)
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 if (i < 0 || i >= cols ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
306 error ("invalid column selection");
5570
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
307 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
308 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
309 octave_idx_type nr = rows ();
5570
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
310
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
311 retval.resize (dim_vector (nr, 1));
5570
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
312
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
313 for (octave_idx_type j = 0; j < nr; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
314 retval.xelem (j) = elem (j, i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
315 }
5570
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
316 }
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
317 else
3074a549d644 [project @ 2005-12-08 21:01:50 by jwe]
jwe
parents: 5539
diff changeset
318 error ("Cell::column: requires 2-d cell array");
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 ());
bb0f2353cff5 new cell array ctype mappers
John W. Eaton <jwe@octave.org>
parents: 7209
diff changeset
347 octave_value *r = retval.fortran_vec ();
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
7618
3209a584e1ac Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents: 7530
diff changeset
357 Cell
3209a584e1ac Further type preservation tests and fix of diag for cell arrays
David Bateman <dbateman@free.fr>
parents: 7530
diff changeset
358 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
359 {
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9415
diff changeset
360 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
361 }
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
362
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
363 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
364 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
365 {
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
366 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
367 }