Dataset#

class numpy::Dataset#

numpy C++ class.

Example#

#include <numpy/np_ndarray.h>
using namespace numpy;

// Use Dataset
Dataset obj;
// ... operations ...

Constructors#

Signature

Location

Example

Dataset(const std::map<std::string, DataVarVariant>& data_vars, const std::map<std::string, Coordinate>& coords =

df_xarray.h:466

Array Creation#

Signature

Return Type

Location

Example

bool empty() const

bool

df_xarray.h:537

View

Indexing / Selection#

Signature

Return Type

Location

Example

const std::map<std::string, std::string>& attrs() const

const std::map<std::string, std::string>&

df_xarray.h:502

std::map<std::string, std::string>& attrs()

std::map<std::string, std::string>&

df_xarray.h:503

Statistics#

Signature

Return Type

Location

Example

std::vector<std::string> var_names() const

std::vector<std::string>

df_xarray.h:513

I/O#

Signature

Return Type

Location

Example

std::string to_string() const

std::string

df_xarray.h:624

View

Other Methods#

Signature

Return Type

Location

Example

void compute_dims()

void

df_xarray.h:717

const Coordinate& coord(const std::string& name) const

const Coordinate&

df_xarray.h:592

const std::map<std::string, Coordinate>& coords() const

const std::map<std::string, Coordinate>&

df_xarray.h:491

std::map<std::string, Coordinate>& coords()

std::map<std::string, Coordinate>&

df_xarray.h:492

const std::map<std::string, DataVarVariant>& data_vars() const

const std::map<std::string, DataVarVariant>&

df_xarray.h:485

std::map<std::string, DataVarVariant>& data_vars()

std::map<std::string, DataVarVariant>&

df_xarray.h:486

\* Call this after directly modifying data_vars() to update

* Call this after directly modifying

df_xarray.h:610

std::vector<std::string> dim_names() const

std::vector<std::string>

df_xarray.h:525

const std::map<std::string, size_t>& dims() const

const std::map<std::string, size_t>&

df_xarray.h:497

void drop_var(const std::string& name)

void

df_xarray.h:573

bool has_coord(const std::string& name) const

bool

df_xarray.h:585

bool has_var(const std::string& name) const

bool

df_xarray.h:546

size_t nvars() const

size_t

df_xarray.h:508

void recompute_dims()

void

df_xarray.h:613

void set_coord(const std::string& name, const Coordinate& coord)

void

df_xarray.h:603

void set_var(const std::string& name, const DataArray<T>& var)

void

df_xarray.h:565

Code Examples#

The following examples are extracted from the test suite.

empty (np_test_1_all.cpp:6316)
6306}
6307
6308void test_data_generator_emptyBenchmarkSorting() {
6309    std::cout << "========= test_data_generator_empty =======================";
6310
6311    DataGenerator<int> gen(42);
6312
6313    // Test empty data generation
6314    std::vector<int> data = gen.generate(0, DataPattern::RANDOM);
6315
6316    if (!(data.empty())) {
6317        std::string description = std::string("test_data_generator_emptyBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.empty())";
6318        std::cout << std::string("[FAIL] ") + description << std::endl;
6319        throw std::runtime_error(description);
6320    }
6321
6322    // std::cout << "Empty data generation test passed" << std::endl;
6323
6324    std::cout << " -> tests passed" << std::endl;
6325}
to_string (np_test_1_all.cpp:454)
444    // Modify through different views
445    view1.setElementAt({0, 0}, 100);
446    view2.setElementAt({2, 1}, 200);  // This is (1, 2) in original
447    view3.setElementAt({0, 0}, 300);  // This is (1, 1) in original
448
449    // std::cout << "After modifications through multiple views:" << std::endl;
450    //original.printArray();
451
452    // Verify all changes are reflected
453    if (!(original.getElementAt({0, 0}) == 100)) {
454        std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({0, 0}) == 100)";
455        std::cout << std::string("[FAIL] ") + description << std::endl;
456        throw std::runtime_error(description);
457    }
458    if (!(original.getElementAt({1, 2}) == 200)) {
459        std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 2}) == 200)";
460        std::cout << std::string("[FAIL] ") + description << std::endl;
461        throw std::runtime_error(description);
462    }
463    if (!(original.getElementAt({1, 1}) == 300)) {
464        std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 300)";