Restructure project sources.

This commit is contained in:
2018-03-26 12:17:52 +02:00
parent a206f81eb2
commit 8015b84311
41 changed files with 2 additions and 37 deletions

63
src/fmri/LayerData.cpp Normal file
View File

@@ -0,0 +1,63 @@
#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();
}
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;
}