Edinburgh Speech Tools  2.1-release
EST_DMatrix.cc
Go to the documentation of this file.
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1995,1996 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32  /*************************************************************************/
33  /* */
34  /* Author : Simon King */
35  /* Date : February 1999 */
36  /* --------------------------------------------------------------------- */
37  /* Double matrix class - copied from DMatrix ! */
38  /* */
39  /*************************************************************************/
40 
41 #include <cstdlib>
42 #include <cstdio>
43 #include <fstream>
44 #include <sstream>
45 #include <cmath>
46 #include <climits>
47 #include "EST_String.h"
48 #include "EST_types.h"
49 #include "EST_FileType.h"
50 #include "EST_Option.h"
51 #include "EST_DMatrix.h"
52 #include "EST_cutils.h" // for swap functions
53 #include "EST_Token.h"
54 #include "rateconv.h"
55 
56 using namespace std;
57 
59 
61 :EST_TSimpleMatrix<double>(a.num_rows(), a.num_columns())
62 {
63  double vv = 0.0;
64  if (b < 0)
65  return;
66  if (b == 0)
67  fill(vv);
68 }
69 
71 {
72  ssize_t i, j;
73  if (a.num_columns() != num_columns())
74  {
75  cerr <<"Matrix addition error: bad number of columns\n";
76  return *this;
77  }
78  if (a.num_rows() != num_rows())
79  {
80  cerr <<"Matrix addition error: bad number of rows\n";
81  return *this;
82  }
83  for (i = 0; i < num_rows(); ++i)
84  for (j = 0; j < num_columns(); ++j)
85  a_no_check(i, j) += a.a_no_check(i,j);
86 
87  return *this;
88 }
89 
91 {
92  ssize_t i, j;
93  if (a.num_columns() != num_columns())
94  {
95  cerr <<"Matrix subtraction error: bad number of columns\n";
96  return *this;
97  }
98  if (a.num_rows() != num_rows())
99  {
100  cerr <<"Matrix subtraction error: bad number of rows\n";
101  return *this;
102  }
103  for (i = 0; i < num_rows(); ++i)
104  for (j = 0; j < num_columns(); ++j)
105  a_no_check(i, j) -= a.a_no_check(i,j);
106 
107  return *this;
108 }
109 
111 {
112 
113  ssize_t i,j;
114  for (i = 0; i < num_rows(); ++i)
115  for (j = 0; j < num_columns(); ++j)
116  a_no_check(i, j) *= f;
117 
118  return *this;
119 }
120 
122 {
123 
124  ssize_t i,j;
125  for (i = 0; i < num_rows(); ++i)
126  for (j = 0; j < num_columns(); ++j)
127  a_no_check(i, j) /= f;
128 
129  return *this;
130 }
131 
133 {
134  EST_DMatrix ab;
135  ssize_t i, j;
136  if (a.num_columns() != b.num_columns())
137  {
138  cerr <<"Matrix addition error: bad number of columns\n";
139  return ab;
140  }
141  if (a.num_rows() != b.num_rows())
142  {
143  cerr <<"Matrix addition error: bad number of rows\n";
144  return ab;
145  }
146  ab.resize(a.num_rows(), a.num_columns());
147  for (i = 0; i < a.num_rows(); ++i)
148  for (j = 0; j < a.num_columns(); ++j)
149  ab.a_no_check(i, j) = a.a_no_check(i, j) + b.a_no_check(i, j);
150 
151  return ab;
152 }
153 
155 {
156  EST_DMatrix ab;
157  ssize_t i, j;
158 
159  if (a.num_columns() != b.num_columns())
160  {
161  cerr <<"Matrix subtraction error: bad number of columns:" <<
162  a.num_columns() << " and " << b.num_columns() << endl;
163  return ab;
164  }
165  if (a.num_rows() != b.num_rows())
166  {
167  cerr <<"Matrix subtraction error: bad number of rows\n";
168  return ab;
169  }
170  ab.resize(a.num_rows(), a.num_columns());
171  for (i = 0; i < a.num_rows(); ++i)
172  for (j = 0; j < a.num_columns(); ++j)
173  ab.a_no_check(i, j) = a.a_no_check(i, j) - b.a_no_check(i, j);
174 
175  return ab;
176 }
177 
178 EST_DMatrix operator*(const double x, const EST_DMatrix &a)
179 {
180  return a*x;
181 }
182 
183 EST_DMatrix operator*(const EST_DMatrix &a, const double x)
184 {
185  EST_DMatrix b(a, 0);
186  ssize_t i, j;
187 
188  for (i = 0; i < a.num_rows(); ++i)
189  for (j = 0; j < a.num_columns(); ++j)
190  b.a_no_check(i,j) = a.a_no_check(i,j) * x;
191 
192  return b;
193 }
194 
196 {
197  // treat the vector as a column vector
198  // multiply each row of the matrix in turn by the vector
199 
200  EST_DVector b;
201  b.resize(a.num_rows());
202 
203  if(a.num_columns() != v.n())
204  {
205  cerr <<"Matrix-vector multiplication error: matrix rows != vector size"
206  << endl;
207  return b;
208  }
209 
210  ssize_t i, j;
211  for (i = 0; i < a.num_rows(); ++i){
212  b[i] = 0.0;
213  for (j = 0; j < a.num_columns(); ++j)
214  b.a_no_check(i) += a.a_no_check(i,j) * v.a_no_check(j);
215  }
216  return b;
217 }
218 
220 {
221  EST_DVector ab;
222  ssize_t i;
223  if (a.length() != b.length())
224  {
225  cerr <<"Vector addition error: mismatched lengths\n";
226  return ab;
227  }
228 
229  ab.resize(a.length());
230  for (i = 0; i < a.length(); ++i)
231  ab.a_no_check(i) = a.a_no_check(i) + b.a_no_check(i);
232 
233  return ab;
234 }
235 
237 {
238  EST_DVector ab;
239  ssize_t i;
240  if (a.length() != b.length())
241  {
242  cerr <<"Vector subtraction error: mismatched lengths\n";
243  return ab;
244  }
245 
246  ab.resize(a.length());
247  for (i = 0; i < a.length(); ++i)
248  ab.a_no_check(i) = a.a_no_check(i) - b.a_no_check(i);
249 
250  return ab;
251 }
252 
253 
255 {
256  // treat the vector as a row vector
257  // multiply the vector by each column of the matrix in turn
258 
259  EST_DVector b;
260  b.resize(a.num_columns());
261 
262  if(a.num_columns() != v.n())
263  {
264  cerr <<"Matrix-vector multiplication error: matrix rows != vector size"
265  << endl;
266  return b;
267  }
268 
269  ssize_t i, j;
270  for (j = 0; j < a.num_columns(); ++j){
271  b[j] = 0.0;
272  for (i = 0; i < a.num_rows(); ++i)
273  b.a_no_check(i) += a.a_no_check(i,j) * v.a_no_check(j);
274  }
275  return b;
276 }
277 
278 
279 #if 0
280 EST_DMatrix operator/(const EST_DMatrix &a, double x)
281 {
282  return (a * (1/x));
283 }
284 #endif
285 
287 {
288  EST_DMatrix ab;
289  multiply(a,b,ab);
290  return ab;
291 }
292 
293 void multiply(const EST_DMatrix &a, const EST_DMatrix &b, EST_DMatrix &ab)
294 {
295 
296  if (a.num_columns() != b.num_rows())
297  {
298  cerr <<"Matrix multiply error: a.num_columns() != b.num_rows()\n";
299  return;
300  }
301 
302  ab.resize(a.num_rows(), b.num_columns());
303  ssize_t i, j, k, n;
304  n = a.num_columns(); // could also be b.num_rows()
305 
306  for (i = 0; i < a.num_rows(); ++i)
307  for (k = 0; k < b.num_columns(); ++k)
308  {
309  ab.a_no_check(i, k) = 0.0;
310  for (j = 0; j < n; ++j)
311  ab.a_no_check(i, k) +=
312  a.a_no_check(i, j) * b.a_no_check(j, k);
313  }
314 }
315 
316 void EST_DMatrix::copyin(double **inx, ssize_t rows, ssize_t cols)
317 {
318  ssize_t i, j;
319 
320  resize(rows, cols);
321 
322  for (i = 0; i < rows; ++i)
323  for (j = 0; j < cols; ++j)
324  a_no_check(i,j) = inx[i][j];
325 
326 }
327 
329  const EST_String &type)
330 {
331 
332  if ((type == "est_ascii") || (type == "est_binary"))
333  return est_save(filename,type);
334  else
335  { // the old stuff raw unheadered
336  ssize_t i, j;
337  ostream *outf;
338  if (filename == "-")
339  outf = &cout;
340  else
341  outf = new ofstream(filename);
342 
343  outf->precision(25);
344  if (!(*outf))
345  {
346  cerr << "DMatrix: can't open file \"" << filename
347  <<"\" for writing" << endl;
348  return misc_write_error;
349  }
350 
351  for (i = 0; i < num_rows(); ++i)
352  {
353  for (j = 0; j < num_columns(); ++j)
354  *outf << a_no_check(i,j) << " ";
355  *outf << endl;
356  }
357 
358  if (outf != &cout)
359  delete outf;
360 
361  return write_ok;
362  }
363 }
364 
366  const EST_String &type)
367 {
368  // Binary save with short header for byte swap and sizes
369  ssize_t i,j;
370  FILE *fd;
371 
372  /* size_t does not have a ISO C++ printf format specifier (%zd is
373  * not standard for C++ 1998 nor C++ 2003). We use a workaround. */
374  std::stringstream tmpstring;
375  std::string tmpstring2;
376 
377  if (filename == "-")
378  fd = stdout;
379  else if ((fd = fopen(filename, "wb")) == NULL)
380  {
381  cerr << "EST_DMatrix: binsave: failed to open \"" << filename <<
382  "\" for writing" << endl;
383  return misc_write_error;
384  }
385 
386  fprintf(fd,"EST_File dmatrix\n");
387  fprintf(fd,"version 1\n");
388  if (type == "est_binary")
389  {
390  fprintf(fd,"DataType binary\n");
391  if (EST_LITTLE_ENDIAN)
392  fprintf(fd,"ByteOrder LittleEndian\n");
393  else
394  fprintf(fd,"ByteOrder BigEndian\n");
395  }
396  else
397  fprintf(fd,"DataType ascii\n");
398 
399  tmpstring.str("");
400  tmpstring << num_rows();
401  tmpstring2 = tmpstring.str();
402  fprintf(fd,"rows %s\n", tmpstring2.c_str());
403  tmpstring.str("");
404  tmpstring << num_columns();
405  tmpstring2 = tmpstring.str();
406  fprintf(fd,"columns %s\n", tmpstring2.c_str());
407 
408  fprintf(fd,"EST_Header_End\n");
409 
410  if (type == "est_binary")
411  {
412  for (i = 0; i < num_rows(); ++i)
413  for (j=0; j < num_columns(); j++)
414  if (fwrite(&a_no_check(i,j),sizeof(double),1,fd) != 1)
415  {
416  cerr << "EST_DMatrix: binsave: failed to write row "
417  << i << " column " << j
418  << " to \"" << filename << "\"" << endl;
419  if (fd != stdout) fclose(fd);
420  return misc_write_error;
421  }
422  }
423  else
424  { // est_ascii
425  for (i = 0; i < num_rows(); ++i)
426  {
427  for (j=0; j < num_columns(); j++)
428  fprintf(fd,"%.25f ",a_no_check(i,j));
429  fprintf(fd,"\n");
430  }
431  }
432 
433  if (fd != stdout)
434  fclose(fd);
435 
436  return write_ok;
437 }
438 
440 {
441 
442  // ascii/binary load with short header for byte swap and sizes
443  ssize_t i,j,k;
444  int rows, cols, swap;
445  EST_TokenStream ts;
446  EST_read_status r;
447  EST_EstFileType t;
448  EST_Option hinfo;
449  bool ascii;
450 
451  if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
452  {
453  cerr << "DMatrix: can't open DMatrix input file "
454  << filename << endl;
455  return misc_read_error;
456  }
457  if ((r = read_est_header(ts, hinfo, ascii, t)) != format_ok)
458  return r;
459  if (t != est_file_dmatrix)
460  return misc_read_error;
461  if (hinfo.ival("version") != 1)
462  {
463  cerr << "DMatrix load: " << ts.pos_description() <<
464  " wrong version of DMatrix format expected 1 but found " <<
465  hinfo.ival("version") << endl;
466  return misc_read_error;
467  }
468  rows = hinfo.ival("rows");
469  cols = hinfo.ival("columns");
470  resize(rows,cols);
471 
472  if (ascii)
473  { // an ascii file
474  for (i = 0; i < num_rows(); ++i)
475  {
476  for (j = 0; j < num_columns(); ++j)
477  a_no_check(i,j) = atof(ts.get().string());
478  if (!ts.eoln())
479  {
480  cerr << "DMatrix load: " << ts.pos_description() <<
481  " missing end of line at end of row " << i << endl;
482  return misc_read_error;
483  }
484  }
485  }
486  else
487  { // a binary file
488  double *buff;
489  if ((EST_BIG_ENDIAN && (hinfo.sval("ByteOrder")=="LittleEndian")) ||
490  (EST_LITTLE_ENDIAN && (hinfo.sval("ByteOrder") == "BigEndian")))
491  swap = TRUE;
492  else
493  swap = FALSE;
494 
495  buff = walloc(double,rows*cols);
496  // A single read is *much* faster than multiple reads
497  if (ts.fread(buff,sizeof(double),rows*cols) != rows*cols)
498  {
499  cerr << "EST_DMatrix: binload: short file in \""
500  << filename << "\"" << endl;
501  wfree(buff);
502  return misc_read_error;
503  }
504  if (swap)
505  swap_bytes_double(buff,rows*cols);
506  for (k = i = 0; i < num_rows(); ++i)
507  for (j = 0; j < num_columns(); ++j)
508  a_no_check(i,j) = buff[k++];
509  wfree(buff);
510  }
511 
512  ts.close();
513  return read_ok;
514 }
515 
517 {
518  EST_read_status r;
519 
520  if ((r = est_load(filename)) == format_ok)
521  return r;
522  else if (r == wrong_format)
523  { // maybe its an ancient ascii file
524  EST_TokenStream ts, tt;
525  EST_StrList sl;
526  ssize_t i, j, n_rows=0, n_cols=0;
527  EST_String t;
528  EST_Litem *p;
529  if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
530  {
531  cerr << "Can't open DMatrix file " << filename << endl;
532  return misc_read_error;
533  }
534  // set up the character constant values for this stream
535  ts.set_SingleCharSymbols(";");
536 
537  // first read in as list
538  for (n_rows = 0; !ts.eof(); ++n_rows)
539  sl.append(ts.get_upto_eoln().string());
540 
541  if (n_rows > 0)
542  {
543  tt.open_string(sl.first());
544  for (n_cols = 0; !tt.eof(); ++n_cols)
545  tt.get().string();
546  }
547 
548  // resize track and copy values in
549  resize(n_rows, n_cols);
550 
551  for (p = sl.head(), i = 0; p != 0; ++i, p = p->next())
552  {
553  tt.open_string(sl(p));
554  for (j = 0; !tt.eof(); ++j)
555  a_no_check(i,j) = atof(tt.get().string());
556  if (j != n_cols)
557  {
558  cerr << "Wrong number of points in row " << i << endl;
559  cerr << "Expected " << n_cols << " got " << j << endl;
560  return misc_read_error;
561  }
562  }
563  return format_ok;
564  }
565  else
566  return r;
567 
568  return format_ok;
569 }
570 
572 {
573  // ascii/binary load with short header for byte swap and sizes
574  ssize_t i,k;
575  int l, swap;
576  EST_TokenStream ts;
577  EST_read_status r;
578  EST_EstFileType t;
579  EST_Option hinfo;
580  bool ascii;
581 
582  if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
583  {
584  cerr << "DVector: can't open DVector input file "
585  << filename << endl;
586  return misc_read_error;
587  }
588  if ((r = read_est_header(ts, hinfo, ascii, t)) != format_ok)
589  return r;
590  if (t != est_file_dvector)
591  return misc_read_error;
592  if (hinfo.ival("version") != 1)
593  {
594  cerr << "DVector load: " << ts.pos_description() <<
595  " wrong version of DVector format expected 1 but found " <<
596  hinfo.ival("version") << endl;
597  return misc_read_error;
598  }
599  l = hinfo.ival("length");
600  resize(l);
601 
602  if (ascii)
603  { // an ascii file
604  for (i = 0; i < length(); ++i)
605  a_no_check(i) = atof(ts.get().string());
606  }
607  else
608  { // a binary file
609  double *buff;
610  if ((EST_BIG_ENDIAN && (hinfo.sval("ByteOrder")=="LittleEndian")) ||
611  (EST_LITTLE_ENDIAN && (hinfo.sval("ByteOrder") == "BigEndian")))
612  swap = TRUE;
613  else
614  swap = FALSE;
615 
616  buff = walloc(double,l);
617  // A single read is *much* faster than multiple reads
618  if (ts.fread(buff,sizeof(double),l) != l)
619  {
620  cerr << "EST_DVector: binload: short file in \""
621  << filename << "\"" << endl;
622  wfree(buff);
623  return misc_read_error;
624  }
625  if (swap)
626  swap_bytes_double(buff,l);
627  for (k = i = 0; i < length(); ++i)
628  a_no_check(i) = buff[k++];
629  wfree(buff);
630  }
631 
632  ts.close();
633  return read_ok;
634 }
635 
637 {
638 
639  EST_read_status r;
640 
641  if ((r = est_load(filename)) == format_ok)
642  return r;
643  else if (r == wrong_format)
644  { // maybe its an ancient ascii file
645  EST_TokenStream ts;
646  EST_String s;
647  int i;
648 
649  i = 0;
650 
651  if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
652  {
653  cerr << "can't open vector input file " << filename << endl;
654  return misc_read_error;
655  }
656  ts.set_SingleCharSymbols(";");
657 
658  while (!ts.eof())
659  {
660  ts.get();
661  ++i;
662  }
663  resize(i);
664 
665  ts.close();
666  if (((filename == "-") ? ts.open(cin) : ts.open(filename)) != 0)
667  {
668  cerr << "can't open vector input file " << filename << endl;
669  return misc_read_error;
670  }
671 
672  for (i = 0; !ts.eof(); ++i)
673  {
674  s = ts.get().string();
675  (*this)[i] = atof(s); // actually returns double
676  }
677  ts.close();
678  return format_ok;
679  }
680  else
681  return r;
682 
683  return format_ok;
684 
685 }
686 
687 
689 {
690  ssize_t i;
691  if(n() != s.n()){
692  cerr << "Cannot elementwise add vectors of differing lengths"
693  << endl;
694  return *this;
695  }
696 
697  for (i = 0; i < n(); ++i)
698  (*this)[i] += s(i);
699 
700 
701  return *this;
702 }
703 
704 
706 {
707  if(n() != s.n()){
708  cerr << "Cannot elementwise multiply vectors of differing lengths"
709  << endl;
710  return *this;
711  }
712 
713  for (ssize_t i = 0; i < n(); ++i)
714  (*this)[i] *= s(i);
715 
716  return *this;
717 }
718 
720 {
721  for (ssize_t i = 0; i < n(); ++i)
722  (*this)[i] *= f;
723 
724  return *this;
725 }
726 
727 double operator*(const EST_DVector &v1, const EST_DVector &v2)
728 {
729  if(v1.length() != v2.length())
730  {
731  cerr << "Can't do vector dot prod - differing vector sizes !" << endl;
732  return 0;
733  }
734  double p=0;
735  for (ssize_t i = 0; i < v1.length(); ++i)
736  p += v1.a_no_check(i) * v2.a_no_check(i);
737 
738  return p;
739 }
740 
741 
743 {
744  for (ssize_t i = 0; i < n(); ++i)
745  (*this)[i] /= f;
746 
747  return *this;
748 }
749 
750 
752  const EST_String &type)
753 {
754 
755  if ((type == "est_ascii") || (type == "est_binary"))
756  return est_save(filename,type);
757  else
758  { // the old stuff raw unheadered
759  ssize_t i;
760  ostream *outf;
761  if (filename == "-")
762  outf = &cout;
763  else
764  outf = new ofstream(filename);
765 
766  outf->precision(25);
767  if (!(*outf))
768  {
769  cerr << "DVector: can't open file \"" << filename
770  <<"\" for writing" << endl;
771  return misc_write_error;
772  }
773 
774  for (i = 0; i < length(); ++i)
775  *outf << a_no_check(i) << " ";
776  *outf << endl;
777 
778  if (outf != &cout)
779  delete outf;
780 
781  return write_ok;
782  }
783 }
784 
786  const EST_String &type)
787 {
788  // Binary save with short header for byte swap and sizes
789  ssize_t i;
790  std::stringstream tmpstring;
791  std::string tmpstring2;
792  FILE *fd;
793  if (filename == "-")
794  fd = stdout;
795  else if ((fd = fopen(filename, "wb")) == NULL)
796  {
797  cerr << "EST_DVector: binsave: failed to open \"" << filename <<
798  "\" for writing" << endl;
799  return misc_write_error;
800  }
801 
802  fprintf(fd,"EST_File dvector\n");
803  fprintf(fd,"version 1\n");
804  if (type == "est_binary")
805  {
806  fprintf(fd,"DataType binary\n");
807  if (EST_LITTLE_ENDIAN)
808  fprintf(fd,"ByteOrder LittleEndian\n");
809  else
810  fprintf(fd,"ByteOrder BigEndian\n");
811  }
812  else
813  fprintf(fd,"DataType ascii\n");
814 
815  tmpstring.str("");
816  tmpstring << length();
817  tmpstring2 = tmpstring.str();
818  fprintf(fd,"length %s\n", tmpstring2.c_str());
819  fprintf(fd,"EST_Header_End\n");
820 
821  if (type == "est_binary")
822  {
823  for (i = 0; i < length(); ++i)
824  if (fwrite(&a_no_check(i),sizeof(double),1,fd) != 1)
825  {
826  cerr << "EST_DVector: binsave: failed to write item "
827  << i << " to \"" << filename << "\"" << endl;
828  if (fd != stdout) fclose(fd);
829  return misc_write_error;
830  }
831  }
832  else
833  { // est_ascii
834  for (i = 0; i < length(); ++i)
835  fprintf(fd,"%.25f ",a_no_check(i));
836  fprintf(fd,"\n");
837  }
838 
839  if (fd != stdout)
840  fclose(fd);
841 
842  return write_ok;
843 }
844 
EST_write_status save(const EST_String &filename, const EST_String &type=EST_DMatrix::default_file_type)
Save in file (ascii or binary)
Definition: EST_DMatrix.cc:328
EST_TokenStream & get(EST_Token &t)
get next token in stream
Definition: EST_Token.cc:499
#define walloc(TYPE, SIZE)
Definition: EST_walloc.h:52
EST_DVector & operator/=(const double d)
elementwise divide by scalar
Definition: EST_DMatrix.cc:742
EST_write_status save(const EST_String &filename, const EST_String &type)
save vector to file filename.
Definition: EST_DMatrix.cc:751
EST_read_status est_load(const EST_String &filename)
Load from file in est format (binary/ascii defined in file itself)
Definition: EST_DMatrix.cc:571
EST_write_status
The file was read in successfully.
int fread(void *buff, int size, int nitems) EST_WARN_UNUSED_RESULT
Reading binary data, (don&#39;t use peek() immediately beforehand)
Definition: EST_Token.cc:368
static EST_String default_file_type
Definition: EST_DMatrix.h:66
ssize_t num_columns() const
return number of columns
Definition: EST_TMatrix.h:179
int ival(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:82
EST_EstFileType
Definition: EST_FileType.h:50
void set_SingleCharSymbols(const EST_String &sc)
set which characters are to be treated as single character symbols
Definition: EST_Token.h:344
void close(void)
Close stream.
Definition: EST_Token.cc:419
INLINE const T & a_no_check(ssize_t n) const
read-only const access operator: without bounds checking
Definition: EST_TVector.h:254
EST_DVector & operator+=(const EST_DVector &s)
elementwise add
Definition: EST_DMatrix.cc:688
friend EST_DMatrix operator*(const EST_DMatrix &a, const double x)
Multiply all elements of matrix by x.
Definition: EST_DMatrix.cc:183
void swap_bytes_double(double *data, int length)
Definition: EST_swapping.cc:68
ssize_t num_rows() const
return number of rows
Definition: EST_TMatrix.h:177
int ssize_t
const double & a(ssize_t row, ssize_t col) const
Definition: EST_TMatrix.h:196
void copyin(double **x, ssize_t rows, ssize_t cols)
Copy 2-d array x of size rows x cols into matrix.
Definition: EST_DMatrix.cc:316
EST_UItem * next()
Definition: EST_UList.h:55
EST_read_status load(const EST_String &filename)
load vector from file filename.
Definition: EST_DMatrix.cc:636
EST_DVector & operator*=(const EST_DVector &s)
elementwise multiply
Definition: EST_DMatrix.cc:705
int open(const EST_String &filename)
open a EST_TokenStream for a file.
Definition: EST_Token.cc:213
int open_string(const EST_String &newbuffer)
open a EST_TokenStream for string rather than a file
Definition: EST_Token.cc:264
int eof()
end of file
Definition: EST_Token.h:362
EST_DMatrix()
default constructor
Definition: EST_DMatrix.h:70
INLINE ssize_t length() const
number of items in vector.
Definition: EST_TVector.h:249
const EST_String & sval(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:93
#define misc_write_error
EST_DMatrix & operator+=(const EST_DMatrix &a)
Add elements of 2 same sized matrices.
Definition: EST_DMatrix.cc:70
The file was written successfully.
#define wrong_format
EST_Complex operator/(const EST_Complex &z1, const EST_Complex &z2)
Definition: EST_Complex.cc:95
void multiply(const EST_DMatrix &a, const EST_DMatrix &b, EST_DMatrix &ab)
Definition: EST_DMatrix.cc:293
#define FALSE
Definition: EST_bool.h:119
EST_read_status read_est_header(EST_TokenStream &ts, EST_Option &hinfo, bool &ascii, EST_EstFileType &t)
Definition: est_file.cc:143
#define misc_read_error
NULL
Definition: EST_WFST.cc:55
A vector class for double precision floating point numbers. EST_DVector x should be used instead of f...
Definition: EST_DMatrix.h:122
const T & first() const
return const reference to first item in list
Definition: EST_TList.h:152
f
Definition: EST_item_aux.cc:48
#define EST_LITTLE_ENDIAN
Definition: EST_cutils.h:71
EST_DMatrix & operator*=(const double f)
elementwise multiply by scalar
Definition: EST_DMatrix.cc:110
void append(const T &item)
add item onto end of list
Definition: EST_TList.h:196
EST_DMatrix operator-(const EST_DMatrix &a, const EST_DMatrix &b)
Definition: EST_DMatrix.cc:154
EST_read_status
const EST_String & string() const
Definition: EST_Token.h:120
#define format_ok
const EST_String pos_description()
A string describing current position, suitable for error messages.
Definition: EST_Token.cc:882
#define EST_BIG_ENDIAN
Definition: EST_cutils.h:69
EST_Token get_upto_eoln(void)
get up to s in end of line as a single token.
Definition: EST_Token.cc:529
EST_DMatrix & operator/=(const double f)
elementwise divide by scalar
Definition: EST_DMatrix.cc:121
EST_UItem * head() const
Definition: EST_UList.h:97
INLINE const double & a_no_check(ssize_t row, ssize_t col) const
const access with no bounds check, care recommend
Definition: EST_TMatrix.h:182
EST_read_status load(const EST_String &filename)
Load from file (ascii or binary as defined in file)
Definition: EST_DMatrix.cc:516
void resize(int rows, int cols, int set=1)
resize matrix
A subclass of EST_TMatrix which copies using memcopy.
EST_DMatrix & operator-=(const EST_DMatrix &a)
Subtract elements of 2 same sized matrices.
Definition: EST_DMatrix.cc:90
void wfree(void *p)
Definition: walloc.c:131
#define TRUE
Definition: EST_bool.h:118
INLINE ssize_t n() const
number of items in vector.
Definition: EST_TVector.h:251
EST_write_status est_save(const EST_String &filename, const EST_String &type)
Save in file in est format.
Definition: EST_DMatrix.cc:365
EST_DMatrix operator+(const EST_DMatrix &a, const EST_DMatrix &b)
Definition: EST_DMatrix.cc:132
void resize(int n, int set=1)
resize vector
int eoln()
end of line
Definition: EST_Token.cc:832
EST_write_status est_save(const EST_String &filename, const EST_String &type)
Definition: EST_DMatrix.cc:785
EST_read_status est_load(const EST_String &filename)
Load from file in est format (binary/ascii defined in file itself)
Definition: EST_DMatrix.cc:439