From 63ac33bff34176fb1ec159ff7e2716bb2b6bf061 Mon Sep 17 00:00:00 2001 From: "Brendan K. Krueger" Date: Tue, 3 Sep 2024 08:55:25 -0600 Subject: [PATCH] Notes --- spiner/databox_wrapper.hpp | 107 +++++++++++++++++++++++++++++++------ 1 file changed, 90 insertions(+), 17 deletions(-) diff --git a/spiner/databox_wrapper.hpp b/spiner/databox_wrapper.hpp index 375d1d622..aba41cce8 100644 --- a/spiner/databox_wrapper.hpp +++ b/spiner/databox_wrapper.hpp @@ -1,16 +1,90 @@ -#ifndef SINGE_UTIL_DATABOXWRAPPER_HPP -#define SINGE_UTIL_DATABOXWRAPPER_HPP +#ifndef _SPINER_DATABOXWRAPPER_HPP_ +#define _SPINER_DATABOXWRAPPER_HPP_ -#include "singe/util/databox.hpp" -#include "singe/util/portability_macros.hpp" +#include "databox.hpp" + +#include "ports-of-call//portability.hpp" #include -namespace singe { -namespace util { +namespace Spiner { // ================================================================================================ +// The original use-case did three things: +// * Add transformations of the data. This was originally hard-coded, but we'll make it general. +// * Add extrapolations off the edge of the table. +// * Adapt the interface. We should instead follow the Databox interface. +// * DataBox() = default; +// * DataBox(T * data, Args... args) noexcept; +// * DataBox(AllocationTarget t, Args... args) noexcept; +// * DataBox(Args... args) noexcept; +// * DataBox(PortableMDArray A) noexcept; +// * DataBox(PortableMDArray& A) noexcept; +// * DataBox(const DataBox& src) noexcept; +// * DataBox(const DataBox& b, const int dim, const int indx, const int nvar) noexcept +// #ifdef SPINER_USE_HDF +// * DataBox(const std::string& filename); +// * DataBox(hid_t loc, const std::string& groupname); +// #endif // SPINER_USE_HDF +// * void setArray(PortableMDArray& A); +// * void resize(AllocationTarget t, Args... args); +// * void resize(Args... args); +// * T& operator()(Args... args); +// * T& operator()(Args... args) const; +// * DataBox slice(const int dim, const int indx, const int nvar) const; +// * DataBox slice(const int indx) const; +// * DataBox slice(const int ix2, const int ix1) const; +// * void reshape(Args... args); +// * T interpToReal(const T x) const noexcept; +// * T interpToReal(const T x2, const T x1) const noexcept; +// * T interpToReal(const T x3, const T x2, const T x1) const noexcept; +// * T interpToReal(const T x4, const T x3, const T x2, const T x1) const noexcept; +// * void interpFromDB(const DataBox& db, const T x); +// * void interpFromDB(const DataBox& db, const T x2, const T x1); +// * DataBox interpToDB(Args... args); +// * void setIndexType(int i, IndexType t); +// * void setRange(int i, Grid_t g); +// * void setRange(int i, Args&&... args); +// * void copyShape(const DataBox& db, const int ndims = 0); +// * void copyMetadata(const DataBox& src); +// #ifdef SPINER_USE_HDF +// * herr_t saveHDF() const; +// * herr_t saveHDF(const std::string& filename) const; +// * herr_t saveHDF(hid_t loc, const std::string& groupname) const; +// * herr_t loadHDF(); +// * herr_t loadHDF(const std::string& filename); +// * herr_t loadHDF(hid_t loc, const std::string& groupname); +// #endif // SPINER_USE_HDF +// * IndexType& indexType(const int i); +// * Grid_t& range(const int i); +// * DataBox& operator=(const DataBox& other); +// * void copy(const DataBox& src); +// * DataStatus dataStatus() const; +// * bool isReference(); +// * bool ownsAllocatedMemory(); +// * bool operator==(const DataBox& other) const; +// * bool operator!=(const DataBox& other) const; +// * void makeShallow(); +// * void reset(); +// * T* data() const; +// * T min() const; +// * T max() const; +// * int rank() const; +// * int size() const; +// * int sizeBytes() const; +// * int dim() const; +// * Grid_t range(int i) const; +// * IndexType indexType(const int i) const; +// * std::size_t serializedSizeInBytes() const; +// * std::size_t serialize(char* dst) const; +// * std::size_t setPointer(T* src); +// * std::size_t setPointer(char* src); +// * std::size_t deSerialize(char* src); +// * DataBox getOnDevice() const; +// * void finalize(); + + // a wrapper to (a) adapt the interface and (b) handle extrapolation off the table // -- note that we assume this is a 1D databox template @@ -23,32 +97,32 @@ class DataBoxWrapper DataType_t Thi_; public: - SINGE_PORTABLE_FUNCTION DataBoxWrapper(DataBox databox) + PORTABLE_FUNCTION DataBoxWrapper(DataBox databox) : databox_{databox} // MUST be initialized before Tlo_ and Thi_ , Tlo_{get_temperature(0)} , Thi_{get_temperature(size() - 1)} {} - SINGE_PORTABLE_FUNCTION constexpr DataType_t get_logT(int const index) const + PORTABLE_FUNCTION constexpr DataType_t get_logT(int const index) const { return databox_.range(0).x(index); } - SINGE_PORTABLE_FUNCTION constexpr DataType_t get_temperature(int const index) const + PORTABLE_FUNCTION constexpr DataType_t get_temperature(int const index) const { return std::exp(get_logT(index)); } - SINGE_PORTABLE_FUNCTION constexpr DataType_t get_value(int const index) const + PORTABLE_FUNCTION constexpr DataType_t get_value(int const index) const { return databox_(index); } - SINGE_PORTABLE_FUNCTION constexpr DataType_t get_logV(int const index) const + PORTABLE_FUNCTION constexpr DataType_t get_logV(int const index) const { return std::log(get_value(index)); } - SINGE_PORTABLE_FUNCTION constexpr int size() const + PORTABLE_FUNCTION constexpr int size() const { return databox_.dim(1); } - SINGE_PORTABLE_FUNCTION constexpr DataType_t operator()(DataType_t const temperature) const + PORTABLE_FUNCTION constexpr DataType_t operator()(DataType_t const temperature) const { if (temperature < Tlo_) { return LowerExtrapolation::extrapolate(temperature, *this); @@ -58,7 +132,7 @@ class DataBoxWrapper return databox_.interpToReal(std::log(temperature)); } } - SINGE_PORTABLE_FUNCTION constexpr void finalize() + PORTABLE_FUNCTION constexpr void finalize() { databox_.finalize(); } @@ -66,7 +140,6 @@ class DataBoxWrapper // ================================================================================================ -} // end namespace util -} // end namespace singe +} // end namespace Spiner -#endif // ifndef SINGE_UTIL_DATABOXWRAPPER_HPP +#endif // ifndef _SPINER_DATABOXWRAPPER_HPP_