Txeo v0.1
A Developer-Friendly TensorFlow C++ Wrapper
Loading...
Searching...
No Matches
TensorIO.h
Go to the documentation of this file.
1#ifndef TENSORIO_H
2#define TENSORIO_H
3#pragma once
4
5#include "txeo/Tensor.h"
6
7#include <cstddef>
8#include <filesystem>
9#include <type_traits>
10
11namespace txeo {
12
18class TensorIO {
19 public:
20 explicit TensorIO(const std::filesystem::path &path, char separator = ',')
21 : _path(std::move(path)), _separator(separator) {};
22
23 template <typename T>
24 [[deprecated("Use class txeo::MatrixIO.")]]
25 txeo::Tensor<T> read_text_file(bool has_header = false) const;
26
27 template <typename T>
28 [[deprecated("Use class txeo::MatrixIO.")]]
29 void write_text_file(const txeo::Tensor<T> &tensor) const;
30
31 template <typename T>
32 requires(std::is_floating_point_v<T>)
33 [[deprecated("Use class txeo::MatrixIO.")]]
34 void write_text_file(const txeo::Tensor<T> &tensor, size_t precision) const;
35
36 template <typename T>
37 [[deprecated("Use class txeo::MatrixIO.")]]
38 static txeo::Tensor<T> read_textfile(const std::filesystem::path &path, char separator = ',',
39 bool has_header = false) {
40 txeo::TensorIO io{path, separator};
41 Tensor<T> resp{io.read_text_file<T>(has_header)};
42 return resp;
43 };
44
45 template <typename T>
46 [[deprecated("Use class txeo::MatrixIO.")]]
47 static void write_textfile(const txeo::Tensor<T> &tensor, const std::filesystem::path &path,
48 char separator = ',') {
49 txeo::TensorIO io{path, separator};
50 io.write_text_file(tensor);
51 }
52
53 template <typename T>
54 requires(std::is_floating_point_v<T>)
55 [[deprecated("Use class txeo::MatrixIO.")]]
56 static void write_textfile(const txeo::Tensor<T> &tensor, size_t precision,
57 const std::filesystem::path &path, char separator = ',') {
58 txeo::TensorIO io{path, separator};
59 io.write_text_file(tensor, precision);
60 };
61
62 private:
63 std::filesystem::path _path;
64 char _separator;
65};
66
71class TensorIOError : public std::runtime_error {
72 public:
73 using std::runtime_error::runtime_error;
74};
75
76} // namespace txeo
77
78#endif
Implements the mathematical concept of tensor, which is a magnitude of multiple order....
Definition Tensor.h:48
Exceptions concerning txeo::TensorIO.
Definition TensorIO.h:71
This class is deprecated. Please use class txeo::MatrixIO.
Definition TensorIO.h:18
static txeo::Tensor< T > read_textfile(const std::filesystem::path &path, char separator=',', bool has_header=false)
Definition TensorIO.h:38
txeo::Tensor< T > read_text_file(bool has_header=false) const
static void write_textfile(const txeo::Tensor< T > &tensor, const std::filesystem::path &path, char separator=',')
Definition TensorIO.h:47
void write_text_file(const txeo::Tensor< T > &tensor) const
TensorIO(const std::filesystem::path &path, char separator=',')
Definition TensorIO.h:20
static void write_textfile(const txeo::Tensor< T > &tensor, size_t precision, const std::filesystem::path &path, char separator=',')
Definition TensorIO.h:56
void write_text_file(const txeo::Tensor< T > &tensor, size_t precision) const
Definition Matrix.h:11