Top-Level Functions =================== .. cpp:namespace:: numpy These functions are available directly in the ``numpy`` namespace. .. code-block:: cpp #include using namespace numpy; auto arr = np::zeros({3, 4}); auto result = np::dot(a, b); auto random = np::random::rand({10}); Array Creation -------------- .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``Matrix diag(const std::vector&diagonal)`` - Matrix - NP_MATRIX_FACTORY.H:101 - :ref:`View ` * - ``Matrix diag(const T &value, size_tn)`` - Matrix - NP_MATRIX_FACTORY.H:114 - :ref:`View ` * - ``std::vector> diag_indices(size_tn, size_tndim = 2)`` - std::vector> - NP_INDEXING_DIAGONAL.H:35 - :ref:`View ` * - ``std::vector> diag_indices_from(const NDArray&arr)`` - std::vector> - NP_INDEXING_DIAGONAL.H:139 - :ref:`View ` * - ``CSRMatrix diag_sparse(const std::vector&diagonal)`` - CSRMatrix - NP_SPARSE.H:455 - :ref:`View ` * - ``CharArray empty(const std::vector&shape)`` - CharArray - NP_CHAR.H:59 - :ref:`View ` * - ``Matrix eye(size_tn)`` - Matrix - NP_MATRIX_FACTORY.H:47 - :ref:`View ` * - ``Matrix eye(size_trows, size_tcols)`` - Matrix - NP_MATRIX_FACTORY.H:56 - :ref:`View ` * - ``CSRMatrix eye_sparse(size_tn)`` - CSRMatrix - NP_SPARSE.H:463 - :ref:`View ` * - ``CharArray full(const std::vector&shape, const std::string &fill_value)`` - CharArray - NP_CHAR.H:64 - :ref:`View ` * - ``Matrix full(size_trows, size_tcols, const T &fill_value)`` - Matrix - NP_MATRIX_FACTORY.H:202 - :ref:`View ` * - ``Matrix full(size_tn, const T &fill_value)`` - Matrix - NP_MATRIX_FACTORY.H:216 - :ref:`View ` * - ``Matrix full_like(const Matrix&other, const T &fill_value)`` - Matrix - NP_MATRIX_FACTORY.H:224 - :ref:`View ` * - ``std::vector> meshgrid(const std::vector>&xi, const std::string &indexing = "xy")`` - std::vector> - NP_ARRAY_CREATION_EXTENDED.H:17 - :ref:`View ` * - ``Matrix ones(size_trows, size_tcols)`` - Matrix - NP_MATRIX_FACTORY.H:69 - :ref:`View ` * - ``Matrix ones(size_tn)`` - Matrix - NP_MATRIX_FACTORY.H:77 - :ref:`View ` * - ``Matrix ones_like(const Matrix&other)`` - Matrix - NP_MATRIX_FACTORY.H:232 - :ref:`View ` * - ``std::tuple,NDArray> tril_indices(size_tn, intk = 0, std::optionalm = std::nullopt)`` - std::tuple,NDArray> - NP_INDEXING_TRIANGULAR.H:30 - :ref:`View ` * - ``std::tuple,NDArray> tril_indices_from(const NDArray&arr, intk = 0)`` - std::tuple,NDArray> - NP_INDEXING_TRIANGULAR.H:133 - :ref:`View ` * - ``std::string trim(const std::string &str)`` - std::string - NP_IO_UTILS.H:1009 - :ref:`View ` * - ``std::tuple,NDArray> triu_indices(size_tn, intk = 0, std::optionalm = std::nullopt)`` - std::tuple,NDArray> - NP_INDEXING_TRIANGULAR.H:79 - :ref:`View ` * - ``std::tuple,NDArray> triu_indices_from(const NDArray&arr, intk = 0)`` - std::tuple,NDArray> - NP_INDEXING_TRIANGULAR.H:168 - :ref:`View ` * - ``CharArray zeros(const std::vector&shape)`` - CharArray - NP_CHAR.H:54 - :ref:`View ` * - ``Matrix zeros(size_trows, size_tcols)`` - Matrix - NP_MATRIX_FACTORY.H:85 - :ref:`View ` * - ``Matrix zeros(size_tn)`` - Matrix - NP_MATRIX_FACTORY.H:93 - :ref:`View ` * - ``Matrix zeros_like(const Matrix&other)`` - Matrix - NP_MATRIX_FACTORY.H:240 - :ref:`View ` Shape Manipulation ------------------ .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``auto broadcast(Arrays &...arrays)`` - auto - NP_VECTORIZE_BROADCAST.H:280 - * - ``bool broadcastShapes(const std::vector&shape1, const std::vector&shape2)`` - bool - NP_UTILS.H:95 - * - ``bool broadcastShapesMulti(const std::vector>&shapes)`` - bool - NP_UTILS.H:212 - * - ``auto broadcast_apply(Func &&func, Arrays &...arrays)`` - auto - NP_VECTORIZE_BROADCAST.H:444 - * - ``std::vector> broadcast_arrays(const std::vector>&arrays)`` - std::vector> - NP_BROADCASTING_UTILS.H:65 - :ref:`View ` * - ``auto broadcast_iterator(Arrays &...arrays)`` - auto - NP_VECTORIZE_BROADCAST.H:452 - * - ``void flattenNestedRecursive(const NDArray&arr, std::vector&result)`` - void - NP_NESTED_ARRAY.H:524 - * - ``Matrix reshape(const std::vector&data, size_trows, size_tcols)`` - Matrix - NP_MATRIX_FACTORY.H:280 - :ref:`View ` * - ``CharArray resize_strings(const CharArray&a)`` - CharArray - NP_CHAR.H:325 - Math Operations --------------- .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``int8_t abs(const int8_t &x)`` - int8_t - NP_MATH_UTILS_SQRT.H:4150 - :ref:`View ` * - ``int16_t abs(const int16_t &x)`` - int16_t - NP_MATH_UTILS_SQRT.H:4155 - :ref:`View ` * - ``int32_t abs(const int32_t &x)`` - int32_t - NP_MATH_UTILS_SQRT.H:4160 - :ref:`View ` * - ``int64_t abs(const int64_t &x)`` - int64_t - NP_MATH_UTILS_SQRT.H:4165 - :ref:`View ` * - ``uint8_t abs(const uint8_t &x)`` - uint8_t - NP_MATH_UTILS_SQRT.H:4170 - :ref:`View ` * - ``uint16_t abs(const uint16_t &x)`` - uint16_t - NP_MATH_UTILS_SQRT.H:4175 - :ref:`View ` * - ``uint32_t abs(const uint32_t &x)`` - uint32_t - NP_MATH_UTILS_SQRT.H:4180 - :ref:`View ` * - ``uint64_t abs(const uint64_t &x)`` - uint64_t - NP_MATH_UTILS_SQRT.H:4185 - :ref:`View ` * - ``bool\_ abs(const bool\_ &x)`` - bool\_ - NP_MATH_UTILS_SQRT.H:4190 - :ref:`View ` * - ``float32 abs(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:4195 - :ref:`View ` * - ``double abs(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:4200 - :ref:`View ` * - ``float32 abs(const complex64 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:4205 - :ref:`View ` * - ``float64 abs(const complex128 &x)`` - float64 - NP_MATH_UTILS_SQRT.H:4210 - :ref:`View ` * - ``timedelta64 abs()`` - timedelta64 - NP_TIMEDELTA64.H:264 - :ref:`View ` * - ``auto abs(const NDArray&x)`` - auto - NP_VECTORIZE.H:403 - :ref:`View ` * - ``Matrix absm(const Matrix&matrix)`` - Matrix - NP_MATRIX_SPECIAL.H:393 - * - ``auto -> NDArray, float32, typename std::conditional, float64, typename std::conditional, longdouble, T>::type>::type>::type> absolute(const NDArray&array)`` - auto -> NDArray, float32, typename std::conditional, float64, typename std::conditional, longdouble, T>::type>::type>::type> - NP_COMPLEX_UTILS.H:190 - :ref:`View ` * - ``CharArray add(const CharArray&a, const CharArray&b)`` - CharArray - NP_CHAR.H:72 - :ref:`View ` * - ``CharArray add(const CharArray&a, const std::string &scalar)`` - CharArray - NP_CHAR.H:77 - :ref:`View ` * - ``CharArray add(const CharArray&a, const CharArray&b)`` - CharArray - NP_CHARARRAY.H:17 - :ref:`View ` * - ``CharArray add(const CharArray&a, const CharArray&b)`` - CharArray - NP_CHARARRAY.H:451 - :ref:`View ` * - ``auto add()`` - auto - NP_FROMPYFUNC.H:111 - :ref:`View ` * - ``auto -> detail::promoted_type_t add(const T1 &x, const T2 &y)`` - auto -> detail::promoted_type_t - NP_MATH_UTILS_SQRT.H:6162 - :ref:`View ` * - ``auto -> NDArray> add(const NDArray&x, const NDArray&y)`` - auto -> NDArray> - NP_MATH_UTILS_SQRT.H:6204 - :ref:`View ` * - ``auto add(const NDArray&a, const NDArray&b)`` - auto - NP_VECTORIZE.H:315 - :ref:`View ` * - ``CSRMatrix add(const CSRMatrix&A, const CSRMatrix&B, Talpha = T{1}, Tbeta = T{1})`` - CSRMatrix - NP_MKL_SPARSE.H:545 - :ref:`View ` * - ``CSRMatrix add(const CSRMatrix&A, const CSRMatrix&B, doublealpha, doublebeta)`` - CSRMatrix - NP_MKL_SPARSE.H:549 - :ref:`View ` * - ``CSRMatrix add(const CSRMatrix&A, const CSRMatrix&B, floatalpha, floatbeta)`` - CSRMatrix - NP_MKL_SPARSE.H:598 - :ref:`View ` * - ``void add_arrays_to_writer(NPZWriter &writer, const std::string &name, const NDArray&array)`` - void - NP_NPZ_UTILS.H:589 - :ref:`View ` * - ``void add_arrays_to_writer(NPZWriter &writer, const std::string &name, const NDArray&array, Args &&...args)`` - void - NP_NPZ_UTILS.H:594 - :ref:`View ` * - ``void add_docstring(T &obj, const std::string &docstring)`` - void - NP_INTROSPECTION.H:111 - :ref:`View ` * - ``void add_newdoc(const std::string &place, const std::string &obj, const std::string &doc)`` - void - NP_INTROSPECTION.H:133 - :ref:`View ` * - ``void add_newdoc_ufunc(const std::string &ufunc_name, const std::string &doc)`` - void - NP_INTROSPECTION.H:157 - :ref:`View ` * - ``void add_scaled_row(T \*data, size_tcols, size_ttarget_row, size_tsource_row, Tscalar)`` - void - NP_LINALG_UTILS.H:191 - :ref:`View ` * - ``double arccos(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:335 - :ref:`View ` * - ``double arccos(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:336 - :ref:`View ` * - ``double arccos(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:337 - :ref:`View ` * - ``double arccos(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:338 - :ref:`View ` * - ``double arccos(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:339 - :ref:`View ` * - ``double arccos(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:340 - :ref:`View ` * - ``double arccos(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:341 - :ref:`View ` * - ``double arccos(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:342 - :ref:`View ` * - ``double arccos(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:343 - :ref:`View ` * - ``float32 arccos(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:344 - :ref:`View ` * - ``double arccos(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:345 - :ref:`View ` * - ``complex64 arccos(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:346 - :ref:`View ` * - ``complex128 arccos(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:347 - :ref:`View ` * - ``void arccos_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_TRIGONOMETRIC.H:409 - * - ``double arccosh(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:782 - :ref:`View ` * - ``double arccosh(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:783 - :ref:`View ` * - ``double arccosh(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:784 - :ref:`View ` * - ``double arccosh(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:785 - :ref:`View ` * - ``double arccosh(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:786 - :ref:`View ` * - ``double arccosh(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:787 - :ref:`View ` * - ``double arccosh(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:788 - :ref:`View ` * - ``double arccosh(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:789 - :ref:`View ` * - ``double arccosh(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:790 - :ref:`View ` * - ``float32 arccosh(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:791 - :ref:`View ` * - ``double arccosh(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:792 - :ref:`View ` * - ``complex64 arccosh(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:793 - :ref:`View ` * - ``complex128 arccosh(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:794 - :ref:`View ` * - ``void arccosh_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_TRIGONOMETRIC.H:765 - * - ``double arcsin(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:293 - :ref:`View ` * - ``double arcsin(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:294 - :ref:`View ` * - ``double arcsin(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:295 - :ref:`View ` * - ``double arcsin(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:296 - :ref:`View ` * - ``double arcsin(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:297 - :ref:`View ` * - ``double arcsin(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:298 - :ref:`View ` * - ``double arcsin(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:299 - :ref:`View ` * - ``double arcsin(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:300 - :ref:`View ` * - ``double arcsin(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:301 - :ref:`View ` * - ``float32 arcsin(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:302 - :ref:`View ` * - ``double arcsin(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:303 - :ref:`View ` * - ``complex64 arcsin(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:304 - :ref:`View ` * - ``complex128 arcsin(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:305 - :ref:`View ` * - ``void arcsin_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_TRIGONOMETRIC.H:350 - * - ``double arcsinh(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:746 - :ref:`View ` * - ``double arcsinh(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:747 - :ref:`View ` * - ``double arcsinh(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:748 - :ref:`View ` * - ``double arcsinh(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:749 - :ref:`View ` * - ``double arcsinh(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:750 - :ref:`View ` * - ``double arcsinh(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:751 - :ref:`View ` * - ``double arcsinh(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:752 - :ref:`View ` * - ``double arcsinh(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:753 - :ref:`View ` * - ``double arcsinh(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:754 - :ref:`View ` * - ``float32 arcsinh(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:755 - :ref:`View ` * - ``double arcsinh(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:756 - :ref:`View ` * - ``complex64 arcsinh(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:757 - :ref:`View ` * - ``complex128 arcsinh(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:758 - :ref:`View ` * - ``void arcsinh_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_TRIGONOMETRIC.H:706 - * - ``double arctan(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:377 - :ref:`View ` * - ``double arctan(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:378 - :ref:`View ` * - ``double arctan(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:379 - :ref:`View ` * - ``double arctan(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:380 - :ref:`View ` * - ``double arctan(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:381 - :ref:`View ` * - ``double arctan(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:382 - :ref:`View ` * - ``double arctan(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:383 - :ref:`View ` * - ``double arctan(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:384 - :ref:`View ` * - ``double arctan(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:385 - :ref:`View ` * - ``float32 arctan(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:386 - :ref:`View ` * - ``double arctan(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:387 - :ref:`View ` * - ``complex64 arctan(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:388 - :ref:`View ` * - ``complex128 arctan(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:389 - :ref:`View ` * - ``arctan2_promoted_t arctan2(const T &y, const T &x)`` - arctan2_promoted_t - NP_MATH_UTILS_SQRT.H:4846 - :ref:`View ` * - ``NDArray> arctan2(const NDArray&y, const NDArray&x)`` - NDArray> - NP_MATH_UTILS_SQRT.H:4853 - :ref:`View ` * - ``NDArray> arctan2(const T &y, const NDArray&x)`` - NDArray> - NP_MATH_UTILS_SQRT.H:4873 - :ref:`View ` * - ``NDArray> arctan2(const NDArray&y, const T &x)`` - NDArray> - NP_MATH_UTILS_SQRT.H:4886 - :ref:`View ` * - ``void arctan_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_TRIGONOMETRIC.H:468 - * - ``double arctanh(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:818 - :ref:`View ` * - ``double arctanh(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:819 - :ref:`View ` * - ``double arctanh(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:820 - :ref:`View ` * - ``double arctanh(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:821 - :ref:`View ` * - ``double arctanh(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:822 - :ref:`View ` * - ``double arctanh(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:823 - :ref:`View ` * - ``double arctanh(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:824 - :ref:`View ` * - ``double arctanh(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:825 - :ref:`View ` * - ``double arctanh(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:826 - :ref:`View ` * - ``float32 arctanh(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:827 - :ref:`View ` * - ``double arctanh(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:828 - :ref:`View ` * - ``complex64 arctanh(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:829 - :ref:`View ` * - ``complex128 arctanh(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:830 - :ref:`View ` * - ``void arctanh_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_TRIGONOMETRIC.H:824 - * - ``double cbrt(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:78 - :ref:`View ` * - ``double cbrt(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:79 - :ref:`View ` * - ``double cbrt(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:80 - :ref:`View ` * - ``double cbrt(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:81 - :ref:`View ` * - ``double cbrt(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:82 - :ref:`View ` * - ``double cbrt(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:83 - :ref:`View ` * - ``double cbrt(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:84 - :ref:`View ` * - ``double cbrt(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:85 - :ref:`View ` * - ``double cbrt(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:86 - :ref:`View ` * - ``float32 cbrt(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:87 - :ref:`View ` * - ``double cbrt(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:88 - :ref:`View ` * - ``complex64 cbrt(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:89 - :ref:`View ` * - ``complex128 cbrt(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:90 - :ref:`View ` * - ``void cbrt_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:1474 - * - ``float32 ceil(const int8_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1014 - :ref:`View ` * - ``float32 ceil(const int16_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1015 - :ref:`View ` * - ``double ceil(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1016 - :ref:`View ` * - ``double ceil(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1017 - :ref:`View ` * - ``float32 ceil(const uint8_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1018 - :ref:`View ` * - ``float32 ceil(const uint16_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1019 - :ref:`View ` * - ``double ceil(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1020 - :ref:`View ` * - ``double ceil(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1021 - :ref:`View ` * - ``float32 ceil(const bool\_ &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1022 - :ref:`View ` * - ``float32 ceil(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1024 - :ref:`View ` * - ``double ceil(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:1025 - :ref:`View ` * - ``datetime64 ceilToDay(const datetime64 &dt)`` - datetime64 - NP_DATETIME_UTILS.H:376 - :ref:`View ` * - ``void ceil_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:1756 - * - ``double cos(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:211 - :ref:`View ` * - ``double cos(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:212 - :ref:`View ` * - ``double cos(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:213 - :ref:`View ` * - ``double cos(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:214 - :ref:`View ` * - ``double cos(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:215 - :ref:`View ` * - ``double cos(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:216 - :ref:`View ` * - ``double cos(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:217 - :ref:`View ` * - ``double cos(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:218 - :ref:`View ` * - ``double cos(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:219 - :ref:`View ` * - ``float32 cos(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:220 - :ref:`View ` * - ``double cos(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:221 - :ref:`View ` * - ``complex64 cos(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:222 - :ref:`View ` * - ``complex128 cos(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:223 - :ref:`View ` * - ``auto cos(const NDArray&x)`` - auto - NP_VECTORIZE.H:359 - :ref:`View ` * - ``auto cos(const NDArray&x, MathBackendbackend)`` - auto - NP_VECTORIZE.H:365 - :ref:`View ` * - ``void cos_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_TRIGONOMETRIC.H:62 - :ref:`View ` * - ``void cos_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:227 - * - ``void cos_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:2215 - * - ``double cosh(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:674 - :ref:`View ` * - ``double cosh(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:675 - :ref:`View ` * - ``double cosh(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:676 - :ref:`View ` * - ``double cosh(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:677 - :ref:`View ` * - ``double cosh(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:678 - :ref:`View ` * - ``double cosh(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:679 - :ref:`View ` * - ``double cosh(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:680 - :ref:`View ` * - ``double cosh(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:681 - :ref:`View ` * - ``double cosh(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:682 - :ref:`View ` * - ``float32 cosh(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:683 - :ref:`View ` * - ``double cosh(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:684 - :ref:`View ` * - ``complex64 cosh(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:685 - :ref:`View ` * - ``complex128 cosh(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:686 - :ref:`View ` * - ``void cosh_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_TRIGONOMETRIC.H:587 - * - ``void cosh_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:521 - * - ``Matrix coshm(const Matrix&matrix)`` - Matrix - NP_MATRIX_SPECIAL.H:307 - * - ``Matrix cosm(const Matrix&matrix)`` - Matrix - NP_MATRIX_SPECIAL.H:235 - :ref:`View ` * - ``typename std::enable_if_t,T> cospi(Tx)`` - typename std::enable_if_t,T> - NP_MATH_EXTENDED.H:106 - :ref:`View ` * - ``typename std::enable_if_t,NDArray> cospi(const NDArray&x)`` - typename std::enable_if_t,NDArray> - NP_MATH_EXTENDED.H:124 - :ref:`View ` * - ``double deg2rad(int8_tx)`` - double - NP_MATH_UTILS_SQRT.H:5199 - :ref:`View ` * - ``double deg2rad(int16_tx)`` - double - NP_MATH_UTILS_SQRT.H:5200 - :ref:`View ` * - ``double deg2rad(int32_tx)`` - double - NP_MATH_UTILS_SQRT.H:5201 - :ref:`View ` * - ``double deg2rad(int64_tx)`` - double - NP_MATH_UTILS_SQRT.H:5202 - :ref:`View ` * - ``double deg2rad(uint8_tx)`` - double - NP_MATH_UTILS_SQRT.H:5203 - :ref:`View ` * - ``double deg2rad(uint16_tx)`` - double - NP_MATH_UTILS_SQRT.H:5204 - :ref:`View ` * - ``double deg2rad(uint32_tx)`` - double - NP_MATH_UTILS_SQRT.H:5205 - :ref:`View ` * - ``double deg2rad(uint64_tx)`` - double - NP_MATH_UTILS_SQRT.H:5206 - :ref:`View ` * - ``double deg2rad(boolx)`` - double - NP_MATH_UTILS_SQRT.H:5209 - :ref:`View ` * - ``float deg2rad(floatx)`` - float - NP_MATH_UTILS_SQRT.H:5212 - :ref:`View ` * - ``double deg2rad(doublex)`` - double - NP_MATH_UTILS_SQRT.H:5213 - :ref:`View ` * - ``complex64 deg2rad(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:5216 - :ref:`View ` * - ``complex128 deg2rad(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:5220 - :ref:`View ` * - ``double degrees(int8_tx)`` - double - NP_MATH_UTILS_SQRT.H:5408 - :ref:`View ` * - ``double degrees(int16_tx)`` - double - NP_MATH_UTILS_SQRT.H:5409 - :ref:`View ` * - ``double degrees(int32_tx)`` - double - NP_MATH_UTILS_SQRT.H:5410 - :ref:`View ` * - ``double degrees(int64_tx)`` - double - NP_MATH_UTILS_SQRT.H:5411 - :ref:`View ` * - ``double degrees(uint8_tx)`` - double - NP_MATH_UTILS_SQRT.H:5412 - :ref:`View ` * - ``double degrees(uint16_tx)`` - double - NP_MATH_UTILS_SQRT.H:5413 - :ref:`View ` * - ``double degrees(uint32_tx)`` - double - NP_MATH_UTILS_SQRT.H:5414 - :ref:`View ` * - ``double degrees(uint64_tx)`` - double - NP_MATH_UTILS_SQRT.H:5415 - :ref:`View ` * - ``double degrees(boolx)`` - double - NP_MATH_UTILS_SQRT.H:5418 - :ref:`View ` * - ``float degrees(floatx)`` - float - NP_MATH_UTILS_SQRT.H:5421 - :ref:`View ` * - ``double degrees(doublex)`` - double - NP_MATH_UTILS_SQRT.H:5422 - :ref:`View ` * - ``complex64 degrees(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:5425 - :ref:`View ` * - ``complex128 degrees(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:5426 - :ref:`View ` * - ``auto -> detail::promoted_type_t divide(const T1 &x, const T2 &y)`` - auto -> detail::promoted_type_t - NP_MATH_UTILS_SQRT.H:6195 - :ref:`View ` * - ``auto -> NDArray> divide(const NDArray&x, const NDArray&y)`` - auto -> NDArray> - NP_MATH_UTILS_SQRT.H:6291 - :ref:`View ` * - ``Matrix divide(const Matrix&a, const Matrix&b)`` - Matrix - NP_MATRIX_OPS.H:50 - :ref:`View ` * - ``auto divide(const NDArray&a, const NDArray&b)`` - auto - NP_VECTORIZE.H:333 - :ref:`View ` * - ``DivideConquerResult divide_conquer_symmetric_tridiagonal(const std::vector::type>&diagonal, const std::vector::type>&subdiagonal, boolcompute_eigenvectors = true)`` - DivideConquerResult - NP_LINALG_UTILS.H:1880 - * - ``double exp(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:408 - :ref:`View ` * - ``double exp(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:409 - :ref:`View ` * - ``double exp(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:410 - :ref:`View ` * - ``double exp(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:411 - :ref:`View ` * - ``double exp(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:412 - :ref:`View ` * - ``double exp(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:413 - :ref:`View ` * - ``double exp(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:414 - :ref:`View ` * - ``double exp(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:415 - :ref:`View ` * - ``double exp(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:416 - :ref:`View ` * - ``float32 exp(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:417 - :ref:`View ` * - ``double exp(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:418 - :ref:`View ` * - ``complex64 exp(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:419 - :ref:`View ` * - ``complex128 exp(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:420 - :ref:`View ` * - ``auto exp(const NDArray&x)`` - auto - NP_VECTORIZE.H:385 - :ref:`View ` * - ``T exp1(Tx)`` - T - NP_EXPONENTIAL_INTEGRALS.H:10 - :ref:`View ` * - ``T exp1(Tx)`` - T - NP_EXPONENTIAL_INTEGRALS.H:59 - :ref:`View ` * - ``double exp2(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:439 - :ref:`View ` * - ``double exp2(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:440 - :ref:`View ` * - ``double exp2(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:441 - :ref:`View ` * - ``double exp2(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:442 - :ref:`View ` * - ``double exp2(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:443 - :ref:`View ` * - ``double exp2(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:444 - :ref:`View ` * - ``double exp2(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:445 - :ref:`View ` * - ``double exp2(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:446 - :ref:`View ` * - ``double exp2(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:447 - :ref:`View ` * - ``float32 exp2(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:448 - :ref:`View ` * - ``double exp2(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:449 - :ref:`View ` * - ``complex64 exp2(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:450 - :ref:`View ` * - ``complex128 exp2(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:451 - :ref:`View ` * - ``NDArray> exp_complex_mkl(const NDArray>&input)`` - NDArray> - NP_MKL_SPECIAL_COMPLEX.H:251 - :ref:`View ` * - ``NDArray> exp_complex_mkl(const NDArray>&input)`` - NDArray> - NP_MKL_SPECIAL_COMPLEX.H:440 - :ref:`View ` * - ``void exp_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_EXPONENTIAL.H:60 - :ref:`View ` * - ``void exp_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:918 - * - ``CharArray expandtabs(const CharArray&a, size_ttabsize = 8)`` - CharArray - NP_CHAR.H:279 - :ref:`View ` * - ``CharArray expandtabs(const CharArray&a, size_ttabsize = 8)`` - CharArray - NP_CHAR_OPS.H:297 - :ref:`View ` * - ``T expi(Tx)`` - T - NP_EXPONENTIAL_INTEGRALS.H:15 - :ref:`View ` * - ``Matrix expm(const Matrix&matrix)`` - Matrix - NP_MATRIX_SPECIAL.H:23 - :ref:`View ` * - ``double expm1(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:596 - :ref:`View ` * - ``double expm1(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:597 - :ref:`View ` * - ``double expm1(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:598 - :ref:`View ` * - ``double expm1(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:599 - :ref:`View ` * - ``double expm1(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:600 - :ref:`View ` * - ``double expm1(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:601 - :ref:`View ` * - ``double expm1(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:602 - :ref:`View ` * - ``double expm1(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:603 - :ref:`View ` * - ``double expm1(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:604 - :ref:`View ` * - ``float32 expm1(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:605 - :ref:`View ` * - ``double expm1(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:606 - :ref:`View ` * - ``complex64 expm1(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:608 - :ref:`View ` * - ``complex128 expm1(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:609 - :ref:`View ` * - ``void expm1_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_EXPONENTIAL.H:113 - * - ``void expm1_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:959 - * - ``T expn(intn, Tx)`` - T - NP_EXPONENTIAL_INTEGRALS.H:99 - * - ``float32 fix(const int8_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1109 - :ref:`View ` * - ``float32 fix(const int16_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1110 - :ref:`View ` * - ``double fix(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1111 - :ref:`View ` * - ``double fix(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1112 - :ref:`View ` * - ``float32 fix(const uint8_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1113 - :ref:`View ` * - ``float32 fix(const uint16_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1114 - :ref:`View ` * - ``double fix(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1115 - :ref:`View ` * - ``double fix(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1116 - :ref:`View ` * - ``float32 fix(const bool\_ &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1117 - :ref:`View ` * - ``float32 fix(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1118 - :ref:`View ` * - ``double fix(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:1119 - :ref:`View ` * - ``auto fix(const NDArray&array)`` - auto - NP_MATH_UTILS_SQRT.H:1122 - :ref:`View ` * - ``float32 floor(const int8_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:968 - :ref:`View ` * - ``float32 floor(const int16_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:969 - :ref:`View ` * - ``double floor(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:970 - :ref:`View ` * - ``double floor(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:971 - :ref:`View ` * - ``float32 floor(const uint8_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:972 - :ref:`View ` * - ``float32 floor(const uint16_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:973 - :ref:`View ` * - ``double floor(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:974 - :ref:`View ` * - ``double floor(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:975 - :ref:`View ` * - ``float32 floor(const bool\_ &x)`` - float32 - NP_MATH_UTILS_SQRT.H:976 - :ref:`View ` * - ``float32 floor(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:978 - :ref:`View ` * - ``double floor(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:979 - :ref:`View ` * - ``datetime64 floorToDay(const datetime64 &dt)`` - datetime64 - NP_DATETIME_UTILS.H:360 - :ref:`View ` * - ``int8_t floor_divide(const int8_t &a, const int8_t &b)`` - int8_t - NP_MATH_UTILS_SQRT.H:1518 - :ref:`View ` * - ``int16_t floor_divide(const int16_t &a, const int16_t &b)`` - int16_t - NP_MATH_UTILS_SQRT.H:1519 - :ref:`View ` * - ``int32_t floor_divide(const int32_t &a, const int32_t &b)`` - int32_t - NP_MATH_UTILS_SQRT.H:1520 - :ref:`View ` * - ``int64_t floor_divide(const int64_t &a, const int64_t &b)`` - int64_t - NP_MATH_UTILS_SQRT.H:1521 - :ref:`View ` * - ``uint8_t floor_divide(const uint8_t &a, const uint8_t &b)`` - uint8_t - NP_MATH_UTILS_SQRT.H:1522 - :ref:`View ` * - ``uint16_t floor_divide(const uint16_t &a, const uint16_t &b)`` - uint16_t - NP_MATH_UTILS_SQRT.H:1523 - :ref:`View ` * - ``uint32_t floor_divide(const uint32_t &a, const uint32_t &b)`` - uint32_t - NP_MATH_UTILS_SQRT.H:1524 - :ref:`View ` * - ``uint64_t floor_divide(const uint64_t &a, const uint64_t &b)`` - uint64_t - NP_MATH_UTILS_SQRT.H:1525 - :ref:`View ` * - ``int8_t floor_divide(const bool\_ &a, const bool\_ &b)`` - int8_t - NP_MATH_UTILS_SQRT.H:1526 - :ref:`View ` * - ``float32 floor_divide(const float32 &a, const float32 &b)`` - float32 - NP_MATH_UTILS_SQRT.H:1527 - :ref:`View ` * - ``double floor_divide(const double &a, const double &b)`` - double - NP_MATH_UTILS_SQRT.H:1528 - :ref:`View ` * - ``float32 floor_divide(const int8_t &a, const float32 &b)`` - float32 - NP_MATH_UTILS_SQRT.H:1532 - :ref:`View ` * - ``float32 floor_divide(const int16_t &a, const float32 &b)`` - float32 - NP_MATH_UTILS_SQRT.H:1533 - :ref:`View ` * - ``double floor_divide(const int32_t &a, const float32 &b)`` - double - NP_MATH_UTILS_SQRT.H:1535 - :ref:`View ` * - ``double floor_divide(const int64_t &a, const float32 &b)`` - double - NP_MATH_UTILS_SQRT.H:1536 - :ref:`View ` * - ``double floor_divide(const int8_t &a, const double &b)`` - double - NP_MATH_UTILS_SQRT.H:1538 - :ref:`View ` * - ``double floor_divide(const int16_t &a, const double &b)`` - double - NP_MATH_UTILS_SQRT.H:1539 - :ref:`View ` * - ``double floor_divide(const int32_t &a, const double &b)`` - double - NP_MATH_UTILS_SQRT.H:1540 - :ref:`View ` * - ``double floor_divide(const int64_t &a, const double &b)`` - double - NP_MATH_UTILS_SQRT.H:1541 - :ref:`View ` * - ``float32 floor_divide(const float32 &a, const int8_t &b)`` - float32 - NP_MATH_UTILS_SQRT.H:1545 - :ref:`View ` * - ``float32 floor_divide(const float32 &a, const int16_t &b)`` - float32 - NP_MATH_UTILS_SQRT.H:1546 - :ref:`View ` * - ``double floor_divide(const float32 &a, const int32_t &b)`` - double - NP_MATH_UTILS_SQRT.H:1548 - :ref:`View ` * - ``double floor_divide(const float32 &a, const int64_t &b)`` - double - NP_MATH_UTILS_SQRT.H:1549 - :ref:`View ` * - ``double floor_divide(const double &a, const int8_t &b)`` - double - NP_MATH_UTILS_SQRT.H:1551 - :ref:`View ` * - ``double floor_divide(const double &a, const int16_t &b)`` - double - NP_MATH_UTILS_SQRT.H:1552 - :ref:`View ` * - ``double floor_divide(const double &a, const int32_t &b)`` - double - NP_MATH_UTILS_SQRT.H:1553 - :ref:`View ` * - ``double floor_divide(const double &a, const int64_t &b)`` - double - NP_MATH_UTILS_SQRT.H:1554 - :ref:`View ` * - ``double floor_divide(const float32 &a, const double &b)`` - double - NP_MATH_UTILS_SQRT.H:1557 - :ref:`View ` * - ``double floor_divide(const double &a, const float32 &b)`` - double - NP_MATH_UTILS_SQRT.H:1558 - :ref:`View ` * - ``int16_t floor_divide(const int8_t &a, const int16_t &b)`` - int16_t - NP_MATH_UTILS_SQRT.H:1562 - :ref:`View ` * - ``int32_t floor_divide(const int8_t &a, const int32_t &b)`` - int32_t - NP_MATH_UTILS_SQRT.H:1563 - :ref:`View ` * - ``int64_t floor_divide(const int8_t &a, const int64_t &b)`` - int64_t - NP_MATH_UTILS_SQRT.H:1564 - :ref:`View ` * - ``int16_t floor_divide(const int16_t &a, const int8_t &b)`` - int16_t - NP_MATH_UTILS_SQRT.H:1566 - :ref:`View ` * - ``int32_t floor_divide(const int16_t &a, const int32_t &b)`` - int32_t - NP_MATH_UTILS_SQRT.H:1567 - :ref:`View ` * - ``int64_t floor_divide(const int16_t &a, const int64_t &b)`` - int64_t - NP_MATH_UTILS_SQRT.H:1568 - :ref:`View ` * - ``int32_t floor_divide(const int32_t &a, const int8_t &b)`` - int32_t - NP_MATH_UTILS_SQRT.H:1570 - :ref:`View ` * - ``int32_t floor_divide(const int32_t &a, const int16_t &b)`` - int32_t - NP_MATH_UTILS_SQRT.H:1571 - :ref:`View ` * - ``int64_t floor_divide(const int32_t &a, const int64_t &b)`` - int64_t - NP_MATH_UTILS_SQRT.H:1572 - :ref:`View ` * - ``int64_t floor_divide(const int64_t &a, const int8_t &b)`` - int64_t - NP_MATH_UTILS_SQRT.H:1574 - :ref:`View ` * - ``int64_t floor_divide(const int64_t &a, const int16_t &b)`` - int64_t - NP_MATH_UTILS_SQRT.H:1575 - :ref:`View ` * - ``int64_t floor_divide(const int64_t &a, const int32_t &b)`` - int64_t - NP_MATH_UTILS_SQRT.H:1576 - :ref:`View ` * - ``uint16_t floor_divide(const uint8_t &a, const uint16_t &b)`` - uint16_t - NP_MATH_UTILS_SQRT.H:1579 - :ref:`View ` * - ``uint32_t floor_divide(const uint8_t &a, const uint32_t &b)`` - uint32_t - NP_MATH_UTILS_SQRT.H:1580 - :ref:`View ` * - ``uint64_t floor_divide(const uint8_t &a, const uint64_t &b)`` - uint64_t - NP_MATH_UTILS_SQRT.H:1581 - :ref:`View ` * - ``uint16_t floor_divide(const uint16_t &a, const uint8_t &b)`` - uint16_t - NP_MATH_UTILS_SQRT.H:1583 - :ref:`View ` * - ``uint32_t floor_divide(const uint16_t &a, const uint32_t &b)`` - uint32_t - NP_MATH_UTILS_SQRT.H:1584 - :ref:`View ` * - ``uint64_t floor_divide(const uint16_t &a, const uint64_t &b)`` - uint64_t - NP_MATH_UTILS_SQRT.H:1585 - :ref:`View ` * - ``uint32_t floor_divide(const uint32_t &a, const uint8_t &b)`` - uint32_t - NP_MATH_UTILS_SQRT.H:1587 - :ref:`View ` * - ``uint32_t floor_divide(const uint32_t &a, const uint16_t &b)`` - uint32_t - NP_MATH_UTILS_SQRT.H:1588 - :ref:`View ` * - ``uint64_t floor_divide(const uint32_t &a, const uint64_t &b)`` - uint64_t - NP_MATH_UTILS_SQRT.H:1589 - :ref:`View ` * - ``uint64_t floor_divide(const uint64_t &a, const uint8_t &b)`` - uint64_t - NP_MATH_UTILS_SQRT.H:1591 - :ref:`View ` * - ``uint64_t floor_divide(const uint64_t &a, const uint16_t &b)`` - uint64_t - NP_MATH_UTILS_SQRT.H:1592 - :ref:`View ` * - ``uint64_t floor_divide(const uint64_t &a, const uint32_t &b)`` - uint64_t - NP_MATH_UTILS_SQRT.H:1593 - :ref:`View ` * - ``int16_t floor_divide(const int8_t &a, const uint8_t &b)`` - int16_t - NP_MATH_UTILS_SQRT.H:1597 - :ref:`View ` * - ``int16_t floor_divide(const uint8_t &a, const int8_t &b)`` - int16_t - NP_MATH_UTILS_SQRT.H:1598 - :ref:`View ` * - ``int32_t floor_divide(const int16_t &a, const uint16_t &b)`` - int32_t - NP_MATH_UTILS_SQRT.H:1599 - :ref:`View ` * - ``int32_t floor_divide(const uint16_t &a, const int16_t &b)`` - int32_t - NP_MATH_UTILS_SQRT.H:1600 - :ref:`View ` * - ``int64_t floor_divide(const int32_t &a, const uint32_t &b)`` - int64_t - NP_MATH_UTILS_SQRT.H:1601 - :ref:`View ` * - ``int64_t floor_divide(const uint32_t &a, const int32_t &b)`` - int64_t - NP_MATH_UTILS_SQRT.H:1602 - :ref:`View ` * - ``double floor_divide(const int64_t &a, const uint64_t &b)`` - double - NP_MATH_UTILS_SQRT.H:1603 - :ref:`View ` * - ``double floor_divide(const uint64_t &a, const int64_t &b)`` - double - NP_MATH_UTILS_SQRT.H:1604 - :ref:`View ` * - ``int32_t floor_divide(const bool\_ &a, const int32_t &b)`` - int32_t - NP_MATH_UTILS_SQRT.H:1607 - :ref:`View ` * - ``int32_t floor_divide(const int32_t &a, const bool\_ &b)`` - int32_t - NP_MATH_UTILS_SQRT.H:1608 - :ref:`View ` * - ``float32 floor_divide(const bool\_ &a, const float32 &b)`` - float32 - NP_MATH_UTILS_SQRT.H:1609 - :ref:`View ` * - ``float32 floor_divide(const float32 &a, const bool\_ &b)`` - float32 - NP_MATH_UTILS_SQRT.H:1610 - :ref:`View ` * - ``auto -> std::enable_if_t\|\| std::is_same_v, NDArray()))>> floor_divide(const TDividend ÷nd_scalar, const NDArray&divisor_array)`` - auto -> std::enable_if_t\|\| std::is_same_v, NDArray()))>> - NP_MATH_UTILS_SQRT.H:1616 - :ref:`View ` * - ``auto -> NDArray(), std::declval()))> floor_divide(const NDArray÷nd_array, const NDArray&divisor_array)`` - auto -> NDArray(), std::declval()))> - NP_MATH_UTILS_SQRT.H:1645 - :ref:`View ` * - ``T floor_divide_impl(const T ÷nd, const T &divisor)`` - T - NP_MATH_UTILS_SQRT.H:1498 - * - ``void floor_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:1797 - * - ``typename std::enable_if_t,T> hypot(Tx1, Tx2)`` - typename std::enable_if_t,T> - NP_MATH_EXTENDED.H:209 - :ref:`View ` * - ``typename std::enable_if_t,NDArray> hypot(const NDArray&x1, const NDArray&x2)`` - typename std::enable_if_t,NDArray> - NP_MATH_EXTENDED.H:216 - :ref:`View ` * - ``typename std::enable_if_t,NDArray> hypot(Tx1, const NDArray&x2)`` - typename std::enable_if_t,NDArray> - NP_MATH_EXTENDED.H:225 - :ref:`View ` * - ``typename std::enable_if_t,NDArray> hypot(const NDArray&x1, Tx2)`` - typename std::enable_if_t,NDArray> - NP_MATH_EXTENDED.H:234 - :ref:`View ` * - ``T hypot_safe(Ta, Tb)`` - T - NP_LINALG_UTILS.H:119 - :ref:`View ` * - ``double log(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:470 - :ref:`View ` * - ``double log(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:471 - :ref:`View ` * - ``double log(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:472 - :ref:`View ` * - ``double log(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:473 - :ref:`View ` * - ``double log(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:474 - :ref:`View ` * - ``double log(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:475 - :ref:`View ` * - ``double log(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:476 - :ref:`View ` * - ``double log(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:477 - :ref:`View ` * - ``double log(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:478 - :ref:`View ` * - ``float32 log(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:479 - :ref:`View ` * - ``double log(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:480 - :ref:`View ` * - ``complex64 log(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:481 - :ref:`View ` * - ``complex128 log(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:482 - :ref:`View ` * - ``auto log(const NDArray&x)`` - auto - NP_VECTORIZE.H:391 - :ref:`View ` * - ``double log10(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:532 - :ref:`View ` * - ``double log10(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:533 - :ref:`View ` * - ``double log10(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:534 - :ref:`View ` * - ``double log10(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:535 - :ref:`View ` * - ``double log10(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:536 - :ref:`View ` * - ``double log10(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:537 - :ref:`View ` * - ``double log10(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:538 - :ref:`View ` * - ``double log10(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:539 - :ref:`View ` * - ``double log10(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:540 - :ref:`View ` * - ``float32 log10(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:541 - :ref:`View ` * - ``double log10(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:542 - :ref:`View ` * - ``complex64 log10(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:543 - :ref:`View ` * - ``complex128 log10(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:544 - :ref:`View ` * - ``void log10_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_EXPONENTIAL.H:241 - * - ``void log10_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:1042 - * - ``double log1p(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:564 - :ref:`View ` * - ``double log1p(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:565 - :ref:`View ` * - ``double log1p(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:566 - :ref:`View ` * - ``double log1p(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:567 - :ref:`View ` * - ``double log1p(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:568 - :ref:`View ` * - ``double log1p(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:569 - :ref:`View ` * - ``double log1p(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:570 - :ref:`View ` * - ``double log1p(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:571 - :ref:`View ` * - ``double log1p(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:572 - :ref:`View ` * - ``float32 log1p(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:573 - :ref:`View ` * - ``double log1p(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:574 - :ref:`View ` * - ``complex64 log1p(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:576 - :ref:`View ` * - ``complex128 log1p(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:577 - :ref:`View ` * - ``void log1p_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_EXPONENTIAL.H:294 - * - ``void log1p_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:1083 - * - ``double log2(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:501 - :ref:`View ` * - ``double log2(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:502 - :ref:`View ` * - ``double log2(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:503 - :ref:`View ` * - ``double log2(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:504 - :ref:`View ` * - ``double log2(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:505 - :ref:`View ` * - ``double log2(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:506 - :ref:`View ` * - ``double log2(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:507 - :ref:`View ` * - ``double log2(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:508 - :ref:`View ` * - ``double log2(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:509 - :ref:`View ` * - ``float32 log2(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:510 - :ref:`View ` * - ``double log2(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:511 - :ref:`View ` * - ``complex64 log2(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:512 - :ref:`View ` * - ``complex128 log2(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:513 - :ref:`View ` * - ``size_t log2_floor(size_tn)`` - size_t - NP_SORTING_ALGORITHMS.H:213 - * - ``NDArray> log_complex_mkl(const NDArray>&input)`` - NDArray> - NP_MKL_SPECIAL_COMPLEX.H:277 - :ref:`View ` * - ``NDArray> log_complex_mkl(const NDArray>&input)`` - NDArray> - NP_MKL_SPECIAL_COMPLEX.H:445 - :ref:`View ` * - ``void log_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_EXPONENTIAL.H:178 - :ref:`View ` * - ``void log_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:1001 - * - ``T log_ndtr(Tx)`` - T - NP_STATISTICAL.H:233 - * - ``T log_ndtr_fallback(Tx)`` - T - NP_STATISTICAL.H:19 - * - ``T log_ndtr_fallback(Tx)`` - T - NP_STATISTICAL.H:215 - * - ``T logaddexp(Tx1, Tx2)`` - T - NP_MATH_UTILS_SQRT.H:7141 - :ref:`View ` * - ``T logaddexp2(Tx1, Tx2)`` - T - NP_MATH_UTILS_SQRT.H:7183 - :ref:`View ` * - ``auto logical_and()`` - auto - NP_FROMPYFUNC.H:125 - :ref:`View ` * - ``auto logical_and(const NDArray&a, const NDArray&b)`` - auto - NP_VECTORIZE.H:451 - :ref:`View ` * - ``auto logical_not(const NDArray&x)`` - auto - NP_VECTORIZE.H:495 - :ref:`View ` * - ``auto logical_or()`` - auto - NP_FROMPYFUNC.H:132 - :ref:`View ` * - ``auto logical_or(const NDArray&a, const NDArray&b)`` - auto - NP_VECTORIZE.H:473 - :ref:`View ` * - ``Matrix logm(const Matrix&matrix)`` - Matrix - NP_MATRIX_SPECIAL.H:72 - * - ``CharArray mod(const CharArray&a, const std::vector&values)`` - CharArray - NP_CHAR.H:87 - :ref:`View ` * - ``CharArray mod(const CharArray&a, const std::vector&values)`` - CharArray - NP_CHAR_OPS.H:23 - :ref:`View ` * - ``int8_t mod(const int8_t &x, const int8_t &y)`` - int8_t - NP_MATH_UTILS_SQRT.H:2272 - :ref:`View ` * - ``int16_t mod(const int16_t &x, const int16_t &y)`` - int16_t - NP_MATH_UTILS_SQRT.H:2281 - :ref:`View ` * - ``int32_t mod(const int32_t &x, const int32_t &y)`` - int32_t - NP_MATH_UTILS_SQRT.H:2290 - :ref:`View ` * - ``int64_t mod(const int64_t &x, const int64_t &y)`` - int64_t - NP_MATH_UTILS_SQRT.H:2299 - :ref:`View ` * - ``uint8_t mod(const uint8_t &x, const uint8_t &y)`` - uint8_t - NP_MATH_UTILS_SQRT.H:2308 - :ref:`View ` * - ``uint16_t mod(const uint16_t &x, const uint16_t &y)`` - uint16_t - NP_MATH_UTILS_SQRT.H:2313 - :ref:`View ` * - ``uint32_t mod(const uint32_t &x, const uint32_t &y)`` - uint32_t - NP_MATH_UTILS_SQRT.H:2318 - :ref:`View ` * - ``uint64_t mod(const uint64_t &x, const uint64_t &y)`` - uint64_t - NP_MATH_UTILS_SQRT.H:2323 - :ref:`View ` * - ``bool\_ mod(const bool\_ &x, const bool\_ &y)`` - bool\_ - NP_MATH_UTILS_SQRT.H:2328 - :ref:`View ` * - ``float32 mod(const float32 &x, const float32 &y)`` - float32 - NP_MATH_UTILS_SQRT.H:2337 - :ref:`View ` * - ``double mod(const double &x, const double &y)`` - double - NP_MATH_UTILS_SQRT.H:2342 - :ref:`View ` * - ``std::pair,NDArray> modf(const NDArray&array)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:1777 - :ref:`View ` * - ``std::pair,NDArray> modf(const NDArray&array)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:1789 - :ref:`View ` * - ``std::pair,NDArray> modf(const NDArray&array)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:1801 - :ref:`View ` * - ``std::pair,NDArray> modf(const NDArray&array)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:1813 - :ref:`View ` * - ``std::pair,NDArray> modf(const NDArray&array)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:1825 - :ref:`View ` * - ``std::pair,NDArray> modf(const NDArray&array)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:1837 - :ref:`View ` * - ``std::pair,NDArray> modf(const NDArray&array)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:1849 - :ref:`View ` * - ``std::pair,NDArray> modf(const NDArray&array)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:1861 - :ref:`View ` * - ``std::pair,NDArray> modf(const NDArray&array)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:1873 - :ref:`View ` * - ``std::pair,NDArray> modf(const NDArray&array)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:1885 - :ref:`View ` * - ``std::pair,NDArray> modf(const NDArray&array)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:1897 - :ref:`View ` * - ``void modified_gram_schmidt(std::vector>&V, size_tk, std::vector&h_col)`` - void - NP_LINALG_UTILS.H:2284 - * - ``CharArray multiply(const CharArray&a, size_trepeats)`` - CharArray - NP_CHAR.H:82 - :ref:`View ` * - ``CharArray multiply(const CharArray&a, size_trepeats)`` - CharArray - NP_CHARARRAY.H:20 - :ref:`View ` * - ``CharArray multiply(const CharArray&a, size_trepeats)`` - CharArray - NP_CHARARRAY.H:463 - :ref:`View ` * - ``auto multiply()`` - auto - NP_FROMPYFUNC.H:118 - :ref:`View ` * - ``auto -> detail::promoted_type_t multiply(const T1 &x, const T2 &y)`` - auto -> detail::promoted_type_t - NP_MATH_UTILS_SQRT.H:6184 - :ref:`View ` * - ``auto -> NDArray> multiply(const NDArray&x, const NDArray&y)`` - auto -> NDArray> - NP_MATH_UTILS_SQRT.H:6262 - :ref:`View ` * - ``Matrix multiply(const Matrix&a, const Matrix&b)`` - Matrix - NP_MATRIX_OPS.H:32 - :ref:`View ` * - ``auto multiply(const NDArray&a, const NDArray&b)`` - auto - NP_VECTORIZE.H:327 - :ref:`View ` * - ``int8_t negative(int8_tvalue)`` - int8_t - NP_MATH_UTILS_SQRT.H:4908 - :ref:`View ` * - ``int16_t negative(int16_tvalue)`` - int16_t - NP_MATH_UTILS_SQRT.H:4920 - :ref:`View ` * - ``int32_t negative(int32_tvalue)`` - int32_t - NP_MATH_UTILS_SQRT.H:4932 - :ref:`View ` * - ``int64_t negative(int64_tvalue)`` - int64_t - NP_MATH_UTILS_SQRT.H:4944 - :ref:`View ` * - ``uint8_t negative(uint8_tvalue)`` - uint8_t - NP_MATH_UTILS_SQRT.H:4956 - :ref:`View ` * - ``uint16_t negative(uint16_tvalue)`` - uint16_t - NP_MATH_UTILS_SQRT.H:4968 - :ref:`View ` * - ``uint32_t negative(uint32_tvalue)`` - uint32_t - NP_MATH_UTILS_SQRT.H:4980 - :ref:`View ` * - ``uint64_t negative(uint64_tvalue)`` - uint64_t - NP_MATH_UTILS_SQRT.H:4992 - :ref:`View ` * - ``bool negative(boolvalue)`` - bool - NP_MATH_UTILS_SQRT.H:5004 - :ref:`View ` * - ``float32 negative(float32value)`` - float32 - NP_MATH_UTILS_SQRT.H:5016 - :ref:`View ` * - ``float64 negative(float64value)`` - float64 - NP_MATH_UTILS_SQRT.H:5028 - :ref:`View ` * - ``complex64 negative(const complex64 &value)`` - complex64 - NP_MATH_UTILS_SQRT.H:5040 - :ref:`View ` * - ``complex128 negative(const complex128 &value)`` - complex128 - NP_MATH_UTILS_SQRT.H:5052 - :ref:`View ` * - ``T positive(Tvalue)`` - T - NP_MATH_UTILS_SQRT.H:7020 - :ref:`View ` * - ``complex64 positive(const complex64 &value)`` - complex64 - NP_MATH_UTILS_SQRT.H:7032 - :ref:`View ` * - ``complex128 positive(const complex128 &value)`` - complex128 - NP_MATH_UTILS_SQRT.H:7042 - :ref:`View ` * - ``int8_t power(const int8_t &base, const int8_t &exp)`` - int8_t - NP_MATH_UTILS_SQRT.H:1297 - :ref:`View ` * - ``int16_t power(const int16_t &base, const int16_t &exp)`` - int16_t - NP_MATH_UTILS_SQRT.H:1298 - :ref:`View ` * - ``int32_t power(const int32_t &base, const int32_t &exp)`` - int32_t - NP_MATH_UTILS_SQRT.H:1299 - :ref:`View ` * - ``int64_t power(const int64_t &base, const int64_t &exp)`` - int64_t - NP_MATH_UTILS_SQRT.H:1300 - :ref:`View ` * - ``uint8_t power(const uint8_t &base, const uint8_t &exp)`` - uint8_t - NP_MATH_UTILS_SQRT.H:1301 - :ref:`View ` * - ``uint16_t power(const uint16_t &base, const uint16_t &exp)`` - uint16_t - NP_MATH_UTILS_SQRT.H:1302 - :ref:`View ` * - ``uint32_t power(const uint32_t &base, const uint32_t &exp)`` - uint32_t - NP_MATH_UTILS_SQRT.H:1303 - :ref:`View ` * - ``uint64_t power(const uint64_t &base, const uint64_t &exp)`` - uint64_t - NP_MATH_UTILS_SQRT.H:1304 - :ref:`View ` * - ``int8_t power(const bool\_ &base, const bool\_ &exp)`` - int8_t - NP_MATH_UTILS_SQRT.H:1305 - :ref:`View ` * - ``float32 power(const float32 &base, const float32 &exp)`` - float32 - NP_MATH_UTILS_SQRT.H:1306 - :ref:`View ` * - ``double power(const double &base, const double &exp)`` - double - NP_MATH_UTILS_SQRT.H:1307 - :ref:`View ` * - ``complex64 power(const complex64 &base, const complex64 &exp)`` - complex64 - NP_MATH_UTILS_SQRT.H:1308 - :ref:`View ` * - ``complex128 power(const complex128 &base, const complex128 &exp)`` - complex128 - NP_MATH_UTILS_SQRT.H:1309 - :ref:`View ` * - ``double power(const int8_t &base, const float32 &exp)`` - double - NP_MATH_UTILS_SQRT.H:1312 - :ref:`View ` * - ``double power(const int16_t &base, const float32 &exp)`` - double - NP_MATH_UTILS_SQRT.H:1313 - :ref:`View ` * - ``double power(const int32_t &base, const float32 &exp)`` - double - NP_MATH_UTILS_SQRT.H:1314 - :ref:`View ` * - ``double power(const int64_t &base, const float32 &exp)`` - double - NP_MATH_UTILS_SQRT.H:1315 - :ref:`View ` * - ``double power(const int8_t &base, const double &exp)`` - double - NP_MATH_UTILS_SQRT.H:1316 - :ref:`View ` * - ``double power(const int16_t &base, const double &exp)`` - double - NP_MATH_UTILS_SQRT.H:1317 - :ref:`View ` * - ``double power(const int32_t &base, const double &exp)`` - double - NP_MATH_UTILS_SQRT.H:1318 - :ref:`View ` * - ``double power(const int64_t &base, const double &exp)`` - double - NP_MATH_UTILS_SQRT.H:1319 - :ref:`View ` * - ``float32 power(const float32 &base, const int8_t &exp)`` - float32 - NP_MATH_UTILS_SQRT.H:1322 - :ref:`View ` * - ``float32 power(const float32 &base, const int16_t &exp)`` - float32 - NP_MATH_UTILS_SQRT.H:1323 - :ref:`View ` * - ``double power(const float32 &base, const int32_t &exp)`` - double - NP_MATH_UTILS_SQRT.H:1324 - :ref:`View ` * - ``double power(const float32 &base, const int64_t &exp)`` - double - NP_MATH_UTILS_SQRT.H:1325 - :ref:`View ` * - ``double power(const double &base, const int8_t &exp)`` - double - NP_MATH_UTILS_SQRT.H:1326 - :ref:`View ` * - ``double power(const double &base, const int16_t &exp)`` - double - NP_MATH_UTILS_SQRT.H:1327 - :ref:`View ` * - ``double power(const double &base, const int32_t &exp)`` - double - NP_MATH_UTILS_SQRT.H:1328 - :ref:`View ` * - ``double power(const double &base, const int64_t &exp)`` - double - NP_MATH_UTILS_SQRT.H:1329 - :ref:`View ` * - ``double power(const float32 &base, const double &exp)`` - double - NP_MATH_UTILS_SQRT.H:1332 - :ref:`View ` * - ``double power(const double &base, const float32 &exp)`` - double - NP_MATH_UTILS_SQRT.H:1333 - :ref:`View ` * - ``int16_t power(const int8_t &base, const int16_t &exp)`` - int16_t - NP_MATH_UTILS_SQRT.H:1337 - :ref:`View ` * - ``int32_t power(const int8_t &base, const int32_t &exp)`` - int32_t - NP_MATH_UTILS_SQRT.H:1338 - :ref:`View ` * - ``int64_t power(const int8_t &base, const int64_t &exp)`` - int64_t - NP_MATH_UTILS_SQRT.H:1339 - :ref:`View ` * - ``int16_t power(const int16_t &base, const int8_t &exp)`` - int16_t - NP_MATH_UTILS_SQRT.H:1341 - :ref:`View ` * - ``int32_t power(const int16_t &base, const int32_t &exp)`` - int32_t - NP_MATH_UTILS_SQRT.H:1342 - :ref:`View ` * - ``int64_t power(const int16_t &base, const int64_t &exp)`` - int64_t - NP_MATH_UTILS_SQRT.H:1343 - :ref:`View ` * - ``int32_t power(const int32_t &base, const int8_t &exp)`` - int32_t - NP_MATH_UTILS_SQRT.H:1345 - :ref:`View ` * - ``int32_t power(const int32_t &base, const int16_t &exp)`` - int32_t - NP_MATH_UTILS_SQRT.H:1346 - :ref:`View ` * - ``int64_t power(const int32_t &base, const int64_t &exp)`` - int64_t - NP_MATH_UTILS_SQRT.H:1347 - :ref:`View ` * - ``int64_t power(const int64_t &base, const int8_t &exp)`` - int64_t - NP_MATH_UTILS_SQRT.H:1349 - :ref:`View ` * - ``int64_t power(const int64_t &base, const int16_t &exp)`` - int64_t - NP_MATH_UTILS_SQRT.H:1350 - :ref:`View ` * - ``int64_t power(const int64_t &base, const int32_t &exp)`` - int64_t - NP_MATH_UTILS_SQRT.H:1351 - :ref:`View ` * - ``complex64 power(const float32 &base, const complex64 &exp)`` - complex64 - NP_MATH_UTILS_SQRT.H:1354 - :ref:`View ` * - ``complex128 power(const float32 &base, const complex128 &exp)`` - complex128 - NP_MATH_UTILS_SQRT.H:1355 - :ref:`View ` * - ``complex128 power(const double &base, const complex64 &exp)`` - complex128 - NP_MATH_UTILS_SQRT.H:1356 - :ref:`View ` * - ``complex128 power(const double &base, const complex128 &exp)`` - complex128 - NP_MATH_UTILS_SQRT.H:1357 - :ref:`View ` * - ``complex128 power(const int32_t &base, const complex64 &exp)`` - complex128 - NP_MATH_UTILS_SQRT.H:1358 - :ref:`View ` * - ``complex128 power(const int32_t &base, const complex128 &exp)`` - complex128 - NP_MATH_UTILS_SQRT.H:1359 - :ref:`View ` * - ``complex64 power(const complex64 &base, const float32 &exp)`` - complex64 - NP_MATH_UTILS_SQRT.H:1362 - :ref:`View ` * - ``complex128 power(const complex128 &base, const float32 &exp)`` - complex128 - NP_MATH_UTILS_SQRT.H:1363 - :ref:`View ` * - ``complex128 power(const complex128 &base, const double &exp)`` - complex128 - NP_MATH_UTILS_SQRT.H:1364 - :ref:`View ` * - ``auto -> std::enable_if_t\|\| std::is_same_v\|\| std::is_same_v\|\| std::is_same_v, NDArray()))>> power(const TBase &base_scalar, const NDArray&exp_array)`` - auto -> std::enable_if_t\|\| std::is_same_v\|\| std::is_same_v\|\| std::is_same_v, NDArray()))>> - NP_MATH_UTILS_SQRT.H:1370 - :ref:`View ` * - ``auto -> NDArray(), std::declval()))> power(const NDArray&base_array, const NDArray&exp_array)`` - auto -> NDArray(), std::declval()))> - NP_MATH_UTILS_SQRT.H:1399 - :ref:`View ` * - ``auto power(const NDArray&a, const NDArray&b)`` - auto - NP_VECTORIZE.H:339 - :ref:`View ` * - ``EigenDecomposition power_iteration(const NDArray&matrix, size_tmax_iterations = 1000, Ttolerance = T{1e-10})`` - EigenDecomposition - NP_LINALG.H:1520 - :ref:`View ` * - ``double rad2deg(int8_tx)`` - double - NP_MATH_UTILS_SQRT.H:5327 - :ref:`View ` * - ``double rad2deg(int16_tx)`` - double - NP_MATH_UTILS_SQRT.H:5328 - :ref:`View ` * - ``double rad2deg(int32_tx)`` - double - NP_MATH_UTILS_SQRT.H:5329 - :ref:`View ` * - ``double rad2deg(int64_tx)`` - double - NP_MATH_UTILS_SQRT.H:5330 - :ref:`View ` * - ``double rad2deg(uint8_tx)`` - double - NP_MATH_UTILS_SQRT.H:5331 - :ref:`View ` * - ``double rad2deg(uint16_tx)`` - double - NP_MATH_UTILS_SQRT.H:5332 - :ref:`View ` * - ``double rad2deg(uint32_tx)`` - double - NP_MATH_UTILS_SQRT.H:5333 - :ref:`View ` * - ``double rad2deg(uint64_tx)`` - double - NP_MATH_UTILS_SQRT.H:5334 - :ref:`View ` * - ``double rad2deg(boolx)`` - double - NP_MATH_UTILS_SQRT.H:5337 - :ref:`View ` * - ``float rad2deg(floatx)`` - float - NP_MATH_UTILS_SQRT.H:5340 - :ref:`View ` * - ``double rad2deg(doublex)`` - double - NP_MATH_UTILS_SQRT.H:5341 - :ref:`View ` * - ``complex64 rad2deg(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:5344 - :ref:`View ` * - ``complex128 rad2deg(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:5348 - :ref:`View ` * - ``double radians(int8_tx)`` - double - NP_MATH_UTILS_SQRT.H:5279 - :ref:`View ` * - ``double radians(int16_tx)`` - double - NP_MATH_UTILS_SQRT.H:5280 - :ref:`View ` * - ``double radians(int32_tx)`` - double - NP_MATH_UTILS_SQRT.H:5281 - :ref:`View ` * - ``double radians(int64_tx)`` - double - NP_MATH_UTILS_SQRT.H:5282 - :ref:`View ` * - ``double radians(uint8_tx)`` - double - NP_MATH_UTILS_SQRT.H:5283 - :ref:`View ` * - ``double radians(uint16_tx)`` - double - NP_MATH_UTILS_SQRT.H:5284 - :ref:`View ` * - ``double radians(uint32_tx)`` - double - NP_MATH_UTILS_SQRT.H:5285 - :ref:`View ` * - ``double radians(uint64_tx)`` - double - NP_MATH_UTILS_SQRT.H:5286 - :ref:`View ` * - ``double radians(boolx)`` - double - NP_MATH_UTILS_SQRT.H:5289 - :ref:`View ` * - ``float radians(floatx)`` - float - NP_MATH_UTILS_SQRT.H:5292 - :ref:`View ` * - ``double radians(doublex)`` - double - NP_MATH_UTILS_SQRT.H:5293 - :ref:`View ` * - ``complex64 radians(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:5296 - :ref:`View ` * - ``complex128 radians(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:5297 - :ref:`View ` * - ``float32 reciprocal(float32value)`` - float32 - NP_MATH_UTILS_SQRT.H:5069 - :ref:`View ` * - ``float64 reciprocal(float64value)`` - float64 - NP_MATH_UTILS_SQRT.H:5081 - :ref:`View ` * - ``complex64 reciprocal(const complex64 &value)`` - complex64 - NP_MATH_UTILS_SQRT.H:5093 - :ref:`View ` * - ``complex128 reciprocal(const complex128 &value)`` - complex128 - NP_MATH_UTILS_SQRT.H:5105 - :ref:`View ` * - ``int8_t remainder(const int8_t &x, const int8_t &y)`` - int8_t - NP_MATH_UTILS_SQRT.H:2853 - :ref:`View ` * - ``int16_t remainder(const int16_t &x, const int16_t &y)`` - int16_t - NP_MATH_UTILS_SQRT.H:2858 - :ref:`View ` * - ``int32_t remainder(const int32_t &x, const int32_t &y)`` - int32_t - NP_MATH_UTILS_SQRT.H:2863 - :ref:`View ` * - ``int64_t remainder(const int64_t &x, const int64_t &y)`` - int64_t - NP_MATH_UTILS_SQRT.H:2868 - :ref:`View ` * - ``uint8_t remainder(const uint8_t &x, const uint8_t &y)`` - uint8_t - NP_MATH_UTILS_SQRT.H:2873 - :ref:`View ` * - ``uint16_t remainder(const uint16_t &x, const uint16_t &y)`` - uint16_t - NP_MATH_UTILS_SQRT.H:2878 - :ref:`View ` * - ``uint32_t remainder(const uint32_t &x, const uint32_t &y)`` - uint32_t - NP_MATH_UTILS_SQRT.H:2883 - :ref:`View ` * - ``uint64_t remainder(const uint64_t &x, const uint64_t &y)`` - uint64_t - NP_MATH_UTILS_SQRT.H:2888 - :ref:`View ` * - ``bool remainder(const bool &x, const bool &y)`` - bool - NP_MATH_UTILS_SQRT.H:2893 - :ref:`View ` * - ``float remainder(const float &x, const float &y)`` - float - NP_MATH_UTILS_SQRT.H:2898 - :ref:`View ` * - ``double remainder(const double &x, const double &y)`` - double - NP_MATH_UTILS_SQRT.H:2903 - :ref:`View ` * - ``auto -> detail::promoted_type_t remainder(const T1 &x, const T2 &y)`` - auto -> detail::promoted_type_t - NP_MATH_UTILS_SQRT.H:6057 - :ref:`View ` * - ``auto -> NDArray> remainder(const NDArray&x, const NDArray&y)`` - auto -> NDArray> - NP_MATH_UTILS_SQRT.H:6115 - :ref:`View ` * - ``float32 rint(const int8_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1195 - :ref:`View ` * - ``float32 rint(const int16_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1196 - :ref:`View ` * - ``double rint(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1197 - :ref:`View ` * - ``double rint(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1198 - :ref:`View ` * - ``float32 rint(const uint8_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1199 - :ref:`View ` * - ``float32 rint(const uint16_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1200 - :ref:`View ` * - ``double rint(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1201 - :ref:`View ` * - ``double rint(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1202 - :ref:`View ` * - ``float32 rint(const bool\_ &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1203 - :ref:`View ` * - ``float32 rint(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1206 - :ref:`View ` * - ``double rint(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:1207 - :ref:`View ` * - ``complex64 rint(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:1210 - :ref:`View ` * - ``complex128 rint(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:1213 - :ref:`View ` * - ``int8_t round(const int8_t &x, intdecimals = 0)`` - int8_t - NP_MATH_UTILS_SQRT.H:870 - :ref:`View ` * - ``int16_t round(const int16_t &x, intdecimals = 0)`` - int16_t - NP_MATH_UTILS_SQRT.H:875 - :ref:`View ` * - ``int32_t round(const int32_t &x, intdecimals = 0)`` - int32_t - NP_MATH_UTILS_SQRT.H:880 - :ref:`View ` * - ``int64_t round(const int64_t &x, intdecimals = 0)`` - int64_t - NP_MATH_UTILS_SQRT.H:885 - :ref:`View ` * - ``uint8_t round(const uint8_t &x, intdecimals = 0)`` - uint8_t - NP_MATH_UTILS_SQRT.H:890 - :ref:`View ` * - ``uint16_t round(const uint16_t &x, intdecimals = 0)`` - uint16_t - NP_MATH_UTILS_SQRT.H:895 - :ref:`View ` * - ``uint32_t round(const uint32_t &x, intdecimals = 0)`` - uint32_t - NP_MATH_UTILS_SQRT.H:900 - :ref:`View ` * - ``uint64_t round(const uint64_t &x, intdecimals = 0)`` - uint64_t - NP_MATH_UTILS_SQRT.H:905 - :ref:`View ` * - ``bool\_ round(const bool\_ &x, intdecimals = 0)`` - bool\_ - NP_MATH_UTILS_SQRT.H:911 - :ref:`View ` * - ``float32 round(const float32 &x, intdecimals = 0)`` - float32 - NP_MATH_UTILS_SQRT.H:916 - :ref:`View ` * - ``double round(const double &x, intdecimals = 0)`` - double - NP_MATH_UTILS_SQRT.H:921 - :ref:`View ` * - ``complex64 round(const complex64 &x, intdecimals = 0)`` - complex64 - NP_MATH_UTILS_SQRT.H:927 - :ref:`View ` * - ``complex128 round(const complex128 &x, intdecimals = 0)`` - complex128 - NP_MATH_UTILS_SQRT.H:930 - :ref:`View ` * - ``void round_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:1879 - * - ``double sin(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:171 - :ref:`View ` * - ``double sin(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:172 - :ref:`View ` * - ``double sin(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:173 - :ref:`View ` * - ``double sin(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:174 - :ref:`View ` * - ``double sin(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:175 - :ref:`View ` * - ``double sin(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:176 - :ref:`View ` * - ``double sin(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:177 - :ref:`View ` * - ``double sin(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:178 - :ref:`View ` * - ``double sin(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:179 - :ref:`View ` * - ``float32 sin(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:180 - :ref:`View ` * - ``double sin(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:181 - :ref:`View ` * - ``complex64 sin(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:182 - :ref:`View ` * - ``complex128 sin(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:183 - :ref:`View ` * - ``auto sin(const NDArray&x)`` - auto - NP_VECTORIZE.H:345 - :ref:`View ` * - ``auto sin(const NDArray&x, MathBackendbackend)`` - auto - NP_VECTORIZE.H:352 - :ref:`View ` * - ``void sin_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_TRIGONOMETRIC.H:228 - :ref:`View ` * - ``void sin_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:272 - * - ``T sinc(Tvalue)`` - T - NP_MATH_UTILS_SQRT.H:7073 - :ref:`View ` * - ``complex64 sinc(const complex64 &value)`` - complex64 - NP_MATH_UTILS_SQRT.H:7099 - :ref:`View ` * - ``complex128 sinc(const complex128 &value)`` - complex128 - NP_MATH_UTILS_SQRT.H:7119 - :ref:`View ` * - ``double sinh(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:638 - :ref:`View ` * - ``double sinh(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:639 - :ref:`View ` * - ``double sinh(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:640 - :ref:`View ` * - ``double sinh(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:641 - :ref:`View ` * - ``double sinh(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:642 - :ref:`View ` * - ``double sinh(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:643 - :ref:`View ` * - ``double sinh(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:644 - :ref:`View ` * - ``double sinh(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:645 - :ref:`View ` * - ``double sinh(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:646 - :ref:`View ` * - ``float32 sinh(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:647 - :ref:`View ` * - ``double sinh(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:648 - :ref:`View ` * - ``complex64 sinh(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:649 - :ref:`View ` * - ``complex128 sinh(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:650 - :ref:`View ` * - ``void sinh_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_TRIGONOMETRIC.H:528 - * - ``void sinh_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:480 - * - ``Matrix sinhm(const Matrix&matrix)`` - Matrix - NP_MATRIX_SPECIAL.H:294 - * - ``Matrix sinm(const Matrix&matrix)`` - Matrix - NP_MATRIX_SPECIAL.H:192 - :ref:`View ` * - ``typename std::enable_if_t,T> sinpi(Tx)`` - typename std::enable_if_t,T> - NP_MATH_EXTENDED.H:154 - :ref:`View ` * - ``typename std::enable_if_t,NDArray> sinpi(const NDArray&x)`` - typename std::enable_if_t,NDArray> - NP_MATH_EXTENDED.H:172 - :ref:`View ` * - ``double sqrt(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:47 - :ref:`View ` * - ``double sqrt(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:48 - :ref:`View ` * - ``double sqrt(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:49 - :ref:`View ` * - ``double sqrt(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:50 - :ref:`View ` * - ``double sqrt(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:51 - :ref:`View ` * - ``double sqrt(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:52 - :ref:`View ` * - ``double sqrt(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:53 - :ref:`View ` * - ``double sqrt(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:54 - :ref:`View ` * - ``double sqrt(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:55 - :ref:`View ` * - ``float32 sqrt(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:56 - :ref:`View ` * - ``double sqrt(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:57 - :ref:`View ` * - ``complex64 sqrt(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:58 - :ref:`View ` * - ``complex128 sqrt(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:59 - :ref:`View ` * - ``auto sqrt(const NDArray&x)`` - auto - NP_VECTORIZE.H:397 - :ref:`View ` * - ``NDArray> sqrt_complex_mkl(const NDArray>&input)`` - NDArray> - NP_MKL_SPECIAL_COMPLEX.H:303 - :ref:`View ` * - ``NDArray> sqrt_complex_mkl(const NDArray>&input)`` - NDArray> - NP_MKL_SPECIAL_COMPLEX.H:450 - :ref:`View ` * - ``void sqrt_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:1392 - :ref:`View ` * - ``Matrix sqrtm(const Matrix&matrix)`` - Matrix - NP_MATRIX_SPECIAL.H:138 - :ref:`View ` * - ``int8_t square(const int8_t &x)`` - int8_t - NP_MATH_UTILS_SQRT.H:131 - :ref:`View ` * - ``int16_t square(const int16_t &x)`` - int16_t - NP_MATH_UTILS_SQRT.H:132 - :ref:`View ` * - ``int32_t square(const int32_t &x)`` - int32_t - NP_MATH_UTILS_SQRT.H:133 - :ref:`View ` * - ``int64_t square(const int64_t &x)`` - int64_t - NP_MATH_UTILS_SQRT.H:134 - :ref:`View ` * - ``uint8_t square(const uint8_t &x)`` - uint8_t - NP_MATH_UTILS_SQRT.H:135 - :ref:`View ` * - ``uint16_t square(const uint16_t &x)`` - uint16_t - NP_MATH_UTILS_SQRT.H:136 - :ref:`View ` * - ``uint32_t square(const uint32_t &x)`` - uint32_t - NP_MATH_UTILS_SQRT.H:137 - :ref:`View ` * - ``uint64_t square(const uint64_t &x)`` - uint64_t - NP_MATH_UTILS_SQRT.H:138 - :ref:`View ` * - ``bool\_ square(const bool\_ &x)`` - bool\_ - NP_MATH_UTILS_SQRT.H:139 - :ref:`View ` * - ``float32 square(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:140 - :ref:`View ` * - ``double square(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:141 - :ref:`View ` * - ``complex64 square(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:142 - :ref:`View ` * - ``complex128 square(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:143 - :ref:`View ` * - ``auto -> detail::promoted_type_t subtract(const T1 &x, const T2 &y)`` - auto -> detail::promoted_type_t - NP_MATH_UTILS_SQRT.H:6173 - :ref:`View ` * - ``auto -> NDArray> subtract(const NDArray&x, const NDArray&y)`` - auto -> NDArray> - NP_MATH_UTILS_SQRT.H:6233 - :ref:`View ` * - ``auto subtract(const NDArray&a, const NDArray&b)`` - auto - NP_VECTORIZE.H:321 - :ref:`View ` * - ``double tan(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:251 - :ref:`View ` * - ``double tan(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:252 - :ref:`View ` * - ``double tan(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:253 - :ref:`View ` * - ``double tan(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:254 - :ref:`View ` * - ``double tan(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:255 - :ref:`View ` * - ``double tan(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:256 - :ref:`View ` * - ``double tan(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:257 - :ref:`View ` * - ``double tan(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:258 - :ref:`View ` * - ``double tan(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:259 - :ref:`View ` * - ``float32 tan(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:260 - :ref:`View ` * - ``double tan(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:261 - :ref:`View ` * - ``complex64 tan(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:262 - :ref:`View ` * - ``complex128 tan(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:263 - :ref:`View ` * - ``auto tan(const NDArray&x)`` - auto - NP_VECTORIZE.H:371 - :ref:`View ` * - ``auto tan(const NDArray&x, MathBackendbackend)`` - auto - NP_VECTORIZE.H:378 - :ref:`View ` * - ``void tan_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_TRIGONOMETRIC.H:290 - * - ``void tan_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:314 - * - ``double tanh(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:710 - :ref:`View ` * - ``double tanh(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:711 - :ref:`View ` * - ``double tanh(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:712 - :ref:`View ` * - ``double tanh(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:713 - :ref:`View ` * - ``double tanh(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:714 - :ref:`View ` * - ``double tanh(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:715 - :ref:`View ` * - ``double tanh(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:716 - :ref:`View ` * - ``double tanh(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:717 - :ref:`View ` * - ``double tanh(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:718 - :ref:`View ` * - ``float32 tanh(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:719 - :ref:`View ` * - ``double tanh(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:720 - :ref:`View ` * - ``complex64 tanh(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:721 - :ref:`View ` * - ``complex128 tanh(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:722 - :ref:`View ` * - ``void tanh_inplace(NDArray&array, MathBackendbackend = MathBackend::MKL)`` - void - NP_TRIGONOMETRIC.H:646 - * - ``void tanh_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:562 - * - ``Matrix tanhm(const Matrix&matrix)`` - Matrix - NP_MATRIX_SPECIAL.H:320 - * - ``Matrix tanm(const Matrix&matrix)`` - Matrix - NP_MATRIX_SPECIAL.H:279 - * - ``auto true_divide(Tx, Ty)`` - auto - NP_MATH_UTILS_SQRT.H:7297 - :ref:`View ` * - ``auto true_divide(const NDArray&x, const NDArray&y)`` - auto - NP_MATH_UTILS_SQRT.H:7318 - :ref:`View ` * - ``float32 trunc(const int8_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1061 - :ref:`View ` * - ``float32 trunc(const int16_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1062 - :ref:`View ` * - ``double trunc(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1063 - :ref:`View ` * - ``double trunc(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1064 - :ref:`View ` * - ``float32 trunc(const uint8_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1065 - :ref:`View ` * - ``float32 trunc(const uint16_t &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1066 - :ref:`View ` * - ``double trunc(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1067 - :ref:`View ` * - ``double trunc(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:1068 - :ref:`View ` * - ``float32 trunc(const bool\_ &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1069 - :ref:`View ` * - ``float32 trunc(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:1071 - :ref:`View ` * - ``double trunc(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:1072 - :ref:`View ` * - ``void trunc_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:1838 - Statistics ---------- .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``double average(const MaskedArray&array, const MaskedArray\*weights = nullptr)`` - double - NP_MASKED_ARRAY.H:1888 - :ref:`View ` * - ``auto average(const NDArray&array, std::optionalaxis = std::nullopt, const NDArray\*weights = nullptr, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:452 - :ref:`View ` * - ``std::pair,NDArray> histogram(const NDArray&array, intbins = 10)`` - std::pair,NDArray> - NP_STATS_UTILS.H:1042 - :ref:`View ` * - ``std::tuple,NDArray,NDArray> histogram2d(const NDArray&x, const NDArray&y, intbins = 10)`` - std::tuple,NDArray,NDArray> - NP_STATS_UTILS.H:1100 - :ref:`View ` * - ``std::tuple,std::vector>> histogramdd(const NDArray&sample, intbins = 10)`` - std::tuple,std::vector>> - NP_STATS_UTILS.H:1167 - :ref:`View ` * - ``T max(const MaskedArray&array)`` - T - NP_MASKED_ARRAY.H:1862 - :ref:`View ` * - ``auto max(const NDArray&array, std::optionalaxis = std::nullopt, boolkeepdims = false, NDArray\*out = nullptr)`` - auto - NP_STATS_UTILS.H:833 - :ref:`View ` * - ``T maxArray()`` - T - NP_NDARRAY.H:858 - :ref:`View ` * - ``auto maximum()`` - auto - NP_FROMPYFUNC.H:139 - :ref:`View ` * - ``int8_t maximum(const int8_t &x, const int8_t &y)`` - int8_t - NP_MATH_UTILS_SQRT.H:2973 - :ref:`View ` * - ``int16_t maximum(const int16_t &x, const int16_t &y)`` - int16_t - NP_MATH_UTILS_SQRT.H:2994 - :ref:`View ` * - ``int32_t maximum(const int32_t &x, const int32_t &y)`` - int32_t - NP_MATH_UTILS_SQRT.H:3015 - :ref:`View ` * - ``int64_t maximum(const int64_t &x, const int64_t &y)`` - int64_t - NP_MATH_UTILS_SQRT.H:3036 - :ref:`View ` * - ``uint8_t maximum(const uint8_t &x, const uint8_t &y)`` - uint8_t - NP_MATH_UTILS_SQRT.H:3057 - :ref:`View ` * - ``uint16_t maximum(const uint16_t &x, const uint16_t &y)`` - uint16_t - NP_MATH_UTILS_SQRT.H:3078 - :ref:`View ` * - ``uint32_t maximum(const uint32_t &x, const uint32_t &y)`` - uint32_t - NP_MATH_UTILS_SQRT.H:3099 - :ref:`View ` * - ``uint64_t maximum(const uint64_t &x, const uint64_t &y)`` - uint64_t - NP_MATH_UTILS_SQRT.H:3120 - :ref:`View ` * - ``bool maximum(const bool &x, const bool &y)`` - bool - NP_MATH_UTILS_SQRT.H:3141 - :ref:`View ` * - ``float maximum(const float &x, const float &y)`` - float - NP_MATH_UTILS_SQRT.H:3162 - :ref:`View ` * - ``double maximum(const double &x, const double &y)`` - double - NP_MATH_UTILS_SQRT.H:3186 - :ref:`View ` * - ``complex64 maximum(const complex64 &x, const complex64 &y)`` - complex64 - NP_MATH_UTILS_SQRT.H:3210 - :ref:`View ` * - ``complex128 maximum(const complex128 &x, const complex128 &y)`` - complex128 - NP_MATH_UTILS_SQRT.H:3234 - :ref:`View ` * - ``auto -> detail::promoted_type_t maximum(const T1 &x, const T2 &y)`` - auto -> detail::promoted_type_t - NP_MATH_UTILS_SQRT.H:5857 - :ref:`View ` * - ``auto -> NDArray> maximum(const NDArray&x, const NDArray&y)`` - auto -> NDArray> - NP_MATH_UTILS_SQRT.H:5931 - :ref:`View ` * - ``T maximum_fill_value(const T &)`` - T - NP_MASKED_ARRAY.H:3342 - :ref:`View ` * - ``T maximum_fill_value(const NDArray&)`` - T - NP_MASKED_ARRAY.H:3356 - :ref:`View ` * - ``T maximum_fill_value(const MaskedArray&)`` - T - NP_MASKED_ARRAY.H:3361 - :ref:`View ` * - ``NUMPYCORE_API DType maximum_sctype(DTypedtype)`` - NUMPYCORE_API DType - NP_DTYPE_UTILS.H:464 - :ref:`View ` * - ``double mean(const MaskedArray&array)`` - double - NP_MASKED_ARRAY.H:1850 - :ref:`View ` * - ``auto mean(const NDArray&array, std::optionalaxis = std::nullopt, boolkeepdims = false, NDArray,double,T>::type>\*out = nullptr)`` - auto - NP_STATS_UTILS.H:400 - :ref:`View ` * - ``double meanArray()`` - double - NP_NDARRAY.H:835 - :ref:`View ` * - ``T median(const MaskedArray&array)`` - T - NP_MASKED_ARRAY.H:1929 - :ref:`View ` * - ``auto median(const NDArray&array, std::optionalaxis = std::nullopt, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:624 - :ref:`View ` * - ``T min(const MaskedArray&array)`` - T - NP_MASKED_ARRAY.H:1856 - :ref:`View ` * - ``auto min(const NDArray&array, std::optionalaxis = std::nullopt, boolkeepdims = false, NDArray\*out = nullptr)`` - auto - NP_STATS_UTILS.H:810 - :ref:`View ` * - ``T minArray()`` - T - NP_NDARRAY.H:841 - :ref:`View ` * - ``NUMPYCORE_API DType min_scalar_type(int64_tvalue)`` - NUMPYCORE_API DType - NP_DTYPE_UTILS.H:161 - :ref:`View ` * - ``NUMPYCORE_API DType min_scalar_type(doublevalue)`` - NUMPYCORE_API DType - NP_DTYPE_UTILS.H:169 - :ref:`View ` * - ``NUMPYCORE_API DType min_scalar_type(std::complexvalue)`` - NUMPYCORE_API DType - NP_DTYPE_UTILS.H:177 - :ref:`View ` * - ``auto minimum()`` - auto - NP_FROMPYFUNC.H:147 - :ref:`View ` * - ``int8_t minimum(const int8_t &x, const int8_t &y)`` - int8_t - NP_MATH_UTILS_SQRT.H:3267 - :ref:`View ` * - ``int16_t minimum(const int16_t &x, const int16_t &y)`` - int16_t - NP_MATH_UTILS_SQRT.H:3288 - :ref:`View ` * - ``int32_t minimum(const int32_t &x, const int32_t &y)`` - int32_t - NP_MATH_UTILS_SQRT.H:3309 - :ref:`View ` * - ``int64_t minimum(const int64_t &x, const int64_t &y)`` - int64_t - NP_MATH_UTILS_SQRT.H:3330 - :ref:`View ` * - ``uint8_t minimum(const uint8_t &x, const uint8_t &y)`` - uint8_t - NP_MATH_UTILS_SQRT.H:3351 - :ref:`View ` * - ``uint16_t minimum(const uint16_t &x, const uint16_t &y)`` - uint16_t - NP_MATH_UTILS_SQRT.H:3372 - :ref:`View ` * - ``uint32_t minimum(const uint32_t &x, const uint32_t &y)`` - uint32_t - NP_MATH_UTILS_SQRT.H:3393 - :ref:`View ` * - ``uint64_t minimum(const uint64_t &x, const uint64_t &y)`` - uint64_t - NP_MATH_UTILS_SQRT.H:3414 - :ref:`View ` * - ``bool\_ minimum(const bool\_ &x, const bool\_ &y)`` - bool\_ - NP_MATH_UTILS_SQRT.H:3435 - :ref:`View ` * - ``float32 minimum(const float32 &x, const float32 &y)`` - float32 - NP_MATH_UTILS_SQRT.H:3456 - :ref:`View ` * - ``double minimum(const double &x, const double &y)`` - double - NP_MATH_UTILS_SQRT.H:3480 - :ref:`View ` * - ``complex64 minimum(const complex64 &x, const complex64 &y)`` - complex64 - NP_MATH_UTILS_SQRT.H:3504 - :ref:`View ` * - ``complex128 minimum(const complex128 &x, const complex128 &y)`` - complex128 - NP_MATH_UTILS_SQRT.H:3528 - :ref:`View ` * - ``auto -> detail::promoted_type_t minimum(const T1 &x, const T2 &y)`` - auto -> detail::promoted_type_t - NP_MATH_UTILS_SQRT.H:5848 - :ref:`View ` * - ``auto -> NDArray> minimum(const NDArray&x, const NDArray&y)`` - auto -> NDArray> - NP_MATH_UTILS_SQRT.H:5903 - :ref:`View ` * - ``T minimum_fill_value(const T &)`` - T - NP_MASKED_ARRAY.H:3370 - :ref:`View ` * - ``T minimum_fill_value(const NDArray&)`` - T - NP_MASKED_ARRAY.H:3384 - :ref:`View ` * - ``T minimum_fill_value(const MaskedArray&)`` - T - NP_MASKED_ARRAY.H:3389 - :ref:`View ` * - ``NUMPYCORE_API char mintypecode(const std::string &typechars)`` - NUMPYCORE_API char - NP_DTYPE_UTILS.H:485 - :ref:`View ` * - ``T nan_to_num(Tvalue, Tnan_val = T{0}, Tposinf_val = std::numeric_limits::max(), Tneginf_val = std::numeric_limits::lowest())`` - T - NP_MATH_UTILS_SQRT.H:6748 - :ref:`View ` * - ``complex64 nan_to_num(const complex64 &value, floatnan_val = 0.0f, floatposinf_val = std::numeric_limits::max(), floatneginf_val = std::numeric_limits::lowest())`` - complex64 - NP_MATH_UTILS_SQRT.H:6803 - :ref:`View ` * - ``complex128 nan_to_num(const complex128 &value, doublenan_val = 0.0, doubleposinf_val = std::numeric_limits::max(), doubleneginf_val = std::numeric_limits::lowest())`` - complex128 - NP_MATH_UTILS_SQRT.H:6832 - :ref:`View ` * - ``size_t nanargmax(const std::vector&arr)`` - size_t - NP_SORTING_ALGORITHMS.H:2243 - :ref:`View ` * - ``size_t nanargmin(const std::vector&arr)`` - size_t - NP_SORTING_ALGORITHMS.H:2194 - :ref:`View ` * - ``auto nanmax(const NDArray&array, std::optionalaxis = std::nullopt, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:1652 - :ref:`View ` * - ``auto nanmean(const NDArray&array, std::optionalaxis = std::nullopt, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:528 - :ref:`View ` * - ``auto nanmedian(const NDArray&array, std::optionalaxis = std::nullopt, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:1454 - :ref:`View ` * - ``auto nanmin(const NDArray&array, std::optionalaxis = std::nullopt, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:1613 - :ref:`View ` * - ``auto nanpercentile(const NDArray&array, doubleq, std::optionalaxis = std::nullopt, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:1690 - :ref:`View ` * - ``auto nanprod(const NDArray&array, std::optionalaxis = std::nullopt, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:1586 - :ref:`View ` * - ``auto nanquantile(const NDArray&array, doubleq, std::optionalaxis = std::nullopt, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:1723 - :ref:`View ` * - ``auto nanstd(const NDArray&array, std::optionalaxis = std::nullopt, intddof = 0, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:563 - :ref:`View ` * - ``auto nansum(const NDArray&array, std::optionalaxis = std::nullopt, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:1560 - :ref:`View ` * - ``auto nanvar(const NDArray&array, std::optionalaxis = std::nullopt, intddof = 0, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:1500 - :ref:`View ` * - ``auto percentile(const NDArray&array, doubleq, std::optionalaxis = std::nullopt)`` - auto - NP_STATS_UTILS.H:900 - :ref:`View ` * - ``T ptp(const MaskedArray&array)`` - T - NP_MASKED_ARRAY.H:1961 - :ref:`View ` * - ``auto ptp(const NDArray&array, std::optionalaxis = std::nullopt, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:1433 - :ref:`View ` * - ``auto quantile(const NDArray&array, doubleq, std::optionalaxis = std::nullopt)`` - auto - NP_STATS_UTILS.H:929 - :ref:`View ` * - ``double std(const MaskedArray&array)`` - double - NP_MASKED_ARRAY.H:1868 - :ref:`View ` * - ``auto std(const NDArray&array, std::optionalaxis = std::nullopt, intddof = 0, boolkeepdims = false, NDArray,double,T>::type>\*out = nullptr)`` - auto - NP_STATS_UTILS.H:665 - :ref:`View ` * - ``T sum(const MaskedArray&array)`` - T - NP_MASKED_ARRAY.H:1844 - :ref:`View ` * - ``auto sum(const NDArray&array, std::optionalaxis = std::nullopt, boolkeepdims = false, NDArray, int64, typename std::conditional::type>::type>\* out = nullptr)`` - auto - NP_STATS_UTILS.H:856 - :ref:`View ` * - ``T sumArray()`` - T - NP_NDARRAY.H:818 - :ref:`View ` * - ``double var(const MaskedArray&array)`` - double - NP_MASKED_ARRAY.H:1874 - :ref:`View ` * - ``auto var(const NDArray&array, std::optionalaxis = std::nullopt, intddof = 0, boolkeepdims = false, NDArray,double,T>::type>\*out = nullptr)`` - auto - NP_STATS_UTILS.H:738 - :ref:`View ` Linear Algebra -------------- .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``auto cholesky_accelerated(const NDArray&matrix, boolupper = false)`` - auto - NP_MKL_LINALG.H:3656 - :ref:`View ` * - ``CholeskyDecomposition cholesky_decomposition(const NDArray&matrix, Ttolerance = utils::machine_epsilon())`` - CholeskyDecomposition - NP_LINALG.H:1084 - :ref:`View ` * - ``CholeskyDecomposition cholesky_decomposition_enhanced(const NDArray&matrix, booluse_upper = false, Ttolerance = utils::machine_epsilon(), boolforce_blocked = false)`` - CholeskyDecomposition - NP_LINALG.H:853 - :ref:`View ` * - ``bool cholesky_panel(T \*matrix, size_tn, size_tlda, size_tpanel_size, Ttolerance = machine_epsilon())`` - bool - NP_LINALG_UTILS.H:458 - * - ``T det(const NDArray&matrix)`` - T - NP_LINALG.H:1185 - :ref:`View ` * - ``std::string detect_delimiter(std::ifstream &file)`` - std::string - NP_IO_UTILS.H:1275 - :ref:`View ` * - ``DType detect_value_type(const std::string &value)`` - DType - NP_IO_UTILS.H:1071 - :ref:`View ` * - ``T dot_product(const T \*a, const T \*b, size_tn)`` - T - NP_LINALG_UTILS.H:204 - :ref:`View ` * - ``EigenDecomposition eig(const NDArray&matrix, typename utils::real_type::typetolerance = utils::machine_epsilon::type>(), booluse_balancing = true)`` - EigenDecomposition - NP_LINALG.H:2761 - :ref:`View ` * - ``GeneralizedEigenDecomposition eig(const NDArray&A, const NDArray&B, boolcompute_left = false, typename utils::real_type::typetolerance = utils::machine_epsilon::type>())`` - GeneralizedEigenDecomposition - NP_LINALG.H:3045 - :ref:`View ` * - ``std::pair>,Matrix>> eig(const Matrix&matrix)`` - std::pair>,Matrix>> - NP_MATRIX_OPS.H:269 - :ref:`View ` * - ``auto eig_accelerated(const NDArray&matrix, boolcompute_vectors = true)`` - auto - NP_MKL_LINALG.H:3625 - :ref:`View ` * - ``::numpy::linalg::EigenDecomposition eig_auto_tuned(const NDArray&matrix, typename real_type::typetolerance = machine_epsilon::type>(), boolcompute_eigenvectors = true)`` - ::numpy::linalg::EigenDecomposition - NP_LINALG_UTILS.H:2914 - * - ``::numpy::linalg::EigenDecomposition eig_optimized(const NDArray&matrix, typename utils::real_type::typetolerance = utils::machine_epsilon::type>(), boolauto_select = true)`` - ::numpy::linalg::EigenDecomposition - NP_LINALG_UTILS.H:2143 - * - ``EigenDecomposition eigh(const NDArray&matrix, boolcompute_vectors = true)`` - EigenDecomposition - NP_LINALG.H:5162 - :ref:`View ` * - ``auto eigvals_accelerated(const NDArray&matrix)`` - auto - NP_MKL_LINALG.H:3641 - :ref:`View ` * - ``std::pair>,std::string> einsum_path(const std::string &subscripts, const std::vector>&shapes, booloptimize = false)`` - std::pair>,std::string> - NP_EINSUM.H:516 - :ref:`View ` * - ``std::pair>,std::string> einsum_path(const std::string &subscripts, const std::vector&sizes, booloptimize = false)`` - std::pair>,std::string> - NP_EINSUM.H:556 - :ref:`View ` * - ``auto inner(const NDArray&a, const NDArray&b)`` - auto - NP_LINALG.H:143 - :ref:`View ` * - ``T innerproduct(const MaskedArray&a, const MaskedArray&b)`` - T - NP_MASKED_ARRAY.H:2928 - :ref:`View ` * - ``void invcbrt_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:1556 - * - ``EigenDecomposition inverse_iteration(const NDArray&matrix, Tshift = T{0}, size_tmax_iterations = 1000, Ttolerance = T{1e-10})`` - EigenDecomposition - NP_LINALG.H:1668 - :ref:`View ` * - ``void invsqrt_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:1515 - * - ``LeastSquaresResult lstsq(const NDArray&A, const NDArray&b, Ttolerance = T{1e-15})`` - LeastSquaresResult - NP_LINALG.H:2562 - :ref:`View ` * - ``Matrix lstsq(const Matrix&A, const Matrix&b)`` - Matrix - NP_MATRIX_OPS.H:427 - :ref:`View ` * - ``auto lstsq_accelerated(const NDArray&A, const NDArray&b)`` - auto - NP_MKL_LINALG.H:3779 - * - ``LeastSquaresResult lstsq_qr(const NDArray&A, const NDArray&b, Ttolerance = utils::machine_epsilon())`` - LeastSquaresResult - NP_LINALG.H:2236 - :ref:`View ` * - ``LeastSquaresResult lstsq_qr(const NDArray&A, const NDArray&b, Ttolerance = utils::machine_epsilon())`` - LeastSquaresResult - NP_LINALG_WRAPPERS.H:102 - :ref:`View ` * - ``LeastSquaresResult lstsq_svd(const NDArray&A, const NDArray&b, Ttolerance = T{1e-15})`` - LeastSquaresResult - NP_LINALG.H:2353 - :ref:`View ` * - ``LeastSquaresResult lstsq_svd(const NDArray&A, const NDArray&b, Ttolerance = utils::machine_epsilon())`` - LeastSquaresResult - NP_LINALG_WRAPPERS.H:128 - :ref:`View ` * - ``Matrix matmul(const Matrix&a, const Matrix&b)`` - Matrix - NP_MATRIX_OPS.H:24 - :ref:`View ` * - ``auto matmul_accelerated(const NDArray&A, const NDArray&B, Talpha = T{1}, Tbeta = T{0})`` - auto - NP_MKL_LINALG.H:3686 - :ref:`View ` * - ``Matrix matrix_power(const Matrix&matrix, intn)`` - Matrix - NP_MATRIX_OPS.H:71 - :ref:`View ` * - ``auto matrix_power_symmetric_accelerated(const NDArray&matrix, intn)`` - auto - NP_MKL_LINALG.H:3702 - :ref:`View ` * - ``size_t matrix_rank(const NDArray&matrix, Ttolerance = T{-1})`` - size_t - NP_LINALG.H:2079 - :ref:`View ` * - ``size_t matrix_rank(const Matrix&matrix, Ttolerance = T{1e-10})`` - size_t - NP_MATRIX_OPS.H:352 - :ref:`View ` * - ``auto norm(const NDArray&x, std::optionalord = std::nullopt, std::optionalaxis = std::nullopt)`` - auto - NP_LINALG.H:250 - :ref:`View ` * - ``T norm1(const CSRMatrix&A)`` - T - NP_SPARSE.H:87 - :ref:`View ` * - ``T norm_fro(const CSRMatrix&A)`` - T - NP_SPARSE.H:142 - :ref:`View ` * - ``T norm_inf(const CSRMatrix&A)`` - T - NP_SPARSE.H:117 - :ref:`View ` * - ``int normalize_axis(intaxis, size_tndim)`` - int - NP_FFT.H:97 - * - ``int normalize_axis(intaxis, size_tndim)`` - int - NP_ARRAY_UTILS.H:12 - * - ``size_t normalize_index(ssize_tindex, size_tdim_size)`` - size_t - NP_INDEX_TYPES.H:212 - * - ``void normalize_vector(T \*data, size_tn, Ttolerance = machine_epsilon())`` - void - NP_LINALG_UTILS.H:234 - :ref:`View ` * - ``std::pair,NDArray> qr(const NDArray&matrix, boolfull_matrices = true)`` - std::pair,NDArray> - NP_LINALG.H:625 - :ref:`View ` * - ``std::pair,Matrix> qr(const Matrix&matrix)`` - std::pair,Matrix> - NP_MATRIX_OPS.H:98 - :ref:`View ` * - ``auto qr_accelerated(const NDArray&matrix, boolfull_matrices = false)`` - auto - NP_MKL_LINALG.H:3748 - * - ``EigenDecomposition qr_algorithm(const NDArray&matrix, size_tmax_iterations = 1000, Ttolerance = T{1e-10})`` - EigenDecomposition - NP_LINALG.H:1758 - :ref:`View ` * - ``typename std::enable_if,SchurDecomposition>::type qr_algorithm_with_shifts(const NDArray&matrix, typename utils::real_type::typetolerance = utils::machine_epsilon::type>(), size_tmax_iterations = 1000)`` - typename std::enable_if,SchurDecomposition>::type - NP_LINALG.H:2638 - * - ``QRDecomposition qr_decomposition(const NDArray&matrix, boolfull_matrices = true, Ttolerance = utils::machine_epsilon())`` - QRDecomposition - NP_LINALG.H:475 - :ref:`View ` * - ``typename std::enable_if,QRDecomposition>::type qr_decomposition_complex(const NDArray&matrix, boolfull_matrices = true, utils::real_type_ttolerance = utils::machine_epsilon>())`` - typename std::enable_if,QRDecomposition>::type - NP_LINALG.H:723 - :ref:`View ` * - ``QRDecomposition qr_for_eigenvalues(const NDArray&matrix, Ttolerance = utils::machine_epsilon())`` - QRDecomposition - NP_LINALG.H:644 - * - ``typename std::enable_if,QRDecomposition>::type qr_for_eigenvalues_complex(const NDArray&matrix, utils::real_type_ttolerance = utils::machine_epsilon>())`` - typename std::enable_if,QRDecomposition>::type - NP_LINALG.H:817 - * - ``Matrix solve(const Matrix&A, const Matrix&b)`` - Matrix - NP_MATRIX_OPS.H:378 - :ref:`View ` * - ``SolveResult solve(const CSRMatrix&A, const NDArray&b, const SolverConfig &config = SolverConfig())`` - SolveResult - NP_SPARSE.H:295 - :ref:`View ` * - ``auto solve_accelerated(const NDArray&A, const NDArray&b)`` - auto - NP_MKL_LINALG.H:3671 - :ref:`View ` * - ``void solve_upper_triangular(T \*x, const T \*R, const T \*b, size_tn, size_tldr)`` - void - NP_LINALG_UTILS.H:433 - * - ``std::tuple,NDArray,NDArray> svd(const NDArray&matrix, boolfull_matrices = true)`` - std::tuple,NDArray,NDArray> - NP_LINALG.H:2049 - :ref:`View ` * - ``SVDResult svd(const NDArray&matrix, boolfull_matrices = true)`` - SVDResult - NP_LINALG_WRAPPERS.H:45 - :ref:`View ` * - ``std::tuple,std::vector,Matrix> svd(const Matrix&matrix)`` - std::tuple,std::vector,Matrix> - NP_MATRIX_OPS.H:235 - :ref:`View ` * - ``auto svd_accelerated(const NDArray&matrix, boolfull_matrices = true)`` - auto - NP_MKL_LINALG.H:3732 - * - ``SVDDecomposition svd_decomposition(const NDArray&matrix, boolfull_matrices = true, Ttolerance = utils::machine_epsilon(), size_tmax_iterations = 1000)`` - SVDDecomposition - NP_LINALG.H:1915 - :ref:`View ` * - ``T trace(const NDArray&array, ssize_toffset = 0, intaxis1 = 0, intaxis2 = 1)`` - T - NP_LINALG.H:4291 - :ref:`View ` FFT --- .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``NDArray> fft(const NDArray&a, size_tn = 0, intaxis = -1)`` - NDArray> - NP_FFT.H:25 - :ref:`View ` * - ``NDArray> fft(const NDArray>&a, size_tn = 0, intaxis = -1)`` - NDArray> - NP_FFT.H:28 - :ref:`View ` * - ``NDArray> fft(const NDArray&a, size_tn, intaxis)`` - NDArray> - NP_FFT.H:167 - :ref:`View ` * - ``NDArray> fft(const NDArray>&a, size_tn, intaxis)`` - NDArray> - NP_FFT.H:264 - :ref:`View ` * - ``NDArray> fft2(const NDArray&a, const std::vector&s = {}, const std::vector&axes = {-2,-1})`` - NDArray> - NP_FFT.H:42 - :ref:`View ` * - ``NDArray> fft2(const NDArray>&a, const std::vector&s = {}, const std::vector&axes = {-2,-1})`` - NDArray> - NP_FFT.H:45 - :ref:`View ` * - ``NDArray> fft2(const NDArray&a, const std::vector&s, const std::vector&axes)`` - NDArray> - NP_FFT.H:1007 - :ref:`View ` * - ``NDArray> fft2(const NDArray>&a, const std::vector&s, const std::vector&axes)`` - NDArray> - NP_FFT.H:1027 - :ref:`View ` * - ``NDArray> fftn(const NDArray&a, const std::vector&s = {}, const std::vector&axes = {})`` - NDArray> - NP_FFT.H:52 - :ref:`View ` * - ``NDArray> fftn(const NDArray>&a, const std::vector&s = {}, const std::vector&axes = {})`` - NDArray> - NP_FFT.H:55 - :ref:`View ` * - ``NDArray> fftn(const NDArray&a, const std::vector&s, const std::vector&axes)`` - NDArray> - NP_FFT.H:914 - :ref:`View ` * - ``NDArray> fftn(const NDArray>&a, const std::vector&s, const std::vector&axes)`` - NDArray> - NP_FFT.H:945 - :ref:`View ` * - ``NDArray> ifft(const NDArray>&a, size_tn = 0, intaxis = -1)`` - NDArray> - NP_FFT.H:31 - :ref:`View ` * - ``NDArray> ifft(const NDArray>&a, size_tn, intaxis)`` - NDArray> - NP_FFT.H:782 - :ref:`View ` * - ``NDArray> ifft2(const NDArray>&a, const std::vector&s = {}, const std::vector&axes = {-2,-1})`` - NDArray> - NP_FFT.H:48 - :ref:`View ` * - ``NDArray> ifft2(const NDArray>&a, const std::vector&s, const std::vector&axes)`` - NDArray> - NP_FFT.H:1047 - :ref:`View ` * - ``NDArray> ifftn(const NDArray>&a, const std::vector&s = {}, const std::vector&axes = {})`` - NDArray> - NP_FFT.H:58 - :ref:`View ` * - ``NDArray> ifftn(const NDArray>&a, const std::vector&s, const std::vector&axes)`` - NDArray> - NP_FFT.H:976 - :ref:`View ` * - ``NDArray> ihfft(const NDArray&a, size_tn = 0, intaxis = -1)`` - NDArray> - NP_FFT.H:78 - :ref:`View ` * - ``NDArray> ihfft(const NDArray&a, size_tn, intaxis)`` - NDArray> - NP_FFT.H:1247 - :ref:`View ` * - ``NDArray> rfft(const NDArray&a, size_tn = 0, intaxis = -1)`` - NDArray> - NP_FFT.H:35 - :ref:`View ` * - ``NDArray> rfft(const NDArray&a, size_tn, intaxis)`` - NDArray> - NP_FFT.H:428 - :ref:`View ` * - ``NDArray> rfft2(const NDArray&a, const std::vector&s = {}, const std::vector&axes = {})`` - NDArray> - NP_FFT.H:62 - :ref:`View ` * - ``NDArray> rfft2(const NDArray&a, const std::vector&s, const std::vector&axes)`` - NDArray> - NP_FFT.H:1067 - :ref:`View ` * - ``NDArray> rfftn(const NDArray&a, const std::vector&s = {}, const std::vector&axes = {})`` - NDArray> - NP_FFT.H:65 - :ref:`View ` * - ``NDArray> rfftn(const NDArray&a, const std::vector&s, const std::vector&axes)`` - NDArray> - NP_FFT.H:1109 - :ref:`View ` Random ------ .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``T beta(Ta, Tb)`` - T - NP_GAMMA_FUNCTIONS.H:284 - :ref:`View ` * - ``T betainc(Ta, Tb, Tx)`` - T - NP_STATISTICAL.H:39 - * - ``T betaincinv(Ta, Tb, Ty)`` - T - NP_STATISTICAL.H:44 - * - ``T binomial(intn, intk)`` - T - NP_ORTHOGONAL_POLYNOMIALS.H:27 - :ref:`View ` * - ``T gamma(Tx)`` - T - NP_GAMMA_FUNCTIONS.H:269 - :ref:`View ` * - ``T gamma_fallback(Tx)`` - T - NP_GAMMA_FUNCTIONS.H:17 - * - ``T gamma_fallback(Tx)`` - T - NP_GAMMA_FUNCTIONS.H:93 - * - ``T gammainc(Ta, Tx)`` - T - NP_STATISTICAL.H:24 - * - ``T gammaincc(Ta, Tx)`` - T - NP_STATISTICAL.H:16 - * - ``T gammaincc(Ta, Tx)`` - T - NP_STATISTICAL.H:29 - * - ``T gammaincinv(Ta, Ty)`` - T - NP_STATISTICAL.H:34 - * - ``Matrix rand(size_trows, size_tcols, unsignedseed = std::random_device{}())`` - Matrix - NP_MATRIX_FACTORY.H:126 - :ref:`View ` * - ``Matrix rand(size_tn, unsignedseed = std::random_device{}())`` - Matrix - NP_MATRIX_FACTORY.H:145 - :ref:`View ` * - ``Matrix randint(Tlow, Thigh, size_trows, size_tcols, unsignedseed = std::random_device{}())`` - Matrix - NP_MATRIX_FACTORY.H:153 - :ref:`View ` * - ``Matrix randn(size_trows, size_tcols, Tmean = T{0}, Tstddev = T{1}, unsignedseed = std::random_device{}())`` - Matrix - NP_MATRIX_FACTORY.H:172 - :ref:`View ` * - ``Matrix randn(size_tn, Tmean = T{0}, Tstddev = T{1}, unsignedseed = std::random_device{}())`` - Matrix - NP_MATRIX_FACTORY.H:191 - :ref:`View ` * - ``void sample_sort(Iteratorfirst, Iteratorlast, Comparecomp, size_tsample_size = 0)`` - void - NP_SORTING_ALGORITHMS.H:1677 - * - ``void sample_sort(Iteratorfirst, Iteratorlast, size_tsample_size = 0)`` - void - NP_SORTING_ALGORITHMS.H:1750 - * - ``void seed(uint64_tseed)`` - void - NP_RANDOM.H:72 - :ref:`View ` * - ``void seed()`` - void - NP_RANDOM.H:81 - :ref:`View ` * - ``void shuffle(NDArray&array)`` - void - NP_RANDOM.H:580 - :ref:`View ` Sorting ------- .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``int32 count_nonzero(const NDArray&array)`` - int32 - NP_BITWISE_OPS.H:354 - :ref:`View ` * - ``void msort(std::vector&arr)`` - void - NP_SORTING_ALGORITHMS.H:2054 - :ref:`View ` * - ``std::tuple,CharArray,CharArray> partition(const CharArray&a, const std::string &sep)`` - std::tuple,CharArray,CharArray> - NP_CHAR.H:268 - :ref:`View ` * - ``std::tuple,CharArray,CharArray> partition(const CharArray&a, const std::string &sep)`` - std::tuple,CharArray,CharArray> - NP_CHAR_OPS.H:457 - :ref:`View ` * - ``void sort(std::optionalaxis, SortKindkind, boolstable)`` - void - NP_INDEXING_UTILS.H:1203 - :ref:`View ` * - ``void sort_complex(std::vector>&arr)`` - void - NP_SORTING_ALGORITHMS.H:2093 - :ref:`View ` * - ``std::vector> sort_complex(const std::vector>&arr)`` - std::vector> - NP_SORTING_ALGORITHMS.H:2115 - :ref:`View ` * - ``void sort_inplace(NDArray&array, std::optionalaxis = std::nullopt, SortKindkind = SortKind::QUICKSORT, boolstable = false)`` - void - NP_INDEXING_UTILS.H:163 - :ref:`View ` * - ``void sort_strings(StringContainer &strings, StringComparePolicypolicy = StringComparePolicy::LEXICOGRAPHIC, const std::locale &loc = std::locale())`` - void - NP_STRING_SORT.H:406 - :ref:`View ` * - ``void sort_strings(std::vector&strings)`` - void - NP_STRING_SORT.H:447 - :ref:`View ` * - ``void sort_strings_case_insensitive(std::vector&strings)`` - void - NP_STRING_SORT.H:451 - :ref:`View ` * - ``void sort_strings_locale_aware(std::vector&strings, const std::locale &loc = std::locale())`` - void - NP_STRING_SORT.H:459 - * - ``void sort_strings_natural(std::vector&strings)`` - void - NP_STRING_SORT.H:455 - :ref:`View ` * - ``void sort_structured(std::vector&arr, const std::vector>&fields, const std::vector&ascending = {}, boolstable = true)`` - void - NP_SORTING_ALGORITHMS.H:1308 - * - ``void sort_tuple_by_fields(std::vector>&arr, const std::vector&field_indices, const std::vector&ascending = {}, boolstable = true)`` - void - NP_SORTING_ALGORITHMS.H:1363 - Comparison ---------- .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool allclose(const NDArray&a, const NDArray&b, doublertol = 1e-05, doubleatol = 1e-08, boolequal_nan = false)`` - bool - NP_ARRAY_COMPARISON.H:17 - :ref:`View ` * - ``bool allclose(const MaskedArray&a, const MaskedArray&b, doublertol = 1e-5, doubleatol = 1e-8)`` - bool - NP_MASKED_ARRAY.H:1683 - :ref:`View ` * - ``bool array_equal(const NDArray&a, const NDArray&b)`` - bool - NP_ARRAY_COMPARISON.H:155 - :ref:`View ` * - ``bool array_equiv(const NDArray&a, const NDArray&b)`` - bool - NP_ARRAY_COMPARISON.H:194 - :ref:`View ` * - ``bool array_equiv(const NDArray&ar1, const NDArray&ar2)`` - bool - NP_SET_UTILS.H:512 - :ref:`View ` * - ``auto equal(const NDArray&a, const NDArray&b)`` - auto - NP_VECTORIZE.H:412 - :ref:`View ` * - ``auto greater(const NDArray&a, const NDArray&b)`` - auto - NP_VECTORIZE.H:436 - :ref:`View ` * - ``auto greater_equal(const NDArray&a, const NDArray&b)`` - auto - NP_VECTORIZE.H:442 - :ref:`View ` * - ``auto less(const NDArray&a, const NDArray&b)`` - auto - NP_VECTORIZE.H:424 - :ref:`View ` * - ``auto less_equal(const NDArray&a, const NDArray&b)`` - auto - NP_VECTORIZE.H:430 - :ref:`View ` * - ``auto not_equal(const NDArray&a, const NDArray&b)`` - auto - NP_VECTORIZE.H:418 - :ref:`View ` * - ``bool operator==(const datetime64 &other)`` - bool - NP_DATETIME64.H:128 - * - ``NDArray operator==(const NDArray&lhs, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:143 - * - ``NDArray operator==(const NDArray&lhs, const T &scalar)`` - NDArray - NP_OPERATORS.H:168 - * - ``NDArray operator==(const T &scalar, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:181 - * - ``bool operator==(const timedelta64 &other)`` - bool - NP_TIMEDELTA64.H:168 - Logical ------- .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool all(const NDArray&array)`` - bool - NP_LOGIC_UTILS.H:156 - :ref:`View ` * - ``bool all(const MaskedArray&array)`` - bool - NP_MASKED_ARRAY.H:2041 - :ref:`View ` * - ``bool all_convertible_to(const std::vector&objects)`` - bool - NP_OBJECT_UTILS.H:283 - * - ``bool allequal(const MaskedArray&a, const MaskedArray&b)`` - bool - NP_MASKED_ARRAY.H:1721 - :ref:`View ` * - ``bool alltrue(const MaskedArray&array)`` - bool - NP_MASKED_ARRAY.H:2002 - :ref:`View ` * - ``bool alltrue(const NDArray&array)`` - bool - NP_NUMPY_WRAPPERS.H:358 - :ref:`View ` * - ``bool any(const NDArray&array)`` - bool - NP_LOGIC_UTILS.H:29 - :ref:`View ` * - ``bool any(const MaskedArray&array)`` - bool - NP_MASKED_ARRAY.H:2051 - :ref:`View ` * - ``bool iscomplex(Tvalue)`` - bool - NP_MATH_UTILS_SQRT.H:6958 - :ref:`View ` * - ``bool iscomplexobj(T)`` - bool - NP_MATH_UTILS_SQRT.H:7006 - :ref:`View ` * - ``bool iscomplexobj(const NDArray&)`` - bool - NP_MATH_UTILS_SQRT.H:7012 - :ref:`View ` * - ``bool isfinite(Tvalue)`` - bool - NP_MATH_UTILS_SQRT.H:6600 - :ref:`View ` * - ``bool isinf(Tvalue)`` - bool - NP_MATH_UTILS_SQRT.H:6560 - :ref:`View ` * - ``bool isnan(Tvalue)`` - bool - NP_MATH_UTILS_SQRT.H:6520 - :ref:`View ` * - ``bool isneginf(floatvalue)`` - bool - NP_MATH_UTILS_SQRT.H:6676 - :ref:`View ` * - ``bool isneginf(doublevalue)`` - bool - NP_MATH_UTILS_SQRT.H:6680 - :ref:`View ` * - ``bool isposinf(floatvalue)`` - bool - NP_MATH_UTILS_SQRT.H:6640 - :ref:`View ` * - ``bool isposinf(doublevalue)`` - bool - NP_MATH_UTILS_SQRT.H:6644 - :ref:`View ` * - ``bool isreal(Tvalue)`` - bool - NP_MATH_UTILS_SQRT.H:6924 - :ref:`View ` * - ``bool isrealobj(T)`` - bool - NP_MATH_UTILS_SQRT.H:6992 - :ref:`View ` * - ``bool isrealobj(const NDArray&)`` - bool - NP_MATH_UTILS_SQRT.H:6998 - :ref:`View ` * - ``bool isscalar(const NDArray&array)`` - bool - NP_ARRAY_INFO.H:172 - :ref:`View ` Set Operations -------------- .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``std::tuple,NDArray,NDArray> intersect1d_indices(const NDArray&ar1, const NDArray&ar2, boolassume_unique = false)`` - std::tuple,NDArray,NDArray> - NP_SET_UTILS.H:399 - * - ``UniqueAll unique_all(const NDArray&array, intaxis = -1, boolequal_nan = false)`` - UniqueAll - NP_SET_UTILS.H:185 - :ref:`View ` * - ``UniqueCounts unique_counts(const NDArray&array, intaxis = -1, boolequal_nan = false)`` - UniqueCounts - NP_SET_UTILS.H:191 - :ref:`View ` * - ``UniqueResult unique_full(const NDArray&array, boolreturn_index = false, boolreturn_inverse = false, boolreturn_counts = false, intaxis = -1, boolequal_nan = false)`` - UniqueResult - NP_SET_UTILS.H:101 - :ref:`View ` * - ``UniqueInverse unique_inverse(const NDArray&array, intaxis = -1, boolequal_nan = false)`` - UniqueInverse - NP_SET_UTILS.H:197 - :ref:`View ` * - ``UniqueValues unique_values(const NDArray&array, intaxis = -1, boolequal_nan = false)`` - UniqueValues - NP_SET_UTILS.H:203 - :ref:`View ` Joining / Splitting ------------------- .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``RecordArray append_fields(const RecordArray &base, const std::vector&names, const std::vector>>&data, const std::vector&fill_values = {}, boolusemask = false, boolasrecarray = true)`` - RecordArray - NP_RECFUNCTIONS.H:553 - :ref:`View ` * - ``std::vector> array_split(const NDArray&array, const std::variant>&indices_or_sections, intaxis = 0)`` - std::vector> - NP_ARRAY_UTILS.H:403 - :ref:`View ` * - ``std::vector> dsplit(const NDArray&array, const std::variant>&indices_or_sections)`` - std::vector> - NP_ARRAY_UTILS.H:392 - :ref:`View ` * - ``std::vector> hsplit(const NDArray&array, const std::variant>&indices_or_sections)`` - std::vector> - NP_ARRAY_UTILS.H:368 - :ref:`View ` * - ``std::vector> hsplit(const MaskedArray&ma, intsections)`` - std::vector> - NP_MASKED_ARRAY.H:4680 - :ref:`View ` * - ``void insertion_sort(Iteratorfirst, Iteratorlast)`` - void - NP_SORTING_ALGORITHMS.H:224 - * - ``void insertion_sort(Iteratorfirst, Iteratorlast, Comparecomp)`` - void - NP_SORTING_ALGORITHMS.H:271 - * - ``std::vector> split(const NDArray&array, const std::variant>&indices_or_sections, intaxis = 0)`` - std::vector> - NP_ARRAY_UTILS.H:307 - :ref:`View ` * - ``std::vector> split(const CharArray&a, const std::string &sep = "", intmaxsplit = -1)`` - std::vector> - NP_CHAR.H:248 - :ref:`View ` * - ``std::vector> split(const CharArray&a, const std::string &sep = "", intmaxsplit = -1)`` - std::vector> - NP_CHAR_OPS.H:138 - :ref:`View ` * - ``std::vector> splitlines(const CharArray&a, boolkeepends = false)`` - std::vector> - NP_CHAR.H:258 - :ref:`View ` * - ``std::vector> splitlines(const CharArray&a, boolkeepends = false)`` - std::vector> - NP_CHAR_OPS.H:203 - :ref:`View ` * - ``RecordArray stack_arrays(const std::vector&arrays, booldefaults = false, boolusemask = false, boolasrecarray = true, boolautoconvert = false)`` - RecordArray - NP_RECFUNCTIONS.H:581 - :ref:`View ` * - ``std::vector> vsplit(const NDArray&array, const std::variant>&indices_or_sections)`` - std::vector> - NP_ARRAY_UTILS.H:381 - :ref:`View ` * - ``std::vector> vsplit(const MaskedArray&ma, intsections)`` - std::vector> - NP_MASKED_ARRAY.H:4693 - :ref:`View ` Type Handling ------------- .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``CharArray asarray(const CharArray&a)`` - CharArray - NP_CHAR.H:49 - :ref:`View ` * - ``NUMPYCORE_API bool can_cast(DTypefrom, DTypeto, CastingModecasting = CastingMode::SAFE)`` - NUMPYCORE_API bool - NP_DTYPE_UTILS.H:60 - :ref:`View ` * - ``NUMPYCORE_API DType common_type(const std::vector&dtypes)`` - NUMPYCORE_API DType - NP_DTYPE_UTILS.H:101 - :ref:`View ` * - ``ObjectTypeId common_type(const std::vector&objects)`` - ObjectTypeId - NP_OBJECT_UTILS.H:230 - :ref:`View ` * - ``void copy_lower_triangular(const T \*source, T \*dest, size_tn, size_tsrc_lda, size_tdest_lda)`` - void - NP_LINALG_UTILS.H:553 - * - ``float32 copysign(float32x1, float32x2)`` - float32 - NP_MATH_UTILS_SQRT.H:5123 - :ref:`View ` * - ``float64 copysign(float64x1, float64x2)`` - float64 - NP_MATH_UTILS_SQRT.H:5158 - :ref:`View ` * - ``void copyto(NDArray&dst, const NDArray&src, const std::optional>&where = std::nullopt)`` - void - NP_ARRAY_MANIPULATION.H:437 - :ref:`View ` * - ``NUMPYCORE_API DType promote_types(DTypetype1, DTypetype2)`` - NUMPYCORE_API DType - NP_DTYPE_UTILS.H:75 - :ref:`View ` * - ``NUMPYCORE_API DType result_type(const std::vector&dtypes)`` - NUMPYCORE_API DType - NP_DTYPE_UTILS.H:88 - :ref:`View ` Special Functions ----------------- .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``T digamma(Tx)`` - T - NP_GAMMA_FUNCTIONS.H:279 - :ref:`View ` * - ``T digamma_fallback(Tx)`` - T - NP_GAMMA_FUNCTIONS.H:19 - * - ``T digamma_fallback(Tx)`` - T - NP_GAMMA_FUNCTIONS.H:103 - * - ``T ellipe(Tm)`` - T - NP_ELLIPTIC.H:55 - :ref:`View ` * - ``T ellipeinc(Tphi, Tm)`` - T - NP_ELLIPTIC.H:113 - :ref:`View ` * - ``T ellipk(Tm)`` - T - NP_ELLIPTIC.H:12 - :ref:`View ` * - ``T ellipkinc(Tphi, Tm)`` - T - NP_ELLIPTIC.H:89 - :ref:`View ` * - ``T erf(Tx)`` - T - NP_ERROR_FUNCTIONS.H:380 - :ref:`View ` * - ``T erf_fallback(Tx)`` - T - NP_ERROR_FUNCTIONS.H:17 - * - ``T erf_fallback(Tx)`` - T - NP_ERROR_FUNCTIONS.H:319 - * - ``T erf_series(Tx)`` - T - NP_ERROR_FUNCTIONS.H:230 - * - ``T erfc(Tx)`` - T - NP_ERROR_FUNCTIONS.H:385 - :ref:`View ` * - ``T erfc_continued_fraction(Tx)`` - T - NP_ERROR_FUNCTIONS.H:250 - * - ``T erfc_fallback(Tx)`` - T - NP_ERROR_FUNCTIONS.H:18 - * - ``T erfc_fallback(Tx)`` - T - NP_ERROR_FUNCTIONS.H:324 - * - ``T erfcinv(Tx)`` - T - NP_ERROR_FUNCTIONS.H:405 - :ref:`View ` * - ``T erfcinv_fallback(Tx)`` - T - NP_ERROR_FUNCTIONS.H:22 - * - ``T erfcinv_fallback(Ty)`` - T - NP_ERROR_FUNCTIONS.H:371 - * - ``T erfcx(Tx)`` - T - NP_ERROR_FUNCTIONS.H:390 - :ref:`View ` * - ``T erfcx_fallback(Tx)`` - T - NP_ERROR_FUNCTIONS.H:19 - * - ``T erfcx_fallback(Tx)`` - T - NP_ERROR_FUNCTIONS.H:329 - * - ``T erfcx_rational(Tx)`` - T - NP_ERROR_FUNCTIONS.H:284 - * - ``T erfi(Tx)`` - T - NP_ERROR_FUNCTIONS.H:395 - :ref:`View ` * - ``T erfi_fallback(Tx)`` - T - NP_ERROR_FUNCTIONS.H:20 - * - ``T erfi_fallback(Tx)`` - T - NP_ERROR_FUNCTIONS.H:334 - * - ``T erfinv(Tx)`` - T - NP_ERROR_FUNCTIONS.H:400 - :ref:`View ` * - ``T erfinv_fallback(Tx)`` - T - NP_ERROR_FUNCTIONS.H:21 - * - ``T erfinv_fallback(Ty)`` - T - NP_ERROR_FUNCTIONS.H:366 - * - ``T erfinv_rational(Ty)`` - T - NP_ERROR_FUNCTIONS.H:298 - * - ``T factorial(Tn)`` - T - NP_GAMMA_FUNCTIONS.H:294 - :ref:`View ` * - ``T factorial2(Tn)`` - T - NP_GAMMA_FUNCTIONS.H:299 - :ref:`View ` * - ``T i0(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:265 - :ref:`View ` * - ``T i0(Tx)`` - T - NP_SPHERICAL_BESSEL.H:19 - :ref:`View ` * - ``T i0_fallback(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:22 - * - ``T i0_fallback(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:211 - * - ``T i1(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:270 - :ref:`View ` * - ``T i1(Tx)`` - T - NP_SPHERICAL_BESSEL.H:20 - :ref:`View ` * - ``T i1_fallback(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:23 - * - ``T i1_fallback(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:216 - * - ``T j0(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:245 - :ref:`View ` * - ``T j0(Tx)`` - T - NP_SPHERICAL_BESSEL.H:13 - :ref:`View ` * - ``T j0_fallback(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:18 - * - ``T j0_fallback(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:191 - * - ``T j1(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:250 - :ref:`View ` * - ``T j1(Tx)`` - T - NP_SPHERICAL_BESSEL.H:14 - :ref:`View ` * - ``T j1_fallback(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:19 - * - ``T j1_fallback(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:196 - * - ``T jn(intn, Tx)`` - T - NP_BESSEL_FUNCTIONS.H:275 - * - ``T jn(intn, Tx)`` - T - NP_SPHERICAL_BESSEL.H:15 - * - ``T k0(Tx)`` - T - NP_SPHERICAL_BESSEL.H:22 - * - ``T k1(Tx)`` - T - NP_SPHERICAL_BESSEL.H:23 - * - ``T lgamma(Tx)`` - T - NP_GAMMA_FUNCTIONS.H:274 - :ref:`View ` * - ``T lgamma_fallback(Tx)`` - T - NP_GAMMA_FUNCTIONS.H:18 - * - ``T lgamma_fallback(Tx)`` - T - NP_GAMMA_FUNCTIONS.H:98 - * - ``T y0(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:255 - :ref:`View ` * - ``T y0(Tx)`` - T - NP_SPHERICAL_BESSEL.H:16 - :ref:`View ` * - ``T y0_fallback(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:20 - * - ``T y0_fallback(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:201 - * - ``T y1(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:260 - :ref:`View ` * - ``T y1(Tx)`` - T - NP_SPHERICAL_BESSEL.H:17 - :ref:`View ` * - ``T y1_fallback(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:21 - * - ``T y1_fallback(Tx)`` - T - NP_BESSEL_FUNCTIONS.H:206 - * - ``T yn(intn, Tx)`` - T - NP_BESSEL_FUNCTIONS.H:280 - * - ``T yn(intn, Tx)`` - T - NP_SPHERICAL_BESSEL.H:18 - * - ``T zeta(Ts)`` - T - NP_MISCELLANEOUS.H:11 - :ref:`View ` * - ``T zetac(Ts)`` - T - NP_MISCELLANEOUS.H:58 - :ref:`View ` I/O --- .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``RecordArray fromfile(const std::string &filename, std::shared_ptrdtype, const std::string &separator = ",", size_tcount = SIZE_MAX, boolskip_header = false)`` - RecordArray - NP_REC_CREATION.H:436 - :ref:`View ` * - ``RecordArray fromstring(const std::string &data, std::shared_ptrdtype, const std::string &separator = ",", size_tcount = SIZE_MAX)`` - RecordArray - NP_REC_CREATION.H:429 - :ref:`View ` * - ``auto load_enhanced(const std::string &filename, const std::string &mmap_mode = "")`` - auto - NP_IO_UTILS.H:939 - * - ``void \* load_library(const std::string &libname)`` - void \* - NP_CTYPES_INTEROP.H:171 - :ref:`View ` * - ``MemoryMappedArray load_memmap(const std::string &filename, const std::string &mode = "r")`` - MemoryMappedArray - NP_MEMMAP.H:646 - :ref:`View ` * - ``auto load_memmap_auto(const std::string &filename, const std::string &mode = "r")`` - auto - NP_MEMMAP.H:676 - * - ``NpzFile load_npz(const std::string &filename)`` - NpzFile - NP_NPZ_UTILS.H:584 - :ref:`View ` * - ``void save(const NDArray&array, const std::string &filename)`` - void - NP_IO_UTILS.H:95 - :ref:`View ` * - ``void save_auto(const NDArray&array, const std::string &filename)`` - void - NP_IO_UTILS.H:763 - :ref:`View ` * - ``void savetxt(const NDArray&array, const std::string &filename, const std::string &delimiter = ",", const std::string &fmt = "%.18e")`` - void - NP_IO_UTILS.H:281 - :ref:`View ` * - ``void savez(const std::string &filename, Args &&...args)`` - void - NP_NPZ_UTILS.H:562 - :ref:`View ` * - ``void savez_compressed(const std::string &filename, Args &&...args)`` - void - NP_NPZ_UTILS.H:578 - :ref:`View ` * - ``void savez_compressed_level(const std::string &filename, intcompression_level, Args &&...args)`` - void - NP_NPZ_UTILS.H:570 - * - ``size_t to_1d_index(size_trow, size_tcol, size_tn_cols)`` - size_t - NP_LINALG_UTILS.H:141 - :ref:`View ` * - ``NDArrayAdvanced to_advanced(const NDArray&array)`` - NDArrayAdvanced - NP_NDARRAY_ADVANCED.H:257 - * - ``CSRMatrix to_csr()`` - CSRMatrix - NP_SPARSE_CONVERT.H:79 - :ref:`View ` * - ``DLManagedTensor \* to_dlpack(const NDArray&arr)`` - DLManagedTensor \* - NP_DLPACK.H:394 - * - ``std::string to_lower(const std::string &str)`` - std::string - NP_INTROSPECTION.H:96 - :ref:`View ` * - ``str\_ to_lower(const str\_&s)`` - str\_ - NP_STRING_TYPES.H:234 - :ref:`View ` * - ``double to_numeric(const str\_&s)`` - double - NP_STRING_TYPES.H:221 - :ref:`View ` * - ``std::string to_subscript(size_tn)`` - std::string - NP_POLYNOMIAL.H:78 - * - ``std::string to_superscript(size_tn)`` - std::string - NP_POLYNOMIAL.H:55 - * - ``str\_ to_upper(const str\_&s)`` - str\_ - NP_STRING_TYPES.H:227 - :ref:`View ` * - ``void tofile(const NDArray&array, const std::string &filename, const std::string &sep = "")`` - void - NP_IO_UTILS.H:832 - :ref:`View ` * - ``std::string tolist()`` - std::string - NP_NDARRAY.H:1135 - :ref:`View ` * - ``std::string tostring(const NDArray&array)`` - std::string - NP_IO_UTILS.H:928 - :ref:`View ` Other ----- .. list-table:: :widths: 45 25 15 15 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``NDArray(const std::vector&shape, const T &fill_value)`` - - NP_NDARRAY.H:424 - :ref:`View ` * - ``NDArray(T \*external_data, const std::vector&shape, std::shared_ptrowner)`` - - NP_NDARRAY.H:482 - :ref:`View ` * - ``datetime64 NaT(DateTimeUnitunit)`` - datetime64 - NP_DATETIME64.H:232 - :ref:`View ` * - ``timedelta64 NaT(DateTimeUnitunit)`` - timedelta64 - NP_TIMEDELTA64.H:272 - :ref:`View ` * - ``PARDISOSolver(const PARDISOSolver &)`` - - NP_PARDISO.H:169 - * - ``noexcept PARDISOSolver(PARDISOSolver &&other)`` - noexcept - NP_PARDISO.H:173 - * - ``Signature(const std::string &sig_str)`` - - NP_VECTORIZE_UTILS.H:368 - * - ``void acos_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:397 - * - ``void acosh_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:645 - * - ``void adaptive_cache_sort(Iteratorfirst, Iteratorlast, Comparecomp)`` - void - NP_CACHE_AWARE_SORT.H:340 - :ref:`View ` * - ``void adaptive_cache_sort(Iteratorfirst, Iteratorlast)`` - void - NP_CACHE_AWARE_SORT.H:364 - :ref:`View ` * - ``void adaptive_cache_sort(Container &container, Comparecomp)`` - void - NP_CACHE_AWARE_SORT.H:371 - :ref:`View ` * - ``void adaptive_cache_sort(Container &container)`` - void - NP_CACHE_AWARE_SORT.H:376 - :ref:`View ` * - ``void adaptive_counting_sort(std::vector&arr)`` - void - NP_SORTING_ALGORITHMS.H:1578 - * - ``void adaptive_ipp_sort(T \*data, size_tn, boolascending = true)`` - void - NP_IPP_SORT.H:635 - * - ``void adaptive_ipp_sort(std::vector&data, boolascending = true)`` - void - NP_IPP_SORT.H:663 - * - ``void adaptive_sort(Iteratorfirst, Iteratorlast)`` - void - NP_SORTING_ALGORITHMS.H:593 - :ref:`View ` * - ``IndexedArrayResult advanced_index(const NDArray&array, const IndexExpr &expr)`` - IndexedArrayResult - NP_ADVANCED_INDEXING.H:356 - * - ``void advanced_sort(Iteratorfirst, Iteratorlast, SortKindkind = SortKind::QUICKSORT)`` - void - NP_SORTING_ALGORITHMS.H:1104 - :ref:`View ` * - ``void advanced_sort(Iteratorfirst, Iteratorlast, Comparecomp, SortKindkind = SortKind::QUICKSORT)`` - void - NP_SORTING_ALGORITHMS.H:1141 - :ref:`View ` * - ``void advanced_sort(std::vector&arr, SortKindkind = SortKind::QUICKSORT)`` - void - NP_SORTING_ALGORITHMS.H:1160 - :ref:`View ` * - ``auto airy(const NDArray&x)`` - auto - NP_AIRY_FUNCTIONS.H:246 - :ref:`View ` * - ``T airy_ai(Tx)`` - T - NP_AIRY_FUNCTIONS.H:174 - :ref:`View ` * - ``auto airy_ai(const NDArray&x)`` - auto - NP_AIRY_FUNCTIONS.H:263 - :ref:`View ` * - ``T airy_bi(Tx)`` - T - NP_AIRY_FUNCTIONS.H:180 - :ref:`View ` * - ``auto airy_bi(const NDArray&x)`` - auto - NP_AIRY_FUNCTIONS.H:276 - :ref:`View ` * - ``auto airye(const NDArray&x)`` - auto - NP_AIRY_FUNCTIONS.H:289 - :ref:`View ` * - ``size_t align_to_cache_line(size_tsize)`` - size_t - NP_MEMORY_POOL.H:272 - * - ``T amax(const MaskedArray&array)`` - T - NP_MASKED_ARRAY.H:1984 - :ref:`View ` * - ``T amax(const NDArray&array)`` - T - NP_NUMPY_WRAPPERS.H:345 - :ref:`View ` * - ``T amin(const MaskedArray&array)`` - T - NP_MASKED_ARRAY.H:1993 - :ref:`View ` * - ``T amin(const NDArray&array)`` - T - NP_NUMPY_WRAPPERS.H:351 - :ref:`View ` * - ``void analyze(const CSRMatrix&A)`` - void - NP_PARDISO.H:244 - * - ``auto -> NDArray, float32, typename std::conditional, float64, typename std::conditional, longdouble, T>::type>::type>::type> angle(const NDArray&array, booldeg = false)`` - auto -> NDArray, float32, typename std::conditional, float64, typename std::conditional, longdouble, T>::type>::type>::type> - NP_COMPLEX_UTILS.H:100 - :ref:`View ` * - ``void apply_block_reflector_left(const HouseholderBlock&block, NDArray&C)`` - void - NP_LINALG_UTILS.H:1478 - * - ``void apply_block_reflector_right(NDArray&C, const HouseholderBlock&block)`` - void - NP_LINALG_UTILS.H:1525 - * - ``void apply_complex_householder_left(T \*A, const T \*v, Ttau, size_tm, size_tn, size_tlda)`` - void - NP_LINALG_UTILS.H:903 - * - ``void apply_givens_rotation(T &a, T &b, Tc, Ts)`` - void - NP_LINALG.H:1887 - * - ``void apply_householder_left(T \*matrix, size_trows, size_tcols, const HouseholderReflector&reflector, size_tstart_row = 0)`` - void - NP_LINALG_UTILS.H:323 - * - ``void apply_householder_to_vector(T \*y, const T \*x, size_tn, const HouseholderReflector&reflector, size_tstart_idx = 0)`` - void - NP_LINALG_UTILS.H:348 - * - ``void apply_qt_to_vector(T \*result, const T \*b, size_tm, const std::vector>&reflectors)`` - void - NP_LINALG_UTILS.H:395 - * - ``bool areBroadcastable(const std::vector&shape1, const std::vector&shape2)`` - bool - NP_VECTORIZE_UTILS.H:124 - * - ``bool are_shapes_compatible_for_concat(const std::vector>&shapes, intaxis)`` - bool - NP_ARRAY_UTILS.H:23 - * - ``auto argmax(const NDArray&array, std::optionalaxis = std::nullopt)`` - auto - NP_INDEXING_UTILS.H:346 - :ref:`View ` * - ``size_t argmax(const MaskedArray&ma)`` - size_t - NP_MASKED_ARRAY.H:4396 - :ref:`View ` * - ``auto argmin(const NDArray&array, std::optionalaxis = std::nullopt)`` - auto - NP_INDEXING_UTILS.H:436 - :ref:`View ` * - ``size_t argmin(const MaskedArray&ma)`` - size_t - NP_MASKED_ARRAY.H:4424 - :ref:`View ` * - ``ArnoldiResult arnoldi_eigenvalues(const NDArray&matrix, size_tnum_eigenvalues = 6, typename real_type::typetolerance = 1e-12)`` - ArnoldiResult - NP_LINALG_UTILS.H:2428 - * - ``ArnoldiResult arnoldi_iteration(const SparseMatrix&A, size_tkrylov_dim = 50, typename real_type::typetolerance = 1e-12, size_tmax_iterations = 1000)`` - ArnoldiResult - NP_LINALG_UTILS.H:2326 - * - ``int8_t around(const int8_t &x, intdecimals = 0)`` - int8_t - NP_MATH_UTILS_SQRT.H:1146 - :ref:`View ` * - ``int16_t around(const int16_t &x, intdecimals = 0)`` - int16_t - NP_MATH_UTILS_SQRT.H:1147 - :ref:`View ` * - ``int32_t around(const int32_t &x, intdecimals = 0)`` - int32_t - NP_MATH_UTILS_SQRT.H:1148 - :ref:`View ` * - ``int64_t around(const int64_t &x, intdecimals = 0)`` - int64_t - NP_MATH_UTILS_SQRT.H:1149 - :ref:`View ` * - ``uint8_t around(const uint8_t &x, intdecimals = 0)`` - uint8_t - NP_MATH_UTILS_SQRT.H:1150 - :ref:`View ` * - ``uint16_t around(const uint16_t &x, intdecimals = 0)`` - uint16_t - NP_MATH_UTILS_SQRT.H:1151 - :ref:`View ` * - ``uint32_t around(const uint32_t &x, intdecimals = 0)`` - uint32_t - NP_MATH_UTILS_SQRT.H:1152 - :ref:`View ` * - ``uint64_t around(const uint64_t &x, intdecimals = 0)`` - uint64_t - NP_MATH_UTILS_SQRT.H:1153 - :ref:`View ` * - ``bool\_ around(const bool\_ &x, intdecimals = 0)`` - bool\_ - NP_MATH_UTILS_SQRT.H:1154 - :ref:`View ` * - ``float32 around(const float32 &x, intdecimals = 0)`` - float32 - NP_MATH_UTILS_SQRT.H:1155 - :ref:`View ` * - ``double around(const double &x, intdecimals = 0)`` - double - NP_MATH_UTILS_SQRT.H:1156 - :ref:`View ` * - ``complex64 around(const complex64 &x, intdecimals = 0)`` - complex64 - NP_MATH_UTILS_SQRT.H:1157 - :ref:`View ` * - ``complex128 around(const complex128 &x, intdecimals = 0)`` - complex128 - NP_MATH_UTILS_SQRT.H:1158 - :ref:`View ` * - ``CharArray array(const std::vector&strings, const std::vector&shape = {})`` - CharArray - NP_CHAR.H:24 - :ref:`View ` * - ``std::string array2string(const NDArray&array, intprecision = -1, const std::string &separator = ", ", const std::string &prefix = "", const std::string &suffix = "", const std::string &floatmode = "", size_tmax_line_width = 0, size_tthreshold = 0, size_tedgeitems = 0)`` - std::string - NP_IO_STRING.H:380 - :ref:`View ` * - ``std::string array2string_impl(const NDArray&array, const PrintOptions &opts, const std::string &prefix = "", const std::string &suffix = "")`` - std::string - NP_IO_STRING.H:277 - * - ``void array_function_dispatch(Funcfunc)`` - void - NP_CHAR.H:405 - :ref:`View ` * - ``std::string array_repr(const NDArray&array)`` - std::string - NP_IO_STRING.H:416 - :ref:`View ` * - ``std::string array_str(const NDArray&array)`` - std::string - NP_IO_STRING.H:404 - :ref:`View ` * - ``std::string array_to_string(const NDArray&arr)`` - std::string - NP_INTROSPECTION.H:356 - * - ``const T \* as_ctypes(const NDArray&array)`` - const T \* - NP_CTYPES_INTEROP.H:48 - :ref:`View ` * - ``T \* as_ctypes(NDArray&array)`` - T \* - NP_CTYPES_INTEROP.H:67 - :ref:`View ` * - ``std::string as_ctypes_type()`` - std::string - NP_CTYPES_INTEROP.H:87 - :ref:`View ` * - ``std::string as_ctypes_type(const NDArray&array)`` - std::string - NP_CTYPES_INTEROP.H:142 - :ref:`View ` * - ``double as_double(const object\_ &obj, doublefallback = 0.0)`` - double - NP_OBJECT_UTILS.H:400 - * - ``int64_t as_int64(const object\_ &obj, int64_tfallback = 0)`` - int64_t - NP_OBJECT_UTILS.H:407 - * - ``NDArray> asbytes(const NDArray&array)`` - NDArray> - NP_STRING_OPERATIONS.H:1184 - :ref:`View ` * - ``void asin_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:356 - * - ``void asinh_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:604 - * - ``Matrix asmatrix(const NDArray&array)`` - Matrix - NP_MATRIX_FACTORY.H:298 - :ref:`View ` * - ``void avx2_bitonic_sort_8_i32(__m256i &v)`` - void - NP_SIMD_SORT.H:200 - * - ``size_t avx2_partition_i32(int32_t \*arr, size_tn, int32_tpivot)`` - size_t - NP_SIMD_SORT.H:229 - * - ``BalancingResult balance_matrix(const NDArray&matrix)`` - BalancingResult - NP_LINALG_UTILS.H:1316 - :ref:`View ` * - ``std::shared_ptr> base(const NDArray&array)`` - std::shared_ptr> - NP_ARRAY_INFO.H:132 - :ref:`View ` * - ``std::string base_repr(int64_tnumber, intbase = 2, intpadding = 0)`` - std::string - NP_BITWISE_OPS.H:443 - :ref:`View ` * - ``T bei(Tx)`` - T - NP_KELVIN_FUNCTIONS.H:131 - :ref:`View ` * - ``auto bei(const NDArray&x)`` - auto - NP_KELVIN_FUNCTIONS.H:290 - :ref:`View ` * - ``T beip(Tx)`` - T - NP_KELVIN_FUNCTIONS.H:217 - :ref:`View ` * - ``auto beip(const NDArray&x)`` - auto - NP_KELVIN_FUNCTIONS.H:342 - :ref:`View ` * - ``CosineBenchmarkResult benchmark_cosine(size_tarray_size)`` - CosineBenchmarkResult - NP_TRIGONOMETRIC.H:102 - :ref:`View ` * - ``T ber(Tx)`` - T - NP_KELVIN_FUNCTIONS.H:106 - :ref:`View ` * - ``auto ber(const NDArray&x)`` - auto - NP_KELVIN_FUNCTIONS.H:277 - :ref:`View ` * - ``T berp(Tx)`` - T - NP_KELVIN_FUNCTIONS.H:202 - :ref:`View ` * - ``auto berp(const NDArray&x)`` - auto - NP_KELVIN_FUNCTIONS.H:329 - :ref:`View ` * - ``std::pair,ConvergenceInfo> bicgstab(const CSRMatrix&A, const NDArray&b, const NDArray\*x0 = nullptr, Ttol = T{1e-6}, intmax_iter = 1000, IterationCallbackcallback = nullptr)`` - std::pair,ConvergenceInfo> - NP_ITERATIVE.H:497 - :ref:`View ` * - ``void binary_insertion_sort(Iteratorfirst, Iteratorlast, Iteratorstart)`` - void - NP_SORTING_ALGORITHMS.H:718 - * - ``void binary_insertion_sort(Iteratorfirst, Iteratorlast, Iteratorstart, Comparecomp)`` - void - NP_SORTING_ALGORITHMS.H:746 - * - ``std::string binary_repr(int64_tnumber, std::optionalwidth = std::nullopt)`` - std::string - NP_BITWISE_OPS.H:489 - :ref:`View ` * - ``void bind_all_masked_array_classes(py::module &ma)`` - void - MASKED_ARRAY_CLASS.H:625 - * - ``void bind_masked_array_class(py::module &m, const std::string &class_name)`` - void - MASKED_ARRAY_CLASS.H:50 - * - ``void bitonic_sort_small_i32(int32_t \*arr, size_tn)`` - void - NP_SIMD_SORT.H:214 - * - ``Matrix block_diag(const std::vector>&matrices)`` - Matrix - NP_MATRIX_FACTORY.H:248 - * - ``HessenbergReduction blocked_hessenberg_reduction(const NDArray&matrix, size_tblock_size = 32)`` - HessenbergReduction - NP_LINALG_UTILS.H:1666 - :ref:`View ` * - ``numpy::linalg::QRDecomposition blocked_qr_decomposition(const NDArray&matrix, size_tblock_size = 64, typename real_type::typetolerance = machine_epsilon::type>())`` - numpy::linalg::QRDecomposition - NP_LINALG_UTILS.H:1572 - :ref:`View ` * - ``void blocked_quicksort(Iteratorfirst, Iteratorlast, Comparecomp)`` - void - NP_CACHE_AWARE_SORT.H:222 - :ref:`View ` * - ``void bucket_sort(std::vector&arr, size_tnum_buckets = 0)`` - void - NP_SORTING_ALGORITHMS.H:1601 - :ref:`View ` * - ``int64_t businessDayCount(const datetime64 &start, const datetime64 &end, const Weekmask &weekmask, const std::set&holidays = {})`` - int64_t - NP_DATETIME_UTILS.H:228 - :ref:`View ` * - ``int64_t businessDayCount(const datetime64 &start, const datetime64 &end, const std::set&holidays = {})`` - int64_t - NP_DATETIME_UTILS.H:255 - :ref:`View ` * - ``datetime64 businessDayOffset(const datetime64 &date, int64_toffset, RollModeroll, const Weekmask &weekmask, const std::set&holidays = {})`` - datetime64 - NP_DATETIME_UTILS.H:261 - :ref:`View ` * - ``datetime64 businessDayOffset(const datetime64 &date, int64_toffset, const std::set&holidays = {})`` - datetime64 - NP_DATETIME_UTILS.H:300 - :ref:`View ` * - ``size_t byte_span(const std::pair&bounds)`` - size_t - NP_ARRAY_INFO.H:352 - :ref:`View ` * - ``Iterator cache_aware_partition(Iteratorfirst, Iteratorlast, Comparecomp)`` - Iterator - NP_CACHE_AWARE_SORT.H:116 - * - ``void cache_aware_quicksort(Iteratorfirst, Iteratorlast, Comparecomp)`` - void - NP_CACHE_AWARE_SORT.H:202 - * - ``void cache_aware_quicksort(Iteratorfirst, Iteratorlast)`` - void - NP_CACHE_AWARE_SORT.H:212 - * - ``void cache_aware_quicksort_impl(Iteratorfirst, Iteratorlast, Comparecomp, intdepth)`` - void - NP_CACHE_AWARE_SORT.H:164 - * - ``void cache_oblivious_merge(Iteratorfirst, Iteratormid, Iteratorlast, Comparecomp)`` - void - NP_CACHE_AWARE_SORT.H:39 - :ref:`View ` * - ``void cache_oblivious_mergesort(Iteratorfirst, Iteratorlast, Comparecomp)`` - void - NP_CACHE_AWARE_SORT.H:89 - :ref:`View ` * - ``size_t calculateSize(const std::vector&shape)`` - size_t - NP_UTILS.H:16 - * - ``size_t calculateTotalSize(const std::vector&shape)`` - size_t - NP_VECTORIZE_UTILS.H:328 - * - ``bool canBroadcast(const Arrays &...arrays)`` - bool - NP_VECTORIZE_BROADCAST.H:386 - * - ``bool canOperate(const object\_ &a, const object\_ &b)`` - bool - NP_OBJECT_HOLDER.H:817 - * - ``bool canReduce(const Ufunc&ufunc)`` - bool - NP_UFUNC.H:690 - * - ``bool can_broadcast(const std::vector>&arrays)`` - bool - NP_BROADCASTING_UTILS.H:92 - :ref:`View ` * - ``bool can_use_mkl_fast_path(const NDArray&a, const NDArray&b)`` - bool - NP_NDARRAY.H:364 - * - ``CharArray capitalize(const CharArray&a)`` - CharArray - NP_CHAR.H:93 - :ref:`View ` * - ``str\_ capitalize(const str\_&s)`` - str\_ - NP_STRING_TYPES.H:241 - :ref:`View ` * - ``CharArray center(const CharArray&a, size_twidth, charfillchar = ' ')`` - CharArray - NP_CHAR.H:135 - :ref:`View ` * - ``CharArray center(const CharArray&a, size_twidth, charfillchar = ' ')`` - CharArray - NP_CHAR_OPS.H:46 - :ref:`View ` * - ``str\_ center(const str\_&s, size_twidth, charfillchar = ' ')`` - str\_ - NP_STRING_TYPES.H:438 - :ref:`View ` * - ``std::pair,std::vector> chebdiv(const std::vector&c1, const std::vector&c2)`` - std::pair,std::vector> - NP_CHEBYSHEV.H:187 - * - ``T chebval(Tx, const std::vector&c)`` - T - NP_CHEBYSHEV.H:246 - :ref:`View ` * - ``T chebyc(intn, Tx)`` - T - NP_ORTHOGONAL_POLYNOMIALS.H:105 - * - ``T chebys(intn, Tx)`` - T - NP_ORTHOGONAL_POLYNOMIALS.H:118 - * - ``T chebyt(intn, Tx)`` - T - NP_ORTHOGONAL_POLYNOMIALS.H:77 - :ref:`View ` * - ``T chebyu(intn, Tx)`` - T - NP_ORTHOGONAL_POLYNOMIALS.H:91 - :ref:`View ` * - ``void check_dft_status(MKL_LONGstatus, const std::string &operation)`` - void - NP_MKL_FFT.H:67 - * - ``void check_lapack_info(const std::string &routine, lapack_intinfo)`` - void - NP_MKL_LINALG.H:71 - * - ``void check_mkl_status(intstatus)`` - void - NP_MKL_SPECIAL.H:30 - * - ``void check_vsl_status(intstatus, const std::string &operation)`` - void - NP_VSL_RANDOM.H:151 - * - ``T chi(Tx)`` - T - NP_MISCELLANEOUS.H:216 - :ref:`View ` * - ``T ci(Tx)`` - T - NP_MISCELLANEOUS.H:151 - :ref:`View ` * - ``Matrix circulant(const std::vector&c)`` - Matrix - NP_MATRIX_SPECIAL.H:515 - :ref:`View ` * - ``int8_t clip(int8_tvalue, int8_tmin_val, int8_tmax_val)`` - int8_t - NP_MATH_UTILS_SQRT.H:4616 - :ref:`View ` * - ``int16_t clip(int16_tvalue, int16_tmin_val, int16_tmax_val)`` - int16_t - NP_MATH_UTILS_SQRT.H:4632 - :ref:`View ` * - ``int32_t clip(int32_tvalue, int32_tmin_val, int32_tmax_val)`` - int32_t - NP_MATH_UTILS_SQRT.H:4648 - :ref:`View ` * - ``int64_t clip(int64_tvalue, int64_tmin_val, int64_tmax_val)`` - int64_t - NP_MATH_UTILS_SQRT.H:4664 - :ref:`View ` * - ``uint8_t clip(uint8_tvalue, uint8_tmin_val, uint8_tmax_val)`` - uint8_t - NP_MATH_UTILS_SQRT.H:4680 - :ref:`View ` * - ``uint16_t clip(uint16_tvalue, uint16_tmin_val, uint16_tmax_val)`` - uint16_t - NP_MATH_UTILS_SQRT.H:4696 - :ref:`View ` * - ``uint32_t clip(uint32_tvalue, uint32_tmin_val, uint32_tmax_val)`` - uint32_t - NP_MATH_UTILS_SQRT.H:4712 - :ref:`View ` * - ``uint64_t clip(uint64_tvalue, uint64_tmin_val, uint64_tmax_val)`` - uint64_t - NP_MATH_UTILS_SQRT.H:4728 - :ref:`View ` * - ``bool\_ clip(bool_value, bool_min_val, bool_max_val)`` - bool\_ - NP_MATH_UTILS_SQRT.H:4744 - :ref:`View ` * - ``float32 clip(float32value, float32min_val, float32max_val)`` - float32 - NP_MATH_UTILS_SQRT.H:4760 - :ref:`View ` * - ``float64 clip(float64value, float64min_val, float64max_val)`` - float64 - NP_MATH_UTILS_SQRT.H:4777 - :ref:`View ` * - ``auto clip(const Array &arr, MinValmin_val, MaxValmax_val)`` - auto - NP_VECTORIZE.H:552 - :ref:`View ` * - ``std::vector> clump_masked(const MaskedArray&a)`` - std::vector> - NP_MASKED_ARRAY.H:3421 - :ref:`View ` * - ``std::vector> clump_unmasked(const MaskedArray&a)`` - std::vector> - NP_MASKED_ARRAY.H:3456 - :ref:`View ` * - ``T coerce_to(const object\_ &obj)`` - T - NP_OBJECT_UTILS.H:151 - * - ``T common_fill_value(const MaskedArray&a, const MaskedArray&b)`` - T - NP_MASKED_ARRAY.H:3329 - :ref:`View ` * - ``Matrix companion(const std::vector&coeffs)`` - Matrix - NP_MATRIX_SPECIAL.H:429 - :ref:`View ` * - ``std::vector> compareAlgorithms(const NDArray&matrix, const std::vector&algorithms = {"implicit_qr","jacobi_parallel","arnoldi"}, typename real_type::typetolerance = machine_epsilon::type>())`` - std::vector> - NP_LINALG_UTILS.H:2933 - * - ``bool compare_numeric_parts(const std::string &a, size_ta_start, size_ta_end, const std::string &b, size_tb_start, size_tb_end)`` - bool - NP_STRING_SORT.H:76 - * - ``bool compatible_memory_layout(const NDArray&a, const NDArray&b)`` - bool - NP_MEMORY_UTILS.H:308 - * - ``NDArray> complex_from_polar(const NDArray&magnitude, const NDArray&angle, booldeg = false)`` - NDArray> - NP_COMPLEX_UTILS.H:253 - :ref:`View ` * - ``NDArray> complex_from_polar(const NDArray&magnitude, const RealType &angle, booldeg = false)`` - NDArray> - NP_COMPLEX_UTILS.H:286 - :ref:`View ` * - ``bool complex_greater(const T &a, const T &b)`` - bool - NP_STATS_UTILS.H:101 - * - ``bool complex_greater_sorting(const T &a, const T &b)`` - bool - NP_SORTING_ALGORITHMS.H:50 - * - ``bool complex_less(const T &a, const T &b)`` - bool - NP_STATS_UTILS.H:91 - * - ``bool complex_less_or_equal_sorting(const T &a, const T &b)`` - bool - NP_SORTING_ALGORITHMS.H:55 - * - ``bool complex_less_sorting(const T &a, const T &b)`` - bool - NP_SORTING_ALGORITHMS.H:40 - * - ``real_type_t complex_norm_2(const T \*data, size_tn)`` - real_type_t - NP_LINALG_UTILS.H:689 - * - ``auto compute_along_axis(const NDArray&array, std::optionalaxis, Funcfunc, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:297 - * - ``void compute_block_reflector(HouseholderBlock&block)`` - void - NP_LINALG_UTILS.H:1445 - * - ``size_t compute_min_run(size_tn)`` - size_t - NP_SORTING_ALGORITHMS.H:709 - * - ``std::pair>,std::vector>> compute_optimal_matrix_order(const std::vector&dims)`` - std::pair>,std::vector>> - NP_LINALG.H:4785 - * - ``size_t compute_output_size(size_tn_a, size_tn_b, const std::string &mode)`` - size_t - NP_SIGNAL.H:23 - * - ``T cond(const NDArray&matrix, size_tp = 2)`` - T - NP_LINALG.H:2149 - :ref:`View ` * - ``T cond(const Matrix&matrix)`` - T - NP_MATRIX_OPS.H:339 - :ref:`View ` * - ``NDArray> conj_complex_mkl(const NDArray>&input)`` - NDArray> - NP_MKL_SPECIAL_COMPLEX.H:377 - :ref:`View ` * - ``NDArray> conj_complex_mkl(const NDArray>&input)`` - NDArray> - NP_MKL_SPECIAL_COMPLEX.H:465 - :ref:`View ` * - ``std::pair,ConvergenceInfo> conjugate_gradient(const CSRMatrix&A, const NDArray&b, const NDArray\*x0 = nullptr, Ttol = T{1e-6}, intmax_iter = 1000, IterationCallbackcallback = nullptr)`` - std::pair,ConvergenceInfo> - NP_ITERATIVE.H:80 - :ref:`View ` * - ``double conversion_numpy(const int8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:32 - * - ``double conversion_numpy(const int16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:33 - * - ``double conversion_numpy(const int32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:34 - * - ``double conversion_numpy(const int64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:35 - * - ``double conversion_numpy(const uint8_t &x)`` - double - NP_MATH_UTILS_SQRT.H:36 - * - ``double conversion_numpy(const uint16_t &x)`` - double - NP_MATH_UTILS_SQRT.H:37 - * - ``double conversion_numpy(const uint32_t &x)`` - double - NP_MATH_UTILS_SQRT.H:38 - * - ``double conversion_numpy(const uint64_t &x)`` - double - NP_MATH_UTILS_SQRT.H:39 - * - ``double conversion_numpy(const bool\_ &x)`` - double - NP_MATH_UTILS_SQRT.H:40 - * - ``float32 conversion_numpy(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:41 - * - ``double conversion_numpy(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:42 - * - ``complex64 conversion_numpy(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:43 - * - ``complex128 conversion_numpy(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:44 - * - ``datetime64 convertTo(DateTimeUnitnew_unit)`` - datetime64 - NP_DATETIME64.H:236 - :ref:`View ` * - ``timedelta64 convertTo(DateTimeUnitnew_unit)`` - timedelta64 - NP_TIMEDELTA64.H:276 - :ref:`View ` * - ``SchurDecomposition convert_real_to_schur(const RealSchurDecomposition&real_schur)`` - SchurDecomposition - NP_LINALG.H:4106 - * - ``CharArray convert_size(const CharArray&a)`` - CharArray - NP_CHAR.H:331 - * - ``Polynomial convert_to_standard(const ChebyshevPolynomial&cheb)`` - Polynomial - NP_SPECIAL_POLYNOMIALS.H:1006 - * - ``Polynomial convert_to_standard(const LegendrePolynomial&leg)`` - Polynomial - NP_SPECIAL_POLYNOMIALS.H:1025 - * - ``Polynomial convert_to_standard(const HermitePolynomial&herm)`` - Polynomial - NP_SPECIAL_POLYNOMIALS.H:1044 - * - ``Polynomial convert_to_standard(const LaguerrePolynomial&lag)`` - Polynomial - NP_SPECIAL_POLYNOMIALS.H:1063 - * - ``Polynomial convert_to_standard(const HermiteEPolynomial&herme)`` - Polynomial - NP_SPECIAL_POLYNOMIALS.H:1082 - * - ``CSRMatrix coo_to_csr(const COOMatrix&coo)`` - CSRMatrix - NP_SPARSE_CONVERT.H:37 - * - ``size_t count(const MaskedArray&array)`` - size_t - NP_MASKED_ARRAY.H:1609 - :ref:`View ` * - ``size_t count(const str\_&s, const std::string &substring)`` - size_t - NP_STRING_TYPES.H:409 - :ref:`View ` * - ``size_t count_masked(const MaskedArray&array)`` - size_t - NP_MASKED_ARRAY.H:1615 - :ref:`View ` * - ``size_t count_nonmasked(const MaskedArray&array)`` - size_t - NP_MASKED_ARRAY.H:1586 - :ref:`View ` * - ``size_t count_nonmasked(const NDArray&array)`` - size_t - NP_MASKED_ARRAY.H:1591 - :ref:`View ` * - ``size_t count_run_and_make_ascending(Iteratorfirst, Iteratorlast)`` - size_t - NP_SORTING_ALGORITHMS.H:772 - * - ``size_t count_run_and_make_ascending(Iteratorfirst, Iteratorlast, Comparecomp)`` - size_t - NP_SORTING_ALGORITHMS.H:798 - * - ``size_t count_unique(const NDArray&array)`` - size_t - NP_SET_UTILS.H:506 - :ref:`View ` * - ``void counting_sort_by_digit(std::vector&arr, Texp)`` - void - NP_SORTING_ALGORITHMS.H:631 - * - ``void counting_sort_range(std::vector&arr, Tmin_val, Tmax_val)`` - void - NP_SORTING_ALGORITHMS.H:1529 - :ref:`View ` * - ``COOMatrix csr_to_coo(const CSRMatrix&csr)`` - COOMatrix - NP_SPARSE_CONVERT.H:98 - * - ``datetime64(int64_tvalue, DateTimeUnitunit)`` - - NP_DATETIME64.H:78 - :ref:`View ` * - ``datetime64(const std::string &iso_string)`` - - NP_DATETIME64.H:82 - :ref:`View ` * - ``int daysInMonth(intyear, intmonth)`` - int - NP_DATETIME64.H:298 - :ref:`View ` * - ``int daysInMonth(intyear, intmonth)`` - int - NP_DATETIME_UTILS.H:533 - :ref:`View ` * - ``CharArray decode(const CharArray&a, const std::string &encoding = "utf-8")`` - CharArray - NP_CHAR.H:290 - :ref:`View ` * - ``CharArray decode(const CharArray&a, const std::string &encoding = "utf-8")`` - CharArray - NP_CHAR_OPS.H:290 - :ref:`View ` * - ``T default_fill_value(const T &)`` - T - NP_MASKED_ARRAY.H:3310 - :ref:`View ` * - ``T default_fill_value(const NDArray&)`` - T - NP_MASKED_ARRAY.H:3315 - :ref:`View ` * - ``T default_fill_value(const MaskedArray&)`` - T - NP_MASKED_ARRAY.H:3320 - :ref:`View ` * - ``Generator default_rng(std::optionalseed = std::nullopt)`` - Generator - NP_BITGEN.H:795 - :ref:`View ` * - ``Weekmask default_weekmask()`` - Weekmask - NP_DATETIME_UTILS.H:23 - * - ``void deprecate(const std::string &msg = "", const std::string &old_name = "", const std::string &new_name = "")`` - void - NP_INTROSPECTION.H:40 - :ref:`View ` * - ``void deprecate_with_doc(const std::string &msg)`` - void - NP_INTROSPECTION.H:60 - :ref:`View ` * - ``DescribeResult describe(const NDArray&array)`` - DescribeResult - NP_STATS_UTILS.H:1919 - :ref:`View ` * - ``std::string device_name(DLDeviceTypedevice_type)`` - std::string - NP_DLPACK.H:237 - * - ``void disp(const std::string &mesg)`` - void - NP_INTROSPECTION.H:276 - :ref:`View ` * - ``void disp(const NDArray&arr)`` - void - NP_INTROSPECTION.H:282 - :ref:`View ` * - ``py::object dispatch_array_to_ma(const py::array &arr_obj, Func &&func)`` - py::object - BINDINGS_HELPERS.H:318 - * - ``py::array dispatch_dtype_4types(const std::string &dtype, Func &&func)`` - py::array - BINDINGS_COMMON.H:202 - * - ``py::array dispatch_dtype_extended(const std::string &dtype, Func &&func)`` - py::array - BINDINGS_COMMON.H:219 - * - ``py::object dispatch_ma_binary(const py::object &ma1_obj, const py::object &ma2_obj, Func &&func)`` - py::object - BINDINGS_HELPERS.H:98 - * - ``py::object dispatch_ma_binary_no_bool(const py::object &ma1_obj, const py::object &ma2_obj, Func &&func)`` - py::object - BINDINGS_HELPERS.H:144 - * - ``py::object dispatch_ma_float_only(const py::object &ma_obj, Func &&func)`` - py::object - BINDINGS_HELPERS.H:288 - * - ``py::object dispatch_ma_reduction(const py::object &ma_obj, Func &&func)`` - py::object - BINDINGS_HELPERS.H:242 - * - ``py::object dispatch_ma_unary(const py::object &ma_obj, Func &&func)`` - py::object - BINDINGS_HELPERS.H:49 - * - ``py::object dispatch_ma_with_scalar(const py::object &ma_obj, const py::object &scalar_obj, Func &&func)`` - py::object - BINDINGS_HELPERS.H:191 - * - ``std::pair,NDArray> divmod(const NDArray&array1, const NDArray&array2)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:1994 - :ref:`View ` * - ``std::pair,NDArray> divmod(const NDArray&array1, const NDArray&array2)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:2011 - :ref:`View ` * - ``std::pair,NDArray> divmod(const NDArray&array1, const NDArray&array2)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:2028 - :ref:`View ` * - ``std::pair,NDArray> divmod(const NDArray&array1, const NDArray&array2)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:2045 - :ref:`View ` * - ``std::pair,NDArray> divmod(const NDArray&array1, const NDArray&array2)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:2062 - :ref:`View ` * - ``std::pair,NDArray> divmod(const NDArray&array1, const NDArray&array2)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:2079 - :ref:`View ` * - ``std::pair,NDArray> divmod(const NDArray&array1, const NDArray&array2)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:2096 - :ref:`View ` * - ``std::pair,NDArray> divmod(const NDArray&array1, const NDArray&array2)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:2113 - :ref:`View ` * - ``std::pair,NDArray> divmod(const NDArray&array1, const NDArray&array2)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:2130 - :ref:`View ` * - ``std::pair,NDArray> divmod(const NDArray&array1, const NDArray&array2)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:2147 - :ref:`View ` * - ``std::pair,NDArray> divmod(const NDArray&array1, const NDArray&array2)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:2164 - :ref:`View ` * - ``std::pair,NDArray> divmod(const NDArray&x, const NDArray&y)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:2187 - :ref:`View ` * - ``std::pair,NDArray> divmod(const NDArray&array, const T &scalar)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:2230 - :ref:`View ` * - ``DType dlpack_to_dtype(const DLDataType &dl_dtype)`` - DType - NP_DLPACK.H:86 - :ref:`View ` * - ``RecordArray drop_fields(const RecordArray &base, const std::vector&drop_names, boolusemask = false, boolasrecarray = true)`` - RecordArray - NP_RECFUNCTIONS.H:562 - :ref:`View ` * - ``DType dtype(const NDArray&)`` - DType - NP_ARRAY_INFO.H:102 - :ref:`View ` * - ``DType dtype(const std::string &type_str)`` - DType - NP_DTYPE_INFO.H:176 - :ref:`View ` * - ``DType dtype(DTypedt)`` - DType - NP_DTYPE_INFO.H:228 - :ref:`View ` * - ``size_t dtype_itemsize(const NDArray&)`` - size_t - NP_ARRAY_INFO.H:116 - :ref:`View ` * - ``std::string dtype_name(const NDArray&)`` - std::string - NP_ARRAY_INFO.H:109 - :ref:`View ` * - ``DLDataType dtype_to_dlpack(DTypedtype)`` - DLDataType - NP_DLPACK.H:153 - * - ``std::string dtype_to_python_string(numpy::DTypedtype)`` - std::string - BINDINGS_HELPERS.H:410 - * - ``std::string dtype_to_string(DTypedt)`` - std::string - NP_DTYPE_INFO.H:242 - :ref:`View ` * - ``void dump(const std::string &filename)`` - void - NP_NDARRAY.H:1350 - :ref:`View ` * - ``CharArray encode(const CharArray&a, const std::string &encoding = "utf-8")`` - CharArray - NP_CHAR.H:285 - :ref:`View ` * - ``CharArray encode(const CharArray&a, const std::string &encoding = "utf-8")`` - CharArray - NP_CHAR_OPS.H:284 - :ref:`View ` * - ``datetime64 endOfMonth(const datetime64 &date)`` - datetime64 - NP_DATETIME_UTILS.H:444 - :ref:`View ` * - ``datetime64 endOfWeek(const datetime64 &date, intstart_day = 0)`` - datetime64 - NP_DATETIME_UTILS.H:424 - :ref:`View ` * - ``datetime64 endOfYear(const datetime64 &date)`` - datetime64 - NP_DATETIME_UTILS.H:482 - :ref:`View ` * - ``bool endswith(const str\_&s, const std::string &suffix)`` - bool - NP_STRING_TYPES.H:316 - :ref:`View ` * - ``std::string error_mode_to_string(ErrorModemode)`` - std::string - NP_ERROR_HANDLING.H:36 - * - ``T estimate_condition_number_1(const T \*matrix, size_tn)`` - T - NP_LINALG_UTILS.H:570 - * - ``T fabs(Tvalue)`` - T - NP_MATH_UTILS_SQRT.H:7054 - :ref:`View ` * - ``void factorize()`` - void - NP_PARDISO.H:281 - * - ``auto fast_mean(const NDArray&array)`` - auto - NP_MKL_ARRAY_OPS.H:528 - * - ``T fast_sum(const NDArray&array)`` - T - NP_MKL_ARRAY_OPS.H:504 - * - ``bool file_exists(const std::string &filename)`` - bool - NP_IO_UTILS.H:970 - :ref:`View ` * - ``void fill(const T &value)`` - void - NP_NDARRAY.H:1170 - :ref:`View ` * - ``void fill_diagonal(NDArray&array, Tval, boolwrap = false)`` - void - NP_INDEXING_DIAGONAL.H:317 - :ref:`View ` * - ``void fill_diagonal(MaskedArray&ma, const T &value)`` - void - NP_MASKED_ARRAY.H:4237 - :ref:`View ` * - ``NUMPYCORE_API DType find_common_type(const std::vector&array_types, const std::vector&scalar_types)`` - NUMPYCORE_API DType - NP_DTYPE_UTILS.H:113 - :ref:`View ` * - ``size_t find_pivot(const T \*data, size_trows, size_tcols, size_tcurrent_row, size_tcurrent_col)`` - size_t - NP_LINALG_UTILS.H:155 - :ref:`View ` * - ``FInfo finfo_float32()`` - FInfo - NP_DTYPE_INFO.H:75 - :ref:`View ` * - ``FInfo finfo_float64()`` - FInfo - NP_DTYPE_INFO.H:83 - :ref:`View ` * - ``FInfo finfo_longdouble()`` - FInfo - NP_DTYPE_INFO.H:91 - :ref:`View ` * - ``ArrayFlags flags(const NDArray&array)`` - ArrayFlags - NP_ARRAY_INFO.H:74 - :ref:`View ` * - ``T & flat(size_tflat_index)`` - T & - NP_NDARRAY.H:1243 - :ref:`View ` * - ``const T & flat(size_tflat_index)`` - const T & - NP_NDARRAY.H:1268 - :ref:`View ` * - ``std::vector> flatnotmasked_contiguous(const MaskedArray&a)`` - std::vector> - NP_MASKED_ARRAY.H:3522 - :ref:`View ` * - ``auto float_power(T1base, T2exponent)`` - auto - NP_MATH_UTILS_SQRT.H:7225 - :ref:`View ` * - ``auto float_power(const NDArray&base, const NDArray&exponent)`` - auto - NP_MATH_UTILS_SQRT.H:7249 - :ref:`View ` * - ``int8_t fmax(const int8_t &x, const int8_t &y)`` - int8_t - NP_MATH_UTILS_SQRT.H:3563 - :ref:`View ` * - ``int16_t fmax(const int16_t &x, const int16_t &y)`` - int16_t - NP_MATH_UTILS_SQRT.H:3584 - :ref:`View ` * - ``int32_t fmax(const int32_t &x, const int32_t &y)`` - int32_t - NP_MATH_UTILS_SQRT.H:3605 - :ref:`View ` * - ``int64_t fmax(const int64_t &x, const int64_t &y)`` - int64_t - NP_MATH_UTILS_SQRT.H:3626 - :ref:`View ` * - ``uint8_t fmax(const uint8_t &x, const uint8_t &y)`` - uint8_t - NP_MATH_UTILS_SQRT.H:3647 - :ref:`View ` * - ``uint16_t fmax(const uint16_t &x, const uint16_t &y)`` - uint16_t - NP_MATH_UTILS_SQRT.H:3668 - :ref:`View ` * - ``uint32_t fmax(const uint32_t &x, const uint32_t &y)`` - uint32_t - NP_MATH_UTILS_SQRT.H:3689 - :ref:`View ` * - ``uint64_t fmax(const uint64_t &x, const uint64_t &y)`` - uint64_t - NP_MATH_UTILS_SQRT.H:3710 - :ref:`View ` * - ``bool\_ fmax(const bool\_ &x, const bool\_ &y)`` - bool\_ - NP_MATH_UTILS_SQRT.H:3731 - :ref:`View ` * - ``float32 fmax(const float32 &x, const float32 &y)`` - float32 - NP_MATH_UTILS_SQRT.H:3752 - :ref:`View ` * - ``double fmax(const double &x, const double &y)`` - double - NP_MATH_UTILS_SQRT.H:3775 - :ref:`View ` * - ``complex64 fmax(const complex64 &x, const complex64 &y)`` - complex64 - NP_MATH_UTILS_SQRT.H:3799 - :ref:`View ` * - ``complex128 fmax(const complex128 &x, const complex128 &y)`` - complex128 - NP_MATH_UTILS_SQRT.H:3820 - :ref:`View ` * - ``auto -> detail::promoted_type_t fmax(const T1 &x, const T2 &y)`` - auto -> detail::promoted_type_t - NP_MATH_UTILS_SQRT.H:5882 - :ref:`View ` * - ``auto -> NDArray> fmax(const NDArray&x, const NDArray&y)`` - auto -> NDArray> - NP_MATH_UTILS_SQRT.H:5997 - :ref:`View ` * - ``int8_t fmin(const int8_t &x, const int8_t &y)`` - int8_t - NP_MATH_UTILS_SQRT.H:3852 - :ref:`View ` * - ``int16_t fmin(const int16_t &x, const int16_t &y)`` - int16_t - NP_MATH_UTILS_SQRT.H:3873 - :ref:`View ` * - ``int32_t fmin(const int32_t &x, const int32_t &y)`` - int32_t - NP_MATH_UTILS_SQRT.H:3894 - :ref:`View ` * - ``int64_t fmin(const int64_t &x, const int64_t &y)`` - int64_t - NP_MATH_UTILS_SQRT.H:3915 - :ref:`View ` * - ``uint8_t fmin(const uint8_t &x, const uint8_t &y)`` - uint8_t - NP_MATH_UTILS_SQRT.H:3936 - :ref:`View ` * - ``uint16_t fmin(const uint16_t &x, const uint16_t &y)`` - uint16_t - NP_MATH_UTILS_SQRT.H:3957 - :ref:`View ` * - ``uint32_t fmin(const uint32_t &x, const uint32_t &y)`` - uint32_t - NP_MATH_UTILS_SQRT.H:3978 - :ref:`View ` * - ``uint64_t fmin(const uint64_t &x, const uint64_t &y)`` - uint64_t - NP_MATH_UTILS_SQRT.H:3999 - :ref:`View ` * - ``bool\_ fmin(const bool\_ &x, const bool\_ &y)`` - bool\_ - NP_MATH_UTILS_SQRT.H:4020 - :ref:`View ` * - ``float32 fmin(const float32 &x, const float32 &y)`` - float32 - NP_MATH_UTILS_SQRT.H:4041 - :ref:`View ` * - ``double fmin(const double &x, const double &y)`` - double - NP_MATH_UTILS_SQRT.H:4064 - :ref:`View ` * - ``complex64 fmin(const complex64 &x, const complex64 &y)`` - complex64 - NP_MATH_UTILS_SQRT.H:4088 - :ref:`View ` * - ``complex128 fmin(const complex128 &x, const complex128 &y)`` - complex128 - NP_MATH_UTILS_SQRT.H:4109 - :ref:`View ` * - ``auto -> detail::promoted_type_t fmin(const T1 &x, const T2 &y)`` - auto -> detail::promoted_type_t - NP_MATH_UTILS_SQRT.H:5866 - :ref:`View ` * - ``auto -> NDArray> fmin(const NDArray&x, const NDArray&y)`` - auto -> NDArray> - NP_MATH_UTILS_SQRT.H:5959 - :ref:`View ` * - ``int8_t fmod(const int8_t &x, const int8_t &y)`` - int8_t - NP_MATH_UTILS_SQRT.H:2608 - :ref:`View ` * - ``int16_t fmod(const int16_t &x, const int16_t &y)`` - int16_t - NP_MATH_UTILS_SQRT.H:2613 - :ref:`View ` * - ``int32_t fmod(const int32_t &x, const int32_t &y)`` - int32_t - NP_MATH_UTILS_SQRT.H:2618 - :ref:`View ` * - ``int64_t fmod(const int64_t &x, const int64_t &y)`` - int64_t - NP_MATH_UTILS_SQRT.H:2623 - :ref:`View ` * - ``uint8_t fmod(const uint8_t &x, const uint8_t &y)`` - uint8_t - NP_MATH_UTILS_SQRT.H:2628 - :ref:`View ` * - ``uint16_t fmod(const uint16_t &x, const uint16_t &y)`` - uint16_t - NP_MATH_UTILS_SQRT.H:2633 - :ref:`View ` * - ``uint32_t fmod(const uint32_t &x, const uint32_t &y)`` - uint32_t - NP_MATH_UTILS_SQRT.H:2638 - :ref:`View ` * - ``uint64_t fmod(const uint64_t &x, const uint64_t &y)`` - uint64_t - NP_MATH_UTILS_SQRT.H:2643 - :ref:`View ` * - ``bool\_ fmod(const bool\_ &x, const bool\_ &y)`` - bool\_ - NP_MATH_UTILS_SQRT.H:2648 - :ref:`View ` * - ``float32 fmod(const float32 &x, const float32 &y)`` - float32 - NP_MATH_UTILS_SQRT.H:2656 - :ref:`View ` * - ``double fmod(const double &x, const double &y)`` - double - NP_MATH_UTILS_SQRT.H:2661 - :ref:`View ` * - ``auto -> detail::promoted_type_t fmod(const T1 &x, const T2 &y)`` - auto -> detail::promoted_type_t - NP_MATH_UTILS_SQRT.H:6038 - :ref:`View ` * - ``auto -> NDArray> fmod(const NDArray&x, const NDArray&y)`` - auto -> NDArray> - NP_MATH_UTILS_SQRT.H:6080 - :ref:`View ` * - ``std::string formatDateTime(const datetime64 &dt, const std::string &format = "%Y-%m-%d %H:%M:%S")`` - std::string - NP_DATETIME_UTILS.H:349 - :ref:`View ` * - ``std::string format_coefficient(Tvalue, intprecision)`` - std::string - NP_POLYNOMIAL.H:101 - * - ``std::string format_element(const T &value, const PrintOptions &opts)`` - std::string - NP_IO_STRING.H:226 - * - ``std::string format_float_positional(doublevalue, intprecision = -1, boolunique = true, booltrim = true, const std::string &sign = "-", intpad_left = 0, intpad_right = 0)`` - std::string - NP_IO_STRING.H:114 - :ref:`View ` * - ``std::string format_float_scientific(doublevalue, intprecision = -1, boolunique = true, booltrim = true, const std::string &sign = "-", intexp_digits = -1, intpad_left = 0)`` - std::string - NP_IO_STRING.H:166 - :ref:`View ` * - ``NUMPYCORE_API DType format_parser(const std::string &format_string)`` - NUMPYCORE_API DType - NP_DTYPE_UTILS.H:405 - :ref:`View ` * - ``void frac_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:1920 - * - ``RealSchurDecomposition francis_qr_real_schur(const NDArray&matrix, Ttolerance = utils::machine_epsilon(), size_tmax_iterations = 0)`` - RealSchurDecomposition - NP_LINALG.H:3855 - * - ``void francis_qr_step(NDArray&H, NDArray&Q, Tshift1, Tshift2, size_tstart, size_tend)`` - void - NP_LINALG.H:3750 - * - ``void francis_qr_step(NDArray&H, NDArray&Q, Tshift1, Tshift2, size_tstart, size_tend)`` - void - NP_LINALG.H:3956 - * - ``void francis_qr_step(NDArray&H, NDArray&Q, size_tn_start, size_tn_end)`` - void - NP_LINALG_UTILS.H:1057 - * - ``T fresnelc(Tx)`` - T - NP_MISCELLANEOUS.H:277 - :ref:`View ` * - ``T fresnels(Tx)`` - T - NP_MISCELLANEOUS.H:244 - :ref:`View ` * - ``std::pair,NDArray> frexp(const NDArray&x)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:5631 - :ref:`View ` * - ``std::pair,NDArray> frexp(const NDArray&x)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:5650 - :ref:`View ` * - ``std::pair,NDArray> frexp(const NDArray&x)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:5669 - :ref:`View ` * - ``std::pair,NDArray> frexp(const NDArray&x)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:5688 - :ref:`View ` * - ``std::pair,NDArray> frexp(const NDArray&x)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:5707 - :ref:`View ` * - ``std::pair,NDArray> frexp(const NDArray&x)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:5726 - :ref:`View ` * - ``std::pair,NDArray> frexp(const NDArray&x)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:5745 - :ref:`View ` * - ``std::pair,NDArray> frexp(const NDArray&x)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:5764 - :ref:`View ` * - ``std::pair,NDArray> frexp(const NDArray&x)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:5783 - :ref:`View ` * - ``std::pair,NDArray> frexp(const NDArray&x)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:5802 - :ref:`View ` * - ``std::pair,NDArray> frexp(const NDArray&x)`` - std::pair,NDArray> - NP_MATH_UTILS_SQRT.H:5821 - :ref:`View ` * - ``datetime64 fromEpochSeconds(int64_tseconds, DateTimeUnitunit)`` - datetime64 - NP_DATETIME64.H:107 - :ref:`View ` * - ``timedelta64 fromSeconds(int64_tseconds, DateTimeUnitunit)`` - timedelta64 - NP_TIMEDELTA64.H:99 - :ref:`View ` * - ``RecordArray fromarrays(const std::vector>>&field_arrays)`` - RecordArray - NP_REC_CREATION.H:424 - :ref:`View ` * - ``auto frompyfunc(Func &&func, size_tnin, size_tnout, std::optionalidentity = std::nullopt, const std::string &doc = "")`` - auto - NP_FROMPYFUNC.H:36 - :ref:`View ` * - ``auto frompyfunc(Func &&func, size_tnin, size_tnout, std::optionalidentity, const char \*doc)`` - auto - NP_FROMPYFUNC.H:57 - :ref:`View ` * - ``auto frompyfunc(Func &&func, size_tnin, size_tnout, const std::string &doc)`` - auto - NP_FROMPYFUNC.H:66 - :ref:`View ` * - ``auto frompyfunc(Func &&func, size_tnin, size_tnout, const char \*doc)`` - auto - NP_FROMPYFUNC.H:71 - :ref:`View ` * - ``RecordArray fromrecords(const std::vector>&records, const std::vector>&field_specs)`` - RecordArray - NP_REC_CREATION.H:414 - :ref:`View ` * - ``RecordArray fromrecords(const std::vector&records)`` - RecordArray - NP_REC_CREATION.H:420 - :ref:`View ` * - ``double fv(doublerate, doublenper, doublepmt, doublepv = 0.0, intwhen = 0)`` - double - NP_FINANCIAL.H:64 - :ref:`View ` * - ``double fv(doublerate, doublenper, doublepmt, doublepv, intwhen)`` - double - NP_FINANCIAL.H:195 - :ref:`View ` * - ``size_t gallop_left(typename std::iterator_traits::value_typekey, Iteratorfirst, size_tlen)`` - size_t - NP_SORTING_ALGORITHMS.H:826 - * - ``size_t gallop_left(typename std::iterator_traits::value_typekey, Iteratorfirst, size_tlen, Comparecomp)`` - size_t - NP_SORTING_ALGORITHMS.H:856 - * - ``size_t gallop_right(typename std::iterator_traits::value_typekey, Iteratorfirst, size_tlen)`` - size_t - NP_SORTING_ALGORITHMS.H:886 - * - ``size_t gallop_right(typename std::iterator_traits::value_typekey, Iteratorfirst, size_tlen, Comparecomp)`` - size_t - NP_SORTING_ALGORITHMS.H:917 - * - ``typename std::enable_if_t,T> gcd(Tx1, Tx2)`` - typename std::enable_if_t,T> - NP_MATH_EXTENDED.H:50 - :ref:`View ` * - ``typename std::enable_if_t,NDArray> gcd(const NDArray&x1, const NDArray&x2)`` - typename std::enable_if_t,NDArray> - NP_MATH_EXTENDED.H:56 - :ref:`View ` * - ``void generate_complex_householder(const T \*x, size_tn, T &tau, T \*v)`` - void - NP_LINALG_UTILS.H:710 - * - ``std::string generate_cosine_benchmark_report()`` - std::string - NP_TRIGONOMETRIC.H:152 - * - ``HouseholderReflector generate_householder(const T \*x, size_tn)`` - HouseholderReflector - NP_LINALG_UTILS.H:257 - * - ``T genlaguerre(intn, Talpha, Tx)`` - T - NP_ORTHOGONAL_POLYNOMIALS.H:196 - :ref:`View ` * - ``std::pair,ConvergenceInfo> gmres(const CSRMatrix&A, const NDArray&b, const NDArray\*x0 = nullptr, intrestart = 30, Ttol = T{1e-6}, intmax_iter = 1000, IterationCallbackcallback = nullptr)`` - std::pair,ConvergenceInfo> - NP_ITERATIVE.H:255 - :ref:`View ` * - ``std::vector,double,T>::type>> gradient(const NDArray&f)`` - std::vector,double,T>::type>> - NP_CUMULATIVE_UTILS.H:400 - :ref:`View ` * - ``NDArray,double,T>::type> gradient(const NDArray&f, intaxis)`` - NDArray,double,T>::type> - NP_CUMULATIVE_UTILS.H:407 - :ref:`View ` * - ``std::vector,double,T>::type>> gradient_all(const NDArray&f)`` - std::vector,double,T>::type>> - NP_CUMULATIVE_UTILS.H:384 - * - ``NDArray,double,T>::type> gradient_axis(const NDArray&f, intaxis)`` - NDArray,double,T>::type> - NP_CUMULATIVE_UTILS.H:280 - * - ``NDArray& handle_out_parameter(const NDArray&result, NDArray\*out)`` - NDArray& - NP_STATS_UTILS.H:57 - * - ``Matrix hankel(const std::vector&c, const std::vector&r = {})`` - Matrix - NP_MATRIX_SPECIAL.H:459 - :ref:`View ` * - ``bool has_avx2()`` - bool - NP_SIMD_SORT.H:65 - * - ``bool has_avx512()`` - bool - NP_SIMD_SORT.H:66 - * - ``bool has_sse42()`` - bool - NP_SIMD_SORT.H:64 - * - ``void heapsort(Iteratorfirst, Iteratorlast)`` - void - NP_SORTING_ALGORITHMS.H:342 - * - ``void heapsort(Iteratorfirst, Iteratorlast, Comparecomp)`` - void - NP_SORTING_ALGORITHMS.H:360 - * - ``T heaviside(Tx, Th0)`` - T - NP_MATH_UTILS_SQRT.H:7362 - :ref:`View ` * - ``std::pair,std::vector> hermdiv(const std::vector&c1, const std::vector&c2)`` - std::pair,std::vector> - NP_HERMITE.H:132 - * - ``std::pair,std::vector> hermediv(const std::vector&c1, const std::vector&c2)`` - std::pair,std::vector> - NP_HERMITE_E.H:126 - * - ``T hermeval(Tx, const std::vector&c)`` - T - NP_HERMITE_E.H:155 - :ref:`View ` * - ``T hermite(intn, Tx)`` - T - NP_ORTHOGONAL_POLYNOMIALS.H:142 - :ref:`View ` * - ``T hermitenorm(intn, Tx)`` - T - NP_ORTHOGONAL_POLYNOMIALS.H:156 - :ref:`View ` * - ``T hermval(Tx, const std::vector&c)`` - T - NP_HERMITE.H:161 - :ref:`View ` * - ``HessenbergReduction hessenberg_reduction_complex(const NDArray&matrix)`` - HessenbergReduction - NP_LINALG_UTILS.H:953 - :ref:`View ` * - ``void hessenberg_reduction_real(NDArray&H, NDArray&Q)`` - void - NP_LINALG.H:3758 - * - ``void householder_qr_step(NDArray&H, NDArray&Q, const std::vector&x, size_tstart, size_tend)`` - void - NP_LINALG.H:3753 - * - ``void householder_qr_step(NDArray&H, NDArray&Q, const std::vector&x, size_tstart, size_tend)`` - void - NP_LINALG.H:4020 - * - ``void hybrid_sort(std::vector&arr, SortKindpreference = SortKind::QUICKSORT)`` - void - NP_SORTING_ALGORITHMS.H:1880 - * - ``T hyp0f1(Ta, Tx)`` - T - NP_HYPERGEOMETRIC.H:11 - :ref:`View ` * - ``T hyp1f1(Ta, Tb, Tx)`` - T - NP_HYPERGEOMETRIC.H:41 - :ref:`View ` * - ``T hyp2f1(Ta, Tb, Tc, Tx)`` - T - NP_HYPERGEOMETRIC.H:77 - :ref:`View ` * - ``T hyperu(Ta, Tb, Tx)`` - T - NP_HYPERGEOMETRIC.H:120 - * - ``size_t ids(const NDArray&arr)`` - size_t - NP_MASKED_ARRAY.H:3296 - :ref:`View ` * - ``size_t ids(const MaskedArray&arr)`` - size_t - NP_MASKED_ARRAY.H:3301 - :ref:`View ` * - ``IndexExpr idx(ssize_ti)`` - IndexExpr - NP_NDARRAY_ADVANCED.H:263 - :ref:`View ` * - ``IndexExpr idx(const Slice &s)`` - IndexExpr - NP_NDARRAY_ADVANCED.H:269 - :ref:`View ` * - ``IndexExpr idx(const NDArray&array)`` - IndexExpr - NP_NDARRAY_ADVANCED.H:275 - :ref:`View ` * - ``IInfo iinfo_int16()`` - IInfo - NP_DTYPE_INFO.H:107 - :ref:`View ` * - ``IInfo iinfo_int32()`` - IInfo - NP_DTYPE_INFO.H:115 - :ref:`View ` * - ``IInfo iinfo_int64()`` - IInfo - NP_DTYPE_INFO.H:123 - :ref:`View ` * - ``IInfo iinfo_int8()`` - IInfo - NP_DTYPE_INFO.H:99 - :ref:`View ` * - ``IInfo iinfo_uint16()`` - IInfo - NP_DTYPE_INFO.H:139 - :ref:`View ` * - ``IInfo iinfo_uint32()`` - IInfo - NP_DTYPE_INFO.H:147 - :ref:`View ` * - ``IInfo iinfo_uint64()`` - IInfo - NP_DTYPE_INFO.H:155 - :ref:`View ` * - ``IInfo iinfo_uint8()`` - IInfo - NP_DTYPE_INFO.H:131 - :ref:`View ` * - ``auto -> NDArray, float32, typename std::conditional, float64, typename std::conditional, longdouble, T>::type>::type>::type> imag(const NDArray&array)`` - auto -> NDArray, float32, typename std::conditional, float64, typename std::conditional, longdouble, T>::type>::type>::type> - NP_COMPLEX_UTILS.H:59 - :ref:`View ` * - ``numpy::linalg::SchurDecomposition implicit_qr_algorithm(const NDArray&matrix, typename real_type::typetolerance = 1e-12, size_tmax_iterations = 1000)`` - numpy::linalg::SchurDecomposition - NP_LINALG_UTILS.H:1199 - :ref:`View ` * - ``bool incrementIndices(std::vector&indices, const std::vector&shape)`` - bool - NP_UTILS.H:149 - :ref:`View ` * - ``bool incrementIndicesHelper(std::vector&indices, const std::vector&shape)`` - bool - NP_NESTED_ARRAY.H:317 - * - ``bool increment_index(std::vector&idx, const std::vector&shape)`` - bool - NP_PADDING.H:325 - * - ``std::vector> indices(const std::vector&dimensions, boolsparse = false)`` - std::vector> - NP_ARRAY_CREATION_EXTENDED.H:273 - :ref:`View ` * - ``auto inferOutputType(Func &&func, Args &&...args)`` - auto - NP_VECTORIZE_UTILS.H:76 - * - ``std::string infer_dtype_from_pyobject(const py::object &obj)`` - std::string - BINDINGS_COMMON.H:290 - * - ``void info(const NDArray&array)`` - void - NP_ARRAY_INFO.H:141 - :ref:`View ` * - ``void info(const T &obj, boolverbose = false)`` - void - NP_INTROSPECTION.H:201 - :ref:`View ` * - ``void info(const NDArray&arr, boolverbose = false)`` - void - NP_INTROSPECTION.H:221 - :ref:`View ` * - ``void initializeTimezoneData()`` - void - NP_TIMEZONE_DATA.H:15 - * - ``T interp(Tx, const NDArray&xp, const NDArray&fp, std::optionalleft = std::nullopt, std::optionalright = std::nullopt)`` - T - NP_NUMERICAL.H:30 - :ref:`View ` * - ``void introsort(Iteratorfirst, Iteratorlast)`` - void - NP_SORTING_ALGORITHMS.H:470 - :ref:`View ` * - ``void introsort(Iteratorfirst, Iteratorlast, Comparecomp)`` - void - NP_SORTING_ALGORITHMS.H:480 - :ref:`View ` * - ``void introsort_impl(Iteratorfirst, Iteratorlast, size_tmax_depth)`` - void - NP_SORTING_ALGORITHMS.H:418 - * - ``void introsort_impl(Iteratorfirst, Iteratorlast, size_tmax_depth, Comparecomp)`` - void - NP_SORTING_ALGORITHMS.H:444 - * - ``double ipmt(doublerate, intper, doublenper, doublepv, doublefv = 0.0, intwhen = 0)`` - double - NP_FINANCIAL.H:160 - :ref:`View ` * - ``double ipmt(doublerate, intper, doublenper, doublepv, doublefv, intwhen)`` - double - NP_FINANCIAL.H:350 - :ref:`View ` * - ``void ipp_argsort(const T \*data, int \*indices, size_tn, boolascending = true)`` - void - NP_IPP_SORT.H:419 - :ref:`View ` * - ``void ipp_bucket_sort(std::vector&arr, size_tnum_buckets = 0)`` - void - NP_IPP_SORT.H:1121 - * - ``void ipp_bucket_sort(std::vector&arr, size_tnum_buckets = 0)`` - void - NP_IPP_SORT.H:1266 - * - ``void ipp_counting_sort(std::vector&arr, Tmin_val, Tmax_val)`` - void - NP_IPP_SORT.H:1011 - * - ``void ipp_counting_sort(std::vector&arr)`` - void - NP_IPP_SORT.H:1062 - * - ``void ipp_counting_sort(std::vector&arr, Tmin_val, Tmax_val)`` - void - NP_IPP_SORT.H:1246 - * - ``void ipp_counting_sort(std::vector&arr)`` - void - NP_IPP_SORT.H:1251 - * - ``void ipp_enhanced_insertion_sort(Iteratorfirst, Iteratorlast)`` - void - NP_SORTING_ALGORITHMS.H:241 - * - ``void ipp_enhanced_introsort(Iteratorfirst, Iteratorlast)`` - void - NP_SORTING_ALGORITHMS.H:550 - :ref:`View ` * - ``void ipp_enhanced_introsort(Iteratorfirst, Iteratorlast, Comparecomp)`` - void - NP_SORTING_ALGORITHMS.H:581 - :ref:`View ` * - ``void ipp_enhanced_introsort_impl(Iteratorfirst, Iteratorlast, size_tmax_depth)`` - void - NP_SORTING_ALGORITHMS.H:495 - * - ``void ipp_enhanced_introsort_impl(Iteratorfirst, Iteratorlast, size_tmax_depth, Comparecomp)`` - void - NP_SORTING_ALGORITHMS.H:522 - * - ``void ipp_msort(std::vector&arr)`` - void - NP_IPP_SORT.H:984 - * - ``void ipp_msort(std::vector&arr)`` - void - NP_IPP_SORT.H:1236 - * - ``void ipp_partition(T \*data, int \*indices, size_tn, size_tk, boolascending = true)`` - void - NP_IPP_SORT.H:728 - * - ``void ipp_radix_sort(T \*data, size_tn, boolascending = true)`` - void - NP_IPP_SORT.H:383 - :ref:`View ` * - ``void ipp_radix_sort(std::vector&data, boolascending = true)`` - void - NP_IPP_SORT.H:600 - :ref:`View ` * - ``size_t ipp_searchsorted(const std::vector&a, const T &v, const std::string &side = "left")`` - size_t - NP_IPP_SORT.H:966 - * - ``size_t ipp_searchsorted(const std::vector&a, const T &v, const std::string &side = "left")`` - size_t - NP_IPP_SORT.H:1231 - * - ``void ipp_sort(T \*data, size_tn, boolascending = true)`` - void - NP_IPP_SORT.H:347 - :ref:`View ` * - ``void ipp_sort(std::vector&data, boolascending = true)`` - void - NP_IPP_SORT.H:593 - :ref:`View ` * - ``void ipp_sort_complex(std::vector>&arr)`` - void - NP_IPP_SORT.H:1086 - * - ``std::vector> ipp_sort_complex(const std::vector>&arr)`` - std::vector> - NP_IPP_SORT.H:1110 - * - ``void ipp_sort_complex(std::vector>&arr)`` - void - NP_IPP_SORT.H:1256 - * - ``std::vector> ipp_sort_complex(const std::vector>&arr)`` - std::vector> - NP_IPP_SORT.H:1261 - * - ``IppStatus ipp_sort_radix_index_partial_ascend(T \*data, int \*indices, intn, intk, Ipp8u \*buffer)`` - IppStatus - NP_IPP_SORT.H:702 - * - ``void ipp_stable_argsort(const T \*data, int \*indices, size_tn, boolascending = true)`` - void - NP_IPP_SORT.H:553 - :ref:`View ` * - ``void ipp_stable_sort(T \*data, size_tn, boolascending = true)`` - void - NP_IPP_SORT.H:481 - :ref:`View ` * - ``void ipp_stable_sort(std::vector&data, boolascending = true)`` - void - NP_IPP_SORT.H:616 - :ref:`View ` * - ``IRAMResult iram_eigenvalues(const SparseMatrix&A, size_tnev = 6, size_tncv = 0, typename real_type::typetol = 1e-12, size_tmax_iter = 1000)`` - IRAMResult - NP_LINALG_UTILS.H:2464 - * - ``double irr(const NDArray&values, doubleguess = 0.1)`` - double - NP_FINANCIAL.H:133 - :ref:`View ` * - ``double irr(const NDArray&values, doubleguess)`` - double - NP_FINANCIAL.H:272 - :ref:`View ` * - ``bool isBusinessDay(const datetime64 &date)`` - bool - NP_DATETIME_UTILS.H:87 - :ref:`View ` * - ``bool isBusinessDay(const datetime64 &date, const Weekmask &weekmask)`` - bool - NP_DATETIME_UTILS.H:92 - :ref:`View ` * - ``bool isBusinessDay(const datetime64 &date, const Weekmask &weekmask, const std::set&holidays)`` - bool - NP_DATETIME_UTILS.H:101 - :ref:`View ` * - ``bool isCContiguous()`` - bool - NP_NDARRAY.H:980 - :ref:`View ` * - ``bool isContiguous()`` - bool - NP_NDARRAY.H:975 - :ref:`View ` * - ``bool isFContiguous()`` - bool - NP_NDARRAY.H:988 - :ref:`View ` * - ``bool isHomogeneousArrays(const NDArray&arr)`` - bool - NP_NESTED_ARRAY.H:399 - :ref:`View ` * - ``bool isLeapYear(intyear)`` - bool - NP_DATETIME64.H:294 - :ref:`View ` * - ``bool isLeapYear(intyear)`` - bool - NP_DATETIME_UTILS.H:529 - :ref:`View ` * - ``bool isMA(const MaskedArray&)`` - bool - NP_MASKED_ARRAY.H:3238 - :ref:`View ` * - ``bool isMA(const NDArray&)`` - bool - NP_MASKED_ARRAY.H:3243 - :ref:`View ` * - ``bool isMaskedArray(const MaskedArray&x)`` - bool - NP_MASKED_ARRAY.H:3249 - :ref:`View ` * - ``bool isMaskedArray(const NDArray&x)`` - bool - NP_MASKED_ARRAY.H:3254 - :ref:`View ` * - ``bool isRectangular(const NDArray&arr)`` - bool - NP_NESTED_ARRAY.H:672 - :ref:`View ` * - ``bool isValidForVectorization(const T &value)`` - bool - NP_VECTORIZE_UTILS.H:286 - * - ``bool isWeekend(const datetime64 &date)`` - bool - NP_DATETIME_UTILS.H:76 - :ref:`View ` * - ``bool isalnum(const str\_&s)`` - bool - NP_STRING_TYPES.H:335 - :ref:`View ` * - ``bool isalpha(const str\_&s)`` - bool - NP_STRING_TYPES.H:323 - :ref:`View ` * - ``bool isarray(const NDArray&)`` - bool - NP_MASKED_ARRAY.H:3277 - :ref:`View ` * - ``bool isarray(const MaskedArray&)`` - bool - NP_MASKED_ARRAY.H:3282 - :ref:`View ` * - ``bool isarray(...)`` - bool - NP_MASKED_ARRAY.H:3288 - :ref:`View ` * - ``bool isdigit(const str\_&s)`` - bool - NP_STRING_TYPES.H:329 - :ref:`View ` * - ``bool isempty(const NDArray&array)`` - bool - NP_ARRAY_INFO.H:197 - :ref:`View ` * - ``bool isfortran(const NDArray&array)`` - bool - NP_LOGIC_UTILS.H:276 - :ref:`View ` * - ``bool islower(const str\_&s)`` - bool - NP_STRING_TYPES.H:341 - :ref:`View ` * - ``bool ismatrix(const NDArray&array)`` - bool - NP_ARRAY_INFO.H:184 - :ref:`View ` * - ``NUMPYCORE_API bool issctype(DTypedtype)`` - NUMPYCORE_API bool - NP_DTYPE_UTILS.H:307 - :ref:`View ` * - ``bool isspace(const str\_&s)`` - bool - NP_STRING_TYPES.H:375 - :ref:`View ` * - ``bool issquare(const NDArray&array)`` - bool - NP_ARRAY_INFO.H:190 - :ref:`View ` * - ``NUMPYCORE_API bool issubclass\_(DTypearg1, TypeCategoryarg2)`` - NUMPYCORE_API bool - NP_DTYPE_UTILS.H:421 - :ref:`View ` * - ``NUMPYCORE_API bool issubdtype(DTypedtype, TypeCategorycategory)`` - NUMPYCORE_API bool - NP_DTYPE_UTILS.H:138 - :ref:`View ` * - ``NUMPYCORE_API bool issubdtype(DTypearg1, DTypearg2)`` - NUMPYCORE_API bool - NP_DTYPE_UTILS.H:148 - :ref:`View ` * - ``NUMPYCORE_API bool issubsctype(DTypearg1, TypeCategoryarg2)`` - NUMPYCORE_API bool - NP_DTYPE_UTILS.H:501 - :ref:`View ` * - ``NUMPYCORE_API bool issubsctype(DTypearg1, DTypearg2)`` - NUMPYCORE_API bool - NP_DTYPE_UTILS.H:506 - :ref:`View ` * - ``bool istitle(const str\_&s)`` - bool - NP_STRING_TYPES.H:381 - :ref:`View ` * - ``bool isupper(const str\_&s)`` - bool - NP_STRING_TYPES.H:358 - :ref:`View ` * - ``bool isvector(const NDArray&array)`` - bool - NP_ARRAY_INFO.H:178 - :ref:`View ` * - ``NDIterRange iter_range(const NDArray&array, boolc_order = true)`` - NDIterRange - NP_NDITER.H:407 - :ref:`View ` * - ``bool iterable(const NDArray&)`` - bool - NP_TYPE_UTILS.H:142 - :ref:`View ` * - ``std::enable_if_t>,bool> iterable(const Container &)`` - std::enable_if_t>,bool> - NP_TYPE_UTILS.H:148 - :ref:`View ` * - ``bool iterable(const T(&)[N])`` - bool - NP_TYPE_UTILS.H:155 - :ref:`View ` * - ``std::enable_if_t>&&!is_std_container_v>&&!is_ndarray_type_v>,bool> iterable(const T &)`` - std::enable_if_t>&&!is_std_container_v>&&!is_ndarray_type_v>,bool> - NP_TYPE_UTILS.H:161 - :ref:`View ` * - ``std::enable_if_t>&&!is_std_container_v>&&!is_ndarray_type_v>&&!is_c_array_v>,bool> iterable(const T &)`` - std::enable_if_t>&&!is_std_container_v>&&!is_ndarray_type_v>&&!is_c_array_v>,bool> - NP_TYPE_UTILS.H:172 - :ref:`View ` * - ``ObjectArrayRange iterate(NDArray&arr)`` - ObjectArrayRange - NP_NESTED_ARRAY.H:133 - :ref:`View ` * - ``T iv(Tv, Tx)`` - T - NP_SPHERICAL_BESSEL.H:21 - * - ``std::vector> ix\_(const std::vector>&sequences)`` - std::vector> - NP_ARRAY_CREATION_EXTENDED.H:108 - :ref:`View ` * - ``T jacobi(intn, Talpha, Tbeta, Tx)`` - T - NP_ORTHOGONAL_POLYNOMIALS.H:212 - :ref:`View ` * - ``JacobiResult jacobi_symmetric_parallel(const NDArray&matrix, typename real_type::typetolerance = 1e-12, size_tmax_iterations = 1000)`` - JacobiResult - NP_LINALG_UTILS.H:2000 - * - ``CharArray join(const std::string &sep, const std::vector>&arrays)`` - CharArray - NP_CHAR.H:263 - :ref:`View ` * - ``CharArray join(const std::string &sep, const std::vector>&arrays)`` - CharArray - NP_CHAR_OPS.H:234 - :ref:`View ` * - ``RecordArray join_by(const std::string &key, const RecordArray &r1, const RecordArray &r2, const std::string &jointype = "inner", const std::string &r1postfix = "1", const std::string &r2postfix = "2", booldefaults = false, boolusemask = false, boolasrecarray = true)`` - RecordArray - NP_RECFUNCTIONS.H:589 - :ref:`View ` * - ``void k_way_merge_sort(Iteratorfirst, Iteratorlast, Comparecomp, size_tk = 4)`` - void - NP_CACHE_AWARE_SORT.H:271 - :ref:`View ` * - ``T kei(Tx)`` - T - NP_KELVIN_FUNCTIONS.H:178 - :ref:`View ` * - ``auto kei(const NDArray&x)`` - auto - NP_KELVIN_FUNCTIONS.H:316 - :ref:`View ` * - ``T keip(Tx)`` - T - NP_KELVIN_FUNCTIONS.H:247 - :ref:`View ` * - ``auto keip(const NDArray&x)`` - auto - NP_KELVIN_FUNCTIONS.H:368 - :ref:`View ` * - ``void kelvin_power_series(Tx, T &ber, T &bei, T &ker, T &kei)`` - void - NP_KELVIN_FUNCTIONS.H:50 - * - ``CorrelationResult kendalltau(const NDArray&x, const NDArray&y)`` - CorrelationResult - NP_STATS_UTILS.H:2205 - :ref:`View ` * - ``T ker(Tx)`` - T - NP_KELVIN_FUNCTIONS.H:156 - :ref:`View ` * - ``auto ker(const NDArray&x)`` - auto - NP_KELVIN_FUNCTIONS.H:303 - :ref:`View ` * - ``T kerp(Tx)`` - T - NP_KELVIN_FUNCTIONS.H:232 - :ref:`View ` * - ``auto kerp(const NDArray&x)`` - auto - NP_KELVIN_FUNCTIONS.H:355 - :ref:`View ` * - ``auto kurtosis(const NDArray&array, std::optionalaxis = std::nullopt, boolfisher = true, boolbias = true, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:1834 - :ref:`View ` * - ``T kv(Tv, Tx)`` - T - NP_SPHERICAL_BESSEL.H:24 - * - ``std::pair,std::vector> lagdiv(const std::vector&c1, const std::vector&c2)`` - std::pair,std::vector> - NP_LAGUERRE.H:142 - * - ``T laguerre(intn, Tx)`` - T - NP_ORTHOGONAL_POLYNOMIALS.H:182 - :ref:`View ` * - ``T lagval(Tx, const std::vector&c)`` - T - NP_LAGUERRE.H:171 - :ref:`View ` * - ``T lbeta(Ta, Tb)`` - T - NP_GAMMA_FUNCTIONS.H:289 - :ref:`View ` * - ``typename std::enable_if_t,T> lcm(Tx1, Tx2)`` - typename std::enable_if_t,T> - NP_MATH_EXTENDED.H:75 - :ref:`View ` * - ``typename std::enable_if_t,NDArray> lcm(const NDArray&x1, const NDArray&x2)`` - typename std::enable_if_t,NDArray> - NP_MATH_EXTENDED.H:81 - :ref:`View ` * - ``float ldexp(boolx1, intx2)`` - float - NP_MATH_UTILS_SQRT.H:5482 - :ref:`View ` * - ``float ldexp(int8_tx1, intx2)`` - float - NP_MATH_UTILS_SQRT.H:5494 - :ref:`View ` * - ``float ldexp(uint8_tx1, intx2)`` - float - NP_MATH_UTILS_SQRT.H:5506 - :ref:`View ` * - ``float ldexp(int16_tx1, intx2)`` - float - NP_MATH_UTILS_SQRT.H:5518 - :ref:`View ` * - ``float ldexp(uint16_tx1, intx2)`` - float - NP_MATH_UTILS_SQRT.H:5530 - :ref:`View ` * - ``double ldexp(int32_tx1, intx2)`` - double - NP_MATH_UTILS_SQRT.H:5542 - :ref:`View ` * - ``double ldexp(uint32_tx1, intx2)`` - double - NP_MATH_UTILS_SQRT.H:5554 - :ref:`View ` * - ``double ldexp(int64_tx1, intx2)`` - double - NP_MATH_UTILS_SQRT.H:5566 - :ref:`View ` * - ``double ldexp(uint64_tx1, intx2)`` - double - NP_MATH_UTILS_SQRT.H:5578 - :ref:`View ` * - ``float ldexp(floatx1, intx2)`` - float - NP_MATH_UTILS_SQRT.H:5590 - :ref:`View ` * - ``double ldexp(doublex1, intx2)`` - double - NP_MATH_UTILS_SQRT.H:5602 - :ref:`View ` * - ``std::pair,std::vector> legdiv(const std::vector&c1, const std::vector&c2)`` - std::pair,std::vector> - NP_LEGENDRE.H:200 - * - ``T legendre(intn, Tx)`` - T - NP_ORTHOGONAL_POLYNOMIALS.H:46 - :ref:`View ` * - ``T legval(Tx, const std::vector&c)`` - T - NP_LEGENDRE.H:255 - :ref:`View ` * - ``T li(Tx)`` - T - NP_EXPONENTIAL_INTEGRALS.H:123 - :ref:`View ` * - ``CharArray ljust(const CharArray&a, size_twidth, charfillchar = ' ')`` - CharArray - NP_CHAR.H:140 - :ref:`View ` * - ``CharArray ljust(const CharArray&a, size_twidth, charfillchar = ' ')`` - CharArray - NP_CHAR_OPS.H:68 - :ref:`View ` * - ``str\_ ljust(const str\_&s, size_twidth, charfillchar = ' ')`` - str\_ - NP_STRING_TYPES.H:453 - :ref:`View ` * - ``CharArray lower(const CharArray&a)`` - CharArray - NP_CHAR.H:103 - :ref:`View ` * - ``T lpmv(intm, intn, Tx)`` - T - NP_ORTHOGONAL_POLYNOMIALS.H:60 - :ref:`View ` * - ``CharArray lstrip(const CharArray&a, const std::string &chars = " \\n\\r\\f\\v")`` - CharArray - NP_CHAR.H:124 - :ref:`View ` * - ``str\_ lstrip(const str\_&s, const std::string &chars = " \\n\\r\\f\\v")`` - str\_ - NP_STRING_TYPES.H:285 - :ref:`View ` * - ``LUResult lu(const NDArray&matrix)`` - LUResult - NP_LINALG_WRAPPERS.H:74 - :ref:`View ` * - ``std::tuple,Matrix,Matrix> lu(const Matrix&matrix)`` - std::tuple,Matrix,Matrix> - NP_MATRIX_OPS.H:170 - :ref:`View ` * - ``auto lu_accelerated(const NDArray&matrix)`` - auto - NP_MKL_LINALG.H:3764 - * - ``std::pair,NDArray> lu_decomposition(const NDArray&matrix)`` - std::pair,NDArray> - NP_LINALG.H:441 - * - ``LUDecomposition lu_decomposition_pivoted(const NDArray&matrix, Ttolerance = utils::machine_epsilon())`` - LUDecomposition - NP_LINALG.H:356 - :ref:`View ` * - ``NUMPYCORE_API MachArInfo machar()`` - NUMPYCORE_API MachArInfo - NP_DTYPE_UTILS.H:382 - :ref:`View ` * - ``T machine_epsilon()`` - T - NP_LINALG_UTILS.H:73 - :ref:`View ` * - ``auto makeBroadcastApplicator(Func &&func, Arrays &...arrays)`` - auto - NP_VECTORIZE_BROADCAST.H:346 - * - ``std::string makeBroadcastError(const std::vector>&shapes)`` - std::string - NP_VECTORIZE_UTILS.H:354 - * - ``auto makeBroadcastIterator(Arrays &...arrays)`` - auto - NP_VECTORIZE_BROADCAST.H:246 - * - ``auto makeCachedFunction(Func &&func, size_tcache_size = 1000)`` - auto - NP_VECTORIZE_UTILS.H:274 - * - ``auto makeScalarBroadcast(const T &scalar)`` - auto - NP_VECTORIZE_BROADCAST.H:378 - * - ``auto makeVectorizedFunction(Func &&func)`` - auto - NP_VECTORIZE_BROADCAST.H:432 - * - ``std::tuple,NDArray> mask_indices(size_tn, const std::string &mask_func, intk = 0)`` - std::tuple,NDArray> - NP_INDEXING_DIAGONAL.H:77 - :ref:`View ` * - ``std::tuple,NDArray> mask_indices(size_tn, MaskFuncmask_func, intk = 0)`` - std::tuple,NDArray> - NP_INDEXING_DIAGONAL.H:109 - :ref:`View ` * - ``Matrix mat(const std::string &matlab_str)`` - Matrix - NP_MATRIX_FACTORY.H:315 - :ref:`View ` * - ``bool matchesSignature(const Signature &sig)`` - bool - NP_VECTORIZE_TRAITS.H:229 - * - ``bool matches_numpy_dtype(const std::string &dtype_str)`` - bool - NP_IO_UTILS.H:85 - * - ``Matrix matrix(const std::string &matlab_str)`` - Matrix - NP_MATRIX_FACTORY.H:23 - :ref:`View ` * - ``Matrix matrix(const std::vector>&data)`` - Matrix - NP_MATRIX_FACTORY.H:31 - :ref:`View ` * - ``Matrix matrix(const NDArray&array)`` - Matrix - NP_MATRIX_FACTORY.H:39 - :ref:`View ` * - ``Matrix matrix_function_eig(const Matrix&matrix, Ffunc)`` - Matrix - NP_MATRIX_SPECIAL.H:336 - * - ``bool may_share_memory(const NDArray&a, const NDArray&b, size_tmax_work = 10000)`` - bool - NP_MEMORY_UTILS.H:19 - :ref:`View ` * - ``MemoryMappedArray memmap(const std::string &filename, const std::vector&shape, const std::string &mode = "r+", size_toffset = 0)`` - MemoryMappedArray - NP_MEMMAP.H:637 - :ref:`View ` * - ``size_t memory_footprint(const NDArray&array)`` - size_t - NP_MEMORY_UTILS.H:296 - :ref:`View ` * - ``void memory_info(const NDArray&array)`` - void - NP_ARRAY_INFO.H:265 - * - ``MemoryLayout memory_layout(const NDArray&array)`` - MemoryLayout - NP_ARRAY_INFO.H:228 - :ref:`View ` * - ``RecordArray merge_arrays(const std::vector&arrays, boolflatten = false, boolusemask = false, boolasrecarray = true)`` - RecordArray - NP_RECFUNCTIONS.H:574 - :ref:`View ` * - ``void merge_at(Iteratorfirst, std::vector>&runs, size_ti)`` - void - NP_SORTING_ALGORITHMS.H:1072 - * - ``void merge_at(Iteratorfirst, std::vector>&runs, size_ti, Comparecomp)`` - void - NP_SORTING_ALGORITHMS.H:1086 - * - ``void merge_collapse(Iteratorfirst, std::vector>&runs)`` - void - NP_SORTING_ALGORITHMS.H:1011 - * - ``void merge_collapse(Iteratorfirst, std::vector>&runs, Comparecomp)`` - void - NP_SORTING_ALGORITHMS.H:1030 - * - ``void merge_force_collapse(Iteratorfirst, std::vector>&runs)`` - void - NP_SORTING_ALGORITHMS.H:1049 - * - ``void merge_force_collapse(Iteratorfirst, std::vector>&runs, Comparecomp)`` - void - NP_SORTING_ALGORITHMS.H:1060 - * - ``double mirr(const NDArray&values, doublefinance_rate, doublereinvest_rate)`` - double - NP_FINANCIAL.H:143 - :ref:`View ` * - ``double mirr(const NDArray&values, doublefinance_rate, doublereinvest_rate)`` - double - NP_FINANCIAL.H:315 - :ref:`View ` * - ``void mkl_abs_array(const T \*a, T \*result, size_tn)`` - void - NP_MKL_ARRAY_OPS.H:220 - * - ``void mkl_add_arrays(const T \*a, const T \*b, T \*result, size_tn)`` - void - NP_MKL_ARRAY_OPS.H:72 - * - ``typename std::enable_if_t,void> mkl_add_arrays(const T \*a, const T \*b, T \*result, size_tn)`` - typename std::enable_if_t,void> - NP_NDARRAY.H:373 - * - ``void mkl_axpy(Talpha, const NDArray&x, NDArray&y)`` - void - NP_MKL_LINALG.H:670 - :ref:`View ` * - ``void mkl_copy(const NDArray&x, NDArray&y)`` - void - NP_MKL_LINALG.H:703 - :ref:`View ` * - ``void mkl_copysign_arrays(const T \*a, const T \*b, T \*result, size_tn)`` - void - NP_MKL_ARRAY_OPS.H:184 - :ref:`View ` * - ``void mkl_divide_arrays(const T \*a, const T \*b, T \*result, size_tn)`` - void - NP_MKL_ARRAY_OPS.H:114 - * - ``typename std::enable_if_t,void> mkl_divide_arrays(const T \*a, const T \*b, T \*result, size_tn)`` - typename std::enable_if_t,void> - NP_NDARRAY.H:412 - * - ``EigenResult mkl_eig(const NDArray&matrix, boolcompute_vectors = true)`` - EigenResult - NP_MKL_LINALG.H:200 - * - ``NDArray> mkl_eigvals(const NDArray&matrix)`` - NDArray> - NP_MKL_LINALG.H:304 - * - ``NDArray> mkl_fft_1d(const NDArray>&input)`` - NDArray> - NP_MKL_FFT.H:238 - :ref:`View ` * - ``void mkl_fmax_arrays(const T \*a, const T \*b, T \*result, size_tn)`` - void - NP_MKL_ARRAY_OPS.H:142 - :ref:`View ` * - ``void mkl_fmin_arrays(const T \*a, const T \*b, T \*result, size_tn)`` - void - NP_MKL_ARRAY_OPS.H:156 - :ref:`View ` * - ``BandLUResult mkl_gbtrf(const NDArray&AB, intkl, intku)`` - BandLUResult - NP_MKL_LINALG.H:1395 - :ref:`View ` * - ``T mkl_gecon(const NDArray&A, Tanorm, charnorm = '1')`` - T - NP_MKL_LINALG.H:2452 - * - ``SchurResult mkl_gees(const NDArray&A, boolcompute_schur_vectors = true)`` - SchurResult - NP_MKL_LINALG.H:2147 - :ref:`View ` * - ``ComplexSchurResult mkl_gees_complex(const NDArray>&A, boolcompute_schur_vectors = true)`` - ComplexSchurResult - NP_MKL_LINALG.H:2225 - * - ``HessenbergResult mkl_gehrd(const NDArray&A)`` - HessenbergResult - NP_MKL_LINALG.H:2089 - :ref:`View ` * - ``RefinementResult mkl_gerfs(const NDArray&A, const NDArray&AF, const NDArray&ipiv, const NDArray&b, const NDArray&x)`` - RefinementResult - NP_MKL_LINALG.H:2573 - * - ``GeneralizedEigenResult mkl_ggev(const NDArray&A, const NDArray&B, boolcompute_left = false, boolcompute_right = true)`` - GeneralizedEigenResult - NP_MKL_LINALG.H:1961 - :ref:`View ` * - ``TridiagonalLUResult mkl_gttrf(const NDArray&dl, const NDArray&d, const NDArray&du)`` - TridiagonalLUResult - NP_MKL_LINALG.H:1742 - :ref:`View ` * - ``NDArray> mkl_hemv(const NDArray>&A, const NDArray>&x, std::complexalpha = std::complex{1,0}, std::complexbeta = std::complex{0,0}, boolupper = true)`` - NDArray> - NP_MKL_LINALG.H:913 - * - ``void mkl_her(Talpha, const NDArray>&x, NDArray>&A, boolupper = true)`` - void - NP_MKL_LINALG.H:1055 - * - ``SymmetricIndefiniteResult> mkl_hetrf(const NDArray>&A, boolupper = false)`` - SymmetricIndefiniteResult> - NP_MKL_LINALG.H:2856 - :ref:`View ` * - ``NDArray> mkl_hetrs(const NDArray>&A, const NDArray&ipiv, const NDArray>&b, boolupper = false)`` - NDArray> - NP_MKL_LINALG.H:2904 - :ref:`View ` * - ``void mkl_hypot_arrays(const T \*a, const T \*b, T \*result, size_tn)`` - void - NP_MKL_ARRAY_OPS.H:170 - :ref:`View ` * - ``NDArray> mkl_ifft_1d(const NDArray>&input)`` - NDArray> - NP_MKL_FFT.H:279 - :ref:`View ` * - ``LSTSQResult mkl_lstsq(const NDArray&A, const NDArray&b)`` - LSTSQResult - NP_MKL_LINALG.H:3546 - :ref:`View ` * - ``auto mkl_lu(const NDArray&matrix)`` - auto - NP_MKL_LINALG.H:3269 - :ref:`View ` * - ``T mkl_mean_array(const T \*data, size_tn)`` - T - NP_MKL_ARRAY_OPS.H:310 - * - ``typename std::enable_if_t,T> mkl_mean_contiguous(const T \*data, size_tn)`` - typename std::enable_if_t,T> - NP_STATS_UTILS.H:151 - :ref:`View ` * - ``void mkl_multiply_arrays(const T \*a, const T \*b, T \*result, size_tn)`` - void - NP_MKL_ARRAY_OPS.H:100 - * - ``typename std::enable_if_t,void> mkl_multiply_arrays(const T \*a, const T \*b, T \*result, size_tn)`` - typename std::enable_if_t,void> - NP_NDARRAY.H:399 - * - ``void mkl_nextafter_arrays(const T \*a, const T \*b, T \*result, size_tn)`` - void - NP_MKL_ARRAY_OPS.H:198 - :ref:`View ` * - ``T mkl_pocon(const NDArray&A, Tanorm, boolupper = false)`` - T - NP_MKL_LINALG.H:2490 - * - ``RefinementResult mkl_porfs(const NDArray&A, const NDArray&AF, const NDArray&b, const NDArray&x, boolupper = false)`` - RefinementResult - NP_MKL_LINALG.H:2649 - * - ``void mkl_power_arrays(const T \*a, const T \*b, T \*result, size_tn)`` - void - NP_MKL_ARRAY_OPS.H:128 - * - ``QRResult mkl_qr(const NDArray&matrix, const std::string &mode = "reduced")`` - QRResult - NP_MKL_LINALG.H:3460 - :ref:`View ` * - ``NDArray> mkl_rfft_1d(const NDArray&input)`` - NDArray> - NP_MKL_FFT.H:326 - :ref:`View ` * - ``void mkl_rot(NDArray&x, NDArray&y, Tc, Ts)`` - void - NP_MKL_LINALG.H:821 - :ref:`View ` * - ``void mkl_rotg(T &a, T &b, T &c, T &s)`` - void - NP_MKL_LINALG.H:796 - :ref:`View ` * - ``void mkl_scal(Talpha, NDArray&x)`` - void - NP_MKL_LINALG.H:766 - :ref:`View ` * - ``void mkl_sqrt_array(const T \*a, T \*result, size_tn)`` - void - NP_MKL_ARRAY_OPS.H:234 - * - ``TridiagonalEigenResult mkl_stedc(const NDArray&d, const NDArray&e, boolcompute_vectors = true)`` - TridiagonalEigenResult - NP_MKL_LINALG.H:2360 - :ref:`View ` * - ``TridiagonalEigenResult mkl_steqr(const NDArray&d, const NDArray&e, boolcompute_vectors = true)`` - TridiagonalEigenResult - NP_MKL_LINALG.H:2289 - :ref:`View ` * - ``void mkl_subtract_arrays(const T \*a, const T \*b, T \*result, size_tn)`` - void - NP_MKL_ARRAY_OPS.H:86 - * - ``typename std::enable_if_t,void> mkl_subtract_arrays(const T \*a, const T \*b, T \*result, size_tn)`` - typename std::enable_if_t,void> - NP_NDARRAY.H:386 - * - ``T mkl_sum_array(const T \*data, size_tn)`` - T - NP_MKL_ARRAY_OPS.H:256 - * - ``T mkl_sum_contiguous(const T \*data, size_tn)`` - T - NP_STATS_UTILS.H:133 - :ref:`View ` * - ``SVDResult mkl_svd(const NDArray&matrix, boolfull_matrices = true)`` - SVDResult - NP_MKL_LINALG.H:3367 - :ref:`View ` * - ``void mkl_swap(NDArray&x, NDArray&y)`` - void - NP_MKL_LINALG.H:736 - :ref:`View ` * - ``SymmetricGeneralizedEigenResult mkl_sygv(const NDArray&A, const NDArray&B, boolcompute_vectors = true, intitype = 1)`` - SymmetricGeneralizedEigenResult - NP_MKL_LINALG.H:3183 - * - ``SymmetricEigenResult mkl_symeig(const NDArray&matrix, boolcompute_vectors = true)`` - SymmetricEigenResult - NP_MKL_LINALG.H:3032 - * - ``void mkl_syr(Talpha, const NDArray&x, NDArray&A, boolupper = true)`` - void - NP_MKL_LINALG.H:1012 - :ref:`View ` * - ``SymmetricIndefiniteResult mkl_sytrf(const NDArray&A, boolupper = false)`` - SymmetricIndefiniteResult - NP_MKL_LINALG.H:2748 - :ref:`View ` * - ``T mkl_trcon(const NDArray&A, charnorm = '1', boolupper = true, boolunit_diag = false)`` - T - NP_MKL_LINALG.H:2530 - :ref:`View ` * - ``void mkl_trmm(const NDArray&A, NDArray&B, Talpha = T{1}, boolside_left = true, boolupper = true, booltrans = false, boolunit_diag = false)`` - void - NP_MKL_LINALG.H:1234 - * - ``void mkl_trmv(const NDArray&A, NDArray&x, boolupper = true, booltrans = false, boolunit_diag = false)`` - void - NP_MKL_LINALG.H:968 - :ref:`View ` * - ``T mkl_variance_array(const T \*data, size_tn, intddof = 0)`` - T - NP_MKL_ARRAY_OPS.H:346 - * - ``typename std::enable_if_t,T> mkl_variance_contiguous(const T \*data, size_tn, intddof = 0)`` - typename std::enable_if_t,T> - NP_STATS_UTILS.H:211 - :ref:`View ` * - ``double mkl_vsl_kurtosis(const NDArray&data, boolexcess = true)`` - double - NP_MKL_VSL_STATS.H:570 - * - ``double mkl_vsl_skewness(const NDArray&data)`` - double - NP_MKL_VSL_STATS.H:531 - * - ``auto moment(const NDArray&array, intn, std::optionalaxis = std::nullopt, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:1737 - :ref:`View ` * - ``size_t multiIndexToFlatIndex(const std::vector&indices, const std::vector&shape, const std::vector&strides)`` - size_t - NP_UTILS.H:58 - * - ``ssize_t multiIndexToFlatIndex(const std::vector&indices, const std::vector&shape, const std::vector&strides)`` - ssize_t - NP_UTILS.H:77 - * - ``size_t multiToFlatIndex(const std::vector&multi_index, const std::vector&shape)`` - size_t - NP_VECTORIZE_UTILS.H:150 - * - ``CharArray narray(const std::vector&strings, const std::vector&shape = {})`` - CharArray - NP_CHAR.H:423 - :ref:`View ` * - ``size_t nbytes(const NDArray&array)`` - size_t - NP_ARRAY_INFO.H:37 - :ref:`View ` * - ``py::array ndarray_to_numpy(numpy::NDArray&&arr)`` - py::array - BINDINGS_COMMON.H:79 - * - ``py::array ndarray_to_numpy(const numpy::NDArray&arr)`` - py::array - BINDINGS_COMMON.H:131 - * - ``NDEnumerate ndenumerate(const NDArray&array)`` - NDEnumerate - NP_NDITER.H:303 - :ref:`View ` * - ``size_t ndim(const NDArray&array)`` - size_t - NP_ARRAY_INFO.H:16 - :ref:`View ` * - ``NDIndex ndindex(const std::vector&shape)`` - NDIndex - NP_NDITER.H:298 - :ref:`View ` * - ``NDIter nditer(const NDArray&array, boolc_order = true)`` - NDIter - NP_NDITER.H:286 - :ref:`View ` * - ``NDIter nditer(const NDArray&array, const std::vector&order)`` - NDIter - NP_NDITER.H:292 - :ref:`View ` * - ``bool nditer_all(const NDArray&array, Predicate &&pred)`` - bool - NP_NDITER.H:359 - :ref:`View ` * - ``bool nditer_any(const NDArray&array, Predicate &&pred)`` - bool - NP_NDITER.H:371 - :ref:`View ` * - ``void nditer_apply(const NDArray&array, Func &&func)`` - void - NP_NDITER.H:313 - :ref:`View ` * - ``size_t nditer_count(const NDArray&array, Predicate &&pred)`` - size_t - NP_NDITER.H:345 - :ref:`View ` * - ``std::optional,T>> nditer_find(const NDArray&array, Predicate &&pred)`` - std::optional,T>> - NP_NDITER.H:333 - :ref:`View ` * - ``T nditer_reduce(const NDArray&array, Func &&func, Tinitial_value = T{})`` - T - NP_NDITER.H:321 - :ref:`View ` * - ``NDPointer ndpointer(size_tndim = 0, const std::vector&shape = {}, const std::vector&flags = {})`` - NDPointer - NP_CTYPES_INTEROP.H:249 - :ref:`View ` * - ``T ndtr(Tx)`` - T - NP_STATISTICAL.H:223 - :ref:`View ` * - ``T ndtr_fallback(Tx)`` - T - NP_STATISTICAL.H:17 - * - ``T ndtr_fallback(Tx)`` - T - NP_STATISTICAL.H:205 - * - ``T ndtri(Ty)`` - T - NP_STATISTICAL.H:228 - :ref:`View ` * - ``T ndtri_fallback(Ty)`` - T - NP_STATISTICAL.H:18 - * - ``T ndtri_fallback(Ty)`` - T - NP_STATISTICAL.H:210 - * - ``NestedIters nested_iters(const NDArray&array, const std::vector>&axes_list)`` - NestedIters - NP_NDITER.H:676 - :ref:`View ` * - ``NestedIters nested_iters(const std::vector>&arrays, const std::vector>&axes_list)`` - NestedIters - NP_NDITER.H:684 - :ref:`View ` * - ``NestedIters nested_iters_2(const NDArray&array, const std::vector&outer_axes, const std::vector&inner_axes)`` - NestedIters - NP_NDITER.H:697 - :ref:`View ` * - ``double newton_raphson(Funcf, Derivativedf, doublex0, doubletol = DEFAULT_TOLERANCE, intmax_iter = MAX_ITERATIONS)`` - double - NP_FINANCIAL.H:30 - * - ``T nextafter(Tx1, Tx2)`` - T - NP_MATH_UTILS_SQRT.H:6863 - :ref:`View ` * - ``std::vector> notmasked_contiguous(const MaskedArray&a)`` - std::vector> - NP_MASKED_ARRAY.H:3491 - :ref:`View ` * - ``datetime64 now(DateTimeUnitunit)`` - datetime64 - NP_DATETIME64.H:205 - :ref:`View ` * - ``double nper(doublerate, doublepmt, doublepv, doublefv = 0.0, intwhen = 0)`` - double - NP_FINANCIAL.H:97 - :ref:`View ` * - ``double nper(doublerate, doublepmt, doublepv, doublefv, intwhen)`` - double - NP_FINANCIAL.H:231 - :ref:`View ` * - ``double npv(doublerate, const NDArray&values)`` - double - NP_FINANCIAL.H:124 - :ref:`View ` * - ``double npv(doublerate, const NDArray&values)`` - double - NP_FINANCIAL.H:251 - :ref:`View ` * - ``void nth_element_partition(Iteratorfirst, Iteratornth, Iteratorlast)`` - void - NP_SORTING_ALGORITHMS.H:1177 - * - ``void nth_element_partition(Iteratorfirst, Iteratornth, Iteratorlast, Comparecomp)`` - void - NP_SORTING_ALGORITHMS.H:1182 - * - ``Iterator numpy_partition(Iteratorfirst, Iteratorlast)`` - Iterator - NP_SORTING_ALGORITHMS.H:382 - * - ``Iterator numpy_partition(Iteratorfirst, Iteratorlast, Comparecomp)`` - Iterator - NP_SORTING_ALGORITHMS.H:400 - * - ``NUMPYCORE_API DType obj2sctype(const std::string &rep, DTypedefault_dtype)`` - NUMPYCORE_API DType - NP_DTYPE_UTILS.H:442 - :ref:`View ` * - ``void openmp_quicksort(Iteratorfirst, Iteratorlast, Comparecomp)`` - void - NP_PARALLEL_SORT.H:281 - * - ``void openmp_quicksort(Iteratorfirst, Iteratorlast)`` - void - NP_PARALLEL_SORT.H:290 - * - ``void openmp_quicksort_impl(Iteratorfirst, Iteratorlast, Comparecomp)`` - void - NP_PARALLEL_SORT.H:241 - * - ``void openmp_quicksort_impl(Iteratorfirst, Iteratorlast)`` - void - NP_PARALLEL_SORT.H:261 - * - ``NDArray operator!(const NDArray&array)`` - NDArray - NP_OPERATORS.H:437 - * - ``bool operator!=(const datetime64 &other)`` - bool - NP_DATETIME64.H:135 - * - ``NDArray operator!=(const NDArray&lhs, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:186 - * - ``NDArray operator!=(const NDArray&lhs, const T &scalar)`` - NDArray - NP_OPERATORS.H:211 - * - ``NDArray operator!=(const T &scalar, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:224 - * - ``bool operator!=(const timedelta64 &other)`` - bool - NP_TIMEDELTA64.H:175 - * - ``NDArray operator&&(const NDArray&lhs, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:381 - * - ``Matrix operator\*(const T &scalar, const Matrix&matrix)`` - Matrix - NP_MATRIX.H:455 - * - ``NDArray operator\*(const NDArray&lhs, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:84 - * - ``NDArray operator\*(const NDArray&lhs, const T &scalar)`` - NDArray - NP_OPERATORS.H:89 - * - ``NDArray operator\*(const T &scalar, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:102 - * - ``Polynomial operator\*(Tscalar, const Polynomial&poly)`` - Polynomial - NP_POLYNOMIAL.H:960 - * - ``Timedelta operator\*(int64_tscalar, const Timedelta &td)`` - Timedelta - NP_TIMEDELTA.H:813 - * - ``Timedelta operator\*(intscalar, const Timedelta &td)`` - Timedelta - NP_TIMEDELTA.H:817 - * - ``Timedelta operator\*(doublescalar, const Timedelta &td)`` - Timedelta - NP_TIMEDELTA.H:821 - * - ``timedelta64 operator\*(int64_tscalar)`` - timedelta64 - NP_TIMEDELTA64.H:144 - * - ``NDArray& operator\*=(NDArray&lhs, const NDArray&rhs)`` - NDArray& - NP_OPERATORS.H:479 - * - ``NDArray& operator\*=(NDArray&lhs, const T &scalar)`` - NDArray& - NP_OPERATORS.H:485 - * - ``NDArray operator+(const NDArray&lhs, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:14 - * - ``NDArray operator+(const NDArray&lhs, const T &scalar)`` - NDArray - NP_OPERATORS.H:19 - * - ``NDArray operator+(const T &scalar, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:32 - * - ``timedelta64 operator+(const timedelta64 &other)`` - timedelta64 - NP_TIMEDELTA64.H:124 - * - ``datetime64 operator+(const timedelta64 &delta)`` - datetime64 - NP_TIMEDELTA64.H:345 - * - ``vstring\_ operator+(const char \*lhs, const vstring\_ &rhs)`` - vstring\_ - NP_VARIABLE_STRING.H:274 - * - ``vstring\_ operator+(const std::string &lhs, const vstring\_ &rhs)`` - vstring\_ - NP_VARIABLE_STRING.H:278 - * - ``NDArray& operator+=(NDArray&lhs, const NDArray&rhs)`` - NDArray& - NP_OPERATORS.H:455 - * - ``NDArray& operator+=(NDArray&lhs, const T &scalar)`` - NDArray& - NP_OPERATORS.H:461 - * - ``NDArray operator-(const NDArray&lhs, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:38 - * - ``NDArray operator-(const NDArray&lhs, const T &scalar)`` - NDArray - NP_OPERATORS.H:43 - * - ``NDArray operator-(const T &scalar, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:56 - * - ``NDArray operator-(const NDArray&array)`` - NDArray - NP_OPERATORS.H:70 - * - ``timedelta64 operator-(const timedelta64 &other)`` - timedelta64 - NP_TIMEDELTA64.H:134 - * - ``timedelta64 operator-()`` - timedelta64 - NP_TIMEDELTA64.H:160 - * - ``timedelta64 operator-(const datetime64 &other)`` - timedelta64 - NP_TIMEDELTA64.H:320 - * - ``datetime64 operator-(const timedelta64 &delta)`` - datetime64 - NP_TIMEDELTA64.H:357 - * - ``NDArray& operator-=(NDArray&lhs, const NDArray&rhs)`` - NDArray& - NP_OPERATORS.H:467 - * - ``NDArray& operator-=(NDArray&lhs, const T &scalar)`` - NDArray& - NP_OPERATORS.H:473 - * - ``NDArray operator/(const NDArray&lhs, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:108 - * - ``NDArray operator/(const NDArray&lhs, const T &scalar)`` - NDArray - NP_OPERATORS.H:113 - * - ``NDArray operator/(const T &scalar, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:126 - * - ``timedelta64 operator/(int64_tscalar)`` - timedelta64 - NP_TIMEDELTA64.H:152 - * - ``NDArray& operator/=(NDArray&lhs, const NDArray&rhs)`` - NDArray& - NP_OPERATORS.H:491 - * - ``NDArray& operator/=(NDArray&lhs, const T &scalar)`` - NDArray& - NP_OPERATORS.H:497 - * - ``bool operator<(const datetime64 &other)`` - bool - NP_DATETIME64.H:139 - * - ``bool operator<(const std::complex&a, const std::complex&b)`` - bool - NP_DTYPE.H:402 - * - ``NDArray operator<(const NDArray&lhs, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:229 - * - ``NDArray operator<(const NDArray&lhs, const T &scalar)`` - NDArray - NP_OPERATORS.H:254 - * - ``NDArray operator<(const T &scalar, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:267 - * - ``bool operator<(const timedelta64 &other)`` - bool - NP_TIMEDELTA64.H:179 - * - ``std::ostream & operator<<(std::ostream &os, const datetime64 &dt)`` - std::ostream & - NP_DATETIME64.H:312 - * - ``std::ostream & operator<<(std::ostream &os, const float16 &value)`` - std::ostream & - NP_FLOAT16.H:276 - * - ``std::ostream & operator<<(std::ostream &os, const Matrix&matrix)`` - std::ostream & - NP_MATRIX.H:461 - * - ``std::ostream & operator<<(std::ostream &os, const object\_ &obj)`` - std::ostream & - NP_OBJECT_HOLDER.H:758 - * - ``std::ostream & operator<<(std::ostream &os, const Polynomial&poly)`` - std::ostream & - NP_POLYNOMIAL.H:965 - * - ``std::ostream & operator<<(std::ostream &os, const str\_&s)`` - std::ostream & - NP_STRING_TYPES.H:177 - * - ``std::ostream & operator<<(std::ostream &os, const Timedelta &td)`` - std::ostream & - NP_TIMEDELTA.H:879 - * - ``std::ostream & operator<<(std::ostream &os, const timedelta64 &td)`` - std::ostream & - NP_TIMEDELTA64.H:369 - * - ``std::ostream & operator<<(std::ostream &os, const Timestamp &ts)`` - std::ostream & - NP_TIMESTAMP.H:1527 - * - ``std::ostream & operator<<(std::ostream &os, const vstring\_ &str)`` - std::ostream & - NP_VARIABLE_STRING.H:262 - * - ``std::ostream & operator<<(std::ostream &os, const vunicode\_ &str)`` - std::ostream & - NP_VARIABLE_STRING.H:605 - * - ``bool operator<=(const datetime64 &other)`` - bool - NP_DATETIME64.H:146 - * - ``bool operator<=(const std::complex&a, const std::complex&b)`` - bool - NP_DTYPE.H:412 - * - ``NDArray operator<=(const NDArray&lhs, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:280 - * - ``NDArray operator<=(const NDArray&lhs, const T &scalar)`` - NDArray - NP_OPERATORS.H:305 - * - ``NDArray operator<=(const T &scalar, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:318 - * - ``bool operator<=(const timedelta64 &other)`` - bool - NP_TIMEDELTA64.H:186 - * - ``PARDISOSolver & operator=(const PARDISOSolver &)`` - PARDISOSolver & - NP_PARDISO.H:170 - * - ``PARDISOSolver & noexcept operator=(PARDISOSolver &&other)`` - PARDISOSolver & noexcept - NP_PARDISO.H:200 - * - ``bool operator>(const datetime64 &other)`` - bool - NP_DATETIME64.H:150 - * - ``bool operator>(const std::complex&a, const std::complex&b)`` - bool - NP_DTYPE.H:407 - * - ``NDArray operator>(const NDArray&lhs, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:331 - * - ``NDArray operator>(const NDArray&lhs, const T &scalar)`` - NDArray - NP_OPERATORS.H:336 - * - ``NDArray operator>(const T &scalar, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:349 - * - ``bool operator>(const timedelta64 &other)`` - bool - NP_TIMEDELTA64.H:190 - * - ``bool operator>=(const datetime64 &other)`` - bool - NP_DATETIME64.H:154 - * - ``bool operator>=(const std::complex&a, const std::complex&b)`` - bool - NP_DTYPE.H:417 - * - ``NDArray operator>=(const NDArray&lhs, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:354 - * - ``NDArray operator>=(const NDArray&lhs, const T &scalar)`` - NDArray - NP_OPERATORS.H:359 - * - ``NDArray operator>=(const T &scalar, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:372 - * - ``bool operator>=(const timedelta64 &other)`` - bool - NP_TIMEDELTA64.H:194 - * - ``std::istream & operator>>(std::istream &is, vstring\_ &str)`` - std::istream & - NP_VARIABLE_STRING.H:267 - * - ``std::istream & operator>>(std::istream &is, vunicode\_ &str)`` - std::istream & - NP_VARIABLE_STRING.H:610 - * - ``NDArray operator\|\|(const NDArray&lhs, const NDArray&rhs)`` - NDArray - NP_OPERATORS.H:409 - * - ``std::string os_fspath(const std::string &path)`` - std::string - NP_IO_UTILS.H:1520 - :ref:`View ` * - ``std::string os_fspath(const std::filesystem::path &path)`` - std::string - NP_IO_UTILS.H:1535 - :ref:`View ` * - ``bool owndata(const NDArray&array)`` - bool - NP_ARRAY_INFO.H:123 - * - ``void pad_constant(NDArray&result, const NDArray&array, const std::vector>&pad_widths, Tconstant_value = T(0))`` - void - NP_PADDING.H:125 - * - ``void pad_edge(NDArray&result, const NDArray&array, const std::vector>&pad_widths)`` - void - NP_PADDING.H:156 - * - ``void pad_empty(NDArray&result, const NDArray&array, const std::vector>&pad_widths)`` - void - NP_PADDING.H:490 - * - ``void pad_linear_ramp(NDArray&result, const NDArray&array, const std::vector>&pad_widths, Tend_value = T(0))`` - void - NP_PADDING.H:429 - * - ``void pad_maximum(NDArray&result, const NDArray&array, const std::vector>&pad_widths)`` - void - NP_PADDING.H:394 - * - ``void pad_mean(NDArray&result, const NDArray&array, const std::vector>&pad_widths)`` - void - NP_PADDING.H:403 - * - ``void pad_median(NDArray&result, const NDArray&array, const std::vector>&pad_widths)`` - void - NP_PADDING.H:413 - * - ``void pad_minimum(NDArray&result, const NDArray&array, const std::vector>&pad_widths)`` - void - NP_PADDING.H:385 - * - ``void pad_reflect(NDArray&result, const NDArray&array, const std::vector>&pad_widths)`` - void - NP_PADDING.H:190 - * - ``void pad_statistical(NDArray&result, const NDArray&array, const std::vector>&pad_widths, StatFuncstat_func)`` - void - NP_PADDING.H:337 - * - ``void pad_symmetric(NDArray&result, const NDArray&array, const std::vector>&pad_widths)`` - void - NP_PADDING.H:241 - * - ``void pad_wrap(NDArray&result, const NDArray&array, const std::vector>&pad_widths)`` - void - NP_PADDING.H:292 - * - ``void parallel_merge(Iteratorfirst, Iteratormid, Iteratorlast, Comparecomp)`` - void - NP_PARALLEL_SORT.H:139 - * - ``void parallel_merge(Iteratorfirst, Iteratormid, Iteratorlast)`` - void - NP_PARALLEL_SORT.H:146 - * - ``void parallel_mergesort(Iteratorfirst, Iteratorlast, Comparecomp)`` - void - NP_PARALLEL_SORT.H:210 - * - ``void parallel_mergesort(Iteratorfirst, Iteratorlast)`` - void - NP_PARALLEL_SORT.H:223 - * - ``void parallel_mergesort_impl(Iteratorfirst, Iteratorlast, Comparecomp, size_tdepth, size_tmax_depth)`` - void - NP_PARALLEL_SORT.H:151 - * - ``void parallel_mergesort_impl(Iteratorfirst, Iteratorlast, size_tdepth, size_tmax_depth)`` - void - NP_PARALLEL_SORT.H:181 - * - ``void parallel_quicksort(Iteratorfirst, Iteratorlast, Comparecomp)`` - void - NP_PARALLEL_SORT.H:109 - * - ``void parallel_quicksort(Iteratorfirst, Iteratorlast)`` - void - NP_PARALLEL_SORT.H:122 - * - ``void parallel_quicksort_impl(Iteratorfirst, Iteratorlast, Comparecomp, size_tdepth, size_tmax_depth)`` - void - NP_PARALLEL_SORT.H:44 - * - ``void parallel_quicksort_impl(Iteratorfirst, Iteratorlast, size_tdepth, size_tmax_depth)`` - void - NP_PARALLEL_SORT.H:77 - * - ``void parallel_sort(Iteratorfirst, Iteratorlast, Comparecomp, ParallelAlgorithmalg = ParallelAlgorithm::AUTO)`` - void - NP_PARALLEL_SORT.H:311 - * - ``void parallel_sort(Iteratorfirst, Iteratorlast, ParallelAlgorithmalg = ParallelAlgorithm::AUTO)`` - void - NP_PARALLEL_SORT.H:352 - * - ``void parallel_sort(Container &container, ParallelAlgorithmalg = ParallelAlgorithm::AUTO)`` - void - NP_PARALLEL_SORT.H:394 - * - ``void parallel_sort(Container &container, Comparecomp, ParallelAlgorithmalg = ParallelAlgorithm::AUTO)`` - void - NP_PARALLEL_SORT.H:400 - * - ``int64_t parseDeltaString(const std::string &delta_string, DateTimeUnit &unit)`` - int64_t - NP_TIMEDELTA64.H:285 - * - ``int64_t parseISO8601(const std::string &iso_string, DateTimeUnit &unit)`` - int64_t - NP_DATETIME64.H:245 - * - ``Signature parseSignature(const std::string &sig_str)`` - Signature - NP_VECTORIZE_UTILS.H:27 - * - ``numpy::DType parse_dtype_string(const std::string &dtype_str)`` - numpy::DType - BINDINGS_COMMON.H:611 - * - ``DType parse_dtype_string(const std::string &dtype_str, size_t &item_size)`` - DType - NP_MEMMAP.H:57 - * - ``EinsumInfo parse_einsum(const std::string &subscripts, size_tnum_inputs)`` - EinsumInfo - NP_EINSUM.H:58 - :ref:`View ` * - ``bool parse_keepdims_parameter(const py::object &keepdims_obj)`` - bool - BINDINGS_COMMON.H:717 - * - ``MMapMode parse_mode(const std::string &mode_str)`` - MMapMode - NP_MEMMAP.H:48 - :ref:`View ` * - ``void parse_nested_sequence(const py::object &obj, std::vector&shape, std::vector&data, size_tdepth = 0)`` - void - BINDINGS_COMMON.H:260 - * - ``NPYHeader parse_npy_header_full(const std::string &filename)`` - NPYHeader - NP_MEMMAP.H:90 - * - ``PadMode parse_pad_mode(const std::string &mode)`` - PadMode - NP_PADDING.H:31 - * - ``std::vector> parse_pad_width(const NDArray&array, const std::vector>&pad_width)`` - std::vector> - NP_PADDING.H:49 - * - ``std::vector> parse_pad_width_uniform(const NDArray&array, size_tpad_width)`` - std::vector> - NP_PADDING.H:89 - * - ``RollMode parse_roll_mode(const std::string &roll_str)`` - RollMode - NP_DATETIME_UTILS.H:54 - * - ``Slice parse_slice_string(const std::string &str)`` - Slice - NP_SLICE_UTILS.H:100 - * - ``Weekmask parse_weekmask(const std::string &mask)`` - Weekmask - NP_DATETIME_UTILS.H:28 - * - ``auto phase(const NDArray&array, booldeg = false)`` - auto - NP_COMPLEX_UTILS.H:150 - :ref:`View ` * - ``double pmt(doublerate, doublenper, doublepv, doublefv = 0.0, intwhen = 0)`` - double - NP_FINANCIAL.H:86 - :ref:`View ` * - ``double pmt(doublerate, doublenper, doublepv, doublefv, intwhen)`` - double - NP_FINANCIAL.H:219 - :ref:`View ` * - ``std::pair,NDArray> polar(const NDArray&array, booldeg = false)`` - std::pair,NDArray> - NP_COMPLEX_UTILS.H:308 - :ref:`View ` * - ``Polynomial poly1d(const std::vector&coeffs, boolreverse = false, const std::string &variable = "x")`` - Polynomial - NP_POLYNOMIAL_UTILS.H:353 - :ref:`View ` * - ``Polynomial poly1d(const NDArray&coeffs, boolreverse = false, const std::string &variable = "x")`` - Polynomial - NP_POLYNOMIAL_UTILS.H:372 - :ref:`View ` * - ``std::pair,std::vector> polydiv(const std::vector÷nd, const std::vector&divisor)`` - std::pair,std::vector> - NP_POLYNOMIAL_UTILS.H:101 - :ref:`View ` * - ``std::pair,std::vector> polydiv(const std::vector&c1, const std::vector&c2)`` - std::pair,std::vector> - NP_POLYNOMIAL.H:102 - :ref:`View ` * - ``bool polyisreal(const std::vector>&coeffs, Ttol = std::numeric_limits::epsilon())`` - bool - NP_POLYNOMIAL_UTILS.H:336 - * - ``std::pair,NDArray> polyplot(const std::vector&coeffs, Tx_min, Tx_max, size_tnum_points = 100)`` - std::pair,NDArray> - NP_POLYNOMIAL_UTILS.H:314 - * - ``std::vector> polyroots(const std::vector&c)`` - std::vector> - NP_POLYNOMIAL.H:453 - :ref:`View ` * - ``T polyval(const std::vector&coeffs, Tx)`` - T - NP_POLYNOMIAL_UTILS.H:19 - :ref:`View ` * - ``T polyval(Tx, const std::vector&c)`` - T - NP_POLYNOMIAL.H:158 - :ref:`View ` * - ``T polyval2d(Tx, Ty, const std::vector>&c)`` - T - NP_POLYNOMIAL.H:182 - * - ``T polyval3d(Tx, Ty, Tz, const std::vector>>&c)`` - T - NP_POLYNOMIAL.H:218 - * - ``void pow3o2_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:1597 - * - ``NDArray> pow_complex_mkl(const NDArray>&base, const NDArray>&exponent)`` - NDArray> - NP_MKL_SPECIAL_COMPLEX.H:403 - * - ``NDArray> pow_complex_mkl(const NDArray>&base, const NDArray>&exponent)`` - NDArray> - NP_MKL_SPECIAL_COMPLEX.H:470 - * - ``double ppmt(doublerate, intper, doublenper, doublepv, doublefv = 0.0, intwhen = 0)`` - double - NP_FINANCIAL.H:172 - :ref:`View ` * - ``double ppmt(doublerate, intper, doublenper, doublepv, doublefv, intwhen)`` - double - NP_FINANCIAL.H:369 - :ref:`View ` * - ``void prefetch_read(const T \*ptr)`` - void - NP_MEMORY_POOL.H:283 - * - ``void prefetch_write(const T \*ptr)`` - void - NP_MEMORY_POOL.H:293 - * - ``void printArray(const std::string &title)`` - void - NP_NDARRAY.H:913 - :ref:`View ` * - ``std::string printNestedArray(const NDArray&arr, intmax_depth)`` - std::string - NP_NESTED_ARRAY.H:835 - :ref:`View ` * - ``void printNestedArrayRecursive(const NDArray&arr, std::ostringstream &oss, intcurrent_depth, intmax_depth, const std::string &indent)`` - void - NP_NESTED_ARRAY.H:781 - * - ``void printNestedStructure(const NDArray&arr, intmax_depth)`` - void - NP_NESTED_ARRAY.H:360 - * - ``void printNestedStructureRecursive(const NDArray&arr, intcurrent_depth, intmax_depth, const std::string &indent)`` - void - NP_NESTED_ARRAY.H:366 - * - ``void print_properties(const CSRMatrix&A, std::ostream &os = std::cout)`` - void - NP_SPARSE.H:555 - * - ``void print_result(const SolveResult&result, std::ostream &os = std::cout)`` - void - NP_SPARSE.H:578 - * - ``void print_vsl_status()`` - void - NP_VSL_RANDOM.H:2420 - :ref:`View ` * - ``PrintOptionsContext printoptions(const PrintOptions &opts)`` - PrintOptionsContext - NP_PRINT_CONFIG.H:136 - :ref:`View ` * - ``PrintOptionsContext printoptions(intprecision = -1, intthreshold = -1, intedgeitems = -1, intlinewidth = -1, bool \*suppress = nullptr, const std::string \*nanstr = nullptr, const std::string \*infstr = nullptr, bool \*sign = nullptr)`` - PrintOptionsContext - NP_PRINT_CONFIG.H:151 - :ref:`View ` * - ``void processInBlocks(Func &&processor, size_ttotal_size, Arrays &&...arrays)`` - void - NP_FROMPYFUNC.H:85 - * - ``T prod(const MaskedArray&array)`` - T - NP_MASKED_ARRAY.H:1880 - :ref:`View ` * - ``auto prod(const NDArray&array, std::optionalaxis = std::nullopt, boolkeepdims = false, NDArray, int64, typename std::conditional::type>::type>\* out = nullptr)`` - auto - NP_STATS_UTILS.H:876 - :ref:`View ` * - ``T product(const MaskedArray&array)`` - T - NP_MASKED_ARRAY.H:2060 - :ref:`View ` * - ``T product(const NDArray&array)`` - T - NP_MATH_EXTENDED.H:445 - :ref:`View ` * - ``int promoteType(const object\_ &a, const object\_ &b)`` - int - NP_OBJECT_HOLDER.H:784 - :ref:`View ` * - ``DType promote_dtype(DTypecurrent, DTypenew_type)`` - DType - NP_IO_UTILS.H:1104 - * - ``std::string promotedTypeName(const object\_ &a, const object\_ &b)`` - std::string - NP_OBJECT_HOLDER.H:804 - * - ``T psi(Tx)`` - T - NP_GAMMA_FUNCTIONS.H:322 - :ref:`View ` * - ``double pv(doublerate, doublenper, doublepmt, doublefv = 0.0, intwhen = 0)`` - double - NP_FINANCIAL.H:75 - :ref:`View ` * - ``double pv(doublerate, doublenper, doublepmt, doublefv, intwhen)`` - double - NP_FINANCIAL.H:207 - :ref:`View ` * - ``std::string quick_cosine_benchmark_report(size_tarray_size = 100000)`` - std::string - NP_SPECIAL_BENCHMARK.H:257 - :ref:`View ` * - ``GeneralizedEigenDecomposition qz_algorithm(const NDArray&A, const NDArray&B, boolcompute_left = false, typename utils::real_type::typetolerance = utils::machine_epsilon::type>())`` - GeneralizedEigenDecomposition - NP_LINALG.H:2957 - * - ``void radix_sort(std::vector&arr)`` - void - NP_SORTING_ALGORITHMS.H:656 - :ref:`View ` * - ``double rate(doublenper, doublepmt, doublepv, doublefv = 0.0, intwhen = 0, doubleguess = 0.1, doubletol = DEFAULT_TOLERANCE, intmaxiter = MAX_ITERATIONS)`` - double - NP_FINANCIAL.H:111 - :ref:`View ` * - ``double rate(doublenper, doublepmt, doublepv, doublefv, intwhen, doubleguess, doubletol, intmaxiter)`` - double - NP_FINANCIAL.H:376 - :ref:`View ` * - ``auto -> NDArray, float32, typename std::conditional, float64, typename std::conditional, longdouble, T>::type>::type>::type> real(const NDArray&array)`` - auto -> NDArray, float32, typename std::conditional, float64, typename std::conditional, longdouble, T>::type>::type>::type> - NP_COMPLEX_UTILS.H:18 - :ref:`View ` * - ``RecordArray rec_ones(const std::vector&shape, std::shared_ptrdtype)`` - RecordArray - NP_REC_CREATION.H:449 - :ref:`View ` * - ``RecordArray rec_zeros(const std::vector&shape, std::shared_ptrdtype)`` - RecordArray - NP_REC_CREATION.H:444 - :ref:`View ` * - ``RecordArray recarray(std::shared_ptrdtype, const std::vector&shape)`` - RecordArray - NP_RECARRAY.H:384 - :ref:`View ` * - ``RecordArray recfromcsv(const std::string &filename, const std::vector&names = {}, const std::vector&dtypes = {}, booluse_header = true, const std::string &missing_value = "", size_tskip_rows = 0, const std::string &comment_char = "#")`` - RecordArray - NP_IO_UTILS.H:1297 - :ref:`View ` * - ``RecordArray recfromtxt(const std::string &filename, const std::vector&names = {}, const std::vector&dtypes = {}, const std::string &delimiter = "", booluse_header = false, const std::string &missing_value = "", size_tskip_rows = 0, const std::string &comment_char = "#", size_tmax_rows = 0)`` - RecordArray - NP_IO_UTILS.H:1392 - :ref:`View ` * - ``std::any reduce(const Ufunc&ufunc, const NDArray&arr, std::optionalaxis = std::nullopt, std::optionalinitial = std::nullopt)`` - std::any - NP_UFUNC_METHODS.H:27 - :ref:`View ` * - ``RecordArray rename_fields(const RecordArray &base, const std::unordered_map&namemap)`` - RecordArray - NP_RECFUNCTIONS.H:569 - :ref:`View ` * - ``RecordArray repack_fields(const RecordArray &array, boolalign = false)`` - RecordArray - NP_RECFUNCTIONS.H:613 - :ref:`View ` * - ``CharArray replace(const CharArray&a, const std::string &old_str, const std::string &new_str, intcount = -1)`` - CharArray - NP_CHAR.H:243 - :ref:`View ` * - ``CharArray replace(const CharArray&a, const std::string &old_str, const std::string &new_str, intcount = -1)`` - CharArray - NP_CHAR_OPS.H:258 - :ref:`View ` * - ``str\_ replace(const str\_&s, const std::string &old_str, const std::string &new_str, intcount = -1)`` - str\_ - NP_STRING_TYPES.H:421 - :ref:`View ` * - ``void reset_printoptions()`` - void - NP_IO_STRING.H:464 - :ref:`View ` * - ``void reset_thread_local_stream(uint32_tseed)`` - void - NP_VSL_RANDOM.H:2380 - * - ``void reset_thread_local_stream(uint32_tseed)`` - void - NP_VSL_RANDOM.H:2385 - * - ``T riccati_jn(intn, Tx)`` - T - NP_SPHERICAL_BESSEL.H:274 - :ref:`View ` * - ``auto riccati_jn(intn, const NDArray&x)`` - auto - NP_SPHERICAL_BESSEL.H:339 - :ref:`View ` * - ``T riccati_yn(intn, Tx)`` - T - NP_SPHERICAL_BESSEL.H:280 - :ref:`View ` * - ``auto riccati_yn(intn, const NDArray&x)`` - auto - NP_SPHERICAL_BESSEL.H:352 - :ref:`View ` * - ``LeastSquaresResult ridge_regression(const NDArray&A, const NDArray&b, Talpha = T{1.0})`` - LeastSquaresResult - NP_LINALG.H:2471 - :ref:`View ` * - ``CharArray rjust(const CharArray&a, size_twidth, charfillchar = ' ')`` - CharArray - NP_CHAR.H:145 - :ref:`View ` * - ``CharArray rjust(const CharArray&a, size_twidth, charfillchar = ' ')`` - CharArray - NP_CHAR_OPS.H:86 - :ref:`View ` * - ``str\_ rjust(const str\_&s, size_twidth, charfillchar = ' ')`` - str\_ - NP_STRING_TYPES.H:464 - :ref:`View ` * - ``datetime64 rollDate(const datetime64 &date, RollModemode, const Weekmask &weekmask, const std::set&holidays)`` - datetime64 - NP_DATETIME_UTILS.H:139 - * - ``std::vector> roots(const std::vector&coeffs)`` - std::vector> - NP_POLYNOMIAL_UTILS.H:218 - :ref:`View ` * - ``std::tuple,CharArray,CharArray> rpartition(const CharArray&a, const std::string &sep)`` - std::tuple,CharArray,CharArray> - NP_CHAR.H:273 - :ref:`View ` * - ``std::tuple,CharArray,CharArray> rpartition(const CharArray&a, const std::string &sep)`` - std::tuple,CharArray,CharArray> - NP_CHAR_OPS.H:482 - :ref:`View ` * - ``std::vector> rsplit(const CharArray&a, const std::string &sep = "", intmaxsplit = -1)`` - std::vector> - NP_CHAR.H:253 - :ref:`View ` * - ``std::vector> rsplit(const CharArray&a, const std::string &sep = "", intmaxsplit = -1)`` - std::vector> - NP_CHAR_OPS.H:196 - :ref:`View ` * - ``CharArray rstrip(const CharArray&a, const std::string &chars = " \\n\\r\\f\\v")`` - CharArray - NP_CHAR.H:129 - :ref:`View ` * - ``str\_ rstrip(const str\_&s, const std::string &chars = " \\n\\r\\f\\v")`` - str\_ - NP_STRING_TYPES.H:297 - :ref:`View ` * - ``void run_full_benchmark()`` - void - NP_BENCHMARK_SORTING.H:527 - * - ``void run_full_benchmark_suite()`` - void - NP_SPECIAL_BENCHMARK.H:276 - * - ``void run_quick_benchmark()`` - void - NP_BENCHMARK_SORTING.H:508 - * - ``T safe_divide(Tnumerator, Tdenominator, real_type_ttolerance = machine_epsilon>())`` - T - NP_LINALG_UTILS.H:110 - :ref:`View ` * - ``T safe_eval(const std::string &expression)`` - T - NP_INTROSPECTION.H:390 - :ref:`View ` * - ``T safe_eval(const std::string &expression)`` - T - NP_LIB_COMPAT.H:123 - :ref:`View ` * - ``T safe_factorial(intn)`` - T - NP_ORTHOGONAL_POLYNOMIALS.H:14 - * - ``T safe_max()`` - T - NP_LINALG_UTILS.H:91 - * - ``T safe_min()`` - T - NP_LINALG_UTILS.H:86 - * - ``void scale_row(T \*data, size_tcols, size_trow, Tscalar)`` - void - NP_LINALG_UTILS.H:183 - :ref:`View ` * - ``std::tuple,NDArray> schur(const NDArray&A, boolcompute_vectors = true)`` - std::tuple,NDArray> - NP_LINALG.H:4241 - :ref:`View ` * - ``SchurDecomposition schur_decomposition(const NDArray&matrix, typename utils::real_type::typetolerance = utils::machine_epsilon::type>())`` - SchurDecomposition - NP_LINALG.H:4135 - :ref:`View ` * - ``RealSchurDecomposition schur_real(const NDArray&matrix, Ttolerance = utils::machine_epsilon())`` - RealSchurDecomposition - NP_LINALG.H:4206 - * - ``NUMPYCORE_API char sctype2char(DTypedtype)`` - NUMPYCORE_API char - NP_DTYPE_UTILS.H:199 - :ref:`View ` * - ``void setElementAt(const std::vector&indices, const T &value)`` - void - NP_NDARRAY.H:537 - :ref:`View ` * - ``void set_array_wrap(decltype(detail::array_wrap_func)func)`` - void - NP_INTROSPECTION.H:307 - * - ``void set_bit_generator(std::shared_ptrbitgen)`` - void - NP_RANDOM.H:2870 - :ref:`View ` * - ``void set_block(T \*dest, const T \*source, size_tstart_row, size_tstart_col, size_tblock_rows, size_tblock_cols, size_tdest_lda, size_tsrc_lda)`` - void - NP_LINALG_UTILS.H:541 - * - ``void set_column(T \*matrix, size_trows, size_tcols, size_tcol_idx, const T \*column, size_tstart_row = 0)`` - void - NP_LINALG_UTILS.H:386 - * - ``void set_default_printstyle(const std::string &style)`` - void - NP_POLYNOMIAL.H:129 - :ref:`View ` * - ``void set_default_value(RecordArray &arr, const std::vector&indices, const std::string &field_name, DTypedtype)`` - void - NP_IO_UTILS.H:1216 - * - ``void set_field_from_string(RecordArray &arr, const std::vector&indices, const std::string &field_name, DTypedtype, const std::string &value_str)`` - void - NP_IO_UTILS.H:1154 - * - ``void set_field_value_from_python(numpy::StructuredArray &arr, size_trow_idx, const numpy::FieldDescriptor &field, py::objectvalue_obj)`` - void - BINDINGS_HELPERS.H:614 - * - ``void set_message_level(intlevel)`` - void - NP_PARDISO.H:395 - * - ``void set_module(const std::string &module_name)`` - void - NP_CHAR.H:438 - :ref:`View ` * - ``void set_num_threads(intnum_threads)`` - void - NP_PARDISO.H:386 - * - ``void set_numeric_ops(const std::unordered_map>&ops)`` - void - NP_INTROSPECTION.H:332 - :ref:`View ` * - ``void set_polynomial_precision(intprecision)`` - void - NP_POLYNOMIAL.H:140 - :ref:`View ` * - ``void set_polynomial_suppress_threshold(doublethreshold)`` - void - NP_POLYNOMIAL.H:148 - * - ``void set_printoptions(intprecision = -1, size_tthreshold = 0, size_tedgeitems = 0, size_tlinewidth = 0, boolsuppress = false, const std::string &separator = "", const std::string &floatmode = "", const std::string &sign = "")`` - void - NP_IO_STRING.H:440 - :ref:`View ` * - ``void set_printoptions(const PrintOptions &opts)`` - void - NP_PRINT_CONFIG.H:146 - :ref:`View ` * - ``void set_state(uint32_tseed)`` - void - NP_RANDOM.H:1748 - :ref:`View ` * - ``void set_string_function(std::function&)>func)`` - void - NP_INTROSPECTION.H:348 - :ref:`View ` * - ``void set_string_function(std::function&,DType)>repr_func, boolis_repr = true)`` - void - NP_IO_STRING.H:469 - :ref:`View ` * - ``void set_tril(NDArray&arr, Tvalue, intk = 0)`` - void - NP_INDEXING_TRIANGULAR.H:225 - :ref:`View ` * - ``void set_triu(NDArray&arr, Tvalue, intk = 0)`` - void - NP_INDEXING_TRIANGULAR.H:239 - :ref:`View ` * - ``size_t setbufsize(size_tsize)`` - size_t - NP_ERROR_HANDLING.H:318 - :ref:`View ` * - ``ErrorState seterrobj(const ErrorState &errobj)`` - ErrorState - NP_ERROR_HANDLING.H:290 - :ref:`View ` * - ``void setflags(boolwrite, boolalign, booluic)`` - void - NP_NDARRAY.H:1423 - :ref:`View ` * - ``std::string shapeToString(const std::vector&shape)`` - std::string - NP_BROADCASTING_UTILS.H:11 - * - ``std::string shapeToString(const std::vector&shape)`` - std::string - NP_VECTORIZE_UTILS.H:340 - * - ``std::string shape_to_string(const std::vector&shape)`` - std::string - NP_STATS_UTILS.H:45 - * - ``bool shapesEqual(const std::vector&shape1, const std::vector&shape2)`` - bool - NP_VECTORIZE_UTILS.H:336 - * - ``bool shares_memory(const NDArray&a, const NDArray&b, size_tmax_work = 10000)`` - bool - NP_MEMORY_UTILS.H:46 - :ref:`View ` * - ``T shi(Tx)`` - T - NP_MISCELLANEOUS.H:183 - :ref:`View ` * - ``bool should_suppress_coefficient(Tvalue, doublethreshold)`` - bool - NP_POLYNOMIAL.H:119 - * - ``bool should_use_counting_sort(const std::vector&arr, T &min_val, T &max_val)`` - bool - NP_SORTING_ALGORITHMS.H:1565 - * - ``bool should_use_simd(size_tn)`` - bool - NP_SIMD_SORT.H:282 - * - ``void show_config()`` - void - NP_ERROR_HANDLING.H:345 - :ref:`View ` * - ``void show_config()`` - void - NP_RUNTIME_INFO.H:157 - :ref:`View ` * - ``void show_runtime()`` - void - NP_RUNTIME_INFO.H:51 - :ref:`View ` * - ``T si(Tx)`` - T - NP_MISCELLANEOUS.H:108 - :ref:`View ` * - ``void sift_down(Iteratorfirst, size_tstart, size_tend)`` - void - NP_SORTING_ALGORITHMS.H:291 - * - ``void sift_down(Iteratorfirst, size_tstart, size_tend, Comparecomp)`` - void - NP_SORTING_ALGORITHMS.H:317 - * - ``int8_t sign(const int8_t &x)`` - int8_t - NP_MATH_UTILS_SQRT.H:4367 - :ref:`View ` * - ``int16_t sign(const int16_t &x)`` - int16_t - NP_MATH_UTILS_SQRT.H:4374 - :ref:`View ` * - ``int32_t sign(const int32_t &x)`` - int32_t - NP_MATH_UTILS_SQRT.H:4381 - :ref:`View ` * - ``int64_t sign(const int64_t &x)`` - int64_t - NP_MATH_UTILS_SQRT.H:4388 - :ref:`View ` * - ``uint8_t sign(const uint8_t &x)`` - uint8_t - NP_MATH_UTILS_SQRT.H:4395 - :ref:`View ` * - ``uint16_t sign(const uint16_t &x)`` - uint16_t - NP_MATH_UTILS_SQRT.H:4400 - :ref:`View ` * - ``uint32_t sign(const uint32_t &x)`` - uint32_t - NP_MATH_UTILS_SQRT.H:4405 - :ref:`View ` * - ``uint64_t sign(const uint64_t &x)`` - uint64_t - NP_MATH_UTILS_SQRT.H:4410 - :ref:`View ` * - ``bool\_ sign(const bool\_ &x)`` - bool\_ - NP_MATH_UTILS_SQRT.H:4415 - :ref:`View ` * - ``float32 sign(const float32 &x)`` - float32 - NP_MATH_UTILS_SQRT.H:4420 - :ref:`View ` * - ``double sign(const double &x)`` - double - NP_MATH_UTILS_SQRT.H:4428 - :ref:`View ` * - ``complex64 sign(const complex64 &x)`` - complex64 - NP_MATH_UTILS_SQRT.H:4436 - :ref:`View ` * - ``complex128 sign(const complex128 &x)`` - complex128 - NP_MATH_UTILS_SQRT.H:4449 - :ref:`View ` * - ``bool signbit(floatvalue)`` - bool - NP_MATH_UTILS_SQRT.H:6712 - :ref:`View ` * - ``bool signbit(doublevalue)`` - bool - NP_MATH_UTILS_SQRT.H:6716 - :ref:`View ` * - ``Matrix signm(const Matrix&matrix)`` - Matrix - NP_MATRIX_SPECIAL.H:407 - * - ``size_t simd_alignment()`` - size_t - NP_SIMD_SORT.H:73 - * - ``void simd_insertion_sort(T \*arr, size_tn)`` - void - NP_SIMD_SORT.H:295 - * - ``size_t simd_partition(T \*arr, size_tn, Tpivot)`` - size_t - NP_SIMD_SORT.H:256 - * - ``std::vector> simple_dft(const std::vector>&input)`` - std::vector> - NP_FFT.H:131 - * - ``std::vector> simple_idft(const std::vector>&input)`` - std::vector> - NP_FFT.H:148 - * - ``size_t size(const NDArray&array)`` - size_t - NP_ARRAY_INFO.H:23 - :ref:`View ` * - ``auto skew(const NDArray&array, std::optionalaxis = std::nullopt, boolbias = true, boolkeepdims = false)`` - auto - NP_STATS_UTILS.H:1766 - :ref:`View ` * - ``bool sometrue(const MaskedArray&array)`` - bool - NP_MASKED_ARRAY.H:2021 - :ref:`View ` * - ``bool sometrue(const NDArray&array)`` - bool - NP_NUMPY_WRAPPERS.H:364 - :ref:`View ` * - ``void source(const T &obj)`` - void - NP_INTROSPECTION.H:188 - :ref:`View ` * - ``T spacing(Tvalue)`` - T - NP_MATH_UTILS_SQRT.H:6892 - :ref:`View ` * - ``CSRMatrix spadd(const CSRMatrix&A, const CSRMatrix&B, Talpha = T{1}, Tbeta = T{1})`` - CSRMatrix - NP_SPARSE.H:517 - * - ``CSRMatrix sparse(const NDArray&dense, Ttol = T{1e-10})`` - CSRMatrix - NP_SPARSE.H:471 - :ref:`View ` * - ``ArnoldiResult sparse_eigenvalues(const NDArray&matrix, size_tnum_eigenvalues = 6, std::stringwhich = "LM", typename real_type::typetolerance = 1e-12, size_tmax_iterations = 1000)`` - ArnoldiResult - NP_LINALG_UTILS.H:2519 - * - ``bool sparse_equals(const CSRMatrix&a, const CSRMatrix&b, Ttol = T{1e-10})`` - bool - NP_SPARSE_CONVERT.H:140 - * - ``bool sparse_equals(const COOMatrix&a, const COOMatrix&b, Ttol = T{1e-10})`` - bool - NP_SPARSE_CONVERT.H:166 - * - ``CorrelationResult spearmanr(const NDArray&x, const NDArray\*y = nullptr)`` - CorrelationResult - NP_STATS_UTILS.H:2140 - :ref:`View ` * - ``T spence(Tx)`` - T - NP_MISCELLANEOUS.H:64 - :ref:`View ` * - ``T spherical_in(intn, Tx)`` - T - NP_SPHERICAL_BESSEL.H:183 - :ref:`View ` * - ``auto spherical_in(intn, const NDArray&x)`` - auto - NP_SPHERICAL_BESSEL.H:313 - :ref:`View ` * - ``T spherical_jn(intn, Tx)`` - T - NP_SPHERICAL_BESSEL.H:104 - :ref:`View ` * - ``auto spherical_jn(intn, const NDArray&x)`` - auto - NP_SPHERICAL_BESSEL.H:287 - :ref:`View ` * - ``T spherical_jn_asymptotic(intn, Tx)`` - T - NP_SPHERICAL_BESSEL.H:58 - * - ``T spherical_jn_miller(intn, Tx)`` - T - NP_SPHERICAL_BESSEL.H:73 - * - ``T spherical_jn_small(intn, Tx)`` - T - NP_SPHERICAL_BESSEL.H:27 - * - ``T spherical_kn(intn, Tx)`` - T - NP_SPHERICAL_BESSEL.H:227 - :ref:`View ` * - ``auto spherical_kn(intn, const NDArray&x)`` - auto - NP_SPHERICAL_BESSEL.H:326 - :ref:`View ` * - ``T spherical_yn(intn, Tx)`` - T - NP_SPHERICAL_BESSEL.H:138 - :ref:`View ` * - ``auto spherical_yn(intn, const NDArray&x)`` - auto - NP_SPHERICAL_BESSEL.H:300 - :ref:`View ` * - ``T spherical_yn_asymptotic(intn, Tx)`` - T - NP_SPHERICAL_BESSEL.H:65 - * - ``CSRMatrix sptranspose(const CSRMatrix&A)`` - CSRMatrix - NP_SPARSE.H:543 - * - ``void sqr_mkl_inplace(NDArray&array)`` - void - NP_MKL_SPECIAL.H:1433 - * - ``datetime64 startOfMonth(const datetime64 &date)`` - datetime64 - NP_DATETIME_UTILS.H:429 - :ref:`View ` * - ``datetime64 startOfWeek(const datetime64 &date, intstart_day = 0)`` - datetime64 - NP_DATETIME_UTILS.H:412 - :ref:`View ` * - ``datetime64 startOfYear(const datetime64 &date)`` - datetime64 - NP_DATETIME_UTILS.H:466 - :ref:`View ` * - ``bool startswith(const str\_&s, const std::string &prefix)`` - bool - NP_STRING_TYPES.H:309 - :ref:`View ` * - ``NDArray> str_asbytes(const NDArray&array)`` - NDArray> - NP_STRING_OPERATIONS.H:1163 - * - ``std::tuple,NDArray,NDArray> str_partition(const NDArray&array, const StringType &sep)`` - std::tuple,NDArray,NDArray> - NP_STRING_OPERATIONS.H:887 - :ref:`View ` * - ``std::tuple,NDArray,NDArray> str_rpartition(const NDArray&array, const StringType &sep)`` - std::tuple,NDArray,NDArray> - NP_STRING_OPERATIONS.H:916 - :ref:`View ` * - ``std::vector> str_rsplit(const NDArray&array, const StringType &sep, intmaxsplit = -1)`` - std::vector> - NP_STRING_OPERATIONS.H:841 - :ref:`View ` * - ``std::vector> str_split(const NDArray&array, const StringType &sep, intmaxsplit = -1)`` - std::vector> - NP_STRING_OPERATIONS.H:644 - :ref:`View ` * - ``std::vector> str_splitlines(const NDArray&array, boolkeepends = false)`` - std::vector> - NP_STRING_OPERATIONS.H:864 - :ref:`View ` * - ``ErrorMode string_to_error_mode(const std::string &str)`` - ErrorMode - NP_ERROR_HANDLING.H:47 - * - ``CharArray strip(const CharArray&a, const std::string &chars = " \\n\\r\\f\\v")`` - CharArray - NP_CHAR.H:119 - :ref:`View ` * - ``str\_ strip(const str\_&s, const std::string &chars = " \\n\\r\\f\\v")`` - str\_ - NP_STRING_TYPES.H:268 - :ref:`View ` * - ``py::list structured_to_python_dtype(const numpy::StructuredDType &dtype)`` - py::list - BINDINGS_HELPERS.H:479 - * - ``py::array structuredarray_to_numpy(const numpy::StructuredArray &arr)`` - py::array - BINDINGS_HELPERS.H:499 - * - ``void swap_rows(T \*data, size_tcols, size_trow1, size_trow2)`` - void - NP_LINALG_UTILS.H:172 - :ref:`View ` * - ``CharArray swapcase(const CharArray&a)`` - CharArray - NP_CHAR.H:113 - :ref:`View ` * - ``auto symeig_accelerated(const NDArray&matrix, boolcompute_vectors = true)`` - auto - NP_MKL_LINALG.H:3717 - :ref:`View ` * - ``void syrk_lower(const T \*A, T \*C, size_tn, size_tk, size_tlda, size_tldc)`` - void - NP_LINALG_UTILS.H:515 - * - ``void three_way_quicksort(Iteratorfirst, Iteratorlast, Comparecomp)`` - void - NP_SORTING_ALGORITHMS.H:1496 - * - ``void three_way_quicksort(Iteratorfirst, Iteratorlast)`` - void - NP_SORTING_ALGORITHMS.H:1522 - * - ``timedelta64(int64_tvalue, DateTimeUnitunit)`` - - NP_TIMEDELTA64.H:66 - :ref:`View ` * - ``timedelta64(const std::string &delta_string)`` - - NP_TIMEDELTA64.H:70 - :ref:`View ` * - ``void timsort(Iteratorfirst, Iteratorlast)`` - void - NP_SORTING_ALGORITHMS.H:948 - :ref:`View ` * - ``void timsort(Iteratorfirst, Iteratorlast, Comparecomp)`` - void - NP_SORTING_ALGORITHMS.H:979 - :ref:`View ` * - ``CharArray title(const CharArray&a)`` - CharArray - NP_CHAR.H:108 - :ref:`View ` * - ``str\_ title(const str\_&s)`` - str\_ - NP_STRING_TYPES.H:253 - :ref:`View ` * - ``int64_t toDays()`` - int64_t - NP_TIMEDELTA64.H:235 - :ref:`View ` * - ``int64_t toEpochSeconds()`` - int64_t - NP_DATETIME64.H:86 - :ref:`View ` * - ``int64_t toHours()`` - int64_t - NP_TIMEDELTA64.H:239 - :ref:`View ` * - ``int64_t toMinutes()`` - int64_t - NP_TIMEDELTA64.H:243 - :ref:`View ` * - ``int64_t toSeconds()`` - int64_t - NP_TIMEDELTA64.H:74 - :ref:`View ` * - ``double toSecondsDouble()`` - double - NP_TIMEDELTA64.H:247 - * - ``std::string toString()`` - std::string - NP_DATETIME64.H:158 - :ref:`View ` * - ``std::string toString(const std::string &title)`` - std::string - NP_NDARRAY.H:875 - :ref:`View ` * - ``std::string toString()`` - std::string - NP_TIMEDELTA64.H:198 - :ref:`View ` * - ``std::tm toTm()`` - std::tm - NP_DATETIME64.H:187 - * - ``datetime64 today()`` - datetime64 - NP_DATETIME64.H:211 - :ref:`View ` * - ``Matrix toeplitz(const std::vector&c, const std::vector&r = {})`` - Matrix - NP_MATRIX_SPECIAL.H:487 - :ref:`View ` * - ``CharArray translate(const CharArray&a, const std::string &table)`` - CharArray - NP_CHAR.H:296 - :ref:`View ` * - ``CharArray translate(const CharArray&a, const std::string &table)`` - CharArray - NP_CHAR_OPS.H:508 - :ref:`View ` * - ``T trapezoid(const NDArray&y, const NDArray\*x = nullptr, Tdx = T{1}, intaxis = -1)`` - T - NP_NUMERICAL.H:212 - :ref:`View ` * - ``T trapezoid(const NDArray&y, Tdx)`` - T - NP_NUMERICAL.H:225 - :ref:`View ` * - ``T trapezoid(const NDArray&y, const NDArray&x)`` - T - NP_NUMERICAL.H:238 - :ref:`View ` * - ``T trapz(const NDArray&y, const NDArray\*x = nullptr, Tdx = T{1})`` - T - NP_NUMERICAL.H:143 - :ref:`View ` * - ``T trapz(const NDArray&y, Tdx)`` - T - NP_NUMERICAL.H:190 - :ref:`View ` * - ``void trsm_left_lower(const T \*L, T \*B, size_tn, size_tnrhs, size_tldl, size_tldb)`` - void - NP_LINALG_UTILS.H:494 - * - ``T try_cast(const object\_ &obj, const T &fallback = T{})`` - T - NP_OBJECT_UTILS.H:87 - :ref:`View ` * - ``bool tuple_compare_by_index(const std::tuple&a, const std::tuple&b, size_tindex)`` - bool - NP_SORTING_ALGORITHMS.H:1393 - * - ``bool tuple_compare_helper(const std::tuple&a, const std::tuple&b, size_truntime_index)`` - bool - NP_SORTING_ALGORITHMS.H:1406 - * - ``std::string type_id_name(ObjectTypeIdid)`` - std::string - NP_OBJECT_UTILS.H:58 - * - ``std::string typename\_(DTypedtype)`` - std::string - NP_DTYPE_UTILS.H:252 - :ref:`View ` * - ``std::string typename\_()`` - std::string - NP_LIB_COMPAT.H:100 - :ref:`View ` * - ``std::string typename\_(const T &obj)`` - std::string - NP_LIB_COMPAT.H:106 - :ref:`View ` * - ``NUMPYCORE_API std::string typename_from_char(chartypecode)`` - NUMPYCORE_API std::string - NP_DTYPE_UTILS.H:215 - :ref:`View ` * - ``std::string typename_str(DTypedtype)`` - std::string - NP_DTYPE_UTILS.H:232 - :ref:`View ` * - ``std::string typename_str()`` - std::string - NP_INTROSPECTION.H:293 - :ref:`View ` * - ``void unbalance_eigenvectors(NDArray&eigenvectors, const BalancingResult&balance_info)`` - void - NP_LINALG_UTILS.H:1410 - * - ``std::vector> unravel_index(const std::vector&indices, const std::vector&shape)`` - std::vector> - NP_INDEXING_DIAGONAL.H:179 - :ref:`View ` * - ``std::vector> unravel_index(size_tindex, const std::vector&shape)`` - std::vector> - NP_INDEXING_DIAGONAL.H:231 - :ref:`View ` * - ``CharArray upper(const CharArray&a)`` - CharArray - NP_CHAR.H:98 - :ref:`View ` * - ``std::u32string utf8_to_utf32(const std::string &utf8_str)`` - std::u32string - NP_STRING_SORT.H:60 - :ref:`View ` * - ``bool validateNestedStructure(const NDArray&arr)`` - bool - NP_NESTED_ARRAY.H:556 - :ref:`View ` * - ``void validate_einsum_dimensions(const std::vector>&inputs, const EinsumInfo &info)`` - void - NP_EINSUM.H:154 - * - ``bool validate_file_size(const std::string &filename, const std::vector&shape)`` - bool - NP_IO_UTILS.H:991 - :ref:`View ` * - ``void validate_integer_power(const TBase &base, const TExp &exp)`` - void - NP_MATH_UTILS_SQRT.H:1276 - * - ``bool values_equal(const T &a, const T &b, boolequal_nan)`` - bool - NP_SET_UTILS.H:30 - * - ``bool values_less(const T &a, const T &b, boolequal_nan)`` - bool - NP_SET_UTILS.H:38 - * - ``void vc_abs(MKL_INTn, const MKL_Complex8 \*a, float \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:204 - * - ``void vc_acos(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:108 - * - ``void vc_acosh(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:166 - * - ``void vc_arg(MKL_INTn, const MKL_Complex8 \*a, float \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:213 - * - ``void vc_asin(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:117 - * - ``void vc_asinh(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:175 - * - ``void vc_atan(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:126 - * - ``void vc_atanh(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:184 - * - ``void vc_conj(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:222 - * - ``void vc_cos(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:79 - * - ``void vc_cosh(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:137 - * - ``void vc_exp(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:30 - * - ``void vc_ln(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:39 - * - ``void vc_log10(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:48 - * - ``void vc_pow(MKL_INTn, const MKL_Complex8 \*a, const MKL_Complex8 \*b, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:59 - * - ``void vc_powx(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8b, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:68 - * - ``void vc_sin(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:88 - * - ``void vc_sinh(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:146 - * - ``void vc_sqrt(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:195 - * - ``void vc_tan(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:97 - * - ``void vc_tanh(MKL_INTn, const MKL_Complex8 \*a, MKL_Complex8 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:155 - * - ``void vd_acos(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:100 - * - ``void vd_acosh(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:172 - * - ``void vd_asin(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:90 - * - ``void vd_asinh(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:162 - * - ``void vd_atan(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:110 - * - ``void vd_atan2(MKL_INTn, const double \*a, const double \*b, double \*y)`` - void - NP_MKL_SPECIAL.H:120 - * - ``void vd_atanh(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:182 - * - ``void vd_cbrt(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:1314 - * - ``void vd_cdfnorm(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:876 - * - ``void vd_cdfnorminv(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:885 - * - ``void vd_ceil(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:1669 - * - ``void vd_cos(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:57 - * - ``void vd_cosh(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:141 - * - ``void vd_erf(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:831 - * - ``void vd_erfc(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:840 - * - ``void vd_erfcinv(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:858 - * - ``void vd_erfcx(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:849 - * - ``void vd_erfinv(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:867 - * - ``void vd_exp(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:705 - * - ``void vd_expm1(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:715 - * - ``void vd_floor(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:1678 - * - ``void vd_fmod(MKL_INTn, const double \*a, const double \*b, double \*y)`` - void - NP_MKL_SPECIAL.H:1714 - * - ``void vd_frac(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:1705 - * - ``void vd_i0(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:757 - * - ``void vd_i1(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:766 - * - ``void vd_invcbrt(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:1332 - * - ``void vd_invsqrt(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:1323 - * - ``void vd_j0(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:775 - * - ``void vd_j1(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:784 - * - ``void vd_lgamma(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:812 - * - ``void vd_ln(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:726 - * - ``void vd_log10(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:736 - * - ``void vd_log1p(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:746 - * - ``void vd_pow(MKL_INTn, const double \*a, const double \*b, double \*y)`` - void - NP_MKL_SPECIAL.H:1359 - * - ``void vd_pow3o2(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:1341 - * - ``void vd_powx(MKL_INTn, const double \*a, doubleb, double \*y)`` - void - NP_MKL_SPECIAL.H:1350 - * - ``void vd_remainder(MKL_INTn, const double \*a, const double \*b, double \*y)`` - void - NP_MKL_SPECIAL.H:1723 - * - ``void vd_round(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:1696 - * - ``void vd_sin(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:68 - * - ``void vd_sinh(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:131 - * - ``void vd_sqr(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:1305 - * - ``void vd_sqrt(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:1296 - * - ``void vd_tan(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:79 - * - ``void vd_tanh(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:151 - * - ``void vd_tgamma(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:821 - * - ``void vd_trunc(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:1687 - * - ``void vd_y0(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:793 - * - ``void vd_y1(MKL_INTn, const double \*a, double \*y)`` - void - NP_MKL_SPECIAL.H:802 - * - ``T vector_norm_2(const T \*data, size_tn)`` - T - NP_LINALG_UTILS.H:214 - :ref:`View ` * - ``T vector_norm_inf(const T \*data, size_tn)`` - T - NP_LINALG_UTILS.H:224 - :ref:`View ` * - ``auto vectorize(Func &&func)`` - auto - NP_VECTORIZE.H:245 - :ref:`View ` * - ``auto vectorize(Func &&func, const VectorizeOptions &options)`` - auto - NP_VECTORIZE.H:250 - :ref:`View ` * - ``auto vectorize(Func &&func, const char \*signature)`` - auto - NP_VECTORIZE.H:258 - :ref:`View ` * - ``auto vectorize(Func &&func, const std::string &signature)`` - auto - NP_VECTORIZE.H:264 - :ref:`View ` * - ``auto vectorize(Func &&func, const std::vector&excluded)`` - auto - NP_VECTORIZE.H:270 - :ref:`View ` * - ``auto vectorize(Func &&func, boolcache, size_tcache_size = 1000)`` - auto - NP_VECTORIZE.H:276 - :ref:`View ` * - ``void vs_acos(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:105 - * - ``void vs_acosh(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:177 - * - ``void vs_asin(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:95 - * - ``void vs_asinh(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:167 - * - ``void vs_atan(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:115 - * - ``void vs_atan2(MKL_INTn, const float \*a, const float \*b, float \*y)`` - void - NP_MKL_SPECIAL.H:125 - * - ``void vs_atanh(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:187 - * - ``void vs_cbrt(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:1318 - * - ``void vs_cdfnorm(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:880 - * - ``void vs_cdfnorminv(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:889 - * - ``void vs_ceil(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:1673 - * - ``void vs_cos(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:62 - * - ``void vs_cosh(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:146 - * - ``void vs_erf(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:835 - * - ``void vs_erfc(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:844 - * - ``void vs_erfcinv(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:862 - * - ``void vs_erfcx(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:853 - * - ``void vs_erfinv(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:871 - * - ``void vs_exp(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:710 - * - ``void vs_expm1(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:720 - * - ``void vs_floor(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:1682 - * - ``void vs_fmod(MKL_INTn, const float \*a, const float \*b, float \*y)`` - void - NP_MKL_SPECIAL.H:1718 - * - ``void vs_frac(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:1709 - * - ``void vs_i0(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:761 - * - ``void vs_i1(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:770 - * - ``void vs_invcbrt(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:1336 - * - ``void vs_invsqrt(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:1327 - * - ``void vs_j0(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:779 - * - ``void vs_j1(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:788 - * - ``void vs_lgamma(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:816 - * - ``void vs_ln(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:731 - * - ``void vs_log10(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:741 - * - ``void vs_log1p(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:751 - * - ``void vs_pow(MKL_INTn, const float \*a, const float \*b, float \*y)`` - void - NP_MKL_SPECIAL.H:1363 - * - ``void vs_pow3o2(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:1345 - * - ``void vs_powx(MKL_INTn, const float \*a, floatb, float \*y)`` - void - NP_MKL_SPECIAL.H:1354 - * - ``void vs_remainder(MKL_INTn, const float \*a, const float \*b, float \*y)`` - void - NP_MKL_SPECIAL.H:1727 - * - ``void vs_round(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:1700 - * - ``void vs_sin(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:73 - * - ``void vs_sinh(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:136 - * - ``void vs_sqr(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:1309 - * - ``void vs_sqrt(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:1300 - * - ``void vs_tan(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:84 - * - ``void vs_tanh(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:156 - * - ``void vs_tgamma(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:825 - * - ``void vs_trunc(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:1691 - * - ``void vs_y0(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:797 - * - ``void vs_y1(MKL_INTn, const float \*a, float \*y)`` - void - NP_MKL_SPECIAL.H:806 - * - ``void vz_abs(MKL_INTn, const MKL_Complex16 \*a, double \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:208 - * - ``void vz_acos(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:112 - * - ``void vz_acosh(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:170 - * - ``void vz_arg(MKL_INTn, const MKL_Complex16 \*a, double \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:217 - * - ``void vz_asin(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:121 - * - ``void vz_asinh(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:179 - * - ``void vz_atan(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:130 - * - ``void vz_atanh(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:188 - * - ``void vz_conj(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:226 - * - ``void vz_cos(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:83 - * - ``void vz_cosh(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:141 - * - ``void vz_exp(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:34 - * - ``void vz_ln(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:43 - * - ``void vz_log10(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:52 - * - ``void vz_pow(MKL_INTn, const MKL_Complex16 \*a, const MKL_Complex16 \*b, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:63 - * - ``void vz_powx(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16b, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:72 - * - ``void vz_sin(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:92 - * - ``void vz_sinh(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:150 - * - ``void vz_sqrt(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:199 - * - ``void vz_tan(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:101 - * - ``void vz_tanh(MKL_INTn, const MKL_Complex16 \*a, MKL_Complex16 \*y)`` - void - NP_MKL_SPECIAL_COMPLEX.H:159 - * - ``void who(const std::string &scope = "")`` - void - NP_INTROSPECTION.H:252 - :ref:`View ` * - ``CharArray zfill(const CharArray&a, size_twidth)`` - CharArray - NP_CHAR.H:150 - :ref:`View ` * - ``CharArray zfill(const CharArray&a, size_twidth)`` - CharArray - NP_CHAR_OPS.H:104 - :ref:`View ` * - ``str\_ zfill(const str\_&s, size_twidth)`` - str\_ - NP_STRING_TYPES.H:475 - :ref:`View ` * - ``auto zscore(const NDArray&array, std::optionalaxis = std::nullopt, intddof = 0)`` - auto - NP_STATS_UTILS.H:1993 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-top_level-diag-0: .. dropdown:: diag (np_test_1_all.cpp:15651) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15641 :emphasize-lines: 11 auto svd_1x1 = svd_decomposition(matrix1x1, false); // std::cout << "1x1 matrix singular value: " << svd_1x1.S.getElementAt({ 0 }) << std::endl; if (!(std::abs(svd_1x1.S.getElementAt({ 0 }) - 5.0) < 1e-10)) { std::string description = std::string("test_svd_edge_cases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(svd_1x1.S.getElementAt({ 0 }) - 5.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test diagonal matrix NDArray diag({ 3, 3 }); diag.setElementAt({ 0, 0 }, 3.0); diag.setElementAt({ 1, 1 }, 2.0); diag.setElementAt({ 2, 2 }, 1.0); // All off-diagonal elements are already 0 auto svd_diag = svd_decomposition(diag, false); // std::cout << "Diagonal matrix singular values:" << std::endl; //svd_diag.S.printArray(); // Singular values should be sorted in descending order .. _example-top_level-diag-1: .. dropdown:: diag (np_test_1_all.cpp:15651) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15641 :emphasize-lines: 11 auto svd_1x1 = svd_decomposition(matrix1x1, false); // std::cout << "1x1 matrix singular value: " << svd_1x1.S.getElementAt({ 0 }) << std::endl; if (!(std::abs(svd_1x1.S.getElementAt({ 0 }) - 5.0) < 1e-10)) { std::string description = std::string("test_svd_edge_cases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(svd_1x1.S.getElementAt({ 0 }) - 5.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test diagonal matrix NDArray diag({ 3, 3 }); diag.setElementAt({ 0, 0 }, 3.0); diag.setElementAt({ 1, 1 }, 2.0); diag.setElementAt({ 2, 2 }, 1.0); // All off-diagonal elements are already 0 auto svd_diag = svd_decomposition(diag, false); // std::cout << "Diagonal matrix singular values:" << std::endl; //svd_diag.S.printArray(); // Singular values should be sorted in descending order .. _example-top_level-diag_indices-2: .. dropdown:: diag_indices (np_test_2_all.cpp:18255) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18245 :emphasize-lines: 11 return 0; } } // namespace numpy_tests // Comprehensive test suite for Diagonal Indexing Utilities // // This file tests the diagonal and masked indexing functionality // including diag_indices() and mask_indices() functions #include #include #include "../numpy/np_ndarray.h" #include "../numpy/np_factory.h" #include "../numpy/np_indexing_diagonal.h" // no using namespace in tests - to avoid name clashes namespace numpy_tests { .. _example-top_level-diag_indices_from-3: .. dropdown:: diag_indices_from (np_test_1_all.cpp:28494) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 28484 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void np_test_indexing_diag_indices_from() { std::cout << "========= diag_indices_from: diagonal indices from array ======================="; // Create a square array auto arr = numpy::NDArray::createZeros({ 4, 4 }); // Get diagonal indices (returns vector, not tuple) auto diag_idx = numpy::diag_indices_from(arr); // Should return vector of 2 arrays, each with 4 elements bool passed = (diag_idx.size() == 2); passed = passed && (diag_idx[0].getSize() == 4); passed = passed && (diag_idx[1].getSize() == 4); if (passed) { // Verify indices are [0,0], [1,1], [2,2], [3,3] for (size_t i = 0; i < 4 && passed; ++i) { if (diag_idx[0].data()[i] != i || .. _example-top_level-diag_sparse-4: .. dropdown:: diag_sparse (np_test_3_all.cpp:20292) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20282 :emphasize-lines: 11 void np_test_sparse_api_utilities() { std::cout << "========= high-level API - utilities ======================="; auto I = numpy::sparse::eye_sparse(5); if (I.nnz() != 5) { std::cout << " [FAIL] : in np_test_sparse_api_utilities() : eye_sparse failed"; throw std::runtime_error("np_test_sparse_api_utilities failed"); } std::vector diag_vals = { 1.0, 2.0, 3.0, 4.0 }; auto D = numpy::sparse::diag_sparse(diag_vals); if (D.nnz() != 4 || D(2, 2) != 3.0) { std::cout << " [FAIL] : in np_test_sparse_api_utilities() : diag_sparse failed"; throw std::runtime_error("np_test_sparse_api_utilities failed"); } std::cout << " -> tests passed" << std::endl; } void np_test_sparse_api_norms() { std::cout << "========= high-level API - matrix norms ======================="; .. _example-top_level-empty-5: .. dropdown:: empty (np_test_1_all.cpp:6316) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6306 :emphasize-lines: 11 } void test_data_generator_emptyBenchmarkSorting() { std::cout << "========= test_data_generator_empty ======================="; DataGenerator gen(42); // Test empty data generation std::vector data = gen.generate(0, DataPattern::RANDOM); if (!(data.empty())) { std::string description = std::string("test_data_generator_emptyBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Empty data generation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-eye-6: .. dropdown:: eye (np_test_1_all.cpp:23980) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23970 :emphasize-lines: 11 // Test geomspace auto geomspace_result = geomspace(1.0, 16.0, 5); if (!(geomspace_result.getShape()[0] == 5)) { std::string description = std::string("testArrayCreationSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(geomspace_result.getShape()[0] == 5)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] geomspace function has correct signature\n"; // Test eye with optional parameters auto eye_square = eye(3); auto eye_rect = eye(3, 4); auto eye_offset = eye(3, 4, 1); if (!((eye_square.getShape() == std::vector{3, 3}))) { std::string description = std::string("testArrayCreationSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((eye_square.getShape() == std::vector{3, 3}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!((eye_rect.getShape() == std::vector{3, 4}))) { std::string description = std::string("testArrayCreationSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((eye_rect.getShape() == std::vector{3, 4}))"; .. _example-top_level-eye-7: .. dropdown:: eye (np_test_1_all.cpp:23980) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23970 :emphasize-lines: 11 // Test geomspace auto geomspace_result = geomspace(1.0, 16.0, 5); if (!(geomspace_result.getShape()[0] == 5)) { std::string description = std::string("testArrayCreationSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(geomspace_result.getShape()[0] == 5)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] geomspace function has correct signature\n"; // Test eye with optional parameters auto eye_square = eye(3); auto eye_rect = eye(3, 4); auto eye_offset = eye(3, 4, 1); if (!((eye_square.getShape() == std::vector{3, 3}))) { std::string description = std::string("testArrayCreationSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((eye_square.getShape() == std::vector{3, 3}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!((eye_rect.getShape() == std::vector{3, 4}))) { std::string description = std::string("testArrayCreationSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((eye_rect.getShape() == std::vector{3, 4}))"; .. _example-top_level-eye_sparse-8: .. dropdown:: eye_sparse (np_test_3_all.cpp:20285) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20275 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } // ============================================================================ // HIGH-LEVEL API TESTS // ============================================================================ void np_test_sparse_api_utilities() { std::cout << "========= high-level API - utilities ======================="; auto I = numpy::sparse::eye_sparse(5); if (I.nnz() != 5) { std::cout << " [FAIL] : in np_test_sparse_api_utilities() : eye_sparse failed"; throw std::runtime_error("np_test_sparse_api_utilities failed"); } std::vector diag_vals = { 1.0, 2.0, 3.0, 4.0 }; auto D = numpy::sparse::diag_sparse(diag_vals); if (D.nnz() != 4 || D(2, 2) != 3.0) { std::cout << " [FAIL] : in np_test_sparse_api_utilities() : diag_sparse failed"; throw std::runtime_error("np_test_sparse_api_utilities failed"); .. _example-top_level-full-9: .. dropdown:: full (np_test_1_all.cpp:6803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6793 :emphasize-lines: 11 // Test zeros auto zeros_arr = zeros<16>({3}); // std::cout << "zeros({3}) result:"; for (size_t i = 0; i < zeros_arr.size(); ++i) { // std::cout << "'" << zeros_arr[i] << "' "; } // std::cout << std::endl; // Test full auto full_arr = full<16>({2, 2}, "FILL"); // std::cout << "full({2, 2}, 'FILL') result:"; // full_arr.print(); // Test empty auto empty_arr = empty<16>({2}); // std::cout << "empty({2}) result (should be uninitialized):"; // empty_arr.print(); std::cout << " -> tests passed" << std::endl; } .. _example-top_level-full-10: .. dropdown:: full (np_test_1_all.cpp:6803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6793 :emphasize-lines: 11 // Test zeros auto zeros_arr = zeros<16>({3}); // std::cout << "zeros({3}) result:"; for (size_t i = 0; i < zeros_arr.size(); ++i) { // std::cout << "'" << zeros_arr[i] << "' "; } // std::cout << std::endl; // Test full auto full_arr = full<16>({2, 2}, "FILL"); // std::cout << "full({2, 2}, 'FILL') result:"; // full_arr.print(); // Test empty auto empty_arr = empty<16>({2}); // std::cout << "empty({2}) result (should be uninitialized):"; // empty_arr.print(); std::cout << " -> tests passed" << std::endl; } .. _example-top_level-full-11: .. dropdown:: full (np_test_1_all.cpp:6803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6793 :emphasize-lines: 11 // Test zeros auto zeros_arr = zeros<16>({3}); // std::cout << "zeros({3}) result:"; for (size_t i = 0; i < zeros_arr.size(); ++i) { // std::cout << "'" << zeros_arr[i] << "' "; } // std::cout << std::endl; // Test full auto full_arr = full<16>({2, 2}, "FILL"); // std::cout << "full({2, 2}, 'FILL') result:"; // full_arr.print(); // Test empty auto empty_arr = empty<16>({2}); // std::cout << "empty({2}) result (should be uninitialized):"; // empty_arr.print(); std::cout << " -> tests passed" << std::endl; } .. _example-top_level-full_like-12: .. dropdown:: full_like (np_test_1_all.cpp:24045) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 24035 :emphasize-lines: 11 } // std::cout << "[OK] diag function with multiple use cases works correctly\n"; // Test array-like functions auto template_array = createFloat64Array({ 2, 3 }, 1.0); auto empty_result = empty({ 3, 4 }); auto full_result = full({ 2, 2 }, 42); auto zeros_like_result = zeros_like(template_array); auto ones_like_result = ones_like(template_array); auto full_like_result = full_like(template_array, 3.14); if (!((empty_result.getShape() == std::vector{3, 4}))) { std::string description = std::string("testArrayCreationSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((empty_result.getShape() == std::vector{3, 4}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!((full_result.getShape() == std::vector{2, 2}))) { std::string description = std::string("testArrayCreationSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((full_result.getShape() == std::vector{2, 2}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-meshgrid-13: .. dropdown:: meshgrid (np_test_1_all.cpp:3898) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3888 :emphasize-lines: 11 // Test basic 2D meshgrid with 'xy' indexing auto x = createFloat64Array({ 3 }); x.setElementAt({ 0 }, 1.0); x.setElementAt({ 1 }, 2.0); x.setElementAt({ 2 }, 3.0); auto y = createFloat64Array({ 2 }); y.setElementAt({ 0 }, 10.0); y.setElementAt({ 1 }, 20.0); auto grids = meshgrid({ x, y }, "xy"); if (!(grids.size() == 2)) { std::string description = std::string("testMeshgrid():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(grids.size() == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Check X grid shape and values if (!(grids[0].getShape() == std::vector({ 2, 3 }))) { std::string description = std::string("testMeshgrid():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(grids[0].getShape() == std::vector({ 2, 3 }))"; .. _example-top_level-ones-14: .. dropdown:: ones (np_test_1_all.cpp:319) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 309 :emphasize-lines: 11 //int_range.printArray(); auto reshaped = int_range.reshapeArray({ 3, 2 }); // std::cout << "Reshaped to 2x2 matrix:"; //reshaped.printArray(); auto zeros = createInt32Zeros({ 2, 3 }); // std::cout << "zeros (2,3):"; //zeros.printArray(); auto ones = createInt32Ones({ 2, 3 }); // std::cout << "ones (2,3):"; //ones.printArray(); // std::cout << "Addition of zeros and ones:" << std::endl; auto sum = zeros.addArrays(ones); //sum.printArray(); // std::cout << "Sum of all elements: " << sum.sumArray() << std::endl; // std::cout << "Mean: " << sum.meanArray() << std::endl; // std::cout << std::endl << "Type introspection with get_typename():" << std::endl; .. _example-top_level-ones-15: .. dropdown:: ones (np_test_1_all.cpp:319) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 309 :emphasize-lines: 11 //int_range.printArray(); auto reshaped = int_range.reshapeArray({ 3, 2 }); // std::cout << "Reshaped to 2x2 matrix:"; //reshaped.printArray(); auto zeros = createInt32Zeros({ 2, 3 }); // std::cout << "zeros (2,3):"; //zeros.printArray(); auto ones = createInt32Ones({ 2, 3 }); // std::cout << "ones (2,3):"; //ones.printArray(); // std::cout << "Addition of zeros and ones:" << std::endl; auto sum = zeros.addArrays(ones); //sum.printArray(); // std::cout << "Sum of all elements: " << sum.sumArray() << std::endl; // std::cout << "Mean: " << sum.meanArray() << std::endl; // std::cout << std::endl << "Type introspection with get_typename():" << std::endl; .. _example-top_level-ones_like-16: .. dropdown:: ones_like (np_test_1_all.cpp:24044) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 24034 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "[OK] diag function with multiple use cases works correctly\n"; // Test array-like functions auto template_array = createFloat64Array({ 2, 3 }, 1.0); auto empty_result = empty({ 3, 4 }); auto full_result = full({ 2, 2 }, 42); auto zeros_like_result = zeros_like(template_array); auto ones_like_result = ones_like(template_array); auto full_like_result = full_like(template_array, 3.14); if (!((empty_result.getShape() == std::vector{3, 4}))) { std::string description = std::string("testArrayCreationSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((empty_result.getShape() == std::vector{3, 4}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!((full_result.getShape() == std::vector{2, 2}))) { std::string description = std::string("testArrayCreationSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((full_result.getShape() == std::vector{2, 2}))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-tril_indices-17: .. dropdown:: tril_indices (np_test_2_all.cpp:15273) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15263 :emphasize-lines: 11 // use a separate namespace for each test group namespace numpy_tests_indexing_triangular { // ============================================================================ // BASIC tril_indices TESTS // ============================================================================ void np_test_indexing_triangular_tril_indices_basic() { std::cout << "========= tril_indices: basic 3x3 matrix ======================="; // Test tril_indices(3, 0) - main diagonal auto [rows, cols] = numpy::tril_indices(3, 0); // Verify count: 3x3 lower triangle has 6 elements (0,0), (1,0), (1,1), (2,0), (2,1), (2,2) if (rows.getShape()[0] != 6) { std::cout << " [FAIL] : in np_test_indexing_triangular_tril_indices_basic() : Expected 6 indices, got " << rows.getShape()[0] << std::endl; throw std::runtime_error("np_test_indexing_triangular_tril_indices_basic failed: incorrect count"); } // Verify expected indices .. _example-top_level-tril_indices_from-18: .. dropdown:: tril_indices_from (np_test_2_all.cpp:15431) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15421 :emphasize-lines: 11 // Create a 3x3 array numpy::NDArray arr({ 3, 3 }); int val = 1; for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 3; ++j) { arr.setElementAt({ i, j }, val++); } } // Get lower triangle indices auto [rows, cols] = numpy::tril_indices_from(arr, 0); // Verify count if (rows.getShape()[0] != 6) { std::cout << " [FAIL] : in np_test_indexing_triangular_tril_indices_from_basic() : Expected 6 indices, got " << rows.getShape()[0] << std::endl; throw std::runtime_error("np_test_indexing_triangular_tril_indices_from_basic failed: incorrect count"); } // Verify extracted values: should be 1, 4, 5, 7, 8, 9 std::vector expected_values = { 1, 4, 5, 7, 8, 9 }; .. _example-top_level-trim-19: .. dropdown:: trim (np_test_5_all.cpp:842) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 832 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } #endif // ============================================================================ // I/O UTILITIES TESTS // ============================================================================ void np_test_io_trim() { std::cout << "========= trim() utility ======================================="; // trim() might be in namespace or as a helper function // Test basic string trimming std::string test1 = " hello "; std::string test2 = "\t\nworld\t\n"; std::string test3 = "no_trim"; // Since trim may not be directly accessible, we'll test the concept auto trim = [](const std::string& str) { size_t start = str.find_first_not_of(" \t\n\r"); .. _example-top_level-triu_indices-20: .. dropdown:: triu_indices (np_test_2_all.cpp:15362) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15352 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } // ============================================================================ // BASIC triu_indices TESTS // ============================================================================ void np_test_indexing_triangular_triu_indices_basic() { std::cout << "========= triu_indices: basic 3x3 matrix ======================="; // Test triu_indices(3, 0) - main diagonal auto [rows, cols] = numpy::triu_indices(3, 0); // Verify count: 3x3 upper triangle has 6 elements (0,0), (0,1), (0,2), (1,1), (1,2), (2,2) if (rows.getShape()[0] != 6) { std::cout << " [FAIL] : in np_test_indexing_triangular_triu_indices_basic() : Expected 6 indices, got " << rows.getShape()[0] << std::endl; throw std::runtime_error("np_test_indexing_triangular_triu_indices_basic failed: incorrect count"); } // Verify expected indices .. _example-top_level-triu_indices_from-21: .. dropdown:: triu_indices_from (np_test_2_all.cpp:15500) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15490 :emphasize-lines: 11 // Create a 3x3 array numpy::NDArray arr({ 3, 3 }); int val = 1; for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 3; ++j) { arr.setElementAt({ i, j }, val++); } } // Get upper triangle indices auto [rows, cols] = numpy::triu_indices_from(arr, 0); // Verify count if (rows.getShape()[0] != 6) { std::cout << " [FAIL] : in np_test_indexing_triangular_triu_indices_from_basic() : Expected 6 indices, got " << rows.getShape()[0] << std::endl; throw std::runtime_error("np_test_indexing_triangular_triu_indices_from_basic failed: incorrect count"); } // Verify extracted values: should be 1, 2, 3, 5, 6, 9 std::vector expected_values = { 1, 2, 3, 5, 6, 9 }; .. _example-top_level-zeros-22: .. dropdown:: zeros (np_test_1_all.cpp:316) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 306 :emphasize-lines: 11 auto int_range = NDArray::createRange(1, 12, 2); // std::cout << "Int32 range array (1 to 10, step 2):" << std::endl; //int_range.printArray(); auto reshaped = int_range.reshapeArray({ 3, 2 }); // std::cout << "Reshaped to 2x2 matrix:"; //reshaped.printArray(); auto zeros = createInt32Zeros({ 2, 3 }); // std::cout << "zeros (2,3):"; //zeros.printArray(); auto ones = createInt32Ones({ 2, 3 }); // std::cout << "ones (2,3):"; //ones.printArray(); // std::cout << "Addition of zeros and ones:" << std::endl; auto sum = zeros.addArrays(ones); //sum.printArray(); // std::cout << "Sum of all elements: " << sum.sumArray() << std::endl; .. _example-top_level-zeros-23: .. dropdown:: zeros (np_test_1_all.cpp:316) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 306 :emphasize-lines: 11 auto int_range = NDArray::createRange(1, 12, 2); // std::cout << "Int32 range array (1 to 10, step 2):" << std::endl; //int_range.printArray(); auto reshaped = int_range.reshapeArray({ 3, 2 }); // std::cout << "Reshaped to 2x2 matrix:"; //reshaped.printArray(); auto zeros = createInt32Zeros({ 2, 3 }); // std::cout << "zeros (2,3):"; //zeros.printArray(); auto ones = createInt32Ones({ 2, 3 }); // std::cout << "ones (2,3):"; //ones.printArray(); // std::cout << "Addition of zeros and ones:" << std::endl; auto sum = zeros.addArrays(ones); //sum.printArray(); // std::cout << "Sum of all elements: " << sum.sumArray() << std::endl; .. _example-top_level-zeros-24: .. dropdown:: zeros (np_test_1_all.cpp:316) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 306 :emphasize-lines: 11 auto int_range = NDArray::createRange(1, 12, 2); // std::cout << "Int32 range array (1 to 10, step 2):" << std::endl; //int_range.printArray(); auto reshaped = int_range.reshapeArray({ 3, 2 }); // std::cout << "Reshaped to 2x2 matrix:"; //reshaped.printArray(); auto zeros = createInt32Zeros({ 2, 3 }); // std::cout << "zeros (2,3):"; //zeros.printArray(); auto ones = createInt32Ones({ 2, 3 }); // std::cout << "ones (2,3):"; //ones.printArray(); // std::cout << "Addition of zeros and ones:" << std::endl; auto sum = zeros.addArrays(ones); //sum.printArray(); // std::cout << "Sum of all elements: " << sum.sumArray() << std::endl; .. _example-top_level-zeros_like-25: .. dropdown:: zeros_like (np_test_1_all.cpp:24043) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 24033 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] diag function with multiple use cases works correctly\n"; // Test array-like functions auto template_array = createFloat64Array({ 2, 3 }, 1.0); auto empty_result = empty({ 3, 4 }); auto full_result = full({ 2, 2 }, 42); auto zeros_like_result = zeros_like(template_array); auto ones_like_result = ones_like(template_array); auto full_like_result = full_like(template_array, 3.14); if (!((empty_result.getShape() == std::vector{3, 4}))) { std::string description = std::string("testArrayCreationSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((empty_result.getShape() == std::vector{3, 4}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!((full_result.getShape() == std::vector{2, 2}))) { std::string description = std::string("testArrayCreationSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((full_result.getShape() == std::vector{2, 2}))"; .. _example-top_level-broadcast_arrays-26: .. dropdown:: broadcast_arrays (np_test_1_all.cpp:3749) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3739 :emphasize-lines: 11 for (size_t i = 0; i < 2; ++i) { arr2.setElementAt({i, 0}, static_cast((i + 1) * 10)); // [10; 20] } for (size_t j = 0; j < 3; ++j) { arr3.setElementAt({0, j}, static_cast((j + 1) * 100)); // [100, 200, 300] } // Broadcast all arrays together std::vector> arrays = {arr1, arr2, arr3}; auto broadcasted = broadcast_arrays(arrays); // All should have shape (2, 3) for (const auto& arr : broadcasted) { if (!((arr.getShape() == std::vector{2, 3}))) { std::string description = std::string("test_broadcast_arrays():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((arr.getShape() == std::vector{2, 3}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } .. _example-top_level-reshape-27: .. dropdown:: reshape (np_test_1_all.cpp:5391) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5381 :emphasize-lines: 11 std::cout << "========= testInvalidReshapeExtended ======================="; auto array = createInt32Array({2, 3}, 42); // Size = 6 // std::cout << "Original array (2x3, size=6):" << std::endl; //array.printArray(); // Valid reshape try { auto reshaped = array.reshapeArray({3, 2}); // Size = 6, OK // std::cout << "[OK] Valid reshape (3x2) works"; } catch (const std::exception& e) { std::cout << " [FAIL] : in testInvalidReshapeExtended(): Unexpected error in valid reshape: " << e.what(); throw std::runtime_error("testInvalidReshapeExtended(): Unexpected error in valid reshape: " + std::string(e.what())); } // Invalid reshape - wrong total size try { auto reshaped = array.reshapeArray({2, 2}); // Size = 4, should fail std::cout << "[FAIL] Invalid reshape should have thrown"; } catch (const std::invalid_argument& e) { .. _example-top_level-abs-28: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-top_level-abs-29: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-top_level-abs-30: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-top_level-abs-31: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-top_level-abs-32: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-top_level-abs-33: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-top_level-abs-34: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-top_level-abs-35: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-top_level-abs-36: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-top_level-abs-37: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-top_level-abs-38: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-top_level-abs-39: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-top_level-abs-40: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-top_level-abs-41: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-top_level-abs-42: .. dropdown:: abs (np_test_1_all.cpp:101) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 91 :emphasize-lines: 11 if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << static_cast(arr.getElementAt({i})) << " "; } } // std::cout << std::endl; } // Helper function for core array extensions tests bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) { return std::abs(a - b) < tolerance; } } void f_nothing() { // This function does nothing and tests nothing // It's a placeholder test function } // ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 -------------------------------- .. _example-top_level-absolute-43: .. dropdown:: absolute (np_test_3_all.cpp:4396) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4386 :emphasize-lines: 11 void testAbsoluteMagnitude() { std::cout << "========= testAbsoluteMagnitude ===="; // Test magnitude of complex numbers auto c_arr = NDArray({ 3 }); c_arr.setElementAt({ 0 }, complex128(3.0, 4.0)); // |3+4i| = 5 c_arr.setElementAt({ 1 }, complex128(-5.0, 12.0)); // |-5+12i| = 13 c_arr.setElementAt({ 2 }, complex128(0.0, -1.0)); // |0-i| = 1 auto magnitudes = absolute(c_arr); if (!(std::abs(magnitudes.getElementAt({ 0 }) - 5.0) < 1e-10)) { std::string description = std::string("testAbsoluteMagnitude():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(magnitudes.getElementAt({ 0 }) - 5.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(magnitudes.getElementAt({ 1 }) - 13.0) < 1e-10)) { std::string description = std::string("testAbsoluteMagnitude():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(magnitudes.getElementAt({ 1 }) - 13.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-add-44: .. dropdown:: add (np_test_1_all.cpp:6410) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6400 :emphasize-lines: 11 void testCharArrayStringOperationsCharArray() { std::cout << "========= testStringOperations ======================="; // Test string concatenation std::vector words1 = {"Hello", "Good", "Nice"}; std::vector words2 = {" World", " Day", " Work"}; auto arr1 = array<32>(words1); auto arr2 = array<32>(words2); auto result = add(arr1, arr2); // std::cout << "String concatenation (add):" << std::endl; for (size_t i = 0; i < result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'"; } // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; .. _example-top_level-add-45: .. dropdown:: add (np_test_1_all.cpp:6410) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6400 :emphasize-lines: 11 void testCharArrayStringOperationsCharArray() { std::cout << "========= testStringOperations ======================="; // Test string concatenation std::vector words1 = {"Hello", "Good", "Nice"}; std::vector words2 = {" World", " Day", " Work"}; auto arr1 = array<32>(words1); auto arr2 = array<32>(words2); auto result = add(arr1, arr2); // std::cout << "String concatenation (add):" << std::endl; for (size_t i = 0; i < result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'"; } // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; .. _example-top_level-add-46: .. dropdown:: add (np_test_1_all.cpp:6410) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6400 :emphasize-lines: 11 void testCharArrayStringOperationsCharArray() { std::cout << "========= testStringOperations ======================="; // Test string concatenation std::vector words1 = {"Hello", "Good", "Nice"}; std::vector words2 = {" World", " Day", " Work"}; auto arr1 = array<32>(words1); auto arr2 = array<32>(words2); auto result = add(arr1, arr2); // std::cout << "String concatenation (add):" << std::endl; for (size_t i = 0; i < result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'"; } // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; .. _example-top_level-add-47: .. dropdown:: add (np_test_1_all.cpp:6410) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6400 :emphasize-lines: 11 void testCharArrayStringOperationsCharArray() { std::cout << "========= testStringOperations ======================="; // Test string concatenation std::vector words1 = {"Hello", "Good", "Nice"}; std::vector words2 = {" World", " Day", " Work"}; auto arr1 = array<32>(words1); auto arr2 = array<32>(words2); auto result = add(arr1, arr2); // std::cout << "String concatenation (add):" << std::endl; for (size_t i = 0; i < result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'"; } // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; .. _example-top_level-add-48: .. dropdown:: add (np_test_1_all.cpp:6410) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6400 :emphasize-lines: 11 void testCharArrayStringOperationsCharArray() { std::cout << "========= testStringOperations ======================="; // Test string concatenation std::vector words1 = {"Hello", "Good", "Nice"}; std::vector words2 = {" World", " Day", " Work"}; auto arr1 = array<32>(words1); auto arr2 = array<32>(words2); auto result = add(arr1, arr2); // std::cout << "String concatenation (add):" << std::endl; for (size_t i = 0; i < result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'"; } // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; .. _example-top_level-add-49: .. dropdown:: add (np_test_1_all.cpp:6410) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6400 :emphasize-lines: 11 void testCharArrayStringOperationsCharArray() { std::cout << "========= testStringOperations ======================="; // Test string concatenation std::vector words1 = {"Hello", "Good", "Nice"}; std::vector words2 = {" World", " Day", " Work"}; auto arr1 = array<32>(words1); auto arr2 = array<32>(words2); auto result = add(arr1, arr2); // std::cout << "String concatenation (add):" << std::endl; for (size_t i = 0; i < result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'"; } // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; .. _example-top_level-add-50: .. dropdown:: add (np_test_1_all.cpp:6410) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6400 :emphasize-lines: 11 void testCharArrayStringOperationsCharArray() { std::cout << "========= testStringOperations ======================="; // Test string concatenation std::vector words1 = {"Hello", "Good", "Nice"}; std::vector words2 = {" World", " Day", " Work"}; auto arr1 = array<32>(words1); auto arr2 = array<32>(words2); auto result = add(arr1, arr2); // std::cout << "String concatenation (add):" << std::endl; for (size_t i = 0; i < result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'"; } // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; .. _example-top_level-add-51: .. dropdown:: add (np_test_1_all.cpp:6410) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6400 :emphasize-lines: 11 void testCharArrayStringOperationsCharArray() { std::cout << "========= testStringOperations ======================="; // Test string concatenation std::vector words1 = {"Hello", "Good", "Nice"}; std::vector words2 = {" World", " Day", " Work"}; auto arr1 = array<32>(words1); auto arr2 = array<32>(words2); auto result = add(arr1, arr2); // std::cout << "String concatenation (add):" << std::endl; for (size_t i = 0; i < result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'"; } // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; .. _example-top_level-add-52: .. dropdown:: add (np_test_1_all.cpp:6410) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6400 :emphasize-lines: 11 void testCharArrayStringOperationsCharArray() { std::cout << "========= testStringOperations ======================="; // Test string concatenation std::vector words1 = {"Hello", "Good", "Nice"}; std::vector words2 = {" World", " Day", " Work"}; auto arr1 = array<32>(words1); auto arr2 = array<32>(words2); auto result = add(arr1, arr2); // std::cout << "String concatenation (add):" << std::endl; for (size_t i = 0; i < result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'"; } // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; .. _example-top_level-add-53: .. dropdown:: add (np_test_1_all.cpp:6410) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6400 :emphasize-lines: 11 void testCharArrayStringOperationsCharArray() { std::cout << "========= testStringOperations ======================="; // Test string concatenation std::vector words1 = {"Hello", "Good", "Nice"}; std::vector words2 = {" World", " Day", " Work"}; auto arr1 = array<32>(words1); auto arr2 = array<32>(words2); auto result = add(arr1, arr2); // std::cout << "String concatenation (add):" << std::endl; for (size_t i = 0; i < result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'"; } // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; .. _example-top_level-add-54: .. dropdown:: add (np_test_1_all.cpp:6410) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6400 :emphasize-lines: 11 void testCharArrayStringOperationsCharArray() { std::cout << "========= testStringOperations ======================="; // Test string concatenation std::vector words1 = {"Hello", "Good", "Nice"}; std::vector words2 = {" World", " Day", " Work"}; auto arr1 = array<32>(words1); auto arr2 = array<32>(words2); auto result = add(arr1, arr2); // std::cout << "String concatenation (add):" << std::endl; for (size_t i = 0; i < result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'"; } // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; .. _example-top_level-add_arrays_to_writer-55: .. dropdown:: add_arrays_to_writer (np_test_5_all.cpp:719) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 709 :emphasize-lines: 11 std::ifstream check_file(filename, std::ios::binary); assert_condition(check_file.good(), "NPZ file was not created after finalize()"); check_file.close(); // std::cout << " Verified NPZ file exists on disk" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_io_npz_add_arrays_to_writer() { std::cout << "========= add_arrays_to_writer() helper ========================"; ensure_test_dir(); std::string filename = test_dir + "test_helper.npz"; { numpy::npz::NPZWriter writer(filename, false); numpy::NDArray arr1 = numpy::arange(0, 4); numpy::NDArray arr2({ 2, 2 }); // Set to ones .. _example-top_level-add_arrays_to_writer-56: .. dropdown:: add_arrays_to_writer (np_test_5_all.cpp:719) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 709 :emphasize-lines: 11 std::ifstream check_file(filename, std::ios::binary); assert_condition(check_file.good(), "NPZ file was not created after finalize()"); check_file.close(); // std::cout << " Verified NPZ file exists on disk" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_io_npz_add_arrays_to_writer() { std::cout << "========= add_arrays_to_writer() helper ========================"; ensure_test_dir(); std::string filename = test_dir + "test_helper.npz"; { numpy::npz::NPZWriter writer(filename, false); numpy::NDArray arr1 = numpy::arange(0, 4); numpy::NDArray arr2({ 2, 2 }); // Set to ones .. _example-top_level-add_docstring-57: .. dropdown:: add_docstring (np_test_5_all.cpp:6323) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6313 :emphasize-lines: 11 } if (perm_set != original_set) { std::cout << " [FAIL] : in np_test_permutation_array_input() : Wrong elements"; throw std::runtime_error("Test failed"); } std::cout << " -> tests passed" << std::endl; } // Test add_docstring() void np_test_add_docstring_basic() { std::cout << "========= add_docstring() basic functionality ======================="; int dummy_object = 42; std::string docstring = "This is a test docstring for the object."; // Function should execute without throwing numpy::introspection::add_docstring(dummy_object, docstring); std::cout << " -> tests passed" << std::endl; .. _example-top_level-add_newdoc-58: .. dropdown:: add_newdoc (np_test_2_all.cpp:19744) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19734 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } // ============================================================================ // DOCSTRING TESTS // ============================================================================ void np_test_introspection_docstring() { std::cout << "========= docstring: add and retrieve documentation ======================="; // Test add_newdoc (simple string-based registry) numpy::introspection::add_newdoc("numpy", "zeros", "Create array filled with zeros"); std::string newdoc = numpy::introspection::get_newdoc("numpy", "zeros"); bool passed = (newdoc == "Create array filled with zeros"); // Test add_newdoc_ufunc numpy::introspection::add_newdoc_ufunc("add", "Element-wise addition"); std::string ufunc_doc = numpy::introspection::get_newdoc("ufunc", "add"); passed = passed && (ufunc_doc == "Element-wise addition"); if (!passed) { .. _example-top_level-add_newdoc_ufunc-59: .. dropdown:: add_newdoc_ufunc (np_test_2_all.cpp:19750) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19740 :emphasize-lines: 11 void np_test_introspection_docstring() { std::cout << "========= docstring: add and retrieve documentation ======================="; // Test add_newdoc (simple string-based registry) numpy::introspection::add_newdoc("numpy", "zeros", "Create array filled with zeros"); std::string newdoc = numpy::introspection::get_newdoc("numpy", "zeros"); bool passed = (newdoc == "Create array filled with zeros"); // Test add_newdoc_ufunc numpy::introspection::add_newdoc_ufunc("add", "Element-wise addition"); std::string ufunc_doc = numpy::introspection::get_newdoc("ufunc", "add"); passed = passed && (ufunc_doc == "Element-wise addition"); if (!passed) { std::cout << " [FAIL] : in np_test_introspection_docstring() : docstring test failed"; throw std::runtime_error("np_test_introspection_docstring failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-add_scaled_row-60: .. dropdown:: add_scaled_row (np_test_5_all.cpp:2972) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2962 :emphasize-lines: 11 // std::cout << " scale_row: row 0 scaled by 2.0 correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_linalg_add_scaled_row() { std::cout << "========= add_scaled_row helper ======================="; // Create matrix: [[1, 2, 3], [4, 5, 6]] std::vector matrix = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; // Add 2 * row 0 to row 1 numpy::linalg::utils::add_scaled_row(matrix.data(), 3, 1, 0, 2.0); // After operation: [[1, 2, 3], [6, 9, 12]] (4+2*1=6, 5+2*2=9, 6+2*3=12) bool passed = is_close(matrix[3], 6.0) && is_close(matrix[4], 9.0) && is_close(matrix[5], 12.0); if (!passed) { std::cout << " [FAIL] : in np_test_linalg_add_scaled_row() : scaled row addition incorrect"; throw std::runtime_error("np_test_linalg_add_scaled_row failed: incorrect addition"); } // std::cout << " add_scaled_row: row 1 += 2*row 0 computed correctly" << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-top_level-arccos-61: .. dropdown:: arccos (np_test_1_all.cpp:23734) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23724 :emphasize-lines: 11 if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-arccos-62: .. dropdown:: arccos (np_test_1_all.cpp:23734) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23724 :emphasize-lines: 11 if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-arccos-63: .. dropdown:: arccos (np_test_1_all.cpp:23734) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23724 :emphasize-lines: 11 if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-arccos-64: .. dropdown:: arccos (np_test_1_all.cpp:23734) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23724 :emphasize-lines: 11 if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-arccos-65: .. dropdown:: arccos (np_test_1_all.cpp:23734) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23724 :emphasize-lines: 11 if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-arccos-66: .. dropdown:: arccos (np_test_1_all.cpp:23734) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23724 :emphasize-lines: 11 if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-arccos-67: .. dropdown:: arccos (np_test_1_all.cpp:23734) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23724 :emphasize-lines: 11 if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-arccos-68: .. dropdown:: arccos (np_test_1_all.cpp:23734) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23724 :emphasize-lines: 11 if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-arccos-69: .. dropdown:: arccos (np_test_1_all.cpp:23734) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23724 :emphasize-lines: 11 if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-arccos-70: .. dropdown:: arccos (np_test_1_all.cpp:23734) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23724 :emphasize-lines: 11 if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-arccos-71: .. dropdown:: arccos (np_test_1_all.cpp:23734) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23724 :emphasize-lines: 11 if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-arccos-72: .. dropdown:: arccos (np_test_1_all.cpp:23734) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23724 :emphasize-lines: 11 if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-arccos-73: .. dropdown:: arccos (np_test_1_all.cpp:23734) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23724 :emphasize-lines: 11 if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-arccosh-74: .. dropdown:: arccosh (np_test_2_all.cpp:1080) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1070 :emphasize-lines: 11 } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; // Test arccosh with values >= 1 NDArray acosh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { acosh_test_data.setElementAt({ i }, 1.0 + 9.0 * static_cast(i) / test_size); } auto std_arccosh = arccosh(acosh_test_data, MathBackend::DEFAULT); auto mkl_arccosh = arccosh(acosh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; .. _example-top_level-arccosh-75: .. dropdown:: arccosh (np_test_2_all.cpp:1080) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1070 :emphasize-lines: 11 } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; // Test arccosh with values >= 1 NDArray acosh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { acosh_test_data.setElementAt({ i }, 1.0 + 9.0 * static_cast(i) / test_size); } auto std_arccosh = arccosh(acosh_test_data, MathBackend::DEFAULT); auto mkl_arccosh = arccosh(acosh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; .. _example-top_level-arccosh-76: .. dropdown:: arccosh (np_test_2_all.cpp:1080) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1070 :emphasize-lines: 11 } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; // Test arccosh with values >= 1 NDArray acosh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { acosh_test_data.setElementAt({ i }, 1.0 + 9.0 * static_cast(i) / test_size); } auto std_arccosh = arccosh(acosh_test_data, MathBackend::DEFAULT); auto mkl_arccosh = arccosh(acosh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; .. _example-top_level-arccosh-77: .. dropdown:: arccosh (np_test_2_all.cpp:1080) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1070 :emphasize-lines: 11 } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; // Test arccosh with values >= 1 NDArray acosh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { acosh_test_data.setElementAt({ i }, 1.0 + 9.0 * static_cast(i) / test_size); } auto std_arccosh = arccosh(acosh_test_data, MathBackend::DEFAULT); auto mkl_arccosh = arccosh(acosh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; .. _example-top_level-arccosh-78: .. dropdown:: arccosh (np_test_2_all.cpp:1080) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1070 :emphasize-lines: 11 } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; // Test arccosh with values >= 1 NDArray acosh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { acosh_test_data.setElementAt({ i }, 1.0 + 9.0 * static_cast(i) / test_size); } auto std_arccosh = arccosh(acosh_test_data, MathBackend::DEFAULT); auto mkl_arccosh = arccosh(acosh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; .. _example-top_level-arccosh-79: .. dropdown:: arccosh (np_test_2_all.cpp:1080) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1070 :emphasize-lines: 11 } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; // Test arccosh with values >= 1 NDArray acosh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { acosh_test_data.setElementAt({ i }, 1.0 + 9.0 * static_cast(i) / test_size); } auto std_arccosh = arccosh(acosh_test_data, MathBackend::DEFAULT); auto mkl_arccosh = arccosh(acosh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; .. _example-top_level-arccosh-80: .. dropdown:: arccosh (np_test_2_all.cpp:1080) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1070 :emphasize-lines: 11 } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; // Test arccosh with values >= 1 NDArray acosh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { acosh_test_data.setElementAt({ i }, 1.0 + 9.0 * static_cast(i) / test_size); } auto std_arccosh = arccosh(acosh_test_data, MathBackend::DEFAULT); auto mkl_arccosh = arccosh(acosh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; .. _example-top_level-arccosh-81: .. dropdown:: arccosh (np_test_2_all.cpp:1080) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1070 :emphasize-lines: 11 } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; // Test arccosh with values >= 1 NDArray acosh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { acosh_test_data.setElementAt({ i }, 1.0 + 9.0 * static_cast(i) / test_size); } auto std_arccosh = arccosh(acosh_test_data, MathBackend::DEFAULT); auto mkl_arccosh = arccosh(acosh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; .. _example-top_level-arccosh-82: .. dropdown:: arccosh (np_test_2_all.cpp:1080) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1070 :emphasize-lines: 11 } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; // Test arccosh with values >= 1 NDArray acosh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { acosh_test_data.setElementAt({ i }, 1.0 + 9.0 * static_cast(i) / test_size); } auto std_arccosh = arccosh(acosh_test_data, MathBackend::DEFAULT); auto mkl_arccosh = arccosh(acosh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; .. _example-top_level-arccosh-83: .. dropdown:: arccosh (np_test_2_all.cpp:1080) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1070 :emphasize-lines: 11 } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; // Test arccosh with values >= 1 NDArray acosh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { acosh_test_data.setElementAt({ i }, 1.0 + 9.0 * static_cast(i) / test_size); } auto std_arccosh = arccosh(acosh_test_data, MathBackend::DEFAULT); auto mkl_arccosh = arccosh(acosh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; .. _example-top_level-arccosh-84: .. dropdown:: arccosh (np_test_2_all.cpp:1080) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1070 :emphasize-lines: 11 } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; // Test arccosh with values >= 1 NDArray acosh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { acosh_test_data.setElementAt({ i }, 1.0 + 9.0 * static_cast(i) / test_size); } auto std_arccosh = arccosh(acosh_test_data, MathBackend::DEFAULT); auto mkl_arccosh = arccosh(acosh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; .. _example-top_level-arccosh-85: .. dropdown:: arccosh (np_test_2_all.cpp:1080) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1070 :emphasize-lines: 11 } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; // Test arccosh with values >= 1 NDArray acosh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { acosh_test_data.setElementAt({ i }, 1.0 + 9.0 * static_cast(i) / test_size); } auto std_arccosh = arccosh(acosh_test_data, MathBackend::DEFAULT); auto mkl_arccosh = arccosh(acosh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; .. _example-top_level-arccosh-86: .. dropdown:: arccosh (np_test_2_all.cpp:1080) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1070 :emphasize-lines: 11 } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; // Test arccosh with values >= 1 NDArray acosh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { acosh_test_data.setElementAt({ i }, 1.0 + 9.0 * static_cast(i) / test_size); } auto std_arccosh = arccosh(acosh_test_data, MathBackend::DEFAULT); auto mkl_arccosh = arccosh(acosh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arccosh.getElementAt({ i }), std_arccosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; .. _example-top_level-arcsin-87: .. dropdown:: arcsin (np_test_1_all.cpp:23733) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23723 :emphasize-lines: 11 auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-arcsin-88: .. dropdown:: arcsin (np_test_1_all.cpp:23733) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23723 :emphasize-lines: 11 auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-arcsin-89: .. dropdown:: arcsin (np_test_1_all.cpp:23733) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23723 :emphasize-lines: 11 auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-arcsin-90: .. dropdown:: arcsin (np_test_1_all.cpp:23733) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23723 :emphasize-lines: 11 auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-arcsin-91: .. dropdown:: arcsin (np_test_1_all.cpp:23733) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23723 :emphasize-lines: 11 auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-arcsin-92: .. dropdown:: arcsin (np_test_1_all.cpp:23733) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23723 :emphasize-lines: 11 auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-arcsin-93: .. dropdown:: arcsin (np_test_1_all.cpp:23733) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23723 :emphasize-lines: 11 auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-arcsin-94: .. dropdown:: arcsin (np_test_1_all.cpp:23733) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23723 :emphasize-lines: 11 auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-arcsin-95: .. dropdown:: arcsin (np_test_1_all.cpp:23733) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23723 :emphasize-lines: 11 auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-arcsin-96: .. dropdown:: arcsin (np_test_1_all.cpp:23733) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23723 :emphasize-lines: 11 auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-arcsin-97: .. dropdown:: arcsin (np_test_1_all.cpp:23733) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23723 :emphasize-lines: 11 auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-arcsin-98: .. dropdown:: arcsin (np_test_1_all.cpp:23733) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23723 :emphasize-lines: 11 auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-arcsin-99: .. dropdown:: arcsin (np_test_1_all.cpp:23733) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23723 :emphasize-lines: 11 auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-arcsinh-100: .. dropdown:: arcsinh (np_test_2_all.cpp:1062) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1052 :emphasize-lines: 11 std::cout << "========= testInverseHyperbolicMKL ===="; size_t test_size = 1000; // Test arcsinh with larger range NDArray asinh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { asinh_test_data.setElementAt({ i }, -10.0 + 20.0 * static_cast(i) / test_size); } auto std_arcsinh = arcsinh(asinh_test_data, MathBackend::DEFAULT); auto mkl_arcsinh = arcsinh(asinh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; .. _example-top_level-arcsinh-101: .. dropdown:: arcsinh (np_test_2_all.cpp:1062) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1052 :emphasize-lines: 11 std::cout << "========= testInverseHyperbolicMKL ===="; size_t test_size = 1000; // Test arcsinh with larger range NDArray asinh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { asinh_test_data.setElementAt({ i }, -10.0 + 20.0 * static_cast(i) / test_size); } auto std_arcsinh = arcsinh(asinh_test_data, MathBackend::DEFAULT); auto mkl_arcsinh = arcsinh(asinh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; .. _example-top_level-arcsinh-102: .. dropdown:: arcsinh (np_test_2_all.cpp:1062) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1052 :emphasize-lines: 11 std::cout << "========= testInverseHyperbolicMKL ===="; size_t test_size = 1000; // Test arcsinh with larger range NDArray asinh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { asinh_test_data.setElementAt({ i }, -10.0 + 20.0 * static_cast(i) / test_size); } auto std_arcsinh = arcsinh(asinh_test_data, MathBackend::DEFAULT); auto mkl_arcsinh = arcsinh(asinh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; .. _example-top_level-arcsinh-103: .. dropdown:: arcsinh (np_test_2_all.cpp:1062) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1052 :emphasize-lines: 11 std::cout << "========= testInverseHyperbolicMKL ===="; size_t test_size = 1000; // Test arcsinh with larger range NDArray asinh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { asinh_test_data.setElementAt({ i }, -10.0 + 20.0 * static_cast(i) / test_size); } auto std_arcsinh = arcsinh(asinh_test_data, MathBackend::DEFAULT); auto mkl_arcsinh = arcsinh(asinh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; .. _example-top_level-arcsinh-104: .. dropdown:: arcsinh (np_test_2_all.cpp:1062) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1052 :emphasize-lines: 11 std::cout << "========= testInverseHyperbolicMKL ===="; size_t test_size = 1000; // Test arcsinh with larger range NDArray asinh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { asinh_test_data.setElementAt({ i }, -10.0 + 20.0 * static_cast(i) / test_size); } auto std_arcsinh = arcsinh(asinh_test_data, MathBackend::DEFAULT); auto mkl_arcsinh = arcsinh(asinh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; .. _example-top_level-arcsinh-105: .. dropdown:: arcsinh (np_test_2_all.cpp:1062) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1052 :emphasize-lines: 11 std::cout << "========= testInverseHyperbolicMKL ===="; size_t test_size = 1000; // Test arcsinh with larger range NDArray asinh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { asinh_test_data.setElementAt({ i }, -10.0 + 20.0 * static_cast(i) / test_size); } auto std_arcsinh = arcsinh(asinh_test_data, MathBackend::DEFAULT); auto mkl_arcsinh = arcsinh(asinh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; .. _example-top_level-arcsinh-106: .. dropdown:: arcsinh (np_test_2_all.cpp:1062) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1052 :emphasize-lines: 11 std::cout << "========= testInverseHyperbolicMKL ===="; size_t test_size = 1000; // Test arcsinh with larger range NDArray asinh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { asinh_test_data.setElementAt({ i }, -10.0 + 20.0 * static_cast(i) / test_size); } auto std_arcsinh = arcsinh(asinh_test_data, MathBackend::DEFAULT); auto mkl_arcsinh = arcsinh(asinh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; .. _example-top_level-arcsinh-107: .. dropdown:: arcsinh (np_test_2_all.cpp:1062) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1052 :emphasize-lines: 11 std::cout << "========= testInverseHyperbolicMKL ===="; size_t test_size = 1000; // Test arcsinh with larger range NDArray asinh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { asinh_test_data.setElementAt({ i }, -10.0 + 20.0 * static_cast(i) / test_size); } auto std_arcsinh = arcsinh(asinh_test_data, MathBackend::DEFAULT); auto mkl_arcsinh = arcsinh(asinh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; .. _example-top_level-arcsinh-108: .. dropdown:: arcsinh (np_test_2_all.cpp:1062) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1052 :emphasize-lines: 11 std::cout << "========= testInverseHyperbolicMKL ===="; size_t test_size = 1000; // Test arcsinh with larger range NDArray asinh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { asinh_test_data.setElementAt({ i }, -10.0 + 20.0 * static_cast(i) / test_size); } auto std_arcsinh = arcsinh(asinh_test_data, MathBackend::DEFAULT); auto mkl_arcsinh = arcsinh(asinh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; .. _example-top_level-arcsinh-109: .. dropdown:: arcsinh (np_test_2_all.cpp:1062) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1052 :emphasize-lines: 11 std::cout << "========= testInverseHyperbolicMKL ===="; size_t test_size = 1000; // Test arcsinh with larger range NDArray asinh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { asinh_test_data.setElementAt({ i }, -10.0 + 20.0 * static_cast(i) / test_size); } auto std_arcsinh = arcsinh(asinh_test_data, MathBackend::DEFAULT); auto mkl_arcsinh = arcsinh(asinh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; .. _example-top_level-arcsinh-110: .. dropdown:: arcsinh (np_test_2_all.cpp:1062) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1052 :emphasize-lines: 11 std::cout << "========= testInverseHyperbolicMKL ===="; size_t test_size = 1000; // Test arcsinh with larger range NDArray asinh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { asinh_test_data.setElementAt({ i }, -10.0 + 20.0 * static_cast(i) / test_size); } auto std_arcsinh = arcsinh(asinh_test_data, MathBackend::DEFAULT); auto mkl_arcsinh = arcsinh(asinh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; .. _example-top_level-arcsinh-111: .. dropdown:: arcsinh (np_test_2_all.cpp:1062) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1052 :emphasize-lines: 11 std::cout << "========= testInverseHyperbolicMKL ===="; size_t test_size = 1000; // Test arcsinh with larger range NDArray asinh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { asinh_test_data.setElementAt({ i }, -10.0 + 20.0 * static_cast(i) / test_size); } auto std_arcsinh = arcsinh(asinh_test_data, MathBackend::DEFAULT); auto mkl_arcsinh = arcsinh(asinh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; .. _example-top_level-arcsinh-112: .. dropdown:: arcsinh (np_test_2_all.cpp:1062) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1052 :emphasize-lines: 11 std::cout << "========= testInverseHyperbolicMKL ===="; size_t test_size = 1000; // Test arcsinh with larger range NDArray asinh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { asinh_test_data.setElementAt({ i }, -10.0 + 20.0 * static_cast(i) / test_size); } auto std_arcsinh = arcsinh(asinh_test_data, MathBackend::DEFAULT); auto mkl_arcsinh = arcsinh(asinh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arcsinh.getElementAt({ i }), std_arcsinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arcsinh MKL accuracy validated\n"; .. _example-top_level-arctan-113: .. dropdown:: arctan (np_test_1_all.cpp:23735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23725 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; .. _example-top_level-arctan-114: .. dropdown:: arctan (np_test_1_all.cpp:23735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23725 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; .. _example-top_level-arctan-115: .. dropdown:: arctan (np_test_1_all.cpp:23735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23725 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; .. _example-top_level-arctan-116: .. dropdown:: arctan (np_test_1_all.cpp:23735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23725 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; .. _example-top_level-arctan-117: .. dropdown:: arctan (np_test_1_all.cpp:23735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23725 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; .. _example-top_level-arctan-118: .. dropdown:: arctan (np_test_1_all.cpp:23735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23725 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; .. _example-top_level-arctan-119: .. dropdown:: arctan (np_test_1_all.cpp:23735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23725 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; .. _example-top_level-arctan-120: .. dropdown:: arctan (np_test_1_all.cpp:23735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23725 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; .. _example-top_level-arctan-121: .. dropdown:: arctan (np_test_1_all.cpp:23735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23725 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; .. _example-top_level-arctan-122: .. dropdown:: arctan (np_test_1_all.cpp:23735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23725 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; .. _example-top_level-arctan-123: .. dropdown:: arctan (np_test_1_all.cpp:23735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23725 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; .. _example-top_level-arctan-124: .. dropdown:: arctan (np_test_1_all.cpp:23735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23725 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; .. _example-top_level-arctan-125: .. dropdown:: arctan (np_test_1_all.cpp:23735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23725 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; .. _example-top_level-arctan2-126: .. dropdown:: arctan2 (np_test_1_all.cpp:23739) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23729 :emphasize-lines: 11 // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; // Test exponential and logarithmic functions auto exp_result = numpy::exp(array); auto log_result = numpy::log(array); .. _example-top_level-arctan2-127: .. dropdown:: arctan2 (np_test_1_all.cpp:23739) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23729 :emphasize-lines: 11 // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; // Test exponential and logarithmic functions auto exp_result = numpy::exp(array); auto log_result = numpy::log(array); .. _example-top_level-arctan2-128: .. dropdown:: arctan2 (np_test_1_all.cpp:23739) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23729 :emphasize-lines: 11 // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; // Test exponential and logarithmic functions auto exp_result = numpy::exp(array); auto log_result = numpy::log(array); .. _example-top_level-arctan2-129: .. dropdown:: arctan2 (np_test_1_all.cpp:23739) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23729 :emphasize-lines: 11 // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); auto acos_result = numpy::arccos(small_array); auto atan_result = numpy::arctan(small_array); // std::cout << "[OK] Inverse trigonometric functions have correct signatures\n"; // Test arctan2 with broadcasting auto atan2_result = arctan2(array, array2); if (!(atan2_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(atan2_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] arctan2 function has correct signature\n"; // Test exponential and logarithmic functions auto exp_result = numpy::exp(array); auto log_result = numpy::log(array); .. _example-top_level-arctanh-130: .. dropdown:: arctanh (np_test_2_all.cpp:1098) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1088 :emphasize-lines: 11 } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; // Test arctanh with values in (-1, 1) NDArray atanh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { atanh_test_data.setElementAt({ i }, -0.99 + 1.98 * static_cast(i) / test_size); } auto std_arctanh = arctanh(atanh_test_data, MathBackend::DEFAULT); auto mkl_arctanh = arctanh(atanh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arctanh MKL accuracy validated\n"; .. _example-top_level-arctanh-131: .. dropdown:: arctanh (np_test_2_all.cpp:1098) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1088 :emphasize-lines: 11 } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; // Test arctanh with values in (-1, 1) NDArray atanh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { atanh_test_data.setElementAt({ i }, -0.99 + 1.98 * static_cast(i) / test_size); } auto std_arctanh = arctanh(atanh_test_data, MathBackend::DEFAULT); auto mkl_arctanh = arctanh(atanh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arctanh MKL accuracy validated\n"; .. _example-top_level-arctanh-132: .. dropdown:: arctanh (np_test_2_all.cpp:1098) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1088 :emphasize-lines: 11 } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; // Test arctanh with values in (-1, 1) NDArray atanh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { atanh_test_data.setElementAt({ i }, -0.99 + 1.98 * static_cast(i) / test_size); } auto std_arctanh = arctanh(atanh_test_data, MathBackend::DEFAULT); auto mkl_arctanh = arctanh(atanh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arctanh MKL accuracy validated\n"; .. _example-top_level-arctanh-133: .. dropdown:: arctanh (np_test_2_all.cpp:1098) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1088 :emphasize-lines: 11 } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; // Test arctanh with values in (-1, 1) NDArray atanh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { atanh_test_data.setElementAt({ i }, -0.99 + 1.98 * static_cast(i) / test_size); } auto std_arctanh = arctanh(atanh_test_data, MathBackend::DEFAULT); auto mkl_arctanh = arctanh(atanh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arctanh MKL accuracy validated\n"; .. _example-top_level-arctanh-134: .. dropdown:: arctanh (np_test_2_all.cpp:1098) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1088 :emphasize-lines: 11 } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; // Test arctanh with values in (-1, 1) NDArray atanh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { atanh_test_data.setElementAt({ i }, -0.99 + 1.98 * static_cast(i) / test_size); } auto std_arctanh = arctanh(atanh_test_data, MathBackend::DEFAULT); auto mkl_arctanh = arctanh(atanh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arctanh MKL accuracy validated\n"; .. _example-top_level-arctanh-135: .. dropdown:: arctanh (np_test_2_all.cpp:1098) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1088 :emphasize-lines: 11 } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; // Test arctanh with values in (-1, 1) NDArray atanh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { atanh_test_data.setElementAt({ i }, -0.99 + 1.98 * static_cast(i) / test_size); } auto std_arctanh = arctanh(atanh_test_data, MathBackend::DEFAULT); auto mkl_arctanh = arctanh(atanh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arctanh MKL accuracy validated\n"; .. _example-top_level-arctanh-136: .. dropdown:: arctanh (np_test_2_all.cpp:1098) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1088 :emphasize-lines: 11 } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; // Test arctanh with values in (-1, 1) NDArray atanh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { atanh_test_data.setElementAt({ i }, -0.99 + 1.98 * static_cast(i) / test_size); } auto std_arctanh = arctanh(atanh_test_data, MathBackend::DEFAULT); auto mkl_arctanh = arctanh(atanh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arctanh MKL accuracy validated\n"; .. _example-top_level-arctanh-137: .. dropdown:: arctanh (np_test_2_all.cpp:1098) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1088 :emphasize-lines: 11 } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; // Test arctanh with values in (-1, 1) NDArray atanh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { atanh_test_data.setElementAt({ i }, -0.99 + 1.98 * static_cast(i) / test_size); } auto std_arctanh = arctanh(atanh_test_data, MathBackend::DEFAULT); auto mkl_arctanh = arctanh(atanh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arctanh MKL accuracy validated\n"; .. _example-top_level-arctanh-138: .. dropdown:: arctanh (np_test_2_all.cpp:1098) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1088 :emphasize-lines: 11 } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; // Test arctanh with values in (-1, 1) NDArray atanh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { atanh_test_data.setElementAt({ i }, -0.99 + 1.98 * static_cast(i) / test_size); } auto std_arctanh = arctanh(atanh_test_data, MathBackend::DEFAULT); auto mkl_arctanh = arctanh(atanh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arctanh MKL accuracy validated\n"; .. _example-top_level-arctanh-139: .. dropdown:: arctanh (np_test_2_all.cpp:1098) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1088 :emphasize-lines: 11 } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; // Test arctanh with values in (-1, 1) NDArray atanh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { atanh_test_data.setElementAt({ i }, -0.99 + 1.98 * static_cast(i) / test_size); } auto std_arctanh = arctanh(atanh_test_data, MathBackend::DEFAULT); auto mkl_arctanh = arctanh(atanh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arctanh MKL accuracy validated\n"; .. _example-top_level-arctanh-140: .. dropdown:: arctanh (np_test_2_all.cpp:1098) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1088 :emphasize-lines: 11 } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; // Test arctanh with values in (-1, 1) NDArray atanh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { atanh_test_data.setElementAt({ i }, -0.99 + 1.98 * static_cast(i) / test_size); } auto std_arctanh = arctanh(atanh_test_data, MathBackend::DEFAULT); auto mkl_arctanh = arctanh(atanh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arctanh MKL accuracy validated\n"; .. _example-top_level-arctanh-141: .. dropdown:: arctanh (np_test_2_all.cpp:1098) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1088 :emphasize-lines: 11 } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; // Test arctanh with values in (-1, 1) NDArray atanh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { atanh_test_data.setElementAt({ i }, -0.99 + 1.98 * static_cast(i) / test_size); } auto std_arctanh = arctanh(atanh_test_data, MathBackend::DEFAULT); auto mkl_arctanh = arctanh(atanh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arctanh MKL accuracy validated\n"; .. _example-top_level-arctanh-142: .. dropdown:: arctanh (np_test_2_all.cpp:1098) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1088 :emphasize-lines: 11 } } // std::cout << "[OK] arccosh MKL accuracy validated\n"; // Test arctanh with values in (-1, 1) NDArray atanh_test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { atanh_test_data.setElementAt({ i }, -0.99 + 1.98 * static_cast(i) / test_size); } auto std_arctanh = arctanh(atanh_test_data, MathBackend::DEFAULT); auto mkl_arctanh = arctanh(atanh_test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))) { std::string description = std::string("testInverseHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_arctanh.getElementAt({ i }), std_arctanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] arctanh MKL accuracy validated\n"; .. _example-top_level-cbrt-143: .. dropdown:: cbrt (np_test_2_all.cpp:5686) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5676 :emphasize-lines: 11 } if (!(approx_equal(square_result.getElementAt({ 3 }), 9.0))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(square_result.getElementAt({ 3 }), 9.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] square function works correctly\n"; // Test cbrt auto cbrt_values = linspace(1.0, 8.0, 4); auto cbrt_result = cbrt(cbrt_values); if (!(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-cbrt-144: .. dropdown:: cbrt (np_test_2_all.cpp:5686) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5676 :emphasize-lines: 11 } if (!(approx_equal(square_result.getElementAt({ 3 }), 9.0))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(square_result.getElementAt({ 3 }), 9.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] square function works correctly\n"; // Test cbrt auto cbrt_values = linspace(1.0, 8.0, 4); auto cbrt_result = cbrt(cbrt_values); if (!(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-cbrt-145: .. dropdown:: cbrt (np_test_2_all.cpp:5686) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5676 :emphasize-lines: 11 } if (!(approx_equal(square_result.getElementAt({ 3 }), 9.0))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(square_result.getElementAt({ 3 }), 9.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] square function works correctly\n"; // Test cbrt auto cbrt_values = linspace(1.0, 8.0, 4); auto cbrt_result = cbrt(cbrt_values); if (!(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-cbrt-146: .. dropdown:: cbrt (np_test_2_all.cpp:5686) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5676 :emphasize-lines: 11 } if (!(approx_equal(square_result.getElementAt({ 3 }), 9.0))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(square_result.getElementAt({ 3 }), 9.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] square function works correctly\n"; // Test cbrt auto cbrt_values = linspace(1.0, 8.0, 4); auto cbrt_result = cbrt(cbrt_values); if (!(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-cbrt-147: .. dropdown:: cbrt (np_test_2_all.cpp:5686) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5676 :emphasize-lines: 11 } if (!(approx_equal(square_result.getElementAt({ 3 }), 9.0))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(square_result.getElementAt({ 3 }), 9.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] square function works correctly\n"; // Test cbrt auto cbrt_values = linspace(1.0, 8.0, 4); auto cbrt_result = cbrt(cbrt_values); if (!(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-cbrt-148: .. dropdown:: cbrt (np_test_2_all.cpp:5686) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5676 :emphasize-lines: 11 } if (!(approx_equal(square_result.getElementAt({ 3 }), 9.0))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(square_result.getElementAt({ 3 }), 9.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] square function works correctly\n"; // Test cbrt auto cbrt_values = linspace(1.0, 8.0, 4); auto cbrt_result = cbrt(cbrt_values); if (!(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-cbrt-149: .. dropdown:: cbrt (np_test_2_all.cpp:5686) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5676 :emphasize-lines: 11 } if (!(approx_equal(square_result.getElementAt({ 3 }), 9.0))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(square_result.getElementAt({ 3 }), 9.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] square function works correctly\n"; // Test cbrt auto cbrt_values = linspace(1.0, 8.0, 4); auto cbrt_result = cbrt(cbrt_values); if (!(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-cbrt-150: .. dropdown:: cbrt (np_test_2_all.cpp:5686) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5676 :emphasize-lines: 11 } if (!(approx_equal(square_result.getElementAt({ 3 }), 9.0))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(square_result.getElementAt({ 3 }), 9.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] square function works correctly\n"; // Test cbrt auto cbrt_values = linspace(1.0, 8.0, 4); auto cbrt_result = cbrt(cbrt_values); if (!(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-cbrt-151: .. dropdown:: cbrt (np_test_2_all.cpp:5686) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5676 :emphasize-lines: 11 } if (!(approx_equal(square_result.getElementAt({ 3 }), 9.0))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(square_result.getElementAt({ 3 }), 9.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] square function works correctly\n"; // Test cbrt auto cbrt_values = linspace(1.0, 8.0, 4); auto cbrt_result = cbrt(cbrt_values); if (!(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-cbrt-152: .. dropdown:: cbrt (np_test_2_all.cpp:5686) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5676 :emphasize-lines: 11 } if (!(approx_equal(square_result.getElementAt({ 3 }), 9.0))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(square_result.getElementAt({ 3 }), 9.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] square function works correctly\n"; // Test cbrt auto cbrt_values = linspace(1.0, 8.0, 4); auto cbrt_result = cbrt(cbrt_values); if (!(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-cbrt-153: .. dropdown:: cbrt (np_test_2_all.cpp:5686) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5676 :emphasize-lines: 11 } if (!(approx_equal(square_result.getElementAt({ 3 }), 9.0))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(square_result.getElementAt({ 3 }), 9.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] square function works correctly\n"; // Test cbrt auto cbrt_values = linspace(1.0, 8.0, 4); auto cbrt_result = cbrt(cbrt_values); if (!(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-cbrt-154: .. dropdown:: cbrt (np_test_2_all.cpp:5686) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5676 :emphasize-lines: 11 } if (!(approx_equal(square_result.getElementAt({ 3 }), 9.0))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(square_result.getElementAt({ 3 }), 9.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] square function works correctly\n"; // Test cbrt auto cbrt_values = linspace(1.0, 8.0, 4); auto cbrt_result = cbrt(cbrt_values); if (!(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-cbrt-155: .. dropdown:: cbrt (np_test_2_all.cpp:5686) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5676 :emphasize-lines: 11 } if (!(approx_equal(square_result.getElementAt({ 3 }), 9.0))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(square_result.getElementAt({ 3 }), 9.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] square function works correctly\n"; // Test cbrt auto cbrt_values = linspace(1.0, 8.0, 4); auto cbrt_result = cbrt(cbrt_values); if (!(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 0 }), std::cbrt(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))) { std::string description = std::string("testPowerFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(cbrt_result.getElementAt({ 3 }), std::cbrt(8.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-ceil-156: .. dropdown:: ceil (np_test_2_all.cpp:5735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5725 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] floor function works correctly\n"; // Test ceil auto ceil_result = ceil(values); if (!(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-ceil-157: .. dropdown:: ceil (np_test_2_all.cpp:5735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5725 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] floor function works correctly\n"; // Test ceil auto ceil_result = ceil(values); if (!(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-ceil-158: .. dropdown:: ceil (np_test_2_all.cpp:5735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5725 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] floor function works correctly\n"; // Test ceil auto ceil_result = ceil(values); if (!(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-ceil-159: .. dropdown:: ceil (np_test_2_all.cpp:5735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5725 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] floor function works correctly\n"; // Test ceil auto ceil_result = ceil(values); if (!(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-ceil-160: .. dropdown:: ceil (np_test_2_all.cpp:5735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5725 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] floor function works correctly\n"; // Test ceil auto ceil_result = ceil(values); if (!(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-ceil-161: .. dropdown:: ceil (np_test_2_all.cpp:5735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5725 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] floor function works correctly\n"; // Test ceil auto ceil_result = ceil(values); if (!(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-ceil-162: .. dropdown:: ceil (np_test_2_all.cpp:5735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5725 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] floor function works correctly\n"; // Test ceil auto ceil_result = ceil(values); if (!(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-ceil-163: .. dropdown:: ceil (np_test_2_all.cpp:5735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5725 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] floor function works correctly\n"; // Test ceil auto ceil_result = ceil(values); if (!(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-ceil-164: .. dropdown:: ceil (np_test_2_all.cpp:5735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5725 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] floor function works correctly\n"; // Test ceil auto ceil_result = ceil(values); if (!(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-ceil-165: .. dropdown:: ceil (np_test_2_all.cpp:5735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5725 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] floor function works correctly\n"; // Test ceil auto ceil_result = ceil(values); if (!(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-ceil-166: .. dropdown:: ceil (np_test_2_all.cpp:5735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5725 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] floor function works correctly\n"; // Test ceil auto ceil_result = ceil(values); if (!(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-ceiltoday-167: .. dropdown:: ceilToDay (np_test_1_all.cpp:28677) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 28667 :emphasize-lines: 11 // DATE UTILITIES TESTS // ============================================================================ void np_test_datetime_floor_ceil() { std::cout << "========= floorToDay/ceilToDay: round to day boundaries ======================="; // Create a datetime with time component auto dt_with_time = numpy::datetime64("2024-01-15T14:30:45"); auto floored = numpy::datetime_utils::floorToDay(dt_with_time); auto ceiled = numpy::datetime_utils::ceilToDay(dt_with_time); // Both should return valid datetime64 objects bool passed = (!floored.isNaT() && !ceiled.isNaT()); if (!passed) { std::cout << " [FAIL] : in np_test_datetime_floor_ceil() : Floor/Ceil operations failed"; throw std::runtime_error("np_test_datetime_floor_ceil failed"); } std::cout << " -> tests passed" << std::endl; .. _example-top_level-cos-168: .. dropdown:: cos (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-cos-169: .. dropdown:: cos (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-cos-170: .. dropdown:: cos (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-cos-171: .. dropdown:: cos (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-cos-172: .. dropdown:: cos (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-cos-173: .. dropdown:: cos (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-cos-174: .. dropdown:: cos (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-cos-175: .. dropdown:: cos (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-cos-176: .. dropdown:: cos (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-cos-177: .. dropdown:: cos (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-cos-178: .. dropdown:: cos (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-cos-179: .. dropdown:: cos (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-cos-180: .. dropdown:: cos (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-cos-181: .. dropdown:: cos (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-cos-182: .. dropdown:: cos (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-cos_inplace-183: .. dropdown:: cos_inplace (np_test_2_all.cpp:531) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 521 :emphasize-lines: 11 } // Create reference result (non-in-place) auto reference = cos(data, MathBackend::DEFAULT); // Create fresh arrays for in-place testing NDArray mkl_data = data.copydeepArray(); NDArray std_data = data.copydeepArray(); // Test MKL in-place cos_inplace(mkl_data, MathBackend::MKL); // Test standard in-place cos_inplace(std_data, MathBackend::DEFAULT); // Verify results - only check a few values to avoid excessive output double max_mkl_error = 0.0; double max_std_error = 0.0; for (size_t i = 0; i < 1000; ++i) { double mkl_val = mkl_data.getElementAt({ i }); .. _example-top_level-cosh-184: .. dropdown:: cosh (np_test_2_all.cpp:1022) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1012 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; // Test cosh auto std_cosh = cosh(test_data, MathBackend::DEFAULT); auto mkl_cosh = cosh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; .. _example-top_level-cosh-185: .. dropdown:: cosh (np_test_2_all.cpp:1022) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1012 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; // Test cosh auto std_cosh = cosh(test_data, MathBackend::DEFAULT); auto mkl_cosh = cosh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; .. _example-top_level-cosh-186: .. dropdown:: cosh (np_test_2_all.cpp:1022) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1012 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; // Test cosh auto std_cosh = cosh(test_data, MathBackend::DEFAULT); auto mkl_cosh = cosh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; .. _example-top_level-cosh-187: .. dropdown:: cosh (np_test_2_all.cpp:1022) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1012 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; // Test cosh auto std_cosh = cosh(test_data, MathBackend::DEFAULT); auto mkl_cosh = cosh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; .. _example-top_level-cosh-188: .. dropdown:: cosh (np_test_2_all.cpp:1022) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1012 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; // Test cosh auto std_cosh = cosh(test_data, MathBackend::DEFAULT); auto mkl_cosh = cosh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; .. _example-top_level-cosh-189: .. dropdown:: cosh (np_test_2_all.cpp:1022) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1012 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; // Test cosh auto std_cosh = cosh(test_data, MathBackend::DEFAULT); auto mkl_cosh = cosh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; .. _example-top_level-cosh-190: .. dropdown:: cosh (np_test_2_all.cpp:1022) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1012 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; // Test cosh auto std_cosh = cosh(test_data, MathBackend::DEFAULT); auto mkl_cosh = cosh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; .. _example-top_level-cosh-191: .. dropdown:: cosh (np_test_2_all.cpp:1022) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1012 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; // Test cosh auto std_cosh = cosh(test_data, MathBackend::DEFAULT); auto mkl_cosh = cosh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; .. _example-top_level-cosh-192: .. dropdown:: cosh (np_test_2_all.cpp:1022) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1012 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; // Test cosh auto std_cosh = cosh(test_data, MathBackend::DEFAULT); auto mkl_cosh = cosh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; .. _example-top_level-cosh-193: .. dropdown:: cosh (np_test_2_all.cpp:1022) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1012 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; // Test cosh auto std_cosh = cosh(test_data, MathBackend::DEFAULT); auto mkl_cosh = cosh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; .. _example-top_level-cosh-194: .. dropdown:: cosh (np_test_2_all.cpp:1022) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1012 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; // Test cosh auto std_cosh = cosh(test_data, MathBackend::DEFAULT); auto mkl_cosh = cosh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; .. _example-top_level-cosh-195: .. dropdown:: cosh (np_test_2_all.cpp:1022) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1012 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; // Test cosh auto std_cosh = cosh(test_data, MathBackend::DEFAULT); auto mkl_cosh = cosh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; .. _example-top_level-cosh-196: .. dropdown:: cosh (np_test_2_all.cpp:1022) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1012 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; // Test cosh auto std_cosh = cosh(test_data, MathBackend::DEFAULT); auto mkl_cosh = cosh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; .. _example-top_level-cosm-197: .. dropdown:: cosm (np_test_2_all.cpp:5220) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5210 :emphasize-lines: 11 assert_test(std::abs(sqrtB_squared(1, 1) - 9.0) < 1e-6, "Matrix square root verification 1,1"); } catch (...) { // std::cout << "Matrix square root test failed"; } // Test matrix sine and cosine numpy::Matrix small_mat("0.1 0; 0 0.1"); // Small matrix for convergence try { auto sinA = numpy::sinm(small_mat); auto cosA = numpy::cosm(small_mat); assert_test(sinA.rows() == 2 && sinA.cols() == 2, "Matrix sine dimensions"); assert_test(cosA.rows() == 2 && cosA.cols() == 2, "Matrix cosine dimensions"); // sin^2 + cos^2 should be close to I for small angles auto sin2 = numpy::multiply(sinA, sinA); auto cos2 = numpy::multiply(cosA, cosA); auto identity_check = sin2 + cos2; assert_test(std::abs(identity_check(0, 0) - 1.0) < 1e-6, "Matrix trig identity"); assert_test(std::abs(identity_check(1, 1) - 1.0) < 1e-6, "Matrix trig identity"); } .. _example-top_level-cospi-198: .. dropdown:: cospi (np_test_1_all.cpp:27865) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27855 :emphasize-lines: 11 } // std::cout << "] (expected: [36, 42, 12])" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_cospi() { std::cout << "========= cospi: cos(x*π) ======================="; // Test special values auto r1 = cospi(0.0); auto r2 = cospi(0.5); auto r3 = cospi(1.0); auto r4 = cospi(1.5); // std::cout << std::fixed << std::setprecision(6); // std::cout << " cospi(0.0) = " << r1 << " (expected: 1.000000)" << std::endl; // std::cout << " cospi(0.5) = " << r2 << " (expected: 0.000000)" << std::endl; // std::cout << " cospi(1.0) = " << r3 << " (expected: -1.000000)" << std::endl; // std::cout << " cospi(1.5) = " << r4 << " (expected: 0.000000)" << std::endl; .. _example-top_level-cospi-199: .. dropdown:: cospi (np_test_1_all.cpp:27865) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27855 :emphasize-lines: 11 } // std::cout << "] (expected: [36, 42, 12])" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_cospi() { std::cout << "========= cospi: cos(x*π) ======================="; // Test special values auto r1 = cospi(0.0); auto r2 = cospi(0.5); auto r3 = cospi(1.0); auto r4 = cospi(1.5); // std::cout << std::fixed << std::setprecision(6); // std::cout << " cospi(0.0) = " << r1 << " (expected: 1.000000)" << std::endl; // std::cout << " cospi(0.5) = " << r2 << " (expected: 0.000000)" << std::endl; // std::cout << " cospi(1.0) = " << r3 << " (expected: -1.000000)" << std::endl; // std::cout << " cospi(1.5) = " << r4 << " (expected: 0.000000)" << std::endl; .. _example-top_level-deg2rad-200: .. dropdown:: deg2rad (np_test_1_all.cpp:23785) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23775 :emphasize-lines: 11 } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; .. _example-top_level-deg2rad-201: .. dropdown:: deg2rad (np_test_1_all.cpp:23785) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23775 :emphasize-lines: 11 } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; .. _example-top_level-deg2rad-202: .. dropdown:: deg2rad (np_test_1_all.cpp:23785) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23775 :emphasize-lines: 11 } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; .. _example-top_level-deg2rad-203: .. dropdown:: deg2rad (np_test_1_all.cpp:23785) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23775 :emphasize-lines: 11 } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; .. _example-top_level-deg2rad-204: .. dropdown:: deg2rad (np_test_1_all.cpp:23785) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23775 :emphasize-lines: 11 } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; .. _example-top_level-deg2rad-205: .. dropdown:: deg2rad (np_test_1_all.cpp:23785) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23775 :emphasize-lines: 11 } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; .. _example-top_level-deg2rad-206: .. dropdown:: deg2rad (np_test_1_all.cpp:23785) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23775 :emphasize-lines: 11 } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; .. _example-top_level-deg2rad-207: .. dropdown:: deg2rad (np_test_1_all.cpp:23785) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23775 :emphasize-lines: 11 } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; .. _example-top_level-deg2rad-208: .. dropdown:: deg2rad (np_test_1_all.cpp:23785) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23775 :emphasize-lines: 11 } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; .. _example-top_level-deg2rad-209: .. dropdown:: deg2rad (np_test_1_all.cpp:23785) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23775 :emphasize-lines: 11 } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; .. _example-top_level-deg2rad-210: .. dropdown:: deg2rad (np_test_1_all.cpp:23785) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23775 :emphasize-lines: 11 } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; .. _example-top_level-deg2rad-211: .. dropdown:: deg2rad (np_test_1_all.cpp:23785) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23775 :emphasize-lines: 11 } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; .. _example-top_level-deg2rad-212: .. dropdown:: deg2rad (np_test_1_all.cpp:23785) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23775 :emphasize-lines: 11 } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; .. _example-top_level-degrees-213: .. dropdown:: degrees (np_test_4_all.cpp:11691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11681 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(180+0i) → π+0i rad (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray degrees({5}); degrees.setElementAt({0}, 0); degrees.setElementAt({1}, 90); degrees.setElementAt({2}, 180); degrees.setElementAt({3}, 270); degrees.setElementAt({4}, 360); auto result = numpy::deg2rad(degrees); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-degrees-214: .. dropdown:: degrees (np_test_4_all.cpp:11691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11681 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(180+0i) → π+0i rad (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray degrees({5}); degrees.setElementAt({0}, 0); degrees.setElementAt({1}, 90); degrees.setElementAt({2}, 180); degrees.setElementAt({3}, 270); degrees.setElementAt({4}, 360); auto result = numpy::deg2rad(degrees); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-degrees-215: .. dropdown:: degrees (np_test_4_all.cpp:11691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11681 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(180+0i) → π+0i rad (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray degrees({5}); degrees.setElementAt({0}, 0); degrees.setElementAt({1}, 90); degrees.setElementAt({2}, 180); degrees.setElementAt({3}, 270); degrees.setElementAt({4}, 360); auto result = numpy::deg2rad(degrees); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-degrees-216: .. dropdown:: degrees (np_test_4_all.cpp:11691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11681 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(180+0i) → π+0i rad (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray degrees({5}); degrees.setElementAt({0}, 0); degrees.setElementAt({1}, 90); degrees.setElementAt({2}, 180); degrees.setElementAt({3}, 270); degrees.setElementAt({4}, 360); auto result = numpy::deg2rad(degrees); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-degrees-217: .. dropdown:: degrees (np_test_4_all.cpp:11691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11681 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(180+0i) → π+0i rad (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray degrees({5}); degrees.setElementAt({0}, 0); degrees.setElementAt({1}, 90); degrees.setElementAt({2}, 180); degrees.setElementAt({3}, 270); degrees.setElementAt({4}, 360); auto result = numpy::deg2rad(degrees); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-degrees-218: .. dropdown:: degrees (np_test_4_all.cpp:11691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11681 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(180+0i) → π+0i rad (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray degrees({5}); degrees.setElementAt({0}, 0); degrees.setElementAt({1}, 90); degrees.setElementAt({2}, 180); degrees.setElementAt({3}, 270); degrees.setElementAt({4}, 360); auto result = numpy::deg2rad(degrees); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-degrees-219: .. dropdown:: degrees (np_test_4_all.cpp:11691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11681 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(180+0i) → π+0i rad (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray degrees({5}); degrees.setElementAt({0}, 0); degrees.setElementAt({1}, 90); degrees.setElementAt({2}, 180); degrees.setElementAt({3}, 270); degrees.setElementAt({4}, 360); auto result = numpy::deg2rad(degrees); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-degrees-220: .. dropdown:: degrees (np_test_4_all.cpp:11691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11681 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(180+0i) → π+0i rad (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray degrees({5}); degrees.setElementAt({0}, 0); degrees.setElementAt({1}, 90); degrees.setElementAt({2}, 180); degrees.setElementAt({3}, 270); degrees.setElementAt({4}, 360); auto result = numpy::deg2rad(degrees); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-degrees-221: .. dropdown:: degrees (np_test_4_all.cpp:11691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11681 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(180+0i) → π+0i rad (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray degrees({5}); degrees.setElementAt({0}, 0); degrees.setElementAt({1}, 90); degrees.setElementAt({2}, 180); degrees.setElementAt({3}, 270); degrees.setElementAt({4}, 360); auto result = numpy::deg2rad(degrees); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-degrees-222: .. dropdown:: degrees (np_test_4_all.cpp:11691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11681 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(180+0i) → π+0i rad (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray degrees({5}); degrees.setElementAt({0}, 0); degrees.setElementAt({1}, 90); degrees.setElementAt({2}, 180); degrees.setElementAt({3}, 270); degrees.setElementAt({4}, 360); auto result = numpy::deg2rad(degrees); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-degrees-223: .. dropdown:: degrees (np_test_4_all.cpp:11691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11681 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(180+0i) → π+0i rad (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray degrees({5}); degrees.setElementAt({0}, 0); degrees.setElementAt({1}, 90); degrees.setElementAt({2}, 180); degrees.setElementAt({3}, 270); degrees.setElementAt({4}, 360); auto result = numpy::deg2rad(degrees); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-degrees-224: .. dropdown:: degrees (np_test_4_all.cpp:11691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11681 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(180+0i) → π+0i rad (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray degrees({5}); degrees.setElementAt({0}, 0); degrees.setElementAt({1}, 90); degrees.setElementAt({2}, 180); degrees.setElementAt({3}, 270); degrees.setElementAt({4}, 360); auto result = numpy::deg2rad(degrees); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-degrees-225: .. dropdown:: degrees (np_test_4_all.cpp:11691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11681 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(180+0i) → π+0i rad (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray degrees({5}); degrees.setElementAt({0}, 0); degrees.setElementAt({1}, 90); degrees.setElementAt({2}, 180); degrees.setElementAt({3}, 270); degrees.setElementAt({4}, 360); auto result = numpy::deg2rad(degrees); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-divide-226: .. dropdown:: divide (np_test_3_all.cpp:16880) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16870 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void np_test_missing_math_functions_divide_array() { std::cout << "========= divide: array-array division ======================="; // explicit namespace to avoid name clashes numpy::NDArray a = numpy::arange(10.0, 16.0, 1.0); numpy::NDArray b = numpy::arange(2.0, 8.0, 1.0); numpy::NDArray result = numpy::divide(a, b); // Verify values: [10,11,12,13,14,15] / [2,3,4,5,6,7] = [5,3.666...,3,2.6,2.333...,2.142...] auto pass = true; double expected[] = { 5.0, 11.0 / 3.0, 3.0, 2.6, 14.0 / 6.0, 15.0 / 7.0 }; for (size_t i = 0; i < 6 && pass; ++i) { double val = result.getElementAt({ i }); double exp = expected[i]; if (std::abs(val - exp) > 1e-10) { pass = false; } .. _example-top_level-divide-227: .. dropdown:: divide (np_test_3_all.cpp:16880) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16870 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void np_test_missing_math_functions_divide_array() { std::cout << "========= divide: array-array division ======================="; // explicit namespace to avoid name clashes numpy::NDArray a = numpy::arange(10.0, 16.0, 1.0); numpy::NDArray b = numpy::arange(2.0, 8.0, 1.0); numpy::NDArray result = numpy::divide(a, b); // Verify values: [10,11,12,13,14,15] / [2,3,4,5,6,7] = [5,3.666...,3,2.6,2.333...,2.142...] auto pass = true; double expected[] = { 5.0, 11.0 / 3.0, 3.0, 2.6, 14.0 / 6.0, 15.0 / 7.0 }; for (size_t i = 0; i < 6 && pass; ++i) { double val = result.getElementAt({ i }); double exp = expected[i]; if (std::abs(val - exp) > 1e-10) { pass = false; } .. _example-top_level-divide-228: .. dropdown:: divide (np_test_3_all.cpp:16880) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16870 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void np_test_missing_math_functions_divide_array() { std::cout << "========= divide: array-array division ======================="; // explicit namespace to avoid name clashes numpy::NDArray a = numpy::arange(10.0, 16.0, 1.0); numpy::NDArray b = numpy::arange(2.0, 8.0, 1.0); numpy::NDArray result = numpy::divide(a, b); // Verify values: [10,11,12,13,14,15] / [2,3,4,5,6,7] = [5,3.666...,3,2.6,2.333...,2.142...] auto pass = true; double expected[] = { 5.0, 11.0 / 3.0, 3.0, 2.6, 14.0 / 6.0, 15.0 / 7.0 }; for (size_t i = 0; i < 6 && pass; ++i) { double val = result.getElementAt({ i }); double exp = expected[i]; if (std::abs(val - exp) > 1e-10) { pass = false; } .. _example-top_level-divide-229: .. dropdown:: divide (np_test_3_all.cpp:16880) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16870 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void np_test_missing_math_functions_divide_array() { std::cout << "========= divide: array-array division ======================="; // explicit namespace to avoid name clashes numpy::NDArray a = numpy::arange(10.0, 16.0, 1.0); numpy::NDArray b = numpy::arange(2.0, 8.0, 1.0); numpy::NDArray result = numpy::divide(a, b); // Verify values: [10,11,12,13,14,15] / [2,3,4,5,6,7] = [5,3.666...,3,2.6,2.333...,2.142...] auto pass = true; double expected[] = { 5.0, 11.0 / 3.0, 3.0, 2.6, 14.0 / 6.0, 15.0 / 7.0 }; for (size_t i = 0; i < 6 && pass; ++i) { double val = result.getElementAt({ i }); double exp = expected[i]; if (std::abs(val - exp) > 1e-10) { pass = false; } .. _example-top_level-exp-230: .. dropdown:: exp (np_test_1_all.cpp:8008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7998 :emphasize-lines: 11 std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision // std::cout << " -> tests passed" << std::endl; } .. _example-top_level-exp-231: .. dropdown:: exp (np_test_1_all.cpp:8008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7998 :emphasize-lines: 11 std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision // std::cout << " -> tests passed" << std::endl; } .. _example-top_level-exp-232: .. dropdown:: exp (np_test_1_all.cpp:8008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7998 :emphasize-lines: 11 std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision // std::cout << " -> tests passed" << std::endl; } .. _example-top_level-exp-233: .. dropdown:: exp (np_test_1_all.cpp:8008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7998 :emphasize-lines: 11 std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision // std::cout << " -> tests passed" << std::endl; } .. _example-top_level-exp-234: .. dropdown:: exp (np_test_1_all.cpp:8008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7998 :emphasize-lines: 11 std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision // std::cout << " -> tests passed" << std::endl; } .. _example-top_level-exp-235: .. dropdown:: exp (np_test_1_all.cpp:8008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7998 :emphasize-lines: 11 std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision // std::cout << " -> tests passed" << std::endl; } .. _example-top_level-exp-236: .. dropdown:: exp (np_test_1_all.cpp:8008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7998 :emphasize-lines: 11 std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision // std::cout << " -> tests passed" << std::endl; } .. _example-top_level-exp-237: .. dropdown:: exp (np_test_1_all.cpp:8008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7998 :emphasize-lines: 11 std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision // std::cout << " -> tests passed" << std::endl; } .. _example-top_level-exp-238: .. dropdown:: exp (np_test_1_all.cpp:8008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7998 :emphasize-lines: 11 std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision // std::cout << " -> tests passed" << std::endl; } .. _example-top_level-exp-239: .. dropdown:: exp (np_test_1_all.cpp:8008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7998 :emphasize-lines: 11 std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision // std::cout << " -> tests passed" << std::endl; } .. _example-top_level-exp-240: .. dropdown:: exp (np_test_1_all.cpp:8008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7998 :emphasize-lines: 11 std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision // std::cout << " -> tests passed" << std::endl; } .. _example-top_level-exp-241: .. dropdown:: exp (np_test_1_all.cpp:8008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7998 :emphasize-lines: 11 std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision // std::cout << " -> tests passed" << std::endl; } .. _example-top_level-exp-242: .. dropdown:: exp (np_test_1_all.cpp:8008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7998 :emphasize-lines: 11 std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision // std::cout << " -> tests passed" << std::endl; } .. _example-top_level-exp-243: .. dropdown:: exp (np_test_1_all.cpp:8008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7998 :emphasize-lines: 11 std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision // std::cout << " -> tests passed" << std::endl; } .. _example-top_level-exp1-244: .. dropdown:: exp1 (np_test_1_all.cpp:10857) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10847 :emphasize-lines: 11 double ei_1 = expi(1.0); if (!(!std::isnan(ei_1) && std::isfinite(ei_1))) { std::string description = std::string("testExponentialIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(ei_1) && std::isfinite(ei_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Exponential integral Ei(x) basic functionality\n"; // Test E1 function // E1(0) should be ∞ if (!(std::isinf(exp1(0.0)) && exp1(0.0) > 0)) { std::string description = std::string("testExponentialIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(exp1(0.0)) && exp1(0.0) > 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } double e1_1 = exp1(1.0); if (!(!std::isnan(e1_1) && std::isfinite(e1_1))) { std::string description = std::string("testExponentialIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(e1_1) && std::isfinite(e1_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-exp1-245: .. dropdown:: exp1 (np_test_1_all.cpp:10857) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10847 :emphasize-lines: 11 double ei_1 = expi(1.0); if (!(!std::isnan(ei_1) && std::isfinite(ei_1))) { std::string description = std::string("testExponentialIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(ei_1) && std::isfinite(ei_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Exponential integral Ei(x) basic functionality\n"; // Test E1 function // E1(0) should be ∞ if (!(std::isinf(exp1(0.0)) && exp1(0.0) > 0)) { std::string description = std::string("testExponentialIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(exp1(0.0)) && exp1(0.0) > 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } double e1_1 = exp1(1.0); if (!(!std::isnan(e1_1) && std::isfinite(e1_1))) { std::string description = std::string("testExponentialIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(e1_1) && std::isfinite(e1_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-exp2-246: .. dropdown:: exp2 (np_test_2_all.cpp:5575) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5565 :emphasize-lines: 11 // Test exp auto exp_result = numpy::exp(values); if (!(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp function works correctly\n"; // Test exp2 auto exp2_result = numpy::exp2(values); if (!(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp2 function works correctly\n"; // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { .. _example-top_level-exp2-247: .. dropdown:: exp2 (np_test_2_all.cpp:5575) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5565 :emphasize-lines: 11 // Test exp auto exp_result = numpy::exp(values); if (!(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp function works correctly\n"; // Test exp2 auto exp2_result = numpy::exp2(values); if (!(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp2 function works correctly\n"; // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { .. _example-top_level-exp2-248: .. dropdown:: exp2 (np_test_2_all.cpp:5575) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5565 :emphasize-lines: 11 // Test exp auto exp_result = numpy::exp(values); if (!(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp function works correctly\n"; // Test exp2 auto exp2_result = numpy::exp2(values); if (!(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp2 function works correctly\n"; // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { .. _example-top_level-exp2-249: .. dropdown:: exp2 (np_test_2_all.cpp:5575) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5565 :emphasize-lines: 11 // Test exp auto exp_result = numpy::exp(values); if (!(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp function works correctly\n"; // Test exp2 auto exp2_result = numpy::exp2(values); if (!(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp2 function works correctly\n"; // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { .. _example-top_level-exp2-250: .. dropdown:: exp2 (np_test_2_all.cpp:5575) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5565 :emphasize-lines: 11 // Test exp auto exp_result = numpy::exp(values); if (!(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp function works correctly\n"; // Test exp2 auto exp2_result = numpy::exp2(values); if (!(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp2 function works correctly\n"; // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { .. _example-top_level-exp2-251: .. dropdown:: exp2 (np_test_2_all.cpp:5575) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5565 :emphasize-lines: 11 // Test exp auto exp_result = numpy::exp(values); if (!(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp function works correctly\n"; // Test exp2 auto exp2_result = numpy::exp2(values); if (!(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp2 function works correctly\n"; // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { .. _example-top_level-exp2-252: .. dropdown:: exp2 (np_test_2_all.cpp:5575) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5565 :emphasize-lines: 11 // Test exp auto exp_result = numpy::exp(values); if (!(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp function works correctly\n"; // Test exp2 auto exp2_result = numpy::exp2(values); if (!(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp2 function works correctly\n"; // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { .. _example-top_level-exp2-253: .. dropdown:: exp2 (np_test_2_all.cpp:5575) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5565 :emphasize-lines: 11 // Test exp auto exp_result = numpy::exp(values); if (!(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp function works correctly\n"; // Test exp2 auto exp2_result = numpy::exp2(values); if (!(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp2 function works correctly\n"; // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { .. _example-top_level-exp2-254: .. dropdown:: exp2 (np_test_2_all.cpp:5575) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5565 :emphasize-lines: 11 // Test exp auto exp_result = numpy::exp(values); if (!(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp function works correctly\n"; // Test exp2 auto exp2_result = numpy::exp2(values); if (!(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp2 function works correctly\n"; // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { .. _example-top_level-exp2-255: .. dropdown:: exp2 (np_test_2_all.cpp:5575) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5565 :emphasize-lines: 11 // Test exp auto exp_result = numpy::exp(values); if (!(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp function works correctly\n"; // Test exp2 auto exp2_result = numpy::exp2(values); if (!(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp2 function works correctly\n"; // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { .. _example-top_level-exp2-256: .. dropdown:: exp2 (np_test_2_all.cpp:5575) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5565 :emphasize-lines: 11 // Test exp auto exp_result = numpy::exp(values); if (!(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp function works correctly\n"; // Test exp2 auto exp2_result = numpy::exp2(values); if (!(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp2 function works correctly\n"; // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { .. _example-top_level-exp2-257: .. dropdown:: exp2 (np_test_2_all.cpp:5575) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5565 :emphasize-lines: 11 // Test exp auto exp_result = numpy::exp(values); if (!(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp function works correctly\n"; // Test exp2 auto exp2_result = numpy::exp2(values); if (!(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp2 function works correctly\n"; // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { .. _example-top_level-exp2-258: .. dropdown:: exp2 (np_test_2_all.cpp:5575) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5565 :emphasize-lines: 11 // Test exp auto exp_result = numpy::exp(values); if (!(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp_result.getElementAt({ 0 }), std::exp(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp function works correctly\n"; // Test exp2 auto exp2_result = numpy::exp2(values); if (!(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(exp2_result.getElementAt({ 0 }), std::exp2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] exp2 function works correctly\n"; // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { .. _example-top_level-exp_complex_mkl-259: .. dropdown:: exp_complex_mkl (np_test_3_all.cpp:17599) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17589 :emphasize-lines: 11 } // Create complex array numpy::NDArray> z({ 4 }); z.setElementAt({ 0 }, std::complex(1.0, 0.0)); z.setElementAt({ 1 }, std::complex(0.0, 1.0)); z.setElementAt({ 2 }, std::complex(1.0, 1.0)); z.setElementAt({ 3 }, std::complex(-1.0, 2.0)); // Test exp auto exp_result = numpy::mkl_special_complex::exp_complex_mkl(z); double tolerance = 1e-10; for (size_t i = 0; i < z.getSize(); ++i) { auto expected = std::exp(z.getElementAt({ i })); auto diff = std::abs(exp_result.getElementAt({ i }) - expected); if (diff > tolerance) { std::cout << " [FAIL] : exp_complex_mkl differs from std::exp at index " << i; throw std::runtime_error("exp_complex_mkl failed"); } } .. _example-top_level-exp_complex_mkl-260: .. dropdown:: exp_complex_mkl (np_test_3_all.cpp:17599) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17589 :emphasize-lines: 11 } // Create complex array numpy::NDArray> z({ 4 }); z.setElementAt({ 0 }, std::complex(1.0, 0.0)); z.setElementAt({ 1 }, std::complex(0.0, 1.0)); z.setElementAt({ 2 }, std::complex(1.0, 1.0)); z.setElementAt({ 3 }, std::complex(-1.0, 2.0)); // Test exp auto exp_result = numpy::mkl_special_complex::exp_complex_mkl(z); double tolerance = 1e-10; for (size_t i = 0; i < z.getSize(); ++i) { auto expected = std::exp(z.getElementAt({ i })); auto diff = std::abs(exp_result.getElementAt({ i }) - expected); if (diff > tolerance) { std::cout << " [FAIL] : exp_complex_mkl differs from std::exp at index " << i; throw std::runtime_error("exp_complex_mkl failed"); } } .. _example-top_level-exp_inplace-261: .. dropdown:: exp_inplace (np_test_2_all.cpp:1212) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1202 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { double val = -3.0 + 6.0 * static_cast(i) / test_size; test_data_d.setElementAt({ i }, val); reference_data_d.setElementAt({ i }, val); } // Get reference result auto reference_result = exp(reference_data_d, MathBackend::MKL); // Test in-place operation exp_inplace(test_data_d, MathBackend::MKL); // Compare results for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(test_data_d.getElementAt({ i }), reference_result.getElementAt({ i })))) { std::string description = std::string("testExponentialInPlace():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(test_data_d.getElementAt({ i }), reference_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } .. _example-top_level-expandtabs-262: .. dropdown:: expandtabs (np_test_5_all.cpp:1417) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1407 :emphasize-lines: 11 // ============================================================================ // FORMATTING OPERATION TESTS // ============================================================================ void np_test_string_expandtabs() { std::cout << "========= expandtabs formatting ======================="; std::vector strings = { "hello\tworld", "test\ttabs" }; auto arr = numpy::char_::array<32>(strings); auto expanded = numpy::char_::expandtabs(arr, 4); bool passed = (expanded.size() == arr.size()); if (!passed) { std::cout << " [FAIL] : in np_test_string_expandtabs() : size mismatch"; throw std::runtime_error("np_test_string_expandtabs failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-expandtabs-263: .. dropdown:: expandtabs (np_test_5_all.cpp:1417) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1407 :emphasize-lines: 11 // ============================================================================ // FORMATTING OPERATION TESTS // ============================================================================ void np_test_string_expandtabs() { std::cout << "========= expandtabs formatting ======================="; std::vector strings = { "hello\tworld", "test\ttabs" }; auto arr = numpy::char_::array<32>(strings); auto expanded = numpy::char_::expandtabs(arr, 4); bool passed = (expanded.size() == arr.size()); if (!passed) { std::cout << " [FAIL] : in np_test_string_expandtabs() : size mismatch"; throw std::runtime_error("np_test_string_expandtabs failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-expi-264: .. dropdown:: expi (np_test_1_all.cpp:10840) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10830 :emphasize-lines: 11 // std::cout << "[OK] Statistical distribution functions with MKL backend\n"; std::cout << " -> tests passed\n"; } void testExponentialIntegrals() { std::cout << "========= testExponentialIntegrals ===="; // Test exponential integrals // ei(0) should be -∞ if (!(std::isinf(expi(0.0)) && expi(0.0) < 0)) { std::string description = std::string("testExponentialIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(expi(0.0)) && expi(0.0) < 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test basic functionality for positive values double ei_1 = expi(1.0); if (!(!std::isnan(ei_1) && std::isfinite(ei_1))) { std::string description = std::string("testExponentialIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(ei_1) && std::isfinite(ei_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-expm-265: .. dropdown:: expm (np_test_2_all.cpp:5188) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5178 :emphasize-lines: 11 /** * Test matrix functions */ void testMatrixFunctions() { std::cout << "========= testMatrixFunctions ======================="; // Test matrix exponential for simple matrices numpy::Matrix A("0 1; 0 0"); // Nilpotent matrix try { auto expA = numpy::expm(A); assert_test(expA.rows() == 2 && expA.cols() == 2, "Matrix exponential dimensions"); // For nilpotent matrix, exp(A) = I + A assert_test(std::abs(expA(0, 0) - 1.0) < 1e-10, "Matrix exponential 0,0"); assert_test(std::abs(expA(0, 1) - 1.0) < 1e-10, "Matrix exponential 0,1"); assert_test(std::abs(expA(1, 0)) < 1e-10, "Matrix exponential 1,0"); assert_test(std::abs(expA(1, 1) - 1.0) < 1e-10, "Matrix exponential 1,1"); } catch (...) { // std::cout << "Matrix exponential test failed"; .. _example-top_level-expm1-266: .. dropdown:: expm1 (np_test_2_all.cpp:1259) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1249 :emphasize-lines: 11 std::cout << "========= testExpm1MKL ===="; size_t test_size = 1000; // Test small values where expm1 is more accurate than exp(x) - 1 NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { small_values.setElementAt({ i }, -0.1 + 0.2 * static_cast(i) / test_size); } auto std_result = expm1(small_values, MathBackend::DEFAULT); auto mkl_result = expm1(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testExpm1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-expm1-267: .. dropdown:: expm1 (np_test_2_all.cpp:1259) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1249 :emphasize-lines: 11 std::cout << "========= testExpm1MKL ===="; size_t test_size = 1000; // Test small values where expm1 is more accurate than exp(x) - 1 NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { small_values.setElementAt({ i }, -0.1 + 0.2 * static_cast(i) / test_size); } auto std_result = expm1(small_values, MathBackend::DEFAULT); auto mkl_result = expm1(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testExpm1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-expm1-268: .. dropdown:: expm1 (np_test_2_all.cpp:1259) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1249 :emphasize-lines: 11 std::cout << "========= testExpm1MKL ===="; size_t test_size = 1000; // Test small values where expm1 is more accurate than exp(x) - 1 NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { small_values.setElementAt({ i }, -0.1 + 0.2 * static_cast(i) / test_size); } auto std_result = expm1(small_values, MathBackend::DEFAULT); auto mkl_result = expm1(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testExpm1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-expm1-269: .. dropdown:: expm1 (np_test_2_all.cpp:1259) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1249 :emphasize-lines: 11 std::cout << "========= testExpm1MKL ===="; size_t test_size = 1000; // Test small values where expm1 is more accurate than exp(x) - 1 NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { small_values.setElementAt({ i }, -0.1 + 0.2 * static_cast(i) / test_size); } auto std_result = expm1(small_values, MathBackend::DEFAULT); auto mkl_result = expm1(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testExpm1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-expm1-270: .. dropdown:: expm1 (np_test_2_all.cpp:1259) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1249 :emphasize-lines: 11 std::cout << "========= testExpm1MKL ===="; size_t test_size = 1000; // Test small values where expm1 is more accurate than exp(x) - 1 NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { small_values.setElementAt({ i }, -0.1 + 0.2 * static_cast(i) / test_size); } auto std_result = expm1(small_values, MathBackend::DEFAULT); auto mkl_result = expm1(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testExpm1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-expm1-271: .. dropdown:: expm1 (np_test_2_all.cpp:1259) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1249 :emphasize-lines: 11 std::cout << "========= testExpm1MKL ===="; size_t test_size = 1000; // Test small values where expm1 is more accurate than exp(x) - 1 NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { small_values.setElementAt({ i }, -0.1 + 0.2 * static_cast(i) / test_size); } auto std_result = expm1(small_values, MathBackend::DEFAULT); auto mkl_result = expm1(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testExpm1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-expm1-272: .. dropdown:: expm1 (np_test_2_all.cpp:1259) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1249 :emphasize-lines: 11 std::cout << "========= testExpm1MKL ===="; size_t test_size = 1000; // Test small values where expm1 is more accurate than exp(x) - 1 NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { small_values.setElementAt({ i }, -0.1 + 0.2 * static_cast(i) / test_size); } auto std_result = expm1(small_values, MathBackend::DEFAULT); auto mkl_result = expm1(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testExpm1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-expm1-273: .. dropdown:: expm1 (np_test_2_all.cpp:1259) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1249 :emphasize-lines: 11 std::cout << "========= testExpm1MKL ===="; size_t test_size = 1000; // Test small values where expm1 is more accurate than exp(x) - 1 NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { small_values.setElementAt({ i }, -0.1 + 0.2 * static_cast(i) / test_size); } auto std_result = expm1(small_values, MathBackend::DEFAULT); auto mkl_result = expm1(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testExpm1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-expm1-274: .. dropdown:: expm1 (np_test_2_all.cpp:1259) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1249 :emphasize-lines: 11 std::cout << "========= testExpm1MKL ===="; size_t test_size = 1000; // Test small values where expm1 is more accurate than exp(x) - 1 NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { small_values.setElementAt({ i }, -0.1 + 0.2 * static_cast(i) / test_size); } auto std_result = expm1(small_values, MathBackend::DEFAULT); auto mkl_result = expm1(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testExpm1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-expm1-275: .. dropdown:: expm1 (np_test_2_all.cpp:1259) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1249 :emphasize-lines: 11 std::cout << "========= testExpm1MKL ===="; size_t test_size = 1000; // Test small values where expm1 is more accurate than exp(x) - 1 NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { small_values.setElementAt({ i }, -0.1 + 0.2 * static_cast(i) / test_size); } auto std_result = expm1(small_values, MathBackend::DEFAULT); auto mkl_result = expm1(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testExpm1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-expm1-276: .. dropdown:: expm1 (np_test_2_all.cpp:1259) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1249 :emphasize-lines: 11 std::cout << "========= testExpm1MKL ===="; size_t test_size = 1000; // Test small values where expm1 is more accurate than exp(x) - 1 NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { small_values.setElementAt({ i }, -0.1 + 0.2 * static_cast(i) / test_size); } auto std_result = expm1(small_values, MathBackend::DEFAULT); auto mkl_result = expm1(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testExpm1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-expm1-277: .. dropdown:: expm1 (np_test_2_all.cpp:1259) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1249 :emphasize-lines: 11 std::cout << "========= testExpm1MKL ===="; size_t test_size = 1000; // Test small values where expm1 is more accurate than exp(x) - 1 NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { small_values.setElementAt({ i }, -0.1 + 0.2 * static_cast(i) / test_size); } auto std_result = expm1(small_values, MathBackend::DEFAULT); auto mkl_result = expm1(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testExpm1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-expm1-278: .. dropdown:: expm1 (np_test_2_all.cpp:1259) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1249 :emphasize-lines: 11 std::cout << "========= testExpm1MKL ===="; size_t test_size = 1000; // Test small values where expm1 is more accurate than exp(x) - 1 NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { small_values.setElementAt({ i }, -0.1 + 0.2 * static_cast(i) / test_size); } auto std_result = expm1(small_values, MathBackend::DEFAULT); auto mkl_result = expm1(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testExpm1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fix-279: .. dropdown:: fix (np_test_1_all.cpp:20933) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20923 :emphasize-lines: 11 // Test fix function (truncate towards zero) auto arr = NDArray({ 6 }); arr.setElementAt({ 0 }, 1.7); arr.setElementAt({ 1 }, -1.7); arr.setElementAt({ 2 }, 2.9); arr.setElementAt({ 3 }, -2.9); arr.setElementAt({ 4 }, 0.5); arr.setElementAt({ 5 }, -0.5); auto result = fix(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fix-280: .. dropdown:: fix (np_test_1_all.cpp:20933) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20923 :emphasize-lines: 11 // Test fix function (truncate towards zero) auto arr = NDArray({ 6 }); arr.setElementAt({ 0 }, 1.7); arr.setElementAt({ 1 }, -1.7); arr.setElementAt({ 2 }, 2.9); arr.setElementAt({ 3 }, -2.9); arr.setElementAt({ 4 }, 0.5); arr.setElementAt({ 5 }, -0.5); auto result = fix(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fix-281: .. dropdown:: fix (np_test_1_all.cpp:20933) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20923 :emphasize-lines: 11 // Test fix function (truncate towards zero) auto arr = NDArray({ 6 }); arr.setElementAt({ 0 }, 1.7); arr.setElementAt({ 1 }, -1.7); arr.setElementAt({ 2 }, 2.9); arr.setElementAt({ 3 }, -2.9); arr.setElementAt({ 4 }, 0.5); arr.setElementAt({ 5 }, -0.5); auto result = fix(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fix-282: .. dropdown:: fix (np_test_1_all.cpp:20933) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20923 :emphasize-lines: 11 // Test fix function (truncate towards zero) auto arr = NDArray({ 6 }); arr.setElementAt({ 0 }, 1.7); arr.setElementAt({ 1 }, -1.7); arr.setElementAt({ 2 }, 2.9); arr.setElementAt({ 3 }, -2.9); arr.setElementAt({ 4 }, 0.5); arr.setElementAt({ 5 }, -0.5); auto result = fix(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fix-283: .. dropdown:: fix (np_test_1_all.cpp:20933) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20923 :emphasize-lines: 11 // Test fix function (truncate towards zero) auto arr = NDArray({ 6 }); arr.setElementAt({ 0 }, 1.7); arr.setElementAt({ 1 }, -1.7); arr.setElementAt({ 2 }, 2.9); arr.setElementAt({ 3 }, -2.9); arr.setElementAt({ 4 }, 0.5); arr.setElementAt({ 5 }, -0.5); auto result = fix(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fix-284: .. dropdown:: fix (np_test_1_all.cpp:20933) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20923 :emphasize-lines: 11 // Test fix function (truncate towards zero) auto arr = NDArray({ 6 }); arr.setElementAt({ 0 }, 1.7); arr.setElementAt({ 1 }, -1.7); arr.setElementAt({ 2 }, 2.9); arr.setElementAt({ 3 }, -2.9); arr.setElementAt({ 4 }, 0.5); arr.setElementAt({ 5 }, -0.5); auto result = fix(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fix-285: .. dropdown:: fix (np_test_1_all.cpp:20933) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20923 :emphasize-lines: 11 // Test fix function (truncate towards zero) auto arr = NDArray({ 6 }); arr.setElementAt({ 0 }, 1.7); arr.setElementAt({ 1 }, -1.7); arr.setElementAt({ 2 }, 2.9); arr.setElementAt({ 3 }, -2.9); arr.setElementAt({ 4 }, 0.5); arr.setElementAt({ 5 }, -0.5); auto result = fix(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fix-286: .. dropdown:: fix (np_test_1_all.cpp:20933) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20923 :emphasize-lines: 11 // Test fix function (truncate towards zero) auto arr = NDArray({ 6 }); arr.setElementAt({ 0 }, 1.7); arr.setElementAt({ 1 }, -1.7); arr.setElementAt({ 2 }, 2.9); arr.setElementAt({ 3 }, -2.9); arr.setElementAt({ 4 }, 0.5); arr.setElementAt({ 5 }, -0.5); auto result = fix(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fix-287: .. dropdown:: fix (np_test_1_all.cpp:20933) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20923 :emphasize-lines: 11 // Test fix function (truncate towards zero) auto arr = NDArray({ 6 }); arr.setElementAt({ 0 }, 1.7); arr.setElementAt({ 1 }, -1.7); arr.setElementAt({ 2 }, 2.9); arr.setElementAt({ 3 }, -2.9); arr.setElementAt({ 4 }, 0.5); arr.setElementAt({ 5 }, -0.5); auto result = fix(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fix-288: .. dropdown:: fix (np_test_1_all.cpp:20933) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20923 :emphasize-lines: 11 // Test fix function (truncate towards zero) auto arr = NDArray({ 6 }); arr.setElementAt({ 0 }, 1.7); arr.setElementAt({ 1 }, -1.7); arr.setElementAt({ 2 }, 2.9); arr.setElementAt({ 3 }, -2.9); arr.setElementAt({ 4 }, 0.5); arr.setElementAt({ 5 }, -0.5); auto result = fix(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fix-289: .. dropdown:: fix (np_test_1_all.cpp:20933) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20923 :emphasize-lines: 11 // Test fix function (truncate towards zero) auto arr = NDArray({ 6 }); arr.setElementAt({ 0 }, 1.7); arr.setElementAt({ 1 }, -1.7); arr.setElementAt({ 2 }, 2.9); arr.setElementAt({ 3 }, -2.9); arr.setElementAt({ 4 }, 0.5); arr.setElementAt({ 5 }, -0.5); auto result = fix(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fix-290: .. dropdown:: fix (np_test_1_all.cpp:20933) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20923 :emphasize-lines: 11 // Test fix function (truncate towards zero) auto arr = NDArray({ 6 }); arr.setElementAt({ 0 }, 1.7); arr.setElementAt({ 1 }, -1.7); arr.setElementAt({ 2 }, 2.9); arr.setElementAt({ 3 }, -2.9); arr.setElementAt({ 4 }, 0.5); arr.setElementAt({ 5 }, -0.5); auto result = fix(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -1.0)) { std::string description = std::string("testFixFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor-291: .. dropdown:: floor (np_test_2_all.cpp:5721) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5711 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] round function works correctly\n"; // Test floor auto floor_result = floor(values); if (!(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-floor-292: .. dropdown:: floor (np_test_2_all.cpp:5721) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5711 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] round function works correctly\n"; // Test floor auto floor_result = floor(values); if (!(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-floor-293: .. dropdown:: floor (np_test_2_all.cpp:5721) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5711 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] round function works correctly\n"; // Test floor auto floor_result = floor(values); if (!(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-floor-294: .. dropdown:: floor (np_test_2_all.cpp:5721) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5711 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] round function works correctly\n"; // Test floor auto floor_result = floor(values); if (!(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-floor-295: .. dropdown:: floor (np_test_2_all.cpp:5721) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5711 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] round function works correctly\n"; // Test floor auto floor_result = floor(values); if (!(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-floor-296: .. dropdown:: floor (np_test_2_all.cpp:5721) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5711 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] round function works correctly\n"; // Test floor auto floor_result = floor(values); if (!(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-floor-297: .. dropdown:: floor (np_test_2_all.cpp:5721) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5711 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] round function works correctly\n"; // Test floor auto floor_result = floor(values); if (!(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-floor-298: .. dropdown:: floor (np_test_2_all.cpp:5721) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5711 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] round function works correctly\n"; // Test floor auto floor_result = floor(values); if (!(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-floor-299: .. dropdown:: floor (np_test_2_all.cpp:5721) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5711 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] round function works correctly\n"; // Test floor auto floor_result = floor(values); if (!(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-floor-300: .. dropdown:: floor (np_test_2_all.cpp:5721) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5711 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] round function works correctly\n"; // Test floor auto floor_result = floor(values); if (!(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-floor-301: .. dropdown:: floor (np_test_2_all.cpp:5721) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5711 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] round function works correctly\n"; // Test floor auto floor_result = floor(values); if (!(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-floortoday-302: .. dropdown:: floorToDay (np_test_1_all.cpp:28676) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 28666 :emphasize-lines: 11 // ============================================================================ // DATE UTILITIES TESTS // ============================================================================ void np_test_datetime_floor_ceil() { std::cout << "========= floorToDay/ceilToDay: round to day boundaries ======================="; // Create a datetime with time component auto dt_with_time = numpy::datetime64("2024-01-15T14:30:45"); auto floored = numpy::datetime_utils::floorToDay(dt_with_time); auto ceiled = numpy::datetime_utils::ceilToDay(dt_with_time); // Both should return valid datetime64 objects bool passed = (!floored.isNaT() && !ceiled.isNaT()); if (!passed) { std::cout << " [FAIL] : in np_test_datetime_floor_ceil() : Floor/Ceil operations failed"; throw std::runtime_error("np_test_datetime_floor_ceil failed"); } .. _example-top_level-floor_divide-303: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-304: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-305: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-306: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-307: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-308: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-309: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-310: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-311: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-312: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-313: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-314: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-315: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-316: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-317: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-318: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-319: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-320: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-321: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-322: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-323: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-324: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-325: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-326: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-327: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-328: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-329: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-330: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-331: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-332: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-333: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-334: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-335: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-336: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-337: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-338: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-339: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-340: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-341: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-342: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-343: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-344: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-345: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-346: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-347: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-348: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-349: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-350: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-351: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-352: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-353: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-354: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-355: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-356: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-357: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-358: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-359: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-360: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-361: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-362: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-363: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-364: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-365: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-366: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-367: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-368: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-floor_divide-369: .. dropdown:: floor_divide (np_test_1_all.cpp:20986) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20976 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.0); a.setElementAt({ 3 }, -7.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = floor_divide(a, b); if (!(result.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == -3.0)) { std::string description = std::string("testFloorDivideFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == -3.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-hypot-370: .. dropdown:: hypot (np_test_1_all.cpp:27546) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27536 :emphasize-lines: 11 auto data = numpy::array({ 2.0, 3.0, 4.0, 5.0 }); auto mask = numpy::array({ false, false, true, false }); auto ma = numpy::ma::masked_array(data, mask); double prod = numpy::ma::product(ma); // std::cout << " ma::product([2,3,-,5]): " << prod << " (expected: 30)" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_hypot() { std::cout << "========= ma::hypot(): Euclidean distance with mask propagation ==="; auto x1 = numpy::array({ 3.0, 3.0, 0.0 }); auto x2 = numpy::array({ 4.0, 0.0, 4.0 }); auto mask1 = numpy::array({ false, true, false }); auto mask2 = numpy::array({ false, false, true }); auto ma1 = numpy::ma::masked_array(x1, mask1); auto ma2 = numpy::ma::masked_array(x2, mask2); auto result = numpy::ma::hypot(ma1, ma2); .. _example-top_level-hypot-371: .. dropdown:: hypot (np_test_1_all.cpp:27546) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27536 :emphasize-lines: 11 auto data = numpy::array({ 2.0, 3.0, 4.0, 5.0 }); auto mask = numpy::array({ false, false, true, false }); auto ma = numpy::ma::masked_array(data, mask); double prod = numpy::ma::product(ma); // std::cout << " ma::product([2,3,-,5]): " << prod << " (expected: 30)" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_hypot() { std::cout << "========= ma::hypot(): Euclidean distance with mask propagation ==="; auto x1 = numpy::array({ 3.0, 3.0, 0.0 }); auto x2 = numpy::array({ 4.0, 0.0, 4.0 }); auto mask1 = numpy::array({ false, true, false }); auto mask2 = numpy::array({ false, false, true }); auto ma1 = numpy::ma::masked_array(x1, mask1); auto ma2 = numpy::ma::masked_array(x2, mask2); auto result = numpy::ma::hypot(ma1, ma2); .. _example-top_level-hypot-372: .. dropdown:: hypot (np_test_1_all.cpp:27546) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27536 :emphasize-lines: 11 auto data = numpy::array({ 2.0, 3.0, 4.0, 5.0 }); auto mask = numpy::array({ false, false, true, false }); auto ma = numpy::ma::masked_array(data, mask); double prod = numpy::ma::product(ma); // std::cout << " ma::product([2,3,-,5]): " << prod << " (expected: 30)" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_hypot() { std::cout << "========= ma::hypot(): Euclidean distance with mask propagation ==="; auto x1 = numpy::array({ 3.0, 3.0, 0.0 }); auto x2 = numpy::array({ 4.0, 0.0, 4.0 }); auto mask1 = numpy::array({ false, true, false }); auto mask2 = numpy::array({ false, false, true }); auto ma1 = numpy::ma::masked_array(x1, mask1); auto ma2 = numpy::ma::masked_array(x2, mask2); auto result = numpy::ma::hypot(ma1, ma2); .. _example-top_level-hypot-373: .. dropdown:: hypot (np_test_1_all.cpp:27546) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27536 :emphasize-lines: 11 auto data = numpy::array({ 2.0, 3.0, 4.0, 5.0 }); auto mask = numpy::array({ false, false, true, false }); auto ma = numpy::ma::masked_array(data, mask); double prod = numpy::ma::product(ma); // std::cout << " ma::product([2,3,-,5]): " << prod << " (expected: 30)" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_hypot() { std::cout << "========= ma::hypot(): Euclidean distance with mask propagation ==="; auto x1 = numpy::array({ 3.0, 3.0, 0.0 }); auto x2 = numpy::array({ 4.0, 0.0, 4.0 }); auto mask1 = numpy::array({ false, true, false }); auto mask2 = numpy::array({ false, false, true }); auto ma1 = numpy::ma::masked_array(x1, mask1); auto ma2 = numpy::ma::masked_array(x2, mask2); auto result = numpy::ma::hypot(ma1, ma2); .. _example-top_level-hypot_safe-374: .. dropdown:: hypot_safe (np_test_2_all.cpp:7347) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7337 :emphasize-lines: 11 // Test safe divide double safe_result = safe_divide(1.0, 2.0); if (!(safe_result == 0.5)) { std::string description = std::string("test_basic_utilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(safe_result == 0.5)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Safe divide 1/2: " << safe_result << std::endl; // Test hypot double hypot_result = hypot_safe(3.0, 4.0); if (!(std::abs(hypot_result - 5.0) < 1e-10)) { std::string description = std::string("test_basic_utilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(hypot_result - 5.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Hypot(3,4): " << hypot_result << std::endl; // std::cout << "Basic utilities test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-log-375: .. dropdown:: log (np_test_1_all.cpp:10350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10340 :emphasize-lines: 11 if (!(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 4 }), 0.5 * std::log(M_PI), 1e-10))) { .. _example-top_level-log-376: .. dropdown:: log (np_test_1_all.cpp:10350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10340 :emphasize-lines: 11 if (!(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 4 }), 0.5 * std::log(M_PI), 1e-10))) { .. _example-top_level-log-377: .. dropdown:: log (np_test_1_all.cpp:10350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10340 :emphasize-lines: 11 if (!(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 4 }), 0.5 * std::log(M_PI), 1e-10))) { .. _example-top_level-log-378: .. dropdown:: log (np_test_1_all.cpp:10350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10340 :emphasize-lines: 11 if (!(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 4 }), 0.5 * std::log(M_PI), 1e-10))) { .. _example-top_level-log-379: .. dropdown:: log (np_test_1_all.cpp:10350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10340 :emphasize-lines: 11 if (!(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 4 }), 0.5 * std::log(M_PI), 1e-10))) { .. _example-top_level-log-380: .. dropdown:: log (np_test_1_all.cpp:10350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10340 :emphasize-lines: 11 if (!(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 4 }), 0.5 * std::log(M_PI), 1e-10))) { .. _example-top_level-log-381: .. dropdown:: log (np_test_1_all.cpp:10350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10340 :emphasize-lines: 11 if (!(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 4 }), 0.5 * std::log(M_PI), 1e-10))) { .. _example-top_level-log-382: .. dropdown:: log (np_test_1_all.cpp:10350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10340 :emphasize-lines: 11 if (!(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 4 }), 0.5 * std::log(M_PI), 1e-10))) { .. _example-top_level-log-383: .. dropdown:: log (np_test_1_all.cpp:10350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10340 :emphasize-lines: 11 if (!(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 4 }), 0.5 * std::log(M_PI), 1e-10))) { .. _example-top_level-log-384: .. dropdown:: log (np_test_1_all.cpp:10350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10340 :emphasize-lines: 11 if (!(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 4 }), 0.5 * std::log(M_PI), 1e-10))) { .. _example-top_level-log-385: .. dropdown:: log (np_test_1_all.cpp:10350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10340 :emphasize-lines: 11 if (!(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 4 }), 0.5 * std::log(M_PI), 1e-10))) { .. _example-top_level-log-386: .. dropdown:: log (np_test_1_all.cpp:10350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10340 :emphasize-lines: 11 if (!(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 4 }), 0.5 * std::log(M_PI), 1e-10))) { .. _example-top_level-log-387: .. dropdown:: log (np_test_1_all.cpp:10350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10340 :emphasize-lines: 11 if (!(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 4 }), 0.5 * std::log(M_PI), 1e-10))) { .. _example-top_level-log-388: .. dropdown:: log (np_test_1_all.cpp:10350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10340 :emphasize-lines: 11 if (!(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 2 }), std::log(2.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 3 }), std::log(6.0), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 4 }), 0.5 * std::log(M_PI), 1e-10))) { .. _example-top_level-log10-389: .. dropdown:: log10 (np_test_2_all.cpp:1444) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1434 :emphasize-lines: 11 size_t test_size = 1000; // Test double precision with powers of 10 NDArray test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [0.01, 1000] to test various powers of 10 test_data.setElementAt({ i }, 0.01 + 999.99 * static_cast(i) / test_size); } auto std_result = log10(test_data, MathBackend::DEFAULT); auto mkl_result = log10(test_data, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testLog10MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-log10-390: .. dropdown:: log10 (np_test_2_all.cpp:1444) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1434 :emphasize-lines: 11 size_t test_size = 1000; // Test double precision with powers of 10 NDArray test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [0.01, 1000] to test various powers of 10 test_data.setElementAt({ i }, 0.01 + 999.99 * static_cast(i) / test_size); } auto std_result = log10(test_data, MathBackend::DEFAULT); auto mkl_result = log10(test_data, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testLog10MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-log10-391: .. dropdown:: log10 (np_test_2_all.cpp:1444) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1434 :emphasize-lines: 11 size_t test_size = 1000; // Test double precision with powers of 10 NDArray test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [0.01, 1000] to test various powers of 10 test_data.setElementAt({ i }, 0.01 + 999.99 * static_cast(i) / test_size); } auto std_result = log10(test_data, MathBackend::DEFAULT); auto mkl_result = log10(test_data, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testLog10MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-log10-392: .. dropdown:: log10 (np_test_2_all.cpp:1444) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1434 :emphasize-lines: 11 size_t test_size = 1000; // Test double precision with powers of 10 NDArray test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [0.01, 1000] to test various powers of 10 test_data.setElementAt({ i }, 0.01 + 999.99 * static_cast(i) / test_size); } auto std_result = log10(test_data, MathBackend::DEFAULT); auto mkl_result = log10(test_data, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testLog10MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-log10-393: .. dropdown:: log10 (np_test_2_all.cpp:1444) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1434 :emphasize-lines: 11 size_t test_size = 1000; // Test double precision with powers of 10 NDArray test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [0.01, 1000] to test various powers of 10 test_data.setElementAt({ i }, 0.01 + 999.99 * static_cast(i) / test_size); } auto std_result = log10(test_data, MathBackend::DEFAULT); auto mkl_result = log10(test_data, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testLog10MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-log10-394: .. dropdown:: log10 (np_test_2_all.cpp:1444) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1434 :emphasize-lines: 11 size_t test_size = 1000; // Test double precision with powers of 10 NDArray test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [0.01, 1000] to test various powers of 10 test_data.setElementAt({ i }, 0.01 + 999.99 * static_cast(i) / test_size); } auto std_result = log10(test_data, MathBackend::DEFAULT); auto mkl_result = log10(test_data, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testLog10MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-log10-395: .. dropdown:: log10 (np_test_2_all.cpp:1444) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1434 :emphasize-lines: 11 size_t test_size = 1000; // Test double precision with powers of 10 NDArray test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [0.01, 1000] to test various powers of 10 test_data.setElementAt({ i }, 0.01 + 999.99 * static_cast(i) / test_size); } auto std_result = log10(test_data, MathBackend::DEFAULT); auto mkl_result = log10(test_data, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testLog10MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-log10-396: .. dropdown:: log10 (np_test_2_all.cpp:1444) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1434 :emphasize-lines: 11 size_t test_size = 1000; // Test double precision with powers of 10 NDArray test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [0.01, 1000] to test various powers of 10 test_data.setElementAt({ i }, 0.01 + 999.99 * static_cast(i) / test_size); } auto std_result = log10(test_data, MathBackend::DEFAULT); auto mkl_result = log10(test_data, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testLog10MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-log10-397: .. dropdown:: log10 (np_test_2_all.cpp:1444) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1434 :emphasize-lines: 11 size_t test_size = 1000; // Test double precision with powers of 10 NDArray test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [0.01, 1000] to test various powers of 10 test_data.setElementAt({ i }, 0.01 + 999.99 * static_cast(i) / test_size); } auto std_result = log10(test_data, MathBackend::DEFAULT); auto mkl_result = log10(test_data, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testLog10MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-log10-398: .. dropdown:: log10 (np_test_2_all.cpp:1444) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1434 :emphasize-lines: 11 size_t test_size = 1000; // Test double precision with powers of 10 NDArray test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [0.01, 1000] to test various powers of 10 test_data.setElementAt({ i }, 0.01 + 999.99 * static_cast(i) / test_size); } auto std_result = log10(test_data, MathBackend::DEFAULT); auto mkl_result = log10(test_data, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testLog10MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-log10-399: .. dropdown:: log10 (np_test_2_all.cpp:1444) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1434 :emphasize-lines: 11 size_t test_size = 1000; // Test double precision with powers of 10 NDArray test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [0.01, 1000] to test various powers of 10 test_data.setElementAt({ i }, 0.01 + 999.99 * static_cast(i) / test_size); } auto std_result = log10(test_data, MathBackend::DEFAULT); auto mkl_result = log10(test_data, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testLog10MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-log10-400: .. dropdown:: log10 (np_test_2_all.cpp:1444) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1434 :emphasize-lines: 11 size_t test_size = 1000; // Test double precision with powers of 10 NDArray test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [0.01, 1000] to test various powers of 10 test_data.setElementAt({ i }, 0.01 + 999.99 * static_cast(i) / test_size); } auto std_result = log10(test_data, MathBackend::DEFAULT); auto mkl_result = log10(test_data, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testLog10MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-log10-401: .. dropdown:: log10 (np_test_2_all.cpp:1444) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1434 :emphasize-lines: 11 size_t test_size = 1000; // Test double precision with powers of 10 NDArray test_data({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [0.01, 1000] to test various powers of 10 test_data.setElementAt({ i }, 0.01 + 999.99 * static_cast(i) / test_size); } auto std_result = log10(test_data, MathBackend::DEFAULT); auto mkl_result = log10(test_data, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); if (!(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))) { std::string description = std::string("testLog10MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_result.getElementAt({ i }), std_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-log1p-402: .. dropdown:: log1p (np_test_2_all.cpp:1493) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1483 :emphasize-lines: 11 } void testLog1pMKL() { std::cout << "========= testLog1pMKL ===="; size_t test_size = 1000; // Test small values where log1p is more accurate than log(1 + x) NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [-0.5, 1.0] to test small x where log1p(x) shines small_values.setElementAt({ i }, -0.5 + 1.5 * static_cast(i) / test_size); } auto std_result = log1p(small_values, MathBackend::DEFAULT); auto mkl_result = log1p(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); .. _example-top_level-log1p-403: .. dropdown:: log1p (np_test_2_all.cpp:1493) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1483 :emphasize-lines: 11 } void testLog1pMKL() { std::cout << "========= testLog1pMKL ===="; size_t test_size = 1000; // Test small values where log1p is more accurate than log(1 + x) NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [-0.5, 1.0] to test small x where log1p(x) shines small_values.setElementAt({ i }, -0.5 + 1.5 * static_cast(i) / test_size); } auto std_result = log1p(small_values, MathBackend::DEFAULT); auto mkl_result = log1p(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); .. _example-top_level-log1p-404: .. dropdown:: log1p (np_test_2_all.cpp:1493) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1483 :emphasize-lines: 11 } void testLog1pMKL() { std::cout << "========= testLog1pMKL ===="; size_t test_size = 1000; // Test small values where log1p is more accurate than log(1 + x) NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [-0.5, 1.0] to test small x where log1p(x) shines small_values.setElementAt({ i }, -0.5 + 1.5 * static_cast(i) / test_size); } auto std_result = log1p(small_values, MathBackend::DEFAULT); auto mkl_result = log1p(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); .. _example-top_level-log1p-405: .. dropdown:: log1p (np_test_2_all.cpp:1493) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1483 :emphasize-lines: 11 } void testLog1pMKL() { std::cout << "========= testLog1pMKL ===="; size_t test_size = 1000; // Test small values where log1p is more accurate than log(1 + x) NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [-0.5, 1.0] to test small x where log1p(x) shines small_values.setElementAt({ i }, -0.5 + 1.5 * static_cast(i) / test_size); } auto std_result = log1p(small_values, MathBackend::DEFAULT); auto mkl_result = log1p(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); .. _example-top_level-log1p-406: .. dropdown:: log1p (np_test_2_all.cpp:1493) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1483 :emphasize-lines: 11 } void testLog1pMKL() { std::cout << "========= testLog1pMKL ===="; size_t test_size = 1000; // Test small values where log1p is more accurate than log(1 + x) NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [-0.5, 1.0] to test small x where log1p(x) shines small_values.setElementAt({ i }, -0.5 + 1.5 * static_cast(i) / test_size); } auto std_result = log1p(small_values, MathBackend::DEFAULT); auto mkl_result = log1p(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); .. _example-top_level-log1p-407: .. dropdown:: log1p (np_test_2_all.cpp:1493) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1483 :emphasize-lines: 11 } void testLog1pMKL() { std::cout << "========= testLog1pMKL ===="; size_t test_size = 1000; // Test small values where log1p is more accurate than log(1 + x) NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [-0.5, 1.0] to test small x where log1p(x) shines small_values.setElementAt({ i }, -0.5 + 1.5 * static_cast(i) / test_size); } auto std_result = log1p(small_values, MathBackend::DEFAULT); auto mkl_result = log1p(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); .. _example-top_level-log1p-408: .. dropdown:: log1p (np_test_2_all.cpp:1493) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1483 :emphasize-lines: 11 } void testLog1pMKL() { std::cout << "========= testLog1pMKL ===="; size_t test_size = 1000; // Test small values where log1p is more accurate than log(1 + x) NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [-0.5, 1.0] to test small x where log1p(x) shines small_values.setElementAt({ i }, -0.5 + 1.5 * static_cast(i) / test_size); } auto std_result = log1p(small_values, MathBackend::DEFAULT); auto mkl_result = log1p(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); .. _example-top_level-log1p-409: .. dropdown:: log1p (np_test_2_all.cpp:1493) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1483 :emphasize-lines: 11 } void testLog1pMKL() { std::cout << "========= testLog1pMKL ===="; size_t test_size = 1000; // Test small values where log1p is more accurate than log(1 + x) NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [-0.5, 1.0] to test small x where log1p(x) shines small_values.setElementAt({ i }, -0.5 + 1.5 * static_cast(i) / test_size); } auto std_result = log1p(small_values, MathBackend::DEFAULT); auto mkl_result = log1p(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); .. _example-top_level-log1p-410: .. dropdown:: log1p (np_test_2_all.cpp:1493) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1483 :emphasize-lines: 11 } void testLog1pMKL() { std::cout << "========= testLog1pMKL ===="; size_t test_size = 1000; // Test small values where log1p is more accurate than log(1 + x) NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [-0.5, 1.0] to test small x where log1p(x) shines small_values.setElementAt({ i }, -0.5 + 1.5 * static_cast(i) / test_size); } auto std_result = log1p(small_values, MathBackend::DEFAULT); auto mkl_result = log1p(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); .. _example-top_level-log1p-411: .. dropdown:: log1p (np_test_2_all.cpp:1493) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1483 :emphasize-lines: 11 } void testLog1pMKL() { std::cout << "========= testLog1pMKL ===="; size_t test_size = 1000; // Test small values where log1p is more accurate than log(1 + x) NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [-0.5, 1.0] to test small x where log1p(x) shines small_values.setElementAt({ i }, -0.5 + 1.5 * static_cast(i) / test_size); } auto std_result = log1p(small_values, MathBackend::DEFAULT); auto mkl_result = log1p(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); .. _example-top_level-log1p-412: .. dropdown:: log1p (np_test_2_all.cpp:1493) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1483 :emphasize-lines: 11 } void testLog1pMKL() { std::cout << "========= testLog1pMKL ===="; size_t test_size = 1000; // Test small values where log1p is more accurate than log(1 + x) NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [-0.5, 1.0] to test small x where log1p(x) shines small_values.setElementAt({ i }, -0.5 + 1.5 * static_cast(i) / test_size); } auto std_result = log1p(small_values, MathBackend::DEFAULT); auto mkl_result = log1p(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); .. _example-top_level-log1p-413: .. dropdown:: log1p (np_test_2_all.cpp:1493) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1483 :emphasize-lines: 11 } void testLog1pMKL() { std::cout << "========= testLog1pMKL ===="; size_t test_size = 1000; // Test small values where log1p is more accurate than log(1 + x) NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [-0.5, 1.0] to test small x where log1p(x) shines small_values.setElementAt({ i }, -0.5 + 1.5 * static_cast(i) / test_size); } auto std_result = log1p(small_values, MathBackend::DEFAULT); auto mkl_result = log1p(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); .. _example-top_level-log1p-414: .. dropdown:: log1p (np_test_2_all.cpp:1493) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1483 :emphasize-lines: 11 } void testLog1pMKL() { std::cout << "========= testLog1pMKL ===="; size_t test_size = 1000; // Test small values where log1p is more accurate than log(1 + x) NDArray small_values({ test_size }); for (size_t i = 0; i < test_size; ++i) { // Fill with values in [-0.5, 1.0] to test small x where log1p(x) shines small_values.setElementAt({ i }, -0.5 + 1.5 * static_cast(i) / test_size); } auto std_result = log1p(small_values, MathBackend::DEFAULT); auto mkl_result = log1p(small_values, MathBackend::MKL); double max_error = 0.0; for (size_t i = 0; i < test_size; ++i) { double error = std::abs(mkl_result.getElementAt({ i }) - std_result.getElementAt({ i })); max_error = std::max(max_error, error); .. _example-top_level-log2-415: .. dropdown:: log2 (np_test_2_all.cpp:5593) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5583 :emphasize-lines: 11 // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log function works correctly\n"; // Test log2 auto log2_result = numpy::log2(values); if (!(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log2 function works correctly\n"; // Test log10 auto log10_result = numpy::log10(values); if (!(approx_equal(log10_result.getElementAt({ 0 }), std::log10(0.1), 1e-9))) { .. _example-top_level-log2-416: .. dropdown:: log2 (np_test_2_all.cpp:5593) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5583 :emphasize-lines: 11 // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log function works correctly\n"; // Test log2 auto log2_result = numpy::log2(values); if (!(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log2 function works correctly\n"; // Test log10 auto log10_result = numpy::log10(values); if (!(approx_equal(log10_result.getElementAt({ 0 }), std::log10(0.1), 1e-9))) { .. _example-top_level-log2-417: .. dropdown:: log2 (np_test_2_all.cpp:5593) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5583 :emphasize-lines: 11 // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log function works correctly\n"; // Test log2 auto log2_result = numpy::log2(values); if (!(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log2 function works correctly\n"; // Test log10 auto log10_result = numpy::log10(values); if (!(approx_equal(log10_result.getElementAt({ 0 }), std::log10(0.1), 1e-9))) { .. _example-top_level-log2-418: .. dropdown:: log2 (np_test_2_all.cpp:5593) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5583 :emphasize-lines: 11 // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log function works correctly\n"; // Test log2 auto log2_result = numpy::log2(values); if (!(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log2 function works correctly\n"; // Test log10 auto log10_result = numpy::log10(values); if (!(approx_equal(log10_result.getElementAt({ 0 }), std::log10(0.1), 1e-9))) { .. _example-top_level-log2-419: .. dropdown:: log2 (np_test_2_all.cpp:5593) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5583 :emphasize-lines: 11 // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log function works correctly\n"; // Test log2 auto log2_result = numpy::log2(values); if (!(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log2 function works correctly\n"; // Test log10 auto log10_result = numpy::log10(values); if (!(approx_equal(log10_result.getElementAt({ 0 }), std::log10(0.1), 1e-9))) { .. _example-top_level-log2-420: .. dropdown:: log2 (np_test_2_all.cpp:5593) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5583 :emphasize-lines: 11 // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log function works correctly\n"; // Test log2 auto log2_result = numpy::log2(values); if (!(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log2 function works correctly\n"; // Test log10 auto log10_result = numpy::log10(values); if (!(approx_equal(log10_result.getElementAt({ 0 }), std::log10(0.1), 1e-9))) { .. _example-top_level-log2-421: .. dropdown:: log2 (np_test_2_all.cpp:5593) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5583 :emphasize-lines: 11 // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log function works correctly\n"; // Test log2 auto log2_result = numpy::log2(values); if (!(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log2 function works correctly\n"; // Test log10 auto log10_result = numpy::log10(values); if (!(approx_equal(log10_result.getElementAt({ 0 }), std::log10(0.1), 1e-9))) { .. _example-top_level-log2-422: .. dropdown:: log2 (np_test_2_all.cpp:5593) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5583 :emphasize-lines: 11 // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log function works correctly\n"; // Test log2 auto log2_result = numpy::log2(values); if (!(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log2 function works correctly\n"; // Test log10 auto log10_result = numpy::log10(values); if (!(approx_equal(log10_result.getElementAt({ 0 }), std::log10(0.1), 1e-9))) { .. _example-top_level-log2-423: .. dropdown:: log2 (np_test_2_all.cpp:5593) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5583 :emphasize-lines: 11 // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log function works correctly\n"; // Test log2 auto log2_result = numpy::log2(values); if (!(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log2 function works correctly\n"; // Test log10 auto log10_result = numpy::log10(values); if (!(approx_equal(log10_result.getElementAt({ 0 }), std::log10(0.1), 1e-9))) { .. _example-top_level-log2-424: .. dropdown:: log2 (np_test_2_all.cpp:5593) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5583 :emphasize-lines: 11 // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log function works correctly\n"; // Test log2 auto log2_result = numpy::log2(values); if (!(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log2 function works correctly\n"; // Test log10 auto log10_result = numpy::log10(values); if (!(approx_equal(log10_result.getElementAt({ 0 }), std::log10(0.1), 1e-9))) { .. _example-top_level-log2-425: .. dropdown:: log2 (np_test_2_all.cpp:5593) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5583 :emphasize-lines: 11 // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log function works correctly\n"; // Test log2 auto log2_result = numpy::log2(values); if (!(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log2 function works correctly\n"; // Test log10 auto log10_result = numpy::log10(values); if (!(approx_equal(log10_result.getElementAt({ 0 }), std::log10(0.1), 1e-9))) { .. _example-top_level-log2-426: .. dropdown:: log2 (np_test_2_all.cpp:5593) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5583 :emphasize-lines: 11 // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log function works correctly\n"; // Test log2 auto log2_result = numpy::log2(values); if (!(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log2 function works correctly\n"; // Test log10 auto log10_result = numpy::log10(values); if (!(approx_equal(log10_result.getElementAt({ 0 }), std::log10(0.1), 1e-9))) { .. _example-top_level-log2-427: .. dropdown:: log2 (np_test_2_all.cpp:5593) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5583 :emphasize-lines: 11 // Test log auto log_result = numpy::log(values); if (!(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log_result.getElementAt({ 0 }), std::log(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log function works correctly\n"; // Test log2 auto log2_result = numpy::log2(values); if (!(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))) { std::string description = std::string("testExponentialLogarithmicFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(log2_result.getElementAt({ 0 }), std::log2(0.1), 1e-9))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] log2 function works correctly\n"; // Test log10 auto log10_result = numpy::log10(values); if (!(approx_equal(log10_result.getElementAt({ 0 }), std::log10(0.1), 1e-9))) { .. _example-top_level-log_complex_mkl-428: .. dropdown:: log_complex_mkl (np_test_3_all.cpp:17611) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17601 :emphasize-lines: 11 for (size_t i = 0; i < z.getSize(); ++i) { auto expected = std::exp(z.getElementAt({ i })); auto diff = std::abs(exp_result.getElementAt({ i }) - expected); if (diff > tolerance) { std::cout << " [FAIL] : exp_complex_mkl differs from std::exp at index " << i; throw std::runtime_error("exp_complex_mkl failed"); } } // Test log auto log_result = numpy::mkl_special_complex::log_complex_mkl(exp_result); for (size_t i = 0; i < z.getSize(); ++i) { auto diff = std::abs(log_result.getElementAt({ i }) - z.getElementAt({ i })); if (diff > tolerance) { std::cout << " [FAIL] : log_complex_mkl(exp(z)) != z at index " << i; throw std::runtime_error("log_complex_mkl failed"); } } #else // std::cout << " [SKIP] MKL support not compiled" << std::endl; #endif .. _example-top_level-log_complex_mkl-429: .. dropdown:: log_complex_mkl (np_test_3_all.cpp:17611) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17601 :emphasize-lines: 11 for (size_t i = 0; i < z.getSize(); ++i) { auto expected = std::exp(z.getElementAt({ i })); auto diff = std::abs(exp_result.getElementAt({ i }) - expected); if (diff > tolerance) { std::cout << " [FAIL] : exp_complex_mkl differs from std::exp at index " << i; throw std::runtime_error("exp_complex_mkl failed"); } } // Test log auto log_result = numpy::mkl_special_complex::log_complex_mkl(exp_result); for (size_t i = 0; i < z.getSize(); ++i) { auto diff = std::abs(log_result.getElementAt({ i }) - z.getElementAt({ i })); if (diff > tolerance) { std::cout << " [FAIL] : log_complex_mkl(exp(z)) != z at index " << i; throw std::runtime_error("log_complex_mkl failed"); } } #else // std::cout << " [SKIP] MKL support not compiled" << std::endl; #endif .. _example-top_level-log_inplace-430: .. dropdown:: log_inplace (np_test_2_all.cpp:1396) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1386 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { double val = 0.5 + 10.0 * static_cast(i) / test_size; test_data_d.setElementAt({ i }, val); reference_data_d.setElementAt({ i }, val); } // Get reference result auto reference_result = log(reference_data_d, MathBackend::MKL); // Test in-place operation log_inplace(test_data_d, MathBackend::MKL); // Compare results for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(test_data_d.getElementAt({ i }), reference_result.getElementAt({ i })))) { std::string description = std::string("testLogarithmInPlace():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(test_data_d.getElementAt({ i }), reference_result.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } .. _example-top_level-logaddexp-431: .. dropdown:: logaddexp (np_test_3_all.cpp:17010) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17000 :emphasize-lines: 11 numpy::NDArray a({ 3 }); a.setElementAt({ 0 }, 1.0); a.setElementAt({ 1 }, 100.0); a.setElementAt({ 2 }, -100.0); numpy::NDArray b({ 3 }); b.setElementAt({ 0 }, 2.0); b.setElementAt({ 1 }, 200.0); b.setElementAt({ 2 }, -50.0); numpy::NDArray result = numpy::logaddexp(a, b); // Verify numerical stability auto pass = true; // logaddexp(1, 2) ≈ 2.313 double expected1 = std::log(std::exp(1.0) + std::exp(2.0)); if (std::abs(result.getElementAt({ 0 }) - expected1) > 1e-10) pass = false; // logaddexp(100, 200) should return 200 (not overflow) if (std::abs(result.getElementAt({ 1 }) - 200.0) > 1e-10) pass = false; .. _example-top_level-logaddexp2-432: .. dropdown:: logaddexp2 (np_test_3_all.cpp:17047) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17037 :emphasize-lines: 11 numpy::NDArray a({ 3 }); a.setElementAt({ 0 }, 1.0); a.setElementAt({ 1 }, 100.0); a.setElementAt({ 2 }, -100.0); numpy::NDArray b({ 3 }); b.setElementAt({ 0 }, 2.0); b.setElementAt({ 1 }, 200.0); b.setElementAt({ 2 }, -50.0); numpy::NDArray result = numpy::logaddexp2(a, b); // Verify numerical stability auto pass = true; // logaddexp2(1, 2) ≈ 2.585 double expected1 = std::log2(std::exp2(1.0) + std::exp2(2.0)); if (std::abs(result.getElementAt({ 0 }) - expected1) > 1e-10) pass = false; // logaddexp2(100, 200) should return 200 (not overflow) if (std::abs(result.getElementAt({ 1 }) - 200.0) > 1e-10) pass = false; .. _example-top_level-logical_and-433: .. dropdown:: logical_and (np_test_1_all.cpp:901) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 891 :emphasize-lines: 11 a.setElementAt({0}, true); a.setElementAt({1}, false); a.setElementAt({2}, true); auto b = NDArray({3}); b.setElementAt({0}, false); b.setElementAt({1}, false); b.setElementAt({2}, true); // Test logical_and auto and_result = logical_and(a, b); bool and_0 = and_result.getElementAt({0}); if (and_0 != false) { // true && false = false std::cout << "[FAIL] in testLogicalOperations(): logical_and[0] = " << and_0 << ", expected false" << std::endl; throw std::runtime_error("testLogicalOperations(): logical_and [0] failed"); } bool and_1 = and_result.getElementAt({1}); if (and_1 != false) { // false && false = false std::cout << "[FAIL] in testLogicalOperations(): logical_and[1] = " << and_1 << ", expected false" << std::endl; throw std::runtime_error("testLogicalOperations(): logical_and [1] failed"); } .. _example-top_level-logical_and-434: .. dropdown:: logical_and (np_test_1_all.cpp:901) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 891 :emphasize-lines: 11 a.setElementAt({0}, true); a.setElementAt({1}, false); a.setElementAt({2}, true); auto b = NDArray({3}); b.setElementAt({0}, false); b.setElementAt({1}, false); b.setElementAt({2}, true); // Test logical_and auto and_result = logical_and(a, b); bool and_0 = and_result.getElementAt({0}); if (and_0 != false) { // true && false = false std::cout << "[FAIL] in testLogicalOperations(): logical_and[0] = " << and_0 << ", expected false" << std::endl; throw std::runtime_error("testLogicalOperations(): logical_and [0] failed"); } bool and_1 = and_result.getElementAt({1}); if (and_1 != false) { // false && false = false std::cout << "[FAIL] in testLogicalOperations(): logical_and[1] = " << and_1 << ", expected false" << std::endl; throw std::runtime_error("testLogicalOperations(): logical_and [1] failed"); } .. _example-top_level-logical_not-435: .. dropdown:: logical_not (np_test_1_all.cpp:939) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 929 :emphasize-lines: 11 throw std::runtime_error("testLogicalOperations(): logical_or [1] failed"); } bool or_2 = or_result.getElementAt({2}); if (or_2 != true) { // true || true = true std::cout << "[FAIL] in testLogicalOperations(): logical_or[2] = " << or_2 << ", expected true" << std::endl; throw std::runtime_error("testLogicalOperations(): logical_or [2] failed"); } // std::cout << "[OK] logical_or function"; // Test logical_not auto not_result = logical_not(a); bool not_0 = not_result.getElementAt({0}); if (not_0 != false) { // !true = false std::cout << "[FAIL] in testLogicalOperations(): logical_not[0] = " << not_0 << ", expected false" << std::endl; throw std::runtime_error("testLogicalOperations(): logical_not [0] failed"); } bool not_1 = not_result.getElementAt({1}); if (not_1 != true) { // !false = true std::cout << "[FAIL] in testLogicalOperations(): logical_not[1] = " << not_1 << ", expected true" << std::endl; throw std::runtime_error("testLogicalOperations(): logical_not [1] failed"); } .. _example-top_level-logical_or-436: .. dropdown:: logical_or (np_test_1_all.cpp:920) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 910 :emphasize-lines: 11 throw std::runtime_error("testLogicalOperations(): logical_and [1] failed"); } bool and_2 = and_result.getElementAt({2}); if (and_2 != true) { // true && true = true std::cout << "[FAIL] in testLogicalOperations(): logical_and[2] = " << and_2 << ", expected true" << std::endl; throw std::runtime_error("testLogicalOperations(): logical_and [2] failed"); } // std::cout << "[OK] logical_and function"; // Test logical_or auto or_result = logical_or(a, b); bool or_0 = or_result.getElementAt({0}); if (or_0 != true) { // true || false = true std::cout << "[FAIL] in testLogicalOperations(): logical_or[0] = " << or_0 << ", expected true" << std::endl; throw std::runtime_error("testLogicalOperations(): logical_or [0] failed"); } bool or_1 = or_result.getElementAt({1}); if (or_1 != false) { // false || false = false std::cout << "[FAIL] in testLogicalOperations(): logical_or[1] = " << or_1 << ", expected false" << std::endl; throw std::runtime_error("testLogicalOperations(): logical_or [1] failed"); } .. _example-top_level-logical_or-437: .. dropdown:: logical_or (np_test_1_all.cpp:920) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 910 :emphasize-lines: 11 throw std::runtime_error("testLogicalOperations(): logical_and [1] failed"); } bool and_2 = and_result.getElementAt({2}); if (and_2 != true) { // true && true = true std::cout << "[FAIL] in testLogicalOperations(): logical_and[2] = " << and_2 << ", expected true" << std::endl; throw std::runtime_error("testLogicalOperations(): logical_and [2] failed"); } // std::cout << "[OK] logical_and function"; // Test logical_or auto or_result = logical_or(a, b); bool or_0 = or_result.getElementAt({0}); if (or_0 != true) { // true || false = true std::cout << "[FAIL] in testLogicalOperations(): logical_or[0] = " << or_0 << ", expected true" << std::endl; throw std::runtime_error("testLogicalOperations(): logical_or [0] failed"); } bool or_1 = or_result.getElementAt({1}); if (or_1 != false) { // false || false = false std::cout << "[FAIL] in testLogicalOperations(): logical_or[1] = " << or_1 << ", expected false" << std::endl; throw std::runtime_error("testLogicalOperations(): logical_or [1] failed"); } .. _example-top_level-mod-438: .. dropdown:: mod (np_test_1_all.cpp:21258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21248 :emphasize-lines: 11 a.setElementAt({ 1 }, -7); a.setElementAt({ 2 }, 7); a.setElementAt({ 3 }, -7); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3); b.setElementAt({ 1 }, 3); b.setElementAt({ 2 }, -3); b.setElementAt({ 3 }, -3); auto result = mod(a, b); if (!(result.getElementAt({ 0 }) == 1)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-mod-439: .. dropdown:: mod (np_test_1_all.cpp:21258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21248 :emphasize-lines: 11 a.setElementAt({ 1 }, -7); a.setElementAt({ 2 }, 7); a.setElementAt({ 3 }, -7); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3); b.setElementAt({ 1 }, 3); b.setElementAt({ 2 }, -3); b.setElementAt({ 3 }, -3); auto result = mod(a, b); if (!(result.getElementAt({ 0 }) == 1)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-mod-440: .. dropdown:: mod (np_test_1_all.cpp:21258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21248 :emphasize-lines: 11 a.setElementAt({ 1 }, -7); a.setElementAt({ 2 }, 7); a.setElementAt({ 3 }, -7); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3); b.setElementAt({ 1 }, 3); b.setElementAt({ 2 }, -3); b.setElementAt({ 3 }, -3); auto result = mod(a, b); if (!(result.getElementAt({ 0 }) == 1)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-mod-441: .. dropdown:: mod (np_test_1_all.cpp:21258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21248 :emphasize-lines: 11 a.setElementAt({ 1 }, -7); a.setElementAt({ 2 }, 7); a.setElementAt({ 3 }, -7); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3); b.setElementAt({ 1 }, 3); b.setElementAt({ 2 }, -3); b.setElementAt({ 3 }, -3); auto result = mod(a, b); if (!(result.getElementAt({ 0 }) == 1)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-mod-442: .. dropdown:: mod (np_test_1_all.cpp:21258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21248 :emphasize-lines: 11 a.setElementAt({ 1 }, -7); a.setElementAt({ 2 }, 7); a.setElementAt({ 3 }, -7); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3); b.setElementAt({ 1 }, 3); b.setElementAt({ 2 }, -3); b.setElementAt({ 3 }, -3); auto result = mod(a, b); if (!(result.getElementAt({ 0 }) == 1)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-mod-443: .. dropdown:: mod (np_test_1_all.cpp:21258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21248 :emphasize-lines: 11 a.setElementAt({ 1 }, -7); a.setElementAt({ 2 }, 7); a.setElementAt({ 3 }, -7); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3); b.setElementAt({ 1 }, 3); b.setElementAt({ 2 }, -3); b.setElementAt({ 3 }, -3); auto result = mod(a, b); if (!(result.getElementAt({ 0 }) == 1)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-mod-444: .. dropdown:: mod (np_test_1_all.cpp:21258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21248 :emphasize-lines: 11 a.setElementAt({ 1 }, -7); a.setElementAt({ 2 }, 7); a.setElementAt({ 3 }, -7); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3); b.setElementAt({ 1 }, 3); b.setElementAt({ 2 }, -3); b.setElementAt({ 3 }, -3); auto result = mod(a, b); if (!(result.getElementAt({ 0 }) == 1)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-mod-445: .. dropdown:: mod (np_test_1_all.cpp:21258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21248 :emphasize-lines: 11 a.setElementAt({ 1 }, -7); a.setElementAt({ 2 }, 7); a.setElementAt({ 3 }, -7); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3); b.setElementAt({ 1 }, 3); b.setElementAt({ 2 }, -3); b.setElementAt({ 3 }, -3); auto result = mod(a, b); if (!(result.getElementAt({ 0 }) == 1)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-mod-446: .. dropdown:: mod (np_test_1_all.cpp:21258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21248 :emphasize-lines: 11 a.setElementAt({ 1 }, -7); a.setElementAt({ 2 }, 7); a.setElementAt({ 3 }, -7); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3); b.setElementAt({ 1 }, 3); b.setElementAt({ 2 }, -3); b.setElementAt({ 3 }, -3); auto result = mod(a, b); if (!(result.getElementAt({ 0 }) == 1)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-mod-447: .. dropdown:: mod (np_test_1_all.cpp:21258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21248 :emphasize-lines: 11 a.setElementAt({ 1 }, -7); a.setElementAt({ 2 }, 7); a.setElementAt({ 3 }, -7); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3); b.setElementAt({ 1 }, 3); b.setElementAt({ 2 }, -3); b.setElementAt({ 3 }, -3); auto result = mod(a, b); if (!(result.getElementAt({ 0 }) == 1)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-mod-448: .. dropdown:: mod (np_test_1_all.cpp:21258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21248 :emphasize-lines: 11 a.setElementAt({ 1 }, -7); a.setElementAt({ 2 }, 7); a.setElementAt({ 3 }, -7); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3); b.setElementAt({ 1 }, 3); b.setElementAt({ 2 }, -3); b.setElementAt({ 3 }, -3); auto result = mod(a, b); if (!(result.getElementAt({ 0 }) == 1)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-mod-449: .. dropdown:: mod (np_test_1_all.cpp:21258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21248 :emphasize-lines: 11 a.setElementAt({ 1 }, -7); a.setElementAt({ 2 }, 7); a.setElementAt({ 3 }, -7); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3); b.setElementAt({ 1 }, 3); b.setElementAt({ 2 }, -3); b.setElementAt({ 3 }, -3); auto result = mod(a, b); if (!(result.getElementAt({ 0 }) == 1)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-mod-450: .. dropdown:: mod (np_test_1_all.cpp:21258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21248 :emphasize-lines: 11 a.setElementAt({ 1 }, -7); a.setElementAt({ 2 }, 7); a.setElementAt({ 3 }, -7); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3); b.setElementAt({ 1 }, 3); b.setElementAt({ 2 }, -3); b.setElementAt({ 3 }, -3); auto result = mod(a, b); if (!(result.getElementAt({ 0 }) == 1)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2)) { std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-modf-451: .. dropdown:: modf (np_test_1_all.cpp:21076) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21066 :emphasize-lines: 11 void testModfFunction() { std::cout << "========= testModfFunction ===="; // Test modf function auto arr = NDArray({ 4 }); arr.setElementAt({ 0 }, 1.5); arr.setElementAt({ 1 }, -2.3); arr.setElementAt({ 2 }, 3.0); arr.setElementAt({ 3 }, -4.0); auto [frac, integer] = modf(arr); if (!(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(integer.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(integer.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-modf-452: .. dropdown:: modf (np_test_1_all.cpp:21076) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21066 :emphasize-lines: 11 void testModfFunction() { std::cout << "========= testModfFunction ===="; // Test modf function auto arr = NDArray({ 4 }); arr.setElementAt({ 0 }, 1.5); arr.setElementAt({ 1 }, -2.3); arr.setElementAt({ 2 }, 3.0); arr.setElementAt({ 3 }, -4.0); auto [frac, integer] = modf(arr); if (!(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(integer.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(integer.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-modf-453: .. dropdown:: modf (np_test_1_all.cpp:21076) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21066 :emphasize-lines: 11 void testModfFunction() { std::cout << "========= testModfFunction ===="; // Test modf function auto arr = NDArray({ 4 }); arr.setElementAt({ 0 }, 1.5); arr.setElementAt({ 1 }, -2.3); arr.setElementAt({ 2 }, 3.0); arr.setElementAt({ 3 }, -4.0); auto [frac, integer] = modf(arr); if (!(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(integer.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(integer.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-modf-454: .. dropdown:: modf (np_test_1_all.cpp:21076) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21066 :emphasize-lines: 11 void testModfFunction() { std::cout << "========= testModfFunction ===="; // Test modf function auto arr = NDArray({ 4 }); arr.setElementAt({ 0 }, 1.5); arr.setElementAt({ 1 }, -2.3); arr.setElementAt({ 2 }, 3.0); arr.setElementAt({ 3 }, -4.0); auto [frac, integer] = modf(arr); if (!(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(integer.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(integer.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-modf-455: .. dropdown:: modf (np_test_1_all.cpp:21076) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21066 :emphasize-lines: 11 void testModfFunction() { std::cout << "========= testModfFunction ===="; // Test modf function auto arr = NDArray({ 4 }); arr.setElementAt({ 0 }, 1.5); arr.setElementAt({ 1 }, -2.3); arr.setElementAt({ 2 }, 3.0); arr.setElementAt({ 3 }, -4.0); auto [frac, integer] = modf(arr); if (!(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(integer.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(integer.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-modf-456: .. dropdown:: modf (np_test_1_all.cpp:21076) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21066 :emphasize-lines: 11 void testModfFunction() { std::cout << "========= testModfFunction ===="; // Test modf function auto arr = NDArray({ 4 }); arr.setElementAt({ 0 }, 1.5); arr.setElementAt({ 1 }, -2.3); arr.setElementAt({ 2 }, 3.0); arr.setElementAt({ 3 }, -4.0); auto [frac, integer] = modf(arr); if (!(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(integer.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(integer.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-modf-457: .. dropdown:: modf (np_test_1_all.cpp:21076) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21066 :emphasize-lines: 11 void testModfFunction() { std::cout << "========= testModfFunction ===="; // Test modf function auto arr = NDArray({ 4 }); arr.setElementAt({ 0 }, 1.5); arr.setElementAt({ 1 }, -2.3); arr.setElementAt({ 2 }, 3.0); arr.setElementAt({ 3 }, -4.0); auto [frac, integer] = modf(arr); if (!(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(integer.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(integer.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-modf-458: .. dropdown:: modf (np_test_1_all.cpp:21076) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21066 :emphasize-lines: 11 void testModfFunction() { std::cout << "========= testModfFunction ===="; // Test modf function auto arr = NDArray({ 4 }); arr.setElementAt({ 0 }, 1.5); arr.setElementAt({ 1 }, -2.3); arr.setElementAt({ 2 }, 3.0); arr.setElementAt({ 3 }, -4.0); auto [frac, integer] = modf(arr); if (!(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(integer.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(integer.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-modf-459: .. dropdown:: modf (np_test_1_all.cpp:21076) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21066 :emphasize-lines: 11 void testModfFunction() { std::cout << "========= testModfFunction ===="; // Test modf function auto arr = NDArray({ 4 }); arr.setElementAt({ 0 }, 1.5); arr.setElementAt({ 1 }, -2.3); arr.setElementAt({ 2 }, 3.0); arr.setElementAt({ 3 }, -4.0); auto [frac, integer] = modf(arr); if (!(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(integer.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(integer.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-modf-460: .. dropdown:: modf (np_test_1_all.cpp:21076) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21066 :emphasize-lines: 11 void testModfFunction() { std::cout << "========= testModfFunction ===="; // Test modf function auto arr = NDArray({ 4 }); arr.setElementAt({ 0 }, 1.5); arr.setElementAt({ 1 }, -2.3); arr.setElementAt({ 2 }, 3.0); arr.setElementAt({ 3 }, -4.0); auto [frac, integer] = modf(arr); if (!(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(integer.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(integer.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-modf-461: .. dropdown:: modf (np_test_1_all.cpp:21076) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21066 :emphasize-lines: 11 void testModfFunction() { std::cout << "========= testModfFunction ===="; // Test modf function auto arr = NDArray({ 4 }); arr.setElementAt({ 0 }, 1.5); arr.setElementAt({ 1 }, -2.3); arr.setElementAt({ 2 }, 3.0); arr.setElementAt({ 3 }, -4.0); auto [frac, integer] = modf(arr); if (!(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(frac.getElementAt({ 0 }) - 0.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(integer.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testModfFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(integer.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-multiply-462: .. dropdown:: multiply (np_test_1_all.cpp:6426) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6416 :emphasize-lines: 11 // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; } // Test string multiplication std::vector patterns = {"Ha", "Ho", "Hi"}; auto pattern_arr = array<32>(patterns); auto repeated = multiply(pattern_arr, 3); // std::cout << "String multiplication:" << std::endl; for (size_t i = 0; i < repeated.size(); ++i) { // std::cout << "'" << pattern_arr[i] << "' * 3 = '" << repeated[i] << "'"; } std::cout << " -> tests passed" << std::endl; } void testCaseConversionsCharArray() { std::cout << "========= testCaseConversions ======================="; .. _example-top_level-multiply-463: .. dropdown:: multiply (np_test_1_all.cpp:6426) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6416 :emphasize-lines: 11 // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; } // Test string multiplication std::vector patterns = {"Ha", "Ho", "Hi"}; auto pattern_arr = array<32>(patterns); auto repeated = multiply(pattern_arr, 3); // std::cout << "String multiplication:" << std::endl; for (size_t i = 0; i < repeated.size(); ++i) { // std::cout << "'" << pattern_arr[i] << "' * 3 = '" << repeated[i] << "'"; } std::cout << " -> tests passed" << std::endl; } void testCaseConversionsCharArray() { std::cout << "========= testCaseConversions ======================="; .. _example-top_level-multiply-464: .. dropdown:: multiply (np_test_1_all.cpp:6426) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6416 :emphasize-lines: 11 // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; } // Test string multiplication std::vector patterns = {"Ha", "Ho", "Hi"}; auto pattern_arr = array<32>(patterns); auto repeated = multiply(pattern_arr, 3); // std::cout << "String multiplication:" << std::endl; for (size_t i = 0; i < repeated.size(); ++i) { // std::cout << "'" << pattern_arr[i] << "' * 3 = '" << repeated[i] << "'"; } std::cout << " -> tests passed" << std::endl; } void testCaseConversionsCharArray() { std::cout << "========= testCaseConversions ======================="; .. _example-top_level-multiply-465: .. dropdown:: multiply (np_test_1_all.cpp:6426) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6416 :emphasize-lines: 11 // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; } // Test string multiplication std::vector patterns = {"Ha", "Ho", "Hi"}; auto pattern_arr = array<32>(patterns); auto repeated = multiply(pattern_arr, 3); // std::cout << "String multiplication:" << std::endl; for (size_t i = 0; i < repeated.size(); ++i) { // std::cout << "'" << pattern_arr[i] << "' * 3 = '" << repeated[i] << "'"; } std::cout << " -> tests passed" << std::endl; } void testCaseConversionsCharArray() { std::cout << "========= testCaseConversions ======================="; .. _example-top_level-multiply-466: .. dropdown:: multiply (np_test_1_all.cpp:6426) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6416 :emphasize-lines: 11 // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; } // Test string multiplication std::vector patterns = {"Ha", "Ho", "Hi"}; auto pattern_arr = array<32>(patterns); auto repeated = multiply(pattern_arr, 3); // std::cout << "String multiplication:" << std::endl; for (size_t i = 0; i < repeated.size(); ++i) { // std::cout << "'" << pattern_arr[i] << "' * 3 = '" << repeated[i] << "'"; } std::cout << " -> tests passed" << std::endl; } void testCaseConversionsCharArray() { std::cout << "========= testCaseConversions ======================="; .. _example-top_level-multiply-467: .. dropdown:: multiply (np_test_1_all.cpp:6426) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6416 :emphasize-lines: 11 // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; } // Test string multiplication std::vector patterns = {"Ha", "Ho", "Hi"}; auto pattern_arr = array<32>(patterns); auto repeated = multiply(pattern_arr, 3); // std::cout << "String multiplication:" << std::endl; for (size_t i = 0; i < repeated.size(); ++i) { // std::cout << "'" << pattern_arr[i] << "' * 3 = '" << repeated[i] << "'"; } std::cout << " -> tests passed" << std::endl; } void testCaseConversionsCharArray() { std::cout << "========= testCaseConversions ======================="; .. _example-top_level-multiply-468: .. dropdown:: multiply (np_test_1_all.cpp:6426) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6416 :emphasize-lines: 11 // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; } // Test string multiplication std::vector patterns = {"Ha", "Ho", "Hi"}; auto pattern_arr = array<32>(patterns); auto repeated = multiply(pattern_arr, 3); // std::cout << "String multiplication:" << std::endl; for (size_t i = 0; i < repeated.size(); ++i) { // std::cout << "'" << pattern_arr[i] << "' * 3 = '" << repeated[i] << "'"; } std::cout << " -> tests passed" << std::endl; } void testCaseConversionsCharArray() { std::cout << "========= testCaseConversions ======================="; .. _example-top_level-multiply-469: .. dropdown:: multiply (np_test_1_all.cpp:6426) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6416 :emphasize-lines: 11 // Test scalar addition auto scalar_result = add(arr1, "!"); // std::cout << "Scalar concatenation:" << std::endl; for (size_t i = 0; i < scalar_result.size(); ++i) { // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'"; } // Test string multiplication std::vector patterns = {"Ha", "Ho", "Hi"}; auto pattern_arr = array<32>(patterns); auto repeated = multiply(pattern_arr, 3); // std::cout << "String multiplication:" << std::endl; for (size_t i = 0; i < repeated.size(); ++i) { // std::cout << "'" << pattern_arr[i] << "' * 3 = '" << repeated[i] << "'"; } std::cout << " -> tests passed" << std::endl; } void testCaseConversionsCharArray() { std::cout << "========= testCaseConversions ======================="; .. _example-top_level-negative-470: .. dropdown:: negative (np_test_1_all.cpp:23415) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23405 :emphasize-lines: 11 if (poisson_default.getSize() != 1) { throw std::runtime_error("Poisson default generation failed"); } // Test poisson with custom parameters auto poisson_custom = poisson(5.0, { {3, 2} }); if (poisson_custom.getShape() != std::vector({ 3, 2 })) { throw std::runtime_error("Poisson custom generation failed"); } // Check values are non-negative (Poisson property) for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 2; ++j) { int val = poisson_custom.getElementAt({ i, j }); if (val < 0) { throw std::runtime_error("Poisson value should be non-negative: " + std::to_string(val)); } } } std::cout << " -> tests passed" << std::endl; .. _example-top_level-negative-471: .. dropdown:: negative (np_test_1_all.cpp:23415) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23405 :emphasize-lines: 11 if (poisson_default.getSize() != 1) { throw std::runtime_error("Poisson default generation failed"); } // Test poisson with custom parameters auto poisson_custom = poisson(5.0, { {3, 2} }); if (poisson_custom.getShape() != std::vector({ 3, 2 })) { throw std::runtime_error("Poisson custom generation failed"); } // Check values are non-negative (Poisson property) for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 2; ++j) { int val = poisson_custom.getElementAt({ i, j }); if (val < 0) { throw std::runtime_error("Poisson value should be non-negative: " + std::to_string(val)); } } } std::cout << " -> tests passed" << std::endl; .. _example-top_level-negative-472: .. dropdown:: negative (np_test_1_all.cpp:23415) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23405 :emphasize-lines: 11 if (poisson_default.getSize() != 1) { throw std::runtime_error("Poisson default generation failed"); } // Test poisson with custom parameters auto poisson_custom = poisson(5.0, { {3, 2} }); if (poisson_custom.getShape() != std::vector({ 3, 2 })) { throw std::runtime_error("Poisson custom generation failed"); } // Check values are non-negative (Poisson property) for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 2; ++j) { int val = poisson_custom.getElementAt({ i, j }); if (val < 0) { throw std::runtime_error("Poisson value should be non-negative: " + std::to_string(val)); } } } std::cout << " -> tests passed" << std::endl; .. _example-top_level-negative-473: .. dropdown:: negative (np_test_1_all.cpp:23415) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23405 :emphasize-lines: 11 if (poisson_default.getSize() != 1) { throw std::runtime_error("Poisson default generation failed"); } // Test poisson with custom parameters auto poisson_custom = poisson(5.0, { {3, 2} }); if (poisson_custom.getShape() != std::vector({ 3, 2 })) { throw std::runtime_error("Poisson custom generation failed"); } // Check values are non-negative (Poisson property) for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 2; ++j) { int val = poisson_custom.getElementAt({ i, j }); if (val < 0) { throw std::runtime_error("Poisson value should be non-negative: " + std::to_string(val)); } } } std::cout << " -> tests passed" << std::endl; .. _example-top_level-negative-474: .. dropdown:: negative (np_test_1_all.cpp:23415) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23405 :emphasize-lines: 11 if (poisson_default.getSize() != 1) { throw std::runtime_error("Poisson default generation failed"); } // Test poisson with custom parameters auto poisson_custom = poisson(5.0, { {3, 2} }); if (poisson_custom.getShape() != std::vector({ 3, 2 })) { throw std::runtime_error("Poisson custom generation failed"); } // Check values are non-negative (Poisson property) for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 2; ++j) { int val = poisson_custom.getElementAt({ i, j }); if (val < 0) { throw std::runtime_error("Poisson value should be non-negative: " + std::to_string(val)); } } } std::cout << " -> tests passed" << std::endl; .. _example-top_level-negative-475: .. dropdown:: negative (np_test_1_all.cpp:23415) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23405 :emphasize-lines: 11 if (poisson_default.getSize() != 1) { throw std::runtime_error("Poisson default generation failed"); } // Test poisson with custom parameters auto poisson_custom = poisson(5.0, { {3, 2} }); if (poisson_custom.getShape() != std::vector({ 3, 2 })) { throw std::runtime_error("Poisson custom generation failed"); } // Check values are non-negative (Poisson property) for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 2; ++j) { int val = poisson_custom.getElementAt({ i, j }); if (val < 0) { throw std::runtime_error("Poisson value should be non-negative: " + std::to_string(val)); } } } std::cout << " -> tests passed" << std::endl; .. _example-top_level-negative-476: .. dropdown:: negative (np_test_1_all.cpp:23415) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23405 :emphasize-lines: 11 if (poisson_default.getSize() != 1) { throw std::runtime_error("Poisson default generation failed"); } // Test poisson with custom parameters auto poisson_custom = poisson(5.0, { {3, 2} }); if (poisson_custom.getShape() != std::vector({ 3, 2 })) { throw std::runtime_error("Poisson custom generation failed"); } // Check values are non-negative (Poisson property) for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 2; ++j) { int val = poisson_custom.getElementAt({ i, j }); if (val < 0) { throw std::runtime_error("Poisson value should be non-negative: " + std::to_string(val)); } } } std::cout << " -> tests passed" << std::endl; .. _example-top_level-negative-477: .. dropdown:: negative (np_test_1_all.cpp:23415) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23405 :emphasize-lines: 11 if (poisson_default.getSize() != 1) { throw std::runtime_error("Poisson default generation failed"); } // Test poisson with custom parameters auto poisson_custom = poisson(5.0, { {3, 2} }); if (poisson_custom.getShape() != std::vector({ 3, 2 })) { throw std::runtime_error("Poisson custom generation failed"); } // Check values are non-negative (Poisson property) for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 2; ++j) { int val = poisson_custom.getElementAt({ i, j }); if (val < 0) { throw std::runtime_error("Poisson value should be non-negative: " + std::to_string(val)); } } } std::cout << " -> tests passed" << std::endl; .. _example-top_level-negative-478: .. dropdown:: negative (np_test_1_all.cpp:23415) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23405 :emphasize-lines: 11 if (poisson_default.getSize() != 1) { throw std::runtime_error("Poisson default generation failed"); } // Test poisson with custom parameters auto poisson_custom = poisson(5.0, { {3, 2} }); if (poisson_custom.getShape() != std::vector({ 3, 2 })) { throw std::runtime_error("Poisson custom generation failed"); } // Check values are non-negative (Poisson property) for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 2; ++j) { int val = poisson_custom.getElementAt({ i, j }); if (val < 0) { throw std::runtime_error("Poisson value should be non-negative: " + std::to_string(val)); } } } std::cout << " -> tests passed" << std::endl; .. _example-top_level-negative-479: .. dropdown:: negative (np_test_1_all.cpp:23415) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23405 :emphasize-lines: 11 if (poisson_default.getSize() != 1) { throw std::runtime_error("Poisson default generation failed"); } // Test poisson with custom parameters auto poisson_custom = poisson(5.0, { {3, 2} }); if (poisson_custom.getShape() != std::vector({ 3, 2 })) { throw std::runtime_error("Poisson custom generation failed"); } // Check values are non-negative (Poisson property) for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 2; ++j) { int val = poisson_custom.getElementAt({ i, j }); if (val < 0) { throw std::runtime_error("Poisson value should be non-negative: " + std::to_string(val)); } } } std::cout << " -> tests passed" << std::endl; .. _example-top_level-negative-480: .. dropdown:: negative (np_test_1_all.cpp:23415) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23405 :emphasize-lines: 11 if (poisson_default.getSize() != 1) { throw std::runtime_error("Poisson default generation failed"); } // Test poisson with custom parameters auto poisson_custom = poisson(5.0, { {3, 2} }); if (poisson_custom.getShape() != std::vector({ 3, 2 })) { throw std::runtime_error("Poisson custom generation failed"); } // Check values are non-negative (Poisson property) for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 2; ++j) { int val = poisson_custom.getElementAt({ i, j }); if (val < 0) { throw std::runtime_error("Poisson value should be non-negative: " + std::to_string(val)); } } } std::cout << " -> tests passed" << std::endl; .. _example-top_level-negative-481: .. dropdown:: negative (np_test_1_all.cpp:23415) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23405 :emphasize-lines: 11 if (poisson_default.getSize() != 1) { throw std::runtime_error("Poisson default generation failed"); } // Test poisson with custom parameters auto poisson_custom = poisson(5.0, { {3, 2} }); if (poisson_custom.getShape() != std::vector({ 3, 2 })) { throw std::runtime_error("Poisson custom generation failed"); } // Check values are non-negative (Poisson property) for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 2; ++j) { int val = poisson_custom.getElementAt({ i, j }); if (val < 0) { throw std::runtime_error("Poisson value should be non-negative: " + std::to_string(val)); } } } std::cout << " -> tests passed" << std::endl; .. _example-top_level-negative-482: .. dropdown:: negative (np_test_1_all.cpp:23415) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23405 :emphasize-lines: 11 if (poisson_default.getSize() != 1) { throw std::runtime_error("Poisson default generation failed"); } // Test poisson with custom parameters auto poisson_custom = poisson(5.0, { {3, 2} }); if (poisson_custom.getShape() != std::vector({ 3, 2 })) { throw std::runtime_error("Poisson custom generation failed"); } // Check values are non-negative (Poisson property) for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 2; ++j) { int val = poisson_custom.getElementAt({ i, j }); if (val < 0) { throw std::runtime_error("Poisson value should be non-negative: " + std::to_string(val)); } } } std::cout << " -> tests passed" << std::endl; .. _example-top_level-positive-483: .. dropdown:: positive (np_test_2_all.cpp:1601) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1591 :emphasize-lines: 11 void testExponentialEdgeCases() { std::cout << "========= testExponentialEdgeCases ===="; // Test special floating-point values NDArray special_cases({ 8 }); special_cases.setElementAt({ 0 }, 0.0); special_cases.setElementAt({ 1 }, std::numeric_limits::infinity()); special_cases.setElementAt({ 2 }, -std::numeric_limits::infinity()); special_cases.setElementAt({ 3 }, std::numeric_limits::quiet_NaN()); special_cases.setElementAt({ 4 }, 700.0); // Large positive (near overflow) special_cases.setElementAt({ 5 }, -700.0); // Large negative (near underflow) special_cases.setElementAt({ 6 }, std::numeric_limits::min()); special_cases.setElementAt({ 7 }, std::numeric_limits::max() / 1e100); auto std_exp_result = exp(special_cases, MathBackend::DEFAULT); auto mkl_exp_result = exp(special_cases, MathBackend::MKL); // Check that both implementations handle special cases consistently for (size_t i = 0; i < 8; ++i) { double std_val = std_exp_result.getElementAt({ i }); .. _example-top_level-positive-484: .. dropdown:: positive (np_test_2_all.cpp:1601) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1591 :emphasize-lines: 11 void testExponentialEdgeCases() { std::cout << "========= testExponentialEdgeCases ===="; // Test special floating-point values NDArray special_cases({ 8 }); special_cases.setElementAt({ 0 }, 0.0); special_cases.setElementAt({ 1 }, std::numeric_limits::infinity()); special_cases.setElementAt({ 2 }, -std::numeric_limits::infinity()); special_cases.setElementAt({ 3 }, std::numeric_limits::quiet_NaN()); special_cases.setElementAt({ 4 }, 700.0); // Large positive (near overflow) special_cases.setElementAt({ 5 }, -700.0); // Large negative (near underflow) special_cases.setElementAt({ 6 }, std::numeric_limits::min()); special_cases.setElementAt({ 7 }, std::numeric_limits::max() / 1e100); auto std_exp_result = exp(special_cases, MathBackend::DEFAULT); auto mkl_exp_result = exp(special_cases, MathBackend::MKL); // Check that both implementations handle special cases consistently for (size_t i = 0; i < 8; ++i) { double std_val = std_exp_result.getElementAt({ i }); .. _example-top_level-positive-485: .. dropdown:: positive (np_test_2_all.cpp:1601) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1591 :emphasize-lines: 11 void testExponentialEdgeCases() { std::cout << "========= testExponentialEdgeCases ===="; // Test special floating-point values NDArray special_cases({ 8 }); special_cases.setElementAt({ 0 }, 0.0); special_cases.setElementAt({ 1 }, std::numeric_limits::infinity()); special_cases.setElementAt({ 2 }, -std::numeric_limits::infinity()); special_cases.setElementAt({ 3 }, std::numeric_limits::quiet_NaN()); special_cases.setElementAt({ 4 }, 700.0); // Large positive (near overflow) special_cases.setElementAt({ 5 }, -700.0); // Large negative (near underflow) special_cases.setElementAt({ 6 }, std::numeric_limits::min()); special_cases.setElementAt({ 7 }, std::numeric_limits::max() / 1e100); auto std_exp_result = exp(special_cases, MathBackend::DEFAULT); auto mkl_exp_result = exp(special_cases, MathBackend::MKL); // Check that both implementations handle special cases consistently for (size_t i = 0; i < 8; ++i) { double std_val = std_exp_result.getElementAt({ i }); .. _example-top_level-power-486: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-487: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-488: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-489: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-490: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-491: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-492: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-493: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-494: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-495: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-496: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-497: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-498: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-499: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-500: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-501: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-502: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-503: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-504: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-505: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-506: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-507: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-508: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-509: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-510: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-511: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-512: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-513: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-514: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-515: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-516: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-517: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-518: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-519: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-520: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-521: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-522: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-523: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-524: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-525: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-526: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-527: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-528: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-529: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-530: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-531: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-532: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-533: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-534: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-535: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-536: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-537: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-538: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-539: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power-540: .. dropdown:: power (np_test_1_all.cpp:23257) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23247 :emphasize-lines: 11 // std::cout << "[OK] Laguerre polynomials work correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_advanced() { std::cout << "========= test_polynomial_advanced ======================="; // Test polynomial power numpy::Polynomial p({ 1, 1 }); // 1 + x auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); .. _example-top_level-power_iteration-541: .. dropdown:: power_iteration (np_test_3_all.cpp:3696) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3686 :emphasize-lines: 11 NDArray matrix({ 2, 2 }); matrix.setElementAt({ 0, 0 }, 3.0); matrix.setElementAt({ 0, 1 }, 1.0); matrix.setElementAt({ 1, 0 }, 0.0); matrix.setElementAt({ 1, 1 }, 2.0); // std::cout << "Test matrix:" << std::endl; //matrix.printArray(); // Apply power iteration auto eigen_result = power_iteration(matrix, 1000, 1e-10); // std::cout << "Converged: " << (eigen_result.converged ? "Yes" : "No") << std::endl; // std::cout << "Iterations: " << eigen_result.iterations << std::endl; // std::cout << "Dominant eigenvalue: " << eigen_result.eigenvalues.getElementAt({ 0 }) << std::endl; // std::cout << "Corresponding eigenvector:" << std::endl; //eigen_result.eigenvectors.printArray(); // Verify result (eigenvalue should be close to 3.0) double lambda = eigen_result.eigenvalues.getElementAt({ 0 }); .. _example-top_level-rad2deg-542: .. dropdown:: rad2deg (np_test_1_all.cpp:23786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23776 :emphasize-lines: 11 if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-rad2deg-543: .. dropdown:: rad2deg (np_test_1_all.cpp:23786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23776 :emphasize-lines: 11 if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-rad2deg-544: .. dropdown:: rad2deg (np_test_1_all.cpp:23786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23776 :emphasize-lines: 11 if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-rad2deg-545: .. dropdown:: rad2deg (np_test_1_all.cpp:23786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23776 :emphasize-lines: 11 if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-rad2deg-546: .. dropdown:: rad2deg (np_test_1_all.cpp:23786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23776 :emphasize-lines: 11 if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-rad2deg-547: .. dropdown:: rad2deg (np_test_1_all.cpp:23786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23776 :emphasize-lines: 11 if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-rad2deg-548: .. dropdown:: rad2deg (np_test_1_all.cpp:23786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23776 :emphasize-lines: 11 if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-rad2deg-549: .. dropdown:: rad2deg (np_test_1_all.cpp:23786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23776 :emphasize-lines: 11 if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-rad2deg-550: .. dropdown:: rad2deg (np_test_1_all.cpp:23786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23776 :emphasize-lines: 11 if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-rad2deg-551: .. dropdown:: rad2deg (np_test_1_all.cpp:23786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23776 :emphasize-lines: 11 if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-rad2deg-552: .. dropdown:: rad2deg (np_test_1_all.cpp:23786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23776 :emphasize-lines: 11 if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-rad2deg-553: .. dropdown:: rad2deg (np_test_1_all.cpp:23786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23776 :emphasize-lines: 11 if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-rad2deg-554: .. dropdown:: rad2deg (np_test_1_all.cpp:23786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23776 :emphasize-lines: 11 if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-radians-555: .. dropdown:: radians (np_test_4_all.cpp:12020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12010 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(π+0i rad) → 180+0i° (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray radians({5}); radians.setElementAt({0}, 0); radians.setElementAt({1}, 1); radians.setElementAt({2}, 2); radians.setElementAt({3}, 3); radians.setElementAt({4}, 6); auto result = numpy::degrees(radians); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-radians-556: .. dropdown:: radians (np_test_4_all.cpp:12020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12010 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(π+0i rad) → 180+0i° (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray radians({5}); radians.setElementAt({0}, 0); radians.setElementAt({1}, 1); radians.setElementAt({2}, 2); radians.setElementAt({3}, 3); radians.setElementAt({4}, 6); auto result = numpy::degrees(radians); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-radians-557: .. dropdown:: radians (np_test_4_all.cpp:12020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12010 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(π+0i rad) → 180+0i° (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray radians({5}); radians.setElementAt({0}, 0); radians.setElementAt({1}, 1); radians.setElementAt({2}, 2); radians.setElementAt({3}, 3); radians.setElementAt({4}, 6); auto result = numpy::degrees(radians); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-radians-558: .. dropdown:: radians (np_test_4_all.cpp:12020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12010 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(π+0i rad) → 180+0i° (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray radians({5}); radians.setElementAt({0}, 0); radians.setElementAt({1}, 1); radians.setElementAt({2}, 2); radians.setElementAt({3}, 3); radians.setElementAt({4}, 6); auto result = numpy::degrees(radians); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-radians-559: .. dropdown:: radians (np_test_4_all.cpp:12020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12010 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(π+0i rad) → 180+0i° (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray radians({5}); radians.setElementAt({0}, 0); radians.setElementAt({1}, 1); radians.setElementAt({2}, 2); radians.setElementAt({3}, 3); radians.setElementAt({4}, 6); auto result = numpy::degrees(radians); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-radians-560: .. dropdown:: radians (np_test_4_all.cpp:12020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12010 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(π+0i rad) → 180+0i° (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray radians({5}); radians.setElementAt({0}, 0); radians.setElementAt({1}, 1); radians.setElementAt({2}, 2); radians.setElementAt({3}, 3); radians.setElementAt({4}, 6); auto result = numpy::degrees(radians); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-radians-561: .. dropdown:: radians (np_test_4_all.cpp:12020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12010 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(π+0i rad) → 180+0i° (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray radians({5}); radians.setElementAt({0}, 0); radians.setElementAt({1}, 1); radians.setElementAt({2}, 2); radians.setElementAt({3}, 3); radians.setElementAt({4}, 6); auto result = numpy::degrees(radians); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-radians-562: .. dropdown:: radians (np_test_4_all.cpp:12020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12010 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(π+0i rad) → 180+0i° (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray radians({5}); radians.setElementAt({0}, 0); radians.setElementAt({1}, 1); radians.setElementAt({2}, 2); radians.setElementAt({3}, 3); radians.setElementAt({4}, 6); auto result = numpy::degrees(radians); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-radians-563: .. dropdown:: radians (np_test_4_all.cpp:12020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12010 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(π+0i rad) → 180+0i° (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray radians({5}); radians.setElementAt({0}, 0); radians.setElementAt({1}, 1); radians.setElementAt({2}, 2); radians.setElementAt({3}, 3); radians.setElementAt({4}, 6); auto result = numpy::degrees(radians); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-radians-564: .. dropdown:: radians (np_test_4_all.cpp:12020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12010 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(π+0i rad) → 180+0i° (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray radians({5}); radians.setElementAt({0}, 0); radians.setElementAt({1}, 1); radians.setElementAt({2}, 2); radians.setElementAt({3}, 3); radians.setElementAt({4}, 6); auto result = numpy::degrees(radians); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-radians-565: .. dropdown:: radians (np_test_4_all.cpp:12020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12010 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(π+0i rad) → 180+0i° (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray radians({5}); radians.setElementAt({0}, 0); radians.setElementAt({1}, 1); radians.setElementAt({2}, 2); radians.setElementAt({3}, 3); radians.setElementAt({4}, 6); auto result = numpy::degrees(radians); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-radians-566: .. dropdown:: radians (np_test_4_all.cpp:12020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12010 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(π+0i rad) → 180+0i° (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray radians({5}); radians.setElementAt({0}, 0); radians.setElementAt({1}, 1); radians.setElementAt({2}, 2); radians.setElementAt({3}, 3); radians.setElementAt({4}, 6); auto result = numpy::degrees(radians); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-radians-567: .. dropdown:: radians (np_test_4_all.cpp:12020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12010 :emphasize-lines: 11 throw std::runtime_error(description); } // Type preservation check static_assert(std::is_same_v, "Result should be complex128"); std::cout << "OK: Test 9 passed: complex128(π+0i rad) → 180+0i° (type preserved)\n"; } // Test 10: int32 array → double array void test_int32_array() { numpy::NDArray radians({5}); radians.setElementAt({0}, 0); radians.setElementAt({1}, 1); radians.setElementAt({2}, 2); radians.setElementAt({3}, 3); radians.setElementAt({4}, 6); auto result = numpy::degrees(radians); // Type check: should be double array static_assert(std::is_same_v>, "Result should be NDArray"); .. _example-top_level-reciprocal-568: .. dropdown:: reciprocal (np_test_2_all.cpp:5856) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5846 :emphasize-lines: 11 } if (!(approx_equal(negative_result.getElementAt({ 6 }), -3.0))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(negative_result.getElementAt({ 6 }), -3.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] negative function works correctly\n"; // Test reciprocal auto nonzero_values = linspace(0.5, 2.0, 4); auto reciprocal_result = reciprocal(nonzero_values); if (!(approx_equal(reciprocal_result.getElementAt({ 0 }), 1.0 / 0.5))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(reciprocal_result.getElementAt({ 0 }), 1.0 / 0.5))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(reciprocal_result.getElementAt({ 3 }), 1.0 / 2.0))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(reciprocal_result.getElementAt({ 3 }), 1.0 / 2.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-reciprocal-569: .. dropdown:: reciprocal (np_test_2_all.cpp:5856) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5846 :emphasize-lines: 11 } if (!(approx_equal(negative_result.getElementAt({ 6 }), -3.0))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(negative_result.getElementAt({ 6 }), -3.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] negative function works correctly\n"; // Test reciprocal auto nonzero_values = linspace(0.5, 2.0, 4); auto reciprocal_result = reciprocal(nonzero_values); if (!(approx_equal(reciprocal_result.getElementAt({ 0 }), 1.0 / 0.5))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(reciprocal_result.getElementAt({ 0 }), 1.0 / 0.5))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(reciprocal_result.getElementAt({ 3 }), 1.0 / 2.0))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(reciprocal_result.getElementAt({ 3 }), 1.0 / 2.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-reciprocal-570: .. dropdown:: reciprocal (np_test_2_all.cpp:5856) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5846 :emphasize-lines: 11 } if (!(approx_equal(negative_result.getElementAt({ 6 }), -3.0))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(negative_result.getElementAt({ 6 }), -3.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] negative function works correctly\n"; // Test reciprocal auto nonzero_values = linspace(0.5, 2.0, 4); auto reciprocal_result = reciprocal(nonzero_values); if (!(approx_equal(reciprocal_result.getElementAt({ 0 }), 1.0 / 0.5))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(reciprocal_result.getElementAt({ 0 }), 1.0 / 0.5))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(reciprocal_result.getElementAt({ 3 }), 1.0 / 2.0))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(reciprocal_result.getElementAt({ 3 }), 1.0 / 2.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-reciprocal-571: .. dropdown:: reciprocal (np_test_2_all.cpp:5856) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5846 :emphasize-lines: 11 } if (!(approx_equal(negative_result.getElementAt({ 6 }), -3.0))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(negative_result.getElementAt({ 6 }), -3.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] negative function works correctly\n"; // Test reciprocal auto nonzero_values = linspace(0.5, 2.0, 4); auto reciprocal_result = reciprocal(nonzero_values); if (!(approx_equal(reciprocal_result.getElementAt({ 0 }), 1.0 / 0.5))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(reciprocal_result.getElementAt({ 0 }), 1.0 / 0.5))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(reciprocal_result.getElementAt({ 3 }), 1.0 / 2.0))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(reciprocal_result.getElementAt({ 3 }), 1.0 / 2.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-remainder-572: .. dropdown:: remainder (np_test_1_all.cpp:21354) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21344 :emphasize-lines: 11 a.setElementAt({ 1 }, 8.0); a.setElementAt({ 2 }, 9.0); a.setElementAt({ 3 }, 10.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 3.0); b.setElementAt({ 3 }, 3.0); auto result = remainder(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-remainder-573: .. dropdown:: remainder (np_test_1_all.cpp:21354) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21344 :emphasize-lines: 11 a.setElementAt({ 1 }, 8.0); a.setElementAt({ 2 }, 9.0); a.setElementAt({ 3 }, 10.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 3.0); b.setElementAt({ 3 }, 3.0); auto result = remainder(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-remainder-574: .. dropdown:: remainder (np_test_1_all.cpp:21354) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21344 :emphasize-lines: 11 a.setElementAt({ 1 }, 8.0); a.setElementAt({ 2 }, 9.0); a.setElementAt({ 3 }, 10.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 3.0); b.setElementAt({ 3 }, 3.0); auto result = remainder(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-remainder-575: .. dropdown:: remainder (np_test_1_all.cpp:21354) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21344 :emphasize-lines: 11 a.setElementAt({ 1 }, 8.0); a.setElementAt({ 2 }, 9.0); a.setElementAt({ 3 }, 10.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 3.0); b.setElementAt({ 3 }, 3.0); auto result = remainder(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-remainder-576: .. dropdown:: remainder (np_test_1_all.cpp:21354) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21344 :emphasize-lines: 11 a.setElementAt({ 1 }, 8.0); a.setElementAt({ 2 }, 9.0); a.setElementAt({ 3 }, 10.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 3.0); b.setElementAt({ 3 }, 3.0); auto result = remainder(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-remainder-577: .. dropdown:: remainder (np_test_1_all.cpp:21354) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21344 :emphasize-lines: 11 a.setElementAt({ 1 }, 8.0); a.setElementAt({ 2 }, 9.0); a.setElementAt({ 3 }, 10.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 3.0); b.setElementAt({ 3 }, 3.0); auto result = remainder(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-remainder-578: .. dropdown:: remainder (np_test_1_all.cpp:21354) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21344 :emphasize-lines: 11 a.setElementAt({ 1 }, 8.0); a.setElementAt({ 2 }, 9.0); a.setElementAt({ 3 }, 10.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 3.0); b.setElementAt({ 3 }, 3.0); auto result = remainder(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-remainder-579: .. dropdown:: remainder (np_test_1_all.cpp:21354) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21344 :emphasize-lines: 11 a.setElementAt({ 1 }, 8.0); a.setElementAt({ 2 }, 9.0); a.setElementAt({ 3 }, 10.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 3.0); b.setElementAt({ 3 }, 3.0); auto result = remainder(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-remainder-580: .. dropdown:: remainder (np_test_1_all.cpp:21354) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21344 :emphasize-lines: 11 a.setElementAt({ 1 }, 8.0); a.setElementAt({ 2 }, 9.0); a.setElementAt({ 3 }, 10.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 3.0); b.setElementAt({ 3 }, 3.0); auto result = remainder(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-remainder-581: .. dropdown:: remainder (np_test_1_all.cpp:21354) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21344 :emphasize-lines: 11 a.setElementAt({ 1 }, 8.0); a.setElementAt({ 2 }, 9.0); a.setElementAt({ 3 }, 10.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 3.0); b.setElementAt({ 3 }, 3.0); auto result = remainder(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-remainder-582: .. dropdown:: remainder (np_test_1_all.cpp:21354) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21344 :emphasize-lines: 11 a.setElementAt({ 1 }, 8.0); a.setElementAt({ 2 }, 9.0); a.setElementAt({ 3 }, 10.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 3.0); b.setElementAt({ 3 }, 3.0); auto result = remainder(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-remainder-583: .. dropdown:: remainder (np_test_1_all.cpp:21354) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21344 :emphasize-lines: 11 a.setElementAt({ 1 }, 8.0); a.setElementAt({ 2 }, 9.0); a.setElementAt({ 3 }, 10.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 3.0); b.setElementAt({ 3 }, 3.0); auto result = remainder(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-remainder-584: .. dropdown:: remainder (np_test_1_all.cpp:21354) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21344 :emphasize-lines: 11 a.setElementAt({ 1 }, 8.0); a.setElementAt({ 2 }, 9.0); a.setElementAt({ 3 }, 10.0); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 3.0); b.setElementAt({ 3 }, 3.0); auto result = remainder(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)) { std::string description = std::string("testRemainderFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - 2.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-rint-585: .. dropdown:: rint (np_test_2_all.cpp:5763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5753 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] trunc function works correctly\n"; // Test rint auto rint_result = rint(values); if (!(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-rint-586: .. dropdown:: rint (np_test_2_all.cpp:5763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5753 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] trunc function works correctly\n"; // Test rint auto rint_result = rint(values); if (!(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-rint-587: .. dropdown:: rint (np_test_2_all.cpp:5763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5753 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] trunc function works correctly\n"; // Test rint auto rint_result = rint(values); if (!(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-rint-588: .. dropdown:: rint (np_test_2_all.cpp:5763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5753 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] trunc function works correctly\n"; // Test rint auto rint_result = rint(values); if (!(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-rint-589: .. dropdown:: rint (np_test_2_all.cpp:5763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5753 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] trunc function works correctly\n"; // Test rint auto rint_result = rint(values); if (!(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-rint-590: .. dropdown:: rint (np_test_2_all.cpp:5763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5753 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] trunc function works correctly\n"; // Test rint auto rint_result = rint(values); if (!(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-rint-591: .. dropdown:: rint (np_test_2_all.cpp:5763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5753 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] trunc function works correctly\n"; // Test rint auto rint_result = rint(values); if (!(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-rint-592: .. dropdown:: rint (np_test_2_all.cpp:5763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5753 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] trunc function works correctly\n"; // Test rint auto rint_result = rint(values); if (!(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-rint-593: .. dropdown:: rint (np_test_2_all.cpp:5763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5753 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] trunc function works correctly\n"; // Test rint auto rint_result = rint(values); if (!(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-rint-594: .. dropdown:: rint (np_test_2_all.cpp:5763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5753 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] trunc function works correctly\n"; // Test rint auto rint_result = rint(values); if (!(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-rint-595: .. dropdown:: rint (np_test_2_all.cpp:5763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5753 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] trunc function works correctly\n"; // Test rint auto rint_result = rint(values); if (!(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-rint-596: .. dropdown:: rint (np_test_2_all.cpp:5763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5753 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] trunc function works correctly\n"; // Test rint auto rint_result = rint(values); if (!(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-rint-597: .. dropdown:: rint (np_test_2_all.cpp:5763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5753 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] trunc function works correctly\n"; // Test rint auto rint_result = rint(values); if (!(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 0 }), std::rint(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(rint_result.getElementAt({ 5 }), std::rint(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-round-598: .. dropdown:: round (np_test_1_all.cpp:23769) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23759 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(power_scalar_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Power functions have correct signatures\n"; // Test rounding functions with new decimals parameter auto round_result = round(array); // Default decimals=0 auto round_decimals_result = round(array, 2); // With decimals if (!(round_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-round-599: .. dropdown:: round (np_test_1_all.cpp:23769) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23759 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(power_scalar_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Power functions have correct signatures\n"; // Test rounding functions with new decimals parameter auto round_result = round(array); // Default decimals=0 auto round_decimals_result = round(array, 2); // With decimals if (!(round_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-round-600: .. dropdown:: round (np_test_1_all.cpp:23769) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23759 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(power_scalar_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Power functions have correct signatures\n"; // Test rounding functions with new decimals parameter auto round_result = round(array); // Default decimals=0 auto round_decimals_result = round(array, 2); // With decimals if (!(round_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-round-601: .. dropdown:: round (np_test_1_all.cpp:23769) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23759 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(power_scalar_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Power functions have correct signatures\n"; // Test rounding functions with new decimals parameter auto round_result = round(array); // Default decimals=0 auto round_decimals_result = round(array, 2); // With decimals if (!(round_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-round-602: .. dropdown:: round (np_test_1_all.cpp:23769) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23759 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(power_scalar_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Power functions have correct signatures\n"; // Test rounding functions with new decimals parameter auto round_result = round(array); // Default decimals=0 auto round_decimals_result = round(array, 2); // With decimals if (!(round_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-round-603: .. dropdown:: round (np_test_1_all.cpp:23769) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23759 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(power_scalar_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Power functions have correct signatures\n"; // Test rounding functions with new decimals parameter auto round_result = round(array); // Default decimals=0 auto round_decimals_result = round(array, 2); // With decimals if (!(round_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-round-604: .. dropdown:: round (np_test_1_all.cpp:23769) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23759 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(power_scalar_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Power functions have correct signatures\n"; // Test rounding functions with new decimals parameter auto round_result = round(array); // Default decimals=0 auto round_decimals_result = round(array, 2); // With decimals if (!(round_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-round-605: .. dropdown:: round (np_test_1_all.cpp:23769) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23759 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(power_scalar_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Power functions have correct signatures\n"; // Test rounding functions with new decimals parameter auto round_result = round(array); // Default decimals=0 auto round_decimals_result = round(array, 2); // With decimals if (!(round_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-round-606: .. dropdown:: round (np_test_1_all.cpp:23769) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23759 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(power_scalar_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Power functions have correct signatures\n"; // Test rounding functions with new decimals parameter auto round_result = round(array); // Default decimals=0 auto round_decimals_result = round(array, 2); // With decimals if (!(round_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-round-607: .. dropdown:: round (np_test_1_all.cpp:23769) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23759 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(power_scalar_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Power functions have correct signatures\n"; // Test rounding functions with new decimals parameter auto round_result = round(array); // Default decimals=0 auto round_decimals_result = round(array, 2); // With decimals if (!(round_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-round-608: .. dropdown:: round (np_test_1_all.cpp:23769) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23759 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(power_scalar_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Power functions have correct signatures\n"; // Test rounding functions with new decimals parameter auto round_result = round(array); // Default decimals=0 auto round_decimals_result = round(array, 2); // With decimals if (!(round_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-round-609: .. dropdown:: round (np_test_1_all.cpp:23769) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23759 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(power_scalar_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Power functions have correct signatures\n"; // Test rounding functions with new decimals parameter auto round_result = round(array); // Default decimals=0 auto round_decimals_result = round(array, 2); // With decimals if (!(round_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-round-610: .. dropdown:: round (np_test_1_all.cpp:23769) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23759 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(power_scalar_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Power functions have correct signatures\n"; // Test rounding functions with new decimals parameter auto round_result = round(array); // Default decimals=0 auto round_decimals_result = round(array, 2); // With decimals if (!(round_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(round_decimals_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-sin-611: .. dropdown:: sin (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-sin-612: .. dropdown:: sin (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-sin-613: .. dropdown:: sin (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-sin-614: .. dropdown:: sin (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-sin-615: .. dropdown:: sin (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-sin-616: .. dropdown:: sin (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-sin-617: .. dropdown:: sin (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-sin-618: .. dropdown:: sin (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-sin-619: .. dropdown:: sin (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-sin-620: .. dropdown:: sin (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-sin-621: .. dropdown:: sin (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-sin-622: .. dropdown:: sin (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-sin-623: .. dropdown:: sin (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-sin-624: .. dropdown:: sin (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-sin-625: .. dropdown:: sin (np_test_1_all.cpp:8006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7996 :emphasize-lines: 11 void testComplex256PrecisionComplex256() { std::cout << "========= testComplex256PrecisionComplex256 ======================="; // Test high precision calculations complex256 high_precision(1.234567890123456789012345L, 9.876543210987654321098765L); // std::cout << std::setprecision(20); // std::cout << "High precision complex: " << high_precision << std::endl; // Test complex exponential (Euler's formula: e^(ix) = cos(x) + i*sin(x)) complex256 i_pi(0.0L, 3.141592653589793238462643383279502884197L); // i*π auto euler = std::exp(i_pi); // std::cout << "e^(iπ) = " << euler << " (should be approximately -1)" << std::endl; // Test complex roots complex256 unity_root = std::exp(complex256(0.0L, 2.0L * 3.141592653589793238462643383279502884197L / 3.0L)); // std::cout << "Cube root of unity: " << unity_root << std::endl; // std::cout << "Cubed: " << unity_root * unity_root * unity_root << " (should be ≈ 1)" << std::endl; // std::cout << std::setprecision(6); // Reset precision .. _example-top_level-sin_inplace-626: .. dropdown:: sin_inplace (np_test_2_all.cpp:882) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 872 :emphasize-lines: 11 NDArray data({ 1000 }); for (size_t i = 0; i < 1000; ++i) { data.setElementAt({ i }, static_cast(i) * 0.01); } auto reference = sin(data, MathBackend::DEFAULT); NDArray mkl_data = data.copydeepArray(); NDArray std_data = data.copydeepArray(); sin_inplace(mkl_data, MathBackend::MKL); sin_inplace(std_data, MathBackend::DEFAULT); for (size_t i = 0; i < 1000; ++i) { double mkl_val = mkl_data.getElementAt({ i }); double std_val = std_data.getElementAt({ i }); double ref_val = reference.getElementAt({ i }); if (!(isApproxEqual(mkl_val, ref_val))) { std::string description = std::string("testSineInPlace():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_val, ref_val))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-sinc-627: .. dropdown:: sinc (np_test_3_all.cpp:16972) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16962 :emphasize-lines: 11 void np_test_missing_math_functions_sinc() { std::cout << "========= sinc: sinc function sin(πx)/(πx) ======================="; // explicit namespace to avoid name clashes numpy::NDArray a({ 4 }); a.setElementAt({ 0 }, 0.0); a.setElementAt({ 1 }, 1.0); a.setElementAt({ 2 }, -1.0); a.setElementAt({ 3 }, 0.5); numpy::NDArray result = numpy::sinc(a); // Verify values: sinc(0)=1, sinc(1)=0, sinc(-1)=0, sinc(0.5)≈0.6366 auto pass = true; // sinc(0) = 1 if (std::abs(result.getElementAt({ 0 }) - 1.0) > 1e-10) pass = false; // sinc(±1) ≈ 0 (actually very small due to sin(π)/π) if (std::abs(result.getElementAt({ 1 })) > 1e-10) pass = false; if (std::abs(result.getElementAt({ 2 })) > 1e-10) pass = false; .. _example-top_level-sinc-628: .. dropdown:: sinc (np_test_3_all.cpp:16972) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16962 :emphasize-lines: 11 void np_test_missing_math_functions_sinc() { std::cout << "========= sinc: sinc function sin(πx)/(πx) ======================="; // explicit namespace to avoid name clashes numpy::NDArray a({ 4 }); a.setElementAt({ 0 }, 0.0); a.setElementAt({ 1 }, 1.0); a.setElementAt({ 2 }, -1.0); a.setElementAt({ 3 }, 0.5); numpy::NDArray result = numpy::sinc(a); // Verify values: sinc(0)=1, sinc(1)=0, sinc(-1)=0, sinc(0.5)≈0.6366 auto pass = true; // sinc(0) = 1 if (std::abs(result.getElementAt({ 0 }) - 1.0) > 1e-10) pass = false; // sinc(±1) ≈ 0 (actually very small due to sin(π)/π) if (std::abs(result.getElementAt({ 1 })) > 1e-10) pass = false; if (std::abs(result.getElementAt({ 2 })) > 1e-10) pass = false; .. _example-top_level-sinc-629: .. dropdown:: sinc (np_test_3_all.cpp:16972) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16962 :emphasize-lines: 11 void np_test_missing_math_functions_sinc() { std::cout << "========= sinc: sinc function sin(πx)/(πx) ======================="; // explicit namespace to avoid name clashes numpy::NDArray a({ 4 }); a.setElementAt({ 0 }, 0.0); a.setElementAt({ 1 }, 1.0); a.setElementAt({ 2 }, -1.0); a.setElementAt({ 3 }, 0.5); numpy::NDArray result = numpy::sinc(a); // Verify values: sinc(0)=1, sinc(1)=0, sinc(-1)=0, sinc(0.5)≈0.6366 auto pass = true; // sinc(0) = 1 if (std::abs(result.getElementAt({ 0 }) - 1.0) > 1e-10) pass = false; // sinc(±1) ≈ 0 (actually very small due to sin(π)/π) if (std::abs(result.getElementAt({ 1 })) > 1e-10) pass = false; if (std::abs(result.getElementAt({ 2 })) > 1e-10) pass = false; .. _example-top_level-sinh-630: .. dropdown:: sinh (np_test_2_all.cpp:1009) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 999 :emphasize-lines: 11 size_t test_size = 1000; NDArray test_data({ test_size }); // Fill with values in [-5, 5] for hyperbolic functions for (size_t i = 0; i < test_size; ++i) { test_data.setElementAt({ i }, -5.0 + 10.0 * static_cast(i) / test_size); } // Test sinh auto std_sinh = sinh(test_data, MathBackend::DEFAULT); auto mkl_sinh = sinh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; .. _example-top_level-sinh-631: .. dropdown:: sinh (np_test_2_all.cpp:1009) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 999 :emphasize-lines: 11 size_t test_size = 1000; NDArray test_data({ test_size }); // Fill with values in [-5, 5] for hyperbolic functions for (size_t i = 0; i < test_size; ++i) { test_data.setElementAt({ i }, -5.0 + 10.0 * static_cast(i) / test_size); } // Test sinh auto std_sinh = sinh(test_data, MathBackend::DEFAULT); auto mkl_sinh = sinh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; .. _example-top_level-sinh-632: .. dropdown:: sinh (np_test_2_all.cpp:1009) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 999 :emphasize-lines: 11 size_t test_size = 1000; NDArray test_data({ test_size }); // Fill with values in [-5, 5] for hyperbolic functions for (size_t i = 0; i < test_size; ++i) { test_data.setElementAt({ i }, -5.0 + 10.0 * static_cast(i) / test_size); } // Test sinh auto std_sinh = sinh(test_data, MathBackend::DEFAULT); auto mkl_sinh = sinh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; .. _example-top_level-sinh-633: .. dropdown:: sinh (np_test_2_all.cpp:1009) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 999 :emphasize-lines: 11 size_t test_size = 1000; NDArray test_data({ test_size }); // Fill with values in [-5, 5] for hyperbolic functions for (size_t i = 0; i < test_size; ++i) { test_data.setElementAt({ i }, -5.0 + 10.0 * static_cast(i) / test_size); } // Test sinh auto std_sinh = sinh(test_data, MathBackend::DEFAULT); auto mkl_sinh = sinh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; .. _example-top_level-sinh-634: .. dropdown:: sinh (np_test_2_all.cpp:1009) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 999 :emphasize-lines: 11 size_t test_size = 1000; NDArray test_data({ test_size }); // Fill with values in [-5, 5] for hyperbolic functions for (size_t i = 0; i < test_size; ++i) { test_data.setElementAt({ i }, -5.0 + 10.0 * static_cast(i) / test_size); } // Test sinh auto std_sinh = sinh(test_data, MathBackend::DEFAULT); auto mkl_sinh = sinh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; .. _example-top_level-sinh-635: .. dropdown:: sinh (np_test_2_all.cpp:1009) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 999 :emphasize-lines: 11 size_t test_size = 1000; NDArray test_data({ test_size }); // Fill with values in [-5, 5] for hyperbolic functions for (size_t i = 0; i < test_size; ++i) { test_data.setElementAt({ i }, -5.0 + 10.0 * static_cast(i) / test_size); } // Test sinh auto std_sinh = sinh(test_data, MathBackend::DEFAULT); auto mkl_sinh = sinh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; .. _example-top_level-sinh-636: .. dropdown:: sinh (np_test_2_all.cpp:1009) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 999 :emphasize-lines: 11 size_t test_size = 1000; NDArray test_data({ test_size }); // Fill with values in [-5, 5] for hyperbolic functions for (size_t i = 0; i < test_size; ++i) { test_data.setElementAt({ i }, -5.0 + 10.0 * static_cast(i) / test_size); } // Test sinh auto std_sinh = sinh(test_data, MathBackend::DEFAULT); auto mkl_sinh = sinh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; .. _example-top_level-sinh-637: .. dropdown:: sinh (np_test_2_all.cpp:1009) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 999 :emphasize-lines: 11 size_t test_size = 1000; NDArray test_data({ test_size }); // Fill with values in [-5, 5] for hyperbolic functions for (size_t i = 0; i < test_size; ++i) { test_data.setElementAt({ i }, -5.0 + 10.0 * static_cast(i) / test_size); } // Test sinh auto std_sinh = sinh(test_data, MathBackend::DEFAULT); auto mkl_sinh = sinh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; .. _example-top_level-sinh-638: .. dropdown:: sinh (np_test_2_all.cpp:1009) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 999 :emphasize-lines: 11 size_t test_size = 1000; NDArray test_data({ test_size }); // Fill with values in [-5, 5] for hyperbolic functions for (size_t i = 0; i < test_size; ++i) { test_data.setElementAt({ i }, -5.0 + 10.0 * static_cast(i) / test_size); } // Test sinh auto std_sinh = sinh(test_data, MathBackend::DEFAULT); auto mkl_sinh = sinh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; .. _example-top_level-sinh-639: .. dropdown:: sinh (np_test_2_all.cpp:1009) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 999 :emphasize-lines: 11 size_t test_size = 1000; NDArray test_data({ test_size }); // Fill with values in [-5, 5] for hyperbolic functions for (size_t i = 0; i < test_size; ++i) { test_data.setElementAt({ i }, -5.0 + 10.0 * static_cast(i) / test_size); } // Test sinh auto std_sinh = sinh(test_data, MathBackend::DEFAULT); auto mkl_sinh = sinh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; .. _example-top_level-sinh-640: .. dropdown:: sinh (np_test_2_all.cpp:1009) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 999 :emphasize-lines: 11 size_t test_size = 1000; NDArray test_data({ test_size }); // Fill with values in [-5, 5] for hyperbolic functions for (size_t i = 0; i < test_size; ++i) { test_data.setElementAt({ i }, -5.0 + 10.0 * static_cast(i) / test_size); } // Test sinh auto std_sinh = sinh(test_data, MathBackend::DEFAULT); auto mkl_sinh = sinh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; .. _example-top_level-sinh-641: .. dropdown:: sinh (np_test_2_all.cpp:1009) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 999 :emphasize-lines: 11 size_t test_size = 1000; NDArray test_data({ test_size }); // Fill with values in [-5, 5] for hyperbolic functions for (size_t i = 0; i < test_size; ++i) { test_data.setElementAt({ i }, -5.0 + 10.0 * static_cast(i) / test_size); } // Test sinh auto std_sinh = sinh(test_data, MathBackend::DEFAULT); auto mkl_sinh = sinh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; .. _example-top_level-sinh-642: .. dropdown:: sinh (np_test_2_all.cpp:1009) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 999 :emphasize-lines: 11 size_t test_size = 1000; NDArray test_data({ test_size }); // Fill with values in [-5, 5] for hyperbolic functions for (size_t i = 0; i < test_size; ++i) { test_data.setElementAt({ i }, -5.0 + 10.0 * static_cast(i) / test_size); } // Test sinh auto std_sinh = sinh(test_data, MathBackend::DEFAULT); auto mkl_sinh = sinh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_sinh.getElementAt({ i }), std_sinh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] sinh MKL accuracy validated\n"; .. _example-top_level-sinm-643: .. dropdown:: sinm (np_test_2_all.cpp:5219) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5209 :emphasize-lines: 11 assert_test(std::abs(sqrtB_squared(0, 0) - 4.0) < 1e-6, "Matrix square root verification 0,0"); assert_test(std::abs(sqrtB_squared(1, 1) - 9.0) < 1e-6, "Matrix square root verification 1,1"); } catch (...) { // std::cout << "Matrix square root test failed"; } // Test matrix sine and cosine numpy::Matrix small_mat("0.1 0; 0 0.1"); // Small matrix for convergence try { auto sinA = numpy::sinm(small_mat); auto cosA = numpy::cosm(small_mat); assert_test(sinA.rows() == 2 && sinA.cols() == 2, "Matrix sine dimensions"); assert_test(cosA.rows() == 2 && cosA.cols() == 2, "Matrix cosine dimensions"); // sin^2 + cos^2 should be close to I for small angles auto sin2 = numpy::multiply(sinA, sinA); auto cos2 = numpy::multiply(cosA, cosA); auto identity_check = sin2 + cos2; assert_test(std::abs(identity_check(0, 0) - 1.0) < 1e-6, "Matrix trig identity"); assert_test(std::abs(identity_check(1, 1) - 1.0) < 1e-6, "Matrix trig identity"); .. _example-top_level-sinpi-644: .. dropdown:: sinpi (np_test_1_all.cpp:27894) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27884 :emphasize-lines: 11 } // std::cout << "]" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_sinpi() { std::cout << "========= sinpi: sin(x*π) ======================="; // Test special values auto r1 = sinpi(0.0); auto r2 = sinpi(0.5); auto r3 = sinpi(1.0); auto r4 = sinpi(1.5); // std::cout << std::fixed << std::setprecision(6); // std::cout << " sinpi(0.0) = " << r1 << " (expected: 0.000000)" << std::endl; // std::cout << " sinpi(0.5) = " << r2 << " (expected: 1.000000)" << std::endl; // std::cout << " sinpi(1.0) = " << r3 << " (expected: 0.000000)" << std::endl; // std::cout << " sinpi(1.5) = " << r4 << " (expected: -1.000000)" << std::endl; .. _example-top_level-sinpi-645: .. dropdown:: sinpi (np_test_1_all.cpp:27894) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27884 :emphasize-lines: 11 } // std::cout << "]" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_sinpi() { std::cout << "========= sinpi: sin(x*π) ======================="; // Test special values auto r1 = sinpi(0.0); auto r2 = sinpi(0.5); auto r3 = sinpi(1.0); auto r4 = sinpi(1.5); // std::cout << std::fixed << std::setprecision(6); // std::cout << " sinpi(0.0) = " << r1 << " (expected: 0.000000)" << std::endl; // std::cout << " sinpi(0.5) = " << r2 << " (expected: 1.000000)" << std::endl; // std::cout << " sinpi(1.0) = " << r3 << " (expected: 0.000000)" << std::endl; // std::cout << " sinpi(1.5) = " << r4 << " (expected: -1.000000)" << std::endl; .. _example-top_level-sqrt-646: .. dropdown:: sqrt (np_test_1_all.cpp:1226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1216 :emphasize-lines: 11 bool int_gt_2 = int_gt.getElementAt({2}); if (int_gt_2 != false) { // 3 > 3 = false std::cout << "[FAIL] in testTypeCompatibility(): int_gt[2] = " << int_gt_2 << ", expected false" << std::endl; throw std::runtime_error("testTypeCompatibility(): int comparison [2] failed"); } // std::cout << "[OK] Integer type comparisons"; // Test with complex types auto complex_a = createComplex128Array({2}); complex_a.setElementAt({0}, {3.0, 4.0}); // magnitude = 5.0 complex_a.setElementAt({1}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 auto complex_b = createComplex128Array({2}); complex_b.setElementAt({0}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 complex_b.setElementAt({1}, {3.0, 4.0}); // magnitude = 5.0 auto complex_gt = greater(complex_a, complex_b); bool complex_gt_0 = complex_gt.getElementAt({0}); if (complex_gt_0 != true) { // |3+4i| > |1+i| = true std::cout << "[FAIL] in testTypeCompatibility(): complex_gt[0] = " << complex_gt_0 << ", expected true" << std::endl; throw std::runtime_error("testTypeCompatibility(): complex comparison [0] failed"); .. _example-top_level-sqrt-647: .. dropdown:: sqrt (np_test_1_all.cpp:1226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1216 :emphasize-lines: 11 bool int_gt_2 = int_gt.getElementAt({2}); if (int_gt_2 != false) { // 3 > 3 = false std::cout << "[FAIL] in testTypeCompatibility(): int_gt[2] = " << int_gt_2 << ", expected false" << std::endl; throw std::runtime_error("testTypeCompatibility(): int comparison [2] failed"); } // std::cout << "[OK] Integer type comparisons"; // Test with complex types auto complex_a = createComplex128Array({2}); complex_a.setElementAt({0}, {3.0, 4.0}); // magnitude = 5.0 complex_a.setElementAt({1}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 auto complex_b = createComplex128Array({2}); complex_b.setElementAt({0}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 complex_b.setElementAt({1}, {3.0, 4.0}); // magnitude = 5.0 auto complex_gt = greater(complex_a, complex_b); bool complex_gt_0 = complex_gt.getElementAt({0}); if (complex_gt_0 != true) { // |3+4i| > |1+i| = true std::cout << "[FAIL] in testTypeCompatibility(): complex_gt[0] = " << complex_gt_0 << ", expected true" << std::endl; throw std::runtime_error("testTypeCompatibility(): complex comparison [0] failed"); .. _example-top_level-sqrt-648: .. dropdown:: sqrt (np_test_1_all.cpp:1226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1216 :emphasize-lines: 11 bool int_gt_2 = int_gt.getElementAt({2}); if (int_gt_2 != false) { // 3 > 3 = false std::cout << "[FAIL] in testTypeCompatibility(): int_gt[2] = " << int_gt_2 << ", expected false" << std::endl; throw std::runtime_error("testTypeCompatibility(): int comparison [2] failed"); } // std::cout << "[OK] Integer type comparisons"; // Test with complex types auto complex_a = createComplex128Array({2}); complex_a.setElementAt({0}, {3.0, 4.0}); // magnitude = 5.0 complex_a.setElementAt({1}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 auto complex_b = createComplex128Array({2}); complex_b.setElementAt({0}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 complex_b.setElementAt({1}, {3.0, 4.0}); // magnitude = 5.0 auto complex_gt = greater(complex_a, complex_b); bool complex_gt_0 = complex_gt.getElementAt({0}); if (complex_gt_0 != true) { // |3+4i| > |1+i| = true std::cout << "[FAIL] in testTypeCompatibility(): complex_gt[0] = " << complex_gt_0 << ", expected true" << std::endl; throw std::runtime_error("testTypeCompatibility(): complex comparison [0] failed"); .. _example-top_level-sqrt-649: .. dropdown:: sqrt (np_test_1_all.cpp:1226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1216 :emphasize-lines: 11 bool int_gt_2 = int_gt.getElementAt({2}); if (int_gt_2 != false) { // 3 > 3 = false std::cout << "[FAIL] in testTypeCompatibility(): int_gt[2] = " << int_gt_2 << ", expected false" << std::endl; throw std::runtime_error("testTypeCompatibility(): int comparison [2] failed"); } // std::cout << "[OK] Integer type comparisons"; // Test with complex types auto complex_a = createComplex128Array({2}); complex_a.setElementAt({0}, {3.0, 4.0}); // magnitude = 5.0 complex_a.setElementAt({1}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 auto complex_b = createComplex128Array({2}); complex_b.setElementAt({0}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 complex_b.setElementAt({1}, {3.0, 4.0}); // magnitude = 5.0 auto complex_gt = greater(complex_a, complex_b); bool complex_gt_0 = complex_gt.getElementAt({0}); if (complex_gt_0 != true) { // |3+4i| > |1+i| = true std::cout << "[FAIL] in testTypeCompatibility(): complex_gt[0] = " << complex_gt_0 << ", expected true" << std::endl; throw std::runtime_error("testTypeCompatibility(): complex comparison [0] failed"); .. _example-top_level-sqrt-650: .. dropdown:: sqrt (np_test_1_all.cpp:1226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1216 :emphasize-lines: 11 bool int_gt_2 = int_gt.getElementAt({2}); if (int_gt_2 != false) { // 3 > 3 = false std::cout << "[FAIL] in testTypeCompatibility(): int_gt[2] = " << int_gt_2 << ", expected false" << std::endl; throw std::runtime_error("testTypeCompatibility(): int comparison [2] failed"); } // std::cout << "[OK] Integer type comparisons"; // Test with complex types auto complex_a = createComplex128Array({2}); complex_a.setElementAt({0}, {3.0, 4.0}); // magnitude = 5.0 complex_a.setElementAt({1}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 auto complex_b = createComplex128Array({2}); complex_b.setElementAt({0}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 complex_b.setElementAt({1}, {3.0, 4.0}); // magnitude = 5.0 auto complex_gt = greater(complex_a, complex_b); bool complex_gt_0 = complex_gt.getElementAt({0}); if (complex_gt_0 != true) { // |3+4i| > |1+i| = true std::cout << "[FAIL] in testTypeCompatibility(): complex_gt[0] = " << complex_gt_0 << ", expected true" << std::endl; throw std::runtime_error("testTypeCompatibility(): complex comparison [0] failed"); .. _example-top_level-sqrt-651: .. dropdown:: sqrt (np_test_1_all.cpp:1226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1216 :emphasize-lines: 11 bool int_gt_2 = int_gt.getElementAt({2}); if (int_gt_2 != false) { // 3 > 3 = false std::cout << "[FAIL] in testTypeCompatibility(): int_gt[2] = " << int_gt_2 << ", expected false" << std::endl; throw std::runtime_error("testTypeCompatibility(): int comparison [2] failed"); } // std::cout << "[OK] Integer type comparisons"; // Test with complex types auto complex_a = createComplex128Array({2}); complex_a.setElementAt({0}, {3.0, 4.0}); // magnitude = 5.0 complex_a.setElementAt({1}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 auto complex_b = createComplex128Array({2}); complex_b.setElementAt({0}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 complex_b.setElementAt({1}, {3.0, 4.0}); // magnitude = 5.0 auto complex_gt = greater(complex_a, complex_b); bool complex_gt_0 = complex_gt.getElementAt({0}); if (complex_gt_0 != true) { // |3+4i| > |1+i| = true std::cout << "[FAIL] in testTypeCompatibility(): complex_gt[0] = " << complex_gt_0 << ", expected true" << std::endl; throw std::runtime_error("testTypeCompatibility(): complex comparison [0] failed"); .. _example-top_level-sqrt-652: .. dropdown:: sqrt (np_test_1_all.cpp:1226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1216 :emphasize-lines: 11 bool int_gt_2 = int_gt.getElementAt({2}); if (int_gt_2 != false) { // 3 > 3 = false std::cout << "[FAIL] in testTypeCompatibility(): int_gt[2] = " << int_gt_2 << ", expected false" << std::endl; throw std::runtime_error("testTypeCompatibility(): int comparison [2] failed"); } // std::cout << "[OK] Integer type comparisons"; // Test with complex types auto complex_a = createComplex128Array({2}); complex_a.setElementAt({0}, {3.0, 4.0}); // magnitude = 5.0 complex_a.setElementAt({1}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 auto complex_b = createComplex128Array({2}); complex_b.setElementAt({0}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 complex_b.setElementAt({1}, {3.0, 4.0}); // magnitude = 5.0 auto complex_gt = greater(complex_a, complex_b); bool complex_gt_0 = complex_gt.getElementAt({0}); if (complex_gt_0 != true) { // |3+4i| > |1+i| = true std::cout << "[FAIL] in testTypeCompatibility(): complex_gt[0] = " << complex_gt_0 << ", expected true" << std::endl; throw std::runtime_error("testTypeCompatibility(): complex comparison [0] failed"); .. _example-top_level-sqrt-653: .. dropdown:: sqrt (np_test_1_all.cpp:1226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1216 :emphasize-lines: 11 bool int_gt_2 = int_gt.getElementAt({2}); if (int_gt_2 != false) { // 3 > 3 = false std::cout << "[FAIL] in testTypeCompatibility(): int_gt[2] = " << int_gt_2 << ", expected false" << std::endl; throw std::runtime_error("testTypeCompatibility(): int comparison [2] failed"); } // std::cout << "[OK] Integer type comparisons"; // Test with complex types auto complex_a = createComplex128Array({2}); complex_a.setElementAt({0}, {3.0, 4.0}); // magnitude = 5.0 complex_a.setElementAt({1}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 auto complex_b = createComplex128Array({2}); complex_b.setElementAt({0}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 complex_b.setElementAt({1}, {3.0, 4.0}); // magnitude = 5.0 auto complex_gt = greater(complex_a, complex_b); bool complex_gt_0 = complex_gt.getElementAt({0}); if (complex_gt_0 != true) { // |3+4i| > |1+i| = true std::cout << "[FAIL] in testTypeCompatibility(): complex_gt[0] = " << complex_gt_0 << ", expected true" << std::endl; throw std::runtime_error("testTypeCompatibility(): complex comparison [0] failed"); .. _example-top_level-sqrt-654: .. dropdown:: sqrt (np_test_1_all.cpp:1226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1216 :emphasize-lines: 11 bool int_gt_2 = int_gt.getElementAt({2}); if (int_gt_2 != false) { // 3 > 3 = false std::cout << "[FAIL] in testTypeCompatibility(): int_gt[2] = " << int_gt_2 << ", expected false" << std::endl; throw std::runtime_error("testTypeCompatibility(): int comparison [2] failed"); } // std::cout << "[OK] Integer type comparisons"; // Test with complex types auto complex_a = createComplex128Array({2}); complex_a.setElementAt({0}, {3.0, 4.0}); // magnitude = 5.0 complex_a.setElementAt({1}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 auto complex_b = createComplex128Array({2}); complex_b.setElementAt({0}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 complex_b.setElementAt({1}, {3.0, 4.0}); // magnitude = 5.0 auto complex_gt = greater(complex_a, complex_b); bool complex_gt_0 = complex_gt.getElementAt({0}); if (complex_gt_0 != true) { // |3+4i| > |1+i| = true std::cout << "[FAIL] in testTypeCompatibility(): complex_gt[0] = " << complex_gt_0 << ", expected true" << std::endl; throw std::runtime_error("testTypeCompatibility(): complex comparison [0] failed"); .. _example-top_level-sqrt-655: .. dropdown:: sqrt (np_test_1_all.cpp:1226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1216 :emphasize-lines: 11 bool int_gt_2 = int_gt.getElementAt({2}); if (int_gt_2 != false) { // 3 > 3 = false std::cout << "[FAIL] in testTypeCompatibility(): int_gt[2] = " << int_gt_2 << ", expected false" << std::endl; throw std::runtime_error("testTypeCompatibility(): int comparison [2] failed"); } // std::cout << "[OK] Integer type comparisons"; // Test with complex types auto complex_a = createComplex128Array({2}); complex_a.setElementAt({0}, {3.0, 4.0}); // magnitude = 5.0 complex_a.setElementAt({1}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 auto complex_b = createComplex128Array({2}); complex_b.setElementAt({0}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 complex_b.setElementAt({1}, {3.0, 4.0}); // magnitude = 5.0 auto complex_gt = greater(complex_a, complex_b); bool complex_gt_0 = complex_gt.getElementAt({0}); if (complex_gt_0 != true) { // |3+4i| > |1+i| = true std::cout << "[FAIL] in testTypeCompatibility(): complex_gt[0] = " << complex_gt_0 << ", expected true" << std::endl; throw std::runtime_error("testTypeCompatibility(): complex comparison [0] failed"); .. _example-top_level-sqrt-656: .. dropdown:: sqrt (np_test_1_all.cpp:1226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1216 :emphasize-lines: 11 bool int_gt_2 = int_gt.getElementAt({2}); if (int_gt_2 != false) { // 3 > 3 = false std::cout << "[FAIL] in testTypeCompatibility(): int_gt[2] = " << int_gt_2 << ", expected false" << std::endl; throw std::runtime_error("testTypeCompatibility(): int comparison [2] failed"); } // std::cout << "[OK] Integer type comparisons"; // Test with complex types auto complex_a = createComplex128Array({2}); complex_a.setElementAt({0}, {3.0, 4.0}); // magnitude = 5.0 complex_a.setElementAt({1}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 auto complex_b = createComplex128Array({2}); complex_b.setElementAt({0}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 complex_b.setElementAt({1}, {3.0, 4.0}); // magnitude = 5.0 auto complex_gt = greater(complex_a, complex_b); bool complex_gt_0 = complex_gt.getElementAt({0}); if (complex_gt_0 != true) { // |3+4i| > |1+i| = true std::cout << "[FAIL] in testTypeCompatibility(): complex_gt[0] = " << complex_gt_0 << ", expected true" << std::endl; throw std::runtime_error("testTypeCompatibility(): complex comparison [0] failed"); .. _example-top_level-sqrt-657: .. dropdown:: sqrt (np_test_1_all.cpp:1226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1216 :emphasize-lines: 11 bool int_gt_2 = int_gt.getElementAt({2}); if (int_gt_2 != false) { // 3 > 3 = false std::cout << "[FAIL] in testTypeCompatibility(): int_gt[2] = " << int_gt_2 << ", expected false" << std::endl; throw std::runtime_error("testTypeCompatibility(): int comparison [2] failed"); } // std::cout << "[OK] Integer type comparisons"; // Test with complex types auto complex_a = createComplex128Array({2}); complex_a.setElementAt({0}, {3.0, 4.0}); // magnitude = 5.0 complex_a.setElementAt({1}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 auto complex_b = createComplex128Array({2}); complex_b.setElementAt({0}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 complex_b.setElementAt({1}, {3.0, 4.0}); // magnitude = 5.0 auto complex_gt = greater(complex_a, complex_b); bool complex_gt_0 = complex_gt.getElementAt({0}); if (complex_gt_0 != true) { // |3+4i| > |1+i| = true std::cout << "[FAIL] in testTypeCompatibility(): complex_gt[0] = " << complex_gt_0 << ", expected true" << std::endl; throw std::runtime_error("testTypeCompatibility(): complex comparison [0] failed"); .. _example-top_level-sqrt-658: .. dropdown:: sqrt (np_test_1_all.cpp:1226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1216 :emphasize-lines: 11 bool int_gt_2 = int_gt.getElementAt({2}); if (int_gt_2 != false) { // 3 > 3 = false std::cout << "[FAIL] in testTypeCompatibility(): int_gt[2] = " << int_gt_2 << ", expected false" << std::endl; throw std::runtime_error("testTypeCompatibility(): int comparison [2] failed"); } // std::cout << "[OK] Integer type comparisons"; // Test with complex types auto complex_a = createComplex128Array({2}); complex_a.setElementAt({0}, {3.0, 4.0}); // magnitude = 5.0 complex_a.setElementAt({1}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 auto complex_b = createComplex128Array({2}); complex_b.setElementAt({0}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 complex_b.setElementAt({1}, {3.0, 4.0}); // magnitude = 5.0 auto complex_gt = greater(complex_a, complex_b); bool complex_gt_0 = complex_gt.getElementAt({0}); if (complex_gt_0 != true) { // |3+4i| > |1+i| = true std::cout << "[FAIL] in testTypeCompatibility(): complex_gt[0] = " << complex_gt_0 << ", expected true" << std::endl; throw std::runtime_error("testTypeCompatibility(): complex comparison [0] failed"); .. _example-top_level-sqrt-659: .. dropdown:: sqrt (np_test_1_all.cpp:1226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1216 :emphasize-lines: 11 bool int_gt_2 = int_gt.getElementAt({2}); if (int_gt_2 != false) { // 3 > 3 = false std::cout << "[FAIL] in testTypeCompatibility(): int_gt[2] = " << int_gt_2 << ", expected false" << std::endl; throw std::runtime_error("testTypeCompatibility(): int comparison [2] failed"); } // std::cout << "[OK] Integer type comparisons"; // Test with complex types auto complex_a = createComplex128Array({2}); complex_a.setElementAt({0}, {3.0, 4.0}); // magnitude = 5.0 complex_a.setElementAt({1}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 auto complex_b = createComplex128Array({2}); complex_b.setElementAt({0}, {1.0, 1.0}); // magnitude = sqrt(2) ≈ 1.414 complex_b.setElementAt({1}, {3.0, 4.0}); // magnitude = 5.0 auto complex_gt = greater(complex_a, complex_b); bool complex_gt_0 = complex_gt.getElementAt({0}); if (complex_gt_0 != true) { // |3+4i| > |1+i| = true std::cout << "[FAIL] in testTypeCompatibility(): complex_gt[0] = " << complex_gt_0 << ", expected true" << std::endl; throw std::runtime_error("testTypeCompatibility(): complex comparison [0] failed"); .. _example-top_level-sqrt_complex_mkl-660: .. dropdown:: sqrt_complex_mkl (np_test_3_all.cpp:17665) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17655 :emphasize-lines: 11 auto conj_result = numpy::mkl_special_complex::conj_complex_mkl(z); for (size_t i = 0; i < z.getSize(); ++i) { auto expected = std::conj(z.getElementAt({ i })); if (std::abs(conj_result.getElementAt({ i }) - expected) > tolerance) { std::cout << " [FAIL] : conj_complex_mkl incorrect at index " << i; throw std::runtime_error("conj_complex_mkl failed"); } } // Test sqrt auto sqrt_result = numpy::mkl_special_complex::sqrt_complex_mkl(z); for (size_t i = 0; i < z.getSize(); ++i) { auto expected = std::sqrt(z.getElementAt({ i })); if (std::abs(sqrt_result.getElementAt({ i }) - expected) > tolerance) { std::cout << " [FAIL] : sqrt_complex_mkl incorrect at index " << i; throw std::runtime_error("sqrt_complex_mkl failed"); } } #else // std::cout << " [SKIP] MKL support not compiled" << std::endl; #endif .. _example-top_level-sqrt_complex_mkl-661: .. dropdown:: sqrt_complex_mkl (np_test_3_all.cpp:17665) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17655 :emphasize-lines: 11 auto conj_result = numpy::mkl_special_complex::conj_complex_mkl(z); for (size_t i = 0; i < z.getSize(); ++i) { auto expected = std::conj(z.getElementAt({ i })); if (std::abs(conj_result.getElementAt({ i }) - expected) > tolerance) { std::cout << " [FAIL] : conj_complex_mkl incorrect at index " << i; throw std::runtime_error("conj_complex_mkl failed"); } } // Test sqrt auto sqrt_result = numpy::mkl_special_complex::sqrt_complex_mkl(z); for (size_t i = 0; i < z.getSize(); ++i) { auto expected = std::sqrt(z.getElementAt({ i })); if (std::abs(sqrt_result.getElementAt({ i }) - expected) > tolerance) { std::cout << " [FAIL] : sqrt_complex_mkl incorrect at index " << i; throw std::runtime_error("sqrt_complex_mkl failed"); } } #else // std::cout << " [SKIP] MKL support not compiled" << std::endl; #endif .. _example-top_level-sqrt_mkl_inplace-662: .. dropdown:: sqrt_mkl_inplace (np_test_3_all.cpp:17389) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17379 :emphasize-lines: 11 break; } } if (!passed) { throw std::runtime_error("np_test_mkl_sqrt failed"); } // Test in-place version numpy::NDArray inplace_data = numpy::arange(1.0, 10.0, 1.0); numpy::mkl_special::sqrt_mkl_inplace(inplace_data); for (size_t i = 0; i < input.getSize(); ++i) { double expected = std::sqrt(input.getElementAt({ i })); if (std::abs(inplace_data.getElementAt({ i }) - expected) > tolerance) { std::cout << " [FAIL] : sqrt_mkl_inplace incorrect at index " << i; throw std::runtime_error("sqrt_mkl_inplace failed"); } } #else // std::cout << " [SKIP] MKL support not compiled" << std::endl; .. _example-top_level-sqrtm-663: .. dropdown:: sqrtm (np_test_2_all.cpp:5204) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5194 :emphasize-lines: 11 assert_test(std::abs(expA(1, 0)) < 1e-10, "Matrix exponential 1,0"); assert_test(std::abs(expA(1, 1) - 1.0) < 1e-10, "Matrix exponential 1,1"); } catch (...) { // std::cout << "Matrix exponential test failed"; } // Test matrix square root for positive definite matrix numpy::Matrix B("4 0; 0 9"); // Diagonal positive matrix try { auto sqrtB = numpy::sqrtm(B); assert_test(sqrtB.rows() == 2 && sqrtB.cols() == 2, "Matrix square root dimensions"); // Verify sqrtB * sqrtB ? B auto sqrtB_squared = sqrtB * sqrtB; assert_test(std::abs(sqrtB_squared(0, 0) - 4.0) < 1e-6, "Matrix square root verification 0,0"); assert_test(std::abs(sqrtB_squared(1, 1) - 9.0) < 1e-6, "Matrix square root verification 1,1"); } catch (...) { // std::cout << "Matrix square root test failed"; } .. _example-top_level-square-664: .. dropdown:: square (np_test_2_all.cpp:4980) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4970 :emphasize-lines: 11 // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); .. _example-top_level-square-665: .. dropdown:: square (np_test_2_all.cpp:4980) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4970 :emphasize-lines: 11 // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); .. _example-top_level-square-666: .. dropdown:: square (np_test_2_all.cpp:4980) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4970 :emphasize-lines: 11 // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); .. _example-top_level-square-667: .. dropdown:: square (np_test_2_all.cpp:4980) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4970 :emphasize-lines: 11 // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); .. _example-top_level-square-668: .. dropdown:: square (np_test_2_all.cpp:4980) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4970 :emphasize-lines: 11 // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); .. _example-top_level-square-669: .. dropdown:: square (np_test_2_all.cpp:4980) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4970 :emphasize-lines: 11 // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); .. _example-top_level-square-670: .. dropdown:: square (np_test_2_all.cpp:4980) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4970 :emphasize-lines: 11 // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); .. _example-top_level-square-671: .. dropdown:: square (np_test_2_all.cpp:4980) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4970 :emphasize-lines: 11 // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); .. _example-top_level-square-672: .. dropdown:: square (np_test_2_all.cpp:4980) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4970 :emphasize-lines: 11 // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); .. _example-top_level-square-673: .. dropdown:: square (np_test_2_all.cpp:4980) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4970 :emphasize-lines: 11 // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); .. _example-top_level-square-674: .. dropdown:: square (np_test_2_all.cpp:4980) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4970 :emphasize-lines: 11 // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); .. _example-top_level-square-675: .. dropdown:: square (np_test_2_all.cpp:4980) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4970 :emphasize-lines: 11 // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); .. _example-top_level-square-676: .. dropdown:: square (np_test_2_all.cpp:4980) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4970 :emphasize-lines: 11 // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); .. _example-top_level-subtract-677: .. dropdown:: subtract (np_test_3_all.cpp:16825) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16815 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void np_test_missing_math_functions_subtract_array() { std::cout << "========= subtract: array-array subtraction ======================="; // explicit namespace to avoid name clashes numpy::NDArray a = numpy::arange(10.0, 16.0, 1.0); numpy::NDArray b = numpy::arange(0.0, 6.0, 1.0); numpy::NDArray result = numpy::subtract(a, b); // Verify values: [10,11,12,13,14,15] - [0,1,2,3,4,5] = [10,10,10,10,10,10] auto pass = true; for (size_t i = 0; i < 6 && pass; ++i) { double val = result.getElementAt({ i }); double exp = 10.0; if (std::abs(val - exp) > 1e-10) { pass = false; } } .. _example-top_level-subtract-678: .. dropdown:: subtract (np_test_3_all.cpp:16825) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16815 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void np_test_missing_math_functions_subtract_array() { std::cout << "========= subtract: array-array subtraction ======================="; // explicit namespace to avoid name clashes numpy::NDArray a = numpy::arange(10.0, 16.0, 1.0); numpy::NDArray b = numpy::arange(0.0, 6.0, 1.0); numpy::NDArray result = numpy::subtract(a, b); // Verify values: [10,11,12,13,14,15] - [0,1,2,3,4,5] = [10,10,10,10,10,10] auto pass = true; for (size_t i = 0; i < 6 && pass; ++i) { double val = result.getElementAt({ i }); double exp = 10.0; if (std::abs(val - exp) > 1e-10) { pass = false; } } .. _example-top_level-subtract-679: .. dropdown:: subtract (np_test_3_all.cpp:16825) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16815 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void np_test_missing_math_functions_subtract_array() { std::cout << "========= subtract: array-array subtraction ======================="; // explicit namespace to avoid name clashes numpy::NDArray a = numpy::arange(10.0, 16.0, 1.0); numpy::NDArray b = numpy::arange(0.0, 6.0, 1.0); numpy::NDArray result = numpy::subtract(a, b); // Verify values: [10,11,12,13,14,15] - [0,1,2,3,4,5] = [10,10,10,10,10,10] auto pass = true; for (size_t i = 0; i < 6 && pass; ++i) { double val = result.getElementAt({ i }); double exp = 10.0; if (std::abs(val - exp) > 1e-10) { pass = false; } } .. _example-top_level-tan-680: .. dropdown:: tan (np_test_1_all.cpp:23723) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23713 :emphasize-lines: 11 void testMathFunctionSignatures() { std::cout << "========= testMathFunctionSignatures ======================="; auto array = linspace(0.1, 2.0, 10); auto array2 = linspace(1.0, 3.0, 10); // Test trigonometric functions auto sin_result = numpy::sin(array); auto cos_result = numpy::cos(array); auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); .. _example-top_level-tan-681: .. dropdown:: tan (np_test_1_all.cpp:23723) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23713 :emphasize-lines: 11 void testMathFunctionSignatures() { std::cout << "========= testMathFunctionSignatures ======================="; auto array = linspace(0.1, 2.0, 10); auto array2 = linspace(1.0, 3.0, 10); // Test trigonometric functions auto sin_result = numpy::sin(array); auto cos_result = numpy::cos(array); auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); .. _example-top_level-tan-682: .. dropdown:: tan (np_test_1_all.cpp:23723) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23713 :emphasize-lines: 11 void testMathFunctionSignatures() { std::cout << "========= testMathFunctionSignatures ======================="; auto array = linspace(0.1, 2.0, 10); auto array2 = linspace(1.0, 3.0, 10); // Test trigonometric functions auto sin_result = numpy::sin(array); auto cos_result = numpy::cos(array); auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); .. _example-top_level-tan-683: .. dropdown:: tan (np_test_1_all.cpp:23723) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23713 :emphasize-lines: 11 void testMathFunctionSignatures() { std::cout << "========= testMathFunctionSignatures ======================="; auto array = linspace(0.1, 2.0, 10); auto array2 = linspace(1.0, 3.0, 10); // Test trigonometric functions auto sin_result = numpy::sin(array); auto cos_result = numpy::cos(array); auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); .. _example-top_level-tan-684: .. dropdown:: tan (np_test_1_all.cpp:23723) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23713 :emphasize-lines: 11 void testMathFunctionSignatures() { std::cout << "========= testMathFunctionSignatures ======================="; auto array = linspace(0.1, 2.0, 10); auto array2 = linspace(1.0, 3.0, 10); // Test trigonometric functions auto sin_result = numpy::sin(array); auto cos_result = numpy::cos(array); auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); .. _example-top_level-tan-685: .. dropdown:: tan (np_test_1_all.cpp:23723) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23713 :emphasize-lines: 11 void testMathFunctionSignatures() { std::cout << "========= testMathFunctionSignatures ======================="; auto array = linspace(0.1, 2.0, 10); auto array2 = linspace(1.0, 3.0, 10); // Test trigonometric functions auto sin_result = numpy::sin(array); auto cos_result = numpy::cos(array); auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); .. _example-top_level-tan-686: .. dropdown:: tan (np_test_1_all.cpp:23723) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23713 :emphasize-lines: 11 void testMathFunctionSignatures() { std::cout << "========= testMathFunctionSignatures ======================="; auto array = linspace(0.1, 2.0, 10); auto array2 = linspace(1.0, 3.0, 10); // Test trigonometric functions auto sin_result = numpy::sin(array); auto cos_result = numpy::cos(array); auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); .. _example-top_level-tan-687: .. dropdown:: tan (np_test_1_all.cpp:23723) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23713 :emphasize-lines: 11 void testMathFunctionSignatures() { std::cout << "========= testMathFunctionSignatures ======================="; auto array = linspace(0.1, 2.0, 10); auto array2 = linspace(1.0, 3.0, 10); // Test trigonometric functions auto sin_result = numpy::sin(array); auto cos_result = numpy::cos(array); auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); .. _example-top_level-tan-688: .. dropdown:: tan (np_test_1_all.cpp:23723) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23713 :emphasize-lines: 11 void testMathFunctionSignatures() { std::cout << "========= testMathFunctionSignatures ======================="; auto array = linspace(0.1, 2.0, 10); auto array2 = linspace(1.0, 3.0, 10); // Test trigonometric functions auto sin_result = numpy::sin(array); auto cos_result = numpy::cos(array); auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); .. _example-top_level-tan-689: .. dropdown:: tan (np_test_1_all.cpp:23723) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23713 :emphasize-lines: 11 void testMathFunctionSignatures() { std::cout << "========= testMathFunctionSignatures ======================="; auto array = linspace(0.1, 2.0, 10); auto array2 = linspace(1.0, 3.0, 10); // Test trigonometric functions auto sin_result = numpy::sin(array); auto cos_result = numpy::cos(array); auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); .. _example-top_level-tan-690: .. dropdown:: tan (np_test_1_all.cpp:23723) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23713 :emphasize-lines: 11 void testMathFunctionSignatures() { std::cout << "========= testMathFunctionSignatures ======================="; auto array = linspace(0.1, 2.0, 10); auto array2 = linspace(1.0, 3.0, 10); // Test trigonometric functions auto sin_result = numpy::sin(array); auto cos_result = numpy::cos(array); auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); .. _example-top_level-tan-691: .. dropdown:: tan (np_test_1_all.cpp:23723) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23713 :emphasize-lines: 11 void testMathFunctionSignatures() { std::cout << "========= testMathFunctionSignatures ======================="; auto array = linspace(0.1, 2.0, 10); auto array2 = linspace(1.0, 3.0, 10); // Test trigonometric functions auto sin_result = numpy::sin(array); auto cos_result = numpy::cos(array); auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); .. _example-top_level-tan-692: .. dropdown:: tan (np_test_1_all.cpp:23723) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23713 :emphasize-lines: 11 void testMathFunctionSignatures() { std::cout << "========= testMathFunctionSignatures ======================="; auto array = linspace(0.1, 2.0, 10); auto array2 = linspace(1.0, 3.0, 10); // Test trigonometric functions auto sin_result = numpy::sin(array); auto cos_result = numpy::cos(array); auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); .. _example-top_level-tan-693: .. dropdown:: tan (np_test_1_all.cpp:23723) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23713 :emphasize-lines: 11 void testMathFunctionSignatures() { std::cout << "========= testMathFunctionSignatures ======================="; auto array = linspace(0.1, 2.0, 10); auto array2 = linspace(1.0, 3.0, 10); // Test trigonometric functions auto sin_result = numpy::sin(array); auto cos_result = numpy::cos(array); auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); .. _example-top_level-tan-694: .. dropdown:: tan (np_test_1_all.cpp:23723) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23713 :emphasize-lines: 11 void testMathFunctionSignatures() { std::cout << "========= testMathFunctionSignatures ======================="; auto array = linspace(0.1, 2.0, 10); auto array2 = linspace(1.0, 3.0, 10); // Test trigonometric functions auto sin_result = numpy::sin(array); auto cos_result = numpy::cos(array); auto tan_result = numpy::tan(array); if (!(sin_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sin_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Trigonometric functions have correct signatures\n"; // Test inverse trigonometric functions auto small_array = linspace(-0.9, 0.9, 5); auto asin_result = numpy::arcsin(small_array); .. _example-top_level-tanh-695: .. dropdown:: tanh (np_test_2_all.cpp:1035) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1025 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; // Test tanh auto std_tanh = tanh(test_data, MathBackend::DEFAULT); auto mkl_tanh = tanh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] tanh MKL accuracy validated\n"; .. _example-top_level-tanh-696: .. dropdown:: tanh (np_test_2_all.cpp:1035) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1025 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; // Test tanh auto std_tanh = tanh(test_data, MathBackend::DEFAULT); auto mkl_tanh = tanh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] tanh MKL accuracy validated\n"; .. _example-top_level-tanh-697: .. dropdown:: tanh (np_test_2_all.cpp:1035) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1025 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; // Test tanh auto std_tanh = tanh(test_data, MathBackend::DEFAULT); auto mkl_tanh = tanh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] tanh MKL accuracy validated\n"; .. _example-top_level-tanh-698: .. dropdown:: tanh (np_test_2_all.cpp:1035) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1025 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; // Test tanh auto std_tanh = tanh(test_data, MathBackend::DEFAULT); auto mkl_tanh = tanh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] tanh MKL accuracy validated\n"; .. _example-top_level-tanh-699: .. dropdown:: tanh (np_test_2_all.cpp:1035) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1025 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; // Test tanh auto std_tanh = tanh(test_data, MathBackend::DEFAULT); auto mkl_tanh = tanh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] tanh MKL accuracy validated\n"; .. _example-top_level-tanh-700: .. dropdown:: tanh (np_test_2_all.cpp:1035) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1025 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; // Test tanh auto std_tanh = tanh(test_data, MathBackend::DEFAULT); auto mkl_tanh = tanh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] tanh MKL accuracy validated\n"; .. _example-top_level-tanh-701: .. dropdown:: tanh (np_test_2_all.cpp:1035) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1025 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; // Test tanh auto std_tanh = tanh(test_data, MathBackend::DEFAULT); auto mkl_tanh = tanh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] tanh MKL accuracy validated\n"; .. _example-top_level-tanh-702: .. dropdown:: tanh (np_test_2_all.cpp:1035) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1025 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; // Test tanh auto std_tanh = tanh(test_data, MathBackend::DEFAULT); auto mkl_tanh = tanh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] tanh MKL accuracy validated\n"; .. _example-top_level-tanh-703: .. dropdown:: tanh (np_test_2_all.cpp:1035) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1025 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; // Test tanh auto std_tanh = tanh(test_data, MathBackend::DEFAULT); auto mkl_tanh = tanh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] tanh MKL accuracy validated\n"; .. _example-top_level-tanh-704: .. dropdown:: tanh (np_test_2_all.cpp:1035) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1025 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; // Test tanh auto std_tanh = tanh(test_data, MathBackend::DEFAULT); auto mkl_tanh = tanh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] tanh MKL accuracy validated\n"; .. _example-top_level-tanh-705: .. dropdown:: tanh (np_test_2_all.cpp:1035) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1025 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; // Test tanh auto std_tanh = tanh(test_data, MathBackend::DEFAULT); auto mkl_tanh = tanh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] tanh MKL accuracy validated\n"; .. _example-top_level-tanh-706: .. dropdown:: tanh (np_test_2_all.cpp:1035) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1025 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; // Test tanh auto std_tanh = tanh(test_data, MathBackend::DEFAULT); auto mkl_tanh = tanh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] tanh MKL accuracy validated\n"; .. _example-top_level-tanh-707: .. dropdown:: tanh (np_test_2_all.cpp:1035) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1025 :emphasize-lines: 11 for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_cosh.getElementAt({ i }), std_cosh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] cosh MKL accuracy validated\n"; // Test tanh auto std_tanh = tanh(test_data, MathBackend::DEFAULT); auto mkl_tanh = tanh(test_data, MathBackend::MKL); for (size_t i = 0; i < test_size; ++i) { if (!(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))) { std::string description = std::string("testHyperbolicMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(mkl_tanh.getElementAt({ i }), std_tanh.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] tanh MKL accuracy validated\n"; .. _example-top_level-true_divide-708: .. dropdown:: true_divide (np_test_3_all.cpp:17109) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17099 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void np_test_missing_math_functions_true_divide() { std::cout << "========= true_divide: true division (always float) ======================="; // explicit namespace to avoid name clashes numpy::NDArray a = numpy::arange(10.0, 16.0, 1.0); numpy::NDArray b = numpy::arange(3.0, 9.0, 1.0); auto result = numpy::true_divide(a, b); // Verify values: [10,11,12,13,14,15] / [3,4,5,6,7,8] auto pass = true; double expected[] = { 10.0 / 3.0, 11.0 / 4.0, 12.0 / 5.0, 13.0 / 6.0, 14.0 / 7.0, 15.0 / 8.0 }; for (size_t i = 0; i < 6 && pass; ++i) { double val = result.getElementAt({ i }); double exp = expected[i]; if (std::abs(val - exp) > 1e-10) { pass = false; } .. _example-top_level-true_divide-709: .. dropdown:: true_divide (np_test_3_all.cpp:17109) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17099 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void np_test_missing_math_functions_true_divide() { std::cout << "========= true_divide: true division (always float) ======================="; // explicit namespace to avoid name clashes numpy::NDArray a = numpy::arange(10.0, 16.0, 1.0); numpy::NDArray b = numpy::arange(3.0, 9.0, 1.0); auto result = numpy::true_divide(a, b); // Verify values: [10,11,12,13,14,15] / [3,4,5,6,7,8] auto pass = true; double expected[] = { 10.0 / 3.0, 11.0 / 4.0, 12.0 / 5.0, 13.0 / 6.0, 14.0 / 7.0, 15.0 / 8.0 }; for (size_t i = 0; i < 6 && pass; ++i) { double val = result.getElementAt({ i }); double exp = expected[i]; if (std::abs(val - exp) > 1e-10) { pass = false; } .. _example-top_level-trunc-710: .. dropdown:: trunc (np_test_2_all.cpp:5749) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5739 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ceil function works correctly\n"; // Test trunc auto trunc_result = trunc(values); if (!(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-trunc-711: .. dropdown:: trunc (np_test_2_all.cpp:5749) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5739 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ceil function works correctly\n"; // Test trunc auto trunc_result = trunc(values); if (!(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-trunc-712: .. dropdown:: trunc (np_test_2_all.cpp:5749) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5739 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ceil function works correctly\n"; // Test trunc auto trunc_result = trunc(values); if (!(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-trunc-713: .. dropdown:: trunc (np_test_2_all.cpp:5749) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5739 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ceil function works correctly\n"; // Test trunc auto trunc_result = trunc(values); if (!(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-trunc-714: .. dropdown:: trunc (np_test_2_all.cpp:5749) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5739 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ceil function works correctly\n"; // Test trunc auto trunc_result = trunc(values); if (!(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-trunc-715: .. dropdown:: trunc (np_test_2_all.cpp:5749) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5739 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ceil function works correctly\n"; // Test trunc auto trunc_result = trunc(values); if (!(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-trunc-716: .. dropdown:: trunc (np_test_2_all.cpp:5749) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5739 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ceil function works correctly\n"; // Test trunc auto trunc_result = trunc(values); if (!(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-trunc-717: .. dropdown:: trunc (np_test_2_all.cpp:5749) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5739 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ceil function works correctly\n"; // Test trunc auto trunc_result = trunc(values); if (!(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-trunc-718: .. dropdown:: trunc (np_test_2_all.cpp:5749) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5739 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ceil function works correctly\n"; // Test trunc auto trunc_result = trunc(values); if (!(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-trunc-719: .. dropdown:: trunc (np_test_2_all.cpp:5749) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5739 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ceil function works correctly\n"; // Test trunc auto trunc_result = trunc(values); if (!(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-trunc-720: .. dropdown:: trunc (np_test_2_all.cpp:5749) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5739 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ceil function works correctly\n"; // Test trunc auto trunc_result = trunc(values); if (!(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 0 }), std::trunc(-2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))) { std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(trunc_result.getElementAt({ 5 }), std::trunc(2.7)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-average-721: .. dropdown:: average (np_test_1_all.cpp:23870) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23860 :emphasize-lines: 11 auto sum_keepdims = sum(array2d, -1, true); // axis=-1, keepdims=True if (!((sum_keepdims.getShape() == std::vector{4, 1}))) { std::string description = std::string("testStatsFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((sum_keepdims.getShape() == std::vector{4, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] sum function with keepdims parameter works correctly\n"; // Test new functions: average, nanmean, nanstd auto weights = createFloat64Array({ 4 }, 1.0); auto avg_result = average(array2d, 0, &weights); // With weights auto avg_no_weights = average(array2d, 0); // No weights if (!((avg_result.getShape() == std::vector{5}))) { std::string description = std::string("testStatsFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((avg_result.getShape() == std::vector{5}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(avg_no_weights.getShape() == avg_result.getShape())) { std::string description = std::string("testStatsFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(avg_no_weights.getShape() == avg_result.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-average-722: .. dropdown:: average (np_test_1_all.cpp:23870) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23860 :emphasize-lines: 11 auto sum_keepdims = sum(array2d, -1, true); // axis=-1, keepdims=True if (!((sum_keepdims.getShape() == std::vector{4, 1}))) { std::string description = std::string("testStatsFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((sum_keepdims.getShape() == std::vector{4, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] sum function with keepdims parameter works correctly\n"; // Test new functions: average, nanmean, nanstd auto weights = createFloat64Array({ 4 }, 1.0); auto avg_result = average(array2d, 0, &weights); // With weights auto avg_no_weights = average(array2d, 0); // No weights if (!((avg_result.getShape() == std::vector{5}))) { std::string description = std::string("testStatsFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((avg_result.getShape() == std::vector{5}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(avg_no_weights.getShape() == avg_result.getShape())) { std::string description = std::string("testStatsFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(avg_no_weights.getShape() == avg_result.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-histogram-723: .. dropdown:: histogram (np_test_1_all.cpp:12124) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12114 :emphasize-lines: 11 void testHistogramAndBinning() { std::cout << "========= testHistogramAndBinning ======================="; // Create array with known distribution auto data = createInt32Array({ 10 }, 0); for (size_t i = 0; i < 10; ++i) { data.setElementAt({ i }, static_cast(i % 3)); // [0,1,2,0,1,2,0,1,2,0] } auto [counts, bin_edges] = histogram(data, 3); // Check histogram if (!(counts.getShape()[0] == 3)) { std::string description = std::string("testHistogramAndBinning():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(counts.getShape()[0] == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(bin_edges.getShape()[0] == 4)) { std::string description = std::string("testHistogramAndBinning():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(bin_edges.getShape()[0] == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-histogram2d-724: .. dropdown:: histogram2d (np_test_2_all.cpp:14501) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14491 :emphasize-lines: 11 numpy::NDArray x({ 10 }); numpy::NDArray y({ 10 }); // Set values: points in a 2x2 grid pattern for (size_t i = 0; i < 10; ++i) { x.setElementAt({ i }, static_cast(i % 5)); // 0-4 range y.setElementAt({ i }, static_cast(i / 5)); // 0-1 range } // Compute 2D histogram with 5 bins auto [hist, x_edges, y_edges] = numpy::histogram2d(x, y, 5); // Verify histogram shape auto hist_shape = hist.getShape(); bool pass = (hist_shape.size() == 2 && hist_shape[0] == 5 && hist_shape[1] == 5); if (!pass) { std::cout << " [FAIL] : histogram2d_basic : incorrect histogram shape"; throw std::runtime_error("histogram2d_basic failed: incorrect shape"); } .. _example-top_level-histogramdd-725: .. dropdown:: histogramdd (np_test_2_all.cpp:14626) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14616 :emphasize-lines: 11 sample.setElementAt({ 0, 0 }, 0.0); sample.setElementAt({ 0, 1 }, 0.0); sample.setElementAt({ 0, 2 }, 0.0); sample.setElementAt({ 1, 0 }, 1.0); sample.setElementAt({ 1, 1 }, 0.0); sample.setElementAt({ 1, 2 }, 0.0); sample.setElementAt({ 2, 0 }, 0.0); sample.setElementAt({ 2, 1 }, 1.0); sample.setElementAt({ 2, 2 }, 0.0); sample.setElementAt({ 3, 0 }, 1.0); sample.setElementAt({ 3, 1 }, 1.0); sample.setElementAt({ 3, 2 }, 0.0); sample.setElementAt({ 4, 0 }, 0.0); sample.setElementAt({ 4, 1 }, 0.0); sample.setElementAt({ 4, 2 }, 1.0); sample.setElementAt({ 5, 0 }, 1.0); sample.setElementAt({ 5, 1 }, 0.0); sample.setElementAt({ 5, 2 }, 1.0); sample.setElementAt({ 6, 0 }, 0.0); sample.setElementAt({ 6, 1 }, 1.0); sample.setElementAt({ 6, 2 }, 1.0); sample.setElementAt({ 7, 0 }, 1.0); sample.setElementAt({ 7, 1 }, 1.0); sample.setElementAt({ 7, 2 }, 1.0); // Compute 3D histogram with 2 bins per dimension auto [hist, edges] = numpy::histogramdd(sample, 2); // Verify histogram shape (2x2x2) auto hist_shape = hist.getShape(); bool pass = (hist_shape.size() == 3 && hist_shape[0] == 2 && hist_shape[1] == 2 && hist_shape[2] == 2); if (!pass) { std::cout << " [FAIL] : histogramdd_3d : incorrect histogram shape"; .. _example-top_level-max-726: .. dropdown:: max (np_test_1_all.cpp:7274) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7264 :emphasize-lines: 11 if (sizeof(uintp) == sizeof(void*)) { // std::cout << " -> uintp size matches pointer size"; } else { // std::cout << " ✗ uintp size doesn't match pointer size" << std::endl; } // Test range limits // std::cout << "Range Information:" << std::endl; // std::cout << " intp min: " << std::numeric_limits::min() << std::endl; // std::cout << " intp max: " << std::numeric_limits::max() << std::endl; // std::cout << " uintp max: " << std::numeric_limits::max() << std::endl; // std::cout << " longdouble digits: " << std::numeric_limits::digits << std::endl; std::cout << " -> tests passed" << std::endl; } void testComplexArithmeticExtendedTypes() { std::cout << "========= testComplexArithmeticExtendedTypes ======================="; clongdouble c1(3.0L, 4.0L); // 3 + 4i .. _example-top_level-max-727: .. dropdown:: max (np_test_1_all.cpp:7274) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7264 :emphasize-lines: 11 if (sizeof(uintp) == sizeof(void*)) { // std::cout << " -> uintp size matches pointer size"; } else { // std::cout << " ✗ uintp size doesn't match pointer size" << std::endl; } // Test range limits // std::cout << "Range Information:" << std::endl; // std::cout << " intp min: " << std::numeric_limits::min() << std::endl; // std::cout << " intp max: " << std::numeric_limits::max() << std::endl; // std::cout << " uintp max: " << std::numeric_limits::max() << std::endl; // std::cout << " longdouble digits: " << std::numeric_limits::digits << std::endl; std::cout << " -> tests passed" << std::endl; } void testComplexArithmeticExtendedTypes() { std::cout << "========= testComplexArithmeticExtendedTypes ======================="; clongdouble c1(3.0L, 4.0L); // 3 + 4i .. _example-top_level-maxarray-728: .. dropdown:: maxArray (np_test_1_all.cpp:234) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 224 :emphasize-lines: 11 array.setElementAt({1, 0}, -1.0); array.setElementAt({1, 1}, 0.0); array.setElementAt({1, 2}, 4.5); // std::cout << "Test array:" << std::endl; //array.printArray(); // std::cout << "Sum: " << array.sumArray() << std::endl; // std::cout << "Mean: " << array.meanArray() << std::endl; // std::cout << "Min: " << array.minArray() << std::endl; // std::cout << "Max: " << array.maxArray() << std::endl; std::cout << " -> tests passed" << std::endl; } void testReshapeAndFlatten() { std::cout << "========= testReshapeAndFlatten ======================="; auto range_array = NDArray::createRange(0, 12, 1); // std::cout << "Range array (0-11):" << std::endl; //range_array.printArray(); .. _example-top_level-maximum-729: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum-730: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum-731: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum-732: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum-733: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum-734: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum-735: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum-736: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum-737: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum-738: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum-739: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum-740: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum-741: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum-742: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum-743: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum-744: .. dropdown:: maximum (np_test_1_all.cpp:23787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23777 :emphasize-lines: 11 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-maximum_fill_value-745: .. dropdown:: maximum_fill_value (np_test_1_all.cpp:27643) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27633 :emphasize-lines: 11 int int_val = 42; double double_val = 3.14; int default_int = numpy::ma::default_fill_value(int_val); double default_double = numpy::ma::default_fill_value(double_val); // std::cout << " ma::default_fill_value(int): " << default_int << " (expected: 999999)" << std::endl; // std::cout << " ma::default_fill_value(double): " << default_double << " (expected: 1e+20)" << std::endl; int max_int = numpy::ma::maximum_fill_value(int_val); double max_double = numpy::ma::maximum_fill_value(double_val); // std::cout << " ma::maximum_fill_value(int): " << max_int << " (expected: INT_MAX)" << std::endl; // std::cout << " ma::maximum_fill_value(double): " << (std::isinf(max_double) ? "inf" : "finite") << " (expected: inf)" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_make_mask_none() { std::cout << "========= ma::make_mask_none(): create unmasked array ==="; .. _example-top_level-maximum_fill_value-746: .. dropdown:: maximum_fill_value (np_test_1_all.cpp:27643) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27633 :emphasize-lines: 11 int int_val = 42; double double_val = 3.14; int default_int = numpy::ma::default_fill_value(int_val); double default_double = numpy::ma::default_fill_value(double_val); // std::cout << " ma::default_fill_value(int): " << default_int << " (expected: 999999)" << std::endl; // std::cout << " ma::default_fill_value(double): " << default_double << " (expected: 1e+20)" << std::endl; int max_int = numpy::ma::maximum_fill_value(int_val); double max_double = numpy::ma::maximum_fill_value(double_val); // std::cout << " ma::maximum_fill_value(int): " << max_int << " (expected: INT_MAX)" << std::endl; // std::cout << " ma::maximum_fill_value(double): " << (std::isinf(max_double) ? "inf" : "finite") << " (expected: inf)" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_make_mask_none() { std::cout << "========= ma::make_mask_none(): create unmasked array ==="; .. _example-top_level-maximum_fill_value-747: .. dropdown:: maximum_fill_value (np_test_1_all.cpp:27643) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27633 :emphasize-lines: 11 int int_val = 42; double double_val = 3.14; int default_int = numpy::ma::default_fill_value(int_val); double default_double = numpy::ma::default_fill_value(double_val); // std::cout << " ma::default_fill_value(int): " << default_int << " (expected: 999999)" << std::endl; // std::cout << " ma::default_fill_value(double): " << default_double << " (expected: 1e+20)" << std::endl; int max_int = numpy::ma::maximum_fill_value(int_val); double max_double = numpy::ma::maximum_fill_value(double_val); // std::cout << " ma::maximum_fill_value(int): " << max_int << " (expected: INT_MAX)" << std::endl; // std::cout << " ma::maximum_fill_value(double): " << (std::isinf(max_double) ? "inf" : "finite") << " (expected: inf)" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_make_mask_none() { std::cout << "========= ma::make_mask_none(): create unmasked array ==="; .. _example-top_level-maximum_sctype-748: .. dropdown:: maximum_sctype (np_test_3_all.cpp:9083) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9073 :emphasize-lines: 11 if (obj2sctype("", DType::INT32) != DType::INT32) { std::cerr << "[FAIL] obj2sctype('', INT32) should return INT32 (default)"; throw std::runtime_error("obj2sctype empty string test failed"); } // std::cout << "[OK] obj2sctype('', INT32) = INT32 (default for empty string)" << std::endl; std::cout << " -> tests passed" << std::endl; } //============================================================================== // Test maximum_sctype() - Maximum precision type of same kind //============================================================================== void np_test_maximum_sctype_integers() { std::cout << "========= np_test_maximum_sctype_integers ======================="; // Test signed integers → INT64 if (maximum_sctype(DType::INT8) != DType::INT64) { std::cerr << "[FAIL] maximum_sctype(INT8) should return INT64"; throw std::runtime_error("maximum_sctype INT8 test failed"); } .. _example-top_level-mean-749: .. dropdown:: mean (np_test_1_all.cpp:11714) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11704 :emphasize-lines: 11 // Create test array auto array = createInt32Array({ 2, 3 }, 0); array.setElementAt({ 0, 0 }, 1); array.setElementAt({ 0, 1 }, 2); array.setElementAt({ 0, 2 }, 3); array.setElementAt({ 1, 0 }, 4); array.setElementAt({ 1, 1 }, 5); array.setElementAt({ 1, 2 }, 6); // Test mean without axis auto mean_all = mean(array); if (!(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))) { std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] mean (all elements) works correctly\n"; // Test mean along axis 0 auto mean_axis0 = mean(array, 0); if (!(mean_axis0.getShape()[0] == 3)) { .. _example-top_level-mean-750: .. dropdown:: mean (np_test_1_all.cpp:11714) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11704 :emphasize-lines: 11 // Create test array auto array = createInt32Array({ 2, 3 }, 0); array.setElementAt({ 0, 0 }, 1); array.setElementAt({ 0, 1 }, 2); array.setElementAt({ 0, 2 }, 3); array.setElementAt({ 1, 0 }, 4); array.setElementAt({ 1, 1 }, 5); array.setElementAt({ 1, 2 }, 6); // Test mean without axis auto mean_all = mean(array); if (!(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))) { std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] mean (all elements) works correctly\n"; // Test mean along axis 0 auto mean_axis0 = mean(array, 0); if (!(mean_axis0.getShape()[0] == 3)) { .. _example-top_level-meanarray-751: .. dropdown:: meanArray (np_test_1_all.cpp:232) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 222 :emphasize-lines: 11 array.setElementAt({0, 1}, 2.5); array.setElementAt({0, 2}, 3.5); array.setElementAt({1, 0}, -1.0); array.setElementAt({1, 1}, 0.0); array.setElementAt({1, 2}, 4.5); // std::cout << "Test array:" << std::endl; //array.printArray(); // std::cout << "Sum: " << array.sumArray() << std::endl; // std::cout << "Mean: " << array.meanArray() << std::endl; // std::cout << "Min: " << array.minArray() << std::endl; // std::cout << "Max: " << array.maxArray() << std::endl; std::cout << " -> tests passed" << std::endl; } void testReshapeAndFlatten() { std::cout << "========= testReshapeAndFlatten ======================="; auto range_array = NDArray::createRange(0, 12, 1); .. _example-top_level-median-752: .. dropdown:: median (np_test_1_all.cpp:11882) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11872 :emphasize-lines: 11 std::cout << "========= testMedianAndPercentiles ======================="; // Test median with odd number of elements auto odd_array = createInt32Array({ 5 }, 0); odd_array.setElementAt({ 0 }, 1); odd_array.setElementAt({ 1 }, 3); odd_array.setElementAt({ 2 }, 5); odd_array.setElementAt({ 3 }, 7); odd_array.setElementAt({ 4 }, 9); auto median_odd = median(odd_array); if (!(approx_equal(median_odd.getElementAt({ 0 }), 5.0, 1e-10))) { std::string description = std::string("testMedianAndPercentiles():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(median_odd.getElementAt({ 0 }), 5.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Median with odd count works correctly\n"; // Test median with even number of elements auto even_array = createInt32Array({ 4 }, 0); even_array.setElementAt({ 0 }, 1); .. _example-top_level-median-753: .. dropdown:: median (np_test_1_all.cpp:11882) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11872 :emphasize-lines: 11 std::cout << "========= testMedianAndPercentiles ======================="; // Test median with odd number of elements auto odd_array = createInt32Array({ 5 }, 0); odd_array.setElementAt({ 0 }, 1); odd_array.setElementAt({ 1 }, 3); odd_array.setElementAt({ 2 }, 5); odd_array.setElementAt({ 3 }, 7); odd_array.setElementAt({ 4 }, 9); auto median_odd = median(odd_array); if (!(approx_equal(median_odd.getElementAt({ 0 }), 5.0, 1e-10))) { std::string description = std::string("testMedianAndPercentiles():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(median_odd.getElementAt({ 0 }), 5.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Median with odd count works correctly\n"; // Test median with even number of elements auto even_array = createInt32Array({ 4 }, 0); even_array.setElementAt({ 0 }, 1); .. _example-top_level-min-754: .. dropdown:: min (np_test_1_all.cpp:2350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2340 :emphasize-lines: 11 if (i % 3 == 0) { large_array.setElementAt({i}, object_(static_cast(i))); } else if (i % 3 == 1) { large_array.setElementAt({i}, object_(static_cast(i) * 0.5)); } else { large_array.setElementAt({i}, object_(std::string("str") + std::to_string(i))); } } // Verify pattern for (size_t i = 0; i < std::min(large_size, size_t(100)); ++i) { // Check first 100 object_ obj = large_array.getElementAt({i}); if (i % 3 == 0) { if (!(obj.is_type())) { std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } else if (i % 3 == 1) { if (!(obj.is_type())) { std::string description = std::string("unknown_function():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type())"; .. _example-top_level-min-755: .. dropdown:: min (np_test_1_all.cpp:2350) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2340 :emphasize-lines: 11 if (i % 3 == 0) { large_array.setElementAt({i}, object_(static_cast(i))); } else if (i % 3 == 1) { large_array.setElementAt({i}, object_(static_cast(i) * 0.5)); } else { large_array.setElementAt({i}, object_(std::string("str") + std::to_string(i))); } } // Verify pattern for (size_t i = 0; i < std::min(large_size, size_t(100)); ++i) { // Check first 100 object_ obj = large_array.getElementAt({i}); if (i % 3 == 0) { if (!(obj.is_type())) { std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } else if (i % 3 == 1) { if (!(obj.is_type())) { std::string description = std::string("unknown_function():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type())"; .. _example-top_level-minarray-756: .. dropdown:: minArray (np_test_1_all.cpp:233) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 223 :emphasize-lines: 11 array.setElementAt({0, 2}, 3.5); array.setElementAt({1, 0}, -1.0); array.setElementAt({1, 1}, 0.0); array.setElementAt({1, 2}, 4.5); // std::cout << "Test array:" << std::endl; //array.printArray(); // std::cout << "Sum: " << array.sumArray() << std::endl; // std::cout << "Mean: " << array.meanArray() << std::endl; // std::cout << "Min: " << array.minArray() << std::endl; // std::cout << "Max: " << array.maxArray() << std::endl; std::cout << " -> tests passed" << std::endl; } void testReshapeAndFlatten() { std::cout << "========= testReshapeAndFlatten ======================="; auto range_array = NDArray::createRange(0, 12, 1); // std::cout << "Range array (0-11):" << std::endl; .. _example-top_level-min_scalar_type-757: .. dropdown:: min_scalar_type (np_test_3_all.cpp:7422) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7412 :emphasize-lines: 11 } //============================================================================== // MIN_SCALAR_TYPE TESTS //============================================================================== void np_test_min_scalar_type_integers() { std::cout << "========= np_test_min_scalar_type_integers ======================="; // Positive values if (min_scalar_type(static_cast(42)) != DType::INT8) { std::cerr << "[FAIL] min_scalar_type(42) should be INT8"; throw std::runtime_error("min_scalar_type test failed"); } // std::cout << "[OK] min_scalar_type(42) -> INT8" << std::endl; if (min_scalar_type(static_cast(200)) != DType::UINT8) { std::cerr << "[FAIL] min_scalar_type(200) should be UINT8"; throw std::runtime_error("min_scalar_type test failed"); } // std::cout << "[OK] min_scalar_type(200) -> UINT8 (> 127)" << std::endl; .. _example-top_level-min_scalar_type-758: .. dropdown:: min_scalar_type (np_test_3_all.cpp:7422) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7412 :emphasize-lines: 11 } //============================================================================== // MIN_SCALAR_TYPE TESTS //============================================================================== void np_test_min_scalar_type_integers() { std::cout << "========= np_test_min_scalar_type_integers ======================="; // Positive values if (min_scalar_type(static_cast(42)) != DType::INT8) { std::cerr << "[FAIL] min_scalar_type(42) should be INT8"; throw std::runtime_error("min_scalar_type test failed"); } // std::cout << "[OK] min_scalar_type(42) -> INT8" << std::endl; if (min_scalar_type(static_cast(200)) != DType::UINT8) { std::cerr << "[FAIL] min_scalar_type(200) should be UINT8"; throw std::runtime_error("min_scalar_type test failed"); } // std::cout << "[OK] min_scalar_type(200) -> UINT8 (> 127)" << std::endl; .. _example-top_level-min_scalar_type-759: .. dropdown:: min_scalar_type (np_test_3_all.cpp:7422) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7412 :emphasize-lines: 11 } //============================================================================== // MIN_SCALAR_TYPE TESTS //============================================================================== void np_test_min_scalar_type_integers() { std::cout << "========= np_test_min_scalar_type_integers ======================="; // Positive values if (min_scalar_type(static_cast(42)) != DType::INT8) { std::cerr << "[FAIL] min_scalar_type(42) should be INT8"; throw std::runtime_error("min_scalar_type test failed"); } // std::cout << "[OK] min_scalar_type(42) -> INT8" << std::endl; if (min_scalar_type(static_cast(200)) != DType::UINT8) { std::cerr << "[FAIL] min_scalar_type(200) should be UINT8"; throw std::runtime_error("min_scalar_type test failed"); } // std::cout << "[OK] min_scalar_type(200) -> UINT8 (> 127)" << std::endl; .. _example-top_level-minimum-760: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum-761: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum-762: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum-763: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum-764: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum-765: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum-766: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum-767: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum-768: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum-769: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum-770: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum-771: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum-772: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum-773: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum-774: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum-775: .. dropdown:: minimum (np_test_1_all.cpp:23788) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23778 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Rounding functions with decimals parameter work correctly\n"; // Test new functions auto deg_array = linspace(0.0, 180.0, 5); auto rad_result = deg2rad(deg_array); auto deg_result = rad2deg(rad_result); auto maximum_result = maximum(array, array2); auto minimum_result = minimum(array, array2); // std::cout << "[OK] New utility functions have correct signatures\n"; // Test scalar arithmetic functions auto add_result = add(array, 5.0); auto multiply_result = multiply(array, 2.0); if (!(add_result.getShape() == array.getShape())) { std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(add_result.getShape() == array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-minimum_fill_value-776: .. dropdown:: minimum_fill_value (np_test_5_all.cpp:3869) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3859 :emphasize-lines: 11 void np_test_minimum_fill_value() { std::cout << "========= minimum_fill_value ======================="; // Test with double array numpy::NDArray arr_double({ 3 }); arr_double.setElementAt({ 0 }, 1.0); arr_double.setElementAt({ 1 }, 2.0); arr_double.setElementAt({ 2 }, 3.0); numpy::MaskedArray ma_double(arr_double); auto min_fill_double = numpy::minimum_fill_value(ma_double); // For doubles, minimum fill value should be a very small negative number if (min_fill_double >= 0) { std::cout << " [FAIL] : in np_test_minimum_fill_value() : Double minimum should be negative"; throw std::runtime_error("Test failed"); } // Test with int32 array numpy::NDArray arr_int({ 3 }); arr_int.setElementAt({ 0 }, 1); .. _example-top_level-minimum_fill_value-777: .. dropdown:: minimum_fill_value (np_test_5_all.cpp:3869) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3859 :emphasize-lines: 11 void np_test_minimum_fill_value() { std::cout << "========= minimum_fill_value ======================="; // Test with double array numpy::NDArray arr_double({ 3 }); arr_double.setElementAt({ 0 }, 1.0); arr_double.setElementAt({ 1 }, 2.0); arr_double.setElementAt({ 2 }, 3.0); numpy::MaskedArray ma_double(arr_double); auto min_fill_double = numpy::minimum_fill_value(ma_double); // For doubles, minimum fill value should be a very small negative number if (min_fill_double >= 0) { std::cout << " [FAIL] : in np_test_minimum_fill_value() : Double minimum should be negative"; throw std::runtime_error("Test failed"); } // Test with int32 array numpy::NDArray arr_int({ 3 }); arr_int.setElementAt({ 0 }, 1); .. _example-top_level-minimum_fill_value-778: .. dropdown:: minimum_fill_value (np_test_5_all.cpp:3869) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3859 :emphasize-lines: 11 void np_test_minimum_fill_value() { std::cout << "========= minimum_fill_value ======================="; // Test with double array numpy::NDArray arr_double({ 3 }); arr_double.setElementAt({ 0 }, 1.0); arr_double.setElementAt({ 1 }, 2.0); arr_double.setElementAt({ 2 }, 3.0); numpy::MaskedArray ma_double(arr_double); auto min_fill_double = numpy::minimum_fill_value(ma_double); // For doubles, minimum fill value should be a very small negative number if (min_fill_double >= 0) { std::cout << " [FAIL] : in np_test_minimum_fill_value() : Double minimum should be negative"; throw std::runtime_error("Test failed"); } // Test with int32 array numpy::NDArray arr_int({ 3 }); arr_int.setElementAt({ 0 }, 1); .. _example-top_level-mintypecode-779: .. dropdown:: mintypecode (np_test_3_all.cpp:9158) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9148 :emphasize-lines: 11 if (maximum_sctype(DType::BOOL) != DType::BOOL) { std::cerr << "[FAIL] maximum_sctype(BOOL) should return BOOL"; throw std::runtime_error("maximum_sctype BOOL test failed"); } // std::cout << "[OK] maximum_sctype(BOOL) = BOOL" << std::endl; std::cout << " -> tests passed" << std::endl; } //============================================================================== // Test mintypecode() - Minimum type code from character string //============================================================================== void np_test_mintypecode_same_type() { std::cout << "========= np_test_mintypecode_same_type ======================="; // Test same type promotion if (mintypecode("ii") != 'i') { std::cerr << "[FAIL] mintypecode('ii') should return 'i'"; throw std::runtime_error("mintypecode 'ii' test failed"); } .. _example-top_level-nan_to_num-780: .. dropdown:: nan_to_num (np_test_5_all.cpp:3443) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3433 :emphasize-lines: 11 // Create array with NaN and Inf values numpy::NDArray arr({ 6 }); arr.setElementAt({ 0 }, 1.0); arr.setElementAt({ 1 }, NaN); arr.setElementAt({ 2 }, 3.0); arr.setElementAt({ 3 }, Inf); arr.setElementAt({ 4 }, 5.0); arr.setElementAt({ 5 }, -Inf); // Replace with defaults: NaN->0, Inf->max, -Inf->lowest auto result = numpy::nan_to_num(arr); // Check that NaN became 0 if (result.getElementAt({ 1 }) != 0.0) { std::cout << " [FAIL] : in np_test_nan_to_num() : NaN not replaced with 0, got " << result.getElementAt({ 1 }); throw std::runtime_error("Test failed"); } // Check that +Inf became max if (!std::isfinite(result.getElementAt({ 3 })) || result.getElementAt({ 3 }) <= 0) { std::cout << " [FAIL] : in np_test_nan_to_num() : +Inf not replaced properly"; .. _example-top_level-nan_to_num-781: .. dropdown:: nan_to_num (np_test_5_all.cpp:3443) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3433 :emphasize-lines: 11 // Create array with NaN and Inf values numpy::NDArray arr({ 6 }); arr.setElementAt({ 0 }, 1.0); arr.setElementAt({ 1 }, NaN); arr.setElementAt({ 2 }, 3.0); arr.setElementAt({ 3 }, Inf); arr.setElementAt({ 4 }, 5.0); arr.setElementAt({ 5 }, -Inf); // Replace with defaults: NaN->0, Inf->max, -Inf->lowest auto result = numpy::nan_to_num(arr); // Check that NaN became 0 if (result.getElementAt({ 1 }) != 0.0) { std::cout << " [FAIL] : in np_test_nan_to_num() : NaN not replaced with 0, got " << result.getElementAt({ 1 }); throw std::runtime_error("Test failed"); } // Check that +Inf became max if (!std::isfinite(result.getElementAt({ 3 })) || result.getElementAt({ 3 }) <= 0) { std::cout << " [FAIL] : in np_test_nan_to_num() : +Inf not replaced properly"; .. _example-top_level-nan_to_num-782: .. dropdown:: nan_to_num (np_test_5_all.cpp:3443) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3433 :emphasize-lines: 11 // Create array with NaN and Inf values numpy::NDArray arr({ 6 }); arr.setElementAt({ 0 }, 1.0); arr.setElementAt({ 1 }, NaN); arr.setElementAt({ 2 }, 3.0); arr.setElementAt({ 3 }, Inf); arr.setElementAt({ 4 }, 5.0); arr.setElementAt({ 5 }, -Inf); // Replace with defaults: NaN->0, Inf->max, -Inf->lowest auto result = numpy::nan_to_num(arr); // Check that NaN became 0 if (result.getElementAt({ 1 }) != 0.0) { std::cout << " [FAIL] : in np_test_nan_to_num() : NaN not replaced with 0, got " << result.getElementAt({ 1 }); throw std::runtime_error("Test failed"); } // Check that +Inf became max if (!std::isfinite(result.getElementAt({ 3 })) || result.getElementAt({ 3 }) <= 0) { std::cout << " [FAIL] : in np_test_nan_to_num() : +Inf not replaced properly"; .. _example-top_level-nanargmax-783: .. dropdown:: nanargmax (np_test_2_all.cpp:8338) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8328 :emphasize-lines: 11 } // std::cout << "[OK] argpartition: PASSED" << std::endl; } // Test nanargmin/nanargmax { std::vector data = { 3.0, std::numeric_limits::quiet_NaN(), 1.0, 4.0 }; try { size_t min_idx = numpy::nanargmin(data); size_t max_idx = numpy::nanargmax(data); if (min_idx != 2 || max_idx != 3) { // indices of 1.0 and 4.0 std::cout << " nanargmin/nanargmax: -> [FAIL]"; throw std::runtime_error("nanargmin/nanargmax: FAILED - incorrect indices returned"); } // std::cout << "[OK] nanargmin/nanargmax: PASSED" << std::endl; } catch (const std::runtime_error&) { throw; // Re-throw our test failures } .. _example-top_level-nanargmin-784: .. dropdown:: nanargmin (np_test_2_all.cpp:8337) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8327 :emphasize-lines: 11 throw std::runtime_error("argpartition: FAILED - array not properly partitioned"); } // std::cout << "[OK] argpartition: PASSED" << std::endl; } // Test nanargmin/nanargmax { std::vector data = { 3.0, std::numeric_limits::quiet_NaN(), 1.0, 4.0 }; try { size_t min_idx = numpy::nanargmin(data); size_t max_idx = numpy::nanargmax(data); if (min_idx != 2 || max_idx != 3) { // indices of 1.0 and 4.0 std::cout << " nanargmin/nanargmax: -> [FAIL]"; throw std::runtime_error("nanargmin/nanargmax: FAILED - incorrect indices returned"); } // std::cout << "[OK] nanargmin/nanargmax: PASSED" << std::endl; } catch (const std::runtime_error&) { throw; // Re-throw our test failures .. _example-top_level-nanmax-785: .. dropdown:: nanmax (np_test_5_all.cpp:3216) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3206 :emphasize-lines: 11 // Create array with NaN values numpy::NDArray arr({ 6 }); arr.setElementAt({ 0 }, 5.0); arr.setElementAt({ 1 }, NaN); arr.setElementAt({ 2 }, 9.0); // Maximum arr.setElementAt({ 3 }, 2.0); arr.setElementAt({ 4 }, NaN); arr.setElementAt({ 5 }, 7.0); auto result = numpy::nanmax(arr); // Expected max: 9.0 if (result.getSize() != 1 || std::abs(result.getElementAt({ 0 }) - 9.0) > 1e-10) { std::cout << " [FAIL] : in np_test_nanmax() : Expected 9.0, got " << result.getElementAt({ 0 }); throw std::runtime_error("Test failed"); } // Test with no NaN numpy::NDArray no_nan({ 4 }); no_nan.setElementAt({ 0 }, 9.0); .. _example-top_level-nanmean-786: .. dropdown:: nanmean (np_test_1_all.cpp:23889) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23879 :emphasize-lines: 11 std::string description = std::string("testStatsFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(avg_no_weights.getShape() == avg_result.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] average function with optional weights works correctly\n"; // Test NaN-aware functions auto float_array = createFloat32Array({ 3, 3 }, 1.0f); float_array.setElementAt({ 1, 1 }, std::numeric_limits::quiet_NaN()); auto nanmean_result = nanmean(float_array, 0); auto nanstd_result = nanstd(float_array, 1, 0, true); if (!((nanmean_result.getShape() == std::vector{3}))) { std::string description = std::string("testStatsFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((nanmean_result.getShape() == std::vector{3}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!((nanstd_result.getShape() == std::vector{3, 1}))) { std::string description = std::string("testStatsFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((nanstd_result.getShape() == std::vector{3, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-nanmedian-787: .. dropdown:: nanmedian (np_test_5_all.cpp:3255) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3245 :emphasize-lines: 11 // Odd length array with NaN numpy::NDArray arr_odd({ 7 }); arr_odd.setElementAt({ 0 }, 1.0); arr_odd.setElementAt({ 1 }, NaN); arr_odd.setElementAt({ 2 }, 3.0); arr_odd.setElementAt({ 3 }, 5.0); // Median of [1, 3, 5, 7, 9] = 5 arr_odd.setElementAt({ 4 }, 7.0); arr_odd.setElementAt({ 5 }, NaN); arr_odd.setElementAt({ 6 }, 9.0); auto result_odd = numpy::nanmedian(arr_odd); // Expected median: 5.0 if (result_odd.getSize() != 1 || std::abs(result_odd.getElementAt({ 0 }) - 5.0) > 1e-10) { std::cout << " [FAIL] : in np_test_nanmedian() : Expected 5.0, got " << result_odd.getElementAt({ 0 }); throw std::runtime_error("Test failed"); } // Even length array with NaN numpy::NDArray arr_even({ 6 }); arr_even.setElementAt({ 0 }, 2.0); .. _example-top_level-nanmin-788: .. dropdown:: nanmin (np_test_5_all.cpp:3178) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3168 :emphasize-lines: 11 // Create array with NaN values numpy::NDArray arr({ 6 }); arr.setElementAt({ 0 }, 5.0); arr.setElementAt({ 1 }, NaN); arr.setElementAt({ 2 }, 2.0); // Minimum arr.setElementAt({ 3 }, 8.0); arr.setElementAt({ 4 }, NaN); arr.setElementAt({ 5 }, 3.0); auto result = numpy::nanmin(arr); // Expected min: 2.0 if (result.getSize() != 1 || std::abs(result.getElementAt({ 0 }) - 2.0) > 1e-10) { std::cout << " [FAIL] : in np_test_nanmin() : Expected 2.0, got " << result.getElementAt({ 0 }); throw std::runtime_error("Test failed"); } // Test with no NaN numpy::NDArray no_nan({ 4 }); no_nan.setElementAt({ 0 }, 9.0); .. _example-top_level-nanpercentile-789: .. dropdown:: nanpercentile (np_test_5_all.cpp:3347) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3337 :emphasize-lines: 11 arr.setElementAt({ 4 }, 4.0); arr.setElementAt({ 5 }, 5.0); arr.setElementAt({ 6 }, NaN); arr.setElementAt({ 7 }, 6.0); arr.setElementAt({ 8 }, 7.0); arr.setElementAt({ 9 }, 8.0); arr.setElementAt({ 10 }, 9.0); arr.setElementAt({ 11 }, 10.0); // Test 50th percentile (median) auto result_50 = numpy::nanpercentile(arr, 50.0); // Expected: median of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] = 5.5 if (result_50.getSize() != 1 || std::abs(result_50.getElementAt({ 0 }) - 5.5) > 0.5) { std::cout << " [FAIL] : in np_test_nanpercentile() : Expected ~5.5, got " << result_50.getElementAt({ 0 }); throw std::runtime_error("Test failed"); } // Test 0th percentile (minimum) auto result_0 = numpy::nanpercentile(arr, 0.0); .. _example-top_level-nanprod-790: .. dropdown:: nanprod (np_test_3_all.cpp:17169) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17159 :emphasize-lines: 11 std::cout << "========= nanprod: product ignoring NaN ======================="; // explicit namespace to avoid name clashes numpy::NDArray a({ 5 }); a.setElementAt({ 0 }, 1.0); a.setElementAt({ 1 }, 2.0); a.setElementAt({ 2 }, std::numeric_limits::quiet_NaN()); a.setElementAt({ 3 }, 3.0); a.setElementAt({ 4 }, 4.0); numpy::NDArray result = numpy::nanprod(a); // Verify value: 1*2*3*4 = 24 (ignoring NaN) auto pass = true; double expected = 24.0; double val = result.getElementAt({ 0 }); if (std::abs(val - expected) > 1e-10) { pass = false; } if (!pass) { .. _example-top_level-nanquantile-791: .. dropdown:: nanquantile (np_test_5_all.cpp:3398) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3388 :emphasize-lines: 11 arr.setElementAt({ 4 }, 4.0); arr.setElementAt({ 5 }, 5.0); arr.setElementAt({ 6 }, NaN); arr.setElementAt({ 7 }, 6.0); arr.setElementAt({ 8 }, 7.0); arr.setElementAt({ 9 }, 8.0); arr.setElementAt({ 10 }, 9.0); arr.setElementAt({ 11 }, 10.0); // Test 0.5 quantile (median) - equivalent to 50th percentile auto result_0_5 = numpy::nanquantile(arr, 0.5); // Expected: median of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] = 5.5 if (result_0_5.getSize() != 1 || std::abs(result_0_5.getElementAt({ 0 }) - 5.5) > 0.5) { std::cout << " [FAIL] : in np_test_nanquantile() : Expected ~5.5, got " << result_0_5.getElementAt({ 0 }); throw std::runtime_error("Test failed"); } // Test 0.0 quantile (minimum) auto result_0_0 = numpy::nanquantile(arr, 0.0); .. _example-top_level-nanstd-792: .. dropdown:: nanstd (np_test_1_all.cpp:23890) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23880 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] average function with optional weights works correctly\n"; // Test NaN-aware functions auto float_array = createFloat32Array({ 3, 3 }, 1.0f); float_array.setElementAt({ 1, 1 }, std::numeric_limits::quiet_NaN()); auto nanmean_result = nanmean(float_array, 0); auto nanstd_result = nanstd(float_array, 1, 0, true); if (!((nanmean_result.getShape() == std::vector{3}))) { std::string description = std::string("testStatsFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((nanmean_result.getShape() == std::vector{3}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!((nanstd_result.getShape() == std::vector{3, 1}))) { std::string description = std::string("testStatsFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((nanstd_result.getShape() == std::vector{3, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-nansum-793: .. dropdown:: nansum (np_test_5_all.cpp:3141) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3131 :emphasize-lines: 11 // Create array with NaN values numpy::NDArray arr({ 6 }); arr.setElementAt({ 0 }, 1.0); arr.setElementAt({ 1 }, NaN); arr.setElementAt({ 2 }, 3.0); arr.setElementAt({ 3 }, 4.0); arr.setElementAt({ 4 }, NaN); arr.setElementAt({ 5 }, 6.0); auto result = numpy::nansum(arr); // Expected sum: 1 + 3 + 4 + 6 = 14 if (result.getSize() != 1 || std::abs(result.getElementAt({ 0 }) - 14.0) > 1e-10) { std::cout << " [FAIL] : in np_test_nansum() : Expected 14, got " << result.getElementAt({ 0 }); throw std::runtime_error("Test failed"); } // Test with no NaN numpy::NDArray no_nan({ 3 }); no_nan.setElementAt({ 0 }, 1.0); .. _example-top_level-nanvar-794: .. dropdown:: nanvar (np_test_5_all.cpp:3299) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3289 :emphasize-lines: 11 // Values: [1, 2, 3, 4, 5] (without NaN) numpy::NDArray arr({ 7 }); arr.setElementAt({ 0 }, 1.0); arr.setElementAt({ 1 }, NaN); arr.setElementAt({ 2 }, 2.0); arr.setElementAt({ 3 }, 3.0); arr.setElementAt({ 4 }, NaN); arr.setElementAt({ 5 }, 4.0); arr.setElementAt({ 6 }, 5.0); auto result = numpy::nanvar(arr); // Mean = (1 + 2 + 3 + 4 + 5) / 5 = 3 // Variance = ((1-3)^2 + (2-3)^2 + (3-3)^2 + (4-3)^2 + (5-3)^2) / 5 // = (4 + 1 + 0 + 1 + 4) / 5 = 10 / 5 = 2.0 double expected = 2.0; if (result.getSize() != 1 || std::abs(result.getElementAt({ 0 }) - expected) > 1e-10) { std::cout << " [FAIL] : in np_test_nanvar() : Expected " << expected << ", got " << result.getElementAt({ 0 }); throw std::runtime_error("Test failed"); } .. _example-top_level-percentile-795: .. dropdown:: percentile (np_test_1_all.cpp:11911) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11901 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "[OK] Median with even count works correctly\n"; // Test percentiles auto perc_array = createInt32Array({ 10 }, 0); for (size_t i = 0; i < 10; ++i) { perc_array.setElementAt({ i }, static_cast(i + 1)); } // Test 50th percentile (should be median) auto perc50 = percentile(perc_array, 50.0); if (!(approx_equal(perc50.getElementAt({ 0 }), 5.5, 1e-10))) { std::string description = std::string("testMedianAndPercentiles():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(perc50.getElementAt({ 0 }), 5.5, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] 50th percentile works correctly\n"; // Test 25th percentile auto perc25 = percentile(perc_array, 25.0); .. _example-top_level-ptp-796: .. dropdown:: ptp (np_test_3_all.cpp:15685) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15675 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "[OK] median() with integers works correctly\n"; std::cout << " -> tests passed\n"; } void test_ptp() { std::cout << "========= test_ptp ===="; // Test ptp (peak-to-peak) auto data = createFloat64Array({ 5 }, 0.0); data.setElementAt({ 0 }, 10.0); data.setElementAt({ 1 }, 50.0); data.setElementAt({ 2 }, 30.0); data.setElementAt({ 3 }, 20.0); data.setElementAt({ 4 }, 40.0); auto mask = createBoolArray({ 5 }, false); MaskedArray ma(data, mask, -999.0); .. _example-top_level-ptp-797: .. dropdown:: ptp (np_test_3_all.cpp:15685) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15675 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "[OK] median() with integers works correctly\n"; std::cout << " -> tests passed\n"; } void test_ptp() { std::cout << "========= test_ptp ===="; // Test ptp (peak-to-peak) auto data = createFloat64Array({ 5 }, 0.0); data.setElementAt({ 0 }, 10.0); data.setElementAt({ 1 }, 50.0); data.setElementAt({ 2 }, 30.0); data.setElementAt({ 3 }, 20.0); data.setElementAt({ 4 }, 40.0); auto mask = createBoolArray({ 5 }, false); MaskedArray ma(data, mask, -999.0); .. _example-top_level-quantile-798: .. dropdown:: quantile (np_test_1_all.cpp:11929) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11919 :emphasize-lines: 11 // Test 25th percentile auto perc25 = percentile(perc_array, 25.0); if (!(approx_equal(perc25.getElementAt({ 0 }), 3.25, 1e-10))) { std::string description = std::string("testMedianAndPercentiles():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(perc25.getElementAt({ 0 }), 3.25, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] 25th percentile works correctly\n"; // Test quantile (equivalent to percentile/100) auto quant75 = quantile(perc_array, 0.75); auto perc75 = percentile(perc_array, 75.0); if (!(approx_equal(quant75.getElementAt({ 0 }), perc75.getElementAt({ 0 }), 1e-10))) { std::string description = std::string("testMedianAndPercentiles():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(quant75.getElementAt({ 0 }), perc75.getElementAt({ 0 }), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Quantile function works correctly\n"; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-std-799: .. dropdown:: std (np_test_1_all.cpp:11836) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11826 :emphasize-lines: 11 auto var_sample = var(array, std::nullopt, 1); // ddof=1 for sample variance double expected_sample_var = 1.25 * 4.0 / 3.0; // Bessel's correction if (!(approx_equal(var_sample.getElementAt({ 0 }), expected_sample_var, 1e-10))) { std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(var_sample.getElementAt({ 0 }), expected_sample_var, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Sample variance works correctly\n"; // Test standard deviation auto std_result = numpy::std(array, std::nullopt, 0); if (!(approx_equal(std_result.getElementAt({ 0 }), std::sqrt(expected_var), 1e-10))) { std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(std_result.getElementAt({ 0 }), std::sqrt(expected_var), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Standard deviation works correctly\n"; // Test along axis auto array2d = createFloat64Array({ 2, 2 }, 0); array2d.setElementAt({ 0, 0 }, 1.0); .. _example-top_level-std-800: .. dropdown:: std (np_test_1_all.cpp:11836) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11826 :emphasize-lines: 11 auto var_sample = var(array, std::nullopt, 1); // ddof=1 for sample variance double expected_sample_var = 1.25 * 4.0 / 3.0; // Bessel's correction if (!(approx_equal(var_sample.getElementAt({ 0 }), expected_sample_var, 1e-10))) { std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(var_sample.getElementAt({ 0 }), expected_sample_var, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Sample variance works correctly\n"; // Test standard deviation auto std_result = numpy::std(array, std::nullopt, 0); if (!(approx_equal(std_result.getElementAt({ 0 }), std::sqrt(expected_var), 1e-10))) { std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(std_result.getElementAt({ 0 }), std::sqrt(expected_var), 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Standard deviation works correctly\n"; // Test along axis auto array2d = createFloat64Array({ 2, 2 }, 0); array2d.setElementAt({ 0, 0 }, 1.0); .. _example-top_level-sum-801: .. dropdown:: sum (np_test_1_all.cpp:11766) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11756 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(mean_axis1.getElementAt({ 1 }), 5.0, 1e-10))) { std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_axis1.getElementAt({ 1 }), 5.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] mean along axis 1 works correctly\n"; // Test sum auto sum_all = sum(array); if (!(sum_all.getElementAt({ 0 }) == 21)) { std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sum_all.getElementAt({ 0 }) == 21)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] sum works correctly\n"; // Test min and max auto min_all = min(array); auto max_all = max(array); .. _example-top_level-sum-802: .. dropdown:: sum (np_test_1_all.cpp:11766) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11756 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(mean_axis1.getElementAt({ 1 }), 5.0, 1e-10))) { std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_axis1.getElementAt({ 1 }), 5.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] mean along axis 1 works correctly\n"; // Test sum auto sum_all = sum(array); if (!(sum_all.getElementAt({ 0 }) == 21)) { std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sum_all.getElementAt({ 0 }) == 21)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] sum works correctly\n"; // Test min and max auto min_all = min(array); auto max_all = max(array); .. _example-top_level-sumarray-803: .. dropdown:: sumArray (np_test_1_all.cpp:231) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 221 :emphasize-lines: 11 array.setElementAt({0, 0}, 1.5); array.setElementAt({0, 1}, 2.5); array.setElementAt({0, 2}, 3.5); array.setElementAt({1, 0}, -1.0); array.setElementAt({1, 1}, 0.0); array.setElementAt({1, 2}, 4.5); // std::cout << "Test array:" << std::endl; //array.printArray(); // std::cout << "Sum: " << array.sumArray() << std::endl; // std::cout << "Mean: " << array.meanArray() << std::endl; // std::cout << "Min: " << array.minArray() << std::endl; // std::cout << "Max: " << array.maxArray() << std::endl; std::cout << " -> tests passed" << std::endl; } void testReshapeAndFlatten() { std::cout << "========= testReshapeAndFlatten ======================="; .. _example-top_level-var-804: .. dropdown:: var (np_test_1_all.cpp:11816) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11806 :emphasize-lines: 11 std::cout << "========= testVarianceAndStandardDeviation ======================="; // Create test array with known variance auto array = createFloat64Array({ 4 }, 0); array.setElementAt({ 0 }, 1.0); array.setElementAt({ 1 }, 2.0); array.setElementAt({ 2 }, 3.0); array.setElementAt({ 3 }, 4.0); // Test variance (population) auto var_result = var(array, std::nullopt, 0); // ddof=0 for population variance double expected_var = 1.25; // Known variance for [1,2,3,4] if (!(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))) { std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Population variance works correctly\n"; // Test variance (sample) auto var_sample = var(array, std::nullopt, 1); // ddof=1 for sample variance .. _example-top_level-var-805: .. dropdown:: var (np_test_1_all.cpp:11816) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11806 :emphasize-lines: 11 std::cout << "========= testVarianceAndStandardDeviation ======================="; // Create test array with known variance auto array = createFloat64Array({ 4 }, 0); array.setElementAt({ 0 }, 1.0); array.setElementAt({ 1 }, 2.0); array.setElementAt({ 2 }, 3.0); array.setElementAt({ 3 }, 4.0); // Test variance (population) auto var_result = var(array, std::nullopt, 0); // ddof=0 for population variance double expected_var = 1.25; // Known variance for [1,2,3,4] if (!(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))) { std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Population variance works correctly\n"; // Test variance (sample) auto var_sample = var(array, std::nullopt, 1); // ddof=1 for sample variance .. _example-top_level-cholesky_accelerated-806: .. dropdown:: cholesky_accelerated (np_test_2_all.cpp:17287) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17277 :emphasize-lines: 11 // Create a symmetric positive-definite matrix // [[4, 2], [2, 3]] numpy::NDArray matrix({ 2, 2 }); matrix.setElementAt({ 0, 0 }, 4.0); matrix.setElementAt({ 0, 1 }, 2.0); matrix.setElementAt({ 1, 0 }, 2.0); matrix.setElementAt({ 1, 1 }, 3.0); try { auto L = numpy::mkl::lapack::cholesky_accelerated(matrix, false); // Check that L is lower triangular // L should be approximately [[2, 0], [1, sqrt(2)]] double l00 = L.getElementAt({ 0, 0 }); double l01 = L.getElementAt({ 0, 1 }); double l10 = L.getElementAt({ 1, 0 }); double l11 = L.getElementAt({ 1, 1 }); if (std::abs(l01) > 1e-10) { std::cout << " [FAIL] : L is not lower triangular"; .. _example-top_level-cholesky_decomposition-807: .. dropdown:: cholesky_decomposition (np_test_3_all.cpp:3890) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3880 :emphasize-lines: 11 matrix.setElementAt({ 1, 0 }, 2.0); matrix.setElementAt({ 1, 1 }, 3.0); matrix.setElementAt({ 1, 2 }, 0.5); matrix.setElementAt({ 2, 0 }, 1.0); matrix.setElementAt({ 2, 1 }, 0.5); matrix.setElementAt({ 2, 2 }, 2.0); // std::cout << "Test matrix:" << std::endl; //matrix.printArray(); auto chol_result = cholesky_decomposition(matrix); // std::cout << "Is positive definite: " << (chol_result.is_positive_definite ? "Yes" : "No") << std::endl; if (chol_result.is_positive_definite) { // std::cout << "L matrix:"; //chol_result.L.printArray(); // Verify L * L^T = A auto L_transpose = chol_result.L.transposeArray(); auto reconstructed = matmul(chol_result.L, L_transpose); // std::cout << "Reconstructed matrix (L * L^T):" << std::endl; .. _example-top_level-cholesky_decomposition_enhanced-808: .. dropdown:: cholesky_decomposition_enhanced (np_test_3_all.cpp:3954) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3944 :emphasize-lines: 11 // std::cout << "Testing " << n << "x" << n << " matrix..." << std::endl; // Test unblocked algorithm (backward compatibility) auto unblocked_result = cholesky_decomposition(matrix); // std::cout << "Unblocked algorithm: " << unblocked_result.factorization_time << " ms" << std::endl; // std::cout << "Algorithm used: " << unblocked_result.algorithm << std::endl; // std::cout << "Is positive definite: " << (unblocked_result.is_positive_definite ? "Yes" : "No") << std::endl; // std::cout << "Condition estimate: " << unblocked_result.condition_estimate << std::endl; // Test blocked algorithm auto blocked_result = cholesky_decomposition_enhanced(matrix, false, utils::machine_epsilon(), true); // std::cout << "Blocked algorithm: " << blocked_result.factorization_time << " ms" << std::endl; // std::cout << "Algorithm used: " << blocked_result.algorithm << std::endl; // std::cout << "Is positive definite: " << (blocked_result.is_positive_definite ? "Yes" : "No") << std::endl; // Verify both give same results (approximately) bool results_match = true; double max_diff = 0.0; for (size_t i = 0; i < n && results_match; ++i) { for (size_t j = 0; j <= i && results_match; ++j) { .. _example-top_level-det-809: .. dropdown:: det (np_test_2_all.cpp:4985) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4975 :emphasize-lines: 11 assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); assert_test(std::abs(inv(0, 1) - 1.0) < 1e-10, "Matrix inverse 0,1"); assert_test(std::abs(inv(1, 0) - 1.5) < 1e-10, "Matrix inverse 1,0"); assert_test(std::abs(inv(1, 1) - (-0.5)) < 1e-10, "Matrix inverse 1,1"); // Verify A * A^-1 = I .. _example-top_level-detect_delimiter-810: .. dropdown:: detect_delimiter (np_test_5_all.cpp:914) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 904 :emphasize-lines: 11 assert_condition(std::abs(val1 - 3.14159) < 1e-6, "parse_float failed for '3.14159'"); assert_condition(std::abs(val2 + 2.5) < 1e-6, "parse_float failed for '-2.5'"); assert_condition(std::abs(val3 - 1e-10) < 1e-15, "parse_float failed for '1e-10'"); // std::cout << " Tested float parsing" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_io_detect_delimiter() { std::cout << "========= detect_delimiter() utility ==========================="; // Test delimiter detection std::string csv_line = "1,2,3,4,5"; std::string tsv_line = "1\t2\t3\t4\t5"; std::string space_line = "1 2 3 4 5"; auto detect_delimiter = [](const std::string& line) -> char { if (line.find(',') != std::string::npos) return ','; if (line.find('\t') != std::string::npos) return '\t'; return ' '; .. _example-top_level-detect_value_type-811: .. dropdown:: detect_value_type (np_test_5_all.cpp:941) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 931 :emphasize-lines: 11 assert_condition(delim1 == ',', "Failed to detect comma delimiter"); assert_condition(delim2 == '\t', "Failed to detect tab delimiter"); assert_condition(delim3 == ' ', "Failed to detect space delimiter"); // std::cout << " Tested delimiter detection" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_io_detect_value_type() { std::cout << "========= detect_value_type() utility =========================="; // Test value type detection auto detect_value_type = [](const std::string& value) -> std::string { try { size_t pos; [[maybe_unused]] int result = std::stoi(value, &pos); if (pos == value.length()) return "int"; } catch (...) {} .. _example-top_level-dot_product-812: .. dropdown:: dot_product (np_test_5_all.cpp:2995) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2985 :emphasize-lines: 11 // ============================================================================ // VECTOR OPERATIONS TESTS // ============================================================================ void np_test_linalg_dot_product() { std::cout << "========= dot_product helper ======================="; // Test dot product std::vector a = { 1.0, 2.0, 3.0 }; std::vector b = { 4.0, 5.0, 6.0 }; double result = numpy::linalg::utils::dot_product(a.data(), b.data(), 3); // 1*4 + 2*5 + 3*6 = 4 + 10 + 18 = 32 bool passed = is_close(result, 32.0); if (!passed) { std::cout << " [FAIL] : in np_test_linalg_dot_product() : dot product " << result << " != expected 32.0"; throw std::runtime_error("np_test_linalg_dot_product failed: incorrect dot product"); } // std::cout << " dot_product([1,2,3], [4,5,6]) = " << result << " (expected 32)" << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-top_level-eig-813: .. dropdown:: eig (np_test_2_all.cpp:5113) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5103 :emphasize-lines: 11 } assert_test(lu_close, "LU decomposition accuracy"); } catch (...) { // std::cout << "LU decomposition test failed (expected for some matrices)"; } // Test eigenvalues for 2x2 matrix numpy::Matrix C("1 2; 2 1"); try { auto [eigenvals, eigenvecs] = numpy::eig(C); assert_test(eigenvals.size() == 2, "Eigenvalue count"); assert_test(eigenvecs.rows() == 2 && eigenvecs.cols() == 2, "Eigenvector dimensions"); // Check that eigenvalues are approximately 3 and -1 std::vector real_parts; for (const auto& val : eigenvals) { real_parts.push_back(val.real()); } std::sort(real_parts.begin(), real_parts.end()); .. _example-top_level-eig-814: .. dropdown:: eig (np_test_2_all.cpp:5113) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5103 :emphasize-lines: 11 } assert_test(lu_close, "LU decomposition accuracy"); } catch (...) { // std::cout << "LU decomposition test failed (expected for some matrices)"; } // Test eigenvalues for 2x2 matrix numpy::Matrix C("1 2; 2 1"); try { auto [eigenvals, eigenvecs] = numpy::eig(C); assert_test(eigenvals.size() == 2, "Eigenvalue count"); assert_test(eigenvecs.rows() == 2 && eigenvecs.cols() == 2, "Eigenvector dimensions"); // Check that eigenvalues are approximately 3 and -1 std::vector real_parts; for (const auto& val : eigenvals) { real_parts.push_back(val.real()); } std::sort(real_parts.begin(), real_parts.end()); .. _example-top_level-eig-815: .. dropdown:: eig (np_test_2_all.cpp:5113) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5103 :emphasize-lines: 11 } assert_test(lu_close, "LU decomposition accuracy"); } catch (...) { // std::cout << "LU decomposition test failed (expected for some matrices)"; } // Test eigenvalues for 2x2 matrix numpy::Matrix C("1 2; 2 1"); try { auto [eigenvals, eigenvecs] = numpy::eig(C); assert_test(eigenvals.size() == 2, "Eigenvalue count"); assert_test(eigenvecs.rows() == 2 && eigenvecs.cols() == 2, "Eigenvector dimensions"); // Check that eigenvalues are approximately 3 and -1 std::vector real_parts; for (const auto& val : eigenvals) { real_parts.push_back(val.real()); } std::sort(real_parts.begin(), real_parts.end()); .. _example-top_level-eig_accelerated-816: .. dropdown:: eig_accelerated (np_test_2_all.cpp:17243) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17233 :emphasize-lines: 11 for (size_t j = 0; j < 3; ++j) { matrix.setElementAt({ i, j }, 0.0); } } // Set diagonal elements matrix.setElementAt({ 0, 0 }, 1.0); matrix.setElementAt({ 1, 1 }, 2.0); matrix.setElementAt({ 2, 2 }, 3.0); try { auto result = numpy::mkl::lapack::eig_accelerated(matrix, true); // Check convergence if (!result.converged) { std::cout << " [FAIL] : Eigendecomposition did not converge"; throw std::runtime_error("np_test_mkl_linalg_eig_diagonal failed: did not converge"); } // Check shapes if (result.eigenvalues.getShape()[0] != 3) { std::cout << " [FAIL] : Expected 3 eigenvalues"; .. _example-top_level-eigh-817: .. dropdown:: eigh (np_test_1_all.cpp:24516) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 24506 :emphasize-lines: 11 return 1; } return 0; } } // Comprehensive test suite for NumPy eigh() and eigvalsh() functions #include #include #include #include "../numpy/np_linalg.h" // no using namespace in tests - to avoid name clashes namespace numpy_tests { .. _example-top_level-eigvals_accelerated-818: .. dropdown:: eigvals_accelerated (np_test_2_all.cpp:17197) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17187 :emphasize-lines: 11 for (size_t j = 0; j < 3; ++j) { matrix.setElementAt({ i, j }, 0.0); } } // Set diagonal elements matrix.setElementAt({ 0, 0 }, 1.0); matrix.setElementAt({ 1, 1 }, 2.0); matrix.setElementAt({ 2, 2 }, 3.0); try { auto eigenvalues = numpy::mkl::lapack::eigvals_accelerated(matrix); // Check that we got 3 eigenvalues if (eigenvalues.getShape()[0] != 3) { std::cout << " [FAIL] : Expected 3 eigenvalues, got " << eigenvalues.getShape()[0]; throw std::runtime_error("np_test_mkl_linalg_eigvals_diagonal failed: wrong number of eigenvalues"); } // For a diagonal matrix, eigenvalues should be the diagonal elements // Note: LAPACK may return them in any order // std::cout << " Eigenvalues: "; .. _example-top_level-einsum_path-819: .. dropdown:: einsum_path (np_test_1_all.cpp:26787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26777 :emphasize-lines: 11 // ============================================================================ // SUB-PHASE 6F: MISCELLANEOUS FUNCTIONS // ============================================================================ void test_misc_functions() { std::cout << "[6F] Miscellaneous Functions (7+ functions)"; // std::cout << "============================================" << std::endl; // Test einsum_path { auto [path, info] = numpy::einsum_path("ij,jk->ik", { {10, 20}, {20, 30} }); if (!(path.size() == 1)) { std::string description = std::string("test_misc_functions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(path.size() == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(path[0].first == 0 && path[0].second == 1)) { std::string description = std::string("test_misc_functions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(path[0].first == 0 && path[0].second == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-einsum_path-820: .. dropdown:: einsum_path (np_test_1_all.cpp:26787) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26777 :emphasize-lines: 11 // ============================================================================ // SUB-PHASE 6F: MISCELLANEOUS FUNCTIONS // ============================================================================ void test_misc_functions() { std::cout << "[6F] Miscellaneous Functions (7+ functions)"; // std::cout << "============================================" << std::endl; // Test einsum_path { auto [path, info] = numpy::einsum_path("ij,jk->ik", { {10, 20}, {20, 30} }); if (!(path.size() == 1)) { std::string description = std::string("test_misc_functions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(path.size() == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(path[0].first == 0 && path[0].second == 1)) { std::string description = std::string("test_misc_functions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(path[0].first == 0 && path[0].second == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-inner-821: .. dropdown:: inner (np_test_3_all.cpp:21007) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20997 :emphasize-lines: 11 // objects by value (not dangling pointers). void np_test_extract_ndarrays_2d() { std::cout << "========= extract_ndarrays_2d: extractNDArraysOfType from 2D ======================="; // Create 2x2 object array with NDArray elements std::vector shape = {2, 2}; numpy::NDArray arr(shape); for (size_t i = 0; i < 2; ++i) { for (size_t j = 0; j < 2; ++j) { numpy::NDArray inner({2}); inner.setElementAt({0}, static_cast(i)); inner.setElementAt({1}, static_cast(j)); arr.setElementAt({i, j}, numpy::object_(inner)); } } // Extract with flatten=true (should get all 4) auto all = numpy::NestedArray::extractObjectsFromArray(arr, true); // Count how many are NDArray .. _example-top_level-innerproduct-822: .. dropdown:: innerproduct (np_test_1_all.cpp:27564) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27554 :emphasize-lines: 11 auto ma2 = numpy::ma::masked_array(x2, mask2); auto result = numpy::ma::hypot(ma1, ma2); // std::cout << " ma::hypot([3,-,0], [4,0,-]): [" << result.data().getElementAt({ 0 }) // << ", -, -] (expected: [5, -, -])"; std::cout << " -> tests passed" << std::endl; } void test_innerproduct() { std::cout << "========= ma::innerproduct(): inner product with masks ==="; auto a = numpy::array({ 1.0, 2.0, 3.0, 4.0 }); auto b = numpy::array({ 5.0, 6.0, 7.0, 8.0 }); auto mask_a = numpy::array({ false, false, true, false }); auto mask_b = numpy::array({ false, false, false, true }); auto ma_a = numpy::ma::masked_array(a, mask_a); auto ma_b = numpy::ma::masked_array(b, mask_b); double result = numpy::ma::innerproduct(ma_a, ma_b); .. _example-top_level-inverse_iteration-823: .. dropdown:: inverse_iteration (np_test_3_all.cpp:3737) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3727 :emphasize-lines: 11 matrix.setElementAt({ 1, 1 }, 3.0); matrix.setElementAt({ 1, 2 }, -1.0); matrix.setElementAt({ 2, 0 }, 0.0); matrix.setElementAt({ 2, 1 }, -1.0); matrix.setElementAt({ 2, 2 }, 2.0); // std::cout << "Test matrix:" << std::endl; //matrix.printArray(); // Use inverse iteration with shift near 2.0 auto eigen_result = inverse_iteration(matrix, 2.1, 1000, 1e-10); // std::cout << "Converged: " << (eigen_result.converged ? "Yes" : "No") << std::endl; // std::cout << "Iterations: " << eigen_result.iterations << std::endl; // std::cout << "Eigenvalue near shift: " << eigen_result.eigenvalues.getElementAt({ 0 }) << std::endl; // std::cout << "Corresponding eigenvector:" << std::endl; //eigen_result.eigenvectors.printArray(); // Verify convergence if (!(eigen_result.converged)) { .. _example-top_level-lstsq-824: .. dropdown:: lstsq (np_test_2_all.cpp:5167) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5157 :emphasize-lines: 11 } catch (...) { // std::cout << "Linear system solve test failed (expected for some systems)"; } // Test least squares for overdetermined system numpy::Matrix A_over("1 1; 1 2; 1 3"); numpy::Matrix b_over("1; 2; 4"); try { auto x_ls = numpy::lstsq(A_over, b_over); assert_test(x_ls.rows() == 2 && x_ls.cols() == 1, "Least squares result dimensions"); // Just check that we get a result (actual verification would require residual calculation) } catch (...) { // std::cout << "Least squares test failed (expected for some systems)"; } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-lstsq-825: .. dropdown:: lstsq (np_test_2_all.cpp:5167) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5157 :emphasize-lines: 11 } catch (...) { // std::cout << "Linear system solve test failed (expected for some systems)"; } // Test least squares for overdetermined system numpy::Matrix A_over("1 1; 1 2; 1 3"); numpy::Matrix b_over("1; 2; 4"); try { auto x_ls = numpy::lstsq(A_over, b_over); assert_test(x_ls.rows() == 2 && x_ls.cols() == 1, "Least squares result dimensions"); // Just check that we get a result (actual verification would require residual calculation) } catch (...) { // std::cout << "Least squares test failed (expected for some systems)"; } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-lstsq_qr-826: .. dropdown:: lstsq_qr (np_test_2_all.cpp:7594) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7584 :emphasize-lines: 11 b.setElementAt({ 1 }, 3.0); // y=3 b.setElementAt({ 2 }, 5.0); // y=5 b.setElementAt({ 3 }, 7.0); // y=7 // std::cout << "Matrix A:" << std::endl; //A.printArray(); // std::cout << "Vector b:" << std::endl; //b.printArray(); // Test QR-based solution auto qr_result = lstsq_qr(A, b); // std::cout << "QR solution:" << std::endl; //qr_result.x.printArray(); // std::cout << "Rank: " << qr_result.rank << std::endl; // std::cout << "Converged: " << (qr_result.converged ? "Yes" : "No") << std::endl; // std::cout << "Residual: " << qr_result.residuals.getElementAt({ 0 }) << std::endl; // Expected solution: a=2, b=1 (perfect line fit) // std::cout << "Expected: a=2, b=1" << std::endl; // std::cout << "Got: a=" << qr_result.x.getElementAt({ 0, 0 }) << ", b=" << qr_result.x.getElementAt({ 1, 0 }) << std::endl; // std::cout << "Testing improved QR implementation (Householder reflections)"; .. _example-top_level-lstsq_qr-827: .. dropdown:: lstsq_qr (np_test_2_all.cpp:7594) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7584 :emphasize-lines: 11 b.setElementAt({ 1 }, 3.0); // y=3 b.setElementAt({ 2 }, 5.0); // y=5 b.setElementAt({ 3 }, 7.0); // y=7 // std::cout << "Matrix A:" << std::endl; //A.printArray(); // std::cout << "Vector b:" << std::endl; //b.printArray(); // Test QR-based solution auto qr_result = lstsq_qr(A, b); // std::cout << "QR solution:" << std::endl; //qr_result.x.printArray(); // std::cout << "Rank: " << qr_result.rank << std::endl; // std::cout << "Converged: " << (qr_result.converged ? "Yes" : "No") << std::endl; // std::cout << "Residual: " << qr_result.residuals.getElementAt({ 0 }) << std::endl; // Expected solution: a=2, b=1 (perfect line fit) // std::cout << "Expected: a=2, b=1" << std::endl; // std::cout << "Got: a=" << qr_result.x.getElementAt({ 0, 0 }) << ", b=" << qr_result.x.getElementAt({ 1, 0 }) << std::endl; // std::cout << "Testing improved QR implementation (Householder reflections)"; .. _example-top_level-lstsq_svd-828: .. dropdown:: lstsq_svd (np_test_2_all.cpp:7618) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7608 :emphasize-lines: 11 std::abs(qr_result.x.getElementAt({ 1, 0 }) - 1.0) < 1e-10; if (qr_accurate) { // std::cout << "[OK] QR solution is now accurate!"; } else { // std::cout << "[WARNING] QR solution still has accuracy issues" << std::endl; } // Test SVD-based solution auto svd_result = lstsq_svd(A, b); // std::cout << "SVD solution:" << std::endl; //svd_result.x.printArray(); // std::cout << "Rank: " << svd_result.rank << std::endl; // std::cout << "Condition number: " << svd_result.condition_number << std::endl; if (!(std::abs(svd_result.x.getElementAt({ 0, 0 }) - 2.0) < 1e-10)) { std::string description = std::string("test_overdetermined_system():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(svd_result.x.getElementAt({ 0, 0 }) - 2.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-lstsq_svd-829: .. dropdown:: lstsq_svd (np_test_2_all.cpp:7618) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7608 :emphasize-lines: 11 std::abs(qr_result.x.getElementAt({ 1, 0 }) - 1.0) < 1e-10; if (qr_accurate) { // std::cout << "[OK] QR solution is now accurate!"; } else { // std::cout << "[WARNING] QR solution still has accuracy issues" << std::endl; } // Test SVD-based solution auto svd_result = lstsq_svd(A, b); // std::cout << "SVD solution:" << std::endl; //svd_result.x.printArray(); // std::cout << "Rank: " << svd_result.rank << std::endl; // std::cout << "Condition number: " << svd_result.condition_number << std::endl; if (!(std::abs(svd_result.x.getElementAt({ 0, 0 }) - 2.0) < 1e-10)) { std::string description = std::string("test_overdetermined_system():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(svd_result.x.getElementAt({ 0, 0 }) - 2.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-matmul-830: .. dropdown:: matmul (np_test_1_all.cpp:15423) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15413 :emphasize-lines: 11 // Verify reconstruction: A = U * S * Vt // First create diagonal matrix from S NDArray S_diag({ 2, 2 }); for (size_t i = 0; i < 2; ++i) { for (size_t j = 0; j < 2; ++j) { S_diag.setElementAt({ i, j }, (i == j) ? svd_result.S.getElementAt({ i }) : 0.0); } } auto US = matmul(svd_result.U, S_diag); auto reconstructed = matmul(US, svd_result.Vt); // std::cout << "Reconstructed matrix (U * S * Vt):" << std::endl; //reconstructed.printArray(); // Check reconstruction error double max_error = 0.0; for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 2; ++j) { double error = std::abs(matrix.getElementAt({ i, j }) - reconstructed.getElementAt({ i, j })); .. _example-top_level-matmul_accelerated-831: .. dropdown:: matmul_accelerated (np_test_2_all.cpp:17665) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17655 :emphasize-lines: 11 A.setElementAt({ 1, 0 }, 3.0); A.setElementAt({ 1, 1 }, 4.0); numpy::NDArray B({ 2, 2 }); B.setElementAt({ 0, 0 }, 5.0); B.setElementAt({ 0, 1 }, 6.0); B.setElementAt({ 1, 0 }, 7.0); B.setElementAt({ 1, 1 }, 8.0); try { auto C = numpy::mkl::lapack::matmul_accelerated(A, B); double c00 = C.getElementAt({ 0, 0 }); double c01 = C.getElementAt({ 0, 1 }); double c10 = C.getElementAt({ 1, 0 }); double c11 = C.getElementAt({ 1, 1 }); // std::cout << " Result C:" << std::endl; // std::cout << " [[" << c00 << ", " << c01 << "]," << std::endl; // std::cout << " [" << c10 << ", " << c11 << "]]" << std::endl; .. _example-top_level-matrix_power-832: .. dropdown:: matrix_power (np_test_5_all.cpp:5327) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5317 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } // Test matrix_power - additional cases void np_test_matrix_power_extended() { std::cout << "========= matrix_power extended cases ======================="; numpy::NDArray A = numpy::array({ {2.0, 1.0}, {1.0, 2.0} }); // Test A^0 = Identity auto A0 = numpy::linalg::matrix_power(A, 0); bool is_identity = (std::abs(A0.getElementAt({ 0, 0 }) - 1.0) < 1e-10 && std::abs(A0.getElementAt({ 0, 1 }) - 0.0) < 1e-10 && std::abs(A0.getElementAt({ 1, 0 }) - 0.0) < 1e-10 && std::abs(A0.getElementAt({ 1, 1 }) - 1.0) < 1e-10); if (!is_identity) { std::cout << " [FAIL] : in np_test_matrix_power_extended() : A^0 != Identity"; throw std::runtime_error("Test failed"); } .. _example-top_level-matrix_power_symmetric_accelerated-833: .. dropdown:: matrix_power_symmetric_accelerated (np_test_2_all.cpp:17706) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17696 :emphasize-lines: 11 // Test with a simple symmetric matrix [[2, 1], [1, 2]] numpy::NDArray matrix({ 2, 2 }); matrix.setElementAt({ 0, 0 }, 2.0); matrix.setElementAt({ 0, 1 }, 1.0); matrix.setElementAt({ 1, 0 }, 1.0); matrix.setElementAt({ 1, 1 }, 2.0); try { // Test A^0 = I auto A0 = numpy::mkl::lapack::matrix_power_symmetric_accelerated(matrix, 0); if (std::abs(A0.getElementAt({ 0, 0 }) - 1.0) > 1e-10 || std::abs(A0.getElementAt({ 1, 1 }) - 1.0) > 1e-10) { std::cout << " [FAIL] : A^0 != I"; throw std::runtime_error("np_test_mkl_linalg_matrix_power failed: A^0"); } // std::cout << " [OK] A^0 = I" << std::endl; // Test A^1 = A auto A1 = numpy::mkl::lapack::matrix_power_symmetric_accelerated(matrix, 1); if (std::abs(A1.getElementAt({ 0, 0 }) - 2.0) > 1e-10) { .. _example-top_level-matrix_rank-834: .. dropdown:: matrix_rank (np_test_2_all.cpp:5133) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5123 :emphasize-lines: 11 assert_test(std::abs(real_parts[0] - (-1.0)) < 1e-10, "Eigenvalue 1"); assert_test(std::abs(real_parts[1] - 3.0) < 1e-10, "Eigenvalue 2"); } catch (...) { // std::cout << "Eigenvalue test failed (expected for some matrices)"; } // Test matrix rank numpy::Matrix D("1 2; 2 4"); // Rank 1 matrix size_t rank = numpy::matrix_rank(D); assert_test(rank <= 2, "Matrix rank bounds check"); std::cout << " -> tests passed" << std::endl; } /** * Test linear system solving */ void testMatrixSolvers() { std::cout << "========= testMatrixSolvers ======================="; .. _example-top_level-matrix_rank-835: .. dropdown:: matrix_rank (np_test_2_all.cpp:5133) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5123 :emphasize-lines: 11 assert_test(std::abs(real_parts[0] - (-1.0)) < 1e-10, "Eigenvalue 1"); assert_test(std::abs(real_parts[1] - 3.0) < 1e-10, "Eigenvalue 2"); } catch (...) { // std::cout << "Eigenvalue test failed (expected for some matrices)"; } // Test matrix rank numpy::Matrix D("1 2; 2 4"); // Rank 1 matrix size_t rank = numpy::matrix_rank(D); assert_test(rank <= 2, "Matrix rank bounds check"); std::cout << " -> tests passed" << std::endl; } /** * Test linear system solving */ void testMatrixSolvers() { std::cout << "========= testMatrixSolvers ======================="; .. _example-top_level-norm-836: .. dropdown:: norm (np_test_1_all.cpp:7964) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7954 :emphasize-lines: 11 void testComplex256FunctionsComplex256() { std::cout << "========= testComplex256FunctionsComplex256 ======================="; complex256 z(3.0L, 4.0L); // 3 + 4i // std::cout << "z = " << z << std::endl; // std::cout << "real(z) = " << z.real() << std::endl; // std::cout << "imag(z) = " << z.imag() << std::endl; // std::cout << "abs(z) = " << std::abs(z) << std::endl; // std::cout << "arg(z) = " << std::arg(z) << " radians" << std::endl; // std::cout << "norm(z) = " << std::norm(z) << std::endl; // std::cout << "conj(z) = " << std::conj(z) << std::endl; // Polar form auto magnitude = std::abs(z); auto phase = std::arg(z); auto polar_z = std::polar(magnitude, phase); // std::cout << "polar form: " << polar_z << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-norm1-837: .. dropdown:: norm1 (np_test_3_all.cpp:20313) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20303 :emphasize-lines: 11 numpy::NDArray dense({ 3, 3 }); dense.setElementAt({ 0, 0 }, 2.0); dense.setElementAt({ 0, 1 }, 1.0); dense.setElementAt({ 1, 1 }, 3.0); dense.setElementAt({ 1, 2 }, 1.0); dense.setElementAt({ 2, 2 }, 4.0); auto A = numpy::sparse::sparse(dense); double n1 = numpy::sparse::norm1(A); double ninf = numpy::sparse::norm_inf(A); double nfro = numpy::sparse::norm_fro(A); if (n1 < 0.0 || ninf < 0.0 || nfro < 0.0) { std::cout << " [FAIL] : in np_test_sparse_api_norms() : Norm computation failed"; throw std::runtime_error("np_test_sparse_api_norms failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-norm_fro-838: .. dropdown:: norm_fro (np_test_3_all.cpp:20315) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20305 :emphasize-lines: 11 dense.setElementAt({ 0, 0 }, 2.0); dense.setElementAt({ 0, 1 }, 1.0); dense.setElementAt({ 1, 1 }, 3.0); dense.setElementAt({ 1, 2 }, 1.0); dense.setElementAt({ 2, 2 }, 4.0); auto A = numpy::sparse::sparse(dense); double n1 = numpy::sparse::norm1(A); double ninf = numpy::sparse::norm_inf(A); double nfro = numpy::sparse::norm_fro(A); if (n1 < 0.0 || ninf < 0.0 || nfro < 0.0) { std::cout << " [FAIL] : in np_test_sparse_api_norms() : Norm computation failed"; throw std::runtime_error("np_test_sparse_api_norms failed"); } std::cout << " -> tests passed" << std::endl; } void np_test_sparse_api_solve() { .. _example-top_level-norm_inf-839: .. dropdown:: norm_inf (np_test_3_all.cpp:20314) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20304 :emphasize-lines: 11 numpy::NDArray dense({ 3, 3 }); dense.setElementAt({ 0, 0 }, 2.0); dense.setElementAt({ 0, 1 }, 1.0); dense.setElementAt({ 1, 1 }, 3.0); dense.setElementAt({ 1, 2 }, 1.0); dense.setElementAt({ 2, 2 }, 4.0); auto A = numpy::sparse::sparse(dense); double n1 = numpy::sparse::norm1(A); double ninf = numpy::sparse::norm_inf(A); double nfro = numpy::sparse::norm_fro(A); if (n1 < 0.0 || ninf < 0.0 || nfro < 0.0) { std::cout << " [FAIL] : in np_test_sparse_api_norms() : Norm computation failed"; throw std::runtime_error("np_test_sparse_api_norms failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-normalize_vector-840: .. dropdown:: normalize_vector (np_test_5_all.cpp:3049) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3039 :emphasize-lines: 11 // std::cout << " vector_norm_inf([-5,3,1,-7,2]) = " << result << " (expected 7)" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_linalg_normalize_vector() { std::cout << "========= normalize_vector helper ======================="; // Test vector normalization std::vector vec = { 3.0, 4.0 }; numpy::linalg::utils::normalize_vector(vec.data(), 2); // After normalization: [3/5, 4/5] = [0.6, 0.8] bool passed = is_close(vec[0], 0.6) && is_close(vec[1], 0.8); if (!passed) { std::cout << " [FAIL] : in np_test_linalg_normalize_vector() : normalized vector incorrect"; throw std::runtime_error("np_test_linalg_normalize_vector failed: incorrect normalization"); } // Check that norm is 1 double norm = numpy::linalg::utils::vector_norm_2(vec.data(), 2); .. _example-top_level-qr-841: .. dropdown:: qr (np_test_2_all.cpp:5064) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5054 :emphasize-lines: 11 /** * Test advanced matrix operations */ void testMatrixAdvancedOps() { std::cout << "========= testMatrixAdvancedOps ======================="; // Test QR decomposition for simple matrix numpy::Matrix A("1 1; 1 2; 0 1"); try { auto [Q, R] = numpy::qr(A); assert_test(Q.rows() == 3 && Q.cols() == 3, "QR decomposition Q dimensions"); assert_test(R.rows() == 3 && R.cols() == 2, "QR decomposition R dimensions"); // Verify Q * R ? A (approximately) auto QR = Q * R; bool qr_close = true; for (size_t i = 0; i < A.rows() && qr_close; ++i) { for (size_t j = 0; j < A.cols() && qr_close; ++j) { if (std::abs(QR(i, j) - A(i, j)) > 1e-6) { qr_close = false; .. _example-top_level-qr-842: .. dropdown:: qr (np_test_2_all.cpp:5064) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5054 :emphasize-lines: 11 /** * Test advanced matrix operations */ void testMatrixAdvancedOps() { std::cout << "========= testMatrixAdvancedOps ======================="; // Test QR decomposition for simple matrix numpy::Matrix A("1 1; 1 2; 0 1"); try { auto [Q, R] = numpy::qr(A); assert_test(Q.rows() == 3 && Q.cols() == 3, "QR decomposition Q dimensions"); assert_test(R.rows() == 3 && R.cols() == 2, "QR decomposition R dimensions"); // Verify Q * R ? A (approximately) auto QR = Q * R; bool qr_close = true; for (size_t i = 0; i < A.rows() && qr_close; ++i) { for (size_t j = 0; j < A.cols() && qr_close; ++j) { if (std::abs(QR(i, j) - A(i, j)) > 1e-6) { qr_close = false; .. _example-top_level-qr_algorithm-843: .. dropdown:: qr_algorithm (np_test_3_all.cpp:3777) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3767 :emphasize-lines: 11 matrix.setElementAt({ 1, 1 }, 4.0); matrix.setElementAt({ 1, 2 }, 1.0); matrix.setElementAt({ 2, 0 }, 0.0); matrix.setElementAt({ 2, 1 }, 1.0); matrix.setElementAt({ 2, 2 }, 4.0); // std::cout << "Test matrix:" << std::endl; //matrix.printArray(); // Apply QR algorithm with more reasonable tolerance auto eigen_result = qr_algorithm(matrix, 1000, 1e-6); // std::cout << "Converged: " << (eigen_result.converged ? "Yes" : "No") << std::endl; // std::cout << "Iterations: " << eigen_result.iterations << std::endl; // std::cout << "All eigenvalues:" << std::endl; //eigen_result.eigenvalues.printArray(); // std::cout << "Eigenvectors (columns):" << std::endl; //eigen_result.eigenvectors.printArray(); .. _example-top_level-qr_decomposition-844: .. dropdown:: qr_decomposition (np_test_1_all.cpp:20163) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20153 :emphasize-lines: 11 std::normal_distribution dist(0.0, 1.0); NDArray A({ n, n }); for (size_t i = 0; i < n; ++i) { for (size_t j = 0; j < n; ++j) { A.setElementAt({ i, j }, dist(gen)); } } // QR decomposition to get orthogonal matrix auto qr_result = qr_decomposition(A); return qr_result.Q; } }; // ============================ // VALIDATION UTILITIES // ============================ template class SchurValidator { .. _example-top_level-qr_decomposition_complex-845: .. dropdown:: qr_decomposition_complex (np_test_3_all.cpp:4993) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4983 :emphasize-lines: 11 matrix.setElementAt({ 1, 0 }, complex128(0, 2)); matrix.setElementAt({ 1, 1 }, complex128(3, -1)); matrix.setElementAt({ 1, 2 }, complex128(1, 1)); matrix.setElementAt({ 2, 0 }, complex128(1, 0)); matrix.setElementAt({ 2, 1 }, complex128(0, 1)); matrix.setElementAt({ 2, 2 }, complex128(2, 2)); // std::cout << "Original matrix:" << std::endl; //matrix.printArray(); auto qr_result = qr_decomposition_complex(matrix); // std::cout << "Q matrix:" << std::endl; //qr_result.Q.printArray(); // std::cout << "R matrix:" << std::endl; //qr_result.R.printArray(); // Verify Q * R = A auto reconstructed = matmul(qr_result.Q, qr_result.R); // std::cout << "Reconstructed matrix (Q * R):" << std::endl; .. _example-top_level-solve-846: .. dropdown:: solve (np_test_2_all.cpp:5150) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5140 :emphasize-lines: 11 * Test linear system solving */ void testMatrixSolvers() { std::cout << "========= testMatrixSolvers ======================="; // Test solve for simple 2x2 system numpy::Matrix A("2 1; 1 1"); numpy::Matrix b("3; 2"); try { auto x = numpy::solve(A, b); assert_test(x.rows() == 2 && x.cols() == 1, "Solve result dimensions"); // Verify A * x = b auto Ax = A * x; assert_test(std::abs(Ax(0, 0) - b(0, 0)) < 1e-10, "Solve verification 0"); assert_test(std::abs(Ax(1, 0) - b(1, 0)) < 1e-10, "Solve verification 1"); } catch (...) { // std::cout << "Linear system solve test failed (expected for some systems)"; } .. _example-top_level-solve-847: .. dropdown:: solve (np_test_2_all.cpp:5150) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5140 :emphasize-lines: 11 * Test linear system solving */ void testMatrixSolvers() { std::cout << "========= testMatrixSolvers ======================="; // Test solve for simple 2x2 system numpy::Matrix A("2 1; 1 1"); numpy::Matrix b("3; 2"); try { auto x = numpy::solve(A, b); assert_test(x.rows() == 2 && x.cols() == 1, "Solve result dimensions"); // Verify A * x = b auto Ax = A * x; assert_test(std::abs(Ax(0, 0) - b(0, 0)) < 1e-10, "Solve verification 0"); assert_test(std::abs(Ax(1, 0) - b(1, 0)) < 1e-10, "Solve verification 1"); } catch (...) { // std::cout << "Linear system solve test failed (expected for some systems)"; } .. _example-top_level-solve_accelerated-848: .. dropdown:: solve_accelerated (np_test_2_all.cpp:17623) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17613 :emphasize-lines: 11 A.setElementAt({ 0, 0 }, 3.0); A.setElementAt({ 0, 1 }, 1.0); A.setElementAt({ 1, 0 }, 1.0); A.setElementAt({ 1, 1 }, 2.0); numpy::NDArray b({ 2 }); b.setElementAt({ 0 }, 9.0); b.setElementAt({ 1 }, 8.0); try { auto x = numpy::mkl::lapack::solve_accelerated(A, b); double x0 = x.getElementAt({ 0 }); double x1 = x.getElementAt({ 1 }); // std::cout << " Solution: x = [" << x0 << ", " << x1 << "]" << std::endl; // Check solution accuracy if (std::abs(x0 - 2.0) > 1e-10 || std::abs(x1 - 3.0) > 1e-10) { std::cout << " [FAIL] : Solution incorrect, expected [2, 3]"; throw std::runtime_error("np_test_mkl_linalg_solve failed: incorrect solution"); .. _example-top_level-svd-849: .. dropdown:: svd (np_test_5_all.cpp:5309) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5299 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } // Test SVD - rank-deficient matrix void np_test_svd_rank_deficient() { std::cout << "========= svd rank-deficient matrix ======================="; // Rank 1 matrix numpy::NDArray A = numpy::array({ {1.0, 2.0}, {2.0, 4.0} }); auto [U, S, Vt] = numpy::linalg::svd(A, false); // Second singular value should be ~0 if (S.getElementAt({ 1 }) > 1e-10) { std::cout << " [FAIL] : in np_test_svd_rank_deficient() : Expected second singular value ~0"; throw std::runtime_error("Test failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-svd-850: .. dropdown:: svd (np_test_5_all.cpp:5309) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5299 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } // Test SVD - rank-deficient matrix void np_test_svd_rank_deficient() { std::cout << "========= svd rank-deficient matrix ======================="; // Rank 1 matrix numpy::NDArray A = numpy::array({ {1.0, 2.0}, {2.0, 4.0} }); auto [U, S, Vt] = numpy::linalg::svd(A, false); // Second singular value should be ~0 if (S.getElementAt({ 1 }) > 1e-10) { std::cout << " [FAIL] : in np_test_svd_rank_deficient() : Expected second singular value ~0"; throw std::runtime_error("Test failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-svd-851: .. dropdown:: svd (np_test_5_all.cpp:5309) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5299 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } // Test SVD - rank-deficient matrix void np_test_svd_rank_deficient() { std::cout << "========= svd rank-deficient matrix ======================="; // Rank 1 matrix numpy::NDArray A = numpy::array({ {1.0, 2.0}, {2.0, 4.0} }); auto [U, S, Vt] = numpy::linalg::svd(A, false); // Second singular value should be ~0 if (S.getElementAt({ 1 }) > 1e-10) { std::cout << " [FAIL] : in np_test_svd_rank_deficient() : Expected second singular value ~0"; throw std::runtime_error("Test failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-svd_decomposition-852: .. dropdown:: svd_decomposition (np_test_1_all.cpp:15400) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15390 :emphasize-lines: 11 matrix.setElementAt({ 0, 1 }, 2.0); matrix.setElementAt({ 1, 0 }, 3.0); matrix.setElementAt({ 1, 1 }, 4.0); matrix.setElementAt({ 2, 0 }, 5.0); matrix.setElementAt({ 2, 1 }, 6.0); // std::cout << "Original matrix:" << std::endl; //matrix.printArray(); // Test compact SVD auto svd_result = svd_decomposition(matrix, false); // std::cout << "Converged: " << (svd_result.converged ? "Yes" : "No") << std::endl; // std::cout << "Iterations: " << svd_result.iterations << std::endl; // std::cout << "U matrix (compact):" << std::endl; //svd_result.U.printArray(); // std::cout << "Singular values:" << std::endl; //svd_result.S.printArray(); .. _example-top_level-trace-853: .. dropdown:: trace (np_test_2_all.cpp:4981) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4971 :emphasize-lines: 11 // Test transpose numpy::Matrix m("1 2 3; 4 5 6"); auto mt = m.transpose(); assert_test(mt.rows() == 3, "Transpose rows"); assert_test(mt.cols() == 2, "Transpose cols"); assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element"); assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element"); // Test trace for square matrix numpy::Matrix square("1 2; 3 4"); double tr = square.trace(); assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace"); // Test determinant for 2x2 matrix double det = square.det(); assert_test(std::abs(det - (-2.0)) < 1e-10, "Matrix determinant 2x2"); // Test matrix inverse for 2x2 auto inv = square.inv(); assert_test(std::abs(inv(0, 0) - (-2.0)) < 1e-10, "Matrix inverse 0,0"); assert_test(std::abs(inv(0, 1) - 1.0) < 1e-10, "Matrix inverse 0,1"); .. _example-top_level-fft-854: .. dropdown:: fft (np_test_3_all.cpp:3261) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3251 :emphasize-lines: 11 void testBasicFFT1D() { std::cout << "========= testBasicFFT1D ===="; // Test simple 1D FFT with known result auto data = createFloat64Array({ 4 }, 0.0); data.setElementAt({ 0 }, 1.0); data.setElementAt({ 1 }, 2.0); data.setElementAt({ 2 }, 3.0); data.setElementAt({ 3 }, 4.0); auto result = fft::fft(data); // Check that we get complex output if (!(result.getShape()[0] == 4)) { std::string description = std::string("testBasicFFT1D():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getShape()[0] == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] FFT produces correct output size\n"; // Test that FFT of constant array gives expected result .. _example-top_level-fft-855: .. dropdown:: fft (np_test_3_all.cpp:3261) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3251 :emphasize-lines: 11 void testBasicFFT1D() { std::cout << "========= testBasicFFT1D ===="; // Test simple 1D FFT with known result auto data = createFloat64Array({ 4 }, 0.0); data.setElementAt({ 0 }, 1.0); data.setElementAt({ 1 }, 2.0); data.setElementAt({ 2 }, 3.0); data.setElementAt({ 3 }, 4.0); auto result = fft::fft(data); // Check that we get complex output if (!(result.getShape()[0] == 4)) { std::string description = std::string("testBasicFFT1D():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getShape()[0] == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] FFT produces correct output size\n"; // Test that FFT of constant array gives expected result .. _example-top_level-fft-856: .. dropdown:: fft (np_test_3_all.cpp:3261) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3251 :emphasize-lines: 11 void testBasicFFT1D() { std::cout << "========= testBasicFFT1D ===="; // Test simple 1D FFT with known result auto data = createFloat64Array({ 4 }, 0.0); data.setElementAt({ 0 }, 1.0); data.setElementAt({ 1 }, 2.0); data.setElementAt({ 2 }, 3.0); data.setElementAt({ 3 }, 4.0); auto result = fft::fft(data); // Check that we get complex output if (!(result.getShape()[0] == 4)) { std::string description = std::string("testBasicFFT1D():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getShape()[0] == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] FFT produces correct output size\n"; // Test that FFT of constant array gives expected result .. _example-top_level-fft-857: .. dropdown:: fft (np_test_3_all.cpp:3261) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3251 :emphasize-lines: 11 void testBasicFFT1D() { std::cout << "========= testBasicFFT1D ===="; // Test simple 1D FFT with known result auto data = createFloat64Array({ 4 }, 0.0); data.setElementAt({ 0 }, 1.0); data.setElementAt({ 1 }, 2.0); data.setElementAt({ 2 }, 3.0); data.setElementAt({ 3 }, 4.0); auto result = fft::fft(data); // Check that we get complex output if (!(result.getShape()[0] == 4)) { std::string description = std::string("testBasicFFT1D():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getShape()[0] == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] FFT produces correct output size\n"; // Test that FFT of constant array gives expected result .. _example-top_level-fft2-858: .. dropdown:: fft2 (np_test_5_all.cpp:6727) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6717 :emphasize-lines: 11 //f2.printArray("f2"); return f2; }; auto fft_ = fft_n(arr2d); //fft_.printArray("f2"); auto fft__ = fft_n(fft_); //fft__.printArray("f2"); auto freq_domain = numpy::fft::fft2(arr2d); //freq_domain.printArray("freq_domain"); // Verify output shape is correct (should be 4x4) bool pass = (freq_domain.getShape()[0] == 2 && freq_domain.getShape()[1] == 2); if (!pass) { std::cout << " [FAIL] : in np_test_fft2_basic() : output shape incorrect"; throw std::runtime_error("np_test_fft2_basic failed: output shape incorrect"); } .. _example-top_level-fft2-859: .. dropdown:: fft2 (np_test_5_all.cpp:6727) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6717 :emphasize-lines: 11 //f2.printArray("f2"); return f2; }; auto fft_ = fft_n(arr2d); //fft_.printArray("f2"); auto fft__ = fft_n(fft_); //fft__.printArray("f2"); auto freq_domain = numpy::fft::fft2(arr2d); //freq_domain.printArray("freq_domain"); // Verify output shape is correct (should be 4x4) bool pass = (freq_domain.getShape()[0] == 2 && freq_domain.getShape()[1] == 2); if (!pass) { std::cout << " [FAIL] : in np_test_fft2_basic() : output shape incorrect"; throw std::runtime_error("np_test_fft2_basic failed: output shape incorrect"); } .. _example-top_level-fft2-860: .. dropdown:: fft2 (np_test_5_all.cpp:6727) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6717 :emphasize-lines: 11 //f2.printArray("f2"); return f2; }; auto fft_ = fft_n(arr2d); //fft_.printArray("f2"); auto fft__ = fft_n(fft_); //fft__.printArray("f2"); auto freq_domain = numpy::fft::fft2(arr2d); //freq_domain.printArray("freq_domain"); // Verify output shape is correct (should be 4x4) bool pass = (freq_domain.getShape()[0] == 2 && freq_domain.getShape()[1] == 2); if (!pass) { std::cout << " [FAIL] : in np_test_fft2_basic() : output shape incorrect"; throw std::runtime_error("np_test_fft2_basic failed: output shape incorrect"); } .. _example-top_level-fft2-861: .. dropdown:: fft2 (np_test_5_all.cpp:6727) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6717 :emphasize-lines: 11 //f2.printArray("f2"); return f2; }; auto fft_ = fft_n(arr2d); //fft_.printArray("f2"); auto fft__ = fft_n(fft_); //fft__.printArray("f2"); auto freq_domain = numpy::fft::fft2(arr2d); //freq_domain.printArray("freq_domain"); // Verify output shape is correct (should be 4x4) bool pass = (freq_domain.getShape()[0] == 2 && freq_domain.getShape()[1] == 2); if (!pass) { std::cout << " [FAIL] : in np_test_fft2_basic() : output shape incorrect"; throw std::runtime_error("np_test_fft2_basic failed: output shape incorrect"); } .. _example-top_level-fftn-862: .. dropdown:: fftn (np_test_2_all.cpp:12580) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12570 :emphasize-lines: 11 std::cout << "========= fftn: 1D real input ======================="; // Create 1D array [1, 2, 3, 4] numpy::NDArray a({ 4 }); a.setElementAt({ 0 }, 1.0); a.setElementAt({ 1 }, 2.0); a.setElementAt({ 2 }, 3.0); a.setElementAt({ 3 }, 4.0); // Perform FFT auto result = numpy::fft::fftn(a); // Verify shape is preserved auto pass = (result.getShape()[0] == 4); if (!pass) { std::cout << " [FAIL] : Shape mismatch"; throw std::runtime_error("np_test_fft_extended_fftn_1d failed: shape mismatch"); } // Verify DC component (sum of all elements) auto dc = result.getElementAt({ 0 }); .. _example-top_level-fftn-863: .. dropdown:: fftn (np_test_2_all.cpp:12580) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12570 :emphasize-lines: 11 std::cout << "========= fftn: 1D real input ======================="; // Create 1D array [1, 2, 3, 4] numpy::NDArray a({ 4 }); a.setElementAt({ 0 }, 1.0); a.setElementAt({ 1 }, 2.0); a.setElementAt({ 2 }, 3.0); a.setElementAt({ 3 }, 4.0); // Perform FFT auto result = numpy::fft::fftn(a); // Verify shape is preserved auto pass = (result.getShape()[0] == 4); if (!pass) { std::cout << " [FAIL] : Shape mismatch"; throw std::runtime_error("np_test_fft_extended_fftn_1d failed: shape mismatch"); } // Verify DC component (sum of all elements) auto dc = result.getElementAt({ 0 }); .. _example-top_level-fftn-864: .. dropdown:: fftn (np_test_2_all.cpp:12580) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12570 :emphasize-lines: 11 std::cout << "========= fftn: 1D real input ======================="; // Create 1D array [1, 2, 3, 4] numpy::NDArray a({ 4 }); a.setElementAt({ 0 }, 1.0); a.setElementAt({ 1 }, 2.0); a.setElementAt({ 2 }, 3.0); a.setElementAt({ 3 }, 4.0); // Perform FFT auto result = numpy::fft::fftn(a); // Verify shape is preserved auto pass = (result.getShape()[0] == 4); if (!pass) { std::cout << " [FAIL] : Shape mismatch"; throw std::runtime_error("np_test_fft_extended_fftn_1d failed: shape mismatch"); } // Verify DC component (sum of all elements) auto dc = result.getElementAt({ 0 }); .. _example-top_level-fftn-865: .. dropdown:: fftn (np_test_2_all.cpp:12580) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12570 :emphasize-lines: 11 std::cout << "========= fftn: 1D real input ======================="; // Create 1D array [1, 2, 3, 4] numpy::NDArray a({ 4 }); a.setElementAt({ 0 }, 1.0); a.setElementAt({ 1 }, 2.0); a.setElementAt({ 2 }, 3.0); a.setElementAt({ 3 }, 4.0); // Perform FFT auto result = numpy::fft::fftn(a); // Verify shape is preserved auto pass = (result.getShape()[0] == 4); if (!pass) { std::cout << " [FAIL] : Shape mismatch"; throw std::runtime_error("np_test_fft_extended_fftn_1d failed: shape mismatch"); } // Verify DC component (sum of all elements) auto dc = result.getElementAt({ 0 }); .. _example-top_level-ifft-866: .. dropdown:: ifft (np_test_5_all.cpp:6760) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6750 :emphasize-lines: 11 size_t n = 16; numpy::NDArray signal({ n }); for (size_t i = 0; i < n; ++i) { signal.setElementAt({ i }, std::sin(2.0 * M_PI * i / n)); } // Forward FFT auto freq_domain = numpy::fft::fft(signal); // Inverse FFT auto time_domain_complex = numpy::fft::ifft(freq_domain); // Verify round trip bool pass = true; for (size_t i = 0; i < n; ++i) { double original = signal.getElementAt({ i }); double reconstructed = time_domain_complex.getElementAt({ i }).real(); if (!is_close(original, reconstructed)) { pass = false; break; } .. _example-top_level-ifft-867: .. dropdown:: ifft (np_test_5_all.cpp:6760) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6750 :emphasize-lines: 11 size_t n = 16; numpy::NDArray signal({ n }); for (size_t i = 0; i < n; ++i) { signal.setElementAt({ i }, std::sin(2.0 * M_PI * i / n)); } // Forward FFT auto freq_domain = numpy::fft::fft(signal); // Inverse FFT auto time_domain_complex = numpy::fft::ifft(freq_domain); // Verify round trip bool pass = true; for (size_t i = 0; i < n; ++i) { double original = signal.getElementAt({ i }); double reconstructed = time_domain_complex.getElementAt({ i }).real(); if (!is_close(original, reconstructed)) { pass = false; break; } .. _example-top_level-ifft2-868: .. dropdown:: ifft2 (np_test_5_all.cpp:6887) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6877 :emphasize-lines: 11 numpy::NDArray original({ 2, 2 }); original.setElementAt({ 0, 0 }, 1.0); original.setElementAt({ 0, 1 }, 2.0); original.setElementAt({ 1, 0 }, 3.0); original.setElementAt({ 1, 1 }, 4.0); // Forward 2D FFT auto freq_domain = numpy::fft::fft2(original); // Inverse 2D FFT auto reconstructed = numpy::fft::ifft2(freq_domain); // Verify round trip - should reconstruct original bool pass = true; double max_error = 0.0; for (size_t i = 0; i < 2; ++i) { for (size_t j = 0; j < 2; ++j) { double orig_val = original.getElementAt({ i, j }); double recon_val = reconstructed.getElementAt({ i, j }).real(); double error = std::abs(orig_val - recon_val); max_error = std::max(max_error, error); .. _example-top_level-ifft2-869: .. dropdown:: ifft2 (np_test_5_all.cpp:6887) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6877 :emphasize-lines: 11 numpy::NDArray original({ 2, 2 }); original.setElementAt({ 0, 0 }, 1.0); original.setElementAt({ 0, 1 }, 2.0); original.setElementAt({ 1, 0 }, 3.0); original.setElementAt({ 1, 1 }, 4.0); // Forward 2D FFT auto freq_domain = numpy::fft::fft2(original); // Inverse 2D FFT auto reconstructed = numpy::fft::ifft2(freq_domain); // Verify round trip - should reconstruct original bool pass = true; double max_error = 0.0; for (size_t i = 0; i < 2; ++i) { for (size_t j = 0; j < 2; ++j) { double orig_val = original.getElementAt({ i, j }); double recon_val = reconstructed.getElementAt({ i, j }).real(); double error = std::abs(orig_val - recon_val); max_error = std::max(max_error, error); .. _example-top_level-ifftn-870: .. dropdown:: ifftn (np_test_2_all.cpp:12675) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12665 :emphasize-lines: 11 // Create test array numpy::NDArray> a({ 4 }); a.setElementAt({ 0 }, std::complex(1.0, 0.0)); a.setElementAt({ 1 }, std::complex(2.0, 0.0)); a.setElementAt({ 2 }, std::complex(3.0, 0.0)); a.setElementAt({ 3 }, std::complex(4.0, 0.0)); // FFT -> IFFT should give back original auto fft_result = numpy::fft::fftn(a); auto ifft_result = numpy::fft::ifftn(fft_result); // Verify round-trip auto pass = true; for (size_t i = 0; i < 4; ++i) { if (!isClose(ifft_result.getElementAt({ i }), a.getElementAt({ i }), 1e-4)) { pass = false; break; } } .. _example-top_level-ifftn-871: .. dropdown:: ifftn (np_test_2_all.cpp:12675) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12665 :emphasize-lines: 11 // Create test array numpy::NDArray> a({ 4 }); a.setElementAt({ 0 }, std::complex(1.0, 0.0)); a.setElementAt({ 1 }, std::complex(2.0, 0.0)); a.setElementAt({ 2 }, std::complex(3.0, 0.0)); a.setElementAt({ 3 }, std::complex(4.0, 0.0)); // FFT -> IFFT should give back original auto fft_result = numpy::fft::fftn(a); auto ifft_result = numpy::fft::ifftn(fft_result); // Verify round-trip auto pass = true; for (size_t i = 0; i < 4; ++i) { if (!isClose(ifft_result.getElementAt({ i }), a.getElementAt({ i }), 1e-4)) { pass = false; break; } } .. _example-top_level-ihfft-872: .. dropdown:: ihfft (np_test_2_all.cpp:13021) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13011 :emphasize-lines: 11 std::cout << "========= hfft: round-trip with ihfft ======================="; // Create real array numpy::NDArray a({ 4 }); a.setElementAt({ 0 }, 1.0); a.setElementAt({ 1 }, 2.0); a.setElementAt({ 2 }, 3.0); a.setElementAt({ 3 }, 4.0); // ihfft -> hfft should give back original auto ihfft_result = numpy::fft::ihfft(a); auto hfft_result = numpy::fft::hfft(ihfft_result); // Verify round-trip auto pass = true; for (size_t i = 0; i < 4; ++i) { if (!isClose(hfft_result.getElementAt({ i }), a.getElementAt({ i }), 1e-3)) { std::cout << " [FAIL] : Mismatch at index " << i << ": " << hfft_result.getElementAt({ i }) << " vs " << a.getElementAt({ i }) << std::endl; pass = false; } .. _example-top_level-ihfft-873: .. dropdown:: ihfft (np_test_2_all.cpp:13021) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13011 :emphasize-lines: 11 std::cout << "========= hfft: round-trip with ihfft ======================="; // Create real array numpy::NDArray a({ 4 }); a.setElementAt({ 0 }, 1.0); a.setElementAt({ 1 }, 2.0); a.setElementAt({ 2 }, 3.0); a.setElementAt({ 3 }, 4.0); // ihfft -> hfft should give back original auto ihfft_result = numpy::fft::ihfft(a); auto hfft_result = numpy::fft::hfft(ihfft_result); // Verify round-trip auto pass = true; for (size_t i = 0; i < 4; ++i) { if (!isClose(hfft_result.getElementAt({ i }), a.getElementAt({ i }), 1e-3)) { std::cout << " [FAIL] : Mismatch at index " << i << ": " << hfft_result.getElementAt({ i }) << " vs " << a.getElementAt({ i }) << std::endl; pass = false; } .. _example-top_level-rfft-874: .. dropdown:: rfft (np_test_5_all.cpp:6927) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6917 :emphasize-lines: 11 std::cout << "========= rfft: Real FFT for real input ======================="; // Create a real signal size_t n = 16; numpy::NDArray real_signal({ n }); for (size_t i = 0; i < n; ++i) { real_signal.setElementAt({ i }, std::cos(2.0 * M_PI * 2.0 * i / n)); // 2 cycles } // Real FFT auto freq_domain = numpy::fft::rfft(real_signal); // Verify output size is n/2 + 1 size_t expected_size = n / 2 + 1; bool pass = (freq_domain.getSize() == expected_size); if (!pass) { std::cout << " [FAIL] : in np_test_rfft_real_input() : output size incorrect"; throw std::runtime_error("np_test_rfft_real_input failed: output size incorrect"); } .. _example-top_level-rfft-875: .. dropdown:: rfft (np_test_5_all.cpp:6927) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6917 :emphasize-lines: 11 std::cout << "========= rfft: Real FFT for real input ======================="; // Create a real signal size_t n = 16; numpy::NDArray real_signal({ n }); for (size_t i = 0; i < n; ++i) { real_signal.setElementAt({ i }, std::cos(2.0 * M_PI * 2.0 * i / n)); // 2 cycles } // Real FFT auto freq_domain = numpy::fft::rfft(real_signal); // Verify output size is n/2 + 1 size_t expected_size = n / 2 + 1; bool pass = (freq_domain.getSize() == expected_size); if (!pass) { std::cout << " [FAIL] : in np_test_rfft_real_input() : output size incorrect"; throw std::runtime_error("np_test_rfft_real_input failed: output size incorrect"); } .. _example-top_level-rfft2-876: .. dropdown:: rfft2 (np_test_2_all.cpp:12749) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12739 :emphasize-lines: 11 // Create 2D real array [[1, 2, 3], [4, 5, 6]] numpy::NDArray a({ 2, 3 }); a.setElementAt({ 0, 0 }, 1.0); a.setElementAt({ 0, 1 }, 2.0); a.setElementAt({ 0, 2 }, 3.0); a.setElementAt({ 1, 0 }, 4.0); a.setElementAt({ 1, 1 }, 5.0); a.setElementAt({ 1, 2 }, 6.0); // Perform 2D real FFT auto result = numpy::fft::rfft2(a); // Output shape should be [2, 2] (last dimension is n/2+1 = 3/2+1 = 2) auto pass = (result.getShape()[0] == 2 && result.getShape()[1] == 2); if (!pass) { std::cout << " [FAIL] : Shape mismatch. Expected [2,2], got [" << result.getShape()[0] << "," << result.getShape()[1] << "]" << std::endl; throw std::runtime_error("np_test_fft_extended_rfft2_basic failed: shape"); } // Verify DC component .. _example-top_level-rfft2-877: .. dropdown:: rfft2 (np_test_2_all.cpp:12749) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12739 :emphasize-lines: 11 // Create 2D real array [[1, 2, 3], [4, 5, 6]] numpy::NDArray a({ 2, 3 }); a.setElementAt({ 0, 0 }, 1.0); a.setElementAt({ 0, 1 }, 2.0); a.setElementAt({ 0, 2 }, 3.0); a.setElementAt({ 1, 0 }, 4.0); a.setElementAt({ 1, 1 }, 5.0); a.setElementAt({ 1, 2 }, 6.0); // Perform 2D real FFT auto result = numpy::fft::rfft2(a); // Output shape should be [2, 2] (last dimension is n/2+1 = 3/2+1 = 2) auto pass = (result.getShape()[0] == 2 && result.getShape()[1] == 2); if (!pass) { std::cout << " [FAIL] : Shape mismatch. Expected [2,2], got [" << result.getShape()[0] << "," << result.getShape()[1] << "]" << std::endl; throw std::runtime_error("np_test_fft_extended_rfft2_basic failed: shape"); } // Verify DC component .. _example-top_level-rfftn-878: .. dropdown:: rfftn (np_test_2_all.cpp:12807) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12797 :emphasize-lines: 11 std::cout << "========= rfftn: 1D real FFT ======================="; // Create 1D array [1, 2, 3, 4] numpy::NDArray a({ 4 }); a.setElementAt({ 0 }, 1.0); a.setElementAt({ 1 }, 2.0); a.setElementAt({ 2 }, 3.0); a.setElementAt({ 3 }, 4.0); // Perform rfftn auto result = numpy::fft::rfftn(a); // Output size should be 4/2+1 = 3 auto pass = (result.getShape()[0] == 3); if (!pass) { std::cout << " [FAIL] : Shape mismatch. Expected 3, got " << result.getShape()[0]; throw std::runtime_error("np_test_fft_extended_rfftn_1d failed: shape"); } // Verify DC component auto dc = result.getElementAt({ 0 }); .. _example-top_level-rfftn-879: .. dropdown:: rfftn (np_test_2_all.cpp:12807) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12797 :emphasize-lines: 11 std::cout << "========= rfftn: 1D real FFT ======================="; // Create 1D array [1, 2, 3, 4] numpy::NDArray a({ 4 }); a.setElementAt({ 0 }, 1.0); a.setElementAt({ 1 }, 2.0); a.setElementAt({ 2 }, 3.0); a.setElementAt({ 3 }, 4.0); // Perform rfftn auto result = numpy::fft::rfftn(a); // Output size should be 4/2+1 = 3 auto pass = (result.getShape()[0] == 3); if (!pass) { std::cout << " [FAIL] : Shape mismatch. Expected 3, got " << result.getShape()[0]; throw std::runtime_error("np_test_fft_extended_rfftn_1d failed: shape"); } // Verify DC component auto dc = result.getElementAt({ 0 }); .. _example-top_level-beta-880: .. dropdown:: beta (np_test_1_all.cpp:10394) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10384 :emphasize-lines: 11 NDArray beta_a({ 4 }); NDArray beta_b({ 4 }); beta_a.setElementAt({ 0 }, 1.0); beta_a.setElementAt({ 1 }, 2.0); beta_a.setElementAt({ 2 }, 1.0); beta_a.setElementAt({ 3 }, 2.0); beta_b.setElementAt({ 0 }, 1.0); beta_b.setElementAt({ 1 }, 1.0); beta_b.setElementAt({ 2 }, 2.0); beta_b.setElementAt({ 3 }, 2.0); auto beta_result = special::beta(beta_a, beta_b, MathBackend::MKL); if (!(isApproxEqual(beta_result.getElementAt({ 0 }), 1.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(beta_result.getElementAt({ 0 }), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(beta_result.getElementAt({ 1 }), 0.5, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(beta_result.getElementAt({ 1 }), 0.5, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-binomial-881: .. dropdown:: binomial (np_test_1_all.cpp:22110) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22100 :emphasize-lines: 11 for (size_t i = 0; i < 4; ++i) { if (!(geom_arr.getElementAt({ i }) >= 1)) { std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(geom_arr.getElementAt({ i }) >= 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] Geometric distribution\n"; // Test binomial distribution auto binom_arr = binomial(20, 0.3, { {5} }); if (!(binom_arr.getShape()[0] == 5)) { std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(binom_arr.getShape()[0] == 5)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < 5; ++i) { int val = binom_arr.getElementAt({ i }); if (!(val >= 0 && val <= 20)) { std::string description = std::string("testDiscreteDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0 && val <= 20)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-gamma-882: .. dropdown:: gamma (np_test_1_all.cpp:10297) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10287 :emphasize-lines: 11 std::cout << "========= testGammaFunctions ===="; // Test gamma function for known values using NDArray with MKL backend NDArray gamma_test({ 6 }); gamma_test.setElementAt({ 0 }, 1.0); gamma_test.setElementAt({ 1 }, 2.0); gamma_test.setElementAt({ 2 }, 3.0); gamma_test.setElementAt({ 3 }, 4.0); gamma_test.setElementAt({ 4 }, 5.0); gamma_test.setElementAt({ 5 }, 0.5); auto gamma_result = special::gamma(gamma_test, MathBackend::MKL); if (!(isApproxEqual(gamma_result.getElementAt({ 0 }), 1.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(gamma_result.getElementAt({ 0 }), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(gamma_result.getElementAt({ 1 }), 1.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(gamma_result.getElementAt({ 1 }), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-rand-883: .. dropdown:: rand (np_test_1_all.cpp:22587) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22577 :emphasize-lines: 11 } // std::cout << "[OK] Dirichlet parameter validation\n"; std::cout << " -> tests passed\n"; } void testExistingDistributions() { std::cout << "========= testExistingDistributions ===="; // Test that existing distributions still work auto rand_arr = rand(3); if (!(rand_arr.getShape()[0] == 3)) { std::string description = std::string("testExistingDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(rand_arr.getShape()[0] == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < 3; ++i) { double val = rand_arr.getElementAt({ i }); if (!(val >= 0.0 && val < 1.0)) { std::string description = std::string("testExistingDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0.0 && val < 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-rand-884: .. dropdown:: rand (np_test_1_all.cpp:22587) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22577 :emphasize-lines: 11 } // std::cout << "[OK] Dirichlet parameter validation\n"; std::cout << " -> tests passed\n"; } void testExistingDistributions() { std::cout << "========= testExistingDistributions ===="; // Test that existing distributions still work auto rand_arr = rand(3); if (!(rand_arr.getShape()[0] == 3)) { std::string description = std::string("testExistingDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(rand_arr.getShape()[0] == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < 3; ++i) { double val = rand_arr.getElementAt({ i }); if (!(val >= 0.0 && val < 1.0)) { std::string description = std::string("testExistingDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0.0 && val < 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-randint-885: .. dropdown:: randint (np_test_1_all.cpp:22611) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22601 :emphasize-lines: 11 // std::cout << "[OK] Existing rand function\n"; auto randn_arr = randn(3); if (!(randn_arr.getShape()[0] == 3)) { std::string description = std::string("testExistingDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(randn_arr.getShape()[0] == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Existing randn function\n"; auto randint_arr = randint(0, 10, { {3} }); if (!(randint_arr.getShape()[0] == 3)) { std::string description = std::string("testExistingDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(randint_arr.getShape()[0] == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < 3; ++i) { int val = randint_arr.getElementAt({ i }); if (!(val >= 0 && val < 10)) { std::string description = std::string("testExistingDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0 && val < 10)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-randn-886: .. dropdown:: randn (np_test_1_all.cpp:22603) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22593 :emphasize-lines: 11 for (size_t i = 0; i < 3; ++i) { double val = rand_arr.getElementAt({ i }); if (!(val >= 0.0 && val < 1.0)) { std::string description = std::string("testExistingDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0.0 && val < 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] Existing rand function\n"; auto randn_arr = randn(3); if (!(randn_arr.getShape()[0] == 3)) { std::string description = std::string("testExistingDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(randn_arr.getShape()[0] == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Existing randn function\n"; auto randint_arr = randint(0, 10, { {3} }); if (!(randint_arr.getShape()[0] == 3)) { std::string description = std::string("testExistingDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(randint_arr.getShape()[0] == 3)"; .. _example-top_level-randn-887: .. dropdown:: randn (np_test_1_all.cpp:22603) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22593 :emphasize-lines: 11 for (size_t i = 0; i < 3; ++i) { double val = rand_arr.getElementAt({ i }); if (!(val >= 0.0 && val < 1.0)) { std::string description = std::string("testExistingDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0.0 && val < 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] Existing rand function\n"; auto randn_arr = randn(3); if (!(randn_arr.getShape()[0] == 3)) { std::string description = std::string("testExistingDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(randn_arr.getShape()[0] == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Existing randn function\n"; auto randint_arr = randint(0, 10, { {3} }); if (!(randint_arr.getShape()[0] == 3)) { std::string description = std::string("testExistingDistributions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(randint_arr.getShape()[0] == 3)"; .. _example-top_level-seed-888: .. dropdown:: seed (np_test_1_all.cpp:14339) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14329 :emphasize-lines: 11 } // std::cout << "[OK] Generator integers method\n"; std::cout << " -> tests passed\n"; } void test_vsl_reproducibility() { std::cout << "========= test_vsl_reproducibility ===="; // Test seed reproducibility seed(42); auto arr1 = normal(0.0, 1.0, { {10} }); seed(42); auto arr2 = normal(0.0, 1.0, { {10} }); for (size_t i = 0; i < 10; ++i) { double val1 = arr1.getElementAt({ i }); double val2 = arr2.getElementAt({ i }); .. _example-top_level-seed-889: .. dropdown:: seed (np_test_1_all.cpp:14339) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14329 :emphasize-lines: 11 } // std::cout << "[OK] Generator integers method\n"; std::cout << " -> tests passed\n"; } void test_vsl_reproducibility() { std::cout << "========= test_vsl_reproducibility ===="; // Test seed reproducibility seed(42); auto arr1 = normal(0.0, 1.0, { {10} }); seed(42); auto arr2 = normal(0.0, 1.0, { {10} }); for (size_t i = 0; i < 10; ++i) { double val1 = arr1.getElementAt({ i }); double val2 = arr2.getElementAt({ i }); .. _example-top_level-shuffle-890: .. dropdown:: shuffle (np_test_1_all.cpp:12901) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12891 :emphasize-lines: 11 large_dataset.reserve(1000); for (int i = 0; i < 1000; ++i) { std::string str = "string" + std::to_string(i); large_dataset.push_back(str); } // Shuffle the dataset std::random_device rd; std::mt19937 gen(rd()); std::shuffle(large_dataset.begin(), large_dataset.end(), gen); // Sort using our string sort sort_strings(large_dataset); // Verify it's sorted if (!(std::is_sorted(large_dataset.begin(), large_dataset.end()))) { std::string description = std::string("test_large_string_dataset():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(large_dataset.begin(), large_dataset.end()))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-count_nonzero-891: .. dropdown:: count_nonzero (np_test_1_all.cpp:3007) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2997 :emphasize-lines: 11 // std::cout << "[OK] popcount function\n"; // Test count_nonzero auto nonzero_arr = NDArray({4}); nonzero_arr.setElementAt({0}, 0); nonzero_arr.setElementAt({1}, 1); nonzero_arr.setElementAt({2}, 0); nonzero_arr.setElementAt({3}, 42); auto nonzero_count = count_nonzero(nonzero_arr); if (!(nonzero_count == 2)) { std::string description = std::string("testBitCounting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(nonzero_count == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test count_nonzero with float64 auto nonzero_float64 = NDArray({4}); nonzero_float64.setElementAt({0}, 0.0); nonzero_float64.setElementAt({1}, 1.5); .. _example-top_level-msort-892: .. dropdown:: msort (np_test_2_all.cpp:8280) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8270 :emphasize-lines: 11 throw std::runtime_error("lexsort: FAILED - result is not properly sorted according to keys"); } // std::cout << "[OK] lexsort: PASSED" << std::endl; } // Test msort { const std::vector data = { 5, 2, 8, 1, 9 }; std::vector expected = { 1, 2, 5, 8, 9 }; auto result = numpy::msort(data); if (result != expected) { std::cout << " msort: -> [FAIL]"; throw std::runtime_error("msort: FAILED - result does not match expected sorted array"); } // std::cout << "[OK] msort: PASSED" << std::endl; } // Test sort_complex { .. _example-top_level-partition-893: .. dropdown:: partition (np_test_1_all.cpp:17008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16998 :emphasize-lines: 11 // Test 1D array partition NDArray arr1d({ 6 }); arr1d.setElementAt({ 0 }, 30); // index 0 arr1d.setElementAt({ 1 }, 10); // index 1 arr1d.setElementAt({ 2 }, 40); // index 2 arr1d.setElementAt({ 3 }, 20); // index 3 arr1d.setElementAt({ 4 }, 50); // index 4 arr1d.setElementAt({ 5 }, 15); // index 5 // Partition around kth=2 (should put 2 smallest elements before position 2) auto partitioned = partition(arr1d, 2); // After partitioning around k=2, elements [0:2] should be <= element at position 2 // and elements [3:] should be >= element at position 2 int pivot_value = partitioned.getElementAt({ 2 }); // Check that first 2 elements are <= pivot if (!(partitioned.getElementAt({ 0 }) <= pivot_value)) { std::string description = std::string("test_partition_functions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(partitioned.getElementAt({ 0 }) <= pivot_value)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-partition-894: .. dropdown:: partition (np_test_1_all.cpp:17008) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16998 :emphasize-lines: 11 // Test 1D array partition NDArray arr1d({ 6 }); arr1d.setElementAt({ 0 }, 30); // index 0 arr1d.setElementAt({ 1 }, 10); // index 1 arr1d.setElementAt({ 2 }, 40); // index 2 arr1d.setElementAt({ 3 }, 20); // index 3 arr1d.setElementAt({ 4 }, 50); // index 4 arr1d.setElementAt({ 5 }, 15); // index 5 // Partition around kth=2 (should put 2 smallest elements before position 2) auto partitioned = partition(arr1d, 2); // After partitioning around k=2, elements [0:2] should be <= element at position 2 // and elements [3:] should be >= element at position 2 int pivot_value = partitioned.getElementAt({ 2 }); // Check that first 2 elements are <= pivot if (!(partitioned.getElementAt({ 0 }) <= pivot_value)) { std::string description = std::string("test_partition_functions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(partitioned.getElementAt({ 0 }) <= pivot_value)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-sort-895: .. dropdown:: sort (np_test_1_all.cpp:6258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6248 :emphasize-lines: 11 std::vector data = gen.generate(100, DataPattern::FEW_UNIQUE); if (!(data.size() == 100)) { std::string description = std::string("test_data_generator_few_uniqueBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Count unique values std::vector sorted_copy = data; std::sort(sorted_copy.begin(), sorted_copy.end()); auto unique_end = std::unique(sorted_copy.begin(), sorted_copy.end()); size_t unique_count = std::distance(sorted_copy.begin(), unique_end); // Should have significantly fewer unique values than total elements if (!(unique_count < data.size() / 2)) { std::string description = std::string("test_data_generator_few_uniqueBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_count < data.size() / 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-sort_complex-896: .. dropdown:: sort_complex (np_test_2_all.cpp:8295) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8285 :emphasize-lines: 11 } // std::cout << "[OK] msort: PASSED" << std::endl; } // Test sort_complex { const std::vector> data = { {3.0, 2.0}, {1.0, 4.0}, {3.0, 1.0}, {1.0, 2.0} }; auto result = numpy::sort_complex(data); // Should be sorted by real part first, then imaginary std::vector> expected = { {1.0, 2.0}, {1.0, 4.0}, {3.0, 1.0}, {3.0, 2.0} }; if (result != expected) { std::cout << " sort_complex: -> [FAIL]"; throw std::runtime_error("sort_complex: FAILED - complex numbers not sorted correctly"); } .. _example-top_level-sort_complex-897: .. dropdown:: sort_complex (np_test_2_all.cpp:8295) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8285 :emphasize-lines: 11 } // std::cout << "[OK] msort: PASSED" << std::endl; } // Test sort_complex { const std::vector> data = { {3.0, 2.0}, {1.0, 4.0}, {3.0, 1.0}, {1.0, 2.0} }; auto result = numpy::sort_complex(data); // Should be sorted by real part first, then imaginary std::vector> expected = { {1.0, 2.0}, {1.0, 4.0}, {3.0, 1.0}, {3.0, 2.0} }; if (result != expected) { std::cout << " sort_complex: -> [FAIL]"; throw std::runtime_error("sort_complex: FAILED - complex numbers not sorted correctly"); } .. _example-top_level-sort_inplace-898: .. dropdown:: sort_inplace (np_test_1_all.cpp:17145) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17135 :emphasize-lines: 11 std::cout << "========= test_inplace_sorting ======================="; // Test 1D in-place sorting NDArray arr1d({ 5 }); arr1d.setElementAt({ 0 }, 5); arr1d.setElementAt({ 1 }, 2); arr1d.setElementAt({ 2 }, 8); arr1d.setElementAt({ 3 }, 1); arr1d.setElementAt({ 4 }, 9); sort_inplace(arr1d); if (!(arr1d.getElementAt({ 0 }) == 1)) { std::string description = std::string("test_inplace_sorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr1d.getElementAt({ 0 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(arr1d.getElementAt({ 1 }) == 2)) { std::string description = std::string("test_inplace_sorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr1d.getElementAt({ 1 }) == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-sort_strings-899: .. dropdown:: sort_strings (np_test_1_all.cpp:12530) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12520 :emphasize-lines: 11 std::cout << "========= test_string_sort_basic ======================="; std::vector strings = { "banana", "apple", "cherry", "date", "elderberry" }; std::vector expected = { "apple", "banana", "cherry", "date", "elderberry" }; sort_strings(strings); if (!(strings == expected)) { std::string description = std::string("test_string_sort_basic():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(strings == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::is_sorted(strings.begin(), strings.end()))) { std::string description = std::string("test_string_sort_basic():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(strings.begin(), strings.end()))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-sort_strings-900: .. dropdown:: sort_strings (np_test_1_all.cpp:12530) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12520 :emphasize-lines: 11 std::cout << "========= test_string_sort_basic ======================="; std::vector strings = { "banana", "apple", "cherry", "date", "elderberry" }; std::vector expected = { "apple", "banana", "cherry", "date", "elderberry" }; sort_strings(strings); if (!(strings == expected)) { std::string description = std::string("test_string_sort_basic():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(strings == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::is_sorted(strings.begin(), strings.end()))) { std::string description = std::string("test_string_sort_basic():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(strings.begin(), strings.end()))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-sort_strings_case_insensitive-901: .. dropdown:: sort_strings_case_insensitive (np_test_1_all.cpp:12555) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12545 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void test_string_sort_case_insensitive() { std::cout << "========= test_string_sort_case_insensitive ======================="; std::vector strings = { "Banana", "apple", "Cherry", "date", "Elderberry" }; sort_strings_case_insensitive(strings); // Check that the result is sorted case-insensitively StringComparator comp(StringComparePolicy::CASE_INSENSITIVE); for (size_t i = 1; i < strings.size(); ++i) { if (!(!comp(strings[i], strings[i - 1]))) { std::string description = std::string("test_string_sort_case_insensitive():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!comp(strings[i], strings[i - 1]))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } .. _example-top_level-sort_strings_natural-902: .. dropdown:: sort_strings_natural (np_test_1_all.cpp:12583) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12573 :emphasize-lines: 11 std::cout << "========= test_string_sort_natural ======================="; std::vector strings = { "file10.txt", "file2.txt", "file1.txt", "file20.txt", "file3.txt" }; std::vector expected = { "file1.txt", "file2.txt", "file3.txt", "file10.txt", "file20.txt" }; sort_strings_natural(strings); if (!(strings == expected)) { std::string description = std::string("test_string_sort_natural():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(strings == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Natural string sorting test passed" << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-top_level-allclose-903: .. dropdown:: allclose (np_test_1_all.cpp:993) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 983 :emphasize-lines: 11 auto a = createFloat64Array({3}); a.setElementAt({0}, 1.0); a.setElementAt({1}, 2.0); a.setElementAt({2}, 3.0); auto b = createFloat64Array({3}); b.setElementAt({0}, 1.000001); // Close to 1.0 b.setElementAt({1}, 2.000001); // Close to 2.0 b.setElementAt({2}, 3.000001); // Close to 3.0 bool close_wide = allclose(a, b, 1e-4, 1e-4); if (close_wide != true) { // Should be close within tolerance std::cout << "[FAIL] in testExistingFunctions(): allclose with 1e-4 tolerance = " << close_wide << ", expected true" << std::endl; throw std::runtime_error("testExistingFunctions(): allclose wide tolerance failed"); } bool close_strict = allclose(a, b, 1e-8, 1e-8); if (close_strict != false) { // Should not be close with stricter tolerance std::cout << "[FAIL] in testExistingFunctions(): allclose with 1e-8 tolerance = " << close_strict << ", expected false" << std::endl; throw std::runtime_error("testExistingFunctions(): allclose strict tolerance failed"); } // std::cout << "[OK] allclose function" << std::endl; .. _example-top_level-allclose-904: .. dropdown:: allclose (np_test_1_all.cpp:993) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 983 :emphasize-lines: 11 auto a = createFloat64Array({3}); a.setElementAt({0}, 1.0); a.setElementAt({1}, 2.0); a.setElementAt({2}, 3.0); auto b = createFloat64Array({3}); b.setElementAt({0}, 1.000001); // Close to 1.0 b.setElementAt({1}, 2.000001); // Close to 2.0 b.setElementAt({2}, 3.000001); // Close to 3.0 bool close_wide = allclose(a, b, 1e-4, 1e-4); if (close_wide != true) { // Should be close within tolerance std::cout << "[FAIL] in testExistingFunctions(): allclose with 1e-4 tolerance = " << close_wide << ", expected true" << std::endl; throw std::runtime_error("testExistingFunctions(): allclose wide tolerance failed"); } bool close_strict = allclose(a, b, 1e-8, 1e-8); if (close_strict != false) { // Should not be close with stricter tolerance std::cout << "[FAIL] in testExistingFunctions(): allclose with 1e-8 tolerance = " << close_strict << ", expected false" << std::endl; throw std::runtime_error("testExistingFunctions(): allclose strict tolerance failed"); } // std::cout << "[OK] allclose function" << std::endl; .. _example-top_level-array_equal-905: .. dropdown:: array_equal (np_test_1_all.cpp:1030) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1020 :emphasize-lines: 11 throw std::runtime_error("testExistingFunctions(): isclose [2] failed"); } // std::cout << "[OK] isclose function"; // Test array_equal auto c = createFloat64Array({3}); c.setElementAt({0}, 1.0); c.setElementAt({1}, 2.0); c.setElementAt({2}, 3.0); bool arr_eq_ac = array_equal(a, c); if (arr_eq_ac != true) { std::cout << "[FAIL] in testExistingFunctions(): array_equal(a, c) = " << arr_eq_ac << ", expected true" << std::endl; throw std::runtime_error("testExistingFunctions(): array_equal(a, c) failed"); } bool arr_eq_ab = array_equal(a, b); if (arr_eq_ab != false) { std::cout << "[FAIL] in testExistingFunctions(): array_equal(a, b) = " << arr_eq_ab << ", expected false" << std::endl; throw std::runtime_error("testExistingFunctions(): array_equal(a, b) failed"); } // std::cout << "[OK] array_equal function" << std::endl; .. _example-top_level-array_equiv-906: .. dropdown:: array_equiv (np_test_1_all.cpp:19718) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19708 :emphasize-lines: 11 equiv2.setElementAt({ 0 }, 3); equiv2.setElementAt({ 1 }, 1); equiv2.setElementAt({ 2 }, 2); equiv2.setElementAt({ 3 }, 1); // Duplicate, but same unique elements auto not_equiv = createInt32Array({ 3 }, 0); not_equiv.setElementAt({ 0 }, 1); not_equiv.setElementAt({ 1 }, 2); not_equiv.setElementAt({ 2 }, 4); // Different element if (!(set_ops::array_equiv(equiv1, equiv2) == true)) { std::string description = std::string("testUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(set_ops::array_equiv(equiv1, equiv2) == true)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(set_ops::array_equiv(equiv1, not_equiv) == false)) { std::string description = std::string("testUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(set_ops::array_equiv(equiv1, not_equiv) == false)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] array_equiv function works correctly\n"; .. _example-top_level-array_equiv-907: .. dropdown:: array_equiv (np_test_1_all.cpp:19718) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19708 :emphasize-lines: 11 equiv2.setElementAt({ 0 }, 3); equiv2.setElementAt({ 1 }, 1); equiv2.setElementAt({ 2 }, 2); equiv2.setElementAt({ 3 }, 1); // Duplicate, but same unique elements auto not_equiv = createInt32Array({ 3 }, 0); not_equiv.setElementAt({ 0 }, 1); not_equiv.setElementAt({ 1 }, 2); not_equiv.setElementAt({ 2 }, 4); // Different element if (!(set_ops::array_equiv(equiv1, equiv2) == true)) { std::string description = std::string("testUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(set_ops::array_equiv(equiv1, equiv2) == true)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(set_ops::array_equiv(equiv1, not_equiv) == false)) { std::string description = std::string("testUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(set_ops::array_equiv(equiv1, not_equiv) == false)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] array_equiv function works correctly\n"; .. _example-top_level-equal-908: .. dropdown:: equal (np_test_1_all.cpp:865) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 855 :emphasize-lines: 11 throw std::runtime_error("testScalarComparisons(): array < scalar [1] failed"); } bool lt_s_2 = lt_scalar.getElementAt({2}); if (lt_s_2 != false) { // 4.0 < 3.0 = false std::cout << "[FAIL] in testScalarComparisons(): array[2] < 3.0: " << lt_s_2 << ", expected false" << std::endl; throw std::runtime_error("testScalarComparisons(): array < scalar [2] failed"); } // std::cout << "[OK] array < scalar"; // Test array == scalar auto eq_scalar = equal(arr, 2.5); bool eq_s_0 = eq_scalar.getElementAt({0}); if (eq_s_0 != false) { // 1.0 == 2.5 = false std::cout << "[FAIL] in testScalarComparisons(): array[0] == 2.5: " << eq_s_0 << ", expected false" << std::endl; throw std::runtime_error("testScalarComparisons(): array == scalar [0] failed"); } bool eq_s_1 = eq_scalar.getElementAt({1}); if (eq_s_1 != true) { // 2.5 == 2.5 = true std::cout << "[FAIL] in testScalarComparisons(): array[1] == 2.5: " << eq_s_1 << ", expected true" << std::endl; throw std::runtime_error("testScalarComparisons(): array == scalar [1] failed"); } .. _example-top_level-greater-909: .. dropdown:: greater (np_test_1_all.cpp:682) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 672 :emphasize-lines: 11 a.setElementAt({2}, 3.0); a.setElementAt({3}, 4.0); auto b = createFloat64Array({4}); b.setElementAt({0}, 2.0); b.setElementAt({1}, 2.0); b.setElementAt({2}, 1.0); b.setElementAt({3}, 5.0); // Test greater auto gt_result = greater(a, b); bool gt_0 = gt_result.getElementAt({0}); if (gt_0 != false) { // 1.0 > 2.0 = false std::cout << "[FAIL] in testElementWiseComparisons(): greater(1.0, 2.0) = " << gt_0 << ", expected false" << std::endl; throw std::runtime_error("testElementWiseComparisons(): greater comparison [0] failed"); } bool gt_1 = gt_result.getElementAt({1}); if (gt_1 != false) { // 2.0 > 2.0 = false std::cout << "[FAIL] in testElementWiseComparisons(): greater(2.0, 2.0) = " << gt_1 << ", expected false" << std::endl; throw std::runtime_error("testElementWiseComparisons(): greater comparison [1] failed"); } .. _example-top_level-greater_equal-910: .. dropdown:: greater_equal (np_test_1_all.cpp:706) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 696 :emphasize-lines: 11 throw std::runtime_error("testElementWiseComparisons(): greater comparison [2] failed"); } bool gt_3 = gt_result.getElementAt({3}); if (gt_3 != false) { // 4.0 > 5.0 = false std::cout << "[FAIL] in testElementWiseComparisons(): greater(4.0, 5.0) = " << gt_3 << ", expected false" << std::endl; throw std::runtime_error("testElementWiseComparisons(): greater comparison [3] failed"); } // std::cout << "[OK] greater function"; // Test greater_equal auto ge_result = greater_equal(a, b); bool ge_0 = ge_result.getElementAt({0}); if (ge_0 != false) { // 1.0 >= 2.0 = false std::cout << "[FAIL] in testElementWiseComparisons(): greater_equal(1.0, 2.0) = " << ge_0 << ", expected false" << std::endl; throw std::runtime_error("testElementWiseComparisons(): greater_equal comparison [0] failed"); } bool ge_1 = ge_result.getElementAt({1}); if (ge_1 != true) { // 2.0 >= 2.0 = true std::cout << "[FAIL] in testElementWiseComparisons(): greater_equal(2.0, 2.0) = " << ge_1 << ", expected true" << std::endl; throw std::runtime_error("testElementWiseComparisons(): greater_equal comparison [1] failed"); } .. _example-top_level-less-911: .. dropdown:: less (np_test_1_all.cpp:730) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 720 :emphasize-lines: 11 throw std::runtime_error("testElementWiseComparisons(): greater_equal comparison [2] failed"); } bool ge_3 = ge_result.getElementAt({3}); if (ge_3 != false) { // 4.0 >= 5.0 = false std::cout << "[FAIL] in testElementWiseComparisons(): greater_equal(4.0, 5.0) = " << ge_3 << ", expected false" << std::endl; throw std::runtime_error("testElementWiseComparisons(): greater_equal comparison [3] failed"); } // std::cout << "[OK] greater_equal function"; // Test less auto lt_result = less(a, b); bool lt_0 = lt_result.getElementAt({0}); if (lt_0 != true) { // 1.0 < 2.0 = true std::cout << "[FAIL] in testElementWiseComparisons(): less(1.0, 2.0) = " << lt_0 << ", expected true" << std::endl; throw std::runtime_error("testElementWiseComparisons(): less comparison [0] failed"); } bool lt_1 = lt_result.getElementAt({1}); if (lt_1 != false) { // 2.0 < 2.0 = false std::cout << "[FAIL] in testElementWiseComparisons(): less(2.0, 2.0) = " << lt_1 << ", expected false" << std::endl; throw std::runtime_error("testElementWiseComparisons(): less comparison [1] failed"); } .. _example-top_level-less_equal-912: .. dropdown:: less_equal (np_test_1_all.cpp:754) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 744 :emphasize-lines: 11 throw std::runtime_error("testElementWiseComparisons(): less comparison [2] failed"); } bool lt_3 = lt_result.getElementAt({3}); if (lt_3 != true) { // 4.0 < 5.0 = true std::cout << "[FAIL] in testElementWiseComparisons(): less(4.0, 5.0) = " << lt_3 << ", expected true" << std::endl; throw std::runtime_error("testElementWiseComparisons(): less comparison [3] failed"); } // std::cout << "[OK] less function"; // Test less_equal auto le_result = less_equal(a, b); bool le_0 = le_result.getElementAt({0}); if (le_0 != true) { // 1.0 <= 2.0 = true std::cout << "[FAIL] in testElementWiseComparisons(): less_equal(1.0, 2.0) = " << le_0 << ", expected true" << std::endl; throw std::runtime_error("testElementWiseComparisons(): less_equal comparison [0] failed"); } bool le_1 = le_result.getElementAt({1}); if (le_1 != true) { // 2.0 <= 2.0 = true std::cout << "[FAIL] in testElementWiseComparisons(): less_equal(2.0, 2.0) = " << le_1 << ", expected true" << std::endl; throw std::runtime_error("testElementWiseComparisons(): less_equal comparison [1] failed"); } .. _example-top_level-not_equal-913: .. dropdown:: not_equal (np_test_1_all.cpp:1050) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1040 :emphasize-lines: 11 // std::cout << "[OK] array_equal function" << std::endl; // Test equal and not_equal auto equal_result = equal(a, c); bool all_eq = allTrue(equal_result); if (all_eq != true) { std::cout << "[FAIL] in testExistingFunctions(): allTrue(equal(a, c)) = " << all_eq << ", expected true" << std::endl; throw std::runtime_error("testExistingFunctions(): equal all true failed"); } auto not_equal_result = not_equal(a, b); bool all_neq = allTrue(not_equal_result); if (all_neq != true) { std::cout << "[FAIL] in testExistingFunctions(): allTrue(not_equal(a, b)) = " << all_neq << ", expected true" << std::endl; throw std::runtime_error("testExistingFunctions(): not_equal all true failed"); } // std::cout << "[OK] equal and not_equal functions" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-all-914: .. dropdown:: all (np_test_4_all.cpp:23928) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23918 :emphasize-lines: 11 } } } auto result = numpy::einsum("ijk->ik", {A}); if (result.getShape()[0] != 2 || result.getShape()[1] != 2) { throw std::runtime_error("einsum partial sum shape wrong"); } // Sum over j: 1+2+3 = 6 for all (i,k) positions if (std::abs(result.getElementAt({0, 0}) - 6.0) > 1e-10 || std::abs(result.getElementAt({1, 1}) - 6.0) > 1e-10) { throw std::runtime_error("einsum partial sum values wrong"); } // std::cout << " OK: Partial sum: 'ijk->ik'\n"; } // Test 5: Size-1 dimension handling { .. _example-top_level-all-915: .. dropdown:: all (np_test_4_all.cpp:23928) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23918 :emphasize-lines: 11 } } } auto result = numpy::einsum("ijk->ik", {A}); if (result.getShape()[0] != 2 || result.getShape()[1] != 2) { throw std::runtime_error("einsum partial sum shape wrong"); } // Sum over j: 1+2+3 = 6 for all (i,k) positions if (std::abs(result.getElementAt({0, 0}) - 6.0) > 1e-10 || std::abs(result.getElementAt({1, 1}) - 6.0) > 1e-10) { throw std::runtime_error("einsum partial sum values wrong"); } // std::cout << " OK: Partial sum: 'ijk->ik'\n"; } // Test 5: Size-1 dimension handling { .. _example-top_level-allequal-916: .. dropdown:: allequal (np_test_3_all.cpp:15154) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15144 :emphasize-lines: 11 auto mask1 = createBoolArray({ 3 }, false); mask1.setElementAt({ 0 }, true); // Mask first element MaskedArray ma1(data1, mask1, -999.0); // Test allequal - identical auto data2 = data1; auto mask2 = mask1; MaskedArray ma2(data2, mask2, -999.0); if (!(allequal(ma1, ma2))) { std::string description = std::string("test_comparison_functions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(allequal(ma1, ma2))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] allequal() returns true for identical arrays\n"; // Test allequal - different data but same mask data2.setElementAt({ 1 }, 99.0); MaskedArray ma3(data2, mask2, -999.0); if (!(!allequal(ma1, ma3))) { .. _example-top_level-alltrue-917: .. dropdown:: alltrue (np_test_1_all.cpp:27518) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27508 :emphasize-lines: 11 double max_val = numpy::ma::amax(ma); double min_val = numpy::ma::amin(ma); // std::cout << " ma::amax() result: " << max_val << " (expected: 6)" << std::endl; // std::cout << " ma::amin() result: " << min_val << " (expected: 1)" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_alltrue_sometrue() { std::cout << "========= ma::alltrue() and ma::sometrue(): boolean checks ==="; auto data1 = numpy::array({ 1.0, 2.0, 0.0, 3.0 }); auto mask1 = numpy::array({ false, false, true, false }); auto ma1 = numpy::ma::masked_array(data1, mask1); auto data2 = numpy::array({ 0.0, 0.0, 1.0 }); auto mask2 = numpy::array({ false, false, false }); auto ma2 = numpy::ma::masked_array(data2, mask2); // std::cout << " ma::alltrue([1,2,-,3]): " << (numpy::ma::alltrue(ma1) ? "true" : "false") << " (expected: true)" << std::endl; .. _example-top_level-alltrue-918: .. dropdown:: alltrue (np_test_1_all.cpp:27518) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27508 :emphasize-lines: 11 double max_val = numpy::ma::amax(ma); double min_val = numpy::ma::amin(ma); // std::cout << " ma::amax() result: " << max_val << " (expected: 6)" << std::endl; // std::cout << " ma::amin() result: " << min_val << " (expected: 1)" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_alltrue_sometrue() { std::cout << "========= ma::alltrue() and ma::sometrue(): boolean checks ==="; auto data1 = numpy::array({ 1.0, 2.0, 0.0, 3.0 }); auto mask1 = numpy::array({ false, false, true, false }); auto ma1 = numpy::ma::masked_array(data1, mask1); auto data2 = numpy::array({ 0.0, 0.0, 1.0 }); auto mask2 = numpy::array({ false, false, false }); auto ma2 = numpy::ma::masked_array(data2, mask2); // std::cout << " ma::alltrue([1,2,-,3]): " << (numpy::ma::alltrue(ma1) ? "true" : "false") << " (expected: true)" << std::endl; .. _example-top_level-any-919: .. dropdown:: any (np_test_2_all.cpp:16758) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16748 :emphasize-lines: 11 // ANY() TESTS - SCALAR RESULT // ============================================================================ void np_test_logic_any_scalar_all_false() { std::cout << "========= any: all false elements ======================="; // Create array with all false/zero elements std::vector data = { 0.0, 0.0, 0.0 }; numpy::NDArray arr = numpy::createArrayFromVector({ 3 }, data); bool result = numpy::any(arr); if (result != false) { std::cout << " [FAIL] : in np_test_logic_any_scalar_all_false() : expected false for all-zero array"; throw std::runtime_error("np_test_logic_any_scalar_all_false failed: expected false"); } std::cout << " -> tests passed" << std::endl; } void np_test_logic_any_scalar_all_true() { .. _example-top_level-any-920: .. dropdown:: any (np_test_2_all.cpp:16758) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16748 :emphasize-lines: 11 // ANY() TESTS - SCALAR RESULT // ============================================================================ void np_test_logic_any_scalar_all_false() { std::cout << "========= any: all false elements ======================="; // Create array with all false/zero elements std::vector data = { 0.0, 0.0, 0.0 }; numpy::NDArray arr = numpy::createArrayFromVector({ 3 }, data); bool result = numpy::any(arr); if (result != false) { std::cout << " [FAIL] : in np_test_logic_any_scalar_all_false() : expected false for all-zero array"; throw std::runtime_error("np_test_logic_any_scalar_all_false failed: expected false"); } std::cout << " -> tests passed" << std::endl; } void np_test_logic_any_scalar_all_true() { .. _example-top_level-iscomplex-921: .. dropdown:: iscomplex (np_test_2_all.cpp:16944) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16934 :emphasize-lines: 11 // ISCOMPLEX() TESTS // ============================================================================ void np_test_logic_iscomplex_real() { std::cout << "========= iscomplex: real-valued array ======================="; // Create real-valued array std::vector data = { 1.0, 2.0, 3.0 }; numpy::NDArray arr = numpy::createArrayFromVector({ 3 }, data); auto result = numpy::iscomplex(arr); // All should be false for real array for (size_t i = 0; i < 3; ++i) { if (result.getElementAt({ i }) != false) { std::cout << " [FAIL] : in np_test_logic_iscomplex_real() : expected all false for real array"; throw std::runtime_error("np_test_logic_iscomplex_real failed: expected false"); } } std::cout << " -> tests passed" << std::endl; .. _example-top_level-iscomplexobj-922: .. dropdown:: iscomplexobj (np_test_4_all.cpp:18056) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18046 :emphasize-lines: 11 std::cout << "Exception: " << e.what() << ""; std::cout << "==============================================\n"; return 1; } } } // namespace numpy_tests // ============================================================================ // isrealobj() and iscomplexobj() scalar + array support tests // ============================================================================ namespace numpy_tests { namespace numpy_tests_isrealobj_scalar { void test_scalar_int32() { std::cout << "========= isrealobj/iscomplexobj(int32) ===="; int32_t val = 42; .. _example-top_level-iscomplexobj-923: .. dropdown:: iscomplexobj (np_test_4_all.cpp:18056) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18046 :emphasize-lines: 11 std::cout << "Exception: " << e.what() << ""; std::cout << "==============================================\n"; return 1; } } } // namespace numpy_tests // ============================================================================ // isrealobj() and iscomplexobj() scalar + array support tests // ============================================================================ namespace numpy_tests { namespace numpy_tests_isrealobj_scalar { void test_scalar_int32() { std::cout << "========= isrealobj/iscomplexobj(int32) ===="; int32_t val = 42; .. _example-top_level-isfinite-924: .. dropdown:: isfinite (np_test_1_all.cpp:7769) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7759 :emphasize-lines: 11 float16 zero(0.0f); // std::cout << "Positive infinity: " << pos_inf << std::endl; // std::cout << "Negative infinity: " << neg_inf << std::endl; // std::cout << "Quiet NaN: " << qnan << std::endl; // std::cout << "Zero: " << zero << std::endl; // std::cout << "Is pos_inf infinite? " << pos_inf.isinf() << std::endl; // std::cout << "Is neg_inf infinite? " << neg_inf.isinf() << std::endl; // std::cout << "Is qnan NaN? " << qnan.isnan() << std::endl; // std::cout << "Is zero finite? " << zero.isfinite() << std::endl; // Test NaN comparison behavior // std::cout << "NaN == NaN: " << (qnan == qnan) << std::endl; // Should be false // std::cout << "NaN != NaN: " << (qnan != qnan) << std::endl; // Should be true // std::cout << " -> tests passed" << std::endl; } void testFloat16PrecisionFloat16() { std::cout << "========= testFloat16PrecisionFloat16 ======================="; .. _example-top_level-isinf-925: .. dropdown:: isinf (np_test_1_all.cpp:7766) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7756 :emphasize-lines: 11 float16 pos_inf = float16::infinity(); float16 neg_inf = -float16::infinity(); float16 qnan = float16::quiet_NaN(); float16 zero(0.0f); // std::cout << "Positive infinity: " << pos_inf << std::endl; // std::cout << "Negative infinity: " << neg_inf << std::endl; // std::cout << "Quiet NaN: " << qnan << std::endl; // std::cout << "Zero: " << zero << std::endl; // std::cout << "Is pos_inf infinite? " << pos_inf.isinf() << std::endl; // std::cout << "Is neg_inf infinite? " << neg_inf.isinf() << std::endl; // std::cout << "Is qnan NaN? " << qnan.isnan() << std::endl; // std::cout << "Is zero finite? " << zero.isfinite() << std::endl; // Test NaN comparison behavior // std::cout << "NaN == NaN: " << (qnan == qnan) << std::endl; // Should be false // std::cout << "NaN != NaN: " << (qnan != qnan) << std::endl; // Should be true // std::cout << " -> tests passed" << std::endl; } .. _example-top_level-isnan-926: .. dropdown:: isnan (np_test_1_all.cpp:7768) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7758 :emphasize-lines: 11 float16 qnan = float16::quiet_NaN(); float16 zero(0.0f); // std::cout << "Positive infinity: " << pos_inf << std::endl; // std::cout << "Negative infinity: " << neg_inf << std::endl; // std::cout << "Quiet NaN: " << qnan << std::endl; // std::cout << "Zero: " << zero << std::endl; // std::cout << "Is pos_inf infinite? " << pos_inf.isinf() << std::endl; // std::cout << "Is neg_inf infinite? " << neg_inf.isinf() << std::endl; // std::cout << "Is qnan NaN? " << qnan.isnan() << std::endl; // std::cout << "Is zero finite? " << zero.isfinite() << std::endl; // Test NaN comparison behavior // std::cout << "NaN == NaN: " << (qnan == qnan) << std::endl; // Should be false // std::cout << "NaN != NaN: " << (qnan != qnan) << std::endl; // Should be true // std::cout << " -> tests passed" << std::endl; } void testFloat16PrecisionFloat16() { .. _example-top_level-isneginf-927: .. dropdown:: isneginf (np_test_5_all.cpp:4531) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4521 :emphasize-lines: 11 } void np_test_isneginf() { std::cout << "========= isneginf ======================="; double inf = std::numeric_limits::infinity(); double neginf = -std::numeric_limits::infinity(); double nan = std::numeric_limits::quiet_NaN(); // Test scalar values bool result1 = numpy::isneginf(neginf); bool result2 = numpy::isneginf(inf); bool result3 = numpy::isneginf(-1.0); bool result4 = numpy::isneginf(nan); if (!result1 || result2 || result3 || result4) { std::cout << " [FAIL] : in np_test_isneginf() : Scalar test failed"; throw std::runtime_error("Test failed"); } // Test with array .. _example-top_level-isneginf-928: .. dropdown:: isneginf (np_test_5_all.cpp:4531) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4521 :emphasize-lines: 11 } void np_test_isneginf() { std::cout << "========= isneginf ======================="; double inf = std::numeric_limits::infinity(); double neginf = -std::numeric_limits::infinity(); double nan = std::numeric_limits::quiet_NaN(); // Test scalar values bool result1 = numpy::isneginf(neginf); bool result2 = numpy::isneginf(inf); bool result3 = numpy::isneginf(-1.0); bool result4 = numpy::isneginf(nan); if (!result1 || result2 || result3 || result4) { std::cout << " [FAIL] : in np_test_isneginf() : Scalar test failed"; throw std::runtime_error("Test failed"); } // Test with array .. _example-top_level-isposinf-929: .. dropdown:: isposinf (np_test_5_all.cpp:4492) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4482 :emphasize-lines: 11 namespace numpy_tests_float_utilities { void np_test_isposinf() { std::cout << "========= isposinf ======================="; double inf = std::numeric_limits::infinity(); double neginf = -std::numeric_limits::infinity(); double nan = std::numeric_limits::quiet_NaN(); // Test scalar values bool result1 = numpy::isposinf(inf); bool result2 = numpy::isposinf(neginf); bool result3 = numpy::isposinf(1.0); bool result4 = numpy::isposinf(nan); if (!result1 || result2 || result3 || result4) { std::cout << " [FAIL] : in np_test_isposinf() : Scalar test failed"; throw std::runtime_error("Test failed"); } // Test with array .. _example-top_level-isposinf-930: .. dropdown:: isposinf (np_test_5_all.cpp:4492) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4482 :emphasize-lines: 11 namespace numpy_tests_float_utilities { void np_test_isposinf() { std::cout << "========= isposinf ======================="; double inf = std::numeric_limits::infinity(); double neginf = -std::numeric_limits::infinity(); double nan = std::numeric_limits::quiet_NaN(); // Test scalar values bool result1 = numpy::isposinf(inf); bool result2 = numpy::isposinf(neginf); bool result3 = numpy::isposinf(1.0); bool result4 = numpy::isposinf(nan); if (!result1 || result2 || result3 || result4) { std::cout << " [FAIL] : in np_test_isposinf() : Scalar test failed"; throw std::runtime_error("Test failed"); } // Test with array .. _example-top_level-isreal-931: .. dropdown:: isreal (np_test_5_all.cpp:4566) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4556 :emphasize-lines: 11 throw std::runtime_error("Test failed"); } std::cout << " -> tests passed" << std::endl; } void np_test_isreal() { std::cout << "========= isreal ======================="; // For real numbers, isreal should return true bool result1 = numpy::isreal(1.5); bool result2 = numpy::isreal(0.0); bool result3 = numpy::isreal(-3.14); if (!result1 || !result2 || !result3) { std::cout << " [FAIL] : in np_test_isreal() : Scalar test failed"; throw std::runtime_error("Test failed"); } // Test with array numpy::NDArray arr({ 3 }); .. _example-top_level-isrealobj-932: .. dropdown:: isrealobj (np_test_4_all.cpp:18056) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18046 :emphasize-lines: 11 std::cout << "Exception: " << e.what() << ""; std::cout << "==============================================\n"; return 1; } } } // namespace numpy_tests // ============================================================================ // isrealobj() and iscomplexobj() scalar + array support tests // ============================================================================ namespace numpy_tests { namespace numpy_tests_isrealobj_scalar { void test_scalar_int32() { std::cout << "========= isrealobj/iscomplexobj(int32) ===="; int32_t val = 42; .. _example-top_level-isrealobj-933: .. dropdown:: isrealobj (np_test_4_all.cpp:18056) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18046 :emphasize-lines: 11 std::cout << "Exception: " << e.what() << ""; std::cout << "==============================================\n"; return 1; } } } // namespace numpy_tests // ============================================================================ // isrealobj() and iscomplexobj() scalar + array support tests // ============================================================================ namespace numpy_tests { namespace numpy_tests_isrealobj_scalar { void test_scalar_int32() { std::cout << "========= isrealobj/iscomplexobj(int32) ===="; int32_t val = 42; .. _example-top_level-isscalar-934: .. dropdown:: isscalar (np_test_2_all.cpp:3579) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3569 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(dtype_itemsize(arr) == sizeof(double))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(dtype_itemsize(arr) == sizeof(double))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test utility checks if (!(!isscalar(arr))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!isscalar(arr))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!isvector(arr))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!isvector(arr))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!ismatrix(arr))) { .. _example-top_level-unique_all-935: .. dropdown:: unique_all (np_test_1_all.cpp:19808) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19798 :emphasize-lines: 11 // Test data with duplicates auto array = createInt32Array({ 7 }, 0); array.setElementAt({ 0 }, 1); array.setElementAt({ 1 }, 2); array.setElementAt({ 2 }, 3); array.setElementAt({ 3 }, 2); // Duplicate array.setElementAt({ 4 }, 1); // Duplicate array.setElementAt({ 5 }, 4); array.setElementAt({ 6 }, 3); // Duplicate // Test unique_all() auto unique_all_result = unique_all(array); if (!(unique_all_result.values.getSize() == 4)) { std::string description = std::string("testNumPy2UniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_all_result.values.getSize() == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(unique_all_result.indices.getSize() == 4)) { std::string description = std::string("testNumPy2UniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_all_result.indices.getSize() == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-unique_counts-936: .. dropdown:: unique_counts (np_test_1_all.cpp:19876) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19866 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(unique_all_result.counts.getElementAt({ 3 }) == 1)) { std::string description = std::string("testNumPy2UniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_all_result.counts.getElementAt({ 3 }) == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] unique_all() works correctly\n"; // Test unique_counts() auto unique_counts_result = unique_counts(array); if (!(unique_counts_result.values.getSize() == 4)) { std::string description = std::string("testNumPy2UniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_counts_result.values.getSize() == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(unique_counts_result.counts.getSize() == 4)) { std::string description = std::string("testNumPy2UniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_counts_result.counts.getSize() == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-unique_full-937: .. dropdown:: unique_full (np_test_1_all.cpp:19029) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19019 :emphasize-lines: 11 for (size_t i = 0; i < expected.size(); ++i) { if (!(unique_result.getElementAt({ i }) == expected[i])) { std::string description = std::string("testUniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_result.getElementAt({ i }) == expected[i])"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] Basic unique operation works correctly\n"; // Test unique with return_counts auto unique_full_result = set_ops::unique_full(array, false, false, true); if (!(unique_full_result.values.getSize() == 4)) { std::string description = std::string("testUniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_full_result.values.getSize() == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(unique_full_result.counts.getSize() == 4)) { std::string description = std::string("testUniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_full_result.counts.getSize() == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-unique_inverse-938: .. dropdown:: unique_inverse (np_test_1_all.cpp:19904) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19894 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(unique_counts_result.counts.getElementAt({ i }) == unique_all_result.counts.getElementAt({ i }))) { std::string description = std::string("testNumPy2UniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_counts_result.counts.getElementAt({ i }) == unique_all_result.counts.getElementAt({ i }))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] unique_counts() works correctly\n"; // Test unique_inverse() auto unique_inverse_result = unique_inverse(array); if (!(unique_inverse_result.values.getSize() == 4)) { std::string description = std::string("testNumPy2UniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_inverse_result.values.getSize() == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(unique_inverse_result.inverse_indices.getSize() == 7)) { std::string description = std::string("testNumPy2UniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_inverse_result.inverse_indices.getSize() == 7)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-unique_values-939: .. dropdown:: unique_values (np_test_1_all.cpp:19934) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19924 :emphasize-lines: 11 } for (size_t i = 0; i < 7; ++i) { if (!(unique_inverse_result.inverse_indices.getElementAt({ i }) == unique_all_result.inverse_indices.getElementAt({ i }))) { std::string description = std::string("testNumPy2UniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_inverse_result.inverse_indices.getElementAt({ i }) == unique_all_result.inverse_indices.getElementAt({ i }))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] unique_inverse() works correctly\n"; // Test unique_values() auto unique_values_result = unique_values(array); if (!(unique_values_result.values.getSize() == 4)) { std::string description = std::string("testNumPy2UniqueOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_values_result.values.getSize() == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Verify same results as unique_all for values for (size_t i = 0; i < 4; ++i) { if (!(unique_values_result.values.getElementAt({ i }) == unique_all_result.values.getElementAt({ i }))) { .. _example-top_level-append_fields-940: .. dropdown:: append_fields (np_test_1_all.cpp:25911) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 25901 :emphasize-lines: 11 auto score_ptr = make_shared_data(score_data); auto rank_ptr = make_shared_data(rank_data); // Append fields std::vector new_field_names = { "score", "rank" }; std::vector>> new_field_data = { {numpy::DType::FLOAT64, score_ptr}, {numpy::DType::INT32, rank_ptr} }; auto result = numpy::RecFunctions::append_fields(base_arr, new_field_names, new_field_data); // Verify result has 4 fields auto field_names = result.getFieldNames(); bool passed = (field_names.size() == 4); if (passed) { // Verify original fields preserved passed = (result.getFieldValue({ 0 }, "id") == 1); passed = passed && (result.getFieldValue({ 1 }, "id") == 2); passed = passed && (result.getFieldValue({ 2 }, "name_length") == 6); .. _example-top_level-array_split-941: .. dropdown:: array_split (np_test_1_all.cpp:5955) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5945 :emphasize-lines: 11 void testArraySplitArrayUtils() { std::cout << "========= testArraySplitArrayUtils ======================"; // Create array that doesn't divide evenly auto arr = NDArray::createRange(0, 10, 1); // [0, 1, 2, ..., 9] (10 elements) // std::cout << "Original array (10 elements):" << std::endl; //arr.printArray(); // Split into 3 unequal sections auto unequal_splits = array_split(arr, 3, 0); // std::cout << "Array split into 3 unequal sections:" << std::endl; if (!(unequal_splits.size() == 3)) { std::string description = std::string("testArraySplitArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unequal_splits.size() == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Should be: [0,1,2,3], [4,5,6], [7,8,9] // std::cout << "Section 0:" << std::endl; .. _example-top_level-dsplit-942: .. dropdown:: dsplit (np_test_1_all.cpp:5916) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5906 :emphasize-lines: 11 if (!(vsplits[i].getShape()[1] == 6)) { std::string description = std::string("testHVDSplitArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(vsplits[i].getShape()[1] == 6)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] vsplit works" << std::endl; // Test dsplit with 3D array auto arr3d = createInt32Array({2, 3, 6}, 1); auto dsplits = dsplit(arr3d, 2); // Split into 2 sections along axis 2 if (!(dsplits.size() == 2)) { std::string description = std::string("testHVDSplitArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(dsplits.size() == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (const auto& split : dsplits) { if (!(split.getShape()[0] == 2)) { std::string description = std::string("testHVDSplitArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(split.getShape()[0] == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-hsplit-943: .. dropdown:: hsplit (np_test_1_all.cpp:5865) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5855 :emphasize-lines: 11 for (size_t i = 0; i < 4; ++i) { for (size_t j = 0; j < 6; ++j) { arr2d.setElementAt({i, j}, static_cast(i * 10 + j)); } } // std::cout << "Original 4x6 array:" << std::endl; //arr2d.printArray(); // Test hsplit auto hsplits = hsplit(arr2d, 3); // Split into 3 sections along axis 1 // std::cout << "Horizontal split into 3 sections:" << std::endl; if (!(hsplits.size() == 3)) { std::string description = std::string("testHVDSplitArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(hsplits.size() == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < hsplits.size(); ++i) { // std::cout << "HSection " << i << ":"; //hsplits[i].printArray(); .. _example-top_level-hsplit-944: .. dropdown:: hsplit (np_test_1_all.cpp:5865) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5855 :emphasize-lines: 11 for (size_t i = 0; i < 4; ++i) { for (size_t j = 0; j < 6; ++j) { arr2d.setElementAt({i, j}, static_cast(i * 10 + j)); } } // std::cout << "Original 4x6 array:" << std::endl; //arr2d.printArray(); // Test hsplit auto hsplits = hsplit(arr2d, 3); // Split into 3 sections along axis 1 // std::cout << "Horizontal split into 3 sections:" << std::endl; if (!(hsplits.size() == 3)) { std::string description = std::string("testHVDSplitArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(hsplits.size() == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < hsplits.size(); ++i) { // std::cout << "HSection " << i << ":"; //hsplits[i].printArray(); .. _example-top_level-split-945: .. dropdown:: split (np_test_1_all.cpp:5760) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5750 :emphasize-lines: 11 std::cout << "========= testSplitArrayUtils ======================"; // Create test array auto arr = NDArray::createRange(0, 12, 1); // [0, 1, 2, ..., 11] auto arr2d = arr.reshapeArray({3, 4}); // std::cout << "Original 2D array:" << std::endl; //arr2d.printArray(); // Test split into equal sections auto splits = split(arr2d, 3, 0); // Split along axis 0 into 3 sections // std::cout << "Split into 3 sections along axis 0:" << std::endl; if (!(splits.size() == 3)) { std::string description = std::string("testSplitArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(splits.size() == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < splits.size(); ++i) { // std::cout << "Section " << i << ":"; //splits[i].printArray(); .. _example-top_level-split-946: .. dropdown:: split (np_test_1_all.cpp:5760) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5750 :emphasize-lines: 11 std::cout << "========= testSplitArrayUtils ======================"; // Create test array auto arr = NDArray::createRange(0, 12, 1); // [0, 1, 2, ..., 11] auto arr2d = arr.reshapeArray({3, 4}); // std::cout << "Original 2D array:" << std::endl; //arr2d.printArray(); // Test split into equal sections auto splits = split(arr2d, 3, 0); // Split along axis 0 into 3 sections // std::cout << "Split into 3 sections along axis 0:" << std::endl; if (!(splits.size() == 3)) { std::string description = std::string("testSplitArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(splits.size() == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < splits.size(); ++i) { // std::cout << "Section " << i << ":"; //splits[i].printArray(); .. _example-top_level-split-947: .. dropdown:: split (np_test_1_all.cpp:5760) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5750 :emphasize-lines: 11 std::cout << "========= testSplitArrayUtils ======================"; // Create test array auto arr = NDArray::createRange(0, 12, 1); // [0, 1, 2, ..., 11] auto arr2d = arr.reshapeArray({3, 4}); // std::cout << "Original 2D array:" << std::endl; //arr2d.printArray(); // Test split into equal sections auto splits = split(arr2d, 3, 0); // Split along axis 0 into 3 sections // std::cout << "Split into 3 sections along axis 0:" << std::endl; if (!(splits.size() == 3)) { std::string description = std::string("testSplitArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(splits.size() == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < splits.size(); ++i) { // std::cout << "Section " << i << ":"; //splits[i].printArray(); .. _example-top_level-splitlines-948: .. dropdown:: splitlines (np_test_5_all.cpp:1395) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1385 :emphasize-lines: 11 } std::cout << " -> tests passed" << std::endl; } void np_test_string_splitlines() { std::cout << "========= splitlines operation ======================="; std::vector strings = { "hello\nworld\ntest", "line1\nline2" }; auto arr = numpy::char_::array<32>(strings); auto result = numpy::char_::splitlines(arr); // Returns vector of CharArrays bool passed = (result.size() > 0); if (!passed) { std::cout << " [FAIL] : in np_test_string_splitlines() : splitlines returned empty result"; throw std::runtime_error("np_test_string_splitlines failed"); } std::cout << " -> tests passed" << std::endl; .. _example-top_level-splitlines-949: .. dropdown:: splitlines (np_test_5_all.cpp:1395) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1385 :emphasize-lines: 11 } std::cout << " -> tests passed" << std::endl; } void np_test_string_splitlines() { std::cout << "========= splitlines operation ======================="; std::vector strings = { "hello\nworld\ntest", "line1\nline2" }; auto arr = numpy::char_::array<32>(strings); auto result = numpy::char_::splitlines(arr); // Returns vector of CharArrays bool passed = (result.size() > 0); if (!passed) { std::cout << " [FAIL] : in np_test_string_splitlines() : splitlines returned empty result"; throw std::runtime_error("np_test_string_splitlines failed"); } std::cout << " -> tests passed" << std::endl; .. _example-top_level-stack_arrays-950: .. dropdown:: stack_arrays (np_test_1_all.cpp:21784) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21774 :emphasize-lines: 11 // std::cout << "Array 1:" << std::endl; //arr1.printArray(); // std::cout << "Array 2:" << std::endl; //arr2.printArray(); auto merged = merge_arrays({ arr1, arr2 }); // std::cout << "Merged arrays:"; //merged.printArray(); auto stacked = stack_arrays({ arr1 }); // std::cout << "Stacked arrays (single array):"; //stacked.printArray(); std::cout << " -> tests passed" << std::endl; } void testRecFunctionsJoin() { std::cout << "========= testRecFunctionsJoin ======================="; auto dtype = std::make_shared(std::vector>{ .. _example-top_level-vsplit-951: .. dropdown:: vsplit (np_test_1_all.cpp:5890) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5880 :emphasize-lines: 11 } if (!(hsplits[i].getShape()[1] == 2)) { std::string description = std::string("testHVDSplitArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(hsplits[i].getShape()[1] == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] hsplit works" << std::endl; // Test vsplit auto vsplits = vsplit(arr2d, 2); // Split into 2 sections along axis 0 // std::cout << "Vertical split into 2 sections:" << std::endl; if (!(vsplits.size() == 2)) { std::string description = std::string("testHVDSplitArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(vsplits.size() == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < vsplits.size(); ++i) { // std::cout << "VSection " << i << ":"; //vsplits[i].printArray(); .. _example-top_level-vsplit-952: .. dropdown:: vsplit (np_test_1_all.cpp:5890) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5880 :emphasize-lines: 11 } if (!(hsplits[i].getShape()[1] == 2)) { std::string description = std::string("testHVDSplitArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(hsplits[i].getShape()[1] == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] hsplit works" << std::endl; // Test vsplit auto vsplits = vsplit(arr2d, 2); // Split into 2 sections along axis 0 // std::cout << "Vertical split into 2 sections:" << std::endl; if (!(vsplits.size() == 2)) { std::string description = std::string("testHVDSplitArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(vsplits.size() == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < vsplits.size(); ++i) { // std::cout << "VSection " << i << ":"; //vsplits[i].printArray(); .. _example-top_level-asarray-953: .. dropdown:: asarray (np_test_2_all.cpp:16085) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16075 :emphasize-lines: 11 // ============================================================================ // ASARRAY TESTS // ============================================================================ void np_test_array_creation_asarray_view_copy() { std::cout << "========= asarray: view vs copy behavior ======================="; auto original = numpy::arange(0.0f, 10.0f, 1.0f); // Test view (no copy) auto view = numpy::asarray(original, false); original.setElementAt({ 0 }, 999.0f); float view_val = view.getElementAt({ 0 }); if (view_val != 999.0f) { std::cout << " [FAIL] : View should reflect changes"; throw std::runtime_error("asarray view test failed"); } // Test copy original.setElementAt({ 0 }, 0.0f); // Reset auto copy = numpy::asarray(original, true); .. _example-top_level-can_cast-954: .. dropdown:: can_cast (np_test_3_all.cpp:6773) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6763 :emphasize-lines: 11 #include "../numpy/np_dtype_utils.h" namespace numpy_tests { using namespace numpy; void np_test_can_cast_no_casting() { std::cout << "========= np_test_can_cast_no_casting ======================="; // NO mode: only exact type matches allowed if (!can_cast(DType::INT32, DType::INT32, CastingMode::NO)) { std::cerr << "[FAIL] INT32 -> INT32 (NO) should be true"; throw std::runtime_error("NO casting test failed"); } // std::cout << "[OK] INT32 -> INT32 (NO): true" << std::endl; if (can_cast(DType::INT8, DType::INT16, CastingMode::NO)) { std::cerr << "[FAIL] INT8 -> INT16 (NO) should be false"; throw std::runtime_error("NO casting test failed"); } // std::cout << "[OK] INT8 -> INT16 (NO): false (different types)" << std::endl; .. _example-top_level-common_type-955: .. dropdown:: common_type (np_test_3_all.cpp:7233) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7223 :emphasize-lines: 11 } //============================================================================== // COMMON_TYPE TESTS //============================================================================== void np_test_common_type_basic() { std::cout << "========= np_test_common_type_basic ======================="; // Integers -> FLOAT64 if (common_type({DType::INT32, DType::INT64}) != DType::FLOAT64) { std::cerr << "[FAIL] common_type({INT32, INT64}) should be FLOAT64"; throw std::runtime_error("common_type test failed"); } // std::cout << "[OK] common_type({INT32, INT64}) -> FLOAT64 (integers promoted to float)" << std::endl; // Floats stay as highest float if (common_type({DType::FLOAT32, DType::FLOAT64}) != DType::FLOAT64) { std::cerr << "[FAIL] common_type({FLOAT32, FLOAT64}) should be FLOAT64"; throw std::runtime_error("common_type test failed"); } .. _example-top_level-common_type-956: .. dropdown:: common_type (np_test_3_all.cpp:7233) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7223 :emphasize-lines: 11 } //============================================================================== // COMMON_TYPE TESTS //============================================================================== void np_test_common_type_basic() { std::cout << "========= np_test_common_type_basic ======================="; // Integers -> FLOAT64 if (common_type({DType::INT32, DType::INT64}) != DType::FLOAT64) { std::cerr << "[FAIL] common_type({INT32, INT64}) should be FLOAT64"; throw std::runtime_error("common_type test failed"); } // std::cout << "[OK] common_type({INT32, INT64}) -> FLOAT64 (integers promoted to float)" << std::endl; // Floats stay as highest float if (common_type({DType::FLOAT32, DType::FLOAT64}) != DType::FLOAT64) { std::cerr << "[FAIL] common_type({FLOAT32, FLOAT64}) should be FLOAT64"; throw std::runtime_error("common_type test failed"); } .. _example-top_level-copysign-957: .. dropdown:: copysign (np_test_3_all.cpp:19372) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19362 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) + 1.0; // Always positive b[i] = (i % 2 == 0) ? 1.0 : -1.0; // Alternating signs } mkl::mkl_copysign_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::copysign(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_copysign():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: copysign results match std::copysign\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-copysign-958: .. dropdown:: copysign (np_test_3_all.cpp:19372) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19362 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) + 1.0; // Always positive b[i] = (i % 2 == 0) ? 1.0 : -1.0; // Alternating signs } mkl::mkl_copysign_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::copysign(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_copysign():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: copysign results match std::copysign\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-copyto-959: .. dropdown:: copyto (np_test_5_all.cpp:10895) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10885 :emphasize-lines: 11 namespace numpy_tests { namespace numpy_tests_copyto { void test_basic_copy_without_mask() { std::cout << " Test 1: Basic Copy Without Mask" << std::endl; auto dst = numpy::NDArray::createZeros({ 3, 3 }); auto src = numpy::NDArray::createOnes({ 3, 3 }); numpy::copyto(dst, src); // Verify all elements are 1 for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 3; ++j) { assert(dst.getElementAt({ i, j }) == 1); } } std::cout << " PASS: All elements copied successfully" << std::endl; } .. _example-top_level-promote_types-960: .. dropdown:: promote_types (np_test_3_all.cpp:7025) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7015 :emphasize-lines: 11 using namespace numpy; //============================================================================== // PROMOTE_TYPES TESTS //============================================================================== void np_test_promote_types_same_type() { std::cout << "========= np_test_promote_types_same_type ======================="; if (promote_types(DType::INT32, DType::INT32) != DType::INT32) { std::cerr << "[FAIL] INT32 + INT32 should be INT32"; throw std::runtime_error("promote_types test failed"); } // std::cout << "[OK] INT32 + INT32 -> INT32" << std::endl; if (promote_types(DType::FLOAT64, DType::FLOAT64) != DType::FLOAT64) { std::cerr << "[FAIL] FLOAT64 + FLOAT64 should be FLOAT64"; throw std::runtime_error("promote_types test failed"); } // std::cout << "[OK] FLOAT64 + FLOAT64 -> FLOAT64" << std::endl; .. _example-top_level-result_type-961: .. dropdown:: result_type (np_test_3_all.cpp:7196) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7186 :emphasize-lines: 11 } //============================================================================== // RESULT_TYPE TESTS //============================================================================== void np_test_result_type_basic() { std::cout << "========= np_test_result_type_basic ======================="; // Single type if (result_type({DType::INT32}) != DType::INT32) { std::cerr << "[FAIL] result_type({INT32}) should be INT32"; throw std::runtime_error("result_type test failed"); } // std::cout << "[OK] result_type({INT32}) -> INT32" << std::endl; // Two types if (result_type({DType::INT32, DType::FLOAT64}) != DType::FLOAT64) { std::cerr << "[FAIL] result_type({INT32, FLOAT64}) should be FLOAT64"; throw std::runtime_error("result_type test failed"); } .. _example-top_level-digamma-962: .. dropdown:: digamma (np_test_1_all.cpp:10372) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10362 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Log gamma function for known values\n"; // Test digamma function - should throw exception as MKL doesn't support it try { NDArray digamma_test({ 2 }); digamma_test.setElementAt({ 0 }, 1.0); digamma_test.setElementAt({ 1 }, 2.0); auto digamma_result = special::digamma(digamma_test, MathBackend::MKL); if (!(false && "digamma should throw exception since MKL doesn't support it")) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(false && \"digamma should throw exception since MKL doesn't support it\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } catch (const std::exception& e) { // std::cout << "[OK] Digamma correctly throws exception (MKL doesn't support digamma): " << e.what() << ""; } .. _example-top_level-ellipe-963: .. dropdown:: ellipe (np_test_1_all.cpp:11100) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11090 :emphasize-lines: 11 std::cout << "========= testEllipticFunctions ===="; // Test complete elliptic integrals // K(0) = π/2 if (!(isApproxEqual(ellipk(0.0), M_PI / 2.0, 1e-6))) { std::string description = std::string("testEllipticFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ellipk(0.0), M_PI / 2.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // E(0) = π/2 if (!(isApproxEqual(ellipe(0.0), M_PI / 2.0, 1e-6))) { std::string description = std::string("testEllipticFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ellipe(0.0), M_PI / 2.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // E(1) = 1 if (!(isApproxEqual(ellipe(1.0), 1.0, 1e-6))) { std::string description = std::string("testEllipticFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ellipe(1.0), 1.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-ellipeinc-964: .. dropdown:: ellipeinc (np_test_1_all.cpp:11122) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11112 :emphasize-lines: 11 // std::cout << "[OK] Complete elliptic integrals basic values\n"; // Test incomplete elliptic integrals // F(0, m) = 0 if (!(isApproxEqual(ellipkinc(0.0, 0.5), 0.0, 1e-10))) { std::string description = std::string("testEllipticFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ellipkinc(0.0, 0.5), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // E(0, m) = 0 if (!(isApproxEqual(ellipeinc(0.0, 0.5), 0.0, 1e-10))) { std::string description = std::string("testEllipticFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ellipeinc(0.0, 0.5), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } double F_result = ellipkinc(M_PI / 4.0, 0.5); double E_result = ellipeinc(M_PI / 4.0, 0.5); if (!(!std::isnan(F_result) && std::isfinite(F_result))) { std::string description = std::string("testEllipticFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(F_result) && std::isfinite(F_result))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-ellipk-965: .. dropdown:: ellipk (np_test_1_all.cpp:11094) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11084 :emphasize-lines: 11 // std::cout << "[OK] Hypergeometric 2F1 function basic functionality\n"; std::cout << " -> tests passed\n"; } void testEllipticFunctions() { std::cout << "========= testEllipticFunctions ===="; // Test complete elliptic integrals // K(0) = π/2 if (!(isApproxEqual(ellipk(0.0), M_PI / 2.0, 1e-6))) { std::string description = std::string("testEllipticFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ellipk(0.0), M_PI / 2.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // E(0) = π/2 if (!(isApproxEqual(ellipe(0.0), M_PI / 2.0, 1e-6))) { std::string description = std::string("testEllipticFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ellipe(0.0), M_PI / 2.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-ellipkinc-966: .. dropdown:: ellipkinc (np_test_1_all.cpp:11116) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11106 :emphasize-lines: 11 if (!(isApproxEqual(ellipe(1.0), 1.0, 1e-6))) { std::string description = std::string("testEllipticFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ellipe(1.0), 1.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Complete elliptic integrals basic values\n"; // Test incomplete elliptic integrals // F(0, m) = 0 if (!(isApproxEqual(ellipkinc(0.0, 0.5), 0.0, 1e-10))) { std::string description = std::string("testEllipticFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ellipkinc(0.0, 0.5), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // E(0, m) = 0 if (!(isApproxEqual(ellipeinc(0.0, 0.5), 0.0, 1e-10))) { std::string description = std::string("testEllipticFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ellipeinc(0.0, 0.5), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-erf-967: .. dropdown:: erf (np_test_1_all.cpp:10489) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10479 :emphasize-lines: 11 } void testErrorFunctions() { std::cout << "========= testErrorFunctions ===="; // Test erf function for known values using NDArray with MKL backend NDArray erf_test({ 3 }); erf_test.setElementAt({ 0 }, 0.0); erf_test.setElementAt({ 1 }, 1.0); erf_test.setElementAt({ 2 }, -1.0); auto erf_mkl_result = special::erf(erf_test, MathBackend::MKL); if (!(isApproxEqual(erf_mkl_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testErrorFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(erf_mkl_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(erf_mkl_result.getElementAt({ 1 }), 0.8427007929497149, 1e-6))) { std::string description = std::string("testErrorFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(erf_mkl_result.getElementAt({ 1 }), 0.8427007929497149, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-erfc-968: .. dropdown:: erfc (np_test_1_all.cpp:10509) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10499 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(isApproxEqual(erf_mkl_result.getElementAt({ 2 }), -0.8427007929497149, 1e-6))) { std::string description = std::string("testErrorFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(erf_mkl_result.getElementAt({ 2 }), -0.8427007929497149, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Error function for known values\n"; // Test erfc function using NDArray with MKL backend auto erfc_mkl_result = special::erfc(erf_test, MathBackend::MKL); if (!(isApproxEqual(erfc_mkl_result.getElementAt({ 0 }), 1.0, 1e-10))) { std::string description = std::string("testErrorFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(erfc_mkl_result.getElementAt({ 0 }), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(erfc_mkl_result.getElementAt({ 1 }), 1.0 - 0.8427007929497149, 1e-6))) { std::string description = std::string("testErrorFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(erfc_mkl_result.getElementAt({ 1 }), 1.0 - 0.8427007929497149, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-erfcinv-969: .. dropdown:: erfcinv (np_test_2_all.cpp:2293) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2283 :emphasize-lines: 11 throw std::runtime_error(description); } } // Test erfcinv with MKL NDArray erfc_test({ test_size }); for (size_t i = 0; i < test_size; ++i) { erfc_test.setElementAt({ i }, 0.05 + 1.9 * static_cast(i) / test_size); // [0.05, 1.95] } auto erfcinv_result = erfcinv(erfc_test, MathBackend::MKL); auto erfc_erfcinv = erfc(erfcinv_result, MathBackend::MKL); // Test self-consistency: erfc(erfcinv(x)) = x for (size_t i = 0; i < test_size; ++i) { double original = erfc_test.getElementAt({ i }); double roundtrip = erfc_erfcinv.getElementAt({ i }); if (!(isApproxEqual(roundtrip, original, 1e-10))) { std::string description = std::string("testInverseErrorFunctionsMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(roundtrip, original, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-erfcx-970: .. dropdown:: erfcx (np_test_1_all.cpp:10550) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10540 :emphasize-lines: 11 std::string description = std::string("testErrorFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(sum, 1.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << "[OK] erf(x) + erfc(x) = 1 identity\n"; // Test erfcx function // Test with MKL if available if (MathBackendConfig::is_mkl_available()) { // erfcx(x) = exp(x²) * erfc(x) for (double x = 0.1; x <= 2.0; x += 0.3) { // Create NDArray for MKL computation auto x_array = createFloat64Array({ 1 }, x); auto erfcx_result = special::erfcx(x_array, MathBackend::MKL); double erfcx_val = erfcx_result.getElementAt({ 0 }); auto erfc_result = special::erfc(x_array, MathBackend::MKL); double expected = std::exp(x * x) * erfc_result.getElementAt({ 0 }); // std::cout << "x: " << x << ", erfcx: " << erfcx_val << ", expected: " << expected // << " : " << erfcx_val - expected << " : " << 1e-6 << ""; .. _example-top_level-erfi-971: .. dropdown:: erfi (np_test_1_all.cpp:10603) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10593 :emphasize-lines: 11 } } // std::cout << "[OK] erfcx implementation fix completed successfully!\n"; // Test erfi function using NDArray NDArray erfi_test({ 3 }); erfi_test.setElementAt({ 0 }, 0.0); erfi_test.setElementAt({ 1 }, 1.0); erfi_test.setElementAt({ 2 }, -1.0); auto erfi_result = special::erfi(erfi_test); if (!(isApproxEqual(erfi_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testErrorFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(erfi_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(erfi_result.getElementAt({ 1 }), 1.6504257587975428, 1e-6))) { std::string description = std::string("testErrorFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(erfi_result.getElementAt({ 1 }), 1.6504257587975428, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-erfinv-972: .. dropdown:: erfinv (np_test_1_all.cpp:10626) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10616 :emphasize-lines: 11 std::string description = std::string("testErrorFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(erfi_result.getElementAt({ 2 }), -1.6504257587975428, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Imaginary error function\n"; // Test erfinv function if (MathBackendConfig::is_mkl_available()) { // Test with MKL backend using NDArray auto zero_array = createFloat64Array({ 1 }, 0.0); auto erfinv_zero = special::erfinv(zero_array, MathBackend::MKL); if (!(isApproxEqual(erfinv_zero.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testErrorFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(erfinv_zero.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test erfinv(erf(x)) = x auto x_array = createFloat64Array({ 1 }, 1.0); auto erf_result = special::erf(x_array, MathBackend::MKL); auto erfinv_result = special::erfinv(erf_result, MathBackend::MKL); .. _example-top_level-factorial-973: .. dropdown:: factorial (np_test_1_all.cpp:10425) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10415 :emphasize-lines: 11 } // std::cout << "[OK] Beta function for known values\n"; // Test factorial function using NDArray with MKL backend NDArray factorial_test({ 5 }); factorial_test.setElementAt({ 0 }, 0.0); factorial_test.setElementAt({ 1 }, 1.0); factorial_test.setElementAt({ 2 }, 2.0); factorial_test.setElementAt({ 3 }, 3.0); factorial_test.setElementAt({ 4 }, 4.0); auto factorial_result = special::factorial(factorial_test, MathBackend::MKL); if (!(isApproxEqual(factorial_result.getElementAt({ 0 }), 1.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(factorial_result.getElementAt({ 0 }), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(factorial_result.getElementAt({ 1 }), 1.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(factorial_result.getElementAt({ 1 }), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-factorial2-974: .. dropdown:: factorial2 (np_test_5_all.cpp:2126) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2116 :emphasize-lines: 11 fact_input.setElementAt({ 3 }, 10.0); auto fact_result = numpy::special::factorial(fact_input, numpy::MathBackend::MKL); double fact_5 = fact_result.getElementAt({ 2 }); if (!close_enough(fact_5, 120.0, 1e-6)) { std::cout << " [FAIL] : in np_test_gamma_beta_functions() : factorial(5) = " << fact_5 << ", expected 120.0"; throw std::runtime_error("factorial(5) test failed"); } // Test factorial2 (double factorial) - scalar version works double fact2_5 = numpy::special::factorial2(5.0); // 5!! = 5*3*1 = 15 if (!close_enough(fact2_5, 15.0, 1e-10)) { std::cout << " [FAIL] : in np_test_gamma_beta_functions() : factorial2(5) = " << fact2_5 << ", expected 15.0"; throw std::runtime_error("factorial2(5) test failed"); } // std::cout << " beta(2,3) = " << beta_2_3 << " (MKL)" << std::endl; // std::cout << " beta(1,1) = " << beta_1_1 << " (MKL)" << std::endl; // std::cout << " lbeta(2,3) = " << lbeta_2_3 << " (MKL)" << std::endl; .. _example-top_level-i0-975: .. dropdown:: i0 (np_test_1_all.cpp:10756) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10746 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] y0 Bessel function with MKL backend\n"; // Test modified Bessel functions using NDArray with MKL backend NDArray i_test({ 2 }); i_test.setElementAt({ 0 }, 0.0); i_test.setElementAt({ 1 }, 1.0); auto i0_result = special::i0(i_test, MathBackend::MKL); if (!(isApproxEqual(i0_result.getElementAt({ 0 }), 1.0, 1e-6))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(i0_result.getElementAt({ 0 }), 1.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } auto i1_result = special::i1(i_test, MathBackend::MKL); if (!(isApproxEqual(i1_result.getElementAt({ 0 }), 0.0, 1e-6))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(i1_result.getElementAt({ 0 }), 0.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-i0-976: .. dropdown:: i0 (np_test_1_all.cpp:10756) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10746 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] y0 Bessel function with MKL backend\n"; // Test modified Bessel functions using NDArray with MKL backend NDArray i_test({ 2 }); i_test.setElementAt({ 0 }, 0.0); i_test.setElementAt({ 1 }, 1.0); auto i0_result = special::i0(i_test, MathBackend::MKL); if (!(isApproxEqual(i0_result.getElementAt({ 0 }), 1.0, 1e-6))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(i0_result.getElementAt({ 0 }), 1.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } auto i1_result = special::i1(i_test, MathBackend::MKL); if (!(isApproxEqual(i1_result.getElementAt({ 0 }), 0.0, 1e-6))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(i1_result.getElementAt({ 0 }), 0.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-i1-977: .. dropdown:: i1 (np_test_1_all.cpp:10763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10753 :emphasize-lines: 11 i_test.setElementAt({ 0 }, 0.0); i_test.setElementAt({ 1 }, 1.0); auto i0_result = special::i0(i_test, MathBackend::MKL); if (!(isApproxEqual(i0_result.getElementAt({ 0 }), 1.0, 1e-6))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(i0_result.getElementAt({ 0 }), 1.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } auto i1_result = special::i1(i_test, MathBackend::MKL); if (!(isApproxEqual(i1_result.getElementAt({ 0 }), 0.0, 1e-6))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(i1_result.getElementAt({ 0 }), 0.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Modified Bessel functions with MKL backend\n"; // Test array operations with MKL backend auto x = createFloat64Array({ 3 }, 0.0); x.setElementAt({ 0 }, 0.0); .. _example-top_level-i1-978: .. dropdown:: i1 (np_test_1_all.cpp:10763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10753 :emphasize-lines: 11 i_test.setElementAt({ 0 }, 0.0); i_test.setElementAt({ 1 }, 1.0); auto i0_result = special::i0(i_test, MathBackend::MKL); if (!(isApproxEqual(i0_result.getElementAt({ 0 }), 1.0, 1e-6))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(i0_result.getElementAt({ 0 }), 1.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } auto i1_result = special::i1(i_test, MathBackend::MKL); if (!(isApproxEqual(i1_result.getElementAt({ 0 }), 0.0, 1e-6))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(i1_result.getElementAt({ 0 }), 0.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Modified Bessel functions with MKL backend\n"; // Test array operations with MKL backend auto x = createFloat64Array({ 3 }, 0.0); x.setElementAt({ 0 }, 0.0); .. _example-top_level-j0-979: .. dropdown:: j0 (np_test_1_all.cpp:10702) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10692 :emphasize-lines: 11 } void testBesselFunctions() { std::cout << "========= testBesselFunctions ===="; // Test j0 function using NDArray with MKL backend NDArray j0_test({ 2 }); j0_test.setElementAt({ 0 }, 0.0); j0_test.setElementAt({ 1 }, 1.0); auto j0_result = special::j0(j0_test, MathBackend::MKL); if (!(isApproxEqual(j0_result.getElementAt({ 0 }), 1.0, 1e-6))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(j0_result.getElementAt({ 0 }), 1.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } double j0_1 = j0_result.getElementAt({ 1 }); if (!(!std::isnan(j0_1) && std::isfinite(j0_1))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(j0_1) && std::isfinite(j0_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-j0-980: .. dropdown:: j0 (np_test_1_all.cpp:10702) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10692 :emphasize-lines: 11 } void testBesselFunctions() { std::cout << "========= testBesselFunctions ===="; // Test j0 function using NDArray with MKL backend NDArray j0_test({ 2 }); j0_test.setElementAt({ 0 }, 0.0); j0_test.setElementAt({ 1 }, 1.0); auto j0_result = special::j0(j0_test, MathBackend::MKL); if (!(isApproxEqual(j0_result.getElementAt({ 0 }), 1.0, 1e-6))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(j0_result.getElementAt({ 0 }), 1.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } double j0_1 = j0_result.getElementAt({ 1 }); if (!(!std::isnan(j0_1) && std::isfinite(j0_1))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(j0_1) && std::isfinite(j0_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-j1-981: .. dropdown:: j1 (np_test_1_all.cpp:10718) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10708 :emphasize-lines: 11 double j0_1 = j0_result.getElementAt({ 1 }); if (!(!std::isnan(j0_1) && std::isfinite(j0_1))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(j0_1) && std::isfinite(j0_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] j0 Bessel function with MKL backend\n"; // Test j1 function using NDArray with MKL backend auto j1_result = special::j1(j0_test, MathBackend::MKL); if (!(isApproxEqual(j1_result.getElementAt({ 0 }), 0.0, 1e-6))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(j1_result.getElementAt({ 0 }), 0.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } double j1_1 = j1_result.getElementAt({ 1 }); if (!(!std::isnan(j1_1) && std::isfinite(j1_1))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(j1_1) && std::isfinite(j1_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-j1-982: .. dropdown:: j1 (np_test_1_all.cpp:10718) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10708 :emphasize-lines: 11 double j0_1 = j0_result.getElementAt({ 1 }); if (!(!std::isnan(j0_1) && std::isfinite(j0_1))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(j0_1) && std::isfinite(j0_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] j0 Bessel function with MKL backend\n"; // Test j1 function using NDArray with MKL backend auto j1_result = special::j1(j0_test, MathBackend::MKL); if (!(isApproxEqual(j1_result.getElementAt({ 0 }), 0.0, 1e-6))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(j1_result.getElementAt({ 0 }), 0.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } double j1_1 = j1_result.getElementAt({ 1 }); if (!(!std::isnan(j1_1) && std::isfinite(j1_1))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(j1_1) && std::isfinite(j1_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-lgamma-983: .. dropdown:: lgamma (np_test_1_all.cpp:10338) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10328 :emphasize-lines: 11 } // std::cout << "[OK] Gamma function for integer and half-integer values\n"; // Test lgamma function using NDArray with MKL backend NDArray lgamma_test({ 5 }); lgamma_test.setElementAt({ 0 }, 1.0); lgamma_test.setElementAt({ 1 }, 2.0); lgamma_test.setElementAt({ 2 }, 3.0); lgamma_test.setElementAt({ 3 }, 4.0); lgamma_test.setElementAt({ 4 }, 0.5); auto lgamma_result = special::lgamma(lgamma_test, MathBackend::MKL); if (!(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 0 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testGammaFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lgamma_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-y0-984: .. dropdown:: y0 (np_test_1_all.cpp:10738) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10728 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] j1 Bessel function with MKL backend\n"; // Test y0 function using NDArray with MKL backend NDArray y0_test({ 2 }); y0_test.setElementAt({ 0 }, 0.001); // Small positive value (Y0(0) diverges) y0_test.setElementAt({ 1 }, 1.0); auto y0_result = special::y0(y0_test, MathBackend::MKL); if (!(std::isfinite(y0_result.getElementAt({ 0 })))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isfinite(y0_result.getElementAt({ 0 })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isfinite(y0_result.getElementAt({ 1 })))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isfinite(y0_result.getElementAt({ 1 })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-y0-985: .. dropdown:: y0 (np_test_1_all.cpp:10738) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10728 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] j1 Bessel function with MKL backend\n"; // Test y0 function using NDArray with MKL backend NDArray y0_test({ 2 }); y0_test.setElementAt({ 0 }, 0.001); // Small positive value (Y0(0) diverges) y0_test.setElementAt({ 1 }, 1.0); auto y0_result = special::y0(y0_test, MathBackend::MKL); if (!(std::isfinite(y0_result.getElementAt({ 0 })))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isfinite(y0_result.getElementAt({ 0 })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isfinite(y0_result.getElementAt({ 1 })))) { std::string description = std::string("testBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isfinite(y0_result.getElementAt({ 1 })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-y1-986: .. dropdown:: y1 (np_test_2_all.cpp:1826) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1816 :emphasize-lines: 11 size_t test_size = 300; NDArray test_data({ test_size }); // Test range [0.1, 20] (Y functions diverge at x=0) for (size_t i = 0; i < test_size; ++i) { test_data.setElementAt({ i }, 0.1 + 19.9 * static_cast(i) / test_size); } // Test MKL implementation only (fallback now throws exception) auto mkl_y0 = y0(test_data, MathBackend::MKL); auto mkl_y1 = y1(test_data, MathBackend::MKL); // Basic sanity check - Y functions should not be NaN for positive arguments for (size_t i = 0; i < test_size; ++i) { if (!(!std::isnan(mkl_y0.getElementAt({ i })))) { std::string description = std::string("testBesselY0Y1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(mkl_y0.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(mkl_y1.getElementAt({ i })))) { std::string description = std::string("testBesselY0Y1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(mkl_y1.getElementAt({ i })))"; .. _example-top_level-y1-987: .. dropdown:: y1 (np_test_2_all.cpp:1826) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1816 :emphasize-lines: 11 size_t test_size = 300; NDArray test_data({ test_size }); // Test range [0.1, 20] (Y functions diverge at x=0) for (size_t i = 0; i < test_size; ++i) { test_data.setElementAt({ i }, 0.1 + 19.9 * static_cast(i) / test_size); } // Test MKL implementation only (fallback now throws exception) auto mkl_y0 = y0(test_data, MathBackend::MKL); auto mkl_y1 = y1(test_data, MathBackend::MKL); // Basic sanity check - Y functions should not be NaN for positive arguments for (size_t i = 0; i < test_size; ++i) { if (!(!std::isnan(mkl_y0.getElementAt({ i })))) { std::string description = std::string("testBesselY0Y1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(mkl_y0.getElementAt({ i })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(mkl_y1.getElementAt({ i })))) { std::string description = std::string("testBesselY0Y1MKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(mkl_y1.getElementAt({ i })))"; .. _example-top_level-zeta-988: .. dropdown:: zeta (np_test_1_all.cpp:10987) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10977 :emphasize-lines: 11 } // std::cout << "[OK] Fresnel integrals basic functionality\n"; std::cout << " -> tests passed\n"; } void testMiscellaneousFunctions() { std::cout << "========= testMiscellaneousFunctions ===="; // Test zeta function if (!(std::isinf(zeta(1.0)))) { std::string description = std::string("testMiscellaneousFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(zeta(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(zeta(0.0), -0.5, 1e-10))) { std::string description = std::string("testMiscellaneousFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(zeta(0.0), -0.5, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-zetac-989: .. dropdown:: zetac (np_test_1_all.cpp:11007) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10997 :emphasize-lines: 11 // ζ(2) = π²/6 if (!(isApproxEqual(zeta(2.0), M_PI * M_PI / 6.0, 1e-6))) { std::string description = std::string("testMiscellaneousFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(zeta(2.0), M_PI * M_PI / 6.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Riemann zeta function basic values\n"; // Test zetac function (zeta - 1) if (!(isApproxEqual(zetac(2.0), M_PI * M_PI / 6.0 - 1.0, 1e-6))) { std::string description = std::string("testMiscellaneousFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(zetac(2.0), M_PI * M_PI / 6.0 - 1.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(zetac(3.0), 1.202056903159 - 1, 1e-6))) { std::string description = std::string("testMiscellaneousFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(zetac(3.0), 1.202056903159 - 1, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Riemann zeta function minus 1\n"; .. _example-top_level-fromfile-990: .. dropdown:: fromfile (np_test_1_all.cpp:26167) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26157 :emphasize-lines: 11 outfile.close(); // Define dtype std::vector> fields = { {"id", numpy::DType::INT32}, {"value", numpy::DType::FLOAT64} }; auto dtype = std::make_shared(fields); // Load from file auto result = numpy::fromfile(filename, dtype, ","); // Verify loaded correctly bool passed = (result.getSize() == 3); if (passed) { passed = (result.getFieldValue({ 0 }, "id") == 1); passed = passed && (std::abs(result.getFieldValue({ 1 }, "value") - 20.5) < 0.001); } // Clean up temp file std::remove(filename.c_str()); .. _example-top_level-fromstring-991: .. dropdown:: fromstring (np_test_1_all.cpp:21885) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21875 :emphasize-lines: 11 std::cout << "========= testStringParsing ======================="; auto dtype = std::make_shared(std::vector>{ {"name", DType::UNICODE32}, { "age", DType::INT32 }, { "score", DType::FLOAT64 } }); std::string data = "Alice,25,85.5\nBob,30,92.3\nCharlie,35,78.9"; auto arr = fromstring(data, dtype, ",", 3); // std::cout << "Array created from string data:" << std::endl; //arr.printArray(); auto name_1 = arr.getFieldValue({ 1 }, "name"); auto age_1 = arr.getFieldValue({ 1 }, "age"); auto score_1 = arr.getFieldValue({ 1 }, "score"); // std::cout << "Verification of record 1:" << std::endl; // std::cout << "Name: " << (name_1.size() > 0 ? "Bob" : "empty") << std::endl; .. _example-top_level-load_library-992: .. dropdown:: load_library (np_test_1_all.cpp:26684) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26674 :emphasize-lines: 11 { std::string type_name = numpy::ctypeslib::as_ctypes_type(); if (!(type_name == "c_double")) { std::string description = std::string("test_ctypes_interop():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(type_name == \"c_double\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ as_ctypes_type() = " << type_name << std::endl; } // Test load_library (stub - returns nullptr) { void* lib = numpy::ctypeslib::load_library("test.dll"); if (!(lib == nullptr)) { std::string description = std::string("test_ctypes_interop():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(lib == nullptr)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ load_library() (stub)" << std::endl; } .. _example-top_level-load_memmap-993: .. dropdown:: load_memmap (np_test_2_all.cpp:10677) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10667 :emphasize-lines: 11 // Test memory mapping with existing NPY file auto regular_array = createFloat32Array({ 3, 4 }, 0.0f); for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 4; ++j) { regular_array.setElementAt({ i, j }, static_cast((i + 1) * (j + 1) * 2.5f)); } } save(regular_array, TEMP_DIR + "test_memmap_existing.npy"); auto mmap_from_npy = numpy::memmap::load_memmap(TEMP_DIR + "test_memmap_existing.npy", "r"); if (!(mmap_from_npy.getShape() == regular_array.getShape())) { std::string description = std::string("testMemoryMapping():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(mmap_from_npy.getShape() == regular_array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 4; ++j) { if (!(approx_equal(mmap_from_npy.getElementAt({ i, j }), regular_array.getElementAt({ i, j }), 1e-6f))) { std::string description = std::string("testMemoryMappedIO():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mmap_from_npy.getElementAt({ i, j }), regular_array.getElementAt({ i, j }), 1e-6f))"; .. _example-top_level-load_npz-994: .. dropdown:: load_npz (np_test_2_all.cpp:10512) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10502 :emphasize-lines: 11 array3.setElementAt({ 0, 1 }, complex128(3.0, 4.0)); array3.setElementAt({ 1, 0 }, complex128(5.0, 6.0)); array3.setElementAt({ 1, 1 }, complex128(7.0, 8.0)); // Test uncompressed NPZ savez(TEMP_DIR + "test_multiple.npz", "integers", array1, "floats", array2, "complex_nums", array3); auto npz_file = load_npz(TEMP_DIR + "test_multiple.npz"); // Verify keys auto keys = npz_file.keys(); if (!(keys.size() == 3)) { std::string description = std::string("testNPZOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(keys.size() == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(npz_file.contains("integers"))) { std::string description = std::string("testNPZOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(npz_file.contains(\"integers\"))"; .. _example-top_level-save-995: .. dropdown:: save (np_test_2_all.cpp:9818) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9808 :emphasize-lines: 11 void testBinaryIOBasic() { std::cout << "========= testBasicBinaryIO ======================="; // Test 1D integer array auto array_1d = createInt32Array({ 5 }, 0); for (size_t i = 0; i < 5; ++i) { array_1d.setElementAt({ i }, static_cast(i + 1)); } save(array_1d, TEMP_DIR + "test_1d.npy"); auto loaded_1d = load(TEMP_DIR + "test_1d.npy"); if (!(loaded_1d.getShape() == array_1d.getShape())) { std::string description = std::string("testBinaryIOBasic():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(loaded_1d.getShape() == array_1d.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < 5; ++i) { if (!(loaded_1d.getElementAt({ i }) == array_1d.getElementAt({ i }))) { std::string description = std::string("testBinaryIOBasic():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(loaded_1d.getElementAt({ i }) == array_1d.getElementAt({ i }))"; .. _example-top_level-save_auto-996: .. dropdown:: save_auto (np_test_2_all.cpp:10080) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10070 :emphasize-lines: 11 std::cout << "========= testAutomaticIO ======================="; auto test_array = createFloat64Array({ 2, 3 }, 0); for (size_t i = 0; i < 2; ++i) { for (size_t j = 0; j < 3; ++j) { test_array.setElementAt({ i, j }, static_cast(i + j + 1) * 1.5); } } // Test auto save/load with .npy extension save_auto(test_array, TEMP_DIR + "test_auto.npy"); auto loaded_npy = load_auto(TEMP_DIR + "test_auto.npy"); if (!(loaded_npy.getShape() == test_array.getShape())) { std::string description = std::string("testAutoIO():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(loaded_npy.getShape() == test_array.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < 2; ++i) { for (size_t j = 0; j < 3; ++j) { if (!(approx_equal(loaded_npy.getElementAt({ i, j }), test_array.getElementAt({ i, j })))) { .. _example-top_level-savetxt-997: .. dropdown:: savetxt (np_test_2_all.cpp:9996) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9986 :emphasize-lines: 11 void testTextIO() { std::cout << "========= testTextIO ======================="; // Test 1D array to text auto array_1d = createFloat64Array({ 5 }, 0); for (size_t i = 0; i < 5; ++i) { array_1d.setElementAt({ i }, static_cast(i) * 0.5 + 1.0); } savetxt(array_1d, TEMP_DIR + "test_1d.txt", " "); auto loaded_1d = loadtxt(TEMP_DIR + "test_1d.txt", " "); if (!(loaded_1d.getShape() == array_1d.getShape())) { std::string description = std::string("testTextIO():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(loaded_1d.getShape() == array_1d.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } for (size_t i = 0; i < 5; ++i) { if (!(approx_equal(loaded_1d.getElementAt({ i }), array_1d.getElementAt({ i })))) { std::string description = std::string("testTextIO():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(loaded_1d.getElementAt({ i }), array_1d.getElementAt({ i })))"; .. _example-top_level-savez-998: .. dropdown:: savez (np_test_2_all.cpp:10507) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10497 :emphasize-lines: 11 array2.setElementAt({ static_cast(i) }, (i + 1) * 1.5); } auto array3 = createComplex128Array({ 2, 2 }, complex128(0, 0)); array3.setElementAt({ 0, 0 }, complex128(1.0, 2.0)); array3.setElementAt({ 0, 1 }, complex128(3.0, 4.0)); array3.setElementAt({ 1, 0 }, complex128(5.0, 6.0)); array3.setElementAt({ 1, 1 }, complex128(7.0, 8.0)); // Test uncompressed NPZ savez(TEMP_DIR + "test_multiple.npz", "integers", array1, "floats", array2, "complex_nums", array3); auto npz_file = load_npz(TEMP_DIR + "test_multiple.npz"); // Verify keys auto keys = npz_file.keys(); if (!(keys.size() == 3)) { std::string description = std::string("testNPZOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(keys.size() == 3)"; .. _example-top_level-savez_compressed-999: .. dropdown:: savez_compressed (np_test_2_all.cpp:10601) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10591 :emphasize-lines: 11 throw std::runtime_error(description); } } } // std::cout << "[OK] Complex array loaded correctly from NPZ\n"; npz_file.close(); // Test compressed NPZ #ifdef HAVE_ZLIB savez_compressed(TEMP_DIR + "test_compressed.npz", "data1", array1, "data2", array2); auto compressed_npz = load_npz(TEMP_DIR + "test_compressed.npz"); auto comp_int = compressed_npz.get("data1"); if (!(comp_int.getShape() == array1.getShape())) { std::string description = std::string("testNPZOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(comp_int.getShape() == array1.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-to_1d_index-1000: .. dropdown:: to_1d_index (np_test_2_all.cpp:7363) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7353 :emphasize-lines: 11 // std::cout << "Hypot(3,4): " << hypot_result << std::endl; // std::cout << "Basic utilities test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_matrix_operations() { std::cout << "========= test_matrix_operations ======================="; // Test matrix indexing size_t idx = to_1d_index(2, 3, 5); // row 2, col 3, 5 columns per row if (!(idx == 13)) { std::string description = std::string("test_matrix_operations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(idx == 13)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } auto [row, col] = to_2d_indices(13, 5); if (!(row == 2 && col == 3)) { std::string description = std::string("test_matrix_operations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(row == 2 && col == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-to_csr-1001: .. dropdown:: to_csr (np_test_3_all.cpp:20025) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20015 :emphasize-lines: 11 void np_test_sparse_conversion() { std::cout << "========= format conversion - COO to CSR ======================="; numpy::sparse::COOMatrix coo(5, 5); coo.add_entry(0, 0, 1.0); coo.add_entry(1, 1, 2.0); coo.add_entry(2, 2, 3.0); coo.add_entry(3, 3, 4.0); coo.add_entry(4, 4, 5.0); auto csr = coo.to_csr(); if (csr.rows() != 5 || csr.cols() != 5 || csr.nnz() != 5) { std::cout << " [FAIL] : in np_test_sparse_conversion() : Conversion produced wrong dimensions"; throw std::runtime_error("np_test_sparse_conversion failed"); } if (!csr.check_format()) { std::cout << " [FAIL] : in np_test_sparse_conversion() : Converted CSR format invalid"; throw std::runtime_error("np_test_sparse_conversion failed"); } .. _example-top_level-to_lower-1002: .. dropdown:: to_lower (np_test_1_all.cpp:7382) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7372 :emphasize-lines: 11 str32 full("Programming"); str32 sub = full.substr(0, 7); // std::cout << "Substring of '" << full << "' (0,7): '" << sub << "'" << std::endl; // Test find str32 search("Hello World Programming"); size_t pos = search.find(str32("World")); // std::cout << "Position of 'World' in '" << search << "': " << pos << std::endl; // Test utility functions str32 lower = to_lower(str32("UPPERCASE")); str32 upper = to_upper(str32("lowercase")); // std::cout << "to_lower('UPPERCASE'): '" << lower << "'" << std::endl; // std::cout << "to_upper('lowercase'): '" << upper << "'" << std::endl; std::cout << " -> tests passed" << std::endl; } void testStringArraysStringTypes() { std::cout << "========= testStringArraysStringTypes ======================="; .. _example-top_level-to_lower-1003: .. dropdown:: to_lower (np_test_1_all.cpp:7382) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7372 :emphasize-lines: 11 str32 full("Programming"); str32 sub = full.substr(0, 7); // std::cout << "Substring of '" << full << "' (0,7): '" << sub << "'" << std::endl; // Test find str32 search("Hello World Programming"); size_t pos = search.find(str32("World")); // std::cout << "Position of 'World' in '" << search << "': " << pos << std::endl; // Test utility functions str32 lower = to_lower(str32("UPPERCASE")); str32 upper = to_upper(str32("lowercase")); // std::cout << "to_lower('UPPERCASE'): '" << lower << "'" << std::endl; // std::cout << "to_upper('lowercase'): '" << upper << "'" << std::endl; std::cout << " -> tests passed" << std::endl; } void testStringArraysStringTypes() { std::cout << "========= testStringArraysStringTypes ======================="; .. _example-top_level-to_numeric-1004: .. dropdown:: to_numeric (np_test_1_all.cpp:7515) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7505 :emphasize-lines: 11 std::cout << "========= testNumericStringOperationsStringTypes ======================="; str32 num_str1("123.45"); str32 num_str2("67.89"); str32 not_num("hello"); // std::cout << "String '" << num_str1 << "' is numeric: " << is_numeric(num_str1) << std::endl; // std::cout << "String '" << not_num << "' is numeric: " << is_numeric(not_num) << std::endl; if (is_numeric(num_str1)) { double val1 = to_numeric(num_str1); // std::cout << "Numeric value of '" << num_str1 << "': " << val1 << std::endl; } if (is_numeric(num_str2)) { double val2 = to_numeric(num_str2); // std::cout << "Numeric value of '" << num_str2 << "': " << val2 << std::endl; } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-to_upper-1005: .. dropdown:: to_upper (np_test_1_all.cpp:7383) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7373 :emphasize-lines: 11 str32 sub = full.substr(0, 7); // std::cout << "Substring of '" << full << "' (0,7): '" << sub << "'" << std::endl; // Test find str32 search("Hello World Programming"); size_t pos = search.find(str32("World")); // std::cout << "Position of 'World' in '" << search << "': " << pos << std::endl; // Test utility functions str32 lower = to_lower(str32("UPPERCASE")); str32 upper = to_upper(str32("lowercase")); // std::cout << "to_lower('UPPERCASE'): '" << lower << "'" << std::endl; // std::cout << "to_upper('lowercase'): '" << upper << "'" << std::endl; std::cout << " -> tests passed" << std::endl; } void testStringArraysStringTypes() { std::cout << "========= testStringArraysStringTypes ======================="; // Test array creation with fill value .. _example-top_level-tofile-1006: .. dropdown:: tofile (np_test_2_all.cpp:10882) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10872 :emphasize-lines: 11 ensure_temp_directory(); // Test tofile and fromfile with binary data auto original_array = createFloat64Array({ 6 }, 0.0); for (size_t i = 0; i < 6; ++i) { original_array.setElementAt({ i }, (i + 1) * 3.14159); } // Write to binary file tofile(original_array, TEMP_DIR + "test_fromfile.bin"); // Read back from binary file auto loaded_array = fromfile(TEMP_DIR + "test_fromfile.bin"); if (!(loaded_array.getShape().size() == 1)) { std::string description = std::string("testBinaryIOExtended():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(loaded_array.getShape().size() == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(loaded_array.getShape()[0] == 6)) { std::string description = std::string("testBinaryIOExtended():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(loaded_array.getShape()[0] == 6)"; .. _example-top_level-tolist-1007: .. dropdown:: tolist (np_test_4_all.cpp:20046) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20036 :emphasize-lines: 11 } // namespace numpy_tests /** * @file np_test_phase6.cpp * @brief Test suite for Phase 6A - HIGH PRIORITY NDArray methods and masked array utilities * * Tests: * - ndarray.nonzero() - Return indices of non-zero elements * - ndarray.tobytes() - Convert to bytes representation * - ndarray.tolist() - Convert to nested list string * - ndarray.fill() - Fill with scalar value (in-place) * - ndarray.item() - Get single element as scalar * - ndarray.itemset() - Set single element value * - ma.masked_all_like() - Create masked array with all elements masked * * Created: 2025-10-28 * Status: Phase 6A Implementation - HIGH PRIORITY functions */ #include "../numpy/np_ndarray.h" .. _example-top_level-tostring-1008: .. dropdown:: tostring (np_test_2_all.cpp:11023) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11013 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(byte_vector[3] == 0x44)) { std::string description = std::string("testBinaryIOExtended():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(byte_vector[3] == 0x44)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] tobytes works correctly\n"; // Test tostring auto string_result = tostring(bytes_array); if (!(string_result == "ABCD")) { std::string description = std::string("testBinaryIOExtended():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(string_result == \"ABCD\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] tostring works correctly\n"; std::cout << " -> tests passed\n"; } .. _example-top_level-ndarray-1009: .. dropdown:: NDArray (np_test_1_all.cpp:890) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 880 :emphasize-lines: 11 } // std::cout << "[OK] array == scalar"; std::cout << " -> tests passed" << std::endl; } void testLogicalOperations() { std::cout << "========= testLogicalOperations ======================="; // Create boolean arrays auto a = NDArray({3}); a.setElementAt({0}, true); a.setElementAt({1}, false); a.setElementAt({2}, true); auto b = NDArray({3}); b.setElementAt({0}, false); b.setElementAt({1}, false); b.setElementAt({2}, true); // Test logical_and .. _example-top_level-ndarray-1010: .. dropdown:: NDArray (np_test_1_all.cpp:890) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 880 :emphasize-lines: 11 } // std::cout << "[OK] array == scalar"; std::cout << " -> tests passed" << std::endl; } void testLogicalOperations() { std::cout << "========= testLogicalOperations ======================="; // Create boolean arrays auto a = NDArray({3}); a.setElementAt({0}, true); a.setElementAt({1}, false); a.setElementAt({2}, true); auto b = NDArray({3}); b.setElementAt({0}, false); b.setElementAt({1}, false); b.setElementAt({2}, true); // Test logical_and .. _example-top_level-nat-1011: .. dropdown:: NaT (np_test_1_all.cpp:7020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7010 :emphasize-lines: 11 // std::cout << april_2024.getElementAt({i}).toString() << " "; } // std::cout << std::endl; std::cout << " -> tests passed" << std::endl; } void testNaTHandlingDateTime() { std::cout << "========= testNaTHandlingDateTime ======================="; datetime64 nat_dt = datetime64::NaT(); timedelta64 nat_td = timedelta64::NaT(); // std::cout << "NaT datetime: " << nat_dt.toString() << std::endl; // std::cout << "NaT timedelta: " << nat_td.toString() << std::endl; datetime64 valid_date("2024-01-01"); // NaT arithmetic datetime64 result1 = valid_date + nat_td; datetime64 result2 = nat_dt + timedelta64(1, DateTimeUnit::Day); .. _example-top_level-nat-1012: .. dropdown:: NaT (np_test_1_all.cpp:7020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7010 :emphasize-lines: 11 // std::cout << april_2024.getElementAt({i}).toString() << " "; } // std::cout << std::endl; std::cout << " -> tests passed" << std::endl; } void testNaTHandlingDateTime() { std::cout << "========= testNaTHandlingDateTime ======================="; datetime64 nat_dt = datetime64::NaT(); timedelta64 nat_td = timedelta64::NaT(); // std::cout << "NaT datetime: " << nat_dt.toString() << std::endl; // std::cout << "NaT timedelta: " << nat_td.toString() << std::endl; datetime64 valid_date("2024-01-01"); // NaT arithmetic datetime64 result1 = valid_date + nat_td; datetime64 result2 = nat_dt + timedelta64(1, DateTimeUnit::Day); .. _example-top_level-adaptive_cache_sort-1013: .. dropdown:: adaptive_cache_sort (np_test_3_all.cpp:6315) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6305 :emphasize-lines: 11 } void test_prefetch_sort() { std::cout << "========= test_prefetch_sort ======================="; // Test adaptive cache sort std::vector data = { 15, 7, 23, 4, 18, 9, 31, 2, 26, 13, 8, 19, 6, 22, 11 }; std::vector expected = data; std::sort(expected.begin(), expected.end()); adaptive_cache_sort(data.begin(), data.end(), std::less()); if (!(data == expected)) { std::string description = std::string("test_prefetch_sort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_prefetch_sort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-adaptive_cache_sort-1014: .. dropdown:: adaptive_cache_sort (np_test_3_all.cpp:6315) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6305 :emphasize-lines: 11 } void test_prefetch_sort() { std::cout << "========= test_prefetch_sort ======================="; // Test adaptive cache sort std::vector data = { 15, 7, 23, 4, 18, 9, 31, 2, 26, 13, 8, 19, 6, 22, 11 }; std::vector expected = data; std::sort(expected.begin(), expected.end()); adaptive_cache_sort(data.begin(), data.end(), std::less()); if (!(data == expected)) { std::string description = std::string("test_prefetch_sort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_prefetch_sort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-adaptive_cache_sort-1015: .. dropdown:: adaptive_cache_sort (np_test_3_all.cpp:6315) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6305 :emphasize-lines: 11 } void test_prefetch_sort() { std::cout << "========= test_prefetch_sort ======================="; // Test adaptive cache sort std::vector data = { 15, 7, 23, 4, 18, 9, 31, 2, 26, 13, 8, 19, 6, 22, 11 }; std::vector expected = data; std::sort(expected.begin(), expected.end()); adaptive_cache_sort(data.begin(), data.end(), std::less()); if (!(data == expected)) { std::string description = std::string("test_prefetch_sort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_prefetch_sort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-adaptive_cache_sort-1016: .. dropdown:: adaptive_cache_sort (np_test_3_all.cpp:6315) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6305 :emphasize-lines: 11 } void test_prefetch_sort() { std::cout << "========= test_prefetch_sort ======================="; // Test adaptive cache sort std::vector data = { 15, 7, 23, 4, 18, 9, 31, 2, 26, 13, 8, 19, 6, 22, 11 }; std::vector expected = data; std::sort(expected.begin(), expected.end()); adaptive_cache_sort(data.begin(), data.end(), std::less()); if (!(data == expected)) { std::string description = std::string("test_prefetch_sort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_prefetch_sort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-adaptive_sort-1017: .. dropdown:: adaptive_sort (np_test_2_all.cpp:8164) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8154 :emphasize-lines: 11 // Test adaptive sorting algorithm selection void test_adaptive_sort() { std::cout << "========= Adaptive Sort Test ============================"; // Test different data types and sizes { std::vector data = { 9, 3, 7, 1, 5, 2, 8, 4, 6 }; std::vector expected = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; numpy::adaptive_sort(data.begin(), data.end()); if (data != expected) { std::cout << " Adaptive sort (small int array): -> [FAIL]"; throw std::runtime_error("Adaptive sort (small int array): FAILED - array not properly sorted"); } // std::cout << "[OK] Adaptive sort (small int array): PASSED" << std::endl; } { std::vector data(1000); .. _example-top_level-advanced_sort-1018: .. dropdown:: advanced_sort (np_test_1_all.cpp:16524) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16514 :emphasize-lines: 11 void test_introsort() { std::cout << "========= test_introsort ======================="; // Test with random data std::vector data = { 64, 34, 25, 12, 22, 11, 90, 5, 77, 30 }; std::vector expected = data; std::sort(expected.begin(), expected.end()); advanced_sort(data, SortKind::QUICKSORT); if (!(data == expected)) { std::string description = std::string("test_introsort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test with already sorted data std::vector sorted_data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::vector sorted_expected = sorted_data; .. _example-top_level-advanced_sort-1019: .. dropdown:: advanced_sort (np_test_1_all.cpp:16524) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16514 :emphasize-lines: 11 void test_introsort() { std::cout << "========= test_introsort ======================="; // Test with random data std::vector data = { 64, 34, 25, 12, 22, 11, 90, 5, 77, 30 }; std::vector expected = data; std::sort(expected.begin(), expected.end()); advanced_sort(data, SortKind::QUICKSORT); if (!(data == expected)) { std::string description = std::string("test_introsort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test with already sorted data std::vector sorted_data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::vector sorted_expected = sorted_data; .. _example-top_level-advanced_sort-1020: .. dropdown:: advanced_sort (np_test_1_all.cpp:16524) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16514 :emphasize-lines: 11 void test_introsort() { std::cout << "========= test_introsort ======================="; // Test with random data std::vector data = { 64, 34, 25, 12, 22, 11, 90, 5, 77, 30 }; std::vector expected = data; std::sort(expected.begin(), expected.end()); advanced_sort(data, SortKind::QUICKSORT); if (!(data == expected)) { std::string description = std::string("test_introsort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test with already sorted data std::vector sorted_data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::vector sorted_expected = sorted_data; .. _example-top_level-airy-1021: .. dropdown:: airy (np_test_1_all.cpp:15721) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15711 :emphasize-lines: 11 using namespace numpy::special; namespace { } void testAiryFunctions() { std::cout << "========= testAiryFunctions ===="; // Test Airy functions at x = 0 auto [ai_0, bi_0] = airy(0.0); if (!(isApproxEqual(ai_0, 0.35502805388781724, 1e-6))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ai_0, 0.35502805388781724, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(bi_0, 0.61492662744600074, 1e-6))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(bi_0, 0.61492662744600074, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-airy_ai-1022: .. dropdown:: airy_ai (np_test_1_all.cpp:15758) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15748 :emphasize-lines: 11 // Test Airy functions for negative values auto [ai_neg1, bi_neg1] = airy(-1.0); if (!(!std::isnan(ai_neg1) && !std::isnan(bi_neg1))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(ai_neg1) && !std::isnan(bi_neg1))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Airy functions for negative arguments\n"; // Test individual Airy functions if (!(isApproxEqual(airy_ai(0.0), ai_0, 1e-6))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(airy_ai(0.0), ai_0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(airy_bi(0.0), bi_0, 1e-6))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(airy_bi(0.0), bi_0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Individual Airy functions\n"; .. _example-top_level-airy_ai-1023: .. dropdown:: airy_ai (np_test_1_all.cpp:15758) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15748 :emphasize-lines: 11 // Test Airy functions for negative values auto [ai_neg1, bi_neg1] = airy(-1.0); if (!(!std::isnan(ai_neg1) && !std::isnan(bi_neg1))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(ai_neg1) && !std::isnan(bi_neg1))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Airy functions for negative arguments\n"; // Test individual Airy functions if (!(isApproxEqual(airy_ai(0.0), ai_0, 1e-6))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(airy_ai(0.0), ai_0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(airy_bi(0.0), bi_0, 1e-6))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(airy_bi(0.0), bi_0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Individual Airy functions\n"; .. _example-top_level-airy_bi-1024: .. dropdown:: airy_bi (np_test_1_all.cpp:15763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15753 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "[OK] Airy functions for negative arguments\n"; // Test individual Airy functions if (!(isApproxEqual(airy_ai(0.0), ai_0, 1e-6))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(airy_ai(0.0), ai_0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(airy_bi(0.0), bi_0, 1e-6))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(airy_bi(0.0), bi_0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Individual Airy functions\n"; // Test exponentially scaled Airy functions auto [aie_0, bie_0] = airye(0.0); if (!(isApproxEqual(aie_0, ai_0, 1e-6))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(aie_0, ai_0, 1e-6))"; .. _example-top_level-airy_bi-1025: .. dropdown:: airy_bi (np_test_1_all.cpp:15763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15753 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "[OK] Airy functions for negative arguments\n"; // Test individual Airy functions if (!(isApproxEqual(airy_ai(0.0), ai_0, 1e-6))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(airy_ai(0.0), ai_0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(airy_bi(0.0), bi_0, 1e-6))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(airy_bi(0.0), bi_0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Individual Airy functions\n"; // Test exponentially scaled Airy functions auto [aie_0, bie_0] = airye(0.0); if (!(isApproxEqual(aie_0, ai_0, 1e-6))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(aie_0, ai_0, 1e-6))"; .. _example-top_level-airye-1026: .. dropdown:: airye (np_test_1_all.cpp:15771) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15761 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(isApproxEqual(airy_bi(0.0), bi_0, 1e-6))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(airy_bi(0.0), bi_0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Individual Airy functions\n"; // Test exponentially scaled Airy functions auto [aie_0, bie_0] = airye(0.0); if (!(isApproxEqual(aie_0, ai_0, 1e-6))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(aie_0, ai_0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(bie_0, bi_0, 1e-6))) { std::string description = std::string("testAiryFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(bie_0, bi_0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-amax-1027: .. dropdown:: amax (np_test_1_all.cpp:27503) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27493 :emphasize-lines: 11 namespace numpy_tests { namespace numpy_tests_phase3 { using namespace numpy; // ============================================================================ // Phase 3A: Masked Array Core Operations (11 functions) // ============================================================================ void test_amax_amin() { std::cout << "========= ma::amax() and ma::amin(): statistical operations ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }); auto mask = numpy::array({ {false, false, true}, {false, true, false} }); auto ma = numpy::ma::masked_array(data, mask); double max_val = numpy::ma::amax(ma); double min_val = numpy::ma::amin(ma); // std::cout << " ma::amax() result: " << max_val << " (expected: 6)" << std::endl; // std::cout << " ma::amin() result: " << min_val << " (expected: 1)" << std::endl; .. _example-top_level-amax-1028: .. dropdown:: amax (np_test_1_all.cpp:27503) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27493 :emphasize-lines: 11 namespace numpy_tests { namespace numpy_tests_phase3 { using namespace numpy; // ============================================================================ // Phase 3A: Masked Array Core Operations (11 functions) // ============================================================================ void test_amax_amin() { std::cout << "========= ma::amax() and ma::amin(): statistical operations ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }); auto mask = numpy::array({ {false, false, true}, {false, true, false} }); auto ma = numpy::ma::masked_array(data, mask); double max_val = numpy::ma::amax(ma); double min_val = numpy::ma::amin(ma); // std::cout << " ma::amax() result: " << max_val << " (expected: 6)" << std::endl; // std::cout << " ma::amin() result: " << min_val << " (expected: 1)" << std::endl; .. _example-top_level-amin-1029: .. dropdown:: amin (np_test_1_all.cpp:27503) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27493 :emphasize-lines: 11 namespace numpy_tests { namespace numpy_tests_phase3 { using namespace numpy; // ============================================================================ // Phase 3A: Masked Array Core Operations (11 functions) // ============================================================================ void test_amax_amin() { std::cout << "========= ma::amax() and ma::amin(): statistical operations ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }); auto mask = numpy::array({ {false, false, true}, {false, true, false} }); auto ma = numpy::ma::masked_array(data, mask); double max_val = numpy::ma::amax(ma); double min_val = numpy::ma::amin(ma); // std::cout << " ma::amax() result: " << max_val << " (expected: 6)" << std::endl; // std::cout << " ma::amin() result: " << min_val << " (expected: 1)" << std::endl; .. _example-top_level-amin-1030: .. dropdown:: amin (np_test_1_all.cpp:27503) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27493 :emphasize-lines: 11 namespace numpy_tests { namespace numpy_tests_phase3 { using namespace numpy; // ============================================================================ // Phase 3A: Masked Array Core Operations (11 functions) // ============================================================================ void test_amax_amin() { std::cout << "========= ma::amax() and ma::amin(): statistical operations ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }); auto mask = numpy::array({ {false, false, true}, {false, true, false} }); auto ma = numpy::ma::masked_array(data, mask); double max_val = numpy::ma::amax(ma); double min_val = numpy::ma::amin(ma); // std::cout << " ma::amax() result: " << max_val << " (expected: 6)" << std::endl; // std::cout << " ma::amin() result: " << min_val << " (expected: 1)" << std::endl; .. _example-top_level-angle-1031: .. dropdown:: angle (np_test_3_all.cpp:4198) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4188 :emphasize-lines: 11 void testAngleComputation() { std::cout << "========= testAngleComputation ===="; // Test with complex numbers auto c_arr = NDArray({ 4 }); c_arr.setElementAt({ 0 }, complex128(1.0, 1.0)); // 45 degrees c_arr.setElementAt({ 1 }, complex128(-1.0, 1.0)); // 135 degrees c_arr.setElementAt({ 2 }, complex128(-1.0, -1.0)); // -135 degrees c_arr.setElementAt({ 3 }, complex128(1.0, 0.0)); // 0 degrees auto angles_rad = angle(c_arr); if (!(std::abs(angles_rad.getElementAt({ 0 }) - M_PI / 4) < 1e-10)) { std::string description = std::string("testAngleComputation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(angles_rad.getElementAt({ 0 }) - M_PI / 4) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(angles_rad.getElementAt({ 1 }) - 3 * M_PI / 4) < 1e-10)) { std::string description = std::string("testAngleComputation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(angles_rad.getElementAt({ 1 }) - 3 * M_PI / 4) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-argmax-1032: .. dropdown:: argmax (np_test_3_all.cpp:20521) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20511 :emphasize-lines: 11 auto result = numpy::argmin(arr); // Should return 1 (index of (1,5)) if (result.getElementAt({0}) != 1) { throw std::runtime_error("argmin() failed: expected index 1"); } std::cout << "PASSED\n"; } void test_argmax_complex128() { std::cout << " Testing argmax() with complex128... "; numpy::NDArray arr({3}); arr.setElementAt({0}, complex128(3.0, 1.0)); // index 0 - largest arr.setElementAt({1}, complex128(1.0, 5.0)); // index 1 arr.setElementAt({2}, complex128(2.0, 2.0)); // index 2 auto result = numpy::argmax(arr); // Should return 0 (index of (3,1)) if (result.getElementAt({0}) != 0) { throw std::runtime_error("argmax() failed: expected index 0"); } .. _example-top_level-argmax-1033: .. dropdown:: argmax (np_test_3_all.cpp:20521) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20511 :emphasize-lines: 11 auto result = numpy::argmin(arr); // Should return 1 (index of (1,5)) if (result.getElementAt({0}) != 1) { throw std::runtime_error("argmin() failed: expected index 1"); } std::cout << "PASSED\n"; } void test_argmax_complex128() { std::cout << " Testing argmax() with complex128... "; numpy::NDArray arr({3}); arr.setElementAt({0}, complex128(3.0, 1.0)); // index 0 - largest arr.setElementAt({1}, complex128(1.0, 5.0)); // index 1 arr.setElementAt({2}, complex128(2.0, 2.0)); // index 2 auto result = numpy::argmax(arr); // Should return 0 (index of (3,1)) if (result.getElementAt({0}) != 0) { throw std::runtime_error("argmax() failed: expected index 0"); } .. _example-top_level-argmin-1034: .. dropdown:: argmin (np_test_3_all.cpp:20506) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20496 :emphasize-lines: 11 if (min_result.getElementAt({0}).real() != 2.0 || min_result.getElementAt({0}).imag() != 1.0) { throw std::runtime_error("min() tie-breaking failed: expected (2,1)"); } if (max_result.getElementAt({0}).real() != 2.0 || max_result.getElementAt({0}).imag() != 5.0) { throw std::runtime_error("max() tie-breaking failed: expected (2,5)"); } std::cout << "PASSED\n"; } void test_argmin_complex128() { std::cout << " Testing argmin() with complex128... "; numpy::NDArray arr({3}); arr.setElementAt({0}, complex128(3.0, 1.0)); // index 0 arr.setElementAt({1}, complex128(1.0, 5.0)); // index 1 - smallest arr.setElementAt({2}, complex128(2.0, 2.0)); // index 2 auto result = numpy::argmin(arr); // Should return 1 (index of (1,5)) if (result.getElementAt({0}) != 1) { throw std::runtime_error("argmin() failed: expected index 1"); } .. _example-top_level-argmin-1035: .. dropdown:: argmin (np_test_3_all.cpp:20506) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20496 :emphasize-lines: 11 if (min_result.getElementAt({0}).real() != 2.0 || min_result.getElementAt({0}).imag() != 1.0) { throw std::runtime_error("min() tie-breaking failed: expected (2,1)"); } if (max_result.getElementAt({0}).real() != 2.0 || max_result.getElementAt({0}).imag() != 5.0) { throw std::runtime_error("max() tie-breaking failed: expected (2,5)"); } std::cout << "PASSED\n"; } void test_argmin_complex128() { std::cout << " Testing argmin() with complex128... "; numpy::NDArray arr({3}); arr.setElementAt({0}, complex128(3.0, 1.0)); // index 0 arr.setElementAt({1}, complex128(1.0, 5.0)); // index 1 - smallest arr.setElementAt({2}, complex128(2.0, 2.0)); // index 2 auto result = numpy::argmin(arr); // Should return 1 (index of (1,5)) if (result.getElementAt({0}) != 1) { throw std::runtime_error("argmin() failed: expected index 1"); } .. _example-top_level-around-1036: .. dropdown:: around (np_test_1_all.cpp:20863) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20853 :emphasize-lines: 11 std::cout << "========= testAroundFunction ===="; // Test around function (alias for round) auto arr = NDArray({ 5 }); arr.setElementAt({ 0 }, 1.4); arr.setElementAt({ 1 }, 1.6); arr.setElementAt({ 2 }, -1.4); arr.setElementAt({ 3 }, -1.6); arr.setElementAt({ 4 }, 2.5); auto result = around(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-around-1037: .. dropdown:: around (np_test_1_all.cpp:20863) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20853 :emphasize-lines: 11 std::cout << "========= testAroundFunction ===="; // Test around function (alias for round) auto arr = NDArray({ 5 }); arr.setElementAt({ 0 }, 1.4); arr.setElementAt({ 1 }, 1.6); arr.setElementAt({ 2 }, -1.4); arr.setElementAt({ 3 }, -1.6); arr.setElementAt({ 4 }, 2.5); auto result = around(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-around-1038: .. dropdown:: around (np_test_1_all.cpp:20863) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20853 :emphasize-lines: 11 std::cout << "========= testAroundFunction ===="; // Test around function (alias for round) auto arr = NDArray({ 5 }); arr.setElementAt({ 0 }, 1.4); arr.setElementAt({ 1 }, 1.6); arr.setElementAt({ 2 }, -1.4); arr.setElementAt({ 3 }, -1.6); arr.setElementAt({ 4 }, 2.5); auto result = around(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-around-1039: .. dropdown:: around (np_test_1_all.cpp:20863) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20853 :emphasize-lines: 11 std::cout << "========= testAroundFunction ===="; // Test around function (alias for round) auto arr = NDArray({ 5 }); arr.setElementAt({ 0 }, 1.4); arr.setElementAt({ 1 }, 1.6); arr.setElementAt({ 2 }, -1.4); arr.setElementAt({ 3 }, -1.6); arr.setElementAt({ 4 }, 2.5); auto result = around(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-around-1040: .. dropdown:: around (np_test_1_all.cpp:20863) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20853 :emphasize-lines: 11 std::cout << "========= testAroundFunction ===="; // Test around function (alias for round) auto arr = NDArray({ 5 }); arr.setElementAt({ 0 }, 1.4); arr.setElementAt({ 1 }, 1.6); arr.setElementAt({ 2 }, -1.4); arr.setElementAt({ 3 }, -1.6); arr.setElementAt({ 4 }, 2.5); auto result = around(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-around-1041: .. dropdown:: around (np_test_1_all.cpp:20863) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20853 :emphasize-lines: 11 std::cout << "========= testAroundFunction ===="; // Test around function (alias for round) auto arr = NDArray({ 5 }); arr.setElementAt({ 0 }, 1.4); arr.setElementAt({ 1 }, 1.6); arr.setElementAt({ 2 }, -1.4); arr.setElementAt({ 3 }, -1.6); arr.setElementAt({ 4 }, 2.5); auto result = around(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-around-1042: .. dropdown:: around (np_test_1_all.cpp:20863) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20853 :emphasize-lines: 11 std::cout << "========= testAroundFunction ===="; // Test around function (alias for round) auto arr = NDArray({ 5 }); arr.setElementAt({ 0 }, 1.4); arr.setElementAt({ 1 }, 1.6); arr.setElementAt({ 2 }, -1.4); arr.setElementAt({ 3 }, -1.6); arr.setElementAt({ 4 }, 2.5); auto result = around(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-around-1043: .. dropdown:: around (np_test_1_all.cpp:20863) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20853 :emphasize-lines: 11 std::cout << "========= testAroundFunction ===="; // Test around function (alias for round) auto arr = NDArray({ 5 }); arr.setElementAt({ 0 }, 1.4); arr.setElementAt({ 1 }, 1.6); arr.setElementAt({ 2 }, -1.4); arr.setElementAt({ 3 }, -1.6); arr.setElementAt({ 4 }, 2.5); auto result = around(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-around-1044: .. dropdown:: around (np_test_1_all.cpp:20863) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20853 :emphasize-lines: 11 std::cout << "========= testAroundFunction ===="; // Test around function (alias for round) auto arr = NDArray({ 5 }); arr.setElementAt({ 0 }, 1.4); arr.setElementAt({ 1 }, 1.6); arr.setElementAt({ 2 }, -1.4); arr.setElementAt({ 3 }, -1.6); arr.setElementAt({ 4 }, 2.5); auto result = around(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-around-1045: .. dropdown:: around (np_test_1_all.cpp:20863) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20853 :emphasize-lines: 11 std::cout << "========= testAroundFunction ===="; // Test around function (alias for round) auto arr = NDArray({ 5 }); arr.setElementAt({ 0 }, 1.4); arr.setElementAt({ 1 }, 1.6); arr.setElementAt({ 2 }, -1.4); arr.setElementAt({ 3 }, -1.6); arr.setElementAt({ 4 }, 2.5); auto result = around(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-around-1046: .. dropdown:: around (np_test_1_all.cpp:20863) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20853 :emphasize-lines: 11 std::cout << "========= testAroundFunction ===="; // Test around function (alias for round) auto arr = NDArray({ 5 }); arr.setElementAt({ 0 }, 1.4); arr.setElementAt({ 1 }, 1.6); arr.setElementAt({ 2 }, -1.4); arr.setElementAt({ 3 }, -1.6); arr.setElementAt({ 4 }, 2.5); auto result = around(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-around-1047: .. dropdown:: around (np_test_1_all.cpp:20863) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20853 :emphasize-lines: 11 std::cout << "========= testAroundFunction ===="; // Test around function (alias for round) auto arr = NDArray({ 5 }); arr.setElementAt({ 0 }, 1.4); arr.setElementAt({ 1 }, 1.6); arr.setElementAt({ 2 }, -1.4); arr.setElementAt({ 3 }, -1.6); arr.setElementAt({ 4 }, 2.5); auto result = around(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-around-1048: .. dropdown:: around (np_test_1_all.cpp:20863) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20853 :emphasize-lines: 11 std::cout << "========= testAroundFunction ===="; // Test around function (alias for round) auto arr = NDArray({ 5 }); arr.setElementAt({ 0 }, 1.4); arr.setElementAt({ 1 }, 1.6); arr.setElementAt({ 2 }, -1.4); arr.setElementAt({ 3 }, -1.6); arr.setElementAt({ 4 }, 2.5); auto result = around(arr); if (!(result.getElementAt({ 0 }) == 1.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 2.0)) { std::string description = std::string("testAroundFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-array-1049: .. dropdown:: array (np_test_1_all.cpp:243) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 233 :emphasize-lines: 11 // std::cout << "Min: " << array.minArray() << std::endl; // std::cout << "Max: " << array.maxArray() << std::endl; std::cout << " -> tests passed" << std::endl; } void testReshapeAndFlatten() { std::cout << "========= testReshapeAndFlatten ======================="; auto range_array = NDArray::createRange(0, 12, 1); // std::cout << "Range array (0-11):" << std::endl; //range_array.printArray(); auto reshaped = range_array.reshapeArray({3, 4}); // std::cout << "Reshaped to 3x4:"; //reshaped.printArray(); auto flattened = reshaped.flattenArray(); // std::cout << "Flattened:" << std::endl; //flattened.printArray(); .. _example-top_level-array2string-1050: .. dropdown:: array2string (np_test_3_all.cpp:10122) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10112 :emphasize-lines: 11 void np_test_io_string_array2string_1d() { std::cout << "========= np_test_io_string_array2string_1d ======================="; // Small array - all elements shown NDArray arr1({ 5 }); for (size_t i = 0; i < 5; ++i) { arr1.setElementAt({ i }, static_cast(i + 1)); } std::string result = array2string(arr1); // std::cout << "Small 1D array: " << result << std::endl; if (!(result.find('[') != std::string::npos)) { std::string description = std::string("np_test_io_string_array2string_1d():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.find('[') != std::string::npos)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.find(']') != std::string::npos)) { std::string description = std::string("np_test_io_string_array2string_1d():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.find(']') != std::string::npos)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-array_function_dispatch-1051: .. dropdown:: array_function_dispatch (np_test_1_all.cpp:26622) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26612 :emphasize-lines: 11 } // ============================================================================ // SUB-PHASE 6C: CHARACTER ARRAYS // ============================================================================ void test_char_extensions() { std::cout << "[6C] Character Array Extensions (3 functions)"; // std::cout << "===============================================" << std::endl; // Test array_function_dispatch (stub) { numpy::char_::array_function_dispatch([]() {}); // std::cout << " ✓ array_function_dispatch() (stub)"; } // Test narray { auto arr = numpy::char_::narray<32>({ "hello", "world" }); if (!(arr.size() == 2)) { std::string description = std::string("test_char_extensions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr.size() == 2)"; .. _example-top_level-array_repr-1052: .. dropdown:: array_repr (np_test_3_all.cpp:10292) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10282 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(str_result.find('[') != std::string::npos)) { std::string description = std::string("np_test_io_string_str_repr():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str_result.find('[') != std::string::npos)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test array_repr std::string repr_result = array_repr(arr); // std::cout << "array_repr result: " << repr_result << std::endl; if (!(!repr_result.empty())) { std::string description = std::string("np_test_io_string_str_repr():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!repr_result.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(repr_result.find("array(") != std::string::npos)) { std::string description = std::string("np_test_io_string_str_repr():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(repr_result.find(\"array(\") != std::string::npos)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-array_str-1053: .. dropdown:: array_str (np_test_3_all.cpp:10278) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10268 :emphasize-lines: 11 void np_test_io_string_str_repr() { std::cout << "========= np_test_io_string_str_repr ======================="; NDArray arr({ 3 }); arr.setElementAt({ 0 }, 1.1); arr.setElementAt({ 1 }, 2.2); arr.setElementAt({ 2 }, 3.3); // Test array_str std::string str_result = array_str(arr); // std::cout << "array_str result: " << str_result << std::endl; if (!(!str_result.empty())) { std::string description = std::string("np_test_io_string_str_repr():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!str_result.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(str_result.find('[') != std::string::npos)) { std::string description = std::string("np_test_io_string_str_repr():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str_result.find('[') != std::string::npos)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-as_ctypes-1054: .. dropdown:: as_ctypes (np_test_1_all.cpp:26659) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26649 :emphasize-lines: 11 // SUB-PHASE 6D: C-TYPES INTEROP // ============================================================================ void test_ctypes_interop() { std::cout << "[6D] C-Types Interoperability (4 functions)"; // std::cout << "=============================================" << std::endl; // Test as_ctypes { auto arr = NDArray({ 10 }, 1.0); const double* ptr = numpy::ctypeslib::as_ctypes(arr); if (!(ptr != nullptr)) { std::string description = std::string("test_ctypes_interop():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ptr != nullptr)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(ptr[0] == 1.0)) { std::string description = std::string("test_ctypes_interop():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ptr[0] == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-as_ctypes-1055: .. dropdown:: as_ctypes (np_test_1_all.cpp:26659) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26649 :emphasize-lines: 11 // SUB-PHASE 6D: C-TYPES INTEROP // ============================================================================ void test_ctypes_interop() { std::cout << "[6D] C-Types Interoperability (4 functions)"; // std::cout << "=============================================" << std::endl; // Test as_ctypes { auto arr = NDArray({ 10 }, 1.0); const double* ptr = numpy::ctypeslib::as_ctypes(arr); if (!(ptr != nullptr)) { std::string description = std::string("test_ctypes_interop():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ptr != nullptr)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(ptr[0] == 1.0)) { std::string description = std::string("test_ctypes_interop():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ptr[0] == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-as_ctypes_type-1056: .. dropdown:: as_ctypes_type (np_test_1_all.cpp:26675) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26665 :emphasize-lines: 11 if (!(ptr[0] == 1.0)) { std::string description = std::string("test_ctypes_interop():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ptr[0] == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ as_ctypes()" << std::endl; } // Test as_ctypes_type { std::string type_name = numpy::ctypeslib::as_ctypes_type(); if (!(type_name == "c_double")) { std::string description = std::string("test_ctypes_interop():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(type_name == \"c_double\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ as_ctypes_type() = " << type_name << std::endl; } // Test load_library (stub - returns nullptr) { .. _example-top_level-as_ctypes_type-1057: .. dropdown:: as_ctypes_type (np_test_1_all.cpp:26675) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26665 :emphasize-lines: 11 if (!(ptr[0] == 1.0)) { std::string description = std::string("test_ctypes_interop():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ptr[0] == 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ as_ctypes()" << std::endl; } // Test as_ctypes_type { std::string type_name = numpy::ctypeslib::as_ctypes_type(); if (!(type_name == "c_double")) { std::string description = std::string("test_ctypes_interop():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(type_name == \"c_double\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ as_ctypes_type() = " << type_name << std::endl; } // Test load_library (stub - returns nullptr) { .. _example-top_level-asbytes-1058: .. dropdown:: asbytes (np_test_4_all.cpp:22398) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22388 :emphasize-lines: 11 } } // namespace numpy_tests /** * @file test_phase6_final.cpp * @brief Comprehensive tests for final Phase 6 functions * * Tests the following functions: * 1. ma.compress_nd() - N-dimensional masked array compression * 2. np.char.asbytes() - String to bytes conversion * 3. assert_array_almost_equal_nulp() - ULP-based comparison * 4. assert_array_max_ulp() - Maximum ULP assertion */ #include #include #include #include #include #include .. _example-top_level-asmatrix-1059: .. dropdown:: asmatrix (np_test_2_all.cpp:5039) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5029 :emphasize-lines: 11 // Test diagonal matrix std::vector diag_vals = { 1.0, 2.0, 3.0 }; auto diag_mat = numpy::diag(diag_vals); assert_test(diag_mat.rows() == 3 && diag_mat.cols() == 3, "Diagonal matrix dimensions"); assert_test(std::abs(diag_mat(0, 0) - 1.0) < 1e-10, "Diagonal matrix element"); assert_test(std::abs(diag_mat(1, 1) - 2.0) < 1e-10, "Diagonal matrix element"); assert_test(std::abs(diag_mat(2, 2) - 3.0) < 1e-10, "Diagonal matrix element"); assert_test(std::abs(diag_mat(0, 1)) < 1e-10, "Diagonal matrix off-diagonal"); // Test arange (using asmatrix() to convert 1D array to row vector) auto arange_mat = numpy::asmatrix(numpy::arange(0.0, 5.0, 1.0)); assert_test(arange_mat.rows() == 1 && arange_mat.cols() == 5, "Arange matrix dimensions"); assert_test(std::abs(arange_mat(0, 0) - 0.0) < 1e-10, "Arange matrix element"); assert_test(std::abs(arange_mat(0, 4) - 4.0) < 1e-10, "Arange matrix element"); // Test linspace (using asmatrix() to convert 1D array to row vector) auto linspace_mat = numpy::asmatrix(numpy::linspace(0.0, 1.0, 5)); assert_test(linspace_mat.rows() == 1 && linspace_mat.cols() == 5, "Linspace matrix dimensions"); assert_test(std::abs(linspace_mat(0, 0) - 0.0) < 1e-10, "Linspace matrix start"); assert_test(std::abs(linspace_mat(0, 4) - 1.0) < 1e-10, "Linspace matrix end"); .. _example-top_level-balance_matrix-1060: .. dropdown:: balance_matrix (np_test_3_all.cpp:5432) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5422 :emphasize-lines: 11 matrix.setElementAt({ 1, 1 }, complex128(2, 0)); matrix.setElementAt({ 1, 2 }, complex128(1000, 0)); matrix.setElementAt({ 2, 0 }, complex128(1000, 0)); matrix.setElementAt({ 2, 1 }, complex128(0.001, 0)); matrix.setElementAt({ 2, 2 }, complex128(3, 0)); // std::cout << "Original ill-conditioned matrix:" << std::endl; //matrix.printArray(); // Apply balancing auto balance_result = utils::balance_matrix(matrix); // std::cout << "Balanced matrix:" << std::endl; //balance_result.balanced_matrix.printArray(); // std::cout << "Balancing scales:" << std::endl; //balance_result.scale.printArray(); // Compute eigenvalues with and without balancing // std::cout << "--- Without balancing ---" << std::endl; auto eig_unbalanced = eig(matrix, 1e-12, false); // No balancing .. _example-top_level-base-1061: .. dropdown:: base (np_test_1_all.cpp:21719) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21709 :emphasize-lines: 11 } void testRecFunctionsBasic() { std::cout << "========= testRecFunctionsBasic ======================="; auto dtype = std::make_shared(std::vector>{ {"name", DType::UNICODE32}, { "score", DType::INT32 } }); RecordArray base(dtype, { 2 }); base.setFieldValue({ 0 }, "name", std::string("Alice")); base.setFieldValue({ 0 }, "score", static_cast(85)); base.setFieldValue({ 1 }, "name", std::string("Bob")); base.setFieldValue({ 1 }, "score", static_cast(92)); // std::cout << "Base array:" << std::endl; //base.printArray(); std::vector names = get_names(base); // std::cout << "Field names: "; .. _example-top_level-base_repr-1062: .. dropdown:: base_repr (np_test_2_all.cpp:13643) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13633 :emphasize-lines: 11 std::cout << "[FAIL] <---------- np_test_sorting_searching test suite failed with exception: " << e.what() << " ================================================== "; return 1; } return 0; } } // namespace numpy_tests // Comprehensive test suite for NumPy Bitwise String Representation Functions // Tests: base_repr() and binary_repr() #include #include #include "../numpy/np_bitwise_ops.h" // no using namespace in tests - to avoid name clashes namespace numpy_tests { // no using namespace in tests - to avoid name clashes .. _example-top_level-bei-1063: .. dropdown:: bei (np_test_1_all.cpp:16163) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16153 :emphasize-lines: 11 void testKelvinFunctions() { std::cout << "========= testKelvinFunctions ===="; // Test Kelvin functions at x = 0 if (!(isApproxEqual(ber(0.0), 1.0, 1e-10))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ber(0.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(bei(0.0), 0.0, 1e-10))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(bei(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isinf(ker(0.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(ker(0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isinf(kei(0.0)))) { .. _example-top_level-bei-1064: .. dropdown:: bei (np_test_1_all.cpp:16163) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16153 :emphasize-lines: 11 void testKelvinFunctions() { std::cout << "========= testKelvinFunctions ===="; // Test Kelvin functions at x = 0 if (!(isApproxEqual(ber(0.0), 1.0, 1e-10))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ber(0.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(bei(0.0), 0.0, 1e-10))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(bei(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isinf(ker(0.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(ker(0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isinf(kei(0.0)))) { .. _example-top_level-beip-1065: .. dropdown:: beip (np_test_1_all.cpp:16258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16248 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "[OK] Kelvin function symmetries\n"; // Test derivatives (basic sanity check) if (!(!std::isnan(berp(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(berp(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(beip(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(beip(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(kerp(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(kerp(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(keip(1.0)))) { .. _example-top_level-beip-1066: .. dropdown:: beip (np_test_1_all.cpp:16258) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16248 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "[OK] Kelvin function symmetries\n"; // Test derivatives (basic sanity check) if (!(!std::isnan(berp(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(berp(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(beip(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(beip(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(kerp(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(kerp(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(keip(1.0)))) { .. _example-top_level-benchmark_cosine-1067: .. dropdown:: benchmark_cosine (np_test_2_all.cpp:800) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 790 :emphasize-lines: 11 if (!MathBackendConfig::is_mkl_available()) { // std::cout << "[INFO] MKL not available, skipping benchmark reporting test\n"; std::cout << " -> tests passed\n"; return; } // Test benchmark reporting functionality // std::cout << "Testing benchmark report generation...\n"; SpecialFunctionsBenchmark benchmark; benchmark.benchmark_cosine(10000); auto report = benchmark.generate_report(); if (!(!report.empty())) { std::string description = std::string("testBenchmarkReporting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!report.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(report.find("Special Functions Benchmark Report") != std::string::npos)) { std::string description = std::string("testBenchmarkReporting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(report.find(\"Special Functions Benchmark Report\") != std::string::npos)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-ber-1068: .. dropdown:: ber (np_test_1_all.cpp:16158) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16148 :emphasize-lines: 11 } // std::cout << "[OK] Spherical Bessel array operations\n"; std::cout << " -> tests passed\n"; } void testKelvinFunctions() { std::cout << "========= testKelvinFunctions ===="; // Test Kelvin functions at x = 0 if (!(isApproxEqual(ber(0.0), 1.0, 1e-10))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ber(0.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(bei(0.0), 0.0, 1e-10))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(bei(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isinf(ker(0.0)))) { .. _example-top_level-ber-1069: .. dropdown:: ber (np_test_1_all.cpp:16158) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16148 :emphasize-lines: 11 } // std::cout << "[OK] Spherical Bessel array operations\n"; std::cout << " -> tests passed\n"; } void testKelvinFunctions() { std::cout << "========= testKelvinFunctions ===="; // Test Kelvin functions at x = 0 if (!(isApproxEqual(ber(0.0), 1.0, 1e-10))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ber(0.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(bei(0.0), 0.0, 1e-10))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(bei(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isinf(ker(0.0)))) { .. _example-top_level-berp-1070: .. dropdown:: berp (np_test_1_all.cpp:16253) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16243 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(isApproxEqual(bei(-x_test), -bei(x_test), 1e-6))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(bei(-x_test), -bei(x_test), 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Kelvin function symmetries\n"; // Test derivatives (basic sanity check) if (!(!std::isnan(berp(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(berp(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(beip(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(beip(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(kerp(1.0)))) { .. _example-top_level-berp-1071: .. dropdown:: berp (np_test_1_all.cpp:16253) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16243 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(isApproxEqual(bei(-x_test), -bei(x_test), 1e-6))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(bei(-x_test), -bei(x_test), 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Kelvin function symmetries\n"; // Test derivatives (basic sanity check) if (!(!std::isnan(berp(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(berp(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(beip(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(beip(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(kerp(1.0)))) { .. _example-top_level-bicgstab-1072: .. dropdown:: bicgstab (np_test_3_all.cpp:20268) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20258 :emphasize-lines: 11 if (i < n - 1) coo.add_entry(i, i + 1, -1.0); } auto A = coo.to_csr(); numpy::NDArray b({ n }); for (size_t i = 0; i < n; ++i) { b.setElementAt({ i }, 1.0); } auto [x, info] = numpy::sparse::bicgstab(A, b, static_cast*>(nullptr), 1e-6, 200); if (!info.converged) { std::cout << " [FAIL] : in np_test_sparse_bicgstab() : BiCGSTAB did not converge"; throw std::runtime_error("np_test_sparse_bicgstab failed"); } std::cout << " -> tests passed" << std::endl; } // ============================================================================ .. _example-top_level-binary_repr-1073: .. dropdown:: binary_repr (np_test_2_all.cpp:13643) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13633 :emphasize-lines: 11 std::cout << "[FAIL] <---------- np_test_sorting_searching test suite failed with exception: " << e.what() << " ================================================== "; return 1; } return 0; } } // namespace numpy_tests // Comprehensive test suite for NumPy Bitwise String Representation Functions // Tests: base_repr() and binary_repr() #include #include #include "../numpy/np_bitwise_ops.h" // no using namespace in tests - to avoid name clashes namespace numpy_tests { // no using namespace in tests - to avoid name clashes .. _example-top_level-blocked_hessenberg_reduction-1074: .. dropdown:: blocked_hessenberg_reduction (np_test_3_all.cpp:5611) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5601 :emphasize-lines: 11 } catch (const std::exception& e) { std::cout << " [FAIL] : in test_blocked_algorithms(): Blocked QR failed: " << e.what(); throw std::runtime_error("test_blocked_algorithms(): Blocked QR failed: " + std::string(e.what())); } try { // Test blocked Hessenberg reduction // std::cout << "Testing blocked Hessenberg reduction..." << std::endl; auto hess_blocked = numpy::linalg::utils::blocked_hessenberg_reduction(A, 2); // std::cout << "Blocked Hessenberg: SUCCESS" << std::endl; // std::cout << "Is upper Hessenberg: " << (hess_blocked.is_upper_hessenberg ? "Yes" : "No") << std::endl; } catch (const std::exception& e) { std::cout << " [FAIL] : in test_blocked_algorithms(): Blocked Hessenberg failed: " << e.what(); throw std::runtime_error("test_blocked_algorithms(): Blocked Hessenberg failed: " + std::string(e.what())); } // std::cout << "Blocked algorithms implementation completed successfully!" << std::endl; .. _example-top_level-blocked_qr_decomposition-1075: .. dropdown:: blocked_qr_decomposition (np_test_3_all.cpp:5598) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5588 :emphasize-lines: 11 A.setElementAt({ 2, 0 }, std::complex(0.1, 0.1)); A.setElementAt({ 2, 1 }, std::complex(0.2, 0.1)); A.setElementAt({ 2, 2 }, std::complex(3.0, 0.2)); // std::cout << "Test matrix (3x3):" << std::endl; // std::cout << "A[0,0] = " << A.getElementAt({ 0, 0 }).real() << " + " << A.getElementAt({ 0, 0 }).imag() << "i" << std::endl; try { // Test blocked QR decomposition with small block size // std::cout << "Testing blocked QR decomposition..." << std::endl; auto qr_blocked = numpy::linalg::utils::blocked_qr_decomposition(A, 2); // std::cout << "Blocked QR: SUCCESS" << std::endl; // std::cout << "Full rank: " << (qr_blocked.is_full_rank ? "Yes" : "No") << std::endl; } catch (const std::exception& e) { std::cout << " [FAIL] : in test_blocked_algorithms(): Blocked QR failed: " << e.what(); throw std::runtime_error("test_blocked_algorithms(): Blocked QR failed: " + std::string(e.what())); } try { .. _example-top_level-blocked_quicksort-1076: .. dropdown:: blocked_quicksort (np_test_3_all.cpp:6289) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6279 :emphasize-lines: 11 // Generate random data std::mt19937 gen(42); std::uniform_int_distribution dist(1, 10000); for (size_t i = 0; i < size; ++i) { data[i] = dist(gen); } std::vector expected = data; std::sort(expected.begin(), expected.end()); blocked_quicksort(data.begin(), data.end(), std::less()); if (!(data == expected)) { std::string description = std::string("test_cache_blocking_sort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_cache_blocking_sort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-bucket_sort-1077: .. dropdown:: bucket_sort (np_test_2_all.cpp:9147) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9137 :emphasize-lines: 11 } void test_ipp_bucket_sort() { std::cout << "========= test_ipp_bucket_sort ========================="; // Test 1: Basic floating-point bucket sorting (float) { std::vector data = { 3.5f, 1.2f, 4.8f, 2.1f, 0.9f, 2.7f, 3.1f }; std::vector expected = { 0.9f, 1.2f, 2.1f, 2.7f, 3.1f, 3.5f, 4.8f }; numpy::bucket_sort(data); if (data != expected) { std::cout << " Basic float bucket sort: -> [FAIL]"; throw std::runtime_error("IPP bucket_sort: FAILED - basic float sorting incorrect"); } // std::cout << " Basic float bucket sort: -> [OK]" << std::endl; } // Test 2: Double precision bucket sorting { .. _example-top_level-businessdaycount-1078: .. dropdown:: businessDayCount (np_test_1_all.cpp:6966) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6956 :emphasize-lines: 11 // Test start/end of periods // std::cout << "Start of week: " << datetime_utils::startOfWeek(test_date).toString() << std::endl; // std::cout << "End of week: " << datetime_utils::endOfWeek(test_date).toString() << std::endl; // std::cout << "Start of month: " << datetime_utils::startOfMonth(test_date).toString() << std::endl; // std::cout << "End of month: " << datetime_utils::endOfMonth(test_date).toString() << std::endl; // Test business day calculations datetime64 start_bday("2024-03-11"); // Monday datetime64 end_bday("2024-03-15"); // Friday int64_t business_days = datetime_utils::businessDayCount(start_bday, end_bday); // std::cout << "Business days from " << start_bday.toString() // << " to " << end_bday.toString() << ": " << business_days << std::endl; datetime64 offset_date = datetime_utils::businessDayOffset(start_bday, 3); // std::cout << "3 business days after " << start_bday.toString() // << ": " << offset_date.toString() << std::endl; // Test leap year // std::cout << "2024 is leap year: " << datetime_utils::isLeapYear(2024) << std::endl; // std::cout << "2023 is leap year: " << datetime_utils::isLeapYear(2023) << std::endl; .. _example-top_level-businessdaycount-1079: .. dropdown:: businessDayCount (np_test_1_all.cpp:6966) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6956 :emphasize-lines: 11 // Test start/end of periods // std::cout << "Start of week: " << datetime_utils::startOfWeek(test_date).toString() << std::endl; // std::cout << "End of week: " << datetime_utils::endOfWeek(test_date).toString() << std::endl; // std::cout << "Start of month: " << datetime_utils::startOfMonth(test_date).toString() << std::endl; // std::cout << "End of month: " << datetime_utils::endOfMonth(test_date).toString() << std::endl; // Test business day calculations datetime64 start_bday("2024-03-11"); // Monday datetime64 end_bday("2024-03-15"); // Friday int64_t business_days = datetime_utils::businessDayCount(start_bday, end_bday); // std::cout << "Business days from " << start_bday.toString() // << " to " << end_bday.toString() << ": " << business_days << std::endl; datetime64 offset_date = datetime_utils::businessDayOffset(start_bday, 3); // std::cout << "3 business days after " << start_bday.toString() // << ": " << offset_date.toString() << std::endl; // Test leap year // std::cout << "2024 is leap year: " << datetime_utils::isLeapYear(2024) << std::endl; // std::cout << "2023 is leap year: " << datetime_utils::isLeapYear(2023) << std::endl; .. _example-top_level-businessdayoffset-1080: .. dropdown:: businessDayOffset (np_test_1_all.cpp:6970) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6960 :emphasize-lines: 11 // std::cout << "End of month: " << datetime_utils::endOfMonth(test_date).toString() << std::endl; // Test business day calculations datetime64 start_bday("2024-03-11"); // Monday datetime64 end_bday("2024-03-15"); // Friday int64_t business_days = datetime_utils::businessDayCount(start_bday, end_bday); // std::cout << "Business days from " << start_bday.toString() // << " to " << end_bday.toString() << ": " << business_days << std::endl; datetime64 offset_date = datetime_utils::businessDayOffset(start_bday, 3); // std::cout << "3 business days after " << start_bday.toString() // << ": " << offset_date.toString() << std::endl; // Test leap year // std::cout << "2024 is leap year: " << datetime_utils::isLeapYear(2024) << std::endl; // std::cout << "2023 is leap year: " << datetime_utils::isLeapYear(2023) << std::endl; // std::cout << "Days in February 2024: " << datetime_utils::daysInMonth(2024, 2) << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-businessdayoffset-1081: .. dropdown:: businessDayOffset (np_test_1_all.cpp:6970) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6960 :emphasize-lines: 11 // std::cout << "End of month: " << datetime_utils::endOfMonth(test_date).toString() << std::endl; // Test business day calculations datetime64 start_bday("2024-03-11"); // Monday datetime64 end_bday("2024-03-15"); // Friday int64_t business_days = datetime_utils::businessDayCount(start_bday, end_bday); // std::cout << "Business days from " << start_bday.toString() // << " to " << end_bday.toString() << ": " << business_days << std::endl; datetime64 offset_date = datetime_utils::businessDayOffset(start_bday, 3); // std::cout << "3 business days after " << start_bday.toString() // << ": " << offset_date.toString() << std::endl; // Test leap year // std::cout << "2024 is leap year: " << datetime_utils::isLeapYear(2024) << std::endl; // std::cout << "2023 is leap year: " << datetime_utils::isLeapYear(2023) << std::endl; // std::cout << "Days in February 2024: " << datetime_utils::daysInMonth(2024, 2) << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-byte_span-1082: .. dropdown:: byte_span (np_test_2_all.cpp:20797) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20787 :emphasize-lines: 11 // std::cout << " PASS" << std::endl; } // Test 6: byte_span convenience function void np_test_byte_span() { std::cout << "Running np_test_byte_span..."; // Test with normal array numpy::NDArray arr = numpy::NDArray::createRange(0, 100, 1); auto bounds = numpy::byte_bounds(arr); size_t span = numpy::byte_span(bounds); size_t expected_span = 100 * sizeof(int); if (!(span == expected_span && "byte_span returned wrong size")) { std::string description = std::string("np_test_byte_span():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(span == expected_span && \"byte_span returned wrong size\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " Array of 100 ints: " << span << " bytes" << std::endl; // Test with empty array .. _example-top_level-cache_oblivious_merge-1083: .. dropdown:: cache_oblivious_merge (np_test_3_all.cpp:6138) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6128 :emphasize-lines: 11 } void test_cache_oblivious_merge_small() { std::cout << "========= test_cache_oblivious_merge_small ======================="; // Test with small arrays that fit in L1 cache std::vector data = { 1, 3, 5, 7, 2, 4, 6, 8 }; auto mid = data.begin() + 4; // Merge two sorted halves cache_oblivious_merge(data.begin(), mid, data.end(), std::less()); // Verify result is sorted std::vector expected = { 1, 2, 3, 4, 5, 6, 7, 8 }; if (!(data == expected)) { std::string description = std::string("test_cache_oblivious_merge_small():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Small cache-oblivious merge test passed" << std::endl; .. _example-top_level-cache_oblivious_mergesort-1084: .. dropdown:: cache_oblivious_mergesort (np_test_3_all.cpp:6200) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6190 :emphasize-lines: 11 } void test_cache_oblivious_sort_basic() { std::cout << "========= test_cache_oblivious_sort_basic ======================="; // Test basic cache-oblivious mergesort functionality std::vector data = { 64, 34, 25, 12, 22, 11, 90, 5, 77, 30, 85, 42, 8, 95, 15 }; std::vector expected = data; std::sort(expected.begin(), expected.end()); cache_oblivious_mergesort(data.begin(), data.end(), std::less()); if (!(data == expected)) { std::string description = std::string("test_cache_oblivious_sort_basic():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_cache_oblivious_sort_basic():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-can_broadcast-1085: .. dropdown:: can_broadcast (np_test_1_all.cpp:3797) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3787 :emphasize-lines: 11 } if (!(broadcasted[2].getElementAt({1, 2}) == 300.0)) { std::string description = std::string("test_broadcast_arrays():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(broadcasted[2].getElementAt({1, 2}) == 300.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "✓ Multiple array broadcasting works" << std::endl; // Test can_broadcast function if (!(can_broadcast(arrays) == true)) { std::string description = std::string("test_broadcast_arrays():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(can_broadcast(arrays) == true)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "✓ can_broadcast function works" << std::endl; // Test broadcast_shape function auto result_shape = broadcast_shape(arrays); if (!((result_shape == std::vector{2, 3}))) { std::string description = std::string("test_broadcast_arrays():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((result_shape == std::vector{2, 3}))"; .. _example-top_level-capitalize-1086: .. dropdown:: capitalize (np_test_1_all.cpp:6461) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6451 :emphasize-lines: 11 } // Test lower case auto lower_result = lower(arr); // std::cout << "Lower case:" << std::endl; for (size_t i = 0; i < lower_result.size(); ++i) { // std::cout << " '" << lower_result[i] << "'"; } // Test capitalize auto cap_result = capitalize(arr); // std::cout << "Capitalize:" << std::endl; for (size_t i = 0; i < cap_result.size(); ++i) { // std::cout << " '" << cap_result[i] << "'"; } // Test title auto title_result = title(arr); // std::cout << "Title case:" << std::endl; for (size_t i = 0; i < title_result.size(); ++i) { // std::cout << " '" << title_result[i] << "'"; .. _example-top_level-capitalize-1087: .. dropdown:: capitalize (np_test_1_all.cpp:6461) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6451 :emphasize-lines: 11 } // Test lower case auto lower_result = lower(arr); // std::cout << "Lower case:" << std::endl; for (size_t i = 0; i < lower_result.size(); ++i) { // std::cout << " '" << lower_result[i] << "'"; } // Test capitalize auto cap_result = capitalize(arr); // std::cout << "Capitalize:" << std::endl; for (size_t i = 0; i < cap_result.size(); ++i) { // std::cout << " '" << cap_result[i] << "'"; } // Test title auto title_result = title(arr); // std::cout << "Title case:" << std::endl; for (size_t i = 0; i < title_result.size(); ++i) { // std::cout << " '" << title_result[i] << "'"; .. _example-top_level-center-1088: .. dropdown:: center (np_test_1_all.cpp:6590) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6580 :emphasize-lines: 11 std::vector words = {"Hi", "Hello", "Test"}; auto arr = array<32>(words); // std::cout << "Original words:" << std::endl; for (size_t i = 0; i < arr.size(); ++i) { // std::cout << "'" << arr[i] << "'"; } // Test center auto centered = center(arr, 10, '*'); // std::cout << "Centered (width=10, fill='*'):" << std::endl; for (size_t i = 0; i < centered.size(); ++i) { // std::cout << "'" << centered[i] << "'"; } // Test ljust auto left_just = ljust(arr, 8, '-'); // std::cout << "Left justified (width=8, fill='-'):" << std::endl; for (size_t i = 0; i < left_just.size(); ++i) { // std::cout << "'" << left_just[i] << "'"; .. _example-top_level-center-1089: .. dropdown:: center (np_test_1_all.cpp:6590) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6580 :emphasize-lines: 11 std::vector words = {"Hi", "Hello", "Test"}; auto arr = array<32>(words); // std::cout << "Original words:" << std::endl; for (size_t i = 0; i < arr.size(); ++i) { // std::cout << "'" << arr[i] << "'"; } // Test center auto centered = center(arr, 10, '*'); // std::cout << "Centered (width=10, fill='*'):" << std::endl; for (size_t i = 0; i < centered.size(); ++i) { // std::cout << "'" << centered[i] << "'"; } // Test ljust auto left_just = ljust(arr, 8, '-'); // std::cout << "Left justified (width=8, fill='-'):" << std::endl; for (size_t i = 0; i < left_just.size(); ++i) { // std::cout << "'" << left_just[i] << "'"; .. _example-top_level-center-1090: .. dropdown:: center (np_test_1_all.cpp:6590) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6580 :emphasize-lines: 11 std::vector words = {"Hi", "Hello", "Test"}; auto arr = array<32>(words); // std::cout << "Original words:" << std::endl; for (size_t i = 0; i < arr.size(); ++i) { // std::cout << "'" << arr[i] << "'"; } // Test center auto centered = center(arr, 10, '*'); // std::cout << "Centered (width=10, fill='*'):" << std::endl; for (size_t i = 0; i < centered.size(); ++i) { // std::cout << "'" << centered[i] << "'"; } // Test ljust auto left_just = ljust(arr, 8, '-'); // std::cout << "Left justified (width=8, fill='-'):" << std::endl; for (size_t i = 0; i < left_just.size(); ++i) { // std::cout << "'" << left_just[i] << "'"; .. _example-top_level-chebval-1091: .. dropdown:: chebval (np_test_5_all.cpp:20729) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20719 :emphasize-lines: 11 std::cout << "========= chebfit: Chebyshev polynomial fitting ======================="; std::vector x = {-1.0, -0.5, 0.0, 0.5, 1.0}; std::vector y = {1.0, 0.25, 0.0, 0.25, 1.0}; // y = x^2 auto coeffs = numpy::polynomial::chebyshev::chebfit(x, y, 2); // Verify fit quality double max_err = 0.0; for (size_t i = 0; i < x.size(); ++i) { double val = numpy::polynomial::chebyshev::chebval(x[i], coeffs); max_err = std::max(max_err, std::abs(val - y[i])); } if (max_err > 1e-10) { std::cout << " [FAIL] : in np_test_chebfit(): max error " << max_err << " exceeds tolerance" << std::endl; throw std::runtime_error("np_test_chebfit failed: fit error too large"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-chebyt-1092: .. dropdown:: chebyt (np_test_1_all.cpp:15872) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15862 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(!std::isnan(lpmv(1, 1, 0.5)))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(lpmv(1, 1, 0.5)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Associated Legendre polynomials\n"; // Test Chebyshev polynomials of the first kind if (!(isApproxEqual(chebyt(0, 0.5), 1.0, 1e-10))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(chebyt(0, 0.5), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(chebyt(1, 0.5), 0.5, 1e-10))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(chebyt(1, 0.5), 0.5, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(chebyt(2, 0.5), -0.5, 1e-6))) { .. _example-top_level-chebyu-1093: .. dropdown:: chebyu (np_test_1_all.cpp:15890) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15880 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(isApproxEqual(chebyt(2, 0.5), -0.5, 1e-6))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(chebyt(2, 0.5), -0.5, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Chebyshev polynomials (first kind)\n"; // Test Chebyshev polynomials of the second kind if (!(isApproxEqual(chebyu(0, 0.5), 1.0, 1e-10))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(chebyu(0, 0.5), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(chebyu(1, 0.5), 1.0, 1e-10))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(chebyu(1, 0.5), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(chebyu(2, 0.5), 0.0, 1e-6))) { .. _example-top_level-chi-1094: .. dropdown:: chi (np_test_1_all.cpp:10934) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10924 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "[OK] Cosine integral basic functionality\n"; // Test hyperbolic integrals if (!(isApproxEqual(shi(0.0), 0.0, 1e-10))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(shi(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isnan(chi(0.0)))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isnan(chi(0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } double shi_1 = shi(1.0); double chi_1 = chi(1.0); if (!(!std::isnan(shi_1) && std::isfinite(shi_1))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(shi_1) && std::isfinite(shi_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-ci-1095: .. dropdown:: ci (np_test_1_all.cpp:10914) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10904 :emphasize-lines: 11 // Si(π/2) ≈ 1.851937 (approximately) double si_pi2 = si(M_PI / 2.0); if (!(!std::isnan(si_pi2) && std::isfinite(si_pi2))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(si_pi2) && std::isfinite(si_pi2))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Sine integral basic functionality\n"; // Test cosine integral (undefined at x = 0) if (!(std::isnan(ci(0.0)))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isnan(ci(0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } double ci_1 = ci(1.0); if (!(!std::isnan(ci_1) && std::isfinite(ci_1))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(ci_1) && std::isfinite(ci_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-circulant-1096: .. dropdown:: circulant (np_test_2_all.cpp:5288) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5278 :emphasize-lines: 11 assert_test(std::abs(hankel_mat(0, 1) - 2.0) < 1e-10, "Hankel matrix element"); assert_test(std::abs(hankel_mat(1, 1) - 3.0) < 1e-10, "Hankel matrix element"); } catch (...) { // std::cout << "Hankel matrix test failed"; } // Test circulant matrix std::vector c_circ = { 1.0, 2.0, 3.0 }; try { auto circ = numpy::circulant(c_circ); assert_test(circ.rows() == 3 && circ.cols() == 3, "Circulant matrix dimensions"); assert_test(std::abs(circ(0, 0) - 1.0) < 1e-10, "Circulant matrix element"); assert_test(std::abs(circ(0, 1) - 2.0) < 1e-10, "Circulant matrix element"); assert_test(std::abs(circ(1, 0) - 3.0) < 1e-10, "Circulant matrix element"); assert_test(std::abs(circ(1, 1) - 1.0) < 1e-10, "Circulant matrix element"); } catch (...) { // std::cout << "Circulant matrix test failed"; } .. _example-top_level-clip-1097: .. dropdown:: clip (np_test_1_all.cpp:15142) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15132 :emphasize-lines: 11 numpy::NDArray values({ 5 }); values.setElementAt({ 0 }, -2.0); values.setElementAt({ 1 }, -1.0); values.setElementAt({ 2 }, 0.5); values.setElementAt({ 3 }, 2.0); values.setElementAt({ 4 }, 5.0); double min_val = -1.0; double max_val = 3.0; auto clip_result = numpy::clip(values, min_val, max_val); bool test8_pass = true; if (std::abs(clip_result.getElementAt({ 0 }) - (-1.0)) > 1e-10 || std::abs(clip_result.getElementAt({ 3 }) - 2.0) > 1e-10 || std::abs(clip_result.getElementAt({ 4 }) - 3.0) > 1e-10) { test8_pass = false; } if (test8_pass) { // std::cout << "[OK] Clip function works correctly"; .. _example-top_level-clip-1098: .. dropdown:: clip (np_test_1_all.cpp:15142) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15132 :emphasize-lines: 11 numpy::NDArray values({ 5 }); values.setElementAt({ 0 }, -2.0); values.setElementAt({ 1 }, -1.0); values.setElementAt({ 2 }, 0.5); values.setElementAt({ 3 }, 2.0); values.setElementAt({ 4 }, 5.0); double min_val = -1.0; double max_val = 3.0; auto clip_result = numpy::clip(values, min_val, max_val); bool test8_pass = true; if (std::abs(clip_result.getElementAt({ 0 }) - (-1.0)) > 1e-10 || std::abs(clip_result.getElementAt({ 3 }) - 2.0) > 1e-10 || std::abs(clip_result.getElementAt({ 4 }) - 3.0) > 1e-10) { test8_pass = false; } if (test8_pass) { // std::cout << "[OK] Clip function works correctly"; .. _example-top_level-clip-1099: .. dropdown:: clip (np_test_1_all.cpp:15142) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15132 :emphasize-lines: 11 numpy::NDArray values({ 5 }); values.setElementAt({ 0 }, -2.0); values.setElementAt({ 1 }, -1.0); values.setElementAt({ 2 }, 0.5); values.setElementAt({ 3 }, 2.0); values.setElementAt({ 4 }, 5.0); double min_val = -1.0; double max_val = 3.0; auto clip_result = numpy::clip(values, min_val, max_val); bool test8_pass = true; if (std::abs(clip_result.getElementAt({ 0 }) - (-1.0)) > 1e-10 || std::abs(clip_result.getElementAt({ 3 }) - 2.0) > 1e-10 || std::abs(clip_result.getElementAt({ 4 }) - 3.0) > 1e-10) { test8_pass = false; } if (test8_pass) { // std::cout << "[OK] Clip function works correctly"; .. _example-top_level-clip-1100: .. dropdown:: clip (np_test_1_all.cpp:15142) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15132 :emphasize-lines: 11 numpy::NDArray values({ 5 }); values.setElementAt({ 0 }, -2.0); values.setElementAt({ 1 }, -1.0); values.setElementAt({ 2 }, 0.5); values.setElementAt({ 3 }, 2.0); values.setElementAt({ 4 }, 5.0); double min_val = -1.0; double max_val = 3.0; auto clip_result = numpy::clip(values, min_val, max_val); bool test8_pass = true; if (std::abs(clip_result.getElementAt({ 0 }) - (-1.0)) > 1e-10 || std::abs(clip_result.getElementAt({ 3 }) - 2.0) > 1e-10 || std::abs(clip_result.getElementAt({ 4 }) - 3.0) > 1e-10) { test8_pass = false; } if (test8_pass) { // std::cout << "[OK] Clip function works correctly"; .. _example-top_level-clip-1101: .. dropdown:: clip (np_test_1_all.cpp:15142) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15132 :emphasize-lines: 11 numpy::NDArray values({ 5 }); values.setElementAt({ 0 }, -2.0); values.setElementAt({ 1 }, -1.0); values.setElementAt({ 2 }, 0.5); values.setElementAt({ 3 }, 2.0); values.setElementAt({ 4 }, 5.0); double min_val = -1.0; double max_val = 3.0; auto clip_result = numpy::clip(values, min_val, max_val); bool test8_pass = true; if (std::abs(clip_result.getElementAt({ 0 }) - (-1.0)) > 1e-10 || std::abs(clip_result.getElementAt({ 3 }) - 2.0) > 1e-10 || std::abs(clip_result.getElementAt({ 4 }) - 3.0) > 1e-10) { test8_pass = false; } if (test8_pass) { // std::cout << "[OK] Clip function works correctly"; .. _example-top_level-clip-1102: .. dropdown:: clip (np_test_1_all.cpp:15142) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15132 :emphasize-lines: 11 numpy::NDArray values({ 5 }); values.setElementAt({ 0 }, -2.0); values.setElementAt({ 1 }, -1.0); values.setElementAt({ 2 }, 0.5); values.setElementAt({ 3 }, 2.0); values.setElementAt({ 4 }, 5.0); double min_val = -1.0; double max_val = 3.0; auto clip_result = numpy::clip(values, min_val, max_val); bool test8_pass = true; if (std::abs(clip_result.getElementAt({ 0 }) - (-1.0)) > 1e-10 || std::abs(clip_result.getElementAt({ 3 }) - 2.0) > 1e-10 || std::abs(clip_result.getElementAt({ 4 }) - 3.0) > 1e-10) { test8_pass = false; } if (test8_pass) { // std::cout << "[OK] Clip function works correctly"; .. _example-top_level-clip-1103: .. dropdown:: clip (np_test_1_all.cpp:15142) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15132 :emphasize-lines: 11 numpy::NDArray values({ 5 }); values.setElementAt({ 0 }, -2.0); values.setElementAt({ 1 }, -1.0); values.setElementAt({ 2 }, 0.5); values.setElementAt({ 3 }, 2.0); values.setElementAt({ 4 }, 5.0); double min_val = -1.0; double max_val = 3.0; auto clip_result = numpy::clip(values, min_val, max_val); bool test8_pass = true; if (std::abs(clip_result.getElementAt({ 0 }) - (-1.0)) > 1e-10 || std::abs(clip_result.getElementAt({ 3 }) - 2.0) > 1e-10 || std::abs(clip_result.getElementAt({ 4 }) - 3.0) > 1e-10) { test8_pass = false; } if (test8_pass) { // std::cout << "[OK] Clip function works correctly"; .. _example-top_level-clip-1104: .. dropdown:: clip (np_test_1_all.cpp:15142) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15132 :emphasize-lines: 11 numpy::NDArray values({ 5 }); values.setElementAt({ 0 }, -2.0); values.setElementAt({ 1 }, -1.0); values.setElementAt({ 2 }, 0.5); values.setElementAt({ 3 }, 2.0); values.setElementAt({ 4 }, 5.0); double min_val = -1.0; double max_val = 3.0; auto clip_result = numpy::clip(values, min_val, max_val); bool test8_pass = true; if (std::abs(clip_result.getElementAt({ 0 }) - (-1.0)) > 1e-10 || std::abs(clip_result.getElementAt({ 3 }) - 2.0) > 1e-10 || std::abs(clip_result.getElementAt({ 4 }) - 3.0) > 1e-10) { test8_pass = false; } if (test8_pass) { // std::cout << "[OK] Clip function works correctly"; .. _example-top_level-clip-1105: .. dropdown:: clip (np_test_1_all.cpp:15142) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15132 :emphasize-lines: 11 numpy::NDArray values({ 5 }); values.setElementAt({ 0 }, -2.0); values.setElementAt({ 1 }, -1.0); values.setElementAt({ 2 }, 0.5); values.setElementAt({ 3 }, 2.0); values.setElementAt({ 4 }, 5.0); double min_val = -1.0; double max_val = 3.0; auto clip_result = numpy::clip(values, min_val, max_val); bool test8_pass = true; if (std::abs(clip_result.getElementAt({ 0 }) - (-1.0)) > 1e-10 || std::abs(clip_result.getElementAt({ 3 }) - 2.0) > 1e-10 || std::abs(clip_result.getElementAt({ 4 }) - 3.0) > 1e-10) { test8_pass = false; } if (test8_pass) { // std::cout << "[OK] Clip function works correctly"; .. _example-top_level-clip-1106: .. dropdown:: clip (np_test_1_all.cpp:15142) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15132 :emphasize-lines: 11 numpy::NDArray values({ 5 }); values.setElementAt({ 0 }, -2.0); values.setElementAt({ 1 }, -1.0); values.setElementAt({ 2 }, 0.5); values.setElementAt({ 3 }, 2.0); values.setElementAt({ 4 }, 5.0); double min_val = -1.0; double max_val = 3.0; auto clip_result = numpy::clip(values, min_val, max_val); bool test8_pass = true; if (std::abs(clip_result.getElementAt({ 0 }) - (-1.0)) > 1e-10 || std::abs(clip_result.getElementAt({ 3 }) - 2.0) > 1e-10 || std::abs(clip_result.getElementAt({ 4 }) - 3.0) > 1e-10) { test8_pass = false; } if (test8_pass) { // std::cout << "[OK] Clip function works correctly"; .. _example-top_level-clip-1107: .. dropdown:: clip (np_test_1_all.cpp:15142) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15132 :emphasize-lines: 11 numpy::NDArray values({ 5 }); values.setElementAt({ 0 }, -2.0); values.setElementAt({ 1 }, -1.0); values.setElementAt({ 2 }, 0.5); values.setElementAt({ 3 }, 2.0); values.setElementAt({ 4 }, 5.0); double min_val = -1.0; double max_val = 3.0; auto clip_result = numpy::clip(values, min_val, max_val); bool test8_pass = true; if (std::abs(clip_result.getElementAt({ 0 }) - (-1.0)) > 1e-10 || std::abs(clip_result.getElementAt({ 3 }) - 2.0) > 1e-10 || std::abs(clip_result.getElementAt({ 4 }) - 3.0) > 1e-10) { test8_pass = false; } if (test8_pass) { // std::cout << "[OK] Clip function works correctly"; .. _example-top_level-clip-1108: .. dropdown:: clip (np_test_1_all.cpp:15142) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15132 :emphasize-lines: 11 numpy::NDArray values({ 5 }); values.setElementAt({ 0 }, -2.0); values.setElementAt({ 1 }, -1.0); values.setElementAt({ 2 }, 0.5); values.setElementAt({ 3 }, 2.0); values.setElementAt({ 4 }, 5.0); double min_val = -1.0; double max_val = 3.0; auto clip_result = numpy::clip(values, min_val, max_val); bool test8_pass = true; if (std::abs(clip_result.getElementAt({ 0 }) - (-1.0)) > 1e-10 || std::abs(clip_result.getElementAt({ 3 }) - 2.0) > 1e-10 || std::abs(clip_result.getElementAt({ 4 }) - 3.0) > 1e-10) { test8_pass = false; } if (test8_pass) { // std::cout << "[OK] Clip function works correctly"; .. _example-top_level-clump_masked-1109: .. dropdown:: clump_masked (np_test_1_all.cpp:27667) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27657 :emphasize-lines: 11 // std::cout << " ma::make_mask_none({3, 4}): shape (" << shape[0] << ", " << shape[1] << ")" << std::endl; // std::cout << " All elements unmasked: " << (mask.getElementAt({ 0, 0 }) == false ? "true" : "false"); std::cout << " -> tests passed"; } // ============================================================================ // Phase 3C: Masked Array Manipulation (15 functions) // ============================================================================ void test_clump_masked_unmasked() { std::cout << "========= ma::clump_masked() and ma::clump_unmasked(): find sequences ==="; auto data = numpy::array({ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }); auto mask = numpy::array({ false, true, true, false, false, true }); auto ma = numpy::ma::masked_array(data, mask); auto masked_clumps = numpy::ma::clump_masked(ma); auto unmasked_clumps = numpy::ma::clump_unmasked(ma); // std::cout << " ma::clump_masked([F,T,T,F,F,T]): " << masked_clumps.size() << " sequences found (expected: 2)" << std::endl; // std::cout << " ma::clump_unmasked([F,T,T,F,F,T]): " << unmasked_clumps.size() << " sequences found (expected: 2)" << std::endl; .. _example-top_level-clump_unmasked-1110: .. dropdown:: clump_unmasked (np_test_1_all.cpp:27667) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27657 :emphasize-lines: 11 // std::cout << " ma::make_mask_none({3, 4}): shape (" << shape[0] << ", " << shape[1] << ")" << std::endl; // std::cout << " All elements unmasked: " << (mask.getElementAt({ 0, 0 }) == false ? "true" : "false"); std::cout << " -> tests passed"; } // ============================================================================ // Phase 3C: Masked Array Manipulation (15 functions) // ============================================================================ void test_clump_masked_unmasked() { std::cout << "========= ma::clump_masked() and ma::clump_unmasked(): find sequences ==="; auto data = numpy::array({ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }); auto mask = numpy::array({ false, true, true, false, false, true }); auto ma = numpy::ma::masked_array(data, mask); auto masked_clumps = numpy::ma::clump_masked(ma); auto unmasked_clumps = numpy::ma::clump_unmasked(ma); // std::cout << " ma::clump_masked([F,T,T,F,F,T]): " << masked_clumps.size() << " sequences found (expected: 2)" << std::endl; // std::cout << " ma::clump_unmasked([F,T,T,F,F,T]): " << unmasked_clumps.size() << " sequences found (expected: 2)" << std::endl; .. _example-top_level-common_fill_value-1111: .. dropdown:: common_fill_value (np_test_5_all.cpp:3838) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3828 :emphasize-lines: 11 numpy::MaskedArray ma1(arr1); ma1.set_fill_value(999.0); numpy::NDArray arr2({ 3 }); arr2.setElementAt({ 0 }, 4.0); arr2.setElementAt({ 1 }, 5.0); arr2.setElementAt({ 2 }, 6.0); numpy::MaskedArray ma2(arr2); ma2.set_fill_value(999.0); auto fill = numpy::common_fill_value(ma1, ma2); if (std::abs(fill - 999.0) > 1e-10) { std::cout << " [FAIL] : in np_test_common_fill_value() : Expected 999.0, got " << fill; throw std::runtime_error("Test failed"); } // Test with different fill values - should return default fill value ma2.set_fill_value(111.0); auto fill2 = numpy::common_fill_value(ma1, ma2); // When fill values differ, function returns default fill value for the type .. _example-top_level-companion-1112: .. dropdown:: companion (np_test_2_all.cpp:5247) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5237 :emphasize-lines: 11 /** * Test special matrix constructors */ void testSpecialMatrices() { std::cout << "========= testSpecialMatrices ======================="; // Test companion matrix std::vector poly_coeffs = { 1.0, -3.0, 2.0 }; // x^2 - 3x + 2 try { auto companion_mat = numpy::companion(poly_coeffs); assert_test(companion_mat.rows() == 2 && companion_mat.cols() == 2, "Companion matrix dimensions"); assert_test(std::abs(companion_mat(0, 1) - 1.0) < 1e-10, "Companion matrix structure"); assert_test(std::abs(companion_mat(1, 0) - (-2.0)) < 1e-10, "Companion matrix coefficients"); assert_test(std::abs(companion_mat(1, 1) - 3.0) < 1e-10, "Companion matrix coefficients"); } catch (...) { // std::cout << "Companion matrix test failed"; } // Test Toeplitz matrix .. _example-top_level-complex_from_polar-1113: .. dropdown:: complex_from_polar (np_test_3_all.cpp:4520) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4510 :emphasize-lines: 11 auto magnitude = NDArray({ 3 }); magnitude.setElementAt({ 0 }, 1.0); magnitude.setElementAt({ 1 }, 2.0); magnitude.setElementAt({ 2 }, 5.0); auto angle_arr = NDArray({ 3 }); angle_arr.setElementAt({ 0 }, 0.0); // 0 degrees angle_arr.setElementAt({ 1 }, M_PI / 2); // 90 degrees angle_arr.setElementAt({ 2 }, M_PI / 4); // 45 degrees auto complex_arr = complex_from_polar(magnitude, angle_arr); if (!(std::abs(complex_arr.getElementAt({ 0 }).real() - 1.0) < 1e-10)) { std::string description = std::string("testComplexFromPolar():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(complex_arr.getElementAt({ 0 }).real() - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(complex_arr.getElementAt({ 0 }).imag() - 0.0) < 1e-10)) { std::string description = std::string("testComplexFromPolar():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(complex_arr.getElementAt({ 0 }).imag() - 0.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-complex_from_polar-1114: .. dropdown:: complex_from_polar (np_test_3_all.cpp:4520) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4510 :emphasize-lines: 11 auto magnitude = NDArray({ 3 }); magnitude.setElementAt({ 0 }, 1.0); magnitude.setElementAt({ 1 }, 2.0); magnitude.setElementAt({ 2 }, 5.0); auto angle_arr = NDArray({ 3 }); angle_arr.setElementAt({ 0 }, 0.0); // 0 degrees angle_arr.setElementAt({ 1 }, M_PI / 2); // 90 degrees angle_arr.setElementAt({ 2 }, M_PI / 4); // 45 degrees auto complex_arr = complex_from_polar(magnitude, angle_arr); if (!(std::abs(complex_arr.getElementAt({ 0 }).real() - 1.0) < 1e-10)) { std::string description = std::string("testComplexFromPolar():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(complex_arr.getElementAt({ 0 }).real() - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(complex_arr.getElementAt({ 0 }).imag() - 0.0) < 1e-10)) { std::string description = std::string("testComplexFromPolar():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(complex_arr.getElementAt({ 0 }).imag() - 0.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-cond-1115: .. dropdown:: cond (np_test_3_all.cpp:19667) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19657 :emphasize-lines: 11 if (rank != 2) { std::cerr << "[FAIL] Expected rank 2, got " << rank; return false; } // std::cout << " [OK] Rectangular matrix: rank = " << rank << std::endl; return true; } /** * Test cond() with diagonal matrix */ bool test_cond_diagonal() { std::cout << " Testing cond() with diagonal matrix..."; NDArray diag_mat = createArrayFromVector( {3, 3}, {1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0} ); .. _example-top_level-cond-1116: .. dropdown:: cond (np_test_3_all.cpp:19667) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19657 :emphasize-lines: 11 if (rank != 2) { std::cerr << "[FAIL] Expected rank 2, got " << rank; return false; } // std::cout << " [OK] Rectangular matrix: rank = " << rank << std::endl; return true; } /** * Test cond() with diagonal matrix */ bool test_cond_diagonal() { std::cout << " Testing cond() with diagonal matrix..."; NDArray diag_mat = createArrayFromVector( {3, 3}, {1.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 3.0} ); .. _example-top_level-conj_complex_mkl-1117: .. dropdown:: conj_complex_mkl (np_test_3_all.cpp:17655) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17645 :emphasize-lines: 11 auto abs_result = numpy::mkl_special_complex::abs_complex_mkl(z); if (std::abs(abs_result.getElementAt({ 0 }) - 5.0) > tolerance) { // |3+4i| = 5 std::cout << " [FAIL] : abs_complex_mkl incorrect for 3+4i"; throw std::runtime_error("abs_complex_mkl failed"); } // Test arg (returns real array) auto arg_result = numpy::mkl_special_complex::arg_complex_mkl(z); // Test conj auto conj_result = numpy::mkl_special_complex::conj_complex_mkl(z); for (size_t i = 0; i < z.getSize(); ++i) { auto expected = std::conj(z.getElementAt({ i })); if (std::abs(conj_result.getElementAt({ i }) - expected) > tolerance) { std::cout << " [FAIL] : conj_complex_mkl incorrect at index " << i; throw std::runtime_error("conj_complex_mkl failed"); } } // Test sqrt auto sqrt_result = numpy::mkl_special_complex::sqrt_complex_mkl(z); .. _example-top_level-conj_complex_mkl-1118: .. dropdown:: conj_complex_mkl (np_test_3_all.cpp:17655) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17645 :emphasize-lines: 11 auto abs_result = numpy::mkl_special_complex::abs_complex_mkl(z); if (std::abs(abs_result.getElementAt({ 0 }) - 5.0) > tolerance) { // |3+4i| = 5 std::cout << " [FAIL] : abs_complex_mkl incorrect for 3+4i"; throw std::runtime_error("abs_complex_mkl failed"); } // Test arg (returns real array) auto arg_result = numpy::mkl_special_complex::arg_complex_mkl(z); // Test conj auto conj_result = numpy::mkl_special_complex::conj_complex_mkl(z); for (size_t i = 0; i < z.getSize(); ++i) { auto expected = std::conj(z.getElementAt({ i })); if (std::abs(conj_result.getElementAt({ i }) - expected) > tolerance) { std::cout << " [FAIL] : conj_complex_mkl incorrect at index " << i; throw std::runtime_error("conj_complex_mkl failed"); } } // Test sqrt auto sqrt_result = numpy::mkl_special_complex::sqrt_complex_mkl(z); .. _example-top_level-conjugate_gradient-1119: .. dropdown:: conjugate_gradient (np_test_3_all.cpp:20207) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20197 :emphasize-lines: 11 if (i < n - 1) coo.add_entry(i, i + 1, -1.0); } auto A = coo.to_csr(); numpy::NDArray b({ n }); for (size_t i = 0; i < n; ++i) { b.setElementAt({ i }, 1.0); } auto [x, info] = numpy::sparse::conjugate_gradient(A, b, static_cast*>(nullptr), 1e-8, 1000); if (!info.converged) { std::cout << " [FAIL] : in np_test_sparse_cg() : CG did not converge"; throw std::runtime_error("np_test_sparse_cg failed: no convergence"); } if (info.final_residual > 1e-6) { std::cout << " [FAIL] : in np_test_sparse_cg() : CG residual too large"; throw std::runtime_error("np_test_sparse_cg failed"); } .. _example-top_level-convertto-1120: .. dropdown:: convertTo (np_test_1_all.cpp:7051) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7041 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void testConversionsDateTime() { std::cout << "========= testConversionsDateTime ======================="; datetime64 dt_seconds("2024-01-01T12:30:45"); // std::cout << "Original (seconds): " << dt_seconds.toString() << std::endl; datetime64 dt_days = dt_seconds.convertTo(DateTimeUnit::Day); // std::cout << "Converted to days: " << dt_days.toString() << std::endl; datetime64 dt_hours = dt_seconds.convertTo(DateTimeUnit::Hour); // std::cout << "Converted to hours: " << dt_hours.toString() << std::endl; timedelta64 td_hours(24, DateTimeUnit::Hour); // std::cout << "24 hours: " << td_hours.toString() << std::endl; timedelta64 td_days = td_hours.convertTo(DateTimeUnit::Day); // std::cout << "Converted to days: " << td_days.toString() << std::endl; .. _example-top_level-convertto-1121: .. dropdown:: convertTo (np_test_1_all.cpp:7051) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7041 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void testConversionsDateTime() { std::cout << "========= testConversionsDateTime ======================="; datetime64 dt_seconds("2024-01-01T12:30:45"); // std::cout << "Original (seconds): " << dt_seconds.toString() << std::endl; datetime64 dt_days = dt_seconds.convertTo(DateTimeUnit::Day); // std::cout << "Converted to days: " << dt_days.toString() << std::endl; datetime64 dt_hours = dt_seconds.convertTo(DateTimeUnit::Hour); // std::cout << "Converted to hours: " << dt_hours.toString() << std::endl; timedelta64 td_hours(24, DateTimeUnit::Hour); // std::cout << "24 hours: " << td_hours.toString() << std::endl; timedelta64 td_days = td_hours.convertTo(DateTimeUnit::Day); // std::cout << "Converted to days: " << td_days.toString() << std::endl; .. _example-top_level-count-1122: .. dropdown:: count (np_test_1_all.cpp:3616) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3606 :emphasize-lines: 11 // Create larger arrays for performance testing auto large_arr = NDArray::createOnes({100, 100}); auto broadcast_arr = NDArray::createOnes({1, 100}); // Time the operation (basic timing) auto start = std::chrono::high_resolution_clock::now(); auto result = large_arr.addArrays(broadcast_arr); auto end = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast(end - start); // std::cout << "Large array broadcasting took " << duration.count() << " microseconds" << std::endl; // Verify result shape if (!((result.getShape() == std::vector{100, 100}))) { std::string description = std::string("test_broadcasting_performance():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((result.getShape() == std::vector{100, 100}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({50, 50}) == 2.0)) { std::string description = std::string("test_broadcasting_performance():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({50, 50}) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-count-1123: .. dropdown:: count (np_test_1_all.cpp:3616) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3606 :emphasize-lines: 11 // Create larger arrays for performance testing auto large_arr = NDArray::createOnes({100, 100}); auto broadcast_arr = NDArray::createOnes({1, 100}); // Time the operation (basic timing) auto start = std::chrono::high_resolution_clock::now(); auto result = large_arr.addArrays(broadcast_arr); auto end = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast(end - start); // std::cout << "Large array broadcasting took " << duration.count() << " microseconds" << std::endl; // Verify result shape if (!((result.getShape() == std::vector{100, 100}))) { std::string description = std::string("test_broadcasting_performance():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((result.getShape() == std::vector{100, 100}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({50, 50}) == 2.0)) { std::string description = std::string("test_broadcasting_performance():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({50, 50}) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-count_masked-1124: .. dropdown:: count_masked (np_test_3_all.cpp:14947) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14937 :emphasize-lines: 11 // Test count (standalone) size_t valid_count = count(ma); if (!(valid_count == 7)) { std::string description = std::string("test_getdata_and_utilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(valid_count == 7)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] count() standalone function works correctly\n"; // Test count_masked size_t masked_count = count_masked(ma); if (!(masked_count == 2)) { std::string description = std::string("test_getdata_and_utilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(masked_count == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] count_masked() returns correct number\n"; // Test compressed (standalone) auto comp = compressed(ma); if (!(comp.getSize() == 7)) { .. _example-top_level-count_nonmasked-1125: .. dropdown:: count_nonmasked (np_test_4_all.cpp:20635) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20625 :emphasize-lines: 11 } // std::cout << "OK: masked_all_like(MaskedArray) test passed" << std::endl; } // Test count shows zero non-masked elements { NDArray data({10}); auto masked = ma::masked_all_like(data); size_t non_masked = ma::count_nonmasked(masked); if (!(non_masked == 0)) { std::string description = std::string("np_test_phase6_ma_masked_all_like():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(non_masked == 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } size_t masked_count = ma::count_masked(masked); if (!(masked_count == 10)) { std::string description = std::string("np_test_phase6_ma_masked_all_like():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(masked_count == 10)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-count_nonmasked-1126: .. dropdown:: count_nonmasked (np_test_4_all.cpp:20635) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20625 :emphasize-lines: 11 } // std::cout << "OK: masked_all_like(MaskedArray) test passed" << std::endl; } // Test count shows zero non-masked elements { NDArray data({10}); auto masked = ma::masked_all_like(data); size_t non_masked = ma::count_nonmasked(masked); if (!(non_masked == 0)) { std::string description = std::string("np_test_phase6_ma_masked_all_like():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(non_masked == 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } size_t masked_count = ma::count_masked(masked); if (!(masked_count == 10)) { std::string description = std::string("np_test_phase6_ma_masked_all_like():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(masked_count == 10)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-count_unique-1127: .. dropdown:: count_unique (np_test_1_all.cpp:19689) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19679 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(set_ops::is_unique(duplicate_array) == false)) { std::string description = std::string("testUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(set_ops::is_unique(duplicate_array) == false)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] is_unique function works correctly\n"; // Test count_unique if (!(set_ops::count_unique(unique_array) == 4)) { std::string description = std::string("testUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(set_ops::count_unique(unique_array) == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(set_ops::count_unique(duplicate_array) == 3)) { std::string description = std::string("testUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(set_ops::count_unique(duplicate_array) == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] count_unique function works correctly\n"; .. _example-top_level-counting_sort_range-1128: .. dropdown:: counting_sort_range (np_test_2_all.cpp:8900) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8890 :emphasize-lines: 11 } void test_ipp_counting_sort() { std::cout << "========= test_ipp_counting_sort ======================="; // Test 1: Basic integer counting sort { std::vector data = { 4, 2, 2, 8, 3, 3, 1 }; std::vector expected = { 1, 2, 2, 3, 3, 4, 8 }; numpy::counting_sort_range(data, 1, 8); if (data != expected) { std::cout << " Basic counting sort: -> [FAIL]"; throw std::runtime_error("IPP counting_sort: FAILED - basic test incorrect"); } // std::cout << " Basic counting sort: -> [OK]" << std::endl; } // Test 2: Large range test { .. _example-top_level-datetime64-1129: .. dropdown:: datetime64 (np_test_1_all.cpp:6990) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6980 :emphasize-lines: 11 } void testBusinessDateRangeDateTime() { std::cout << "========= testBusinessDateRangeDateTime ======================="; datetime64 start("2024-03-11"); // Monday datetime64 end("2024-03-22"); // Friday (2 weeks later) // Create holidays set std::set holidays; holidays.insert(datetime64("2024-03-15")); // Friday holiday auto business_dates = createBusinessDateRange(start, end, holidays); // std::cout << "Business dates from " << start.toString() // << " to " << end.toString() << " (excluding 2024-03-15):" << std::endl; //business_dates.printArray(); std::cout << " -> tests passed" << std::endl; } void testMonthRangeDateTime() { .. _example-top_level-datetime64-1130: .. dropdown:: datetime64 (np_test_1_all.cpp:6990) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6980 :emphasize-lines: 11 } void testBusinessDateRangeDateTime() { std::cout << "========= testBusinessDateRangeDateTime ======================="; datetime64 start("2024-03-11"); // Monday datetime64 end("2024-03-22"); // Friday (2 weeks later) // Create holidays set std::set holidays; holidays.insert(datetime64("2024-03-15")); // Friday holiday auto business_dates = createBusinessDateRange(start, end, holidays); // std::cout << "Business dates from " << start.toString() // << " to " << end.toString() << " (excluding 2024-03-15):" << std::endl; //business_dates.printArray(); std::cout << " -> tests passed" << std::endl; } void testMonthRangeDateTime() { .. _example-top_level-daysinmonth-1131: .. dropdown:: daysInMonth (np_test_1_all.cpp:6977) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6967 :emphasize-lines: 11 // std::cout << "Business days from " << start_bday.toString() // << " to " << end_bday.toString() << ": " << business_days << std::endl; datetime64 offset_date = datetime_utils::businessDayOffset(start_bday, 3); // std::cout << "3 business days after " << start_bday.toString() // << ": " << offset_date.toString() << std::endl; // Test leap year // std::cout << "2024 is leap year: " << datetime_utils::isLeapYear(2024) << std::endl; // std::cout << "2023 is leap year: " << datetime_utils::isLeapYear(2023) << std::endl; // std::cout << "Days in February 2024: " << datetime_utils::daysInMonth(2024, 2) << std::endl; std::cout << " -> tests passed" << std::endl; } void testBusinessDateRangeDateTime() { std::cout << "========= testBusinessDateRangeDateTime ======================="; datetime64 start("2024-03-11"); // Monday datetime64 end("2024-03-22"); // Friday (2 weeks later) .. _example-top_level-daysinmonth-1132: .. dropdown:: daysInMonth (np_test_1_all.cpp:6977) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6967 :emphasize-lines: 11 // std::cout << "Business days from " << start_bday.toString() // << " to " << end_bday.toString() << ": " << business_days << std::endl; datetime64 offset_date = datetime_utils::businessDayOffset(start_bday, 3); // std::cout << "3 business days after " << start_bday.toString() // << ": " << offset_date.toString() << std::endl; // Test leap year // std::cout << "2024 is leap year: " << datetime_utils::isLeapYear(2024) << std::endl; // std::cout << "2023 is leap year: " << datetime_utils::isLeapYear(2023) << std::endl; // std::cout << "Days in February 2024: " << datetime_utils::daysInMonth(2024, 2) << std::endl; std::cout << " -> tests passed" << std::endl; } void testBusinessDateRangeDateTime() { std::cout << "========= testBusinessDateRangeDateTime ======================="; datetime64 start("2024-03-11"); // Monday datetime64 end("2024-03-22"); // Friday (2 weeks later) .. _example-top_level-decode-1133: .. dropdown:: decode (np_test_5_all.cpp:1188) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1178 :emphasize-lines: 11 void np_test_string_encode_decode() { std::cout << "========= encode/decode operations ======================="; // Test encode std::vector strings = { "hello", "world", "test" }; auto arr = numpy::char_::array<32>(strings); auto encoded = numpy::char_::encode(arr, "utf-8"); // Test decode auto decoded = numpy::char_::decode(encoded, "utf-8"); // Verify basic operation (just check no exceptions thrown) bool passed = true; if (!passed) { std::cout << " [FAIL] : in np_test_string_encode_decode() : encode/decode failed"; throw std::runtime_error("np_test_string_encode_decode failed"); } std::cout << " -> tests passed" << std::endl; .. _example-top_level-decode-1134: .. dropdown:: decode (np_test_5_all.cpp:1188) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1178 :emphasize-lines: 11 void np_test_string_encode_decode() { std::cout << "========= encode/decode operations ======================="; // Test encode std::vector strings = { "hello", "world", "test" }; auto arr = numpy::char_::array<32>(strings); auto encoded = numpy::char_::encode(arr, "utf-8"); // Test decode auto decoded = numpy::char_::decode(encoded, "utf-8"); // Verify basic operation (just check no exceptions thrown) bool passed = true; if (!passed) { std::cout << " [FAIL] : in np_test_string_encode_decode() : encode/decode failed"; throw std::runtime_error("np_test_string_encode_decode failed"); } std::cout << " -> tests passed" << std::endl; .. _example-top_level-default_fill_value-1135: .. dropdown:: default_fill_value (np_test_1_all.cpp:27637) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27627 :emphasize-lines: 11 // std::cout << " ma::isMA(regular_array): " << (numpy::ma::isMA(regular_array) ? "true" : "false") << " (expected: false)" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_fill_value_functions() { std::cout << "========= Fill value query functions ==="; int int_val = 42; double double_val = 3.14; int default_int = numpy::ma::default_fill_value(int_val); double default_double = numpy::ma::default_fill_value(double_val); // std::cout << " ma::default_fill_value(int): " << default_int << " (expected: 999999)" << std::endl; // std::cout << " ma::default_fill_value(double): " << default_double << " (expected: 1e+20)" << std::endl; int max_int = numpy::ma::maximum_fill_value(int_val); double max_double = numpy::ma::maximum_fill_value(double_val); // std::cout << " ma::maximum_fill_value(int): " << max_int << " (expected: INT_MAX)" << std::endl; // std::cout << " ma::maximum_fill_value(double): " << (std::isinf(max_double) ? "inf" : "finite") << " (expected: inf)" << std::endl; .. _example-top_level-default_fill_value-1136: .. dropdown:: default_fill_value (np_test_1_all.cpp:27637) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27627 :emphasize-lines: 11 // std::cout << " ma::isMA(regular_array): " << (numpy::ma::isMA(regular_array) ? "true" : "false") << " (expected: false)" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_fill_value_functions() { std::cout << "========= Fill value query functions ==="; int int_val = 42; double double_val = 3.14; int default_int = numpy::ma::default_fill_value(int_val); double default_double = numpy::ma::default_fill_value(double_val); // std::cout << " ma::default_fill_value(int): " << default_int << " (expected: 999999)" << std::endl; // std::cout << " ma::default_fill_value(double): " << default_double << " (expected: 1e+20)" << std::endl; int max_int = numpy::ma::maximum_fill_value(int_val); double max_double = numpy::ma::maximum_fill_value(double_val); // std::cout << " ma::maximum_fill_value(int): " << max_int << " (expected: INT_MAX)" << std::endl; // std::cout << " ma::maximum_fill_value(double): " << (std::isinf(max_double) ? "inf" : "finite") << " (expected: inf)" << std::endl; .. _example-top_level-default_fill_value-1137: .. dropdown:: default_fill_value (np_test_1_all.cpp:27637) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27627 :emphasize-lines: 11 // std::cout << " ma::isMA(regular_array): " << (numpy::ma::isMA(regular_array) ? "true" : "false") << " (expected: false)" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_fill_value_functions() { std::cout << "========= Fill value query functions ==="; int int_val = 42; double double_val = 3.14; int default_int = numpy::ma::default_fill_value(int_val); double default_double = numpy::ma::default_fill_value(double_val); // std::cout << " ma::default_fill_value(int): " << default_int << " (expected: 999999)" << std::endl; // std::cout << " ma::default_fill_value(double): " << default_double << " (expected: 1e+20)" << std::endl; int max_int = numpy::ma::maximum_fill_value(int_val); double max_double = numpy::ma::maximum_fill_value(double_val); // std::cout << " ma::maximum_fill_value(int): " << max_int << " (expected: INT_MAX)" << std::endl; // std::cout << " ma::maximum_fill_value(double): " << (std::isinf(max_double) ? "inf" : "finite") << " (expected: inf)" << std::endl; .. _example-top_level-default_rng-1138: .. dropdown:: default_rng (np_test_1_all.cpp:25144) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 25134 :emphasize-lines: 11 } std::cout << " -> tests passed" << std::endl; } // ============================================================================ // DEFAULT_RNG TESTS // ============================================================================ void np_test_bitgen_default_rng() { std::cout << "========= default_rng() factory ======================="; // Test with seed auto rng1 = numpy::random::default_rng(12345); auto val1 = rng1.random({ 1 }).data()[0]; // Test reproducibility auto rng2 = numpy::random::default_rng(12345); auto val2 = rng2.random({ 1 }).data()[0]; if (std::abs(val1 - val2) > 1e-15) { .. _example-top_level-deprecate-1139: .. dropdown:: deprecate (np_test_2_all.cpp:19720) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19710 :emphasize-lines: 11 // ============================================================================ // DEPRECATION TESTS // ============================================================================ void np_test_introspection_deprecate() { std::cout << "========= deprecate: basic deprecation warnings ======================="; // Test basic deprecate // std::cout << "Testing basic deprecation..." << std::endl; numpy::deprecate("", "old_api", "new_api"); // Test deprecate_with_doc // std::cout << "Testing deprecation with custom message..." << std::endl; numpy::deprecate_with_doc("This function is obsolete and will be removed."); // Verify no exceptions thrown bool passed = true; if (!passed) { std::cout << " [FAIL] : in np_test_introspection_deprecate() : deprecation test failed"; .. _example-top_level-deprecate_with_doc-1140: .. dropdown:: deprecate_with_doc (np_test_2_all.cpp:19724) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19714 :emphasize-lines: 11 void np_test_introspection_deprecate() { std::cout << "========= deprecate: basic deprecation warnings ======================="; // Test basic deprecate // std::cout << "Testing basic deprecation..." << std::endl; numpy::deprecate("", "old_api", "new_api"); // Test deprecate_with_doc // std::cout << "Testing deprecation with custom message..." << std::endl; numpy::deprecate_with_doc("This function is obsolete and will be removed."); // Verify no exceptions thrown bool passed = true; if (!passed) { std::cout << " [FAIL] : in np_test_introspection_deprecate() : deprecation test failed"; throw std::runtime_error("np_test_introspection_deprecate failed"); } std::cout << " -> tests passed" << std::endl; .. _example-top_level-describe-1141: .. dropdown:: describe (np_test_1_all.cpp:11448) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11438 :emphasize-lines: 11 auto moment2_result = moment(normal_data, 2); // std::cout << "2nd moment: " << moment2_result.getElementAt({ 0 }) << std::endl; if (!(moment2_result.getElementAt({ 0 }) > 0)) { std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(moment2_result.getElementAt({ 0 }) > 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Moment calculation\n"; // Test describe auto desc_result = describe(normal_data); // std::cout << "Describe result:" << std::endl; // std::cout << " nobs: " << desc_result.nobs << std::endl; // std::cout << " min: " << desc_result.minmax.first << ", max: " << desc_result.minmax.second << std::endl; // std::cout << " mean: " << desc_result.mean << std::endl; // std::cout << " variance: " << desc_result.variance << std::endl; if (!(desc_result.nobs == 5)) { std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(desc_result.nobs == 5)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-disp-1142: .. dropdown:: disp (np_test_2_all.cpp:19822) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19812 :emphasize-lines: 11 } // ============================================================================ // DISPLAY TESTS // ============================================================================ void np_test_introspection_display() { std::cout << "========= disp: display messages ======================="; // Test string display numpy::introspection::disp("Test message from disp()"); numpy::introspection::disp("Another test message"); bool passed = true; // Verify no exceptions if (!passed) { std::cout << " [FAIL] : in np_test_introspection_display() : display test failed"; throw std::runtime_error("np_test_introspection_display failed"); } std::cout << " -> tests passed" << std::endl; .. _example-top_level-disp-1143: .. dropdown:: disp (np_test_2_all.cpp:19822) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19812 :emphasize-lines: 11 } // ============================================================================ // DISPLAY TESTS // ============================================================================ void np_test_introspection_display() { std::cout << "========= disp: display messages ======================="; // Test string display numpy::introspection::disp("Test message from disp()"); numpy::introspection::disp("Another test message"); bool passed = true; // Verify no exceptions if (!passed) { std::cout << " [FAIL] : in np_test_introspection_display() : display test failed"; throw std::runtime_error("np_test_introspection_display failed"); } std::cout << " -> tests passed" << std::endl; .. _example-top_level-divmod-1144: .. dropdown:: divmod (np_test_1_all.cpp:21140) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21130 :emphasize-lines: 11 auto a = NDArray({ 3 }); a.setElementAt({ 0 }, 7.0); a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.5); auto b = NDArray({ 3 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 2.0); auto [quotient, remainder] = divmod(a, b); if (!(quotient.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quotient.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-divmod-1145: .. dropdown:: divmod (np_test_1_all.cpp:21140) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21130 :emphasize-lines: 11 auto a = NDArray({ 3 }); a.setElementAt({ 0 }, 7.0); a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.5); auto b = NDArray({ 3 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 2.0); auto [quotient, remainder] = divmod(a, b); if (!(quotient.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quotient.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-divmod-1146: .. dropdown:: divmod (np_test_1_all.cpp:21140) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21130 :emphasize-lines: 11 auto a = NDArray({ 3 }); a.setElementAt({ 0 }, 7.0); a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.5); auto b = NDArray({ 3 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 2.0); auto [quotient, remainder] = divmod(a, b); if (!(quotient.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quotient.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-divmod-1147: .. dropdown:: divmod (np_test_1_all.cpp:21140) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21130 :emphasize-lines: 11 auto a = NDArray({ 3 }); a.setElementAt({ 0 }, 7.0); a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.5); auto b = NDArray({ 3 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 2.0); auto [quotient, remainder] = divmod(a, b); if (!(quotient.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quotient.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-divmod-1148: .. dropdown:: divmod (np_test_1_all.cpp:21140) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21130 :emphasize-lines: 11 auto a = NDArray({ 3 }); a.setElementAt({ 0 }, 7.0); a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.5); auto b = NDArray({ 3 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 2.0); auto [quotient, remainder] = divmod(a, b); if (!(quotient.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quotient.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-divmod-1149: .. dropdown:: divmod (np_test_1_all.cpp:21140) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21130 :emphasize-lines: 11 auto a = NDArray({ 3 }); a.setElementAt({ 0 }, 7.0); a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.5); auto b = NDArray({ 3 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 2.0); auto [quotient, remainder] = divmod(a, b); if (!(quotient.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quotient.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-divmod-1150: .. dropdown:: divmod (np_test_1_all.cpp:21140) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21130 :emphasize-lines: 11 auto a = NDArray({ 3 }); a.setElementAt({ 0 }, 7.0); a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.5); auto b = NDArray({ 3 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 2.0); auto [quotient, remainder] = divmod(a, b); if (!(quotient.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quotient.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-divmod-1151: .. dropdown:: divmod (np_test_1_all.cpp:21140) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21130 :emphasize-lines: 11 auto a = NDArray({ 3 }); a.setElementAt({ 0 }, 7.0); a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.5); auto b = NDArray({ 3 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 2.0); auto [quotient, remainder] = divmod(a, b); if (!(quotient.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quotient.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-divmod-1152: .. dropdown:: divmod (np_test_1_all.cpp:21140) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21130 :emphasize-lines: 11 auto a = NDArray({ 3 }); a.setElementAt({ 0 }, 7.0); a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.5); auto b = NDArray({ 3 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 2.0); auto [quotient, remainder] = divmod(a, b); if (!(quotient.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quotient.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-divmod-1153: .. dropdown:: divmod (np_test_1_all.cpp:21140) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21130 :emphasize-lines: 11 auto a = NDArray({ 3 }); a.setElementAt({ 0 }, 7.0); a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.5); auto b = NDArray({ 3 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 2.0); auto [quotient, remainder] = divmod(a, b); if (!(quotient.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quotient.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-divmod-1154: .. dropdown:: divmod (np_test_1_all.cpp:21140) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21130 :emphasize-lines: 11 auto a = NDArray({ 3 }); a.setElementAt({ 0 }, 7.0); a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.5); auto b = NDArray({ 3 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 2.0); auto [quotient, remainder] = divmod(a, b); if (!(quotient.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quotient.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-divmod-1155: .. dropdown:: divmod (np_test_1_all.cpp:21140) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21130 :emphasize-lines: 11 auto a = NDArray({ 3 }); a.setElementAt({ 0 }, 7.0); a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.5); auto b = NDArray({ 3 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 2.0); auto [quotient, remainder] = divmod(a, b); if (!(quotient.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quotient.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-divmod-1156: .. dropdown:: divmod (np_test_1_all.cpp:21140) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21130 :emphasize-lines: 11 auto a = NDArray({ 3 }); a.setElementAt({ 0 }, 7.0); a.setElementAt({ 1 }, -7.0); a.setElementAt({ 2 }, 7.5); auto b = NDArray({ 3 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, 2.0); auto [quotient, remainder] = divmod(a, b); if (!(quotient.getElementAt({ 0 }) == 2.0)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quotient.getElementAt({ 0 }) == 2.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)) { std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-dlpack_to_dtype-1157: .. dropdown:: dlpack_to_dtype (np_test_2_all.cpp:19156) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19146 :emphasize-lines: 11 void np_test_dlpack_dtype_mapping() { std::cout << "========= from_dlpack: dtype mapping ======================="; // Test float32 DLDataType dtype_f32; dtype_f32.code = kDLFloat; dtype_f32.bits = 32; dtype_f32.lanes = 1; numpy::DType np_dtype_f32 = numpy::dlpack::dlpack_to_dtype(dtype_f32); if (np_dtype_f32 != numpy::DType::FLOAT32) { std::cout << " [FAIL] : float32 mapping incorrect"; throw std::runtime_error("np_test_dlpack_dtype_mapping failed: float32"); } // Test float64 DLDataType dtype_f64; dtype_f64.code = kDLFloat; dtype_f64.bits = 64; dtype_f64.lanes = 1; .. _example-top_level-drop_fields-1158: .. dropdown:: drop_fields (np_test_1_all.cpp:21737) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21727 :emphasize-lines: 11 std::vector names = get_names(base); // std::cout << "Field names: "; for (const auto& name : names) { // std::cout << name << " "; } // std::cout << std::endl; // std::cout << "Field structure: " << get_fieldstructure(base) << std::endl; auto dropped = drop_fields(base, { "score" }); // std::cout << "After dropping 'score' field:"; //dropped.printArray(); std::unordered_map rename_map = { {"name", "student_name"} }; auto renamed = rename_fields(base, rename_map); // std::cout << "After renaming 'name' to 'student_name':" << std::endl; //renamed.printArray(); std::cout << " -> tests passed" << std::endl; } .. _example-top_level-dtype-1159: .. dropdown:: dtype (np_test_3_all.cpp:7942) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7932 :emphasize-lines: 11 if (info.max != expected_max) { std::cerr << "[FAIL] IInfo::max mismatch"; throw std::runtime_error("IInfo uint64 max test failed"); } // std::cout << "[OK] IInfo::max = " << info.max << std::endl; std::cout << " -> tests passed" << std::endl; } // ============================================================================ // dtype() Tests - DType descriptor creation // ============================================================================ void np_test_dtype_from_string_integers() { std::cout << "========= np_test_dtype_from_string_integers ======================="; // Test integer type strings if (dtype("int8") != DType::INT8) { std::cerr << "[FAIL] dtype(\"int8\") should return INT8"; throw std::runtime_error("dtype string test failed"); } .. _example-top_level-dtype-1160: .. dropdown:: dtype (np_test_3_all.cpp:7942) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7932 :emphasize-lines: 11 if (info.max != expected_max) { std::cerr << "[FAIL] IInfo::max mismatch"; throw std::runtime_error("IInfo uint64 max test failed"); } // std::cout << "[OK] IInfo::max = " << info.max << std::endl; std::cout << " -> tests passed" << std::endl; } // ============================================================================ // dtype() Tests - DType descriptor creation // ============================================================================ void np_test_dtype_from_string_integers() { std::cout << "========= np_test_dtype_from_string_integers ======================="; // Test integer type strings if (dtype("int8") != DType::INT8) { std::cerr << "[FAIL] dtype(\"int8\") should return INT8"; throw std::runtime_error("dtype string test failed"); } .. _example-top_level-dtype-1161: .. dropdown:: dtype (np_test_3_all.cpp:7942) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7932 :emphasize-lines: 11 if (info.max != expected_max) { std::cerr << "[FAIL] IInfo::max mismatch"; throw std::runtime_error("IInfo uint64 max test failed"); } // std::cout << "[OK] IInfo::max = " << info.max << std::endl; std::cout << " -> tests passed" << std::endl; } // ============================================================================ // dtype() Tests - DType descriptor creation // ============================================================================ void np_test_dtype_from_string_integers() { std::cout << "========= np_test_dtype_from_string_integers ======================="; // Test integer type strings if (dtype("int8") != DType::INT8) { std::cerr << "[FAIL] dtype(\"int8\") should return INT8"; throw std::runtime_error("dtype string test failed"); } .. _example-top_level-dtype_itemsize-1162: .. dropdown:: dtype_itemsize (np_test_2_all.cpp:3572) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3562 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test dtype functions if (!(dtype_name(arr) == "float64")) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(dtype_name(arr) == \"float64\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(dtype_itemsize(arr) == sizeof(double))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(dtype_itemsize(arr) == sizeof(double))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test utility checks if (!(!isscalar(arr))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!isscalar(arr))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-dtype_name-1163: .. dropdown:: dtype_name (np_test_2_all.cpp:3567) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3557 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(flags_info.writeable == true)) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(flags_info.writeable == true)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test dtype functions if (!(dtype_name(arr) == "float64")) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(dtype_name(arr) == \"float64\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(dtype_itemsize(arr) == sizeof(double))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(dtype_itemsize(arr) == sizeof(double))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-dtype_to_string-1164: .. dropdown:: dtype_to_string (np_test_3_all.cpp:8075) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8065 :emphasize-lines: 11 } // std::cout << "[OK] dtype(DType::FLOAT64) -> FLOAT64" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_dtype_to_string() { std::cout << "========= np_test_dtype_to_string ======================="; // Test DType to string conversion (inverse of dtype(string)) if (dtype_to_string(DType::INT8) != "int8") { std::cerr << "[FAIL] dtype_to_string(INT8) should return \"int8\""; throw std::runtime_error("dtype_to_string test failed"); } // std::cout << "[OK] dtype_to_string(INT8) -> \"int8\"" << std::endl; if (dtype_to_string(DType::INT32) != "int32") { std::cerr << "[FAIL] dtype_to_string(INT32) should return \"int32\""; throw std::runtime_error("dtype_to_string test failed"); } // std::cout << "[OK] dtype_to_string(INT32) -> \"int32\"" << std::endl; .. _example-top_level-dump-1165: .. dropdown:: dump (np_test_4_all.cpp:22039) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22029 :emphasize-lines: 11 return 1; } } } // namespace numpy_tests // Comprehensive test suite for Phase 6 NDArray Methods // // This file tests the Phase 6 LOW priority NDArray methods: // - byteswap() - Swap byte order for endianness conversion // - dump() - Serialize array to binary file // - dumps() - Serialize array to byte vector // - setflags() - Set array metadata flags #include #include #include #include #include #include #include "../numpy/np_ndarray.h" .. _example-top_level-encode-1166: .. dropdown:: encode (np_test_5_all.cpp:1185) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1175 :emphasize-lines: 11 // ============================================================================ // ENCODING/DECODING TESTS // ============================================================================ void np_test_string_encode_decode() { std::cout << "========= encode/decode operations ======================="; // Test encode std::vector strings = { "hello", "world", "test" }; auto arr = numpy::char_::array<32>(strings); auto encoded = numpy::char_::encode(arr, "utf-8"); // Test decode auto decoded = numpy::char_::decode(encoded, "utf-8"); // Verify basic operation (just check no exceptions thrown) bool passed = true; if (!passed) { std::cout << " [FAIL] : in np_test_string_encode_decode() : encode/decode failed"; throw std::runtime_error("np_test_string_encode_decode failed"); .. _example-top_level-encode-1167: .. dropdown:: encode (np_test_5_all.cpp:1185) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1175 :emphasize-lines: 11 // ============================================================================ // ENCODING/DECODING TESTS // ============================================================================ void np_test_string_encode_decode() { std::cout << "========= encode/decode operations ======================="; // Test encode std::vector strings = { "hello", "world", "test" }; auto arr = numpy::char_::array<32>(strings); auto encoded = numpy::char_::encode(arr, "utf-8"); // Test decode auto decoded = numpy::char_::decode(encoded, "utf-8"); // Verify basic operation (just check no exceptions thrown) bool passed = true; if (!passed) { std::cout << " [FAIL] : in np_test_string_encode_decode() : encode/decode failed"; throw std::runtime_error("np_test_string_encode_decode failed"); .. _example-top_level-endofmonth-1168: .. dropdown:: endOfMonth (np_test_1_all.cpp:6960) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6950 :emphasize-lines: 11 // std::cout << "Test date: " << test_date.toString() << std::endl; // std::cout << "Is weekend: " << datetime_utils::isWeekend(test_date) << std::endl; // std::cout << "Is business day: " << datetime_utils::isBusinessDay(test_date) << std::endl; // std::cout << "Weekday: " << datetime_utils::getWeekday(test_date) << std::endl; // std::cout << "Day of year: " << datetime_utils::getDayOfYear(test_date) << std::endl; // Test start/end of periods // std::cout << "Start of week: " << datetime_utils::startOfWeek(test_date).toString() << std::endl; // std::cout << "End of week: " << datetime_utils::endOfWeek(test_date).toString() << std::endl; // std::cout << "Start of month: " << datetime_utils::startOfMonth(test_date).toString() << std::endl; // std::cout << "End of month: " << datetime_utils::endOfMonth(test_date).toString() << std::endl; // Test business day calculations datetime64 start_bday("2024-03-11"); // Monday datetime64 end_bday("2024-03-15"); // Friday int64_t business_days = datetime_utils::businessDayCount(start_bday, end_bday); // std::cout << "Business days from " << start_bday.toString() // << " to " << end_bday.toString() << ": " << business_days << std::endl; datetime64 offset_date = datetime_utils::businessDayOffset(start_bday, 3); .. _example-top_level-endofweek-1169: .. dropdown:: endOfWeek (np_test_1_all.cpp:6958) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6948 :emphasize-lines: 11 datetime64 test_date("2024-03-15"); // Friday // std::cout << "Test date: " << test_date.toString() << std::endl; // std::cout << "Is weekend: " << datetime_utils::isWeekend(test_date) << std::endl; // std::cout << "Is business day: " << datetime_utils::isBusinessDay(test_date) << std::endl; // std::cout << "Weekday: " << datetime_utils::getWeekday(test_date) << std::endl; // std::cout << "Day of year: " << datetime_utils::getDayOfYear(test_date) << std::endl; // Test start/end of periods // std::cout << "Start of week: " << datetime_utils::startOfWeek(test_date).toString() << std::endl; // std::cout << "End of week: " << datetime_utils::endOfWeek(test_date).toString() << std::endl; // std::cout << "Start of month: " << datetime_utils::startOfMonth(test_date).toString() << std::endl; // std::cout << "End of month: " << datetime_utils::endOfMonth(test_date).toString() << std::endl; // Test business day calculations datetime64 start_bday("2024-03-11"); // Monday datetime64 end_bday("2024-03-15"); // Friday int64_t business_days = datetime_utils::businessDayCount(start_bday, end_bday); // std::cout << "Business days from " << start_bday.toString() // << " to " << end_bday.toString() << ": " << business_days << std::endl; .. _example-top_level-endofyear-1170: .. dropdown:: endOfYear (np_test_1_all.cpp:28731) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 28721 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void np_test_datetime_year_boundaries() { std::cout << "========= startOfYear/endOfYear: year boundary dates ======================="; auto dt = numpy::datetime64("2024-06-15"); auto start = numpy::datetime_utils::startOfYear(dt); auto end = numpy::datetime_utils::endOfYear(dt); // Verify both return valid datetime64 objects bool passed = (!start.isNaT() && !end.isNaT()); if (!passed) { std::cout << " [FAIL] : in np_test_datetime_year_boundaries() : Year boundary calculation failed"; throw std::runtime_error("np_test_datetime_year_boundaries failed"); } std::cout << " -> tests passed" << std::endl; .. _example-top_level-endswith-1171: .. dropdown:: endswith (np_test_1_all.cpp:6552) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6542 :emphasize-lines: 11 // Test startswith auto starts_result = startswith(arr, "Hello"); // std::cout << "startswith 'Hello': "; for (size_t i = 0; i < starts_result.getSize(); ++i) { // std::cout << starts_result.getElementAt({i}) << " "; } // std::cout << std::endl; // Test endswith auto ends_result = endswith(arr, "fun"); // std::cout << "endswith 'fun': "; for (size_t i = 0; i < ends_result.getSize(); ++i) { // std::cout << ends_result.getElementAt({i}) << " "; } // std::cout << std::endl; // Test find auto find_result = find(arr, "o"); // std::cout << "find 'o' positions: "; for (size_t i = 0; i < find_result.getSize(); ++i) { .. _example-top_level-fabs-1172: .. dropdown:: fabs (np_test_3_all.cpp:16937) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16927 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void np_test_missing_math_functions_fabs() { std::cout << "========= fabs: floating-point absolute value ======================="; // explicit namespace to avoid name clashes numpy::NDArray a = numpy::arange(-3.0, 3.0, 1.0); numpy::NDArray result = numpy::fabs(a); // Verify values: [-3,-2,-1,0,1,2] -> [3,2,1,0,1,2] auto pass = true; double expected[] = { 3.0, 2.0, 1.0, 0.0, 1.0, 2.0 }; for (size_t i = 0; i < 6 && pass; ++i) { double val = result.getElementAt({ i }); double exp = expected[i]; if (std::abs(val - exp) > 1e-10) { pass = false; } .. _example-top_level-file_exists-1173: .. dropdown:: file_exists (np_test_2_all.cpp:11044) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11034 :emphasize-lines: 11 void testFileUtilities() { std::cout << "========= testFileUtilities ===="; ensure_temp_directory(); // Create a test file auto test_array = createFloat32Array({ 5, 3 }, 1.5f); save(test_array, TEMP_DIR + "test_utilities.npy"); // Test file existence if (!(file_exists(TEMP_DIR + "test_utilities.npy"))) { std::string description = std::string("testFileUtilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(file_exists(TEMP_DIR + \"test_utilities.npy\"))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!file_exists(TEMP_DIR + "nonexistent_file.npy"))) { std::string description = std::string("testFileUtilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!file_exists(TEMP_DIR + \"nonexistent_file.npy\"))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] file_exists works correctly\n"; .. _example-top_level-fill-1174: .. dropdown:: fill (np_test_4_all.cpp:20047) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20037 :emphasize-lines: 11 } // namespace numpy_tests /** * @file np_test_phase6.cpp * @brief Test suite for Phase 6A - HIGH PRIORITY NDArray methods and masked array utilities * * Tests: * - ndarray.nonzero() - Return indices of non-zero elements * - ndarray.tobytes() - Convert to bytes representation * - ndarray.tolist() - Convert to nested list string * - ndarray.fill() - Fill with scalar value (in-place) * - ndarray.item() - Get single element as scalar * - ndarray.itemset() - Set single element value * - ma.masked_all_like() - Create masked array with all elements masked * * Created: 2025-10-28 * Status: Phase 6A Implementation - HIGH PRIORITY functions */ #include "../numpy/np_ndarray.h" #include "../numpy/np_masked_array.h" .. _example-top_level-fill_diagonal-1175: .. dropdown:: fill_diagonal (np_test_5_all.cpp:11622) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11612 :emphasize-lines: 11 #include "../numpy/np_indexing_diagonal.h" #include "../numpy/np_factory.h" #include "../numpy/np_array_manipulation.h" #include #include namespace numpy_tests { namespace numpy_tests_fill_diagonal { void test_square_matrix() { std::cout << " Testing fill_diagonal() - Square matrix..."; auto arr = numpy::NDArray::createZeros({ 3, 3 }); numpy::fill_diagonal(arr, 99); for (size_t i = 0; i < 3; ++i) { if (arr.getElementAt({ i, i }) != 99) { std::cout << " FAIL" << std::endl; throw std::runtime_error("fill_diagonal square: wrong value"); } } std::cout << " PASS" << std::endl; .. _example-top_level-fill_diagonal-1176: .. dropdown:: fill_diagonal (np_test_5_all.cpp:11622) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11612 :emphasize-lines: 11 #include "../numpy/np_indexing_diagonal.h" #include "../numpy/np_factory.h" #include "../numpy/np_array_manipulation.h" #include #include namespace numpy_tests { namespace numpy_tests_fill_diagonal { void test_square_matrix() { std::cout << " Testing fill_diagonal() - Square matrix..."; auto arr = numpy::NDArray::createZeros({ 3, 3 }); numpy::fill_diagonal(arr, 99); for (size_t i = 0; i < 3; ++i) { if (arr.getElementAt({ i, i }) != 99) { std::cout << " FAIL" << std::endl; throw std::runtime_error("fill_diagonal square: wrong value"); } } std::cout << " PASS" << std::endl; .. _example-top_level-find_common_type-1177: .. dropdown:: find_common_type (np_test_3_all.cpp:7264) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7254 :emphasize-lines: 11 } //============================================================================== // FIND_COMMON_TYPE TESTS //============================================================================== void np_test_find_common_type_basic() { std::cout << "========= np_test_find_common_type_basic ======================="; // Only arrays if (find_common_type({DType::INT32, DType::FLOAT32}, {}) != DType::FLOAT64) { std::cerr << "[FAIL] find_common_type({INT32, FLOAT32}, {}) should be FLOAT64"; throw std::runtime_error("find_common_type test failed"); } // std::cout << "[OK] find_common_type({INT32, FLOAT32}, {}) -> FLOAT64" << std::endl; // Only scalars if (find_common_type({}, {DType::INT32, DType::INT64}) != DType::FLOAT64) { std::cerr << "[FAIL] find_common_type({}, {INT32, INT64}) should be FLOAT64"; throw std::runtime_error("find_common_type test failed"); } .. _example-top_level-find_pivot-1178: .. dropdown:: find_pivot (np_test_5_all.cpp:2916) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2906 :emphasize-lines: 11 // ============================================================================ // MATRIX OPERATIONS TESTS // ============================================================================ void np_test_linalg_find_pivot() { std::cout << "========= find_pivot helper ======================="; // Create matrix: [[1, 2], [5, 6], [3, 4]] std::vector matrix = { 1.0, 2.0, 5.0, 6.0, 3.0, 4.0 }; size_t pivot_row = numpy::linalg::utils::find_pivot(matrix.data(), 3, 2, 0, 0); // Largest absolute value in column 0 starting from row 0 is 5 at row 1 bool passed = (pivot_row == 1); if (!passed) { std::cout << " [FAIL] : in np_test_linalg_find_pivot() : pivot row " << pivot_row << " != expected 1"; throw std::runtime_error("np_test_linalg_find_pivot failed: incorrect pivot row"); } // std::cout << " find_pivot: pivot row = " << pivot_row << " (expected 1)" << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-top_level-finfo_float32-1179: .. dropdown:: finfo_float32 (np_test_3_all.cpp:7576) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7566 :emphasize-lines: 11 using namespace numpy; // ============================================================================ // FInfo Tests - Floating-point type information // ============================================================================ void np_test_finfo_float32() { std::cout << "========= np_test_finfo_float32 ======================="; auto info = finfo_float32(); // Test bits if (info.bits != 32) { std::cerr << "[FAIL] FInfo::bits should be 32, got " << info.bits; throw std::runtime_error("FInfo float32 bits test failed"); } // std::cout << "[OK] FInfo::bits = 32" << std::endl; // Test epsilon float expected_eps = std::numeric_limits::epsilon(); .. _example-top_level-finfo_float64-1180: .. dropdown:: finfo_float64 (np_test_3_all.cpp:7624) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7614 :emphasize-lines: 11 throw std::runtime_error("FInfo float32 precision test failed"); } // std::cout << "[OK] FInfo::precision = " << info.precision << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_finfo_float64() { std::cout << "========= np_test_finfo_float64 ======================="; auto info = finfo_float64(); // Test bits if (info.bits != 64) { std::cerr << "[FAIL] FInfo::bits should be 64, got " << info.bits; throw std::runtime_error("FInfo float64 bits test failed"); } // std::cout << "[OK] FInfo::bits = 64" << std::endl; // Test epsilon double expected_eps = std::numeric_limits::epsilon(); .. _example-top_level-finfo_longdouble-1181: .. dropdown:: finfo_longdouble (np_test_3_all.cpp:7672) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7662 :emphasize-lines: 11 throw std::runtime_error("FInfo float64 precision test failed"); } // std::cout << "[OK] FInfo::precision = " << info.precision << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_finfo_longdouble() { std::cout << "========= np_test_finfo_longdouble ======================="; auto info = finfo_longdouble(); // Test bits (long double is at least 64 bits, often 80 or 128) int expected_bits = sizeof(long double) * 8; if (info.bits != expected_bits) { std::cerr << "[FAIL] FInfo::bits should be " << expected_bits << ", got " << info.bits << std::endl; throw std::runtime_error("FInfo longdouble bits test failed"); } // std::cout << "[OK] FInfo::bits = " << info.bits << std::endl; .. _example-top_level-flags-1182: .. dropdown:: flags (np_test_2_all.cpp:3554) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3544 :emphasize-lines: 11 } // Test nbytes if (!(nbytes(arr) == 24 * sizeof(double))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(nbytes(arr) == 24 * sizeof(double))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test flags auto flags_info = flags(arr); if (!(flags_info.owndata == true)) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(flags_info.owndata == true)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(flags_info.writeable == true)) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(flags_info.writeable == true)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-flat-1183: .. dropdown:: flat (np_test_5_all.cpp:11172) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11162 :emphasize-lines: 11 // ============================================================================ // NDITER TESTS // ============================================================================ void np_test_nditer_basic() { std::cout << "========= NDIter: basic C-order iteration ======================="; // Create 2D array numpy::NDArray arr({ 3, 4 }); for (size_t i = 0; i < 12; ++i) { arr.flat(i) = static_cast(i); } // Test C-order iteration auto it = numpy::nditer(arr, true); int count = 0; while (!it.is_finished()) { int value = *it; auto indices = it.indices(); size_t flat_idx = it.flat_index(); .. _example-top_level-flat-1184: .. dropdown:: flat (np_test_5_all.cpp:11172) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11162 :emphasize-lines: 11 // ============================================================================ // NDITER TESTS // ============================================================================ void np_test_nditer_basic() { std::cout << "========= NDIter: basic C-order iteration ======================="; // Create 2D array numpy::NDArray arr({ 3, 4 }); for (size_t i = 0; i < 12; ++i) { arr.flat(i) = static_cast(i); } // Test C-order iteration auto it = numpy::nditer(arr, true); int count = 0; while (!it.is_finished()) { int value = *it; auto indices = it.indices(); size_t flat_idx = it.flat_index(); .. _example-top_level-flatnotmasked_contiguous-1185: .. dropdown:: flatnotmasked_contiguous (np_test_5_all.cpp:4824) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4814 :emphasize-lines: 11 // Create array with some masked values: [1, X, X, 4, 5, X, 7, 8] numpy::NDArray arr({ 8 }); for (size_t i = 0; i < 8; ++i) { arr.setElementAt({ i }, static_cast(i + 1)); } numpy::MaskedArray ma(arr); ma.mask_at({ 1 }); // Mask index 1 ma.mask_at({ 2 }); // Mask index 2 ma.mask_at({ 5 }); // Mask index 5 auto contiguous_regions = numpy::flatnotmasked_contiguous(ma); // Expected regions: [0:1], [3:5], [6:8] if (contiguous_regions.size() != 3) { std::cout << " [FAIL] : in np_test_flatnotmasked_contiguous() : Expected 3 regions, got " << contiguous_regions.size(); throw std::runtime_error("Test failed"); } // Test with all masked numpy::NDArray arr2({ 3 }); for (size_t i = 0; i < 3; ++i) { .. _example-top_level-float_power-1186: .. dropdown:: float_power (np_test_3_all.cpp:17081) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17071 :emphasize-lines: 11 // TYPE-PROMOTED OPERATIONS TESTS // ============================================================================ void np_test_missing_math_functions_float_power() { std::cout << "========= float_power: power with float promotion ======================="; // explicit namespace to avoid name clashes numpy::NDArray base = numpy::arange(1.0, 5.0, 1.0); numpy::NDArray exponent = numpy::arange(2.0, 6.0, 1.0); auto result = numpy::float_power(base, exponent); // Verify values: [1,2,3,4] ** [2,3,4,5] = [1,8,81,1024] auto pass = true; double expected[] = { 1.0, 8.0, 81.0, 1024.0 }; for (size_t i = 0; i < 4 && pass; ++i) { double val = result.getElementAt({ i }); double exp = expected[i]; if (std::abs(val - exp) > 1e-8) { pass = false; } .. _example-top_level-float_power-1187: .. dropdown:: float_power (np_test_3_all.cpp:17081) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17071 :emphasize-lines: 11 // TYPE-PROMOTED OPERATIONS TESTS // ============================================================================ void np_test_missing_math_functions_float_power() { std::cout << "========= float_power: power with float promotion ======================="; // explicit namespace to avoid name clashes numpy::NDArray base = numpy::arange(1.0, 5.0, 1.0); numpy::NDArray exponent = numpy::arange(2.0, 6.0, 1.0); auto result = numpy::float_power(base, exponent); // Verify values: [1,2,3,4] ** [2,3,4,5] = [1,8,81,1024] auto pass = true; double expected[] = { 1.0, 8.0, 81.0, 1024.0 }; for (size_t i = 0; i < 4 && pass; ++i) { double val = result.getElementAt({ i }); double exp = expected[i]; if (std::abs(val - exp) > 1e-8) { pass = false; } .. _example-top_level-fmax-1188: .. dropdown:: fmax (np_test_3_all.cpp:19282) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19272 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmax results match std::fmax\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmax-1189: .. dropdown:: fmax (np_test_3_all.cpp:19282) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19272 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmax results match std::fmax\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmax-1190: .. dropdown:: fmax (np_test_3_all.cpp:19282) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19272 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmax results match std::fmax\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmax-1191: .. dropdown:: fmax (np_test_3_all.cpp:19282) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19272 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmax results match std::fmax\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmax-1192: .. dropdown:: fmax (np_test_3_all.cpp:19282) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19272 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmax results match std::fmax\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmax-1193: .. dropdown:: fmax (np_test_3_all.cpp:19282) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19272 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmax results match std::fmax\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmax-1194: .. dropdown:: fmax (np_test_3_all.cpp:19282) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19272 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmax results match std::fmax\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmax-1195: .. dropdown:: fmax (np_test_3_all.cpp:19282) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19272 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmax results match std::fmax\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmax-1196: .. dropdown:: fmax (np_test_3_all.cpp:19282) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19272 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmax results match std::fmax\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmax-1197: .. dropdown:: fmax (np_test_3_all.cpp:19282) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19272 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmax results match std::fmax\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmax-1198: .. dropdown:: fmax (np_test_3_all.cpp:19282) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19272 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmax results match std::fmax\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmax-1199: .. dropdown:: fmax (np_test_3_all.cpp:19282) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19272 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmax results match std::fmax\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmax-1200: .. dropdown:: fmax (np_test_3_all.cpp:19282) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19272 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmax results match std::fmax\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmax-1201: .. dropdown:: fmax (np_test_3_all.cpp:19282) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19272 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmax results match std::fmax\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmax-1202: .. dropdown:: fmax (np_test_3_all.cpp:19282) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19272 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmax results match std::fmax\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmin-1203: .. dropdown:: fmin (np_test_3_all.cpp:19312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19302 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmin results match std::fmin\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmin-1204: .. dropdown:: fmin (np_test_3_all.cpp:19312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19302 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmin results match std::fmin\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmin-1205: .. dropdown:: fmin (np_test_3_all.cpp:19312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19302 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmin results match std::fmin\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmin-1206: .. dropdown:: fmin (np_test_3_all.cpp:19312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19302 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmin results match std::fmin\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmin-1207: .. dropdown:: fmin (np_test_3_all.cpp:19312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19302 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmin results match std::fmin\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmin-1208: .. dropdown:: fmin (np_test_3_all.cpp:19312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19302 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmin results match std::fmin\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmin-1209: .. dropdown:: fmin (np_test_3_all.cpp:19312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19302 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmin results match std::fmin\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmin-1210: .. dropdown:: fmin (np_test_3_all.cpp:19312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19302 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmin results match std::fmin\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmin-1211: .. dropdown:: fmin (np_test_3_all.cpp:19312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19302 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmin results match std::fmin\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmin-1212: .. dropdown:: fmin (np_test_3_all.cpp:19312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19302 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmin results match std::fmin\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmin-1213: .. dropdown:: fmin (np_test_3_all.cpp:19312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19302 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmin results match std::fmin\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmin-1214: .. dropdown:: fmin (np_test_3_all.cpp:19312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19302 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmin results match std::fmin\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmin-1215: .. dropdown:: fmin (np_test_3_all.cpp:19312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19302 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmin results match std::fmin\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmin-1216: .. dropdown:: fmin (np_test_3_all.cpp:19312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19302 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmin results match std::fmin\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmin-1217: .. dropdown:: fmin (np_test_3_all.cpp:19312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19302 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: fmin results match std::fmin\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-fmod-1218: .. dropdown:: fmod (np_test_1_all.cpp:21321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21311 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.5); a.setElementAt({ 2 }, 7.5); a.setElementAt({ 3 }, -7.5); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = fmod(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fmod-1219: .. dropdown:: fmod (np_test_1_all.cpp:21321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21311 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.5); a.setElementAt({ 2 }, 7.5); a.setElementAt({ 3 }, -7.5); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = fmod(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fmod-1220: .. dropdown:: fmod (np_test_1_all.cpp:21321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21311 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.5); a.setElementAt({ 2 }, 7.5); a.setElementAt({ 3 }, -7.5); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = fmod(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fmod-1221: .. dropdown:: fmod (np_test_1_all.cpp:21321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21311 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.5); a.setElementAt({ 2 }, 7.5); a.setElementAt({ 3 }, -7.5); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = fmod(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fmod-1222: .. dropdown:: fmod (np_test_1_all.cpp:21321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21311 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.5); a.setElementAt({ 2 }, 7.5); a.setElementAt({ 3 }, -7.5); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = fmod(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fmod-1223: .. dropdown:: fmod (np_test_1_all.cpp:21321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21311 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.5); a.setElementAt({ 2 }, 7.5); a.setElementAt({ 3 }, -7.5); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = fmod(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fmod-1224: .. dropdown:: fmod (np_test_1_all.cpp:21321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21311 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.5); a.setElementAt({ 2 }, 7.5); a.setElementAt({ 3 }, -7.5); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = fmod(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fmod-1225: .. dropdown:: fmod (np_test_1_all.cpp:21321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21311 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.5); a.setElementAt({ 2 }, 7.5); a.setElementAt({ 3 }, -7.5); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = fmod(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fmod-1226: .. dropdown:: fmod (np_test_1_all.cpp:21321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21311 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.5); a.setElementAt({ 2 }, 7.5); a.setElementAt({ 3 }, -7.5); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = fmod(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fmod-1227: .. dropdown:: fmod (np_test_1_all.cpp:21321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21311 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.5); a.setElementAt({ 2 }, 7.5); a.setElementAt({ 3 }, -7.5); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = fmod(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fmod-1228: .. dropdown:: fmod (np_test_1_all.cpp:21321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21311 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.5); a.setElementAt({ 2 }, 7.5); a.setElementAt({ 3 }, -7.5); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = fmod(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fmod-1229: .. dropdown:: fmod (np_test_1_all.cpp:21321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21311 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.5); a.setElementAt({ 2 }, 7.5); a.setElementAt({ 3 }, -7.5); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = fmod(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-fmod-1230: .. dropdown:: fmod (np_test_1_all.cpp:21321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21311 :emphasize-lines: 11 a.setElementAt({ 1 }, -7.5); a.setElementAt({ 2 }, 7.5); a.setElementAt({ 3 }, -7.5); auto b = NDArray({ 4 }); b.setElementAt({ 0 }, 3.0); b.setElementAt({ 1 }, 3.0); b.setElementAt({ 2 }, -3.0); b.setElementAt({ 3 }, -3.0); auto result = fmod(a, b); if (!(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 0 }) - 1.5) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)) { std::string description = std::string("testFmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result.getElementAt({ 1 }) - (-1.5)) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-formatdatetime-1231: .. dropdown:: formatDateTime (np_test_1_all.cpp:28694) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 28684 :emphasize-lines: 11 throw std::runtime_error("np_test_datetime_floor_ceil failed"); } std::cout << " -> tests passed" << std::endl; } void np_test_datetime_formatting() { std::cout << "========= formatDateTime: convert to string ======================="; auto dt = numpy::datetime64("2024-01-15"); std::string formatted = numpy::datetime_utils::formatDateTime(dt); bool passed = (formatted.find("2024") != std::string::npos && formatted.find("01") != std::string::npos && formatted.find("15") != std::string::npos); if (!passed) { std::cout << " [FAIL] : in np_test_datetime_formatting() : Formatted string incorrect: " << formatted; throw std::runtime_error("np_test_datetime_formatting failed"); } .. _example-top_level-format_float_positional-1232: .. dropdown:: format_float_positional (np_test_3_all.cpp:9911) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9901 :emphasize-lines: 11 namespace numpy_io_string { // ============================ // TEST: Float Formatting // ============================ void np_test_io_string_format_float_positional() { std::cout << "========= np_test_io_string_format_float_positional ======================="; // Test basic formatting std::string result = format_float_positional(3.14159265, 2); // std::cout << "3.14159265 with precision 2: " << result << std::endl; if (!(result == "3.14" || result == "3.1")) { std::string description = std::string("np_test_io_string_format_float_positional():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result == \"3.14\" || result == \"3.1\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test special values result = format_float_positional(std::numeric_limits::quiet_NaN()); // std::cout << "NaN: " << result << std::endl; .. _example-top_level-format_float_scientific-1233: .. dropdown:: format_float_scientific (np_test_3_all.cpp:9977) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9967 :emphasize-lines: 11 throw std::runtime_error(description); } std::cout << " -> tests passed" << std::endl; } void np_test_io_string_format_float_scientific() { std::cout << "========= np_test_io_string_format_float_scientific ======================="; // Test basic scientific formatting std::string result = format_float_scientific(1234.5, 2); // std::cout << "1234.5 in scientific (prec 2): " << result << std::endl; if (!(result.find('e') != std::string::npos)) { std::string description = std::string("np_test_io_string_format_float_scientific():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.find('e') != std::string::npos)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test special values result = format_float_scientific(std::numeric_limits::quiet_NaN()); // std::cout << "NaN: " << result << std::endl; .. _example-top_level-format_parser-1234: .. dropdown:: format_parser (np_test_3_all.cpp:8795) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8785 :emphasize-lines: 11 if (info.precision < 10 || info.precision > 20) { std::cerr << "[FAIL] machar().precision should be 10-20, got: " << info.precision; throw std::runtime_error("machar precision test failed"); } // std::cout << "[OK] machar().precision = " << info.precision << std::endl; std::cout << " -> tests passed" << std::endl; } //============================================================================== // Test format_parser() - Parse format strings //============================================================================== void np_test_format_parser_integers() { std::cout << "========= np_test_format_parser_integers ======================="; // Test signed integers if (format_parser("i1") != DType::INT8) { std::cerr << "[FAIL] format_parser('i1') should return INT8"; throw std::runtime_error("format_parser i1 test failed"); } .. _example-top_level-fresnelc-1235: .. dropdown:: fresnelc (np_test_1_all.cpp:10960) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10950 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "[OK] Hyperbolic integrals basic functionality\n"; // Test Fresnel integrals if (!(isApproxEqual(fresnels(0.0), 0.0, 1e-10))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(fresnels(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(fresnelc(0.0), 0.0, 1e-10))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(fresnelc(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } double s_1 = fresnels(1.0); double c_1 = fresnelc(1.0); if (!(!std::isnan(s_1) && std::isfinite(s_1))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(s_1) && std::isfinite(s_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-fresnels-1236: .. dropdown:: fresnels (np_test_1_all.cpp:10955) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10945 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(!std::isnan(chi_1) && std::isfinite(chi_1))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(chi_1) && std::isfinite(chi_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Hyperbolic integrals basic functionality\n"; // Test Fresnel integrals if (!(isApproxEqual(fresnels(0.0), 0.0, 1e-10))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(fresnels(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(fresnelc(0.0), 0.0, 1e-10))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(fresnelc(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-frexp-1237: .. dropdown:: frexp (np_test_4_all.cpp:12821) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12811 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test frexp() scalar + array overloads with type promotion // Unary function: returns (mantissa, exponent) where x = mantissa * 2^exponent namespace numpy_tests { namespace numpy_tests_frexp_scalar { using namespace numpy; void test_frexp_bool() { // bool → float32 auto [mant, exp] = numpy::frexp(true); .. _example-top_level-frexp-1238: .. dropdown:: frexp (np_test_4_all.cpp:12821) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12811 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test frexp() scalar + array overloads with type promotion // Unary function: returns (mantissa, exponent) where x = mantissa * 2^exponent namespace numpy_tests { namespace numpy_tests_frexp_scalar { using namespace numpy; void test_frexp_bool() { // bool → float32 auto [mant, exp] = numpy::frexp(true); .. _example-top_level-frexp-1239: .. dropdown:: frexp (np_test_4_all.cpp:12821) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12811 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test frexp() scalar + array overloads with type promotion // Unary function: returns (mantissa, exponent) where x = mantissa * 2^exponent namespace numpy_tests { namespace numpy_tests_frexp_scalar { using namespace numpy; void test_frexp_bool() { // bool → float32 auto [mant, exp] = numpy::frexp(true); .. _example-top_level-frexp-1240: .. dropdown:: frexp (np_test_4_all.cpp:12821) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12811 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test frexp() scalar + array overloads with type promotion // Unary function: returns (mantissa, exponent) where x = mantissa * 2^exponent namespace numpy_tests { namespace numpy_tests_frexp_scalar { using namespace numpy; void test_frexp_bool() { // bool → float32 auto [mant, exp] = numpy::frexp(true); .. _example-top_level-frexp-1241: .. dropdown:: frexp (np_test_4_all.cpp:12821) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12811 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test frexp() scalar + array overloads with type promotion // Unary function: returns (mantissa, exponent) where x = mantissa * 2^exponent namespace numpy_tests { namespace numpy_tests_frexp_scalar { using namespace numpy; void test_frexp_bool() { // bool → float32 auto [mant, exp] = numpy::frexp(true); .. _example-top_level-frexp-1242: .. dropdown:: frexp (np_test_4_all.cpp:12821) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12811 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test frexp() scalar + array overloads with type promotion // Unary function: returns (mantissa, exponent) where x = mantissa * 2^exponent namespace numpy_tests { namespace numpy_tests_frexp_scalar { using namespace numpy; void test_frexp_bool() { // bool → float32 auto [mant, exp] = numpy::frexp(true); .. _example-top_level-frexp-1243: .. dropdown:: frexp (np_test_4_all.cpp:12821) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12811 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test frexp() scalar + array overloads with type promotion // Unary function: returns (mantissa, exponent) where x = mantissa * 2^exponent namespace numpy_tests { namespace numpy_tests_frexp_scalar { using namespace numpy; void test_frexp_bool() { // bool → float32 auto [mant, exp] = numpy::frexp(true); .. _example-top_level-frexp-1244: .. dropdown:: frexp (np_test_4_all.cpp:12821) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12811 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test frexp() scalar + array overloads with type promotion // Unary function: returns (mantissa, exponent) where x = mantissa * 2^exponent namespace numpy_tests { namespace numpy_tests_frexp_scalar { using namespace numpy; void test_frexp_bool() { // bool → float32 auto [mant, exp] = numpy::frexp(true); .. _example-top_level-frexp-1245: .. dropdown:: frexp (np_test_4_all.cpp:12821) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12811 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test frexp() scalar + array overloads with type promotion // Unary function: returns (mantissa, exponent) where x = mantissa * 2^exponent namespace numpy_tests { namespace numpy_tests_frexp_scalar { using namespace numpy; void test_frexp_bool() { // bool → float32 auto [mant, exp] = numpy::frexp(true); .. _example-top_level-frexp-1246: .. dropdown:: frexp (np_test_4_all.cpp:12821) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12811 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test frexp() scalar + array overloads with type promotion // Unary function: returns (mantissa, exponent) where x = mantissa * 2^exponent namespace numpy_tests { namespace numpy_tests_frexp_scalar { using namespace numpy; void test_frexp_bool() { // bool → float32 auto [mant, exp] = numpy::frexp(true); .. _example-top_level-frexp-1247: .. dropdown:: frexp (np_test_4_all.cpp:12821) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12811 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test frexp() scalar + array overloads with type promotion // Unary function: returns (mantissa, exponent) where x = mantissa * 2^exponent namespace numpy_tests { namespace numpy_tests_frexp_scalar { using namespace numpy; void test_frexp_bool() { // bool → float32 auto [mant, exp] = numpy::frexp(true); .. _example-top_level-fromepochseconds-1248: .. dropdown:: fromEpochSeconds (np_test_1_all.cpp:28776) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 28766 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } // ============================================================================ // DATETIME64 METHODS TESTS // ============================================================================ void np_test_datetime64_epoch_conversion() { std::cout << "========= datetime64 epoch conversion: fromEpochSeconds/toEpochSeconds ======================="; // Test fromEpochSeconds (needs two parameters: seconds and unit) int64_t epoch_seconds = 1704067200; // Jan 1, 2024 00:00:00 UTC auto dt = numpy::datetime64::fromEpochSeconds(epoch_seconds, numpy::DateTimeUnit::Second); // Test toEpochSeconds int64_t converted = dt.toEpochSeconds(); bool passed = (converted == epoch_seconds); if (!passed) { std::cout << " [FAIL] : in np_test_datetime64_epoch_conversion() : Epoch conversion failed"; .. _example-top_level-fromseconds-1249: .. dropdown:: fromSeconds (np_test_1_all.cpp:28819) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 28809 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } // ============================================================================ // TIMEDELTA64 METHODS TESTS // ============================================================================ void np_test_timedelta64_conversions() { std::cout << "========= timedelta64 conversions: fromSeconds/toSeconds/toDays ======================="; // Test fromSeconds (needs two parameters: seconds and unit) int64_t seconds = 86400; // 1 day auto td = numpy::timedelta64::fromSeconds(seconds, numpy::DateTimeUnit::Second); // Test toSeconds int64_t converted_seconds = td.toSeconds(); // Test toDays (returns int64_t) int64_t days = td.toDays(); bool passed = (converted_seconds == seconds && days == 1); .. _example-top_level-fromarrays-1250: .. dropdown:: fromarrays (np_test_1_all.cpp:21655) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21645 :emphasize-lines: 11 ids.setElementAt({ 2 }, 300); NDArray scores({ 3 }); scores.setElementAt({ 0 }, 85.5); scores.setElementAt({ 1 }, 92.3); scores.setElementAt({ 2 }, 78.9); std::vector>> int_arrays = { {"id", ids} }; std::vector>> float_arrays = { {"score", scores} }; auto arr1 = fromarrays(int_arrays); auto arr2 = fromarrays(float_arrays); // std::cout << "Array from int arrays:" << std::endl; //arr1.printArray(); // std::cout << "Array from float arrays:" << std::endl; //arr2.printArray(); auto id_check = arr1.getFieldValue({ 1 }, "id"); auto score_check = arr2.getFieldValue({ 2 }, "score"); .. _example-top_level-frompyfunc-1251: .. dropdown:: frompyfunc (np_test_3_all.cpp:786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 776 :emphasize-lines: 11 * Test suite for np_frompyfunc functionality * Following CLAUDE.md test format requirements */ // Test 1: Basic frompyfunc creation int np_test_frompyfunc_basic() { std::cout << "========= np_test_frompyfunc_basic ======================="; try { auto square = [](double x) { return x * x; }; auto ufunc_square = numpy::frompyfunc(square, 1, 1); numpy::NDArray arr({ 3 }); arr.setElementAt({ 0 }, 2.0); arr.setElementAt({ 1 }, 3.0); arr.setElementAt({ 2 }, 4.0); auto result = ufunc_square(arr); // Convert back to double to check values auto typed_result = numpy::astype(result); .. _example-top_level-frompyfunc-1252: .. dropdown:: frompyfunc (np_test_3_all.cpp:786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 776 :emphasize-lines: 11 * Test suite for np_frompyfunc functionality * Following CLAUDE.md test format requirements */ // Test 1: Basic frompyfunc creation int np_test_frompyfunc_basic() { std::cout << "========= np_test_frompyfunc_basic ======================="; try { auto square = [](double x) { return x * x; }; auto ufunc_square = numpy::frompyfunc(square, 1, 1); numpy::NDArray arr({ 3 }); arr.setElementAt({ 0 }, 2.0); arr.setElementAt({ 1 }, 3.0); arr.setElementAt({ 2 }, 4.0); auto result = ufunc_square(arr); // Convert back to double to check values auto typed_result = numpy::astype(result); .. _example-top_level-frompyfunc-1253: .. dropdown:: frompyfunc (np_test_3_all.cpp:786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 776 :emphasize-lines: 11 * Test suite for np_frompyfunc functionality * Following CLAUDE.md test format requirements */ // Test 1: Basic frompyfunc creation int np_test_frompyfunc_basic() { std::cout << "========= np_test_frompyfunc_basic ======================="; try { auto square = [](double x) { return x * x; }; auto ufunc_square = numpy::frompyfunc(square, 1, 1); numpy::NDArray arr({ 3 }); arr.setElementAt({ 0 }, 2.0); arr.setElementAt({ 1 }, 3.0); arr.setElementAt({ 2 }, 4.0); auto result = ufunc_square(arr); // Convert back to double to check values auto typed_result = numpy::astype(result); .. _example-top_level-frompyfunc-1254: .. dropdown:: frompyfunc (np_test_3_all.cpp:786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 776 :emphasize-lines: 11 * Test suite for np_frompyfunc functionality * Following CLAUDE.md test format requirements */ // Test 1: Basic frompyfunc creation int np_test_frompyfunc_basic() { std::cout << "========= np_test_frompyfunc_basic ======================="; try { auto square = [](double x) { return x * x; }; auto ufunc_square = numpy::frompyfunc(square, 1, 1); numpy::NDArray arr({ 3 }); arr.setElementAt({ 0 }, 2.0); arr.setElementAt({ 1 }, 3.0); arr.setElementAt({ 2 }, 4.0); auto result = ufunc_square(arr); // Convert back to double to check values auto typed_result = numpy::astype(result); .. _example-top_level-fromrecords-1255: .. dropdown:: fromrecords (np_test_1_all.cpp:21622) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21612 :emphasize-lines: 11 record2.set("value", static_cast(20.7)); record2.set("active", static_cast(false)); records.push_back(record2); StructuredRecord record3; record3.set("id", static_cast(3)); record3.set("value", static_cast(15.3)); record3.set("active", static_cast(true)); records.push_back(record3); auto arr = fromrecords(records); // std::cout << "Array created from records:" << std::endl; //arr.printArray(); auto id_1 = arr.getFieldValue({ 1 }, "id"); auto value_2 = arr.getFieldValue({ 2 }, "value"); auto active_0 = arr.getFieldValue({ 0 }, "active"); // std::cout << "Verification:" << std::endl; // std::cout << "Record 1 ID: " << id_1 << " (expected: 2)" << std::endl; .. _example-top_level-fromrecords-1256: .. dropdown:: fromrecords (np_test_1_all.cpp:21622) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21612 :emphasize-lines: 11 record2.set("value", static_cast(20.7)); record2.set("active", static_cast(false)); records.push_back(record2); StructuredRecord record3; record3.set("id", static_cast(3)); record3.set("value", static_cast(15.3)); record3.set("active", static_cast(true)); records.push_back(record3); auto arr = fromrecords(records); // std::cout << "Array created from records:" << std::endl; //arr.printArray(); auto id_1 = arr.getFieldValue({ 1 }, "id"); auto value_2 = arr.getFieldValue({ 2 }, "value"); auto active_0 = arr.getFieldValue({ 0 }, "active"); // std::cout << "Verification:" << std::endl; // std::cout << "Record 1 ID: " << id_1 << " (expected: 2)" << std::endl; .. _example-top_level-fv-1257: .. dropdown:: fv (np_test_3_all.cpp:1299) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1289 :emphasize-lines: 11 bool isApproxEqual(double a, double b, double tol = TOLERANCE) { return std::abs(a - b) < tol; } void testBasicTVMFunctions() { std::cout << "========= testBasicTVMFunctions ======================="; // Test Future Value // Example: $1000 at 5% for 10 years double fv_result = fv(0.05, 10, 0, -1000); double expected_fv = 1628.89; // 1000 * (1.05)^10 if (!(isApproxEqual(fv_result, expected_fv, 0.01))) { std::string description = std::string("testBasicTVMFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(fv_result, expected_fv, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] fv() calculation: $1000 at 5% for 10 years = $" << fv_result << std::endl; // Test Present Value // Example: What PV is needed to get $1628.89 in 10 years at 5%? .. _example-top_level-fv-1258: .. dropdown:: fv (np_test_3_all.cpp:1299) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1289 :emphasize-lines: 11 bool isApproxEqual(double a, double b, double tol = TOLERANCE) { return std::abs(a - b) < tol; } void testBasicTVMFunctions() { std::cout << "========= testBasicTVMFunctions ======================="; // Test Future Value // Example: $1000 at 5% for 10 years double fv_result = fv(0.05, 10, 0, -1000); double expected_fv = 1628.89; // 1000 * (1.05)^10 if (!(isApproxEqual(fv_result, expected_fv, 0.01))) { std::string description = std::string("testBasicTVMFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(fv_result, expected_fv, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] fv() calculation: $1000 at 5% for 10 years = $" << fv_result << std::endl; // Test Present Value // Example: What PV is needed to get $1628.89 in 10 years at 5%? .. _example-top_level-gcd-1259: .. dropdown:: gcd (np_test_1_all.cpp:27815) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27805 :emphasize-lines: 11 namespace numpy_tests { namespace numpy_tests_phase2_math { using namespace numpy; void test_gcd() { std::cout << "========= gcd: greatest common divisor ======================="; // Scalar tests auto result1 = gcd(12, 18); // std::cout << " gcd(12, 18) = " << result1 << " (expected: 6)" << std::endl; auto result2 = gcd(54, 24); // std::cout << " gcd(54, 24) = " << result2 << " (expected: 6)" << std::endl; // Array tests auto arr1 = array({ 12, 54, 100 }); auto arr2 = array({ 18, 24, 10 }); auto arr_result = gcd(arr1, arr2); .. _example-top_level-gcd-1260: .. dropdown:: gcd (np_test_1_all.cpp:27815) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27805 :emphasize-lines: 11 namespace numpy_tests { namespace numpy_tests_phase2_math { using namespace numpy; void test_gcd() { std::cout << "========= gcd: greatest common divisor ======================="; // Scalar tests auto result1 = gcd(12, 18); // std::cout << " gcd(12, 18) = " << result1 << " (expected: 6)" << std::endl; auto result2 = gcd(54, 24); // std::cout << " gcd(54, 24) = " << result2 << " (expected: 6)" << std::endl; // Array tests auto arr1 = array({ 12, 54, 100 }); auto arr2 = array({ 18, 24, 10 }); auto arr_result = gcd(arr1, arr2); .. _example-top_level-genlaguerre-1261: .. dropdown:: genlaguerre (np_test_1_all.cpp:15962) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15952 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(isApproxEqual(laguerre(2, 1.0), -0.5, 1e-6))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(laguerre(2, 1.0), -0.5, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Laguerre polynomials\n"; // Test generalized Laguerre polynomials if (!(isApproxEqual(genlaguerre(0, 1.0, 1.0), 1.0, 1e-10))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(genlaguerre(0, 1.0, 1.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(genlaguerre(1, 1.0, 1.0), 1.0, 1e-6))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(genlaguerre(1, 1.0, 1.0), 1.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Generalized Laguerre polynomials\n"; .. _example-top_level-gmres-1262: .. dropdown:: gmres (np_test_3_all.cpp:20240) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20230 :emphasize-lines: 11 if (i < n - 1) coo.add_entry(i, i + 1, -0.5); } auto A = coo.to_csr(); numpy::NDArray b({ n }); for (size_t i = 0; i < n; ++i) { b.setElementAt({ i }, 1.0); } auto [x, info] = numpy::sparse::gmres(A, b, static_cast*>(nullptr), 20, 1e-6, 200); if (!info.converged) { std::cout << " [FAIL] : in np_test_sparse_gmres() : GMRES did not converge"; throw std::runtime_error("np_test_sparse_gmres failed"); } std::cout << " -> tests passed" << std::endl; } void np_test_sparse_bicgstab() { .. _example-top_level-gradient-1263: .. dropdown:: gradient (np_test_5_all.cpp:4712) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4702 :emphasize-lines: 11 // Test gradient with 1D array numpy::NDArray arr({5}); arr.setElementAt({0}, 1.0); arr.setElementAt({1}, 2.0); arr.setElementAt({2}, 4.0); arr.setElementAt({3}, 7.0); arr.setElementAt({4}, 11.0); // Specify axis 0 explicitly to avoid ambiguity auto grad = numpy::gradient(arr, 0); // Expected gradient approximately: [1, 1.5, 2.5, 3.5, 4] // First: (2-1) = 1 // Middle: (4-1)/2 = 1.5, (7-2)/2 = 2.5, (11-4)/2 = 3.5 // Last: (11-7) = 4 if (grad.getSize() != arr.getSize()) { std::cout << " [FAIL] : in np_test_gradient_1d() : Gradient size mismatch"; throw std::runtime_error("Test failed"); } .. _example-top_level-gradient-1264: .. dropdown:: gradient (np_test_5_all.cpp:4712) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4702 :emphasize-lines: 11 // Test gradient with 1D array numpy::NDArray arr({5}); arr.setElementAt({0}, 1.0); arr.setElementAt({1}, 2.0); arr.setElementAt({2}, 4.0); arr.setElementAt({3}, 7.0); arr.setElementAt({4}, 11.0); // Specify axis 0 explicitly to avoid ambiguity auto grad = numpy::gradient(arr, 0); // Expected gradient approximately: [1, 1.5, 2.5, 3.5, 4] // First: (2-1) = 1 // Middle: (4-1)/2 = 1.5, (7-2)/2 = 2.5, (11-4)/2 = 3.5 // Last: (11-7) = 4 if (grad.getSize() != arr.getSize()) { std::cout << " [FAIL] : in np_test_gradient_1d() : Gradient size mismatch"; throw std::runtime_error("Test failed"); } .. _example-top_level-hankel-1265: .. dropdown:: hankel (np_test_2_all.cpp:5275) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5265 :emphasize-lines: 11 assert_test(std::abs(toep(1, 0) - 2.0) < 1e-10, "Toeplitz matrix element"); assert_test(std::abs(toep(2, 1) - 2.0) < 1e-10, "Toeplitz matrix element"); } catch (...) { // std::cout << "Toeplitz matrix test failed"; } // Test Hankel matrix std::vector c_hankel = { 1.0, 2.0, 3.0 }; try { auto hankel_mat = numpy::hankel(c_hankel); assert_test(hankel_mat.rows() == 3 && hankel_mat.cols() == 3, "Hankel matrix dimensions"); assert_test(std::abs(hankel_mat(0, 0) - 1.0) < 1e-10, "Hankel matrix element"); assert_test(std::abs(hankel_mat(0, 1) - 2.0) < 1e-10, "Hankel matrix element"); assert_test(std::abs(hankel_mat(1, 1) - 3.0) < 1e-10, "Hankel matrix element"); } catch (...) { // std::cout << "Hankel matrix test failed"; } // Test circulant matrix .. _example-top_level-heaviside-1266: .. dropdown:: heaviside (np_test_2_all.cpp:14857) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14847 :emphasize-lines: 11 numpy::NDArray neg_arr({ 3 }); neg_arr.setElementAt({ 0 }, -2.0); neg_arr.setElementAt({ 1 }, -1.0); neg_arr.setElementAt({ 2 }, -0.5); numpy::NDArray h0_arr({ 3 }); h0_arr.setElementAt({ 0 }, 0.5); h0_arr.setElementAt({ 1 }, 0.5); h0_arr.setElementAt({ 2 }, 0.5); numpy::NDArray result_neg = numpy::heaviside(neg_arr, h0_arr); auto pass = true; // Check negative values -> 0 for (size_t i = 0; i < 3; ++i) { double val = result_neg.getElementAt({ i }); if (std::abs(val - 0.0) > 1e-10) { std::cout << " [FAIL] : heaviside(" << neg_arr.getElementAt({ i }) << ", 0.5) = " << val << ", expected 0.0"; pass = false; .. _example-top_level-hermeval-1267: .. dropdown:: hermeval (np_test_5_all.cpp:20795) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20785 :emphasize-lines: 11 void np_test_hermefit() { std::cout << "========= hermefit: HermiteE (probabilist) polynomial fitting ======================="; std::vector x = {-1.0, 0.0, 1.0}; std::vector y = {1.0, 0.0, 1.0}; auto coeffs = numpy::polynomial::hermite_e::hermefit(x, y, 2); double max_err = 0.0; for (size_t i = 0; i < x.size(); ++i) { double val = numpy::polynomial::hermite_e::hermeval(x[i], coeffs); max_err = std::max(max_err, std::abs(val - y[i])); } if (max_err > 1e-10) { std::cout << " [FAIL] : in np_test_hermefit(): max error " << max_err << " exceeds tolerance" << std::endl; throw std::runtime_error("np_test_hermefit failed: fit error too large"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-hermite-1268: .. dropdown:: hermite (np_test_1_all.cpp:15908) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15898 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(isApproxEqual(chebyu(2, 0.5), 0.0, 1e-6))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(chebyu(2, 0.5), 0.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Chebyshev polynomials (second kind)\n"; // Test Hermite polynomials (physicist's) if (!(isApproxEqual(hermite(0, 1.0), 1.0, 1e-10))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(hermite(0, 1.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(hermite(1, 1.0), 2.0, 1e-10))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(hermite(1, 1.0), 2.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(hermite(2, 1.0), 2.0, 1e-6))) { .. _example-top_level-hermitenorm-1269: .. dropdown:: hermitenorm (np_test_1_all.cpp:15926) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15916 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(isApproxEqual(hermite(2, 1.0), 2.0, 1e-6))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(hermite(2, 1.0), 2.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Hermite polynomials (physicist's)\n"; // Test Hermite polynomials (probabilist's) if (!(isApproxEqual(hermitenorm(0, 1.0), 1.0, 1e-10))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(hermitenorm(0, 1.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(hermitenorm(1, 1.0), 1.0, 1e-10))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(hermitenorm(1, 1.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(hermitenorm(2, 1.0), 0.0, 1e-6))) { .. _example-top_level-hermval-1270: .. dropdown:: hermval (np_test_5_all.cpp:20773) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20763 :emphasize-lines: 11 void np_test_hermfit() { std::cout << "========= hermfit: Hermite (physicist) polynomial fitting ======================="; std::vector x = {-1.0, 0.0, 1.0}; std::vector y = {1.0, 0.0, 1.0}; auto coeffs = numpy::polynomial::hermite::hermfit(x, y, 2); double max_err = 0.0; for (size_t i = 0; i < x.size(); ++i) { double val = numpy::polynomial::hermite::hermval(x[i], coeffs); max_err = std::max(max_err, std::abs(val - y[i])); } if (max_err > 1e-10) { std::cout << " [FAIL] : in np_test_hermfit(): max error " << max_err << " exceeds tolerance" << std::endl; throw std::runtime_error("np_test_hermfit failed: fit error too large"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-hessenberg_reduction_complex-1271: .. dropdown:: hessenberg_reduction_complex (np_test_3_all.cpp:5142) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5132 :emphasize-lines: 11 matrix.setElementAt({ 2, 2 }, complex128(2, 2)); matrix.setElementAt({ 2, 3 }, complex128(-1, 1)); matrix.setElementAt({ 3, 0 }, complex128(-1, 1)); matrix.setElementAt({ 3, 1 }, complex128(1, 0)); matrix.setElementAt({ 3, 2 }, complex128(0, -1)); matrix.setElementAt({ 3, 3 }, complex128(3, 0)); // std::cout << "Original matrix:" << std::endl; //matrix.printArray(); auto hess_result = utils::hessenberg_reduction_complex(matrix); // std::cout << "Hessenberg form (H):" << std::endl; //hess_result.H.printArray(); // std::cout << "Orthogonal matrix (Q):" << std::endl; //hess_result.Q.printArray(); // std::cout << "Is upper Hessenberg: " << (hess_result.is_upper_hessenberg ? "Yes" : "No") << std::endl; // Verify Q*H*Q^H = A .. _example-top_level-hyp0f1-1272: .. dropdown:: hyp0f1 (np_test_1_all.cpp:11040) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11030 :emphasize-lines: 11 // std::cout << "[OK] Dilogarithm (Spence function) basic values\n"; std::cout << " -> tests passed\n"; } void testHypergeometricFunctions() { std::cout << "========= testHypergeometricFunctions ===="; // Test 0F1 function // 0F1(a; 0) = 1 if (!(isApproxEqual(hyp0f1(1.0, 0.0), 1.0, 1e-10))) { std::string description = std::string("testHypergeometricFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(hyp0f1(1.0, 0.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } double hyp0f1_result = hyp0f1(1.5, 0.5); if (!(!std::isnan(hyp0f1_result) && std::isfinite(hyp0f1_result))) { std::string description = std::string("testHypergeometricFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(hyp0f1_result) && std::isfinite(hyp0f1_result))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-hyp1f1-1273: .. dropdown:: hyp1f1 (np_test_1_all.cpp:11056) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11046 :emphasize-lines: 11 double hyp0f1_result = hyp0f1(1.5, 0.5); if (!(!std::isnan(hyp0f1_result) && std::isfinite(hyp0f1_result))) { std::string description = std::string("testHypergeometricFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(hyp0f1_result) && std::isfinite(hyp0f1_result))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Hypergeometric 0F1 function basic functionality\n"; // Test 1F1 function (Kummer) // 1F1(a, b; 0) = 1 if (!(isApproxEqual(hyp1f1(1.0, 2.0, 0.0), 1.0, 1e-10))) { std::string description = std::string("testHypergeometricFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(hyp1f1(1.0, 2.0, 0.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } double hyp1f1_result = hyp1f1(1.0, 2.0, 0.5); if (!(!std::isnan(hyp1f1_result) && std::isfinite(hyp1f1_result))) { std::string description = std::string("testHypergeometricFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(hyp1f1_result) && std::isfinite(hyp1f1_result))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-hyp2f1-1274: .. dropdown:: hyp2f1 (np_test_1_all.cpp:11072) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11062 :emphasize-lines: 11 double hyp1f1_result = hyp1f1(1.0, 2.0, 0.5); if (!(!std::isnan(hyp1f1_result) && std::isfinite(hyp1f1_result))) { std::string description = std::string("testHypergeometricFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(hyp1f1_result) && std::isfinite(hyp1f1_result))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Hypergeometric 1F1 function basic functionality\n"; // Test 2F1 function (Gauss) // 2F1(a, b, c; 0) = 1 if (!(isApproxEqual(hyp2f1(1.0, 2.0, 3.0, 0.0), 1.0, 1e-10))) { std::string description = std::string("testHypergeometricFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(hyp2f1(1.0, 2.0, 3.0, 0.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } double hyp2f1_result = hyp2f1(0.5, 1.0, 1.5, 0.3); if (!(!std::isnan(hyp2f1_result) && std::isfinite(hyp2f1_result))) { std::string description = std::string("testHypergeometricFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(hyp2f1_result) && std::isfinite(hyp2f1_result))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-ids-1275: .. dropdown:: ids (np_test_1_all.cpp:21642) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21632 :emphasize-lines: 11 // std::cout << "Record 1 ID: " << id_1 << " (expected: 2)" << std::endl; // std::cout << "Record 2 value: " << value_2 << " (expected: 15.3)" << std::endl; // std::cout << "Record 0 active: " << (active_0 ? "true" : "false") << " (expected: true)" << std::endl; std::cout << " -> tests passed" << std::endl; } void testFromArrays() { std::cout << "========= testFromArrays ======================="; NDArray ids({ 3 }); ids.setElementAt({ 0 }, 100); ids.setElementAt({ 1 }, 200); ids.setElementAt({ 2 }, 300); NDArray scores({ 3 }); scores.setElementAt({ 0 }, 85.5); scores.setElementAt({ 1 }, 92.3); scores.setElementAt({ 2 }, 78.9); std::vector>> int_arrays = { {"id", ids} }; .. _example-top_level-ids-1276: .. dropdown:: ids (np_test_1_all.cpp:21642) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21632 :emphasize-lines: 11 // std::cout << "Record 1 ID: " << id_1 << " (expected: 2)" << std::endl; // std::cout << "Record 2 value: " << value_2 << " (expected: 15.3)" << std::endl; // std::cout << "Record 0 active: " << (active_0 ? "true" : "false") << " (expected: true)" << std::endl; std::cout << " -> tests passed" << std::endl; } void testFromArrays() { std::cout << "========= testFromArrays ======================="; NDArray ids({ 3 }); ids.setElementAt({ 0 }, 100); ids.setElementAt({ 1 }, 200); ids.setElementAt({ 2 }, 300); NDArray scores({ 3 }); scores.setElementAt({ 0 }, 85.5); scores.setElementAt({ 1 }, 92.3); scores.setElementAt({ 2 }, 78.9); std::vector>> int_arrays = { {"id", ids} }; .. _example-top_level-idx-1277: .. dropdown:: idx (np_test_2_all.cpp:7377) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7367 :emphasize-lines: 11 throw std::runtime_error(description); } auto [row, col] = to_2d_indices(13, 5); if (!(row == 2 && col == 3)) { std::string description = std::string("test_matrix_operations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(row == 2 && col == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Matrix indexing: (2,3) -> " << idx << " -> (" << row << "," << col << ")" << std::endl; // Test vector operations double vec[3] = { 3.0, 4.0, 0.0 }; double norm = vector_norm_2(vec, 3); if (!(std::abs(norm - 5.0) < 1e-10)) { std::string description = std::string("test_matrix_operations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(norm - 5.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Vector norm [3,4,0]: " << norm << std::endl; .. _example-top_level-idx-1278: .. dropdown:: idx (np_test_2_all.cpp:7377) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7367 :emphasize-lines: 11 throw std::runtime_error(description); } auto [row, col] = to_2d_indices(13, 5); if (!(row == 2 && col == 3)) { std::string description = std::string("test_matrix_operations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(row == 2 && col == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Matrix indexing: (2,3) -> " << idx << " -> (" << row << "," << col << ")" << std::endl; // Test vector operations double vec[3] = { 3.0, 4.0, 0.0 }; double norm = vector_norm_2(vec, 3); if (!(std::abs(norm - 5.0) < 1e-10)) { std::string description = std::string("test_matrix_operations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(norm - 5.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Vector norm [3,4,0]: " << norm << std::endl; .. _example-top_level-idx-1279: .. dropdown:: idx (np_test_2_all.cpp:7377) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7367 :emphasize-lines: 11 throw std::runtime_error(description); } auto [row, col] = to_2d_indices(13, 5); if (!(row == 2 && col == 3)) { std::string description = std::string("test_matrix_operations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(row == 2 && col == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Matrix indexing: (2,3) -> " << idx << " -> (" << row << "," << col << ")" << std::endl; // Test vector operations double vec[3] = { 3.0, 4.0, 0.0 }; double norm = vector_norm_2(vec, 3); if (!(std::abs(norm - 5.0) < 1e-10)) { std::string description = std::string("test_matrix_operations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(norm - 5.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Vector norm [3,4,0]: " << norm << std::endl; .. _example-top_level-iinfo_int16-1280: .. dropdown:: iinfo_int16 (np_test_3_all.cpp:7738) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7728 :emphasize-lines: 11 throw std::runtime_error("IInfo int8 max test failed"); } // std::cout << "[OK] IInfo::max = 127" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_iinfo_int16() { std::cout << "========= np_test_iinfo_int16 ======================="; auto info = iinfo_int16(); // Test bits if (info.bits != 16) { std::cerr << "[FAIL] IInfo::bits should be 16, got " << info.bits; throw std::runtime_error("IInfo int16 bits test failed"); } // std::cout << "[OK] IInfo::bits = 16" << std::endl; // Test min if (info.min != -32768) { .. _example-top_level-iinfo_int32-1281: .. dropdown:: iinfo_int32 (np_test_3_all.cpp:7767) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7757 :emphasize-lines: 11 throw std::runtime_error("IInfo int16 max test failed"); } // std::cout << "[OK] IInfo::max = 32767" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_iinfo_int32() { std::cout << "========= np_test_iinfo_int32 ======================="; auto info = iinfo_int32(); // Test bits if (info.bits != 32) { std::cerr << "[FAIL] IInfo::bits should be 32, got " << info.bits; throw std::runtime_error("IInfo int32 bits test failed"); } // std::cout << "[OK] IInfo::bits = 32" << std::endl; // Test min if (info.min != -2147483648) { .. _example-top_level-iinfo_int64-1282: .. dropdown:: iinfo_int64 (np_test_3_all.cpp:7796) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7786 :emphasize-lines: 11 throw std::runtime_error("IInfo int32 max test failed"); } // std::cout << "[OK] IInfo::max = 2147483647" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_iinfo_int64() { std::cout << "========= np_test_iinfo_int64 ======================="; auto info = iinfo_int64(); // Test bits if (info.bits != 64) { std::cerr << "[FAIL] IInfo::bits should be 64, got " << info.bits; throw std::runtime_error("IInfo int64 bits test failed"); } // std::cout << "[OK] IInfo::bits = 64" << std::endl; // Test min (use hex to avoid overflow in literals) int64_t expected_min = std::numeric_limits::min(); .. _example-top_level-iinfo_int8-1283: .. dropdown:: iinfo_int8 (np_test_3_all.cpp:7709) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7699 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } // ============================================================================ // IInfo Tests - Integer type information // ============================================================================ void np_test_iinfo_int8() { std::cout << "========= np_test_iinfo_int8 ======================="; auto info = iinfo_int8(); // Test bits if (info.bits != 8) { std::cerr << "[FAIL] IInfo::bits should be 8, got " << info.bits; throw std::runtime_error("IInfo int8 bits test failed"); } // std::cout << "[OK] IInfo::bits = 8" << std::endl; // Test min if (info.min != -128) { .. _example-top_level-iinfo_uint16-1284: .. dropdown:: iinfo_uint16 (np_test_3_all.cpp:7856) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7846 :emphasize-lines: 11 throw std::runtime_error("IInfo uint8 max test failed"); } // std::cout << "[OK] IInfo::max = 255" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_iinfo_uint16() { std::cout << "========= np_test_iinfo_uint16 ======================="; auto info = iinfo_uint16(); // Test bits if (info.bits != 16) { std::cerr << "[FAIL] IInfo::bits should be 16, got " << info.bits; throw std::runtime_error("IInfo uint16 bits test failed"); } // std::cout << "[OK] IInfo::bits = 16" << std::endl; // Test min if (info.min != 0) { .. _example-top_level-iinfo_uint32-1285: .. dropdown:: iinfo_uint32 (np_test_3_all.cpp:7885) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7875 :emphasize-lines: 11 throw std::runtime_error("IInfo uint16 max test failed"); } // std::cout << "[OK] IInfo::max = 65535" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_iinfo_uint32() { std::cout << "========= np_test_iinfo_uint32 ======================="; auto info = iinfo_uint32(); // Test bits if (info.bits != 32) { std::cerr << "[FAIL] IInfo::bits should be 32, got " << info.bits; throw std::runtime_error("IInfo uint32 bits test failed"); } // std::cout << "[OK] IInfo::bits = 32" << std::endl; // Test min if (info.min != 0) { .. _example-top_level-iinfo_uint64-1286: .. dropdown:: iinfo_uint64 (np_test_3_all.cpp:7914) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7904 :emphasize-lines: 11 throw std::runtime_error("IInfo uint32 max test failed"); } // std::cout << "[OK] IInfo::max = 4294967295" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_iinfo_uint64() { std::cout << "========= np_test_iinfo_uint64 ======================="; auto info = iinfo_uint64(); // Test bits if (info.bits != 64) { std::cerr << "[FAIL] IInfo::bits should be 64, got " << info.bits; throw std::runtime_error("IInfo uint64 bits test failed"); } // std::cout << "[OK] IInfo::bits = 64" << std::endl; // Test min if (info.min != 0) { .. _example-top_level-iinfo_uint8-1287: .. dropdown:: iinfo_uint8 (np_test_3_all.cpp:7827) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7817 :emphasize-lines: 11 throw std::runtime_error("IInfo int64 max test failed"); } // std::cout << "[OK] IInfo::max = " << info.max << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_iinfo_uint8() { std::cout << "========= np_test_iinfo_uint8 ======================="; auto info = iinfo_uint8(); // Test bits if (info.bits != 8) { std::cerr << "[FAIL] IInfo::bits should be 8, got " << info.bits; throw std::runtime_error("IInfo uint8 bits test failed"); } // std::cout << "[OK] IInfo::bits = 8" << std::endl; // Test min if (info.min != 0) { .. _example-top_level-imag-1288: .. dropdown:: imag (np_test_1_all.cpp:7961) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7951 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void testComplex256FunctionsComplex256() { std::cout << "========= testComplex256FunctionsComplex256 ======================="; complex256 z(3.0L, 4.0L); // 3 + 4i // std::cout << "z = " << z << std::endl; // std::cout << "real(z) = " << z.real() << std::endl; // std::cout << "imag(z) = " << z.imag() << std::endl; // std::cout << "abs(z) = " << std::abs(z) << std::endl; // std::cout << "arg(z) = " << std::arg(z) << " radians" << std::endl; // std::cout << "norm(z) = " << std::norm(z) << std::endl; // std::cout << "conj(z) = " << std::conj(z) << std::endl; // Polar form auto magnitude = std::abs(z); auto phase = std::arg(z); auto polar_z = std::polar(magnitude, phase); // std::cout << "polar form: " << polar_z << std::endl; .. _example-top_level-implicit_qr_algorithm-1289: .. dropdown:: implicit_qr_algorithm (np_test_3_all.cpp:5498) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5488 :emphasize-lines: 11 A.setElementAt({ 2, 2 }, std::complex(1.0, 0.6)); A.setElementAt({ 2, 3 }, std::complex(0.3, 0.2)); A.setElementAt({ 3, 0 }, std::complex(0.1, 0.05)); A.setElementAt({ 3, 1 }, std::complex(0.2, 0.1)); A.setElementAt({ 3, 2 }, std::complex(0.15, 0.1)); A.setElementAt({ 3, 3 }, std::complex(0.8, 0.4)); // Test implicit QR algorithm try { auto implicit_result = numpy::linalg::utils::implicit_qr_algorithm(A, 1e-12); // std::cout << "Implicit QR eigenvalues:" << std::endl; for (size_t i = 0; i < 4; ++i) { auto eigen = implicit_result.eigenvalues.getElementAt({ i }); // std::cout << " ?" << i << " = " << eigen.real() << " + " << eigen.imag() << "i"; } // Test basic properties // 1. Verify Q is orthogonal: Q * Q^H = I auto Qt_conjugate = implicit_result.Q.transposeArray(); for (size_t i = 0; i < 4; ++i) { .. _example-top_level-incrementindices-1290: .. dropdown:: incrementIndices (np_test_1_all.cpp:52) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 42 :emphasize-lines: 11 // Helper functions for array comparison tests namespace { const double TOLERANCE = 1e-10; bool allTrue(const NDArray& arr) { std::vector indices(arr.getShape().size(), 0); do { if (!arr.getElementAt(indices)) { return false; } } while (incrementIndices(indices, arr.getShape())); return true; } bool allFalse(const NDArray& arr) { std::vector indices(arr.getShape().size(), 0); do { if (arr.getElementAt(indices)) { return false; } } while (incrementIndices(indices, arr.getShape())); .. _example-top_level-indices-1291: .. dropdown:: indices (np_test_1_all.cpp:47) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 37 :emphasize-lines: 11 using namespace numpy; using namespace numpy::benchmark; using namespace numpy::char_; // Helper functions for array comparison tests namespace { const double TOLERANCE = 1e-10; bool allTrue(const NDArray& arr) { std::vector indices(arr.getShape().size(), 0); do { if (!arr.getElementAt(indices)) { return false; } } while (incrementIndices(indices, arr.getShape())); return true; } bool allFalse(const NDArray& arr) { std::vector indices(arr.getShape().size(), 0); .. _example-top_level-info-1292: .. dropdown:: info (np_test_2_all.cpp:19772) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19762 :emphasize-lines: 11 // ============================================================================ // INFO TESTS (using primitive types to avoid NDArray complexities) // ============================================================================ void np_test_introspection_info() { std::cout << "========= info: display object information ======================="; // Test info on primitive type int x = 42; // std::cout << "Primitive type info:" << std::endl; numpy::introspection::info(x); double y = 3.14; // std::cout << "Double type info:" << std::endl; numpy::introspection::info(y, true); bool passed = true; // Just verify no exceptions if (!passed) { std::cout << " [FAIL] : in np_test_introspection_info() : info test failed"; throw std::runtime_error("np_test_introspection_info failed"); .. _example-top_level-info-1293: .. dropdown:: info (np_test_2_all.cpp:19772) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19762 :emphasize-lines: 11 // ============================================================================ // INFO TESTS (using primitive types to avoid NDArray complexities) // ============================================================================ void np_test_introspection_info() { std::cout << "========= info: display object information ======================="; // Test info on primitive type int x = 42; // std::cout << "Primitive type info:" << std::endl; numpy::introspection::info(x); double y = 3.14; // std::cout << "Double type info:" << std::endl; numpy::introspection::info(y, true); bool passed = true; // Just verify no exceptions if (!passed) { std::cout << " [FAIL] : in np_test_introspection_info() : info test failed"; throw std::runtime_error("np_test_introspection_info failed"); .. _example-top_level-info-1294: .. dropdown:: info (np_test_2_all.cpp:19772) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19762 :emphasize-lines: 11 // ============================================================================ // INFO TESTS (using primitive types to avoid NDArray complexities) // ============================================================================ void np_test_introspection_info() { std::cout << "========= info: display object information ======================="; // Test info on primitive type int x = 42; // std::cout << "Primitive type info:" << std::endl; numpy::introspection::info(x); double y = 3.14; // std::cout << "Double type info:" << std::endl; numpy::introspection::info(y, true); bool passed = true; // Just verify no exceptions if (!passed) { std::cout << " [FAIL] : in np_test_introspection_info() : info test failed"; throw std::runtime_error("np_test_introspection_info failed"); .. _example-top_level-interp-1295: .. dropdown:: interp (np_test_4_all.cpp:19121) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19111 :emphasize-lines: 11 return 0; } } // namespace numpy_tests /** * Phase 4 Tests: Numerical Methods & Signal Processing * * Tests for: * - np.interp() - 1D linear interpolation * - np.trapz() - Trapezoidal numerical integration * - np.convolve() - Discrete convolution (direct + FFT) * - np.correlate() - Cross-correlation (direct + FFT) * * Following TESTING_CPP.md format */ #include "../numpy/np_numerical.h" #include "../numpy/np_signal.h" #include .. _example-top_level-introsort-1296: .. dropdown:: introsort (np_test_2_all.cpp:9317) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9307 :emphasize-lines: 11 std::vector data(size); std::uniform_int_distribution dist(0, 1000000); for (auto& x : data) { x = dist(gen); } // Test different algorithms std::vector&)>>> algorithms = { {"Standard introsort", [](std::vector& arr) { numpy::introsort(arr.begin(), arr.end()); }}, #if IPP_ENABLED {"IPP-enhanced introsort", [](std::vector& arr) { numpy::ipp_enhanced_introsort(arr.begin(), arr.end()); }}, {"Adaptive sort", [](std::vector& arr) { numpy::adaptive_sort(arr.begin(), arr.end()); }}, #endif {"Standard std::sort", [](std::vector& arr) { .. _example-top_level-introsort-1297: .. dropdown:: introsort (np_test_2_all.cpp:9317) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9307 :emphasize-lines: 11 std::vector data(size); std::uniform_int_distribution dist(0, 1000000); for (auto& x : data) { x = dist(gen); } // Test different algorithms std::vector&)>>> algorithms = { {"Standard introsort", [](std::vector& arr) { numpy::introsort(arr.begin(), arr.end()); }}, #if IPP_ENABLED {"IPP-enhanced introsort", [](std::vector& arr) { numpy::ipp_enhanced_introsort(arr.begin(), arr.end()); }}, {"Adaptive sort", [](std::vector& arr) { numpy::adaptive_sort(arr.begin(), arr.end()); }}, #endif {"Standard std::sort", [](std::vector& arr) { .. _example-top_level-ipmt-1298: .. dropdown:: ipmt (np_test_3_all.cpp:1435) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1425 :emphasize-lines: 11 std::cout << "========= testPaymentComponents ======================="; // Test ipmt and ppmt for a simple loan double rate = 0.06 / 12; // 6% annual, monthly double nper = 12; // 1 year double pv = 10000; // $10,000 loan double total_payment = pmt(rate, nper, pv); // Test first payment breakdown double first_interest = ipmt(rate, 1, nper, pv); double first_principal = ppmt(rate, 1, nper, pv); // Interest + Principal should equal total payment if (!(isApproxEqual(first_interest + first_principal, total_payment, 0.01))) { std::string description = std::string("testPaymentComponents():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(first_interest + first_principal, total_payment, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ipmt() + ppmt() = total payment for period 1" << std::endl; .. _example-top_level-ipmt-1299: .. dropdown:: ipmt (np_test_3_all.cpp:1435) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1425 :emphasize-lines: 11 std::cout << "========= testPaymentComponents ======================="; // Test ipmt and ppmt for a simple loan double rate = 0.06 / 12; // 6% annual, monthly double nper = 12; // 1 year double pv = 10000; // $10,000 loan double total_payment = pmt(rate, nper, pv); // Test first payment breakdown double first_interest = ipmt(rate, 1, nper, pv); double first_principal = ppmt(rate, 1, nper, pv); // Interest + Principal should equal total payment if (!(isApproxEqual(first_interest + first_principal, total_payment, 0.01))) { std::string description = std::string("testPaymentComponents():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(first_interest + first_principal, total_payment, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ipmt() + ppmt() = total payment for period 1" << std::endl; .. _example-top_level-ipp_argsort-1300: .. dropdown:: ipp_argsort (np_test_2_all.cpp:7998) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7988 :emphasize-lines: 11 throw std::runtime_error("IPP uint32 radix sort: EXCEPTION - " + std::string(e.what())); } } // Test argsort { std::vector data = { 3.5f, 1.2f, 4.8f, 2.1f }; std::vector indices(data.size()); try { numpy::ipp::ipp_argsort(data.data(), indices.data(), data.size(), true); // Expected order: 1.2, 2.1, 3.5, 4.8 -> indices: 1, 3, 0, 2 std::vector expected = { 1, 3, 0, 2 }; if (indices != expected) { std::string error_msg = "IPP float argsort: FAILED - Expected: ["; for (size_t i = 0; i < expected.size(); ++i) { if (i > 0) error_msg += ", "; error_msg += std::to_string(expected[i]); } .. _example-top_level-ipp_enhanced_introsort-1301: .. dropdown:: ipp_enhanced_introsort (np_test_2_all.cpp:8143) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8133 :emphasize-lines: 11 for (size_t size : sizes) { std::vector data(size); std::uniform_int_distribution dist(-1000, 1000); for (auto& x : data) { x = dist(gen); } std::vector reference = data; std::sort(reference.begin(), reference.end()); numpy::ipp_enhanced_introsort(data.begin(), data.end()); if (data != reference) { std::cout << " IPP Enhanced Introsort (" << size << " elements): -> [FAIL]"; throw std::runtime_error("IPP Enhanced Introsort (" + std::to_string(size) + " elements): FAILED - array not properly sorted"); } // std::cout << "[OK] IPP Enhanced Introsort (" << size << " elements): PASSED" << std::endl; } // std::cout << std::endl; } .. _example-top_level-ipp_enhanced_introsort-1302: .. dropdown:: ipp_enhanced_introsort (np_test_2_all.cpp:8143) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8133 :emphasize-lines: 11 for (size_t size : sizes) { std::vector data(size); std::uniform_int_distribution dist(-1000, 1000); for (auto& x : data) { x = dist(gen); } std::vector reference = data; std::sort(reference.begin(), reference.end()); numpy::ipp_enhanced_introsort(data.begin(), data.end()); if (data != reference) { std::cout << " IPP Enhanced Introsort (" << size << " elements): -> [FAIL]"; throw std::runtime_error("IPP Enhanced Introsort (" + std::to_string(size) + " elements): FAILED - array not properly sorted"); } // std::cout << "[OK] IPP Enhanced Introsort (" << size << " elements): PASSED" << std::endl; } // std::cout << std::endl; } .. _example-top_level-ipp_radix_sort-1303: .. dropdown:: ipp_radix_sort (np_test_2_all.cpp:7978) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7968 :emphasize-lines: 11 std::vector data(1000); std::uniform_int_distribution dist(0, 10000); for (auto& x : data) { x = dist(gen); } std::vector reference = data; std::sort(reference.begin(), reference.end()); try { numpy::ipp::ipp_radix_sort(data, true); if (data != reference) { std::cout << " IPP uint32 radix sort (1000 elements): -> [FAIL]"; throw std::runtime_error("IPP uint32 radix sort (1000 elements): FAILED - Array not properly sorted"); } // std::cout << "[OK] IPP uint32 radix sort (1000 elements): PASSED" << std::endl; } catch (const numpy::ipp::IPPSortException& e) { std::cout << " IPP uint32 radix sort: -> [FAIL]"; throw std::runtime_error("IPP uint32 radix sort: EXCEPTION - " + std::string(e.what())); .. _example-top_level-ipp_radix_sort-1304: .. dropdown:: ipp_radix_sort (np_test_2_all.cpp:7978) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7968 :emphasize-lines: 11 std::vector data(1000); std::uniform_int_distribution dist(0, 10000); for (auto& x : data) { x = dist(gen); } std::vector reference = data; std::sort(reference.begin(), reference.end()); try { numpy::ipp::ipp_radix_sort(data, true); if (data != reference) { std::cout << " IPP uint32 radix sort (1000 elements): -> [FAIL]"; throw std::runtime_error("IPP uint32 radix sort (1000 elements): FAILED - Array not properly sorted"); } // std::cout << "[OK] IPP uint32 radix sort (1000 elements): PASSED" << std::endl; } catch (const numpy::ipp::IPPSortException& e) { std::cout << " IPP uint32 radix sort: -> [FAIL]"; throw std::runtime_error("IPP uint32 radix sort: EXCEPTION - " + std::string(e.what())); .. _example-top_level-ipp_sort-1305: .. dropdown:: ipp_sort (np_test_2_all.cpp:7952) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7942 :emphasize-lines: 11 // std::cout << "IPP not available, skipping IPP sorting tests"; return; } // Test with different data types { std::vector data = { 5, 2, 8, 1, 9, 3 }; std::vector expected = { 1, 2, 3, 5, 8, 9 }; try { numpy::ipp::ipp_sort(data, true); if (data != expected) { std::cout << " IPP int32 sort: -> [FAIL]"; throw std::runtime_error("IPP int32 sort: FAILED - Array not properly sorted"); } // std::cout << "[OK] IPP int32 sort: PASSED" << std::endl; } catch (const numpy::ipp::IPPSortException& e) { std::cout << " IPP int32 sort: -> [FAIL]"; throw std::runtime_error("IPP int32 sort: EXCEPTION - " + std::string(e.what())); .. _example-top_level-ipp_sort-1306: .. dropdown:: ipp_sort (np_test_2_all.cpp:7952) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7942 :emphasize-lines: 11 // std::cout << "IPP not available, skipping IPP sorting tests"; return; } // Test with different data types { std::vector data = { 5, 2, 8, 1, 9, 3 }; std::vector expected = { 1, 2, 3, 5, 8, 9 }; try { numpy::ipp::ipp_sort(data, true); if (data != expected) { std::cout << " IPP int32 sort: -> [FAIL]"; throw std::runtime_error("IPP int32 sort: FAILED - Array not properly sorted"); } // std::cout << "[OK] IPP int32 sort: PASSED" << std::endl; } catch (const numpy::ipp::IPPSortException& e) { std::cout << " IPP int32 sort: -> [FAIL]"; throw std::runtime_error("IPP int32 sort: EXCEPTION - " + std::string(e.what())); .. _example-top_level-ipp_stable_argsort-1307: .. dropdown:: ipp_stable_argsort (np_test_2_all.cpp:8068) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8058 :emphasize-lines: 11 std::cout << " IPP stable sort (integers): -> [FAIL]"; throw std::runtime_error("IPP stable sort (integers): EXCEPTION - " + std::string(e.what())); } } // Test stable argsort with duplicate values { std::vector data = { 2.5f, 1.0f, 2.5f, 3.0f, 1.0f }; try { auto indices = numpy::ipp::ipp_stable_argsort(data, true); // Check if result is valid argsort bool is_valid_argsort = true; for (size_t i = 1; i < indices.size() && is_valid_argsort; ++i) { if (data[indices[i - 1]] > data[indices[i]]) { is_valid_argsort = false; } // For stable sort, equal elements should maintain original order if (data[indices[i - 1]] == data[indices[i]] && indices[i - 1] > indices[i]) { is_valid_argsort = false; .. _example-top_level-ipp_stable_sort-1308: .. dropdown:: ipp_stable_sort (np_test_2_all.cpp:8048) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8038 :emphasize-lines: 11 // std::cout << "IPP not available, skipping IPP stable sorting tests"; return; } // Test stable sort with duplicate values { std::vector data = { 3, 1, 4, 1, 5, 9, 2, 6, 5 }; std::vector original_data = data; try { numpy::ipp::ipp_stable_sort(data, true); bool is_sorted = std::is_sorted(data.begin(), data.end()); if (!is_sorted) { std::cout << " IPP stable sort (integers): -> [FAIL]"; throw std::runtime_error("IPP stable sort (integers): FAILED - array not properly sorted"); } // std::cout << "[OK] IPP stable sort (integers): PASSED" << std::endl; } catch (const numpy::ipp::IPPSortException& e) { std::cout << " IPP stable sort (integers): -> [FAIL]"; .. _example-top_level-ipp_stable_sort-1309: .. dropdown:: ipp_stable_sort (np_test_2_all.cpp:8048) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8038 :emphasize-lines: 11 // std::cout << "IPP not available, skipping IPP stable sorting tests"; return; } // Test stable sort with duplicate values { std::vector data = { 3, 1, 4, 1, 5, 9, 2, 6, 5 }; std::vector original_data = data; try { numpy::ipp::ipp_stable_sort(data, true); bool is_sorted = std::is_sorted(data.begin(), data.end()); if (!is_sorted) { std::cout << " IPP stable sort (integers): -> [FAIL]"; throw std::runtime_error("IPP stable sort (integers): FAILED - array not properly sorted"); } // std::cout << "[OK] IPP stable sort (integers): PASSED" << std::endl; } catch (const numpy::ipp::IPPSortException& e) { std::cout << " IPP stable sort (integers): -> [FAIL]"; .. _example-top_level-irr-1310: .. dropdown:: irr (np_test_3_all.cpp:1403) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1393 :emphasize-lines: 11 double expected_npv = -1000 + 300 / 1.1 + 300 / 1.21 + 300 / 1.331 + 300 / 1.4641; if (!(isApproxEqual(npv_result, expected_npv, 0.01))) { std::string description = std::string("testCashFlowFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(npv_result, expected_npv, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] npv() calculation: Project NPV at 10% = $" << npv_result << std::endl; // Test IRR // Same cash flows - should give IRR where NPV = 0 double irr_result = irr(cash_flows); double npv_at_irr = npv(irr_result, cash_flows); if (!(isApproxEqual(npv_at_irr, 0.0, 0.01))) { std::string description = std::string("testCashFlowFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(npv_at_irr, 0.0, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] irr() calculation: Project IRR = " << irr_result * 100 << "%" << std::endl; // Test MIRR double mirr_result = mirr(cash_flows, 0.10, 0.12); // 10% finance rate, 12% reinvest rate .. _example-top_level-irr-1311: .. dropdown:: irr (np_test_3_all.cpp:1403) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1393 :emphasize-lines: 11 double expected_npv = -1000 + 300 / 1.1 + 300 / 1.21 + 300 / 1.331 + 300 / 1.4641; if (!(isApproxEqual(npv_result, expected_npv, 0.01))) { std::string description = std::string("testCashFlowFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(npv_result, expected_npv, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] npv() calculation: Project NPV at 10% = $" << npv_result << std::endl; // Test IRR // Same cash flows - should give IRR where NPV = 0 double irr_result = irr(cash_flows); double npv_at_irr = npv(irr_result, cash_flows); if (!(isApproxEqual(npv_at_irr, 0.0, 0.01))) { std::string description = std::string("testCashFlowFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(npv_at_irr, 0.0, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] irr() calculation: Project IRR = " << irr_result * 100 << "%" << std::endl; // Test MIRR double mirr_result = mirr(cash_flows, 0.10, 0.12); // 10% finance rate, 12% reinvest rate .. _example-top_level-isbusinessday-1312: .. dropdown:: isBusinessDay (np_test_1_all.cpp:6952) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6942 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void testDatetimeUtilsDateTime() { std::cout << "========= testDatetimeUtilsDateTime ======================="; datetime64 test_date("2024-03-15"); // Friday // std::cout << "Test date: " << test_date.toString() << std::endl; // std::cout << "Is weekend: " << datetime_utils::isWeekend(test_date) << std::endl; // std::cout << "Is business day: " << datetime_utils::isBusinessDay(test_date) << std::endl; // std::cout << "Weekday: " << datetime_utils::getWeekday(test_date) << std::endl; // std::cout << "Day of year: " << datetime_utils::getDayOfYear(test_date) << std::endl; // Test start/end of periods // std::cout << "Start of week: " << datetime_utils::startOfWeek(test_date).toString() << std::endl; // std::cout << "End of week: " << datetime_utils::endOfWeek(test_date).toString() << std::endl; // std::cout << "Start of month: " << datetime_utils::startOfMonth(test_date).toString() << std::endl; // std::cout << "End of month: " << datetime_utils::endOfMonth(test_date).toString() << std::endl; // Test business day calculations .. _example-top_level-isbusinessday-1313: .. dropdown:: isBusinessDay (np_test_1_all.cpp:6952) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6942 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void testDatetimeUtilsDateTime() { std::cout << "========= testDatetimeUtilsDateTime ======================="; datetime64 test_date("2024-03-15"); // Friday // std::cout << "Test date: " << test_date.toString() << std::endl; // std::cout << "Is weekend: " << datetime_utils::isWeekend(test_date) << std::endl; // std::cout << "Is business day: " << datetime_utils::isBusinessDay(test_date) << std::endl; // std::cout << "Weekday: " << datetime_utils::getWeekday(test_date) << std::endl; // std::cout << "Day of year: " << datetime_utils::getDayOfYear(test_date) << std::endl; // Test start/end of periods // std::cout << "Start of week: " << datetime_utils::startOfWeek(test_date).toString() << std::endl; // std::cout << "End of week: " << datetime_utils::endOfWeek(test_date).toString() << std::endl; // std::cout << "Start of month: " << datetime_utils::startOfMonth(test_date).toString() << std::endl; // std::cout << "End of month: " << datetime_utils::endOfMonth(test_date).toString() << std::endl; // Test business day calculations .. _example-top_level-isbusinessday-1314: .. dropdown:: isBusinessDay (np_test_1_all.cpp:6952) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6942 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void testDatetimeUtilsDateTime() { std::cout << "========= testDatetimeUtilsDateTime ======================="; datetime64 test_date("2024-03-15"); // Friday // std::cout << "Test date: " << test_date.toString() << std::endl; // std::cout << "Is weekend: " << datetime_utils::isWeekend(test_date) << std::endl; // std::cout << "Is business day: " << datetime_utils::isBusinessDay(test_date) << std::endl; // std::cout << "Weekday: " << datetime_utils::getWeekday(test_date) << std::endl; // std::cout << "Day of year: " << datetime_utils::getDayOfYear(test_date) << std::endl; // Test start/end of periods // std::cout << "Start of week: " << datetime_utils::startOfWeek(test_date).toString() << std::endl; // std::cout << "End of week: " << datetime_utils::endOfWeek(test_date).toString() << std::endl; // std::cout << "Start of month: " << datetime_utils::startOfMonth(test_date).toString() << std::endl; // std::cout << "End of month: " << datetime_utils::endOfMonth(test_date).toString() << std::endl; // Test business day calculations .. _example-top_level-isccontiguous-1315: .. dropdown:: isCContiguous (np_test_1_all.cpp:393) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 383 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void testMemoryLayoutQueries() { std::cout << "========= testMemoryLayoutQueries ======================="; auto array = createFloat64Array({2, 3}); // std::cout << "Array contiguous: " << (array.isContiguous() ? "Yes" : "No") << std::endl; // std::cout << "Array C-contiguous: " << (array.isCContiguous() ? "Yes" : "No") << std::endl; // std::cout << "Array F-contiguous: " << (array.isFContiguous() ? "Yes" : "No") << std::endl; // Test with a transposed view auto transposed = array.transposeView(); // std::cout << "Transposed contiguous: " << (transposed.isContiguous() ? "Yes" : "No") << std::endl; // std::cout << "Transposed C-contiguous: " << (transposed.isCContiguous() ? "Yes" : "No") << std::endl; // std::cout << "Transposed F-contiguous: " << (transposed.isFContiguous() ? "Yes" : "No") << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-iscontiguous-1316: .. dropdown:: isContiguous (np_test_1_all.cpp:392) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 382 :emphasize-lines: 11 //array.printArray(); std::cout << " -> tests passed" << std::endl; } void testMemoryLayoutQueries() { std::cout << "========= testMemoryLayoutQueries ======================="; auto array = createFloat64Array({2, 3}); // std::cout << "Array contiguous: " << (array.isContiguous() ? "Yes" : "No") << std::endl; // std::cout << "Array C-contiguous: " << (array.isCContiguous() ? "Yes" : "No") << std::endl; // std::cout << "Array F-contiguous: " << (array.isFContiguous() ? "Yes" : "No") << std::endl; // Test with a transposed view auto transposed = array.transposeView(); // std::cout << "Transposed contiguous: " << (transposed.isContiguous() ? "Yes" : "No") << std::endl; // std::cout << "Transposed C-contiguous: " << (transposed.isCContiguous() ? "Yes" : "No") << std::endl; // std::cout << "Transposed F-contiguous: " << (transposed.isFContiguous() ? "Yes" : "No") << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-top_level-isfcontiguous-1317: .. dropdown:: isFContiguous (np_test_1_all.cpp:394) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 384 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void testMemoryLayoutQueries() { std::cout << "========= testMemoryLayoutQueries ======================="; auto array = createFloat64Array({2, 3}); // std::cout << "Array contiguous: " << (array.isContiguous() ? "Yes" : "No") << std::endl; // std::cout << "Array C-contiguous: " << (array.isCContiguous() ? "Yes" : "No") << std::endl; // std::cout << "Array F-contiguous: " << (array.isFContiguous() ? "Yes" : "No") << std::endl; // Test with a transposed view auto transposed = array.transposeView(); // std::cout << "Transposed contiguous: " << (transposed.isContiguous() ? "Yes" : "No") << std::endl; // std::cout << "Transposed C-contiguous: " << (transposed.isCContiguous() ? "Yes" : "No") << std::endl; // std::cout << "Transposed F-contiguous: " << (transposed.isFContiguous() ? "Yes" : "No") << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-ishomogeneousarrays-1318: .. dropdown:: isHomogeneousArrays (np_test_1_all.cpp:1824) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1814 :emphasize-lines: 11 } } // Test homogeneous array detection std::vector> double_arrays; for (int i = 0; i < 3; ++i) { double_arrays.push_back(NDArray({2}, i * 1.5)); } NDArray homogeneous = createObjectArrayFromNDArrays(double_arrays); if (!(NestedArray::isHomogeneousArrays(homogeneous))) { std::string description = std::string("testObjectArrayOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(NestedArray::isHomogeneousArrays(homogeneous))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test heterogeneous detection NDArray heterogeneous = createMixedObjectArray({ object_(NDArray({2}, 1)), object_(42) }); .. _example-top_level-isleapyear-1319: .. dropdown:: isLeapYear (np_test_1_all.cpp:6975) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6965 :emphasize-lines: 11 int64_t business_days = datetime_utils::businessDayCount(start_bday, end_bday); // std::cout << "Business days from " << start_bday.toString() // << " to " << end_bday.toString() << ": " << business_days << std::endl; datetime64 offset_date = datetime_utils::businessDayOffset(start_bday, 3); // std::cout << "3 business days after " << start_bday.toString() // << ": " << offset_date.toString() << std::endl; // Test leap year // std::cout << "2024 is leap year: " << datetime_utils::isLeapYear(2024) << std::endl; // std::cout << "2023 is leap year: " << datetime_utils::isLeapYear(2023) << std::endl; // std::cout << "Days in February 2024: " << datetime_utils::daysInMonth(2024, 2) << std::endl; std::cout << " -> tests passed" << std::endl; } void testBusinessDateRangeDateTime() { std::cout << "========= testBusinessDateRangeDateTime ======================="; datetime64 start("2024-03-11"); // Monday .. _example-top_level-isleapyear-1320: .. dropdown:: isLeapYear (np_test_1_all.cpp:6975) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6965 :emphasize-lines: 11 int64_t business_days = datetime_utils::businessDayCount(start_bday, end_bday); // std::cout << "Business days from " << start_bday.toString() // << " to " << end_bday.toString() << ": " << business_days << std::endl; datetime64 offset_date = datetime_utils::businessDayOffset(start_bday, 3); // std::cout << "3 business days after " << start_bday.toString() // << ": " << offset_date.toString() << std::endl; // Test leap year // std::cout << "2024 is leap year: " << datetime_utils::isLeapYear(2024) << std::endl; // std::cout << "2023 is leap year: " << datetime_utils::isLeapYear(2023) << std::endl; // std::cout << "Days in February 2024: " << datetime_utils::daysInMonth(2024, 2) << std::endl; std::cout << " -> tests passed" << std::endl; } void testBusinessDateRangeDateTime() { std::cout << "========= testBusinessDateRangeDateTime ======================="; datetime64 start("2024-03-11"); // Monday .. _example-top_level-isma-1321: .. dropdown:: isMA (np_test_1_all.cpp:27619) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27609 :emphasize-lines: 11 // std::cout << " Row 0 (powers of 1): [" << result.data().getElementAt({ 0, 0 }) << ", " // << result.data().getElementAt({ 0, 1 }) << ", " << result.data().getElementAt({ 0, 2 }) << "]"; std::cout << " -> tests passed"; } // ============================================================================ // Phase 3B: Masked Array Utilities (11 functions) // ============================================================================ void test_isMA_isMaskedArray() { std::cout << "========= ma::isMA() and ma::isMaskedArray(): type checking ==="; auto data = numpy::array({ 1.0, 2.0, 3.0 }); auto mask = numpy::array({ false, true, false }); auto ma = numpy::ma::masked_array(data, mask); auto regular_array = numpy::array({ 1.0, 2.0, 3.0 }); // std::cout << " ma::isMA(masked_array): " << (numpy::ma::isMA(ma) ? "true" : "false") << " (expected: true)" << std::endl; // std::cout << " ma::isMA(regular_array): " << (numpy::ma::isMA(regular_array) ? "true" : "false") << " (expected: false)" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-isma-1322: .. dropdown:: isMA (np_test_1_all.cpp:27619) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27609 :emphasize-lines: 11 // std::cout << " Row 0 (powers of 1): [" << result.data().getElementAt({ 0, 0 }) << ", " // << result.data().getElementAt({ 0, 1 }) << ", " << result.data().getElementAt({ 0, 2 }) << "]"; std::cout << " -> tests passed"; } // ============================================================================ // Phase 3B: Masked Array Utilities (11 functions) // ============================================================================ void test_isMA_isMaskedArray() { std::cout << "========= ma::isMA() and ma::isMaskedArray(): type checking ==="; auto data = numpy::array({ 1.0, 2.0, 3.0 }); auto mask = numpy::array({ false, true, false }); auto ma = numpy::ma::masked_array(data, mask); auto regular_array = numpy::array({ 1.0, 2.0, 3.0 }); // std::cout << " ma::isMA(masked_array): " << (numpy::ma::isMA(ma) ? "true" : "false") << " (expected: true)" << std::endl; // std::cout << " ma::isMA(regular_array): " << (numpy::ma::isMA(regular_array) ? "true" : "false") << " (expected: false)" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-ismaskedarray-1323: .. dropdown:: isMaskedArray (np_test_1_all.cpp:27619) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27609 :emphasize-lines: 11 // std::cout << " Row 0 (powers of 1): [" << result.data().getElementAt({ 0, 0 }) << ", " // << result.data().getElementAt({ 0, 1 }) << ", " << result.data().getElementAt({ 0, 2 }) << "]"; std::cout << " -> tests passed"; } // ============================================================================ // Phase 3B: Masked Array Utilities (11 functions) // ============================================================================ void test_isMA_isMaskedArray() { std::cout << "========= ma::isMA() and ma::isMaskedArray(): type checking ==="; auto data = numpy::array({ 1.0, 2.0, 3.0 }); auto mask = numpy::array({ false, true, false }); auto ma = numpy::ma::masked_array(data, mask); auto regular_array = numpy::array({ 1.0, 2.0, 3.0 }); // std::cout << " ma::isMA(masked_array): " << (numpy::ma::isMA(ma) ? "true" : "false") << " (expected: true)" << std::endl; // std::cout << " ma::isMA(regular_array): " << (numpy::ma::isMA(regular_array) ? "true" : "false") << " (expected: false)" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-ismaskedarray-1324: .. dropdown:: isMaskedArray (np_test_1_all.cpp:27619) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27609 :emphasize-lines: 11 // std::cout << " Row 0 (powers of 1): [" << result.data().getElementAt({ 0, 0 }) << ", " // << result.data().getElementAt({ 0, 1 }) << ", " << result.data().getElementAt({ 0, 2 }) << "]"; std::cout << " -> tests passed"; } // ============================================================================ // Phase 3B: Masked Array Utilities (11 functions) // ============================================================================ void test_isMA_isMaskedArray() { std::cout << "========= ma::isMA() and ma::isMaskedArray(): type checking ==="; auto data = numpy::array({ 1.0, 2.0, 3.0 }); auto mask = numpy::array({ false, true, false }); auto ma = numpy::ma::masked_array(data, mask); auto regular_array = numpy::array({ 1.0, 2.0, 3.0 }); // std::cout << " ma::isMA(masked_array): " << (numpy::ma::isMA(ma) ? "true" : "false") << " (expected: true)" << std::endl; // std::cout << " ma::isMA(regular_array): " << (numpy::ma::isMA(regular_array) ? "true" : "false") << " (expected: false)" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-isrectangular-1325: .. dropdown:: isRectangular (np_test_3_all.cpp:21198) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21188 :emphasize-lines: 11 CHECK(jagged.getSize() == 3, "np_test_nested_jagged", "jagged.size != 3"); // Test getRowLengths std::vector lengths = numpy::NestedArray::getRowLengths(jagged); CHECK(lengths.size() == 3, "np_test_nested_jagged", "lengths.size != 3"); CHECK(lengths[0] == 3, "np_test_nested_jagged", "lengths[0] != 3"); CHECK(lengths[1] == 2, "np_test_nested_jagged", "lengths[1] != 2"); CHECK(lengths[2] == 4, "np_test_nested_jagged", "lengths[2] != 4"); // Test isRectangular bool is_rect = numpy::NestedArray::isRectangular(jagged); CHECK(!is_rect, "np_test_nested_jagged", "jagged should not be rectangular"); // Create rectangular array numpy::NDArray rect = numpy::make_jagged_array({ {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }); bool is_rect2 = numpy::NestedArray::isRectangular(rect); CHECK(is_rect2, "np_test_nested_jagged", "rect should be rectangular"); .. _example-top_level-isweekend-1326: .. dropdown:: isWeekend (np_test_1_all.cpp:6951) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6941 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void testDatetimeUtilsDateTime() { std::cout << "========= testDatetimeUtilsDateTime ======================="; datetime64 test_date("2024-03-15"); // Friday // std::cout << "Test date: " << test_date.toString() << std::endl; // std::cout << "Is weekend: " << datetime_utils::isWeekend(test_date) << std::endl; // std::cout << "Is business day: " << datetime_utils::isBusinessDay(test_date) << std::endl; // std::cout << "Weekday: " << datetime_utils::getWeekday(test_date) << std::endl; // std::cout << "Day of year: " << datetime_utils::getDayOfYear(test_date) << std::endl; // Test start/end of periods // std::cout << "Start of week: " << datetime_utils::startOfWeek(test_date).toString() << std::endl; // std::cout << "End of week: " << datetime_utils::endOfWeek(test_date).toString() << std::endl; // std::cout << "Start of month: " << datetime_utils::startOfMonth(test_date).toString() << std::endl; // std::cout << "End of month: " << datetime_utils::endOfMonth(test_date).toString() << std::endl; .. _example-top_level-isalnum-1327: .. dropdown:: isalnum (np_test_5_all.cpp:1210) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1200 :emphasize-lines: 11 // ============================================================================ // CHARACTER CHECKING TESTS // ============================================================================ void np_test_string_isalnum() { std::cout << "========= isalnum character checking ======================="; std::vector strings = { "hello123", "test!", "abc", "123" }; auto arr = numpy::char_::array<32>(strings); auto result = numpy::char_::isalnum(arr); // Verify dimensions match bool passed = (result.getSize() == arr.size()); if (!passed) { std::cout << " [FAIL] : in np_test_string_isalnum() : result size mismatch"; throw std::runtime_error("np_test_string_isalnum failed"); } std::cout << " -> tests passed" << std::endl; .. _example-top_level-isalpha-1328: .. dropdown:: isalpha (np_test_1_all.cpp:6498) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6488 :emphasize-lines: 11 // Test isdigit auto digit_result = isdigit(arr); // std::cout << "isdigit results: "; for (size_t i = 0; i < digit_result.getSize(); ++i) { // std::cout << digit_result.getElementAt({i}) << " "; } // std::cout << std::endl; // Test isalpha auto alpha_result = isalpha(arr); // std::cout << "isalpha results: "; for (size_t i = 0; i < alpha_result.getSize(); ++i) { // std::cout << alpha_result.getElementAt({i}) << " "; } // std::cout << std::endl; // Test islower auto lower_test_result = islower(arr); // std::cout << "islower results: "; for (size_t i = 0; i < lower_test_result.getSize(); ++i) { .. _example-top_level-isarray-1329: .. dropdown:: isarray (np_test_5_all.cpp:3970) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3960 :emphasize-lines: 11 void np_test_isarray() { std::cout << "========= isarray ======================="; // NDArray should be recognized as array numpy::NDArray arr({ 5 }); for (size_t i = 0; i < 5; ++i) { arr.setElementAt({ i }, static_cast(i + 1)); } bool result1 = numpy::isarray(arr); if (!result1) { std::cout << " [FAIL] : in np_test_isarray() : NDArray should be array"; throw std::runtime_error("Test failed"); } // MaskedArray should also be recognized as array numpy::MaskedArray ma(arr); bool result2 = numpy::isarray(ma); .. _example-top_level-isarray-1330: .. dropdown:: isarray (np_test_5_all.cpp:3970) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3960 :emphasize-lines: 11 void np_test_isarray() { std::cout << "========= isarray ======================="; // NDArray should be recognized as array numpy::NDArray arr({ 5 }); for (size_t i = 0; i < 5; ++i) { arr.setElementAt({ i }, static_cast(i + 1)); } bool result1 = numpy::isarray(arr); if (!result1) { std::cout << " [FAIL] : in np_test_isarray() : NDArray should be array"; throw std::runtime_error("Test failed"); } // MaskedArray should also be recognized as array numpy::MaskedArray ma(arr); bool result2 = numpy::isarray(ma); .. _example-top_level-isarray-1331: .. dropdown:: isarray (np_test_5_all.cpp:3970) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3960 :emphasize-lines: 11 void np_test_isarray() { std::cout << "========= isarray ======================="; // NDArray should be recognized as array numpy::NDArray arr({ 5 }); for (size_t i = 0; i < 5; ++i) { arr.setElementAt({ i }, static_cast(i + 1)); } bool result1 = numpy::isarray(arr); if (!result1) { std::cout << " [FAIL] : in np_test_isarray() : NDArray should be array"; throw std::runtime_error("Test failed"); } // MaskedArray should also be recognized as array numpy::MaskedArray ma(arr); bool result2 = numpy::isarray(ma); .. _example-top_level-isdigit-1332: .. dropdown:: isdigit (np_test_1_all.cpp:6490) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6480 :emphasize-lines: 11 std::vector test_strings = {"123", "abc", "ABC", "Hello World", " ", ""}; auto arr = array<32>(test_strings); // std::cout << "Test strings: "; for (size_t i = 0; i < arr.size(); ++i) { // std::cout << "'" << arr[i] << "' "; } // std::cout << std::endl; // Test isdigit auto digit_result = isdigit(arr); // std::cout << "isdigit results: "; for (size_t i = 0; i < digit_result.getSize(); ++i) { // std::cout << digit_result.getElementAt({i}) << " "; } // std::cout << std::endl; // Test isalpha auto alpha_result = isalpha(arr); // std::cout << "isalpha results: "; for (size_t i = 0; i < alpha_result.getSize(); ++i) { .. _example-top_level-isempty-1333: .. dropdown:: isempty (np_test_2_all.cpp:3594) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3584 :emphasize-lines: 11 if (!(!isvector(arr))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!isvector(arr))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!ismatrix(arr))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!ismatrix(arr))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!isempty(arr))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!isempty(arr))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 2D array auto arr2d = createFloat64Array({ 3, 3 }); if (!(ismatrix(arr2d))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ismatrix(arr2d))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-isfortran-1334: .. dropdown:: isfortran (np_test_2_all.cpp:17010) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17000 :emphasize-lines: 11 // ISFORTRAN() TESTS // ============================================================================ void np_test_logic_isfortran_1d() { std::cout << "========= isfortran: 1D array ======================="; // 1D arrays are both C and Fortran contiguous std::vector data = { 1.0, 2.0, 3.0, 4.0, 5.0 }; numpy::NDArray arr = numpy::createArrayFromVector({ 5 }, data); bool result = numpy::isfortran(arr); if (result != true) { std::cout << " [FAIL] : in np_test_logic_isfortran_1d() : 1D arrays should be Fortran contiguous"; throw std::runtime_error("np_test_logic_isfortran_1d failed"); } std::cout << " -> tests passed" << std::endl; } void np_test_logic_isfortran_2d_c_contiguous() { .. _example-top_level-islower-1335: .. dropdown:: islower (np_test_1_all.cpp:6506) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6496 :emphasize-lines: 11 // Test isalpha auto alpha_result = isalpha(arr); // std::cout << "isalpha results: "; for (size_t i = 0; i < alpha_result.getSize(); ++i) { // std::cout << alpha_result.getElementAt({i}) << " "; } // std::cout << std::endl; // Test islower auto lower_test_result = islower(arr); // std::cout << "islower results: "; for (size_t i = 0; i < lower_test_result.getSize(); ++i) { // std::cout << lower_test_result.getElementAt({i}) << " "; } // std::cout << std::endl; // Test isupper auto upper_test_result = isupper(arr); // std::cout << "isupper results: "; for (size_t i = 0; i < upper_test_result.getSize(); ++i) { .. _example-top_level-ismatrix-1336: .. dropdown:: ismatrix (np_test_2_all.cpp:3589) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3579 :emphasize-lines: 11 if (!(!isscalar(arr))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!isscalar(arr))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!isvector(arr))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!isvector(arr))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!ismatrix(arr))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!ismatrix(arr))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!isempty(arr))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!isempty(arr))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-issctype-1337: .. dropdown:: issctype (np_test_3_all.cpp:8616) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8606 :emphasize-lines: 11 } //============================================================================== // Test issctype //============================================================================== void np_test_issctype_numeric() { std::cout << "========= np_test_issctype_numeric ======================="; // Test numeric scalar types if (!issctype(DType::BOOL)) { std::cerr << "[FAIL] issctype(BOOL) should return true"; throw std::runtime_error("issctype BOOL test failed"); } // std::cout << "[OK] issctype(BOOL) = true" << std::endl; if (!issctype(DType::INT8)) { std::cerr << "[FAIL] issctype(INT8) should return true"; throw std::runtime_error("issctype INT8 test failed"); } // std::cout << "[OK] issctype(INT8) = true" << std::endl; .. _example-top_level-isspace-1338: .. dropdown:: isspace (np_test_1_all.cpp:6522) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6512 :emphasize-lines: 11 // Test isupper auto upper_test_result = isupper(arr); // std::cout << "isupper results: "; for (size_t i = 0; i < upper_test_result.getSize(); ++i) { // std::cout << upper_test_result.getElementAt({i}) << " "; } // std::cout << std::endl; // Test isspace auto space_result = isspace(arr); // std::cout << "isspace results: "; for (size_t i = 0; i < space_result.getSize(); ++i) { // std::cout << space_result.getElementAt({i}) << " "; } // std::cout << std::endl; std::cout << " -> tests passed" << std::endl; } void testStringSearchCharArray() { .. _example-top_level-issquare-1339: .. dropdown:: issquare (np_test_2_all.cpp:3607) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3597 :emphasize-lines: 11 throw std::runtime_error(description); } // Test 2D array auto arr2d = createFloat64Array({ 3, 3 }); if (!(ismatrix(arr2d))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ismatrix(arr2d))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(issquare(arr2d))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(issquare(arr2d))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 1D array auto arr1d = createFloat64Array({ 5 }); if (!(isvector(arr1d))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isvector(arr1d))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-issubclass_-1340: .. dropdown:: issubclass_ (np_test_3_all.cpp:8937) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8927 :emphasize-lines: 11 if (format_parser("b") != DType::BOOL) { std::cerr << "[FAIL] format_parser('b') should return BOOL"; throw std::runtime_error("format_parser bool test failed"); } // std::cout << "[OK] format_parser('b') = BOOL" << std::endl; std::cout << " -> tests passed" << std::endl; } //============================================================================== // Test issubclass_() - Strict subclass checking //============================================================================== void np_test_issubclass_integers() { std::cout << "========= np_test_issubclass_integers ======================="; // Test integer subclass relationships if (!issubclass_(DType::INT32, TypeCategory::INTEGER)) { std::cerr << "[FAIL] issubclass_(INT32, INTEGER) should be true"; throw std::runtime_error("issubclass_ INT32-INTEGER test failed"); } .. _example-top_level-issubdtype-1341: .. dropdown:: issubdtype (np_test_3_all.cpp:7295) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7285 :emphasize-lines: 11 } //============================================================================== // ISSUBDTYPE TESTS //============================================================================== void np_test_issubdtype_category() { std::cout << "========= np_test_issubdtype_category ======================="; // INTEGER category if (!issubdtype(DType::INT32, TypeCategory::INTEGER)) { std::cerr << "[FAIL] INT32 should be subtype of INTEGER"; throw std::runtime_error("issubdtype test failed"); } // std::cout << "[OK] INT32 is subtype of INTEGER" << std::endl; if (!issubdtype(DType::UINT64, TypeCategory::INTEGER)) { std::cerr << "[FAIL] UINT64 should be subtype of INTEGER"; throw std::runtime_error("issubdtype test failed"); } // std::cout << "[OK] UINT64 is subtype of INTEGER" << std::endl; .. _example-top_level-issubdtype-1342: .. dropdown:: issubdtype (np_test_3_all.cpp:7295) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7285 :emphasize-lines: 11 } //============================================================================== // ISSUBDTYPE TESTS //============================================================================== void np_test_issubdtype_category() { std::cout << "========= np_test_issubdtype_category ======================="; // INTEGER category if (!issubdtype(DType::INT32, TypeCategory::INTEGER)) { std::cerr << "[FAIL] INT32 should be subtype of INTEGER"; throw std::runtime_error("issubdtype test failed"); } // std::cout << "[OK] INT32 is subtype of INTEGER" << std::endl; if (!issubdtype(DType::UINT64, TypeCategory::INTEGER)) { std::cerr << "[FAIL] UINT64 should be subtype of INTEGER"; throw std::runtime_error("issubdtype test failed"); } // std::cout << "[OK] UINT64 is subtype of INTEGER" << std::endl; .. _example-top_level-issubsctype-1343: .. dropdown:: issubsctype (np_test_3_all.cpp:9226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9216 :emphasize-lines: 11 if (mintypecode("iD") != 'D') { std::cerr << "[FAIL] mintypecode('iD') should return 'D' (int32 + complex128 → complex128)"; throw std::runtime_error("mintypecode 'iD' test failed"); } // std::cout << "[OK] mintypecode('iD') = 'D' (int32 + complex128 → complex128)" << std::endl; std::cout << " -> tests passed" << std::endl; } //============================================================================== // Test issubsctype() - Scalar subtype checking //============================================================================== void np_test_issubsctype_category() { std::cout << "========= np_test_issubsctype_category ======================="; // Test scalar subtype with category if (!issubsctype(DType::INT32, TypeCategory::INTEGER)) { std::cerr << "[FAIL] issubsctype(INT32, INTEGER) should be true"; throw std::runtime_error("issubsctype INT32-INTEGER test failed"); } .. _example-top_level-issubsctype-1344: .. dropdown:: issubsctype (np_test_3_all.cpp:9226) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9216 :emphasize-lines: 11 if (mintypecode("iD") != 'D') { std::cerr << "[FAIL] mintypecode('iD') should return 'D' (int32 + complex128 → complex128)"; throw std::runtime_error("mintypecode 'iD' test failed"); } // std::cout << "[OK] mintypecode('iD') = 'D' (int32 + complex128 → complex128)" << std::endl; std::cout << " -> tests passed" << std::endl; } //============================================================================== // Test issubsctype() - Scalar subtype checking //============================================================================== void np_test_issubsctype_category() { std::cout << "========= np_test_issubsctype_category ======================="; // Test scalar subtype with category if (!issubsctype(DType::INT32, TypeCategory::INTEGER)) { std::cerr << "[FAIL] issubsctype(INT32, INTEGER) should be true"; throw std::runtime_error("issubsctype INT32-INTEGER test failed"); } .. _example-top_level-istitle-1345: .. dropdown:: istitle (np_test_5_all.cpp:1262) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1252 :emphasize-lines: 11 } std::cout << " -> tests passed" << std::endl; } void np_test_string_istitle() { std::cout << "========= istitle character checking ======================="; std::vector strings = { "Hello World", "hello world", "HELLO", "Title Case" }; auto arr = numpy::char_::array<32>(strings); auto result = numpy::char_::istitle(arr); bool passed = (result.getSize() == arr.size()); if (!passed) { std::cout << " [FAIL] : in np_test_string_istitle() : result size mismatch"; throw std::runtime_error("np_test_string_istitle failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-isupper-1346: .. dropdown:: isupper (np_test_1_all.cpp:6514) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6504 :emphasize-lines: 11 // Test islower auto lower_test_result = islower(arr); // std::cout << "islower results: "; for (size_t i = 0; i < lower_test_result.getSize(); ++i) { // std::cout << lower_test_result.getElementAt({i}) << " "; } // std::cout << std::endl; // Test isupper auto upper_test_result = isupper(arr); // std::cout << "isupper results: "; for (size_t i = 0; i < upper_test_result.getSize(); ++i) { // std::cout << upper_test_result.getElementAt({i}) << " "; } // std::cout << std::endl; // Test isspace auto space_result = isspace(arr); // std::cout << "isspace results: "; for (size_t i = 0; i < space_result.getSize(); ++i) { .. _example-top_level-isvector-1347: .. dropdown:: isvector (np_test_2_all.cpp:3584) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3574 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test utility checks if (!(!isscalar(arr))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!isscalar(arr))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!isvector(arr))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!isvector(arr))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!ismatrix(arr))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!ismatrix(arr))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!isempty(arr))) { .. _example-top_level-iter_range-1348: .. dropdown:: iter_range (np_test_5_all.cpp:11452) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11442 :emphasize-lines: 11 void np_test_iter_range() { std::cout << "========= IterRange: range-based for loops ======================="; numpy::NDArray arr({ 2, 3 }); for (size_t i = 0; i < 6; ++i) { arr.flat(i) = static_cast(i); } int count = 0; int expected = 0; for (const auto& val : numpy::iter_range(arr)) { if (val != expected) { std::cout << " [FAIL] : in np_test_iter_range() : incorrect value"; throw std::runtime_error("np_test_iter_range failed"); } count++; expected++; } if (count != 6) { std::cout << " [FAIL] : in np_test_iter_range() : incorrect count"; .. _example-top_level-iterable-1349: .. dropdown:: iterable (np_test_2_all.cpp:22234) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22224 :emphasize-lines: 11 catch (const std::exception& e) { std::cout << "[FAIL] <---------- np_test_compare_chararrays test suite failed with exception: " << e.what(); return 1; } return 0; } } // namespace numpy_tests // Comprehensive test suite for np.iterable() // // This file tests the iterable() functionality including: // - Compile-time type trait checks // - Runtime iterability checks for various container types // - NDArray iterability // - Non-iterable types #include #include #include .. _example-top_level-iterable-1350: .. dropdown:: iterable (np_test_2_all.cpp:22234) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22224 :emphasize-lines: 11 catch (const std::exception& e) { std::cout << "[FAIL] <---------- np_test_compare_chararrays test suite failed with exception: " << e.what(); return 1; } return 0; } } // namespace numpy_tests // Comprehensive test suite for np.iterable() // // This file tests the iterable() functionality including: // - Compile-time type trait checks // - Runtime iterability checks for various container types // - NDArray iterability // - Non-iterable types #include #include #include .. _example-top_level-iterable-1351: .. dropdown:: iterable (np_test_2_all.cpp:22234) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22224 :emphasize-lines: 11 catch (const std::exception& e) { std::cout << "[FAIL] <---------- np_test_compare_chararrays test suite failed with exception: " << e.what(); return 1; } return 0; } } // namespace numpy_tests // Comprehensive test suite for np.iterable() // // This file tests the iterable() functionality including: // - Compile-time type trait checks // - Runtime iterability checks for various container types // - NDArray iterability // - Non-iterable types #include #include #include .. _example-top_level-iterable-1352: .. dropdown:: iterable (np_test_2_all.cpp:22234) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22224 :emphasize-lines: 11 catch (const std::exception& e) { std::cout << "[FAIL] <---------- np_test_compare_chararrays test suite failed with exception: " << e.what(); return 1; } return 0; } } // namespace numpy_tests // Comprehensive test suite for np.iterable() // // This file tests the iterable() functionality including: // - Compile-time type trait checks // - Runtime iterability checks for various container types // - NDArray iterability // - Non-iterable types #include #include #include .. _example-top_level-iterable-1353: .. dropdown:: iterable (np_test_2_all.cpp:22234) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22224 :emphasize-lines: 11 catch (const std::exception& e) { std::cout << "[FAIL] <---------- np_test_compare_chararrays test suite failed with exception: " << e.what(); return 1; } return 0; } } // namespace numpy_tests // Comprehensive test suite for np.iterable() // // This file tests the iterable() functionality including: // - Compile-time type trait checks // - Runtime iterability checks for various container types // - NDArray iterability // - Non-iterable types #include #include #include .. _example-top_level-iterate-1354: .. dropdown:: iterate (np_test_3_all.cpp:20913) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20903 :emphasize-lines: 11 } // Test flat index if (it2.flatIndex() != 1) { std::cout << " [FAIL] : iterator incorrect flat index" << std::endl; throw std::runtime_error("np_test_extract_iterator failed: incorrect flat index"); } // Test range-based for loop iteration_count = 0; for (auto obj : numpy::iterate(arr)) { int* val = obj.get_as(); if (val && *val == iteration_count) { ++iteration_count; } } if (iteration_count != 6) { std::cout << " [FAIL] : range-based for loop incorrect count" << std::endl; throw std::runtime_error("np_test_extract_iterator failed: range-based for loop incorrect count"); } .. _example-top_level-ix_-1355: .. dropdown:: ix_ (np_test_4_all.cpp:23151) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23141 :emphasize-lines: 11 return 1; } return 0; } } // namespace numpy_tests // numpy_tests/np_test_phase7.cpp // Phase 7: Remaining numpy1.md Functions // Functions: typename_str(), make_mask(), ix_(), einsum() #include #include #include #include #include "../numpy/np_ndarray.h" #include "../numpy/np_dtype.h" #include "../numpy/np_dtype_utils.h" #include "../numpy/np_masked_array.h" #include "../numpy/np_factory.h" .. _example-top_level-jacobi-1356: .. dropdown:: jacobi (np_test_1_all.cpp:15975) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15965 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(isApproxEqual(genlaguerre(1, 1.0, 1.0), 1.0, 1e-6))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(genlaguerre(1, 1.0, 1.0), 1.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Generalized Laguerre polynomials\n"; // Test Jacobi polynomials if (!(isApproxEqual(jacobi(0, 1.0, 1.0, 0.5), 1.0, 1e-10))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(jacobi(0, 1.0, 1.0, 0.5), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(jacobi(1, 1.0, 1.0, 0.5)))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(jacobi(1, 1.0, 1.0, 0.5)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Jacobi polynomials\n"; .. _example-top_level-join-1357: .. dropdown:: join (np_test_5_all.cpp:1341) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1331 :emphasize-lines: 11 // ============================================================================ void np_test_string_join() { std::cout << "========= join operation ======================="; // Join takes a separator string and vector of CharArrays std::vector> arrays; arrays.push_back(numpy::char_::array<32>({ "a", "b", "c" })); arrays.push_back(numpy::char_::array<32>({ "x", "y", "z" })); auto result = numpy::char_::join("-", arrays); bool passed = true; if (!passed) { std::cout << " [FAIL] : in np_test_string_join() : join operation failed"; throw std::runtime_error("np_test_string_join failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-join-1358: .. dropdown:: join (np_test_5_all.cpp:1341) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1331 :emphasize-lines: 11 // ============================================================================ void np_test_string_join() { std::cout << "========= join operation ======================="; // Join takes a separator string and vector of CharArrays std::vector> arrays; arrays.push_back(numpy::char_::array<32>({ "a", "b", "c" })); arrays.push_back(numpy::char_::array<32>({ "x", "y", "z" })); auto result = numpy::char_::join("-", arrays); bool passed = true; if (!passed) { std::cout << " [FAIL] : in np_test_string_join() : join operation failed"; throw std::runtime_error("np_test_string_join failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-join_by-1359: .. dropdown:: join_by (np_test_1_all.cpp:21826) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21816 :emphasize-lines: 11 right.setFieldValue({ 1 }, "info", std::string("B")); right.setFieldValue({ 2 }, "key", static_cast(4)); right.setFieldValue({ 2 }, "info", std::string("D")); // std::cout << "Left array:" << std::endl; //left.printArray(); // std::cout << "Right array:" << std::endl; //right.printArray(); auto inner_join = join_by("key", left, right, "inner"); // std::cout << "Inner join on 'key':" << std::endl; //inner_join.printArray(); auto outer_join = join_by("key", left, right, "outer"); // std::cout << "Outer join on 'key':" << std::endl; //outer_join.printArray(); std::cout << " -> tests passed" << std::endl; } .. _example-top_level-k_way_merge_sort-1360: .. dropdown:: k_way_merge_sort (np_test_3_all.cpp:6372) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6362 :emphasize-lines: 11 } void test_streaming_sort() { std::cout << "========= test_streaming_sort ======================="; // Test k-way merge sort std::vector data = { 3.14, 1.41, 2.71, 0.57, 1.61, 2.23, 4.66, 1.73, 3.32, 2.44 }; std::vector expected = data; std::sort(expected.begin(), expected.end()); k_way_merge_sort(data.begin(), data.end(), std::less()); if (!(data == expected)) { std::string description = std::string("test_streaming_sort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_streaming_sort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-kei-1361: .. dropdown:: kei (np_test_1_all.cpp:16173) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16163 :emphasize-lines: 11 if (!(isApproxEqual(bei(0.0), 0.0, 1e-10))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(bei(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isinf(ker(0.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(ker(0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isinf(kei(0.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(kei(0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Kelvin functions at x=0\n"; // Test Kelvin functions for small positive values double x_small = 0.1; if (!(!std::isnan(ber(x_small)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(ber(x_small)))"; .. _example-top_level-kei-1362: .. dropdown:: kei (np_test_1_all.cpp:16173) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16163 :emphasize-lines: 11 if (!(isApproxEqual(bei(0.0), 0.0, 1e-10))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(bei(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isinf(ker(0.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(ker(0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isinf(kei(0.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(kei(0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Kelvin functions at x=0\n"; // Test Kelvin functions for small positive values double x_small = 0.1; if (!(!std::isnan(ber(x_small)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(ber(x_small)))"; .. _example-top_level-keip-1363: .. dropdown:: keip (np_test_1_all.cpp:16268) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16258 :emphasize-lines: 11 if (!(!std::isnan(beip(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(beip(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(kerp(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(kerp(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(keip(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(keip(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Kelvin function derivatives\n"; // Test combined function auto [ber_val, bei_val, ker_val, kei_val] = kelvin_all(1.0); if (!(isApproxEqual(ber_val, ber(1.0), 1e-6))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ber_val, ber(1.0), 1e-6))"; .. _example-top_level-keip-1364: .. dropdown:: keip (np_test_1_all.cpp:16268) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16258 :emphasize-lines: 11 if (!(!std::isnan(beip(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(beip(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(kerp(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(kerp(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(keip(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(keip(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Kelvin function derivatives\n"; // Test combined function auto [ber_val, bei_val, ker_val, kei_val] = kelvin_all(1.0); if (!(isApproxEqual(ber_val, ber(1.0), 1e-6))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ber_val, ber(1.0), 1e-6))"; .. _example-top_level-kendalltau-1365: .. dropdown:: kendalltau (np_test_1_all.cpp:11551) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11541 :emphasize-lines: 11 auto spearman_result = spearmanr(x, &y); // std::cout << "Spearman correlation: " << spearman_result.coefficient << ", p-value: " << spearman_result.pvalue << std::endl; if (!(std::abs(spearman_result.coefficient - 1.0) < 1e-10)) { std::string description = std::string("testCorrelationAnalysis():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(spearman_result.coefficient - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Spearman correlation\n"; // Test Kendall's tau auto kendall_result = kendalltau(x, y); // std::cout << "Kendall's tau: " << kendall_result.coefficient << ", p-value: " << kendall_result.pvalue << std::endl; if (!(std::abs(kendall_result.coefficient - 1.0) < 1e-10)) { std::string description = std::string("testCorrelationAnalysis():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(kendall_result.coefficient - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Kendall's tau\n"; // Test with some randomness auto x2 = createFloat32Array({ 6 }, 0.0f); .. _example-top_level-ker-1366: .. dropdown:: ker (np_test_1_all.cpp:16168) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16158 :emphasize-lines: 11 if (!(isApproxEqual(ber(0.0), 1.0, 1e-10))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ber(0.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(bei(0.0), 0.0, 1e-10))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(bei(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isinf(ker(0.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(ker(0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isinf(kei(0.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(kei(0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Kelvin functions at x=0\n"; .. _example-top_level-ker-1367: .. dropdown:: ker (np_test_1_all.cpp:16168) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16158 :emphasize-lines: 11 if (!(isApproxEqual(ber(0.0), 1.0, 1e-10))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ber(0.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(bei(0.0), 0.0, 1e-10))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(bei(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isinf(ker(0.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(ker(0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isinf(kei(0.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(kei(0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Kelvin functions at x=0\n"; .. _example-top_level-kerp-1368: .. dropdown:: kerp (np_test_1_all.cpp:16263) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16253 :emphasize-lines: 11 if (!(!std::isnan(berp(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(berp(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(beip(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(beip(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(kerp(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(kerp(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(keip(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(keip(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Kelvin function derivatives\n"; .. _example-top_level-kerp-1369: .. dropdown:: kerp (np_test_1_all.cpp:16263) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16253 :emphasize-lines: 11 if (!(!std::isnan(berp(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(berp(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(beip(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(beip(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(kerp(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(kerp(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(keip(1.0)))) { std::string description = std::string("testKelvinFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(keip(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Kelvin function derivatives\n"; .. _example-top_level-kurtosis-1370: .. dropdown:: kurtosis (np_test_1_all.cpp:11433) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11423 :emphasize-lines: 11 // std::cout << "Skewness of [1,2,3,4,5]: " << skew_result.getElementAt({ 0 }) << std::endl; // Should be close to 0 for symmetric data if (!(std::abs(skew_result.getElementAt({ 0 })) < 0.1)) { std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(skew_result.getElementAt({ 0 })) < 0.1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Skewness calculation\n"; // Test kurtosis auto kurt_result = kurtosis(normal_data); // std::cout << "Kurtosis of [1,2,3,4,5]: " << kurt_result.getElementAt({ 0 }) << std::endl; // std::cout << "[OK] Kurtosis calculation\n"; // Test moment auto moment2_result = moment(normal_data, 2); // std::cout << "2nd moment: " << moment2_result.getElementAt({ 0 }) << std::endl; if (!(moment2_result.getElementAt({ 0 }) > 0)) { std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(moment2_result.getElementAt({ 0 }) > 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-laguerre-1371: .. dropdown:: laguerre (np_test_1_all.cpp:15944) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15934 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(isApproxEqual(hermitenorm(2, 1.0), 0.0, 1e-6))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(hermitenorm(2, 1.0), 0.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Hermite polynomials (probabilist's)\n"; // Test Laguerre polynomials if (!(isApproxEqual(laguerre(0, 1.0), 1.0, 1e-10))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(laguerre(0, 1.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(laguerre(1, 1.0), 0.0, 1e-6))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(laguerre(1, 1.0), 0.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(laguerre(2, 1.0), -0.5, 1e-6))) { .. _example-top_level-lagval-1372: .. dropdown:: lagval (np_test_5_all.cpp:20817) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20807 :emphasize-lines: 11 void np_test_lagfit() { std::cout << "========= lagfit: Laguerre polynomial fitting ======================="; std::vector x = {0.0, 0.5, 1.0, 1.5, 2.0}; std::vector y = {0.0, 0.25, 1.0, 2.25, 4.0}; auto coeffs = numpy::polynomial::laguerre::lagfit(x, y, 2); double max_err = 0.0; for (size_t i = 0; i < x.size(); ++i) { double val = numpy::polynomial::laguerre::lagval(x[i], coeffs); max_err = std::max(max_err, std::abs(val - y[i])); } if (max_err > 1e-10) { std::cout << " [FAIL] : in np_test_lagfit(): max error " << max_err << " exceeds tolerance" << std::endl; throw std::runtime_error("np_test_lagfit failed: fit error too large"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-lbeta-1373: .. dropdown:: lbeta (np_test_2_all.cpp:2134) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2124 :emphasize-lines: 11 a_vals.setElementAt({ 1 }, 2.0); a_vals.setElementAt({ 2 }, 3.0); a_vals.setElementAt({ 3 }, 0.5); b_vals.setElementAt({ 0 }, 1.0); b_vals.setElementAt({ 1 }, 3.0); b_vals.setElementAt({ 2 }, 2.0); b_vals.setElementAt({ 3 }, 0.5); auto beta_result = beta(a_vals, b_vals, MathBackend::MKL); auto lbeta_result = lbeta(a_vals, b_vals, MathBackend::MKL); // Verify relationship: beta(a,b) = exp(lbeta(a,b)) for (size_t i = 0; i < 4; ++i) { double beta_val = beta_result.getElementAt({ i }); double exp_lbeta = std::exp(lbeta_result.getElementAt({ i })); if (!(isApproxEqual(beta_val, exp_lbeta, 1e-12))) { std::string description = std::string("testBetaFunctionsMKL():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(beta_val, exp_lbeta, 1e-12))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-lcm-1374: .. dropdown:: lcm (np_test_1_all.cpp:27840) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27830 :emphasize-lines: 11 } // std::cout << "] (expected: [6, 6, 10])" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_lcm() { std::cout << "========= lcm: least common multiple ======================="; // Scalar tests auto result1 = lcm(12, 18); // std::cout << " lcm(12, 18) = " << result1 << " (expected: 36)" << std::endl; auto result2 = lcm(21, 6); // std::cout << " lcm(21, 6) = " << result2 << " (expected: 42)" << std::endl; // Array tests auto arr1 = array({ 12, 21, 4 }); auto arr2 = array({ 18, 6, 6 }); auto arr_result = lcm(arr1, arr2); .. _example-top_level-lcm-1375: .. dropdown:: lcm (np_test_1_all.cpp:27840) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27830 :emphasize-lines: 11 } // std::cout << "] (expected: [6, 6, 10])" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_lcm() { std::cout << "========= lcm: least common multiple ======================="; // Scalar tests auto result1 = lcm(12, 18); // std::cout << " lcm(12, 18) = " << result1 << " (expected: 36)" << std::endl; auto result2 = lcm(21, 6); // std::cout << " lcm(21, 6) = " << result2 << " (expected: 42)" << std::endl; // Array tests auto arr1 = array({ 12, 21, 4 }); auto arr2 = array({ 18, 6, 6 }); auto arr_result = lcm(arr1, arr2); .. _example-top_level-ldexp-1376: .. dropdown:: ldexp (np_test_4_all.cpp:13182) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13172 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test ldexp() scalar + array overloads with type promotion // Binary function: x1 * 2^x2 (mantissa × 2^exponent) namespace numpy_tests { namespace numpy_tests_ldexp_scalar { using namespace numpy; void test_ldexp_bool() { // bool → float32 float result = numpy::ldexp(true, 2); .. _example-top_level-ldexp-1377: .. dropdown:: ldexp (np_test_4_all.cpp:13182) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13172 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test ldexp() scalar + array overloads with type promotion // Binary function: x1 * 2^x2 (mantissa × 2^exponent) namespace numpy_tests { namespace numpy_tests_ldexp_scalar { using namespace numpy; void test_ldexp_bool() { // bool → float32 float result = numpy::ldexp(true, 2); .. _example-top_level-ldexp-1378: .. dropdown:: ldexp (np_test_4_all.cpp:13182) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13172 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test ldexp() scalar + array overloads with type promotion // Binary function: x1 * 2^x2 (mantissa × 2^exponent) namespace numpy_tests { namespace numpy_tests_ldexp_scalar { using namespace numpy; void test_ldexp_bool() { // bool → float32 float result = numpy::ldexp(true, 2); .. _example-top_level-ldexp-1379: .. dropdown:: ldexp (np_test_4_all.cpp:13182) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13172 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test ldexp() scalar + array overloads with type promotion // Binary function: x1 * 2^x2 (mantissa × 2^exponent) namespace numpy_tests { namespace numpy_tests_ldexp_scalar { using namespace numpy; void test_ldexp_bool() { // bool → float32 float result = numpy::ldexp(true, 2); .. _example-top_level-ldexp-1380: .. dropdown:: ldexp (np_test_4_all.cpp:13182) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13172 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test ldexp() scalar + array overloads with type promotion // Binary function: x1 * 2^x2 (mantissa × 2^exponent) namespace numpy_tests { namespace numpy_tests_ldexp_scalar { using namespace numpy; void test_ldexp_bool() { // bool → float32 float result = numpy::ldexp(true, 2); .. _example-top_level-ldexp-1381: .. dropdown:: ldexp (np_test_4_all.cpp:13182) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13172 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test ldexp() scalar + array overloads with type promotion // Binary function: x1 * 2^x2 (mantissa × 2^exponent) namespace numpy_tests { namespace numpy_tests_ldexp_scalar { using namespace numpy; void test_ldexp_bool() { // bool → float32 float result = numpy::ldexp(true, 2); .. _example-top_level-ldexp-1382: .. dropdown:: ldexp (np_test_4_all.cpp:13182) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13172 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test ldexp() scalar + array overloads with type promotion // Binary function: x1 * 2^x2 (mantissa × 2^exponent) namespace numpy_tests { namespace numpy_tests_ldexp_scalar { using namespace numpy; void test_ldexp_bool() { // bool → float32 float result = numpy::ldexp(true, 2); .. _example-top_level-ldexp-1383: .. dropdown:: ldexp (np_test_4_all.cpp:13182) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13172 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test ldexp() scalar + array overloads with type promotion // Binary function: x1 * 2^x2 (mantissa × 2^exponent) namespace numpy_tests { namespace numpy_tests_ldexp_scalar { using namespace numpy; void test_ldexp_bool() { // bool → float32 float result = numpy::ldexp(true, 2); .. _example-top_level-ldexp-1384: .. dropdown:: ldexp (np_test_4_all.cpp:13182) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13172 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test ldexp() scalar + array overloads with type promotion // Binary function: x1 * 2^x2 (mantissa × 2^exponent) namespace numpy_tests { namespace numpy_tests_ldexp_scalar { using namespace numpy; void test_ldexp_bool() { // bool → float32 float result = numpy::ldexp(true, 2); .. _example-top_level-ldexp-1385: .. dropdown:: ldexp (np_test_4_all.cpp:13182) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13172 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test ldexp() scalar + array overloads with type promotion // Binary function: x1 * 2^x2 (mantissa × 2^exponent) namespace numpy_tests { namespace numpy_tests_ldexp_scalar { using namespace numpy; void test_ldexp_bool() { // bool → float32 float result = numpy::ldexp(true, 2); .. _example-top_level-ldexp-1386: .. dropdown:: ldexp (np_test_4_all.cpp:13182) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13172 :emphasize-lines: 11 } } // namespace numpy_tests #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" #include #include #include // Test ldexp() scalar + array overloads with type promotion // Binary function: x1 * 2^x2 (mantissa × 2^exponent) namespace numpy_tests { namespace numpy_tests_ldexp_scalar { using namespace numpy; void test_ldexp_bool() { // bool → float32 float result = numpy::ldexp(true, 2); .. _example-top_level-legendre-1387: .. dropdown:: legendre (np_test_1_all.cpp:15836) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15826 :emphasize-lines: 11 } // std::cout << "[OK] Airy function array operations\n"; std::cout << " -> tests passed\n"; } void testOrthogonalPolynomials() { std::cout << "========= testOrthogonalPolynomials ===="; // Test Legendre polynomials if (!(isApproxEqual(legendre(0, 0.5), 1.0, 1e-10))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(legendre(0, 0.5), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(legendre(1, 0.5), 0.5, 1e-10))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(legendre(1, 0.5), 0.5, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(legendre(2, 0.5), -0.125, 1e-6))) { .. _example-top_level-legval-1388: .. dropdown:: legval (np_test_5_all.cpp:20751) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20741 :emphasize-lines: 11 void np_test_legfit() { std::cout << "========= legfit: Legendre polynomial fitting ======================="; std::vector x = {-1.0, -0.5, 0.0, 0.5, 1.0}; std::vector y = {1.0, 0.25, 0.0, 0.25, 1.0}; auto coeffs = numpy::polynomial::legendre::legfit(x, y, 2); double max_err = 0.0; for (size_t i = 0; i < x.size(); ++i) { double val = numpy::polynomial::legendre::legval(x[i], coeffs); max_err = std::max(max_err, std::abs(val - y[i])); } if (max_err > 1e-10) { std::cout << " [FAIL] : in np_test_legfit(): max error " << max_err << " exceeds tolerance" << std::endl; throw std::runtime_error("np_test_legfit failed: fit error too large"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-li-1389: .. dropdown:: li (np_test_1_all.cpp:10872) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10862 :emphasize-lines: 11 double e1_1 = exp1(1.0); if (!(!std::isnan(e1_1) && std::isfinite(e1_1))) { std::string description = std::string("testExponentialIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(e1_1) && std::isfinite(e1_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Exponential integral E1(x) basic functionality\n"; // Test logarithmic integral if (!(std::isnan(li(0.0)))) { std::string description = std::string("testExponentialIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isnan(li(0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isnan(li(1.0)))) { std::string description = std::string("testExponentialIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isnan(li(1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-ljust-1390: .. dropdown:: ljust (np_test_1_all.cpp:6597) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6587 :emphasize-lines: 11 } // Test center auto centered = center(arr, 10, '*'); // std::cout << "Centered (width=10, fill='*'):" << std::endl; for (size_t i = 0; i < centered.size(); ++i) { // std::cout << "'" << centered[i] << "'"; } // Test ljust auto left_just = ljust(arr, 8, '-'); // std::cout << "Left justified (width=8, fill='-'):" << std::endl; for (size_t i = 0; i < left_just.size(); ++i) { // std::cout << "'" << left_just[i] << "'"; } // Test rjust auto right_just = rjust(arr, 8, '+'); // std::cout << "Right justified (width=8, fill='+'):" << std::endl; for (size_t i = 0; i < right_just.size(); ++i) { // std::cout << "'" << right_just[i] << "'"; .. _example-top_level-ljust-1391: .. dropdown:: ljust (np_test_1_all.cpp:6597) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6587 :emphasize-lines: 11 } // Test center auto centered = center(arr, 10, '*'); // std::cout << "Centered (width=10, fill='*'):" << std::endl; for (size_t i = 0; i < centered.size(); ++i) { // std::cout << "'" << centered[i] << "'"; } // Test ljust auto left_just = ljust(arr, 8, '-'); // std::cout << "Left justified (width=8, fill='-'):" << std::endl; for (size_t i = 0; i < left_just.size(); ++i) { // std::cout << "'" << left_just[i] << "'"; } // Test rjust auto right_just = rjust(arr, 8, '+'); // std::cout << "Right justified (width=8, fill='+'):" << std::endl; for (size_t i = 0; i < right_just.size(); ++i) { // std::cout << "'" << right_just[i] << "'"; .. _example-top_level-ljust-1392: .. dropdown:: ljust (np_test_1_all.cpp:6597) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6587 :emphasize-lines: 11 } // Test center auto centered = center(arr, 10, '*'); // std::cout << "Centered (width=10, fill='*'):" << std::endl; for (size_t i = 0; i < centered.size(); ++i) { // std::cout << "'" << centered[i] << "'"; } // Test ljust auto left_just = ljust(arr, 8, '-'); // std::cout << "Left justified (width=8, fill='-'):" << std::endl; for (size_t i = 0; i < left_just.size(); ++i) { // std::cout << "'" << left_just[i] << "'"; } // Test rjust auto right_just = rjust(arr, 8, '+'); // std::cout << "Right justified (width=8, fill='+'):" << std::endl; for (size_t i = 0; i < right_just.size(); ++i) { // std::cout << "'" << right_just[i] << "'"; .. _example-top_level-lower-1393: .. dropdown:: lower (np_test_1_all.cpp:6454) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6444 :emphasize-lines: 11 } // Test upper case auto upper_result = upper(arr); // std::cout << "Upper case:" << std::endl; for (size_t i = 0; i < upper_result.size(); ++i) { // std::cout << " '" << upper_result[i] << "'"; } // Test lower case auto lower_result = lower(arr); // std::cout << "Lower case:" << std::endl; for (size_t i = 0; i < lower_result.size(); ++i) { // std::cout << " '" << lower_result[i] << "'"; } // Test capitalize auto cap_result = capitalize(arr); // std::cout << "Capitalize:" << std::endl; for (size_t i = 0; i < cap_result.size(); ++i) { // std::cout << " '" << cap_result[i] << "'"; .. _example-top_level-lpmv-1394: .. dropdown:: lpmv (np_test_1_all.cpp:15854) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15844 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(isApproxEqual(legendre(2, 0.5), -0.125, 1e-6))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(legendre(2, 0.5), -0.125, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Legendre polynomials\n"; // Test associated Legendre polynomials if (!(isApproxEqual(lpmv(0, 0, 0.5), 1.0, 1e-10))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lpmv(0, 0, 0.5), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(lpmv(0, 1, 0.5), 0.5, 1e-10))) { std::string description = std::string("testOrthogonalPolynomials():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(lpmv(0, 1, 0.5), 0.5, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(lpmv(1, 1, 0.5)))) { .. _example-top_level-lstrip-1395: .. dropdown:: lstrip (np_test_1_all.cpp:6641) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6631 :emphasize-lines: 11 } // Test strip auto stripped = strip(arr); // std::cout << "After strip():" << std::endl; for (size_t i = 0; i < stripped.size(); ++i) { // std::cout << "'" << stripped[i] << "'"; } // Test lstrip auto left_stripped = lstrip(arr); // std::cout << "After lstrip():" << std::endl; for (size_t i = 0; i < left_stripped.size(); ++i) { // std::cout << "'" << left_stripped[i] << "'"; } // Test rstrip auto right_stripped = rstrip(arr); // std::cout << "After rstrip():" << std::endl; for (size_t i = 0; i < right_stripped.size(); ++i) { // std::cout << "'" << right_stripped[i] << "'"; .. _example-top_level-lstrip-1396: .. dropdown:: lstrip (np_test_1_all.cpp:6641) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6631 :emphasize-lines: 11 } // Test strip auto stripped = strip(arr); // std::cout << "After strip():" << std::endl; for (size_t i = 0; i < stripped.size(); ++i) { // std::cout << "'" << stripped[i] << "'"; } // Test lstrip auto left_stripped = lstrip(arr); // std::cout << "After lstrip():" << std::endl; for (size_t i = 0; i < left_stripped.size(); ++i) { // std::cout << "'" << left_stripped[i] << "'"; } // Test rstrip auto right_stripped = rstrip(arr); // std::cout << "After rstrip():" << std::endl; for (size_t i = 0; i < right_stripped.size(); ++i) { // std::cout << "'" << right_stripped[i] << "'"; .. _example-top_level-lu-1397: .. dropdown:: lu (np_test_2_all.cpp:5088) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5078 :emphasize-lines: 11 assert_test(qr_close, "QR decomposition accuracy"); } catch (...) { // QR might fail for some matrices in simplified implementation // std::cout << "QR decomposition test skipped (expected for simplified implementation)" << std::endl; } // Test LU decomposition numpy::Matrix B("2 1; 1 1"); try { auto [P, L, U] = numpy::lu(B); assert_test(P.rows() == 2 && P.cols() == 2, "LU decomposition P dimensions"); assert_test(L.rows() == 2 && L.cols() == 2, "LU decomposition L dimensions"); assert_test(U.rows() == 2 && U.cols() == 2, "LU decomposition U dimensions"); // Verify P * A = L * U (approximately) auto PA = P * B; auto LU = L * U; bool lu_close = true; for (size_t i = 0; i < 2 && lu_close; ++i) { for (size_t j = 0; j < 2 && lu_close; ++j) { .. _example-top_level-lu-1398: .. dropdown:: lu (np_test_2_all.cpp:5088) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5078 :emphasize-lines: 11 assert_test(qr_close, "QR decomposition accuracy"); } catch (...) { // QR might fail for some matrices in simplified implementation // std::cout << "QR decomposition test skipped (expected for simplified implementation)" << std::endl; } // Test LU decomposition numpy::Matrix B("2 1; 1 1"); try { auto [P, L, U] = numpy::lu(B); assert_test(P.rows() == 2 && P.cols() == 2, "LU decomposition P dimensions"); assert_test(L.rows() == 2 && L.cols() == 2, "LU decomposition L dimensions"); assert_test(U.rows() == 2 && U.cols() == 2, "LU decomposition U dimensions"); // Verify P * A = L * U (approximately) auto PA = P * B; auto LU = L * U; bool lu_close = true; for (size_t i = 0; i < 2 && lu_close; ++i) { for (size_t j = 0; j < 2 && lu_close; ++j) { .. _example-top_level-lu_decomposition_pivoted-1399: .. dropdown:: lu_decomposition_pivoted (np_test_2_all.cpp:7452) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7442 :emphasize-lines: 11 matrix.setElementAt({ 1, 1 }, 2.0); matrix.setElementAt({ 1, 2 }, 3.0); matrix.setElementAt({ 2, 0 }, 2.0); matrix.setElementAt({ 2, 1 }, 3.0); matrix.setElementAt({ 2, 2 }, 4.0); // std::cout << "Original matrix:" << std::endl; //matrix.printArray(); // Test new pivoted LU decomposition auto lu_result = lu_decomposition_pivoted(matrix); // std::cout << "Is singular: " << (lu_result.is_singular ? "Yes" : "No") << std::endl; // std::cout << "Permutation sign: " << lu_result.sign << std::endl; // std::cout << "L matrix:" << std::endl; //lu_result.L.printArray(); // std::cout << "U matrix:" << std::endl; //lu_result.U.printArray(); .. _example-top_level-machar-1400: .. dropdown:: machar (np_test_3_all.cpp:8755) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8745 :emphasize-lines: 11 #include #include #include #include #include "../numpy/np_dtype_utils.h" using namespace numpy; //============================================================================== // Test machar() - Machine arithmetic information //============================================================================== void np_test_machar_properties() { std::cout << "========= np_test_machar_properties ======================="; MachArInfo info = machar(); // Check that bits is 64 for double if (info.bits != 64) { std::cerr << "[FAIL] machar().bits should be 64 for double, got: " << info.bits; .. _example-top_level-machine_epsilon-1401: .. dropdown:: machine_epsilon (np_test_2_all.cpp:7320) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7310 :emphasize-lines: 11 namespace numpy_tests { using namespace numpy::linalg::utils; namespace test_lu_simple { void test_basic_utilities() { std::cout << "========= test_basic_utilities ======================="; // Test machine epsilon auto eps_double = machine_epsilon(); if (!(eps_double > 0)) { std::string description = std::string("test_basic_utilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(eps_double > 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Machine epsilon (double): " << eps_double << std::endl; // Test zero check bool is_zero_result = is_zero(1e-16); if (!(is_zero_result == true)) { .. _example-top_level-mask_indices-1402: .. dropdown:: mask_indices (np_test_1_all.cpp:28523) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 28513 :emphasize-lines: 11 throw std::runtime_error("np_test_indexing_diag_indices_from failed"); } std::cout << " -> tests passed" << std::endl; } void np_test_indexing_mask_indices() { std::cout << "========= mask_indices: triangular mask indices ======================="; // Get upper triangular indices for 3x3 matrix auto triu_idx = numpy::mask_indices(3, "triu", 0); // Should return tuple of 2 arrays bool passed = (std::get<0>(triu_idx).getSize() > 0); passed = passed && (std::get<1>(triu_idx).getSize() > 0); passed = passed && (std::get<0>(triu_idx).getSize() == std::get<1>(triu_idx).getSize()); // Get lower triangular indices auto tril_idx = numpy::mask_indices(3, "tril", 0); passed = passed && (std::get<0>(tril_idx).getSize() > 0); passed = passed && (std::get<1>(tril_idx).getSize() > 0); .. _example-top_level-mask_indices-1403: .. dropdown:: mask_indices (np_test_1_all.cpp:28523) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 28513 :emphasize-lines: 11 throw std::runtime_error("np_test_indexing_diag_indices_from failed"); } std::cout << " -> tests passed" << std::endl; } void np_test_indexing_mask_indices() { std::cout << "========= mask_indices: triangular mask indices ======================="; // Get upper triangular indices for 3x3 matrix auto triu_idx = numpy::mask_indices(3, "triu", 0); // Should return tuple of 2 arrays bool passed = (std::get<0>(triu_idx).getSize() > 0); passed = passed && (std::get<1>(triu_idx).getSize() > 0); passed = passed && (std::get<0>(triu_idx).getSize() == std::get<1>(triu_idx).getSize()); // Get lower triangular indices auto tril_idx = numpy::mask_indices(3, "tril", 0); passed = passed && (std::get<0>(tril_idx).getSize() > 0); passed = passed && (std::get<1>(tril_idx).getSize() > 0); .. _example-top_level-mat-1404: .. dropdown:: mat (np_test_2_all.cpp:11401) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11391 :emphasize-lines: 11 // use a separate namespace for each test group namespace numpy_tests_linalg_missing { // ============================================================================ // DIAGONAL AND TRACE TESTS // ============================================================================ void np_test_linalg_missing_diagonal() { std::cout << "========= diagonal: extract diagonal from matrix ======================="; numpy::NDArray mat({ 3, 4 }); for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 4; ++j) { mat.setElementAt({ i, j }, static_cast(i * 4 + j)); } } auto diag = numpy::diagonal(mat); if (diag.getShape()[0] != 3) { std::cout << " [FAIL] : diagonal shape incorrect"; throw std::runtime_error("diagonal test failed: wrong shape"); .. _example-top_level-matrix-1405: .. dropdown:: matrix (np_test_1_all.cpp:15388) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15378 :emphasize-lines: 11 using namespace numpy; using namespace numpy::linalg; void test_svd_basic() { std::cout << "========= test_svd_basic ======================="; // std::cout << "Testing basic SVD decomposition..." << std::endl; // Create a simple 3x2 matrix NDArray matrix({ 3, 2 }); matrix.setElementAt({ 0, 0 }, 1.0); matrix.setElementAt({ 0, 1 }, 2.0); matrix.setElementAt({ 1, 0 }, 3.0); matrix.setElementAt({ 1, 1 }, 4.0); matrix.setElementAt({ 2, 0 }, 5.0); matrix.setElementAt({ 2, 1 }, 6.0); // std::cout << "Original matrix:" << std::endl; //matrix.printArray(); .. _example-top_level-matrix-1406: .. dropdown:: matrix (np_test_1_all.cpp:15388) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15378 :emphasize-lines: 11 using namespace numpy; using namespace numpy::linalg; void test_svd_basic() { std::cout << "========= test_svd_basic ======================="; // std::cout << "Testing basic SVD decomposition..." << std::endl; // Create a simple 3x2 matrix NDArray matrix({ 3, 2 }); matrix.setElementAt({ 0, 0 }, 1.0); matrix.setElementAt({ 0, 1 }, 2.0); matrix.setElementAt({ 1, 0 }, 3.0); matrix.setElementAt({ 1, 1 }, 4.0); matrix.setElementAt({ 2, 0 }, 5.0); matrix.setElementAt({ 2, 1 }, 6.0); // std::cout << "Original matrix:" << std::endl; //matrix.printArray(); .. _example-top_level-matrix-1407: .. dropdown:: matrix (np_test_1_all.cpp:15388) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15378 :emphasize-lines: 11 using namespace numpy; using namespace numpy::linalg; void test_svd_basic() { std::cout << "========= test_svd_basic ======================="; // std::cout << "Testing basic SVD decomposition..." << std::endl; // Create a simple 3x2 matrix NDArray matrix({ 3, 2 }); matrix.setElementAt({ 0, 0 }, 1.0); matrix.setElementAt({ 0, 1 }, 2.0); matrix.setElementAt({ 1, 0 }, 3.0); matrix.setElementAt({ 1, 1 }, 4.0); matrix.setElementAt({ 2, 0 }, 5.0); matrix.setElementAt({ 2, 1 }, 6.0); // std::cout << "Original matrix:" << std::endl; //matrix.printArray(); .. _example-top_level-may_share_memory-1408: .. dropdown:: may_share_memory (np_test_2_all.cpp:3735) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3725 :emphasize-lines: 11 std::cout << " -> tests passed\n"; } void testMemoryUtils() { std::cout << "Testing memory utilities...\n"; auto arr1 = createFloat64Array({ 3, 4 }); auto arr2 = createFloat64Array({ 3, 4 }); // Test memory sharing checks bool may_share = may_share_memory(arr1, arr2); bool shares = shares_memory(arr1, arr2); // These should be false for different arrays if (!(!may_share || !shares)) { std::string description = std::string("testMemoryUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!may_share || !shares)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test broadcast_to auto small_arr = createFloat64Array({ 1, 3 }); .. _example-top_level-memmap-1409: .. dropdown:: memmap (np_test_2_all.cpp:10637) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10627 :emphasize-lines: 11 std::cout << " -> tests passed\n"; } void testMemoryMapping() { std::cout << "========= testMemoryMapping ===="; ensure_temp_directory(); // Test creating a new memory-mapped file std::vector shape = { 10, 5 }; auto mmap_array = numpy::memmap::memmap(TEMP_DIR + "test_memmap_new.npy", shape, "w+"); // Write some data for (size_t i = 0; i < 10; ++i) { for (size_t j = 0; j < 5; ++j) { mmap_array.setElementAt({ i, j }, static_cast(i * 5 + j + 1)); } } mmap_array.flush(); // std::cout << "[OK] Created and wrote to memory-mapped file\n"; .. _example-top_level-memory_footprint-1410: .. dropdown:: memory_footprint (np_test_2_all.cpp:3791) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3781 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(mem_info.total_bytes == 12 * sizeof(double))) { std::string description = std::string("testMemoryUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(mem_info.total_bytes == 12 * sizeof(double))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test memory footprint if (!(memory_footprint(arr1) == 12 * sizeof(double))) { std::string description = std::string("testMemoryUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(memory_footprint(arr1) == 12 * sizeof(double))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test contiguous array functions auto contiguous = ascontiguousarray(arr1); if (!(contiguous.getShape() == arr1.getShape())) { std::string description = std::string("testMemoryUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(contiguous.getShape() == arr1.getShape())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-memory_layout-1411: .. dropdown:: memory_layout (np_test_5_all.cpp:8737) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8727 :emphasize-lines: 11 } // =========================== // MemoryLayout Tests // =========================== void np_test_toString_memorylayout() { std::cout << "========= MemoryLayout::toString() ======================="; numpy::NDArray arr({ 3, 4 }); auto layout = numpy::memory_layout(arr); std::string result = layout.toString(); // std::cout << "Result:\n" << result << std::endl; verify_not_empty(result, "MemoryLayout toString()"); if (!verify_contains(result, "Memory Layout:", "MemoryLayout")) { throw std::runtime_error("Missing header in toString()"); } .. _example-top_level-merge_arrays-1412: .. dropdown:: merge_arrays (np_test_1_all.cpp:21780) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21770 :emphasize-lines: 11 arr2.setFieldValue({ 0 }, "name", std::string("Alice")); arr2.setFieldValue({ 1 }, "id", static_cast(4)); arr2.setFieldValue({ 1 }, "name", std::string("Bob")); // std::cout << "Array 1:" << std::endl; //arr1.printArray(); // std::cout << "Array 2:" << std::endl; //arr2.printArray(); auto merged = merge_arrays({ arr1, arr2 }); // std::cout << "Merged arrays:"; //merged.printArray(); auto stacked = stack_arrays({ arr1 }); // std::cout << "Stacked arrays (single array):"; //stacked.printArray(); std::cout << " -> tests passed" << std::endl; } .. _example-top_level-mirr-1413: .. dropdown:: mirr (np_test_3_all.cpp:1413) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1403 :emphasize-lines: 11 double irr_result = irr(cash_flows); double npv_at_irr = npv(irr_result, cash_flows); if (!(isApproxEqual(npv_at_irr, 0.0, 0.01))) { std::string description = std::string("testCashFlowFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(npv_at_irr, 0.0, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] irr() calculation: Project IRR = " << irr_result * 100 << "%" << std::endl; // Test MIRR double mirr_result = mirr(cash_flows, 0.10, 0.12); // 10% finance rate, 12% reinvest rate if (!(mirr_result > 0.0 && mirr_result < 1.0)) { std::string description = std::string("testCashFlowFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(mirr_result > 0.0 && mirr_result < 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] mirr() calculation: Project MIRR = " << mirr_result * 100 << "%" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-mirr-1414: .. dropdown:: mirr (np_test_3_all.cpp:1413) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1403 :emphasize-lines: 11 double irr_result = irr(cash_flows); double npv_at_irr = npv(irr_result, cash_flows); if (!(isApproxEqual(npv_at_irr, 0.0, 0.01))) { std::string description = std::string("testCashFlowFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(npv_at_irr, 0.0, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] irr() calculation: Project IRR = " << irr_result * 100 << "%" << std::endl; // Test MIRR double mirr_result = mirr(cash_flows, 0.10, 0.12); // 10% finance rate, 12% reinvest rate if (!(mirr_result > 0.0 && mirr_result < 1.0)) { std::string description = std::string("testCashFlowFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(mirr_result > 0.0 && mirr_result < 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] mirr() calculation: Project MIRR = " << mirr_result * 100 << "%" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-mkl_axpy-1415: .. dropdown:: mkl_axpy (np_test_3_all.cpp:17828) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17818 :emphasize-lines: 11 NDArray x({ 3 }); x.setElementAt({ 0 }, 1.0); x.setElementAt({ 1 }, 2.0); x.setElementAt({ 2 }, 3.0); NDArray y({ 3 }); y.setElementAt({ 0 }, 10.0); y.setElementAt({ 1 }, 20.0); y.setElementAt({ 2 }, 30.0); mkl::lapack::mkl_axpy(alpha, x, y); // Expected: y = 2*x + y = [2*1+10, 2*2+20, 2*3+30] = [12, 24, 36] if (!is_close(y.getElementAt({ 0 }), 12.0) || !is_close(y.getElementAt({ 1 }), 24.0) || !is_close(y.getElementAt({ 2 }), 36.0)) { throw std::runtime_error("mkl_axpy test failed"); } // std::cout << " mkl_axpy: y = [" << y.getElementAt({ 0 }) << ", " // << y.getElementAt({ 1 }) << ", " << y.getElementAt({ 2 }) // << "] (expected [12, 24, 36])"; .. _example-top_level-mkl_copy-1416: .. dropdown:: mkl_copy (np_test_3_all.cpp:17865) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17855 :emphasize-lines: 11 // Test: copy x to y { NDArray x({ 4 }); x.setElementAt({ 0 }, 1.5); x.setElementAt({ 1 }, 2.5); x.setElementAt({ 2 }, 3.5); x.setElementAt({ 3 }, 4.5); NDArray y({ 4 }); // Initialize with zeros mkl::lapack::mkl_copy(x, y); // Verify y == x for (size_t i = 0; i < 4; ++i) { if (!is_close(y.getElementAt({ i }), x.getElementAt({ i }))) { throw std::runtime_error("mkl_copy test failed at index " + std::to_string(i)); } } // std::cout << " mkl_copy: y = [" << y.getElementAt({ 0 }) << ", " // << y.getElementAt({ 1 }) << ", " << y.getElementAt({ 2 }) << ", " // << y.getElementAt({ 3 }) << "]"; .. _example-top_level-mkl_copysign_arrays-1417: .. dropdown:: mkl_copysign_arrays (np_test_3_all.cpp:19368) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19358 :emphasize-lines: 11 #ifdef NUMPY_USE_MKL const size_t n = 1000; std::vector a(n), b(n), result(n); for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) + 1.0; // Always positive b[i] = (i % 2 == 0) ? 1.0 : -1.0; // Alternating signs } mkl::mkl_copysign_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::copysign(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_copysign():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } .. _example-top_level-mkl_fft_1d-1418: .. dropdown:: mkl_fft_1d (np_test_2_all.cpp:17919) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17909 :emphasize-lines: 11 void np_test_mkl_fft_1d_complex() { std::cout << "========= mkl_fft_1d complex FFT (size=8) ======================="; numpy::NDArray> signal({ 8 }); auto signal_data = signal.data(); for (size_t i = 0; i < 8; ++i) { signal_data[i] = std::complex(std::sin(2.0 * M_PI * i / 8.0), 0.0); } auto result = numpy::fft::mkl::mkl_fft_1d(signal); // Verify output shape if (result.getShape()[0] != 8) { std::cout << " [FAIL] : in np_test_mkl_fft_1d_complex() : incorrect output shape"; throw std::runtime_error("np_test_mkl_fft_1d_complex failed: incorrect output shape"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-mkl_fmax_arrays-1419: .. dropdown:: mkl_fmax_arrays (np_test_3_all.cpp:19278) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19268 :emphasize-lines: 11 #ifdef NUMPY_USE_MKL const size_t n = 1000; std::vector a(n), b(n), result(n); for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmax_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmax(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmax():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } .. _example-top_level-mkl_fmin_arrays-1420: .. dropdown:: mkl_fmin_arrays (np_test_3_all.cpp:19308) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19298 :emphasize-lines: 11 #ifdef NUMPY_USE_MKL const size_t n = 1000; std::vector a(n), b(n), result(n); for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) - 500.0; b[i] = static_cast(n - i) - 500.0; } mkl::mkl_fmin_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::fmin(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-10)) { std::string description = std::string("test_vml_fmin():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } .. _example-top_level-mkl_gbtrf-1421: .. dropdown:: mkl_gbtrf (np_test_3_all.cpp:18312) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18302 :emphasize-lines: 11 AB.setElementAt({ 3, 1 }, 1.0); // subdiagonal A[2,1] AB.setElementAt({ 3, 2 }, 0.0); // unused // RHS: [1, 2, 3] numpy::NDArray b({ static_cast(n) }); b.setElementAt({ 0 }, 1.0); b.setElementAt({ 1 }, 2.0); b.setElementAt({ 2 }, 3.0); // Factor auto lu_result = numpy::mkl::lapack::mkl_gbtrf(AB, kl, ku); if (!lu_result.converged) { throw std::runtime_error("mkl_gbtrf failed to converge"); } // std::cout << " mkl_gbtrf: factorization successful" << std::endl; // Solve auto x = numpy::mkl::lapack::mkl_gbtrs(lu_result.AB, lu_result.ipiv, b, kl, ku); // std::cout << " mkl_gbtrs solution: [" // << x.getElementAt({ 0 }) << ", " // << x.getElementAt({ 1 }) << ", " .. _example-top_level-mkl_gees-1422: .. dropdown:: mkl_gees (np_test_3_all.cpp:18673) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18663 :emphasize-lines: 11 A.setElementAt({0, 0}, 4.0); A.setElementAt({0, 1}, 2.0); A.setElementAt({0, 2}, 0.0); A.setElementAt({1, 0}, 2.0); A.setElementAt({1, 1}, 5.0); A.setElementAt({1, 2}, 1.0); A.setElementAt({2, 0}, 0.0); A.setElementAt({2, 1}, 1.0); A.setElementAt({2, 2}, 3.0); auto result = numpy::mkl::lapack::mkl_gees(A, true); if (!result.converged) { std::cout << " [FAIL] : in np_test_mkl_phase3_2_schur() : mkl_gees failed to converge"; throw std::runtime_error("np_test_mkl_phase3_2_schur failed: mkl_gees did not converge"); } // Verify shapes and eigenvalue count bool passed = (result.S.getShape()[0] == static_cast(n)) && (result.Z.getShape()[0] == static_cast(n)) && (result.eigenvalues.getSize() == static_cast(n)); .. _example-top_level-mkl_gehrd-1423: .. dropdown:: mkl_gehrd (np_test_3_all.cpp:18621) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18611 :emphasize-lines: 11 numpy::NDArray A({static_cast(n), static_cast(n)}); // Fill with a test matrix for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { A.setElementAt({static_cast(i), static_cast(j)}, static_cast(i + j + 1)); } } auto result = numpy::mkl::lapack::mkl_gehrd(A); if (!result.converged) { std::cout << " [FAIL] : in np_test_mkl_phase3_2_hessenberg() : mkl_gehrd failed to converge"; throw std::runtime_error("np_test_mkl_phase3_2_hessenberg failed: mkl_gehrd did not converge"); } // Verify shapes bool passed = (result.H.getShape()[0] == static_cast(n)) && (result.H.getShape()[1] == static_cast(n)) && (result.Q.getShape()[0] == static_cast(n)) && .. _example-top_level-mkl_ggev-1424: .. dropdown:: mkl_ggev (np_test_3_all.cpp:18574) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18564 :emphasize-lines: 11 A.setElementAt({1, 2}, 1.0); A.setElementAt({2, 0}, 0.0); A.setElementAt({2, 1}, 1.0); A.setElementAt({2, 2}, 3.0); // B = identity matrix B.setElementAt({0, 0}, 1.0); B.setElementAt({1, 1}, 1.0); B.setElementAt({2, 2}, 1.0); auto result = numpy::mkl::lapack::mkl_ggev(A, B, false, true); if (!result.converged) { std::cout << " [FAIL] : in np_test_mkl_phase3_2_generalized_eigen() : mkl_ggev failed to converge"; throw std::runtime_error("np_test_mkl_phase3_2_generalized_eigen failed: mkl_ggev did not converge"); } // Verify we got eigenvalues bool passed = (result.alpha.getSize() == static_cast(n)) && (result.beta.getSize() == static_cast(n)); .. _example-top_level-mkl_gttrf-1425: .. dropdown:: mkl_gttrf (np_test_3_all.cpp:18469) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18459 :emphasize-lines: 11 du.setElementAt({ 0 }, 1.0); du.setElementAt({ 1 }, 1.0); // RHS: [1, 2, 3] numpy::NDArray b({ static_cast(n) }); b.setElementAt({ 0 }, 1.0); b.setElementAt({ 1 }, 2.0); b.setElementAt({ 2 }, 3.0); // Factor auto lu_result = numpy::mkl::lapack::mkl_gttrf(dl, d, du); if (!lu_result.converged) { throw std::runtime_error("mkl_gttrf failed to converge"); } // std::cout << " mkl_gttrf: factorization successful" << std::endl; // Solve auto x = numpy::mkl::lapack::mkl_gttrs(lu_result.dl, lu_result.d, lu_result.du, lu_result.du2, lu_result.ipiv, b); // std::cout << " mkl_gttrs solution: [" // << x.getElementAt({ 0 }) << ", " .. _example-top_level-mkl_hetrf-1426: .. dropdown:: mkl_hetrf (np_test_3_all.cpp:19025) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19015 :emphasize-lines: 11 A.setElementAt({ 0, 0 }, std::complex(1.0, 0.0)); A.setElementAt({ 0, 1 }, std::complex(2.0, 1.0)); A.setElementAt({ 0, 2 }, std::complex(0.0, 0.0)); A.setElementAt({ 1, 0 }, std::complex(2.0, -1.0)); A.setElementAt({ 1, 1 }, std::complex(-1.0, 0.0)); A.setElementAt({ 1, 2 }, std::complex(1.0, 0.5)); A.setElementAt({ 2, 0 }, std::complex(0.0, 0.0)); A.setElementAt({ 2, 1 }, std::complex(1.0, -0.5)); A.setElementAt({ 2, 2 }, std::complex(2.0, 0.0)); auto lu_result = numpy::mkl::lapack::mkl_hetrf(A, false); if (!lu_result.converged) { std::cout << " [FAIL] : in np_test_mkl_phase3_4_hermitian_indefinite() : mkl_hetrf failed to converge"; throw std::runtime_error("np_test_mkl_phase3_4_hermitian_indefinite failed: mkl_hetrf did not converge"); } // Test solving numpy::NDArray> b({ static_cast(n) }); b.setElementAt({ 0 }, std::complex(1.0, 0.0)); b.setElementAt({ 1 }, std::complex(2.0, 0.0)); .. _example-top_level-mkl_hetrs-1427: .. dropdown:: mkl_hetrs (np_test_3_all.cpp:19038) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19028 :emphasize-lines: 11 std::cout << " [FAIL] : in np_test_mkl_phase3_4_hermitian_indefinite() : mkl_hetrf failed to converge"; throw std::runtime_error("np_test_mkl_phase3_4_hermitian_indefinite failed: mkl_hetrf did not converge"); } // Test solving numpy::NDArray> b({ static_cast(n) }); b.setElementAt({ 0 }, std::complex(1.0, 0.0)); b.setElementAt({ 1 }, std::complex(2.0, 0.0)); b.setElementAt({ 2 }, std::complex(3.0, 0.0)); auto x = numpy::mkl::lapack::mkl_hetrs(lu_result.A, lu_result.ipiv, b, false); bool passed = (x.getSize() == static_cast(n)); if (!passed) { std::cout << " [FAIL] : in np_test_mkl_phase3_4_hermitian_indefinite() : solution size incorrect"; throw std::runtime_error("np_test_mkl_phase3_4_hermitian_indefinite failed: size mismatch"); } #else // std::cout << " [SKIP] MKL support not compiled" << std::endl; #endif .. _example-top_level-mkl_hypot_arrays-1428: .. dropdown:: mkl_hypot_arrays (np_test_3_all.cpp:19338) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19328 :emphasize-lines: 11 #ifdef NUMPY_USE_MKL const size_t n = 1000; std::vector a(n), b(n), result(n); for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i) / 10.0; b[i] = static_cast(n - i) / 10.0; } mkl::mkl_hypot_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::hypot(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-9)) { std::string description = std::string("test_vml_hypot():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-9)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } .. _example-top_level-mkl_ifft_1d-1429: .. dropdown:: mkl_ifft_1d (np_test_2_all.cpp:17962) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17952 :emphasize-lines: 11 std::cout << "========= mkl_fft_1d/mkl_ifft_1d roundtrip (size=32) ======================="; numpy::NDArray> original({ 32 }); auto original_data = original.data(); for (size_t i = 0; i < 32; ++i) { original_data[i] = std::complex(static_cast(i) * 0.1, static_cast(i) * 0.05); } auto freq = numpy::fft::mkl::mkl_fft_1d(original); auto reconstructed = numpy::fft::mkl::mkl_ifft_1d(freq); // Verify roundtrip accuracy if (!arrays_close(original, reconstructed, 1e-10)) { std::cout << " [FAIL] : in np_test_mkl_fft_roundtrip() : FFT/IFFT roundtrip does not reconstruct original"; throw std::runtime_error("np_test_mkl_fft_roundtrip failed: roundtrip accuracy check failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-mkl_lstsq-1430: .. dropdown:: mkl_lstsq (np_test_2_all.cpp:17571) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17561 :emphasize-lines: 11 A.setElementAt({4, 0}, 4.0); A.setElementAt({4, 1}, 1.0); numpy::NDArray b({5}); b.setElementAt({0}, 1.0); b.setElementAt({1}, 3.0); b.setElementAt({2}, 5.0); b.setElementAt({3}, 7.0); b.setElementAt({4}, 9.0); try { auto result = numpy::mkl::lapack::mkl_lstsq(A, b); if (!result.converged) { std::cout << " [FAIL] : LSTSQ did not converge"; throw std::runtime_error("np_test_mkl_linalg_lstsq failed: not converged"); } double m = result.x.getElementAt({0}); double c = result.x.getElementAt({1}); // std::cout << " Solution: m = " << m << ", c = " << c << std::endl; .. _example-top_level-mkl_lu-1431: .. dropdown:: mkl_lu (np_test_2_all.cpp:17459) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17449 :emphasize-lines: 11 // Create a simple 3x3 matrix numpy::NDArray A({3, 3}); double data[] = {4.0, 3.0, 2.0, 3.0, 2.0, 1.0, 2.0, 1.0, 3.0}; for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 3; ++j) { A.setElementAt({i, j}, data[i * 3 + j]); } } try { auto [L, U, P] = numpy::mkl::lapack::mkl_lu(A); // Verify dimensions auto l_shape = L.getShape(); auto u_shape = U.getShape(); auto p_shape = P.getShape(); if (l_shape[0] != 3 || l_shape[1] != 3 || u_shape[0] != 3 || u_shape[1] != 3 || p_shape[0] != 3 || p_shape[1] != 3) { std::cout << " [FAIL] : Incorrect dimensions"; throw std::runtime_error("np_test_mkl_linalg_lu failed: dimensions"); } .. _example-top_level-mkl_mean_contiguous-1432: .. dropdown:: mkl_mean_contiguous (np_test_5_all.cpp:1601) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1591 :emphasize-lines: 11 // std::cout << " mkl_sum_contiguous: double sum = " << sum_double << ", float sum = " << sum_float << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_stats_mkl_mean_contiguous() { std::cout << "========= mkl_mean_contiguous helper ======================="; // Test mkl_mean_contiguous with double array std::vector data = { 1.0, 2.0, 3.0, 4.0, 5.0 }; double mean_val = numpy::mkl_mean_contiguous(data.data(), data.size()); bool passed = is_close(mean_val, 3.0); if (!passed) { std::cout << " [FAIL] : in np_test_stats_mkl_mean_contiguous() : mean " << mean_val << " != expected 3.0" << std::endl; throw std::runtime_error("np_test_stats_mkl_mean_contiguous failed: incorrect mean"); } // Test with larger array std::vector large_data(1000); .. _example-top_level-mkl_nextafter_arrays-1433: .. dropdown:: mkl_nextafter_arrays (np_test_3_all.cpp:19398) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19388 :emphasize-lines: 11 #ifdef NUMPY_USE_MKL const size_t n = 1000; std::vector a(n), b(n), result(n); for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i); b[i] = a[i] + 1.0; } mkl::mkl_nextafter_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::nextafter(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-14)) { std::string description = std::string("test_vml_nextafter():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-14)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } .. _example-top_level-mkl_qr-1434: .. dropdown:: mkl_qr (np_test_2_all.cpp:17379) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17369 :emphasize-lines: 11 -4.0, 24.0, -41.0, -1.0, 1.0, 0.0 }; for (size_t i = 0; i < 4; ++i) { for (size_t j = 0; j < 3; ++j) { A.setElementAt({i, j}, data[i * 3 + j]); } } try { auto result = numpy::mkl::lapack::mkl_qr(A, "reduced"); if (!result.converged) { std::cout << " [FAIL] : QR did not converge"; throw std::runtime_error("np_test_mkl_linalg_qr failed: not converged"); } // Check dimensions: for 4x3 economy QR // Q should be 4x3, R should be 3x3 auto q_shape = result.Q.getShape(); auto r_shape = result.R.getShape(); .. _example-top_level-mkl_rfft_1d-1435: .. dropdown:: mkl_rfft_1d (np_test_2_all.cpp:17939) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17929 :emphasize-lines: 11 void np_test_mkl_fft_rfft_1d() { std::cout << "========= mkl_rfft_1d real FFT (size=16) ======================="; numpy::NDArray real_signal({ 16 }); auto real_signal_data = real_signal.data(); for (size_t i = 0; i < 16; ++i) { real_signal_data[i] = std::cos(2.0 * M_PI * i / 16.0); } auto result = numpy::fft::mkl::mkl_rfft_1d(real_signal); // Verify output shape (should be n/2 + 1 = 16/2 + 1 = 9) if (result.getShape()[0] != 9) { std::cout << " [FAIL] : in np_test_mkl_fft_rfft_1d() : incorrect output shape (got " << result.getShape()[0] << ", expected 9)" << std::endl; throw std::runtime_error("np_test_mkl_fft_rfft_1d failed: incorrect output shape"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-mkl_rot-1436: .. dropdown:: mkl_rot (np_test_3_all.cpp:18027) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18017 :emphasize-lines: 11 double s = 0.8; NDArray x({ 2 }); x.setElementAt({ 0 }, 1.0); x.setElementAt({ 1 }, 0.0); NDArray y({ 2 }); y.setElementAt({ 0 }, 0.0); y.setElementAt({ 1 }, 1.0); mkl::lapack::mkl_rot(x, y, c, s); // After rotation with c=0.6, s=0.8: // x_new[i] = c*x[i] + s*y[i] // y_new[i] = -s*x[i] + c*y[i] // For i=0: x_new[0] = 0.6*1 + 0.8*0 = 0.6, y_new[0] = -0.8*1 + 0.6*0 = -0.8 // For i=1: x_new[1] = 0.6*0 + 0.8*1 = 0.8, y_new[1] = -0.8*0 + 0.6*1 = 0.6 if (!is_close(x.getElementAt({ 0 }), 0.6) || !is_close(x.getElementAt({ 1 }), 0.8) || !is_close(y.getElementAt({ 0 }), -0.8) || .. _example-top_level-mkl_rotg-1437: .. dropdown:: mkl_rotg (np_test_3_all.cpp:17979) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17969 :emphasize-lines: 11 // std::cout << " [SKIP] MKL not available"; return; } // Test: Generate Givens rotation { double a = 3.0; double b = 4.0; double c, s; mkl::lapack::mkl_rotg(a, b, c, s); // For a=3, b=4: r=5, c=3/5=0.6, s=4/5=0.8 // After rotg: a should be r (hypotenuse) double expected_r = std::sqrt(3.0 * 3.0 + 4.0 * 4.0); // 5.0 if (!is_close(a, expected_r, 1e-10)) { throw std::runtime_error("mkl_rotg test failed: a=" + std::to_string(a) + ", expected r=" + std::to_string(expected_r)); } // Verify c^2 + s^2 = 1 (rotation property) .. _example-top_level-mkl_scal-1438: .. dropdown:: mkl_scal (np_test_3_all.cpp:17945) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17935 :emphasize-lines: 11 // Test: scale x by alpha { double alpha = 3.0; NDArray x({ 4 }); x.setElementAt({ 0 }, 1.0); x.setElementAt({ 1 }, 2.0); x.setElementAt({ 2 }, 3.0); x.setElementAt({ 3 }, 4.0); mkl::lapack::mkl_scal(alpha, x); // Expected: x = 3*x = [3, 6, 9, 12] if (!is_close(x.getElementAt({ 0 }), 3.0) || !is_close(x.getElementAt({ 1 }), 6.0) || !is_close(x.getElementAt({ 2 }), 9.0) || !is_close(x.getElementAt({ 3 }), 12.0)) { throw std::runtime_error("mkl_scal test failed"); } // std::cout << " mkl_scal: x = [" << x.getElementAt({ 0 }) << ", " // << x.getElementAt({ 1 }) << ", " << x.getElementAt({ 2 }) << ", " .. _example-top_level-mkl_stedc-1439: .. dropdown:: mkl_stedc (np_test_3_all.cpp:18767) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18757 :emphasize-lines: 11 numpy::NDArray d({static_cast(n)}); numpy::NDArray e({static_cast(n - 1)}); d.setElementAt({0}, 4.0); d.setElementAt({1}, 4.0); d.setElementAt({2}, 4.0); e.setElementAt({0}, 1.0); e.setElementAt({1}, 1.0); auto result = numpy::mkl::lapack::mkl_stedc(d, e, true); if (!result.converged) { std::cout << " [FAIL] : in np_test_mkl_phase3_2_tridiagonal_dc() : mkl_stedc failed to converge"; throw std::runtime_error("np_test_mkl_phase3_2_tridiagonal_dc failed: mkl_stedc did not converge"); } // Verify eigenvalue count bool passed = (result.eigenvalues.getSize() == static_cast(n)); if (!passed) { .. _example-top_level-mkl_steqr-1440: .. dropdown:: mkl_steqr (np_test_3_all.cpp:18721) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18711 :emphasize-lines: 11 numpy::NDArray d({static_cast(n)}); numpy::NDArray e({static_cast(n - 1)}); d.setElementAt({0}, 4.0); d.setElementAt({1}, 4.0); d.setElementAt({2}, 4.0); e.setElementAt({0}, 1.0); e.setElementAt({1}, 1.0); auto result = numpy::mkl::lapack::mkl_steqr(d, e, true); if (!result.converged) { std::cout << " [FAIL] : in np_test_mkl_phase3_2_tridiagonal_qr() : mkl_steqr failed to converge"; throw std::runtime_error("np_test_mkl_phase3_2_tridiagonal_qr failed: mkl_steqr did not converge"); } // Verify eigenvalue count bool passed = (result.eigenvalues.getSize() == static_cast(n)); if (!passed) { .. _example-top_level-mkl_sum_contiguous-1441: .. dropdown:: mkl_sum_contiguous (np_test_5_all.cpp:1572) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1562 :emphasize-lines: 11 // ============================================================================ // MKL HELPER FUNCTION TESTS // ============================================================================ #ifdef NUMPY_USE_MKL void np_test_stats_mkl_sum_contiguous() { std::cout << "========= mkl_sum_contiguous helper ======================="; // Test mkl_sum_contiguous with double array std::vector data_double = { 1.0, 2.0, 3.0, 4.0, 5.0 }; double sum_double = numpy::mkl_sum_contiguous(data_double.data(), data_double.size()); bool passed = is_close(sum_double, 15.0); if (!passed) { std::cout << " [FAIL] : in np_test_stats_mkl_sum_contiguous() : double sum " << sum_double << " != expected 15.0" << std::endl; throw std::runtime_error("np_test_stats_mkl_sum_contiguous failed: incorrect double sum"); } // Test mkl_sum_contiguous with float array std::vector data_float = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; .. _example-top_level-mkl_svd-1442: .. dropdown:: mkl_svd (np_test_2_all.cpp:17329) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17319 :emphasize-lines: 11 // Create a simple 3x3 matrix numpy::NDArray A({3, 3}); double data[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; for (size_t i = 0; i < 3; ++i) { for (size_t j = 0; j < 3; ++j) { A.setElementAt({i, j}, data[i * 3 + j]); } } try { auto result = numpy::mkl::lapack::mkl_svd(A, false); if (!result.converged) { std::cout << " [FAIL] : SVD did not converge"; throw std::runtime_error("np_test_mkl_linalg_svd failed: not converged"); } // Check dimensions: for 3x3 economy SVD // U should be 3x3, S should be 3x1, Vt should be 3x3 auto u_shape = result.U.getShape(); auto s_shape = result.S.getShape(); .. _example-top_level-mkl_swap-1443: .. dropdown:: mkl_swap (np_test_3_all.cpp:17904) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17894 :emphasize-lines: 11 NDArray x({ 3 }); x.setElementAt({ 0 }, 1.0); x.setElementAt({ 1 }, 2.0); x.setElementAt({ 2 }, 3.0); NDArray y({ 3 }); y.setElementAt({ 0 }, 10.0); y.setElementAt({ 1 }, 20.0); y.setElementAt({ 2 }, 30.0); mkl::lapack::mkl_swap(x, y); // After swap: x should be [10, 20, 30], y should be [1, 2, 3] if (!is_close(x.getElementAt({ 0 }), 10.0) || !is_close(x.getElementAt({ 1 }), 20.0) || !is_close(x.getElementAt({ 2 }), 30.0) || !is_close(y.getElementAt({ 0 }), 1.0) || !is_close(y.getElementAt({ 1 }), 2.0) || !is_close(y.getElementAt({ 2 }), 3.0)) { throw std::runtime_error("mkl_swap test failed"); } .. _example-top_level-mkl_syr-1444: .. dropdown:: mkl_syr (np_test_3_all.cpp:18177) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18167 :emphasize-lines: 11 } } NDArray x({ 3 }); x.setElementAt({ 0 }, 1.0); x.setElementAt({ 1 }, 2.0); x.setElementAt({ 2 }, 3.0); double alpha = 1.0; mkl::lapack::mkl_syr(alpha, x, A, true); // Expected: A = x*x^T = [[1, 2, 3], [2, 4, 6], [3, 6, 9]] // Upper triangle only (since upper=true) if (!is_close(A.getElementAt({ 0, 0 }), 1.0) || !is_close(A.getElementAt({ 0, 1 }), 2.0) || !is_close(A.getElementAt({ 0, 2 }), 3.0) || !is_close(A.getElementAt({ 1, 1 }), 4.0) || !is_close(A.getElementAt({ 1, 2 }), 6.0) || !is_close(A.getElementAt({ 2, 2 }), 9.0)) { throw std::runtime_error("mkl_syr test failed"); .. _example-top_level-mkl_sytrf-1445: .. dropdown:: mkl_sytrf (np_test_3_all.cpp:18969) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18959 :emphasize-lines: 11 A.setElementAt({ 0, 0 }, 1.0); A.setElementAt({ 0, 1 }, 2.0); A.setElementAt({ 0, 2 }, 0.0); A.setElementAt({ 1, 0 }, 2.0); A.setElementAt({ 1, 1 }, -1.0); A.setElementAt({ 1, 2 }, 1.0); A.setElementAt({ 2, 0 }, 0.0); A.setElementAt({ 2, 1 }, 1.0); A.setElementAt({ 2, 2 }, 2.0); auto lu_result = numpy::mkl::lapack::mkl_sytrf(A, false); if (!lu_result.converged) { std::cout << " [FAIL] : in np_test_mkl_phase3_4_symmetric_indefinite() : mkl_sytrf failed to converge"; throw std::runtime_error("np_test_mkl_phase3_4_symmetric_indefinite failed: mkl_sytrf did not converge"); } // Test solving numpy::NDArray b({ static_cast(n) }); b.setElementAt({ 0 }, 1.0); b.setElementAt({ 1 }, 2.0); .. _example-top_level-mkl_trcon-1446: .. dropdown:: mkl_trcon (np_test_3_all.cpp:18871) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18861 :emphasize-lines: 11 A.setElementAt({ 0, 0 }, 2.0); A.setElementAt({ 0, 1 }, 1.0); A.setElementAt({ 0, 2 }, 1.0); A.setElementAt({ 1, 0 }, 0.0); A.setElementAt({ 1, 1 }, 2.0); A.setElementAt({ 1, 2 }, 1.0); A.setElementAt({ 2, 0 }, 0.0); A.setElementAt({ 2, 1 }, 0.0); A.setElementAt({ 2, 2 }, 2.0); double rcond = numpy::mkl::lapack::mkl_trcon(A, '1', true, false); bool passed = (rcond > 0.0 && rcond <= 1.0); if (!passed) { std::cout << " [FAIL] : in np_test_mkl_phase3_3_triangular_condition() : rcond out of valid range"; throw std::runtime_error("np_test_mkl_phase3_3_triangular_condition failed: invalid rcond"); } #else // std::cout << " [SKIP] MKL support not compiled" << std::endl; #endif .. _example-top_level-mkl_trmv-1447: .. dropdown:: mkl_trmv (np_test_3_all.cpp:18133) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18123 :emphasize-lines: 11 A.setElementAt({ 1, 2 }, 1.0); A.setElementAt({ 2, 0 }, 0.0); A.setElementAt({ 2, 1 }, 0.0); A.setElementAt({ 2, 2 }, 2.0); NDArray x({ 3 }); x.setElementAt({ 0 }, 1.0); x.setElementAt({ 1 }, 2.0); x.setElementAt({ 2 }, 3.0); mkl::lapack::mkl_trmv(A, x, true, false, false); // Expected: A*x = [2*1+1*2+1*3, 2*2+1*3, 2*3] = [7, 7, 6] if (!is_close(x.getElementAt({ 0 }), 7.0) || !is_close(x.getElementAt({ 1 }), 7.0) || !is_close(x.getElementAt({ 2 }), 6.0)) { throw std::runtime_error("mkl_trmv test failed"); } // std::cout << " mkl_trmv: x = [" << x.getElementAt({ 0 }) << ", " // << x.getElementAt({ 1 }) << ", " << x.getElementAt({ 2 }) // << "] (expected [7, 7, 6])"; .. _example-top_level-mkl_variance_contiguous-1448: .. dropdown:: mkl_variance_contiguous (np_test_5_all.cpp:1635) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1625 :emphasize-lines: 11 // std::cout << " mkl_mean_contiguous: mean = " << mean_val << ", large array mean = " << large_mean << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_stats_mkl_variance_contiguous() { std::cout << "========= mkl_variance_contiguous helper ======================="; // Test mkl_variance_contiguous with known data // Variance of {1, 2, 3, 4, 5} = E[(X - mean)^2] = E[(X - 3)^2] = (4 + 1 + 0 + 1 + 4) / 5 = 2.0 std::vector data = { 1.0, 2.0, 3.0, 4.0, 5.0 }; double var_ddof0 = numpy::mkl_variance_contiguous(data.data(), data.size(), 0); bool passed = is_close(var_ddof0, 2.0); if (!passed) { std::cout << " [FAIL] : in np_test_stats_mkl_variance_contiguous() : variance (ddof=0) " << var_ddof0 << " != expected 2.0" << std::endl; throw std::runtime_error("np_test_stats_mkl_variance_contiguous failed: incorrect variance ddof=0"); } // Test with ddof=1 (sample variance) // Sample variance = 10 / 4 = 2.5 .. _example-top_level-moment-1449: .. dropdown:: moment (np_test_1_all.cpp:11438) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11428 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "[OK] Skewness calculation\n"; // Test kurtosis auto kurt_result = kurtosis(normal_data); // std::cout << "Kurtosis of [1,2,3,4,5]: " << kurt_result.getElementAt({ 0 }) << std::endl; // std::cout << "[OK] Kurtosis calculation\n"; // Test moment auto moment2_result = moment(normal_data, 2); // std::cout << "2nd moment: " << moment2_result.getElementAt({ 0 }) << std::endl; if (!(moment2_result.getElementAt({ 0 }) > 0)) { std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(moment2_result.getElementAt({ 0 }) > 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Moment calculation\n"; // Test describe auto desc_result = describe(normal_data); .. _example-top_level-narray-1450: .. dropdown:: narray (np_test_1_all.cpp:26630) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26620 :emphasize-lines: 11 // std::cout << "===============================================" << std::endl; // Test array_function_dispatch (stub) { numpy::char_::array_function_dispatch([]() {}); // std::cout << " ✓ array_function_dispatch() (stub)"; } // Test narray { auto arr = numpy::char_::narray<32>({ "hello", "world" }); if (!(arr.size() == 2)) { std::string description = std::string("test_char_extensions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr.size() == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ narray<32>()" << std::endl; } // Test set_module (stub) { .. _example-top_level-nbytes-1451: .. dropdown:: nbytes (np_test_2_all.cpp:3547) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3537 :emphasize-lines: 11 } // Test itemsize if (!(itemsize(arr) == sizeof(double))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(itemsize(arr) == sizeof(double))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test nbytes if (!(nbytes(arr) == 24 * sizeof(double))) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(nbytes(arr) == 24 * sizeof(double))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test flags auto flags_info = flags(arr); if (!(flags_info.owndata == true)) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(flags_info.owndata == true)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-ndenumerate-1452: .. dropdown:: ndenumerate (np_test_2_all.cpp:3860) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3850 :emphasize-lines: 11 throw std::runtime_error(description); } } if (!(idx_count == 4)) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(idx_count == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test NDEnumerate auto enum_iter = ndenumerate(arr); size_t enum_count = 0; for (; !enum_iter.is_finished(); ++enum_iter, ++enum_count) { auto pair = *enum_iter; if (!(pair.first.size() == 2)) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(pair.first.size() == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqualMCO(pair.second, expected_values[enum_count]))) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqualMCO(pair.second, expected_values[enum_count]))"; .. _example-top_level-ndim-1453: .. dropdown:: ndim (np_test_2_all.cpp:3526) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3516 :emphasize-lines: 11 void testArrayInfo() { std::cout << "Testing array information functions...\n"; // Test basic info functions auto arr = createFloat64Array({ 2, 3, 4 }); for (size_t i = 0; i < arr.getSize(); ++i) { arr.setElementAt({ i / 12, (i / 4) % 3, i % 4 }, static_cast(i)); } // Test ndim if (!(ndim(arr) == 3)) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ndim(arr) == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test size if (!(size(arr) == 24)) { std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(size(arr) == 24)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-ndindex-1454: .. dropdown:: ndindex (np_test_2_all.cpp:3838) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3828 :emphasize-lines: 11 throw std::runtime_error(description); } } if (!(count == 6)) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(count == 6)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test NDIndex auto idx_iter = ndindex({ 2, 2 }); size_t idx_count = 0; for (; !idx_iter.is_finished(); ++idx_iter, ++idx_count) { const auto& indices = *idx_iter; if (!(indices.size() == 2)) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(indices.size() == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(indices[0] < 2 && indices[1] < 2)) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(indices[0] < 2 && indices[1] < 2)"; .. _example-top_level-nditer-1455: .. dropdown:: nditer (np_test_2_all.cpp:3820) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3810 :emphasize-lines: 11 std::cout << "Testing iterator functionality...\n"; // Test NDIter auto arr = createFloat64Array({ 2, 3 }); for (size_t i = 0; i < 2; ++i) { for (size_t j = 0; j < 3; ++j) { arr.setElementAt({ i, j }, static_cast(i * 3 + j)); } } auto iter = nditer(arr); size_t count = 0; double expected_values[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }; for (; !iter.is_finished(); ++iter, ++count) { if (!(isApproxEqualMCO(*iter, expected_values[count]))) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqualMCO(*iter, expected_values[count]))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } .. _example-top_level-nditer-1456: .. dropdown:: nditer (np_test_2_all.cpp:3820) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3810 :emphasize-lines: 11 std::cout << "Testing iterator functionality...\n"; // Test NDIter auto arr = createFloat64Array({ 2, 3 }); for (size_t i = 0; i < 2; ++i) { for (size_t j = 0; j < 3; ++j) { arr.setElementAt({ i, j }, static_cast(i * 3 + j)); } } auto iter = nditer(arr); size_t count = 0; double expected_values[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }; for (; !iter.is_finished(); ++iter, ++count) { if (!(isApproxEqualMCO(*iter, expected_values[count]))) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqualMCO(*iter, expected_values[count]))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } .. _example-top_level-nditer_all-1457: .. dropdown:: nditer_all (np_test_2_all.cpp:3896) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3886 :emphasize-lines: 11 throw std::runtime_error(description); } size_t positive_count = nditer_count(arr, [](double x) { return x > 2.0; }); if (!(positive_count == 3)) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(positive_count == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } bool all_non_negative = nditer_all(arr, [](double x) { return x >= 0.0; }); if (!(all_non_negative)) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(all_non_negative)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } bool any_greater_than_10 = nditer_any(arr, [](double x) { return x > 10.0; }); if (!(!any_greater_than_10)) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!any_greater_than_10)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-nditer_any-1458: .. dropdown:: nditer_any (np_test_2_all.cpp:3903) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3893 :emphasize-lines: 11 throw std::runtime_error(description); } bool all_non_negative = nditer_all(arr, [](double x) { return x >= 0.0; }); if (!(all_non_negative)) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(all_non_negative)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } bool any_greater_than_10 = nditer_any(arr, [](double x) { return x > 10.0; }); if (!(!any_greater_than_10)) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!any_greater_than_10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Iterator functionality\n"; std::cout << " -> tests passed\n"; } .. _example-top_level-nditer_apply-1459: .. dropdown:: nditer_apply (np_test_5_all.cpp:11388) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11378 :emphasize-lines: 11 void np_test_functional_iteration() { std::cout << "========= Functional: nditer_apply/reduce/find/count ======================="; numpy::NDArray arr({ 2, 3 }); for (size_t i = 0; i < 6; ++i) { arr.flat(i) = static_cast(i + 1); } // Test nditer_apply int apply_count = 0; numpy::nditer_apply(arr, [&apply_count](double val, const std::vector& idx) { apply_count++; }); if (apply_count != 6) { std::cout << " [FAIL] : in np_test_functional_iteration() : nditer_apply count wrong"; throw std::runtime_error("np_test_functional_iteration failed"); } // Test nditer_reduce (sum) double sum = numpy::nditer_reduce(arr, [](double acc, double val) { .. _example-top_level-nditer_count-1460: .. dropdown:: nditer_count (np_test_2_all.cpp:3889) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3879 :emphasize-lines: 11 } // Test functional iteration double sum = nditer_reduce(arr, [](double a, double b) { return a + b; }, 0.0); if (!(isApproxEqualMCO(sum, 15.0))) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqualMCO(sum, 15.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } size_t positive_count = nditer_count(arr, [](double x) { return x > 2.0; }); if (!(positive_count == 3)) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(positive_count == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } bool all_non_negative = nditer_all(arr, [](double x) { return x >= 0.0; }); if (!(all_non_negative)) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(all_non_negative)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-nditer_find-1461: .. dropdown:: nditer_find (np_test_5_all.cpp:11408) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11398 :emphasize-lines: 11 double sum = numpy::nditer_reduce(arr, [](double acc, double val) { return acc + val; }, 0.0); if (std::abs(sum - 21.0) > 1e-10) { // 1+2+3+4+5+6 = 21 std::cout << " [FAIL] : in np_test_functional_iteration() : nditer_reduce sum wrong"; throw std::runtime_error("np_test_functional_iteration failed"); } // Test nditer_find auto result = numpy::nditer_find(arr, [](double val) { return val > 3.5; }); if (!result.has_value() || result.value().second != 4.0) { std::cout << " [FAIL] : in np_test_functional_iteration() : nditer_find failed"; throw std::runtime_error("np_test_functional_iteration failed"); } // Test nditer_count size_t count = numpy::nditer_count(arr, [](double val) { return val > 2.0; }); if (count != 4) { // 3, 4, 5, 6 std::cout << " [FAIL] : in np_test_functional_iteration() : nditer_count wrong"; throw std::runtime_error("np_test_functional_iteration failed"); .. _example-top_level-nditer_reduce-1462: .. dropdown:: nditer_reduce (np_test_2_all.cpp:3882) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3872 :emphasize-lines: 11 throw std::runtime_error(description); } } if (!(enum_count == 6)) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(enum_count == 6)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test functional iteration double sum = nditer_reduce(arr, [](double a, double b) { return a + b; }, 0.0); if (!(isApproxEqualMCO(sum, 15.0))) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqualMCO(sum, 15.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } size_t positive_count = nditer_count(arr, [](double x) { return x > 2.0; }); if (!(positive_count == 3)) { std::string description = std::string("testIterators():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(positive_count == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-ndpointer-1463: .. dropdown:: ndpointer (np_test_1_all.cpp:26697) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26687 :emphasize-lines: 11 if (!(lib == nullptr)) { std::string description = std::string("test_ctypes_interop():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(lib == nullptr)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ load_library() (stub)" << std::endl; } // Test ndpointer { auto ptr_desc = numpy::ctypeslib::ndpointer(2, { 10, 10 }); auto arr = NDArray({ 10, 10 }, 0.0); bool matches = ptr_desc.matches(arr); if (!(matches)) { std::string description = std::string("test_ctypes_interop():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(matches)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ ndpointer()" << std::endl; } .. _example-top_level-ndtr-1464: .. dropdown:: ndtr (np_test_1_all.cpp:10796) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10786 :emphasize-lines: 11 } void testSpecialStatisticalFunctions() { std::cout << "========= testStatisticalFunctions ===="; // Test normal distribution functions using NDArray with MKL backend NDArray ndtr_test({ 3 }); ndtr_test.setElementAt({ 0 }, 0.0); ndtr_test.setElementAt({ 1 }, -std::numeric_limits::infinity()); ndtr_test.setElementAt({ 2 }, std::numeric_limits::infinity()); auto ndtr_result = special::ndtr(ndtr_test, MathBackend::MKL); if (!(isApproxEqual(ndtr_result.getElementAt({ 0 }), 0.5, 1e-10))) { std::string description = std::string("testSpecialStatisticalFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ndtr_result.getElementAt({ 0 }), 0.5, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(ndtr_result.getElementAt({ 1 }), 0.0, 1e-10))) { std::string description = std::string("testSpecialStatisticalFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ndtr_result.getElementAt({ 1 }), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-ndtri-1465: .. dropdown:: ndtri (np_test_1_all.cpp:10815) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10805 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(ndtr_result.getElementAt({ 2 }), 1.0, 1e-10))) { std::string description = std::string("testSpecialStatisticalFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ndtr_result.getElementAt({ 2 }), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Normal CDF basic values\n"; // Test ndtri (inverse normal CDF) using NDArray with MKL backend NDArray ndtri_test({ 1 }); ndtri_test.setElementAt({ 0 }, 0.5); auto ndtri_result = special::ndtri(ndtri_test, MathBackend::MKL); if (!(isApproxEqual(ndtri_result.getElementAt({ 0 }), 0.0, 1e-6))) { std::string description = std::string("testSpecialStatisticalFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(ndtri_result.getElementAt({ 0 }), 0.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Inverse normal CDF basic functionality\n"; .. _example-top_level-nested_iters-1466: .. dropdown:: nested_iters (np_test_2_all.cpp:22552) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22542 :emphasize-lines: 11 catch (const std::exception& e) { std::cout << "[FAIL] <---------- np_test_iterable test suite failed with exception: " << e.what(); return 1; } return 0; } } // namespace numpy_tests // Comprehensive test suite for np.nested_iters() // // This file tests the nested_iters() functionality including: // - Basic nested iteration over multiple axes // - Multi-level nesting // - Broadcasting support // - Reset functionality // - Value access through iterators #include #include .. _example-top_level-nested_iters-1467: .. dropdown:: nested_iters (np_test_2_all.cpp:22552) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22542 :emphasize-lines: 11 catch (const std::exception& e) { std::cout << "[FAIL] <---------- np_test_iterable test suite failed with exception: " << e.what(); return 1; } return 0; } } // namespace numpy_tests // Comprehensive test suite for np.nested_iters() // // This file tests the nested_iters() functionality including: // - Basic nested iteration over multiple axes // - Multi-level nesting // - Broadcasting support // - Reset functionality // - Value access through iterators #include #include .. _example-top_level-nested_iters_2-1468: .. dropdown:: nested_iters_2 (np_test_2_all.cpp:22677) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22667 :emphasize-lines: 11 // ============================================================================ // CONVENIENCE FUNCTION TESTS // ============================================================================ void np_test_nested_iters_convenience() { std::cout << "========= nested_iters: convenience function nested_iters_2 ======================="; numpy::NDArray arr({ 5, 6 }); // Use convenience function auto iters = numpy::nested_iters_2(arr, { 0 }, { 1 }); auto& outer = iters[0]; auto& inner = iters[1]; if (outer.size() != 5 || inner.size() != 6) { std::cout << " [FAIL] : Convenience function sizes incorrect"; throw std::runtime_error("np_test_nested_iters_convenience failed"); } // Verify can iterate size_t count = 0; .. _example-top_level-nextafter-1469: .. dropdown:: nextafter (np_test_3_all.cpp:19402) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19392 :emphasize-lines: 11 for (size_t i = 0; i < n; ++i) { a[i] = static_cast(i); b[i] = a[i] + 1.0; } mkl::mkl_nextafter_arrays(a.data(), b.data(), result.data(), n); // Verify results for (size_t i = 0; i < n; ++i) { double expected = std::nextafter(a[i], b[i]); if (!(std::abs(result[i] - expected) < 1e-14)) { std::string description = std::string("test_vml_nextafter():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(result[i] - expected) < 1e-14)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // std::cout << " PASSED: nextafter results match std::nextafter\n"; #else // std::cout << " SKIPPED: MKL not available\n"; .. _example-top_level-notmasked_contiguous-1470: .. dropdown:: notmasked_contiguous (np_test_5_all.cpp:4921) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4911 :emphasize-lines: 11 arr.setElementAt({ i }, static_cast(i + 1)); } numpy::MaskedArray ma(arr); // Mask some elements ma.mask_at({ 1 }); // Mask index 1 ma.mask_at({ 2 }); // Mask index 2 ma.mask_at({ 5 }); // Mask index 5 // Find contiguous regions auto contiguous_regions = numpy::notmasked_contiguous(ma); // Expected regions: [0:1], [3:5], [6:8] if (contiguous_regions.size() != 3) { std::cout << " [FAIL] : in np_test_notmasked_contiguous() : Expected 3 regions, got " << contiguous_regions.size(); throw std::runtime_error("Test failed"); } // Test with no mask numpy::NDArray arr2({ 5 }); for (size_t i = 0; i < 5; ++i) { .. _example-top_level-now-1471: .. dropdown:: now (np_test_1_all.cpp:3611) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3601 :emphasize-lines: 11 void test_broadcasting_performance() { std::cout << "========= test_broadcasting_performance ======================="; // std::cout << "Testing broadcasting performance..." << std::endl; // Create larger arrays for performance testing auto large_arr = NDArray::createOnes({100, 100}); auto broadcast_arr = NDArray::createOnes({1, 100}); // Time the operation (basic timing) auto start = std::chrono::high_resolution_clock::now(); auto result = large_arr.addArrays(broadcast_arr); auto end = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast(end - start); // std::cout << "Large array broadcasting took " << duration.count() << " microseconds" << std::endl; // Verify result shape if (!((result.getShape() == std::vector{100, 100}))) { std::string description = std::string("test_broadcasting_performance():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((result.getShape() == std::vector{100, 100}))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-nper-1472: .. dropdown:: nper (np_test_3_all.cpp:1332) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1322 :emphasize-lines: 11 double expected_pmt = -1199.10; // Standard mortgage calculation if (!(isApproxEqual(monthly_pmt, expected_pmt, 1.0))) { std::string description = std::string("testBasicTVMFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(monthly_pmt, expected_pmt, 1.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] pmt() calculation: $200k loan at 6% for 30 years = $" << monthly_pmt << std::endl; // Test Number of Periods // Example: How long to pay off $200k with $1200/month at 6% annual? double nper_result = nper(monthly_rate, -1200, 200000); if (!(isApproxEqual(nper_result, 360.0, 5.0))) { std::string description = std::string("testBasicTVMFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(nper_result, 360.0, 5.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] nper() calculation: Time to pay $200k with $1200/month = " << nper_result << " months" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-nper-1473: .. dropdown:: nper (np_test_3_all.cpp:1332) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1322 :emphasize-lines: 11 double expected_pmt = -1199.10; // Standard mortgage calculation if (!(isApproxEqual(monthly_pmt, expected_pmt, 1.0))) { std::string description = std::string("testBasicTVMFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(monthly_pmt, expected_pmt, 1.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] pmt() calculation: $200k loan at 6% for 30 years = $" << monthly_pmt << std::endl; // Test Number of Periods // Example: How long to pay off $200k with $1200/month at 6% annual? double nper_result = nper(monthly_rate, -1200, 200000); if (!(isApproxEqual(nper_result, 360.0, 5.0))) { std::string description = std::string("testBasicTVMFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(nper_result, 360.0, 5.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] nper() calculation: Time to pay $200k with $1200/month = " << nper_result << " months" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-npv-1474: .. dropdown:: npv (np_test_3_all.cpp:1392) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1382 :emphasize-lines: 11 // Test NPV // Example: Initial investment of -$1000, returns of $300 for 4 years at 10% discount rate auto cash_flows = createFloat64Array({ 5 }, 0.0); cash_flows.setElementAt({ 0 }, -1000.0); cash_flows.setElementAt({ 1 }, 300.0); cash_flows.setElementAt({ 2 }, 300.0); cash_flows.setElementAt({ 3 }, 300.0); cash_flows.setElementAt({ 4 }, 300.0); double npv_result = npv(0.10, cash_flows); double expected_npv = -1000 + 300 / 1.1 + 300 / 1.21 + 300 / 1.331 + 300 / 1.4641; if (!(isApproxEqual(npv_result, expected_npv, 0.01))) { std::string description = std::string("testCashFlowFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(npv_result, expected_npv, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] npv() calculation: Project NPV at 10% = $" << npv_result << std::endl; // Test IRR // Same cash flows - should give IRR where NPV = 0 .. _example-top_level-npv-1475: .. dropdown:: npv (np_test_3_all.cpp:1392) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1382 :emphasize-lines: 11 // Test NPV // Example: Initial investment of -$1000, returns of $300 for 4 years at 10% discount rate auto cash_flows = createFloat64Array({ 5 }, 0.0); cash_flows.setElementAt({ 0 }, -1000.0); cash_flows.setElementAt({ 1 }, 300.0); cash_flows.setElementAt({ 2 }, 300.0); cash_flows.setElementAt({ 3 }, 300.0); cash_flows.setElementAt({ 4 }, 300.0); double npv_result = npv(0.10, cash_flows); double expected_npv = -1000 + 300 / 1.1 + 300 / 1.21 + 300 / 1.331 + 300 / 1.4641; if (!(isApproxEqual(npv_result, expected_npv, 0.01))) { std::string description = std::string("testCashFlowFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(npv_result, expected_npv, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] npv() calculation: Project NPV at 10% = $" << npv_result << std::endl; // Test IRR // Same cash flows - should give IRR where NPV = 0 .. _example-top_level-obj2sctype-1476: .. dropdown:: obj2sctype (np_test_3_all.cpp:8997) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8987 :emphasize-lines: 11 if (!issubclass_(DType::COMPLEX128, TypeCategory::COMPLEX_FLOATING)) { std::cerr << "[FAIL] issubclass_(COMPLEX128, COMPLEX_FLOATING) should be true"; throw std::runtime_error("issubclass_ COMPLEX128-COMPLEX_FLOATING test failed"); } // std::cout << "[OK] issubclass_(COMPLEX128, COMPLEX_FLOATING) = true" << std::endl; std::cout << " -> tests passed" << std::endl; } //============================================================================== // Test obj2sctype() - Object to scalar type conversion //============================================================================== void np_test_obj2sctype_type_names() { std::cout << "========= np_test_obj2sctype_type_names ======================="; // Test type name strings if (obj2sctype("int32", DType::FLOAT64) != DType::INT32) { std::cerr << "[FAIL] obj2sctype('int32', FLOAT64) should return INT32"; throw std::runtime_error("obj2sctype int32 test failed"); } .. _example-top_level-os_fspath-1477: .. dropdown:: os_fspath (np_test_1_all.cpp:26870) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26860 :emphasize-lines: 11 } catch (const std::exception& e) { std::cerr << "[FAILURE] Phase 6 test failed: " << e.what(); return 1; } } } // namespace numpy_tests // Phase 5 Utilities Test Suite: typename(), find_duplicate(), recarray(), os_fspath(), get_remaining_size(), newbyteorder() // Tests all 6 Phase 5 implemented functions with comprehensive coverage #include "../numpy/np_ndarray.h" #include "../numpy/np_dtype_utils.h" #include "../numpy/np_recarray.h" #include "../numpy/np_recfunctions.h" #include "../numpy/np_io_utils.h" #include #include #include .. _example-top_level-os_fspath-1478: .. dropdown:: os_fspath (np_test_1_all.cpp:26870) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26860 :emphasize-lines: 11 } catch (const std::exception& e) { std::cerr << "[FAILURE] Phase 6 test failed: " << e.what(); return 1; } } } // namespace numpy_tests // Phase 5 Utilities Test Suite: typename(), find_duplicate(), recarray(), os_fspath(), get_remaining_size(), newbyteorder() // Tests all 6 Phase 5 implemented functions with comprehensive coverage #include "../numpy/np_ndarray.h" #include "../numpy/np_dtype_utils.h" #include "../numpy/np_recarray.h" #include "../numpy/np_recfunctions.h" #include "../numpy/np_io_utils.h" #include #include #include .. _example-top_level-parse_einsum-1479: .. dropdown:: parse_einsum (np_test_4_all.cpp:23541) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23531 :emphasize-lines: 11 std::cout << " -> tests passed\n"; } // Test einsum() parser - Days 5-6 void np_test_phase7_einsum_parser() { std::cout << "========= einsum() parser: Parse Einstein notation ==================\n"; // Test 1: Explicit output - matrix multiplication { auto info = numpy::einsum_internal::parse_einsum("ij,jk->ik", 2); if (info.input_subscripts.size() != 2) { throw std::runtime_error("Parser failed: wrong number of inputs"); } if (info.input_subscripts[0] != "ij" || info.input_subscripts[1] != "jk") { throw std::runtime_error("Parser failed: wrong input subscripts"); } if (info.output_subscript != "ik") { throw std::runtime_error("Parser failed: wrong output subscript"); } .. _example-top_level-parse_mode-1480: .. dropdown:: parse_mode (np_test_3_all.cpp:10514) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10504 :emphasize-lines: 11 } // ============================ // TEST: Memory Map Mode Parsing // ============================ void np_test_io_memmap_mode_parsing() { std::cout << "========= np_test_io_memmap_mode_parsing ======================="; // Test all valid modes if (!(memmap::parse_mode("r") == memmap::MMapMode::READ_ONLY)) { std::string description = std::string("np_test_io_memmap_mode_parsing():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(memmap::parse_mode(\"r\") == memmap::MMapMode::READ_ONLY)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(memmap::parse_mode("r+") == memmap::MMapMode::READ_WRITE)) { std::string description = std::string("np_test_io_memmap_mode_parsing():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(memmap::parse_mode(\"r+\") == memmap::MMapMode::READ_WRITE)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(memmap::parse_mode("w+") == memmap::MMapMode::WRITE)) { .. _example-top_level-phase-1481: .. dropdown:: phase (np_test_3_all.cpp:4286) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4276 :emphasize-lines: 11 void testPhaseAlias() { std::cout << "========= testPhaseAlias ===="; // Test that phase is an alias for angle auto c_arr = NDArray({ 2 }); c_arr.setElementAt({ 0 }, complex128(3.0, 4.0)); c_arr.setElementAt({ 1 }, complex128(-2.0, 3.0)); auto angles = angle(c_arr); auto phases = phase(c_arr); if (!(std::abs(angles.getElementAt({ 0 }) - phases.getElementAt({ 0 })) < 1e-10)) { std::string description = std::string("testPhaseAlias():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(angles.getElementAt({ 0 }) - phases.getElementAt({ 0 })) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::abs(angles.getElementAt({ 1 }) - phases.getElementAt({ 1 })) < 1e-10)) { std::string description = std::string("testPhaseAlias():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(angles.getElementAt({ 1 }) - phases.getElementAt({ 1 })) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-top_level-pmt-1482: .. dropdown:: pmt (np_test_3_all.cpp:1321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1311 :emphasize-lines: 11 if (!(isApproxEqual(pv_result, 1000.0, 0.01))) { std::string description = std::string("testBasicTVMFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(pv_result, 1000.0, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] pv() calculation: PV for $1628.89 in 10 years at 5% = $" << pv_result << std::endl; // Test Payment // Example: Monthly payment for $200,000 loan at 6% annual (0.5% monthly) for 30 years double monthly_rate = 0.06 / 12; double monthly_pmt = pmt(monthly_rate, 30 * 12, 200000); double expected_pmt = -1199.10; // Standard mortgage calculation if (!(isApproxEqual(monthly_pmt, expected_pmt, 1.0))) { std::string description = std::string("testBasicTVMFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(monthly_pmt, expected_pmt, 1.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] pmt() calculation: $200k loan at 6% for 30 years = $" << monthly_pmt << std::endl; // Test Number of Periods // Example: How long to pay off $200k with $1200/month at 6% annual? .. _example-top_level-pmt-1483: .. dropdown:: pmt (np_test_3_all.cpp:1321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1311 :emphasize-lines: 11 if (!(isApproxEqual(pv_result, 1000.0, 0.01))) { std::string description = std::string("testBasicTVMFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(pv_result, 1000.0, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] pv() calculation: PV for $1628.89 in 10 years at 5% = $" << pv_result << std::endl; // Test Payment // Example: Monthly payment for $200,000 loan at 6% annual (0.5% monthly) for 30 years double monthly_rate = 0.06 / 12; double monthly_pmt = pmt(monthly_rate, 30 * 12, 200000); double expected_pmt = -1199.10; // Standard mortgage calculation if (!(isApproxEqual(monthly_pmt, expected_pmt, 1.0))) { std::string description = std::string("testBasicTVMFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(monthly_pmt, expected_pmt, 1.0))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] pmt() calculation: $200k loan at 6% for 30 years = $" << monthly_pmt << std::endl; // Test Number of Periods // Example: How long to pay off $200k with $1200/month at 6% annual? .. _example-top_level-polar-1484: .. dropdown:: polar (np_test_1_all.cpp:7970) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7960 :emphasize-lines: 11 // std::cout << "real(z) = " << z.real() << std::endl; // std::cout << "imag(z) = " << z.imag() << std::endl; // std::cout << "abs(z) = " << std::abs(z) << std::endl; // std::cout << "arg(z) = " << std::arg(z) << " radians" << std::endl; // std::cout << "norm(z) = " << std::norm(z) << std::endl; // std::cout << "conj(z) = " << std::conj(z) << std::endl; // Polar form auto magnitude = std::abs(z); auto phase = std::arg(z); auto polar_z = std::polar(magnitude, phase); // std::cout << "polar form: " << polar_z << std::endl; std::cout << " -> tests passed" << std::endl; } void testComplex256ComparisonsComplex256() { std::cout << "========= testComplex256ComparisonsComplex256 ======================="; complex256 a(3.0L, 4.0L); complex256 b(3.0L, 4.0L); .. _example-top_level-poly1d-1485: .. dropdown:: poly1d (np_test_2_all.cpp:11821) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11811 :emphasize-lines: 11 // ============================================================================ // POLY1D TESTS // ============================================================================ void np_test_poly1d_basic() { std::cout << "========= poly1d: basic construction ======================="; // Test 1: Create polynomial 1*x^2 + 2*x + 3 from NumPy-style coefficients [1, 2, 3] std::vector coeffs = { 1.0, 2.0, 3.0 }; auto p = numpy::poly1d(coeffs); // Coefficients should be stored in ascending order internally: [3, 2, 1] const auto& internal_coeffs = p.coefficients(); auto pass = (internal_coeffs.size() == 3 && close_enough(internal_coeffs[0], 3.0) && close_enough(internal_coeffs[1], 2.0) && close_enough(internal_coeffs[2], 1.0)); if (!pass) { .. _example-top_level-poly1d-1486: .. dropdown:: poly1d (np_test_2_all.cpp:11821) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11811 :emphasize-lines: 11 // ============================================================================ // POLY1D TESTS // ============================================================================ void np_test_poly1d_basic() { std::cout << "========= poly1d: basic construction ======================="; // Test 1: Create polynomial 1*x^2 + 2*x + 3 from NumPy-style coefficients [1, 2, 3] std::vector coeffs = { 1.0, 2.0, 3.0 }; auto p = numpy::poly1d(coeffs); // Coefficients should be stored in ascending order internally: [3, 2, 1] const auto& internal_coeffs = p.coefficients(); auto pass = (internal_coeffs.size() == 3 && close_enough(internal_coeffs[0], 3.0) && close_enough(internal_coeffs[1], 2.0) && close_enough(internal_coeffs[2], 1.0)); if (!pass) { .. _example-top_level-polydiv-1487: .. dropdown:: polydiv (np_test_1_all.cpp:23267) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23257 :emphasize-lines: 11 auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); // x^2 - 1 = (x - 1)(x + 1) + 0 if (!((quotient == std::vector{1, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((quotient == std::vector{1, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!((remainder == std::vector{0}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((remainder == std::vector{0}))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-polydiv-1488: .. dropdown:: polydiv (np_test_1_all.cpp:23267) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23257 :emphasize-lines: 11 auto p_squared = p.power(2); // (1 + x)^2 = 1 + 2x + x^2 if (!((p_squared.coefficients() == std::vector{1, 2, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((p_squared.coefficients() == std::vector{1, 2, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polynomial division std::vector dividend = { -1, 0, 1 }; // x^2 - 1 std::vector divisor = { -1, 1 }; // x - 1 auto [quotient, remainder] = numpy::polydiv(dividend, divisor); // x^2 - 1 = (x - 1)(x + 1) + 0 if (!((quotient == std::vector{1, 1}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((quotient == std::vector{1, 1}))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!((remainder == std::vector{0}))) { std::string description = std::string("test_polynomial_advanced():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((remainder == std::vector{0}))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-polyroots-1489: .. dropdown:: polyroots (np_test_4_all.cpp:19878) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19868 :emphasize-lines: 11 catch (const std::exception& e) { // std::cout << " [INFO] : polyfit function exists (exception: " << e.what() << ")"; } std::cout << " -> tests passed" << std::endl; } void np_test_phase5_roots() { std::cout << "========= roots/polyroots: polynomial root finding ======================="; // Test polyroots() function with simple polynomial: x^2 - 1 = 0 (roots: ±1) // Coefficients: [-1, 0, 1] represents -1 + 0*x + 1*x^2 std::vector coeffs = {-1.0, 0.0, 1.0}; auto roots_poly = numpy::polynomial::polynomial::polyroots(coeffs); if (roots_poly.size() != 2) { throw std::runtime_error("polyroots failed: expected 2 roots"); } // std::cout << " [INFO] : polyroots function defined in numpy/np_polynomial_utils.h" << std::endl; // std::cout << " [INFO] : Uses companion matrix eigenvalue method for root finding" << std::endl; .. _example-top_level-polyval-1490: .. dropdown:: polyval (np_test_1_all.cpp:22931) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22921 :emphasize-lines: 11 // std::cout << "[OK] Polynomial calculus works correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_utilities() { std::cout << "========= test_polynomial_utilities ======================="; // Test polyval std::vector coeffs = { 1, 2, 3 }; // 1 + 2x + 3x^2 if (!(std::abs(numpy::polyval(coeffs, 2.0) - 17.0) < 1e-10)) { std::string description = std::string("test_polynomial_utilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(numpy::polyval(coeffs, 2.0) - 17.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polyder auto deriv_coeffs = numpy::polynomial::polynomial::polyder(coeffs); if (!((deriv_coeffs == std::vector{2, 6}))) { std::string description = std::string("test_polynomial_utilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((deriv_coeffs == std::vector{2, 6}))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-polyval-1491: .. dropdown:: polyval (np_test_1_all.cpp:22931) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22921 :emphasize-lines: 11 // std::cout << "[OK] Polynomial calculus works correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_utilities() { std::cout << "========= test_polynomial_utilities ======================="; // Test polyval std::vector coeffs = { 1, 2, 3 }; // 1 + 2x + 3x^2 if (!(std::abs(numpy::polyval(coeffs, 2.0) - 17.0) < 1e-10)) { std::string description = std::string("test_polynomial_utilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(numpy::polyval(coeffs, 2.0) - 17.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test polyder auto deriv_coeffs = numpy::polynomial::polynomial::polyder(coeffs); if (!((deriv_coeffs == std::vector{2, 6}))) { std::string description = std::string("test_polynomial_utilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((deriv_coeffs == std::vector{2, 6}))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-ppmt-1492: .. dropdown:: ppmt (np_test_3_all.cpp:1436) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1426 :emphasize-lines: 11 // Test ipmt and ppmt for a simple loan double rate = 0.06 / 12; // 6% annual, monthly double nper = 12; // 1 year double pv = 10000; // $10,000 loan double total_payment = pmt(rate, nper, pv); // Test first payment breakdown double first_interest = ipmt(rate, 1, nper, pv); double first_principal = ppmt(rate, 1, nper, pv); // Interest + Principal should equal total payment if (!(isApproxEqual(first_interest + first_principal, total_payment, 0.01))) { std::string description = std::string("testPaymentComponents():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(first_interest + first_principal, total_payment, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ipmt() + ppmt() = total payment for period 1" << std::endl; // First interest payment should be PV * rate .. _example-top_level-ppmt-1493: .. dropdown:: ppmt (np_test_3_all.cpp:1436) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1426 :emphasize-lines: 11 // Test ipmt and ppmt for a simple loan double rate = 0.06 / 12; // 6% annual, monthly double nper = 12; // 1 year double pv = 10000; // $10,000 loan double total_payment = pmt(rate, nper, pv); // Test first payment breakdown double first_interest = ipmt(rate, 1, nper, pv); double first_principal = ppmt(rate, 1, nper, pv); // Interest + Principal should equal total payment if (!(isApproxEqual(first_interest + first_principal, total_payment, 0.01))) { std::string description = std::string("testPaymentComponents():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(first_interest + first_principal, total_payment, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ipmt() + ppmt() = total payment for period 1" << std::endl; // First interest payment should be PV * rate .. _example-top_level-printarray-1494: .. dropdown:: printArray (np_test_1_all.cpp:67) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 57 :emphasize-lines: 11 std::vector indices(arr.getShape().size(), 0); do { if (arr.getElementAt(indices)) { return false; } } while (incrementIndices(indices, arr.getShape())); return true; } template void printArray(const NDArray& arr, const std::string& name) { std::cout << name << ": "; if (arr.getShape().size() == 1) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << arr.getElementAt({i}) << " "; } } // std::cout << std::endl; } // Helper functions for bitwise operations tests .. _example-top_level-printnestedarray-1495: .. dropdown:: printNestedArray (np_test_3_all.cpp:21364) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21354 :emphasize-lines: 11 // Create nested structure numpy::NDArray inner({2}); inner.setElementAt({0}, numpy::object_(1)); inner.setElementAt({1}, numpy::object_(2)); numpy::NDArray outer({2}); outer.setElementAt({0}, numpy::object_(inner)); outer.setElementAt({1}, numpy::object_(std::string("hello"))); // Get print output std::string output = numpy::NestedArray::printNestedArray(outer); // Check output contains expected elements CHECK(output.find("Nested Array Structure") != std::string::npos, "np_test_nested_print", "missing header"); CHECK(output.find("shape=") != std::string::npos, "np_test_nested_print", "missing shape"); std::cout << " -> tests passed" << std::endl; } #undef CHECK .. _example-top_level-print_vsl_status-1496: .. dropdown:: print_vsl_status (np_test_1_all.cpp:14528) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14518 :emphasize-lines: 11 namespace numpy_tests { using namespace numpy::random; void test_vsl_uniform_basic() { std::cout << "========= test_vsl_uniform_basic ===="; // Test basic VSL availability // std::cout << "VSL available: " << (numpy::vsl::is_vsl_available() ? "Yes" : "No") << std::endl; numpy::vsl::print_vsl_status(); #ifdef NUMPY_USE_MKL if (numpy::vsl::is_vsl_available()) { // Test direct VSL uniform auto vsl_arr = numpy::vsl::vsl_uniform(0.0, 1.0, { 100 }); if (!(vsl_arr.getShape()[0] == 100)) { std::string description = std::string("test_vsl_uniform_basic():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(vsl_arr.getShape()[0] == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-printoptions-1497: .. dropdown:: printoptions (np_test_2_all.cpp:21234) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21224 :emphasize-lines: 11 catch (const std::exception& e) { std::cout << "[FAIL] <---------- np_test_show_runtime test suite failed with exception: " << e.what(); return 1; } return 0; } } // namespace numpy_tests // Comprehensive test suite for printoptions() // // This file tests the printoptions() functionality // including context manager and global print options #include #include #include #include "../numpy/np_print_config.h" // IMPORTANT: No using namespace directives to avoid name clashes .. _example-top_level-printoptions-1498: .. dropdown:: printoptions (np_test_2_all.cpp:21234) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21224 :emphasize-lines: 11 catch (const std::exception& e) { std::cout << "[FAIL] <---------- np_test_show_runtime test suite failed with exception: " << e.what(); return 1; } return 0; } } // namespace numpy_tests // Comprehensive test suite for printoptions() // // This file tests the printoptions() functionality // including context manager and global print options #include #include #include #include "../numpy/np_print_config.h" // IMPORTANT: No using namespace directives to avoid name clashes .. _example-top_level-prod-1499: .. dropdown:: prod (np_test_1_all.cpp:11795) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11785 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "[OK] min and max work correctly\n"; // Test product auto small_array = createInt32Array({ 3 }, 0); small_array.setElementAt({ 0 }, 2); small_array.setElementAt({ 1 }, 3); small_array.setElementAt({ 2 }, 4); auto prod_result = prod(small_array); if (!(prod_result.getElementAt({ 0 }) == 24)) { std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(prod_result.getElementAt({ 0 }) == 24)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] prod works correctly\n"; std::cout << " -> tests passed" << std::endl; } void testVarianceAndStandardDeviation() { .. _example-top_level-prod-1500: .. dropdown:: prod (np_test_1_all.cpp:11795) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11785 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "[OK] min and max work correctly\n"; // Test product auto small_array = createInt32Array({ 3 }, 0); small_array.setElementAt({ 0 }, 2); small_array.setElementAt({ 1 }, 3); small_array.setElementAt({ 2 }, 4); auto prod_result = prod(small_array); if (!(prod_result.getElementAt({ 0 }) == 24)) { std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(prod_result.getElementAt({ 0 }) == 24)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] prod works correctly\n"; std::cout << " -> tests passed" << std::endl; } void testVarianceAndStandardDeviation() { .. _example-top_level-product-1501: .. dropdown:: product (np_test_1_all.cpp:5362) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5352 :emphasize-lines: 11 try { auto result = array1.multiplyArrays(array2); std::cout << "[FAIL] Incompatible shape multiplication should have thrown" << std::endl; } catch (const std::invalid_argument& e) { // std::cout << "[OK] Incompatible multiplication properly throws: " << e.what(); } // Test incompatible dot product try { auto result = array1.dotProduct(array2); // 2x3 * 3x2 should actually work // std::cout << "[OK] Compatible dot product (2x3 * 3x2) works" << std::endl; } catch (const std::exception& e) { std::cout << " [FAIL] : in testIncompatibleShapesErrorExtended(): Unexpected dot product error: " << e.what(); throw std::runtime_error("testIncompatibleShapesErrorExtended(): Unexpected dot product error: " + std::string(e.what())); } // Test truly incompatible dot product auto array3 = createInt32Array({2, 2}, 1); try { auto result = array1.dotProduct(array3); // 2x3 * 2x2 should fail std::cout << "[FAIL] Incompatible dot product should have thrown" << std::endl; .. _example-top_level-product-1502: .. dropdown:: product (np_test_1_all.cpp:5362) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5352 :emphasize-lines: 11 try { auto result = array1.multiplyArrays(array2); std::cout << "[FAIL] Incompatible shape multiplication should have thrown" << std::endl; } catch (const std::invalid_argument& e) { // std::cout << "[OK] Incompatible multiplication properly throws: " << e.what(); } // Test incompatible dot product try { auto result = array1.dotProduct(array2); // 2x3 * 3x2 should actually work // std::cout << "[OK] Compatible dot product (2x3 * 3x2) works" << std::endl; } catch (const std::exception& e) { std::cout << " [FAIL] : in testIncompatibleShapesErrorExtended(): Unexpected dot product error: " << e.what(); throw std::runtime_error("testIncompatibleShapesErrorExtended(): Unexpected dot product error: " + std::string(e.what())); } // Test truly incompatible dot product auto array3 = createInt32Array({2, 2}, 1); try { auto result = array1.dotProduct(array3); // 2x3 * 2x2 should fail std::cout << "[FAIL] Incompatible dot product should have thrown" << std::endl; .. _example-top_level-promotetype-1503: .. dropdown:: promoteType (np_test_3_all.cpp:21676) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21666 :emphasize-lines: 11 void np_test_object_arith_promote_helper() { std::cout << "========= promoteType helper ====" ; numpy::object_ int_obj(5); numpy::object_ dbl_obj(3.14); numpy::object_ str_obj(std::string("hello")); numpy::object_ str_obj2(std::string("world")); numpy::object_ null_obj; CHECK(numpy::promoteType(int_obj, int_obj) == 1, "np_test_object_arith_promote_helper", "int+int should be 1"); CHECK(numpy::promoteType(int_obj, dbl_obj) == 2, "np_test_object_arith_promote_helper", "int+dbl should be 2"); CHECK(numpy::promoteType(dbl_obj, int_obj) == 2, "np_test_object_arith_promote_helper", "dbl+int should be 2"); CHECK(numpy::promoteType(dbl_obj, dbl_obj) == 2, "np_test_object_arith_promote_helper", "dbl+dbl should be 2"); CHECK(numpy::promoteType(str_obj, str_obj2) == 3, "np_test_object_arith_promote_helper", "str+str should be 3"); CHECK(numpy::promoteType(null_obj, int_obj) == 0, "np_test_object_arith_promote_helper", "null+int should be 0"); CHECK(numpy::promoteType(int_obj, str_obj) == 0, "np_test_object_arith_promote_helper", "int+str should be 0"); std::cout << " -> tests passed" << std::endl; } .. _example-top_level-psi-1504: .. dropdown:: psi (np_test_5_all.cpp:2140) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2130 :emphasize-lines: 11 std::cout << " [FAIL] : in np_test_gamma_beta_functions() : factorial2(5) = " << fact2_5 << ", expected 15.0"; throw std::runtime_error("factorial2(5) test failed"); } // std::cout << " beta(2,3) = " << beta_2_3 << " (MKL)" << std::endl; // std::cout << " beta(1,1) = " << beta_1_1 << " (MKL)" << std::endl; // std::cout << " lbeta(2,3) = " << lbeta_2_3 << " (MKL)" << std::endl; // std::cout << " factorial(5) = " << fact_5 << " (MKL)" << std::endl; // std::cout << " factorial2(5) = " << fact2_5 << " (scalar)" << std::endl; // std::cout << " Tested: beta(), lbeta(), factorial() with MKL backend, factorial2() scalar" << std::endl; // std::cout << " Note: psi()/digamma() unavailable - Intel MKL doesn't provide it" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_error_function_variants() { std::cout << "========= Testing Error Function Variants ======================="; // Create test input array numpy::NDArray test_vals({ 4 }); test_vals.setElementAt({ 0 }, 0.0); test_vals.setElementAt({ 1 }, 0.5); .. _example-top_level-pv-1505: .. dropdown:: pv (np_test_3_all.cpp:1310) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1300 :emphasize-lines: 11 double expected_fv = 1628.89; // 1000 * (1.05)^10 if (!(isApproxEqual(fv_result, expected_fv, 0.01))) { std::string description = std::string("testBasicTVMFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(fv_result, expected_fv, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] fv() calculation: $1000 at 5% for 10 years = $" << fv_result << std::endl; // Test Present Value // Example: What PV is needed to get $1628.89 in 10 years at 5%? double pv_result = pv(0.05, 10, 0, -1628.89); if (!(isApproxEqual(pv_result, 1000.0, 0.01))) { std::string description = std::string("testBasicTVMFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(pv_result, 1000.0, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] pv() calculation: PV for $1628.89 in 10 years at 5% = $" << pv_result << std::endl; // Test Payment // Example: Monthly payment for $200,000 loan at 6% annual (0.5% monthly) for 30 years double monthly_rate = 0.06 / 12; .. _example-top_level-pv-1506: .. dropdown:: pv (np_test_3_all.cpp:1310) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1300 :emphasize-lines: 11 double expected_fv = 1628.89; // 1000 * (1.05)^10 if (!(isApproxEqual(fv_result, expected_fv, 0.01))) { std::string description = std::string("testBasicTVMFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(fv_result, expected_fv, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] fv() calculation: $1000 at 5% for 10 years = $" << fv_result << std::endl; // Test Present Value // Example: What PV is needed to get $1628.89 in 10 years at 5%? double pv_result = pv(0.05, 10, 0, -1628.89); if (!(isApproxEqual(pv_result, 1000.0, 0.01))) { std::string description = std::string("testBasicTVMFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(pv_result, 1000.0, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] pv() calculation: PV for $1628.89 in 10 years at 5% = $" << pv_result << std::endl; // Test Payment // Example: Monthly payment for $200,000 loan at 6% annual (0.5% monthly) for 30 years double monthly_rate = 0.06 / 12; .. _example-top_level-quick_cosine_benchmark_report-1507: .. dropdown:: quick_cosine_benchmark_report (np_test_2_all.cpp:822) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 812 :emphasize-lines: 11 } if (!(report.find("cos") != std::string::npos)) { std::string description = std::string("testBenchmarkReporting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(report.find(\"cos\") != std::string::npos)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Benchmark reporting working correctly\n"; // Test quick benchmark report auto quick_report = quick_cosine_benchmark_report(50000); if (!(!quick_report.empty())) { std::string description = std::string("testBenchmarkReporting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!quick_report.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(quick_report.find("Quick Cosine Benchmark") != std::string::npos)) { std::string description = std::string("testBenchmarkReporting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quick_report.find(\"Quick Cosine Benchmark\") != std::string::npos)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-radix_sort-1508: .. dropdown:: radix_sort (np_test_1_all.cpp:16681) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16671 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void test_radix_sort() { std::cout << "========= test_radix_sort ======================="; // Test with positive integers std::vector data = { 170, 45, 75, 90, 2, 802, 24, 66 }; std::vector expected = { 2, 24, 45, 66, 75, 90, 170, 802 }; radix_sort(data); if (!(data == expected)) { std::string description = std::string("test_radix_sort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test with negative numbers std::vector neg_data = { -5, 3, -1, 8, -10, 0 }; std::vector neg_expected = { -10, -5, -1, 0, 3, 8 }; .. _example-top_level-rate-1509: .. dropdown:: rate (np_test_3_all.cpp:1348) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1338 :emphasize-lines: 11 // std::cout << "[OK] nper() calculation: Time to pay $200k with $1200/month = " << nper_result << " months" << std::endl; std::cout << " -> tests passed" << std::endl; } void testRateFunction() { std::cout << "========= testRateFunction ======================="; // Test Rate calculation // Example: What rate is needed for $1000 to become $2000 in 10 years with no payments? double rate_result = rate(10, 0, -1000, 2000); double expected_rate = std::log(2.0) / 10.0; // ln(2)/10 ? 0.0693 if (!(isApproxEqual(rate_result, expected_rate, 0.01))) { std::string description = std::string("testRateFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(rate_result, expected_rate, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] rate() calculation: Rate to double money in 10 years = " << rate_result * 100 << "%" << std::endl; // Test rate with payments // Example: Effective rate for $200k loan with $1200/month payments over 30 years .. _example-top_level-rate-1510: .. dropdown:: rate (np_test_3_all.cpp:1348) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1338 :emphasize-lines: 11 // std::cout << "[OK] nper() calculation: Time to pay $200k with $1200/month = " << nper_result << " months" << std::endl; std::cout << " -> tests passed" << std::endl; } void testRateFunction() { std::cout << "========= testRateFunction ======================="; // Test Rate calculation // Example: What rate is needed for $1000 to become $2000 in 10 years with no payments? double rate_result = rate(10, 0, -1000, 2000); double expected_rate = std::log(2.0) / 10.0; // ln(2)/10 ? 0.0693 if (!(isApproxEqual(rate_result, expected_rate, 0.01))) { std::string description = std::string("testRateFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(rate_result, expected_rate, 0.01))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] rate() calculation: Rate to double money in 10 years = " << rate_result * 100 << "%" << std::endl; // Test rate with payments // Example: Effective rate for $200k loan with $1200/month payments over 30 years .. _example-top_level-real-1511: .. dropdown:: real (np_test_1_all.cpp:7960) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7950 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void testComplex256FunctionsComplex256() { std::cout << "========= testComplex256FunctionsComplex256 ======================="; complex256 z(3.0L, 4.0L); // 3 + 4i // std::cout << "z = " << z << std::endl; // std::cout << "real(z) = " << z.real() << std::endl; // std::cout << "imag(z) = " << z.imag() << std::endl; // std::cout << "abs(z) = " << std::abs(z) << std::endl; // std::cout << "arg(z) = " << std::arg(z) << " radians" << std::endl; // std::cout << "norm(z) = " << std::norm(z) << std::endl; // std::cout << "conj(z) = " << std::conj(z) << std::endl; // Polar form auto magnitude = std::abs(z); auto phase = std::arg(z); auto polar_z = std::polar(magnitude, phase); .. _example-top_level-rec_ones-1512: .. dropdown:: rec_ones (np_test_1_all.cpp:21915) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21905 :emphasize-lines: 11 auto dtype = std::make_shared(std::vector>{ {"x", DType::INT32}, { "y", DType::FLOAT64 }, { "flag", DType::BOOL } }); auto zeros_arr = rec_zeros({ 2, 2 }, dtype); // std::cout << "Zeros array (2x2):"; //zeros_arr.printArray(); auto ones_arr = rec_ones({ 1, 3 }, dtype); // std::cout << "Ones array (1x3):"; //ones_arr.printArray(); auto x_val = zeros_arr.getFieldValue({ 0, 0 }, "x"); auto y_val = ones_arr.getFieldValue({ 0, 1 }, "y"); auto flag_val = ones_arr.getFieldValue({ 0, 2 }, "flag"); // std::cout << "Verification:" << std::endl; // std::cout << "Zeros array x[0,0]: " << x_val << " (expected: 0)" << std::endl; // std::cout << "Ones array y[0,1]: " << y_val << " (expected: 1.0)" << std::endl; .. _example-top_level-rec_zeros-1513: .. dropdown:: rec_zeros (np_test_1_all.cpp:21911) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21901 :emphasize-lines: 11 void testZerosOnesCreation() { std::cout << "========= testZerosOnesCreation ======================="; auto dtype = std::make_shared(std::vector>{ {"x", DType::INT32}, { "y", DType::FLOAT64 }, { "flag", DType::BOOL } }); auto zeros_arr = rec_zeros({ 2, 2 }, dtype); // std::cout << "Zeros array (2x2):"; //zeros_arr.printArray(); auto ones_arr = rec_ones({ 1, 3 }, dtype); // std::cout << "Ones array (1x3):"; //ones_arr.printArray(); auto x_val = zeros_arr.getFieldValue({ 0, 0 }, "x"); auto y_val = ones_arr.getFieldValue({ 0, 1 }, "y"); auto flag_val = ones_arr.getFieldValue({ 0, 2 }, "flag"); .. _example-top_level-recarray-1514: .. dropdown:: recarray (np_test_1_all.cpp:26870) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26860 :emphasize-lines: 11 } catch (const std::exception& e) { std::cerr << "[FAILURE] Phase 6 test failed: " << e.what(); return 1; } } } // namespace numpy_tests // Phase 5 Utilities Test Suite: typename(), find_duplicate(), recarray(), os_fspath(), get_remaining_size(), newbyteorder() // Tests all 6 Phase 5 implemented functions with comprehensive coverage #include "../numpy/np_ndarray.h" #include "../numpy/np_dtype_utils.h" #include "../numpy/np_recarray.h" #include "../numpy/np_recfunctions.h" #include "../numpy/np_io_utils.h" #include #include #include .. _example-top_level-recfromcsv-1515: .. dropdown:: recfromcsv (np_test_2_all.cpp:18616) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18606 :emphasize-lines: 11 // ============================================================================ // RECFROMCSV TESTS // ============================================================================ void np_test_io_extensions_recfromcsv_basic() { std::cout << "========= recfromcsv: basic CSV loading ======================="; create_csv_file("test_basic.csv"); auto data = numpy::io::recfromcsv(csv_test_dir + "test_basic.csv"); // Verify shape if (data.getShape()[0] != 3) { std::cout << " [FAIL] : in np_test_io_extensions_recfromcsv_basic() : Expected 3 rows, got " << data.getShape()[0] << std::endl; throw std::runtime_error("np_test_io_extensions_recfromcsv_basic failed: wrong row count"); } // Verify field count auto dtype = data.getDType(); .. _example-top_level-recfromtxt-1516: .. dropdown:: recfromtxt (np_test_2_all.cpp:18733) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18723 :emphasize-lines: 11 // ============================================================================ // RECFROMTXT TESTS // ============================================================================ void np_test_io_extensions_recfromtxt_whitespace() { std::cout << "========= recfromtxt: whitespace delimiter ======================="; create_txt_file("test_whitespace.txt"); auto data = numpy::io::recfromtxt( csv_test_dir + "test_whitespace.txt", { "name", "age", "salary", "active" } ); // Verify shape if (data.getShape()[0] != 3) { std::cout << " [FAIL] : Expected 3 rows"; throw std::runtime_error("np_test_io_extensions_recfromtxt_whitespace failed: wrong row count"); } .. _example-top_level-reduce-1517: .. dropdown:: reduce (np_test_3_all.cpp:946) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 936 :emphasize-lines: 11 sum_arr.setElementAt({ 1 }, 2.0); sum_arr.setElementAt({ 2 }, 3.0); sum_arr.setElementAt({ 3 }, 4.0); // Convert to object array for reduce numpy::NDArray obj_sum_arr({ 4 }); for (size_t i = 0; i < 4; ++i) { obj_sum_arr.setElementAt({ i }, std::any{ sum_arr.getElementAt({i}) }); } auto reduce_result = ufunc_sum.reduce(obj_sum_arr); double final_sum = std::any_cast(reduce_result); if (std::abs(final_sum - 10.0) > 1e-10) { std::cout << "[FAIL] Reduce method failed"; return 1; } // std::cout << "[OK] Reduce method works correctly" << std::endl; std::cout << " -> tests passed" << std::endl; return 0; .. _example-top_level-rename_fields-1518: .. dropdown:: rename_fields (np_test_1_all.cpp:21742) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21732 :emphasize-lines: 11 } // std::cout << std::endl; // std::cout << "Field structure: " << get_fieldstructure(base) << std::endl; auto dropped = drop_fields(base, { "score" }); // std::cout << "After dropping 'score' field:"; //dropped.printArray(); std::unordered_map rename_map = { {"name", "student_name"} }; auto renamed = rename_fields(base, rename_map); // std::cout << "After renaming 'name' to 'student_name':" << std::endl; //renamed.printArray(); std::cout << " -> tests passed" << std::endl; } void testRecFunctionsMergeStack() { std::cout << "========= testRecFunctionsMergeStack ======================="; auto dtype1 = std::make_shared(std::vector>{ .. _example-top_level-repack_fields-1519: .. dropdown:: repack_fields (np_test_1_all.cpp:21867) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21857 :emphasize-lines: 11 // std::cout << "Array with duplicates:" << std::endl; //arr.printArray(); auto duplicates = find_duplicates(arr, "id"); // std::cout << "Duplicate indices based on 'id' field: "; for (size_t idx : duplicates) { // std::cout << idx << " "; } // std::cout << std::endl; auto repacked = repack_fields(arr, false); // std::cout << "Repacked array:" << std::endl; //repacked.printArray(); std::cout << " -> tests passed" << std::endl; } void testStringParsing() { std::cout << "========= testStringParsing ======================="; auto dtype = std::make_shared(std::vector>{ .. _example-top_level-replace-1520: .. dropdown:: replace (np_test_1_all.cpp:6717) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6707 :emphasize-lines: 11 std::vector text = {"Hello world", "The world is big", "world peace"}; auto arr = array<64>(text); // std::cout << "Original text:" << std::endl; for (size_t i = 0; i < arr.size(); ++i) { // std::cout << "'" << arr[i] << "'"; } // Test replace auto replaced = replace(arr, "world", "universe"); // std::cout << "After replacing 'world' with 'universe':" << std::endl; for (size_t i = 0; i < replaced.size(); ++i) { // std::cout << "'" << replaced[i] << "'"; } // Test replace with count limit std::vector repeated_text = {"test test test", "more test cases", "test everything"}; auto repeated_arr = array<64>(repeated_text); auto limited_replace = replace(repeated_arr, "test", "example", 1); .. _example-top_level-replace-1521: .. dropdown:: replace (np_test_1_all.cpp:6717) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6707 :emphasize-lines: 11 std::vector text = {"Hello world", "The world is big", "world peace"}; auto arr = array<64>(text); // std::cout << "Original text:" << std::endl; for (size_t i = 0; i < arr.size(); ++i) { // std::cout << "'" << arr[i] << "'"; } // Test replace auto replaced = replace(arr, "world", "universe"); // std::cout << "After replacing 'world' with 'universe':" << std::endl; for (size_t i = 0; i < replaced.size(); ++i) { // std::cout << "'" << replaced[i] << "'"; } // Test replace with count limit std::vector repeated_text = {"test test test", "more test cases", "test everything"}; auto repeated_arr = array<64>(repeated_text); auto limited_replace = replace(repeated_arr, "test", "example", 1); .. _example-top_level-replace-1522: .. dropdown:: replace (np_test_1_all.cpp:6717) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6707 :emphasize-lines: 11 std::vector text = {"Hello world", "The world is big", "world peace"}; auto arr = array<64>(text); // std::cout << "Original text:" << std::endl; for (size_t i = 0; i < arr.size(); ++i) { // std::cout << "'" << arr[i] << "'"; } // Test replace auto replaced = replace(arr, "world", "universe"); // std::cout << "After replacing 'world' with 'universe':" << std::endl; for (size_t i = 0; i < replaced.size(); ++i) { // std::cout << "'" << replaced[i] << "'"; } // Test replace with count limit std::vector repeated_text = {"test test test", "more test cases", "test everything"}; auto repeated_arr = array<64>(repeated_text); auto limited_replace = replace(repeated_arr, "test", "example", 1); .. _example-top_level-reset_printoptions-1523: .. dropdown:: reset_printoptions (np_test_3_all.cpp:10094) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10084 :emphasize-lines: 11 } // std::cout << "Sign: " << opts.sign << std::endl; if (!(opts.sign == "+")) { std::string description = std::string("np_test_io_string_printoptions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(opts.sign == \"+\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Reset and verify reset_printoptions(); opts = get_printoptions(); // std::cout << "After reset - Precision: " << opts.precision << std::endl; if (!(opts.precision == 8)) { std::string description = std::string("np_test_io_string_printoptions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(opts.precision == 8)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Restore original options PrintOptionsManager::set(original); .. _example-top_level-riccati_jn-1524: .. dropdown:: riccati_jn (np_test_1_all.cpp:16110) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16100 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(spherical_kn(0, 1.0) > 0)) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(spherical_kn(0, 1.0) > 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Modified spherical Bessel k_n\n"; // Test Riccati-Bessel functions if (!(isApproxEqual(riccati_jn(0, 0.0), 0.0, 1e-10))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(riccati_jn(0, 0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(riccati_jn(0, 1.0)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(riccati_jn(0, 1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(riccati_yn(0, 1.0)))) { .. _example-top_level-riccati_jn-1525: .. dropdown:: riccati_jn (np_test_1_all.cpp:16110) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16100 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(spherical_kn(0, 1.0) > 0)) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(spherical_kn(0, 1.0) > 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Modified spherical Bessel k_n\n"; // Test Riccati-Bessel functions if (!(isApproxEqual(riccati_jn(0, 0.0), 0.0, 1e-10))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(riccati_jn(0, 0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(riccati_jn(0, 1.0)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(riccati_jn(0, 1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(riccati_yn(0, 1.0)))) { .. _example-top_level-riccati_yn-1526: .. dropdown:: riccati_yn (np_test_1_all.cpp:16120) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16110 :emphasize-lines: 11 if (!(isApproxEqual(riccati_jn(0, 0.0), 0.0, 1e-10))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(riccati_jn(0, 0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(riccati_jn(0, 1.0)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(riccati_jn(0, 1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(riccati_yn(0, 1.0)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(riccati_yn(0, 1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Riccati-Bessel functions\n"; // Test array operations auto x = createFloat64Array({ 3 }, 0.0); x.setElementAt({ 0 }, 0.1); x.setElementAt({ 1 }, 1.0); .. _example-top_level-riccati_yn-1527: .. dropdown:: riccati_yn (np_test_1_all.cpp:16120) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16110 :emphasize-lines: 11 if (!(isApproxEqual(riccati_jn(0, 0.0), 0.0, 1e-10))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(riccati_jn(0, 0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(riccati_jn(0, 1.0)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(riccati_jn(0, 1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(riccati_yn(0, 1.0)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(riccati_yn(0, 1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Riccati-Bessel functions\n"; // Test array operations auto x = createFloat64Array({ 3 }, 0.0); x.setElementAt({ 0 }, 0.1); x.setElementAt({ 1 }, 1.0); .. _example-top_level-ridge_regression-1528: .. dropdown:: ridge_regression (np_test_2_all.cpp:7760) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7750 :emphasize-lines: 11 //A.printArray(); // std::cout << "Vector b:" << std::endl; //b.printArray(); // Test without regularization auto normal_result = lstsq(A, b); // std::cout << "Normal least squares solution:" << std::endl; //normal_result.x.printArray(); // Test with regularization auto ridge_result = ridge_regression(A, b, 0.1); // std::cout << "Ridge regression solution (alpha=0.1):" << std::endl; //ridge_result.x.printArray(); // std::cout << "Method: " << ridge_result.method << std::endl; // Ridge solution should be more stable (smaller norm) double normal_norm = 0.0, ridge_norm = 0.0; for (size_t i = 0; i < 2; ++i) { double normal_val = normal_result.x.getElementAt({ i, 0 }); double ridge_val = ridge_result.x.getElementAt({ i, 0 }); normal_norm += normal_val * normal_val; .. _example-top_level-rjust-1529: .. dropdown:: rjust (np_test_1_all.cpp:6604) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6594 :emphasize-lines: 11 } // Test ljust auto left_just = ljust(arr, 8, '-'); // std::cout << "Left justified (width=8, fill='-'):" << std::endl; for (size_t i = 0; i < left_just.size(); ++i) { // std::cout << "'" << left_just[i] << "'"; } // Test rjust auto right_just = rjust(arr, 8, '+'); // std::cout << "Right justified (width=8, fill='+'):" << std::endl; for (size_t i = 0; i < right_just.size(); ++i) { // std::cout << "'" << right_just[i] << "'"; } // Test zfill with numbers std::vector numbers = {"42", "-17", "+99"}; auto num_arr = array<32>(numbers); auto zero_filled = zfill(num_arr, 6); // std::cout << "Zero filled numbers (width=6):" << std::endl; .. _example-top_level-rjust-1530: .. dropdown:: rjust (np_test_1_all.cpp:6604) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6594 :emphasize-lines: 11 } // Test ljust auto left_just = ljust(arr, 8, '-'); // std::cout << "Left justified (width=8, fill='-'):" << std::endl; for (size_t i = 0; i < left_just.size(); ++i) { // std::cout << "'" << left_just[i] << "'"; } // Test rjust auto right_just = rjust(arr, 8, '+'); // std::cout << "Right justified (width=8, fill='+'):" << std::endl; for (size_t i = 0; i < right_just.size(); ++i) { // std::cout << "'" << right_just[i] << "'"; } // Test zfill with numbers std::vector numbers = {"42", "-17", "+99"}; auto num_arr = array<32>(numbers); auto zero_filled = zfill(num_arr, 6); // std::cout << "Zero filled numbers (width=6):" << std::endl; .. _example-top_level-rjust-1531: .. dropdown:: rjust (np_test_1_all.cpp:6604) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6594 :emphasize-lines: 11 } // Test ljust auto left_just = ljust(arr, 8, '-'); // std::cout << "Left justified (width=8, fill='-'):" << std::endl; for (size_t i = 0; i < left_just.size(); ++i) { // std::cout << "'" << left_just[i] << "'"; } // Test rjust auto right_just = rjust(arr, 8, '+'); // std::cout << "Right justified (width=8, fill='+'):" << std::endl; for (size_t i = 0; i < right_just.size(); ++i) { // std::cout << "'" << right_just[i] << "'"; } // Test zfill with numbers std::vector numbers = {"42", "-17", "+99"}; auto num_arr = array<32>(numbers); auto zero_filled = zfill(num_arr, 6); // std::cout << "Zero filled numbers (width=6):" << std::endl; .. _example-top_level-roots-1532: .. dropdown:: roots (np_test_1_all.cpp:23043) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 23033 :emphasize-lines: 11 // std::cout << "[OK] Polynomial fitting works correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_polynomial_roots() { std::cout << "========= test_polynomial_roots ======================="; // Test quadratic: x^2 - 1 = (x-1)(x+1), roots should be ±1 numpy::Polynomial quad({ -1, 0, 1 }); auto roots = quad.roots(); // TODO: Fix root finding algorithm - temporarily disabled // assert(roots.size() == 2); // Sort roots by real part std::sort(roots.begin(), roots.end(), [](const std::complex& a, const std::complex& b) { return a.real() < b.real(); }); .. _example-top_level-rpartition-1533: .. dropdown:: rpartition (np_test_5_all.cpp:1358) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1348 :emphasize-lines: 11 } std::cout << " -> tests passed" << std::endl; } void np_test_string_rpartition() { std::cout << "========= rpartition operation ======================="; std::vector strings = { "hello-world-test", "a-b-c" }; auto arr = numpy::char_::array<32>(strings); auto result = numpy::char_::rpartition(arr, "-"); // Returns tuple of 3 CharArrays: (before, separator, after) // Verify tuple has 3 elements bool passed = true; if (!passed) { std::cout << " [FAIL] : in np_test_string_rpartition() : rpartition failed"; throw std::runtime_error("np_test_string_rpartition failed"); } .. _example-top_level-rpartition-1534: .. dropdown:: rpartition (np_test_5_all.cpp:1358) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1348 :emphasize-lines: 11 } std::cout << " -> tests passed" << std::endl; } void np_test_string_rpartition() { std::cout << "========= rpartition operation ======================="; std::vector strings = { "hello-world-test", "a-b-c" }; auto arr = numpy::char_::array<32>(strings); auto result = numpy::char_::rpartition(arr, "-"); // Returns tuple of 3 CharArrays: (before, separator, after) // Verify tuple has 3 elements bool passed = true; if (!passed) { std::cout << " [FAIL] : in np_test_string_rpartition() : rpartition failed"; throw std::runtime_error("np_test_string_rpartition failed"); } .. _example-top_level-rsplit-1535: .. dropdown:: rsplit (np_test_5_all.cpp:1377) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1367 :emphasize-lines: 11 } std::cout << " -> tests passed" << std::endl; } void np_test_string_rsplit() { std::cout << "========= rsplit operation ======================="; std::vector strings = { "hello world test", "a b c d" }; auto arr = numpy::char_::array<32>(strings); auto result = numpy::char_::rsplit(arr, " ", 1); // Returns vector of CharArrays bool passed = (result.size() > 0); if (!passed) { std::cout << " [FAIL] : in np_test_string_rsplit() : rsplit returned empty result"; throw std::runtime_error("np_test_string_rsplit failed"); } std::cout << " -> tests passed" << std::endl; .. _example-top_level-rsplit-1536: .. dropdown:: rsplit (np_test_5_all.cpp:1377) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1367 :emphasize-lines: 11 } std::cout << " -> tests passed" << std::endl; } void np_test_string_rsplit() { std::cout << "========= rsplit operation ======================="; std::vector strings = { "hello world test", "a b c d" }; auto arr = numpy::char_::array<32>(strings); auto result = numpy::char_::rsplit(arr, " ", 1); // Returns vector of CharArrays bool passed = (result.size() > 0); if (!passed) { std::cout << " [FAIL] : in np_test_string_rsplit() : rsplit returned empty result"; throw std::runtime_error("np_test_string_rsplit failed"); } std::cout << " -> tests passed" << std::endl; .. _example-top_level-rstrip-1537: .. dropdown:: rstrip (np_test_1_all.cpp:6648) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6638 :emphasize-lines: 11 } // Test lstrip auto left_stripped = lstrip(arr); // std::cout << "After lstrip():" << std::endl; for (size_t i = 0; i < left_stripped.size(); ++i) { // std::cout << "'" << left_stripped[i] << "'"; } // Test rstrip auto right_stripped = rstrip(arr); // std::cout << "After rstrip():" << std::endl; for (size_t i = 0; i < right_stripped.size(); ++i) { // std::cout << "'" << right_stripped[i] << "'"; } std::cout << " -> tests passed" << std::endl; } void testStringComparisonCharArray() { std::cout << "========= testStringComparison ======================="; .. _example-top_level-rstrip-1538: .. dropdown:: rstrip (np_test_1_all.cpp:6648) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6638 :emphasize-lines: 11 } // Test lstrip auto left_stripped = lstrip(arr); // std::cout << "After lstrip():" << std::endl; for (size_t i = 0; i < left_stripped.size(); ++i) { // std::cout << "'" << left_stripped[i] << "'"; } // Test rstrip auto right_stripped = rstrip(arr); // std::cout << "After rstrip():" << std::endl; for (size_t i = 0; i < right_stripped.size(); ++i) { // std::cout << "'" << right_stripped[i] << "'"; } std::cout << " -> tests passed" << std::endl; } void testStringComparisonCharArray() { std::cout << "========= testStringComparison ======================="; .. _example-top_level-safe_divide-1539: .. dropdown:: safe_divide (np_test_2_all.cpp:7338) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7328 :emphasize-lines: 11 // Test zero check bool is_zero_result = is_zero(1e-16); if (!(is_zero_result == true)) { std::string description = std::string("test_basic_utilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(is_zero_result == true)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Is 1e-16 zero? " << (is_zero_result ? "Yes" : "No") << std::endl; // Test safe divide double safe_result = safe_divide(1.0, 2.0); if (!(safe_result == 0.5)) { std::string description = std::string("test_basic_utilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(safe_result == 0.5)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Safe divide 1/2: " << safe_result << std::endl; // Test hypot double hypot_result = hypot_safe(3.0, 4.0); if (!(std::abs(hypot_result - 5.0) < 1e-10)) { .. _example-top_level-safe_eval-1540: .. dropdown:: safe_eval (np_test_1_all.cpp:26441) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26431 :emphasize-lines: 11 { std::string type_name = numpy::lib::typename_(); if (!(!type_name.empty())) { std::string description = std::string("test_lib_aliases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!type_name.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ numpy::lib::typename_() = " << type_name << std::endl; } // Test safe_eval (should throw) { bool threw = false; try { numpy::lib::safe_eval("1+1"); } catch (const std::runtime_error&) { threw = true; } if (!(threw)) { std::string description = std::string("test_lib_aliases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(threw)"; .. _example-top_level-safe_eval-1541: .. dropdown:: safe_eval (np_test_1_all.cpp:26441) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26431 :emphasize-lines: 11 { std::string type_name = numpy::lib::typename_(); if (!(!type_name.empty())) { std::string description = std::string("test_lib_aliases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!type_name.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ numpy::lib::typename_() = " << type_name << std::endl; } // Test safe_eval (should throw) { bool threw = false; try { numpy::lib::safe_eval("1+1"); } catch (const std::runtime_error&) { threw = true; } if (!(threw)) { std::string description = std::string("test_lib_aliases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(threw)"; .. _example-top_level-scale_row-1542: .. dropdown:: scale_row (np_test_5_all.cpp:2953) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2943 :emphasize-lines: 11 // std::cout << " swap_rows: row 0 and row 1 swapped correctly" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_linalg_scale_row() { std::cout << "========= scale_row helper ======================="; // Create matrix: [[1, 2, 3], [4, 5, 6]] std::vector matrix = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; numpy::linalg::utils::scale_row(matrix.data(), 3, 0, 2.0); // After scale: [[2, 4, 6], [4, 5, 6]] bool passed = is_close(matrix[0], 2.0) && is_close(matrix[1], 4.0) && is_close(matrix[2], 6.0); if (!passed) { std::cout << " [FAIL] : in np_test_linalg_scale_row() : row not scaled correctly"; throw std::runtime_error("np_test_linalg_scale_row failed: incorrect scale"); } // std::cout << " scale_row: row 0 scaled by 2.0 correctly" << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-top_level-schur-1543: .. dropdown:: schur (np_test_1_all.cpp:27198) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27188 :emphasize-lines: 11 for (size_t i = 0; i < a_flat.getSize(); ++i) { if (!is_close(a_flat.getElementAt({ i }), b_flat.getElementAt({ i }), tol)) { return false; } } return true; } // ============================ // PHASE 4A: SCHUR DECOMPOSITION TESTS // TEMPORARILY DISABLED - compilation issues with schur() visibility // ============================ /* void test_schur_diagonal() { std::cout << "========= schur: diagonal matrix ======================="; NDArray A({3, 3}); A.setElementAt({0, 0}, 1.0); A.setElementAt({1, 1}, 2.0); A.setElementAt({2, 2}, 3.0); .. _example-top_level-schur_decomposition-1544: .. dropdown:: schur_decomposition (np_test_1_all.cpp:20309) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20299 :emphasize-lines: 11 // Test different matrix sizes std::vector sizes = { 3, 5, 8, 10 }; for (size_t n : sizes) { // std::cout << " Testing " << n << "x" << n << " matrix..."; auto matrix = generator.real_matrix_real_eigenvalues(n); benchmark.time_operation([&]() { auto schur_result = schur_decomposition(matrix); // Validate decomposition auto decomp_validation = validator.validate_decomposition(matrix, schur_result); auto orth_validation = validator.validate_orthogonality(schur_result.Q); if (!decomp_validation.passed) { std::cout << " [FAIL] Decomposition validation: " << decomp_validation.error_message; all_passed = false; } .. _example-top_level-sctype2char-1545: .. dropdown:: sctype2char (np_test_3_all.cpp:8212) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8202 :emphasize-lines: 11 using namespace numpy; //============================================================================== // Test sctype2char for integer types //============================================================================== void np_test_sctype2char_signed_integers() { std::cout << "========= np_test_sctype2char_signed_integers ======================="; // Test signed integers if (sctype2char(DType::INT8) != 'b') { std::cerr << "[FAIL] sctype2char(INT8) should return 'b', got '" << sctype2char(DType::INT8) << "'"; throw std::runtime_error("sctype2char INT8 test failed"); } // std::cout << "[OK] sctype2char(INT8) = 'b'" << std::endl; if (sctype2char(DType::INT16) != 'h') { std::cerr << "[FAIL] sctype2char(INT16) should return 'h'"; throw std::runtime_error("sctype2char INT16 test failed"); } // std::cout << "[OK] sctype2char(INT16) = 'h'" << std::endl; .. _example-top_level-setelementat-1546: .. dropdown:: setElementAt (np_test_1_all.cpp:135) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 125 :emphasize-lines: 11 //ones_array.printArray(); std::cout << " -> tests passed" << std::endl; } void testElementAccess() { std::cout << "========= testElementAccess ======================="; auto array = createInt32Array({3, 3}, 0); array.setElementAt({0, 0}, 1); array.setElementAt({0, 1}, 2); array.setElementAt({0, 2}, 3); array.setElementAt({1, 1}, 5); array.setElementAt({2, 2}, 9); // std::cout << "Array after setting elements:" << std::endl; //array.printArray(); // std::cout << "Element at (1,1): " << array.getElementAt({1, 1}) << std::endl; // std::cout << "Element at (2,2): " << array.getElementAt({2, 2}); .. _example-top_level-set_bit_generator-1547: .. dropdown:: set_bit_generator (np_test_1_all.cpp:26738) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26728 :emphasize-lines: 11 std::string description = std::string("test_bitgen_api():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(bitgen->name() == \"MT19937\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ get_bit_generator() = " << bitgen->name() << std::endl; } // Test set_bit_generator with PCG64 { auto pcg = std::make_shared(12345); numpy::random::set_bit_generator(pcg); auto retrieved = numpy::random::get_bit_generator(); if (!(retrieved->name() == "PCG64")) { std::string description = std::string("test_bitgen_api():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(retrieved->name() == \"PCG64\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ set_bit_generator(PCG64)" << std::endl; } .. _example-top_level-set_default_printstyle-1548: .. 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")) { .. _example-top_level-set_module-1549: .. dropdown:: set_module (np_test_1_all.cpp:26639) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26629 :emphasize-lines: 11 { auto arr = numpy::char_::narray<32>({ "hello", "world" }); if (!(arr.size() == 2)) { std::string description = std::string("test_char_extensions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr.size() == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ narray<32>()" << std::endl; } // Test set_module (stub) { numpy::char_::set_module("numpy.char"); // std::cout << " ✓ set_module() (stub)" << std::endl; } // std::cout << " [PASS] Sub-phase 6C complete (3 functions tested)" << std::endl; } // ============================================================================ // SUB-PHASE 6D: C-TYPES INTEROP .. _example-top_level-set_numeric_ops-1550: .. dropdown:: set_numeric_ops (np_test_2_all.cpp:19926) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19916 :emphasize-lines: 11 void np_test_introspection_numeric_ops() { std::cout << "========= numeric_ops: operation registry ======================="; // Test numeric ops std::cout << "\n"; std::unordered_map> ops; ops["custom_add"] = []() { std::cout << " Custom add operation" << std::endl; }; ops["custom_mul"] = []() { std::cout << " Custom mul operation"; }; numpy::introspection::set_numeric_ops(ops); auto retrieved_ops = numpy::introspection::get_numeric_ops(); bool passed = (retrieved_ops.size() == 2); // std::cout << "Numeric ops registered: " << retrieved_ops.size() << " operations" << std::endl; if (!passed) { std::cout << " [FAIL] : in np_test_introspection_numeric_ops() : numeric ops test failed"; throw std::runtime_error("np_test_introspection_numeric_ops failed"); } .. _example-top_level-set_polynomial_precision-1551: .. dropdown:: set_polynomial_precision (np_test_5_all.cpp:8799) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8789 :emphasize-lines: 11 } // =========================== // 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")) { throw std::runtime_error("Missing variable symbol in polynomial"); .. _example-top_level-set_printoptions-1552: .. dropdown:: set_printoptions (np_test_2_all.cpp:21278) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21268 :emphasize-lines: 11 if (default_opts.threshold != 1000) { std::cout << " [FAIL] : in np_test_printoptions_basic() : default threshold should be 1000, got " << default_opts.threshold << std::endl; throw std::runtime_error("np_test_printoptions_basic failed: default threshold incorrect"); } // Set new options numpy::PrintOptions new_opts; new_opts.precision = 3; new_opts.threshold = 500; numpy::set_printoptions(new_opts); // Verify changes auto current_opts = numpy::get_printoptions(); if (current_opts.precision != 3 || current_opts.threshold != 500) { std::cout << " [FAIL] : in np_test_printoptions_basic() : set_printoptions failed\n"; throw std::runtime_error("np_test_printoptions_basic failed: options not set correctly"); } // Restore defaults numpy::set_printoptions(default_opts); .. _example-top_level-set_printoptions-1553: .. dropdown:: set_printoptions (np_test_2_all.cpp:21278) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21268 :emphasize-lines: 11 if (default_opts.threshold != 1000) { std::cout << " [FAIL] : in np_test_printoptions_basic() : default threshold should be 1000, got " << default_opts.threshold << std::endl; throw std::runtime_error("np_test_printoptions_basic failed: default threshold incorrect"); } // Set new options numpy::PrintOptions new_opts; new_opts.precision = 3; new_opts.threshold = 500; numpy::set_printoptions(new_opts); // Verify changes auto current_opts = numpy::get_printoptions(); if (current_opts.precision != 3 || current_opts.threshold != 500) { std::cout << " [FAIL] : in np_test_printoptions_basic() : set_printoptions failed\n"; throw std::runtime_error("np_test_printoptions_basic failed: options not set correctly"); } // Restore defaults numpy::set_printoptions(default_opts); .. _example-top_level-set_state-1554: .. dropdown:: set_state (np_test_1_all.cpp:22363) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22353 :emphasize-lines: 11 } // std::cout << "[OK] Random bytes\n"; // Test state functions std::string state = get_state(); if (!(!state.empty())) { std::string description = std::string("testRandomUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!state.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } set_state(12345); // std::cout << "[OK] State functions\n"; std::cout << " -> tests passed\n"; } void testGeneratorAPI() { std::cout << "========= testGeneratorAPI ===="; // Test modern Generator API auto gen = create_generator(42); .. _example-top_level-set_string_function-1555: .. dropdown:: set_string_function (np_test_3_all.cpp:10324) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10314 :emphasize-lines: 11 // TEST: Custom String Function // ============================ void np_test_io_string_custom_function() { std::cout << "========= np_test_io_string_custom_function ======================="; // Save original repr function auto original_repr = PrintOptionsManager::get_repr_function(); // Set custom repr function set_string_function([](const void* data, const std::vector& shape, DType dtype) -> std::string { return ""; }, true); NDArray arr({ 3 }); arr.setElementAt({ 0 }, 1); arr.setElementAt({ 1 }, 2); arr.setElementAt({ 2 }, 3); std::string result = array_repr(arr); // std::cout << "Custom repr result: " << result << std::endl; .. _example-top_level-set_string_function-1556: .. dropdown:: set_string_function (np_test_3_all.cpp:10324) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10314 :emphasize-lines: 11 // TEST: Custom String Function // ============================ void np_test_io_string_custom_function() { std::cout << "========= np_test_io_string_custom_function ======================="; // Save original repr function auto original_repr = PrintOptionsManager::get_repr_function(); // Set custom repr function set_string_function([](const void* data, const std::vector& shape, DType dtype) -> std::string { return ""; }, true); NDArray arr({ 3 }); arr.setElementAt({ 0 }, 1); arr.setElementAt({ 1 }, 2); arr.setElementAt({ 2 }, 3); std::string result = array_repr(arr); // std::cout << "Custom repr result: " << result << std::endl; .. _example-top_level-set_tril-1557: .. dropdown:: set_tril (np_test_2_all.cpp:15636) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15626 :emphasize-lines: 11 // Create a 4x4 array filled with ones numpy::NDArray arr({ 4, 4 }); for (size_t i = 0; i < 4; ++i) { for (size_t j = 0; j < 4; ++j) { arr.setElementAt({ i, j }, 1); } } // Set lower triangle to 0 numpy::set_tril(arr, 0, 0); // Verify lower triangle is 0 and upper triangle is 1 for (size_t i = 0; i < 4; ++i) { for (size_t j = 0; j < 4; ++j) { int val = arr.getElementAt({ i, j }); if (j <= i) { // Lower triangle (including diagonal) should be 0 if (val != 0) { std::cout << " [FAIL] : in np_test_indexing_triangular_set_tril() : Lower triangle not set correctly at (" << i << "," << j << ")" << std::endl; .. _example-top_level-set_triu-1558: .. dropdown:: set_triu (np_test_2_all.cpp:15676) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15666 :emphasize-lines: 11 // Create a 4x4 array filled with ones numpy::NDArray arr({ 4, 4 }); for (size_t i = 0; i < 4; ++i) { for (size_t j = 0; j < 4; ++j) { arr.setElementAt({ i, j }, 1); } } // Set upper triangle to 0 numpy::set_triu(arr, 0, 0); // Verify upper triangle is 0 and lower triangle is 1 for (size_t i = 0; i < 4; ++i) { for (size_t j = 0; j < 4; ++j) { int val = arr.getElementAt({ i, j }); if (j >= i) { // Upper triangle (including diagonal) should be 0 if (val != 0) { std::cout << " [FAIL] : in np_test_indexing_triangular_set_triu() : Upper triangle not set correctly at (" << i << "," << j << ")" << std::endl; .. _example-top_level-setbufsize-1559: .. dropdown:: setbufsize (np_test_2_all.cpp:19559) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19549 :emphasize-lines: 11 std::cout << " [FAIL] : Default buffer size should be 8192, got " << buf_size; throw std::runtime_error("np_test_getbufsize_default failed"); } std::cout << " -> tests passed" << std::endl; } void np_test_setbufsize() { std::cout << "========= setbufsize: set buffer size ======================="; size_t old_size = numpy::config::setbufsize(16384); if (old_size != 8192) { std::cout << " [FAIL] : Old buffer size should be 8192"; throw std::runtime_error("np_test_setbufsize failed: old size"); } size_t new_size = numpy::config::getbufsize(); if (new_size != 16384) { std::cout << " [FAIL] : New buffer size should be 16384"; .. _example-top_level-seterrobj-1560: .. dropdown:: seterrobj (np_test_2_all.cpp:19518) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19508 :emphasize-lines: 11 std::cout << "========= errobj: get/set error object ======================="; // Create custom error state numpy::config::ErrorState custom_state; custom_state.divide = numpy::config::ErrorMode::Raise; custom_state.over = numpy::config::ErrorMode::Ignore; custom_state.under = numpy::config::ErrorMode::Warn; custom_state.invalid = numpy::config::ErrorMode::Call; // Set error object auto old_obj = numpy::config::seterrobj(custom_state); // Get error object auto new_obj = numpy::config::geterrobj(); if (new_obj.divide != numpy::config::ErrorMode::Raise) { std::cout << " [FAIL] : divide mode incorrect"; throw std::runtime_error("np_test_errobj failed: divide"); } if (new_obj.over != numpy::config::ErrorMode::Ignore) { .. _example-top_level-setflags-1561: .. dropdown:: setflags (np_test_4_all.cpp:22041) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22031 :emphasize-lines: 11 } } // namespace numpy_tests // Comprehensive test suite for Phase 6 NDArray Methods // // This file tests the Phase 6 LOW priority NDArray methods: // - byteswap() - Swap byte order for endianness conversion // - dump() - Serialize array to binary file // - dumps() - Serialize array to byte vector // - setflags() - Set array metadata flags #include #include #include #include #include #include #include "../numpy/np_ndarray.h" // IMPORTANT: No using namespace directives to avoid name clashes .. _example-top_level-shares_memory-1562: .. dropdown:: shares_memory (np_test_2_all.cpp:3736) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3726 :emphasize-lines: 11 } void testMemoryUtils() { std::cout << "Testing memory utilities...\n"; auto arr1 = createFloat64Array({ 3, 4 }); auto arr2 = createFloat64Array({ 3, 4 }); // Test memory sharing checks bool may_share = may_share_memory(arr1, arr2); bool shares = shares_memory(arr1, arr2); // These should be false for different arrays if (!(!may_share || !shares)) { std::string description = std::string("testMemoryUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!may_share || !shares)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test broadcast_to auto small_arr = createFloat64Array({ 1, 3 }); small_arr.setElementAt({ 0, 0 }, 1.0); .. _example-top_level-shi-1563: .. dropdown:: shi (np_test_1_all.cpp:10929) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10919 :emphasize-lines: 11 double ci_1 = ci(1.0); if (!(!std::isnan(ci_1) && std::isfinite(ci_1))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(ci_1) && std::isfinite(ci_1))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Cosine integral basic functionality\n"; // Test hyperbolic integrals if (!(isApproxEqual(shi(0.0), 0.0, 1e-10))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(shi(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(std::isnan(chi(0.0)))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isnan(chi(0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-show_config-1564: .. dropdown:: show_config (np_test_2_all.cpp:19607) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19597 :emphasize-lines: 11 // ======================================================================== // CONFIGURATION DISPLAY TESTS // ======================================================================== void np_test_show_config() { std::cout << "========= show_config: display configuration ======================="; // This is a visual test - just ensure it doesn't crash try { numpy::config::show_config(); } catch (const std::exception& e) { std::cout << " [FAIL] : show_config threw exception: " << e.what(); throw std::runtime_error("np_test_show_config failed"); } std::cout << " -> tests passed" << std::endl; } // ======================================================================== .. _example-top_level-show_config-1565: .. dropdown:: show_config (np_test_2_all.cpp:19607) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19597 :emphasize-lines: 11 // ======================================================================== // CONFIGURATION DISPLAY TESTS // ======================================================================== void np_test_show_config() { std::cout << "========= show_config: display configuration ======================="; // This is a visual test - just ensure it doesn't crash try { numpy::config::show_config(); } catch (const std::exception& e) { std::cout << " [FAIL] : show_config threw exception: " << e.what(); throw std::runtime_error("np_test_show_config failed"); } std::cout << " -> tests passed" << std::endl; } // ======================================================================== .. _example-top_level-show_runtime-1566: .. dropdown:: show_runtime (np_test_2_all.cpp:21078) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21068 :emphasize-lines: 11 else { std::cerr << "========================================" << std::endl; std::cerr << failed_tests << " byte_bounds test(s) FAILED!" << std::endl; std::cerr << "========================================\n" << std::endl; return 1; } } } // namespace numpy_tests // Comprehensive test suite for show_runtime() // // This file tests the show_runtime() functionality // including runtime configuration display #include #include #include #include #include "../numpy/np_runtime_info.h" .. _example-top_level-si-1567: .. dropdown:: si (np_test_1_all.cpp:10898) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10888 :emphasize-lines: 11 } // std::cout << "[OK] Logarithmic integral basic functionality\n"; std::cout << " -> tests passed\n"; } void testTrigonometricIntegrals() { std::cout << "========= testTrigonometricIntegrals ===="; // Test sine integral if (!(isApproxEqual(si(0.0), 0.0, 1e-10))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(si(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Si(π/2) ≈ 1.851937 (approximately) double si_pi2 = si(M_PI / 2.0); if (!(!std::isnan(si_pi2) && std::isfinite(si_pi2))) { std::string description = std::string("testTrigonometricIntegrals():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(si_pi2) && std::isfinite(si_pi2))"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-top_level-sign-1568: .. dropdown:: sign (np_test_2_all.cpp:5803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5793 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] abs function works correctly\n"; // Test sign auto sign_result = sign(values); if (!(sign_result.getElementAt({ 0 }) == -1.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 0 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(sign_result.getElementAt({ 3 }) == 0.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 3 }) == 0.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-sign-1569: .. dropdown:: sign (np_test_2_all.cpp:5803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5793 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] abs function works correctly\n"; // Test sign auto sign_result = sign(values); if (!(sign_result.getElementAt({ 0 }) == -1.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 0 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(sign_result.getElementAt({ 3 }) == 0.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 3 }) == 0.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-sign-1570: .. dropdown:: sign (np_test_2_all.cpp:5803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5793 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] abs function works correctly\n"; // Test sign auto sign_result = sign(values); if (!(sign_result.getElementAt({ 0 }) == -1.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 0 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(sign_result.getElementAt({ 3 }) == 0.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 3 }) == 0.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-sign-1571: .. dropdown:: sign (np_test_2_all.cpp:5803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5793 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] abs function works correctly\n"; // Test sign auto sign_result = sign(values); if (!(sign_result.getElementAt({ 0 }) == -1.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 0 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(sign_result.getElementAt({ 3 }) == 0.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 3 }) == 0.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-sign-1572: .. dropdown:: sign (np_test_2_all.cpp:5803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5793 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] abs function works correctly\n"; // Test sign auto sign_result = sign(values); if (!(sign_result.getElementAt({ 0 }) == -1.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 0 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(sign_result.getElementAt({ 3 }) == 0.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 3 }) == 0.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-sign-1573: .. dropdown:: sign (np_test_2_all.cpp:5803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5793 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] abs function works correctly\n"; // Test sign auto sign_result = sign(values); if (!(sign_result.getElementAt({ 0 }) == -1.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 0 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(sign_result.getElementAt({ 3 }) == 0.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 3 }) == 0.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-sign-1574: .. dropdown:: sign (np_test_2_all.cpp:5803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5793 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] abs function works correctly\n"; // Test sign auto sign_result = sign(values); if (!(sign_result.getElementAt({ 0 }) == -1.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 0 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(sign_result.getElementAt({ 3 }) == 0.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 3 }) == 0.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-sign-1575: .. dropdown:: sign (np_test_2_all.cpp:5803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5793 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] abs function works correctly\n"; // Test sign auto sign_result = sign(values); if (!(sign_result.getElementAt({ 0 }) == -1.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 0 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(sign_result.getElementAt({ 3 }) == 0.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 3 }) == 0.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-sign-1576: .. dropdown:: sign (np_test_2_all.cpp:5803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5793 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] abs function works correctly\n"; // Test sign auto sign_result = sign(values); if (!(sign_result.getElementAt({ 0 }) == -1.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 0 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(sign_result.getElementAt({ 3 }) == 0.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 3 }) == 0.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-sign-1577: .. dropdown:: sign (np_test_2_all.cpp:5803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5793 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] abs function works correctly\n"; // Test sign auto sign_result = sign(values); if (!(sign_result.getElementAt({ 0 }) == -1.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 0 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(sign_result.getElementAt({ 3 }) == 0.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 3 }) == 0.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-sign-1578: .. dropdown:: sign (np_test_2_all.cpp:5803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5793 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] abs function works correctly\n"; // Test sign auto sign_result = sign(values); if (!(sign_result.getElementAt({ 0 }) == -1.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 0 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(sign_result.getElementAt({ 3 }) == 0.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 3 }) == 0.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-sign-1579: .. dropdown:: sign (np_test_2_all.cpp:5803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5793 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] abs function works correctly\n"; // Test sign auto sign_result = sign(values); if (!(sign_result.getElementAt({ 0 }) == -1.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 0 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(sign_result.getElementAt({ 3 }) == 0.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 3 }) == 0.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-sign-1580: .. dropdown:: sign (np_test_2_all.cpp:5803) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5793 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(abs_result.getElementAt({ 6 }), std::abs(3.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] abs function works correctly\n"; // Test sign auto sign_result = sign(values); if (!(sign_result.getElementAt({ 0 }) == -1.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 0 }) == -1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(sign_result.getElementAt({ 3 }) == 0.0)) { std::string description = std::string("testSpecialFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sign_result.getElementAt({ 3 }) == 0.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-top_level-signbit-1581: .. dropdown:: signbit (np_test_1_all.cpp:10279) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10269 :emphasize-lines: 11 using namespace numpy; using namespace numpy::special; namespace { bool isApproxEqual(double a, double b, double tol) { if (std::isnan(a) && std::isnan(b)) return true; if (std::isinf(a) && std::isinf(b) && std::signbit(a) == std::signbit(b)) return true; return std::abs(a - b) < tol || std::abs(a - b) < tol * std::max(std::abs(a), std::abs(b)); } } void testGammaFunctions() { std::cout << "========= testGammaFunctions ===="; // Test gamma function for known values using NDArray with MKL backend .. _example-top_level-signbit-1582: .. dropdown:: signbit (np_test_1_all.cpp:10279) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10269 :emphasize-lines: 11 using namespace numpy; using namespace numpy::special; namespace { bool isApproxEqual(double a, double b, double tol) { if (std::isnan(a) && std::isnan(b)) return true; if (std::isinf(a) && std::isinf(b) && std::signbit(a) == std::signbit(b)) return true; return std::abs(a - b) < tol || std::abs(a - b) < tol * std::max(std::abs(a), std::abs(b)); } } void testGammaFunctions() { std::cout << "========= testGammaFunctions ===="; // Test gamma function for known values using NDArray with MKL backend .. _example-top_level-size-1583: .. dropdown:: size (np_test_1_all.cpp:47) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 37 :emphasize-lines: 11 using namespace numpy; using namespace numpy::benchmark; using namespace numpy::char_; // Helper functions for array comparison tests namespace { const double TOLERANCE = 1e-10; bool allTrue(const NDArray& arr) { std::vector indices(arr.getShape().size(), 0); do { if (!arr.getElementAt(indices)) { return false; } } while (incrementIndices(indices, arr.getShape())); return true; } bool allFalse(const NDArray& arr) { std::vector indices(arr.getShape().size(), 0); .. _example-top_level-skew-1584: .. dropdown:: skew (np_test_1_all.cpp:11422) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11412 :emphasize-lines: 11 std::cout << "========= testDistributionShapeMeasures ======================="; // Test skewness with known data auto normal_data = createFloat32Array({ 5 }, 0.0f); normal_data.setElementAt({ 0 }, 1.0f); normal_data.setElementAt({ 1 }, 2.0f); normal_data.setElementAt({ 2 }, 3.0f); normal_data.setElementAt({ 3 }, 4.0f); normal_data.setElementAt({ 4 }, 5.0f); auto skew_result = skew(normal_data); // std::cout << "Skewness of [1,2,3,4,5]: " << skew_result.getElementAt({ 0 }) << std::endl; // Should be close to 0 for symmetric data if (!(std::abs(skew_result.getElementAt({ 0 })) < 0.1)) { std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(skew_result.getElementAt({ 0 })) < 0.1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Skewness calculation\n"; // Test kurtosis .. _example-top_level-sometrue-1585: .. dropdown:: sometrue (np_test_1_all.cpp:27518) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27508 :emphasize-lines: 11 double max_val = numpy::ma::amax(ma); double min_val = numpy::ma::amin(ma); // std::cout << " ma::amax() result: " << max_val << " (expected: 6)" << std::endl; // std::cout << " ma::amin() result: " << min_val << " (expected: 1)" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_alltrue_sometrue() { std::cout << "========= ma::alltrue() and ma::sometrue(): boolean checks ==="; auto data1 = numpy::array({ 1.0, 2.0, 0.0, 3.0 }); auto mask1 = numpy::array({ false, false, true, false }); auto ma1 = numpy::ma::masked_array(data1, mask1); auto data2 = numpy::array({ 0.0, 0.0, 1.0 }); auto mask2 = numpy::array({ false, false, false }); auto ma2 = numpy::ma::masked_array(data2, mask2); // std::cout << " ma::alltrue([1,2,-,3]): " << (numpy::ma::alltrue(ma1) ? "true" : "false") << " (expected: true)" << std::endl; .. _example-top_level-sometrue-1586: .. dropdown:: sometrue (np_test_1_all.cpp:27518) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27508 :emphasize-lines: 11 double max_val = numpy::ma::amax(ma); double min_val = numpy::ma::amin(ma); // std::cout << " ma::amax() result: " << max_val << " (expected: 6)" << std::endl; // std::cout << " ma::amin() result: " << min_val << " (expected: 1)" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_alltrue_sometrue() { std::cout << "========= ma::alltrue() and ma::sometrue(): boolean checks ==="; auto data1 = numpy::array({ 1.0, 2.0, 0.0, 3.0 }); auto mask1 = numpy::array({ false, false, true, false }); auto ma1 = numpy::ma::masked_array(data1, mask1); auto data2 = numpy::array({ 0.0, 0.0, 1.0 }); auto mask2 = numpy::array({ false, false, false }); auto ma2 = numpy::ma::masked_array(data2, mask2); // std::cout << " ma::alltrue([1,2,-,3]): " << (numpy::ma::alltrue(ma1) ? "true" : "false") << " (expected: true)" << std::endl; .. _example-top_level-source-1587: .. dropdown:: source (np_test_2_all.cpp:19894) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19884 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } // ============================================================================ // SOURCE AND WHO TESTS (STUBS) // ============================================================================ void np_test_introspection_stubs() { std::cout << "========= source/who: stub functions ======================="; // Test source (stub function) int test_var = 42; // std::cout << "Testing source():" << std::endl; numpy::introspection::source(test_var); // Test who (stub function) // std::cout << "Testing who():" << std::endl; numpy::introspection::who("numpy"); bool passed = true; // Stubs should not throw .. _example-top_level-spacing-1588: .. dropdown:: spacing (np_test_5_all.cpp:4596) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4586 :emphasize-lines: 11 std::cout << " [FAIL] : in np_test_isreal() : Array test failed"; throw std::runtime_error("Test failed"); } std::cout << " -> tests passed" << std::endl; } void np_test_spacing() { std::cout << "========= spacing ======================="; // spacing(x) returns the distance to the next adjacent number double val1 = 1.0; double val2 = 0.0; double val3 = 1000.0; double space1 = numpy::spacing(val1); double space2 = numpy::spacing(val2); double space3 = numpy::spacing(val3); // Verify spacing is positive and makes sense if (space1 <= 0 || space2 <= 0 || space3 <= 0) { .. _example-top_level-sparse-1589: .. dropdown:: sparse (np_test_3_all.cpp:20311) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20301 :emphasize-lines: 11 void np_test_sparse_api_norms() { std::cout << "========= high-level API - matrix norms ======================="; numpy::NDArray dense({ 3, 3 }); dense.setElementAt({ 0, 0 }, 2.0); dense.setElementAt({ 0, 1 }, 1.0); dense.setElementAt({ 1, 1 }, 3.0); dense.setElementAt({ 1, 2 }, 1.0); dense.setElementAt({ 2, 2 }, 4.0); auto A = numpy::sparse::sparse(dense); double n1 = numpy::sparse::norm1(A); double ninf = numpy::sparse::norm_inf(A); double nfro = numpy::sparse::norm_fro(A); if (n1 < 0.0 || ninf < 0.0 || nfro < 0.0) { std::cout << " [FAIL] : in np_test_sparse_api_norms() : Norm computation failed"; throw std::runtime_error("np_test_sparse_api_norms failed"); } .. _example-top_level-spearmanr-1590: .. dropdown:: spearmanr (np_test_1_all.cpp:11541) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11531 :emphasize-lines: 11 auto x = createFloat32Array({ 5 }, 0.0f); auto y = createFloat32Array({ 5 }, 0.0f); // Perfect positive correlation x.setElementAt({ 0 }, 1.0f); y.setElementAt({ 0 }, 2.0f); x.setElementAt({ 1 }, 2.0f); y.setElementAt({ 1 }, 4.0f); x.setElementAt({ 2 }, 3.0f); y.setElementAt({ 2 }, 6.0f); x.setElementAt({ 3 }, 4.0f); y.setElementAt({ 3 }, 8.0f); x.setElementAt({ 4 }, 5.0f); y.setElementAt({ 4 }, 10.0f); auto spearman_result = spearmanr(x, &y); // std::cout << "Spearman correlation: " << spearman_result.coefficient << ", p-value: " << spearman_result.pvalue << std::endl; if (!(std::abs(spearman_result.coefficient - 1.0) < 1e-10)) { std::string description = std::string("testCorrelationAnalysis():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(spearman_result.coefficient - 1.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Spearman correlation\n"; // Test Kendall's tau auto kendall_result = kendalltau(x, y); .. _example-top_level-spence-1591: .. dropdown:: spence (np_test_1_all.cpp:11020) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11010 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(isApproxEqual(zetac(3.0), 1.202056903159 - 1, 1e-6))) { std::string description = std::string("testMiscellaneousFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(zetac(3.0), 1.202056903159 - 1, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Riemann zeta function minus 1\n"; // Test dilogarithm (Spence function) if (!(isApproxEqual(spence(0.0), 0.0, 1e-10))) { std::string description = std::string("testMiscellaneousFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(spence(0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(spence(1.0), M_PI * M_PI / 6.0, 1e-6))) { std::string description = std::string("testMiscellaneousFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(spence(1.0), M_PI * M_PI / 6.0, 1e-6))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Dilogarithm (Spence function) basic values\n"; .. _example-top_level-spherical_in-1592: .. dropdown:: spherical_in (np_test_1_all.cpp:16069) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16059 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(!std::isnan(spherical_yn(1, x_pos)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(spherical_yn(1, x_pos)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Spherical Bessel y_n for positive arguments\n"; // Test modified spherical Bessel function i_n if (!(isApproxEqual(spherical_in(0, 0.0), 1.0, 1e-10))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(spherical_in(0, 0.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(spherical_in(1, 0.0), 0.0, 1e-10))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(spherical_in(1, 0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(spherical_in(0, 1.0)))) { .. _example-top_level-spherical_in-1593: .. dropdown:: spherical_in (np_test_1_all.cpp:16069) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16059 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(!std::isnan(spherical_yn(1, x_pos)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(spherical_yn(1, x_pos)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Spherical Bessel y_n for positive arguments\n"; // Test modified spherical Bessel function i_n if (!(isApproxEqual(spherical_in(0, 0.0), 1.0, 1e-10))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(spherical_in(0, 0.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(spherical_in(1, 0.0), 0.0, 1e-10))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(spherical_in(1, 0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(spherical_in(0, 1.0)))) { .. _example-top_level-spherical_jn-1594: .. dropdown:: spherical_jn (np_test_1_all.cpp:16018) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16008 :emphasize-lines: 11 } // std::cout << "[OK] Orthogonal polynomial array operations\n"; std::cout << " -> tests passed\n"; } void testSphericalBesselFunctions() { std::cout << "========= testSphericalBesselFunctions ===="; // Test spherical Bessel function j_n at x = 0 if (!(isApproxEqual(spherical_jn(0, 0.0), 1.0, 1e-10))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(spherical_jn(0, 0.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(spherical_jn(1, 0.0), 0.0, 1e-10))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(spherical_jn(1, 0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(spherical_jn(2, 0.0), 0.0, 1e-10))) { .. _example-top_level-spherical_jn-1595: .. dropdown:: spherical_jn (np_test_1_all.cpp:16018) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16008 :emphasize-lines: 11 } // std::cout << "[OK] Orthogonal polynomial array operations\n"; std::cout << " -> tests passed\n"; } void testSphericalBesselFunctions() { std::cout << "========= testSphericalBesselFunctions ===="; // Test spherical Bessel function j_n at x = 0 if (!(isApproxEqual(spherical_jn(0, 0.0), 1.0, 1e-10))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(spherical_jn(0, 0.0), 1.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(spherical_jn(1, 0.0), 0.0, 1e-10))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqual(spherical_jn(1, 0.0), 0.0, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqual(spherical_jn(2, 0.0), 0.0, 1e-10))) { .. _example-top_level-spherical_kn-1596: .. dropdown:: spherical_kn (np_test_1_all.cpp:16092) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16082 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(spherical_in(0, 1.0) > 1.0)) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(spherical_in(0, 1.0) > 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Modified spherical Bessel i_n\n"; // Test modified spherical Bessel function k_n if (!(std::isinf(spherical_kn(0, 0.0)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(spherical_kn(0, 0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(spherical_kn(0, 1.0)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(spherical_kn(0, 1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(spherical_kn(0, 1.0) > 0)) { .. _example-top_level-spherical_kn-1597: .. dropdown:: spherical_kn (np_test_1_all.cpp:16092) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16082 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(spherical_in(0, 1.0) > 1.0)) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(spherical_in(0, 1.0) > 1.0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Modified spherical Bessel i_n\n"; // Test modified spherical Bessel function k_n if (!(std::isinf(spherical_kn(0, 0.0)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::isinf(spherical_kn(0, 0.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(spherical_kn(0, 1.0)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(spherical_kn(0, 1.0)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(spherical_kn(0, 1.0) > 0)) { .. _example-top_level-spherical_yn-1598: .. dropdown:: spherical_yn (np_test_1_all.cpp:16056) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16046 :emphasize-lines: 11 } if (!(spherical_jn(1, x_small) > 0)) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(spherical_jn(1, x_small) > 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Spherical Bessel j_n for small arguments\n"; // Test spherical Bessel function y_n for positive values double x_pos = 1.0; if (!(!std::isnan(spherical_yn(0, x_pos)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(spherical_yn(0, x_pos)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(spherical_yn(1, x_pos)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(spherical_yn(1, x_pos)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Spherical Bessel y_n for positive arguments\n"; .. _example-top_level-spherical_yn-1599: .. dropdown:: spherical_yn (np_test_1_all.cpp:16056) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16046 :emphasize-lines: 11 } if (!(spherical_jn(1, x_small) > 0)) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(spherical_jn(1, x_small) > 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Spherical Bessel j_n for small arguments\n"; // Test spherical Bessel function y_n for positive values double x_pos = 1.0; if (!(!std::isnan(spherical_yn(0, x_pos)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(spherical_yn(0, x_pos)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!std::isnan(spherical_yn(1, x_pos)))) { std::string description = std::string("testSphericalBesselFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!std::isnan(spherical_yn(1, x_pos)))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Spherical Bessel y_n for positive arguments\n"; .. _example-top_level-startofmonth-1600: .. dropdown:: startOfMonth (np_test_1_all.cpp:6959) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6949 :emphasize-lines: 11 // std::cout << "Test date: " << test_date.toString() << std::endl; // std::cout << "Is weekend: " << datetime_utils::isWeekend(test_date) << std::endl; // std::cout << "Is business day: " << datetime_utils::isBusinessDay(test_date) << std::endl; // std::cout << "Weekday: " << datetime_utils::getWeekday(test_date) << std::endl; // std::cout << "Day of year: " << datetime_utils::getDayOfYear(test_date) << std::endl; // Test start/end of periods // std::cout << "Start of week: " << datetime_utils::startOfWeek(test_date).toString() << std::endl; // std::cout << "End of week: " << datetime_utils::endOfWeek(test_date).toString() << std::endl; // std::cout << "Start of month: " << datetime_utils::startOfMonth(test_date).toString() << std::endl; // std::cout << "End of month: " << datetime_utils::endOfMonth(test_date).toString() << std::endl; // Test business day calculations datetime64 start_bday("2024-03-11"); // Monday datetime64 end_bday("2024-03-15"); // Friday int64_t business_days = datetime_utils::businessDayCount(start_bday, end_bday); // std::cout << "Business days from " << start_bday.toString() // << " to " << end_bday.toString() << ": " << business_days << std::endl; .. _example-top_level-startofweek-1601: .. dropdown:: startOfWeek (np_test_1_all.cpp:6957) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6947 :emphasize-lines: 11 datetime64 test_date("2024-03-15"); // Friday // std::cout << "Test date: " << test_date.toString() << std::endl; // std::cout << "Is weekend: " << datetime_utils::isWeekend(test_date) << std::endl; // std::cout << "Is business day: " << datetime_utils::isBusinessDay(test_date) << std::endl; // std::cout << "Weekday: " << datetime_utils::getWeekday(test_date) << std::endl; // std::cout << "Day of year: " << datetime_utils::getDayOfYear(test_date) << std::endl; // Test start/end of periods // std::cout << "Start of week: " << datetime_utils::startOfWeek(test_date).toString() << std::endl; // std::cout << "End of week: " << datetime_utils::endOfWeek(test_date).toString() << std::endl; // std::cout << "Start of month: " << datetime_utils::startOfMonth(test_date).toString() << std::endl; // std::cout << "End of month: " << datetime_utils::endOfMonth(test_date).toString() << std::endl; // Test business day calculations datetime64 start_bday("2024-03-11"); // Monday datetime64 end_bday("2024-03-15"); // Friday int64_t business_days = datetime_utils::businessDayCount(start_bday, end_bday); // std::cout << "Business days from " << start_bday.toString() .. _example-top_level-startofyear-1602: .. dropdown:: startOfYear (np_test_1_all.cpp:28730) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 28720 :emphasize-lines: 11 } std::cout << " -> tests passed" << std::endl; } void np_test_datetime_year_boundaries() { std::cout << "========= startOfYear/endOfYear: year boundary dates ======================="; auto dt = numpy::datetime64("2024-06-15"); auto start = numpy::datetime_utils::startOfYear(dt); auto end = numpy::datetime_utils::endOfYear(dt); // Verify both return valid datetime64 objects bool passed = (!start.isNaT() && !end.isNaT()); if (!passed) { std::cout << " [FAIL] : in np_test_datetime_year_boundaries() : Year boundary calculation failed"; throw std::runtime_error("np_test_datetime_year_boundaries failed"); } .. _example-top_level-startswith-1603: .. dropdown:: startswith (np_test_1_all.cpp:6544) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6534 :emphasize-lines: 11 std::vector sentences = {"Hello World", "Programming is fun", "NumPy arrays"}; auto arr = array<32>(sentences); // std::cout << "Test sentences:" << std::endl; for (size_t i = 0; i < arr.size(); ++i) { // std::cout << " '" << arr[i] << "'"; } // Test startswith auto starts_result = startswith(arr, "Hello"); // std::cout << "startswith 'Hello': "; for (size_t i = 0; i < starts_result.getSize(); ++i) { // std::cout << starts_result.getElementAt({i}) << " "; } // std::cout << std::endl; // Test endswith auto ends_result = endswith(arr, "fun"); // std::cout << "endswith 'fun': "; for (size_t i = 0; i < ends_result.getSize(); ++i) { .. _example-top_level-str_partition-1604: .. dropdown:: str_partition (np_test_3_all.cpp:14023) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14013 :emphasize-lines: 11 // std::cout << "[OK] Splitlines test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_str_partition() { std::cout << "========= np_test_str_partition ======================="; NDArray arr({ 1 }); arr.data()[0] = vstring_("hello-world"); auto [before, sep, after] = str_partition(arr, vstring_("-")); if (before.data()[0].to_string() != "hello" || sep.data()[0].to_string() != "-" || after.data()[0].to_string() != "world") { std::cerr << "[FAIL] partition test failed"; throw std::runtime_error("partition test failed"); } // std::cout << "[OK] Partition test passed" << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-top_level-str_rpartition-1605: .. dropdown:: str_rpartition (np_test_3_all.cpp:14042) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14032 :emphasize-lines: 11 // std::cout << "[OK] Partition test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_str_rpartition() { std::cout << "========= np_test_str_rpartition ======================="; NDArray arr({ 1 }); arr.data()[0] = vstring_("a-b-c"); auto [before, sep, after] = str_rpartition(arr, vstring_("-")); if (before.data()[0].to_string() != "a-b" || sep.data()[0].to_string() != "-" || after.data()[0].to_string() != "c") { std::cerr << "[FAIL] rpartition test failed"; throw std::runtime_error("rpartition test failed"); } // std::cout << "[OK] Rpartition test passed" << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-top_level-str_rsplit-1606: .. dropdown:: str_rsplit (np_test_3_all.cpp:13989) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13979 :emphasize-lines: 11 // std::cout << "[OK] Split test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_str_rsplit() { std::cout << "========= np_test_str_rsplit ======================="; NDArray arr({ 1 }); arr.data()[0] = vstring_("a,b,c"); auto result = str_rsplit(arr, vstring_(",")); if (result.size() != 1 || result[0].data()[0].to_string() != "c") { std::cerr << "[FAIL] rsplit test failed"; throw std::runtime_error("rsplit test failed"); } // std::cout << "[OK] Rsplit test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-str_split-1607: .. dropdown:: str_split (np_test_3_all.cpp:13972) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13962 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void np_test_str_split() { std::cout << "========= np_test_str_split ======================="; NDArray arr({ 2 }); arr.data()[0] = vstring_("a,b,c"); arr.data()[1] = vstring_("x,y"); auto result = str_split(arr, vstring_(",")); if (result.size() != 1 || result[0].data()[0].to_string() != "a") { std::cerr << "[FAIL] split test failed"; throw std::runtime_error("split test failed"); } // std::cout << "[OK] Split test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-str_splitlines-1608: .. dropdown:: str_splitlines (np_test_3_all.cpp:14006) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13996 :emphasize-lines: 11 // std::cout << "[OK] Rsplit test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_str_splitlines() { std::cout << "========= np_test_str_splitlines ======================="; NDArray arr({ 1 }); arr.data()[0] = vstring_("a\nb\nc"); auto result = str_splitlines(arr, false); if (result.size() != 1 || result[0].data()[0].to_string() != "a") { std::cerr << "[FAIL] splitlines test failed"; throw std::runtime_error("splitlines test failed"); } // std::cout << "[OK] Splitlines test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-strip-1609: .. dropdown:: strip (np_test_1_all.cpp:6634) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6624 :emphasize-lines: 11 std::vector padded = {" hello ", "\t\tworld\t\t", " spaces "}; auto arr = array<32>(padded); // std::cout << "Original padded strings:" << std::endl; for (size_t i = 0; i < arr.size(); ++i) { // std::cout << "'" << arr[i] << "'"; } // Test strip auto stripped = strip(arr); // std::cout << "After strip():" << std::endl; for (size_t i = 0; i < stripped.size(); ++i) { // std::cout << "'" << stripped[i] << "'"; } // Test lstrip auto left_stripped = lstrip(arr); // std::cout << "After lstrip():" << std::endl; for (size_t i = 0; i < left_stripped.size(); ++i) { // std::cout << "'" << left_stripped[i] << "'"; .. _example-top_level-strip-1610: .. dropdown:: strip (np_test_1_all.cpp:6634) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6624 :emphasize-lines: 11 std::vector padded = {" hello ", "\t\tworld\t\t", " spaces "}; auto arr = array<32>(padded); // std::cout << "Original padded strings:" << std::endl; for (size_t i = 0; i < arr.size(); ++i) { // std::cout << "'" << arr[i] << "'"; } // Test strip auto stripped = strip(arr); // std::cout << "After strip():" << std::endl; for (size_t i = 0; i < stripped.size(); ++i) { // std::cout << "'" << stripped[i] << "'"; } // Test lstrip auto left_stripped = lstrip(arr); // std::cout << "After lstrip():" << std::endl; for (size_t i = 0; i < left_stripped.size(); ++i) { // std::cout << "'" << left_stripped[i] << "'"; .. _example-top_level-swap_rows-1611: .. dropdown:: swap_rows (np_test_5_all.cpp:2934) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2924 :emphasize-lines: 11 // std::cout << " find_pivot: pivot row = " << pivot_row << " (expected 1)" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_linalg_swap_rows() { std::cout << "========= swap_rows helper ======================="; // Create matrix: [[1, 2, 3], [4, 5, 6]] std::vector matrix = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }; numpy::linalg::utils::swap_rows(matrix.data(), 3, 0, 1); // After swap: [[4, 5, 6], [1, 2, 3]] bool passed = (matrix[0] == 4.0 && matrix[1] == 5.0 && matrix[2] == 6.0 && matrix[3] == 1.0 && matrix[4] == 2.0 && matrix[5] == 3.0); if (!passed) { std::cout << " [FAIL] : in np_test_linalg_swap_rows() : rows not swapped correctly"; throw std::runtime_error("np_test_linalg_swap_rows failed: incorrect swap"); } // std::cout << " swap_rows: row 0 and row 1 swapped correctly" << std::endl; .. _example-top_level-swapcase-1612: .. dropdown:: swapcase (np_test_5_all.cpp:1434) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1424 :emphasize-lines: 11 } std::cout << " -> tests passed" << std::endl; } void np_test_string_swapcase() { std::cout << "========= swapcase formatting ======================="; std::vector strings = { "Hello World", "TEST", "test" }; auto arr = numpy::char_::array<32>(strings); auto result = numpy::char_::swapcase(arr); bool passed = (result.size() == arr.size()); if (!passed) { std::cout << " [FAIL] : in np_test_string_swapcase() : size mismatch"; throw std::runtime_error("np_test_string_swapcase failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-symeig_accelerated-1613: .. dropdown:: symeig_accelerated (np_test_2_all.cpp:17757) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 17747 :emphasize-lines: 11 matrix.setElementAt({ 0, 1 }, 1.0); matrix.setElementAt({ 0, 2 }, 0.0); matrix.setElementAt({ 1, 0 }, 1.0); matrix.setElementAt({ 1, 1 }, 4.0); matrix.setElementAt({ 1, 2 }, 1.0); matrix.setElementAt({ 2, 0 }, 0.0); matrix.setElementAt({ 2, 1 }, 1.0); matrix.setElementAt({ 2, 2 }, 4.0); try { auto result = numpy::mkl::lapack::symeig_accelerated(matrix, true); // Check convergence if (!result.converged) { std::cout << " [FAIL] : Symmetric eigendecomposition did not converge"; throw std::runtime_error("np_test_mkl_linalg_symeig failed: did not converge"); } // std::cout << " Eigenvalues: "; for (size_t i = 0; i < 3; ++i) { // std::cout << result.eigenvalues.getElementAt({ i }) << " "; .. _example-top_level-timedelta64-1614: .. dropdown:: timedelta64 (np_test_1_all.cpp:7030) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7020 :emphasize-lines: 11 datetime64 nat_dt = datetime64::NaT(); timedelta64 nat_td = timedelta64::NaT(); // std::cout << "NaT datetime: " << nat_dt.toString() << std::endl; // std::cout << "NaT timedelta: " << nat_td.toString() << std::endl; datetime64 valid_date("2024-01-01"); // NaT arithmetic datetime64 result1 = valid_date + nat_td; datetime64 result2 = nat_dt + timedelta64(1, DateTimeUnit::Day); timedelta64 result3 = valid_date - nat_dt; // std::cout << "Valid date + NaT timedelta = " << result1.toString() << std::endl; // std::cout << "NaT datetime + valid timedelta = " << result2.toString() << std::endl; // std::cout << "Valid date - NaT datetime = " << result3.toString() << std::endl; // NaT comparisons // std::cout << "NaT == NaT: " << (nat_dt == datetime64::NaT()) << std::endl; // std::cout << "Valid date == NaT: " << (valid_date == nat_dt) << std::endl; // std::cout << "NaT < Valid date: " << (nat_dt < valid_date) << std::endl; .. _example-top_level-timedelta64-1615: .. dropdown:: timedelta64 (np_test_1_all.cpp:7030) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7020 :emphasize-lines: 11 datetime64 nat_dt = datetime64::NaT(); timedelta64 nat_td = timedelta64::NaT(); // std::cout << "NaT datetime: " << nat_dt.toString() << std::endl; // std::cout << "NaT timedelta: " << nat_td.toString() << std::endl; datetime64 valid_date("2024-01-01"); // NaT arithmetic datetime64 result1 = valid_date + nat_td; datetime64 result2 = nat_dt + timedelta64(1, DateTimeUnit::Day); timedelta64 result3 = valid_date - nat_dt; // std::cout << "Valid date + NaT timedelta = " << result1.toString() << std::endl; // std::cout << "NaT datetime + valid timedelta = " << result2.toString() << std::endl; // std::cout << "Valid date - NaT datetime = " << result3.toString() << std::endl; // NaT comparisons // std::cout << "NaT == NaT: " << (nat_dt == datetime64::NaT()) << std::endl; // std::cout << "Valid date == NaT: " << (valid_date == nat_dt) << std::endl; // std::cout << "NaT < Valid date: " << (nat_dt < valid_date) << std::endl; .. _example-top_level-timsort-1616: .. dropdown:: timsort (np_test_1_all.cpp:16955) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16945 :emphasize-lines: 11 // std::cout << "Introsort time: " << introsort_time << " microseconds" << std::endl; // Benchmark heapsort data_copy = random_data; start = std::chrono::high_resolution_clock::now(); advanced_sort(data_copy, SortKind::HEAPSORT); end = std::chrono::high_resolution_clock::now(); auto heapsort_time = std::chrono::duration_cast(end - start).count(); // std::cout << "Heapsort time: " << heapsort_time << " microseconds" << std::endl; // Benchmark timsort (stable) data_copy = random_data; start = std::chrono::high_resolution_clock::now(); advanced_sort(data_copy, SortKind::STABLE); end = std::chrono::high_resolution_clock::now(); auto timsort_time = std::chrono::duration_cast(end - start).count(); // std::cout << "Timsort time: " << timsort_time << " microseconds" << std::endl; // Benchmark std::sort for comparison data_copy = random_data; start = std::chrono::high_resolution_clock::now(); .. _example-top_level-timsort-1617: .. dropdown:: timsort (np_test_1_all.cpp:16955) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16945 :emphasize-lines: 11 // std::cout << "Introsort time: " << introsort_time << " microseconds" << std::endl; // Benchmark heapsort data_copy = random_data; start = std::chrono::high_resolution_clock::now(); advanced_sort(data_copy, SortKind::HEAPSORT); end = std::chrono::high_resolution_clock::now(); auto heapsort_time = std::chrono::duration_cast(end - start).count(); // std::cout << "Heapsort time: " << heapsort_time << " microseconds" << std::endl; // Benchmark timsort (stable) data_copy = random_data; start = std::chrono::high_resolution_clock::now(); advanced_sort(data_copy, SortKind::STABLE); end = std::chrono::high_resolution_clock::now(); auto timsort_time = std::chrono::duration_cast(end - start).count(); // std::cout << "Timsort time: " << timsort_time << " microseconds" << std::endl; // Benchmark std::sort for comparison data_copy = random_data; start = std::chrono::high_resolution_clock::now(); .. _example-top_level-title-1618: .. dropdown:: title (np_test_1_all.cpp:6468) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6458 :emphasize-lines: 11 } // Test capitalize auto cap_result = capitalize(arr); // std::cout << "Capitalize:" << std::endl; for (size_t i = 0; i < cap_result.size(); ++i) { // std::cout << " '" << cap_result[i] << "'"; } // Test title auto title_result = title(arr); // std::cout << "Title case:" << std::endl; for (size_t i = 0; i < title_result.size(); ++i) { // std::cout << " '" << title_result[i] << "'"; } std::cout << " -> tests passed" << std::endl; } void testStringTestingCharArray() { std::cout << "========= testStringTesting ======================="; .. _example-top_level-title-1619: .. dropdown:: title (np_test_1_all.cpp:6468) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6458 :emphasize-lines: 11 } // Test capitalize auto cap_result = capitalize(arr); // std::cout << "Capitalize:" << std::endl; for (size_t i = 0; i < cap_result.size(); ++i) { // std::cout << " '" << cap_result[i] << "'"; } // Test title auto title_result = title(arr); // std::cout << "Title case:" << std::endl; for (size_t i = 0; i < title_result.size(); ++i) { // std::cout << " '" << title_result[i] << "'"; } std::cout << " -> tests passed" << std::endl; } void testStringTestingCharArray() { std::cout << "========= testStringTesting ======================="; .. _example-top_level-todays-1620: .. dropdown:: toDays (np_test_1_all.cpp:28826) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 28816 :emphasize-lines: 11 void np_test_timedelta64_conversions() { std::cout << "========= timedelta64 conversions: fromSeconds/toSeconds/toDays ======================="; // Test fromSeconds (needs two parameters: seconds and unit) int64_t seconds = 86400; // 1 day auto td = numpy::timedelta64::fromSeconds(seconds, numpy::DateTimeUnit::Second); // Test toSeconds int64_t converted_seconds = td.toSeconds(); // Test toDays (returns int64_t) int64_t days = td.toDays(); bool passed = (converted_seconds == seconds && days == 1); if (!passed) { std::cout << " [FAIL] : in np_test_timedelta64_conversions() : Conversion failed - seconds: " << converted_seconds << ", days: " << days << std::endl; throw std::runtime_error("np_test_timedelta64_conversions failed"); } .. _example-top_level-toepochseconds-1621: .. dropdown:: toEpochSeconds (np_test_1_all.cpp:28781) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 28771 :emphasize-lines: 11 // ============================================================================ void np_test_datetime64_epoch_conversion() { std::cout << "========= datetime64 epoch conversion: fromEpochSeconds/toEpochSeconds ======================="; // Test fromEpochSeconds (needs two parameters: seconds and unit) int64_t epoch_seconds = 1704067200; // Jan 1, 2024 00:00:00 UTC auto dt = numpy::datetime64::fromEpochSeconds(epoch_seconds, numpy::DateTimeUnit::Second); // Test toEpochSeconds int64_t converted = dt.toEpochSeconds(); bool passed = (converted == epoch_seconds); if (!passed) { std::cout << " [FAIL] : in np_test_datetime64_epoch_conversion() : Epoch conversion failed"; throw std::runtime_error("np_test_datetime64_epoch_conversion failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-tohours-1622: .. dropdown:: toHours (np_test_1_all.cpp:6863) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6853 :emphasize-lines: 11 timedelta64 one_day(1, DateTimeUnit::Day); // std::cout << "One day: " << one_day.toString() << std::endl; timedelta64 five_hours(5, DateTimeUnit::Hour); // std::cout << "Five hours: " << five_hours.toString() << std::endl; timedelta64 from_string("30 minutes"); // std::cout << "From string '30 minutes': " << from_string.toString() << std::endl; // Test conversions // std::cout << "One day in hours: " << one_day.toHours() << std::endl; // std::cout << "Five hours in minutes: " << five_hours.toMinutes() << std::endl; std::cout << " -> tests passed" << std::endl; } void testDatetimeArithmeticDateTime() { std::cout << "========= testDatetimeArithmeticDateTime ======================="; datetime64 start_date("2024-01-01"); timedelta64 one_week(7, DateTimeUnit::Day); .. _example-top_level-tominutes-1623: .. dropdown:: toMinutes (np_test_1_all.cpp:6864) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6854 :emphasize-lines: 11 // std::cout << "One day: " << one_day.toString() << std::endl; timedelta64 five_hours(5, DateTimeUnit::Hour); // std::cout << "Five hours: " << five_hours.toString() << std::endl; timedelta64 from_string("30 minutes"); // std::cout << "From string '30 minutes': " << from_string.toString() << std::endl; // Test conversions // std::cout << "One day in hours: " << one_day.toHours() << std::endl; // std::cout << "Five hours in minutes: " << five_hours.toMinutes() << std::endl; std::cout << " -> tests passed" << std::endl; } void testDatetimeArithmeticDateTime() { std::cout << "========= testDatetimeArithmeticDateTime ======================="; datetime64 start_date("2024-01-01"); timedelta64 one_week(7, DateTimeUnit::Day); timedelta64 three_days(3, DateTimeUnit::Day); .. _example-top_level-toseconds-1624: .. dropdown:: toSeconds (np_test_1_all.cpp:28824) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 28814 :emphasize-lines: 11 // ============================================================================ void np_test_timedelta64_conversions() { std::cout << "========= timedelta64 conversions: fromSeconds/toSeconds/toDays ======================="; // Test fromSeconds (needs two parameters: seconds and unit) int64_t seconds = 86400; // 1 day auto td = numpy::timedelta64::fromSeconds(seconds, numpy::DateTimeUnit::Second); // Test toSeconds int64_t converted_seconds = td.toSeconds(); // Test toDays (returns int64_t) int64_t days = td.toDays(); bool passed = (converted_seconds == seconds && days == 1); if (!passed) { std::cout << " [FAIL] : in np_test_timedelta64_conversions() : Conversion failed - seconds: " << converted_seconds << ", days: " << days << std::endl; throw std::runtime_error("np_test_timedelta64_conversions failed"); .. _example-top_level-tostring-1625: .. dropdown:: toString (np_test_1_all.cpp:6826) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6816 :emphasize-lines: 11 void testDatetime64CreationDateTime() { std::cout << "========= testDatetime64CreationDateTime ======================="; // Test default constructor datetime64 default_dt; if (!(default_dt.isNaT())) { std::string description = std::string("testDatetime64CreationDateTime():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(default_dt.isNaT())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Default datetime64 is NaT: " << default_dt.toString() << std::endl; // Test value constructor datetime64 epoch_day(0, DateTimeUnit::Day); // std::cout << "Epoch day: " << epoch_day.toString() << std::endl; // Test string constructor datetime64 date_from_string("2024-01-15"); // std::cout << "Date from string '2024-01-15': " << date_from_string.toString() << std::endl; datetime64 datetime_from_string("2024-01-15T10:30:45"); .. _example-top_level-tostring-1626: .. dropdown:: toString (np_test_1_all.cpp:6826) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6816 :emphasize-lines: 11 void testDatetime64CreationDateTime() { std::cout << "========= testDatetime64CreationDateTime ======================="; // Test default constructor datetime64 default_dt; if (!(default_dt.isNaT())) { std::string description = std::string("testDatetime64CreationDateTime():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(default_dt.isNaT())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Default datetime64 is NaT: " << default_dt.toString() << std::endl; // Test value constructor datetime64 epoch_day(0, DateTimeUnit::Day); // std::cout << "Epoch day: " << epoch_day.toString() << std::endl; // Test string constructor datetime64 date_from_string("2024-01-15"); // std::cout << "Date from string '2024-01-15': " << date_from_string.toString() << std::endl; datetime64 datetime_from_string("2024-01-15T10:30:45"); .. _example-top_level-tostring-1627: .. dropdown:: toString (np_test_1_all.cpp:6826) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6816 :emphasize-lines: 11 void testDatetime64CreationDateTime() { std::cout << "========= testDatetime64CreationDateTime ======================="; // Test default constructor datetime64 default_dt; if (!(default_dt.isNaT())) { std::string description = std::string("testDatetime64CreationDateTime():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(default_dt.isNaT())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Default datetime64 is NaT: " << default_dt.toString() << std::endl; // Test value constructor datetime64 epoch_day(0, DateTimeUnit::Day); // std::cout << "Epoch day: " << epoch_day.toString() << std::endl; // Test string constructor datetime64 date_from_string("2024-01-15"); // std::cout << "Date from string '2024-01-15': " << date_from_string.toString() << std::endl; datetime64 datetime_from_string("2024-01-15T10:30:45"); .. _example-top_level-today-1628: .. dropdown:: today (np_test_1_all.cpp:6840) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6830 :emphasize-lines: 11 // std::cout << "Epoch day: " << epoch_day.toString() << std::endl; // Test string constructor datetime64 date_from_string("2024-01-15"); // std::cout << "Date from string '2024-01-15': " << date_from_string.toString() << std::endl; datetime64 datetime_from_string("2024-01-15T10:30:45"); // std::cout << "DateTime from string '2024-01-15T10:30:45': " << datetime_from_string.toString() << std::endl; // Test static methods datetime64 today = datetime64::today(); // std::cout << "Today: " << today.toString() << std::endl; datetime64 now = datetime64::now(); // std::cout << "Now: " << now.toString() << std::endl; std::cout << " -> tests passed" << std::endl; } void testTimedelta64CreationDateTime() { std::cout << "========= testTimedelta64CreationDateTime ======================="; .. _example-top_level-toeplitz-1629: .. dropdown:: toeplitz (np_test_2_all.cpp:5261) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5251 :emphasize-lines: 11 assert_test(std::abs(companion_mat(1, 1) - 3.0) < 1e-10, "Companion matrix coefficients"); } catch (...) { // std::cout << "Companion matrix test failed"; } // Test Toeplitz matrix std::vector c = { 1.0, 2.0, 3.0 }; std::vector r = { 1.0, 4.0, 5.0 }; try { auto toep = numpy::toeplitz(c, r); assert_test(toep.rows() == 3 && toep.cols() == 3, "Toeplitz matrix dimensions"); assert_test(std::abs(toep(0, 0) - 1.0) < 1e-10, "Toeplitz matrix element"); assert_test(std::abs(toep(0, 1) - 4.0) < 1e-10, "Toeplitz matrix element"); assert_test(std::abs(toep(1, 0) - 2.0) < 1e-10, "Toeplitz matrix element"); assert_test(std::abs(toep(2, 1) - 2.0) < 1e-10, "Toeplitz matrix element"); } catch (...) { // std::cout << "Toeplitz matrix test failed"; } .. _example-top_level-translate-1630: .. dropdown:: translate (np_test_5_all.cpp:1454) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1444 :emphasize-lines: 11 } void np_test_string_translate() { std::cout << "========= translate formatting ======================="; std::vector strings = { "hello", "world" }; auto arr = numpy::char_::array<32>(strings); // Create translation table std::string table = "abcdefghijklmnopqrstuvwxyz123456789012345678901234567890"; auto result = numpy::char_::translate(arr, table); bool passed = (result.size() == arr.size()); if (!passed) { std::cout << " [FAIL] : in np_test_string_translate() : size mismatch"; throw std::runtime_error("np_test_string_translate failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-translate-1631: .. dropdown:: translate (np_test_5_all.cpp:1454) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1444 :emphasize-lines: 11 } void np_test_string_translate() { std::cout << "========= translate formatting ======================="; std::vector strings = { "hello", "world" }; auto arr = numpy::char_::array<32>(strings); // Create translation table std::string table = "abcdefghijklmnopqrstuvwxyz123456789012345678901234567890"; auto result = numpy::char_::translate(arr, table); bool passed = (result.size() == arr.size()); if (!passed) { std::cout << " [FAIL] : in np_test_string_translate() : size mismatch"; throw std::runtime_error("np_test_string_translate failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-top_level-trapezoid-1632: .. dropdown:: trapezoid (np_test_5_all.cpp:10310) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10300 :emphasize-lines: 11 // SECTION 1: New Alias Functions Tests // ======================================================================== void np_test_trapezoid_alias() { std::cout << "========= trapezoid: alias verification ======================="; // Test 1: Uniform spacing with dx - integral of y=x from 0 to 9 // Using arange: 0, 1, 2, ..., 9 numpy::NDArray y1 = numpy::arange(0.0, 10.0, 1.0); double result_trapz = numpy::trapz(y1, 1.0); double result_trapezoid = numpy::trapezoid(y1, 1.0); if (std::abs(result_trapz - result_trapezoid) > 1e-10) { std::cout << " [FAIL] : in np_test_trapezoid_alias() : trapezoid alias does not match trapz" << std::endl; throw std::runtime_error("trapezoid alias test failed: results don't match"); } // Verify the integral value: Sum = (0+1)/2 + (1+2)/2 + ... + (8+9)/2 = 40.5 if (std::abs(result_trapezoid - 40.5) > 1e-10) { std::cout << " [FAIL] : in np_test_trapezoid_alias() : trapezoid integral incorrect (expected 40.5, got " << result_trapezoid << ")" << std::endl; .. _example-top_level-trapezoid-1633: .. dropdown:: trapezoid (np_test_5_all.cpp:10310) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10300 :emphasize-lines: 11 // SECTION 1: New Alias Functions Tests // ======================================================================== void np_test_trapezoid_alias() { std::cout << "========= trapezoid: alias verification ======================="; // Test 1: Uniform spacing with dx - integral of y=x from 0 to 9 // Using arange: 0, 1, 2, ..., 9 numpy::NDArray y1 = numpy::arange(0.0, 10.0, 1.0); double result_trapz = numpy::trapz(y1, 1.0); double result_trapezoid = numpy::trapezoid(y1, 1.0); if (std::abs(result_trapz - result_trapezoid) > 1e-10) { std::cout << " [FAIL] : in np_test_trapezoid_alias() : trapezoid alias does not match trapz" << std::endl; throw std::runtime_error("trapezoid alias test failed: results don't match"); } // Verify the integral value: Sum = (0+1)/2 + (1+2)/2 + ... + (8+9)/2 = 40.5 if (std::abs(result_trapezoid - 40.5) > 1e-10) { std::cout << " [FAIL] : in np_test_trapezoid_alias() : trapezoid integral incorrect (expected 40.5, got " << result_trapezoid << ")" << std::endl; .. _example-top_level-trapezoid-1634: .. dropdown:: trapezoid (np_test_5_all.cpp:10310) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10300 :emphasize-lines: 11 // SECTION 1: New Alias Functions Tests // ======================================================================== void np_test_trapezoid_alias() { std::cout << "========= trapezoid: alias verification ======================="; // Test 1: Uniform spacing with dx - integral of y=x from 0 to 9 // Using arange: 0, 1, 2, ..., 9 numpy::NDArray y1 = numpy::arange(0.0, 10.0, 1.0); double result_trapz = numpy::trapz(y1, 1.0); double result_trapezoid = numpy::trapezoid(y1, 1.0); if (std::abs(result_trapz - result_trapezoid) > 1e-10) { std::cout << " [FAIL] : in np_test_trapezoid_alias() : trapezoid alias does not match trapz" << std::endl; throw std::runtime_error("trapezoid alias test failed: results don't match"); } // Verify the integral value: Sum = (0+1)/2 + (1+2)/2 + ... + (8+9)/2 = 40.5 if (std::abs(result_trapezoid - 40.5) > 1e-10) { std::cout << " [FAIL] : in np_test_trapezoid_alias() : trapezoid integral incorrect (expected 40.5, got " << result_trapezoid << ")" << std::endl; .. _example-top_level-trapz-1635: .. dropdown:: trapz (np_test_4_all.cpp:19122) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19112 :emphasize-lines: 11 return 0; } } // namespace numpy_tests /** * Phase 4 Tests: Numerical Methods & Signal Processing * * Tests for: * - np.interp() - 1D linear interpolation * - np.trapz() - Trapezoidal numerical integration * - np.convolve() - Discrete convolution (direct + FFT) * - np.correlate() - Cross-correlation (direct + FFT) * * Following TESTING_CPP.md format */ #include "../numpy/np_numerical.h" #include "../numpy/np_signal.h" #include #include .. _example-top_level-trapz-1636: .. dropdown:: trapz (np_test_4_all.cpp:19122) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19112 :emphasize-lines: 11 return 0; } } // namespace numpy_tests /** * Phase 4 Tests: Numerical Methods & Signal Processing * * Tests for: * - np.interp() - 1D linear interpolation * - np.trapz() - Trapezoidal numerical integration * - np.convolve() - Discrete convolution (direct + FFT) * - np.correlate() - Cross-correlation (direct + FFT) * * Following TESTING_CPP.md format */ #include "../numpy/np_numerical.h" #include "../numpy/np_signal.h" #include #include .. _example-top_level-try_cast-1637: .. dropdown:: try_cast (np_test_3_all.cpp:21861) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21851 :emphasize-lines: 11 CHECK(a != b, "np_test_object_mixed_hash_compare", "a != b failed"); std::cout << " -> tests passed" << std::endl; } void np_test_object_mixed_coercion() { std::cout << "========= object_ type coercion ====" ; // Integer to double numpy::object_ int_obj(42); double d = numpy::try_cast(int_obj, 0.0); CHECK(d == 42.0, "np_test_object_mixed_coercion", "int to double failed"); // Double to int numpy::object_ double_obj(3.7); int i = numpy::try_cast(double_obj, 0); CHECK(i == 3, "np_test_object_mixed_coercion", "double to int failed"); // String to int numpy::object_ str_obj(std::string("123")); int si = numpy::try_cast(str_obj, 0); .. _example-top_level-typename_-1638: .. dropdown:: typename_ (np_test_1_all.cpp:26432) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26422 :emphasize-lines: 11 // ============================================================================ // SUB-PHASE 6A: LIBRARY NAMESPACE ALIASES // ============================================================================ void test_lib_aliases() { std::cout << "[6A] Testing Library Namespace Aliases (12 functions)"; // std::cout << "=======================================================" << std::endl; // Test typename_ alias { std::string type_name = numpy::lib::typename_(); if (!(!type_name.empty())) { std::string description = std::string("test_lib_aliases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!type_name.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ numpy::lib::typename_() = " << type_name << std::endl; } // Test safe_eval (should throw) { .. _example-top_level-typename_-1639: .. dropdown:: typename_ (np_test_1_all.cpp:26432) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26422 :emphasize-lines: 11 // ============================================================================ // SUB-PHASE 6A: LIBRARY NAMESPACE ALIASES // ============================================================================ void test_lib_aliases() { std::cout << "[6A] Testing Library Namespace Aliases (12 functions)"; // std::cout << "=======================================================" << std::endl; // Test typename_ alias { std::string type_name = numpy::lib::typename_(); if (!(!type_name.empty())) { std::string description = std::string("test_lib_aliases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!type_name.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ numpy::lib::typename_() = " << type_name << std::endl; } // Test safe_eval (should throw) { .. _example-top_level-typename_-1640: .. dropdown:: typename_ (np_test_1_all.cpp:26432) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26422 :emphasize-lines: 11 // ============================================================================ // SUB-PHASE 6A: LIBRARY NAMESPACE ALIASES // ============================================================================ void test_lib_aliases() { std::cout << "[6A] Testing Library Namespace Aliases (12 functions)"; // std::cout << "=======================================================" << std::endl; // Test typename_ alias { std::string type_name = numpy::lib::typename_(); if (!(!type_name.empty())) { std::string description = std::string("test_lib_aliases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!type_name.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << " ✓ numpy::lib::typename_() = " << type_name << std::endl; } // Test safe_eval (should throw) { .. _example-top_level-typename_from_char-1641: .. dropdown:: typename_from_char (np_test_3_all.cpp:8393) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8383 :emphasize-lines: 11 } //============================================================================== // Test typename_from_char //============================================================================== void np_test_typename_from_char_integers() { std::cout << "========= np_test_typename_from_char_integers ======================="; // Test signed integers if (typename_from_char('b') != "int8") { std::cerr << "[FAIL] typename_from_char('b') should return 'int8'"; throw std::runtime_error("typename_from_char 'b' test failed"); } // std::cout << "[OK] typename_from_char('b') = 'int8'" << std::endl; if (typename_from_char('h') != "int16") { std::cerr << "[FAIL] typename_from_char('h') should return 'int16'"; throw std::runtime_error("typename_from_char 'h' test failed"); } // std::cout << "[OK] typename_from_char('h') = 'int16'" << std::endl; .. _example-top_level-typename_str-1642: .. dropdown:: typename_str (np_test_2_all.cpp:19796) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19786 :emphasize-lines: 11 } // ============================================================================ // TYPENAME TESTS // ============================================================================ void np_test_introspection_typename() { std::cout << "========= typename: get type name strings ======================="; // Test various types std::string name_double = numpy::introspection::typename_str(); std::string name_int = numpy::introspection::typename_str(); std::string name_float = numpy::introspection::typename_str(); // std::cout << "double: " << name_double << std::endl; // std::cout << "int: " << name_int << std::endl; // std::cout << "float: " << name_float << std::endl; bool passed = !name_double.empty() && !name_int.empty() && !name_float.empty(); if (!passed) { .. _example-top_level-typename_str-1643: .. dropdown:: typename_str (np_test_2_all.cpp:19796) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19786 :emphasize-lines: 11 } // ============================================================================ // TYPENAME TESTS // ============================================================================ void np_test_introspection_typename() { std::cout << "========= typename: get type name strings ======================="; // Test various types std::string name_double = numpy::introspection::typename_str(); std::string name_int = numpy::introspection::typename_str(); std::string name_float = numpy::introspection::typename_str(); // std::cout << "double: " << name_double << std::endl; // std::cout << "int: " << name_int << std::endl; // std::cout << "float: " << name_float << std::endl; bool passed = !name_double.empty() && !name_int.empty() && !name_float.empty(); if (!passed) { .. _example-top_level-unravel_index-1644: .. dropdown:: unravel_index (np_test_4_all.cpp:18786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18776 :emphasize-lines: 11 throw std::runtime_error("diag_indices_from failed: wrong array size"); } std::cout << " -> tests passed" << std::endl; } void np_test_phase2_unravel_index() { std::cout << "========= unravel_index: flat to coordinate conversion ======================="; // Test single index auto coords1 = numpy::unravel_index(5, {3, 3}); if (coords1.size() != 2) { std::cout << " [FAIL] : unravel_index returned " << coords1.size() << " arrays, expected 2"; throw std::runtime_error("unravel_index failed: wrong number of coordinate arrays"); } if (coords1[0].getElementAt({0}) != 1 || coords1[1].getElementAt({0}) != 2) { std::cout << " [FAIL] : unravel_index(5, {3,3}) should be (1,2)"; throw std::runtime_error("unravel_index failed: incorrect coordinates"); } .. _example-top_level-unravel_index-1645: .. dropdown:: unravel_index (np_test_4_all.cpp:18786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18776 :emphasize-lines: 11 throw std::runtime_error("diag_indices_from failed: wrong array size"); } std::cout << " -> tests passed" << std::endl; } void np_test_phase2_unravel_index() { std::cout << "========= unravel_index: flat to coordinate conversion ======================="; // Test single index auto coords1 = numpy::unravel_index(5, {3, 3}); if (coords1.size() != 2) { std::cout << " [FAIL] : unravel_index returned " << coords1.size() << " arrays, expected 2"; throw std::runtime_error("unravel_index failed: wrong number of coordinate arrays"); } if (coords1[0].getElementAt({0}) != 1 || coords1[1].getElementAt({0}) != 2) { std::cout << " [FAIL] : unravel_index(5, {3,3}) should be (1,2)"; throw std::runtime_error("unravel_index failed: incorrect coordinates"); } .. _example-top_level-upper-1646: .. dropdown:: upper (np_test_1_all.cpp:6447) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6437 :emphasize-lines: 11 std::vector mixed_case = {"hello world", "GOOD DAY", "Mixed Case"}; auto arr = array<32>(mixed_case); // std::cout << "Original strings:" << std::endl; for (size_t i = 0; i < arr.size(); ++i) { // std::cout << " '" << arr[i] << "'"; } // Test upper case auto upper_result = upper(arr); // std::cout << "Upper case:" << std::endl; for (size_t i = 0; i < upper_result.size(); ++i) { // std::cout << " '" << upper_result[i] << "'"; } // Test lower case auto lower_result = lower(arr); // std::cout << "Lower case:" << std::endl; for (size_t i = 0; i < lower_result.size(); ++i) { // std::cout << " '" << lower_result[i] << "'"; .. _example-top_level-utf8_to_utf32-1647: .. dropdown:: utf8_to_utf32 (np_test_1_all.cpp:12748) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12738 :emphasize-lines: 11 // std::cout << "String argsort test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_utf8_conversion() { std::cout << "========= test_utf8_conversion ======================="; // Test UTF-8 to UTF-32 conversion std::string utf8_str = "Hello"; auto utf32_str = numpy::string_sort::detail::utf8_to_utf32(utf8_str); if (!(utf32_str.size() == utf8_str.size())) { std::string description = std::string("test_utf8_conversion():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(utf32_str.size() == utf8_str.size())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test with ASCII characters for (size_t i = 0; i < utf8_str.size(); ++i) { if (!(utf32_str[i] == static_cast(utf8_str[i]))) { .. _example-top_level-validatenestedstructure-1648: .. dropdown:: validateNestedStructure (np_test_3_all.cpp:21285) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21275 :emphasize-lines: 11 inner1.setElementAt({1}, numpy::object_(2)); numpy::NDArray inner2({2}); inner2.setElementAt({0}, numpy::object_(3)); inner2.setElementAt({1}, numpy::object_(4)); numpy::NDArray outer({2}); outer.setElementAt({0}, numpy::object_(inner1)); outer.setElementAt({1}, numpy::object_(inner2)); bool valid = numpy::NestedArray::validateNestedStructure(outer); CHECK(valid, "np_test_nested_validate", "homogeneous should be valid"); // Create heterogeneous structure (different inner shapes) numpy::NDArray inner3({3}); // Different size! inner3.setElementAt({0}, numpy::object_(1)); inner3.setElementAt({1}, numpy::object_(2)); inner3.setElementAt({2}, numpy::object_(3)); numpy::NDArray hetero({2}); hetero.setElementAt({0}, numpy::object_(inner1)); // size 2 .. _example-top_level-validate_file_size-1649: .. dropdown:: validate_file_size (np_test_2_all.cpp:11077) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11067 :emphasize-lines: 11 std::string description = std::string("testFileUtilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(element_count > 15)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] File size utilities work correctly\n"; // Test file size validation std::vector correct_shape = { 5, 3 }; std::vector too_large_shape = { 100, 100 }; if (!(validate_file_size(TEMP_DIR + "test_utilities.npy", correct_shape))) { std::string description = std::string("testFileUtilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(validate_file_size(TEMP_DIR + \"test_utilities.npy\", correct_shape))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!validate_file_size(TEMP_DIR + "test_utilities.npy", too_large_shape))) { std::string description = std::string("testFileUtilities():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!validate_file_size(TEMP_DIR + \"test_utilities.npy\", too_large_shape))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] File size validation works correctly\n"; .. _example-top_level-vector_norm_2-1650: .. dropdown:: vector_norm_2 (np_test_2_all.cpp:7381) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7371 :emphasize-lines: 11 if (!(row == 2 && col == 3)) { std::string description = std::string("test_matrix_operations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(row == 2 && col == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Matrix indexing: (2,3) -> " << idx << " -> (" << row << "," << col << ")" << std::endl; // Test vector operations double vec[3] = { 3.0, 4.0, 0.0 }; double norm = vector_norm_2(vec, 3); if (!(std::abs(norm - 5.0) < 1e-10)) { std::string description = std::string("test_matrix_operations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(norm - 5.0) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Vector norm [3,4,0]: " << norm << std::endl; // std::cout << "Matrix operations test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-top_level-vector_norm_inf-1651: .. dropdown:: vector_norm_inf (np_test_5_all.cpp:3031) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3021 :emphasize-lines: 11 // std::cout << " vector_norm_2([3, 4]) = " << result << " (expected 5)" << std::endl; std::cout << " -> tests passed" << std::endl; } void np_test_linalg_vector_norm_inf() { std::cout << "========= vector_norm_inf helper ======================="; // Test infinity norm std::vector vec = { -5.0, 3.0, 1.0, -7.0, 2.0 }; double result = numpy::linalg::utils::vector_norm_inf(vec.data(), 5); // max(|-5|, |3|, |1|, |-7|, |2|) = 7 bool passed = is_close(result, 7.0); if (!passed) { std::cout << " [FAIL] : in np_test_linalg_vector_norm_inf() : norm " << result << " != expected 7.0"; throw std::runtime_error("np_test_linalg_vector_norm_inf failed: incorrect norm"); } // std::cout << " vector_norm_inf([-5,3,1,-7,2]) = " << result << " (expected 7)" << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-top_level-vectorize-1652: .. dropdown:: vectorize (np_test_1_all.cpp:14881) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14871 :emphasize-lines: 11 std::cout << "[Vectorize] Test Suite" << std::endl; std::cout << "===========================" << std::endl; int errors = 0; try { // Test 1: Basic scalar function vectorization std::cout << "========= test_basic_scalar_vectorization =======================" ; auto square = [](double x) { return x * x; }; auto vectorized_square = numpy::vectorize(square); numpy::NDArray arr({ 3 }); arr.setElementAt({ 0 }, 2.0); arr.setElementAt({ 1 }, 3.0); arr.setElementAt({ 2 }, 4.0); auto result = vectorized_square(arr); numpy::NDArray expected({ 3 }); expected.setElementAt({ 0 }, 4.0); .. _example-top_level-vectorize-1653: .. dropdown:: vectorize (np_test_1_all.cpp:14881) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14871 :emphasize-lines: 11 std::cout << "[Vectorize] Test Suite" << std::endl; std::cout << "===========================" << std::endl; int errors = 0; try { // Test 1: Basic scalar function vectorization std::cout << "========= test_basic_scalar_vectorization =======================" ; auto square = [](double x) { return x * x; }; auto vectorized_square = numpy::vectorize(square); numpy::NDArray arr({ 3 }); arr.setElementAt({ 0 }, 2.0); arr.setElementAt({ 1 }, 3.0); arr.setElementAt({ 2 }, 4.0); auto result = vectorized_square(arr); numpy::NDArray expected({ 3 }); expected.setElementAt({ 0 }, 4.0); .. _example-top_level-vectorize-1654: .. dropdown:: vectorize (np_test_1_all.cpp:14881) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14871 :emphasize-lines: 11 std::cout << "[Vectorize] Test Suite" << std::endl; std::cout << "===========================" << std::endl; int errors = 0; try { // Test 1: Basic scalar function vectorization std::cout << "========= test_basic_scalar_vectorization =======================" ; auto square = [](double x) { return x * x; }; auto vectorized_square = numpy::vectorize(square); numpy::NDArray arr({ 3 }); arr.setElementAt({ 0 }, 2.0); arr.setElementAt({ 1 }, 3.0); arr.setElementAt({ 2 }, 4.0); auto result = vectorized_square(arr); numpy::NDArray expected({ 3 }); expected.setElementAt({ 0 }, 4.0); .. _example-top_level-vectorize-1655: .. dropdown:: vectorize (np_test_1_all.cpp:14881) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14871 :emphasize-lines: 11 std::cout << "[Vectorize] Test Suite" << std::endl; std::cout << "===========================" << std::endl; int errors = 0; try { // Test 1: Basic scalar function vectorization std::cout << "========= test_basic_scalar_vectorization =======================" ; auto square = [](double x) { return x * x; }; auto vectorized_square = numpy::vectorize(square); numpy::NDArray arr({ 3 }); arr.setElementAt({ 0 }, 2.0); arr.setElementAt({ 1 }, 3.0); arr.setElementAt({ 2 }, 4.0); auto result = vectorized_square(arr); numpy::NDArray expected({ 3 }); expected.setElementAt({ 0 }, 4.0); .. _example-top_level-vectorize-1656: .. dropdown:: vectorize (np_test_1_all.cpp:14881) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14871 :emphasize-lines: 11 std::cout << "[Vectorize] Test Suite" << std::endl; std::cout << "===========================" << std::endl; int errors = 0; try { // Test 1: Basic scalar function vectorization std::cout << "========= test_basic_scalar_vectorization =======================" ; auto square = [](double x) { return x * x; }; auto vectorized_square = numpy::vectorize(square); numpy::NDArray arr({ 3 }); arr.setElementAt({ 0 }, 2.0); arr.setElementAt({ 1 }, 3.0); arr.setElementAt({ 2 }, 4.0); auto result = vectorized_square(arr); numpy::NDArray expected({ 3 }); expected.setElementAt({ 0 }, 4.0); .. _example-top_level-vectorize-1657: .. dropdown:: vectorize (np_test_1_all.cpp:14881) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 14871 :emphasize-lines: 11 std::cout << "[Vectorize] Test Suite" << std::endl; std::cout << "===========================" << std::endl; int errors = 0; try { // Test 1: Basic scalar function vectorization std::cout << "========= test_basic_scalar_vectorization =======================" ; auto square = [](double x) { return x * x; }; auto vectorized_square = numpy::vectorize(square); numpy::NDArray arr({ 3 }); arr.setElementAt({ 0 }, 2.0); arr.setElementAt({ 1 }, 3.0); arr.setElementAt({ 2 }, 4.0); auto result = vectorized_square(arr); numpy::NDArray expected({ 3 }); expected.setElementAt({ 0 }, 4.0); .. _example-top_level-who-1658: .. dropdown:: who (np_test_2_all.cpp:19899) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19889 :emphasize-lines: 11 // ============================================================================ void np_test_introspection_stubs() { std::cout << "========= source/who: stub functions ======================="; // Test source (stub function) int test_var = 42; // std::cout << "Testing source():" << std::endl; numpy::introspection::source(test_var); // Test who (stub function) // std::cout << "Testing who():" << std::endl; numpy::introspection::who("numpy"); bool passed = true; // Stubs should not throw if (!passed) { std::cout << " [FAIL] : in np_test_introspection_stubs() : stub test failed"; throw std::runtime_error("np_test_introspection_stubs failed"); } .. _example-top_level-zfill-1659: .. dropdown:: zfill (np_test_1_all.cpp:6613) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6603 :emphasize-lines: 11 // Test rjust auto right_just = rjust(arr, 8, '+'); // std::cout << "Right justified (width=8, fill='+'):" << std::endl; for (size_t i = 0; i < right_just.size(); ++i) { // std::cout << "'" << right_just[i] << "'"; } // Test zfill with numbers std::vector numbers = {"42", "-17", "+99"}; auto num_arr = array<32>(numbers); auto zero_filled = zfill(num_arr, 6); // std::cout << "Zero filled numbers (width=6):" << std::endl; for (size_t i = 0; i < zero_filled.size(); ++i) { // std::cout << "'" << num_arr[i] << "' -> '" << zero_filled[i] << "'"; } std::cout << " -> tests passed" << std::endl; } void testStringTrimmingCharArray() { std::cout << "========= testStringTrimming ======================="; .. _example-top_level-zfill-1660: .. dropdown:: zfill (np_test_1_all.cpp:6613) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6603 :emphasize-lines: 11 // Test rjust auto right_just = rjust(arr, 8, '+'); // std::cout << "Right justified (width=8, fill='+'):" << std::endl; for (size_t i = 0; i < right_just.size(); ++i) { // std::cout << "'" << right_just[i] << "'"; } // Test zfill with numbers std::vector numbers = {"42", "-17", "+99"}; auto num_arr = array<32>(numbers); auto zero_filled = zfill(num_arr, 6); // std::cout << "Zero filled numbers (width=6):" << std::endl; for (size_t i = 0; i < zero_filled.size(); ++i) { // std::cout << "'" << num_arr[i] << "' -> '" << zero_filled[i] << "'"; } std::cout << " -> tests passed" << std::endl; } void testStringTrimmingCharArray() { std::cout << "========= testStringTrimming ======================="; .. _example-top_level-zfill-1661: .. dropdown:: zfill (np_test_1_all.cpp:6613) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6603 :emphasize-lines: 11 // Test rjust auto right_just = rjust(arr, 8, '+'); // std::cout << "Right justified (width=8, fill='+'):" << std::endl; for (size_t i = 0; i < right_just.size(); ++i) { // std::cout << "'" << right_just[i] << "'"; } // Test zfill with numbers std::vector numbers = {"42", "-17", "+99"}; auto num_arr = array<32>(numbers); auto zero_filled = zfill(num_arr, 6); // std::cout << "Zero filled numbers (width=6):" << std::endl; for (size_t i = 0; i < zero_filled.size(); ++i) { // std::cout << "'" << num_arr[i] << "' -> '" << zero_filled[i] << "'"; } std::cout << " -> tests passed" << std::endl; } void testStringTrimmingCharArray() { std::cout << "========= testStringTrimming ======================="; .. _example-top_level-zscore-1662: .. dropdown:: zscore (np_test_1_all.cpp:11489) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11479 :emphasize-lines: 11 void testStandardizationAndRanking() { std::cout << "========= testStandardizationAndRanking ======================="; // Test zscore auto data = createFloat32Array({ 4 }, 0.0f); data.setElementAt({ 0 }, 1.0f); data.setElementAt({ 1 }, 2.0f); data.setElementAt({ 2 }, 3.0f); data.setElementAt({ 3 }, 4.0f); auto zscore_result = zscore(data); // std::cout << "Z-scores calculated" << std::endl; // Z-scores should sum to approximately 0 double sum = 0; for (size_t i = 0; i < 4; ++i) { sum += zscore_result.getElementAt({ i }); } if (!(std::abs(sum) < 1e-10)) { std::string description = std::string("testStandardizationAndRanking():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(sum) < 1e-10)"; std::cout << std::string("[FAIL] ") + description << std::endl;