2 #ifndef COMMON_NPYIO_HPP_     3 #define COMMON_NPYIO_HPP_    19   void parse_npy_header(FILE* fp) {
    21     int64_t res = fread(buffer, 
sizeof(
char), 11, fp);
    23       ERR << 
"Something wrong. Could not read header " << std::endl;
    27     std::cout << 
"first 11 characters::" << buffer << std::endl;
    29     std::string header = fgets(buffer, 256, fp);
    30     assert(header[header.size() - 1] == 
'\n');
    34     int64_t loc1 = header.find(
"fortran_order");
    36     this->m_fortran_order = (header.substr(loc1, 4) == 
"True" ? true : 
false);
    39     loc1 = header.find(
"(");
    40     int64_t loc2 = header.find(
")");
    41     if (loc1 < 0 || loc2 < 0) {
    42       ERR << 
"could not find ()" << std::endl;
    46     std::string str_shape = header.substr(loc1 + 1, loc2 - loc1 - 1);
    47     if (str_shape[str_shape.size() - 1] == 
',') {
    50       this->m_modes = std::count(str_shape.begin(), str_shape.end(), 
',') + 1;
    52     this->m_dims = arma::zeros<UVEC>(m_modes);
    54     std::stringstream ss(str_shape);
    58     while (getline(ss, s, 
',')) {
    59       this->m_dims[i++] = ::atoi(s.c_str());
    64     loc1 = header.find(
"descr");
    67         (header[loc1] == 
'<' || header[loc1] == 
'|' ? true : 
false);
    70     std::string word_size = header.substr(loc1 + 2);
    71     loc2 = word_size.find(
"'");
    72     this->m_word_size = atoi(word_size.substr(0, loc2).c_str());
    78     this->m_word_size = 0;
    79     this->m_fortran_order = 
false;
    82   void load(std::string fname) {
    83     FILE* fp = fopen(fname.c_str(), 
"rb");
    85       ERR << 
"Could not load the file " << fname << std::endl;
    89     this->m_input_tensor = 
new Tensor(this->m_dims);
    91                           sizeof(std::vector<double>::value_type),
    94       WARN << 
"something wrong ::read::" << nread
    95            << 
"::numel::" << this->m_input_tensor->
numel()
    96            << 
"::word_size::" << this->m_word_size << std::endl;
   100     INFO << 
"modes::" << this->m_modes << 
"::dims::" << std::endl
   101          << this->m_dims << 
"::fortran_order::" << this->m_fortran_order
   102          << 
"::word_size::" << this->m_word_size << std::endl;
   107 #endif  // COMMON_NPYIO_HPP_ Data is stored such that the unfolding  is column major. 
 
std::vector< double > m_data
 
void load(std::string fname)
 
UWORD numel() const
Returns total number of elements. 
 
ncp_factors contains the factors of the ncp every ith factor is of size n_i * k number of factors is ...