VSLRandomStream#
-
class numpy::VSLRandomStream#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Create random generator
Generator gen(12345); // seed
// Generate random values
auto uniform = gen.random({3, 3});
auto normal = gen.standard_normal({10});
auto integers = gen.integers(0, 100, {5});
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
NP_VSL_RANDOM.H:190 |
|
|
NP_VSL_RANDOM.H:213 |
|
|
NP_VSL_RANDOM.H:216 |
|
|
NP_VSL_RANDOM.H:2026 |
|
|
NP_VSL_RANDOM.H:2033 |
|
|
NP_VSL_RANDOM.H:2035 |
Operators#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
VSLRandomStream & |
NP_VSL_RANDOM.H:214 |
|
|
VSLRandomStream & noexcept |
NP_VSL_RANDOM.H:220 |
|
|
VSLRandomStream & |
NP_VSL_RANDOM.H:2034 |
|
|
VSLRandomStream & |
NP_VSL_RANDOM.H:2036 |
Array Creation#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
NP_VSL_RANDOM.H:2231 |
Indexing / Selection#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
VSLStreamStatePtr |
NP_VSL_RANDOM.H:1085 |
Math Operations#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
NP_VSL_RANDOM.H:621 |
|
|
void |
NP_VSL_RANDOM.H:2146 |
|
|
void |
NP_VSL_RANDOM.H:347 |
|
|
void |
NP_VSL_RANDOM.H:2068 |
|
|
void |
NP_VSL_RANDOM.H:361 |
|
|
void |
NP_VSL_RANDOM.H:2072 |
|
|
void |
NP_VSL_RANDOM.H:709 |
|
|
void |
NP_VSL_RANDOM.H:2186 |
|
|
void |
NP_VSL_RANDOM.H:584 |
|
|
void |
NP_VSL_RANDOM.H:2132 |
|
|
void |
NP_VSL_RANDOM.H:599 |
|
|
void |
NP_VSL_RANDOM.H:2136 |
|
|
void |
NP_VSL_RANDOM.H:885 |
|
|
void |
NP_VSL_RANDOM.H:2206 |
|
|
void |
NP_VSL_RANDOM.H:862 |
Linear Algebra#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
NP_VSL_RANDOM.H:610 |
|
|
void |
NP_VSL_RANDOM.H:2141 |
|
|
void |
NP_VSL_RANDOM.H:318 |
|
|
void |
NP_VSL_RANDOM.H:2060 |
|
|
void |
NP_VSL_RANDOM.H:333 |
|
|
void |
NP_VSL_RANDOM.H:2064 |
Random#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
NP_VSL_RANDOM.H:643 |
|
|
void |
NP_VSL_RANDOM.H:2156 |
|
|
void |
NP_VSL_RANDOM.H:406 |
|
|
void |
NP_VSL_RANDOM.H:2084 |
|
|
void |
NP_VSL_RANDOM.H:421 |
|
|
void |
NP_VSL_RANDOM.H:2088 |
|
|
void |
NP_VSL_RANDOM.H:750 |
|
|
void |
NP_VSL_RANDOM.H:2191 |
|
|
void |
NP_VSL_RANDOM.H:727 |
|
|
void |
NP_VSL_RANDOM.H:993 |
|
|
void |
NP_VSL_RANDOM.H:2216 |
|
|
void |
NP_VSL_RANDOM.H:955 |
|
|
void |
NP_VSL_RANDOM.H:974 |
|
|
void |
NP_VSL_RANDOM.H:632 |
|
|
void |
NP_VSL_RANDOM.H:2151 |
|
|
void |
NP_VSL_RANDOM.H:376 |
|
|
void |
NP_VSL_RANDOM.H:2076 |
|
|
void |
NP_VSL_RANDOM.H:391 |
|
|
void |
NP_VSL_RANDOM.H:2080 |
|
|
void |
NP_VSL_RANDOM.H:791 |
|
|
void |
NP_VSL_RANDOM.H:2196 |
|
|
void |
NP_VSL_RANDOM.H:772 |
|
|
void |
NP_VSL_RANDOM.H:235 |
|
|
void |
NP_VSL_RANDOM.H:2038 |
|
|
void |
NP_VSL_RANDOM.H:298 |
|
|
void |
NP_VSL_RANDOM.H:2054 |
|
|
int |
NP_VSL_RANDOM.H:1065 |
|
|
int |
NP_VSL_RANDOM.H:1076 |
|
|
void |
NP_VSL_RANDOM.H:253 |
|
|
void |
NP_VSL_RANDOM.H:2042 |
|
|
void |
NP_VSL_RANDOM.H:268 |
|
|
void |
NP_VSL_RANDOM.H:2046 |
|
|
void |
NP_VSL_RANDOM.H:283 |
|
|
void |
NP_VSL_RANDOM.H:2050 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
NP_VSL_RANDOM.H:687 |
|
|
void |
NP_VSL_RANDOM.H:2176 |
|
|
void |
NP_VSL_RANDOM.H:524 |
|
|
void |
NP_VSL_RANDOM.H:2116 |
|
|
void |
NP_VSL_RANDOM.H:539 |
|
|
void |
NP_VSL_RANDOM.H:2120 |
|
|
void |
NP_VSL_RANDOM.H:2226 |
|
|
void |
NP_VSL_RANDOM.H:839 |
|
|
void |
NP_VSL_RANDOM.H:2201 |
|
|
void |
NP_VSL_RANDOM.H:813 |
|
|
void |
NP_VSL_RANDOM.H:698 |
|
|
void |
NP_VSL_RANDOM.H:2181 |
|
|
void |
NP_VSL_RANDOM.H:554 |
|
|
void |
NP_VSL_RANDOM.H:2124 |
|
|
void |
NP_VSL_RANDOM.H:569 |
|
|
void |
NP_VSL_RANDOM.H:2128 |
|
|
void |
NP_VSL_RANDOM.H:933 |
|
|
void |
NP_VSL_RANDOM.H:2211 |
|
|
void |
NP_VSL_RANDOM.H:909 |
|
|
void |
NP_VSL_RANDOM.H:654 |
|
|
void |
NP_VSL_RANDOM.H:2161 |
|
|
void |
NP_VSL_RANDOM.H:436 |
|
|
void |
NP_VSL_RANDOM.H:2092 |
|
|
void |
NP_VSL_RANDOM.H:451 |
|
|
void |
NP_VSL_RANDOM.H:2096 |
|
|
int |
NP_VSL_RANDOM.H:1019 |
|
|
int |
NP_VSL_RANDOM.H:1034 |
|
|
int |
NP_VSL_RANDOM.H:1051 |
|
|
void |
NP_VSL_RANDOM.H:665 |
|
|
void |
NP_VSL_RANDOM.H:2166 |
|
|
void |
NP_VSL_RANDOM.H:465 |
|
|
void |
NP_VSL_RANDOM.H:2100 |
|
|
void |
NP_VSL_RANDOM.H:479 |
|
|
void |
NP_VSL_RANDOM.H:2104 |
|
|
void |
NP_VSL_RANDOM.H:2221 |
|
|
void |
NP_VSL_RANDOM.H:676 |
|
|
void |
NP_VSL_RANDOM.H:2171 |
|
|
void |
NP_VSL_RANDOM.H:494 |
|
|
void |
NP_VSL_RANDOM.H:2108 |
|
|
void |
NP_VSL_RANDOM.H:509 |
|
|
void |
NP_VSL_RANDOM.H:2112 |
Code Examples#
The following examples are extracted from the test suite.
triangular (np_test_1_all.cpp:22034)
22024 for (size_t i = 0; i < 3; ++i) {
22025 if (!(lognormal_arr.getElementAt({ i }) > 0.0)) {
22026 std::string description = std::string("testContinuousDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(lognormal_arr.getElementAt({ i }) > 0.0)";
22027 std::cout << std::string("[FAIL] ") + description << std::endl;
22028 throw std::runtime_error(description);
22029 }
22030 }
22031 // std::cout << "[OK] Log-normal distribution\n";
22032
22033 // Test triangular distribution
22034 auto triangular_arr = triangular<double>(0.0, 0.5, 1.0, { {3} });
22035 for (size_t i = 0; i < 3; ++i) {
22036 double val = triangular_arr.getElementAt({ i });
22037 if (!(val >= 0.0 && val <= 1.0)) {
22038 std::string description = std::string("testContinuousDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0.0 && val <= 1.0)";
22039 std::cout << std::string("[FAIL] ") + description << std::endl;
22040 throw std::runtime_error(description);
22041 }
22042 }
22043 // std::cout << "[OK] Triangular distribution\n";
exponential (np_test_1_all.cpp:8006)
7996void testComplex256PrecisionComplex256() {
7997 std::cout << "========= testComplex256PrecisionComplex256 =======================";
7998
7999 // Test high precision calculations
8000 complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L);
8001
8002 // std::cout << std::setprecision(20);
8003 // std::cout << "High precision complex: " << high_precision << std::endl;
8004
8005 // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x))
8006 complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π
8007 auto euler = std::exp(i_pi);
8008 // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl;
8009
8010 // Test complex roots
8011 complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L));
8012 // std::cout << "Cube root of unity: " << unity_root << std::endl;
8013 // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl;
8014
8015 // std::cout << std::setprecision(6); // Reset precision
exponential (np_test_1_all.cpp:8006)
7996void testComplex256PrecisionComplex256() {
7997 std::cout << "========= testComplex256PrecisionComplex256 =======================";
7998
7999 // Test high precision calculations
8000 complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L);
8001
8002 // std::cout << std::setprecision(20);
8003 // std::cout << "High precision complex: " << high_precision << std::endl;
8004
8005 // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x))
8006 complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π
8007 auto euler = std::exp(i_pi);
8008 // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl;
8009
8010 // Test complex roots
8011 complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L));
8012 // std::cout << "Cube root of unity: " << unity_root << std::endl;
8013 // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl;
8014
8015 // std::cout << std::setprecision(6); // Reset precision
lognormal (np_test_1_all.cpp:14134)
14124 }
14125 // std::cout << "[OK] Beta distribution float precision\n";
14126
14127 std::cout << " -> tests passed\n";
14128 }
14129
14130 void test_vsl_additional_distributions() {
14131 std::cout << "========= test_vsl_additional_distributions ====";
14132
14133 // Test lognormal distribution
14134 auto lognorm_arr = lognormal<double>(0.0, 1.0, { {100} });
14135 for (size_t i = 0; i < 100; ++i) {
14136 double val = lognorm_arr.getElementAt({ i });
14137 if (!(val > 0.0)) {
14138 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val > 0.0)";
14139 std::cout << std::string("[FAIL] ") + description << std::endl;
14140 throw std::runtime_error(description);
14141 }
14142 if (!(val < 100.0)) {
14143 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val < 100.0)";
14144 std::cout << std::string("[FAIL] ") + description << std::endl;
lognormal (np_test_1_all.cpp:14134)
14124 }
14125 // std::cout << "[OK] Beta distribution float precision\n";
14126
14127 std::cout << " -> tests passed\n";
14128 }
14129
14130 void test_vsl_additional_distributions() {
14131 std::cout << "========= test_vsl_additional_distributions ====";
14132
14133 // Test lognormal distribution
14134 auto lognorm_arr = lognormal<double>(0.0, 1.0, { {100} });
14135 for (size_t i = 0; i < 100; ++i) {
14136 double val = lognorm_arr.getElementAt({ i });
14137 if (!(val > 0.0)) {
14138 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val > 0.0)";
14139 std::cout << std::string("[FAIL] ") + description << std::endl;
14140 throw std::runtime_error(description);
14141 }
14142 if (!(val < 100.0)) {
14143 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val < 100.0)";
14144 std::cout << std::string("[FAIL] ") + description << std::endl;
negative_binomial (np_test_1_all.cpp:22127)
22117 int val = binom_arr.getElementAt({ i });
22118 if (!(val >= 0 && val <= 20)) {
22119 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0 && val <= 20)";
22120 std::cout << std::string("[FAIL] ") + description << std::endl;
22121 throw std::runtime_error(description);
22122 }
22123 }
22124 // std::cout << "[OK] Binomial distribution\n";
22125
22126 // Test negative binomial distribution
22127 auto negbinom_arr = negative_binomial<int>(10, 0.3, { {3} });
22128 if (!(negbinom_arr.getShape()[0] == 3)) {
22129 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(negbinom_arr.getShape()[0] == 3)";
22130 std::cout << std::string("[FAIL] ") + description << std::endl;
22131 throw std::runtime_error(description);
22132 }
22133 for (size_t i = 0; i < 3; ++i) {
22134 if (!(negbinom_arr.getElementAt({ i }) >= 0)) {
22135 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(negbinom_arr.getElementAt({ i }) >= 0)";
22136 std::cout << std::string("[FAIL] ") + description << std::endl;
22137 throw std::runtime_error(description);
negative_binomial (np_test_1_all.cpp:22127)
22117 int val = binom_arr.getElementAt({ i });
22118 if (!(val >= 0 && val <= 20)) {
22119 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0 && val <= 20)";
22120 std::cout << std::string("[FAIL] ") + description << std::endl;
22121 throw std::runtime_error(description);
22122 }
22123 }
22124 // std::cout << "[OK] Binomial distribution\n";
22125
22126 // Test negative binomial distribution
22127 auto negbinom_arr = negative_binomial<int>(10, 0.3, { {3} });
22128 if (!(negbinom_arr.getShape()[0] == 3)) {
22129 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(negbinom_arr.getShape()[0] == 3)";
22130 std::cout << std::string("[FAIL] ") + description << std::endl;
22131 throw std::runtime_error(description);
22132 }
22133 for (size_t i = 0; i < 3; ++i) {
22134 if (!(negbinom_arr.getElementAt({ i }) >= 0)) {
22135 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(negbinom_arr.getElementAt({ i }) >= 0)";
22136 std::cout << std::string("[FAIL] ") + description << std::endl;
22137 throw std::runtime_error(description);
normal (np_test_1_all.cpp:13866)
13856#include "../numpy/np_random.h"
13857
13858namespace numpy_tests {
13859
13860 using namespace numpy::random;
13861
13862 void test_vsl_normal_distribution() {
13863 std::cout << "========= test_vsl_normal_distribution ====";
13864
13865 // Test basic normal distribution
13866 auto norm_arr = normal<double>(0.0, 1.0, { {100} });
13867 if (!(norm_arr.getShape()[0] == 100)) {
13868 std::string description = std::string("test_vsl_normal_distribution():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(norm_arr.getShape()[0] == 100)";
13869 std::cout << std::string("[FAIL] ") + description << std::endl;
13870 throw std::runtime_error(description);
13871 }
13872
13873 // Check that values are reasonable for standard normal
13874 double sum = 0.0, sum_sq = 0.0;
13875 for (size_t i = 0; i < 100; ++i) {
13876 double val = norm_arr.getElementAt({ i });
normal (np_test_1_all.cpp:13866)
13856#include "../numpy/np_random.h"
13857
13858namespace numpy_tests {
13859
13860 using namespace numpy::random;
13861
13862 void test_vsl_normal_distribution() {
13863 std::cout << "========= test_vsl_normal_distribution ====";
13864
13865 // Test basic normal distribution
13866 auto norm_arr = normal<double>(0.0, 1.0, { {100} });
13867 if (!(norm_arr.getShape()[0] == 100)) {
13868 std::string description = std::string("test_vsl_normal_distribution():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(norm_arr.getShape()[0] == 100)";
13869 std::cout << std::string("[FAIL] ") + description << std::endl;
13870 throw std::runtime_error(description);
13871 }
13872
13873 // Check that values are reasonable for standard normal
13874 double sum = 0.0, sum_sq = 0.0;
13875 for (size_t i = 0; i < 100; ++i) {
13876 double val = norm_arr.getElementAt({ i });
beta (np_test_1_all.cpp:10394)
10384 NDArray<double> beta_a({ 4 });
10385 NDArray<double> beta_b({ 4 });
10386 beta_a.setElementAt({ 0 }, 1.0);
10387 beta_a.setElementAt({ 1 }, 2.0);
10388 beta_a.setElementAt({ 2 }, 1.0);
10389 beta_a.setElementAt({ 3 }, 2.0);
10390 beta_b.setElementAt({ 0 }, 1.0);
10391 beta_b.setElementAt({ 1 }, 1.0);
10392 beta_b.setElementAt({ 2 }, 2.0);
10393 beta_b.setElementAt({ 3 }, 2.0);
10394 auto beta_result = special::beta(beta_a, beta_b, MathBackend::MKL);
10395
10396 if (!(isApproxEqual(beta_result.getElementAt({ 0 }), 1.0, 1e-10))) {
10397 std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(beta_result.getElementAt({ 0 }), 1.0, 1e-10))";
10398 std::cout << std::string("[FAIL] ") + description << std::endl;
10399 throw std::runtime_error(description);
10400 }
10401 if (!(isApproxEqual(beta_result.getElementAt({ 1 }), 0.5, 1e-10))) {
10402 std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(beta_result.getElementAt({ 1 }), 0.5, 1e-10))";
10403 std::cout << std::string("[FAIL] ") + description << std::endl;
10404 throw std::runtime_error(description);
beta (np_test_1_all.cpp:10394)
10384 NDArray<double> beta_a({ 4 });
10385 NDArray<double> beta_b({ 4 });
10386 beta_a.setElementAt({ 0 }, 1.0);
10387 beta_a.setElementAt({ 1 }, 2.0);
10388 beta_a.setElementAt({ 2 }, 1.0);
10389 beta_a.setElementAt({ 3 }, 2.0);
10390 beta_b.setElementAt({ 0 }, 1.0);
10391 beta_b.setElementAt({ 1 }, 1.0);
10392 beta_b.setElementAt({ 2 }, 2.0);
10393 beta_b.setElementAt({ 3 }, 2.0);
10394 auto beta_result = special::beta(beta_a, beta_b, MathBackend::MKL);
10395
10396 if (!(isApproxEqual(beta_result.getElementAt({ 0 }), 1.0, 1e-10))) {
10397 std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(beta_result.getElementAt({ 0 }), 1.0, 1e-10))";
10398 std::cout << std::string("[FAIL] ") + description << std::endl;
10399 throw std::runtime_error(description);
10400 }
10401 if (!(isApproxEqual(beta_result.getElementAt({ 1 }), 0.5, 1e-10))) {
10402 std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(beta_result.getElementAt({ 1 }), 0.5, 1e-10))";
10403 std::cout << std::string("[FAIL] ") + description << std::endl;
10404 throw std::runtime_error(description);
binomial (np_test_1_all.cpp:22110)
22100 for (size_t i = 0; i < 4; ++i) {
22101 if (!(geom_arr.getElementAt({ i }) >= 1)) {
22102 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(geom_arr.getElementAt({ i }) >= 1)";
22103 std::cout << std::string("[FAIL] ") + description << std::endl;
22104 throw std::runtime_error(description);
22105 }
22106 }
22107 // std::cout << "[OK] Geometric distribution\n";
22108
22109 // Test binomial distribution
22110 auto binom_arr = binomial<int>(20, 0.3, { {5} });
22111 if (!(binom_arr.getShape()[0] == 5)) {
22112 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(binom_arr.getShape()[0] == 5)";
22113 std::cout << std::string("[FAIL] ") + description << std::endl;
22114 throw std::runtime_error(description);
22115 }
22116 for (size_t i = 0; i < 5; ++i) {
22117 int val = binom_arr.getElementAt({ i });
22118 if (!(val >= 0 && val <= 20)) {
22119 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0 && val <= 20)";
22120 std::cout << std::string("[FAIL] ") + description << std::endl;
binomial (np_test_1_all.cpp:22110)
22100 for (size_t i = 0; i < 4; ++i) {
22101 if (!(geom_arr.getElementAt({ i }) >= 1)) {
22102 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(geom_arr.getElementAt({ i }) >= 1)";
22103 std::cout << std::string("[FAIL] ") + description << std::endl;
22104 throw std::runtime_error(description);
22105 }
22106 }
22107 // std::cout << "[OK] Geometric distribution\n";
22108
22109 // Test binomial distribution
22110 auto binom_arr = binomial<int>(20, 0.3, { {5} });
22111 if (!(binom_arr.getShape()[0] == 5)) {
22112 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(binom_arr.getShape()[0] == 5)";
22113 std::cout << std::string("[FAIL] ") + description << std::endl;
22114 throw std::runtime_error(description);
22115 }
22116 for (size_t i = 0; i < 5; ++i) {
22117 int val = binom_arr.getElementAt({ i });
22118 if (!(val >= 0 && val <= 20)) {
22119 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0 && val <= 20)";
22120 std::cout << std::string("[FAIL] ") + description << std::endl;
chisquare (np_test_1_all.cpp:21974)
21964#include <algorithm>
21965#include "../numpy/np_random.h"
21966namespace numpy_tests {
21967
21968 using namespace numpy::random;
21969
21970 void testContinuousDistributions() {
21971 std::cout << "========= testContinuousDistributions ====";
21972
21973 // Test chi-square distribution
21974 auto chi2_arr = chisquare<double>(3.0, { {2, 3} });
21975 if (!(chi2_arr.getShape()[0] == 2)) {
21976 std::string description = std::string("testContinuousDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(chi2_arr.getShape()[0] == 2)";
21977 std::cout << std::string("[FAIL] ") + description << std::endl;
21978 throw std::runtime_error(description);
21979 }
21980 if (!(chi2_arr.getShape()[1] == 3)) {
21981 std::string description = std::string("testContinuousDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(chi2_arr.getShape()[1] == 3)";
21982 std::cout << std::string("[FAIL] ") + description << std::endl;
21983 throw std::runtime_error(description);
21984 }
chisquare (np_test_1_all.cpp:21974)
21964#include <algorithm>
21965#include "../numpy/np_random.h"
21966namespace numpy_tests {
21967
21968 using namespace numpy::random;
21969
21970 void testContinuousDistributions() {
21971 std::cout << "========= testContinuousDistributions ====";
21972
21973 // Test chi-square distribution
21974 auto chi2_arr = chisquare<double>(3.0, { {2, 3} });
21975 if (!(chi2_arr.getShape()[0] == 2)) {
21976 std::string description = std::string("testContinuousDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(chi2_arr.getShape()[0] == 2)";
21977 std::cout << std::string("[FAIL] ") + description << std::endl;
21978 throw std::runtime_error(description);
21979 }
21980 if (!(chi2_arr.getShape()[1] == 3)) {
21981 std::string description = std::string("testContinuousDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(chi2_arr.getShape()[1] == 3)";
21982 std::cout << std::string("[FAIL] ") + description << std::endl;
21983 throw std::runtime_error(description);
21984 }
gamma (np_test_1_all.cpp:10297)
10287 std::cout << "========= testGammaFunctions ====";
10288
10289 // Test gamma function for known values using NDArray with MKL backend
10290 NDArray<double> gamma_test({ 6 });
10291 gamma_test.setElementAt({ 0 }, 1.0);
10292 gamma_test.setElementAt({ 1 }, 2.0);
10293 gamma_test.setElementAt({ 2 }, 3.0);
10294 gamma_test.setElementAt({ 3 }, 4.0);
10295 gamma_test.setElementAt({ 4 }, 5.0);
10296 gamma_test.setElementAt({ 5 }, 0.5);
10297 auto gamma_result = special::gamma(gamma_test, MathBackend::MKL);
10298
10299 if (!(isApproxEqual(gamma_result.getElementAt({ 0 }), 1.0, 1e-10))) {
10300 std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(gamma_result.getElementAt({ 0 }), 1.0, 1e-10))";
10301 std::cout << std::string("[FAIL] ") + description << std::endl;
10302 throw std::runtime_error(description);
10303 }
10304 if (!(isApproxEqual(gamma_result.getElementAt({ 1 }), 1.0, 1e-10))) {
10305 std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(gamma_result.getElementAt({ 1 }), 1.0, 1e-10))";
10306 std::cout << std::string("[FAIL] ") + description << std::endl;
10307 throw std::runtime_error(description);
gamma (np_test_1_all.cpp:10297)
10287 std::cout << "========= testGammaFunctions ====";
10288
10289 // Test gamma function for known values using NDArray with MKL backend
10290 NDArray<double> gamma_test({ 6 });
10291 gamma_test.setElementAt({ 0 }, 1.0);
10292 gamma_test.setElementAt({ 1 }, 2.0);
10293 gamma_test.setElementAt({ 2 }, 3.0);
10294 gamma_test.setElementAt({ 3 }, 4.0);
10295 gamma_test.setElementAt({ 4 }, 5.0);
10296 gamma_test.setElementAt({ 5 }, 0.5);
10297 auto gamma_result = special::gamma(gamma_test, MathBackend::MKL);
10298
10299 if (!(isApproxEqual(gamma_result.getElementAt({ 0 }), 1.0, 1e-10))) {
10300 std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(gamma_result.getElementAt({ 0 }), 1.0, 1e-10))";
10301 std::cout << std::string("[FAIL] ") + description << std::endl;
10302 throw std::runtime_error(description);
10303 }
10304 if (!(isApproxEqual(gamma_result.getElementAt({ 1 }), 1.0, 1e-10))) {
10305 std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(gamma_result.getElementAt({ 1 }), 1.0, 1e-10))";
10306 std::cout << std::string("[FAIL] ") + description << std::endl;
10307 throw std::runtime_error(description);
poisson (np_test_1_all.cpp:23404)
23394#include "../numpy/np_random.h"
23395
23396namespace numpy_tests {
23397
23398 using namespace numpy::random;
23399
23400 void np_test_poisson_basic_generation() {
23401 std::cout << "========= np_test_poisson_basic_generation =======================";
23402
23403 // Test poisson with default parameters (lambda=1.0, size=1)
23404 auto poisson_default = poisson<int>(1.0);
23405 if (poisson_default.getSize() != 1) {
23406 throw std::runtime_error("Poisson default generation failed");
23407 }
23408
23409 // Test poisson with custom parameters
23410 auto poisson_custom = poisson<int>(5.0, { {3, 2} });
23411 if (poisson_custom.getShape() != std::vector<size_t>({ 3, 2 })) {
23412 throw std::runtime_error("Poisson custom generation failed");
23413 }
poisson (np_test_1_all.cpp:23404)
23394#include "../numpy/np_random.h"
23395
23396namespace numpy_tests {
23397
23398 using namespace numpy::random;
23399
23400 void np_test_poisson_basic_generation() {
23401 std::cout << "========= np_test_poisson_basic_generation =======================";
23402
23403 // Test poisson with default parameters (lambda=1.0, size=1)
23404 auto poisson_default = poisson<int>(1.0);
23405 if (poisson_default.getSize() != 1) {
23406 throw std::runtime_error("Poisson default generation failed");
23407 }
23408
23409 // Test poisson with custom parameters
23410 auto poisson_custom = poisson<int>(5.0, { {3, 2} });
23411 if (poisson_custom.getShape() != std::vector<size_t>({ 3, 2 })) {
23412 throw std::runtime_error("Poisson custom generation failed");
23413 }
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 });
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 });
uniform (np_test_1_all.cpp:14301)
14291 double val = beta_gen.getElementAt({ i });
14292 if (!(val >= 0.0 && val <= 1.0)) {
14293 std::string description = std::string("test_vsl_generator_class():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0.0 && val <= 1.0)";
14294 std::cout << std::string("[FAIL] ") + description << std::endl;
14295 throw std::runtime_error(description);
14296 }
14297 }
14298 // std::cout << "[OK] Generator beta method\n";
14299
14300 // Test uniform and random methods
14301 auto unif_gen = gen.uniform<double>(0.0, 10.0, { {50} });
14302 auto rand_gen = gen.random<double>({ {50} });
14303
14304 for (size_t i = 0; i < 50; ++i) {
14305 double unif_val = unif_gen.getElementAt({ i });
14306 double rand_val = rand_gen.getElementAt({ i });
14307 if (!(unif_val >= 0.0 && unif_val < 10.0)) {
14308 std::string description = std::string("test_vsl_generator_class():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unif_val >= 0.0 && unif_val < 10.0)";
14309 std::cout << std::string("[FAIL] ") + description << std::endl;
14310 throw std::runtime_error(description);
14311 }
uniform (np_test_1_all.cpp:14301)
14291 double val = beta_gen.getElementAt({ i });
14292 if (!(val >= 0.0 && val <= 1.0)) {
14293 std::string description = std::string("test_vsl_generator_class():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0.0 && val <= 1.0)";
14294 std::cout << std::string("[FAIL] ") + description << std::endl;
14295 throw std::runtime_error(description);
14296 }
14297 }
14298 // std::cout << "[OK] Generator beta method\n";
14299
14300 // Test uniform and random methods
14301 auto unif_gen = gen.uniform<double>(0.0, 10.0, { {50} });
14302 auto rand_gen = gen.random<double>({ {50} });
14303
14304 for (size_t i = 0; i < 50; ++i) {
14305 double unif_val = unif_gen.getElementAt({ i });
14306 double rand_val = rand_gen.getElementAt({ i });
14307 if (!(unif_val >= 0.0 && unif_val < 10.0)) {
14308 std::string description = std::string("test_vsl_generator_class():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unif_val >= 0.0 && unif_val < 10.0)";
14309 std::cout << std::string("[FAIL] ") + description << std::endl;
14310 throw std::runtime_error(description);
14311 }
uniform_f64 (np_test_1_all.cpp:14610)
14600 void test_vsl_uniform_reproducibility() {
14601 std::cout << "========= test_vsl_uniform_reproducibility ====";
14602
14603#ifdef NUMPY_USE_MKL
14604 if (numpy::vsl::is_vsl_available()) {
14605 // Test seed reproducibility with VSL streams
14606 numpy::vsl::VSLRandomStream stream1(12345);
14607 numpy::vsl::VSLRandomStream stream2(12345);
14608
14609 std::vector<double> buf1(100), buf2(100);
14610 stream1.uniform_f64(buf1.data(), 100, 0.0, 1.0);
14611 stream2.uniform_f64(buf2.data(), 100, 0.0, 1.0);
14612
14613 for (size_t i = 0; i < 100; ++i) {
14614 if (!(std::abs(buf1[i] - buf2[i]) < 1e-15)) {
14615 std::string description = std::string("test_vsl_uniform_reproducibility():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(buf1[i] - buf2[i]) < 1e-15)";
14616 std::cout << std::string("[FAIL] ") + description << std::endl;
14617 throw std::runtime_error(description);
14618 }
14619 }
14620 // std::cout << "[OK] VSL stream reproducibility\n";
uniform_f64 (np_test_1_all.cpp:14610)
14600 void test_vsl_uniform_reproducibility() {
14601 std::cout << "========= test_vsl_uniform_reproducibility ====";
14602
14603#ifdef NUMPY_USE_MKL
14604 if (numpy::vsl::is_vsl_available()) {
14605 // Test seed reproducibility with VSL streams
14606 numpy::vsl::VSLRandomStream stream1(12345);
14607 numpy::vsl::VSLRandomStream stream2(12345);
14608
14609 std::vector<double> buf1(100), buf2(100);
14610 stream1.uniform_f64(buf1.data(), 100, 0.0, 1.0);
14611 stream2.uniform_f64(buf2.data(), 100, 0.0, 1.0);
14612
14613 for (size_t i = 0; i < 100; ++i) {
14614 if (!(std::abs(buf1[i] - buf2[i]) < 1e-15)) {
14615 std::string description = std::string("test_vsl_uniform_reproducibility():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(buf1[i] - buf2[i]) < 1e-15)";
14616 std::cout << std::string("[FAIL] ") + description << std::endl;
14617 throw std::runtime_error(description);
14618 }
14619 }
14620 // std::cout << "[OK] VSL stream reproducibility\n";
cauchy (np_test_3_all.cpp:5774)
5764namespace numpy_tests {
5765
5766 using namespace numpy::random;
5767
5768 namespace test_cauchy_gumbel {
5769
5770 void np_test_cauchy_gumbel_basic_generation() {
5771 std::cout << "========= np_test_cauchy_gumbel_basic_generation =======================";
5772
5773 // Test cauchy with default parameters
5774 auto cauchy_default = cauchy<double>();
5775 if (cauchy_default.getSize() != 1) {
5776 throw std::runtime_error("Cauchy default generation failed");
5777 }
5778
5779 // Test cauchy with custom parameters
5780 auto cauchy_custom = cauchy<double>(2.0, 0.5, { {3, 2} });
5781 if (cauchy_custom.getShape() != std::vector<size_t>({ 3, 2 })) {
5782 throw std::runtime_error("Cauchy custom generation failed");
5783 }
cauchy (np_test_3_all.cpp:5774)
5764namespace numpy_tests {
5765
5766 using namespace numpy::random;
5767
5768 namespace test_cauchy_gumbel {
5769
5770 void np_test_cauchy_gumbel_basic_generation() {
5771 std::cout << "========= np_test_cauchy_gumbel_basic_generation =======================";
5772
5773 // Test cauchy with default parameters
5774 auto cauchy_default = cauchy<double>();
5775 if (cauchy_default.getSize() != 1) {
5776 throw std::runtime_error("Cauchy default generation failed");
5777 }
5778
5779 // Test cauchy with custom parameters
5780 auto cauchy_custom = cauchy<double>(2.0, 0.5, { {3, 2} });
5781 if (cauchy_custom.getShape() != std::vector<size_t>({ 3, 2 })) {
5782 throw std::runtime_error("Cauchy custom generation failed");
5783 }
geometric (np_test_1_all.cpp:22094)
22084 }
22085 // std::cout << "[OK] Student's t-distribution\n";
22086
22087 std::cout << " -> tests passed\n";
22088 }
22089
22090 void testDiscreteDistributions() {
22091 std::cout << "========= testDiscreteDistributions ====";
22092
22093 // Test geometric distribution
22094 auto geom_arr = geometric<int>(0.3, { {4} });
22095 if (!(geom_arr.getShape()[0] == 4)) {
22096 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(geom_arr.getShape()[0] == 4)";
22097 std::cout << std::string("[FAIL] ") + description << std::endl;
22098 throw std::runtime_error(description);
22099 }
22100 for (size_t i = 0; i < 4; ++i) {
22101 if (!(geom_arr.getElementAt({ i }) >= 1)) {
22102 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(geom_arr.getElementAt({ i }) >= 1)";
22103 std::cout << std::string("[FAIL] ") + description << std::endl;
22104 throw std::runtime_error(description);
geometric (np_test_1_all.cpp:22094)
22084 }
22085 // std::cout << "[OK] Student's t-distribution\n";
22086
22087 std::cout << " -> tests passed\n";
22088 }
22089
22090 void testDiscreteDistributions() {
22091 std::cout << "========= testDiscreteDistributions ====";
22092
22093 // Test geometric distribution
22094 auto geom_arr = geometric<int>(0.3, { {4} });
22095 if (!(geom_arr.getShape()[0] == 4)) {
22096 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(geom_arr.getShape()[0] == 4)";
22097 std::cout << std::string("[FAIL] ") + description << std::endl;
22098 throw std::runtime_error(description);
22099 }
22100 for (size_t i = 0; i < 4; ++i) {
22101 if (!(geom_arr.getElementAt({ i }) >= 1)) {
22102 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(geom_arr.getElementAt({ i }) >= 1)";
22103 std::cout << std::string("[FAIL] ") + description << std::endl;
22104 throw std::runtime_error(description);
gumbel (np_test_3_all.cpp:5786)
5776 throw std::runtime_error("Cauchy default generation failed");
5777 }
5778
5779 // Test cauchy with custom parameters
5780 auto cauchy_custom = cauchy<double>(2.0, 0.5, { {3, 2} });
5781 if (cauchy_custom.getShape() != std::vector<size_t>({ 3, 2 })) {
5782 throw std::runtime_error("Cauchy custom generation failed");
5783 }
5784
5785 // Test gumbel with default parameters
5786 auto gumbel_default = gumbel<double>();
5787 if (gumbel_default.getSize() != 1) {
5788 throw std::runtime_error("Gumbel default generation failed");
5789 }
5790
5791 // Test gumbel with custom parameters
5792 auto gumbel_custom = gumbel<double>(1.0, 2.0, { {2, 3} });
5793 if (gumbel_custom.getShape() != std::vector<size_t>({ 2, 3 })) {
5794 throw std::runtime_error("Gumbel custom generation failed");
5795 }
gumbel (np_test_3_all.cpp:5786)
5776 throw std::runtime_error("Cauchy default generation failed");
5777 }
5778
5779 // Test cauchy with custom parameters
5780 auto cauchy_custom = cauchy<double>(2.0, 0.5, { {3, 2} });
5781 if (cauchy_custom.getShape() != std::vector<size_t>({ 3, 2 })) {
5782 throw std::runtime_error("Cauchy custom generation failed");
5783 }
5784
5785 // Test gumbel with default parameters
5786 auto gumbel_default = gumbel<double>();
5787 if (gumbel_default.getSize() != 1) {
5788 throw std::runtime_error("Gumbel default generation failed");
5789 }
5790
5791 // Test gumbel with custom parameters
5792 auto gumbel_custom = gumbel<double>(1.0, 2.0, { {2, 3} });
5793 if (gumbel_custom.getShape() != std::vector<size_t>({ 2, 3 })) {
5794 throw std::runtime_error("Gumbel custom generation failed");
5795 }
hypergeometric (np_test_1_all.cpp:22143)
22133 for (size_t i = 0; i < 3; ++i) {
22134 if (!(negbinom_arr.getElementAt({ i }) >= 0)) {
22135 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(negbinom_arr.getElementAt({ i }) >= 0)";
22136 std::cout << std::string("[FAIL] ") + description << std::endl;
22137 throw std::runtime_error(description);
22138 }
22139 }
22140 // std::cout << "[OK] Negative binomial distribution\n";
22141
22142 // Test hypergeometric distribution
22143 auto hypergeo_arr = hypergeometric<int>(20, 30, 10, { {3} });
22144 if (!(hypergeo_arr.getShape()[0] == 3)) {
22145 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(hypergeo_arr.getShape()[0] == 3)";
22146 std::cout << std::string("[FAIL] ") + description << std::endl;
22147 throw std::runtime_error(description);
22148 }
22149 for (size_t i = 0; i < 3; ++i) {
22150 int val = hypergeo_arr.getElementAt({ i });
22151 if (!(val >= 0 && val <= 10)) {
22152 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0 && val <= 10)";
22153 std::cout << std::string("[FAIL] ") + description << std::endl;
hypergeometric (np_test_1_all.cpp:22143)
22133 for (size_t i = 0; i < 3; ++i) {
22134 if (!(negbinom_arr.getElementAt({ i }) >= 0)) {
22135 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(negbinom_arr.getElementAt({ i }) >= 0)";
22136 std::cout << std::string("[FAIL] ") + description << std::endl;
22137 throw std::runtime_error(description);
22138 }
22139 }
22140 // std::cout << "[OK] Negative binomial distribution\n";
22141
22142 // Test hypergeometric distribution
22143 auto hypergeo_arr = hypergeometric<int>(20, 30, 10, { {3} });
22144 if (!(hypergeo_arr.getShape()[0] == 3)) {
22145 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(hypergeo_arr.getShape()[0] == 3)";
22146 std::cout << std::string("[FAIL] ") + description << std::endl;
22147 throw std::runtime_error(description);
22148 }
22149 for (size_t i = 0; i < 3; ++i) {
22150 int val = hypergeo_arr.getElementAt({ i });
22151 if (!(val >= 0 && val <= 10)) {
22152 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0 && val <= 10)";
22153 std::cout << std::string("[FAIL] ") + description << std::endl;
laplace (np_test_1_all.cpp:14151)
14141 }
14142 if (!(val < 100.0)) {
14143 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val < 100.0)";
14144 std::cout << std::string("[FAIL] ") + description << std::endl;
14145 throw std::runtime_error(description);
14146 }
14147 }
14148 // std::cout << "[OK] Lognormal distribution test\n";
14149
14150 // Test Laplace distribution
14151 auto laplace_arr = laplace<double>(0.0, 1.0, { {100} });
14152 for (size_t i = 0; i < 100; ++i) {
14153 double val = laplace_arr.getElementAt({ i });
14154 if (!(std::abs(val) < 10.0)) {
14155 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(val) < 10.0)";
14156 std::cout << std::string("[FAIL] ") + description << std::endl;
14157 throw std::runtime_error(description);
14158 }
14159 }
14160 // std::cout << "[OK] Laplace distribution test\n";
laplace (np_test_1_all.cpp:14151)
14141 }
14142 if (!(val < 100.0)) {
14143 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val < 100.0)";
14144 std::cout << std::string("[FAIL] ") + description << std::endl;
14145 throw std::runtime_error(description);
14146 }
14147 }
14148 // std::cout << "[OK] Lognormal distribution test\n";
14149
14150 // Test Laplace distribution
14151 auto laplace_arr = laplace<double>(0.0, 1.0, { {100} });
14152 for (size_t i = 0; i < 100; ++i) {
14153 double val = laplace_arr.getElementAt({ i });
14154 if (!(std::abs(val) < 10.0)) {
14155 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(val) < 10.0)";
14156 std::cout << std::string("[FAIL] ") + description << std::endl;
14157 throw std::runtime_error(description);
14158 }
14159 }
14160 // std::cout << "[OK] Laplace distribution test\n";
multinomial (np_test_1_all.cpp:22161)
22151 if (!(val >= 0 && val <= 10)) {
22152 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0 && val <= 10)";
22153 std::cout << std::string("[FAIL] ") + description << std::endl;
22154 throw std::runtime_error(description);
22155 }
22156 }
22157 // std::cout << "[OK] Hypergeometric distribution\n";
22158
22159 // Test multinomial distribution
22160 std::vector<double> pvals = { 0.2, 0.3, 0.5 };
22161 auto multi_arr = multinomial<int>(100, pvals, { {2} });
22162 if (!(multi_arr.getShape()[0] == 2)) {
22163 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(multi_arr.getShape()[0] == 2)";
22164 std::cout << std::string("[FAIL] ") + description << std::endl;
22165 throw std::runtime_error(description);
22166 }
22167 if (!(multi_arr.getShape()[1] == 3)) {
22168 std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(multi_arr.getShape()[1] == 3)";
22169 std::cout << std::string("[FAIL] ") + description << std::endl;
22170 throw std::runtime_error(description);
22171 }
multivariate_normal (np_test_1_all.cpp:22212)
22202 std::cout << " -> tests passed\n";
22203 }
22204
22205 void testMultivariateDistributions() {
22206 std::cout << "========= testMultivariateDistributions ====";
22207
22208 // Test multivariate normal distribution
22209 std::vector<double> mean = { 0.0, 1.0 };
22210 std::vector<std::vector<double>> cov = { {1.0, 0.5}, {0.5, 2.0} };
22211 auto mvn_arr = multivariate_normal<double>(mean, cov, { {3} });
22212
22213 if (!(mvn_arr.getShape()[0] == 3)) {
22214 std::string description = std::string("testMultivariateDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(mvn_arr.getShape()[0] == 3)";
22215 std::cout << std::string("[FAIL] ") + description << std::endl;
22216 throw std::runtime_error(description);
22217 }
22218 if (!(mvn_arr.getShape()[1] == 2)) {
22219 std::string description = std::string("testMultivariateDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(mvn_arr.getShape()[1] == 2)";
22220 std::cout << std::string("[FAIL] ") + description << std::endl;
22221 throw std::runtime_error(description);
multivariate_normal (np_test_1_all.cpp:22212)
22202 std::cout << " -> tests passed\n";
22203 }
22204
22205 void testMultivariateDistributions() {
22206 std::cout << "========= testMultivariateDistributions ====";
22207
22208 // Test multivariate normal distribution
22209 std::vector<double> mean = { 0.0, 1.0 };
22210 std::vector<std::vector<double>> cov = { {1.0, 0.5}, {0.5, 2.0} };
22211 auto mvn_arr = multivariate_normal<double>(mean, cov, { {3} });
22212
22213 if (!(mvn_arr.getShape()[0] == 3)) {
22214 std::string description = std::string("testMultivariateDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(mvn_arr.getShape()[0] == 3)";
22215 std::cout << std::string("[FAIL] ") + description << std::endl;
22216 throw std::runtime_error(description);
22217 }
22218 if (!(mvn_arr.getShape()[1] == 2)) {
22219 std::string description = std::string("testMultivariateDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(mvn_arr.getShape()[1] == 2)";
22220 std::cout << std::string("[FAIL] ") + description << std::endl;
22221 throw std::runtime_error(description);
rayleigh (np_test_1_all.cpp:14163)
14153 double val = laplace_arr.getElementAt({ i });
14154 if (!(std::abs(val) < 10.0)) {
14155 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(val) < 10.0)";
14156 std::cout << std::string("[FAIL] ") + description << std::endl;
14157 throw std::runtime_error(description);
14158 }
14159 }
14160 // std::cout << "[OK] Laplace distribution test\n";
14161
14162 // Test Rayleigh distribution
14163 auto rayleigh_arr = rayleigh<double>(1.0, { {100} });
14164 for (size_t i = 0; i < 100; ++i) {
14165 double val = rayleigh_arr.getElementAt({ i });
14166 if (!(val >= 0.0)) {
14167 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0.0)";
14168 std::cout << std::string("[FAIL] ") + description << std::endl;
14169 throw std::runtime_error(description);
14170 }
14171 if (!(val < 10.0)) {
14172 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val < 10.0)";
14173 std::cout << std::string("[FAIL] ") + description << std::endl;
rayleigh (np_test_1_all.cpp:14163)
14153 double val = laplace_arr.getElementAt({ i });
14154 if (!(std::abs(val) < 10.0)) {
14155 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(val) < 10.0)";
14156 std::cout << std::string("[FAIL] ") + description << std::endl;
14157 throw std::runtime_error(description);
14158 }
14159 }
14160 // std::cout << "[OK] Laplace distribution test\n";
14161
14162 // Test Rayleigh distribution
14163 auto rayleigh_arr = rayleigh<double>(1.0, { {100} });
14164 for (size_t i = 0; i < 100; ++i) {
14165 double val = rayleigh_arr.getElementAt({ i });
14166 if (!(val >= 0.0)) {
14167 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0.0)";
14168 std::cout << std::string("[FAIL] ") + description << std::endl;
14169 throw std::runtime_error(description);
14170 }
14171 if (!(val < 10.0)) {
14172 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val < 10.0)";
14173 std::cout << std::string("[FAIL] ") + description << std::endl;
weibull (np_test_1_all.cpp:14180)
14170 }
14171 if (!(val < 10.0)) {
14172 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val < 10.0)";
14173 std::cout << std::string("[FAIL] ") + description << std::endl;
14174 throw std::runtime_error(description);
14175 }
14176 }
14177 // std::cout << "[OK] Rayleigh distribution test\n";
14178
14179 // Test Weibull distribution
14180 auto weibull_arr = weibull<double>(2.0, { {100} });
14181 for (size_t i = 0; i < 100; ++i) {
14182 double val = weibull_arr.getElementAt({ i });
14183 if (!(val >= 0.0)) {
14184 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0.0)";
14185 std::cout << std::string("[FAIL] ") + description << std::endl;
14186 throw std::runtime_error(description);
14187 }
14188 if (!(val < 10.0)) {
14189 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val < 10.0)";
14190 std::cout << std::string("[FAIL] ") + description << std::endl;
weibull (np_test_1_all.cpp:14180)
14170 }
14171 if (!(val < 10.0)) {
14172 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val < 10.0)";
14173 std::cout << std::string("[FAIL] ") + description << std::endl;
14174 throw std::runtime_error(description);
14175 }
14176 }
14177 // std::cout << "[OK] Rayleigh distribution test\n";
14178
14179 // Test Weibull distribution
14180 auto weibull_arr = weibull<double>(2.0, { {100} });
14181 for (size_t i = 0; i < 100; ++i) {
14182 double val = weibull_arr.getElementAt({ i });
14183 if (!(val >= 0.0)) {
14184 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0.0)";
14185 std::cout << std::string("[FAIL] ") + description << std::endl;
14186 throw std::runtime_error(description);
14187 }
14188 if (!(val < 10.0)) {
14189 std::string description = std::string("test_vsl_additional_distributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val < 10.0)";
14190 std::cout << std::string("[FAIL] ") + description << std::endl;