Beispiel #1
0
 void writeText(const char *fn) const {
   AzFile file(fn); 
   file.open("wb"); 
   int ix; 
   for (ix = 0; ix < num; ++ix) {
     AzBytArr s; s.cn(ints[ix]); s.nl(); 
     s.writeText(&file);  
   }
   file.close(true); 
 }
/*----------------------------------------------------------------------*/
void AzSvDataS::mergeData(const AzSmat *m_x,
                         const AzSvFeatInfo *feat,
                         const char *fn_template,
                         const char *str,
                         bool doSparse,
                         int digits,
                         const char *out_x_fn,
                         const char *out_n_fn,
                         int num,
                         const char *names[])
{
  const char *eyec = "AzSvDataS::mergeData";

  int data_num = m_x->colNum();
  int f_num = m_x->rowNum();
  if (feat->featNum() != f_num) {
    throw new AzException(eyec, "Conflict btw m_x and featInfo");
  }
  AzFile n_file(out_n_fn);
  n_file.open("wb");
  int fx;
  for (fx = 0; fx < feat->featNum(); ++fx) {
    AzBytArr s; feat->desc(fx, &s); s.nl();
    s.writeText(&n_file);
  }

  AzSmat m;
  m_x->transpose(&m);
  m.resize(data_num, f_num+num);
  AzStrPool sp_names;
  for (fx = 0; fx < num; ++fx) {
    AzBytArr s_fn(fn_template);
    s_fn.replace("*", names[fx]);

    AzDvect v;
    AzSvDataS::readVector(s_fn.c_str(), &v);
    if (v.rowNum() != m.rowNum()) {
      throw new AzException(AzInputError, eyec, "conflict in #data:", s_fn.c_str());
    }
    m.col_u(f_num+fx)->set(&v);

    AzBytArr s_nm;
    if (AzTools::isSpecified(str)) s_nm.c(str);
    s_nm.c(names[fx]); s_nm.nl();
    s_nm.writeText(&n_file);
  }
  n_file.close(true);

  AzSmat m1;
  m.transpose(&m1);
  m1.writeText(out_x_fn, digits, doSparse);
}
 /*--------------------------------------*/
 virtual void writeText(const char *fn, const AzIntArr *ia, int digits) const {
   AzFile file(fn); 
   file.open("wb"); 
   AzBytArr s;
   int ix; 
   for (ix = 0; ix < ia->size(); ++ix) {
     int row = ia->get(ix);  
     double val = get(row); 
     s.cn(val, digits); 
     s.nl(); 
   }
   s.writeText(&file); 
   file.close(true); 
 }
Beispiel #4
0
/*--------------------------------------------------------*/
int AzTools::writeList(const char *fn, 
                        const AzStrArray *sp_list)
{
  int max_len = 0; 
  AzFile file(fn); 
  file.open("wb"); 
  int num = sp_list->size(); 
  int ix; 
  for (ix = 0; ix < num; ++ix) {
    AzBytArr s; 
    sp_list->get(ix, &s); 
    s.concat("\n");
    max_len = MAX(max_len, s.getLen());  
    s.writeText(&file);  
  }
  file.close(true); 
  return max_len; 
}
  /*--------------------------------------*/
  virtual void writeText_sparse(const char *fn, const AzIntArr *ia, int digits) const {
    AzFile file(fn); 
    file.open("wb"); 
    AzBytArr s_header("sparse "); s_header.cn(rowNum()); s_header.nl(); 
    s_header.writeText(&file);

    int num; 
    const int *cxs = ia->point(&num); 
    int ix; 
    for (ix = 0; ix < num; ++ix) {
      int cx = cxs[ix];  
      AzBytArr s; 
      col(cx)->to_sparse(&s, digits); 
      s.nl(); 
      s.writeText(&file); 
    }
    file.close(true); 
  }
Beispiel #6
0
 /*--------------------------------------*/
 virtual void writeText(const char *fn, const AzIntArr *ia, 
                        int digits, 
                        bool doSparse=false) const {
   if (doSparse) {
     writeText_sparse(fn, ia, digits); 
     return; 
   }
   AzFile file(fn); 
   file.open("wb");
   int num; 
   const int *cxs = ia->point(&num);  
   int ix; 
   for (ix = 0; ix < num; ++ix) {
     int cx = cxs[ix];  
     AzBytArr s; 
     col(cx)->to_dense(&s, digits); 
     s.nl(); 
     s.writeText(&file); 
   }
   file.close(true); 
 }
 /*--------------------------------------*/
 virtual void writeText(const char *fn, const AzIntArr *ia, 
                        int digits, 
                        bool doSparse=false, 
                        bool doAppend=false) const {
   if (doSparse) {
     if (doAppend) throw new AzException("AzReadOnlyMatrix::writeText", "sparse matrices cannot be appended"); 
     writeText_sparse(fn, ia, digits); 
     return; 
   }
   AzFile file(fn); 
   if (doAppend) file.open("ab"); 
   else          file.open("wb");
   int num; 
   const int *cxs = ia->point(&num);  
   int ix; 
   for (ix = 0; ix < num; ++ix) {
     int cx = cxs[ix];  
     AzBytArr s; 
     col(cx)->to_dense(&s, digits); 
     s.nl(); 
     s.writeText(&file); 
   }
   file.close(true); 
 }