From eda5bc26f44ee9a6f83dcf8c91f17296d7fc509d Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 12 Feb 2024 14:52:43 +0100 Subject: Move into version control --- .../include/armadillo_bits/diskio_bones.hpp | 229 +++++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 src/armadillo/include/armadillo_bits/diskio_bones.hpp (limited to 'src/armadillo/include/armadillo_bits/diskio_bones.hpp') diff --git a/src/armadillo/include/armadillo_bits/diskio_bones.hpp b/src/armadillo/include/armadillo_bits/diskio_bones.hpp new file mode 100644 index 0000000..03e1ac5 --- /dev/null +++ b/src/armadillo/include/armadillo_bits/diskio_bones.hpp @@ -0,0 +1,229 @@ +// SPDX-License-Identifier: Apache-2.0 +// +// Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au) +// Copyright 2008-2016 National ICT Australia (NICTA) +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ------------------------------------------------------------------------ + + +//! \addtogroup diskio +//! @{ + + +//! class for saving and loading matrices and fields - INTERNAL USE ONLY! +class diskio + { + public: + + arma_deprecated inline static file_type guess_file_type(std::istream& f); + + + private: + + template friend class Mat; + template friend class Cube; + template friend class SpMat; + template friend class field; + + friend class Mat_aux; + friend class Cube_aux; + friend class SpMat_aux; + friend class field_aux; + + template arma_cold inline static std::string gen_txt_header(const Mat&); + template arma_cold inline static std::string gen_bin_header(const Mat&); + + template arma_cold inline static std::string gen_bin_header(const SpMat&); + + template arma_cold inline static std::string gen_txt_header(const Cube&); + template arma_cold inline static std::string gen_bin_header(const Cube&); + + arma_cold inline static file_type guess_file_type_internal(std::istream& f); + + arma_cold inline static std::string gen_tmp_name(const std::string& x); + + arma_cold inline static bool safe_rename(const std::string& old_name, const std::string& new_name); + + arma_cold inline static bool is_readable(const std::string& name); + + arma_cold inline static void sanitise_token(std::string& token); + + template inline static bool convert_token(eT& val, const std::string& token); + template inline static bool convert_token(std::complex& val, const std::string& token); + + template inline static bool convert_token_strict(eT& val, const std::string& token); + + template inline static std::streamsize prepare_stream(std::ostream& f); + + + // + // matrix saving + + template inline static bool save_raw_ascii (const Mat& x, const std::string& final_name); + template inline static bool save_raw_binary (const Mat& x, const std::string& final_name); + template inline static bool save_arma_ascii (const Mat& x, const std::string& final_name); + template inline static bool save_csv_ascii (const Mat& x, const std::string& final_name, const field& header, const bool with_header, const char separator); + template inline static bool save_coord_ascii(const Mat& x, const std::string& final_name); + template inline static bool save_arma_binary(const Mat& x, const std::string& final_name); + template inline static bool save_pgm_binary (const Mat& x, const std::string& final_name); + template inline static bool save_pgm_binary (const Mat< std::complex >& x, const std::string& final_name); + template inline static bool save_hdf5_binary(const Mat& x, const hdf5_name& spec, std::string& err_msg); + + template inline static bool save_raw_ascii (const Mat& x, std::ostream& f); + template inline static bool save_raw_binary (const Mat& x, std::ostream& f); + template inline static bool save_arma_ascii (const Mat& x, std::ostream& f); + template inline static bool save_csv_ascii (const Mat& x, std::ostream& f, const char separator); + template inline static bool save_csv_ascii (const Mat< std::complex >& x, std::ostream& f, const char separator); + template inline static bool save_coord_ascii(const Mat& x, std::ostream& f); + template inline static bool save_coord_ascii(const Mat< std::complex >& x, std::ostream& f); + template inline static bool save_arma_binary(const Mat& x, std::ostream& f); + template inline static bool save_pgm_binary (const Mat& x, std::ostream& f); + template inline static bool save_pgm_binary (const Mat< std::complex >& x, std::ostream& f); + + + // + // matrix loading + + template inline static bool load_raw_ascii (Mat& x, const std::string& name, std::string& err_msg); + template inline static bool load_raw_binary (Mat& x, const std::string& name, std::string& err_msg); + template inline static bool load_arma_ascii (Mat& x, const std::string& name, std::string& err_msg); + template inline static bool load_csv_ascii (Mat& x, const std::string& name, std::string& err_msg, field& header, const bool with_header, const char separator, const bool strict); + template inline static bool load_coord_ascii(Mat& x, const std::string& name, std::string& err_msg); + template inline static bool load_arma_binary(Mat& x, const std::string& name, std::string& err_msg); + template inline static bool load_pgm_binary (Mat& x, const std::string& name, std::string& err_msg); + template inline static bool load_pgm_binary (Mat< std::complex >& x, const std::string& name, std::string& err_msg); + template inline static bool load_hdf5_binary(Mat& x, const hdf5_name& spec, std::string& err_msg); + template inline static bool load_auto_detect(Mat& x, const std::string& name, std::string& err_msg); + + template inline static bool load_raw_ascii (Mat& x, std::istream& f, std::string& err_msg); + template inline static bool load_raw_binary (Mat& x, std::istream& f, std::string& err_msg); + template inline static bool load_arma_ascii (Mat& x, std::istream& f, std::string& err_msg); + template inline static bool load_csv_ascii (Mat& x, std::istream& f, std::string& err_msg, const char separator, const bool strict); + template inline static bool load_csv_ascii (Mat< std::complex >& x, std::istream& f, std::string& err_msg, const char separator, const bool strict); + template inline static bool load_coord_ascii(Mat& x, std::istream& f, std::string& err_msg); + template inline static bool load_coord_ascii(Mat< std::complex >& x, std::istream& f, std::string& err_msg); + template inline static bool load_arma_binary(Mat& x, std::istream& f, std::string& err_msg); + template inline static bool load_pgm_binary (Mat& x, std::istream& is, std::string& err_msg); + template inline static bool load_pgm_binary (Mat< std::complex >& x, std::istream& is, std::string& err_msg); + template inline static bool load_auto_detect(Mat& x, std::istream& f, std::string& err_msg); + + inline static void pnm_skip_comments(std::istream& f); + + + // + // sparse matrix saving + + template inline static bool save_csv_ascii (const SpMat& x, const std::string& final_name, const field& header, const bool with_header, const char separator); + template inline static bool save_coord_ascii(const SpMat& x, const std::string& final_name); + template inline static bool save_arma_binary(const SpMat& x, const std::string& final_name); + + template inline static bool save_csv_ascii (const SpMat& x, std::ostream& f, const char separator); + template inline static bool save_csv_ascii (const SpMat< std::complex >& x, std::ostream& f, const char separator); + template inline static bool save_coord_ascii(const SpMat& x, std::ostream& f); + template inline static bool save_coord_ascii(const SpMat< std::complex >& x, std::ostream& f); + template inline static bool save_arma_binary(const SpMat& x, std::ostream& f); + + + // + // sparse matrix loading + + template inline static bool load_csv_ascii (SpMat& x, const std::string& name, std::string& err_msg, field& header, const bool with_header, const char separator); + template inline static bool load_coord_ascii(SpMat& x, const std::string& name, std::string& err_msg); + template inline static bool load_arma_binary(SpMat& x, const std::string& name, std::string& err_msg); + + template inline static bool load_csv_ascii (SpMat& x, std::istream& f, std::string& err_msg, const char separator); + template inline static bool load_csv_ascii (SpMat< std::complex >& x, std::istream& f, std::string& err_msg, const char separator); + template inline static bool load_coord_ascii(SpMat& x, std::istream& f, std::string& err_msg); + template inline static bool load_coord_ascii(SpMat< std::complex >& x, std::istream& f, std::string& err_msg); + template inline static bool load_arma_binary(SpMat& x, std::istream& f, std::string& err_msg); + + + + // + // cube saving + + template inline static bool save_raw_ascii (const Cube& x, const std::string& name); + template inline static bool save_raw_binary (const Cube& x, const std::string& name); + template inline static bool save_arma_ascii (const Cube& x, const std::string& name); + template inline static bool save_arma_binary(const Cube& x, const std::string& name); + template inline static bool save_hdf5_binary(const Cube& x, const hdf5_name& spec, std::string& err_msg); + + template inline static bool save_raw_ascii (const Cube& x, std::ostream& f); + template inline static bool save_raw_binary (const Cube& x, std::ostream& f); + template inline static bool save_arma_ascii (const Cube& x, std::ostream& f); + template inline static bool save_arma_binary(const Cube& x, std::ostream& f); + + + // + // cube loading + + template inline static bool load_raw_ascii (Cube& x, const std::string& name, std::string& err_msg); + template inline static bool load_raw_binary (Cube& x, const std::string& name, std::string& err_msg); + template inline static bool load_arma_ascii (Cube& x, const std::string& name, std::string& err_msg); + template inline static bool load_arma_binary(Cube& x, const std::string& name, std::string& err_msg); + template inline static bool load_hdf5_binary(Cube& x, const hdf5_name& spec, std::string& err_msg); + template inline static bool load_auto_detect(Cube& x, const std::string& name, std::string& err_msg); + + template inline static bool load_raw_ascii (Cube& x, std::istream& f, std::string& err_msg); + template inline static bool load_raw_binary (Cube& x, std::istream& f, std::string& err_msg); + template inline static bool load_arma_ascii (Cube& x, std::istream& f, std::string& err_msg); + template inline static bool load_arma_binary(Cube& x, std::istream& f, std::string& err_msg); + template inline static bool load_auto_detect(Cube& x, std::istream& f, std::string& err_msg); + + + // + // field saving and loading + + template inline static bool save_arma_binary(const field& x, const std::string& name); + template inline static bool save_arma_binary(const field& x, std::ostream& f); + + template inline static bool load_arma_binary( field& x, const std::string& name, std::string& err_msg); + template inline static bool load_arma_binary( field& x, std::istream& f, std::string& err_msg); + + template inline static bool load_auto_detect( field& x, const std::string& name, std::string& err_msg); + template inline static bool load_auto_detect( field& x, std::istream& f, std::string& err_msg); + + inline static bool save_std_string(const field& x, const std::string& name); + inline static bool save_std_string(const field& x, std::ostream& f); + + inline static bool load_std_string( field& x, const std::string& name, std::string& err_msg); + inline static bool load_std_string( field& x, std::istream& f, std::string& err_msg); + + + + // + // handling of PPM images by cubes + + template inline static bool save_ppm_binary(const Cube& x, const std::string& final_name); + template inline static bool save_ppm_binary(const Cube& x, std::ostream& f); + + template inline static bool load_ppm_binary( Cube& x, const std::string& final_name, std::string& err_msg); + template inline static bool load_ppm_binary( Cube& x, std::istream& f, std::string& err_msg); + + + // + // handling of PPM images by fields + + template inline static bool save_ppm_binary(const field& x, const std::string& final_name); + template inline static bool save_ppm_binary(const field& x, std::ostream& f); + + template inline static bool load_ppm_binary( field& x, const std::string& final_name, std::string& err_msg); + template inline static bool load_ppm_binary( field& x, std::istream& f, std::string& err_msg); + + + + }; + + + +//! @} -- cgit v1.2.1