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

Add MinMax in non-template API #3193

Merged
merged 12 commits into from
May 2, 2022
313 changes: 308 additions & 5 deletions bindings/CXX11/adios2/cxx11/VariableNT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ size_t VariableNT::StructItems() const
{
helper::Throw<std::runtime_error>(
"bindings::CXX11", "VariableNT", "StructItems",
"invalid data type " + ToString(m_Variable->m_Type));
"invalid data type " + ToString(m_Variable->m_Type) +
", only Struct type supports this API");
}
return reinterpret_cast<core::VariableStruct *>(m_Variable)
->m_StructDefinition.Items();
Expand All @@ -266,7 +267,8 @@ std::string VariableNT::StructItemName(const size_t index) const
{
helper::Throw<std::runtime_error>(
"bindings::CXX11", "VariableNT", "StructItemName",
"invalid data type " + ToString(m_Variable->m_Type));
"invalid data type " + ToString(m_Variable->m_Type) +
", only Struct type supports this API");
}
return reinterpret_cast<core::VariableStruct *>(m_Variable)
->m_StructDefinition.Name(index);
Expand All @@ -279,7 +281,8 @@ size_t VariableNT::StructItemOffset(const size_t index) const
{
helper::Throw<std::runtime_error>(
"bindings::CXX11", "VariableNT", "StructItemOffset",
"invalid data type " + ToString(m_Variable->m_Type));
"invalid data type " + ToString(m_Variable->m_Type) +
", only Struct type supports this API");
}
return reinterpret_cast<core::VariableStruct *>(m_Variable)
->m_StructDefinition.Offset(index);
Expand All @@ -292,7 +295,8 @@ DataType VariableNT::StructItemType(const size_t index) const
{
helper::Throw<std::runtime_error>(
"bindings::CXX11", "VariableNT", "StructItemType",
"invalid data type " + ToString(m_Variable->m_Type));
"invalid data type " + ToString(m_Variable->m_Type) +
", only Struct type supports this API");
}
return reinterpret_cast<core::VariableStruct *>(m_Variable)
->m_StructDefinition.Type(index);
Expand All @@ -305,10 +309,309 @@ size_t VariableNT::StructItemSize(const size_t index) const
{
helper::Throw<std::runtime_error>(
"bindings::CXX11", "VariableNT", "StructItemSize",
"invalid data type " + ToString(m_Variable->m_Type));
"invalid data type " + ToString(m_Variable->m_Type) +
", only Struct type supports this API");
}
return reinterpret_cast<core::VariableStruct *>(m_Variable)
->m_StructDefinition.Size(index);
}

std::pair<VariableNT::T, VariableNT::T>
VariableNT::MinMax(const size_t step) const
{
helper::CheckForNullptr(m_Variable, "in call to VariableNT::MinMax");
return {Min(step), Max(step)};
}

VariableNT::T VariableNT::Min(const size_t step) const
{
helper::CheckForNullptr(m_Variable, "in call to VariableNT::Min");
if (m_Variable->m_Type == DataType::Int8)
{
VariableNT::T ret = {0};
ret.Int8 =
reinterpret_cast<core::Variable<int8_t> *>(m_Variable)->Min(step);
return ret;
}
else if (m_Variable->m_Type == DataType::UInt8)
{
VariableNT::T ret = {0};
ret.UInt8 =
reinterpret_cast<core::Variable<uint8_t> *>(m_Variable)->Min(step);
return ret;
}
else if (m_Variable->m_Type == DataType::Int16)
{
VariableNT::T ret = {0};
ret.Int16 =
reinterpret_cast<core::Variable<int16_t> *>(m_Variable)->Min(step);
return ret;
}
else if (m_Variable->m_Type == DataType::UInt16)
{
VariableNT::T ret = {0};
ret.UInt16 =
reinterpret_cast<core::Variable<uint16_t> *>(m_Variable)->Min(step);
return ret;
}
else if (m_Variable->m_Type == DataType::Int32)
{
VariableNT::T ret = {0};
ret.Int32 =
reinterpret_cast<core::Variable<int32_t> *>(m_Variable)->Min(step);
return ret;
}
else if (m_Variable->m_Type == DataType::UInt32)
{
VariableNT::T ret = {0};
ret.UInt32 =
reinterpret_cast<core::Variable<uint32_t> *>(m_Variable)->Min(step);
return ret;
}
else if (m_Variable->m_Type == DataType::Int64)
{
VariableNT::T ret = {0};
ret.Int64 =
reinterpret_cast<core::Variable<int64_t> *>(m_Variable)->Min(step);
return ret;
}
else if (m_Variable->m_Type == DataType::UInt64)
{
VariableNT::T ret = {0};
ret.UInt64 =
reinterpret_cast<core::Variable<uint64_t> *>(m_Variable)->Min(step);
return ret;
}
else if (m_Variable->m_Type == DataType::Float)
{
VariableNT::T ret = {0};
ret.Float =
reinterpret_cast<core::Variable<float> *>(m_Variable)->Min(step);
return ret;
}
else if (m_Variable->m_Type == DataType::Double)
{
VariableNT::T ret = {0};
ret.Double =
reinterpret_cast<core::Variable<double> *>(m_Variable)->Min(step);
return ret;
}
helper::Throw<std::runtime_error>(
"bindings::CXX11", "VariableNT", "Min",
"invalid data type " + ToString(m_Variable->m_Type) +
", only basic numeric types support this API");
return {0};
}

