26 #include "transpose.hpp" 
   27 #include "serializing_stream.hpp" 
   38     s.
pack(
"Transpose::dense", 
false);
 
   43     s.
pack(
"Transpose::dense", 
true);
 
   48     s.
unpack(
"Transpose::dense", t);
 
   56   int Transpose::eval(
const double** arg, 
double** res, casadi_int* iw, 
double* w)
 const {
 
   57     return eval_gen<double>(arg, res, iw, w);
 
   61     return eval_gen<double>(arg, res, iw, w);
 
   66     return eval_gen<SXElem>(arg, res, iw, w);
 
   71     return eval_gen<SXElem>(arg, res, iw, w);
 
   76                           casadi_int* iw, T* w)
 const {
 
   79     const casadi_int* x_row = 
dep(0).
row();
 
   80     casadi_int x_sz = 
dep(0).
nnz();
 
   88     std::copy(xT_colind, xT_colind+xT_ncol+1, iw);
 
   89     for (casadi_int el=0; el<x_sz; ++el) {
 
   90       xT[iw[x_row[el]]++] = x[el];
 
   97                                casadi_int* iw, T* w)
 const {
 
  104     for (casadi_int i=0; i<x_ncol; ++i) {
 
  105       for (casadi_int j=0; j<x_nrow; ++j) {
 
  106         xT[i+j*x_ncol] = x[j+i*x_nrow];
 
  119     casadi_int nz = 
nnz();
 
  120     const casadi_int* x_row = 
dep().
row();
 
  125     std::copy(xT_colind, xT_colind+xT_ncol+1, iw);
 
  126     for (casadi_int el=0; el<nz; ++el) {
 
  127       xT[iw[*x_row++]++] = *x++;
 
  139     casadi_int nz = 
nnz();
 
  140     const casadi_int* x_row = 
dep().
row();
 
  145     std::copy(xT_colind, xT_colind+xT_ncol+1, iw);
 
  146     for (casadi_int el=0; el<nz; ++el) {
 
  147       casadi_int elT = iw[*x_row++]++;
 
  163     for (casadi_int rr=0; rr<x_nrow; ++rr) {
 
  164       for (casadi_int cc=0; cc<x_ncol; ++cc) {
 
  165         *xT++ = x[rr+cc*x_nrow];
 
  180     for (casadi_int rr=0; rr<x_nrow; ++rr) {
 
  181       for (casadi_int cc=0; cc<x_ncol; ++cc) {
 
  182         x[rr+cc*x_nrow] |= *xT;
 
  190     return arg.at(0) + 
"'";
 
  198                           std::vector<std::vector<MX> >& fsens)
 const {
 
  199     for (casadi_int d=0; d<fsens.size(); ++d) {
 
  200       fsens[d][0] = fseed[d][0].T();
 
  205                           std::vector<std::vector<MX> >& asens)
 const {
 
  206     for (casadi_int d=0; d<aseed.size(); ++d) {
 
  207       asens[d][0] += aseed[d][0].T();
 
  212                             const std::vector<casadi_int>& arg,
 
  213                             const std::vector<casadi_int>& res,
 
  214                             const std::vector<bool>& arg_is_ref,
 
  215                             std::vector<bool>& res_is_ref)
 const {
 
  221                                 const std::vector<casadi_int>& arg,
 
  222                                 const std::vector<casadi_int>& res,
 
  223                                 const std::vector<bool>& arg_is_ref,
 
  224                                 std::vector<bool>& res_is_ref)
 const {
 
  225     g.
local(
"cs", 
"const casadi_real", 
"*");
 
  226     g.
local(
"rr", 
"casadi_real", 
"*");
 
  227     g.
local(
"i", 
"casadi_int");
 
  228     g.
local(
"j", 
"casadi_int");
 
  229     g << 
"for (i=0, rr=" << g.
work(res[0], 
nnz(), 
false) << 
", " 
  230       << 
"cs=" << g.
work(arg[0], 
nnz(), arg_is_ref[0]) << 
"; i<" << 
dep().
size2() << 
"; ++i) " 
  231       << 
"for (j=0; j<" << 
dep().
size1() << 
"; ++j) " 
  232       << 
"rr[i+j*" << 
dep().
size2() << 
"] = *cs++;\n";
 
Helper class for C code generation.
std::string work(casadi_int n, casadi_int sz, bool is_ref) const
void local(const std::string &name, const std::string &type, const std::string &ref="")
Declare a local variable.
std::string trans(const std::string &x, const Sparsity &sp_x, const std::string &y, const Sparsity &sp_y, const std::string &iw)
Transpose.
int eval(const double **arg, double **res, casadi_int *iw, double *w) const override
Evaluate the function numerically.
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.
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.
int eval_gen(const T *const *arg, T *const *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.
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.
casadi_int size2() const
Get the second dimension (i.e. number of columns)
casadi_int size1() const
Get the first dimension (i.e. number of rows)
const casadi_int * row() const
Get the sparsity pattern. See the Sparsity class for details.
Node class for MX objects.
virtual void serialize_type(SerializingStream &s) const
Serialize type information.
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.
Helper class for Serialization.
void pack(const Sparsity &e)
Serializes an object to the output stream.
Sparsity T() const
Transpose the matrix.
casadi_int size2() const
Get the number of columns.
const casadi_int * colind() const
Get a reference to the colindex of all column element (see class description)
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 eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w) const override
Evaluate the function symbolically (SX)
int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity forward.
int eval_gen(const T *const *arg, T *const *res, casadi_int *iw, T *w) const
Evaluate the function (template)
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.
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
Transpose(const MX &x)
Constructor.
int sp_reverse(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const override
Propagate sparsity backwards.
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.
void ad_reverse(const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens) const override
Calculate reverse mode directional derivatives.
void serialize_type(SerializingStream &s) const override
Serialize type information.
unsigned long long bvec_t