-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated takane, vendored in chihaya.
- Loading branch information
Showing
64 changed files
with
2,871 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#ifndef CHIHAYA_BINARY_ARITHMETIC_HPP | ||
#define CHIHAYA_BINARY_ARITHMETIC_HPP | ||
|
||
#include "H5Cpp.h" | ||
#include "ritsuko/hdf5/hdf5.hpp" | ||
#include "ritsuko/ritsuko.hpp" | ||
|
||
#include <stdexcept> | ||
#include <vector> | ||
#include <string> | ||
|
||
#include "utils_public.hpp" | ||
#include "utils_arithmetic.hpp" | ||
#include "utils_misc.hpp" | ||
#include "utils_unary.hpp" | ||
|
||
/** | ||
* @file binary_arithmetic.hpp | ||
* @brief Validation for delayed binary arithmetic operations. | ||
*/ | ||
|
||
namespace chihaya { | ||
|
||
/** | ||
* @namespace chihaya::binary_arithmetic | ||
* @brief Namespace for delayed binary arithmetic operations. | ||
*/ | ||
namespace binary_arithmetic { | ||
|
||
/** | ||
* @param handle An open handle on a HDF5 group representing a binary arithmetic operation. | ||
* @param version Version of the **chihaya** specification. | ||
* @param state Validation state, passed to `validate()`. | ||
* | ||
* @return Details of the object after applying the arithmetic operation. | ||
* Otherwise, if the validation failed, an error is raised. | ||
*/ | ||
inline ArrayDetails validate(const H5::Group& handle, const ritsuko::Version& version, State& state) { | ||
auto left_details = internal_arithmetic::fetch_seed(handle, "left", version, state); | ||
auto right_details = internal_arithmetic::fetch_seed(handle, "right", version, state); | ||
|
||
bool okay = internal_misc::are_dimensions_equal(left_details.dimensions, right_details.dimensions); | ||
if (!okay) { | ||
throw std::runtime_error("'left' and 'right' should have the same dimensions"); | ||
} | ||
|
||
auto method = internal_unary::load_method(handle); | ||
if (!internal_arithmetic::is_valid_operation(method)) { | ||
throw std::runtime_error("unrecognized 'method' (" + method + ")"); | ||
} | ||
|
||
left_details.type = internal_arithmetic::determine_output_type(left_details.type, right_details.type, method); | ||
return left_details; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef CHIHAYA_BINARY_COMPARISON_HPP | ||
#define CHIHAYA_BINARY_COMPARISON_HPP | ||
|
||
#include "H5Cpp.h" | ||
#include "ritsuko/hdf5/hdf5.hpp" | ||
#include "ritsuko/ritsuko.hpp" | ||
|
||
#include <stdexcept> | ||
#include <vector> | ||
|
||
#include "utils_public.hpp" | ||
#include "utils_misc.hpp" | ||
#include "utils_comparison.hpp" | ||
#include "utils_unary.hpp" | ||
|
||
/** | ||
* @file binary_comparison.hpp | ||
* @brief Validation for delayed binary comparisons. | ||
*/ | ||
|
||
namespace chihaya { | ||
|
||
/** | ||
* @namespace chihaya::binary_comparison | ||
* @brief Namespace for delayed binary comparisons. | ||
*/ | ||
namespace binary_comparison { | ||
|
||
/** | ||
* @param handle An open handle on a HDF5 group representing a binary comparison. | ||
* @param version Version of the **chihaya** specification. | ||
* @param state Validation state, passed to `validate()`. | ||
* | ||
* @return Details of the object after applying the comparison operation. | ||
* Otherwise, if the validation failed, an error is raised. | ||
*/ | ||
inline ArrayDetails validate(const H5::Group& handle, const ritsuko::Version& version, State& state) { | ||
auto left_details = internal_misc::load_seed_details(handle, "left", version, state); | ||
auto right_details = internal_misc::load_seed_details(handle, "right", version, state); | ||
|
||
bool okay = internal_misc::are_dimensions_equal(left_details.dimensions, right_details.dimensions); | ||
if (!okay) { | ||
throw std::runtime_error("'left' and 'right' should have the same dimensions"); | ||
} | ||
|
||
if ((left_details.type == STRING) != (right_details.type == STRING)) { | ||
throw std::runtime_error("both or neither of 'left' and 'right' should contain strings"); | ||
} | ||
|
||
auto method = internal_unary::load_method(handle); | ||
if (!internal_comparison::is_valid_operation(method)) { | ||
throw std::runtime_error("unrecognized 'method' (" + method + ")"); | ||
} | ||
|
||
left_details.type = BOOLEAN; | ||
return left_details; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef CHIHAYA_BINARY_LOGIC_HPP | ||
#define CHIHAYA_BINARY_LOGIC_HPP | ||
|
||
#include "H5Cpp.h" | ||
#include "ritsuko/ritsuko.hpp" | ||
#include "ritsuko/hdf5/hdf5.hpp" | ||
|
||
#include <stdexcept> | ||
#include <vector> | ||
#include <string> | ||
|
||
#include "utils_public.hpp" | ||
#include "utils_logic.hpp" | ||
#include "utils_misc.hpp" | ||
|
||
/** | ||
* @file binary_logic.hpp | ||
* @brief Validation for delayed binary logical operations. | ||
*/ | ||
|
||
namespace chihaya { | ||
|
||
/** | ||
* @namespace chihaya::binary_logic | ||
* @brief Namespace for delayed binary logical operations. | ||
*/ | ||
namespace binary_logic { | ||
|
||
/** | ||
* @param handle An open handle on a HDF5 group representing a binary logical operation. | ||
* @param version Version of the **chihaya** specification. | ||
* @param state Validation state, passed to `validate()`. | ||
* | ||
* @return Details of the object after applying the logical operation. | ||
* Otherwise, if the validation failed, an error is raised. | ||
*/ | ||
inline ArrayDetails validate(const H5::Group& handle, const ritsuko::Version& version, State& state) { | ||
auto left_details = internal_logic::fetch_seed(handle, "left", version, state); | ||
auto right_details = internal_logic::fetch_seed(handle, "right", version, state); | ||
|
||
bool okay = internal_misc::are_dimensions_equal(left_details.dimensions, right_details.dimensions); | ||
if (!okay) { | ||
throw std::runtime_error("'left' and 'right' should have the same dimensions"); | ||
} | ||
|
||
auto method = internal_unary::load_method(handle); | ||
if (!internal_logic::is_valid_operation(method)) { | ||
throw std::runtime_error("unrecognized 'method' (" + method + ")"); | ||
} | ||
|
||
left_details.type = BOOLEAN; | ||
return left_details; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef CHIHAYA_HPP | ||
#define CHIHAYA_HPP | ||
|
||
/** | ||
* @file chihaya.hpp | ||
* | ||
* @brief Umbrella header for all **chihaya** code. | ||
*/ | ||
|
||
#include "validate.hpp" | ||
|
||
/** | ||
* @namespace chihaya | ||
* @brief Namespace for all **chihaya** functions. | ||
*/ | ||
namespace chihaya {} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#ifndef CHIHAYA_COMBINE_HPP | ||
#define CHIHAYA_COMBINE_HPP | ||
|
||
#include "H5Cpp.h" | ||
#include "ritsuko/ritsuko.hpp" | ||
#include "ritsuko/hdf5/hdf5.hpp" | ||
|
||
#include <stdexcept> | ||
#include <vector> | ||
#include <string> | ||
#include <cstdint> | ||
|
||
#include "utils_list.hpp" | ||
#include "utils_misc.hpp" | ||
|
||
/** | ||
* @file combine.hpp | ||
* @brief Validation for delayed combining operations. | ||
*/ | ||
|
||
namespace chihaya { | ||
|
||
/** | ||
* @cond | ||
*/ | ||
inline ArrayDetails validate(const H5::Group&, const ritsuko::Version&, State&); | ||
/** | ||
* @endcond | ||
*/ | ||
|
||
/** | ||
* @namespace chihaya::combine | ||
* @brief Namespace for delayed combining operations. | ||
*/ | ||
namespace combine { | ||
|
||
/** | ||
* @param handle An open handle on a HDF5 group representing a combining operation. | ||
* @param version Version of the **chihaya** specification. | ||
* @param state Validation state, passed to `validate()`. | ||
* | ||
* @return Details of the combined object. | ||
* Otherwise, if the validation failed, an error is raised. | ||
*/ | ||
inline ArrayDetails validate(const H5::Group& handle, const ritsuko::Version& version, State& state) { | ||
uint64_t along = internal_misc::load_along(handle, version); | ||
|
||
auto shandle = ritsuko::hdf5::open_group(handle, "seeds"); | ||
internal_list::ListDetails list_params; | ||
try { | ||
list_params = internal_list::validate(shandle, version); | ||
} catch (std::exception& e) { | ||
throw std::runtime_error(std::string("failed to load 'seeds' list; ") + e.what()); | ||
} | ||
if (list_params.present.size() != list_params.length) { | ||
throw std::runtime_error("missing elements in the 'seeds' list"); | ||
} | ||
|
||
std::vector<size_t> dimensions; | ||
ArrayType type = BOOLEAN; | ||
{ | ||
bool first = true; | ||
size_t num_strings = 0; | ||
|
||
for (const auto& p : list_params.present) { | ||
auto current = ritsuko::hdf5::open_group(shandle, p.second.c_str()); | ||
|
||
ArrayDetails cur_seed; | ||
try { | ||
cur_seed = ::chihaya::validate(current, version, state); | ||
} catch (std::exception& e) { | ||
throw std::runtime_error("failed to validate 'seeds/" + p.second + "'; " + std::string(e.what())); | ||
} | ||
|
||
if (first) { | ||
type = cur_seed.type; | ||
dimensions = cur_seed.dimensions; | ||
if (static_cast<size_t>(along) >= dimensions.size()) { | ||
throw std::runtime_error("'along' should be less than the seed dimensionality"); | ||
} | ||
first = false; | ||
} else { | ||
if (type < cur_seed.type) { | ||
type = cur_seed.type; | ||
} | ||
if (dimensions.size() != cur_seed.dimensions.size()) { | ||
throw std::runtime_error("dimensionality mismatch between seeds"); | ||
} | ||
for (size_t d = 0; d < dimensions.size(); ++d) { | ||
if (d == static_cast<size_t>(along)) { | ||
dimensions[d] += cur_seed.dimensions[d]; | ||
} else if (dimensions[d] != cur_seed.dimensions[d]) { | ||
throw std::runtime_error("inconsistent dimension extents between seeds"); | ||
} | ||
} | ||
} | ||
|
||
num_strings += (cur_seed.type == STRING); | ||
} | ||
|
||
if (num_strings != 0 && num_strings != list_params.length) { | ||
throw std::runtime_error("either none or all of the arrays to be combined should contain strings"); | ||
} | ||
} | ||
|
||
return ArrayDetails(type, std::move(dimensions)); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
#endif |
Oops, something went wrong.