31 casadi_assert(x.
is_column(),
"Dimension mismatch");
32 casadi_assert(y.
is_column(),
"Dimension mismatch");
33 set_dep(A, densify(x), densify(y));
37 std::string
Bilin::disp(
const std::vector<std::string>& arg)
const {
38 return "bilin(" + arg.at(0) +
", " + arg.at(1) +
", " + arg.at(2) +
")";
41 void Bilin::eval_mx(
const std::vector<MX>& arg, std::vector<MX>& res)
const {
42 res[0] = bilin(arg[0], arg[1], arg[2]);
46 std::vector<std::vector<MX> >& fsens)
const {
47 for (casadi_int d=0; d<fsens.size(); ++d) {
49 = bilin(fseed[d][0],
dep(1),
dep(2))
50 + bilin(
dep(0), fseed[d][1],
dep(2))
51 + bilin(
dep(0),
dep(1), fseed[d][2]);
56 std::vector<std::vector<MX> >& asens)
const {
57 for (casadi_int d=0; d<aseed.size(); ++d) {
58 asens[d][0] = rank1(project(asens[d][0],
dep(0).
sparsity()),
59 aseed[d][0],
dep(1),
dep(2));
60 asens[d][1] += aseed[d][0] * mtimes(
dep(0),
dep(2));
61 asens[d][2] += aseed[d][0] * mtimes(
dep(0).
T(),
dep(1));
65 int Bilin::eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const {
66 return eval_gen<double>(arg, res, iw, w);
70 return eval_gen<SXElem>(arg, res, iw, w);
85 casadi_int cc, rr, el;
86 for (cc=0; cc<sp_A.
ncol; ++cc) {
93 r |= arg[1][rr] | arg[0][el] | arg[2][cc];
102 bvec_t s_r=res[0][0]; res[0][0] = 0;
106 casadi_int cc, rr, el;
107 for (cc=0; cc<sp_A.
ncol; ++cc) {
123 const std::vector<casadi_int>& arg,
124 const std::vector<casadi_int>& res,
125 const std::vector<bool>& arg_is_ref,
126 std::vector<bool>& res_is_ref)
const {
127 g << g.
workel(res[0]) <<
" = "
130 g.
work(arg[2],
dep(2).
nnz(), arg_is_ref[2])) <<
";\n";
int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity forward.
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 sp_reverse(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity backwards.
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)
std::string disp(const std::vector< std::string > &arg) const override
Print expression.
int eval(const double **arg, double **res, casadi_int *iw, double *w) const override
Evaluate the function numerically.
Bilin(const MX &A, const MX &x, const MX &y)
Constructor.
void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res) const override
Evaluate symbolically (MX)
int eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w) const override
Evaluate the function symbolically (SX)
void ad_forward(const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens) const override
Calculate forward mode directional derivatives.
Helper class for C code generation.
std::string work(casadi_int n, casadi_int sz, bool is_ref) const
std::string bilin(const std::string &A, const Sparsity &sp_A, const std::string &x, const std::string &y)
Codegen bilinear form.
std::string workel(casadi_int n) const
bool is_column() const
Check if the matrix is a column vector (i.e. size2()==1)
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.
The basic scalar symbolic class of CasADi.
static Sparsity scalar(bool dense_scalar=true)
Create a scalar sparsity pattern *.
unsigned long long bvec_t
T1 casadi_bilin(const T1 *A, const casadi_int *sp_A, const T1 *x, const T1 *y)
Compact representation of a sparsity pattern.
const casadi_int * colind