26 #ifndef CASADI_SETNONZEROS_IMPL_HPP
27 #define CASADI_SETNONZEROS_IMPL_HPP
29 #include "setnonzeros.hpp"
30 #include "casadi_misc.hpp"
31 #include "serializing_stream.hpp"
41 std::pair<Slice, Slice> sl =
to_slice2(nz);
42 return create(y, x, sl.first, sl.second);
73 const std::vector<casadi_int>& nz) :
SetNonzeros<Add>(y, x), nz_(nz) {
76 std::vector<bool> already_set(this->
nnz(),
false);
77 for (std::vector<casadi_int>::reverse_iterator i=
nz_.rbegin(); i!=
nz_.rend(); ++i) {
79 if (already_set[*i]) {
82 already_set[*i] =
true;
95 const std::vector<bool>& unique)
const {
105 const std::vector<bool>& unique)
const {
115 const std::vector<bool>& unique)
const {
125 const std::vector<bool>& unique)
const {
127 std::vector<casadi_int> nz =
all();
131 const casadi_int* orow = osp.
row();
132 std::vector<casadi_int> ocol = osp.
get_col();
135 const Sparsity &isp = dep(1).sparsity();
136 std::vector<casadi_int> icol = isp.
get_col();
140 std::vector<casadi_int> onz_count(osp.
nnz()+2, 0);
141 for (std::vector<casadi_int>::const_iterator it=nz.begin(); it!=nz.end(); ++it) {
146 for (casadi_int i=0; i<onz_count.size()-1; ++i) {
147 onz_count[i+1] += onz_count[i];
151 std::vector<casadi_int> nz_order(nz.size());
152 for (casadi_int k=0; k<nz.size(); ++k) {
154 nz_order[onz_count[1+nz[k]]++] = k;
158 std::vector<casadi_int>& with_duplicates = onz_count;
159 onz_count.resize(nz.size());
160 for (casadi_int k=0; k<nz.size(); ++k) {
162 casadi_int onz_k = nz[nz_order[k]];
166 with_duplicates[k] = ocol[onz_k]*osp.
size1() + orow[onz_k];
168 with_duplicates[k] = -1;
173 std::vector<casadi_int> el_output;
177 std::vector<casadi_int> r_colind, r_row, r_nz, r_ind;
186 r_nz.resize(with_duplicates.size());
187 std::copy(with_duplicates.begin(), with_duplicates.end(), r_nz.begin());
188 res[0].sparsity().get_nz(r_nz);
199 bool elements_to_add =
false;
200 for (std::vector<casadi_int>::iterator k=r_nz.begin(); k!=r_nz.end(); ++k) {
203 elements_to_add =
true;
211 if (!elements_to_add)
return;
214 r_ind.resize(el_output.size());
215 std::copy(el_output.begin(), el_output.end(), r_ind.begin());
216 res[0].sparsity().get_nz(r_ind);
219 for (std::vector<casadi_int>::iterator k=r_nz.begin(); k!=r_nz.end(); ++k) {
220 if (*k>=0 && nz[*k]>=0 && r_ind[nz[*k]]<0) {
225 res[0] = res[0]->get_project(sp);
228 std::copy(el_output.begin(), el_output.end(), r_ind.begin());
229 res[0].sparsity().get_nz(r_ind);
236 for (std::vector<casadi_int>::iterator k=r_nz.begin(); k!=r_nz.end(); ++k) {
243 res[0] = arg[1]->get_nzadd(res[0], r_nz);
248 std::vector<std::vector<MX> >& fsens)
const {
250 std::vector<casadi_int> nz =
all();
253 casadi_int nfwd = fsens.size();
257 const casadi_int* orow = osp.
row();
258 std::vector<casadi_int> ocol;
261 const Sparsity &isp = dep(1).sparsity();
262 std::vector<casadi_int> icol;
264 bool first_run =
true;
266 std::vector<casadi_int> onz_count;
268 std::vector<casadi_int> nz_order;
271 std::vector<casadi_int>& with_duplicates = onz_count;
274 std::vector<casadi_int> el_output;
277 std::vector<casadi_int> r_colind, r_row, r_nz, r_ind;
280 for (casadi_int d=0; d<nfwd; ++d) {
283 const MX& arg = fseed[d][1];
284 const MX& arg0 = fseed[d][0];
286 MX& res = fsens[d][0];
315 onz_count.resize(osp.
nnz()+2, 0);
316 for (std::vector<casadi_int>::const_iterator it=nz.begin(); it!=nz.end(); ++it) {
321 for (casadi_int i=0; i<onz_count.size()-1; ++i) {
322 onz_count[i+1] += onz_count[i];
326 nz_order.resize(nz.size());
327 for (casadi_int k=0; k<nz.size(); ++k) {
329 nz_order[onz_count[1+nz[k]]++] = k;
332 onz_count.resize(nz.size());
333 for (casadi_int k=0; k<nz.size(); ++k) {
335 casadi_int onz_k = nz[nz_order[k]];
339 with_duplicates[k] = ocol[onz_k]*osp.
size1() + orow[onz_k];
341 with_duplicates[k] = -1;
353 r_nz.resize(with_duplicates.size());
354 std::copy(with_duplicates.begin(), with_duplicates.end(), r_nz.begin());
367 bool elements_to_add =
false;
368 for (std::vector<casadi_int>::iterator k=r_nz.begin(); k!=r_nz.end(); ++k) {
371 elements_to_add =
true;
379 if (!elements_to_add)
continue;
382 r_ind.resize(el_output.size());
383 std::copy(el_output.begin(), el_output.end(), r_ind.begin());
387 for (std::vector<casadi_int>::iterator k=r_nz.begin(); k!=r_nz.end(); ++k) {
388 if (*k>=0 && nz[*k]>=0 && r_ind[nz[*k]]<0) {
396 std::copy(el_output.begin(), el_output.end(), r_ind.begin());
404 for (std::vector<casadi_int>::iterator k=r_nz.begin(); k!=r_nz.end(); ++k) {
418 std::vector<std::vector<MX> >& asens)
const {
420 std::vector<casadi_int> nz =
all();
423 casadi_int nadj = aseed.size();
427 const casadi_int* orow = osp.
row();
428 std::vector<casadi_int> ocol;
431 const Sparsity &isp = dep(1).sparsity();
432 const casadi_int* irow = isp.
row();
433 std::vector<casadi_int> icol;
435 std::vector<casadi_int> onz_count;
438 std::vector<casadi_int> nz_order;
440 std::vector<casadi_int>& with_duplicates = onz_count;
443 std::vector<casadi_int> el_output;
445 bool first_run =
true;
448 std::vector<casadi_int> r_colind, r_row, r_nz, r_ind;
450 for (casadi_int d=0; d<nadj; ++d) {
451 if (osp==aseed[d][0].sparsity()) {
461 asens[d][1] += aseed[d][0]->get_nzref(isp, nz);
465 asens[d][0] += aseed[d][0];
473 onz_count.resize(osp.
nnz()+2, 0);
474 for (std::vector<casadi_int>::const_iterator it=nz.begin(); it!=nz.end(); ++it) {
479 for (casadi_int i=0; i<onz_count.size()-1; ++i) {
480 onz_count[i+1] += onz_count[i];
484 nz_order.resize(nz.size());
485 for (casadi_int k=0; k<nz.size(); ++k) {
487 nz_order[onz_count[1+nz[k]]++] = k;
491 onz_count.resize(nz.size());
492 for (casadi_int k=0; k<nz.size(); ++k) {
494 casadi_int onz_k = nz[nz_order[k]];
498 with_duplicates[k] = ocol[onz_k]*osp.
size1() + orow[onz_k];
500 with_duplicates[k] = -1;
509 r_ind.resize(el_output.size());
510 std::copy(el_output.begin(), el_output.end(), r_ind.begin());
511 aseed[d][0].sparsity().get_nz(r_ind);
514 r_colind.resize(isp.
size2()+1);
515 std::fill(r_colind.begin(), r_colind.end(), 0);
520 for (casadi_int k=0; k<nz.size(); ++k) {
523 casadi_int el = nz[k];
526 if (el==-1)
continue;
529 casadi_int el_arg = r_ind[el];
532 if (el_arg==-1)
continue;
535 r_nz.push_back(el_arg);
538 casadi_int i=icol[k], j=irow[k];
546 for (casadi_int i=1; i<r_colind.size(); ++i) r_colind[i] += r_colind[i-1];
552 asens[d][1] += aseed[d][0]->get_nzref(f_sp, r_nz);
556 asens[d][0] += aseed[d][0];
559 asens[d][0] += aseed[d][0];
567 eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
568 return eval_gen<double>(arg, res, iw, w);
574 return eval_gen<SXElem>(arg, res, iw, w);
580 eval_gen(
const T** arg, T** res, casadi_int* iw, T* w)
const {
581 const T* idata0 = arg[0];
582 const T* idata = arg[1];
584 if (idata0 != odata) {
585 std::copy(idata0, idata0+this->dep(0).nnz(), odata);
587 for (
auto k=this->nz_.begin(); k!=this->nz_.end(); ++k, ++idata) {
589 if (*k>=0) odata[*k] += *idata;
591 if (*k>=0) odata[*k] = *idata;
599 eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
600 return eval_gen<double>(arg, res, iw, w);
606 return eval_gen<SXElem>(arg, res, iw, w);
612 eval_gen(
const T** arg, T** res, casadi_int* iw, T* w)
const {
613 const T* idata0 = arg[0];
614 const T* idata = arg[1];
616 if (idata0 != odata) {
617 std::copy(idata0, idata0+this->dep(0).nnz(), odata);
619 T* odata_stop = odata + s_.stop;
620 for (odata += s_.start; odata != odata_stop; odata += s_.step) {
632 eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
633 return eval_gen<double>(arg, res, iw, w);
639 return eval_gen<SXElem>(arg, res, iw, w);
645 eval_gen(
const T** arg, T** res, casadi_int* iw, T* w)
const {
646 const T* idata0 = arg[0];
647 const T* idata = arg[1];
649 if (idata0 != odata) {
650 std::copy(idata0, idata0 + this->dep(0).nnz(), odata);
652 T* outer_stop = odata + outer_.stop;
653 T* outer = odata + outer_.start;
654 for (; outer != outer_stop; outer += outer_.step) {
655 for (
T* inner = outer+inner_.start;
656 inner != outer+inner_.stop;
657 inner += inner_.step) {
671 const bvec_t *a0 = arg[0];
674 casadi_int n = this->nnz();
677 if (r != a0) std::copy(a0, a0+n, r);
678 for (
auto k=this->nz_.begin(); k!=this->nz_.end(); ++k, ++a) {
680 if (*k>=0) r[*k] |= *a;
682 if (*k>=0) r[*k] = *a;
693 for (
auto k=this->nz_.begin(); k!=this->nz_.end(); ++k, ++a) {
708 const bvec_t *a0 = arg[0];
711 casadi_int n = this->nnz();
714 if (r != a0) std::copy(a0, a0+n, r);
715 for (casadi_int k=s_.start; k!=s_.stop; k+=s_.step) {
730 for (casadi_int k=s_.start; k!=s_.stop; k+=s_.step) {
743 const bvec_t *a0 = arg[0];
746 casadi_int n = this->nnz();
749 if (r != a0) std::copy(a0, a0+n, r);
750 for (casadi_int k1=outer_.start; k1!=outer_.stop; k1+=outer_.step) {
751 for (casadi_int k2=k1+inner_.start; k2!=k1+inner_.stop; k2+=inner_.step) {
767 for (casadi_int k1=outer_.start; k1!=outer_.stop; k1+=outer_.step) {
768 for (casadi_int k2=k1+inner_.start; k2!=k1+inner_.stop; k2+=inner_.step) {
781 std::stringstream ss;
782 ss <<
"(" << arg.at(0) << nz_ << (Add ?
" += " :
" = ") << arg.at(1) <<
")";
788 std::stringstream ss;
789 ss <<
"(" << arg.at(0) <<
"[" << s_ <<
"]" << (Add ?
" += " :
" = ") << arg.at(1) <<
")";
795 std::stringstream ss;
796 ss <<
"(" << arg.at(0) <<
"[" << outer_ <<
";" << inner_ <<
"]" << (Add ?
" += " :
" = ")
803 std::vector<casadi_int> nz =
all();
810 if (!this->sameOpAndDeps(node, depth))
return false;
814 if (n==
nullptr)
return false;
817 if (this->sparsity()!=node->
sparsity())
return false;
820 if (this->nz_.size()!=n->
nz_.size())
return false;
821 if (!std::equal(this->nz_.begin(), this->nz_.end(), n->
nz_.begin()))
return false;
829 if (!this->sameOpAndDeps(node, depth))
return false;
833 if (n==
nullptr)
return false;
836 if (this->sparsity()!=node->
sparsity())
return false;
839 if (this->s_ != n->
s_)
return false;
847 if (!this->sameOpAndDeps(node, depth))
return false;
851 if (n==
nullptr)
return false;
854 if (this->sparsity()!=node->
sparsity())
return false;
857 if (this->inner_ != n->
inner_ || this->outer_!=n->
outer_)
return false;
865 const std::vector<casadi_int>& arg,
866 const std::vector<casadi_int>& res,
867 const std::vector<bool>& arg_is_ref,
868 std::vector<bool>& res_is_ref)
const {
870 if (arg[0]!=res[0] || arg_is_ref[0]) {
871 g << g.
copy(g.
work(arg[0], this->dep(0).nnz(), arg_is_ref[0]), this->nnz(),
872 g.
work(res[0], this->nnz(),
false)) <<
'\n';
876 std::string ind = g.
constant(this->nz_);
879 g.
local(
"cii",
"const casadi_int",
"*");
880 g.
local(
"rr",
"casadi_real",
"*");
881 g.
local(
"cs",
"const casadi_real",
"*");
882 g <<
"for (cii=" << ind <<
", rr=" << g.
work(res[0], this->nnz(),
false) <<
", "
883 <<
"cs=" << g.
work(arg[1], this->dep(1).nnz(), arg_is_ref[1]) <<
"; cii!=" << ind
884 <<
"+" << this->nz_.size() <<
"; ++cii, ++cs) ";
886 g <<
"if (*cii>=0) ";
888 g <<
"rr[*cii] " << (Add?
"+=":
"=") <<
" *cs;\n";
894 const std::vector<casadi_int>& arg,
895 const std::vector<casadi_int>& res,
896 const std::vector<bool>& arg_is_ref,
897 std::vector<bool>& res_is_ref)
const {
899 if (arg[0]!=res[0] || arg_is_ref[0]) {
900 g << g.
copy(g.
work(arg[0], this->dep(0).nnz(), arg_is_ref[0]), this->nnz(),
901 g.
work(res[0], this->nnz(),
false)) <<
'\n';
905 g.
local(
"rr",
"casadi_real",
"*");
906 g.
local(
"cs",
"const casadi_real",
"*");
907 g <<
"for (rr=" << g.
work(res[0], this->nnz(),
false) <<
"+" << s_.start <<
", cs="
908 << g.
work(arg[1], this->dep(1).nnz(), arg_is_ref[1]) <<
"; rr!="
909 << g.
work(res[0], this->nnz(),
false) <<
"+" << s_.stop
910 <<
"; rr+=" << s_.step <<
")"
911 <<
" *rr " << (Add?
"+=":
"=") <<
" *cs++;\n";
917 const std::vector<casadi_int>& arg,
918 const std::vector<casadi_int>& res,
919 const std::vector<bool>& arg_is_ref,
920 std::vector<bool>& res_is_ref)
const {
922 if (arg[0]!=res[0] || arg_is_ref[0]) {
923 g << g.
copy(g.
work(arg[0], this->dep(0).nnz(), arg_is_ref[0]), this->nnz(),
924 g.
work(res[0], this->nnz(),
false)) <<
'\n';
928 g.
local(
"rr",
"casadi_real",
"*");
929 g.
local(
"cs",
"const casadi_real",
"*");
930 g.
local(
"tt",
"casadi_real",
"*");
931 g <<
"for (rr=" << g.
work(res[0], this->nnz(),
false) <<
"+" << outer_.start
932 <<
", cs=" << g.
work(arg[1], this->dep(1).nnz(), arg_is_ref[1]) <<
"; rr!="
933 << g.
work(res[0], this->nnz(),
false) <<
"+" << outer_.stop
934 <<
"; rr+=" << outer_.step <<
")"
935 <<
" for (tt=rr+" << inner_.start <<
"; tt!=rr+" << inner_.stop
936 <<
"; tt+=" << inner_.step <<
")"
937 <<
" *tt " << (Add?
"+=":
"=") <<
" *cs++;\n";
943 s.
pack(
"SetNonzerosVector::nonzeros", nz_);
948 s.
unpack(
"SetNonzerosVector::nonzeros",
nz_);
954 s.
pack(
"SetNonzeros::type",
'a');
960 s.
pack(
"SetNonzerosSlice::slice", s_);
965 s.
unpack(
"SetNonzerosSlice::slice",
s_);
971 s.
pack(
"SetNonzeros::type",
'b');
977 s.
pack(
"SetNonzerosSlice2::inner", inner_);
978 s.
pack(
"SetNonzerosSlice2::outer", outer_);
990 s.
pack(
"SetNonzeros::type",
'c');
996 s.
unpack(
"SetNonzeros::type", t);
1001 default: casadi_assert_dev(
false);
Helper class for C code generation.
std::string work(casadi_int n, casadi_int sz, bool is_ref) const
std::string copy(const std::string &arg, std::size_t n, const std::string &res)
Create a copy operation.
std::string constant(const std::vector< casadi_int > &v)
Represent an array constant; adding it when new.
void local(const std::string &name, const std::string &type, const std::string &ref="")
Declare a local variable.
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
casadi_int nnz() const
Get the number of (structural) non-zero elements.
static MX zeros(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries zero.
Node class for MX objects.
virtual void serialize_type(SerializingStream &s) const
Serialize type information.
virtual MX get_nzassign(const MX &y, const std::vector< casadi_int > &nz) const
Assign the nonzeros of a matrix to another matrix.
static void copy_rev(bvec_t *arg, bvec_t *res, casadi_int len)
Propagate sparsities backwards through a copy operation.
const Sparsity & sparsity() const
Get the sparsity.
casadi_int nnz(casadi_int i=0) const
bool matches_sparsity(const std::vector< T > &arg) const
virtual void serialize_body(SerializingStream &s) const
Serialize an object without type information.
virtual MX get_project(const Sparsity &sp, bool unique=false) const
Create set sparse.
virtual MX get_nzadd(const MX &y, const std::vector< casadi_int > &nz) const
Add the nonzeros of a matrix to another matrix.
static MX create(MXNode *node)
Create from node.
const Sparsity & sparsity() const
Get the sparsity pattern.
The basic scalar symbolic class of CasADi.
Helper class for Serialization.
void pack(const Sparsity &e)
Serializes an object to the output stream.
int eval_gen(const T **arg, T **res, casadi_int *iw, T *w) const
Evaluate the function (template)
int sp_reverse(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity backwards.
int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity forward.
int eval(const double **arg, double **res, casadi_int *iw, double *w) const override
Evaluate the function numerically.
void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res, const std::vector< bool > &unique={}) const override
Evaluate symbolically (MX)
void serialize_type(SerializingStream &s) const override
Serialize type information.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
bool is_equal(const MXNode *node, casadi_int depth) const override
Check if two nodes are equivalent up to a given depth.
SetNonzerosSlice2(const MX &y, const MX &x, const Slice &inner, const Slice &outer)
Constructor.
int eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w) const override
Evaluate the function symbolically (SX)
std::string disp(const std::vector< std::string > &arg) const override
Print expression.
void generate(CodeGenerator &g, const std::vector< casadi_int > &arg, const std::vector< casadi_int > &res, const std::vector< bool > &arg_is_ref, std::vector< bool > &res_is_ref) const override
Generate code for the operation.
std::string disp(const std::vector< std::string > &arg) const override
Print expression.
void generate(CodeGenerator &g, const std::vector< casadi_int > &arg, const std::vector< casadi_int > &res, const std::vector< bool > &arg_is_ref, std::vector< bool > &res_is_ref) const override
Generate code for the operation.
int eval(const double **arg, double **res, casadi_int *iw, double *w) const override
Evaluate the function numerically.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
int eval_gen(const T **arg, T **res, casadi_int *iw, T *w) const
Evaluate the function (template)
SetNonzerosSlice(const MX &y, const MX &x, const Slice &s)
Constructor.
void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res, const std::vector< bool > &unique={}) const override
Evaluate symbolically (MX)
bool is_equal(const MXNode *node, casadi_int depth) const override
Check if two nodes are equivalent up to a given depth.
int eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w) const override
Evaluate the function symbolically (SX)
int sp_reverse(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity backwards.
void serialize_type(SerializingStream &s) const override
Serialize type information.
int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity forward.
Add the nonzeros of a matrix to another matrix.
SetNonzerosVector(const MX &y, const MX &x, const std::vector< casadi_int > &nz)
Constructor.
bool is_equal(const MXNode *node, casadi_int depth) const override
Check if two nodes are equivalent up to a given depth.
void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res, const std::vector< bool > &unique={}) const override
Evaluate symbolically (MX)
std::vector< casadi_int > nz_
Operation sequence.
int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity forward.
int eval(const double **arg, double **res, casadi_int *iw, double *w) const override
Evaluate the function numerically.
std::string disp(const std::vector< std::string > &arg) const override
Print expression.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
int sp_reverse(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity backwards.
int eval_gen(const T **arg, T **res, casadi_int *iw, T *w) const
Evaluate the function (template)
void serialize_type(SerializingStream &s) const override
Serialize type information.
int eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w) const override
Evaluate the function symbolically (SX)
void generate(CodeGenerator &g, const std::vector< casadi_int > &arg, const std::vector< casadi_int > &res, const std::vector< bool > &arg_is_ref, std::vector< bool > &res_is_ref) const override
Generate code for the operation.
Assign or add entries to a matrix.
void ad_reverse(const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens) const override
Calculate reverse mode directional derivatives.
static MX create(const MX &y, const MX &x, const std::vector< casadi_int > &nz)
Create functions.
void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res, const std::vector< bool > &unique={}) const override
Evaluate symbolically (MX)
void ad_forward(const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens) const override
Calculate forward mode directional derivatives.
SetNonzeros(const MX &y, const MX &x)
Constructor.
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
Matrix< casadi_int > mapping() const override
Get an IM representation of a GetNonzeros or SetNonzeros node.
~SetNonzeros() override=0
Destructor.
Class representing a Slice.
casadi_int stop
stop value: use std::numeric_limits<casadi_int>::max() to indicate unboundedness
casadi_int start
start value: negative values will get added to length
casadi_int get_nz(casadi_int rr, casadi_int cc) const
Get the index of an existing non-zero element.
casadi_int size1() const
Get the number of rows.
std::vector< casadi_int > find(bool ind1=SWIG_IND1) const
Get the location of all non-zero elements as they would appear in a Dense matrix.
Sparsity unite(const Sparsity &y, std::vector< unsigned char > &mapping) const
Union of two sparsity patterns.
std::vector< casadi_int > get_col() const
Get the column for each non-zero entry.
casadi_int nnz() const
Get the number of (structural) non-zeros.
casadi_int size2() const
Get the number of columns.
const casadi_int * row() const
Get a reference to row-vector,.
template class CASADI_EXPORT Matrix< casadi_int >
unsigned long long bvec_t
bool has_negative(const std::vector< T > &v)
Check if the vector has negative entries.
bool CASADI_EXPORT is_slice(const IM &x, bool ind1=false)
Is the IM a Slice.
bool CASADI_EXPORT is_slice2(const std::vector< casadi_int > &v)
Check if an index vector can be represented more efficiently as two nested slices.
bool all(const std::vector< bool > &v)
Check if all arguments are true.
std::pair< Slice, Slice > CASADI_EXPORT to_slice2(const std::vector< casadi_int > &v)
Construct nested slices from an index vector (requires is_slice2(v) to be true)
Slice CASADI_EXPORT to_slice(const IM &x, bool ind1=false)
Convert IM to Slice.