Skip to content

Commit

Permalink
Merge pull request #134 from pfnet-research/modify_error_in_vpt_building
Browse files Browse the repository at this point in the history
input_not_found exception and output_not_found exception are added
  • Loading branch information
okdshin authored Oct 12, 2018
2 parents 1232129 + 30a42fa commit a14552e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
6 changes: 6 additions & 0 deletions include/menoh/menoh.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ enum menoh_error_code_constant {
menoh_error_code_same_named_parameter_already_exist,
menoh_error_code_same_named_attribute_already_exist,
menoh_error_code_invalid_backend_config_error,
menoh_error_code_input_not_found_error,
menoh_error_code_output_not_found_error,
};
typedef int32_t menoh_error_code;
/*! \brief Users can get detailed message about last error.
Expand Down Expand Up @@ -268,6 +270,10 @@ typedef struct menoh_variable_profile_table*
menoh_variable_profile_table_handle;

/*! \brief Factory function for variable_profile_table
*
* \note this function throws menoh_input_not_found_error when no nodes have given input name.
* \note this function throws menoh_output_not_found_error when no nodes have given output name.
* \note this function throws menoh_variable_not_found_error when needed variable for model execution does not exist.
*/
menoh_error_code MENOH_API menoh_build_variable_profile_table(
const menoh_variable_profile_table_builder_handle builder,
Expand Down
7 changes: 5 additions & 2 deletions menoh/attribute_completion_and_shape_inference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <menoh/array.hpp>
#include <menoh/model_data.hpp>
#include <menoh/utility.hpp>

namespace menoh_impl {
inline auto complete_attribute_and_infer_shape(
Expand All @@ -32,8 +33,10 @@ namespace menoh_impl {
p.first,
array_profile(p.second.dtype(), p.second.dims())); });
auto profile_of = [&variable_profile_table](std::string const& name){
assert(variable_profile_table.find(name) !=
variable_profile_table.end());
if(variable_profile_table.find(name) ==
variable_profile_table.end()) {
throw variable_not_found(name);
}
return variable_profile_table.at(name);
};
auto dims_of = [&variable_profile_table, profile_of](
Expand Down
44 changes: 42 additions & 2 deletions menoh/menoh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ namespace menoh_impl {

#undef MENOH_ERROR_MESSAGE_MAX_LENGTH

namespace menoh_impl {
class input_not_found : public exception {
public:
input_not_found(std::string const& input_name)
: exception(menoh_error_code_input_not_found_error,
"menoh input not found error: " + input_name) {}
};
class output_not_found : public exception {
public:
output_not_found(std::string const& output_name)
: exception(menoh_error_code_output_not_found_error,
"menoh output not found error: " + output_name) {}
};
} // namespace menoh_impl

const char* menoh_get_last_error_message() {
return menoh_impl::get_error_message_singleton().data();
}
Expand Down Expand Up @@ -328,9 +343,34 @@ menoh_error_code menoh_build_variable_profile_table(
input_profile_table(builder->input_name_and_profile_list.begin(),
builder->input_name_and_profile_list.end());

std::set<std::string> given_input_name_set;
for(auto const& p : input_profile_table) {
given_input_name_set.insert(p.first);
}
std::set<std::string> model_input_name_set;
for(auto const& node : model_data->model_data.node_list) {
model_input_name_set.insert(node.input_name_list.begin(),
node.input_name_list.end());
}
std::vector<std::string> diff;
std::set_difference(
given_input_name_set.begin(), given_input_name_set.end(),
model_input_name_set.begin(), model_input_name_set.end(),
std::back_inserter(diff));
if(!diff.empty()) {
throw menoh_impl::input_not_found(diff.front());
}

auto output_profile_table =
menoh_impl::complete_attribute_and_infer_shape(
model_data->model_data, input_profile_table);
menoh_impl::complete_attribute_and_infer_shape(model_data->model_data,
input_profile_table);

for(auto const& output_name : builder->required_output_name_list) {
if(output_profile_table.find(output_name) ==
output_profile_table.end()) {
throw menoh_impl::output_not_found(output_name);
}
}

*dst_handle =
std::make_unique<menoh_variable_profile_table>(
Expand Down
7 changes: 5 additions & 2 deletions scripts/gen_attribute_completion_and_shape_inference_hpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def main():
#include <menoh/array.hpp>
#include <menoh/model_data.hpp>
#include <menoh/utility.hpp>
namespace menoh_impl {{
inline auto complete_attribute_and_infer_shape(
Expand All @@ -100,8 +101,10 @@ def main():
p.first,
array_profile(p.second.dtype(), p.second.dims())); }});
auto profile_of = [&variable_profile_table](std::string const& name){{
assert(variable_profile_table.find(name) !=
variable_profile_table.end());
if(variable_profile_table.find(name) ==
variable_profile_table.end()) {{
throw variable_not_found(name);
}}
return variable_profile_table.at(name);
}};
auto dims_of = [&variable_profile_table, profile_of](
Expand Down

0 comments on commit a14552e

Please sign in to comment.