-
Notifications
You must be signed in to change notification settings - Fork 777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
additional sparseJacobian
functions
#610
Conversation
Just my first impression tho, why tag dispatch instead of multiple functions with different names? |
I felt it would be awkward to have names like sparseJacobian() // vector of boost::tuple
sparseJacobian_() // matrix
sparseJacobianEigen_() // Eigen::SparseMatrix
sparseJacobianEigenTriples_() // vector of Eigen::Triple's And figured sparseJacobian <vector<boost::tuple>> ()
sparseJacobian <Matrix> ()
sparseJacobian <Eigen::SparseMatrix> ()
sparseJacobian <vector<Eigen::Triple>> () would be cleaner. But not sure. Ok, Frank - yes I did find compilation times to get way slower on my computer so I will change this. Thx for the tip! |
We also need to make sure to be backward compatible. |
I'm with Fan on this. Will also cause problems with wrapper. (which you have to be aware of) |
@gchenfc ping on this. Please re-request review once comments have been addressed. |
Eigen::SparseMatrix functionality is moved into SparseMatrix.h to isolate large includes. Also, SparseMatrixEigenTriplets is removed because it's not actually useful and is almost identical to SparseMatrixBoostTriplets
I changed the names back, so now the relevant functions are: gfg.sparseJacobian() // vector of boost::tuple
gfg.sparseJacobian_() // matrix
SparseMatrix::JacobianEigen(gfg) // Eigen::SparseMatrix Now I also added additional useful arguments for ordering and dimensions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate you trying to "do the right thing", but it just comes across as heavy handed here, with the class and static methods. This is supposed to be a simple PR, not a heavy handed one :-) I think you should just move the static functions to gfg.cpp, unless there is a good reason.
Light-handed approach philosophy: "Don't build for the future, but the now". The now only needs gfg unit tests and functionality, so this is what this PR should be.
@@ -33,6 +33,8 @@ | |||
#include <boost/tuple/tuple.hpp> | |||
#include <boost/math/special_functions/fpclassify.hpp> | |||
|
|||
#include <vector> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move additions in this file to SparseMatrix.h...
// note: Eigen only supports signed (e.g. not size_t) StorageIndex | ||
typedef Eigen::SparseMatrix<double, Eigen::ColMajor, int> SparseMatrixEigen; | ||
|
||
class GTSAM_EXPORT SparseMatrix { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a class?
|
||
#pragma once | ||
|
||
#include "gtsam/linear/GaussianFactorGraph.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
base cannot know about linear :-/ the directories in GTSAm form a directed graph.
I think all these are utilities for GaussianFactorGraph functions, right? Then why not make them static functions inside GaussianFactorGraph.cpp? Only expose the type (which you exposed in Matrix.h) in the GaussianFactorGraph.h header.
Yes sounds great - I originally wanted to put them in GaussianFactorGraph.cpp but you made an earlier comment that you wanted to avoid that if possible so I tried without, which was very ugly. I knew the extra file was ugly too and I really didn't like it. |
@dellaert To clarify what I assume is your original reasoning for not wanting to place these static functions in GaussianFactorGraph directly, either GaussianFactorGraph.h will have to |
Right. You can add a new file in linear subdirectory that is focused on the Eigen functionality, so we don't include Eigen/Sparse in gfg.h. Given the other utilities, I could see it even be a simple header only file. |
Let’s fix and land? |
Switched to #677 to reduce commit- and diff- pollution |
The primary purpose of this PR is to make a
sparseJacobian
function inGaussianFactorGraph
that returns anEigen::SparseMatrix
. This is useful for interfacing with third-party linear solvers (#111) such as Eigen's sparse factorizer, and CUDA-accelerated linear solvers like SuiteSparse and cuSPARSE.Currently, there are already two functions:
But I would argue that this naming scheme isn't great. Instead, I propose to template the function on the type of output we want. So,
Then it would be used:
That is the gist.
A couple (controversial) implementation details:
sparseJacobian
is actually returning a 3-tuple since I found that the dimensions of the sparse matrix are often useful. An alternative would be passing by ("optional") reference