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 <stdexcept>
10#include <type_traits>
11#include <utility>
12
13namespace txeo {
14
20class TensorIO {
21 public:
22 explicit TensorIO(const std::filesystem::path &path, char separator = ',')
23 : _path(std::move(path)), _separator(separator) {};
24
25 template <typename T>
26 [[deprecated("Use class txeo::MatrixIO.")]]
28
29 template <typename T>
30 [[deprecated("Use class txeo::MatrixIO.")]]
32
33 template <typename T>
34 requires(std::is_floating_point_v<T>)
35 [[deprecated("Use class txeo::MatrixIO.")]]
36 void write_text_file(const txeo::Tensor<T> &tensor, size_t precision) const;
37
38 template <typename T>
39 [[deprecated("Use class txeo::MatrixIO.")]]
40 static txeo::Tensor<T> read_textfile(const std::filesystem::path &path, char separator = ',',
41 bool has_header = false) {
42 txeo::TensorIO io{path, separator};
43 Tensor<T> resp{io.read_text_file<T>(has_header)};
44 return resp;
45 };
46
47 template <typename T>
48 [[deprecated("Use class txeo::MatrixIO.")]]
49 static void write_textfile(const txeo::Tensor<T> &tensor, const std::filesystem::path &path,
50 char separator = ',') {
51 txeo::TensorIO io{path, separator};
52 io.write_text_file(tensor);
53 }
54
55 template <typename T>
56 requires(std::is_floating_point_v<T>)
57 [[deprecated("Use class txeo::MatrixIO.")]]
58 static void write_textfile(const txeo::Tensor<T> &tensor, size_t precision,
59 const std::filesystem::path &path, char separator = ',') {
60 txeo::TensorIO io{path, separator};
61 io.write_text_file(tensor, precision);
62 };
63
64 private:
65 std::filesystem::path _path;
66 char _separator;
67};
68
73class TensorIOError : public std::runtime_error {
74 public:
75 using std::runtime_error::runtime_error;
76};
77
78} // namespace txeo
79
80#endif
A container for managing training, evaluation, and test data splits.
Definition DataTable.h:24
Exceptions concerning txeo::TensorIO.
Definition TensorIO.h:73
This class is deprecated. Please use class txeo::MatrixIO.
Definition TensorIO.h:20
static txeo::Tensor< T > read_textfile(const std::filesystem::path &path, char separator=',', bool has_header=false)
Definition TensorIO.h:40
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:49
void write_text_file(const txeo::Tensor< T > &tensor) const
TensorIO(const std::filesystem::path &path, char separator=',')
Definition TensorIO.h:22
static void write_textfile(const txeo::Tensor< T > &tensor, size_t precision, const std::filesystem::path &path, char separator=',')
Definition TensorIO.h:58
void write_text_file(const txeo::Tensor< T > &tensor, size_t precision) const