HermitePolynomial#

class numpy::HermitePolynomial#

numpy C++ class.

Example#

#include <numpy/np_ndarray.h>
using namespace numpy;

// Use HermitePolynomial
HermitePolynomial obj;
// ... operations ...

Constructors#

Signature

Location

Example

HermitePolynomial(const std::vector<T>&coeffs = {T(0)})

NP_SPECIAL_POLYNOMIALS.H:435

Indexing / Selection#

Signature

Return Type

Location

Example

std::string get_default_printstyle()

std::string

NP_SPECIAL_POLYNOMIALS.H:539

View

PolynomialPrintOptions get_printoptions()

PolynomialPrintOptions

NP_SPECIAL_POLYNOMIALS.H:547

View

Other Methods#

Signature

Return Type

Location

Example

TargetType convert()

TargetType

NP_SPECIAL_POLYNOMIALS.H:553

View

std::pair<NDArray<T>,NDArray<T>> gauss_quadrature(size_tn)

std::pair<NDArray<T>,NDArray<T>>

NP_SPECIAL_POLYNOMIALS.H:512

HermitePolynomial<T> physicist(size_tn)

HermitePolynomial<T>

NP_SPECIAL_POLYNOMIALS.H:440

View

HermitePolynomial<T> probabilist(size_tn)

HermitePolynomial<T>

NP_SPECIAL_POLYNOMIALS.H:476

View

void set_default_printstyle(const std::string &style)

void

NP_SPECIAL_POLYNOMIALS.H:535

View

void set_precision(intprecision)

void

NP_SPECIAL_POLYNOMIALS.H:543

std::string toString_ascii()

std::string

NP_SPECIAL_POLYNOMIALS.H:559

std::string toString_unicode()

std::string

NP_SPECIAL_POLYNOMIALS.H:600

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");
physicist (np_test_1_all.cpp:23165)
23155    // This is implicit in the construction but we verify some key properties
23156
23157    // std::cout << "[OK] Legendre polynomials work correctly" << std::endl;
23158    std::cout << " -> tests passed" << std::endl;
23159  }
23160
23161  void test_hermite_polynomials() {
23162    std::cout << "========= test_hermite_polynomials =======================";
23163
23164    // Test physicist's Hermite polynomials
23165    auto H0 = numpy::special::HermitePolynomial<double>::physicist(0);
23166    if (!((H0.coefficients() == std::vector<double>{1}))) {
23167        std::string description = std::string("test_hermite_polynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((H0.coefficients() == std::vector<double>{1}))";
23168        std::cout << std::string("[FAIL] ") + description << std::endl;
23169        throw std::runtime_error(description);
23170    }
23171
23172    auto H1 = numpy::special::HermitePolynomial<double>::physicist(1);
23173    if (!((H1.coefficients() == std::vector<double>{0, 2}))) {
23174        std::string description = std::string("test_hermite_polynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((H1.coefficients() == std::vector<double>{0, 2}))";
23175        std::cout << std::string("[FAIL] ") + description << std::endl;
probabilist (np_test_1_all.cpp:23187)
23177    }
23178
23179    auto H2 = numpy::special::HermitePolynomial<double>::physicist(2);
23180    if (!((H2.coefficients() == std::vector<double>{-2, 0, 4}))) {
23181        std::string description = std::string("test_hermite_polynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((H2.coefficients() == std::vector<double>{-2, 0, 4}))";
23182        std::cout << std::string("[FAIL] ") + description << std::endl;
23183        throw std::runtime_error(description);
23184    }
23185
23186    // Test probabilist's Hermite polynomials
23187    auto He0 = numpy::special::HermitePolynomial<double>::probabilist(0);
23188    if (!((He0.coefficients() == std::vector<double>{1}))) {
23189        std::string description = std::string("test_hermite_polynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((He0.coefficients() == std::vector<double>{1}))";
23190        std::cout << std::string("[FAIL] ") + description << std::endl;
23191        throw std::runtime_error(description);
23192    }
23193
23194    auto He1 = numpy::special::HermitePolynomial<double>::probabilist(1);
23195    if (!((He1.coefficients() == std::vector<double>{0, 1}))) {
23196        std::string description = std::string("test_hermite_polynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((He1.coefficients() == std::vector<double>{0, 1}))";
23197        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")) {