Skip to content

Commit

Permalink
Avoid transposing J.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Sep 7, 2023
1 parent 9bf29f6 commit 22d2acf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
1 change: 1 addition & 0 deletions nmodl/ode.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def solve_non_lin_system(eq_strings, vars, constants, function_calls):
vecJcode = []
for i, j in itertools.product(range(jacobian.rows), range(jacobian.cols)):
flat_index = i + jacobian.rows * j
flat_index = i*jacobian.cols + j

rhs = sp.ccode(jacobian[i,j].simplify().subs(X_vec_map).evalf(), user_functions=custom_fcts)
vecJcode.append(f"J[{flat_index}] = {rhs}")
Expand Down
8 changes: 1 addition & 7 deletions src/solver/newton/newton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ EIGEN_DEVICE_FUNC int newton_solver(Eigen::Matrix<double, N, 1>& X,
// Vector to store result of function F(X):
Eigen::Matrix<double, N, 1> F;
// Matrix to store jacobian of F(X):
Eigen::Matrix<double, N, N> J;
Eigen::Matrix<double, N, N, Eigen::RowMajor> J;
// Solver iteration count:
int iter = -1;
while (++iter < max_iter) {
Expand All @@ -72,12 +72,6 @@ EIGEN_DEVICE_FUNC int newton_solver(Eigen::Matrix<double, N, 1>& X,
// we have converged: return iteration count
return iter;
}
// In Eigen the default storage order is ColMajor.
// Crout's implementation requires matrices stored in RowMajor order (C-style arrays).
// Therefore, the transposeInPlace is critical such that the data() method to give the rows
// instead of the columns.
if (!J.IsRowMajor)
J.transposeInPlace();
Eigen::Matrix<int, N, 1> pivot;
Eigen::Matrix<double, N, 1> rowmax;
// Check if J is singular
Expand Down

0 comments on commit 22d2acf

Please sign in to comment.