ChebyshevPolynomial#
-
class numpy::ChebyshevPolynomial#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use ChebyshevPolynomial
ChebyshevPolynomial obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
NP_SPECIAL_POLYNOMIALS.H:20 |
Indexing / Selection#
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
TargetType |
NP_SPECIAL_POLYNOMIALS.H:149 |
|
|
ChebyshevPolynomial<T> |
NP_SPECIAL_POLYNOMIALS.H:104 |
|
|
ChebyshevPolynomial<T> |
NP_SPECIAL_POLYNOMIALS.H:24 |
|
|
ChebyshevPolynomial<T> |
NP_SPECIAL_POLYNOMIALS.H:59 |
|
|
void |
NP_SPECIAL_POLYNOMIALS.H:131 |
|
|
void |
NP_SPECIAL_POLYNOMIALS.H:139 |
|
|
std::string |
NP_SPECIAL_POLYNOMIALS.H:155 |
|
|
std::string |
NP_SPECIAL_POLYNOMIALS.H:201 |
Code Examples#
The following examples are extracted from the test suite.
get_default_printstyle (np_test_5_all.cpp:8998)
8988 // Test 2: Switch to Unicode via static method
8989 numpy::Polynomial<double>::set_default_printstyle("unicode");
8990 std::string result2 = p1.toString();
8991 // std::cout << "Static method Unicode: " << result2 << std::endl;
8992
8993 if (!verify_contains(result2, "\u00B7", "Static method Unicode")) {
8994 throw std::runtime_error("Polynomial<T>::set_default_printstyle('unicode') failed");
8995 }
8996
8997 // Test 3: Verify Polynomial<T>::get_default_printstyle() static method
8998 std::string current_style = numpy::Polynomial<double>::get_default_printstyle();
8999 // std::cout << "Current style via static method: " << current_style << std::endl;
9000
9001 if (current_style != "unicode") {
9002 throw std::runtime_error("Polynomial<T>::get_default_printstyle() returned wrong value");
9003 }
9004
9005 // Test 4: Verify all polynomial types share the same global print style
9006 numpy::Chebyshev<double>::set_default_printstyle("ascii");
9007 numpy::Chebyshev<double> cheb({ 1.0, 2.0 });
get_printoptions (np_test_2_all.cpp:21259)
21249 namespace numpy_tests_printoptions {
21250
21251 // ============================================================================
21252 // BASIC FUNCTIONALITY TESTS
21253 // ============================================================================
21254
21255 void np_test_printoptions_basic() {
21256 std::cout << "========= printoptions: basic get/set ====";
21257
21258 // Get default options
21259 auto default_opts = numpy::get_printoptions();
21260
21261 // Verify defaults
21262 if (default_opts.precision != 8) {
21263 std::cout << " [FAIL] : in np_test_printoptions_basic() : default precision should be 8, got "
21264 << default_opts.precision << std::endl;
21265 throw std::runtime_error("np_test_printoptions_basic failed: default precision incorrect");
21266 }
21267
21268 if (default_opts.threshold != 1000) {
21269 std::cout << " [FAIL] : in np_test_printoptions_basic() : default threshold should be 1000, got "
convert (np_test_5_all.cpp:9049)
9039 throw std::runtime_error("Static method and global function don't share state");
9040 }
9041
9042 // Reset to default ASCII
9043 numpy::set_default_printstyle("ascii");
9044
9045 std::cout << " -> tests passed" << std::endl;
9046 }
9047
9048 void np_test_toString_polynomial_convert() {
9049 std::cout << "========= polynomial.convert(): basis conversion (NumPy API) =======================";
9050
9051 // Test Chebyshev -> Standard conversion (user's example)
9052 // NumPy: numpy.polynomial.Chebyshev([1,2,3]).convert(kind=np.polynomial.Polynomial)
9053 // Expected: -2.0 + 2.0 x + 6.0 x**2
9054 {
9055 numpy::special::ChebyshevPolynomial<double> cheb({ 1.0, 2.0, 3.0 });
9056 auto std_poly = cheb.convert<numpy::Polynomial<double>>();
9057
9058 if (std_poly.coefficients().size() != 3) {
9059 throw std::runtime_error("Chebyshev conversion: wrong coefficient count");
of_first_kind (np_test_1_all.cpp:23076)
23066 // assert(std::abs(linear_roots[0].imag()) < 1e-10);
23067
23068 // std::cout << "[OK] Polynomial root finding works correctly" << std::endl;
23069 std::cout << " -> tests passed" << std::endl;
23070 }
23071
23072 void test_chebyshev_polynomials() {
23073 std::cout << "========= test_chebyshev_polynomials =======================";
23074
23075 // Test first few Chebyshev polynomials of the first kind
23076 auto T0 = numpy::special::ChebyshevPolynomial<double>::of_first_kind(0);
23077 if (!((T0.coefficients() == std::vector<double>{1}))) {
23078 std::string description = std::string("test_chebyshev_polynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((T0.coefficients() == std::vector<double>{1}))";
23079 std::cout << std::string("[FAIL] ") + description << std::endl;
23080 throw std::runtime_error(description);
23081 }
23082
23083 auto T1 = numpy::special::ChebyshevPolynomial<double>::of_first_kind(1);
23084 if (!((T1.coefficients() == std::vector<double>{0, 1}))) {
23085 std::string description = std::string("test_chebyshev_polynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((T1.coefficients() == std::vector<double>{0, 1}))";
23086 std::cout << std::string("[FAIL] ") + description << std::endl;
set_default_printstyle (np_test_5_all.cpp:8798)
8788 std::cout << " -> tests passed" << std::endl;
8789 }
8790
8791 // ===========================
8792 // Polynomial Tests
8793 // ===========================
8794
8795 void np_test_toString_polynomial_basic() {
8796 std::cout << "========= Polynomial toString() basic ============================";
8797
8798 numpy::set_default_printstyle("ascii");
8799 numpy::set_polynomial_precision(2);
8800
8801 numpy::Polynomial<double> p({ 1.0, 2.0, 3.0 });
8802 std::string result = p.toString();
8803
8804 // std::cout << "Polynomial: " << result << std::endl;
8805
8806 verify_not_empty(result, "Polynomial toString()");
8807
8808 if (!verify_contains(result, "x", "Polynomial")) {