List of all members | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
casadi::Linsol Class Reference

Linear solver. More...

#include <linsol.hpp>

Detailed Description

Create a solver for linear systems of equations Solves the linear system A*X = B or A^T*X = B for X with A square and non-singular

If A is structurally singular, an error will be thrown during init. If A is numerically singular, the prepare step will fail.

General information

List of plugins

- csparsecholesky

- csparse

- ma27

- lapacklu

- lapackqr

- mumps

- ldl

- qr

- tridiag

- symbolicqr

Note: some of the plugins in this list might not be available on your system. Also, there might be extra plugins available to you that are not listed here. You can obtain their documentation with Linsol.doc("myextraplugin")


csparsecholesky

Linsol with CSparseCholesky Interface

Extra doc: https://github.com/casadi/casadi/wiki/L_21u


csparse

Linsol with CSparse Interface

Extra doc: https://github.com/casadi/casadi/wiki/L_21t


ma27

Interface to the sparse direct linear solver MA27 Works for symmetric indefinite systems Partly adopted from qpOASES 3.2

Author
Joel Andersson
Date
2016

Extra doc: https://github.com/casadi/casadi/wiki/L_229


lapacklu

This class solves the linear system A.x=b by making an LU factorization of A:
A = L.U, with L lower and U upper triangular

Extra doc: https://github.com/casadi/casadi/wiki/L_22h


List of available options
IdTypeDescription
allow_equilibration_failureOT_BOOLNon-fatal error when equilibration fails
equilibrationOT_BOOLEquilibrate the matrix

lapackqr

This class solves the linear system A.x=b by making an QR factorization of A:
A = Q.R, with Q orthogonal and R upper triangular

Extra doc: https://github.com/casadi/casadi/wiki/L_22g


List of available options
IdTypeDescription
max_nrhsOT_INTMaximum number of right-hand-sides that get processed in a single pass [default:10].

mumps

Interface to the sparse direct linear solver MUMPS Works for symmetric indefinite systems

Author
Joel Andersson
Date
2019

Extra doc: https://github.com/casadi/casadi/wiki/L_22t


List of available options
IdTypeDescription
posdefOT_BOOLPositive definite
symmetricOT_BOOLSymmetric matrix

ldl

Linear solver using sparse direct LDL factorization

Extra doc: https://github.com/casadi/casadi/wiki/L_233


List of available options
IdTypeDescription
incompleteOT_BOOLIncomplete factorization, without any fill-in
preorderingOT_BOOLApproximate minimal degree (AMD) preordering

qr

Linear solver using sparse direct QR factorization

Extra doc: https://github.com/casadi/casadi/wiki/L_22z


List of available options
IdTypeDescription
cacheOT_DOUBLEAmount of factorisations to remember (thread-local) [0]
epsOT_DOUBLEMinimum R entry before singularity is declared [1e-12]

tridiag

Linear solver for tridiagonal matrices

Extra doc: https://github.com/casadi/casadi/wiki/L_22v


symbolicqr

Linear solver for sparse least-squares problems Inspired from https://github.com/scipy/scipy/blob/v0.14.0/scipy/sparse/linalg/isolve/lsqr.py#L96

Extra doc: https://github.com/casadi/casadi/wiki/L_230

Linsol based on QR factorization with sparsity pattern based reordering without partial pivoting

Extra doc: https://github.com/casadi/casadi/wiki/L_231


List of available options
IdTypeDescription
foptsOT_DICTOptions to be passed to generated function objects
Author
Joel Andersson
Date
2011-2016

Extra doc: https://github.com/casadi/casadi/wiki/L_1kh

Definition at line 53 of file linsol.hpp.

Inheritance diagram for casadi::Linsol:
Inheritance graph
[legend]
Collaboration diagram for casadi::Linsol:
Collaboration graph
[legend]

Public Types

using internal_base_type = SharedObjectInternal
 
using base_type = SharedObject
 

Public Member Functions

 Linsol ()
 Default constructor. More...
 
 Linsol (const std::string &name, const std::string &solver, const Sparsity &sp, const Dict &opts=Dict())
 Constructor. More...
 
LinsolInternaloperator-> ()
 Access functions of the node. More...
 
