Skip to content
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-30883: Incorrect triplet initialization can result in crash #185

Merged
merged 3 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions include/lsst/jointcal/Associations.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class Associations {
Point getCommonTangentPoint() const { return _commonTangentPoint; }
///@}

/// The number of MeasuredStars at the start of fitting, before any outliers are removed.
size_t getMaxMeasuredStars() const { return _maxMeasuredStars; }

/**
Expand Down
6 changes: 5 additions & 1 deletion include/lsst/jointcal/FittedStar.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ class FittedStar : public BaseStar {
stream << " mcount: " << _measurementCount;
}

//!
/**
* The number of MeasuredStars currently associated with this FittedStar.
*/
///@{
int getMeasurementCount() const { return _measurementCount; }
int& getMeasurementCount() { return _measurementCount; }
///@}

/// Add a measuredStar on-sky magnitude.
void addMagMeasurement(double magValue, double magWeight);
Expand Down
2 changes: 1 addition & 1 deletion include/lsst/jointcal/Tripletlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef Eigen::Triplet<double> Trip;
// it would be wise to implement it differently if talking to cholmod
class TripletList : public std::vector<Trip> {
public:
TripletList(int count) : _nextFreeIndex(0) { reserve(count); };
TripletList(std::size_t count) : _nextFreeIndex(0) { reserve(count); };

void addTriplet(Eigen::Index i, Eigen::Index j, double val) {
push_back(Trip(i, j, val));
Expand Down
7 changes: 5 additions & 2 deletions src/FitterBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,11 @@ MinimizeResult FitterBase::minimize(std::string const &whatToFit, double nSigmaC

MinimizeResult returnCode = MinimizeResult::Converged;

// TODO : write a guesser for the number of triplets
std::size_t nTrip = (_lastNTrip) ? _lastNTrip : 1e6;
// For the initial vector size, use all measured stars + all fitted stars, which should give the
// maximum possible number of triplets.
std::size_t nTrip = (_lastNTrip)
? _lastNTrip
: _associations->getMaxMeasuredStars() + _associations->fittedStarList.size();
TripletList tripletList(nTrip);
Eigen::VectorXd grad(_nTotal);
grad.setZero();
Expand Down