MathBackendConfig#
-
class numpy::MathBackendConfig#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use MathBackendConfig
MathBackendConfig obj;
// ... operations ...
Indexing / Selection#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
MathBackend |
NP_SPECIAL.H:18 |
Type Checking#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
NP_SPECIAL.H:26 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
NP_SPECIAL.H:22 |
Code Examples#
The following examples are extracted from the test suite.
get_default_backend (np_test_1_all.cpp:25367)
25357 // std::cout << "[OK] BoostInfo tests passed" << std::endl;
25358 }
25359
25360 void test_boost_config() {
25361 std::cout << "========= Testing BoostConfig ===================";
25362
25363 using namespace numpy::boost_lib;
25364
25365 // Test default backend
25366 Backend default_backend = BoostConfig::get_default_backend();
25367 // std::cout << "Default backend: "
25368 // << (default_backend == Backend::AUTO ? "AUTO" :
25369 // default_backend == Backend::BOOST ? "BOOST" : "STANDARD")
25370 // << std::endl;
25371
25372 // Test backend resolution
25373 Backend resolved_auto = BoostConfig::resolve_backend(Backend::AUTO);
25374 // std::cout << "Resolved AUTO backend: "
25375 // << (resolved_auto == Backend::BOOST ? "BOOST" : "STANDARD")
25376 // << std::endl;
is_mkl_available (np_test_1_all.cpp:10549)
10539 if (!(isApproxEqual(sum, 1.0, 1e-6))) {
10540 std::string description = std::string("testErrorFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(sum, 1.0, 1e-6))";
10541 std::cout << std::string("[FAIL] ") + description << std::endl;
10542 throw std::runtime_error(description);
10543 }
10544 }
10545 // std::cout << "[OK] erf(x) + erfc(x) = 1 identity\n";
10546
10547 // Test erfcx function
10548 // Test with MKL if available
10549 if (MathBackendConfig::is_mkl_available()) {
10550 // erfcx(x) = exp(x²) * erfc(x)
10551 for (double x = 0.1; x <= 2.0; x += 0.3) {
10552 // Create NDArray for MKL computation
10553 auto x_array = createFloat64Array({ 1 }, x);
10554 auto erfcx_result = special::erfcx(x_array, MathBackend::MKL);
10555 double erfcx_val = erfcx_result.getElementAt({ 0 });
10556
10557 auto erfc_result = special::erfc(x_array, MathBackend::MKL);
10558 double expected = std::exp(x * x) * erfc_result.getElementAt({ 0 });
10559 // std::cout << "x: " << x << ", erfcx: " << erfcx_val << ", expected: " << expected
set_default_backend (np_test_1_all.cpp:25414)
25404 // Test forced STANDARD backend
25405 bool use_standard = BoostConfig::should_use_boost(Backend::STANDARD);
25406 if (use_standard) {
25407 throw std::runtime_error("Forced STANDARD backend not working");
25408 }
25409 // std::cout << "[OK] Forced STANDARD backend works" << std::endl;
25410
25411 // Test backend setting
25412 Backend original = BoostConfig::get_default_backend();
25413 BoostConfig::set_default_backend(Backend::STANDARD);
25414 if (BoostConfig::get_default_backend() != Backend::STANDARD) {
25415 throw std::runtime_error("Backend setting not working");
25416 }
25417 BoostConfig::set_default_backend(original); // Restore
25418 // std::cout << "[OK] Backend setting works" << std::endl;
25419
25420 // std::cout << "[OK] BoostConfig tests passed" << std::endl;
25421 }
25422
25423#if BOOST_ENABLED