Moby
SparseJacobian.h
1 /****************************************************************************
2  * Copyright 2015 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0
4  * License (obtainable from http://www.apache.org/licenses/LICENSE-2.0).
5  ****************************************************************************/
6 
7 #ifndef _SPARSE_JACOBIAN_H
8 #define _SPARSE_JACOBIAN_H
9 
10 #include <pthread.h>
11 #include <vector>
12 #include <Ravelin/MatrixNd.h>
13 
14 namespace Moby {
15 
17 
22 {
23  unsigned st_col_idx, st_row_idx;
24  unsigned rows() const { return block.rows(); }
25  unsigned columns() const { return block.columns(); }
26  Ravelin::MatrixNd block;
27 };
28 
31 {
32  public:
33  SparseJacobian() { rows = cols = 0; }
34  Ravelin::VectorNd& mult(const Ravelin::VectorNd& x, Ravelin::VectorNd& result) const;
35  Ravelin::MatrixNd& mult(const Ravelin::MatrixNd& x, Ravelin::MatrixNd& result) const;
36  Ravelin::MatrixNd& transpose_mult(const Ravelin::MatrixNd& x, Ravelin::MatrixNd& result) const;
37  Ravelin::MatrixNd& mult(const std::vector<MatrixBlock>& M, unsigned result_cols, Ravelin::MatrixNd& result) const;
38  Ravelin::MatrixNd& mult(const std::vector<Ravelin::MatrixNd>& M, Ravelin::MatrixNd& result) const;
39  Ravelin::MatrixNd& mult_transpose(const SparseJacobian& M, Ravelin::MatrixNd& result) const;
40  Ravelin::MatrixNd& to_dense(Ravelin::MatrixNd& M) const;
41 
42  // vector of Jacobian blocks
43  std::vector<MatrixBlock> blocks;
44 
45  // the number of rows and columns in the dense Jacobian
46  unsigned rows, cols;
47 };
48 
49 } // end namespace
50 #endif
51 
A Sparse Jacobian representation along with multiplication routines.
Definition: SparseJacobian.h:30
Ravelin::MatrixNd & transpose_mult(const Ravelin::MatrixNd &x, Ravelin::MatrixNd &result) const
Multiplies the transpose of this sparse Jacobian by a matrix.
Definition: SparseJacobian.cpp:83
Matrix block.
Definition: SparseJacobian.h:21
Ravelin::MatrixNd & to_dense(Ravelin::MatrixNd &M) const
Converts a sparse Jacobian to a dense matrix (for debugging purposes)
Definition: SparseJacobian.cpp:305
Ravelin::MatrixNd & mult_transpose(const SparseJacobian &M, Ravelin::MatrixNd &result) const
Multiples this sparse Jacobian by the transpose of another sparse Jacobian.
Definition: SparseJacobian.cpp:120