Unverified Commit 02405796 authored by Jai Menon's avatar Jai Menon Committed by GitHub

Merge branch 'master' into jmenon/cpu_kernels

parents f80e1d0c 69a2d4aa
# Copyright 2017 Nervana Systems Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
NGRAPH_DIST_DIR = ${HOME}/ngraph_dist
CXXFLAGS += -std=c++11
CPPFLAGS += -I $(NGRAPH_DIST_DIR)
LDFLAGS = -L $(NGRAPH_DIST_DIR)
OBJ = main.o
%.o: %.cpp $(DEPS)
$(CXX) -c -o $@ $< $(CXXFLAGS) $(CPPFLAGS)
ngraph-test: $(OBJ)
$(CXX) -o $@ $(OBJ) $(LDFLAGS) -lngraph
.PHONY: clean
clean:
rm -f $(OBJ) ngraph-test
// ----------------------------------------------------------------------------
// Copyright 2017 Nervana Systems Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// ----------------------------------------------------------------------------
#include <stdio.h>
#include "ngraph/ngraph.hpp"
#include "ngraph/ops/dot.hpp"
using namespace std;
using namespace ngraph;
int main(int argc, char** argv)
{
printf( "Building graph\n" );
// Function with 4 parameters
auto arg0 = op::parameter(element::Float::type, {7, 3});
auto arg1 = op::parameter(element::Float::type, {3});
auto arg2 = op::parameter(element::Float::type, {32, 7});
auto arg3 = op::parameter(element::Float::type, {32, 7});
auto broadcast_1 = op::broadcast(arg3, {10, 32, 7}, {0});
auto dot = op::dot(arg2, arg0);
auto cluster_0 = op::function(dot, {arg0, arg1, arg2, arg3});
auto result = cluster_0->result();
printf( "Finished\n" );
}
\ No newline at end of file
...@@ -117,8 +117,12 @@ namespace ngraph ...@@ -117,8 +117,12 @@ namespace ngraph
std::shared_ptr<Node> backprop_node(const std::shared_ptr<Node>& x, std::shared_ptr<Node> backprop_node(const std::shared_ptr<Node>& x,
const std::shared_ptr<Node>& c); const std::shared_ptr<Node>& c);
/// Returns the shape if this node has tensor type, othetwise error. /// Returns the shape if this node has tensor type, otherwise an ngraph-error is thrown.
const Shape& get_shape() const { return m_value_type->get_shape(); } const Shape& get_shape() const { return m_value_type->get_shape(); }
const element::Type& get_element_type() const { return m_value_type->get_element_type(); }
virtual std::shared_ptr<Node>
copy_with_new_args(const std::vector<std::shared_ptr<Node>>& new_args) const = 0;
protected: protected:
Nodes m_arguments; Nodes m_arguments;
std::shared_ptr<const ValueType> m_value_type; std::shared_ptr<const ValueType> m_value_type;
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#pragma once #pragma once
#include <memory>
#include "ngraph/ops/op.hpp" #include "ngraph/ops/op.hpp"
namespace ngraph namespace ngraph
...@@ -50,6 +52,14 @@ namespace ngraph ...@@ -50,6 +52,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Abs>(new_args.at(0));
}
virtual std::string description() const override { return "Abs"; } virtual std::string description() const override { return "Abs"; }
}; };
} }
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#pragma once #pragma once
#include <memory>
#include "ngraph/ops/op.hpp" #include "ngraph/ops/op.hpp"
namespace ngraph namespace ngraph
...@@ -50,6 +52,14 @@ namespace ngraph ...@@ -50,6 +52,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Acos>(new_args.at(0));
}
virtual std::string description() const override { return "Acos"; } virtual std::string description() const override { return "Acos"; }
}; };
} }
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#pragma once #pragma once
#include <memory>
#include "ngraph/ops/op.hpp" #include "ngraph/ops/op.hpp"
namespace ngraph namespace ngraph
...@@ -51,6 +53,15 @@ namespace ngraph ...@@ -51,6 +53,15 @@ namespace ngraph
: BinaryElementwiseArithmetic(arg0, arg1) : BinaryElementwiseArithmetic(arg0, arg1)
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Add>(new_args.at(0), new_args.at(1));
}
virtual std::string description() const override { return "Add"; } virtual std::string description() const override { return "Add"; }
protected: protected:
virtual void generate_adjoints(autodiff::Adjoints& adjoints, virtual void generate_adjoints(autodiff::Adjoints& adjoints,
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#pragma once #pragma once
#include <memory>
#include "ngraph/ops/op.hpp" #include "ngraph/ops/op.hpp"
namespace ngraph namespace ngraph
...@@ -50,6 +52,14 @@ namespace ngraph ...@@ -50,6 +52,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Asin>(new_args.at(0));
}
virtual std::string description() const override { return "Asin"; } virtual std::string description() const override { return "Asin"; }
}; };
} }
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#pragma once #pragma once
#include <memory>
#include "ngraph/ops/op.hpp" #include "ngraph/ops/op.hpp"
namespace ngraph namespace ngraph
...@@ -50,6 +52,14 @@ namespace ngraph ...@@ -50,6 +52,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Atan>(new_args.at(0));
}
virtual std::string description() const override { return "Atan"; } virtual std::string description() const override { return "Atan"; }
}; };
} }
......
...@@ -74,12 +74,20 @@ namespace ngraph ...@@ -74,12 +74,20 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Broadcast>(new_args.at(0), m_shape, m_broadcast_axes);
}
virtual std::string description() const override { return "Broadcast"; } virtual std::string description() const override { return "Broadcast"; }
virtual void propagate_types() override; virtual void propagate_types() override;
/// \return An set containing the indices of the broadcast axes (0-based). /// \return An set containing the indices of the broadcast axes (0-based).
const AxisSet& get_broadcast_axes() const { return m_broadcast_axes; } const AxisSet& get_broadcast_axes() const { return m_broadcast_axes; }
protected: const Shape& get_broadcast_shape() const { return m_shape; }
protected: protected:
virtual void generate_adjoints(autodiff::Adjoints& adjoints, virtual void generate_adjoints(autodiff::Adjoints& adjoints,
const std::shared_ptr<Node>& delta) override; const std::shared_ptr<Node>& delta) override;
......
...@@ -50,6 +50,14 @@ namespace ngraph ...@@ -50,6 +50,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Ceiling>(new_args.at(0));
}
virtual std::string description() const override { return "Ceiling"; } virtual std::string description() const override { return "Ceiling"; }
}; };
} }
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#pragma once #pragma once
#include <memory>
#include "ngraph/ops/op.hpp" #include "ngraph/ops/op.hpp"
namespace ngraph namespace ngraph
...@@ -74,6 +76,12 @@ namespace ngraph ...@@ -74,6 +76,12 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
return std::make_shared<Concat>(new_args, m_concatenation_axis);
}
virtual std::string description() const override { return "Concatenate"; } virtual std::string description() const override { return "Concatenate"; }
virtual void propagate_types() override; virtual void propagate_types() override;
......
...@@ -82,12 +82,20 @@ namespace ngraph ...@@ -82,12 +82,20 @@ namespace ngraph
/// \param value The value of the tensor constant. /// \param value The value of the tensor constant.
ParameterizedConstant( ParameterizedConstant(
const Shape& shape, const Shape& shape,
typename std::shared_ptr<ngraph::runtime::ParameterizedTensorView<T>>& value) const typename std::shared_ptr<ngraph::runtime::ParameterizedTensorView<T>>& value)
: ConstantBase(std::make_shared<TensorViewType>(T::element_type(), shape)) : ConstantBase(std::make_shared<TensorViewType>(T::element_type(), shape))
, m_value(value) , m_value(value)
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 0)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<ParameterizedConstant<T>>(get_shape(), m_value);
}
virtual std::string description() const override { return "ParameterizedConstant"; } virtual std::string description() const override { return "ParameterizedConstant"; }
virtual std::string get_node_id() const override virtual std::string get_node_id() const override
{ {
...@@ -103,7 +111,7 @@ namespace ngraph ...@@ -103,7 +111,7 @@ namespace ngraph
} }
protected: protected:
std::shared_ptr<ngraph::runtime::ParameterizedTensorView<T>> m_value; const std::shared_ptr<ngraph::runtime::ParameterizedTensorView<T>> m_value;
}; };
/// \brief A 32-bit floating-point tensor constant. /// \brief A 32-bit floating-point tensor constant.
...@@ -171,6 +179,14 @@ namespace ngraph ...@@ -171,6 +179,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 0)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Constant>(get_element_type(), get_shape(), m_value_strings);
}
virtual std::string description() const override { return "Constant"; } virtual std::string description() const override { return "Constant"; }
virtual std::string get_node_id() const override virtual std::string get_node_id() const override
{ {
......
...@@ -61,8 +61,17 @@ namespace ngraph ...@@ -61,8 +61,17 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Convert>(new_args.at(0), m_element_type);
}
virtual const element::Type& virtual const element::Type&
propagate_element_types(const element::Type& arg_element_type) const override; propagate_element_types(const element::Type& arg_element_type) const override;
const element::Type& get_convert_element_type() const { return m_element_type; }
virtual std::string description() const override { return "Convert"; } virtual std::string description() const override { return "Convert"; }
protected: protected:
const ngraph::element::Type& m_element_type; const ngraph::element::Type& m_element_type;
......
...@@ -50,6 +50,14 @@ namespace ngraph ...@@ -50,6 +50,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Cos>(new_args.at(0));
}
virtual std::string description() const override { return "Cos"; } virtual std::string description() const override { return "Cos"; }
}; };
} }
......
...@@ -50,6 +50,14 @@ namespace ngraph ...@@ -50,6 +50,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Cosh>(new_args.at(0));
}
virtual std::string description() const override { return "Cosh"; } virtual std::string description() const override { return "Cosh"; }
}; };
} }
......
...@@ -52,6 +52,14 @@ namespace ngraph ...@@ -52,6 +52,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Divide>(new_args.at(0), new_args.at(1));
}
virtual void generate_adjoints(autodiff::Adjoints& adjoints, virtual void generate_adjoints(autodiff::Adjoints& adjoints,
const std::shared_ptr<Node>& delta) override; const std::shared_ptr<Node>& delta) override;
......
...@@ -114,6 +114,14 @@ namespace ngraph ...@@ -114,6 +114,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Dot>(new_args.at(0), new_args.at(1));
}
virtual std::string description() const override { return "Dot"; } virtual std::string description() const override { return "Dot"; }
virtual void propagate_types() override; virtual void propagate_types() override;
......
...@@ -51,6 +51,15 @@ namespace ngraph ...@@ -51,6 +51,15 @@ namespace ngraph
: BinaryElementwiseComparison(arg0, arg1) : BinaryElementwiseComparison(arg0, arg1)
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Equal>(new_args.at(0), new_args.at(1));
}
virtual std::string description() const override { return "Equal"; } virtual std::string description() const override { return "Equal"; }
}; };
} }
......
...@@ -50,6 +50,14 @@ namespace ngraph ...@@ -50,6 +50,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Exp>(new_args.at(0));
}
virtual void generate_adjoints(autodiff::Adjoints& adjoints, virtual void generate_adjoints(autodiff::Adjoints& adjoints,
const std::shared_ptr<Node>& delta) override; const std::shared_ptr<Node>& delta) override;
......
...@@ -50,6 +50,14 @@ namespace ngraph ...@@ -50,6 +50,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Floor>(new_args.at(0));
}
virtual std::string description() const override { return "Floor"; } virtual std::string description() const override { return "Floor"; }
}; };
} }
......
...@@ -60,6 +60,12 @@ namespace ngraph ...@@ -60,6 +60,12 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
return std::make_shared<FunctionCall>(m_function, new_args);
}
virtual std::string description() const override { return "FunctionCall"; } virtual std::string description() const override { return "FunctionCall"; }
virtual void propagate_types() override; virtual void propagate_types() override;
......
...@@ -60,6 +60,14 @@ namespace ngraph ...@@ -60,6 +60,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<GetTupleElement>(new_args.at(0), m_n);
}
virtual void propagate_types() override; virtual void propagate_types() override;
virtual std::string description() const override { return "GetTupleElement"; } virtual std::string description() const override { return "GetTupleElement"; }
/// \return The index of the tuple element to get. /// \return The index of the tuple element to get.
......
...@@ -51,6 +51,15 @@ namespace ngraph ...@@ -51,6 +51,15 @@ namespace ngraph
: BinaryElementwiseComparison(arg0, arg1) : BinaryElementwiseComparison(arg0, arg1)
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Greater>(new_args.at(0), new_args.at(1));
}
virtual std::string description() const override { return "Greater"; } virtual std::string description() const override { return "Greater"; }
}; };
} }
......
...@@ -51,6 +51,15 @@ namespace ngraph ...@@ -51,6 +51,15 @@ namespace ngraph
: BinaryElementwiseComparison(arg0, arg1) : BinaryElementwiseComparison(arg0, arg1)
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<GreaterEq>(new_args.at(0), new_args.at(1));
}
virtual std::string description() const override { return "GreaterEq"; } virtual std::string description() const override { return "GreaterEq"; }
}; };
} }
......
...@@ -51,6 +51,15 @@ namespace ngraph ...@@ -51,6 +51,15 @@ namespace ngraph
: BinaryElementwiseComparison(arg0, arg1) : BinaryElementwiseComparison(arg0, arg1)
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Less>(new_args.at(0), new_args.at(1));
}
virtual std::string description() const override { return "Less"; } virtual std::string description() const override { return "Less"; }
}; };
} }
......
...@@ -51,6 +51,15 @@ namespace ngraph ...@@ -51,6 +51,15 @@ namespace ngraph
: BinaryElementwiseComparison(arg0, arg1) : BinaryElementwiseComparison(arg0, arg1)
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<LessEq>(new_args.at(0), new_args.at(1));
}
virtual std::string description() const override { return "LessEq"; } virtual std::string description() const override { return "LessEq"; }
}; };
} }
......
...@@ -50,6 +50,14 @@ namespace ngraph ...@@ -50,6 +50,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Log>(new_args.at(0));
}
virtual void generate_adjoints(autodiff::Adjoints& adjoints, virtual void generate_adjoints(autodiff::Adjoints& adjoints,
const std::shared_ptr<Node>& delta) override; const std::shared_ptr<Node>& delta) override;
......
...@@ -51,6 +51,15 @@ namespace ngraph ...@@ -51,6 +51,15 @@ namespace ngraph
: BinaryElementwiseArithmetic(arg0, arg1) : BinaryElementwiseArithmetic(arg0, arg1)
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Maximum>(new_args.at(0), new_args.at(1));
}
virtual std::string description() const override { return "Maximum"; } virtual std::string description() const override { return "Maximum"; }
protected: protected:
virtual void generate_adjoints(autodiff::Adjoints& adjoints, virtual void generate_adjoints(autodiff::Adjoints& adjoints,
......
...@@ -51,6 +51,15 @@ namespace ngraph ...@@ -51,6 +51,15 @@ namespace ngraph
: BinaryElementwiseArithmetic(arg0, arg1) : BinaryElementwiseArithmetic(arg0, arg1)
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Minimum>(new_args.at(0), new_args.at(1));
}
virtual std::string description() const override { return "Minimum"; } virtual std::string description() const override { return "Minimum"; }
protected: protected:
virtual void generate_adjoints(autodiff::Adjoints& adjoints, virtual void generate_adjoints(autodiff::Adjoints& adjoints,
......
...@@ -52,6 +52,14 @@ namespace ngraph ...@@ -52,6 +52,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Multiply>(new_args.at(0), new_args.at(1));
}
virtual std::string description() const override { return "Multiply"; } virtual std::string description() const override { return "Multiply"; }
protected: protected:
virtual void generate_adjoints(autodiff::Adjoints& adjoints, virtual void generate_adjoints(autodiff::Adjoints& adjoints,
......
...@@ -50,6 +50,14 @@ namespace ngraph ...@@ -50,6 +50,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Negative>(new_args.at(0));
}
virtual void generate_adjoints(autodiff::Adjoints& adjoints, virtual void generate_adjoints(autodiff::Adjoints& adjoints,
const std::shared_ptr<Node>& delta) override; const std::shared_ptr<Node>& delta) override;
......
...@@ -51,6 +51,15 @@ namespace ngraph ...@@ -51,6 +51,15 @@ namespace ngraph
: BinaryElementwiseComparison(arg0, arg1) : BinaryElementwiseComparison(arg0, arg1)
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<NotEqual>(new_args.at(0), new_args.at(1));
}
virtual std::string description() const override { return "NotEqual"; } virtual std::string description() const override { return "NotEqual"; }
}; };
} }
......
...@@ -62,6 +62,14 @@ namespace ngraph ...@@ -62,6 +62,14 @@ namespace ngraph
/// \param shape The shape of the parameter. /// \param shape The shape of the parameter.
Parameter(const ngraph::element::Type& element_type, const Shape& shape); Parameter(const ngraph::element::Type& element_type, const Shape& shape);
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 0)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Parameter>(get_value_type());
}
std::string description() const override { return "Parameter"; } std::string description() const override { return "Parameter"; }
virtual void propagate_types() override; virtual void propagate_types() override;
}; };
......
...@@ -51,6 +51,15 @@ namespace ngraph ...@@ -51,6 +51,15 @@ namespace ngraph
: BinaryElementwiseArithmetic(arg0, arg1) : BinaryElementwiseArithmetic(arg0, arg1)
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Power>(new_args.at(0), new_args.at(1));
}
virtual std::string description() const override { return "Power"; } virtual std::string description() const override { return "Power"; }
}; };
} }
......
...@@ -106,6 +106,15 @@ namespace ngraph ...@@ -106,6 +106,15 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Reduce>(
new_args.at(0), new_args.at(1), m_reduction_function, m_reduction_axes);
}
virtual std::string description() const override { return "Reduce"; } virtual std::string description() const override { return "Reduce"; }
virtual void propagate_types() override; virtual void propagate_types() override;
......
...@@ -53,6 +53,15 @@ namespace ngraph ...@@ -53,6 +53,15 @@ namespace ngraph
: BinaryElementwiseArithmetic(arg0, arg1) : BinaryElementwiseArithmetic(arg0, arg1)
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Remainder>(new_args.at(0), new_args.at(1));
}
virtual std::string description() const override { return "Remainder"; } virtual std::string description() const override { return "Remainder"; }
}; };
} }
......
...@@ -78,6 +78,14 @@ namespace ngraph ...@@ -78,6 +78,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Reshape>(new_args.at(0), m_input_order, m_output_shape);
}
virtual std::string description() const override { return "Reshape"; } virtual std::string description() const override { return "Reshape"; }
virtual void propagate_types() override; virtual void propagate_types() override;
......
...@@ -55,6 +55,15 @@ namespace ngraph ...@@ -55,6 +55,15 @@ namespace ngraph
: Builtin(Nodes{arg0, arg1, arg2}) : Builtin(Nodes{arg0, arg1, arg2})
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 3)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Select>(new_args.at(0), new_args.at(1), new_args.at(2));
}
virtual std::string description() const override { return "Select"; } virtual std::string description() const override { return "Select"; }
virtual void propagate_types() override; virtual void propagate_types() override;
}; };
......
...@@ -52,6 +52,14 @@ namespace ngraph ...@@ -52,6 +52,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Sign>(new_args.at(0));
}
virtual std::string description() const override { return "Sign"; } virtual std::string description() const override { return "Sign"; }
}; };
} }
......
...@@ -50,6 +50,14 @@ namespace ngraph ...@@ -50,6 +50,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Sin>(new_args.at(0));
}
virtual std::string description() const override { return "Sin"; } virtual std::string description() const override { return "Sin"; }
}; };
} }
......
...@@ -50,6 +50,14 @@ namespace ngraph ...@@ -50,6 +50,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Sinh>(new_args.at(0));
}
virtual std::string description() const override { return "Sinh"; } virtual std::string description() const override { return "Sinh"; }
}; };
} }
......
...@@ -88,6 +88,15 @@ namespace ngraph ...@@ -88,6 +88,15 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Slice>(
new_args.at(0), m_lower_bounds, m_upper_bounds, m_step);
}
virtual std::string description() const override { return "Slice"; } virtual std::string description() const override { return "Slice"; }
virtual void propagate_types() override; virtual void propagate_types() override;
......
...@@ -52,6 +52,14 @@ namespace ngraph ...@@ -52,6 +52,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 2)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Subtract>(new_args.at(0), new_args.at(1));
}
virtual void generate_adjoints(autodiff::Adjoints& adjoints, virtual void generate_adjoints(autodiff::Adjoints& adjoints,
const std::shared_ptr<Node>& delta) override; const std::shared_ptr<Node>& delta) override;
......
...@@ -93,6 +93,14 @@ namespace ngraph ...@@ -93,6 +93,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Sum>(new_args.at(0), m_reduction_axes);
}
virtual std::string description() const override { return "Sum"; } virtual std::string description() const override { return "Sum"; }
virtual void propagate_types() override; virtual void propagate_types() override;
......
...@@ -50,6 +50,14 @@ namespace ngraph ...@@ -50,6 +50,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Tan>(new_args.at(0));
}
virtual std::string description() const override { return "Tan"; } virtual std::string description() const override { return "Tan"; }
}; };
} }
......
...@@ -50,6 +50,14 @@ namespace ngraph ...@@ -50,6 +50,14 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
if (new_args.size() != 1)
throw ngraph_error("Incorrect number of new arguments");
return std::make_shared<Tanh>(new_args.at(0));
}
virtual std::string description() const override { return "Tanh"; } virtual std::string description() const override { return "Tanh"; }
}; };
} }
......
...@@ -50,6 +50,12 @@ namespace ngraph ...@@ -50,6 +50,12 @@ namespace ngraph
{ {
} }
virtual std::shared_ptr<Node> copy_with_new_args(
const std::vector<std::shared_ptr<Node>>& new_args) const override
{
return std::make_shared<Tuple>(new_args);
}
virtual std::string description() const override { return "Tuple"; } virtual std::string description() const override { return "Tuple"; }
virtual void propagate_types() override; virtual void propagate_types() override;
}; };
......
...@@ -177,6 +177,8 @@ namespace ngraph ...@@ -177,6 +177,8 @@ namespace ngraph
const_iterator end() const { return m_elements.end(); } const_iterator end() const { return m_elements.end(); }
vtype get_vector() { return m_elements; } vtype get_vector() { return m_elements; }
const vtype get_vector() const { return m_elements; } const vtype get_vector() const { return m_elements; }
operator const vtype() const { return m_elements; }
operator vtype() { return m_elements; }
bool operator==(const NDArrayBase<T>& other) const bool operator==(const NDArrayBase<T>& other) const
{ {
return m_shape == other.m_shape && m_elements == other.m_elements; return m_shape == other.m_shape && m_elements == other.m_elements;
......
...@@ -70,6 +70,11 @@ const Shape& TupleType::get_shape() const ...@@ -70,6 +70,11 @@ const Shape& TupleType::get_shape() const
throw ngraph_error("get_shape() called on Tuple"); throw ngraph_error("get_shape() called on Tuple");
} }
const element::Type& TupleType::get_element_type() const
{
throw ngraph_error("get_element_type() called on Tuple");
}
std::ostream& ngraph::operator<<(std::ostream& out, const ValueType& obj) std::ostream& ngraph::operator<<(std::ostream& out, const ValueType& obj)
{ {
out << "ValueType()"; out << "ValueType()";
......
...@@ -43,6 +43,7 @@ namespace ngraph ...@@ -43,6 +43,7 @@ namespace ngraph
virtual void collect_tensor_views( virtual void collect_tensor_views(
std::vector<std::shared_ptr<const TensorViewType>>& views) const = 0; std::vector<std::shared_ptr<const TensorViewType>>& views) const = 0;
virtual const Shape& get_shape() const = 0; virtual const Shape& get_shape() const = 0;
virtual const element::Type& get_element_type() const = 0;
friend std::ostream& operator<<(std::ostream&, const ValueType&); friend std::ostream& operator<<(std::ostream&, const ValueType&);
}; };
...@@ -59,7 +60,7 @@ namespace ngraph ...@@ -59,7 +60,7 @@ namespace ngraph
{ {
} }
const element::Type& get_element_type() const { return m_element_type; } virtual const element::Type& get_element_type() const override { return m_element_type; }
virtual const Shape& get_shape() const override { return m_shape; } virtual const Shape& get_shape() const override { return m_shape; }
virtual bool operator==(const ValueType& that) const override; virtual bool operator==(const ValueType& that) const override;
virtual void collect_tensor_views( virtual void collect_tensor_views(
...@@ -93,6 +94,8 @@ namespace ngraph ...@@ -93,6 +94,8 @@ namespace ngraph
return m_element_types; return m_element_types;
} }
virtual const element::Type& get_element_type() const override;
virtual bool operator==(const ValueType& that) const override; virtual bool operator==(const ValueType& that) const override;
virtual void collect_tensor_views( virtual void collect_tensor_views(
std::vector<std::shared_ptr<const TensorViewType>>& views) const override; std::vector<std::shared_ptr<const TensorViewType>>& views) const override;
......
...@@ -23,6 +23,7 @@ include_directories( ...@@ -23,6 +23,7 @@ include_directories(
set (SRC set (SRC
autodiff.cpp autodiff.cpp
copy.cpp
build_graph.cpp build_graph.cpp
eigen.cpp eigen.cpp
input_output_assign.cpp input_output_assign.cpp
......
This diff is collapsed.
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