7 #include "../../common/common.hpp"
8 #include "../../operations/io/io.hpp"
14 template <
typename Type>
17 std::vector<Type> array;
18 std::vector<int> shape;
27 template <
typename T,
typename Alloc = std::allocator<T>>
29 shape = std::vector<int>();
33 for (
int i = depth; i < shape.size(); i++) {
37 array = std::vector<Type>(index * shape[0]);
39 for (
int i = 0; i < vec.size(); i++) {
40 write(vec[i], i * index, depth);
44 template <
typename T,
typename Alloc = std::allocator<T>>
45 void mold(std::vector<T, Alloc> vec) {
46 int size = vec.size();
47 shape.emplace_back(size);
54 void mold(std::vector<bool>::reference value) {}
63 find_file_pointer(path,
id, pos);
68 if (pos[1] !=
static_cast<int>(TFHEType::TFHEArray)) {
73 if ((fp = fopen(path,
"rb")) == NULL) {
74 printf(
"ファイルオープンエラー\n");
78 fseek(fp, pos[0] + 12L + Type::array_option_num() * 4L, SEEK_SET);
80 fread(inbf,
sizeof(
int), 1, fp);
82 int* tmp =
new int[inbf[0]];
84 fread(tmp,
sizeof(
int), inbf[0], fp);
85 shape = std::vector<int>(inbf[0]);
86 for (
int i = 0; i < shape.size(); i++) {
90 int size = array_size();
92 array = std::vector<Type>(size);
93 for (
int i = 0; i < array.size(); i++) {
94 array[i].load_raw(fp);
105 template <
class... T>
107 std::initializer_list<int> q{n...};
108 std::vector<int> p(q.begin(), q.end());
110 int size = shape.size();
113 for (
int i = 0; i < size - 1; i++) {
114 index *= shape[size - i - 1];
126 void save(
const char* path,
int id) {
129 find_file_pointer(path,
id, pos);
132 remove_from_file(path, pos);
135 if ((fp = fopen(path,
"ab+")) == NULL) {
136 printf(
"ファイルオープンエラー\n");
139 fseek(fp, 0L, SEEK_END);
142 Type::save_option_forArray(fp);
144 for (
int i = 0; i < array.size(); i++) {
145 array[i].save_raw(fp);
152 void save_option(FILE* fp) {
153 int* outbf =
new int[1 + shape.size()];
154 outbf[0] = shape.size();
155 for (
int i = 0; i < shape.size(); i++) {
156 outbf[1 + i] = shape[i];
158 fwrite(outbf,
sizeof(
int), 1 + shape.size(), fp);
162 void save_meta(FILE* fp,
int id) {
163 int size = Type::array_size(shape.size(), array.size());
167 outbf[1] =
static_cast<int>(TFHEType::TFHEArray);
169 fwrite(outbf,
sizeof(
int), 3, fp);
172 template <
typename T>
173 void write(T vec,
int pos,
int depth) {
176 for (
int i = depth; i < shape.size(); i++) {
179 for (
int i = 0; i < vec.size(); i++) {
180 write(vec[i], pos + i * index, depth);
184 void write(
int num,
int pos,
int depth) { array[pos] = Type(num); }
186 void write(std::vector<bool>::reference value,
int pos,
int depth) {
187 array[pos] = Type(value);
192 for (
int i = 0; i < shape.size(); i++) {