-
Notifications
You must be signed in to change notification settings - Fork 7
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-10227: Replace raw arrays with std::vector #217
Changes from 1 commit
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 |
---|---|---|
|
@@ -23,7 +23,6 @@ | |
*/ | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
#include <iomanip> | ||
|
||
#include "lsst/jointcal/AstrometryTransform.h" | ||
|
@@ -65,10 +64,10 @@ std::ostream &operator<<(std::ostream &stream, const StarMatchList &starMatchLis | |
return stream; | ||
} | ||
|
||
static std::unique_ptr<double[]> chi2_array(const StarMatchList &starMatchList, | ||
static std::vector<double> chi2_array(const StarMatchList &starMatchList, | ||
const AstrometryTransform &transform) { | ||
unsigned s = starMatchList.size(); | ||
auto res = std::unique_ptr<double[]>(new double[s]); | ||
std::vector<double> res(s,0.); | ||
unsigned count = 0; | ||
for (auto const &it : starMatchList) res[count++] = it.computeChi2(transform); | ||
return res; | ||
|
@@ -116,12 +115,12 @@ void StarMatchList::refineTransform(double nSigmas) { | |
if (npair == 0) break; // should never happen | ||
|
||
// compute some chi2 statistics | ||
std::unique_ptr<double[]> chi2_array(new double[npair]); | ||
std::vector<double> chi2_array(npair); | ||
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. Make this 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. Done. Also use ranged based loop. |
||
unsigned count = 0; | ||
for (auto &starMatch : *this) | ||
chi2_array[count++] = starMatch.chi2 = starMatch.computeChi2(*_transform); | ||
|
||
std::sort(chi2_array.get(), chi2_array.get() + npair); | ||
std::sort(chi2_array.begin(), chi2_array.end()); | ||
double median = (npair & 1) ? chi2_array[npair / 2] | ||
: (chi2_array[npair / 2 - 1] + chi2_array[npair / 2]) * 0.5; | ||
|
||
|
@@ -245,7 +244,7 @@ double computeDist2(const StarMatchList &starMatchList, const AstrometryTransfor | |
|
||
double computeChi2(const StarMatchList &starMatchList, const AstrometryTransform &transform) { | ||
unsigned s = starMatchList.size(); | ||
std::unique_ptr<double[]> chi2s(chi2_array(starMatchList, transform)); | ||
std::vector<double> chi2s(chi2_array(starMatchList, transform)); | ||
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. Worth making this |
||
double chi2 = 0; | ||
for (unsigned k = 0; k < s; ++k) chi2 += chi2s[k]; | ||
return chi2; | ||
|
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.
While we're at it, lets replace
res
->result
ands
->size
.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.
Done.
std::vector<double> result
also does not need to be default intialized