GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-sparse.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2005-2024 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_oct_sparse_h)
27 #define octave_oct_sparse_h 1
28 
29 #include "octave-config.h"
30 
31 #include <limits>
32 
33 #if defined (HAVE_CHOLMOD)
34 # include "dSparse.h"
35 # include "CSparse.h"
36 #endif
37 
38 #if defined (HAVE_SUITESPARSE_AMD_H)
39 # include <suitesparse/amd.h>
40 #elif defined (HAVE_AMD_AMD_H)
41 # include <amd/amd.h>
42 #elif defined (HAVE_AMD_H)
43 # include <amd.h>
44 #endif
45 
46 #if defined (HAVE_SUITESPARSE_CCOLAMD_H)
47 # include <suitesparse/ccolamd.h>
48 #elif defined (HAVE_CCOLAMD_CCOLAMD_H)
49 # include <ccolamd/ccolamd.h>
50 #elif defined (HAVE_CCOLAMD_H)
51 # include <ccolamd.h>
52 #endif
53 
54 #if defined (HAVE_SUITESPARSE_CHOLMOD_H)
55 # include <suitesparse/cholmod.h>
56 #elif defined (HAVE_CHOLMOD_CHOLMOD_H)
57 # include <cholmod/cholmod.h>
58 #elif defined (HAVE_CHOLMOD_H)
59 # include <cholmod.h>
60 #endif
61 
62 #if defined (HAVE_SUITESPARSE_COLAMD_H)
63 # include <suitesparse/colamd.h>
64 #elif defined (HAVE_COLAMD_COLAMD_H)
65 # include <colamd/colamd.h>
66 #elif defined (HAVE_COLAMD_H)
67 # include <colamd.h>
68 #endif
69 
70 #if defined (HAVE_SUITESPARSE_CS_H)
71 # include <suitesparse/cs.h>
72 #elif defined (HAVE_CXSPARSE_CS_H)
73 # include <cxsparse/cs.h>
74 #elif defined (HAVE_CS_H)
75 # include <cs.h>
76 #endif
77 
78 #if defined (HAVE_SUITESPARSE_UMFPACK_H)
79 # include <suitesparse/umfpack.h>
80 #elif defined (HAVE_UMFPACK_UMFPACK_H)
81 # include <umfpack/umfpack.h>
82 #elif defined (HAVE_UMFPACK_H)
83 # include <umfpack.h>
84 #endif
85 
86 #if defined (HAVE_SUITESPARSE_SUITESPARSEQR_HPP)
87 # include <suitesparse/SuiteSparseQR.hpp>
88 #elif defined (HAVE_SUITESPARSEQR_HPP)
89 # include <SuiteSparseQR.hpp>
90 #endif
91 
92 // Cope with API differences between SuiteSparse versions
93 
94 #if defined (SUITESPARSE_VERSION)
95 # if (SUITESPARSE_VERSION >= SUITESPARSE_VER_CODE (7, 0))
96 # define SUITESPARSE_NAME(name) SuiteSparse_ ## name
97 # define SUITESPARSE_SET_FCN(name) SuiteSparse_config_ ## name ## _set
98 # define SUITESPARSE_ASSIGN_FPTR(f_name, f_var, f_assign) \
99  SUITESPARSE_SET_FCN(f_name) (f_assign)
100 # define SUITESPARSE_ASSIGN_FPTR2(f_name, f_var, f_assign) \
101  SUITESPARSE_SET_FCN(f_name) (SUITESPARSE_NAME (f_assign))
102 # elif (SUITESPARSE_VERSION >= SUITESPARSE_VER_CODE (4, 3))
103 # define SUITESPARSE_NAME(name) SuiteSparse_ ## name
104 # define SUITESPARSE_ASSIGN_FPTR(f_name, f_var, f_assign) \
105  (SuiteSparse_config.f_name = f_assign)
106 # define SUITESPARSE_ASSIGN_FPTR2(f_name, f_var, f_assign) \
107  (SuiteSparse_config.f_name = SUITESPARSE_NAME (f_assign))
108 # else
109 # define SUITESPARSE_ASSIGN_FPTR(f_name, f_var, f_assign) \
110  (f_var = f_assign)
111 # define SUITESPARSE_ASSIGN_FPTR2(f_name, f_var, f_assign) \
112  (f_var = CHOLMOD_NAME (f_assign))
113 # endif
114 #endif
115 
116 // Function names depend on integer type.
117 
118 #if defined (HAVE_AMD)
119 # if defined (OCTAVE_ENABLE_64)
120 # define AMD_NAME(name) amd_l ## name
121 # else
122 # define AMD_NAME(name) amd ## name
123 # endif
124 #endif
125 
126 #if defined (HAVE_CCOLAMD)
127 # if defined (OCTAVE_ENABLE_64)
128 # define CCOLAMD_NAME(name) ccolamd_l ## name
129 # define CSYMAMD_NAME(name) csymamd_l ## name
130 # else
131 # define CCOLAMD_NAME(name) ccolamd ## name
132 # define CSYMAMD_NAME(name) csymamd ## name
133 # endif
134 #endif
135 
136 #if defined (HAVE_CHOLMOD)
137 # if defined (OCTAVE_ENABLE_64)
138 # define CHOLMOD_NAME(name) cholmod_l_ ## name
139 # else
140 # define CHOLMOD_NAME(name) cholmod_ ## name
141 # endif
142 #endif
143 
144 #if defined (HAVE_COLAMD)
145 # if defined (OCTAVE_ENABLE_64)
146 # define COLAMD_NAME(name) colamd_l ## name
147 # define SYMAMD_NAME(name) symamd_l ## name
148 # else
149 # define COLAMD_NAME(name) colamd ## name
150 # define SYMAMD_NAME(name) symamd ## name
151 # endif
152 #endif
153 
154 #if defined (HAVE_CXSPARSE)
155 # if defined (OCTAVE_ENABLE_64)
156 # define CXSPARSE_DNAME(name) cs_dl ## name
157 # define CXSPARSE_ZNAME(name) cs_cl ## name
158 # else
159 # define CXSPARSE_DNAME(name) cs_di ## name
160 # define CXSPARSE_ZNAME(name) cs_ci ## name
161 # endif
162 #endif
163 
164 #if defined (HAVE_UMFPACK)
165 # if defined (OCTAVE_ENABLE_64)
166 # define UMFPACK_DNAME(name) umfpack_dl_ ## name
167 # define UMFPACK_ZNAME(name) umfpack_zl_ ## name
168 # else
169 # define UMFPACK_DNAME(name) umfpack_di_ ## name
170 # define UMFPACK_ZNAME(name) umfpack_zi_ ## name
171 # endif
172 #endif
173 
174 #if (defined (HAVE_AMD) || defined (HAVE_CCOLAMD) \
175  || defined (HAVE_CHOLMOD) || defined (HAVE_COLAMD) \
176  || defined (HAVE_CXSPARSE) || defined (HAVE_SPQR) \
177  || defined (HAVE_UMFPACK))
178 
180 
181 # if defined (OCTAVE_ENABLE_64)
182 typedef SuiteSparse_long suitesparse_integer;
183 # else
185 # endif
186 
189 
190 extern const OCTAVE_API suitesparse_integer *
192 
195 
196 extern const OCTAVE_API octave_idx_type *
198 
199 inline octave_idx_type
200 from_suitesparse_long (SuiteSparse_long x)
201 {
204  (*current_liboctave_error_handler)
205  ("integer dimension or index out of range for Octave's indexing type");
206 
207  return static_cast<octave_idx_type> (x);
208 }
209 
210 inline octave_idx_type
211 from_size_t (std::size_t x)
212 {
213  // std::size_t is guaranteed to be unsigned
215  (*current_liboctave_error_handler)
216  ("integer dimension or index out of range for Octave's index type");
217 
218  return static_cast<octave_idx_type> (x);
219 }
220 
221 OCTAVE_END_NAMESPACE(octave)
222 
223 #endif
224 #endif
charNDArray max(char d, const charNDArray &m)
Definition: chNDArray.cc:230
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:207
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
F77_RET_T const F77_DBLE * x
#define OCTAVE_API
Definition: main.cc:55
octave_idx_type * to_octave_idx_type_ptr(suitesparse_integer *i)
Definition: oct-sparse.cc:67
int suitesparse_integer
Definition: oct-sparse.h:184
suitesparse_integer * to_suitesparse_intptr(octave_idx_type *i)
Definition: oct-sparse.cc:51
octave_idx_type from_suitesparse_long(SuiteSparse_long x)
Definition: oct-sparse.h:200
octave_idx_type from_size_t(std::size_t x)
Definition: oct-sparse.h:211