-
Notifications
You must be signed in to change notification settings - Fork 118
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
treeset: use eigen instead of sparse13 #2643
Conversation
✔️ 5c5c730 -> Azure artifacts URL |
✔️ 29c58af -> Azure artifacts URL |
✔️ 6ce1dcb -> Azure artifacts URL |
This comment has been minimized.
This comment has been minimized.
Quality Gate passedThe SonarCloud Quality Gate passed, but some issues were introduced. 6 New issues |
This comment has been minimized.
This comment has been minimized.
✔️ 68dca39 -> Azure artifacts URL |
This comment has been minimized.
This comment has been minimized.
68dca39
to
8794fda
Compare
✔️ d52b91e -> Azure artifacts URL |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
src/nrniv/matrixmap.cpp
Outdated
@@ -54,7 +55,11 @@ void MatrixMap::alloc(int start, int nnode, Node** nodes, int* layer) { | |||
} else { | |||
jt = start + j - nnode; | |||
} | |||
ptree_[plen_] = spGetElement(_nt->_sp13mat, it, jt); | |||
if (it == 0 || jt == 0) { | |||
ptree_[plen_] = &place_holder; |
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.
This is a joke of sparse13
I can explain that (this is funny)
spPrint(_nt->_sp13mat, 1, 0, 1); | ||
std::cout << &_nt->_sparseMat << std::endl; | ||
} else { | ||
int i, n = spGetSize(_nt->_sp13mat, 0); | ||
spPrint(_nt->_sp13mat, 1, 1, 1); | ||
for (i = 1; i <= n; ++i) { | ||
std::cout << &_nt->_sparseMat << std::endl; | ||
int n = _nt->_sparseMat->cols(); | ||
for (int i = 1; i <= n; ++i) { |
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.
What should we do about that? I'm for removing...
namespace Eigen { | ||
template <typename _Scalar, int _Options, typename _StorageIndex> | ||
class 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.
This file is installed and use, so if we include <Eigen>
we need to install Eigen
header too...
void* _vcv; /* replaces old cvode_instance and nrn_cvode_ */ | ||
double* _sparse_rhs; /* rhs matrix for sparse13 solver. updates to and from this vector | ||
need to be transfered to actual_rhs */ | ||
Eigen::SparseMatrix<double, 1, int>* _sparseMat{}; /* handle to general sparse matrix */ |
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.
We give number otherwise we have to declare the enum behind the option and I have no idea how to do that without conflict at resolution...
spSolve(_nt->_sp13mat, _nt->_sp13_rhs, _nt->_sp13_rhs); | ||
_nt->_sparseMat->makeCompressed(); | ||
Eigen::SparseLU<Eigen::SparseMatrix<double, Eigen::RowMajor>> lu(*_nt->_sparseMat); | ||
Eigen::Map<Eigen::VectorXd> rhs(_nt->_sparse_rhs + 1, _nt->_sparseMat->cols()); |
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.
other joke of sparse13
the matrix is 1-indexed so we use the vector off by one.
Eigen::SparseMatrix<double, Eigen::RowMajor>& m_ = *_nt->_sparseMat; | ||
for (int k = 0; k < m_.outerSize(); ++k) { | ||
for (Eigen::SparseMatrix<double, Eigen::RowMajor>::InnerIterator it(m_, k); it; ++it) { | ||
it.valueRef() = 0.; | ||
} | ||
} |
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.
An other funny joke of sparse13
the function spClear
just reset all pre-declared number to 0 instead of removing them (it should be like that because this is a sparse matrix...).
src/nrnoc/treeset.cpp
Outdated
const Node* nd = nt->_v_node[in]; | ||
const Extnode* nde = nd->extnode; | ||
const Node* pnd = nt->_v_parent[in]; | ||
int i = nd->eqn_index_; | ||
nt->_sparseMat->coeffRef(i - 1, i - 1) = 0.; | ||
if (nde) { | ||
for (int ie = 0; ie < nlayer; ++ie) { | ||
int k = i + ie + 1; | ||
nt->_sparseMat->coeffRef(k - 1, k - 1) = 0.; | ||
nt->_sparseMat->coeffRef(k - 1, k - 2) = 0; | ||
nt->_sparseMat->coeffRef(k - 2, k - 1) = 0; | ||
} | ||
} | ||
if (pnd) { | ||
int j = pnd->eqn_index_; | ||
nt->_sparseMat->coeffRef(j - 1, i - 1); | ||
nt->_sparseMat->coeffRef(i - 1, j - 1); | ||
if (nde && pnd->extnode) | ||
for (int ie = 0; ie < nlayer; ++ie) { | ||
int kp = j + ie + 1; | ||
int k = i + ie + 1; | ||
nt->_sparseMat->coeffRef(kp - 1, k - 1) = 0; | ||
nt->_sparseMat->coeffRef(k - 1, kp - 1) = 0; | ||
} | ||
} | ||
} | ||
// nt->_sparseMat->makeCompressed(); | ||
for (in = 0; in < nt->end; ++in) { |
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.
This is a copy of the code below for allocating values.
sparse13
is more or less a linked list of single value so when we get pointer afterward they are stable.
Eigen
is a kind of vector of values. So can be reallocate. So we reserve all the values rights now and get the pointer afterward.
✔️ 61aca57 -> Azure artifacts URL |
This comment has been minimized.
This comment has been minimized.
✔️ 846364d -> Azure artifacts URL |
This comment has been minimized.
This comment has been minimized.
✔️ f4bc02d -> Azure artifacts URL |
3a12308
to
f4bc02d
Compare
✔️ f4bc02d -> Azure artifacts URL |
This comment has been minimized.
This comment has been minimized.
Please retry analysis of this Pull-Request directly on SonarCloud |
✔️ e1df5f2 -> Azure artifacts URL |
This comment has been minimized.
This comment has been minimized.
Quality Gate passedIssues Measures |
✔️ 6b411b6 -> Azure artifacts URL |
Superseeded by #3142 |
No description provided.