#ifndef PRINT_H #define PRINT_H #include #include #include #include #include #include #ifdef FASTOR_SSE2_IMPL #include #endif #ifdef FASTOR_AVX_IMPL #include #endif namespace Fastor { //! IOFormat class for tensors struct IOFormat { inline IOFormat( int precision, const std::string& colsep, const std::string& rowsep, const std::string& rowprefix, const std::string& rowsuffix, bool print_dimensions ) { _precision = precision; _colsep = colsep; _rowsep = rowsep; _rowprefix = rowprefix; _rowsuffix = rowsuffix; _print_dimensions = print_dimensions; } int _precision; std::string _colsep; std::string _rowsep; std::string _rowprefix; std::string _rowsuffix; bool _print_dimensions; }; #ifndef FASTOR_DEFINE_IO_FORMAT #define FASTOR_DEFINE_IO_FORMAT {std::numeric_limits::digits10,", ","\n","[","]",true}; // #define FASTOR_DEFINE_IO_FORMAT IOFormat(9,",","\n","[","]",true); #endif #ifdef FASTOR_SSE2_IMPL inline void print(__m128 b) { const float* a = (const float*)&b; std::cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << '\n'; } inline void print(__m128d b) { const double* a = (const double*)&b; std::cout << a[0] << " " << a[1] << '\n'; } #endif #ifdef FASTOR_AVX_IMPL inline void print(__m256 b) { const float* a = (const float*)&b; std::cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << " " << a[4] << " " << a[5] << " " << a[6] << " " << a[7] << '\n'; } inline void print(__m256d b) { const double* a = (const double*)&b; std::cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << '\n'; } #endif template inline void print(const std::vector &v) { for (auto &k: v) { std::cout << k << '\n'; } std::cout << std::endl; } template inline void print(const std::array &arr) { for (std::size_t i=0; i inline void print(const std::vector> &arr) { for (std::size_t i=0; i inline void print(const std::vector> &arr) { for (std::size_t i=0; i inline void print(const std::array,N> &arr) { for (std::size_t i=0; i inline void print(const T *arr) { for (std::size_t i=0; i inline void print(const T &a) { std::cout << a << '\n'; } template inline void print(const T &first, const Rest& ... rest) { print(first); print(rest...); } inline void print() { std::cout << '\n'; } /*--------------------------------------*/ // Print horizontally /*--------------------------------------*/ template inline void println(const std::vector &v) { for (auto &k: v) { std::cout << k << ' '; } std::cout << '\n'; } template inline void println(const std::array &arr) { for (std::size_t i=0; i inline void println(const T *arr) { for (std::size_t i=0; i inline void println(const T &a) { std::cout << a; } template inline void println(const T &first, const Rest& ... rest) { println(first); std::cout << ' '; println(rest...); } inline void println() { std::cout << ' '; } /*--------------------------------------*/ // Warn /*--------------------------------------*/ template inline void warn(const T &a) { std::cerr << a << '\n'; } template inline void warn(const T &first, const Rest& ... rest) { warn(first); warn(rest...); } } // end of namespace #endif