Skip to content

Commit

Permalink
Change to 1-base
Browse files Browse the repository at this point in the history
  • Loading branch information
siuwuncheung committed Mar 7, 2024
1 parent b57ec2b commit ff4baf0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/misc/combine_samples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ int main(int argc, char* argv[])

if (rank==0) std::cout << "Loading data from " << kind << std::endl;
for(const auto& sample_name: sample_names) {
static_basis_generator->loadSampleRange(sample_name, kind, col_min, col_max);
static_basis_generator->loadSampleRange(sample_name, kind, col_min-1, col_max-1);
}

if (rank==0) std::cout << "Saving data uploaded as a snapshot matrix" <<
Expand Down
9 changes: 5 additions & 4 deletions lib/linalg/BasisGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "svd/IncrementalSVDBrand.h"

#include <iomanip>
#include <fstream>

namespace CAROM {

Expand Down Expand Up @@ -189,12 +190,12 @@ BasisGenerator::loadSampleRange(const std::string& base_file_name,

int num_rows = mat->numRows();
int num_cols = mat->numColumns();
if (col_min < 1) col_min = 1;
if (col_max > num_cols) col_max = num_cols;
if (col_min < 0) col_min = 0;
if (col_max > num_cols-1) col_max = num_cols-1;

CAROM_VERIFY(col_max >= col_min);

for (int j = col_min-1; j < col_max; j++) {
for (int j = col_min; j <= col_max; j++) {
double* u_in = new double[num_rows];
for (int i = 0; i < num_rows; i++) {
if (kind == "basis") {
Expand All @@ -215,7 +216,7 @@ BasisGenerator::loadSamples(const std::string& base_file_name,
int cutoff,
Database::formats db_format)
{
loadSampleRange(base_file_name, kind, 1, cutoff, db_format);
loadSampleRange(base_file_name, kind, 0, cutoff-1, db_format);
}

double
Expand Down
3 changes: 1 addition & 2 deletions lib/linalg/BasisGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "mpi.h"

#include <cmath>
#include <fstream>

/* Use C++11 built-in shared pointers if available; else fallback to Boost. */
#if __cplusplus >= 201103L
Expand Down Expand Up @@ -158,7 +157,7 @@ class BasisGenerator
void
loadSampleRange(const std::string& base_file_name,
const std::string& kind = "basis",
int col_min = 1,
int col_min = 0,
int col_max = 1e9,
Database::formats db_format = Database::HDF5);

Expand Down

0 comments on commit ff4baf0

Please sign in to comment.