1#ifndef CHIHAYA_MATRIX_PRODUCT_HPP
2#define CHIHAYA_MATRIX_PRODUCT_HPP
5#include "ritsuko/ritsuko.hpp"
10#include "utils_misc.hpp"
23namespace matrix_product {
30inline std::pair<ArrayDetails, bool> fetch_seed(
const H5::Group& handle,
const std::string& target,
const std::string& orientation,
const ritsuko::Version& version, Options& options) {
32 auto seed_details = internal_misc::load_seed_details(handle, target, version, options);
33 if (seed_details.dimensions.size() != 2) {
34 throw std::runtime_error(
"expected '" + target +
"' to be a 2-dimensional array for a matrix product");
36 if (seed_details.type == STRING) {
37 throw std::runtime_error(std::string(
"type of '") + target +
"' should be integer, float or boolean for a matrix product");
41 auto oristr = internal_misc::load_scalar_string_dataset(handle, orientation);
42 if (oristr !=
"N" && oristr !=
"T") {
43 throw std::runtime_error(
"'" + orientation +
"' should be either 'N' or 'T' for a matrix product");
46 return std::pair<ArrayDetails, bool>(seed_details, oristr ==
"T");
63 auto left_details = internal::fetch_seed(handle,
"left_seed",
"left_orientation", version, options);
64 auto right_details = internal::fetch_seed(handle,
"right_seed",
"right_orientation", version, options);
70 size_t common, common2;
72 if (left_details.second) {
73 nrow = left_details.first.dimensions[1];
74 common = left_details.first.dimensions[0];
76 nrow = left_details.first.dimensions[0];
77 common = left_details.first.dimensions[1];
80 if (right_details.second) {
81 ncol = right_details.first.dimensions[0];
82 common2 = right_details.first.dimensions[1];
84 ncol = right_details.first.dimensions[1];
85 common2 = right_details.first.dimensions[0];
89 if (common != common2) {
90 throw std::runtime_error(
"inconsistent common dimensions (" + std::to_string(common) +
" vs " + std::to_string(common2) +
")");
94 if (left_details.first.type == FLOAT || right_details.first.type == FLOAT) {
97 output.
type = INTEGER;
ArrayDetails validate(const H5::Group &handle, const ritsuko::Version &version, Options &options)
Definition: matrix_product.hpp:62
Namespace for all chihaya functions.
Definition: binary_arithmetic.hpp:22
Details about an array.
Definition: utils_public.hpp:36
std::vector< size_t > dimensions
Definition: utils_public.hpp:56
ArrayType type
Definition: utils_public.hpp:50
Validation options.
Definition: utils_public.hpp:66
bool details_only
Definition: utils_public.hpp:71
Various public utilities.