Commit 72ba85be authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add specialized getValue in XdmfArray when getting single value.

This improves performance slightly since there is no calculation of offset
into the array using strides.
parent cd830047
......@@ -492,6 +492,7 @@ private:
class Erase;
class GetArrayType;
class GetCapacity;
template <typename T> class GetValue;
template <typename T> class GetValues;
class GetValuesPointer;
class GetValuesString;
......
......@@ -25,6 +25,34 @@
#include <numeric>
#include "XdmfArray.hpp"
template <typename T>
class XdmfArray::GetValue : public boost::static_visitor<T> {
public:
GetValue(const unsigned int index) :
mIndex(index)
{
}
template<typename U>
T
operator()(const boost::shared_array<const U> & array) const
{
return (T)array[mIndex];
}
template<typename U>
T
operator()(const shared_ptr<std::vector<U> > & array) const
{
return (T)array->operator[](mIndex);
}
private:
const unsigned int mIndex;
};
template <typename T>
class XdmfArray::GetValues : public boost::static_visitor<void> {
public:
......@@ -174,9 +202,15 @@ template <typename T>
T
XdmfArray::getValue(const unsigned int index) const
{
T toReturn;
this->getValues(index, &toReturn, 1);
return toReturn;
if(mHaveArray) {
boost::apply_visitor(GetValue<T>(index),
mArray);
}
else if(mHaveArrayPointer) {
boost::apply_visitor(GetValue<T>(index),
mArrayPointer);
}
return 0;
}
template <typename T>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment