1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1998-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING.  If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_ov_bool_sparse_h)
27 #define octave_ov_bool_sparse_h 1
28 
29 #include "octave-config.h"
30 
31 #include <cstdlib>
32 
33 #include <iosfwd>
34 #include <string>
35 
36 #include "mx-base.h"
37 #include "str-vec.h"
38 
39 #include "error.h"
40 #include "oct-stream.h"
41 #include "ov-base.h"
42 #include "ov-typeinfo.h"
43 
44 #include "boolSparse.h"
45 #include "ov-base-sparse.h"
46 #include "ov-re-sparse.h"
47 
48 class octave_value_list;
49 
50 class
51 OCTINTERP_API
52 octave_sparse_bool_matrix : public octave_base_sparse<SparseBoolMatrix>
53 {
54 public:
55 
octave_sparse_bool_matrix(void)56   octave_sparse_bool_matrix (void)
57     : octave_base_sparse<SparseBoolMatrix> () { }
58 
octave_sparse_bool_matrix(const SparseBoolMatrix & bnda)59   octave_sparse_bool_matrix (const SparseBoolMatrix& bnda)
60     : octave_base_sparse<SparseBoolMatrix> (bnda) { }
61 
octave_sparse_bool_matrix(const SparseBoolMatrix & bnda,const MatrixType & t)62   octave_sparse_bool_matrix (const SparseBoolMatrix& bnda,
63                              const MatrixType& t)
64     : octave_base_sparse<SparseBoolMatrix> (bnda, t) { }
65 
octave_sparse_bool_matrix(const boolNDArray & m)66   octave_sparse_bool_matrix (const boolNDArray& m)
67     : octave_base_sparse<SparseBoolMatrix> (SparseBoolMatrix (m)) { }
68 
octave_sparse_bool_matrix(const boolMatrix & m)69   octave_sparse_bool_matrix (const boolMatrix& m)
70     : octave_base_sparse<SparseBoolMatrix> (SparseBoolMatrix (m)) { }
71 
octave_sparse_bool_matrix(const Sparse<bool> & a)72   octave_sparse_bool_matrix (const Sparse<bool>& a)
73     : octave_base_sparse<SparseBoolMatrix> (a) { }
74 
octave_sparse_bool_matrix(const octave_sparse_bool_matrix & bm)75   octave_sparse_bool_matrix (const octave_sparse_bool_matrix& bm)
76     : octave_base_sparse<SparseBoolMatrix> (bm) { }
77 
78   ~octave_sparse_bool_matrix (void) = default;
79 
clone(void)80   octave_base_value * clone (void) const
81   { return new octave_sparse_bool_matrix (*this); }
empty_clone(void)82   octave_base_value * empty_clone (void) const
83   { return new octave_sparse_bool_matrix (); }
84 
85   type_conv_info numeric_conversion_function (void) const;
86 
87   octave_base_value * try_narrowing_conversion (void);
88 
89   // FIXME: Adapt idx_vector to allow sparse logical indexing without overflow!
90   idx_vector index_vector (bool /* require_integers */ = false) const
91   {
92     return idx_vector (matrix);
93   }
94 
builtin_type(void)95   builtin_type_t builtin_type (void) const { return btyp_bool; }
96 
is_bool_matrix(void)97   bool is_bool_matrix (void) const { return true; }
98 
islogical(void)99   bool islogical (void) const { return true; }
100 
isreal(void)101   bool isreal (void) const { return true; }
102 
isnumeric(void)103   bool isnumeric (void) const { return false; }
104 
105   double double_value (bool = false) const;
106 
107   double scalar_value (bool frc_str_conv = false) const
108   { return double_value (frc_str_conv); }
109 
110   Matrix matrix_value (bool = false) const;
111 
112   NDArray array_value (bool = false) const;
113 
114   Complex complex_value (bool = false) const;
115 
116   ComplexMatrix complex_matrix_value (bool = false) const;
117 
118   ComplexNDArray complex_array_value (bool = false) const;
119 
120   charNDArray char_array_value (bool = false) const;
121 
122   boolMatrix bool_matrix_value (bool = false) const;
123 
124   boolNDArray bool_array_value (bool = false) const;
125 
126   SparseMatrix sparse_matrix_value (bool = false) const;
127 
128   SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
129 
130   SparseBoolMatrix sparse_bool_matrix_value (bool = false) const
131   { return matrix; }
132 
133   octave_value convert_to_str_internal (bool pad, bool force, char type) const;
134 
135   octave_value as_double (void) const;
136 
137   bool save_binary (std::ostream& os, bool save_as_floats);
138 
139   bool load_binary (std::istream& is, bool swap,
140                     octave::mach_info::float_format fmt);
141 
142   bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
143 
144   bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
145 
146   mxArray * as_mxArray (void) const;
147 
148   // Mapper functions are converted to double for treatment
map(unary_mapper_t umap)149   octave_value map (unary_mapper_t umap) const
150   {
151     octave_sparse_matrix m (sparse_matrix_value ());
152     return m.map (umap);
153   }
154 
155 protected:
156 
157   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
158 };
159 
160 #endif
161