Skip to content

Commit

Permalink
Feature 1899 num array (#1944)
Browse files Browse the repository at this point in the history
* Per issue #1899, changed the main storage array (double * e) to vector<double> e. Modifying functions accordingly. SL

* Per issue #1899: removed commented out code. Still in progress. SL

* Per issue #1899: modified more functions to use vector or vector functions instead of arrays. In progress. SL

* Per issue #1899: updated add() functions to use push_back to add values to vector. SL

* Per #1899, correct logic in NumArray::init_from_scratch() to call NumArray::clear() instead of vector::clear().

* Per issue #1899: added some temporary print statements for debugging. SL

* Per issue #1899: added some more temporary print statements for debugging. In progress. SL

* Per issue #1899: added some temporary print statements for debugging. In progress. SL

* Per issue #1899: replaced Nelements with n_elements(). SL

* Per issue #1899: modified extend function some more for using vectors. In progres. SL

* Per issue #1899: continued to modify some functions for using a base vector for storage (instead of array). In progress. SL

* Per issue #1899: removed / added a few temporary print statements for debugging. SL

* Per #1899, this change seems to clearly be a bug. We should be using tc_poly_array_alloc_inc instead of num_array_alloc_inc in tc_poly.cc.

* Per issue #1899: commented out some print statements for now. For running make test. SL

* Per #1899, updating NumArray class to use STL::vector.

* Per #1899, I removed the exact option from NumArray::extend() since after switching to STL::vector, it'll ALWAYS be an exact allocation. Previously, we always rounded up to the next allocation increment, but there's no allocation increment anymore. Updating the other code to removes calls to exact.

* Per #1899, removing debug cout statements.

* Per #1899, cleaning up one leftover debug cout line.

* Per issue #1899: updated the erase() funciton to use vector.clear() and vector.reserve(). SL

* Per issue: #1899, cleaned up clear() and erase() functions. SL

Co-authored-by: Seth Linden <linden@kiowa.rap.ucar.edu>
Co-authored-by: John Halley Gotway <johnhg@ucar.edu>
  • Loading branch information
3 people authored Oct 15, 2021
1 parent 77f38b3 commit 2afeb79
Show file tree
Hide file tree
Showing 9 changed files with 457 additions and 527 deletions.
868 changes: 404 additions & 464 deletions met/src/basic/vx_util/num_array.cc

Large diffs are not rendered by default.

30 changes: 10 additions & 20 deletions met/src/basic/vx_util/num_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
////////////////////////////////////////////////////////////////////////


static const int num_array_alloc_inc = 1000;


////////////////////////////////////////////////////////////////////////


class NumArray {

private:
Expand All @@ -40,11 +34,7 @@ class NumArray {

void assign(const NumArray &);

double * e;

int Nelements;

int Nalloc;
vector<double> e;

bool Sorted;

Expand All @@ -59,15 +49,15 @@ class NumArray {

void erase();

void extend(int, bool exact = true);
void extend(int);

void dump(ostream &, int depth = 0) const;

double operator[](int) const;

const double * vals() const;
double * buf() const;

double * buf();
int has(int, bool forward=true) const;
int has(double, bool forward=true) const;

Expand Down Expand Up @@ -127,12 +117,12 @@ class NumArray {
////////////////////////////////////////////////////////////////////////


inline int NumArray::n_elements() const { return ( Nelements ); }
inline int NumArray::n () const { return ( Nelements ); }
inline const double * NumArray::vals() const { return ( e ); }
inline double * NumArray::buf() const { return ( e ); }
inline void NumArray::inc(int i, int v) { e[i] += v; return; }
inline void NumArray::inc(int i, double v) { e[i] += v; return; }
inline int NumArray::n_elements() const { return ( e.size() ); }
inline int NumArray::n () const { return ( e.size() ); }
inline const double * NumArray::vals() const { return ( e.data() ); }
inline double * NumArray::buf() { return ( e.data() ); }
inline void NumArray::inc(int i, int v) { e[i] += v; return; }
inline void NumArray::inc(int i, double v) { e[i] += v; return; }


////////////////////////////////////////////////////////////////////////
Expand Down
26 changes: 13 additions & 13 deletions met/src/libcode/vx_statistics/pair_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,23 @@ void PairBase::erase() {

////////////////////////////////////////////////////////////////////////

void PairBase::extend(int n, bool exact) {
void PairBase::extend(int n) {

o_na.extend (n, exact);
x_na.extend (n, exact);
y_na.extend (n, exact);
wgt_na.extend(n, exact);
o_na.extend (n);
x_na.extend (n);
y_na.extend (n);
wgt_na.extend(n);

cmn_na.extend(n, exact);
csd_na.extend(n, exact);
cdf_na.extend(n, exact);
cmn_na.extend(n);
csd_na.extend(n);
cdf_na.extend(n);

if(IsPointVx) {
lat_na.extend(n, exact);
lon_na.extend(n, exact);
vld_ta.extend(n, exact);
lvl_na.extend(n, exact);
elv_na.extend(n, exact);
lat_na.extend(n);
lon_na.extend(n);
vld_ta.extend(n);
lvl_na.extend(n);
elv_na.extend(n);
}

return;
Expand Down
2 changes: 1 addition & 1 deletion met/src/libcode/vx_statistics/pair_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class PairBase {
void clear();
void erase();

void extend(int, bool exact = true); // Allocate memory for expected size
void extend(int); // Allocate memory for expected size

bool is_point_vx() const;

Expand Down
46 changes: 23 additions & 23 deletions met/src/libcode/vx_statistics/pair_data_ensemble.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,35 +143,35 @@ void PairDataEnsemble::clear() {

////////////////////////////////////////////////////////////////////////

void PairDataEnsemble::extend(int n, bool exact) {
void PairDataEnsemble::extend(int n) {
int i;

// Allocate memory for the number of observations.
// Only applies to arrays sized by n_obs which does not include:
// rhist_na, relp_na, phist_na

PairBase::extend(n, exact);

obs_error_entry.extend(n, exact);

for(i=0; i<n_ens; i++) e_na[i].extend(n, exact);

v_na.extend (n, exact);
r_na.extend (n, exact);
crps_emp_na.extend (n, exact);
crpscl_emp_na.extend (n, exact);
crps_gaus_na.extend (n, exact);
crpscl_gaus_na.extend (n, exact);
ign_na.extend (n, exact);
pit_na.extend (n, exact);
skip_ba.extend (n, exact);
var_na.extend (n, exact);
var_oerr_na.extend (n, exact);
var_plus_oerr_na.extend (n, exact);
esum_na.extend (n, exact);
esumsq_na.extend (n, exact);
mn_na.extend (n, exact);
mn_oerr_na.extend (n, exact);
PairBase::extend(n);

obs_error_entry.extend(n);

for(i=0; i<n_ens; i++) e_na[i].extend(n);

v_na.extend (n);
r_na.extend (n);
crps_emp_na.extend (n);
crpscl_emp_na.extend (n);
crps_gaus_na.extend (n);
crpscl_gaus_na.extend (n);
ign_na.extend (n);
pit_na.extend (n);
skip_ba.extend (n);
var_na.extend (n);
var_oerr_na.extend (n);
var_plus_oerr_na.extend (n);
esum_na.extend (n);
esumsq_na.extend (n);
mn_na.extend (n);
mn_oerr_na.extend (n);

return;
}
Expand Down
2 changes: 1 addition & 1 deletion met/src/libcode/vx_statistics/pair_data_ensemble.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class PairDataEnsemble : public PairBase {

void clear();

void extend(int, bool exact = true);
void extend(int);

bool has_obs_error() const;

Expand Down
6 changes: 3 additions & 3 deletions met/src/libcode/vx_statistics/pair_data_point.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ void PairDataPoint::erase() {

////////////////////////////////////////////////////////////////////////

void PairDataPoint::extend(int n, bool exact) {
void PairDataPoint::extend(int n) {

PairBase::extend(n, exact);
PairBase::extend(n);

f_na.extend(n, exact);
f_na.extend(n);

return;
}
Expand Down
2 changes: 1 addition & 1 deletion met/src/libcode/vx_statistics/pair_data_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PairDataPoint : public PairBase {
void clear();
void erase();

void extend(int, bool exact = true);
void extend(int);

bool add_point_pair(const char *, double, double, double, double,
unixtime, double, double, double, double,
Expand Down
2 changes: 1 addition & 1 deletion met/src/tools/tc_utils/tc_dland/tc_poly.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void TCPolyArray::extend(int n, bool exact) {
if(!exact) {
int k = n/tc_poly_array_alloc_inc;

if(n%num_array_alloc_inc) k++;
if(n%tc_poly_array_alloc_inc) k++;

n = k*tc_poly_array_alloc_inc;
}
Expand Down

0 comments on commit 2afeb79

Please sign in to comment.