-
Notifications
You must be signed in to change notification settings - Fork 8
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
DM-14725: Eliminate explicit use of ndarray::EigenView in C++ code #58
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,22 +283,24 @@ class ProfileObjective : public OptimizerObjective { | |
Scalar oAlpha = parameters[1] * _normalization; | ||
Scalar iR2 = parameters[2] * parameters[2]; | ||
Scalar oR2 = parameters[3] * parameters[3]; | ||
residuals.asEigen<Eigen::ArrayXpr>() = _data | ||
- (iAlpha/iR2)*(_arg/iR2).exp() | ||
- (oAlpha/oR2)*(_arg/oR2).exp(); | ||
auto argEigen = _arg.asEigen<Eigen::ArrayXpr>(); | ||
residuals.asEigen<Eigen::ArrayXpr>() = _data.asEigen<Eigen::ArrayXpr>() | ||
- (iAlpha/iR2)*(argEigen/iR2).exp() | ||
- (oAlpha/oR2)*(argEigen/oR2).exp(); | ||
} | ||
|
||
virtual bool differentiateResiduals( | ||
ndarray::Array<Scalar const,1,1> const & parameters, | ||
ndarray::Array<Scalar,2,-2> const & derivatives | ||
) const { | ||
ndarray::EigenView<Scalar,2,-2,Eigen::ArrayXpr> d(derivatives); | ||
auto d = derivatives.asEigen<Eigen::ArrayXpr>(); | ||
auto argEigen = _arg.asEigen<Eigen::ArrayXpr>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You end up doing these conversions a lot. Consider using private getters or simply letting the types of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The plan is as follows: add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does that reduce the code duplication of translating |
||
Scalar iR2 = parameters[2] * parameters[2]; | ||
Scalar oR2 = parameters[3] * parameters[3]; | ||
d.col(0) = - (_normalization/iR2)*(_arg/iR2).exp(); | ||
d.col(1) = - (_normalization/oR2)*(_arg/oR2).exp(); | ||
d.col(2) = -2.0*d.col(0)*(_arg/iR2 + 1.0)*parameters[0]/parameters[2]; | ||
d.col(3) = -2.0*d.col(1)*(_arg/oR2 + 1.0)*parameters[1]/parameters[3]; | ||
d.col(0) = - (_normalization/iR2)*(argEigen/iR2).exp(); | ||
d.col(1) = - (_normalization/oR2)*(argEigen/oR2).exp(); | ||
d.col(2) = -2.0*d.col(0)*(argEigen/iR2 + 1.0)*parameters[0]/parameters[2]; | ||
d.col(3) = -2.0*d.col(1)*(argEigen/oR2 + 1.0)*parameters[1]/parameters[3]; | ||
return true; | ||
} | ||
|
||
|
@@ -325,8 +327,8 @@ class ProfileObjective : public OptimizerObjective { | |
Scalar _maxRadius; | ||
Scalar _minRadiusDiff; | ||
Scalar _normalization; | ||
ndarray::EigenView<Scalar,1,1,Eigen::ArrayXpr> _data; | ||
ndarray::EigenView<Scalar,1,1,Eigen::ArrayXpr> _arg; | ||
ndarray::Array<Scalar,1,1> _data; // ArrayXpr | ||
ndarray::Array<Scalar,1,1> _arg; // ArrayXpr | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand these comments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think they were placeholders. I'll remove them on DM-14625 (since I jumped the gun and merged this branch before I realized you had any suggested changes). |
||
}; | ||
|
||
} // anonymous | ||
|
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.
👍 for separation of interface and implementation.