UQTk: Uncertainty Quantification Toolkit 3.1.5
Array1D.h
Go to the documentation of this file.
1/* =====================================================================================
2
3 The UQ Toolkit (UQTk) version 3.1.5
4 Copyright (2024) NTESS
5 https://www.sandia.gov/UQToolkit/
6 https://github.com/sandialabs/UQTk
7
8 Copyright 2024 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 https://github.com/sandialabs/UQTk/discussions
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
45using 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
60template<typename T>
61class Array1D{
62private:
63
64public:
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
202 // For calling shape in Python
203 vector<int> shape(){
204 vector<int> s (1,0);
205 s[0] = this -> XSize();
206 return s;
207 }
208
209 // For assigning a value to a specified index in the array
210 void assign(const int x,const T val){
211 data_[x] = val;
212 }
213
215 // cannot be read with numpy's fromfile after creation
216 void DumpBinary(char *filename){
217 FILE *f_out;
218 f_out = fopen(filename,"wb");
219 fwrite(&xsize_,sizeof(xsize_),1,f_out);
220 fwrite(this->GetConstArrayPointer(),sizeof(T),xsize_,f_out);
221 fclose(f_out);
222 }
223
224 // read binary file created with DumpBinary
225 // Cannot use numpy's from files
226 // only for use in c++
227 void ReadBinary(char *filename){
228 FILE *f_in;
229 f_in = fopen(filename,"rb");
230 fread(&xsize_,sizeof(xsize_),1,f_in);
231 data_.resize(xsize_);
232 fread(this->GetArrayPointer(),sizeof(T),xsize_,f_in);
233 fclose(f_in);
234 }
235
236 // Following two methods are not compatable with certain clang comilers
237 // creates binary file that can be read with numpy's fromfile
238 void DumpBinary4py(char *filename){
239 ofstream f_out;
240 f_out.open(filename, ios::out | ios::binary);
241 f_out.write((char*)this->GetArrayPointer(),sizeof(T[xsize_])); // convert array pointer to char string
242 f_out.close();
243 }
244
245 // can read in DumpBinary4py output, but needs size of vector
246 // fromfile can automatically detect size file, so, if need by, one can use numpy's fromfile to determine # of elements
247 void ReadBinary4py(char *filename, int n){
248 xsize_ = n;
249 ifstream f_in;
250 f_in.open(filename, ios::in | ios::binary);
251 f_in.read((char*)this->GetArrayPointer(),sizeof(T[xsize_])); // convert array pointer to char string
252 f_in.close();
253 }
254
255 // Set user-defined list to data_ vector
256 // This will work even for string type
257 void setArray(vector<T> inarray){
258 data_ = inarray;
259 xsize_ = inarray.size();
260 }
261
262 // Returns data_ vector as a list in python
263 // Also acts as a print to see individual elements
264 vector<T> flatten(){
265 return data_;
266 }
267
268 string type(){
269 return "string";
270 }
271};
272
273template<>
274class Array1D <int>{
275private:
276 int xsize_; // private size of vector
277public:
278 vector<int> data_; // private copy of data vector
279
281 Array1D(): xsize_(0) {};
282
284 Array1D(const int& nx): xsize_(nx) {
285 data_.resize(xsize_);
286 }
287
289 Array1D(const int& nx, const int& t): xsize_(nx) {
290 data_.resize(xsize_, t);
291 }
292
294 Array1D& operator=(const Array1D &obj) {
295 xsize_ = obj.xsize_;
296 data_ = obj.data_;
297 return *this;
298 }
299
301 Array1D(const Array1D &obj): xsize_(obj.xsize_), data_(obj.data_) {};
302
304 ~Array1D() {data_.clear();}
305
307 void Clear() {
308 xsize_ = 0;
309 data_.clear();
310 }
311
313 int XSize() const {return xsize_;}
314
316 int Length() const {return xsize_;}
317
319 void Resize(const int& nx) {
320 xsize_ = nx;
321 data_.resize(xsize_);
322 }
323
326 void Resize(const int& nx, const int& t) {
327 data_.clear();
328 xsize_ = nx;
329 data_.resize(xsize_, t);
330 }
331
333 void SetValue(const int& t){
334 for(int i=0; i < (int)data_.size(); i++){
335 data_[i] = t;
336 }
337 }
338
340 void PushBack(const int& t){
341 xsize_ += 1;
342 data_.push_back(t);
343 }
344
349 return &(data_[0]);
350 }
351
355 const int* GetConstArrayPointer() const {
356 return &(data_[0]);
357 }
358
359 // allows access element by element, e.g. this(i) gives data_[i]
360 int& operator()(int ix) {return data_[ix];}
361 const int& operator()(int ix) const {return data_[ix];}
362
365 void insert(Array1D<int>& insarr,int ix){
366 /*if (ix<0 || ix>xsize_){
367 throw Tantrum("Array1D:insert():: insert index out of bounds.");
368 }*/
369 int addsize = insarr.Length();
370 xsize_+=addsize;
371 int* ptr=insarr.GetArrayPointer();
372 data_.insert(data_.begin()+ix,ptr,ptr+addsize);
373 }
374
377 void insert(const int& insval,int ix){
378 /*if (ix<0 || ix>xsize_)
379 throw Tantrum("Array1D:insert():: insert index out of bounds.");*/
380 xsize_+=1;
381 data_.insert(data_.begin()+ix,insval);
382 }
383
385 void erase(int ix){
386 /*if (ix<0 || ix>=xsize_)
387 throw Tantrum("Array1D:erase():: erase index out of bounds.");*/
388 xsize_-=1;
389 data_.erase(data_.begin()+ix);
390 }
391
393 void DumpBinary(FILE* f_out) const {
394 fwrite(&xsize_,sizeof(xsize_),1,f_out);
395 fwrite(this->GetConstArrayPointer(),sizeof(int),xsize_,f_out);
396 }
397
399 void ReadBinary(FILE* f_in){
400 fread(&xsize_,sizeof(xsize_),1,f_in);
401 data_.resize(xsize_);
402 fread(this->GetArrayPointer(),sizeof(int),xsize_,f_in);
403 }
404
405 /**********************************************************
406 // Methods for interfacing with python
407 **********************************************************/
408
409 // For calling [] in Python
410 int& operator[](int i) {return data_[i];}
411
412 // For calling shape in Python
413 vector<int> shape(){
414 vector<int> s (1,0);
415 s[0] = this -> XSize();
416 return s;
417 }
418
419 // For assigning a value to a specified index in the array
420 void assign(const int x,const int val){
421 data_[x] = val;
422 }
423
425 // cannot be read with numpy's fromfile after creation
426 void DumpBinary(char *filename){
427 FILE *f_out;
428 f_out = fopen(filename,"wb");
429 fwrite(&xsize_,sizeof(xsize_),1,f_out);
430 fwrite(this->GetConstArrayPointer(),sizeof(int),xsize_,f_out);
431 fclose(f_out);
432 }
433
434 // read binary file created with DumpBinary
435 // Cannot use numpy's from files
436 // only for use in c++
437 void ReadBinary(char *filename){
438 FILE *f_in;
439 f_in = fopen(filename,"rb");
440 fread(&xsize_,sizeof(xsize_),1,f_in);
441 data_.resize(xsize_);
442 fread(this->GetArrayPointer(),sizeof(int),xsize_,f_in);
443 fclose(f_in);
444 }
445
446 // creates binary file that can be read with numpy's fromfile
447 void DumpBinary4py(char *filename){
448 ofstream f_out;
449 f_out.open(filename, ios::out | ios::binary);
450 f_out.write((char*)this->GetArrayPointer(),xsize_*sizeof(int)); // convert array pointer to char string
451 f_out.close();
452 }
453
454 // can read in DumpBinary4py output, but needs size of vector
455 // fromfile can automatically detect size file, so, if need by, one can use numpy's fromfile to determine # of elements
456 void ReadBinary4py(char *filename, int n){
457 xsize_ = n;
458 ifstream f_in;
459 f_in.open(filename, ios::in | ios::binary);
460 f_in.read((char*)this->GetArrayPointer(),xsize_*sizeof(int)); // convert array pointer to char string
461 f_in.close();
462 }
463
464 // Set user-defined list to data_ vector
465 // This will work even for string type
466 void setArray(vector<int> inarray){
467 data_ = inarray;
468 xsize_ = inarray.size();
469 }
470
471 // // Sets user-defined 1d numpy array to data_ vector
472 void setnpintArray(vector<int> inarray, int n){
473 xsize_ = n;
474 data_.clear();
475 for(int i = 0; i < n; ++i){
476 data_.push_back(inarray[i]);
477 }
478 }
479 // This is not to be used for a string type
480 void getnpintArray(long * outarray){
481 // xsize_ = n;
482 // data_.assign(inarray,inarray+n);
483 copy(data_.begin(), data_.end(), outarray);
484 }
485
486 // Returns data_ vector as a list in python
487 // Also acts as a print to see individual elements
488 vector<int> flatten(){
489 return data_;
490 }
491
492 string type(){
493 return "int";
494 }
495
496};
497
498template<>
499class Array1D <double> {
500private:
501 int xsize_; // private size of vector
502public:
503 vector<double> data_; // private copy of data vector
504
505
507 Array1D(): xsize_(0) {};
508
510 Array1D(const int& nx): xsize_(nx) {
511 data_.resize(xsize_);
512 }
513
515 Array1D(const int& nx, const double& t): xsize_(nx) {
516 data_.resize(xsize_, t);
517 }
518
520 Array1D& operator=(const Array1D &obj) {
521 xsize_ = obj.xsize_;
522 data_ = obj.data_;
523 return *this;
524 }
525
527 Array1D(const Array1D &obj): xsize_(obj.xsize_), data_(obj.data_) {};
528
530 ~Array1D() {data_.clear();}
531
533 void Clear() {
534 xsize_ = 0;
535 data_.clear();
536 }
537
539 int XSize() const {return xsize_;}
540
542 int Length() const {return xsize_;}
543
545 void Resize(const int& nx) {
546 xsize_ = nx;
547 data_.resize(xsize_);
548 }
549
552 void Resize(const int& nx, const double& t) {
553 data_.clear();
554 xsize_ = nx;
555 data_.resize(xsize_, t);
556 }
557
559 void SetValue(const double& t){
560 for(int i=0; i < (int)data_.size(); i++){
561 data_[i] = t;
562 }
563 }
564
566 void PushBack(const double& t){
567 xsize_ += 1;
568 data_.push_back(t);
569 }
570
574 double* GetArrayPointer() {
575 return &(data_[0]);
576 }
577
581 const double* GetConstArrayPointer() const {
582 return &(data_[0]);
583 }
584
585 // allows access element by element, e.g. this(i) gives data_[i]
586 double& operator()(int ix) {return data_[ix];}
587 const double& operator()(int ix) const {return data_[ix];}
588
591 void insert(Array1D<double>& insarr,int ix){
592 /*if (ix<0 || ix>xsize_){
593 throw Tantrum("Array1D:insert():: insert index out of bounds.");
594 }*/
595 int addsize = insarr.Length();
596 xsize_+=addsize;
597 double* ptr=insarr.GetArrayPointer();
598 data_.insert(data_.begin()+ix,ptr,ptr+addsize);
599 }
600
603 void insert(const double& insval,int ix){
604 /*if (ix<0 || ix>xsize_)
605 throw Tantrum("Array1D:insert():: insert index out of bounds.");*/
606 xsize_+=1;
607 data_.insert(data_.begin()+ix,insval);
608 }
609
611 void erase(int ix){
612 /*if (ix<0 || ix>=xsize_)
613 throw Tantrum("Array1D:erase():: erase index out of bounds.");*/
614 xsize_-=1;
615 data_.erase(data_.begin()+ix);
616 }
617
619 void DumpBinary(FILE* f_out) const {
620 fwrite(&xsize_,sizeof(xsize_),1,f_out);
621 fwrite(this->GetConstArrayPointer(),sizeof(double),xsize_,f_out);
622 }
623
625 void ReadBinary(FILE* f_in){
626 fread(&xsize_,sizeof(xsize_),1,f_in);
627 data_.resize(xsize_);
628 fread(this->GetArrayPointer(),sizeof(double),xsize_,f_in);
629 }
630
631 /**********************************************************
632 // Methods for interfacing with python
633 **********************************************************/
634
635 // For calling [] in Python
636 double& operator[](int i) {return data_[i];}
637
638 // For calling shape in Python
639 vector<int> shape(){
640 vector<int> s (1,0);
641 s[0] = this -> XSize();
642 return s;
643 }
644
645 // For assigning a value to a specified index in the array
646 void assign(const int x,const double val){
647 data_[x] = val;
648 }
649
651 // cannot be read with numpy's fromfile after creation
652 void DumpBinary(char *filename){
653 FILE *f_out;
654 f_out = fopen(filename,"wb");
655 fwrite(&xsize_,sizeof(xsize_),1,f_out);
656 fwrite(this->GetConstArrayPointer(),sizeof(double),xsize_,f_out);
657 fclose(f_out);
658 }
659
660 // read binary file created with DumpBinary
661 // Cannot use numpy's from files
662 // only for use in c++
663 void ReadBinary(char *filename){
664 FILE *f_in;
665 f_in = fopen(filename,"rb");
666 fread(&xsize_,sizeof(xsize_),1,f_in);
667 data_.resize(xsize_);
668 fread(this->GetArrayPointer(),sizeof(double),xsize_,f_in);
669 fclose(f_in);
670 }
671
672 // creates binary file that can be read with numpy's fromfile
673 void DumpBinary4py(char *filename){
674 ofstream f_out;
675 f_out.open(filename, ios::out | ios::binary);
676 f_out.write((char*)this->GetArrayPointer(),xsize_*sizeof(double)); // convert array pointer to char string
677 f_out.close();
678 }
679
680 // can read in DumpBinary4py output, but needs size of vector
681 // fromfile can automatically detect size file, so, if need by, one can use numpy's fromfile to determine # of elements
682 void ReadBinary4py(char *filename, int n){
683 xsize_ = n;
684 ifstream f_in;
685 f_in.open(filename, ios::in | ios::binary);
686 f_in.read((char*)this->GetArrayPointer(),xsize_*sizeof(double)); // convert array pointer to char string
687 f_in.close();
688 }
689
690 // Set user-defined list to data_ vector
691 // This will work even for string type
692 void setArray(vector<double> inarray){
693 data_ = inarray;
694 xsize_ = inarray.size();
695 }
696
697 // Sets user-defined 1d numpy array to data_ vector
698 // This is not to be used for a string type
699 void setnpdblArray(vector<double> inarray, int n){
700 xsize_ = n;
701 data_.clear();
702 for(int i = 0; i < n; ++i){
703 data_.push_back(inarray[i]);
704 }
705 }
706 // Sets user-defined 1d numpy array to data_ vector
707 // This is not to be used for a string type
708 void getnpdblArray(double* outarray){
709 // xsize_ = n;
710 // data_.assign(inarray,inarray+n);
711 copy(data_.begin(), data_.end(), outarray);
712 }
713
714 // Returns data_ vector as a list in python
715 // Also acts as a print to see individual elements
716 vector<double> flatten(){
717 return data_;
718 }
719
720 string type(){
721 return "double";
722 }
723};
724
725#endif /* ARRAY1D_H_SEEN */
Array1D< double > copy(Array1D< double > &in_array)
Returns a copy of 1D array.
Definition arraytools.cpp:1607
Array1D()
Default constructor, which does not allocate any memory.
Definition Array1D.h:507
vector< double > flatten()
Definition Array1D.h:716
void PushBack(const double &t)
Add element to the end of the vector.
Definition Array1D.h:566
void ReadBinary(char *filename)
Definition Array1D.h:663
void assign(const int x, const double val)
Definition Array1D.h:646
double & operator()(int ix)
Definition Array1D.h:586
void ReadBinary4py(char *filename, int n)
Definition Array1D.h:682
void Clear()
Function to clear the memory.
Definition Array1D.h:533
const double & operator()(int ix) const
Definition Array1D.h:587
void DumpBinary(char *filename)
Dump contents of the array to a file in binary format.
Definition Array1D.h:652
void insert(const double &insval, int ix)
Insert a given value to the position ix.
Definition Array1D.h:603
int XSize() const
Returns size in the x-direction.
Definition Array1D.h:539
Array1D & operator=(const Array1D &obj)
Assignment operator copies the data structure by value.
Definition Array1D.h:520
void SetValue(const double &t)
Set all values in the array to the given value.
Definition Array1D.h:559
int Length() const
Returns length (i.e. size in the x-direction)
Definition Array1D.h:542
void Resize(const int &nx, const double &t)
Resizes the array and sets ALL entries to the specified value.
Definition Array1D.h:552
void DumpBinary4py(char *filename)
Definition Array1D.h:673
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:574
void Resize(const int &nx)
Resizes the array.
Definition Array1D.h:545
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:581
void getnpdblArray(double *outarray)
Definition Array1D.h:708
Array1D(const int &nx, const double &t)
Constructor that allocates and initializes the data to a value t.
Definition Array1D.h:515
int xsize_
Definition Array1D.h:501
void DumpBinary(FILE *f_out) const
Dump contents of the array to a file in binary format.
Definition Array1D.h:619
double & operator[](int i)
Definition Array1D.h:636
void setArray(vector< double > inarray)
Definition Array1D.h:692
Array1D(const int &nx)
Constructor that allocates the memory.
Definition Array1D.h:510
void setnpdblArray(vector< double > inarray, int n)
Definition Array1D.h:699
string type()
Definition Array1D.h:720
vector< int > shape()
Definition Array1D.h:639
Array1D(const Array1D &obj)
Copy constructor.
Definition Array1D.h:527
void erase(int ix)
Erase the value from the position ix.
Definition Array1D.h:611
void ReadBinary(FILE *f_in)
Read contents of the array from a file in binary format.
Definition Array1D.h:625
vector< double > data_
Definition Array1D.h:503
~Array1D()
Destructor that frees up the memory.
Definition Array1D.h:530
void insert(Array1D< double > &insarr, int ix)
Insert a given array to the position ix.
Definition Array1D.h:591
Array1D(const int &nx, const int &t)
Constructor that allocates and initializes the data to a value t.
Definition Array1D.h:289
string type()
Definition Array1D.h:492
void insert(const int &insval, int ix)
Insert a given value to the position ix.
Definition Array1D.h:377
void Clear()
Function to clear the memory.
Definition Array1D.h:307
void erase(int ix)
Erase the value from the position ix.
Definition Array1D.h:385
vector< int > data_
Definition Array1D.h:278
vector< int > flatten()
Definition Array1D.h:488
Array1D & operator=(const Array1D &obj)
Assignment operator copies the data structure by value.
Definition Array1D.h:294
void DumpBinary(char *filename)
Dump contents of the array to a file in binary format.
Definition Array1D.h:426
void Resize(const int &nx)
Resizes the array.
Definition Array1D.h:319
void DumpBinary4py(char *filename)
Definition Array1D.h:447
void getnpintArray(long *outarray)
Definition Array1D.h:480
int & operator[](int i)
Definition Array1D.h:410
Array1D()
Default constructor, which does not allocate any memory.
Definition Array1D.h:281
int Length() const
Returns length (i.e. size in the x-direction)
Definition Array1D.h:316
void ReadBinary4py(char *filename, int n)
Definition Array1D.h:456
void insert(Array1D< int > &insarr, int ix)
Insert a given array to the position ix.
Definition Array1D.h:365
void SetValue(const int &t)
Set all values in the array to the given value.
Definition Array1D.h:333
void setnpintArray(vector< int > inarray, int n)
Definition Array1D.h:472
void ReadBinary(char *filename)
Definition Array1D.h:437
~Array1D()
Destructor that frees up the memory.
Definition Array1D.h:304
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:355
void assign(const int x, const int val)
Definition Array1D.h:420
void setArray(vector< int > inarray)
Definition Array1D.h:466
void PushBack(const int &t)
Add element to the end of the vector.
Definition Array1D.h:340
Array1D(const Array1D &obj)
Copy constructor.
Definition Array1D.h:301
int xsize_
Definition Array1D.h:276
Array1D(const int &nx)
Constructor that allocates the memory.
Definition Array1D.h:284
void ReadBinary(FILE *f_in)
Read contents of the array from a file in binary format.
Definition Array1D.h:399
void Resize(const int &nx, const int &t)
Resizes the array and sets ALL entries to the specified value.
Definition Array1D.h:326
int XSize() const
Returns size in the x-direction.
Definition Array1D.h:313
const int & operator()(int ix) const
Definition Array1D.h:361
int & operator()(int ix)
Definition Array1D.h:360
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:348
void DumpBinary(FILE *f_out) const
Dump contents of the array to a file in binary format.
Definition Array1D.h:393
vector< int > shape()
Definition Array1D.h:413
Stores data of any type T in a 1D array.
Definition Array1D.h:61
void ReadBinary(char *filename)
Definition Array1D.h:227
const T & operator()(int ix) const
Definition Array1D.h:151
void setArray(vector< T > inarray)
Definition Array1D.h:257
T & operator()(int ix)
Definition Array1D.h:150
vector< int > shape()
Definition Array1D.h:203
Array1D(const int &nx)
Constructor that allocates the memory.
Definition Array1D.h:74
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
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
Array1D & operator=(const Array1D &obj)
Assignment operator copies the data structure by value.
Definition Array1D.h:84
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
Array1D(const int &nx, const T &t)
Constructor that allocates and initializes the data to a value t.
Definition Array1D.h:79
void Resize(const int &nx)
Resizes the array.
Definition Array1D.h:109
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
string type()
Definition Array1D.h:268
vector< T > flatten()
Definition Array1D.h:264
void ReadBinary(FILE *f_in)
Read contents of the array from a file in binary format.
Definition Array1D.h:189
void DumpBinary(char *filename)
Dump contents of the array to a file in binary format.
Definition Array1D.h:216
void assign(const int x, const T val)
Definition Array1D.h:210
int xsize_
Definition Array1D.h:67
void ReadBinary4py(char *filename, int n)
Definition Array1D.h:247
int Length() const
Returns length (i.e. size in the x-direction)
Definition Array1D.h:106
T & operator[](int i)
Definition Array1D.h:200
void DumpBinary4py(char *filename)
Definition Array1D.h:238
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