LegacyGenerator#
-
class numpy::LegacyGenerator#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use LegacyGenerator
LegacyGenerator obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
NP_RANDOM.H:1763 |
Random#
Code Examples#
The following examples are extracted from the test suite.
seed (np_test_1_all.cpp:14339)
14329 }
14330 // std::cout << "[OK] Generator integers method\n";
14331
14332 std::cout << " -> tests passed\n";
14333 }
14334
14335 void test_vsl_reproducibility() {
14336 std::cout << "========= test_vsl_reproducibility ====";
14337
14338 // Test seed reproducibility
14339 seed(42);
14340 auto arr1 = normal<double>(0.0, 1.0, { {10} });
14341
14342 seed(42);
14343 auto arr2 = normal<double>(0.0, 1.0, { {10} });
14344
14345
14346
14347 for (size_t i = 0; i < 10; ++i) {
14348 double val1 = arr1.getElementAt({ i });
14349 double val2 = arr2.getElementAt({ i });
shuffle (np_test_1_all.cpp:12901)
12891 large_dataset.reserve(1000);
12892
12893 for (int i = 0; i < 1000; ++i) {
12894 std::string str = "string" + std::to_string(i);
12895 large_dataset.push_back(str);
12896 }
12897
12898 // Shuffle the dataset
12899 std::random_device rd;
12900 std::mt19937 gen(rd());
12901 std::shuffle(large_dataset.begin(), large_dataset.end(), gen);
12902
12903 // Sort using our string sort
12904 sort_strings(large_dataset);
12905
12906 // Verify it's sorted
12907 if (!(std::is_sorted(large_dataset.begin(), large_dataset.end()))) {
12908 std::string description = std::string("test_large_string_dataset():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(large_dataset.begin(), large_dataset.end()))";
12909 std::cout << std::string("[FAIL] ") + description << std::endl;
12910 throw std::runtime_error(description);
12911 }