const LinsolInternaloperator-> () const
 
std::string plugin_name () const
 Query plugin name. More...
 
const Sparsitysparsity () const
 Get linear system sparsity. More...
 
void sfact (const DM &A) const
 Symbolic factorization of the linear system, e.g. selecting pivots. More...
 
void nfact (const DM &A) const
 Numeric factorization of the linear system. More...
 
casadi_int neig (const DM &A) const
 Number of negative eigenvalues. More...
 
casadi_int rank (const DM &A) const
 Matrix rank. More...
 
double det (const DM &A) const
 Matrix determinant. More...
 
MX det (const MX &A) const
 Matrix determinant as an MX graph node. More...
 
Dict stats (int mem=1) const
 Get all statistics obtained at the end of the last evaluate call. More...
 
casadi_int checkout () const
 Checkout a memory object. More...
 
void release (int mem) const
 Release a memory object. More...
 
void serialize (SerializingStream &s) const
 Serialize an object. More...
 
std::string class_name () const
 Get class name. More...
 
void disp (std::ostream &stream, bool more=false) const
 Print a description of the object. More...
 
std::string get_str (bool more=false) const
 Get string representation. More...
 
void print_ptr (std::ostream &stream=casadi::uout()) const
 
void own (SharedObjectInternal *node)
 
void assign (SharedObjectInternal *node)
 Assign the node to a node class pointer without reference counting. More...
 
SharedObjectInternalget () const
 Get a const pointer to the node. More...
 
casadi_int getCount () const
 Get the reference count. More...
 
void swap (GenericShared &other)
 Swap content with another instance. More...
 
std::string debug_repr () const
 
bool is_null () const
 Is a null pointer? More...
 
casadi_int __hash__ () const
 Returns a number that is unique for a given Node. More...
 
GenericWeakRef< SharedObject, SharedObjectInternal > * weak ()
 Get a weak reference to the object. More...
 
DM solve (const DM &A, const DM &B, bool tr=false) const
 
MX solve (const MX &A, const MX &B, bool tr=false) const
 
int sfact (const double *A, int mem=0) const
 
int nfact (const double *A, int mem=0) const
 
int solve (const double *A, double *x, casadi_int nrhs=1, bool tr=false, int mem=0) const
 
double det (const double *A, int mem=0) const
 
casadi_int neig (const double *A, int mem=0) const
 
casadi_int rank (const double *A, int mem=0) const
 

Static Public Member Functions

static std::string type_name ()
 Get type name. More...
 
static bool test_cast (const SharedObjectInternal *ptr)
 Check if a particular cast is allowed. More...
 
static Linsol create (LinsolInternal *node)
 Create from node. More...
 
static bool has_plugin (const std::string &name)
 Check if a plugin is available. More...
 
static void load_plugin (const std::string &name)
 Explicitly load a plugin dynamically. More...
 
static std::string doc (const std::string &name)
 Get solver specific documentation. More...
 
static Linsol deserialize (DeserializingStream &s)
 Deserialize with type disambiguation. More...
 

Protected Member Functions

void count_up ()
 
void count_down ()
 

Member Typedef Documentation

◆ base_type

Definition at line 103 of file shared_object.hpp.

◆ internal_base_type

Definition at line 102 of file shared_object.hpp.

Constructor & Destructor Documentation

◆ Linsol() [1/2]

casadi::Linsol::Linsol ( )

Definition at line 32 of file linsol.cpp.

32  {
33  }

◆ Linsol() [2/2]

casadi::Linsol::Linsol ( const std::string &  name,
const std::string &  solver,
const Sparsity sp,
const Dict opts = Dict() 
)
explicit

Definition at line 35 of file linsol.cpp.

36  {
37  own(LinsolInternal::getPlugin(solver).creator(name, sp));
38  (*this)->construct(opts);
39  }
static Plugin & getPlugin(const std::string &pname)
Load and get the creator function.

