Commit 22e2307b authored by Robert Kimball's avatar Robert Kimball

update clang-format to sort includes and rerun style

parent 7da5f65e
...@@ -44,3 +44,10 @@ SpacesInSquareBrackets: false ...@@ -44,3 +44,10 @@ SpacesInSquareBrackets: false
SortIncludes: false SortIncludes: false
ReflowComments: true ReflowComments: true
IncludeCategories:
- Regex: '^".*'
Priority: 3
- Regex: '^<.*'
Priority: 2
SortIncludes: true
...@@ -27,7 +27,10 @@ const ngraph::ElementType element_type_uint64_t = ngraph::ElementType(64, false, ...@@ -27,7 +27,10 @@ const ngraph::ElementType element_type_uint64_t = ngraph::ElementType(64, false,
std::map<std::string, ngraph::ElementType> ngraph::ElementType::m_element_list; std::map<std::string, ngraph::ElementType> ngraph::ElementType::m_element_list;
ngraph::ElementType::ElementType(size_t bitwidth, bool is_float, bool is_signed, const std::string& cname) ngraph::ElementType::ElementType(size_t bitwidth,
bool is_float,
bool is_signed,
const std::string& cname)
: m_bitwidth{bitwidth} : m_bitwidth{bitwidth}
, m_is_float{is_float} , m_is_float{is_float}
, m_is_signed{is_signed} , m_is_signed{is_signed}
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
#pragma once #pragma once
#include <string>
#include <map> #include <map>
#include <string>
namespace ngraph namespace ngraph
{ {
......
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
*/ */
#include <chrono> #include <chrono>
#include <condition_variable>
#include <ctime>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <ctime>
#include <thread>
#include <mutex> #include <mutex>
#include <condition_variable> #include <thread>
#include "log.hpp" #include "log.hpp"
......
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
#pragma once #pragma once
#include <deque>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
#include <deque>
namespace nervana namespace nervana
{ {
...@@ -36,7 +36,8 @@ namespace nervana ...@@ -36,7 +36,8 @@ namespace nervana
return i < _size ? _string[i] : throw std::out_of_range(""); return i < _size ? _string[i] : throw std::out_of_range("");
} }
constexpr const char* get_ptr(size_t offset) const { return &_string[offset]; } constexpr const char* get_ptr(size_t offset) const { return &_string[offset]; }
constexpr size_t size() const { return _size; } constexpr size_t size() const { return _size; }
private: private:
const char* _string; const char* _string;
size_t _size; size_t _size;
...@@ -44,8 +45,9 @@ namespace nervana ...@@ -44,8 +45,9 @@ namespace nervana
constexpr const char* find_last(conststring s, size_t offset, char ch) 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) return offset == 0
: find_last(s, offset - 1, ch)); ? 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) constexpr const char* find_last(conststring s, char ch)
...@@ -67,6 +69,7 @@ namespace nervana ...@@ -67,6 +69,7 @@ namespace nervana
~log_helper(); ~log_helper();
std::ostream& stream() { return _stream; } std::ostream& stream() { return _stream; }
private: private:
std::stringstream _stream; std::stringstream _stream;
}; };
...@@ -81,9 +84,9 @@ namespace nervana ...@@ -81,9 +84,9 @@ namespace nervana
static void stop(); static void stop();
private: private:
static void log_item(const std::string& s); static void log_item(const std::string& s);
static void process_event(const std::string& s); static void process_event(const std::string& s);
static void thread_entry(void* param); static void thread_entry(void* param);
static std::string log_path; static std::string log_path;
static std::deque<std::string> queue; static std::deque<std::string> queue;
}; };
......
...@@ -14,96 +14,94 @@ ...@@ -14,96 +14,94 @@
#pragma once #pragma once
#include <string>
#include <map> #include <map>
#include <string>
namespace ngraph 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 = "");
//================================================================================================ //!-----------------------------------------------------------------------------------
// NameableValue //! graph_label
// An Axis labels a dimension of a tensor. The op-graph uses //! The label used for drawings of the graph.
// the identity of Axis objects to pair and specify dimensions in //!-----------------------------------------------------------------------------------
// symbolic expressions. This system has several advantages over const std::string& graph_label();
// 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 //! name
//! The label used for drawings of the graph. //! Sets the object name to a unique name based on name.
//!----------------------------------------------------------------------------------- //!
const std::string& graph_label(); //! Arguments:
//! name: Prefix for the name
//!-----------------------------------------------------------------------------------
const std::string& name();
//!----------------------------------------------------------------------------------- //!-----------------------------------------------------------------------------------
//! name //! name
//! Sets the object name to a unique name based on name. //!-----------------------------------------------------------------------------------
//! void name(const std::string& name);
//! Arguments:
//! name: Prefix for the name
//!-----------------------------------------------------------------------------------
const std::string& name();
//!----------------------------------------------------------------------------------- //!-----------------------------------------------------------------------------------
//! name //! short_name
//!----------------------------------------------------------------------------------- //!-----------------------------------------------------------------------------------
void name(const std::string& name); const std::string& short_name();
//!----------------------------------------------------------------------------------- //!-----------------------------------------------------------------------------------
//! short_name //! named
//!----------------------------------------------------------------------------------- //!-----------------------------------------------------------------------------------
const std::string& short_name(); NameableValue& named(const std::string& name);
//!----------------------------------------------------------------------------------- static size_t __counter;
//! named static std::map<std::string, NameableValue> __all_names;
//!-----------------------------------------------------------------------------------
NameableValue& named(const std::string& name);
static size_t __counter; std::string m_name;
static std::map<std::string, NameableValue> __all_names; std::string m_graph_label;
std::string m_short_name;
std::string m_name; std::string m_doc_string;
std::string m_graph_label; };
std::string m_short_name;
std::string m_doc_string;
};
} // end namespace ngraph } // end namespace ngraph
#include <iostream>
#include <algorithm> #include <algorithm>
#include <iostream>
#include "strides.hpp" #include "strides.hpp"
#include "util.hpp" #include "util.hpp"
......
#pragma once #pragma once
#include <cstdio> #include <cstdio>
#include <vector>
#include <initializer_list> #include <initializer_list>
#include <vector>
#include "element_type.hpp" #include "element_type.hpp"
#include "tree.hpp" #include "tree.hpp"
......
#pragma once #pragma once
#include <algorithm>
#include <functional> #include <functional>
#include <vector>
#include <initializer_list> #include <initializer_list>
#include <iostream> #include <iostream>
#include <algorithm> #include <vector>
#include "util.hpp" #include "util.hpp"
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include <map>
#include <iomanip> #include <iomanip>
#include <map>
#include "util.hpp" #include "util.hpp"
......
...@@ -14,184 +14,184 @@ ...@@ -14,184 +14,184 @@
#pragma once #pragma once
#include <string>
#include <sstream>
#include <vector>
#include <chrono>
#include <algorithm> #include <algorithm>
#include <map> #include <chrono>
#include <iostream> #include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
namespace ngraph namespace ngraph
{ {
class stopwatch;
extern std::map<std::string, stopwatch*> stopwatch_statistics;
class stopwatch; template <typename T>
extern std::map<std::string, stopwatch*> stopwatch_statistics; std::string join(const T& v, const std::string& sep)
template <typename T>
std::string join(const T& v, const std::string& sep)
{
std::ostringstream ss;
for (const auto& x : v)
{ {
if (&x != &*(v.begin())) std::ostringstream ss;
for (const auto& x : v)
{ {
ss << sep; if (&x != &*(v.begin()))
{
ss << sep;
}
ss << x;
} }
ss << x; return ss.str();
} }
return ss.str();
}
template <typename U, typename T> template <typename U, typename T>
bool contains(const U& container, const T& obj) bool contains(const U& container, const T& obj)
{
bool rc = false;
for (auto o : container)
{ {
if (o == obj) bool rc = false;
for (auto o : container)
{ {
rc = true; if (o == obj)
break; {
rc = true;
break;
}
} }
return rc;
} }
return rc;
}
template <typename U, typename T> template <typename U, typename T>
bool contains_key(const U& container, const T& obj) bool contains_key(const U& container, const T& obj)
{
bool rc = false;
for (auto o : container)
{ {
if (o.first == obj) bool rc = false;
for (auto o : container)
{ {
rc = true; if (o.first == obj)
break; {
rc = true;
break;
}
} }
return rc;
} }
return rc;
}
template <typename U, typename T> template <typename U, typename T>
void remove_from(U& container, const T& obj) void remove_from(U& container, const T& obj)
{
auto it = container.find(obj);
if (it != container.end())
{ {
container.erase(it); auto it = container.find(obj);
if (it != container.end())
{
container.erase(it);
}
} }
}
size_t hash_combine(const std::vector<size_t>& list); size_t hash_combine(const std::vector<size_t>& list);
void dump(std::ostream& out, const void*, size_t); void dump(std::ostream& out, const void*, size_t);
std::string to_lower(const std::string& s); std::string to_lower(const std::string& s);
std::string trim(const std::string& s); std::string trim(const std::string& s);
std::vector<std::string> split(const std::string& s, char delimiter, bool trim = false); std::vector<std::string> split(const std::string& s, char delimiter, bool trim = false);
class stopwatch class stopwatch
{
public:
stopwatch() {}
stopwatch(const std::string& name)
: m_name{name}
{ {
stopwatch_statistics.insert({m_name, this}); public:
} stopwatch() {}
stopwatch(const std::string& name)
: m_name{name}
{
stopwatch_statistics.insert({m_name, this});
}
~stopwatch() ~stopwatch()
{
if (m_name.size() > 0)
{ {
stopwatch_statistics.find(m_name); if (m_name.size() > 0)
{
stopwatch_statistics.find(m_name);
}
} }
}
void start() void start()
{
if (m_active == false)
{ {
m_total_count++; if (m_active == false)
m_active = true; {
m_start_time = m_clock.now(); m_total_count++;
m_active = true;
m_start_time = m_clock.now();
}
} }
}
void stop() void stop()
{
if (m_active == true)
{ {
auto end_time = m_clock.now(); if (m_active == true)
m_last_time = end_time - m_start_time; {
m_total_time += m_last_time; auto end_time = m_clock.now();
m_active = false; m_last_time = end_time - m_start_time;
m_total_time += m_last_time;
m_active = false;
}
}
size_t get_call_count() const { return m_total_count; }
size_t get_seconds() const { return get_nanoseconds() / 1e9; }
size_t get_milliseconds() const { return get_nanoseconds() / 1e6; }
size_t get_microseconds() const { return get_nanoseconds() / 1e3; }
size_t get_nanoseconds() const
{
if (m_active)
{
return (m_clock.now() - m_start_time).count();
}
else
{
return m_last_time.count();
}
} }
}
size_t get_call_count() const { return m_total_count; } size_t get_total_seconds() const { return get_total_nanoseconds() / 1e9; }
size_t get_seconds() const { return get_nanoseconds() / 1e9; } size_t get_total_milliseconds() const { return get_total_nanoseconds() / 1e6; }
size_t get_milliseconds() const { return get_nanoseconds() / 1e6; } size_t get_total_microseconds() const { return get_total_nanoseconds() / 1e3; }
size_t get_microseconds() const { return get_nanoseconds() / 1e3; } size_t get_total_nanoseconds() const { return m_total_time.count(); }
size_t get_nanoseconds() const
private:
std::chrono::high_resolution_clock m_clock;
std::chrono::time_point<std::chrono::high_resolution_clock> m_start_time;
bool m_active = false;
std::chrono::nanoseconds m_total_time =
std::chrono::high_resolution_clock::duration::zero();
std::chrono::nanoseconds m_last_time;
size_t m_total_count = 0;
std::string m_name;
};
template <class InputIt, class BinaryOp>
typename std::iterator_traits<InputIt>::value_type
reduce(InputIt first, InputIt last, BinaryOp op)
{ {
if (m_active) typename std::iterator_traits<InputIt>::value_type result;
if (first == last)
{ {
return (m_clock.now() - m_start_time).count(); result = {};
} }
else else
{ {
return m_last_time.count(); result = *first++;
while (first != last)
{
result = op(result, *first);
first++;
}
} }
return result;
} }
size_t get_total_seconds() const { return get_total_nanoseconds() / 1e9; } template <typename T>
size_t get_total_milliseconds() const { return get_total_nanoseconds() / 1e6; } T plus(const T& a, const T& b)
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;
bool m_active = false;
std::chrono::nanoseconds m_total_time = std::chrono::high_resolution_clock::duration::zero();
std::chrono::nanoseconds m_last_time;
size_t m_total_count = 0;
std::string m_name;
};
template <class InputIt, class BinaryOp>
typename std::iterator_traits<InputIt>::value_type
reduce(InputIt first, InputIt last, BinaryOp op)
{
typename std::iterator_traits<InputIt>::value_type result;
if (first == last)
{ {
result = {}; return a + b;
} }
else
template <typename T>
T mul(const T& a, const T& b)
{ {
result = *first++; return a * b;
while (first != last)
{
result = op(result, *first);
first++;
}
} }
return result;
}
template <typename T>
T plus(const T& a, const T& b)
{
return a + b;
}
template <typename T>
T mul(const T& a, const T& b)
{
return a * b;
}
} // end namespace ngraph } // end namespace ngraph
...@@ -15,10 +15,10 @@ ...@@ -15,10 +15,10 @@
#pragma once #pragma once
#include <array> #include <array>
#include <random> #include <cstring>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <cstring> #include <random>
static std::mt19937_64 random_generator; static std::mt19937_64 random_generator;
......
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include <vector>
#include <string>
#include <sstream> #include <sstream>
#include <string>
#include <unordered_map> #include <unordered_map>
#include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include <vector>
#include <string>
#include <sstream> #include <sstream>
#include <string>
#include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include <vector>
#include <string>
#include <sstream> #include <sstream>
#include <string>
#include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include <iostream>
#include <chrono> #include <chrono>
#include <iostream>
#include "gtest/gtest.h" #include "gtest/gtest.h"
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include <vector>
#include <string>
#include <sstream> #include <sstream>
#include <string>
#include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include <vector>
#include <string>
#include <sstream> #include <sstream>
#include <string>
#include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
......
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include <vector>
#include <string>
#include <sstream> #include <sstream>
#include <string>
#include <unordered_map> #include <unordered_map>
#include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
......
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include <vector>
#include <string>
#include <sstream>
#include <memory> #include <memory>
#include <sstream>
#include <string>
#include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include <vector>
#include <string>
#include <sstream> #include <sstream>
#include <string>
#include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#include <vector>
#include <string>
#include <sstream> #include <sstream>
#include <string>
#include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
......
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