Commit f03b2c20 authored by Adam Procter's avatar Adam Procter

Review comment

parent 7da2eae4
......@@ -16,11 +16,25 @@
#include <iostream>
#include <limits>
#include <sstream>
#include "ngraph/dimension.hpp"
using namespace ngraph;
Dimension::Dimension(size_t dimension)
: m_dimension(dimension)
{
if (dimension == s_undetermined_val)
{
std::stringstream ss;
ss << "Cannot convert the value 0x" << std::uppercase << std::hex << s_undetermined_val
<< " to Dimension: this value is used internally to represent an undetermined "
"dimension.";
throw std::invalid_argument(ss.str());
}
}
std::ostream& ngraph::operator<<(std::ostream& str, const Dimension& dimension)
{
if (dimension.is_determined())
......
......@@ -32,17 +32,9 @@ namespace ngraph
public:
/// \brief Constructs a known dimension.
///
/// Requires that size_t != std::numeric_limits<size_t>::max(). If that condition
/// does not hold, throws std::invalid_argument.
Dimension(size_t dimension)
: m_dimension(dimension)
{
if (dimension == s_undetermined_val)
{
throw std::invalid_argument(
"Cannot convert std::numeric_limits<size_t>::max() to Dimension");
}
}
/// Requires that dimension != s_undetermined_val. If that condition does not hold,
/// throws std::invalid_argument.
Dimension(size_t dimension);
/// \brief Constructs an unknown dimension.
Dimension() { m_dimension = s_undetermined_val; }
......@@ -64,13 +56,13 @@ namespace ngraph
bool compatible(const Dimension& d) const;
/// \brief Constructs an unknown dimension.
static Dimension undetermined() { return Dimension(); }
/// \brief Constant for the value used internally to represent an unknown dimension.
static const size_t s_undetermined_val{std::numeric_limits<size_t>::max()};
private:
// The actual numerical value of the dimension. s_undetermined_val is a special case,
// representing an unknown dimension.
size_t m_dimension;
// Constant for the size_t value used to represent an unknown dimension.
static const size_t s_undetermined_val{std::numeric_limits<size_t>::max()};
};
/// \brief Inserts a human-readable representation of "dimension" into "str".
......
......@@ -71,7 +71,7 @@ TEST(partial_shape, dim_construction_undetermined)
TEST(partial_shape, dim_construction_size_t_max)
{
EXPECT_ANY_THROW({ Dimension d{std::numeric_limits<size_t>::max()}; });
EXPECT_ANY_THROW({ Dimension d{Dimension::s_undetermined_val}; });
}
TEST(partial_shape, dim_conversion_determined)
......
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