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