ChebyshevPolynomial =================== .. cpp:class:: numpy::ChebyshevPolynomial numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use ChebyshevPolynomial ChebyshevPolynomial obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``ChebyshevPolynomial(const std::vector&coeffs = {T(0)})`` - NP_SPECIAL_POLYNOMIALS.H:20 - 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:135 - :ref:`View ` * - ``PolynomialPrintOptions get_printoptions()`` - PolynomialPrintOptions - NP_SPECIAL_POLYNOMIALS.H:143 - :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:149 - :ref:`View ` * - ``ChebyshevPolynomial interpolate(const NDArray&y)`` - ChebyshevPolynomial - NP_SPECIAL_POLYNOMIALS.H:104 - * - ``ChebyshevPolynomial of_first_kind(size_tn)`` - ChebyshevPolynomial - NP_SPECIAL_POLYNOMIALS.H:24 - :ref:`View ` * - ``ChebyshevPolynomial of_second_kind(size_tn)`` - ChebyshevPolynomial - NP_SPECIAL_POLYNOMIALS.H:59 - * - ``void set_default_printstyle(const std::string &style)`` - void - NP_SPECIAL_POLYNOMIALS.H:131 - :ref:`View ` * - ``void set_precision(intprecision)`` - void - NP_SPECIAL_POLYNOMIALS.H:139 - * - ``std::string toString_ascii()`` - std::string - NP_SPECIAL_POLYNOMIALS.H:155 - * - ``std::string toString_unicode()`` - std::string - NP_SPECIAL_POLYNOMIALS.H:201 - Code Examples ------------- The following examples are extracted from the test suite. .. _example-chebyshevpolynomial-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-chebyshevpolynomial-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-chebyshevpolynomial-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-chebyshevpolynomial-of_first_kind-3: .. dropdown:: of_first_kind (np_test_1_all.cpp:23076) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23066 :emphasize-lines: 11 // assert(std::abs(linear_roots[0].imag()) < 1e-10); // std::cout << "[OK] Polynomial root finding works correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_chebyshev_polynomials() { std::cout << "========= test_chebyshev_polynomials ======================="; // Test first few Chebyshev polynomials of the first kind auto T0 = numpy::special::ChebyshevPolynomial::of_first_kind(0); if (!((T0.coefficients() == std::vector{1}))) { std::string description = std::string("test_chebyshev_polynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((T0.coefficients() == std::vector{1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } auto T1 = numpy::special::ChebyshevPolynomial::of_first_kind(1); if (!((T1.coefficients() == std::vector{0, 1}))) { std::string description = std::string("test_chebyshev_polynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((T1.coefficients() == std::vector{0, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-chebyshevpolynomial-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")) {