GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
chMatrix.cc
Go to the documentation of this file.
1 // Matrix manipulations.
2 /*
3 
4 Copyright (C) 1995-2017 John W. Eaton
5 Copyright (C) 2010 VZLU Prague
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
11 Free Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
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
20 along with Octave; see the file COPYING. If not, see
21 <http://www.gnu.org/licenses/>.
22 
23 */
24 
25 #if defined (HAVE_CONFIG_H)
26 # include "config.h"
27 #endif
28 
29 #include <cstring>
30 
31 #include <iostream>
32 #include <string>
33 
34 #include "lo-error.h"
35 #include "str-vec.h"
36 #include "mx-base.h"
37 #include "mx-inlines.cc"
38 #include "mx-op-defs.h"
39 
40 // charMatrix class.
41 
42 bool
44 {
45  if (rows () != a.rows () || cols () != a.cols ())
46  return 0;
47 
48  return mx_inline_equal (numel (), data (), a.data ());
49 }
50 
51 bool
53 {
54  return !(*this == a);
55 }
56 
59 {
60  if (s)
61  {
62  octave_idx_type s_len = strlen (s);
63 
64  if (r < 0 || r >= rows () || c < 0 || c + s_len - 1 > cols ())
65  (*current_liboctave_error_handler) ("range error for insert");
66 
67  for (octave_idx_type i = 0; i < s_len; i++)
68  elem (r, c+i) = s[i];
69  }
70  return *this;
71 }
72 
75 {
76  Array<char>::insert (a, r, c);
77  return *this;
78 }
79 
82 {
84 
85  octave_idx_type nr = rows ();
86  octave_idx_type nc = cols ();
87 
88  if (r == 0 && (nr == 0 || nc == 0))
89  return retval;
90 
91  if (r < 0 || r >= nr)
92  (*current_liboctave_error_handler) ("range error for row_as_string");
93 
94  retval.resize (nc, '\0');
95 
96  for (octave_idx_type i = 0; i < nc; i++)
97  retval[i] = elem (r, i);
98 
99  if (strip_ws)
100  {
101  while (--nc >= 0)
102  {
103  char c = retval[nc];
104  if (c && c != ' ')
105  break;
106  }
107 
108  retval.resize (nc+1);
109  }
110 
111  return retval;
112 }
113 
116  octave_idx_type r2, octave_idx_type c2) const
117 {
118  if (r1 > r2) { std::swap (r1, r2); }
119  if (c1 > c2) { std::swap (c1, c2); }
120 
121  octave_idx_type new_r = r2 - r1 + 1;
122  octave_idx_type new_c = c2 - c1 + 1;
123 
124  charMatrix result (new_r, new_c);
125 
126  for (octave_idx_type j = 0; j < new_c; j++)
127  for (octave_idx_type i = 0; i < new_r; i++)
128  result.elem (i, j) = elem (r1+i, c1+j);
129 
130  return result;
131 }
132 
135 
136 SM_CMP_OPS (char, charMatrix)
137 SM_BOOL_OPS (char, charMatrix)
138 
139 MM_CMP_OPS (charMatrix, charMatrix)
140 MM_BOOL_OPS (charMatrix, charMatrix)
bool operator==(const charMatrix &a) const
Definition: chMatrix.cc:43
#define MM_BOOL_OPS(M1, M2)
Definition: mx-op-defs.h:212
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
#define SM_BOOL_OPS(S, M)
Definition: mx-op-defs.h:169
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov.h:524
char & elem(octave_idx_type n)
Definition: Array.h:482
s
Definition: file-io.cc:2682
#define MS_CMP_OPS(M, S)
Definition: mx-op-defs.h:109
std::string row_as_string(octave_idx_type, bool strip_ws=false) const
Definition: chMatrix.cc:81
octave_idx_type rows(void) const
Definition: Array.h:401
Array< T > & insert(const Array< T > &a, const Array< octave_idx_type > &idx)
Insert an array into another at a specified position.
Definition: Array.cc:1601
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:398
bool swap
Definition: load-save.cc:725
charMatrix & insert(const char *s, octave_idx_type r, octave_idx_type c)
Definition: chMatrix.cc:58
bool operator!=(const charMatrix &a) const
Definition: chMatrix.cc:52
const char * data(void) const
Definition: Array.h:582
octave_value retval
Definition: data.cc:6294
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
T::size_type strlen(const typename T::value_type *str)
Definition: oct-string.cc:75
With real return the complex result
Definition: data.cc:3375
charMatrix extract(octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const
Definition: chMatrix.cc:115
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
#define MS_BOOL_OPS(M, S)
Definition: mx-op-defs.h:126
#define MM_CMP_OPS(M1, M2)
Definition: mx-op-defs.h:195
bool mx_inline_equal(size_t n, const T1 *x, const T2 *y)
Definition: mx-inlines.cc:532
octave_idx_type cols(void) const
Definition: Array.h:409
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
#define SM_CMP_OPS(S, M)
Definition: mx-op-defs.h:152