VariableNT::T VariableNT::Max(const size_t step) const
{
helper::CheckForNullptr(m_Variable, "in call to VariableNT::Max");
if (m_Variable->m_Type == DataType::Int8)
{
VariableNT::T ret = {0};
ret.Int8 =
reinterpret_cast<core::Variable<int8_t> *>(m_Variable)->Max(step);
return ret;
}
else if (m_Variable->m_Type == DataType::UInt8)
{
VariableNT::T ret = {0};
ret.UInt8 =
reinterpret_cast<core::Variable<uint8_t> *>(m_Variable)->Max(step);
return ret;
}
else if (m_Variable->m_Type == DataType::Int16)
{
VariableNT::T ret = {0};
ret.Int16 =
reinterpret_cast<core::Variable<int16_t> *>(m_Variable)->Max(step);
return ret;
}
else if (m_Variable->m_Type == DataType::UInt16)
{
VariableNT::T ret = {0};
ret.UInt16 =
reinterpret_cast<core::Variable<uint16_t> *>(m_Variable)->Max(step);
return ret;
}
else if (m_Variable->m_Type == DataType::Int32)
{
VariableNT::T ret = {0};
ret.Int32 =
reinterpret_cast<core::Variable<int32_t> *>(m_Variable)->Max(step);
return ret;
}
else if (m_Variable->m_Type == DataType::UInt32)
{
VariableNT::T ret = {0};
ret.UInt32 =
reinterpret_cast<core::Variable<uint32_t> *>(m_Variable)->Max(step);
return ret;
}
else if (m_Variable->m_Type == DataType::Int64)
{
VariableNT::T ret = {0};
ret.Int64 =
reinterpret_cast<core::Variable<int64_t> *>(m_Variable)->Max(step);
return ret;
}
else if (m_Variable->m_Type == DataType::UInt64)
{
VariableNT::T ret = {0};
ret.UInt64 =
reinterpret_cast<core::Variable<uint64_t> *>(m_Variable)->Max(step);
return ret;
}
else if (m_Variable->m_Type == DataType::Float)
{
VariableNT::T ret = {0};
ret.Float =
reinterpret_cast<core::Variable<float> *>(m_Variable)->Max(step);
return ret;
}
else if (m_Variable->m_Type == DataType::Double)
{
VariableNT::T ret = {0};
ret.Double =
reinterpret_cast<core::Variable<double> *>(m_Variable)->Max(step);
return ret;
}
helper::Throw<std::runtime_error>(
"bindings::CXX11", "VariableNT", "Max",
"invalid data type " + ToString(m_Variable->m_Type) +
", only basic numeric types support this API");
return {0};
}

double VariableNT::MinDouble(const size_t step) const
{
helper::CheckForNullptr(m_Variable, "in call to VariableNT::MinDouble");
if (m_Variable->m_Type == DataType::Int8)
{
return static_cast<double>(
reinterpret_cast<core::Variable<int8_t> *>(m_Variable)->Min(step));
}
else if (m_Variable->m_Type == DataType::UInt8)
{
return static_cast<double>(
reinterpret_cast<core::Variable<uint8_t> *>(m_Variable)->Min(step));
}
else if (m_Variable->m_Type == DataType::Int16)
{
return static_cast<double>(
reinterpret_cast<core::Variable<int16_t> *>(m_Variable)->Min(step));
}
else if (m_Variable->m_Type == DataType::UInt16)
{
return static_cast<double>(
reinterpret_cast<core::Variable<uint16_t> *>(m_Variable)
->Min(step));
}
else if (m_Variable->m_Type == DataType::Int32)
{
return static_cast<double>(
reinterpret_cast<core::Variable<int32_t> *>(m_Variable)->Min(step));
}
else if (m_Variable->m_Type == DataType::UInt32)
{
return static_cast<double>(
reinterpret_cast<core::Variable<uint32_t> *>(m_Variable)
->Min(step));
}
else if (m_Variable->m_Type == DataType::Int64)
{
return static_cast<double>(
reinterpret_cast<core::Variable<int64_t> *>(m_Variable)->Min(step));
}
else if (m_Variable->m_Type == DataType::UInt64)
{
return static_cast<double>(
reinterpret_cast<core::Variable<uint64_t> *>(m_Variable)
->Min(step));
}
else if (m_Variable->m_Type == DataType::Float)
{
return static_cast<double>(
reinterpret_cast<core::Variable<float> *>(m_Variable)->Min(step));
}
else if (m_Variable->m_Type == DataType::Double)
{
return static_cast<double>(
reinterpret_cast<core::Variable<double> *>(m_Variable)->Min(step));
}
helper::Throw<std::runtime_error>(
"bindings::CXX11", "VariableNT", "MinDouble",
"invalid data type " + ToString(m_Variable->m_Type) +
", only basic numeric types support this API");
return 0;
}

