26 #include "symbolic_qr.hpp"
35 int CASADI_LINSOL_SYMBOLICQR_EXPORT
38 plugin->name =
"symbolicqr";
40 plugin->version = CASADI_VERSION;
63 "Options to be passed to generated function objects"}}
72 for (
auto&& op : opts) {
73 if (op.first==
"fopts") {
82 std::vector<casadi_int> rowperm, colperm, rowblock, colblock, coarse_rowblock, coarse_colblock;
83 sp_.
btf(rowperm, colperm, rowblock, colblock, coarse_rowblock, coarse_colblock);
86 std::vector<casadi_int> inv_colperm(colperm.size());
87 for (casadi_int k=0; k<colperm.size(); ++k)
88 inv_colperm[colperm[k]] = k;
91 std::vector<casadi_int> inv_rowperm(rowperm.size());
92 for (casadi_int k=0; k<rowperm.size(); ++k)
93 inv_rowperm[rowperm[k]] = k;
96 SX Aperm = A(rowperm, colperm);
112 SX bperm = b(rowperm,
Slice());
118 SX x = xperm(inv_colperm,
Slice());
121 std::vector<SX> solv_in = {
Q, R, b};
130 bperm = b(colperm,
Slice());
136 x = xperm(inv_rowperm,
Slice());
151 m->w.resize(m->w.size() +
sp_.
size1());
179 std::fill_n(
get_ptr(m->arg), solv.
n_in(),
nullptr);
183 for (casadi_int i=0; i<nrhs; ++i) {
195 casadi_int* iw,
SXElem* w,
void* mem,
196 bool tr, casadi_int nrhs)
const {
198 casadi_assert_dev(arg[0]!=
nullptr);
199 casadi_assert_dev(arg[1]!=
nullptr);
200 casadi_assert_dev(res[0]!=
nullptr);
204 std::copy(arg[1], arg[1]+A.
nnz(), A->begin());
214 for (casadi_int i=0; i<nrhs; ++i) {
215 std::copy(a, a+v[2].
nnz(), v[2]->begin());
216 SX rr = solv(v).at(0);
217 std::copy(rr->begin(), rr->end(), r);
226 iw.resize(std::max(
iw.size(), f.
sz_iw()));
227 w.resize(std::max(
w.size(), f.
sz_w()));
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
void version(const std::string &name, int v)
static const Options options_
Options.
casadi_int nnz_out() const
Get number of output nonzeros.
size_t sz_res() const
Get required length of res field.
size_t sz_iw() const
Get required length of iw field.
casadi_int n_out() const
Get the number of function outputs.
casadi_int n_in() const
Get the number of function inputs.
size_t sz_w() const
Get required length of w field.
size_t sz_arg() const
Get required length of arg field.
casadi_int nnz() const
Get the number of (structural) non-zero elements.
casadi_int size1() const
Get the first dimension (i.e. number of rows)
static Matrix< Scalar > sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.
static Matrix< Scalar > zeros(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries zero.
void init(const Dict &opts) override
Initialize.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
casadi_int nrow() const
Get sparsity pattern.
int init_mem(void *mem) const override
Initalize memory block.
Sparse matrix class. SX and DM are specializations.
Matrix< Scalar > T() const
Transpose the matrix.
const Sparsity & sparsity() const
Const access the sparsity - reference to data member.
static Matrix< Scalar > solve(const Matrix< Scalar > &A, const Matrix< Scalar > &b)
static void registerPlugin(const Plugin &plugin, bool needs_lock=true)
Register an integrator in the factory.
void clear_mem()
Clear all memory (called from destructor)
The basic scalar symbolic class of CasADi.
Helper class for Serialization.
void version(const std::string &name, int v)
void pack(const Sparsity &e)
Serializes an object to the output stream.
Class representing a Slice.
casadi_int size1() const
Get the number of rows.
casadi_int size2() const
Get the number of columns.
casadi_int btf(std::vector< casadi_int > &rowperm, std::vector< casadi_int > &colperm, std::vector< casadi_int > &rowblock, std::vector< casadi_int > &colblock, std::vector< casadi_int > &coarse_rowblock, std::vector< casadi_int > &coarse_colblock) const
Calculate the block triangular form (BTF)
int init_mem(void *mem) const override
Initalize memory block.
static const Options options_
Options.
SymbolicQr(const std::string &name, const Sparsity &sp)
void init(const Dict &opts) override
Initialize.
static LinsolInternal * creator(const std::string &name, const Sparsity &sp)
Create a new Linsol.
static const std::string meta_doc
A documentation string.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
int solve(void *mem, const double *A, double *x, casadi_int nrhs, bool tr) const override
void linsol_eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w, void *mem, bool tr, casadi_int nrhs) const override
Evaluate symbolically (SX)
int nfact(void *mem, const double *A) const override
Numeric factorization.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
int CASADI_LINSOL_SYMBOLICQR_EXPORT casadi_register_linsol_symbolicqr(LinsolInternal::Plugin *plugin)
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
T * get_ptr(std::vector< T > &v)
Get a pointer to the data contained in the vector.
void CASADI_LINSOL_SYMBOLICQR_EXPORT casadi_load_linsol_symbolicqr()
Options metadata for a class.
void alloc(const Function &f)
std::vector< casadi_int > iw
std::vector< double * > res
std::vector< const double * > arg