MKLConfig ========= .. cpp:class:: numpy::MKLConfig numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use MKLConfig MKLConfig obj; // ... operations ... Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``Backend get_default_backend()`` - Backend - MKL_CONFIG.H:183 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``Backend resolve_backend(Backendrequested = Backend::AUTO)`` - Backend - MKL_CONFIG.H:190 - :ref:`View ` * - ``void set_default_backend(Backendbackend)`` - void - MKL_CONFIG.H:176 - :ref:`View ` * - ``bool should_use_mkl(Backendrequested = Backend::AUTO)`` - bool - MKL_CONFIG.H:211 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-mklconfig-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-mklconfig-resolve_backend-1: .. dropdown:: resolve_backend (np_test_1_all.cpp:25374) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 25364 :emphasize-lines: 11 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; // Test should_use_boost bool use_boost = BoostConfig::should_use_boost(Backend::AUTO); // std::cout << "Should use Boost (AUTO): " << (use_boost ? "Yes" : "No") << std::endl; // Verify consistency if (BoostInfo::is_runtime_available()) { .. _example-mklconfig-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 .. _example-mklconfig-should_use_mkl-3: .. dropdown:: should_use_mkl (np_test_3_all.cpp:17749) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17739 :emphasize-lines: 11 return std::abs(a - b) <= (atol + rtol * std::abs(b)); } // ============================ // LEVEL 1 BLAS TESTS // ============================ void np_test_mkl_dot() { std::cout << "========= mkl_dot test ======================="; #ifdef NUMPY_USE_MKL if (!mkl::MKLConfig::should_use_mkl()) { // std::cout << " [SKIP] MKL not available"; return; } // Test 1: Simple dot product with double { NDArray x({ 3 }); x.setElementAt({ 0 }, 1.0); x.setElementAt({ 1 }, 2.0); x.setElementAt({ 2 }, 3.0);