MathBackendConfig ================= .. cpp:class:: numpy::MathBackendConfig numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use MathBackendConfig MathBackendConfig obj; // ... operations ... Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``MathBackend get_default_backend()`` - MathBackend - NP_SPECIAL.H:18 - :ref:`View ` Type Checking ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool is_mkl_available()`` - bool - NP_SPECIAL.H:26 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void set_default_backend(MathBackendbackend)`` - void - NP_SPECIAL.H:22 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-mathbackendconfig-get_default_backend-0: .. dropdown:: get_default_backend (np_test_1_all.cpp:25367) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 25357 :emphasize-lines: 11 // std::cout << "[OK] BoostInfo tests passed" << std::endl; } void test_boost_config() { std::cout << "========= Testing BoostConfig ==================="; using namespace numpy::boost_lib; // Test default backend Backend default_backend = BoostConfig::get_default_backend(); // std::cout << "Default backend: " // << (default_backend == Backend::AUTO ? "AUTO" : // default_backend == Backend::BOOST ? "BOOST" : "STANDARD") // << std::endl; // Test backend resolution Backend resolved_auto = BoostConfig::resolve_backend(Backend::AUTO); // std::cout << "Resolved AUTO backend: " // << (resolved_auto == Backend::BOOST ? "BOOST" : "STANDARD") // << std::endl; .. _example-mathbackendconfig-is_mkl_available-1: .. dropdown:: is_mkl_available (np_test_1_all.cpp:10549) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10539 :emphasize-lines: 11 if (!(isApproxEqual(sum, 1.0, 1e-6))) { std::string description = std::string("testErrorFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(sum, 1.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] erf(x) + erfc(x) = 1 identity\n"; // Test erfcx function // Test with MKL if available if (MathBackendConfig::is_mkl_available()) { // erfcx(x) = exp(x²) * erfc(x) for (double x = 0.1; x <= 2.0; x += 0.3) { // Create NDArray for MKL computation auto x_array = createFloat64Array({ 1 }, x); auto erfcx_result = special::erfcx(x_array, MathBackend::MKL); double erfcx_val = erfcx_result.getElementAt({ 0 }); auto erfc_result = special::erfc(x_array, MathBackend::MKL); double expected = std::exp(x * x) * erfc_result.getElementAt({ 0 }); // std::cout << "x: " << x << ", erfcx: " << erfcx_val << ", expected: " << expected .. _example-mathbackendconfig-set_default_backend-2: .. dropdown:: set_default_backend (np_test_1_all.cpp:25414) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 25404 :emphasize-lines: 11 // Test forced STANDARD backend bool use_standard = BoostConfig::should_use_boost(Backend::STANDARD); if (use_standard) { throw std::runtime_error("Forced STANDARD backend not working"); } // std::cout << "[OK] Forced STANDARD backend works" << std::endl; // Test backend setting Backend original = BoostConfig::get_default_backend(); BoostConfig::set_default_backend(Backend::STANDARD); if (BoostConfig::get_default_backend() != Backend::STANDARD) { throw std::runtime_error("Backend setting not working"); } BoostConfig::set_default_backend(original); // Restore // std::cout << "[OK] Backend setting works" << std::endl; // std::cout << "[OK] BoostConfig tests passed" << std::endl; } #if BOOST_ENABLED