LegendrePolynomial ================== .. cpp:class:: numpy::LegendrePolynomial numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use LegendrePolynomial LegendrePolynomial obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``LegendrePolynomial(const std::vector&coeffs = {T(0)})`` - NP_SPECIAL_POLYNOMIALS.H:255 - Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``std::string get_default_printstyle()`` - std::string - NP_SPECIAL_POLYNOMIALS.H:325 - :ref:`View ` * - ``PolynomialPrintOptions get_printoptions()`` - PolynomialPrintOptions - NP_SPECIAL_POLYNOMIALS.H:333 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``TargetType convert()`` - TargetType - NP_SPECIAL_POLYNOMIALS.H:339 - :ref:`View ` * - ``std::pair,NDArray> gauss_quadrature(size_tn)`` - std::pair,NDArray> - NP_SPECIAL_POLYNOMIALS.H:296 - * - ``LegendrePolynomial generate(size_tn)`` - LegendrePolynomial - NP_SPECIAL_POLYNOMIALS.H:259 - :ref:`View ` * - ``void set_default_printstyle(const std::string &style)`` - void - NP_SPECIAL_POLYNOMIALS.H:321 - :ref:`View ` * - ``void set_precision(intprecision)`` - void - NP_SPECIAL_POLYNOMIALS.H:329 - * - ``std::string toString_ascii()`` - std::string - NP_SPECIAL_POLYNOMIALS.H:345 - * - ``std::string toString_unicode()`` - std::string - NP_SPECIAL_POLYNOMIALS.H:386 - Code Examples ------------- The following examples are extracted from the test suite. .. _example-legendrepolynomial-get_default_printstyle-0: .. dropdown:: get_default_printstyle (np_test_5_all.cpp:8998) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8988 :emphasize-lines: 11 // Test 2: Switch to Unicode via static method numpy::Polynomial::set_default_printstyle("unicode"); std::string result2 = p1.toString(); // std::cout << "Static method Unicode: " << result2 << std::endl; if (!verify_contains(result2, "\u00B7", "Static method Unicode")) { throw std::runtime_error("Polynomial::set_default_printstyle('unicode') failed"); } // Test 3: Verify Polynomial::get_default_printstyle() static method std::string current_style = numpy::Polynomial::get_default_printstyle(); // std::cout << "Current style via static method: " << current_style << std::endl; if (current_style != "unicode") { throw std::runtime_error("Polynomial::get_default_printstyle() returned wrong value"); } // Test 4: Verify all polynomial types share the same global print style numpy::Chebyshev::set_default_printstyle("ascii"); numpy::Chebyshev cheb({ 1.0, 2.0 }); .. _example-legendrepolynomial-get_printoptions-1: .. dropdown:: get_printoptions (np_test_2_all.cpp:21259) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21249 :emphasize-lines: 11 namespace numpy_tests_printoptions { // ============================================================================ // BASIC FUNCTIONALITY TESTS // ============================================================================ void np_test_printoptions_basic() { std::cout << "========= printoptions: basic get/set ===="; // Get default options auto default_opts = numpy::get_printoptions(); // Verify defaults if (default_opts.precision != 8) { std::cout << " [FAIL] : in np_test_printoptions_basic() : default precision should be 8, got " << default_opts.precision << std::endl; throw std::runtime_error("np_test_printoptions_basic failed: default precision incorrect"); } if (default_opts.threshold != 1000) { std::cout << " [FAIL] : in np_test_printoptions_basic() : default threshold should be 1000, got " .. _example-legendrepolynomial-convert-2: .. dropdown:: convert (np_test_5_all.cpp:9049) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9039 :emphasize-lines: 11 throw std::runtime_error("Static method and global function don't share state"); } // Reset to default ASCII numpy::set_default_printstyle("ascii"); std::cout << " -> tests passed" << std::endl; } void np_test_toString_polynomial_convert() { std::cout << "========= polynomial.convert(): basis conversion (NumPy API) ======================="; // Test Chebyshev -> Standard conversion (user's example) // NumPy: numpy.polynomial.Chebyshev([1,2,3]).convert(kind=np.polynomial.Polynomial) // Expected: -2.0 + 2.0 x + 6.0 x**2 { numpy::special::ChebyshevPolynomial cheb({ 1.0, 2.0, 3.0 }); auto std_poly = cheb.convert>(); if (std_poly.coefficients().size() != 3) { throw std::runtime_error("Chebyshev conversion: wrong coefficient count"); .. _example-legendrepolynomial-generate-3: .. dropdown:: generate (np_test_1_all.cpp:6129) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6119 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void test_data_generator_randomBenchmarkSorting() { std::cout << "========= test_data_generator_random ======================="; DataGenerator gen(42); // Fixed seed for reproducibility // Test random data generation std::vector data = gen.generate(100, DataPattern::RANDOM); if (!(data.size() == 100)) { std::string description = std::string("test_data_generator_randomBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Check that not all elements are the same (should be random) bool has_variation = false; for (size_t i = 1; i < data.size(); ++i) { .. _example-legendrepolynomial-set_default_printstyle-4: .. dropdown:: set_default_printstyle (np_test_5_all.cpp:8798) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8788 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } // =========================== // Polynomial Tests // =========================== void np_test_toString_polynomial_basic() { std::cout << "========= Polynomial toString() basic ============================"; numpy::set_default_printstyle("ascii"); numpy::set_polynomial_precision(2); numpy::Polynomial p({ 1.0, 2.0, 3.0 }); std::string result = p.toString(); // std::cout << "Polynomial: " << result << std::endl; verify_not_empty(result, "Polynomial toString()"); if (!verify_contains(result, "x", "Polynomial")) {