34 std::string
Rank1::disp(
const std::vector<std::string>& arg)
const {
35 return "rank1(" + arg.at(0) +
", " + arg.at(1)
36 +
", " + arg.at(2) +
", " + arg.at(3) +
")";
39 void Rank1::eval_mx(
const std::vector<MX>& arg, std::vector<MX>& res)
const {
40 res[0] = rank1(arg[0], arg[1], arg[2], arg[3]);
44 std::vector<std::vector<MX> >& fsens)
const {
45 for (casadi_int d=0; d<fsens.size(); ++d) {
47 v = rank1(v, fseed[d][1],
dep(2),
dep(3));
48 v = rank1(v,
dep(1), fseed[d][2],
dep(3));
49 v = rank1(v,
dep(1),
dep(2), fseed[d][3]);
55 std::vector<std::vector<MX> >& asens)
const {
56 for (casadi_int d=0; d<aseed.size(); ++d) {
57 asens[d][1] += bilin(aseed[d][0],
dep(2),
dep(3));
58 asens[d][2] +=
dep(1) * mtimes(aseed[d][0],
dep(3));
59 asens[d][3] +=
dep(1) * mtimes(aseed[d][0].
T(),
dep(2));
60 asens[d][0] += aseed[d][0];
64 int Rank1::eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
65 return eval_gen<double>(arg, res, iw, w);
69 return eval_gen<SXElem>(arg, res, iw, w);
81 if (arg[0]!=res[0]) std::copy(arg[0], arg[0]+
dep(0).
nnz(), res[0]);
88 casadi_int cc, rr, el;
89 for (cc=0; cc<ncol_A; ++cc) {
91 for (el=colind_A[cc]; el<colind_A[cc+1]; ++el) {
96 res[0][el] |= *arg[1] | arg[2][rr] | arg[3][cc];
108 casadi_int cc, rr, el;
109 for (cc=0; cc<ncol_A; ++cc) {
111 for (el=colind_A[cc]; el<colind_A[cc+1]; ++el) {
116 *arg[1] |= res[0][el];
117 arg[2][rr] |= res[0][el];
118 arg[3][cc] |= res[0][el];
128 const std::vector<casadi_int>& arg,
129 const std::vector<casadi_int>& res,
130 const std::vector<bool>& arg_is_ref,
131 std::vector<bool>& res_is_ref)
const {
133 if (arg[0]!=res[0] || arg_is_ref[0]) {
136 g.
work(res[0],
nnz(),
false)) <<
"\n";
140 std::string a = g.
work(res[0],
dep(0).
nnz(),
false);
141 std::string b = g.
work(arg[2],
dep(2).
nnz(), arg_is_ref[2]);
142 std::string c = g.
work(arg[3],
dep(3).
nnz(), arg_is_ref[3]);
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 rank1(const std::string &A, const Sparsity &sp_A, const std::string &alpha, const std::string &x, const std::string &y)
Rank-1 update.
std::string workel(casadi_int n) const
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
const MX & dep(casadi_int ind=0) const
dependencies - functions that have to be evaluated before this one
void set_sparsity(const Sparsity &sparsity)
Set the sparsity.
void set_dep(const MX &dep)
Set unary dependency.
const Sparsity & sparsity() const
Get the sparsity pattern.
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_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w) const override
Evaluate the function symbolically (SX)
int eval(const double **arg, double **res, casadi_int *iw, double *w) const override
Evaluate the function numerically.
void ad_forward(const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens) const override
Calculate forward mode directional derivatives.
int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity forward.
void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res) const override
Evaluate symbolically (MX)
std::string disp(const std::vector< std::string > &arg) const override
Print expression.
int sp_reverse(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity backwards.
Rank1(const MX &A, const MX &alpha, const MX &x, const MX &y)
Constructor.
void ad_reverse(const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens) const override
Calculate reverse mode directional derivatives.
int eval_gen(const T **arg, T **res, casadi_int *iw, T *w) const
Evaluate the function (template)
The basic scalar symbolic class of CasADi.
casadi_int size2() const
Get the number of columns.
const casadi_int * row() const
Get a reference to row-vector,.
const casadi_int * colind() const
Get a reference to the colindex of all column element (see class description)
unsigned long long bvec_t
void casadi_copy(const T1 *x, casadi_int n, T1 *y)
COPY: y <-x.
void casadi_rank1(T1 *A, const casadi_int *sp_A, T1 alpha, const T1 *x)
Adds a multiple alpha/2 of the outer product mul(x, trans(x)) to A.