UQTk: Uncertainty Quantification Toolkit  3.1.1
Array1D.h
Go to the documentation of this file.
1 /* =====================================================================================
2 
3  The UQ Toolkit (UQTk) version 3.1.1
4  Copyright (2021) NTESS
5  https://www.sandia.gov/UQToolkit/
6  https://github.com/sandialabs/UQTk
7 
8  Copyright 2021 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
9  Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government
10  retains certain rights in this software.
11 
12  This file is part of The UQ Toolkit (UQTk)
13 
14  UQTk is open source software: you can redistribute it and/or modify
15  it under the terms of BSD 3-Clause License
16 
17  UQTk is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  BSD 3 Clause License for more details.
21 
22  You should have received a copy of the BSD 3 Clause License
23  along with UQTk. If not, see https://choosealicense.com/licenses/bsd-3-clause/.
24 
25  Questions? Contact the UQTk Developers at <uqtk-developers@software.sandia.gov>
26  Sandia National Laboratories, Livermore, CA, USA
27 ===================================================================================== */
30 
31 #ifndef ARRAY1D_H_SEEN
32 #define ARRAY1D_H_SEEN
33 
34 #include <string>
35 #include <string.h>
36 #include <iostream>
37 #include <vector>
38 #include <fstream>
39 #include <iterator>
40 #include <algorithm>
41 #include <typeinfo>
42 
43 #include "error_handlers.h"
44 
45 using namespace std;
46 
47 // template<typename T> T max_test(T a, T b) { return a > b ? a : b; }
48 
59 //column major for fortran blas
60 template<typename T>
61 class Array1D{
62 private:
63 
64 public:
65  // These two quantities used to be private but making them public
66  // allows for easy access to python interface as a "list"
67  int xsize_; // public (used to be private) size of vector
68  vector<T> data_; // public (used to be private) copy of data vector
69 
71  Array1D(): xsize_(0) {};
72 
74  Array1D(const int& nx): xsize_(nx) {
75  data_.resize(xsize_);
76  }
77 
79  Array1D(const int& nx, const T& t): xsize_(nx) {
80  data_.resize(xsize_, t);
81  }
82 
84  Array1D& operator=(const Array1D &obj) {
85  xsize_ = obj.xsize_;
86  data_ = obj.data_;
87  return *this;
88  }
89 
91  Array1D(const Array1D &obj): xsize_(obj.xsize_), data_(obj.data_) {};
92 
94  ~Array1D() {data_.clear();}
95 
97  void Clear() {
98  xsize_ = 0;
99  data_.clear();
100  }
101 
103  int XSize() const {return xsize_;}
104 
106  int Length() const {return xsize_;}
107 
109  void Resize(const int& nx) {
110  xsize_ = nx;
111  data_.resize(xsize_);
112  }
113 
116  void Resize(const int& nx, const T& t) {
117  data_.clear();
118  xsize_ = nx;
119  data_.resize(xsize_, t);
120  }
121 
123  void SetValue(const T& t){
124  for(int i=0; i < data_.size(); i++){
125  data_[i] = t;
126  }
127  }
128 
130  void PushBack(const T& t){
131  xsize_ += 1;
132  data_.push_back(t);
133  }
134 
139  return &(data_[0]);
140  }
141 
145  const T* GetConstArrayPointer() const {
146  return &(data_[0]);
147  }
148 
149  // allows access element by element, e.g. this(i) gives data_[i]
150  T& operator()(int ix) {return data_[ix];}
151  const T& operator()(int ix) const {return data_[ix];}
152 
155  void insert(Array1D<T>& insarr,int ix){
156  if (ix<0 || ix>xsize_){
157  throw Tantrum("Array1D:insert():: insert index out of bounds.");
158  }
159  int addsize = insarr.Length();
160  xsize_+=addsize;
161  T* ptr=insarr.GetArrayPointer();
162  data_.insert(data_.begin()+ix,ptr,ptr+addsize);
163  }
164 
167  void insert(const T& insval,int ix){
168  if (ix<0 || ix>xsize_)
169  throw Tantrum("Array1D:insert():: insert index out of bounds.");
170  xsize_+=1;
171  data_.insert(data_.begin()+ix,insval);
172  }
173 
175  void erase(int ix){
176  if (ix<0 || ix>=xsize_)
177  throw Tantrum("Array1D:erase():: erase index out of bounds.");
178  xsize_-=1;
179  data_.erase(data_.begin()+ix);
180  }
181 
183  void DumpBinary(FILE* f_out) const {
184  fwrite(&xsize_,sizeof(xsize_),1,f_out);
185  fwrite(this->GetConstArrayPointer(),sizeof(T),xsize_,f_out);
186  }
187 
189  void ReadBinary(FILE* f_in){
190  fread(&xsize_,sizeof(xsize_),1,f_in);
191  data_.resize(xsize_);
192  fread(this->GetArrayPointer(),sizeof(T),xsize_,f_in);
193  }
194 
195  /**********************************************************
196  // Methods for interfacing with python
197  **********************************************************/
198 
199  // For calling [] in Python
200  T& operator[](int i) {return data_[i];}
201 
203  // cannot be read with numpy's fromfile after creation
204  void DumpBinary(char *filename){
205  FILE *f_out;
206  f_out = fopen(filename,"wb");
207  fwrite(&xsize_,sizeof(xsize_),1,f_out);
208  fwrite(this->GetConstArrayPointer(),sizeof(T),xsize_,f_out);
209  fclose(f_out);
210  }
211 
212  // read binary file created with DumpBinary
213  // Cannot use numpy's from files
214  // only for use in c++
215  void ReadBinary(char *filename){
216  FILE *f_in;
217  f_in = fopen(filename,"rb");
218  fread(&xsize_,sizeof(xsize_),1,f_in);
219  data_.resize(xsize_);
220  fread(this->GetArrayPointer(),sizeof(T),xsize_,f_in);
221  fclose(f_in);
222  }
223 
224  // Following two methods are not compatable with certain clang comilers
225  // creates binary file that can be read with numpy's fromfile
226  void DumpBinary4py(char *filename){
227  ofstream f_out;
228  f_out.open(filename, ios::out | ios::binary);
229  f_out.write((char*)this->GetArrayPointer(),sizeof(T[xsize_])); // convert array pointer to char string
230  f_out.close();
231  }
232 
233  // can read in DumpBinary4py output, but needs size of vector
234  // fromfile can automatically detect size file, so, if need by, one can use numpy's fromfile to determine # of elements
235  void ReadBinary4py(char *filename, int n){
236  xsize_ = n;
237  ifstream f_in;
238  f_in.open(filename, ios::in | ios::binary);
239  f_in.read((char*)this->GetArrayPointer(),sizeof(T[xsize_])); // convert array pointer to char string
240  f_in.close();
241  }
242 
243  // Set user-defined list to data_ vector
244  // This will work even for string type
245  void setArray(vector<T> inarray){
246  data_ = inarray;
247  xsize_ = inarray.size();
248  }
249 
250  // Returns data_ vector as a list in python
251  // Also acts as a print to see individual elements
252  vector<T> flatten(){
253  return data_;
254  }
255 
256  string type(){
257  return "string";
258  }
259 };
260 
261 template<>
262 class Array1D <int>{
263 private:
264  int xsize_; // private size of vector
265 public:
266  vector<int> data_; // private copy of data vector
267 
269  Array1D(): xsize_(0) {};
270 
272  Array1D(const int& nx): xsize_(nx) {
273  data_.resize(xsize_);
274  }
275 
277  Array1D(const int& nx, const int& t): xsize_(nx) {
278  data_.resize(xsize_, t);
279  }
280 
282  Array1D& operator=(const Array1D &obj) {
283  xsize_ = obj.xsize_;
284  data_ = obj.data_;
285  return *this;
286  }
287 
289  Array1D(const Array1D &obj): xsize_(obj.xsize_), data_(obj.data_) {};
290 
292  ~Array1D() {data_.clear();}
293 
295  void Clear() {
296  xsize_ = 0;
297  data_.clear();
298  }
299 
301  int XSize() const {return xsize_;}
302 
304  int Length() const {return xsize_;}
305 
307  void Resize(const int& nx) {
308  xsize_ = nx;
309  data_.resize(xsize_);
310  }
311 
314  void Resize(const int& nx, const int& t) {
315  data_.clear();
316  xsize_ = nx;
317  data_.resize(xsize_, t);
318  }
319 
321  void SetValue(const int& t){
322  for(int i=0; i < (int)data_.size(); i++){
323  data_[i] = t;
324  }
325  }
326 
328  void PushBack(const int& t){
329  xsize_ += 1;
330  data_.push_back(t);
331  }
332 
337  return &(data_[0]);
338  }
339 
343  const int* GetConstArrayPointer() const {
344  return &(data_[0]);
345  }
346 
347  // allows access element by element, e.g. this(i) gives data_[i]
348  int& operator()(int ix) {return data_[ix];}
349  const int& operator()(int ix) const {return data_[ix];}
350 
353  void insert(Array1D<int>& insarr,int ix){
354  if (ix<0 || ix>xsize_){
355  throw Tantrum("Array1D:insert():: insert index out of bounds.");
356  }
357  int addsize = insarr.Length();
358  xsize_+=addsize;
359  int* ptr=insarr.GetArrayPointer();
360  data_.insert(data_.begin()+ix,ptr,ptr+addsize);
361  }
362 
365  void insert(const int& insval,int ix){
366  if (ix<0 || ix>xsize_)
367  throw Tantrum("Array1D:insert():: insert index out of bounds.");
368  xsize_+=1;
369  data_.insert(data_.begin()+ix,insval);
370  }
371 
373  void erase(int ix){
374  if (ix<0 || ix>=xsize_)
375  throw Tantrum("Array1D:erase():: erase index out of bounds.");
376  xsize_-=1;
377  data_.erase(data_.begin()+ix);
378  }
379 
381  void DumpBinary(FILE* f_out) const {
382  fwrite(&xsize_,sizeof(xsize_),1,f_out);
383  fwrite(this->GetConstArrayPointer(),sizeof(int),xsize_,f_out);
384  }
385 
387  void ReadBinary(FILE* f_in){
388  fread(&xsize_,sizeof(xsize_),1,f_in);
389  data_.resize(xsize_);
390  fread(this->GetArrayPointer(),sizeof(int),xsize_,f_in);
391  }
392 
393  /**********************************************************
394  // Methods for interfacing with python
395  **********************************************************/
396 
397  // For calling [] in Python
398  int& operator[](int i) {return data_[i];}
399 
401  // cannot be read with numpy's fromfile after creation
402  void DumpBinary(char *filename){
403  FILE *f_out;
404  f_out = fopen(filename,"wb");
405  fwrite(&xsize_,sizeof(xsize_),1,f_out);
406  fwrite(this->GetConstArrayPointer(),sizeof(int),xsize_,f_out);
407  fclose(f_out);
408  }
409 
410  // read binary file created with DumpBinary
411  // Cannot use numpy's from files
412  // only for use in c++
413  void ReadBinary(char *filename){
414  FILE *f_in;
415  f_in = fopen(filename,"rb");
416  fread(&xsize_,sizeof(xsize_),1,f_in);
417  data_.resize(xsize_);
418  fread(this->GetArrayPointer(),sizeof(int),xsize_,f_in);
419  fclose(f_in);
420  }
421 
422  // creates binary file that can be read with numpy's fromfile
423  void DumpBinary4py(char *filename){
424  ofstream f_out;
425  f_out.open(filename, ios::out | ios::binary);
426  f_out.write((char*)this->GetArrayPointer(),xsize_*sizeof(int)); // convert array pointer to char string
427  f_out.close();
428  }
429 
430  // can read in DumpBinary4py output, but needs size of vector
431  // fromfile can automatically detect size file, so, if need by, one can use numpy's fromfile to determine # of elements
432  void ReadBinary4py(char *filename, int n){
433  xsize_ = n;
434  ifstream f_in;
435  f_in.open(filename, ios::in | ios::binary);
436  f_in.read((char*)this->GetArrayPointer(),xsize_*sizeof(int)); // convert array pointer to char string
437  f_in.close();
438  }
439 
440  // Set user-defined list to data_ vector
441  // This will work even for string type
442  void setArray(vector<int> inarray){
443  data_ = inarray;
444  xsize_ = inarray.size();
445  }
446 
447  // // Sets user-defined 1d numpy array to data_ vector
448  void setnpintArray(long* inarray, int n){
449  xsize_ = n;
450  data_.assign(inarray,inarray+n);
451  }
452  // This is not to be used for a string type
453  void getnpintArray(long* outarray, int n){
454  // xsize_ = n;
455  // data_.assign(inarray,inarray+n);
456  copy(data_.begin(), data_.end(), outarray);
457  }
458 
459  // Returns data_ vector as a list in python
460  // Also acts as a print to see individual elements
461  vector<int> flatten(){
462  return data_;
463  }
464 
465  string type(){
466  return "int";
467  }
468 
469 };
470 
471 template<>
472 class Array1D <double> {
473 private:
474  int xsize_; // private size of vector
475 public:
476  vector<double> data_; // private copy of data vector
477 
478 
480  Array1D(): xsize_(0) {};
481 
483  Array1D(const int& nx): xsize_(nx) {
484  data_.resize(xsize_);
485  }
486 
488  Array1D(const int& nx, const double& t): xsize_(nx) {
489  data_.resize(xsize_, t);
490  }
491 
493  Array1D& operator=(const Array1D &obj) {
494  xsize_ = obj.xsize_;
495  data_ = obj.data_;
496  return *this;
497  }
498 
500  Array1D(const Array1D &obj): xsize_(obj.xsize_), data_(obj.data_) {};
501 
503  ~Array1D() {data_.clear();}
504 
506  void Clear() {
507  xsize_ = 0;
508  data_.clear();
509  }
510 
512  int XSize() const {return xsize_;}
513 
515  int Length() const {return xsize_;}
516 
518  void Resize(const int& nx) {
519  xsize_ = nx;
520  data_.resize(xsize_);
521  }
522 
525  void Resize(const int& nx, const double& t) {
526  data_.clear();
527  xsize_ = nx;
528  data_.resize(xsize_, t);
529  }
530 
532  void SetValue(const double& t){
533  for(int i=0; i < (int)data_.size(); i++){
534  data_[i] = t;
535  }
536  }
537 
539  void PushBack(const double& t){
540  xsize_ += 1;
541  data_.push_back(t);
542  }
543 
547  double* GetArrayPointer() {
548  return &(data_[0]);
549  }
550 
554  const double* GetConstArrayPointer() const {
555  return &(data_[0]);
556  }
557 
558  // allows access element by element, e.g. this(i) gives data_[i]
559  double& operator()(int ix) {return data_[ix];}
560  const double& operator()(int ix) const {return data_[ix];}
561 
564  void insert(Array1D<double>& insarr,int ix){
565  if (ix<0 || ix>xsize_){
566  throw Tantrum("Array1D:insert():: insert index out of bounds.");
567  }
568  int addsize = insarr.Length();
569  xsize_+=addsize;
570  double* ptr=insarr.GetArrayPointer();
571  data_.insert(data_.begin()+ix,ptr,ptr+addsize);
572  }
573 
576  void insert(const double& insval,int ix){
577  if (ix<0 || ix>xsize_)
578  throw Tantrum("Array1D:insert():: insert index out of bounds.");
579  xsize_+=1;
580  data_.insert(data_.begin()+ix,insval);
581  }
582 
584  void erase(int ix){
585  if (ix<0 || ix>=xsize_)
586  throw Tantrum("Array1D:erase():: erase index out of bounds.");
587  xsize_-=1;
588  data_.erase(data_.begin()+ix);
589  }
590 
592  void DumpBinary(FILE* f_out) const {
593  fwrite(&xsize_,sizeof(xsize_),1,f_out);
594  fwrite(this->GetConstArrayPointer(),sizeof(double),xsize_,f_out);
595  }
596 
598  void ReadBinary(FILE* f_in){
599  fread(&xsize_,sizeof(xsize_),1,f_in);
600  data_.resize(xsize_);
601  fread(this->GetArrayPointer(),sizeof(double),xsize_,f_in);
602  }
603 
604  /**********************************************************
605  // Methods for interfacing with python
606  **********************************************************/
607 
608  // For calling [] in Python
609  double& operator[](int i) {return data_[i];}
610 
612  // cannot be read with numpy's fromfile after creation
613  void DumpBinary(char *filename){
614  FILE *f_out;
615  f_out = fopen(filename,"wb");
616  fwrite(&xsize_,sizeof(xsize_),1,f_out);
617  fwrite(this->GetConstArrayPointer(),sizeof(double),xsize_,f_out);
618  fclose(f_out);
619  }
620 
621  // read binary file created with DumpBinary
622  // Cannot use numpy's from files
623  // only for use in c++
624  void ReadBinary(char *filename){
625  FILE *f_in;
626  f_in = fopen(filename,"rb");
627  fread(&xsize_,sizeof(xsize_),1,f_in);
628  data_.resize(xsize_);
629  fread(this->GetArrayPointer(),sizeof(double),xsize_,f_in);
630  fclose(f_in);
631  }
632 
633  // creates binary file that can be read with numpy's fromfile
634  void DumpBinary4py(char *filename){
635  ofstream f_out;
636  f_out.open(filename, ios::out | ios::binary);
637  f_out.write((char*)this->GetArrayPointer(),xsize_*sizeof(double)); // convert array pointer to char string
638  f_out.close();
639  }
640 
641  // can read in DumpBinary4py output, but needs size of vector
642  // fromfile can automatically detect size file, so, if need by, one can use numpy's fromfile to determine # of elements
643  void ReadBinary4py(char *filename, int n){
644  xsize_ = n;
645  ifstream f_in;
646  f_in.open(filename, ios::in | ios::binary);
647  f_in.read((char*)this->GetArrayPointer(),xsize_*sizeof(double)); // convert array pointer to char string
648  f_in.close();
649  }
650 
651  // Set user-defined list to data_ vector
652  // This will work even for string type
653  void setArray(vector<double> inarray){
654  data_ = inarray;
655  xsize_ = inarray.size();
656  }
657 
658  // Sets user-defined 1d numpy array to data_ vector
659  // This is not to be used for a string type
660  void setnpdblArray(double* inarray, int n){
661  xsize_ = n;
662  data_.assign(inarray,inarray+n);
663  }
664  // Sets user-defined 1d numpy array to data_ vector
665  // This is not to be used for a string type
666  void getnpdblArray(double* outarray, int n){
667  // xsize_ = n;
668  // data_.assign(inarray,inarray+n);
669  copy(data_.begin(), data_.end(), outarray);
670  }
671 
672  // Returns data_ vector as a list in python
673  // Also acts as a print to see individual elements
674  vector<double> flatten(){
675  return data_;
676  }
677 
678  string type(){
679  return "double";
680  }
681 };
682 
683 #endif /* ARRAY1D_H_SEEN */
Array1D< double > copy(Array1D< double > &in_array)
Returns a copy of 1D array.
Definition: arraytools.cpp:1604
Definition: Array1D.h:472
Array1D()
Default constructor, which does not allocate any memory.
Definition: Array1D.h:480
void PushBack(const double &t)
Add element to the end of the vector.
Definition: Array1D.h:539
void ReadBinary(char *filename)
Definition: Array1D.h:624
double * GetArrayPointer()
Return a pointer to the first element of the data in the vector so we can use it access the data in a...
Definition: Array1D.h:547
void ReadBinary4py(char *filename, int n)
Definition: Array1D.h:643
const double * GetConstArrayPointer() const
Return a const point to the first element of the data in the vector so we can use it access the data ...
Definition: Array1D.h:554
void Clear()
Function to clear the memory.
Definition: Array1D.h:506
void DumpBinary(char *filename)
Dump contents of the array to a file in binary format.
Definition: Array1D.h:613
void insert(const double &insval, int ix)
Insert a given value to the position ix.
Definition: Array1D.h:576
int XSize() const
Returns size in the x-direction.
Definition: Array1D.h:512
void SetValue(const double &t)
Set all values in the array to the given value.
Definition: Array1D.h:532
double & operator()(int ix)
Definition: Array1D.h:559
int Length() const
Returns length (i.e. size in the x-direction)
Definition: Array1D.h:515
void Resize(const int &nx, const double &t)
Resizes the array and sets ALL entries to the specified value.
Definition: Array1D.h:525
void setnpdblArray(double *inarray, int n)
Definition: Array1D.h:660
void DumpBinary4py(char *filename)
Definition: Array1D.h:634
void Resize(const int &nx)
Resizes the array.
Definition: Array1D.h:518
Array1D(const int &nx, const double &t)
Constructor that allocates and initializes the data to a value t.
Definition: Array1D.h:488
int xsize_
Definition: Array1D.h:474
void DumpBinary(FILE *f_out) const
Dump contents of the array to a file in binary format.
Definition: Array1D.h:592
void setArray(vector< double > inarray)
Definition: Array1D.h:653
Array1D(const int &nx)
Constructor that allocates the memory.
Definition: Array1D.h:483
Array1D & operator=(const Array1D &obj)
Assignment operator copies the data structure by value.
Definition: Array1D.h:493
void getnpdblArray(double *outarray, int n)
Definition: Array1D.h:666
string type()
Definition: Array1D.h:678
Array1D(const Array1D &obj)
Copy constructor.
Definition: Array1D.h:500
void erase(int ix)
Erase the value from the position ix.
Definition: Array1D.h:584
void ReadBinary(FILE *f_in)
Read contents of the array from a file in binary format.
Definition: Array1D.h:598
vector< double > data_
Definition: Array1D.h:476
const double & operator()(int ix) const
Definition: Array1D.h:560
~Array1D()
Destructor that frees up the memory.
Definition: Array1D.h:503
vector< double > flatten()
Definition: Array1D.h:674
void insert(Array1D< double > &insarr, int ix)
Insert a given array to the position ix.
Definition: Array1D.h:564
double & operator[](int i)
Definition: Array1D.h:609
Definition: Array1D.h:262
Array1D(const int &nx, const int &t)
Constructor that allocates and initializes the data to a value t.
Definition: Array1D.h:277
string type()
Definition: Array1D.h:465
void insert(const int &insval, int ix)
Insert a given value to the position ix.
Definition: Array1D.h:365
void Clear()
Function to clear the memory.
Definition: Array1D.h:295
void erase(int ix)
Erase the value from the position ix.
Definition: Array1D.h:373
vector< int > data_
Definition: Array1D.h:266
void setnpintArray(long *inarray, int n)
Definition: Array1D.h:448
void DumpBinary(char *filename)
Dump contents of the array to a file in binary format.
Definition: Array1D.h:402
void Resize(const int &nx)
Resizes the array.
Definition: Array1D.h:307
void DumpBinary4py(char *filename)
Definition: Array1D.h:423
int & operator()(int ix)
Definition: Array1D.h:348
Array1D()
Default constructor, which does not allocate any memory.
Definition: Array1D.h:269
int Length() const
Returns length (i.e. size in the x-direction)
Definition: Array1D.h:304
void ReadBinary4py(char *filename, int n)
Definition: Array1D.h:432
void insert(Array1D< int > &insarr, int ix)
Insert a given array to the position ix.
Definition: Array1D.h:353
void SetValue(const int &t)
Set all values in the array to the given value.
Definition: Array1D.h:321
vector< int > flatten()
Definition: Array1D.h:461
Array1D & operator=(const Array1D &obj)
Assignment operator copies the data structure by value.
Definition: Array1D.h:282
void ReadBinary(char *filename)
Definition: Array1D.h:413
~Array1D()
Destructor that frees up the memory.
Definition: Array1D.h:292
const int * GetConstArrayPointer() const
Return a const point to the first element of the data in the vector so we can use it access the data ...
Definition: Array1D.h:343
int & operator[](int i)
Definition: Array1D.h:398
void setArray(vector< int > inarray)
Definition: Array1D.h:442
void PushBack(const int &t)
Add element to the end of the vector.
Definition: Array1D.h:328
const int & operator()(int ix) const
Definition: Array1D.h:349
Array1D(const Array1D &obj)
Copy constructor.
Definition: Array1D.h:289
int * GetArrayPointer()
Return a pointer to the first element of the data in the vector so we can use it access the data in a...
Definition: Array1D.h:336
int xsize_
Definition: Array1D.h:264
void getnpintArray(long *outarray, int n)
Definition: Array1D.h:453
Array1D(const int &nx)
Constructor that allocates the memory.
Definition: Array1D.h:272
void ReadBinary(FILE *f_in)
Read contents of the array from a file in binary format.
Definition: Array1D.h:387
void Resize(const int &nx, const int &t)
Resizes the array and sets ALL entries to the specified value.
Definition: Array1D.h:314
int XSize() const
Returns size in the x-direction.
Definition: Array1D.h:301
void DumpBinary(FILE *f_out) const
Dump contents of the array to a file in binary format.
Definition: Array1D.h:381
Stores data of any type T in a 1D array.
Definition: Array1D.h:61
T * GetArrayPointer()
Return a pointer to the first element of the data in the vector so we can use it access the data in a...
Definition: Array1D.h:138
T & operator[](int i)
Definition: Array1D.h:200
void ReadBinary(char *filename)
Definition: Array1D.h:215
void setArray(vector< T > inarray)
Definition: Array1D.h:245
Array1D(const int &nx)
Constructor that allocates the memory.
Definition: Array1D.h:74
int XSize() const
Returns size in the x-direction.
Definition: Array1D.h:103
Array1D(const Array1D &obj)
Copy constructor.
Definition: Array1D.h:91
~Array1D()
Destructor that frees up the memory.
Definition: Array1D.h:94
void DumpBinary(FILE *f_out) const
Dump contents of the array to a file in binary format.
Definition: Array1D.h:183
vector< T > data_
Definition: Array1D.h:68
void PushBack(const T &t)
Add element to the end of the vector.
Definition: Array1D.h:130
void SetValue(const T &t)
Set all values in the array to the given value.
Definition: Array1D.h:123
void insert(const T &insval, int ix)
Insert a given value to the position ix.
Definition: Array1D.h:167
void Clear()
Function to clear the memory.
Definition: Array1D.h:97
void Resize(const int &nx, const T &t)
Resizes the array and sets ALL entries to the specified value.
Definition: Array1D.h:116
const T & operator()(int ix) const
Definition: Array1D.h:151
Array1D(const int &nx, const T &t)
Constructor that allocates and initializes the data to a value t.
Definition: Array1D.h:79
vector< T > flatten()
Definition: Array1D.h:252
Array1D & operator=(const Array1D &obj)
Assignment operator copies the data structure by value.
Definition: Array1D.h:84
const T * GetConstArrayPointer() const
Return a const point to the first element of the data in the vector so we can use it access the data ...
Definition: Array1D.h:145
void Resize(const int &nx)
Resizes the array.
Definition: Array1D.h:109
string type()
Definition: Array1D.h:256
void ReadBinary(FILE *f_in)
Read contents of the array from a file in binary format.
Definition: Array1D.h:189
T & operator()(int ix)
Definition: Array1D.h:150
void DumpBinary(char *filename)
Dump contents of the array to a file in binary format.
Definition: Array1D.h:204
int xsize_
Definition: Array1D.h:67
void ReadBinary4py(char *filename, int n)
Definition: Array1D.h:235
int Length() const
Returns length (i.e. size in the x-direction)
Definition: Array1D.h:106
void DumpBinary4py(char *filename)
Definition: Array1D.h:226
Array1D()
Default constructor, which does not allocate any memory.
Definition: Array1D.h:71
void insert(Array1D< T > &insarr, int ix)
Insert a given array to the position ix.
Definition: Array1D.h:155
void erase(int ix)
Erase the value from the position ix.
Definition: Array1D.h:175