This repository has been archived on 2019-09-17. You can view files and clone it, but cannot push or open issues or pull requests.
Files
research-project/src/fmri/LayerData.cpp
Bert Peters d0c888024d Use global color interpolation.
Now every place uses the globally defined colors rather than specific
colors whenever needed. Next: make those colors configurable.
2018-05-03 13:33:02 +02:00

79 lines
1.3 KiB
C++

#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>
#include <glog/logging.h>
#include "LayerData.hpp"
using namespace fmri;
using namespace std;
LayerData::LayerData(const string& name, const vector<int>& shape, const DType* data) :
name_(name),
shape_(shape)
{
const auto dataSize = numEntries();
// Compute the dimension of the data area
data_.reset(new DType[dataSize]);
// Copy the data over with memcpy because it's just faster that way
memcpy(data_.get(), data, sizeof(DType) * dataSize);
}
size_t LayerData::numEntries() const
{
return static_cast<size_t>(accumulate(shape_.begin(), shape_.end(), 1, multiplies<>()));
}
const vector<int>& LayerData::shape() const
{
return shape_;
}
const string& LayerData::name() const
{
return name_;
}
DType const * LayerData::data() const
{
return data_.get();
}
const DType &LayerData::operator[](std::size_t i) const
{
return data_[i];
}
DType const *LayerData::begin() const
{
return data();
}
DType const *LayerData::end() const
{
return data() + numEntries();
}
ostream& operator<< (ostream& o, const LayerData& layer)
{
o << layer.name() << '(';
bool first = true;
for (auto d : layer.shape()) {
if (!first) {
o << ", ";
} else {
first = false;
}
o << d;
}
o << ')';
return o;
}