Dataset ======= .. cpp:class:: numpy::Dataset numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use Dataset Dataset obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``Dataset(const std::map& data_vars, const std::map& coords =`` - df_xarray.h:466 - Array Creation -------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool empty() const`` - bool - df_xarray.h:537 - :ref:`View ` Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``const std::map& attrs() const`` - const std::map& - df_xarray.h:502 - * - ``std::map& attrs()`` - std::map& - df_xarray.h:503 - Statistics ---------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``std::vector var_names() const`` - std::vector - df_xarray.h:513 - I/O --- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``std::string to_string() const`` - std::string - df_xarray.h:624 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - 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& coords() const`` - const std::map& - df_xarray.h:491 - * - ``std::map& coords()`` - std::map& - df_xarray.h:492 - * - ``const std::map& data_vars() const`` - const std::map& - df_xarray.h:485 - * - ``std::map& data_vars()`` - std::map& - df_xarray.h:486 - * - ``\* Call this after directly modifying data_vars() to update`` - \* Call this after directly modifying - df_xarray.h:610 - * - ``std::vector dim_names() const`` - std::vector - df_xarray.h:525 - * - ``const std::map& dims() const`` - const std::map& - 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& var)`` - void - df_xarray.h:565 - Code Examples ------------- The following examples are extracted from the test suite. .. _example-dataset-empty-0: .. dropdown:: empty (np_test_1_all.cpp:6316) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6306 :emphasize-lines: 11 } void test_data_generator_emptyBenchmarkSorting() { std::cout << "========= test_data_generator_empty ======================="; DataGenerator gen(42); // Test empty data generation std::vector data = gen.generate(0, DataPattern::RANDOM); if (!(data.empty())) { std::string description = std::string("test_data_generator_emptyBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Empty data generation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-dataset-to_string-1: .. dropdown:: to_string (np_test_1_all.cpp:454) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 444 :emphasize-lines: 11 // Modify through different views view1.setElementAt({0, 0}, 100); view2.setElementAt({2, 1}, 200); // This is (1, 2) in original view3.setElementAt({0, 0}, 300); // This is (1, 1) in original // std::cout << "After modifications through multiple views:" << std::endl; //original.printArray(); // Verify all changes are reflected if (!(original.getElementAt({0, 0}) == 100)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({0, 0}) == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(original.getElementAt({1, 2}) == 200)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 2}) == 200)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(original.getElementAt({1, 1}) == 300)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 300)";