Commit bfd9655f authored by Adam Procter's avatar Adam Procter

Remove 'undetermined' class, encode unknown dimension as max size_t value

parent 3b4584f7
...@@ -29,9 +29,9 @@ set (SRC ...@@ -29,9 +29,9 @@ set (SRC
descriptor/layout/tensor_layout.cpp descriptor/layout/tensor_layout.cpp
descriptor/output.cpp descriptor/output.cpp
descriptor/tensor.cpp descriptor/tensor.cpp
dimension.cpp
file_util.cpp file_util.cpp
function.cpp function.cpp
length.cpp
log.cpp log.cpp
node.cpp node.cpp
op/abs.cpp op/abs.cpp
...@@ -137,7 +137,6 @@ set (SRC ...@@ -137,7 +137,6 @@ set (SRC
pass/serialize.cpp pass/serialize.cpp
pass/zero_dim_tensor_elimination.cpp pass/zero_dim_tensor_elimination.cpp
pattern/matcher.cpp pattern/matcher.cpp
rank.cpp
runtime/aligned_buffer.cpp runtime/aligned_buffer.cpp
runtime/backend.cpp runtime/backend.cpp
runtime/backend_manager.cpp runtime/backend_manager.cpp
...@@ -147,7 +146,6 @@ set (SRC ...@@ -147,7 +146,6 @@ set (SRC
shape.cpp shape.cpp
strides.cpp strides.cpp
type/element_type.cpp type/element_type.cpp
undetermined.cpp
util.cpp util.cpp
graph_util.cpp graph_util.cpp
placement.cpp placement.cpp
......
...@@ -14,13 +14,18 @@ ...@@ -14,13 +14,18 @@
// limitations under the License. // limitations under the License.
//***************************************************************************** //*****************************************************************************
#include "ngraph/rank.hpp" #include <iostream>
#include <limits>
std::ostream& ngraph::operator<<(std::ostream& str, const Rank& rank) #include "ngraph/dimension.hpp"
using namespace ngraph;
std::ostream& ngraph::operator<<(std::ostream& str, const Dimension& dimension)
{ {
if (rank.is_determined()) if (dimension.is_determined())
{ {
return (str << size_t(rank)); return (str << size_t(dimension));
} }
else else
{ {
...@@ -28,12 +33,20 @@ std::ostream& ngraph::operator<<(std::ostream& str, const Rank& rank) ...@@ -28,12 +33,20 @@ std::ostream& ngraph::operator<<(std::ostream& str, const Rank& rank)
} }
} }
bool ngraph::operator==(const Rank& r1, const Rank& r2) Dimension ngraph::operator+(const Dimension& d1, const Dimension& d2)
{
return (d1.is_determined() && d2.is_determined() ? size_t(d1) + size_t(d2)
: Dimension::undetermined());
}
bool ngraph::operator==(const Dimension& d1, const Dimension& d2)
{ {
return (r1.is_determined() && r2.is_determined() && size_t(r1) == size_t(r2)); return (d1.is_determined() && d2.is_determined() && size_t(d1) == size_t(d2));
} }
bool ngraph::operator!=(const Rank& r1, const Rank& r2) bool ngraph::operator!=(const Dimension& d1, const Dimension& d2)
{ {
return (r1.is_determined() && r2.is_determined() && size_t(r1) != size_t(r2)); return (d1.is_determined() && d2.is_determined() && size_t(d1) != size_t(d2));
} }
const Dimension& Dimension::s_undetermined{};
...@@ -18,37 +18,33 @@ ...@@ -18,37 +18,33 @@
#pragma once #pragma once
#include <limits>
#include <stddef.h> #include <stddef.h>
#include "ngraph/undetermined.hpp"
namespace ngraph namespace ngraph
{ {
class Length class Dimension
{ {
public: public:
Length(size_t length) Dimension(size_t dimension)
: m_length(length) : m_dimension(dimension)
, m_is_determined(true)
{
}
Length(const Undetermined&)
: m_length(0)
, m_is_determined(false)
{ {
} }
Length() Dimension()
: m_length(0) : m_dimension(s_undetermined_val)
, m_is_determined(false)
{ {
} }
bool is_determined() const { return m_is_determined; } bool is_determined() const { return m_dimension != s_undetermined_val; }
explicit operator size_t() const { return m_length; } explicit operator size_t() const { return m_dimension; }
static const Dimension& undetermined() { return s_undetermined; }
private: private:
size_t m_length; size_t m_dimension;
bool m_is_determined; static const Dimension& s_undetermined;
static const size_t s_undetermined_val{std::numeric_limits<size_t>::max()};
}; };
std::ostream& operator<<(std::ostream& str, const Length& length); std::ostream& operator<<(std::ostream& str, const Dimension& dimension);
Length operator+(const Length& l1, const Length& l2); Dimension operator+(const Dimension& d1, const Dimension& d2);
bool operator==(const Dimension& d1, const Dimension& d2);
bool operator!=(const Dimension& d1, const Dimension& d2);
} }
//*****************************************************************************
// Copyright 2017-2018 Intel Corporation
//
// 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.
//*****************************************************************************
#include "ngraph/length.hpp"
std::ostream& ngraph::operator<<(std::ostream& str, const Length& length)
{
if (length.is_determined())
{
return (str << size_t(length));
}
else
{
return (str << "?");
}
}
ngraph::Length ngraph::operator+(const Length& l1, const Length& l2)
{
return (l1.is_determined() && l2.is_determined() ? size_t(l1) + size_t(l2)
: Length(undetermined));
}
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
//***************************************************************************** //*****************************************************************************
#include <algorithm> #include <algorithm>
#include <iostream>
#include <vector> #include <vector>
#include "ngraph/partial_shape.hpp" #include "ngraph/partial_shape.hpp"
...@@ -23,16 +24,17 @@ using namespace ngraph; ...@@ -23,16 +24,17 @@ using namespace ngraph;
bool ngraph::PartialShape::is_complete() const bool ngraph::PartialShape::is_complete() const
{ {
return m_rank_is_determined && std::all_of(m_lengths.begin(), return m_rank_is_determined &&
m_lengths.end(), std::all_of(m_dimensions.begin(), m_dimensions.end(), [](const Dimension& d) {
[](const Length& l) { return l.is_determined(); }); return d.is_determined();
});
} }
ngraph::PartialShape ngraph::operator+(const PartialShape& s1, const PartialShape& s2) PartialShape ngraph::operator+(const PartialShape& s1, const PartialShape& s2)
{ {
if (!s1.rank_is_determined() || !s2.rank_is_determined()) if (!s1.rank_is_determined() || !s2.rank_is_determined())
{ {
return undetermined; return PartialShape::undetermined();
} }
if (s1.rank() != s2.rank()) if (s1.rank() != s2.rank())
...@@ -42,9 +44,9 @@ ngraph::PartialShape ngraph::operator+(const PartialShape& s1, const PartialShap ...@@ -42,9 +44,9 @@ ngraph::PartialShape ngraph::operator+(const PartialShape& s1, const PartialShap
PartialShape result{}; PartialShape result{};
result.m_rank_is_determined = true; result.m_rank_is_determined = true;
for (size_t i = 0; i < s1.m_lengths.size(); i++) for (size_t i = 0; i < s1.m_dimensions.size(); i++)
{ {
result.m_lengths.push_back(s1.m_lengths[i] + s2.m_lengths[i]); result.m_dimensions.push_back(s1.m_dimensions[i] + s2.m_dimensions[i]);
} }
return result; return result;
} }
...@@ -55,13 +57,13 @@ std::ostream& ngraph::operator<<(std::ostream& str, const PartialShape& shape) ...@@ -55,13 +57,13 @@ std::ostream& ngraph::operator<<(std::ostream& str, const PartialShape& shape)
{ {
str << "{"; str << "{";
bool first = true; bool first = true;
for (auto& l : shape.m_lengths) for (auto& d : shape.m_dimensions)
{ {
if (!first) if (!first)
{ {
str << ","; str << ",";
} }
str << l; str << d;
first = false; first = false;
} }
return (str << "}"); return (str << "}");
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include <stddef.h> #include <stddef.h>
#include "ngraph/length.hpp" #include "ngraph/dimension.hpp"
#include "ngraph/rank.hpp" #include "ngraph/rank.hpp"
namespace ngraph namespace ngraph
...@@ -28,26 +28,28 @@ namespace ngraph ...@@ -28,26 +28,28 @@ namespace ngraph
class PartialShape class PartialShape
{ {
public: public:
PartialShape(std::initializer_list<Length> init) PartialShape(std::initializer_list<Dimension> init)
: m_rank_is_determined(true) : PartialShape(true, init)
, m_lengths(init)
{
}
PartialShape(const Undetermined&)
: m_rank_is_determined(false)
, m_lengths()
{ {
} }
bool rank_is_determined() const { return m_rank_is_determined; } bool rank_is_determined() const { return m_rank_is_determined; }
bool is_complete() const; bool is_complete() const;
Rank rank() const { return m_rank_is_determined ? Rank(m_lengths.size()) : undetermined; } Rank rank() const
{
return m_rank_is_determined ? Rank(m_dimensions.size()) : Rank::undetermined();
}
friend std::ostream& operator<<(std::ostream& str, const PartialShape& shape); friend std::ostream& operator<<(std::ostream& str, const PartialShape& shape);
friend PartialShape operator+(const PartialShape& s1, const PartialShape& s2); friend PartialShape operator+(const PartialShape& s1, const PartialShape& s2);
PartialShape append(const PartialShape& other); PartialShape append(const PartialShape& other);
static PartialShape undetermined() { return PartialShape(false, {}); }
private: private:
PartialShape(bool rank_is_determined, std::initializer_list<Dimension> init)
: m_rank_is_determined(rank_is_determined)
, m_dimensions(init)
{
}
bool m_rank_is_determined; bool m_rank_is_determined;
std::vector<Length> m_lengths; std::vector<Dimension> m_dimensions;
}; };
PartialShape operator+(const PartialShape& s1, const PartialShape& s2); PartialShape operator+(const PartialShape& s1, const PartialShape& s2);
......
...@@ -14,42 +14,11 @@ ...@@ -14,42 +14,11 @@
// limitations under the License. // limitations under the License.
//***************************************************************************** //*****************************************************************************
// XXX: THIS CLASS IS NOT IN USE YET AND THE ENTIRE DESIGN IS SUBJECT TO CHANGE.
#pragma once #pragma once
#include <stddef.h> #include "ngraph/dimension.hpp"
#include "ngraph/undetermined.hpp"
namespace ngraph namespace ngraph
{ {
class Rank using Rank = Dimension;
{
public:
Rank(size_t rank)
: m_rank(rank)
, m_is_determined(true)
{
}
Rank(const Undetermined&)
: m_rank(0)
, m_is_determined(false)
{
}
Rank()
: m_rank(0)
, m_is_determined(false)
{
}
bool is_determined() const { return m_is_determined; }
explicit operator size_t() const { return m_rank; }
private:
size_t m_rank;
bool m_is_determined;
};
std::ostream& operator<<(std::ostream& str, const Rank& rank);
bool operator==(const Rank& r1, const Rank& r2);
bool operator!=(const Rank& r1, const Rank& r2);
} }
//*****************************************************************************
// Copyright 2017-2018 Intel Corporation
//
// 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.
//*****************************************************************************
#include "ngraph/undetermined.hpp"
using namespace ngraph;
const Undetermined ngraph::undetermined{};
//*****************************************************************************
// Copyright 2017-2018 Intel Corporation
//
// 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.
//*****************************************************************************
// XXX: THIS CLASS IS NOT IN USE YET AND THE ENTIRE DESIGN IS SUBJECT TO CHANGE.
#pragma once
#include <iostream>
namespace ngraph
{
class Undetermined
{
public:
Undetermined() {}
};
extern const Undetermined undetermined;
}
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