8 #ifndef LAYER_LOADER_H_ 9 #define LAYER_LOADER_H_ 26 root_directory(root_directory) {}
33 this->current_layer_index = layer_index;
45 std::ofstream output(path_from_args(tensor, variable_name));
46 output << tensor.to_raw_string();
54 template<
class Tensor>
58 string filename = path_from_args(tensor, variable_name);
60 tensor =
Tensor(bc::io::read_uniform<value_type>(descriptor, tensor.
get_allocator()).row(0));
65 using value_type =
typename T::value_type;
67 tensor = bc::io::read_uniform<value_type>(descriptor, tensor.get_allocator());
70 template<
class T,
int X>
72 using value_type =
typename T::value_type;
74 auto csv_mat = bc::io::read_uniform<value_type>(descriptor, tensor.get_allocator());
75 tensor = csv_mat.reshaped(tensor.inner_shape());
86 string path_from_args(
int dim,
string variable_name)
90 return fs::make_path(directory, variable_name +
"." + extension);
94 string path_from_args(
const T& tensor,
string variable_name) {
95 return path_from_args(T::tensor_dim, variable_name);
107 case 0:
return "scl";
108 case 1:
return "vec";
109 case 2:
return "mat";
110 case 3:
return "cube";
122 #undef BC_USE_EXPERIMENTAL_FILE_SYSTEM string current_layer_subdir() const
Definition: layer_loader.h:36
Layer_Loader(string root_directory)
Definition: layer_loader.h:25
int mkdir(const std::string &name)
Definition: filesystem.h:31
Definition: constexpr_int.h:14
Definition: layer_loader.h:19
allocator_type get_allocator() const
Definition: array.h:51
bc::string make_path(const bc::string &path)
Definition: filesystem.h:40
bc::tensors::Tensor_Base< bc::tensors::exprs::Array< bc::Shape< dim >, ValueType, Allocator > > Tensor
Definition: tensors.h:39
bool directory_exists(const std::string &name)
Definition: filesystem.h:21
void save_variable(const T &tensor, string variable_name)
Definition: layer_loader.h:44
BCINLINE auto dim(const Integers &... ints)
Definition: dim.h:336
string root_directory
Definition: layer_loader.h:21
std::string to_string(int precision=8, bool pretty=true, bool sparse=false) const
Definition: tensor_utility.h:34
int current_layer_index
Definition: layer_loader.h:23
typename parent_type::value_type value_type
Definition: tensor_base.h:41
void set_current_layer_index(int layer_index)
Definition: layer_loader.h:32
csv_descriptor & header(bool header)
Definition: io.h:65
bool file_exists(int dim, string filename)
Definition: layer_loader.h:100
Definition: filesystem.h:11
void load_variable(T &tensor, string variable_name, Integer< 2 >)
Definition: layer_loader.h:64
void make_current_directory()
Definition: layer_loader.h:78
bool file_exists(const std::string &name)
Definition: filesystem.h:35
void load_variable(T &tensor, string variable_name)
Definition: layer_loader.h:50
string current_layername
Definition: layer_loader.h:22
void load_variable(Tensor &tensor, string variable_name, Integer< 1 >)
Definition: layer_loader.h:55
void set_current_layer_name(string current_layername)
Definition: layer_loader.h:28
static string dim_to_extension(int dim)
Definition: layer_loader.h:105
The Evaluator determines if an expression needs to be greedily optimized.
Definition: algorithms.h:22
void load_variable(T &tensor, string variable_name, Integer< X >)
Definition: layer_loader.h:71