comparison libinterp/octave-value/ov-base-sparse.h @ 15195:2fc554ffbc28

split libinterp from src * libinterp: New directory. Move all files from src directory here except Makefile.am, main.cc, main-cli.cc, mkoctfile.in.cc, mkoctfilr.in.sh, octave-config.in.cc, octave-config.in.sh. * libinterp/Makefile.am: New file, extracted from src/Makefile.am. * src/Makefile.am: Delete everything except targets and definitions needed to build and link main and utility programs. * Makefile.am (SUBDIRS): Include libinterp in the list. * autogen.sh: Run config-module.sh in libinterp/dldfcn directory, not src/dldfcn directory. * configure.ac (AC_CONFIG_SRCDIR): Use libinterp/octave.cc, not src/octave.cc. (DL_LDFLAGS, LIBOCTINTERP): Use libinterp, not src. (AC_CONFIG_FILES): Include libinterp/Makefile in the list. * find-docstring-files.sh: Look in libinterp, not src. * gui/src/Makefile.am (liboctgui_la_CPPFLAGS): Find header files in libinterp, not src.
author John W. Eaton <jwe@octave.org>
date Sat, 18 Aug 2012 16:23:39 -0400
parents src/octave-value/ov-base-sparse.h@46b19589b593
children 8fce0ed4894a
comparison
equal deleted inserted replaced
15194:0f0b795044c3 15195:2fc554ffbc28
1 /*
2
3 Copyright (C) 2004-2012 David Bateman
4 Copyright (C) 1998-2004 Andy Adler
5
6 This file is part of Octave.
7
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21
22 */
23
24 #if !defined (octave_base_sparse_h)
25 #define octave_base_sparse_h 1
26
27 #include <cstdlib>
28
29 #include <iosfwd>
30 #include <string>
31
32 #include "str-vec.h"
33
34 #include "error.h"
35 #include "oct-obj.h"
36 #include "ov-base.h"
37 #include "ov-typeinfo.h"
38
39 #include "boolSparse.h"
40 #include "MatrixType.h"
41
42 class tree_walker;
43
44 class octave_sparse_bool_matrix;
45
46 template <class T>
47 class
48 octave_base_sparse : public octave_base_value
49 {
50 public:
51
52 octave_base_sparse (void)
53 : octave_base_value (), matrix (), typ (MatrixType ())
54 { }
55
56 octave_base_sparse (const T& a) : octave_base_value (), matrix (a),
57 typ (MatrixType ())
58 {
59 if (matrix.ndims () == 0)
60 matrix.resize (dim_vector (0, 0));
61 }
62
63 octave_base_sparse (const T& a, const MatrixType& t) : octave_base_value (),
64 matrix (a), typ (t)
65 {
66 if (matrix.ndims () == 0)
67 matrix.resize (dim_vector (0, 0));
68 }
69
70 octave_base_sparse (const octave_base_sparse& a) :
71 octave_base_value (), matrix (a.matrix), typ (a.typ) { }
72
73 ~octave_base_sparse (void) { }
74
75 octave_idx_type nnz (void) const { return matrix.nnz (); }
76
77 octave_idx_type nzmax (void) const { return matrix.nzmax (); }
78
79 size_t byte_size (void) const { return matrix.byte_size (); }
80
81 octave_value squeeze (void) const { return matrix.squeeze (); }
82
83 octave_value full_value (void) const { return matrix.matrix_value (); }
84
85 octave_value subsref (const std::string& type,
86 const std::list<octave_value_list>& idx);
87
88 octave_value_list subsref (const std::string& type,
89 const std::list<octave_value_list>& idx, int)
90 { return subsref (type, idx); }
91
92 octave_value subsasgn (const std::string& type,
93 const std::list<octave_value_list>& idx,
94 const octave_value& rhs);
95
96 void assign (const octave_value_list& idx, const T& rhs);
97
98 void delete_elements (const octave_value_list& idx);
99
100 dim_vector dims (void) const { return matrix.dims (); }
101
102 octave_value do_index_op (const octave_value_list& idx,
103 bool resize_ok = false);
104
105 octave_value reshape (const dim_vector& new_dims) const
106 { return T (matrix.reshape (new_dims)); }
107
108 octave_value permute (const Array<int>& vec, bool inv = false) const
109 { return T (matrix.permute (vec, inv)); }
110
111 octave_value resize (const dim_vector& dv, bool = false) const;
112
113 octave_value all (int dim = 0) const { return matrix.all (dim); }
114 octave_value any (int dim = 0) const { return matrix.any (dim); }
115
116 octave_value diag (octave_idx_type k = 0) const
117 { return octave_value (matrix.diag (k)); }
118
119 octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const
120 { return octave_value (matrix.sort (dim, mode)); }
121 octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
122 sortmode mode = ASCENDING) const
123 { return octave_value (matrix.sort (sidx, dim, mode)); }
124
125 sortmode is_sorted (sortmode mode = UNSORTED) const
126 { return full_value ().is_sorted (mode); }
127
128 MatrixType matrix_type (void) const { return typ; }
129 MatrixType matrix_type (const MatrixType& _typ) const
130 { MatrixType ret = typ; typ = _typ; return ret; }
131
132 bool is_matrix_type (void) const { return true; }
133
134 bool is_numeric_type (void) const { return true; }
135
136 bool is_sparse_type (void) const { return true; }
137
138 bool is_defined (void) const { return true; }
139
140 bool is_constant (void) const { return true; }
141
142 bool is_true (void) const;
143
144 octave_idx_type capacity (void) const { return matrix.capacity (); }
145
146 bool print_as_scalar (void) const;
147
148 void print (std::ostream& os, bool pr_as_read_syntax = false) const;
149
150 void print_info (std::ostream& os, const std::string& prefix) const;
151
152 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
153
154 bool save_ascii (std::ostream& os);
155
156 bool load_ascii (std::istream& is);
157
158 // Unsafe. These functions exists to support the MEX interface.
159 // You should not use them anywhere else.
160 void *mex_get_data (void) const { return matrix.mex_get_data (); }
161
162 octave_idx_type *mex_get_ir (void) const { return matrix.mex_get_ir (); }
163
164 octave_idx_type *mex_get_jc (void) const { return matrix.mex_get_jc (); }
165
166 protected:
167
168 octave_value map (octave_base_value::unary_mapper_t umap) const;
169
170 T matrix;
171
172 mutable MatrixType typ;
173 };
174
175 #endif