All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
tcrossprod.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_REV_MAT_FUN_TCROSSPROD_HPP
#define STAN_MATH_REV_MAT_FUN_TCROSSPROD_HPP
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/fun/typedefs.hpp>
#include <stan/math/rev/core.hpp>
#include <stan/math/rev/mat/fun/Eigen_NumTraits.hpp>
#include <stan/math/rev/mat/fun/typedefs.hpp>
#include <stan/math/rev/mat/fun/dot_product.hpp>
#include <stan/math/rev/mat/fun/dot_self.hpp>
#include <stan/math/rev/mat/fun/columns_dot_self.hpp>
#include <boost/math/tools/promotion.hpp>
#include <vector>
namespace stan {
namespace math {
inline matrix_v
tcrossprod(const matrix_v& M) {
if (M.rows() == 0)
return matrix_v(0, 0);
// if (M.rows() == 1)
// return M * M.transpose();
// WAS JUST THIS
// matrix_v result(M.rows(), M.rows());
// return result.setZero().selfadjointView<Eigen::Upper>().rankUpdate(M);
matrix_v MMt(M.rows(), M.rows());
vari** vs
= reinterpret_cast< vari**>(ChainableStack::memalloc_
.alloc((M.rows() * M.cols())
* sizeof(vari*)));
int pos = 0;
for (int m = 0; m < M.rows(); ++m)
for (int n = 0; n < M.cols(); ++n)
vs[pos++] = M(m, n).vi_;
for (int m = 0; m < M.rows(); ++m)
MMt(m, m) = var(new dot_self_vari(vs + m * M.cols(), M.cols()));
for (int m = 0; m < M.rows(); ++m) {
for (int n = 0; n < m; ++n) {
MMt(m, n) = var(new dot_product_vari<var, var>(vs + m * M.cols(),
vs + n * M.cols(),
M.cols()));
MMt(n, m) = MMt(m, n);
}
}
return MMt;
}
}
}
#endif
core.hpp
Eigen_NumTraits.hpp
stan::math::AutodiffStackStorage::memalloc_
static stack_alloc memalloc_
Definition: autodiffstackstorage.hpp:16
stan::math::vari
The variable implementation base class.
Definition: vari.hpp:28
stan::math::tcrossprod
Eigen::Matrix< fvar< T >, R, R > tcrossprod(const Eigen::Matrix< fvar< T >, R, C > &m)
Definition: tcrossprod.hpp:17
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
columns_dot_self.hpp
stan::math::matrix_v
Eigen::Matrix< var, Eigen::Dynamic, Eigen::Dynamic > matrix_v
The type of a matrix holding stan::math::var values.
Definition: typedefs.hpp:21
dot_self.hpp
typedefs.hpp
dot_product.hpp
Eigen.hpp
stan::math::stack_alloc::alloc
void * alloc(size_t len)
Return a newly allocated block of memory of the appropriate size managed by the stack allocator...
Definition: stack_alloc.hpp:170
typedefs.hpp

[ Stan Home Page ] © 2011–2015, Stan Development Team.