References casadi::PluginInterface< LinsolInternal >::getPlugin(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().

Member Function Documentation

◆ __hash__()

casadi_int casadi::GenericShared< SharedObject , SharedObjectInternal >::__hash__
inherited

If the Object does not point to any node, "0" is returned.

Extra doc: https://github.com/casadi/casadi/wiki/L_av

Definition at line 123 of file generic_shared_impl.hpp.

148  {
149  return reinterpret_cast<casadi_int>(get());
150  }

◆ assign()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::assign ( Internal *  node)
inherited

improper use will cause memory leaks!

Extra doc: https://github.com/casadi/casadi/wiki/L_at

Definition at line 96 of file generic_shared_impl.hpp.

86  {
87  node = node_;
88  }

◆ checkout()

casadi_int casadi::Linsol::checkout ( ) const

Definition at line 220 of file linsol.cpp.

220  {
221  return (*this)->checkout();
222  }

Referenced by casadi::SundialsInterface::init_mem(), and casadi::Ipqp::solve().

◆ class_name()

std::string casadi::SharedObject::class_name ( ) const
inherited

◆ count_down()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::count_down
protectedinherited

Definition at line 133 of file generic_shared_impl.hpp.

46  {
47 #ifdef WITH_EXTRA_CHECKS
48  casadi_assert_dev(Function::call_depth_==0);
49 #endif // WITH_EXTRA_CHECKS
50  if (!node) return;
51 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
52  GenericWeakRef<Shared, Internal>* weak_ref =
53  node->weak_ref_.load(std::memory_order_acquire);
54 #else
55  GenericWeakRef<Shared, Internal>* weak_ref = node->weak_ref_;
56 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
57  if (weak_ref) {
58 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
59  // get_mutex() returns a shared_ptr copy, so the mutex outlives this lock
60  // even if delete node (below) destroys the WeakRefInternal holding it
61  auto mutex = weak_ref->get_mutex();
62  // Avoid triggering a delete while a weak_ref.shared_if_alive is being called
63  std::lock_guard<std::mutex> lock(*mutex);
64 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
65 
66  if (--static_cast<Internal*>(node)->count == 0) {
67  delete node;
68  node = nullptr;
69  }
70  } else {
71  if (--static_cast<Internal*>(node)->count == 0) {
72  delete node;
73  node = nullptr;
74  }
75  }
76  }

◆ count_up()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::count_up
protectedinherited

Definition at line 132 of file generic_shared_impl.hpp.

36  {
37 #ifdef WITH_EXTRA_CHECKS
38  casadi_assert_dev(Function::call_depth_==0);
39 #endif // WITH_EXTRA_CHECKS
40 
41  if (node) static_cast<Internal*>(node)->count++;
42 
43  }

◆ create()

Linsol casadi::Linsol::create ( LinsolInternal node)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_1kj

Definition at line 259 of file linsol.cpp.

259  {
260  Linsol ret;
261  ret.own(node);
262  return ret;
263  }
Linsol()
Default constructor.
Definition: linsol.cpp:32

References casadi::GenericShared< Shared, Internal >::own().

◆ debug_repr()

std::string casadi::GenericShared< SharedObject , SharedObjectInternal >::debug_repr
inherited

Definition at line 112 of file generic_shared_impl.hpp.

91  {
92  if (node) {
93  return node->debug_repr(node);
94  } else {
95  return "NULL";
96  }
97  }
std::string debug_repr(const Internal *) const

◆ deserialize()

Linsol casadi::Linsol::deserialize ( DeserializingStream s)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_1kn

Definition at line 252 of file linsol.cpp.

252  {
253  Linsol linsol;
254  linsol.own(LinsolInternal::deserialize(s));
255  linsol->finalize();
256  return linsol;
257  }
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.

References casadi::LinsolInternal::deserialize(), casadi::ProtoFunction::finalize(), and casadi::GenericShared< Shared, Internal >::own().

◆ det() [1/3]

double casadi::Linsol::det ( const DM A) const

Not available for all solvers

Extra doc: https://github.com/casadi/casadi/wiki/L_2hw

Definition at line 195 of file linsol.cpp.

195  {
196  if (A.sparsity()!=sparsity()) return det(project(A, sparsity()));
197  scoped_checkout<Linsol> mem(*this);
198  if (sfact(A.ptr(), mem)) casadi_error("Linsol::det: 'sfact' failed");
199  if (nfact(A.ptr(), mem)) casadi_error("Linsol::det: 'nfact' failed");
200  return det(A.ptr(), mem);
201  }
void nfact(const DM &A) const
Numeric factorization of the linear system.
Definition: linsol.cpp:130
double det(const DM &A) const
Matrix determinant.
Definition: linsol.cpp:195
const Sparsity & sparsity() const
Get linear system sparsity.
Definition: linsol.cpp:69
void sfact(const DM &A) const
Symbolic factorization of the linear system, e.g. selecting pivots.
Definition: linsol.cpp:105

References nfact(), casadi::Matrix< Scalar >::ptr(), sfact(), sparsity(), and casadi::Matrix< Scalar >::sparsity().

Referenced by casadi::MX::det(), casadi::Determinant::eval(), and casadi::Determinant::eval_mx().

◆ det() [2/3]

double casadi::Linsol::det ( const double *  A,
int  mem = 0 
) const

Low-level API

Definition at line 171 of file linsol.cpp.

171  {
172  auto m = static_cast<LinsolMemory*>((*this)->memory(mem));
173  casadi_assert(m->is_nfact, "Linear system has not been factorized");
174  return (*this)->det(m, A);
175  }

◆ det() [3/3]

MX casadi::Linsol::det ( const MX A) const

Definition at line 203 of file linsol.cpp.

203  {
204  return A->get_det(*this);
205  }

References casadi::MXNode::get_det().

◆ disp()

void casadi::SharedObject::disp ( std::ostream &  stream,
bool  more = false 
) const
inherited

Definition at line 35 of file shared_object.cpp.

35  {
36  if (is_null()) {
37  stream << "NULL";
38  } else {
39  (*this)->disp(stream, more);
40  }
41  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null().

Referenced by casadi::Nlpsol::disp_more(), and casadi::CsparseInterface::nfact().

◆ doc()

std::string casadi::Linsol::doc ( const std::string &  name)
static

Definition at line 61 of file linsol.cpp.

61  {
62  return LinsolInternal::getPlugin(name).doc;
63  }

References casadi::PluginInterface< LinsolInternal >::getPlugin().

Referenced by casadi::doc_linsol().

◆ get()

Definition at line 99 of file generic_shared_impl.hpp.

115  {
116  return node;
117  }

◆ get_str()

std::string casadi::SharedObject::get_str ( bool  more = false) const
inlineinherited

Definition at line 91 of file shared_object.hpp.

91  {
92  std::stringstream ss;
93  disp(ss, more);
94  return ss.str();
95  }
void disp(std::ostream &stream, bool more=false) const
Print a description of the object.

◆ getCount()

casadi_int casadi::GenericShared< SharedObject , SharedObjectInternal >::getCount
inherited

Definition at line 102 of file generic_shared_impl.hpp.

138  {
139  return (*this)->getCount();
140  }

◆ has_plugin()

bool casadi::Linsol::has_plugin ( const std::string &  name)
static

Definition at line 53 of file linsol.cpp.

53  {
54  return LinsolInternal::has_plugin(name);
55  }
static bool has_plugin(const std::string &pname, bool verbose=false)
Check if a plugin is available or can be loaded.

References casadi::PluginInterface< LinsolInternal >::has_plugin().

Referenced by casadi::has_linsol().

◆ is_null()

Definition at line 116 of file generic_shared_impl.hpp.

120  {
121  return node==nullptr;
122  }

◆ load_plugin()

void casadi::Linsol::load_plugin ( const std::string &  name)
static

Definition at line 57 of file linsol.cpp.

57  {
59  }
static Plugin load_plugin(const std::string &pname, bool register_plugin=true, bool needs_lock=true)
Load a plugin dynamically.

References casadi::PluginInterface< LinsolInternal >::load_plugin().

Referenced by casadi::load_linsol().

◆ neig() [1/2]

casadi_int casadi::Linsol::neig ( const DM A) const

Not available for all solvers

Extra doc: https://github.com/casadi/casadi/wiki/L_1kk

Definition at line 177 of file linsol.cpp.

177  {
178  if (A.sparsity()!=sparsity()) return neig(project(A, sparsity()));
179  casadi_int n = neig(A.ptr());
180  casadi_assert(n>=0, "'neig' failed");
181  return n;
182  }
casadi_int neig(const DM &A) const
Number of negative eigenvalues.
Definition: linsol.cpp:177

References casadi::Matrix< Scalar >::ptr(), sparsity(), and casadi::Matrix< Scalar >::sparsity().

Referenced by casadi::QpoasesInterface::qpoases_nfact().

◆ neig() [2/2]

casadi_int casadi::Linsol::neig ( const double *  A,
int  mem = 0 
) const

Low-level API

Definition at line 184 of file linsol.cpp.

184  {
185  return (*this)->neig((*this)->memory(mem), A);
186  }

◆ nfact() [1/2]

void casadi::Linsol::nfact ( const DM A) const

Definition at line 130 of file linsol.cpp.

130  {
131  if (A.sparsity()!=sparsity()) {
132  nfact(project(A, sparsity()));
133  return;
134  }
135  if (nfact(A.ptr())) casadi_error("'nfact' failed");
136  }

References casadi::Matrix< Scalar >::ptr(), sparsity(), and casadi::Matrix< Scalar >::sparsity().

Referenced by det(), casadi::Determinant::eval(), casadi::SlicotDple::eval(), casadi::KinsolInterface::psetup(), casadi::QpoasesInterface::qpoases_nfact(), solve(), casadi::Ipqp::solve(), and casadi::Newton::solve().

◆ nfact() [2/2]

int casadi::Linsol::nfact ( const double *  A,
int  mem = 0 
) const

Low-level API

Definition at line 138 of file linsol.cpp.

138  {
139  if (A==nullptr) return 1;
140  auto *m = static_cast<LinsolMemory*>((*this)->memory(mem));
141 
142  // Perform pivoting, if required
143  if (!m->is_sfact) {
144  if (sfact(A, mem)) return 1;
145  }
146 
147  m->is_nfact = false;
148  if (m->t_total) m->fstats.at("nfact").tic();
149  int flag = (*this)->nfact(m, A);
150  if (m->t_total) m->fstats.at("nfact").toc();
151  if (flag && (*this)->regularity_check_) {
152  // Collect nonzeros
153  std::vector<std::string> nonzeros(sparsity().nnz());
154  for (size_t nz = 0; nz < nonzeros.size(); ++nz)
155  nonzeros[nz] = std::to_string(A[nz]);
156  // Create .m file
157  std::string fname = (*this)->class_name() + "_" + (*this)->name_ + "_debug.m";
158  auto mfile_ptr = Filesystem::ofstream_ptr(fname);
159  std::ostream& mfile = *mfile_ptr;
160  Dict opts;
161  opts["name"] = "A";
162  opts["nonzeros"] = nonzeros;
163  sparsity().export_code("matlab", mfile, opts);
164  casadi_error("Numerical factorization failed for " + (*this)->name_
165  + "[" + (*this)->class_name() + "]. Linear system saved to '" + fname + "'");
166  }
167  m->is_nfact = true;
168  return flag;
169  }
static std::unique_ptr< std::ostream > ofstream_ptr(const std::string &path, std::ios_base::openmode mode=std::ios_base::out)
Definition: filesystem.cpp:115
void export_code(const std::string &lang, std::ostream &stream=casadi::uout(), const Dict &options=Dict()) const
Export matrix in specific language.
Definition: sparsity.cpp:789
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.

References casadi::Sparsity::export_code(), casadi::LinsolMemory::is_nfact, casadi::Filesystem::ofstream_ptr(), sfact(), and sparsity().

◆ operator->() [1/2]

LinsolInternal * casadi::Linsol::operator-> ( )

Definition at line 41 of file linsol.cpp.

41  {
42  return static_cast<LinsolInternal*>(SharedObject::operator->());
43  }
SharedObjectInternal * operator->() const
Access a member function or object.

References casadi::GenericShared< SharedObject, SharedObjectInternal >::operator->().

◆ operator->() [2/2]

const LinsolInternal * casadi::Linsol::operator-> ( ) const

Definition at line 45 of file linsol.cpp.

45  {
46  return static_cast<const LinsolInternal*>(SharedObject::operator->());
47  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::operator->().

◆ own()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::own ( Internal *  node)
inherited

Assign the node to a node class pointer (or null)

Definition at line 89 of file generic_shared_impl.hpp.

◆ plugin_name()

std::string casadi::Linsol::plugin_name ( ) const

Definition at line 65 of file linsol.cpp.

65  {
66  return (*this)->plugin_name();
67  }

◆ print_ptr()

void casadi::SharedObject::print_ptr ( std::ostream &  stream = casadi::uout()) const
inherited

Print the pointer to the internal class

Definition at line 43 of file shared_object.cpp.

43  {
44  stream << get();
45  }
SharedObjectInternal * get() const
Get a const pointer to the node.

References casadi::GenericShared< SharedObject, SharedObjectInternal >::get().

◆ rank() [1/2]

casadi_int casadi::Linsol::rank ( const DM A) const

Not available for all solvers

Extra doc: https://github.com/casadi/casadi/wiki/L_1kl

Definition at line 188 of file linsol.cpp.

188  {
189  if (A.sparsity()!=sparsity()) return rank(project(A, sparsity()));
190  casadi_int n = rank(A.ptr());
191  casadi_assert(n>=0, "'rank' failed");
192  return n;
193  }
casadi_int rank(const DM &A) const
Matrix rank.
Definition: linsol.cpp:188

References casadi::Matrix< Scalar >::ptr(), sparsity(), and casadi::Matrix< Scalar >::sparsity().

Referenced by casadi::QpoasesInterface::qpoases_nfact().

◆ rank() [2/2]

casadi_int casadi::Linsol::rank ( const double *  A,
int  mem = 0 
) const

Low-level API

Definition at line 207 of file linsol.cpp.

207  {
208  return (*this)->rank((*this)->memory(mem), A);
209  }

◆ release()

void casadi::Linsol::release ( int  mem) const

Definition at line 224 of file linsol.cpp.

224  {
225  (*this)->release(mem);
226  }

Referenced by casadi::Ipqp::solve().

◆ serialize()

void casadi::Linsol::serialize ( SerializingStream s) const

Extra doc: https://github.com/casadi/casadi/wiki/L_1km

Definition at line 247 of file linsol.cpp.

247  {
248  // TODO(jgillis): I don't get why LinsolInternal:: this is necessary
249  (*this)->LinsolInternal::serialize(s);
250  }

◆ sfact() [1/2]

void casadi::Linsol::sfact ( const DM A) const

Definition at line 105 of file linsol.cpp.

105  {
106  if (A.sparsity()!=sparsity()) {
107  sfact(project(A, sparsity()));
108  return;
109  }
110  if (sfact(A.ptr())) casadi_error("'sfact' failed");
111  }

References casadi::Matrix< Scalar >::ptr(), sparsity(), and casadi::Matrix< Scalar >::sparsity().

Referenced by det(), casadi::Determinant::eval(), casadi::SlicotDple::eval(), nfact(), casadi::QpoasesInterface::qpoases_sfact(), and solve().

◆ sfact() [2/2]

int casadi::Linsol::sfact ( const double *  A,
int  mem = 0 
) const

Low-level API

Definition at line 113 of file linsol.cpp.

113  {
114  if (A==nullptr) return 1;
115  auto *m = static_cast<LinsolMemory*>((*this)->memory(mem));
116 
117  // Factorization will be needed after this step
118  m->is_sfact = m->is_nfact = false;
119 
120  if (m->t_total) m->fstats.at("sfact").tic();
121  // Perform pivoting
122  if ((*this)->sfact(m, A)) return 1;
123  if (m->t_total) m->fstats.at("sfact").toc();
124 
125  // Mark as (successfully) pivoted
126  m->is_sfact = true;
127  return 0;
128  }

References casadi::LinsolMemory::is_sfact.

◆ solve() [1/3]

DM casadi::Linsol::solve ( const DM A,
const DM B,
bool  tr = false 
) const

Solve linear system of equations

Definition at line 73 of file linsol.cpp.

73  {
74  casadi_assert(A.size1()==B.size1(),
75  "Linsol::solve: Dimension mismatch. A and b must have matching row count. "
76  "Got " + A.dim() + " and " + B.dim() + ".");
77 
78  scoped_checkout<Linsol> mem(*this);
79  auto *m = static_cast<LinsolMemory*>((*this)->memory(mem));
80 
81  // Reset statistics
82  for (auto&& s : m->fstats) s.second.reset();
83  if (m->t_total) m->t_total->tic();
84  // Symbolic factorization
85  if (sfact(A.ptr(), mem)) casadi_error("Linsol::solve: 'sfact' failed");
86 
87  // Numeric factorization
88  if (nfact(A.ptr(), mem)) casadi_error("Linsol::solve: 'nfact' failed");
89 
90  // Solve
91  DM x = densify(B);
92  if (solve(A.ptr(), x.ptr(), x.size2(), tr, mem))
93  casadi_error("Linsol::solve: 'solve' failed");
94  // Show statistics
95  if (m->t_total) m->t_total->toc();
96 
97  (*this)->print_time(m->fstats);
98  return x;
99  }
DM solve(const DM &A, const DM &B, bool tr=false) const
Definition: linsol.cpp:73
Matrix< double > DM
Definition: dm_fwd.hpp:33

References casadi::GenericMatrix< MatType >::dim(), nfact(), casadi::Matrix< Scalar >::ptr(), sfact(), casadi::GenericMatrix< MatType >::size1(), casadi::GenericMatrix< MatType >::size2(), casadi::ProtoFunctionMemory::t_total, and casadi::FStats::tic().

Referenced by casadi::SlicotDple::eval(), casadi::KinsolInterface::psolve(), casadi::QpoasesInterface::qpoases_solve(), casadi::Ipqp::solve(), casadi::LinsolCall< Tr >::solve(), casadi::MX::solve(), casadi::Newton::solve(), and casadi::IdasInterface::solve_transposed().

◆ solve() [2/3]

int casadi::Linsol::solve ( const double *  A,
double *  x,
casadi_int  nrhs = 1,
bool  tr = false,
int  mem = 0 
) const

Low-level API

Definition at line 211 of file linsol.cpp.

211  {
212  auto *m = static_cast<LinsolMemory*>((*this)->memory(mem));
213  casadi_assert(m->is_nfact, "Linear system has not been factorized");
214  if (m->t_total) m->fstats.at("solve").tic();
215  int ret = (*this)->solve(m, A, x, nrhs, tr);
216  if (m->t_total) m->fstats.at("solve").toc();
217  return ret;
218  }

◆ solve() [3/3]

MX casadi::Linsol::solve ( const MX A,
const MX B,
bool  tr = false 
) const

Solve linear system of equations

Definition at line 101 of file linsol.cpp.

101  {
102  return A->get_solve(B, tr, *this);
103  }

References casadi::MXNode::get_solve().

◆ sparsity()

const Sparsity & casadi::Linsol::sparsity ( ) const

Definition at line 69 of file linsol.cpp.

69  {
70  return (*this)->sp_;
71  }

Referenced by det(), casadi::SundialsInterface::init(), neig(), nfact(), rank(), casadi::SundialsInterface::set_work(), and sfact().

◆ stats()

Dict casadi::Linsol::stats ( int  mem = 1) const

Definition at line 241 of file linsol.cpp.

241  {
242  casadi_assert((*this)->has_memory(mem),
243  "No stats available since Linsol did not solve a problem yet.");
244  return (*this)->get_stats((*this)->memory(mem));
245  }

◆ swap()

Definition at line 105 of file generic_shared_impl.hpp.

131  {
132  GenericShared<Shared, Internal> temp = *this;
133  *this = other;
134  other = temp;
135  }

◆ test_cast()

bool casadi::Linsol::test_cast ( const SharedObjectInternal ptr)
static

Definition at line 49 of file linsol.cpp.

49  {
50  return dynamic_cast<const LinsolInternal*>(ptr)!=nullptr;
51  }

◆ type_name()

static std::string casadi::Linsol::type_name ( )
inlinestatic

Extra doc: https://github.com/casadi/casadi/wiki/L_1ki

Definition at line 60 of file linsol.hpp.

60 {return "Linsol";}

◆ weak()

Extra doc: https://github.com/casadi/casadi/wiki/L_aw

Definition at line 130 of file generic_shared_impl.hpp.

143  {
144  return (*this)->weak();
145  }

The documentation for this class was generated from the following files: