"...resnet50_tensorflow.git" did not exist on "2a3971dd29e3319558c67234eb2c955fa34c5ecd"
Commit 5fea4bba authored by Paul's avatar Paul
Browse files

Add custom exception

parent 10aff10b
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define RTG_GUARD_BUILTIN_HPP #define RTG_GUARD_BUILTIN_HPP
#include <rtg/operand.hpp> #include <rtg/operand.hpp>
#include <rtg/errors.hpp>
namespace rtg { namespace rtg {
...@@ -10,16 +11,16 @@ namespace builtin { ...@@ -10,16 +11,16 @@ namespace builtin {
struct literal struct literal
{ {
std::string name() const { return "@literal"; } std::string name() const { return "@literal"; }
shape compute_shape(std::vector<shape>) const { throw "builtin"; } shape compute_shape(std::vector<shape>) const { RTG_THROW("builtin"); }
argument compute(std::vector<argument>) const { throw "builtin"; } argument compute(std::vector<argument>) const { RTG_THROW("builtin"); }
}; };
struct param struct param
{ {
std::string parameter; std::string parameter;
std::string name() const { return "@param:" + parameter; } std::string name() const { return "@param:" + parameter; }
shape compute_shape(std::vector<shape>) const { throw "builtin"; } shape compute_shape(std::vector<shape>) const { RTG_THROW("builtin"); }
argument compute(std::vector<argument>) const { throw "builtin"; } argument compute(std::vector<argument>) const { RTG_THROW("builtin"); }
}; };
} // namespace builtin } // namespace builtin
......
#ifndef RTG_GUARD_ERRORS_HPP
#define RTG_GUARD_ERRORS_HPP
#include <exception>
#include <stdexcept>
#include <string>
namespace rtg {
struct exception : std::runtime_error
{
exception(std::string msg = "")
: std::runtime_error(msg)
{}
};
inline exception make_exception(std::string context, std::string message = "")
{
return {context + ": " + message};
}
inline std::string make_source_context(const std::string& file, int line)
{
return file + ":" + std::to_string(line);
}
#define RTG_THROW(...) \
throw rtg::make_exception(rtg::make_source_context(__FILE__, __LINE__), __VA_ARGS__)
} // namespace rtg
#endif
...@@ -9,7 +9,7 @@ namespace rtg { ...@@ -9,7 +9,7 @@ namespace rtg {
struct not_computable struct not_computable
{ {
argument compute(std::vector<argument>) const { throw std::runtime_error("not computable"); } argument compute(std::vector<argument>) const { RTG_THROW("not computable"); }
}; };
struct convolution struct convolution
...@@ -25,15 +25,15 @@ struct convolution ...@@ -25,15 +25,15 @@ struct convolution
shape compute_shape(std::vector<shape> inputs) const shape compute_shape(std::vector<shape> inputs) const
{ {
if(inputs.size() != 2) if(inputs.size() != 2)
throw std::runtime_error("Wrong number of arguments"); RTG_THROW("Wrong number of arguments");
const shape& input = inputs.at(0); const shape& input = inputs.at(0);
const shape& weights = inputs.at(1); const shape& weights = inputs.at(1);
if(input.type() != weights.type()) if(input.type() != weights.type())
throw std::runtime_error("Type doesn't match"); RTG_THROW("Type doesn't match");
if(input.lens().size() != weights.lens().size()) if(input.lens().size() != weights.lens().size())
throw std::runtime_error("Dimensions don't match"); RTG_THROW("Dimensions don't match");
if(input.lens().size() != 4) if(input.lens().size() != 4)
throw std::runtime_error("Only 4d convolution supported"); RTG_THROW("Only 4d convolution supported");
auto t = input.type(); auto t = input.type();
return {t, return {t,
...@@ -55,7 +55,7 @@ struct convolution ...@@ -55,7 +55,7 @@ struct convolution
}}; }};
} }
argument compute(std::vector<argument>) const { throw std::runtime_error("not computable"); } argument compute(std::vector<argument>) const { RTG_THROW("not computable"); }
}; };
struct pooling struct pooling
...@@ -72,10 +72,10 @@ struct pooling ...@@ -72,10 +72,10 @@ struct pooling
shape compute_shape(std::vector<shape> inputs) const shape compute_shape(std::vector<shape> inputs) const
{ {
if(inputs.empty()) if(inputs.empty())
throw std::runtime_error("Wrong number of arguments"); RTG_THROW("Wrong number of arguments");
const shape& input = inputs.at(0); const shape& input = inputs.at(0);
if(input.lens().size() != 4) if(input.lens().size() != 4)
throw std::runtime_error("Only 4d pooling supported"); RTG_THROW("Only 4d pooling supported");
auto t = input.type(); auto t = input.type();
return {t, return {t,
...@@ -95,7 +95,7 @@ struct pooling ...@@ -95,7 +95,7 @@ struct pooling
}}; }};
} }
argument compute(std::vector<argument>) const { throw std::runtime_error("not computable"); } argument compute(std::vector<argument>) const { RTG_THROW("not computable"); }
}; };
struct activation struct activation
...@@ -105,11 +105,11 @@ struct activation ...@@ -105,11 +105,11 @@ struct activation
shape compute_shape(std::vector<shape> inputs) const shape compute_shape(std::vector<shape> inputs) const
{ {
if(inputs.empty()) if(inputs.empty())
throw std::runtime_error("Wrong number of arguments"); RTG_THROW("Wrong number of arguments");
return inputs.front(); return inputs.front();
} }
argument compute(std::vector<argument>) const { throw std::runtime_error("not computable"); } argument compute(std::vector<argument>) const { RTG_THROW("not computable"); }
}; };
struct reshape struct reshape
...@@ -119,7 +119,7 @@ struct reshape ...@@ -119,7 +119,7 @@ struct reshape
shape compute_shape(std::vector<shape> inputs) const shape compute_shape(std::vector<shape> inputs) const
{ {
if(inputs.empty()) if(inputs.empty())
throw std::runtime_error("Wrong number of arguments"); RTG_THROW("Wrong number of arguments");
auto&& idims = inputs.front().lens(); auto&& idims = inputs.front().lens();
std::vector<std::size_t> rdims(dims.begin(), dims.end()); std::vector<std::size_t> rdims(dims.begin(), dims.end());
for(std::size_t i = 0; i < dims.size(); i++) for(std::size_t i = 0; i < dims.size(); i++)
...@@ -135,7 +135,7 @@ struct reshape ...@@ -135,7 +135,7 @@ struct reshape
return {inputs.front().type(), rdims}; return {inputs.front().type(), rdims};
} }
argument compute(std::vector<argument>) const { throw std::runtime_error("not computable"); } argument compute(std::vector<argument>) const { RTG_THROW("not computable"); }
}; };
} // namespace rtg } // namespace rtg
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include <cassert> #include <cassert>
#include <ostream> #include <ostream>
#include <rtg/errors.hpp>
namespace rtg { namespace rtg {
struct shape struct shape
...@@ -115,7 +117,7 @@ struct shape ...@@ -115,7 +117,7 @@ struct shape
RTG_SHAPE_VISIT_TYPES(RTG_SHAPE_VISITOR_CASE) RTG_SHAPE_VISIT_TYPES(RTG_SHAPE_VISITOR_CASE)
#undef RTG_SHAPE_VISITOR_CASE #undef RTG_SHAPE_VISITOR_CASE
} }
throw std::runtime_error("Unknown type"); RTG_THROW("Unknown type");
} }
private: private:
......
...@@ -96,7 +96,7 @@ std::string shape::type_string() const ...@@ -96,7 +96,7 @@ std::string shape::type_string() const
RTG_SHAPE_VISIT_TYPES(RTG_SHAPE_TYPE_STRING_CASE) RTG_SHAPE_VISIT_TYPES(RTG_SHAPE_TYPE_STRING_CASE)
#undef RTG_SHAPE_TYPE_STRING_CASE #undef RTG_SHAPE_TYPE_STRING_CASE
} }
throw "Invalid type"; RTG_THROW("Invalid type");
} }
bool operator==(const shape& x, const shape& y) bool operator==(const shape& x, const shape& y)
......
...@@ -11,13 +11,13 @@ struct sum_op ...@@ -11,13 +11,13 @@ struct sum_op
{ {
rtg::argument result; rtg::argument result;
if(args.size() != 2) if(args.size() != 2)
throw "Wrong args"; RTG_THROW("Wrong args");
if(args[0].get_shape() != args[1].get_shape()) if(args[0].get_shape() != args[1].get_shape())
throw "Wrong args"; RTG_THROW("Wrong args");
if(args[0].get_shape().lens().size() != 1) if(args[0].get_shape().lens().size() != 1)
throw "Wrong args"; RTG_THROW("Wrong args");
if(args[0].get_shape().lens().front() != 1) if(args[0].get_shape().lens().front() != 1)
throw "Wrong args"; RTG_THROW("Wrong args");
args[0].visit_at([&](auto x) { args[0].visit_at([&](auto x) {
args[1].visit_at([&](auto y) { result = rtg::literal{x + y}.get_argument(); }); args[1].visit_at([&](auto y) { result = rtg::literal{x + y}.get_argument(); });
...@@ -28,7 +28,7 @@ struct sum_op ...@@ -28,7 +28,7 @@ struct sum_op
rtg::shape compute_shape(std::vector<rtg::shape> inputs) const rtg::shape compute_shape(std::vector<rtg::shape> inputs) const
{ {
if(inputs.size() != 2) if(inputs.size() != 2)
throw "Wrong inputs"; RTG_THROW("Wrong inputs");
return inputs.front(); return inputs.front();
} }
}; };
......
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