Commit 6b1ea2a1 authored by Robert Kimball's avatar Robert Kimball Committed by Scott Cyphers

remove unused files (#143)

parent 8156e3e0
// ----------------------------------------------------------------------------
// 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 "ngraph.hpp"
#include "log.hpp"
NGraph* create_ngraph_object()
{
return new NGraph();
}
void destroy_ngraph_object(NGraph* pObj)
{
delete pObj;
}
void NGraph::add_params(const std::vector<std::string>& paramList)
{
NGRAPH_INFO << "Adding parameters";
m_params.insert(m_params.end(), paramList.begin(), paramList.end());
}
const std::vector<std::string>& NGraph::get_params() const
{
return m_params;
}
#pragma once
// ----------------------------------------------------------------------------
// 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 <string>
#include <vector>
class NGraph
{
public:
void add_params(const std::vector<std::string>& paramList);
const std::vector<std::string>& get_params() const;
std::string get_name() const { return "NGraph Implementation Object"; }
private:
std::vector<std::string> m_params;
};
// Factory methods
extern "C" NGraph* create_ngraph_object();
extern "C" void destroy_ngraph_object(NGraph* pObj);
// FUnction pointers to the factory methods
typedef NGraph* (*CreateNGraphObjPfn)();
typedef void (*DestroyNGraphObjPfn)(NGraph*);
// ----------------------------------------------------------------------------
// 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 <sstream>
#include "names.hpp"
using namespace ngraph;
size_t NameableValue::__counter = 0;
std::map<std::string, NameableValue> NameableValue::__all_names;
NameableValue::NameableValue(const std::string& name,
const std::string& graph_label_type,
const std::string& doc_string)
: m_name{name}
, m_doc_string{doc_string}
{
auto glt = m_name;
if (graph_label_type.size() > 0)
{
glt = graph_label_type;
}
{
std::stringstream ss;
ss << glt << "[" << m_name << "]";
m_graph_label = ss.str();
}
}
const std::string& NameableValue::graph_label()
{
return m_graph_label;
}
const std::string& NameableValue::name()
{
return m_name;
}
void NameableValue::name(const std::string& name)
{
// if name == type(self).__name__ or name in NameableValue.__all_names:
// while True:
// c_name = "{}_{}".format(name, type(self).__counter)
// if c_name not in NameableValue.__all_names:
// name = c_name
// break
// type(self).__counter += 1
// NameableValue.__all_names[name] = self
// self.__name = name
}
const std::string& NameableValue::short_name()
{
// sn = self.name.split('_')[0]
// if sn.find('.') != -1:
// sn = sn.split('.')[1]
// return sn
static const std::string x = "unimplemented";
return x;
}
NameableValue& NameableValue::named(const std::string& name)
{
m_name = name;
return *this;
}
// ----------------------------------------------------------------------------
// 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
// ----------------------------------------------------------------------------
#pragma once
#include <map>
#include <string>
namespace ngraph
{
//================================================================================================
// NameableValue
// An Axis labels a dimension of a tensor. The op-graph uses
// the identity of Axis objects to pair and specify dimensions in
// symbolic expressions. This system has several advantages over
// using the length and position of the axis as in other frameworks:
//
// 1) Convenience. The dimensions of tensors, which may be nested
// deep in a computation graph, can be specified without having to
// calculate their lengths.
//
// 2) Safety. Axis labels are analogous to types in general-purpose
// programming languages, allowing objects to interact only when
// they are permitted to do so in advance. In symbolic computation,
// this prevents interference between axes that happen to have the
// same lengths but are logically distinct, e.g. if the number of
// training examples and the number of input features are both 50.
//
// TODO: Please add to the list...
//
// Arguments:
// length: The length of the axis.
// batch: Whether the axis is a batch axis.
// recurrent: Whether the axis is a recurrent axis.
//================================================================================================
class NameableValue
{
public:
//!-----------------------------------------------------------------------------------
//! NameableValue
//! An object that can be named.
//!
//! Arguments:
//! graph_label_type: A label that should be used when drawing the graph. Defaults to
//! the class name.
//! name (str): The name of the object.
//! **kwargs: Parameters for related classes.
//!
//! Attributes:
//! graph_label_type: A label that should be used when drawing the graph.
//! id: Unique id for this object.
//!-----------------------------------------------------------------------------------
NameableValue(const std::string& name,
const std::string& graph_label_type = "",
const std::string& doc_string = "");
//!-----------------------------------------------------------------------------------
//! graph_label
//! The label used for drawings of the graph.
//!-----------------------------------------------------------------------------------
const std::string& graph_label();
//!-----------------------------------------------------------------------------------
//! name
//! Sets the object name to a unique name based on name.
//!
//! Arguments:
//! name: Prefix for the name
//!-----------------------------------------------------------------------------------
const std::string& name();
//!-----------------------------------------------------------------------------------
//! name
//!-----------------------------------------------------------------------------------
void name(const std::string& name);
//!-----------------------------------------------------------------------------------
//! short_name
//!-----------------------------------------------------------------------------------
const std::string& short_name();
//!-----------------------------------------------------------------------------------
//! named
//!-----------------------------------------------------------------------------------
NameableValue& named(const std::string& name);
static size_t __counter;
static std::map<std::string, NameableValue> __all_names;
std::string m_name;
std::string m_graph_label;
std::string m_short_name;
std::string m_doc_string;
};
} // end namespace ngraph
#include <algorithm>
#include <iostream>
#include "strides.hpp"
#include "util.hpp"
using namespace std;
//================================================================================================
//
//================================================================================================
ngraph::tensor_size::tensor_size()
: m_tree{}
, m_element_type{element_type_float}
{
}
ngraph::tensor_size::tensor_size(size_t s, ElementType et)
: m_tree{s}
, m_element_type{et}
{
}
ngraph::tensor_size::tensor_size(const std::initializer_list<scalar_tree>& list, ElementType et)
: m_tree{list}
, m_element_type{et}
{
}
ngraph::tensor_size::tensor_size(const std::vector<size_t>& list, const ElementType& et)
: m_tree{list}
, m_element_type{et}
{
}
ngraph::tensor_stride ngraph::tensor_size::full_strides() const
{
tensor_stride result{*this};
vector<size_t*> value_pointer_list;
vector<size_t> size_list;
scalar_tree::traverse_tree(result.m_tree, [&](size_t* value) {
value_pointer_list.push_back(value);
size_list.push_back(*value);
});
int index = value_pointer_list.size() - 1;
*value_pointer_list[index] = result.m_element_type.size();
for (index--; index >= 0; index--)
{
*value_pointer_list[index] = *value_pointer_list[index + 1] * size_list[index + 1];
}
return result;
}
ngraph::tensor_stride ngraph::tensor_size::strides() const
{
return full_strides().strides();
}
ngraph::tensor_size ngraph::tensor_size::sizes() const
{
vector<size_t> tmp;
if (m_tree.is_list())
{
for (auto s : m_tree.get_list())
{
tmp.push_back(s.reduce([](size_t a, size_t b) { return a * b; }));
}
}
else
{
tmp.push_back(m_tree.get_value());
}
return tensor_size(tmp, m_element_type);
}
std::ostream& ngraph::operator<<(std::ostream& out, const ngraph::tensor_size& s)
{
out << s.m_tree;
return out;
}
//================================================================================================
//
//================================================================================================
ngraph::tensor_stride::tensor_stride()
: m_tree{}
, m_element_type{element_type_float}
{
}
ngraph::tensor_stride::tensor_stride(const tensor_size& s)
: m_tree{}
, m_element_type{s.m_element_type}
{
m_tree = s.m_tree;
}
ngraph::tensor_stride::tensor_stride(const std::vector<size_t>& list, const ElementType& et)
: m_tree{}
, m_element_type{et}
{
m_tree = list;
}
ngraph::tensor_stride ngraph::tensor_stride::reduce_strides() const
{
vector<size_t> tmp;
if (m_tree.is_list())
{
for (auto s : m_tree.get_list())
{
tmp.push_back(s.reduce([](size_t a, size_t b) { return min(a, b); }));
}
}
else
{
tmp.push_back(m_tree.get_value());
}
return tensor_stride(tmp, m_element_type);
}
ngraph::tensor_stride ngraph::tensor_stride::full_strides() const
{
return *this;
}
ngraph::tensor_stride ngraph::tensor_stride::strides() const
{
return reduce_strides();
}
std::ostream& ngraph::operator<<(std::ostream& out, const ngraph::tensor_stride& s)
{
out << s.m_tree;
return out;
}
#pragma once
#include <cstdio>
#include <initializer_list>
#include <vector>
#include "element_type.hpp"
#include "tree.hpp"
namespace ngraph
{
class tensor_size;
class tensor_stride;
}
//================================================================================================
//
//================================================================================================
class ngraph::tensor_size
{
friend class tensor_stride;
public:
tensor_size();
tensor_size(size_t s, ElementType et = element_type_float);
tensor_size(const std::initializer_list<scalar_tree>& list,
ElementType et = element_type_float);
const ElementType& get_type() const { return m_element_type; }
tensor_stride full_strides() const;
tensor_stride strides() const;
tensor_size sizes() const;
tensor_size operator[](size_t index) const;
friend std::ostream& operator<<(std::ostream& out, const tensor_size& s);
private:
tensor_size(const std::vector<size_t>&, const ElementType&);
scalar_tree m_tree;
ElementType m_element_type;
};
//================================================================================================
//
//================================================================================================
class ngraph::tensor_stride
{
friend class tensor_size;
public:
tensor_stride();
const ElementType& get_type() const { return m_element_type; }
tensor_stride full_strides() const;
tensor_stride strides() const;
tensor_stride reduce_strides() const;
tensor_stride operator[](size_t index) const;
friend std::ostream& operator<<(std::ostream& out, const tensor_stride& s);
private:
tensor_stride(const tensor_size&);
tensor_stride(const std::vector<size_t>&, const ElementType&);
scalar_tree m_tree;
ElementType m_element_type;
};
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// ----------------------------------------------------------------------------
// 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
// ----------------------------------------------------------------------------
#pragma once
#include <map>
#include <memory>
#include <sstream>
#include <string>
#include <type_traits>
#include <vector>
#include "element_type.hpp"
namespace ngraph
{
class ExecutionState;
class Op;
// class TensorDescription;
class ComputationOp;
using computation_op_ptr = std::shared_ptr<ComputationOp>;
using op_ptr = std::shared_ptr<Op>;
using scalar_t = float;
//================================================================================================
// TensorInterface
//================================================================================================
class TensorInterface
{
public:
virtual ~TensorInterface() {}
virtual const ElementType& element_type() const = 0;
virtual std::string value_string() const = 0;
};
//================================================================================================
// Tensor
//================================================================================================
template <typename T>
class Tensor : public TensorInterface
{
public:
Tensor(const T& val)
: m_value{val}
, m_element_type{element_type_float}
{
}
virtual ~Tensor() {}
const ElementType& element_type() const override { return m_element_type; }
std::string value_string() const override
{
std::string rc = "WTF";
if (std::is_floating_point<T>::value)
{
std::stringstream ss;
ss << m_value;
rc = ss.str();
}
return rc;
}
private:
T m_value;
ElementType m_element_type;
};
//================================================================================================
// Transformer
//================================================================================================
class Transformer
{
public:
virtual ~Transformer() {}
virtual ExecutionState& execution_state() = 0;
};
//================================================================================================
// TensorDescription
//================================================================================================
// class TensorDescription
// {
// public:
// virtual ~TensorDescription();
// virtual axes_key_t axes_key() const = 0;
// virtual std::string name() const = 0;
// virtual std::vector<size_t> shape() const = 0;
// virtual std::shared_ptr<TensorDescription> base() = 0;
// virtual ElementType element_type() const = 0;
// virtual size_t tensor_size() = 0;
// virtual bool is_persistent() = 0;
// virtual bool is_input() = 0;
// };
//================================================================================================
// Op
//================================================================================================
// class Op
// {
// // Any operation that can be in an AST.
// // Arguments:
// // args: Values used by this node.
// // const: The value of a constant Op, or None,
// // constant (bool): The Op is constant. Default False.
// // forward: If not None, the node to use instead of this node.
// // metadata: String key value dictionary for frontend metadata.
// // kwargs: Args defined in related classes.
// // Attributes:
// // const: The value of a constant.
// // constant (bool): The value is constant.
// // control_deps (OrderedSet): Ops in addtion to args that must run before this op.
// // persistent (bool): The value will be retained from computation to computation and
// // not shared. Always True if reference is set.
// // metadata: Dictionary with of string keys and values used for attaching
// // arbitrary metadata to nodes.
// // trainable: The value is trainable.
// public:
// virtual ~Op() {}
// virtual std::string name() const = 0;
// virtual tensor_description_ptr tensor_description() = 0;
// virtual op_ptr tensor() = 0;
// virtual bool is_tensor_op() = 0;
// virtual bool is_state_op() const = 0;
// virtual bool is_sequencing_op() const = 0;
// virtual op_ptr effective_tensor_op() = 0;
// virtual const std::vector<op_ptr>& all_deps() const = 0;
// // ops
// // TODO support multiple types
// static op_ptr constant(float value)
// {
// op_ptr = make_shared<LiteralScalarOp>(value);
// }
// };
//================================================================================================
// TensorOp
//================================================================================================
// class TensorOp : public Op
// {
// public:
// std::string name() const override { return "TensorOp"; }
// tensor_description_ptr tensor_description() override { return nullptr; }
// op_ptr tensor() override { return nullptr; }
// bool is_tensor_op() override { return true; }
// bool is_state_op() const override { return false; }
// op_ptr effective_tensor_op() override { return nullptr; }
// const std::vector<op_ptr>& all_deps() const override { return m_all_deps; }
// private:
// std::vector<op_ptr> m_all_deps;
// };
} // end of namespace ngraph
// ----------------------------------------------------------------------------
// 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 "mock_transformer.hpp"
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include "ngraph/tree.hpp"
#include "ngraph/util.hpp"
//================================================================================================
//
//================================================================================================
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