Skip to content

Commit

Permalink
Move covariance-indexing funcs to the only place they're used.
Browse files Browse the repository at this point in the history
The compound field types that once used these are gone, so the only
place we need them is in the backwards-compatibility reading code.
  • Loading branch information
TallJimbo committed Feb 6, 2021
1 parent edb9d54 commit b73402e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
16 changes: 0 additions & 16 deletions include/lsst/afw/table/FieldBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@ namespace lsst {
namespace afw {
namespace table {

namespace detail {

class TableImpl;

/**
* Defines the ordering of packed covariance matrices.
*
* This storage is equivalent to LAPACK 'UPLO=U'.
*/
inline int indexCovariance(int i, int j) { return (i < j) ? (i + j * (j + 1) / 2) : (j + i * (i + 1) / 2); }

/// Defines the packed size of a covariance matrices.
inline int computeCovariancePackedSize(int size) { return size * (size + 1) / 2; }

} // namespace detail

/**
* Field base class default implementation (used for numeric scalars and lsst::geom::Angle).
*/
Expand Down
20 changes: 17 additions & 3 deletions src/table/io/FitsSchemaInputMapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,20 @@ class CovarianceConversionReader : public FitsColumnReader {
return oldUnits;
}

/**
* Defines the ordering of packed covariance matrices.
*
* This storage is equivalent to LAPACK 'UPLO=U'.
*/
static int indexCovariance(int i, int j) {
return (i < j) ? (i + j * (j + 1) / 2) : (j + i * (i + 1) / 2);
}

/// Defines the packed size of a covariance matrices.
static int computeCovariancePackedSize(int size) {
return size * (size + 1) / 2;
}

static std::unique_ptr<FitsColumnReader> make(Schema &schema, FitsSchemaItem const &item,
std::vector<std::string> const &names) {
return std::unique_ptr<FitsColumnReader>(new CovarianceConversionReader(schema, item, names));
Expand All @@ -605,14 +619,14 @@ class CovarianceConversionReader : public FitsColumnReader {
: _column(item.column),
_size(names.size()),
_key(CovarianceMatrixKey<T, N>::addFields(schema, item.ttype, names, guessUnits(item.tunit))),
_buffer(new T[detail::computeCovariancePackedSize(names.size())]) {}
_buffer(new T[computeCovariancePackedSize(names.size())]) {}

void readCell(BaseRecord &record, std::size_t row, afw::fits::Fits &fits,
std::shared_ptr<InputArchive> const &archive) const override {
fits.readTableArray(row, _column, detail::computeCovariancePackedSize(_size), _buffer.get());
fits.readTableArray(row, _column, computeCovariancePackedSize(_size), _buffer.get());
for (int i = 0; i < _size; ++i) {
for (int j = i; j < _size; ++j) {
_key.setElement(record, i, j, _buffer[detail::indexCovariance(i, j)]);
_key.setElement(record, i, j, _buffer[indexCovariance(i, j)]);
}
}
}
Expand Down

0 comments on commit b73402e

Please sign in to comment.