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-32662: rework catalog column array access to improve type dispatch performance #618

Merged
merged 13 commits into from
Dec 15, 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
35 changes: 25 additions & 10 deletions include/lsst/afw/table/BaseColumnView.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define AFW_TABLE_BaseColumnView_h_INCLUDED

#include <cstdint>
#include <optional>

#include "lsst/afw/table/BaseTable.h"

Expand Down Expand Up @@ -96,6 +97,9 @@ class BaseColumnView {
template <typename T>
ndarray::ArrayRef<T, 2, 1> const operator[](Key<Array<T> > const& key) const;

/// Return a 1-d array of radians for an Angle field.
ndarray::ArrayRef<double, 1> const radians(Key<Angle> const & key) const;

/**
* Return a 1-d array expression corresponding to a flag bit.
*
Expand Down Expand Up @@ -129,12 +133,16 @@ class BaseColumnView {
/**
* Construct a BaseColumnView from an iterator range.
*
* The iterators must dereference to a reference or const reference to a record.
* If the record data is not contiguous in memory, throws lsst::pex::exceptions::RuntimeError.
* The iterators must dereference to a reference or const reference to a
* record. If the record data is not contiguous in memory, returns an
* empty optional.
*/
template <typename InputIterator>
static BaseColumnView make(std::shared_ptr<BaseTable> const& table, InputIterator first,
InputIterator last);
static std::optional<BaseColumnView> make(
std::shared_ptr<BaseTable> const& table,
InputIterator first,
InputIterator last
);

/**
* @brief Return true if the given record iterator range is continuous and the records all belong
Expand Down Expand Up @@ -179,8 +187,13 @@ class ColumnViewT : public BaseColumnView {

/// @copydoc BaseColumnView::make
template <typename InputIterator>
static ColumnViewT make(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last) {
return ColumnViewT(BaseColumnView::make(table, first, last));
static std::optional<ColumnViewT> make(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last) {
auto base = BaseColumnView::make(table, first, last);
if (base) {
return ColumnViewT(base.value());
} else {
return std::nullopt;
}
}

ColumnViewT(ColumnViewT const&) = default;
Expand All @@ -194,8 +207,11 @@ class ColumnViewT : public BaseColumnView {
};

template <typename InputIterator>
BaseColumnView BaseColumnView::make(std::shared_ptr<BaseTable> const& table, InputIterator first,
InputIterator last) {
std::optional<BaseColumnView> BaseColumnView::make(
std::shared_ptr<BaseTable> const& table,
InputIterator first,
InputIterator last
) {
if (first == last) {
return BaseColumnView(table, 0, nullptr, ndarray::Manager::Ptr());
}
Expand All @@ -207,8 +223,7 @@ BaseColumnView BaseColumnView::make(std::shared_ptr<BaseTable> const& table, Inp
char* expected = reinterpret_cast<char*>(buf) + recordSize;
for (++first; first != last; ++first, ++recordCount, expected += recordSize) {
if (first->_data != expected || first->_manager != manager) {
throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
"Record data is not contiguous in memory.");
return std::nullopt;
}
}
return BaseColumnView(table, recordCount, buf, manager);
Expand Down