35 return std::string(
"ARMA_MAT_TXT_IU001");
40 return std::string(
"ARMA_MAT_TXT_IS001");
45 return std::string(
"ARMA_MAT_TXT_IU002");
50 return std::string(
"ARMA_MAT_TXT_IS002");
55 return std::string(
"ARMA_MAT_TXT_IU004");
60 return std::string(
"ARMA_MAT_TXT_IS004");
62 #if defined(ARMA_64BIT_WORD) 64 if(is_u64<eT>::value ==
true)
66 return std::string(
"ARMA_MAT_TXT_IU008");
69 if(is_s64<eT>::value ==
true)
71 return std::string(
"ARMA_MAT_TXT_IS008");
77 return std::string(
"ARMA_MAT_TXT_FN004");
82 return std::string(
"ARMA_MAT_TXT_FN008");
87 return std::string(
"ARMA_MAT_TXT_FC008");
92 return std::string(
"ARMA_MAT_TXT_FC016");
108 template<
typename eT>
119 return std::string(
"ARMA_MAT_BIN_IU001");
124 return std::string(
"ARMA_MAT_BIN_IS001");
129 return std::string(
"ARMA_MAT_BIN_IU002");
134 return std::string(
"ARMA_MAT_BIN_IS002");
139 return std::string(
"ARMA_MAT_BIN_IU004");
144 return std::string(
"ARMA_MAT_BIN_IS004");
146 #if defined(ARMA_64BIT_WORD) 148 if(is_u64<eT>::value ==
true)
150 return std::string(
"ARMA_MAT_BIN_IU008");
153 if(is_s64<eT>::value ==
true)
155 return std::string(
"ARMA_MAT_BIN_IS008");
161 return std::string(
"ARMA_MAT_BIN_FN004");
166 return std::string(
"ARMA_MAT_BIN_FN008");
171 return std::string(
"ARMA_MAT_BIN_FC008");
176 return std::string(
"ARMA_MAT_BIN_FC016");
180 return std::string();
192 template<
typename eT>
203 return std::string(
"ARMA_CUB_TXT_IU001");
208 return std::string(
"ARMA_CUB_TXT_IS001");
213 return std::string(
"ARMA_CUB_TXT_IU002");
218 return std::string(
"ARMA_CUB_TXT_IS002");
223 return std::string(
"ARMA_CUB_TXT_IU004");
228 return std::string(
"ARMA_CUB_TXT_IS004");
230 #if defined(ARMA_64BIT_WORD) 232 if(is_u64<eT>::value ==
true)
234 return std::string(
"ARMA_CUB_TXT_IU008");
237 if(is_s64<eT>::value ==
true)
239 return std::string(
"ARMA_CUB_TXT_IS008");
245 return std::string(
"ARMA_CUB_TXT_FN004");
250 return std::string(
"ARMA_CUB_TXT_FN008");
255 return std::string(
"ARMA_CUB_TXT_FC008");
260 return std::string(
"ARMA_CUB_TXT_FC016");
264 return std::string();
276 template<
typename eT>
287 return std::string(
"ARMA_CUB_BIN_IU001");
292 return std::string(
"ARMA_CUB_BIN_IS001");
297 return std::string(
"ARMA_CUB_BIN_IU002");
302 return std::string(
"ARMA_CUB_BIN_IS002");
307 return std::string(
"ARMA_CUB_BIN_IU004");
312 return std::string(
"ARMA_CUB_BIN_IS004");
314 #if defined(ARMA_64BIT_WORD) 316 if(is_u64<eT>::value ==
true)
318 return std::string(
"ARMA_CUB_BIN_IU008");
321 if(is_s64<eT>::value ==
true)
323 return std::string(
"ARMA_CUB_BIN_IS008");
329 return std::string(
"ARMA_CUB_BIN_FN004");
334 return std::string(
"ARMA_CUB_BIN_FN008");
339 return std::string(
"ARMA_CUB_BIN_FC008");
344 return std::string(
"ARMA_CUB_BIN_FC016");
348 return std::string();
362 const std::fstream::pos_type pos1 = f.tellg();
365 f.seekg(0, ios::end);
368 const std::fstream::pos_type pos2 = f.tellg();
370 const uword N = ( (pos1 >= 0) && (pos2 >= 0) ) ?
uword(pos2 - pos1) : 0;
377 unsigned char* ptr = data.
memptr();
380 f.read( reinterpret_cast<char*>(ptr), std::streamsize(N) );
382 const bool load_okay = f.good();
387 bool has_binary =
false;
388 bool has_comma =
false;
390 if(load_okay ==
true)
393 uword j = (N >= 2) ? 1 : 0;
395 for(; j<N; i+=2, j+=2)
397 const unsigned char val_i = ptr[i];
398 const unsigned char val_j = ptr[j];
401 if( ((val_i <= 8) || (val_i >= 123)) || ((val_j <= 8) || (val_j >= 123)) )
407 if( (val_i ==
',') || (val_j ==
',') )
442 case 0: out =
'0';
break;
443 case 1: out =
'1';
break;
444 case 2: out =
'2';
break;
445 case 3: out =
'3';
break;
446 case 4: out =
'4';
break;
447 case 5: out =
'5';
break;
448 case 6: out =
'6';
break;
449 case 7: out =
'7';
break;
450 case 8: out =
'8';
break;
451 case 9: out =
'9';
break;
452 case 10: out =
'a';
break;
453 case 11: out =
'b';
break;
454 case 12: out =
'c';
break;
455 case 13: out =
'd';
break;
456 case 14: out =
'e';
break;
457 case 15: out =
'f';
break;
458 default: out =
'-';
break;
471 const u8 b = x - 16*a;
490 const std::string* ptr_x = &x;
491 const u8* ptr_ptr_x =
reinterpret_cast<const u8*
>(&ptr_x);
493 const char* extra =
".tmp_";
494 const uword extra_size = 5;
496 const uword tmp_size = 2*
sizeof(u8*) + 2*2;
499 uword char_count = 0;
501 for(
uword i=0; i<
sizeof(u8*); ++i)
507 const uword x_size =
static_cast<uword>(x.size());
510 for(
uword i=0; i<x_size; ++i)
522 out.resize(x_size + extra_size + tmp_size);
525 for(
uword i=0; i<x_size; ++i)
530 for(
uword i=0; i<extra_size; ++i)
532 out[x_size + i] = extra[i];
535 for(
uword i=0; i<tmp_size; ++i)
537 out[x_size + extra_size + i] = tmp[i];
554 std::fstream f(new_name.c_str(), std::fstream::out | std::fstream::app);
557 bool save_okay = f.good();
560 if(save_okay ==
true)
562 std::remove(new_name.c_str());
564 const int mv_result = std::rename(old_name.c_str(), new_name.c_str());
566 save_okay = (mv_result == 0);
576 template<
typename eT>
585 std::fstream f(tmp_name.c_str(), std::fstream::out);
587 bool save_okay = f.is_open();
589 if(save_okay ==
true)
596 if(save_okay ==
true)
609 template<
typename eT>
622 f.setf(ios::scientific);
650 template<
typename eT>
659 std::ofstream f(tmp_name.c_str(), std::fstream::binary);
661 bool save_okay = f.is_open();
663 if(save_okay ==
true)
670 if(save_okay ==
true)
681 template<
typename eT>
688 f.write( reinterpret_cast<const char*>(x.
mem), std::streamsize(x.
n_elem*
sizeof(eT)) );
697 template<
typename eT>
706 std::ofstream f(tmp_name.c_str());
708 bool save_okay = f.is_open();
710 if(save_okay ==
true)
717 if(save_okay ==
true)
730 template<
typename eT>
737 const ios::fmtflags orig_flags = f.flags();
748 f.setf(ios::scientific);
770 const bool save_okay = f.good();
780 template<
typename eT>
789 std::ofstream f(tmp_name.c_str());
791 bool save_okay = f.is_open();
793 if(save_okay ==
true)
800 if(save_okay ==
true)
812 template<
typename eT>
819 const ios::fmtflags orig_flags = f.flags();
825 f.setf(ios::scientific);
832 for(
uword row=0; row < x_n_rows; ++row)
834 for(
uword col=0; col < x_n_cols; ++col)
838 if( col < (x_n_cols-1) )
847 const bool save_okay = f.good();
858 template<
typename eT>
867 std::ofstream f(tmp_name.c_str(), std::fstream::binary);
869 bool save_okay = f.is_open();
871 if(save_okay ==
true)
878 if(save_okay ==
true)
891 template<
typename eT>
901 f.write( reinterpret_cast<const char*>(x.
mem), std::streamsize(x.
n_elem*
sizeof(eT)) );
909 template<
typename eT>
918 std::fstream f(tmp_name.c_str(), std::fstream::out | std::fstream::binary);
920 bool save_okay = f.is_open();
922 if(save_okay ==
true)
929 if(save_okay ==
true)
946 template<
typename eT>
966 tmp[i] = u8( x.
at(row,col) );
971 f.write(reinterpret_cast<const char*>(tmp.
mem), std::streamsize(n_elem) );
1011 template<
typename eT>
1019 f.open(name.c_str(), std::fstream::in);
1021 bool load_okay = f.is_open();
1023 if(load_okay ==
true)
1037 template<
typename eT>
1044 bool load_okay = f.good();
1047 const std::fstream::pos_type pos1 = f.tellg();
1055 bool f_n_cols_found =
false;
1057 std::string line_string;
1060 while( (f.good() ==
true) && (load_okay ==
true) )
1062 std::getline(f, line_string);
1064 if(line_string.size() == 0)
1069 std::stringstream line_stream(line_string);
1071 uword line_n_cols = 0;
1073 while (line_stream >> token)
1078 if(f_n_cols_found ==
false)
1080 f_n_cols = line_n_cols;
1081 f_n_cols_found =
true;
1085 if(line_n_cols != f_n_cols)
1087 err_msg =
"inconsistent number of columns in ";
1095 if(load_okay ==
true)
1104 for(
uword row=0; (row < x.
n_rows) && (load_okay ==
true); ++row)
1106 for(
uword col=0; (col < x.
n_cols) && (load_okay ==
true); ++col)
1110 if(f.fail() ==
false)
1112 x.
at(row,col) = val;
1117 err_msg =
"couldn't interpret data in ";
1126 if( (f_n_cols_found ==
false) && (load_okay ==
true) )
1139 template<
typename eT>
1147 f.open(name.c_str(), std::fstream::binary);
1149 bool load_okay = f.is_open();
1151 if(load_okay ==
true)
1162 template<
typename eT>
1171 const std::streampos pos1 = f.tellg();
1174 f.seekg(0, ios::end);
1177 const std::streampos pos2 = f.tellg();
1179 const uword N = ( (pos1 >= 0) && (pos2 >= 0) ) ?
uword(pos2 - pos1) : 0;
1188 f.read( reinterpret_cast<char *>(x.
memptr()), std::streamsize(N) );
1197 template<
typename eT>
1204 std::ifstream f(name.c_str());
1206 bool load_okay = f.is_open();
1208 if(load_okay ==
true)
1221 template<
typename eT>
1228 bool load_okay =
true;
1230 std::string f_header;
1250 load_okay = f.good();
1255 err_msg =
"incorrect header in ";
1264 template<
typename eT>
1272 f.open(name.c_str(), std::fstream::in);
1274 bool load_okay = f.is_open();
1276 if(load_okay ==
true)
1288 template<
typename eT>
1295 bool load_okay = f.good();
1298 const std::fstream::pos_type pos1 = f.tellg();
1306 std::string line_string;
1309 while( (f.good() ==
true) && (load_okay ==
true) )
1311 std::getline(f, line_string);
1313 if(line_string.size() == 0)
1318 std::stringstream line_stream(line_string);
1320 uword line_n_cols = 0;
1322 while(line_stream.good() ==
true)
1324 getline(line_stream, token,
',');
1328 if(f_n_cols < line_n_cols)
1330 f_n_cols = line_n_cols;
1339 x.
zeros(f_n_rows, f_n_cols);
1343 while(f.good() ==
true)
1345 std::getline(f, line_string);
1347 if(line_string.size() == 0)
1352 std::stringstream line_stream(line_string);
1356 while(line_stream.good() ==
true)
1358 getline(line_stream, token,
',');
1362 std::stringstream ss(token);
1366 if(ss.fail() ==
false)
1368 x.
at(row,col) = val;
1384 template<
typename eT>
1392 f.open(name.c_str(), std::fstream::binary);
1394 bool load_okay = f.is_open();
1396 if(load_okay ==
true)
1407 template<
typename eT>
1414 bool load_okay =
true;
1416 std::string f_header;
1430 f.read( reinterpret_cast<char *>(x.
memptr()), std::streamsize(x.
n_elem*
sizeof(eT)) );
1432 load_okay = f.good();
1437 err_msg =
"incorrect header in ";
1449 while( isspace(f.peek()) )
1451 while( isspace(f.peek()) )
1458 while( (f.peek() !=
'\r') && (f.peek()!=
'\n') )
1469 template<
typename eT>
1477 f.open(name.c_str(), std::fstream::in | std::fstream::binary);
1479 bool load_okay = f.is_open();
1481 if(load_okay ==
true)
1493 template<
typename eT>
1498 bool load_okay =
true;
1500 std::string f_header;
1503 if(f_header ==
"P5")
1520 if( (f_maxval > 0) || (f_maxval <= 65535) )
1526 const uword n_elem = f_n_cols*f_n_rows;
1529 f.read( reinterpret_cast<char*>(tmp.
memptr()), std::streamsize(n_elem) );
1537 for(
uword row=0; row < f_n_rows; ++row)
1539 for(
uword col=0; col < f_n_cols; ++col)
1541 x.
at(row,col) = eT(tmp[i]);
1549 const uword n_elem = f_n_cols*f_n_rows;
1552 f.read( reinterpret_cast<char *>(tmp.
memptr()), std::streamsize(n_elem*2) );
1556 for(
uword row=0; row < f_n_rows; ++row)
1558 for(
uword col=0; col < f_n_cols; ++col)
1560 x.
at(row,col) = eT(tmp[i]);
1571 err_msg =
"currently no code available to handle loading ";
1574 if(f.good() ==
false)
1582 err_msg =
"unsupported header in ";
1591 template<
typename T>
1609 template<
typename T>
1627 template<
typename eT>
1635 f.open(name.c_str(), std::fstream::in | std::fstream::binary);
1637 bool load_okay = f.is_open();
1639 if(load_okay ==
true)
1651 template<
typename eT>
1658 static const std::string ARMA_MAT_TXT =
"ARMA_MAT_TXT";
1659 static const std::string ARMA_MAT_BIN =
"ARMA_MAT_BIN";
1660 static const std::string P5 =
"P5";
1664 std::streampos pos = f.tellg();
1666 f.read( raw_header.memptr(), std::streamsize(ARMA_MAT_TXT.length()) );
1667 raw_header[ARMA_MAT_TXT.length()] =
'\0';
1672 const std::string header = raw_header.
mem;
1674 if(ARMA_MAT_TXT == header.substr(0,ARMA_MAT_TXT.length()))
1679 if(ARMA_MAT_BIN == header.substr(0,ARMA_MAT_BIN.length()))
1684 if(P5 == header.substr(0,P5.length()))
1707 err_msg =
"unknown data in ";
1722 template<
typename eT>
1731 std::fstream f(tmp_name.c_str(), std::fstream::out);
1733 bool save_okay = f.is_open();
1735 if(save_okay ==
true)
1742 if(save_okay ==
true)
1754 template<
typename eT>
1767 f.setf(ios::scientific);
1782 f.width(cell_width);
1785 f << x.
at(row,col,slice);
1798 template<
typename eT>
1807 std::ofstream f(tmp_name.c_str(), std::fstream::binary);
1809 bool save_okay = f.is_open();
1811 if(save_okay ==
true)
1818 if(save_okay ==
true)
1829 template<
typename eT>
1836 f.write( reinterpret_cast<const char*>(x.
mem), std::streamsize(x.
n_elem*
sizeof(eT)) );
1845 template<
typename eT>
1854 std::ofstream f(tmp_name.c_str());
1856 bool save_okay = f.is_open();
1858 if(save_okay ==
true)
1865 if(save_okay ==
true)
1878 template<
typename eT>
1885 const ios::fmtflags orig_flags = f.flags();
1896 f.setf(ios::scientific);
1911 f.width(cell_width);
1914 f << x.
at(row,col,slice);
1921 const bool save_okay = f.good();
1923 f.flags(orig_flags);
1932 template<
typename eT>
1941 std::ofstream f(tmp_name.c_str(), std::fstream::binary);
1943 bool save_okay = f.is_open();
1945 if(save_okay ==
true)
1952 if(save_okay ==
true)
1965 template<
typename eT>
1975 f.write( reinterpret_cast<const char*>(x.
mem), std::streamsize(x.
n_elem*
sizeof(eT)) );
1984 template<
typename eT>
1994 if(load_okay ==
true)
2015 template<
typename eT>
2025 if(load_okay ==
true)
2046 template<
typename eT>
2054 f.open(name.c_str(), std::fstream::binary);
2056 bool load_okay = f.is_open();
2058 if(load_okay ==
true)
2069 template<
typename eT>
2078 const std::streampos pos1 = f.tellg();
2081 f.seekg(0, ios::end);
2084 const std::streampos pos2 = f.tellg();
2086 const uword N = ( (pos1 >= 0) && (pos2 >= 0) ) ?
uword(pos2 - pos1) : 0;
2095 f.read( reinterpret_cast<char *>(x.
memptr()), std::streamsize(N) );
2104 template<
typename eT>
2111 std::ifstream f(name.c_str());
2113 bool load_okay = f.is_open();
2115 if(load_okay ==
true)
2128 template<
typename eT>
2135 bool load_okay =
true;
2137 std::string f_header;
2149 x.
set_size(f_n_rows, f_n_cols, f_n_slices);
2157 f >> x.
at(row,col,slice);
2162 load_okay = f.good();
2167 err_msg =
"incorrect header in ";
2177 template<
typename eT>
2185 f.open(name.c_str(), std::fstream::binary);
2187 bool load_okay = f.is_open();
2189 if(load_okay ==
true)
2200 template<
typename eT>
2207 bool load_okay =
true;
2209 std::string f_header;
2224 x.
set_size(f_n_rows, f_n_cols, f_n_slices);
2225 f.read( reinterpret_cast<char *>(x.
memptr()), std::streamsize(x.
n_elem*
sizeof(eT)) );
2227 load_okay = f.good();
2232 err_msg =
"incorrect header in ";
2241 template<
typename eT>
2249 f.open(name.c_str(), std::fstream::in | std::fstream::binary);
2251 bool load_okay = f.is_open();
2253 if(load_okay ==
true)
2265 template<
typename eT>
2272 static const std::string ARMA_CUB_TXT =
"ARMA_CUB_TXT";
2273 static const std::string ARMA_CUB_BIN =
"ARMA_CUB_BIN";
2274 static const std::string P6 =
"P6";
2278 std::streampos pos = f.tellg();
2280 f.read( raw_header.memptr(), std::streamsize(ARMA_CUB_TXT.length()) );
2281 raw_header[ARMA_CUB_TXT.length()] =
'\0';
2286 const std::string header = raw_header.
mem;
2288 if(ARMA_CUB_TXT == header.substr(0, ARMA_CUB_TXT.length()))
2293 if(ARMA_CUB_BIN == header.substr(0, ARMA_CUB_BIN.length()))
2298 if(P6 == header.substr(0, P6.length()))
2321 err_msg =
"unknown data in ";
2337 template<
typename T1>
2346 std::ofstream f( tmp_name.c_str(), std::fstream::binary );
2348 bool save_okay = f.is_open();
2350 if(save_okay ==
true)
2357 if(save_okay ==
true)
2368 template<
typename T1>
2377 f <<
"ARMA_FLD_BIN" <<
'\n';
2381 bool save_okay =
true;
2387 if(save_okay ==
false)
2398 template<
typename T1>
2405 std::ifstream f( name.c_str(), std::fstream::binary );
2407 bool load_okay = f.is_open();
2409 if(load_okay ==
true)
2420 template<
typename T1>
2429 bool load_okay =
true;
2434 if(f_type !=
"ARMA_FLD_BIN")
2437 err_msg =
"unsupported field type in ";
2455 if(load_okay ==
false)
2475 std::ofstream f( tmp_name.c_str(), std::fstream::binary );
2477 bool save_okay = f.is_open();
2479 if(save_okay ==
true)
2486 if(save_okay ==
true)
2529 std::ifstream f( name.c_str() );
2531 bool load_okay = f.is_open();
2533 if(load_okay ==
true)
2550 bool load_okay =
true;
2558 bool f_n_cols_found =
false;
2560 std::string line_string;
2563 while( (f.good() ==
true) && (load_okay ==
true) )
2565 std::getline(f, line_string);
2566 if(line_string.size() == 0)
2569 std::stringstream line_stream(line_string);
2571 uword line_n_cols = 0;
2572 while (line_stream >> token)
2575 if(f_n_cols_found ==
false)
2577 f_n_cols = line_n_cols;
2578 f_n_cols_found =
true;
2582 if(line_n_cols != f_n_cols)
2585 err_msg =
"inconsistent number of columns in ";
2592 if(load_okay ==
true)
2595 f.seekg(0, ios::beg);
2609 if(f.good() ==
false)
2620 template<
typename T1>
2628 f.open(name.c_str(), std::fstream::in | std::fstream::binary);
2630 bool load_okay = f.is_open();
2632 if(load_okay ==
true)
2644 template<
typename T1>
2653 static const std::string ARMA_FLD_BIN =
"ARMA_FLD_BIN";
2654 static const std::string P6 =
"P6";
2658 std::streampos pos = f.tellg();
2660 f.read( raw_header.memptr(), std::streamsize(ARMA_FLD_BIN.length()) );
2665 raw_header[ARMA_FLD_BIN.length()] =
'\0';
2667 const std::string header = raw_header.
mem;
2669 if(ARMA_FLD_BIN == header.substr(0, ARMA_FLD_BIN.length()))
2674 if(P6 == header.substr(0, P6.length()))
2680 err_msg =
"unsupported header in ";
2691 template<
typename eT>
2699 f.open(name.c_str(), std::fstream::in | std::fstream::binary);
2701 bool load_okay = f.is_open();
2703 if(load_okay ==
true)
2714 template<
typename eT>
2721 bool load_okay =
true;
2723 std::string f_header;
2726 if(f_header ==
"P6")
2743 if( (f_maxval > 0) || (f_maxval <= 65535) )
2749 const uword n_elem = 3*f_n_cols*f_n_rows;
2752 f.read( reinterpret_cast<char*>(tmp.
memptr()), std::streamsize(n_elem) );
2760 for(
uword row=0; row < f_n_rows; ++row)
2762 for(
uword col=0; col < f_n_cols; ++col)
2764 x.
at(row,col,0) = eT(tmp[i+0]);
2765 x.
at(row,col,1) = eT(tmp[i+1]);
2766 x.
at(row,col,2) = eT(tmp[i+2]);
2774 const uword n_elem = 3*f_n_cols*f_n_rows;
2777 f.read( reinterpret_cast<char *>(tmp.
memptr()), std::streamsize(2*n_elem) );
2781 for(
uword row=0; row < f_n_rows; ++row)
2783 for(
uword col=0; col < f_n_cols; ++col)
2785 x.
at(row,col,0) = eT(tmp[i+0]);
2786 x.
at(row,col,1) = eT(tmp[i+1]);
2787 x.
at(row,col,2) = eT(tmp[i+2]);
2799 err_msg =
"currently no code available to handle loading ";
2802 if(f.good() ==
false)
2811 err_msg =
"unsupported header in ";
2819 template<
typename eT>
2828 std::ofstream f( tmp_name.c_str(), std::fstream::binary );
2830 bool save_okay = f.is_open();
2832 if(save_okay ==
true)
2839 if(save_okay ==
true)
2850 template<
typename eT>
2880 f.write( reinterpret_cast<const char*>(tmp.
mem), std::streamsize(n_elem) );
2892 template<
typename T1>
2900 f.open(name.c_str(), std::fstream::in | std::fstream::binary);
2902 bool load_okay = f.is_open();
2904 if(load_okay ==
true)
2915 template<
typename T1>
2923 typedef typename T1::elem_type eT;
2925 bool load_okay =
true;
2927 std::string f_header;
2930 if(f_header ==
"P6")
2947 if( (f_maxval > 0) || (f_maxval <= 65535) )
2960 const uword n_elem = 3*f_n_cols*f_n_rows;
2963 f.read( reinterpret_cast<char*>(tmp.
memptr()), std::streamsize(n_elem) );
2971 for(
uword row=0; row < f_n_rows; ++row)
2973 for(
uword col=0; col < f_n_cols; ++col)
2975 R.
at(row,col) = eT(tmp[i+0]);
2976 G.
at(row,col) = eT(tmp[i+1]);
2977 B.
at(row,col) = eT(tmp[i+2]);
2985 const uword n_elem = 3*f_n_cols*f_n_rows;
2988 f.read( reinterpret_cast<char *>(tmp.
memptr()), std::streamsize(2*n_elem) );
2992 for(
uword row=0; row < f_n_rows; ++row)
2994 for(
uword col=0; col < f_n_cols; ++col)
2996 R.
at(row,col) = eT(tmp[i+0]);
2997 G.
at(row,col) = eT(tmp[i+1]);
2998 B.
at(row,col) = eT(tmp[i+2]);
3010 err_msg =
"currently no code available to handle loading ";
3013 if(f.good() ==
false)
3022 err_msg =
"unsupported header in ";
3030 template<
typename T1>
3038 std::ofstream f( tmp_name.c_str(), std::fstream::binary );
3040 bool save_okay = f.is_open();
3042 if(save_okay ==
true)
3049 if(save_okay ==
true)
3060 template<
typename T1>
3069 typedef typename T1::elem_type eT;
3071 arma_debug_check( (x.
n_elem != 3),
"diskio::save_ppm_binary(): given field must have exactly 3 matrices of equal size" );
3073 bool same_size =
true;
3074 for(
uword i=1; i<3; ++i)
3076 if( (x(0).n_rows != x(i).n_rows) || (x(0).n_cols != x(i).n_cols) )
3083 arma_debug_check( (same_size !=
true),
"diskio::save_ppm_binary(): given field must have exactly 3 matrices of equal size" );
3110 f.write( reinterpret_cast<const char*>(tmp.
mem), std::streamsize(n_elem) );
static arma_inline const eT & tmp_real(const eT &X)
internal function to obtain the real part of either a plain number or a complex number ...
static bool save_raw_binary(const Mat< eT > &x, const std::string &final_name)
Save a matrix as raw binary (no header)
arma_inline const Op< T1, op_sum > sum(const Base< typename T1::elem_type, T1 > &X, const uword dim=0)
Delayed sum of elements of a matrix along a specified dimension (either rows or columns). The result is stored in a dense matrix that has either one column or one row. For dim = 0, find the sum of each column. For dim = 1, find the sum of each row. The default is dim = 0. NOTE: this function works differently than in Matlab/Octave.
arma_inline arma_warn_unused eT * memptr()
returns a pointer to array of eTs used by the matrix
A lightweight array for POD types. If the amount of memory requested is small, the stack is used...
static bool save_pgm_binary(const Mat< eT > &x, const std::string &final_name)
Save a matrix as a PGM greyscale image.
void set_size(const uword in_elem)
change the matrix to have user specified dimensions (data is not preserved)
static void conv_to_hex(char *out, const u8 x)
static out_eT from(const Base< in_eT, T1 > &in, const typename arma_not_cx< in_eT >::result *junk=0)
static bool load_arma_binary(Mat< eT > &x, const std::string &name, std::string &err_msg)
static bool load_pgm_binary(Mat< eT > &x, const std::string &name, std::string &err_msg)
Load a PGM greyscale image as a matrix.
static char conv_to_hex_char(const u8 x)
const uword n_rows
number of rows in the field (read-only)
static bool save_csv_ascii(const Mat< eT > &x, const std::string &final_name)
Save a matrix in CSV text format (human readable)
const uword n_cols
number of columns in the field (read-only)
static file_type guess_file_type(std::istream &f)
void set_size(const uword n_obj_in)
void set_size(const uword in_rows, const uword in_cols, const uword in_slices)
change the cube to have user specified dimensions (data is not preserved)
const uword n_cols
number of columns in the matrix (read-only)
const uword n_elem
number of elements in the matrix (read-only)
const uword n_rows
number of rows in the matrix (read-only)
comma separated values (CSV), without any other information
#define arma_type_check(condition)
static bool load_std_string(field< std::string > &x, const std::string &name, std::string &err_msg)
arma_inline arma_warn_unused eT * memptr()
returns a pointer to array of eTs used by the cube
const uword n_cols
number of columns in each slice (read-only)
static bool save_ppm_binary(const Cube< T1 > &x, const std::string &final_name)
static std::string gen_bin_header(const Mat< eT > &x)
static bool load_ppm_binary(Cube< T1 > &x, const std::string &final_name, std::string &err_msg)
static bool load_raw_binary(Mat< eT > &x, const std::string &name, std::string &err_msg)
arma_inline Mat< eT > & slice(const uword in_slice)
provide the reference to the matrix representing a single slice
arma_inline arma_warn_unused eT & at(const uword i)
linear element accessor (treats the matrix as a vector); no bounds check.
#define arma_ignore(variable)
static bool load_auto_detect(Mat< eT > &x, const std::string &name, std::string &err_msg)
Try to load a matrix by automatically determining its type.
static std::string gen_tmp_name(const std::string &x)
static bool save_raw_ascii(const Mat< eT > &x, const std::string &final_name)
arma_aligned const eT *const mem
pointer to the memory used by the cube (memory is read-only)
static bool load_raw_ascii(Mat< eT > &x, const std::string &name, std::string &err_msg)
static std::string gen_txt_header(const Mat< eT > &x)
#define arma_extra_debug_sigprint
static bool save_std_string(const field< std::string > &x, const std::string &name)
ASCII format (text), without any other information.
raw binary format, without any other information.
static bool safe_rename(const std::string &old_name, const std::string &new_name)
static bool load_arma_ascii(Mat< eT > &x, const std::string &name, std::string &err_msg)
static bool save_arma_ascii(const Mat< eT > &x, const std::string &final_name)
const uword n_elem
number of elements in the cube (read-only)
arma_inline eT * memptr()
static bool load_csv_ascii(Mat< eT > &x, const std::string &name, std::string &err_msg)
Load a matrix in CSV text format (human readable)
arma_aligned const eT *const mem
pointer to the memory used by the matrix (memory is read-only)
arma_aligned const eT *const mem
pointer to memory used by the object
static void pnm_skip_comments(std::istream &f)
const uword n_elem
number of elements in the field (read-only)
arma_inline arma_warn_unused bool is_empty() const
returns true if the matrix has no elements
static bool save_arma_binary(const Mat< eT > &x, const std::string &final_name)
const uword n_slices
number of slices in the cube (read-only)
const uword n_rows
number of rows in each slice (read-only)
arma_inline oT & at(const uword i)
linear element accessor (treats the field as a vector); no bounds check
arma_inline arma_warn_unused eT & at(const uword i)
linear element accessor (treats the cube as a vector); no bounds check.