double VariableNT::MaxDouble(const size_t step) const
{
helper::CheckForNullptr(m_Variable, "in call to VariableNT::MaxDouble");
if (m_Variable->m_Type == DataType::Int8)
{
return static_cast<double>(
reinterpret_cast<core::Variable<int8_t> *>(m_Variable)->Max(step));
}
else if (m_Variable->m_Type == DataType::UInt8)
{
return static_cast<double>(
reinterpret_cast<core::Variable<uint8_t> *>(m_Variable)->Max(step));
}
else if (m_Variable->m_Type == DataType::Int16)
{
return static_cast<double>(
reinterpret_cast<core::Variable<int16_t> *>(m_Variable)->Max(step));
}
else if (m_Variable->m_Type == DataType::UInt16)
{
return static_cast<double>(
reinterpret_cast<core::Variable<uint16_t> *>(m_Variable)
->Max(step));
}
else if (m_Variable->m_Type == DataType::Int32)
{
return static_cast<double>(
reinterpret_cast<core::Variable<int32_t> *>(m_Variable)->Max(step));
}
else if (m_Variable->m_Type == DataType::UInt32)
{
return static_cast<double>(
reinterpret_cast<core::Variable<uint32_t> *>(m_Variable)
->Max(step));
}
else if (m_Variable->m_Type == DataType::Int64)
{
return static_cast<double>(
reinterpret_cast<core::Variable<int64_t> *>(m_Variable)->Max(step));
}
else if (m_Variable->m_Type == DataType::UInt64)
{
return static_cast<double>(
reinterpret_cast<core::Variable<uint64_t> *>(m_Variable)
->Max(step));
}
else if (m_Variable->m_Type == DataType::Float)
{
return static_cast<double>(
reinterpret_cast<core::Variable<float> *>(m_Variable)->Max(step));
}
else if (m_Variable->m_Type == DataType::Double)
{
return static_cast<double>(
reinterpret_cast<core::Variable<double> *>(m_Variable)->Max(step));
}
helper::Throw<std::runtime_error>(
"bindings::CXX11", "VariableNT", "MaxDouble",
"invalid data type " + ToString(m_Variable->m_Type) +
", only basic numeric types support this API");
return 0;
}

std::pair<double, double> VariableNT::MinMaxDouble(const size_t step) const
{
helper::CheckForNullptr(m_Variable, "in call to VariableNT::MinMaxDouble");
return {MinDouble(step), MaxDouble(step)};
}
} // end namespace adios2
25 changes: 25 additions & 0 deletions bindings/CXX11/adios2/cxx11/VariableNT.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,31 @@ class VariableNT
DataType StructItemType(const size_t index) const;
size_t StructItemSize(const size_t index) const;

union T
{
int8_t Int8;
uint8_t UInt8;
int16_t Int16;
uint16_t UInt16;
int32_t Int32;
uint32_t UInt32;
int64_t Int64;
uint64_t UInt64;
float Float;
double Double;
std::complex<float> Complex;
std::complex<double> DComplex;
};

T Min(const size_t step = adios2::DefaultSizeT) const;
T Max(const size_t step = adios2::DefaultSizeT) const;
std::pair<T, T> MinMax(const size_t step = adios2::DefaultSizeT) const;

double MinDouble(const size_t step = adios2::DefaultSizeT) const;
double MaxDouble(const size_t step = adios2::DefaultSizeT) const;
std::pair<double, double>
MinMaxDouble(const size_t step = adios2::DefaultSizeT) const;

private:
friend class IO;
friend class Engine;
Expand Down
2 changes: 0 additions & 2 deletions source/adios2/core/Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ class Variable : public VariableBase

T *GetData() const noexcept;

size_t SubStreamsInfoSize();

Dims Count() const;

size_t SelectionSize() const;
Expand Down
Loading