LegacyGenerator =============== .. cpp:class:: numpy::LegacyGenerator numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use LegacyGenerator LegacyGenerator obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``LegacyGenerator(uint64_tseed)`` - NP_RANDOM.H:1763 - Random ------ .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void seed(uint32_tseed)`` - void - NP_RANDOM.H:2810 - :ref:`View ` * - ``void shuffle(NDArray&array)`` - void - NP_RANDOM.H:2643 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-legacygenerator-seed-0: .. dropdown:: seed (np_test_1_all.cpp:14339) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14329 :emphasize-lines: 11 } // std::cout << "[OK] Generator integers method\n"; std::cout << " -> tests passed\n"; } void test_vsl_reproducibility() { std::cout << "========= test_vsl_reproducibility ===="; // Test seed reproducibility seed(42); auto arr1 = normal(0.0, 1.0, { {10} }); seed(42); auto arr2 = normal(0.0, 1.0, { {10} }); for (size_t i = 0; i < 10; ++i) { double val1 = arr1.getElementAt({ i }); double val2 = arr2.getElementAt({ i }); .. _example-legacygenerator-shuffle-1: .. dropdown:: shuffle (np_test_1_all.cpp:12901) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12891 :emphasize-lines: 11 large_dataset.reserve(1000); for (int i = 0; i < 1000; ++i) { std::string str = "string" + std::to_string(i); large_dataset.push_back(str); } // Shuffle the dataset std::random_device rd; std::mt19937 gen(rd()); std::shuffle(large_dataset.begin(), large_dataset.end(), gen); // Sort using our string sort sort_strings(large_dataset); // Verify it's sorted if (!(std::is_sorted(large_dataset.begin(), large_dataset.end()))) { std::string description = std::string("test_large_string_dataset():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(large_dataset.begin(), large_dataset.end()))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); }