1#ifndef CAROTID_UTILITY_H
2#define CAROTID_UTILITY_H
11using Path = std::filesystem::path;
14using Mat = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>;
17using Vec = Eigen::Matrix<T, Eigen::Dynamic, 1>;
20[[nodiscard]] std::expected<Mat<T>, std::ios_base::failure>
22 std::ifstream in(filename, std::ios::binary);
24 return std::unexpected(
25 std::ios_base::failure(
"File not found or could not be opened.",
26 std::make_error_code(std::errc::io_error)));
31 in.read(
reinterpret_cast<char *
>(mat.data()), rows * cols *
sizeof(T));
33 return std::unexpected(std::ios_base::failure(
34 "Failed to read the entire file.", std::make_error_code(std::errc::io_error)));
41[[nodiscard]] std::expected<Vec<T>, std::ios_base::failure>
43 std::ifstream in(filename, std::ios::binary);
45 return std::unexpected(
46 std::ios_base::failure(
"File not found or could not be opened.",
47 std::make_error_code(std::errc::io_error)));
52 in.read(
reinterpret_cast<char *
>(vec.data()), n *
sizeof(T));
54 return std::unexpected(std::ios_base::failure(
55 "Failed to read the entire file.", std::make_error_code(std::errc::io_error)));
Definition IdentityGenerator.h:6
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vec
Definition Utility.h:17
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > Mat
Definition Utility.h:14
std::expected< Mat< T >, std::ios_base::failure > loadBinaryIntoMatrix(const Path &filename, int rows, int cols)
Definition Utility.h:21
std::filesystem::path Path
Definition Utility.h:11
std::expected< Vec< T >, std::ios_base::failure > loadBinaryIntoVector(const Path &filename, int n)
Definition Utility.h:42