Mercurial > hg > octave-nkf
annotate liboctave/array/chMatrix.cc @ 20830:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | a9574e3c6e9e |
children |
rev | line source |
---|---|
1993 | 1 // Matrix manipulations. |
1573 | 2 /* |
3 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19509
diff
changeset
|
4 Copyright (C) 1995-2015 John W. Eaton |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
5 Copyright (C) 2010 VZLU Prague |
1573 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
1573 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
1573 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
27 #endif | |
28 | |
7048 | 29 #include <cstring> |
30 | |
3503 | 31 #include <iostream> |
1728 | 32 #include <string> |
33 | |
1573 | 34 #include "lo-error.h" |
2349 | 35 #include "str-vec.h" |
1573 | 36 #include "mx-base.h" |
37 #include "mx-inlines.cc" | |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8750
diff
changeset
|
38 #include "mx-op-defs.h" |
1573 | 39 |
40 // charMatrix class. | |
41 | |
2384 | 42 bool |
1573 | 43 charMatrix::operator == (const charMatrix& a) const |
44 { | |
45 if (rows () != a.rows () || cols () != a.cols ()) | |
46 return 0; | |
47 | |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19898
diff
changeset
|
48 return mx_inline_equal (numel (), data (), a.data ()); |
1573 | 49 } |
50 | |
2384 | 51 bool |
1573 | 52 charMatrix::operator != (const charMatrix& a) const |
53 { | |
54 return !(*this == a); | |
55 } | |
56 | |
57 charMatrix& | |
5275 | 58 charMatrix::insert (const char *s, octave_idx_type r, octave_idx_type c) |
1573 | 59 { |
60 if (s) | |
61 { | |
5275 | 62 octave_idx_type s_len = strlen (s); |
1573 | 63 |
64 if (r < 0 || r >= rows () || c < 0 || c + s_len - 1 > cols ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10267
diff
changeset
|
65 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10267
diff
changeset
|
66 (*current_liboctave_error_handler) ("range error for insert"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10267
diff
changeset
|
67 return *this; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10267
diff
changeset
|
68 } |
1573 | 69 |
5275 | 70 for (octave_idx_type i = 0; i < s_len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10267
diff
changeset
|
71 elem (r, c+i) = s[i]; |
1573 | 72 } |
73 return *this; | |
74 } | |
75 | |
76 charMatrix& | |
5275 | 77 charMatrix::insert (const charMatrix& a, octave_idx_type r, octave_idx_type c) |
1573 | 78 { |
10351
5150ceb4dbb4
base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
79 Array<char>::insert (a, r, c); |
1573 | 80 return *this; |
81 } | |
82 | |
3504 | 83 std::string |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
84 charMatrix::row_as_string (octave_idx_type r, bool strip_ws) const |
1573 | 85 { |
3504 | 86 std::string retval; |
2613 | 87 |
5275 | 88 octave_idx_type nr = rows (); |
89 octave_idx_type nc = cols (); | |
2613 | 90 |
14012
4faef552363d
charMatrix::row_as_string: return early if r is 0 and either nr or nc is 0
John W. Eaton <jwe@octave.org>
parents:
12959
diff
changeset
|
91 if (r == 0 && (nr == 0 || nc == 0)) |
2613 | 92 return retval; |
93 | |
94 if (r < 0 || r >= nr) | |
1573 | 95 { |
96 (*current_liboctave_error_handler) ("range error for row_as_string"); | |
2613 | 97 return retval; |
1573 | 98 } |
99 | |
2613 | 100 retval.resize (nc, '\0'); |
1573 | 101 |
5275 | 102 for (octave_idx_type i = 0; i < nc; i++) |
1573 | 103 retval[i] = elem (r, i); |
104 | |
11265
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10521
diff
changeset
|
105 if (strip_ws) |
2493 | 106 { |
11265
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10521
diff
changeset
|
107 while (--nc >= 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10267
diff
changeset
|
108 { |
11265
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10521
diff
changeset
|
109 char c = retval[nc]; |
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10521
diff
changeset
|
110 if (c && c != ' ') |
a117dc8ea1b9
charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents:
10521
diff
changeset
|
111 break; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10267
diff
changeset
|
112 } |
3836 | 113 |
114 retval.resize (nc+1); | |
2493 | 115 } |
1780 | 116 |
1573 | 117 return retval; |
118 } | |
119 | |
2255 | 120 charMatrix |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
121 charMatrix::extract (octave_idx_type r1, octave_idx_type c1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
122 octave_idx_type r2, octave_idx_type c2) const |
3189 | 123 { |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
124 if (r1 > r2) { std::swap (r1, r2); } |
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
125 if (c1 > c2) { std::swap (c1, c2); } |
3189 | 126 |
5275 | 127 octave_idx_type new_r = r2 - r1 + 1; |
128 octave_idx_type new_c = c2 - c1 + 1; | |
3189 | 129 |
130 charMatrix result (new_r, new_c); | |
131 | |
5275 | 132 for (octave_idx_type j = 0; j < new_c; j++) |
133 for (octave_idx_type i = 0; i < new_r; i++) | |
3189 | 134 result.elem (i, j) = elem (r1+i, c1+j); |
135 | |
136 return result; | |
137 } | |
138 | |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
139 MS_CMP_OPS (charMatrix, char) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9370
diff
changeset
|
140 MS_BOOL_OPS (charMatrix, char) |
6456 | 141 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
142 SM_CMP_OPS (char, charMatrix) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9370
diff
changeset
|
143 SM_BOOL_OPS (char, charMatrix) |
6456 | 144 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
145 MM_CMP_OPS (charMatrix, charMatrix) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9370
diff
changeset
|
146 MM_BOOL_OPS (charMatrix, charMatrix) |