Solve warnings with a magic range class.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
#include "Range.hpp"
|
||||||
#include "ActivityAnimation.hpp"
|
#include "ActivityAnimation.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
@@ -20,13 +21,13 @@ ActivityAnimation::ActivityAnimation(std::size_t count, const float *aPos, const
|
|||||||
offset(new float[count])
|
offset(new float[count])
|
||||||
{
|
{
|
||||||
memcpy(startingPos.get(), aPos, sizeof(aPos[0]) * bufferLength);
|
memcpy(startingPos.get(), aPos, sizeof(aPos[0]) * bufferLength);
|
||||||
for (int i = 0; i < bufferLength; ++i) {
|
for (auto i : Range(bufferLength)) {
|
||||||
delta[i] = bPos[i] - aPos[i];
|
delta[i] = bPos[i] - aPos[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& random = rng();
|
auto& random = rng();
|
||||||
std::uniform_real_distribution<float> rd;
|
std::uniform_real_distribution<float> rd;
|
||||||
for (int i = 0; i < count; ++i) {
|
for (auto i : Range(count)) {
|
||||||
offset[i] = rd(random);
|
offset[i] = rd(random);
|
||||||
delta[3 * i] += xDist;
|
delta[3 * i] += xDist;
|
||||||
}
|
}
|
||||||
@@ -36,7 +37,7 @@ void ActivityAnimation::draw(float timeScale) const
|
|||||||
{
|
{
|
||||||
std::unique_ptr<float[]> vertexBuffer(new float[bufferLength]);
|
std::unique_ptr<float[]> vertexBuffer(new float[bufferLength]);
|
||||||
|
|
||||||
for (auto i = 0; i < bufferLength; ++i) {
|
for (auto i : Range(bufferLength)) {
|
||||||
vertexBuffer[i] = startingPos[i] + correct_timescale(offset[i/3] + timeScale) * delta[i];
|
vertexBuffer[i] = startingPos[i] + correct_timescale(offset[i/3] + timeScale) * delta[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ FlatLayerVisualisation::FlatLayerVisualisation(const LayerData &layer, Ordering
|
|||||||
indexBuffer[v++] = vertexBase + 2;
|
indexBuffer[v++] = vertexBase + 2;
|
||||||
indexBuffer[v++] = vertexBase + 3;
|
indexBuffer[v++] = vertexBase + 3;
|
||||||
}
|
}
|
||||||
assert(v == faceCount * 3);
|
assert(v == (int) faceCount * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatLayerVisualisation::render()
|
void FlatLayerVisualisation::render()
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ LayerInfo::Type LayerInfo::typeByName(string_view name)
|
|||||||
|
|
||||||
LayerInfo::LayerInfo(string_view name, string_view type,
|
LayerInfo::LayerInfo(string_view name, string_view type,
|
||||||
const vector<boost::shared_ptr<caffe::Blob<DType>>> ¶meters)
|
const vector<boost::shared_ptr<caffe::Blob<DType>>> ¶meters)
|
||||||
: parameters_(parameters), name_(name), type_(typeByName(type))
|
: parameters_(parameters), type_(typeByName(type)), name_(name)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
37
src/Range.hpp
Normal file
37
src/Range.hpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace fmri
|
||||||
|
{
|
||||||
|
template<class T>
|
||||||
|
class Range
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
T start_;
|
||||||
|
T end_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Range(const T &num) : start_(0), end_(num) {};
|
||||||
|
|
||||||
|
Range(const T &start, const T &end) : start_(start), end_(end) {};
|
||||||
|
|
||||||
|
class Iter
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
T cur_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Iter(const T &cur) : cur_(cur)
|
||||||
|
{};
|
||||||
|
|
||||||
|
bool operator!=(const Iter& o) { return o.cur_ != cur_; }
|
||||||
|
Iter&operator++() { ++cur_; return *this; }
|
||||||
|
|
||||||
|
T &operator*() { return cur_; }
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef Iter const_iterator;
|
||||||
|
|
||||||
|
const_iterator begin() const { return Iter(start_); }
|
||||||
|
const_iterator end() const { return Iter(end_); }
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -106,7 +106,6 @@ vector<LayerData> Simulator::Impl::simulate(const string& image_file)
|
|||||||
|
|
||||||
const auto& names = net.layer_names();
|
const auto& names = net.layer_names();
|
||||||
const auto& results = net.top_vecs();
|
const auto& results = net.top_vecs();
|
||||||
const auto& layers = net.layers();
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < names.size(); ++i) {
|
for (unsigned int i = 0; i < names.size(); ++i) {
|
||||||
CHECK_EQ(results[i].size(), 1) << "Multiple outputs per layer are not supported!" << endl;
|
CHECK_EQ(results[i].size(), 1) << "Multiple outputs per layer are not supported!" << endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user