Restructure project sources.
This commit is contained in:
63
src/fmri/LayerData.cpp
Normal file
63
src/fmri/LayerData.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user