Commit 5817c0a7 authored by Scott Cyphers's avatar Scott Cyphers

Switch to factory functions, style on some more files.

parent 494b16cd
......@@ -37,6 +37,7 @@ namespace nervana
}
constexpr const char* get_ptr(size_t offset) const { return &_string[offset]; }
constexpr size_t size() const { return _size; }
private:
const char* _string;
size_t _size;
......@@ -44,8 +45,9 @@ namespace nervana
constexpr const char* find_last(conststring s, size_t offset, char ch)
{
return offset == 0 ? s.get_ptr(0) : (s[offset] == ch ? s.get_ptr(offset + 1)
: find_last(s, offset - 1, ch));
return offset == 0
? s.get_ptr(0)
: (s[offset] == ch ? s.get_ptr(offset + 1) : find_last(s, offset - 1, ch));
}
constexpr const char* find_last(conststring s, char ch)
......@@ -67,6 +69,7 @@ namespace nervana
~log_helper();
std::ostream& stream() { return _stream; }
private:
std::stringstream _stream;
};
......
......@@ -14,8 +14,8 @@
#pragma once
#include <vector>
#include <set>
#include <vector>
#include "ngraph/type.hpp"
......@@ -31,7 +31,6 @@ namespace ngraph
class Node : public TypedValueMixin
{
public:
using ptr = std::shared_ptr<Node>;
Node(const std::vector<Node::ptr>& arguments, ValueType::ptr type = nullptr)
......@@ -39,7 +38,8 @@ namespace ngraph
, m_arguments(arguments)
{
// Add this node as a user of each argument.
for(auto node : m_arguments){
for (auto node : m_arguments)
{
node->m_users.insert(node.get());
}
}
......
......@@ -50,8 +50,15 @@ namespace ngraph
{
};
namespace op
{
std::shared_ptr<Node> broadcast(const Node::ptr& tensor, size_t axis);
}
class Broadcast : public Op, public std::enable_shared_from_this<Broadcast>
{
friend std::shared_ptr<Node> op::broadcast(const Node::ptr& tensor, size_t axis);
protected:
class BroadcastCall : public Call
{
......@@ -68,29 +75,17 @@ namespace ngraph
size_t m_axis;
};
public:
std::shared_ptr<BroadcastCall> operator()(const Node::ptr& tensor, size_t axis)
{
return std::make_shared<BroadcastCall>(shared_from_this(), tensor, axis);
}
static std::shared_ptr<Broadcast> s_op;
};
namespace op
{
extern decltype(*std::shared_ptr<Broadcast>()) broadcast;
std::shared_ptr<Node> dot(const Node::ptr& arg0, const Node::ptr& arg1);
}
class Dot : public Op, public std::enable_shared_from_this<Dot>
{
public:
Call::ptr operator()(const Node::ptr& arg0, const Node::ptr& arg1)
{
return std::make_shared<Call>(shared_from_this(), std::vector<Node::ptr>{arg0, arg1});
}
friend std::shared_ptr<Node> op::dot(const Node::ptr& arg0, const Node::ptr& arg1);
static std::shared_ptr<Dot> s_op;
};
namespace op
{
extern decltype(*std::shared_ptr<Dot>()) dot;
}
}
......@@ -15,7 +15,18 @@
#include "ngraph/ngraph.hpp"
using namespace ngraph;
using namespace std;
decltype(*std::shared_ptr<Broadcast>()) ngraph::op::broadcast = *std::make_shared<Broadcast>();
shared_ptr<Broadcast> ngraph::Broadcast::s_op = make_shared<ngraph::Broadcast>();
decltype(*std::shared_ptr<Dot>()) ngraph::op::dot = *std::make_shared<Dot>();
shared_ptr<Node> ngraph::op::broadcast(const Node::ptr& tensor, size_t axis)
{
return make_shared<Broadcast::BroadcastCall>(Broadcast::s_op->shared_from_this(), tensor, axis);
}
shared_ptr<Dot> ngraph::Dot::s_op = make_shared<ngraph::Dot>();
shared_ptr<Node> ngraph::op::dot(const Node::ptr& arg0, const Node::ptr& arg1)
{
return make_shared<Call>(Dot::s_op->shared_from_this(), std::vector<Node::ptr>{arg0, arg1});
}
......@@ -148,6 +148,7 @@ namespace ngraph
size_t get_total_milliseconds() const { return get_total_nanoseconds() / 1e6; }
size_t get_total_microseconds() const { return get_total_nanoseconds() / 1e3; }
size_t get_total_nanoseconds() const { return m_total_time.count(); }
private:
std::chrono::high_resolution_clock m_clock;
std::chrono::time_point<std::chrono::high_resolution_clock> m_start_time;
......
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