DataFrame ========= .. cpp:class:: numpy::DataFrame numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use DataFrame DataFrame obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``DataFrame(const std::map>& data, std::unique_ptr index = nullptr)`` - df_dataframe.h:381 - * - ``DataFrame(const std::vector>& columns, const std::vector& column_names, std::unique_ptr index = nullptr)`` - df_dataframe.h:433 - * - ``DataFrame(const numpy::NDArray& data, std::unique_ptr index = nullptr, const std::vector& columns =`` - df_dataframe.h:492 - * - ``DataFrame(const DataFrame& other)`` - df_dataframe.h:543 - * - ``DataFrame(DataFrame&& other) noexcept`` - df_dataframe.h:558 - Construction ------------ .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``static DataFrame from_dict( const std::map>& data, const std::string& orient = "columns", const std::vector& columns =`` - DataFrame - df_dataframe.h:18160 - * - ``static DataFrame from_dict( const std::map>& data, std::unique_ptr index)`` - DataFrame - df_dataframe.h:18339 - * - ``static DataFrame from_dict_tight(const TightDict& tight_data)`` - DataFrame - df_dataframe.h:18288 - * - ``static DataFrame from_records( const std::vector>& data, const std::vector& columns, const std::string& index = "", const std::vector& exclude =`` - DataFrame - df_dataframe.h:18388 - * - ``static DataFrame from_records( const std::vector>& data, const std::string& index = "", const std::vector& exclude =`` - DataFrame - df_dataframe.h:18573 - * - ``static DataFrame from_records_tuple( const std::vector>& data, const std::vector& columns, size_t nrows = 0)`` - DataFrame - df_dataframe.h:18716 - * - ``oss << make_hsep('+', '-', '+') << "\\n"`` - oss << - df_dataframe.h:17976 - * - ``oss << make_hsep('+', '=', '+') << "\\n"`` - oss << - df_dataframe.h:17991 - * - ``oss << make_hsep('+', '-', '+') << "\\n"`` - oss << - df_dataframe.h:18012 - Array Creation -------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool empty() const override`` - bool - df_dataframe.h:616 - :ref:`View ` Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``T at(const std::string& row_label, const std::string& col_label) const`` - T - df_dataframe.h:1659 - :ref:`View ` * - ``DataFrame at_time(const std::string& time) const`` - DataFrame - df_dataframe.h:12177 - * - ``const Attrs& attrs() const override`` - const Attrs& - df_dataframe.h:750 - * - ``Attrs& attrs() override`` - Attrs& - df_dataframe.h:757 - * - ``std::optional get(const std::string& key, std::optional default_value = std::nullopt) const`` - std::optional - df_dataframe.h:6165 - :ref:`View ` * - ``size_t get_column_index(const std::string& name) const`` - size_t - df_dataframe.h:1494 - * - ``std::vector get_column_values_as_double\_(size_t col_idx) const`` - std::vector - df_dataframe.h:10357 - * - ``size_t get_num_levels(int axis) const`` - size_t - df_dataframe.h:8009 - * - ``std::optional get_optional(const std::string& key) const`` - std::optional - df_dataframe.h:2398 - * - ``size_t get_row_index(const std::string& label) const`` - size_t - df_dataframe.h:22250 - * - ``bool get_value_bool(size_t idx) const override`` - bool - df_dataframe.h:3287 - * - ``std::string get_value_str(size_t idx) const override`` - std::string - df_dataframe.h:22137 - * - ``ItemsRange items() const`` - ItemsRange - df_dataframe.h:1045 - * - ``DataFrame select_dtypes(const std::vector& include =`` - DataFrame - df_dataframe.h:2623 - * - ``DataFrame take(const std::vector& indices) const`` - DataFrame - df_dataframe.h:1720 - :ref:`View ` * - ``DataFrame where(const DataFrame& cond, double other = std::numeric_limits::quiet_NaN()) const`` - DataFrame - df_dataframe.h:3564 - :ref:`View ` Shape Manipulation ------------------ .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``DataFrame T() const`` - DataFrame - df_dataframe.h:685 - :ref:`View ` * - ``DataFrame squeeze() const`` - DataFrame - df_dataframe.h:8673 - :ref:`View ` * - ``DataFrame swapaxes(int axis1 = 0, int axis2 = 1) const`` - DataFrame - df_dataframe.h:6201 - :ref:`View ` * - ``DataFrame transpose() const`` - DataFrame - df_dataframe.h:7426 - :ref:`View ` Statistics ---------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``DataFrame cov(int ddof = 1) const`` - DataFrame - df_dataframe.h:6763 - :ref:`View ` * - ``Series max(int axis = 0, bool skipna = true, bool numeric_only = false) const`` - Series - df_dataframe.h:5481 - :ref:`View ` * - ``Series max_cols(bool skipna = true) const`` - Series - df_dataframe.h:4383 - * - ``Series mean(int axis = 0, bool skipna = true, bool numeric_only = false) const`` - Series - df_dataframe.h:5314 - :ref:`View ` * - ``Series mean_cols(bool skipna = true) const`` - Series - df_dataframe.h:4322 - * - ``Series median(int axis = 0, bool skipna = true, bool numeric_only = false) const`` - Series - df_dataframe.h:4849 - :ref:`View ` * - ``Series median_cols(bool skipna = true) const`` - Series - df_dataframe.h:4801 - * - ``Series min(int axis = 0, bool skipna = true, bool numeric_only = false) const`` - Series - df_dataframe.h:5438 - :ref:`View ` * - ``Series min_cols(bool skipna = true) const`` - Series - df_dataframe.h:4353 - * - ``Series quantile(double q = 0.5, int axis = 0, bool numeric_only = false, const std::string& interpolation = "linear") const`` - Series - df_dataframe.h:5685 - :ref:`View ` * - ``Series quantile_cols(double q, const std::string& interpolation = "linear") const`` - Series - df_dataframe.h:6681 - * - ``Series std(int axis = 0, bool skipna = true, int ddof = 1, bool numeric_only = false) const`` - Series - df_dataframe.h:5357 - :ref:`View ` * - ``Series std_cols(bool skipna = true, int ddof = 1) const`` - Series - df_dataframe.h:4599 - * - ``Series sum(int axis = 0, bool skipna = true, bool numeric_only = false) const`` - Series - df_dataframe.h:5274 - :ref:`View ` * - ``Series sum_cols(bool skipna = true) const`` - Series - df_dataframe.h:4293 - * - ``Series var(int axis = 0, bool skipna = true, int ddof = 1, bool numeric_only = false) const`` - Series - df_dataframe.h:5405 - :ref:`View ` * - ``Series var_cols(bool skipna = true, int ddof = 1) const`` - Series - df_dataframe.h:4637 - Sorting ------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``DataFrame sort_index(bool ascending = true) const`` - DataFrame - df_dataframe.h:7326 - * - ``DataFrame sort_values(const std::string& by, bool ascending = true) const`` - DataFrame - df_dataframe.h:7290 - * - ``DataFrame sort_values(const std::vector& by, bool ascending = true) const`` - DataFrame - df_dataframe.h:7297 - Math Operations --------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``DataFrame abs() const`` - DataFrame - df_dataframe.h:9252 - :ref:`View ` * - ``DataFrame add(const DataFrame& other, double fill_value = 0.0) const`` - DataFrame - df_dataframe.h:8958 - :ref:`View ` * - ``DataFrame add(double scalar) const`` - DataFrame - df_dataframe.h:8962 - :ref:`View ` * - ``void add_column(const std::string& name, const std::vector& data)`` - void - df_dataframe.h:2466 - * - ``DataFrame add_prefix(const std::string& prefix, int axis = -1) const`` - DataFrame - df_dataframe.h:2317 - * - ``add_shared_string(idx_lbl)`` - - df_dataframe.h:15159 - * - ``add_shared_string(columns_index\_.get_value_str(c))`` - - df_dataframe.h:15163 - * - ``add_shared_string(idx_val)`` - - df_dataframe.h:15172 - * - ``add_shared_string(na_rep)`` - - df_dataframe.h:15179 - * - ``add_shared_string(val)`` - - df_dataframe.h:15182 - * - ``DataFrame add_suffix(const std::string& suffix, int axis = -1) const`` - DataFrame - df_dataframe.h:2362 - * - ``add_zip_entry("[Content_Types].xml", content_types.str())`` - - df_dataframe.h:15216 - * - ``add_zip_entry("_rels/.rels", rels.str())`` - - df_dataframe.h:15224 - * - ``add_zip_entry("xl/_rels/workbook.xml.rels", wb_rels.str())`` - - df_dataframe.h:15234 - * - ``add_zip_entry("xl/workbook.xml", workbook.str())`` - - df_dataframe.h:15245 - * - ``add_zip_entry("xl/styles.xml", styles.str())`` - - df_dataframe.h:15257 - * - ``add_zip_entry("xl/sharedStrings.xml", shared_strings_xml.str())`` - - df_dataframe.h:15268 - * - ``add_zip_entry("xl/worksheets/sheet1.xml", sheet.str())`` - - df_dataframe.h:15388 - * - ``DataFrame ceil() const`` - DataFrame - df_dataframe.h:9245 - :ref:`View ` * - ``DataFrame divide(const DataFrame& other, double fill_value = 1.0) const`` - DataFrame - df_dataframe.h:9007 - :ref:`View ` * - ``DataFrameExpanding expanding(size_t min_periods = 1) const`` - DataFrameExpanding - df_dataframe.h:5971 - * - ``DataFrame explode(const std::string& column) const`` - DataFrame - df_dataframe.h:8613 - * - ``DataFrame floor() const`` - DataFrame - df_dataframe.h:9238 - :ref:`View ` * - ``DataFrame floordiv(const DataFrame& other) const`` - DataFrame - df_dataframe.h:9022 - * - ``DataFrame floordiv(double scalar) const`` - DataFrame - df_dataframe.h:9026 - * - ``DataFrame mod(const DataFrame& other) const`` - DataFrame - df_dataframe.h:9033 - :ref:`View ` * - ``DataFrame mod(double scalar) const`` - DataFrame - df_dataframe.h:9037 - :ref:`View ` * - ``\* Returns a DataFrame where each column contains the mode(s) for that column.`` - \* Returns a DataFrame where each column contains the - df_dataframe.h:4903 - :ref:`View ` * - ``DataFrame mode(int axis = 0, bool numeric_only = false, bool dropna = true) const`` - DataFrame - df_dataframe.h:4912 - :ref:`View ` * - ``DataFrame mode_cols(bool numeric_only = false, bool dropna = true) const`` - DataFrame - df_dataframe.h:4931 - * - ``DataFrame mode_rows(bool numeric_only = false, bool dropna = true) const`` - DataFrame - df_dataframe.h:5067 - * - ``DataFrame multiply(const DataFrame& other, double fill_value = 1.0) const`` - DataFrame - df_dataframe.h:8992 - :ref:`View ` * - ``DataFrame round(int decimals = 0) const`` - DataFrame - df_dataframe.h:9228 - :ref:`View ` * - ``DataFrame subtract(const DataFrame& other, double fill_value = 0.0) const`` - DataFrame - df_dataframe.h:8977 - :ref:`View ` * - ``DataFrame truncate(const std::optional& before = std::nullopt, const std::optional& after = std::nullopt) const`` - DataFrame - df_dataframe.h:12215 - :ref:`View ` Linear Algebra -------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``DataFrame dot(const DataFrame& other) const`` - DataFrame - df_dataframe.h:8806 - :ref:`View ` * - ``Series dot(const Series& other) const`` - Series - df_dataframe.h:8865 - :ref:`View ` * - ``void invalidate_caches() const`` - void - df_dataframe.h:22246 - Random ------ .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``DataFrame sample(size_t n, unsigned int seed = 0) const`` - DataFrame - df_dataframe.h:1694 - :ref:`View ` * - ``DataFrame sample_frac(double frac, unsigned int seed = 0) const`` - DataFrame - df_dataframe.h:1712 - Comparison ---------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool equals(const DataFrame& other) const`` - bool - df_dataframe.h:4193 - Logical ------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool all(bool skipna = true) const override`` - bool - df_dataframe.h:11025 - :ref:`View ` * - ``Series all_axis(int axis = 0, bool skipna = true) const`` - Series - df_dataframe.h:11053 - * - ``bool any(bool skipna = true) const override`` - bool - df_dataframe.h:11035 - :ref:`View ` * - ``Series any_axis(int axis = 0, bool skipna = true) const`` - Series - df_dataframe.h:11175 - Set Operations -------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``DataFrame isin(const std::vector& values) const`` - DataFrame - df_dataframe.h:3407 - :ref:`View ` * - ``DataFrame isin(const std::map>& values) const`` - DataFrame - df_dataframe.h:3461 - :ref:`View ` I/O --- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void to_clipboard( bool excel = true, char sep = '\\t', bool index = true, bool header = true, const std::string& na_rep = "") const`` - void - df_dataframe.h:17591 - * - ``std::string to_csv(bool include_index = true, char sep = ',') const`` - std::string - df_dataframe.h:12336 - * - ``std::map> to_dict( const std::string& orient = "list") const`` - std::map> - df_dataframe.h:12669 - * - ``std::map> to_dict_orient_dict( bool index = true) const`` - std::map> - df_dataframe.h:12714 - * - ``std::map> to_dict_orient_index() const`` - std::map> - df_dataframe.h:12800 - * - ``std::vector> to_dict_orient_records( bool index = false) const`` - std::vector> - df_dataframe.h:12753 - * - ``std::map> to_dict_orient_series() const`` - std::map> - df_dataframe.h:12954 - * - ``DictSplitResult to_dict_orient_split(bool index = true) const`` - DictSplitResult - df_dataframe.h:12840 - * - ``DictTightResult to_dict_orient_tight(bool index = true) const`` - DictTightResult - df_dataframe.h:12899 - * - ``void to_excel( const std::string& excel_writer, const std::string& sheet_name = "Sheet1", const std::string& na_rep = "", const std::string& float_format = "", const std::vector& columns =`` - void - df_dataframe.h:15022 - * - ``\* This is the inverse operation of to_excel().`` - \* This is the inverse operation of - df_dataframe.h:19062 - * - ``\* This is the inverse operation of to_feather().`` - \* This is the inverse operation of - df_dataframe.h:20763 - * - ``std::vector to_feather( const std::string& path = "", const std::string& compression = "uncompressed", [[maybe_unused]] int compression_level = -1, [[maybe_unused]] int64_t chunksize = -1, int version = 2) const`` - std::vector - df_dataframe.h:20934 - * - ``void to_gbq(const std::string& destination_table, const std::string& project_id = "", const std::string& if_exists = "fail", bool progress_bar = true) const`` - void - df_dataframe.h:6255 - * - ``std::vector to_hdf( const std::string& path_or_buf = "", const std::string& key = "df", const std::string& mode = "a", [[maybe_unused]] std::optional complevel = std::nullopt, [[maybe_unused]] const std::string& complib = "zlib", [[maybe_unused]] bool append = false, const std::string& format = "fixed", bool index = true, [[maybe_unused]] const std::map& min_itemsize =`` - std::vector - df_dataframe.h:14419 - * - ``\* Reads a file written by to_hdf() and returns its contents as a DataFrame.`` - \* Reads a file written by - df_dataframe.h:19928 - * - ``\* This is the inverse operation of to_hdf().`` - \* This is the inverse operation of - df_dataframe.h:19929 - * - ``std::string to_html( std::ostream\* buf = nullptr, const std::vector& columns =`` - std::string - df_dataframe.h:15603 - * - ``std::string to_json(const std::string& orient = "columns") const`` - std::string - df_dataframe.h:12367 - * - ``std::string to_latex( std::ostream\* buf = nullptr, const std::vector& columns =`` - std::string - df_dataframe.h:15983 - * - ``std::string to_markdown( std::ostream\* buf = nullptr, [[maybe_unused]] const std::string& mode = "wt", bool index = true, const std::string& tablefmt = "pipe", const std::vector& colalign =`` - std::string - df_dataframe.h:17799 - * - ``numpy::NDArray to_numpy(const std::string& dtype = "float64", bool copy = true, double na_value = std::numeric_limits::quiet_NaN()) const`` - numpy::NDArray - df_dataframe.h:6218 - :ref:`View ` * - ``std::vector to_orc( const std::string& path = "", const std::string& engine = "pyarrow", std::optional index = std::nullopt, [[maybe_unused]] const std::map& engine_kwargs =`` - std::vector - df_dataframe.h:13005 - * - ``std::vector to_parquet( const std::string& path = "", const std::string& engine = "pyarrow", [[maybe_unused]] const std::string& compression = "snappy", std::optional index = std::nullopt, const std::vector& partition_cols =`` - std::vector - df_dataframe.h:13568 - * - ``\* This is the inverse operation of to_parquet().`` - \* This is the inverse operation of - df_dataframe.h:19474 - * - ``\* (use to_parquet() for custom indices)`` - \* (use - df_dataframe.h:20912 - * - ``DataFrame to_period(const std::string& freq = "", int axis = 0, bool copy = true) const`` - DataFrame - df_dataframe.h:12013 - * - ``std::vector to_pickle( const std::string& path = "", [[maybe_unused]] const std::string& compression = "infer", [[maybe_unused]] int protocol = 5) const`` - std::vector - df_dataframe.h:14213 - * - ``numpy::RecordArray to_records( bool index = true, const std::map& column_dtypes =`` - numpy::RecordArray - df_dataframe.h:16347 - * - ``std::vector> to_records_dict() const`` - std::vector> - df_dataframe.h:20867 - * - ``std::optional to_sql( const std::string& name, const std::string& con_path, const std::string& schema = "", const std::string& if_exists = "fail", bool index = true, const std::string& index_label = "", std::optional chunksize = std::nullopt, const std::map& dtype =`` - std::optional - df_dataframe.h:14659 - * - ``\* Reads a SQLite database file created by to_sql() and returns a DataFrame.`` - \* Reads a SQLite database file created by - df_dataframe.h:20155 - * - ``\* This parses the SQL file format generated by to_sql().`` - \* This parses the SQL file format generated by - df_dataframe.h:20156 - * - ``\* generated by to_sql(). For full SQL support, use a database library.`` - \* generated by - df_dataframe.h:20176 - * - ``std::vector to_stata( const std::string& path = "", const std::map& convert_dates =`` - std::vector - df_dataframe.h:16620 - * - ``\* This is the inverse operation of to_stata().`` - \* This is the inverse operation of - df_dataframe.h:20373 - * - ``\* If false, write a string representation (similar to to_string()).`` - \* If false, write a string representation (similar to - df_dataframe.h:17544 - :ref:`View ` * - ``std::string to_string() const override`` - std::string - df_dataframe.h:22164 - :ref:`View ` * - ``std::vector to_string_vector() const override`` - std::vector - df_dataframe.h:22150 - * - ``DataFrame to_timestamp(const std::string& freq = "", const std::string& how = "start", int axis = 0, bool copy = true) const`` - DataFrame - df_dataframe.h:12054 - * - ``Dataset to_xarray() const`` - Dataset - df_dataframe.h:21983 - * - ``std::string to_xml(const std::string& path = "", bool index = true, const std::string& root_name = "data", const std::string& row_name = "row", bool pretty_print = true) const`` - std::string - df_dataframe.h:6278 - Joining / Splitting ------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void insert(size_t loc, const std::string& column, std::unique_ptr value)`` - void - df_dataframe.h:2434 - :ref:`View ` * - ``insert(ncols(), name, std::make_unique>(data, name))`` - - df_dataframe.h:2467 - :ref:`View ` * - ``DataFrame stack() const`` - DataFrame - df_dataframe.h:8694 - :ref:`View ` Type Handling ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``DataFrame astype(const std::string& dtype) const`` - DataFrame - df_dataframe.h:9622 - :ref:`View ` * - ``DataFrame astype(const std::map& dtype_map) const`` - DataFrame - df_dataframe.h:9644 - :ref:`View ` * - ``DataFrame copy([[maybe_unused]] bool deep = true) const`` - DataFrame - df_dataframe.h:12317 - :ref:`View ` * - ``copy_to_clipboard_impl(text)`` - - df_dataframe.h:17639 - * - ``static void copy_to_clipboard_impl(const std::string& text)`` - static void - df_dataframe.h:17648 - * - ``void copy_value_from(size_t src_idx, size_t dst_idx) override`` - void - df_dataframe.h:3336 - Special Functions ----------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``DataFrame combine(const DataFrame& other, Func func, std::optional fill_value = std::nullopt, bool overwrite = true) const`` - DataFrame - df_dataframe.h:11622 - :ref:`View ` * - ``DataFrame combine_first(const DataFrame& other) const`` - DataFrame - df_dataframe.h:11738 - Type Checking ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``static bool is_bool_string(const std::string& value)`` - static bool - df_dataframe.h:9861 - * - ``static bool is_float_actually_integer(double value)`` - static bool - df_dataframe.h:9906 - * - ``static bool is_float_string(const std::string& value)`` - static bool - df_dataframe.h:9887 - * - ``bool is_homogeneous_type() const`` - bool - df_dataframe.h:785 - * - ``static bool is_integer_string(const std::string& value)`` - static bool - df_dataframe.h:9869 - * - ``bool is_na_at(size_t idx) const override`` - bool - df_dataframe.h:3252 - Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``\* DataFrame A(`` - \* DataFrame - df_dataframe.h:8801 - :ref:`View ` * - ``\* DataFrame A(`` - \* DataFrame - df_dataframe.h:8859 - :ref:`View ` * - ``\* DataFrame B(`` - \* DataFrame - df_dataframe.h:8802 - :ref:`View ` * - ``\* Reads an Excel (.xlsx) file and returns its contents as a DataFrame.`` - \* Reads an - df_dataframe.h:19061 - * - ``\* Reads a Feather (Arrow IPC) file and returns its contents as a DataFrame.`` - \* Reads a - df_dataframe.h:20762 - * - ``\* Hierarchical Data Format (HDF) is a self-describing format that allows`` - \* Hierarchical Data - df_dataframe.h:14344 - * - ``GlobalFree(hMem)`` - - df_dataframe.h:17672 - * - ``GlobalFree(hMem)`` - - df_dataframe.h:17682 - * - ``GlobalUnlock(hMem)`` - - df_dataframe.h:17678 - * - ``\* The Series has a MultiIndex (or single Index) from the unique value combinations.`` - \* The Series has a - df_dataframe.h:6464 - * - ``\* Writes the DataFrame to an Excel file in the Office Open XML (.xlsx) format.`` - \* Writes the DataFrame to an Excel file in the Office Open - df_dataframe.h:14963 - * - ``DataFrame agg(const std::string& func_name, int axis = 0) const`` - DataFrame - df_dataframe.h:10908 - * - ``DataFrame agg(const std::vector& funcs, int axis = 0) const`` - DataFrame - df_dataframe.h:10968 - * - ``DataFrame aggregate(const std::string& func_name, int axis = 0) const`` - DataFrame - df_dataframe.h:10998 - * - ``DataFrame aggregate(const std::vector& funcs, int axis = 0) const`` - DataFrame - df_dataframe.h:11005 - * - ``std::pair align( const DataFrame& other, const std::string& join = "outer", int axis = -1, double fill_value = std::numeric_limits::quiet_NaN()) const`` - std::pair - df_dataframe.h:11556 - * - ``\* If empty, uses default alignment (right for numeric, left for text).`` - \* If empty, uses default - df_dataframe.h:17748 - * - ``DataFrame apply(Func&& func, int axis = 0) const`` - DataFrame - df_dataframe.h:9473 - * - ``std::vector apply_named_transform\_(const std::string& func_name, const std::vector& values) const`` - std::vector - df_dataframe.h:10375 - * - ``DataFrame applymap(Func&& func) const`` - DataFrame - df_dataframe.h:9515 - * - ``std::istringstream arr_stream(arr_str)`` - std::istringstream - df_dataframe.h:18980 - * - ``DataFrame asfreq(const std::string& freq, const std::string& method = "") const`` - DataFrame - df_dataframe.h:11966 - * - ``Series asof(const std::string& where, const std::vector& subset =`` - Series - df_dataframe.h:12260 - * - ``DataFrame asof(const std::vector& where, const std::vector& subset =`` - DataFrame - df_dataframe.h:12266 - * - ``DataFrame assign(const std::string& col_name, const std::vector& data) const`` - DataFrame - df_dataframe.h:4253 - * - ``std::vector axes() const override`` - std::vector - df_dataframe.h:706 - :ref:`View ` * - ``numpy::NDArray b(`` - numpy::NDArray - df_dataframe.h:8882 - :ref:`View ` * - ``DataFrame backfill(int axis = 0, std::optional limit = std::nullopt) const`` - DataFrame - df_dataframe.h:6012 - * - ``iterator begin()`` - iterator - df_dataframe.h:888 - :ref:`View ` * - ``const_iterator begin() const`` - const_iterator - df_dataframe.h:892 - :ref:`View ` * - ``DataFrame between_time(const std::string& start_time, const std::string& end_time, bool include_start = true, bool include_end = true) const`` - DataFrame - df_dataframe.h:12190 - * - ``DataFrame between_time(const std::string& start_time, const std::string& end_time, const std::string& inclusive) const`` - DataFrame - df_dataframe.h:12205 - * - ``DataFrame bfill(int axis = 0, std::optional limit = std::nullopt) const`` - DataFrame - df_dataframe.h:2897 - * - ``DataFrame binary_op(const DataFrame& other, BinaryOp op) const`` - DataFrame - df_dataframe.h:22262 - * - ``DataFrame binary_op_fill(const DataFrame& other, double fill_value, BinaryOp op) const`` - DataFrame - df_dataframe.h:22407 - * - ``bool bool\_() const`` - bool - df_dataframe.h:6079 - :ref:`View ` * - ``const_iterator cbegin() const`` - const_iterator - df_dataframe.h:896 - * - ``const_iterator cend() const`` - const_iterator - df_dataframe.h:912 - * - ``std::ifstream check_file(path_or_buf)`` - std::ifstream - df_dataframe.h:14575 - :ref:`View ` * - ``std::ifstream check_file(con_path)`` - std::ifstream - df_dataframe.h:14691 - :ref:`View ` * - ``void clear_cache() const override`` - void - df_dataframe.h:22233 - * - ``DataFrame clip(double lower, double upper) const`` - DataFrame - df_dataframe.h:9259 - :ref:`View ` * - ``std::unique_ptr clone() const override`` - std::unique_ptr - df_dataframe.h:12325 - :ref:`View ` * - ``numpy::NDArray code_arr(std::vector`` - numpy::NDArray - df_dataframe.h:6657 - * - ``Series& col(const std::string& name)`` - Series& - df_dataframe.h:1467 - * - ``const Series& col(const std::string& name) const`` - const Series& - df_dataframe.h:1481 - * - ``std::istringstream cols_stream(cols_def)`` - std::istringstream - df_dataframe.h:20211 - * - ``\* Counts the number of unique (distinct) values per column (axis=0) or per row (axis=1).`` - \* Counts the number of unique (distinct) values per - df_dataframe.h:6396 - :ref:`View ` * - ``\* Apply a named transform function to each column (axis=0) or row (axis=1).`` - \* Apply a named transform function to each - df_dataframe.h:10681 - :ref:`View ` * - ``const Index& columns() const`` - const Index& - df_dataframe.h:692 - :ref:`View ` * - ``\* Data columns (total 3 columns):`` - \* Data - df_dataframe.h:12432 - :ref:`View ` * - ``std::vector> columns(col_names.size())`` - std::vector> - df_dataframe.h:18836 - :ref:`View ` * - ``std::vector> columns(col_indices.size())`` - std::vector> - df_dataframe.h:19406 - :ref:`View ` * - ``std::vector> columns_data(col_names.size())`` - std::vector> - df_dataframe.h:20303 - * - ``DataFrame compare( const DataFrame& other, bool keep_shape = false, bool keep_equal = false) const`` - DataFrame - df_dataframe.h:11832 - * - ``DataFrame compare_op(const DataFrame& other, CompOp op) const`` - DataFrame - df_dataframe.h:22376 - * - ``static DataFrame concat(const std::vector& frames, bool ignore_index = false)`` - static DataFrame - df_dataframe.h:11278 - * - ``inline DataFrame concat(const std::vector& frames, bool ignore_index = false)`` - DataFrame - df_dataframe.h:22493 - * - ``DataFrame convert_dtypes( bool infer_objects = true, bool convert_string = true, bool convert_integer = true, bool convert_boolean = true, bool convert_floating = true) const`` - DataFrame - df_dataframe.h:10058 - * - ``\* Unlike convert_dtypes(), this method:`` - \* Unlike - df_dataframe.h:10183 - * - ``static numpy::bool\_ convert_to_bool(const std::string& value, const std::string& source_dtype, const std::string& col_name, size_t row_idx)`` - static numpy::bool\_ - df_dataframe.h:9829 - * - ``static numpy::float64 convert_to_float64(const std::string& value, const std::string& source_dtype, const std::string& col_name, size_t row_idx)`` - static numpy::float64 - df_dataframe.h:9795 - * - ``static numpy::int64 convert_to_int64(const std::string& value, const std::string& source_dtype, const std::string& col_name, size_t row_idx)`` - static numpy::int64 - df_dataframe.h:9767 - * - ``DataFrame corr(const std::string& method = "pearson") const`` - DataFrame - df_dataframe.h:6722 - * - ``Series corrwith(const DataFrame& other, int axis = 0, bool drop = false, const std::string& method = "pearson", bool numeric_only = false) const`` - Series - df_dataframe.h:6809 - * - ``Series corrwith(const Series& other, int axis = 0, bool drop = false, const std::string& method = "pearson", bool numeric_only = false) const`` - Series - df_dataframe.h:7105 - * - ``size_t count() const override`` - size_t - df_dataframe.h:2756 - :ref:`View ` * - ``Series count_cols() const`` - Series - df_dataframe.h:4653 - * - ``DataFrame cummax(int axis = 0) const`` - DataFrame - df_dataframe.h:9367 - * - ``DataFrame cummin(int axis = 0) const`` - DataFrame - df_dataframe.h:9336 - * - ``DataFrame cumprod(int axis = 0) const`` - DataFrame - df_dataframe.h:9305 - :ref:`View ` * - ``DataFrame cumsum(int axis = 0) const`` - DataFrame - df_dataframe.h:9274 - :ref:`View ` * - ``DataArray da(data,`` - DataArray - df_dataframe.h:22054 - * - ``DataArray da(data,`` - DataArray - df_dataframe.h:22065 - * - ``DataArray da(data,`` - DataArray - df_dataframe.h:22076 - * - ``DataArray da(data,`` - DataArray - df_dataframe.h:22087 - * - ``DataArray da(data,`` - DataArray - df_dataframe.h:22098 - * - ``DataArray da(data,`` - DataArray - df_dataframe.h:22110 - * - ``DataArray da(data,`` - DataArray - df_dataframe.h:22120 - * - ``numpy::NDArray data(std::vector`` - numpy::NDArray - df_dataframe.h:22050 - :ref:`View ` * - ``numpy::NDArray data(std::vector`` - numpy::NDArray - df_dataframe.h:22061 - :ref:`View ` * - ``numpy::NDArray data(std::vector`` - numpy::NDArray - df_dataframe.h:22072 - :ref:`View ` * - ``numpy::NDArray data(std::vector`` - numpy::NDArray - df_dataframe.h:22083 - :ref:`View ` * - ``numpy::NDArray data(std::vector`` - numpy::NDArray - df_dataframe.h:22094 - :ref:`View ` * - ``numpy::NDArray data(std::vector`` - numpy::NDArray - df_dataframe.h:22106 - :ref:`View ` * - ``numpy::NDArray data(std::vector`` - numpy::NDArray - df_dataframe.h:22116 - :ref:`View ` * - ``DataFrame describe() const`` - DataFrame - df_dataframe.h:4670 - :ref:`View ` * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:880 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:924 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:1030 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:1169 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:1379 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:1761 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:3401 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:3451 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:3558 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:3611 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:3665 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:3804 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:6468 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:10049 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:10196 - * - ``\* DataFrame df(std::map>`` - \* DataFrame - df_dataframe.h:12655 - * - ``\* DataFrame df(std::map>`` - \* DataFrame - df_dataframe.h:12705 - * - ``\* DataFrame df(std::map>`` - \* DataFrame - df_dataframe.h:12745 - * - ``\* DataFrame df(std::map>`` - \* DataFrame - df_dataframe.h:12791 - * - ``\* DataFrame df(std::map>`` - \* DataFrame - df_dataframe.h:12831 - * - ``\* DataFrame df(std::map>`` - \* DataFrame - df_dataframe.h:12886 - * - ``\* DataFrame df(std::map>`` - \* DataFrame - df_dataframe.h:12946 - * - ``\* DataFrame df(std::map>`` - \* DataFrame - df_dataframe.h:16322 - * - ``\* pandas::DataFrame df(`` - \* pandas::DataFrame - df_dataframe.h:17560 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:17760 - * - ``\* DataFrame df(data, nullptr,`` - \* DataFrame - df_dataframe.h:21973 - * - ``\* DataFrame df(`` - \* DataFrame - df_dataframe.h:22462 - * - ``\* Converts a sequence of dicts (maps) into a DataFrame. Each dict represents`` - \* Converts a sequence of - df_dataframe.h:18539 - * - ``DataFrame diff(int periods = 1, int axis = 0) const`` - DataFrame - df_dataframe.h:9398 - :ref:`View ` * - ``DataFrame div(const DataFrame& other, double fill_value = 1.0) const`` - DataFrame - df_dataframe.h:8999 - * - ``DataFrame div(double scalar) const`` - DataFrame - df_dataframe.h:9003 - * - ``DataFrame drop(const std::vector& labels, int axis = 0) const`` - DataFrame - df_dataframe.h:2542 - * - ``DataFrame drop_duplicates(const std::vector& subset =`` - DataFrame - df_dataframe.h:4117 - * - ``void drop_inplace(const std::vector& labels, int axis = 0)`` - void - df_dataframe.h:2551 - * - ``static std::string drop_level_from_label(const std::string& label, size_t level)`` - static std::string - df_dataframe.h:7673 - * - ``DataFrame droplevel(int level, int axis = 0) const`` - DataFrame - df_dataframe.h:7483 - * - ``DataFrame droplevel(int level, const std::string& axis) const`` - DataFrame - df_dataframe.h:7500 - * - ``DataFrame droplevel(const std::string& level_name, int axis = 0) const`` - DataFrame - df_dataframe.h:7522 - * - ``DataFrame droplevel(const std::vector& levels, int axis = 0) const`` - DataFrame - df_dataframe.h:7544 - * - ``DataFrame droplevel_columns(int level) const`` - DataFrame - df_dataframe.h:7617 - * - ``DataFrame droplevel_index(int level) const`` - DataFrame - df_dataframe.h:7567 - * - ``DataFrame dropna(int axis = 0, const std::string& how = "any") const`` - DataFrame - df_dataframe.h:2767 - * - ``\* DatetimeIndex dt_idx(`` - \* DatetimeIndex - df_dataframe.h:11998 - * - ``\* DatetimeIndex dt_idx(`` - \* DatetimeIndex - df_dataframe.h:12146 - * - ``std::string dtype_name() const override`` - std::string - df_dataframe.h:649 - :ref:`View ` * - ``Series dtypes() const`` - Series - df_dataframe.h:713 - :ref:`View ` * - ``Series duplicated(const std::vector& subset =`` - Series - df_dataframe.h:4050 - * - ``iterator end()`` - iterator - df_dataframe.h:904 - :ref:`View ` * - ``const_iterator end() const`` - const_iterator - df_dataframe.h:908 - :ref:`View ` * - ``\* Provides begin() and end() for range-based for loops.`` - \* Provides begin() and - df_dataframe.h:1002 - :ref:`View ` * - ``\* Provides begin() and end() for range-based for loops.`` - \* Provides begin() and - df_dataframe.h:1132 - :ref:`View ` * - ``\* Provides begin() and end() for range-based for loops.`` - \* Provides begin() and - df_dataframe.h:1336 - :ref:`View ` * - ``DataFrame eq(const DataFrame& other) const`` - DataFrame - df_dataframe.h:8912 - * - ``escape_html(url) + ""`` - - df_dataframe.h:15725 - * - ``oss << escape_latex(index\_->name().value())`` - oss << - df_dataframe.h:16190 - * - ``oss << escape_latex(col_name)`` - oss << - df_dataframe.h:16202 - * - ``oss << escape_latex(index\_->name().value())`` - oss << - df_dataframe.h:16220 - * - ``oss << escape_latex(col_name)`` - oss << - df_dataframe.h:16230 - * - ``oss << escape_latex(idx_val)`` - oss << - df_dataframe.h:16254 - * - ``static std::string escape_xml(const std::string& str)`` - static std::string - df_dataframe.h:6334 - * - ``std::variant, DataFrame, std::monostate> eval( const std::string& expr, bool inplace = false)`` - std::variant, DataFrame, std::monostate> - df_dataframe.h:3822 - * - ``std::vector eval_expression(const std::string& expr) const`` - std::vector - df_dataframe.h:3928 - * - ``double eval_postfix(const std::vector& postfix, size_t row) const`` - double - df_dataframe.h:3950 - * - ``bool evaluate_comparison(const query::ComparisonNode\* comp, size_t row) const`` - bool - df_dataframe.h:3736 - * - ``bool evaluate_query_node(const query::ASTNode\* node, size_t row) const`` - bool - df_dataframe.h:3704 - * - ``evaluate_query_node(and_node->right.get(), row)`` - - df_dataframe.h:3715 - * - ``evaluate_query_node(or_node->right.get(), row)`` - - df_dataframe.h:3720 - * - ``DataFrameEWM ewm(double span, bool adjust = true, bool ignore_na = false) const`` - DataFrameEWM - df_dataframe.h:5982 - * - ``DataFrame ffill(int axis = 0, std::optional limit = std::nullopt) const`` - DataFrame - df_dataframe.h:2811 - * - ``std::ofstream file(path)`` - std::ofstream - df_dataframe.h:6318 - :ref:`View ` * - ``std::ofstream file(path, std::ios::binary)`` - std::ofstream - df_dataframe.h:13506 - :ref:`View ` * - ``std::ofstream file(path, std::ios::binary)`` - std::ofstream - df_dataframe.h:14149 - :ref:`View ` * - ``std::ofstream file(path, std::ios::binary)`` - std::ofstream - df_dataframe.h:14328 - :ref:`View ` * - ``std::ofstream file(path_or_buf, std::ios::binary)`` - std::ofstream - df_dataframe.h:14582 - :ref:`View ` * - ``std::ofstream file(excel_writer, std::ios::binary)`` - std::ofstream - df_dataframe.h:15502 - :ref:`View ` * - ``\* std::ofstream file("output.html")`` - \* std::ofstream - df_dataframe.h:15562 - :ref:`View ` * - ``\* std::ofstream file("output.tex")`` - \* std::ofstream - df_dataframe.h:15958 - :ref:`View ` * - ``std::ofstream file(path, std::ios::binary)`` - std::ofstream - df_dataframe.h:17521 - :ref:`View ` * - ``\* std::ofstream file("output.md")`` - \* std::ofstream - df_dataframe.h:17793 - :ref:`View ` * - ``std::ifstream file(path, std::ios::binary \| std::ios::ate)`` - std::ifstream - df_dataframe.h:19101 - :ref:`View ` * - ``std::ifstream file(path, std::ios::binary \| std::ios::ate)`` - std::ifstream - df_dataframe.h:19500 - :ref:`View ` * - ``std::ifstream file(path, std::ios::binary \| std::ios::ate)`` - std::ifstream - df_dataframe.h:19955 - :ref:`View ` * - ``std::ifstream file(con)`` - std::ifstream - df_dataframe.h:20187 - :ref:`View ` * - ``std::ifstream file(path, std::ios::binary \| std::ios::ate)`` - std::ifstream - df_dataframe.h:20399 - :ref:`View ` * - ``std::ifstream file(path, std::ios::binary \| std::ios::ate)`` - std::ifstream - df_dataframe.h:20789 - :ref:`View ` * - ``std::ofstream file(path, std::ios::binary)`` - std::ofstream - df_dataframe.h:21935 - :ref:`View ` * - ``DataFrame fillna(double value) const`` - DataFrame - df_dataframe.h:3512 - * - ``DataFrame fillna(const std::map& values) const`` - DataFrame - df_dataframe.h:3523 - * - ``void fillna_double(double value) override`` - void - df_dataframe.h:3265 - * - ``DataFrame filter(const std::vector& items =`` - DataFrame - df_dataframe.h:6103 - :ref:`View ` * - ``DataFrame filter_items(const std::vector& items) const`` - DataFrame - df_dataframe.h:1727 - * - ``DataFrame filter_like(const std::string& like) const`` - DataFrame - df_dataframe.h:1734 - * - ``DataFrame first(const std::string& offset) const`` - DataFrame - df_dataframe.h:12223 - :ref:`View ` * - ``std::optional first_valid_index() const`` - std::optional - df_dataframe.h:6030 - * - ``const Flags& flags() const override`` - const Flags& - df_dataframe.h:771 - :ref:`View ` * - ``insert_sql << format_sql_value(index\_->get_value_str(r), col_types[col_idx])`` - insert_sql << - df_dataframe.h:14878 - * - ``insert_sql << format_sql_value(columns\_[c]->get_value_str(r), col_types[col_idx])`` - insert_sql << - df_dataframe.h:14885 - * - ``insert_sql << format_sql_value(index\_->get_value_str(r), col_types[col_idx])`` - insert_sql << - df_dataframe.h:14908 - * - ``insert_sql << format_sql_value(columns\_[c]->get_value_str(r), col_types[col_idx])`` - insert_sql << - df_dataframe.h:14915 - * - ``oss << format_value(c, r)`` - oss << - df_dataframe.h:16265 - * - ``std::string found(reinterpret_cast(&buffer[pos]), expected_start.size())`` - std::string - df_dataframe.h:20418 - :ref:`View ` * - ``std::string found(reinterpret_cast(&buffer[pos]), tag.size())`` - std::string - df_dataframe.h:20428 - :ref:`View ` * - ``DataFrame ge(const DataFrame& other) const`` - DataFrame - df_dataframe.h:8947 - * - ``std::mt19937 gen(seed == 0 ? std::random_device`` - std::mt19937 - df_dataframe.h:1700 - :ref:`View ` * - ``DataFrameGroupBy groupby(const std::string& by, bool as_index = true, bool sort = true, bool dropna = true) const`` - DataFrameGroupBy - df_dataframe.h:11908 - * - ``DataFrameGroupBy groupby(const std::vector& by, bool as_index = true, bool sort = true, bool dropna = true) const`` - DataFrameGroupBy - df_dataframe.h:11921 - * - ``DataFrame gt(const DataFrame& other) const`` - DataFrame - df_dataframe.h:8940 - * - ``bool has_cached_values() const override`` - bool - df_dataframe.h:22237 - * - ``bool has_column(const std::string& name) const`` - bool - df_dataframe.h:1505 - * - ``bool hasnans() const override`` - bool - df_dataframe.h:2746 - * - ``DataFrame head(size_t n = 5) const`` - DataFrame - df_dataframe.h:1678 - * - ``\* Can also be a list of strings to use as column headers (aliases).`` - \* Can also be a list of strings to use as column - df_dataframe.h:14974 - * - ``T iat(size_t row, size_t col_idx) const`` - T - df_dataframe.h:1667 - * - ``numpy::NDArray idx_arr(std::vector`` - numpy::NDArray - df_dataframe.h:22014 - * - ``numpy::NDArray idx_arr(std::vector`` - numpy::NDArray - df_dataframe.h:22022 - * - ``Series idxmax(int axis = 0, bool skipna = true) const`` - Series - df_dataframe.h:4425 - * - ``Series idxmin(int axis = 0, bool skipna = true) const`` - Series - df_dataframe.h:4518 - * - ``T iloc(size_t row, size_t col_idx) const`` - T - df_dataframe.h:1562 - * - ``DataFrame iloc(const std::vector& row_indices, const std::vector& col_indices) const`` - DataFrame - df_dataframe.h:1645 - * - ``DataFrame iloc_cols(const std::vector& col_indices) const`` - DataFrame - df_dataframe.h:1631 - * - ``DataFrame iloc_row(size_t row) const`` - DataFrame - df_dataframe.h:1580 - * - ``DataFrame iloc_rows(size_t start, size_t stop, size_t step = 1) const`` - DataFrame - df_dataframe.h:1590 - * - ``DataFrame iloc_rows(const std::vector& row_indices) const`` - DataFrame - df_dataframe.h:1601 - * - ``const IndexBase& index() const override`` - const IndexBase& - df_dataframe.h:699 - :ref:`View ` * - ``\* For hierarchical index (MultiIndex-like structure represented as \* concatenated strings), select rows matching all levels.`` - \* For hierarchical - df_dataframe.h:1811 - :ref:`View ` * - ``static std::string infer_best_dtype( const std::vector& str_values, const std::string& source_dtype, bool convert_string, bool convert_integer, bool convert_boolean, bool convert_floating)`` - static std::string - df_dataframe.h:9921 - * - ``DataFrame infer_objects(bool copy = true) const`` - DataFrame - df_dataframe.h:10206 - * - ``void info(std::ostream& buf = std::cout, bool verbose = true, size_t max_cols = 0) const`` - void - df_dataframe.h:12442 - :ref:`View ` * - ``DataFrame interpolate(const std::string& method = "linear", int axis = 0, std::optional limit = std::nullopt, const std::string& limit_direction = "both") const`` - DataFrame - df_dataframe.h:2989 - * - ``interpolate_column(result, c, method, limit, limit_direction)`` - - df_dataframe.h:3015 - * - ``void interpolate_column(DataFrame& result, size_t col_idx, const std::string& method, std::optional limit, const std::string& limit_direction) const`` - void - df_dataframe.h:3032 - * - ``interpolate_row(result, r, method, limit, limit_direction)`` - - df_dataframe.h:3020 - * - ``void interpolate_row(DataFrame& result, size_t row_idx, const std::string& method, std::optional limit, const std::string& limit_direction) const`` - void - df_dataframe.h:3145 - * - ``void isetitem(size_t loc, const std::vector& value)`` - void - df_dataframe.h:6182 - * - ``numpy::NDArray isna() const`` - numpy::NDArray - df_dataframe.h:3360 - * - ``numpy::NDArray isnull() const`` - numpy::NDArray - df_dataframe.h:5994 - * - ``std::istringstream iss(eval_expr)`` - std::istringstream - df_dataframe.h:3840 - * - ``std::istringstream iss(label)`` - std::istringstream - df_dataframe.h:7675 - * - ``std::istringstream iss(label)`` - std::istringstream - df_dataframe.h:7710 - * - ``RowsRange iterrows() const`` - RowsRange - df_dataframe.h:1186 - * - ``\* and dtype preservation, consider using itertuples() instead.`` - \* and dtype preservation, consider using - df_dataframe.h:1068 - * - ``\* preservation, use itertuples() instead.`` - \* preservation, use - df_dataframe.h:1162 - * - ``TuplesRange itertuples(bool index = true, const std::string& name = "Pandas") const`` - TuplesRange - df_dataframe.h:1411 - * - ``DataFrame join( const DataFrame& other, const std::string& how = "left", const std::string& lsuffix = "", const std::string& rsuffix = "_r", bool sort = false) const`` - DataFrame - df_dataframe.h:11475 - :ref:`View ` * - ``const Index& keys() const`` - const Index& - df_dataframe.h:933 - :ref:`View ` * - ``\* Returns a dictionary with five keys (superset of 'split'):`` - \* Returns a dictionary with five - df_dataframe.h:12874 - :ref:`View ` * - ``Series kurt(int axis = 0, bool skipna = true, bool numeric_only = false) const`` - Series - df_dataframe.h:5619 - * - ``Series kurt_cols(bool skipna = true) const`` - Series - df_dataframe.h:4753 - * - ``Series kurtosis(int axis = 0, bool skipna = true, bool numeric_only = false) const`` - Series - df_dataframe.h:5673 - :ref:`View ` * - ``\* Returns the row label (index) where the maximum value occurs for each column.`` - \* Returns the row - df_dataframe.h:4413 - * - ``\* Returns the row label (index) where the minimum value occurs for each column.`` - \* Returns the row - df_dataframe.h:4506 - * - ``\* over the column labels (info axis).`` - \* over the column - df_dataframe.h:822 - * - ``DataFrame last(const std::string& offset) const`` - DataFrame - df_dataframe.h:12230 - * - ``std::optional last_valid_index() const`` - std::optional - df_dataframe.h:6050 - * - ``DataFrame le(const DataFrame& other) const`` - DataFrame - df_dataframe.h:8933 - * - ``std::vector> level_arrays(col_names.size())`` - std::vector> - df_dataframe.h:6614 - * - ``\* innermost levels (i=-2, j=-1). Hierarchical indices are represented`` - \* innermost - df_dataframe.h:7875 - :ref:`View ` * - ``T loc(const std::string& row_label, const std::string& col_label) const`` - T - df_dataframe.h:1517 - * - ``DataFrame loc(const std::vector& row_labels, const std::vector& col_labels) const`` - DataFrame - df_dataframe.h:1548 - * - ``DataFrame loc_row(const std::string& row_label) const`` - DataFrame - df_dataframe.h:1526 - * - ``DataFrame loc_rows(const std::vector& row_labels) const`` - DataFrame - df_dataframe.h:1534 - * - ``DataFrame lt(const DataFrame& other) const`` - DataFrame - df_dataframe.h:8926 - * - ``\* map() applies the function to every individual element.`` - \* - df_dataframe.h:9550 - * - ``DataFrame map(Func&& func, const std::string& na_action = "") const`` - DataFrame - df_dataframe.h:9562 - * - ``\* This is the inverse of where(): mask(cond, other) == where(!cond, other)`` - \* This is the inverse of where(): - df_dataframe.h:3607 - :ref:`View ` * - ``DataFrame mask(const DataFrame& cond, double other = std::numeric_limits::quiet_NaN()) const`` - DataFrame - df_dataframe.h:3617 - :ref:`View ` * - ``DataFrame melt(const std::vector& id_vars, const std::vector& value_vars =`` - DataFrame - df_dataframe.h:8538 - * - ``Series memory_usage(bool index = true, bool deep = false) const`` - Series - df_dataframe.h:12552 - * - ``size_t memory_usage_total(bool deep = false) const`` - size_t - df_dataframe.h:12597 - * - ``DataFrame merge( const DataFrame& right, const std::string& how = "inner", const std::vector& on =`` - DataFrame - df_dataframe.h:11311 - * - ``DataFrame merge( const DataFrame& right, const std::string& how, const std::string& on, const std::pair& suffixes =`` - DataFrame - df_dataframe.h:11459 - * - ``DataFrame mul(const DataFrame& other, double fill_value = 1.0) const`` - DataFrame - df_dataframe.h:8984 - * - ``DataFrame mul(double scalar) const`` - DataFrame - df_dataframe.h:8988 - * - ``MultiIndex multi_idx(std::move(levels), std::move(codes), level_names)`` - MultiIndex - df_dataframe.h:6664 - * - ``std::string name(reinterpret_cast(&buffer[pos + 30]), name_len)`` - std::string - df_dataframe.h:19156 - :ref:`View ` * - ``\* with hierarchical column names (original_col_func_name).`` - \* with hierarchical column - df_dataframe.h:10764 - :ref:`View ` * - ``size_t nbytes() const override`` - size_t - df_dataframe.h:637 - :ref:`View ` * - ``size_t ncols() const`` - size_t - df_dataframe.h:678 - * - ``size_t ndim() const override`` - size_t - df_dataframe.h:630 - :ref:`View ` * - ``DataFrame ne(const DataFrame& other) const`` - DataFrame - df_dataframe.h:8919 - * - ``DataFrame nlargest(size_t n, const std::string& column) const`` - DataFrame - df_dataframe.h:7348 - * - ``numpy::NDArray notna() const`` - numpy::NDArray - df_dataframe.h:3375 - * - ``numpy::NDArray notnull() const`` - numpy::NDArray - df_dataframe.h:6002 - * - ``size_t nrows() const`` - size_t - df_dataframe.h:671 - * - ``DataFrame nsmallest(size_t n, const std::string& column) const`` - DataFrame - df_dataframe.h:7356 - * - ``Series nunique(int axis = 0, bool dropna = true) const`` - Series - df_dataframe.h:6403 - * - ``Series nunique_cols(bool dropna = true) const`` - Series - df_dataframe.h:6358 - * - ``std::istringstream obj_stream(obj_str)`` - std::istringstream - df_dataframe.h:19020 - * - ``\* Series objects (as NDFrameBase pointers for type-erasure).`` - \* Series - df_dataframe.h:12940 - :ref:`View ` * - ``\* a generator of (label, content) pairs.`` - \* a generator - df_dataframe.h:1027 - :ref:`View ` * - ``DataFrame pad(int axis = 0, std::optional limit = std::nullopt) const`` - DataFrame - df_dataframe.h:6022 - :ref:`View ` * - ``oss << pad_string(idx_header, widths[0], alignments[0]) << " "`` - oss << - df_dataframe.h:18020 - * - ``oss << pad_string(columns_index\_.get_value_str(c), widths[w_idx], alignments[w_idx])`` - oss << - df_dataframe.h:18024 - * - ``oss << pad_string(index\_->get_value_str(r), widths[0], alignments[0]) << " "`` - oss << - df_dataframe.h:18043 - * - ``oss << pad_string(val, widths[w_idx], alignments[w_idx])`` - oss << - df_dataframe.h:18053 - * - ``oss << pad_string(idx_header, widths[0], alignments[0]) << " "`` - oss << - df_dataframe.h:18064 - * - ``oss << pad_string(columns_index\_.get_value_str(c), widths[w_idx], alignments[w_idx])`` - oss << - df_dataframe.h:18068 - * - ``oss << pad_string(index\_->get_value_str(r), widths[0], alignments[0]) << " "`` - oss << - df_dataframe.h:18076 - * - ``oss << pad_string(val, widths[w_idx], alignments[w_idx])`` - oss << - df_dataframe.h:18086 - * - ``pad_to_8(body_buffer)`` - - df_dataframe.h:21147 - * - ``pad_to_8(body_buffer)`` - - df_dataframe.h:21258 - * - ``pad_to_8(body_buffer)`` - - df_dataframe.h:21271 - * - ``pad_to_8(feather_bytes)`` - - df_dataframe.h:21868 - * - ``std::vector> pairs(counts.begin(), counts.end())`` - std::vector> - df_dataframe.h:6570 - :ref:`View ` * - ``query::QueryExpression parsed(expr)`` - query::QueryExpression - df_dataframe.h:3675 - * - ``DataFrame pct_change(int periods = 1) const`` - DataFrame - df_dataframe.h:7260 - * - ``\* PeriodIndex period_idx(`` - \* PeriodIndex - df_dataframe.h:12036 - * - ``auto pipe(Func&& func, Args&&... args) const`` - auto - df_dataframe.h:11013 - * - ``DataFrame pivot(const std::string& index_col, const std::string& columns_col, const std::string& values_col) const`` - DataFrame - df_dataframe.h:8094 - * - ``DataFrame pivot_table(const std::string& values, const std::string& index, const std::string& columns, const std::string& aggfunc = "mean", double fill_value = std::numeric_limits::quiet_NaN()) const`` - DataFrame - df_dataframe.h:8165 - * - ``DataFrame pivot_table(const std::vector& values, const std::vector& index, const std::string& columns, const std::string& aggfunc = "mean", double fill_value = std::numeric_limits::quiet_NaN()) const`` - DataFrame - df_dataframe.h:8186 - * - ``DataFrame pivot_table_with_margins( const std::string& values, const std::string& index, const std::string& columns, const std::string& aggfunc = "mean", double fill_value = std::numeric_limits::quiet_NaN(), bool margins = false, const std::string& margins_name = "All" ) const`` - DataFrame - df_dataframe.h:8363 - * - ``DataFrame pivot_table_with_margins( const std::vector& values, const std::vector& index, const std::string& columns, const std::string& aggfunc = "mean", double fill_value = std::numeric_limits::quiet_NaN(), bool margins = false, const std::string& margins_name = "All" ) const`` - DataFrame - df_dataframe.h:8390 - * - ``DataFrame pow(const DataFrame& other) const`` - DataFrame - df_dataframe.h:9044 - :ref:`View ` * - ``DataFrame pow(double exponent) const`` - DataFrame - df_dataframe.h:9048 - :ref:`View ` * - ``\* to specify which axis to prefix (0 for index, 1 for columns).`` - \* to specify which axis to - df_dataframe.h:2307 - :ref:`View ` * - ``Series prod(int axis = 0, bool skipna = true, bool numeric_only = false) const`` - Series - df_dataframe.h:5214 - :ref:`View ` * - ``Series prod_cols(bool skipna = true) const`` - Series - df_dataframe.h:5168 - * - ``Series product(int axis = 0, bool skipna = true, bool numeric_only = false) const`` - Series - df_dataframe.h:5791 - :ref:`View ` * - ``\* empty vector if path is provided (file written to disk).`` - \* empty vector if path is - df_dataframe.h:12980 - * - ``DataFrame query(const std::string& expr) const`` - DataFrame - df_dataframe.h:3673 - * - ``DataFrame radd(const DataFrame& other, double fill_value = 0.0) const`` - DataFrame - df_dataframe.h:9066 - * - ``DataFrame radd(double scalar, double fill_value = std::numeric_limits::quiet_NaN()) const`` - DataFrame - df_dataframe.h:9071 - * - ``DataFrame rank(int axis = 0, const std::string& method = "average", bool ascending = true, const std::string& na_option = "keep", bool pct = false) const`` - DataFrame - df_dataframe.h:7370 - * - ``DataFrame rdiv(const DataFrame& other, double fill_value = 1.0) const`` - DataFrame - df_dataframe.h:9135 - * - ``DataFrame rdiv(double scalar, double fill_value = std::numeric_limits::quiet_NaN()) const`` - DataFrame - df_dataframe.h:9139 - * - ``std::regex re(regex)`` - std::regex - df_dataframe.h:6115 - * - ``std::regex re(regex)`` - std::regex - df_dataframe.h:6142 - * - ``static DataFrame read_csv( const std::string& csv_data, char sep = ',', bool header = true, const std::string& index_col = "")`` - static DataFrame - df_dataframe.h:18779 - * - ``static DataFrame read_excel( const std::string& path, const std::string& sheet_name = "Sheet1", int header = 0, const std::vector& usecols =`` - static DataFrame - df_dataframe.h:19093 - * - ``static DataFrame read_feather( const std::string& path, [[maybe_unused]] const std::vector& columns =`` - static DataFrame - df_dataframe.h:20784 - * - ``static DataFrame read_hdf( const std::string& path, [[maybe_unused]] const std::string& key = "")`` - static DataFrame - df_dataframe.h:19950 - * - ``static DataFrame read_json( const std::string& json_data, const std::string& orient = "columns")`` - static DataFrame - df_dataframe.h:18930 - * - ``static DataFrame read_parquet( const std::string& path, const std::vector& columns =`` - static DataFrame - df_dataframe.h:19495 - * - ``static DataFrame read_sql( [[maybe_unused]] const std::string& sql, const std::string& con, [[maybe_unused]] const std::vector& columns =`` - static DataFrame - df_dataframe.h:20181 - * - ``static DataFrame read_stata( const std::string& path, [[maybe_unused]] bool convert_dates = true)`` - static DataFrame - df_dataframe.h:20394 - * - ``DataFrame reindex(const std::vector& labels, int axis = 0, double fill_value = std::nan("")) const`` - DataFrame - df_dataframe.h:2175 - * - ``DataFrame reindex_by_indexer( const numpy::NDArray& indexer, const Index& new_index, double fill_value) const`` - DataFrame - df_dataframe.h:12273 - * - ``DataFrame reindex_like(const DataFrame& other) const`` - DataFrame - df_dataframe.h:2410 - * - ``DataFrame rename(const std::map& mapper, int axis = 0) const`` - DataFrame - df_dataframe.h:2146 - * - ``DataFrame rename_axis(const std::string& name, int axis = 0) const`` - DataFrame - df_dataframe.h:2284 - * - ``DataFrame rename_columns(const std::map& mapper) const`` - DataFrame - df_dataframe.h:2124 - * - ``DataFrame reorder_levels(const std::vector& order, int axis = 0) const`` - DataFrame - df_dataframe.h:7775 - * - ``DataFrame reorder_levels(const std::vector& order, const std::string& axis) const`` - DataFrame - df_dataframe.h:7826 - * - ``DataFrame reorder_levels(const std::vector& order, int axis = 0) const`` - DataFrame - df_dataframe.h:7849 - * - ``DataFrame reorder_levels_columns(const std::vector& order) const`` - DataFrame - df_dataframe.h:8051 - * - ``static std::string reorder_levels_in_label(const std::string& label, const std::vector& order)`` - static std::string - df_dataframe.h:7708 - * - ``DataFrame reorder_levels_index(const std::vector& order) const`` - DataFrame - df_dataframe.h:8024 - * - ``DataFrame replace(double to_replace, double value) const`` - DataFrame - df_dataframe.h:3540 - :ref:`View ` * - ``void replace_value(double to_replace, double value) override`` - void - df_dataframe.h:3275 - * - ``std::string repr() const override`` - std::string - df_dataframe.h:22218 - * - ``\* representation (default: true). Currently unused.`` - \* - df_dataframe.h:15531 - :ref:`View ` * - ``\* representation (default: true). Currently unused.`` - \* - df_dataframe.h:15925 - :ref:`View ` * - ``DataFrameResampler resample(const std::string& freq, const std::string& closed = "left", const std::string& label = "left") const`` - DataFrameResampler - df_dataframe.h:11952 - * - ``void reset_index(bool drop) override`` - void - df_dataframe.h:2096 - * - ``numpy::RecordArray result(struct_dtype,`` - numpy::RecordArray - df_dataframe.h:16454 - :ref:`View ` * - ``DataFrame rfloordiv(const DataFrame& other, double fill_value = 1.0) const`` - DataFrame - df_dataframe.h:9165 - * - ``DataFrame rfloordiv(double scalar, double fill_value = std::numeric_limits::quiet_NaN()) const`` - DataFrame - df_dataframe.h:9169 - * - ``DataFrame rmod(const DataFrame& other, double fill_value = 1.0) const`` - DataFrame - df_dataframe.h:9187 - * - ``DataFrame rmod(double scalar, double fill_value = std::numeric_limits::quiet_NaN()) const`` - DataFrame - df_dataframe.h:9191 - * - ``DataFrame rmul(const DataFrame& other, double fill_value = 1.0) const`` - DataFrame - df_dataframe.h:9112 - * - ``DataFrame rmul(double scalar, double fill_value = std::numeric_limits::quiet_NaN()) const`` - DataFrame - df_dataframe.h:9117 - * - ``\* Provides rolling (moving) window aggregation methods for DataFrames.`` - \* Provides - df_dataframe.h:5802 - * - ``DataFrameRolling rolling(size_t window, size_t min_periods = 1, bool center = false) const`` - DataFrameRolling - df_dataframe.h:5962 - * - ``DataFrame rpow(const DataFrame& other, double fill_value = 1.0) const`` - DataFrame - df_dataframe.h:9209 - * - ``DataFrame rpow(double base, double fill_value = std::numeric_limits::quiet_NaN()) const`` - DataFrame - df_dataframe.h:9213 - * - ``DataFrame rsub(const DataFrame& other, double fill_value = 0.0) const`` - DataFrame - df_dataframe.h:9090 - * - ``DataFrame rsub(double scalar, double fill_value = std::numeric_limits::quiet_NaN()) const`` - DataFrame - df_dataframe.h:9094 - * - ``DataFrame rtruediv(const DataFrame& other, double fill_value = 1.0) const`` - DataFrame - df_dataframe.h:9147 - * - ``DataFrame rtruediv(double scalar, double fill_value = std::numeric_limits::quiet_NaN()) const`` - DataFrame - df_dataframe.h:9151 - * - ``DataFrame scalar_op(double scalar, BinaryOp op) const`` - DataFrame - df_dataframe.h:22319 - * - ``DataFrame scalar_op_with_fill(double scalar, double fill_value, BinaryOp op) const`` - DataFrame - df_dataframe.h:22345 - * - ``Series sem(int axis = 0, bool skipna = true, int ddof = 1, bool numeric_only = false) const`` - Series - df_dataframe.h:5525 - * - ``Series sem_cols(bool skipna = true, int ddof = 1) const`` - Series - df_dataframe.h:4699 - * - ``\* sequences (default: true).`` - \* - df_dataframe.h:15544 - :ref:`View ` * - ``void set_attrs(const Attrs& attrs) override`` - void - df_dataframe.h:764 - * - ``DataFrame set_axis(const std::vector& labels, int axis = 0) const`` - DataFrame - df_dataframe.h:2245 - * - ``set_field_value(r, field.first, field.second, index\_->get_value_str(r))`` - - df_dataframe.h:16530 - * - ``set_field_value(r, field.first, field.second, columns\_[c]->get_value_str(r))`` - - df_dataframe.h:16537 - * - ``void set_flags(const Flags& flags) override`` - void - df_dataframe.h:778 - * - ``void set_index(std::unique_ptr new_index) override`` - void - df_dataframe.h:2060 - * - ``DataFrame set_index_col(const std::string& col_name, bool drop = true) const`` - DataFrame - df_dataframe.h:2073 - * - ``void set_value_double(size_t idx, double value) override`` - void - df_dataframe.h:3317 - * - ``void set_value_nan(size_t idx) override`` - void - df_dataframe.h:3301 - * - ``std::vector shape() const override`` - std::vector - df_dataframe.h:623 - :ref:`View ` * - ``DataFrame shift(int periods = 1, int axis = 0) const`` - DataFrame - df_dataframe.h:9432 - :ref:`View ` * - ``size_t size() const override`` - size_t - df_dataframe.h:609 - :ref:`View ` * - ``Series skew(int axis = 0, bool skipna = true, bool numeric_only = false) const`` - Series - df_dataframe.h:5566 - :ref:`View ` * - ``Series skew_cols(bool skipna = true) const`` - Series - df_dataframe.h:4715 - * - ``\* represent time spans (periods) rather than time points.`` - \* represent time - df_dataframe.h:11973 - * - ``\* Format specification (simplified):`` - \* Format - df_dataframe.h:14406 - * - ``std::ofstream sql_file(sql_file_path)`` - std::ofstream - df_dataframe.h:14936 - * - ``std::stringstream ss(val)`` - std::stringstream - df_dataframe.h:8625 - :ref:`View ` * - ``std::string str(reinterpret_cast(&buffer[pos]), len)`` - std::string - df_dataframe.h:20017 - :ref:`View ` * - ``numpy::str64 str_field(str_val)`` - numpy::str64 - df_dataframe.h:16511 - * - ``numpy::str64 str_field(str_val)`` - numpy::str64 - df_dataframe.h:16518 - * - ``std::istringstream stream(csv_data)`` - std::istringstream - df_dataframe.h:18786 - * - ``\* If empty string (default), passes NaN to func like any other value.`` - \* If empty - df_dataframe.h:9546 - :ref:`View ` * - ``inline Styler style() const`` - inline Styler - df_dataframe.h:22483 - * - ``DataFrame sub(const DataFrame& other, double fill_value = 0.0) const`` - DataFrame - df_dataframe.h:8969 - * - ``DataFrame sub(double scalar) const`` - DataFrame - df_dataframe.h:8973 - * - ``\* to specify which axis to suffix (0 for index, 1 for columns).`` - \* to specify which axis to - df_dataframe.h:2352 - * - ``DataFrame swaplevel(int i = -2, int j = -1, int axis = 0) const`` - DataFrame - df_dataframe.h:7912 - * - ``DataFrame swaplevel(int i, int j, const std::string& axis) const`` - DataFrame - df_dataframe.h:7960 - * - ``DataFrame swaplevel(const std::string& i, const std::string& j, int axis = 0) const`` - DataFrame - df_dataframe.h:7983 - * - ``DataFrame tail(size_t n = 5) const`` - DataFrame - df_dataframe.h:1686 - * - ``DataFrame transform(Func&& func, int axis = 0) const`` - DataFrame - df_dataframe.h:10615 - * - ``DataFrame transform(const std::string& func_name, int axis = 0) const`` - DataFrame - df_dataframe.h:10713 - * - ``DataFrame transform(const std::vector& func_names, int axis = 0) const`` - DataFrame - df_dataframe.h:10777 - * - ``DataFrame transform(const std::map& col_func_map, int axis = 0) const`` - DataFrame - df_dataframe.h:10817 - * - ``DataFrame transform(const std::map>& col_funcs_map, int axis = 0) const`` - DataFrame - df_dataframe.h:10866 - * - ``DataFrame truediv(const DataFrame& other) const`` - DataFrame - df_dataframe.h:9011 - * - ``DataFrame truediv(double scalar) const`` - DataFrame - df_dataframe.h:9015 - * - ``DataFrame tz_convert(const std::string& tz, int axis = 0, int level = -1, bool copy = true) const`` - DataFrame - df_dataframe.h:12106 - :ref:`View ` * - ``\* use tz_convert() to change timezones.`` - \* use - df_dataframe.h:12160 - :ref:`View ` * - ``\* use tz_localize() first to assign a timezone.`` - \* use - df_dataframe.h:12102 - :ref:`View ` * - ``DataFrame tz_localize(const std::string& tz, int axis = 0, int level = -1, bool copy = true, const std::string& ambiguous = "raise", const std::string& nonexistent = "raise") const`` - DataFrame - df_dataframe.h:12164 - :ref:`View ` * - ``DataFrame unary_op(UnaryOp op) const`` - DataFrame - df_dataframe.h:22293 - * - ``DataFrame unstack() const`` - DataFrame - df_dataframe.h:8708 - * - ``\* Currently unused (no MultiIndex column support yet).`` - \* Currently - df_dataframe.h:15935 - :ref:`View ` * - ``void update(const DataFrame& other, bool overwrite = true)`` - void - df_dataframe.h:11791 - * - ``\* Series v(`` - \* Series - df_dataframe.h:8860 - :ref:`View ` * - ``\* Can be a single value (applies to all) or per-column values.`` - \* Can be a single - df_dataframe.h:15524 - :ref:`View ` * - ``std::variant, Series> value_counts( const std::vector& subset =`` - std::variant, Series> - df_dataframe.h:6490 - * - ``numpy::NDArray values() const`` - numpy::NDArray - df_dataframe.h:730 - :ref:`View ` * - ``\* missing values (NA). It analyzes the data in each column and infers the`` - \* missing - df_dataframe.h:10028 - :ref:`View ` * - ``\* Provides exponential weighted (EWM) aggregation methods for DataFrames.`` - \* Provides exponential - df_dataframe.h:5909 - * - ``\* object implementing a binary write() function. If empty, returns`` - \* object implementing a binary - df_dataframe.h:14169 - :ref:`View ` * - ``write_byte(static_cast(data_label.length()))`` - - df_dataframe.h:16978 - * - ``write_byte(static_cast(c))`` - - df_dataframe.h:16981 - * - ``write_byte(static_cast(ts.length()))`` - - df_dataframe.h:16997 - * - ``write_byte(static_cast(c))`` - - df_dataframe.h:16999 - * - ``write_byte(static_cast(missing_int8))`` - - df_dataframe.h:17139 - * - ``write_byte(static_cast(static_cast(val)))`` - - df_dataframe.h:17142 - * - ``write_byte(0)`` - - df_dataframe.h:17236 - * - ``write_byte(0)`` - - df_dataframe.h:17237 - * - ``write_byte(0)`` - - df_dataframe.h:17238 - * - ``write_byte(static_cast(c))`` - - df_dataframe.h:17261 - * - ``write_byte(big_endian ? 0x01 : 0x02)`` - - df_dataframe.h:17302 - * - ``write_byte(0x01)`` - - df_dataframe.h:17305 - * - ``write_byte(0x00)`` - - df_dataframe.h:17308 - * - ``write_byte(static_cast(col.stata_type))`` - - df_dataframe.h:17335 - * - ``write_byte(static_cast(col.stata_type))`` - - df_dataframe.h:17337 - * - ``write_byte(0x00)`` - - df_dataframe.h:17376 - * - ``write_byte(static_cast(missing_int8))`` - - df_dataframe.h:17424 - * - ``write_byte(static_cast(static_cast(val)))`` - - df_dataframe.h:17427 - * - ``write_byte(0)`` - - df_dataframe.h:17495 - * - ``write_byte(static_cast(c))`` - - df_dataframe.h:17509 - * - ``write_byte(0)`` - - df_dataframe.h:17511 - * - ``write_field_header(page_header, 1, THRIFT_I32, prev_fid)`` - - df_dataframe.h:13806 - * - ``write_field_header(page_header, 2, THRIFT_I32, prev_fid)`` - - df_dataframe.h:13810 - * - ``write_field_header(page_header, 3, THRIFT_I32, prev_fid)`` - - df_dataframe.h:13814 - * - ``write_field_header(page_header, 5, THRIFT_STRUCT, prev_fid)`` - - df_dataframe.h:13818 - * - ``write_field_header(page_header, 1, THRIFT_I32, prev_dph)`` - - df_dataframe.h:13822 - * - ``write_field_header(page_header, 2, THRIFT_I32, prev_dph)`` - - df_dataframe.h:13825 - * - ``write_field_header(page_header, 3, THRIFT_I32, prev_dph)`` - - df_dataframe.h:13828 - * - ``write_field_header(page_header, 4, THRIFT_I32, prev_dph)`` - - df_dataframe.h:13831 - * - ``write_field_header(page_header, 1, THRIFT_I32, prev_fid)`` - - df_dataframe.h:13949 - * - ``write_field_header(page_header, 2, THRIFT_I32, prev_fid)`` - - df_dataframe.h:13953 - * - ``write_field_header(page_header, 3, THRIFT_I32, prev_fid)`` - - df_dataframe.h:13957 - * - ``write_field_header(page_header, 5, THRIFT_STRUCT, prev_fid)`` - - df_dataframe.h:13961 - * - ``write_field_header(page_header, 1, THRIFT_I32, prev_dph)`` - - df_dataframe.h:13964 - * - ``write_field_header(page_header, 2, THRIFT_I32, prev_dph)`` - - df_dataframe.h:13966 - * - ``write_field_header(page_header, 3, THRIFT_I32, prev_dph)`` - - df_dataframe.h:13968 - * - ``write_field_header(page_header, 4, THRIFT_I32, prev_dph)`` - - df_dataframe.h:13970 - * - ``write_field_header(metadata, 1, THRIFT_I32, prev_fid)`` - - df_dataframe.h:13996 - * - ``write_field_header(metadata, 2, THRIFT_LIST, prev_fid)`` - - df_dataframe.h:14000 - * - ``write_field_header(metadata, 4, THRIFT_BINARY, prev_se)`` - - df_dataframe.h:14008 - * - ``write_field_header(metadata, 6, THRIFT_I32, prev_se)`` - - df_dataframe.h:14011 - * - ``write_field_header(metadata, 1, THRIFT_I32, prev_se)`` - - df_dataframe.h:14020 - * - ``write_field_header(metadata, 4, THRIFT_BINARY, prev_se)`` - - df_dataframe.h:14023 - * - ``write_field_header(metadata, 7, THRIFT_I32, prev_se)`` - - df_dataframe.h:14027 - * - ``write_field_header(metadata, 3, THRIFT_I64, prev_fid)`` - - df_dataframe.h:14033 - * - ``write_field_header(metadata, 4, THRIFT_LIST, prev_fid)`` - - df_dataframe.h:14037 - * - ``write_field_header(metadata, 1, THRIFT_LIST, prev_rg)`` - - df_dataframe.h:14045 - * - ``write_field_header(metadata, 2, THRIFT_I64, prev_cc)`` - - df_dataframe.h:14052 - * - ``write_field_header(metadata, 3, THRIFT_STRUCT, prev_cc)`` - - df_dataframe.h:14056 - * - ``write_field_header(metadata, 1, THRIFT_I32, prev_cm)`` - - df_dataframe.h:14061 - * - ``write_field_header(metadata, 2, THRIFT_LIST, prev_cm)`` - - df_dataframe.h:14065 - * - ``write_field_header(metadata, 3, THRIFT_LIST, prev_cm)`` - - df_dataframe.h:14070 - * - ``write_field_header(metadata, 4, THRIFT_I32, prev_cm)`` - - df_dataframe.h:14075 - * - ``write_field_header(metadata, 5, THRIFT_I64, prev_cm)`` - - df_dataframe.h:14079 - * - ``write_field_header(metadata, 6, THRIFT_I64, prev_cm)`` - - df_dataframe.h:14083 - * - ``write_field_header(metadata, 7, THRIFT_I64, prev_cm)`` - - df_dataframe.h:14087 - * - ``write_field_header(metadata, 9, THRIFT_I64, prev_cm)`` - - df_dataframe.h:14091 - * - ``write_field_header(metadata, 2, THRIFT_I64, prev_rg)`` - - df_dataframe.h:14101 - * - ``write_field_header(metadata, 3, THRIFT_I64, prev_rg)`` - - df_dataframe.h:14105 - * - ``write_field_header(metadata, 5, THRIFT_LIST, prev_fid)`` - - df_dataframe.h:14112 - * - ``write_field_header(metadata, 1, THRIFT_BINARY, prev_kv)`` - - df_dataframe.h:14116 - * - ``write_field_header(metadata, 2, THRIFT_BINARY, prev_kv)`` - - df_dataframe.h:14118 - * - ``write_field_header(metadata, 6, THRIFT_BINARY, prev_fid)`` - - df_dataframe.h:14124 - * - ``write_flatbuf_string(fields_data, name)`` - - df_dataframe.h:21359 - * - ``write_float32(missing_f)`` - - df_dataframe.h:17165 - * - ``write_float32(static_cast(val))`` - - df_dataframe.h:17168 - * - ``write_float32(missing_f)`` - - df_dataframe.h:17447 - * - ``write_float32(static_cast(val))`` - - df_dataframe.h:17450 - * - ``write_float64(val)`` - - df_dataframe.h:17125 - * - ``write_float64(missing_d)`` - - df_dataframe.h:17175 - * - ``write_float64(stata_ms)`` - - df_dataframe.h:17181 - * - ``write_float64(val)`` - - df_dataframe.h:17184 - * - ``write_float64(val)`` - - df_dataframe.h:17413 - * - ``write_float64(missing_d)`` - - df_dataframe.h:17456 - * - ``write_float64(stata_ms)`` - - df_dataframe.h:17461 - * - ``write_float64(val)`` - - df_dataframe.h:17464 - * - ``write_int16(missing_int16)`` - - df_dataframe.h:17147 - * - ``write_int16(static_cast(val))`` - - df_dataframe.h:17150 - * - ``write_int16(static_cast(nvar))`` - - df_dataframe.h:17311 - * - ``write_int16(0)`` - - df_dataframe.h:17352 - * - ``write_int16(missing_int16)`` - - df_dataframe.h:17431 - * - ``write_int16(static_cast(val))`` - - df_dataframe.h:17434 - * - ``write_int32(missing_int32)`` - - df_dataframe.h:17118 - * - ``write_int32(static_cast(val))`` - - df_dataframe.h:17120 - * - ``write_int32(missing_int32)`` - - df_dataframe.h:17155 - * - ``write_int32(static_cast(val))`` - - df_dataframe.h:17158 - * - ``write_int32(lbl_len)`` - - df_dataframe.h:17230 - * - ``write_int32(static_cast(labels.size()))`` - - df_dataframe.h:17241 - * - ``write_int32(static_cast(txt_len))`` - - df_dataframe.h:17244 - * - ``write_int32(offset)`` - - df_dataframe.h:17249 - * - ``write_int32(val)`` - - df_dataframe.h:17255 - * - ``write_int32(static_cast(nobs))`` - - df_dataframe.h:17314 - * - ``write_int32(static_cast(val))`` - - df_dataframe.h:17410 - * - ``write_int32(missing_int32)`` - - df_dataframe.h:17438 - * - ``write_int32(static_cast(val))`` - - df_dataframe.h:17441 - * - ``write_int32(lbl_len)`` - - df_dataframe.h:17493 - * - ``write_int32(static_cast(labels.size()))`` - - df_dataframe.h:17496 - * - ``write_int32(static_cast(txt_len))`` - - df_dataframe.h:17497 - * - ``write_int32(offset)`` - - df_dataframe.h:17501 - * - ``write_int32(val)`` - - df_dataframe.h:17505 - * - ``write_int64(range_idx->start())`` - - df_dataframe.h:14279 - * - ``write_int64(range_idx->stop())`` - - df_dataframe.h:14280 - * - ``write_int64(range_idx->step())`` - - df_dataframe.h:14281 - * - ``write_int64(range_idx->start())`` - - df_dataframe.h:14525 - * - ``write_int64(range_idx->stop())`` - - df_dataframe.h:14526 - * - ``write_int64(range_idx->step())`` - - df_dataframe.h:14527 - * - ``write_int64(static_cast(nobs))`` - - df_dataframe.h:16966 - * - ``write_le32(body_buffer, static_cast(val))`` - - df_dataframe.h:21173 - * - ``write_le32(body_buffer, static_cast(bits))`` - - df_dataframe.h:21195 - * - ``write_le32(body_buffer, current_offset)`` - - df_dataframe.h:21252 - * - ``write_le32(body_buffer, current_offset)`` - - df_dataframe.h:21255 - * - ``write_le32(fields_data, bit_width)`` - - df_dataframe.h:21370 - * - ``write_le32(feather_bytes, metadata_size)`` - - df_dataframe.h:21766 - * - ``write_le32(feather_bytes, static_cast(rb_message.size()))`` - - df_dataframe.h:21862 - * - ``write_le32(feather_bytes, footer_size)`` - - df_dataframe.h:21927 - * - ``write_le64(body_buffer, val)`` - - df_dataframe.h:21175 - * - ``write_le64(body_buffer, static_cast(bits))`` - - df_dataframe.h:21209 - * - ``write_le64(body_buffer, val)`` - - df_dataframe.h:21237 - * - ``write_list_header(metadata, column_chunks.size(), THRIFT_STRUCT)`` - - df_dataframe.h:14046 - * - ``write_list_header(metadata, 1, THRIFT_I32)`` - - df_dataframe.h:14066 - * - ``write_list_header(metadata, 1, THRIFT_BINARY)`` - - df_dataframe.h:14071 - * - ``write_list_header(metadata, 1, THRIFT_STRUCT)`` - - df_dataframe.h:14113 - * - ``write_string(metadata, "schema")`` - - df_dataframe.h:14009 - * - ``write_string(metadata, column_chunks[i].col_name)`` - - df_dataframe.h:14024 - * - ``write_string(metadata, cc.col_name)`` - - df_dataframe.h:14072 - * - ``write_string(metadata, "pandas")`` - - df_dataframe.h:14117 - * - ``write_string(metadata, "`` - - df_dataframe.h:14119 - * - ``write_string(metadata, "PandasCore C++ Library")`` - - df_dataframe.h:14125 - * - ``write_string(range_idx->name().value())`` - - df_dataframe.h:14283 - * - ``write_string(index\_->get_value_str(i))`` - - df_dataframe.h:14292 - * - ``write_string(index\_->name().value())`` - - df_dataframe.h:14296 - * - ``write_string(columns_index\_.get_value_str(c))`` - - df_dataframe.h:14307 - * - ``write_string(dtype)`` - - df_dataframe.h:14311 - * - ``write_string(val_str)`` - - df_dataframe.h:14322 - * - ``write_string(key)`` - - df_dataframe.h:14510 - * - ``write_string(range_idx->name().value())`` - - df_dataframe.h:14529 - * - ``write_string(index\_->get_value_str(i))`` - - df_dataframe.h:14538 - * - ``write_string(index\_->name().value())`` - - df_dataframe.h:14542 - * - ``write_string(columns_index\_.get_value_str(c))`` - - df_dataframe.h:14554 - * - ``write_string(dtype)`` - - df_dataframe.h:14558 - * - ``write_string(val_str)`` - - df_dataframe.h:14567 - * - ``write_string(name, varname_len)`` - - df_dataframe.h:17029 - * - ``write_string(col.format, format_len)`` - - df_dataframe.h:17045 - * - ``write_string(col.name, varname_len)`` - - df_dataframe.h:17055 - * - ``write_string("", varname_len)`` - - df_dataframe.h:17057 - * - ``write_string(col.label, varlabel_len)`` - - df_dataframe.h:17066 - * - ``write_string(idx_str, col.stata_type)`` - - df_dataframe.h:17128 - * - ``write_string(val, col.stata_type)`` - - df_dataframe.h:17189 - * - ``write_string(col.name, varname_len)`` - - df_dataframe.h:17233 - * - ``write_string(data_label, 81)`` - - df_dataframe.h:17317 - * - ``write_string(ts, 18)`` - - df_dataframe.h:17329 - * - ``write_string(name, 33)`` - - df_dataframe.h:17347 - * - ``write_string(col.format, 49)`` - - df_dataframe.h:17357 - * - ``write_string(col.name, 33)`` - - df_dataframe.h:17363 - * - ``write_string("", 33)`` - - df_dataframe.h:17365 - * - ``write_string(col.label, 81)`` - - df_dataframe.h:17371 - * - ``write_string(idx_str, col.stata_type)`` - - df_dataframe.h:17415 - * - ``write_string(val, col.stata_type)`` - - df_dataframe.h:17468 - * - ``write_string(col.name, 33)`` - - df_dataframe.h:17494 - * - ``write_tag("")`` - - df_dataframe.h:16941 - * - ``write_tag("
")`` - - df_dataframe.h:16942 - * - ``write_tag("")`` - - df_dataframe.h:16945 - * - ``write_tag(std::to_string(version))`` - - df_dataframe.h:16946 - * - ``write_tag("")`` - - df_dataframe.h:16947 - * - ``write_tag("")`` - - df_dataframe.h:16950 - * - ``write_tag(big_endian ? "MSF" : "LSF")`` - - df_dataframe.h:16951 - * - ``write_tag("")`` - - df_dataframe.h:16952 - * - ``write_tag("")`` - - df_dataframe.h:16955 - * - ``write_tag("")`` - - df_dataframe.h:16961 - * - ``write_tag("")`` - - df_dataframe.h:16964 - * - ``write_tag("")`` - - df_dataframe.h:16970 - * - ``write_tag("")`` - - df_dataframe.h:16983 - * - ``write_tag("")`` - - df_dataframe.h:16986 - * - ``write_tag("")`` - - df_dataframe.h:17001 - * - ``write_tag("
")`` - - df_dataframe.h:17003 - * - ``write_tag("")`` - - df_dataframe.h:17007 - * - ``write_tag("")`` - - df_dataframe.h:17011 - * - ``write_tag("")`` - - df_dataframe.h:17015 - * - ``write_tag("")`` - - df_dataframe.h:17019 - * - ``write_tag("")`` - - df_dataframe.h:17023 - * - ``write_tag("")`` - - df_dataframe.h:17031 - * - ``write_tag("")`` - - df_dataframe.h:17035 - * - ``write_tag("")`` - - df_dataframe.h:17039 - * - ``write_tag("")`` - - df_dataframe.h:17043 - * - ``write_tag("")`` - - df_dataframe.h:17047 - * - ``write_tag("")`` - - df_dataframe.h:17051 - * - ``write_tag("")`` - - df_dataframe.h:17060 - * - ``write_tag("")`` - - df_dataframe.h:17064 - * - ``write_tag("")`` - - df_dataframe.h:17068 - * - ``write_tag("")`` - - df_dataframe.h:17072 - * - ``write_tag("")`` - - df_dataframe.h:17073 - * - ``write_tag("")`` - - df_dataframe.h:17077 - * - ``write_tag("")`` - - df_dataframe.h:17194 - * - ``write_tag("")`` - - df_dataframe.h:17198 - * - ``write_tag("")`` - - df_dataframe.h:17199 - * - ``write_tag("")`` - - df_dataframe.h:17203 - * - ``write_tag("")`` - - df_dataframe.h:17214 - * - ``write_tag("")`` - - df_dataframe.h:17266 - * - ``write_tag("")`` - - df_dataframe.h:17271 - * - ``write_tag("
")`` - - df_dataframe.h:17275 - * - ``write_uint16(nvar)`` - - df_dataframe.h:16959 - * - ``write_uint16(static_cast(data_label.length()))`` - - df_dataframe.h:16976 - * - ``write_uint16(col.stata_type)`` - - df_dataframe.h:17017 - * - ``write_uint16(0)`` - - df_dataframe.h:17037 - * - ``write_uint32(static_cast(str.size()))`` - - df_dataframe.h:14267 - * - ``write_uint32(0)`` - - df_dataframe.h:14298 - * - ``write_uint32(static_cast(ncols()))`` - - df_dataframe.h:14303 - * - ``write_uint32(static_cast(str.size()))`` - - df_dataframe.h:14503 - * - ``write_uint32(0)`` - - df_dataframe.h:14544 - * - ``write_uint32(static_cast(ncols()))`` - - df_dataframe.h:14550 - * - ``write_uint32(static_cast(nvar))`` - - df_dataframe.h:16957 - * - ``write_uint32(static_cast(nobs))`` - - df_dataframe.h:16968 - * - ``write_uint64(index\_->size())`` - - df_dataframe.h:14290 - * - ``write_uint64(n)`` - - df_dataframe.h:14315 - * - ``write_uint64(index\_->size())`` - - df_dataframe.h:14536 - * - ``write_uint64(n)`` - - df_dataframe.h:14562 - * - ``write_varint(encoded)`` - - df_dataframe.h:13066 - * - ``write_varint(data.size())`` - - df_dataframe.h:13081 - * - ``write_varint(str.size())`` - - df_dataframe.h:13087 - * - ``write_zigzag_to(page_header, 0)`` - - df_dataframe.h:13807 - * - ``write_zigzag_to(page_header, static_cast(page_data.size()))`` - - df_dataframe.h:13811 - * - ``write_zigzag_to(page_header, static_cast(page_data.size()))`` - - df_dataframe.h:13815 - * - ``write_zigzag_to(page_header, static_cast(nrows()))`` - - df_dataframe.h:13823 - * - ``write_zigzag_to(page_header, ENCODING_PLAIN)`` - - df_dataframe.h:13826 - * - ``write_zigzag_to(page_header, ENCODING_PLAIN)`` - - df_dataframe.h:13829 - * - ``write_zigzag_to(page_header, ENCODING_PLAIN)`` - - df_dataframe.h:13832 - * - ``write_zigzag_to(page_header, 0)`` - - df_dataframe.h:13950 - * - ``write_zigzag_to(page_header, static_cast(page_data.size()))`` - - df_dataframe.h:13954 - * - ``write_zigzag_to(page_header, static_cast(page_data.size()))`` - - df_dataframe.h:13958 - * - ``write_zigzag_to(page_header, static_cast(nrows()))`` - - df_dataframe.h:13965 - * - ``write_zigzag_to(page_header, ENCODING_PLAIN)`` - - df_dataframe.h:13967 - * - ``write_zigzag_to(page_header, ENCODING_PLAIN)`` - - df_dataframe.h:13969 - * - ``write_zigzag_to(page_header, ENCODING_PLAIN)`` - - df_dataframe.h:13971 - * - ``write_zigzag_to(metadata, static_cast(total_cols))`` - - df_dataframe.h:14012 - * - ``write_zigzag_to(metadata, column_chunks[i].parquet_type)`` - - df_dataframe.h:14021 - * - ``write_zigzag_to(metadata, static_cast(nrows()))`` - - df_dataframe.h:14034 - * - ``write_zigzag_to(metadata, cc.file_offset)`` - - df_dataframe.h:14053 - * - ``write_zigzag_to(metadata, cc.parquet_type)`` - - df_dataframe.h:14062 - * - ``write_zigzag_to(metadata, ENCODING_PLAIN)`` - - df_dataframe.h:14067 - * - ``write_zigzag_to(metadata, COMPRESSION_UNCOMPRESSED)`` - - df_dataframe.h:14076 - * - ``write_zigzag_to(metadata, cc.num_values)`` - - df_dataframe.h:14080 - * - ``write_zigzag_to(metadata, cc.total_size)`` - - df_dataframe.h:14084 - * - ``write_zigzag_to(metadata, cc.total_size)`` - - df_dataframe.h:14088 - * - ``write_zigzag_to(metadata, cc.file_offset)`` - - df_dataframe.h:14092 - * - ``write_zigzag_to(metadata, row_group_total_size)`` - - df_dataframe.h:14102 - * - ``write_zigzag_to(metadata, static_cast(nrows()))`` - - df_dataframe.h:14106 - * - ``std::string xml(entry.data.begin(), entry.data.end())`` - std::string - df_dataframe.h:19175 - * - ``std::string xml(entry.data.begin(), entry.data.end())`` - std::string - df_dataframe.h:19225 - * - ``std::string xml(entry.data.begin(), entry.data.end())`` - std::string - df_dataframe.h:19265 - * - ``DataFrame xs(const std::string& key, int axis = 0, bool drop_level = true) const`` - DataFrame - df_dataframe.h:1775 - * - ``DataFrame xs(const std::string& key, const std::string& axis, bool drop_level = true) const`` - DataFrame - df_dataframe.h:1796 - * - ``DataFrame xs(const std::vector& keys, int axis = 0, const std::vector& levels =`` - DataFrame - df_dataframe.h:1826 - * - ``DataFrame xs_col(const std::string& key, bool drop_level) const`` - DataFrame - df_dataframe.h:1893 - * - ``DataFrame xs_cols_multi(const std::vector& keys, const std::vector& levels, bool drop_level) const`` - DataFrame - df_dataframe.h:1999 - * - ``DataFrame xs_row(const std::string& key, bool drop_level) const`` - DataFrame - df_dataframe.h:1841 - * - ``DataFrame xs_rows_multi(const std::vector& keys, const std::vector& levels, bool drop_level) const`` - DataFrame - df_dataframe.h:1941 - Code Examples ------------- The following examples are extracted from the test suite. .. _example-dataframe-empty-0: .. 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-dataframe-at-1: .. dropdown:: at (np_test_1_all.cpp:144) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 134 :emphasize-lines: 11 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}); std::cout << " -> tests passed" << std::endl; } void testArithmetic() { std::cout << "========= testArithmeticOperations ======================="; auto array1 = createFloat32Array({2, 2}, 5.0f); auto array2 = createFloat32Array({2, 2}, 3.0f); .. _example-dataframe-get-2: .. dropdown:: get (np_test_1_all.cpp:28526) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 28516 :emphasize-lines: 11 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); if (!passed) { std::cout << " [FAIL] : in np_test_indexing_mask_indices() : Mask indices incorrect"; .. _example-dataframe-take-3: .. dropdown:: take (np_test_5_all.cpp:4313) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4303 :emphasize-lines: 11 for (size_t i = 0; i < 6; ++i) { arr.setElementAt({ i }, static_cast(i * 10)); // [0, 10, 20, 30, 40, 50] } // Take specific indices numpy::NDArray indices({ 3 }); indices.setElementAt({ 0 }, 5); // 50 indices.setElementAt({ 1 }, 2); // 20 indices.setElementAt({ 2 }, 0); // 0 auto result = numpy::take(arr, indices); if (result.getSize() != 3) { std::cout << " [FAIL] : in np_test_take_basic() : Wrong result size"; throw std::runtime_error("Test failed"); } if (result.getElementAt({ 0 }) != 50 || result.getElementAt({ 1 }) != 20 || result.getElementAt({ 2 }) != 0) { std::cout << " [FAIL] : in np_test_take_basic() : Wrong values extracted"; throw std::runtime_error("Test failed"); } .. _example-dataframe-where-4: .. dropdown:: where (np_test_3_all.cpp:15253) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15243 :emphasize-lines: 11 auto y_data = createInt32Array({ 4 }, 0); y_data.setElementAt({ 0 }, 100); y_data.setElementAt({ 1 }, 200); y_data.setElementAt({ 2 }, 300); y_data.setElementAt({ 3 }, 400); auto y_mask = createBoolArray({ 4 }, false); MaskedArray y(y_data, y_mask, -999); // Test where() selection auto result = where(condition, x, y); if (!(result.getElementAt({ 0 }) == 10)) { std::string description = std::string("test_where_selection():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 10)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.getElementAt({ 1 }) == 200)) { std::string description = std::string("test_where_selection():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 200)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-dataframe-t-5: .. dropdown:: T (np_test_1_all.cpp:20062) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20052 :emphasize-lines: 11 std::mt19937 gen; public: MatrixGenerator(unsigned seed = 12345) : gen(seed) {} // Generate real matrix with known real eigenvalues NDArray real_matrix_real_eigenvalues(size_t n) { // Create diagonal matrix with known eigenvalues NDArray D = NDArray::createZeros({ n, n }); for (size_t i = 0; i < n; ++i) { D.setElementAt({ i, i }, T(i + 1)); // Eigenvalues 1, 2, 3, ... } // Create random orthogonal transformation auto Q = random_orthogonal_matrix(n); auto QT = Q.transposeArray(); // A = Q * D * Q^T return matmul(matmul(Q, D), QT); } .. _example-dataframe-squeeze-6: .. dropdown:: squeeze (np_test_1_all.cpp:18076) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18066 :emphasize-lines: 11 using namespace numpy; void testSqueeze() { std::cout << "========= testSqueeze ======================="; // Create array with singleton dimensions auto array = createInt32Array({ 1, 4, 1, 3, 1 }, 5); // Test squeeze all singleton dimensions auto squeezed_all = squeeze(array); if (!(squeezed_all.getShape().size() == 2)) { std::string description = std::string("testSqueeze():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(squeezed_all.getShape().size() == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(squeezed_all.getShape()[0] == 4)) { std::string description = std::string("testSqueeze():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(squeezed_all.getShape()[0] == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-dataframe-swapaxes-7: .. dropdown:: swapaxes (np_test_2_all.cpp:3707) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3697 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqualMCO(rolled.getElementAt({ 0, 0 }), arr.getElementAt({ 0, 3 })))) { std::string description = std::string("testRotationFlipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqualMCO(rolled.getElementAt({ 0, 0 }), arr.getElementAt({ 0, 3 })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test swapaxes auto swapped = swapaxes(arr, 0, 1); if (!(swapped.getShape() == std::vector({ 4, 3 }))) { std::string description = std::string("testRotationFlipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(swapped.getShape() == std::vector({ 4, 3 }))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(isApproxEqualMCO(swapped.getElementAt({ 0, 0 }), arr.getElementAt({ 0, 0 })))) { std::string description = std::string("testRotationFlipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqualMCO(swapped.getElementAt({ 0, 0 }), arr.getElementAt({ 0, 0 })))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-dataframe-transpose-8: .. dropdown:: transpose (np_test_2_all.cpp:4973) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4963 :emphasize-lines: 11 } /** * Test matrix properties and methods */ void testMatrixProperties() { std::cout << "========= testMatrixProperties ======================="; // 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"); .. _example-dataframe-cov-9: .. dropdown:: cov (np_test_1_all.cpp:12038) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12028 :emphasize-lines: 11 data.setElementAt({ 0, 0 }, 1.0); data.setElementAt({ 0, 1 }, 2.0); data.setElementAt({ 0, 2 }, 3.0); // Variable 2: [2, 4, 6] (perfectly correlated) data.setElementAt({ 1, 0 }, 2.0); data.setElementAt({ 1, 1 }, 4.0); data.setElementAt({ 1, 2 }, 6.0); // Test covariance matrix auto cov_matrix = cov(data); if (!(cov_matrix.getShape()[0] == 2)) { std::string description = std::string("testCovarianceAndCorrelation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(cov_matrix.getShape()[0] == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(cov_matrix.getShape()[1] == 2)) { std::string description = std::string("testCovarianceAndCorrelation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(cov_matrix.getShape()[1] == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-dataframe-max-10: .. 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-dataframe-mean-11: .. 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-dataframe-median-12: .. 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-dataframe-min-13: .. 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-dataframe-quantile-14: .. 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-dataframe-std-15: .. 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-dataframe-sum-16: .. 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-dataframe-var-17: .. 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-dataframe-abs-18: .. 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-dataframe-add-19: .. 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-dataframe-add-20: .. 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-dataframe-ceil-21: .. 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-dataframe-divide-22: .. 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-dataframe-floor-23: .. 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-dataframe-mod-24: .. 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-dataframe-mod-25: .. 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-dataframe-mode-26: .. dropdown:: mode (np_test_4_all.cpp:20711) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20701 :emphasize-lines: 11 #include using namespace numpy; namespace numpy_tests { namespace numpy_tests_phase6b { void np_test_phase6b_can_cast() { std::cout << "=== Test can_cast() ==="; // Test SAFE casting mode (default) { // Same type is always safe if (!(can_cast(DType::INT32, DType::INT32, CastingMode::SAFE) == true)) { std::string description = std::string("np_test_phase6b_can_cast():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(can_cast(DType::INT32, DType::INT32, CastingMode::SAFE) == true)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(can_cast(DType::FLOAT64, DType::FLOAT64, CastingMode::SAFE) == true)) { std::string description = std::string("np_test_phase6b_can_cast():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(can_cast(DType::FLOAT64, DType::FLOAT64, CastingMode::SAFE) == true)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-dataframe-mode-27: .. dropdown:: mode (np_test_4_all.cpp:20711) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20701 :emphasize-lines: 11 #include using namespace numpy; namespace numpy_tests { namespace numpy_tests_phase6b { void np_test_phase6b_can_cast() { std::cout << "=== Test can_cast() ==="; // Test SAFE casting mode (default) { // Same type is always safe if (!(can_cast(DType::INT32, DType::INT32, CastingMode::SAFE) == true)) { std::string description = std::string("np_test_phase6b_can_cast():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(can_cast(DType::INT32, DType::INT32, CastingMode::SAFE) == true)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(can_cast(DType::FLOAT64, DType::FLOAT64, CastingMode::SAFE) == true)) { std::string description = std::string("np_test_phase6b_can_cast():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(can_cast(DType::FLOAT64, DType::FLOAT64, CastingMode::SAFE) == true)"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-dataframe-multiply-28: .. 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-dataframe-round-29: .. 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-dataframe-subtract-30: .. 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-dataframe-truncate-31: .. dropdown:: truncate (np_test_5_all.cpp:7536) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7526 :emphasize-lines: 11 if (!passed) { std::cout << " [FAIL] : cutdeg failed"; throw std::runtime_error("np_test_cutdeg failed"); } std::cout << " -> tests passed" << std::endl; } void np_test_truncate() { std::cout << "========= truncate: truncate to size ======================="; numpy::Polynomial p({ 1.0, 2.0, 3.0, 4.0, 5.0 }); auto truncated = p.truncate(3); // Keep only first 3 coefficients auto coefs = truncated.coefficients(); bool passed = (coefs.size() == 3 && std::abs(coefs[0] - 1.0) < 1e-10 && std::abs(coefs[1] - 2.0) < 1e-10 && std::abs(coefs[2] - 3.0) < 1e-10); .. _example-dataframe-dot-32: .. dropdown:: dot (np_test_2_all.cpp:11523) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11513 :emphasize-lines: 11 numpy::NDArray v2({ 3 }); v1.setElementAt({ 0 }, 1.0); v1.setElementAt({ 1 }, 2.0); v1.setElementAt({ 2 }, 3.0); v2.setElementAt({ 0 }, 4.0); v2.setElementAt({ 1 }, 5.0); v2.setElementAt({ 2 }, 6.0); auto result = numpy::linalg::dot(v1, v2); double expected = 1.0 * 4.0 + 2.0 * 5.0 + 3.0 * 6.0; // = 32 // Extract scalar from 0-D array double result_value = result.getElementAt({}); if (std::abs(result_value - expected) > 1e-10) { std::cout << " [FAIL] : dot product incorrect, expected " << expected << ", got " << result_value; throw std::runtime_error("dot test failed"); } .. _example-dataframe-dot-33: .. dropdown:: dot (np_test_2_all.cpp:11523) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11513 :emphasize-lines: 11 numpy::NDArray v2({ 3 }); v1.setElementAt({ 0 }, 1.0); v1.setElementAt({ 1 }, 2.0); v1.setElementAt({ 2 }, 3.0); v2.setElementAt({ 0 }, 4.0); v2.setElementAt({ 1 }, 5.0); v2.setElementAt({ 2 }, 6.0); auto result = numpy::linalg::dot(v1, v2); double expected = 1.0 * 4.0 + 2.0 * 5.0 + 3.0 * 6.0; // = 32 // Extract scalar from 0-D array double result_value = result.getElementAt({}); if (std::abs(result_value - expected) > 1e-10) { std::cout << " [FAIL] : dot product incorrect, expected " << expected << ", got " << result_value; throw std::runtime_error("dot test failed"); } .. _example-dataframe-sample-34: .. dropdown:: sample (np_test_1_all.cpp:22321) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22311 :emphasize-lines: 11 throw std::runtime_error(description); } for (size_t i = 0; i < 3; ++i) { double val = random_samp.getElementAt({ i }); if (!(val >= 0.0 && val < 1.0)) { std::string description = std::string("testRandomUtilityFunctions():") + __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] Random sample (alias)\n"; auto ranf_arr = ranf({ {3} }); if (!(ranf_arr.getShape()[0] == 3)) { std::string description = std::string("testRandomUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ranf_arr.getShape()[0] == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] ranf (alias)\n"; auto sample_arr = sample({ {3} }); .. _example-dataframe-all-35: .. 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-dataframe-any-36: .. 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-dataframe-isin-37: .. dropdown:: isin (np_test_1_all.cpp:19434) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19424 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(membership.getElementAt({ 5 }) == false)) { std::string description = std::string("testMembershipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(membership.getElementAt({ 5 }) == false)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Membership testing (in1d) works correctly\n"; // Test isin (alias for in1d) auto isin_result = isin(test_array, test_values); // Should be identical to in1d result for (size_t i = 0; i < membership.getSize(); ++i) { if (!(isin_result.getElementAt({ i }) == membership.getElementAt({ i }))) { std::string description = std::string("testMembershipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isin_result.getElementAt({ i }) == membership.getElementAt({ i }))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } .. _example-dataframe-isin-38: .. dropdown:: isin (np_test_1_all.cpp:19434) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19424 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(membership.getElementAt({ 5 }) == false)) { std::string description = std::string("testMembershipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(membership.getElementAt({ 5 }) == false)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Membership testing (in1d) works correctly\n"; // Test isin (alias for in1d) auto isin_result = isin(test_array, test_values); // Should be identical to in1d result for (size_t i = 0; i < membership.getSize(); ++i) { if (!(isin_result.getElementAt({ i }) == membership.getElementAt({ i }))) { std::string description = std::string("testMembershipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isin_result.getElementAt({ i }) == membership.getElementAt({ i }))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } .. _example-dataframe-to_numpy-39: .. dropdown:: to_numpy (np_test_5_all.cpp:21373) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21363 :emphasize-lines: 11 if (errors == 0) { std::cout << "np_test_timedelta_components -> tests passed" << std::endl; } return errors; } // ============================================================================= // Test 4: Total Conversion Properties // ============================================================================= int np_test_timedelta_total_conversions() { int errors = 0; numpy::Timedelta td(1, 12, 0); // 1 day 12 hours = 1.5 days = 36 hours // total_seconds { double secs = td.total_seconds(); double expected = (24 + 12) * 3600.0; if (std::abs(secs - expected) > 0.0001) { std::cout << "[FAIL] np_test_timedelta_total_conversions: total_seconds expected " << expected << ", got " << secs << std::endl; .. _example-dataframe-to_string-40: .. dropdown:: to_string (np_test_1_all.cpp:454) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 444 :emphasize-lines: 11 // Modify through different views view1.setElementAt({0, 0}, 100); view2.setElementAt({2, 1}, 200); // This is (1, 2) in original view3.setElementAt({0, 0}, 300); // This is (1, 1) in original // std::cout << "After modifications through multiple views:" << std::endl; //original.printArray(); // Verify all changes are reflected if (!(original.getElementAt({0, 0}) == 100)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({0, 0}) == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(original.getElementAt({1, 2}) == 200)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 2}) == 200)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(original.getElementAt({1, 1}) == 300)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 300)"; .. _example-dataframe-to_string-41: .. dropdown:: to_string (np_test_1_all.cpp:454) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 444 :emphasize-lines: 11 // Modify through different views view1.setElementAt({0, 0}, 100); view2.setElementAt({2, 1}, 200); // This is (1, 2) in original view3.setElementAt({0, 0}, 300); // This is (1, 1) in original // std::cout << "After modifications through multiple views:" << std::endl; //original.printArray(); // Verify all changes are reflected if (!(original.getElementAt({0, 0}) == 100)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({0, 0}) == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(original.getElementAt({1, 2}) == 200)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 2}) == 200)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(original.getElementAt({1, 1}) == 300)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 300)"; .. _example-dataframe-insert-42: .. dropdown:: insert (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-dataframe-insert-43: .. dropdown:: insert (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-dataframe-stack-44: .. dropdown:: stack (np_test_1_all.cpp:5509) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5499 :emphasize-lines: 11 void testStackArrayUtils() { std::cout << "========= testStackArrayUtils ======================="; // Test 1D stacking auto arr1 = NDArray::createRange(0, 3, 1); // [0, 1, 2] auto arr2 = NDArray::createRange(3, 6, 1); // [3, 4, 5] auto arr3 = NDArray::createRange(6, 9, 1); // [6, 7, 8] // Stack along axis 0 (new first dimension) auto result0 = stack({arr1, arr2, arr3}, 0); // std::cout << "1D stack (axis=0):"; //result0.printArray(); if (!(result0.getShape()[0] == 3)) { std::string description = std::string("testStackArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result0.getShape()[0] == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result0.getShape()[1] == 3)) { std::string description = std::string("testStackArrayUtils():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result0.getShape()[1] == 3)"; .. _example-dataframe-astype-45: .. dropdown:: astype (np_test_3_all.cpp:796) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 786 :emphasize-lines: 11 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); if (std::abs(typed_result.getElementAt({ 0 }) - 4.0) > 1e-10 || std::abs(typed_result.getElementAt({ 1 }) - 9.0) > 1e-10 || std::abs(typed_result.getElementAt({ 2 }) - 16.0) > 1e-10) { std::cout << "[FAIL] Basic frompyfunc creation failed"; return 1; } // std::cout << "[OK] Basic frompyfunc creation works correctly" << std::endl; std::cout << " -> tests passed" << std::endl; return 0; .. _example-dataframe-astype-46: .. dropdown:: astype (np_test_3_all.cpp:796) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 786 :emphasize-lines: 11 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); if (std::abs(typed_result.getElementAt({ 0 }) - 4.0) > 1e-10 || std::abs(typed_result.getElementAt({ 1 }) - 9.0) > 1e-10 || std::abs(typed_result.getElementAt({ 2 }) - 16.0) > 1e-10) { std::cout << "[FAIL] Basic frompyfunc creation failed"; return 1; } // std::cout << "[OK] Basic frompyfunc creation works correctly" << std::endl; std::cout << " -> tests passed" << std::endl; return 0; .. _example-dataframe-copy-47: .. dropdown:: copy (np_test_1_all.cpp:9812) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9802 :emphasize-lines: 11 //original.printArray(); // The modification should be at position (1,1) in original if (!(original.getElementAt({1, 1}) == 9999)) { std::string description = std::string("testSliceCopyVsViewMemoryOwnership():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 9999)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Slice view shares memory with original"; // Test slice copy (should be independent) auto slice_copy = original.sliceArray({{2, 4}, {2, 4}}); // std::cout << "Slice copy [2:4, 2:4]:"; //slice_copy.printArray(); slice_copy.setElementAt({0, 0}, 7777); // std::cout << "After modifying slice copy at (0,0):" << std::endl; // std::cout << "Original array:" << std::endl; //original.printArray(); // std::cout << "Slice copy:" << std::endl; .. _example-dataframe-combine-48: .. dropdown:: combine (np_test_5_all.cpp:22273) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22263 :emphasize-lines: 11 auto pass = true; std::string fail_msg; // Default constructor (NaT) numpy::Timestamp nat; if (!nat.isNaT()) { pass = false; fail_msg = "Default constructor should create NaT"; } // Component constructor numpy::Timestamp ts1(2024, 6, 15, 14, 30, 45); if (ts1.year() != 2024 || ts1.month() != 6 || ts1.day() != 15 || ts1.hour() != 14 || ts1.minute() != 30 || ts1.second() != 45) { pass = false; fail_msg = "Component constructor values incorrect"; } // With microseconds and nanoseconds numpy::Timestamp ts2(2024, 1, 1, 12, 0, 0, 123456, 789); .. _example-dataframe-a-49: .. dropdown:: A (np_test_1_all.cpp:15562) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15552 :emphasize-lines: 11 auto pseudoinv = pinv(matrix); // std::cout << "Pseudoinverse:" << std::endl; //pseudoinv.printArray(); // Test Moore-Penrose conditions // 1. A * A^+ * A = A auto AApA = matmul(matmul(matrix, pseudoinv), matrix); // std::cout << "A * A^+ * A (should equal A):" << std::endl; //AApA.printArray(); // Check reconstruction 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 }) - AApA.getElementAt({ i, j })); if (error > max_error) max_error = error; } } .. _example-dataframe-a-50: .. dropdown:: A (np_test_1_all.cpp:15562) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15552 :emphasize-lines: 11 auto pseudoinv = pinv(matrix); // std::cout << "Pseudoinverse:" << std::endl; //pseudoinv.printArray(); // Test Moore-Penrose conditions // 1. A * A^+ * A = A auto AApA = matmul(matmul(matrix, pseudoinv), matrix); // std::cout << "A * A^+ * A (should equal A):" << std::endl; //AApA.printArray(); // Check reconstruction 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 }) - AApA.getElementAt({ i, j })); if (error > max_error) max_error = error; } } .. _example-dataframe-b-51: .. dropdown:: B (np_test_2_all.cpp:3245) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3235 :emphasize-lines: 11 mkl_set_num_threads(4); int num_threads = mkl_get_max_threads(); // std::cout << "MKL Max Threads: " << num_threads << std::endl; std::cout << " -> tests passed" << std::endl; } void testMKLMatrixMultiplication() { std::cout << "========= testMKLMatrixMultiplication ======================="; // Create test matrices: A (3x4) * B (4x2) = C (3x2) const int m = 3, n = 2, k = 4; // Matrix A (3x4) - row major order std::vector A = { 1.0, 2.0, 3.0, 4.0, // row 0 5.0, 6.0, 7.0, 8.0, // row 1 9.0, 10.0, 11.0, 12.0 // row 2 }; // Matrix B (4x2) - row major order .. _example-dataframe-axes-52: .. dropdown:: axes (np_test_5_all.cpp:16631) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16621 :emphasize-lines: 11 return 0; } else { std::cout << " [FAIL] reshape() failed" << std::endl; return 1; } } // Test 15: transpose() - Transpose array (SKIPPED - needs implementation) int test_transpose() { std::cout << "\n[TEST] ma.transpose() - SKIPPED (needs correct transpose API)" << std::endl; return 0; // Skip for now } // Test 16: swapaxes() - Swap two axes (SKIPPED - needs implementation) int test_swapaxes() { std::cout << "\n[TEST] ma.swapaxes() - SKIPPED (needs correct swapaxes API)" << std::endl; return 0; // Skip for now } // Test 17: repeat() - Repeat elements int test_repeat() { .. _example-dataframe-b-53: .. dropdown:: b (np_test_1_all.cpp:7707) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7697 :emphasize-lines: 11 // std::cout << "Float16 ones array (2x3):"; //ones_array.printArray(); std::cout << " -> tests passed" << std::endl; } void testFloat16ArithmeticFloat16() { std::cout << "========= testFloat16ArithmeticFloat16 ======================="; float16 a(2.5f); float16 b(1.5f); // std::cout << "a = " << a << ", b = " << b << std::endl; // std::cout << "a + b = " << (a + b) << std::endl; // std::cout << "a - b = " << (a - b) << std::endl; // std::cout << "a * b = " << (a * b) << std::endl; // std::cout << "a / b = " << (a / b) << std::endl; // Test array arithmetic auto arr1 = createFloat16Array({2}, float16(2.5f)); auto arr2 = createFloat16Array({2}, float16(1.5f)); .. _example-dataframe-begin-54: .. dropdown:: begin (np_test_1_all.cpp:6171) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6161 :emphasize-lines: 11 // Test sorted data generation std::vector data = gen.generate(50, DataPattern::SORTED); if (!(data.size() == 50)) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Verify data is sorted if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __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); } // std::cout << "Sorted data generation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-dataframe-begin-55: .. dropdown:: begin (np_test_1_all.cpp:6171) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6161 :emphasize-lines: 11 // Test sorted data generation std::vector data = gen.generate(50, DataPattern::SORTED); if (!(data.size() == 50)) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Verify data is sorted if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __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); } // std::cout << "Sorted data generation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-dataframe-bool_-56: .. dropdown:: bool_ (np_test_3_all.cpp:15233) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15223 :emphasize-lines: 11 std::cout << "========= test_where_selection ===="; // Create condition, x, and y arrays auto cond_data = createBoolArray({ 4 }, false); cond_data.setElementAt({ 0 }, true); cond_data.setElementAt({ 1 }, false); cond_data.setElementAt({ 2 }, true); cond_data.setElementAt({ 3 }, false); auto cond_mask = createBoolArray({ 4 }, false); MaskedArray condition(cond_data, cond_mask, bool_(false)); auto x_data = createInt32Array({ 4 }, 0); x_data.setElementAt({ 0 }, 10); x_data.setElementAt({ 1 }, 20); x_data.setElementAt({ 2 }, 30); x_data.setElementAt({ 3 }, 40); auto x_mask = createBoolArray({ 4 }, false); MaskedArray x(x_data, x_mask, -999); .. _example-dataframe-check_file-57: .. dropdown:: check_file (np_test_5_all.cpp:709) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 699 :emphasize-lines: 11 arr.setElementAt({ static_cast(i / 3), static_cast(i % 3) }, i); } writer.add_array("data", arr); writer.finalize(); // Test finalize // std::cout << " NPZ file finalized successfully" << std::endl; } // Verify file was written 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 ========================"; .. _example-dataframe-check_file-58: .. dropdown:: check_file (np_test_5_all.cpp:709) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 699 :emphasize-lines: 11 arr.setElementAt({ static_cast(i / 3), static_cast(i % 3) }, i); } writer.add_array("data", arr); writer.finalize(); // Test finalize // std::cout << " NPZ file finalized successfully" << std::endl; } // Verify file was written 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 ========================"; .. _example-dataframe-clip-59: .. 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-dataframe-clone-60: .. dropdown:: clone (np_test_1_all.cpp:24942) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 24932 :emphasize-lines: 11 } // Test reproducibility numpy::random::PCG64DXSM rng2(11111); if (rng2.next_uint64() != val) { std::cout << " [FAIL] : in np_test_bitgen_pcg64dxsm() : not reproducible"; throw std::runtime_error("np_test_bitgen_pcg64dxsm failed"); } // Test clone auto cloned = rng.clone(); if (cloned->name() != "PCG64DXSM") { std::cout << " [FAIL] : in np_test_bitgen_pcg64dxsm() : clone name incorrect"; throw std::runtime_error("np_test_bitgen_pcg64dxsm failed"); } std::cout << " -> tests passed" << std::endl; } // ============================================================================ // PHILOX TESTS .. _example-dataframe-column-61: .. dropdown:: column (np_test_4_all.cpp:21695) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21685 :emphasize-lines: 11 data.setElementAt({0, 1}, 2.0); data.setElementAt({0, 2}, 3.0); data.setElementAt({1, 0}, 4.0); data.setElementAt({1, 1}, 5.0); data.setElementAt({1, 2}, 6.0); data.setElementAt({2, 0}, 7.0); data.setElementAt({2, 1}, 8.0); data.setElementAt({2, 2}, 9.0); NDArray mask({3, 3}, bool_(false)); // Mask entire middle column (col 1) mask.setElementAt({0, 1}, bool_(true)); mask.setElementAt({1, 1}, bool_(true)); mask.setElementAt({2, 1}, bool_(true)); auto ma = ma::masked_array(data, mask); auto result = ma::compress_cols(ma); // Should keep columns 0 and 2 only if (!(result.getShape()[0] == 3)) { std::string description = std::string("np_test_phase6c_compress_cols():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getShape()[0] == 3)"; .. _example-dataframe-column-62: .. dropdown:: column (np_test_4_all.cpp:21695) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21685 :emphasize-lines: 11 data.setElementAt({0, 1}, 2.0); data.setElementAt({0, 2}, 3.0); data.setElementAt({1, 0}, 4.0); data.setElementAt({1, 1}, 5.0); data.setElementAt({1, 2}, 6.0); data.setElementAt({2, 0}, 7.0); data.setElementAt({2, 1}, 8.0); data.setElementAt({2, 2}, 9.0); NDArray mask({3, 3}, bool_(false)); // Mask entire middle column (col 1) mask.setElementAt({0, 1}, bool_(true)); mask.setElementAt({1, 1}, bool_(true)); mask.setElementAt({2, 1}, bool_(true)); auto ma = ma::masked_array(data, mask); auto result = ma::compress_cols(ma); // Should keep columns 0 and 2 only if (!(result.getShape()[0] == 3)) { std::string description = std::string("np_test_phase6c_compress_cols():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getShape()[0] == 3)"; .. _example-dataframe-columns-63: .. dropdown:: columns (np_test_4_all.cpp:22531) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22521 :emphasize-lines: 11 mask.setElementAt({1, 3}, false); mask.setElementAt({2, 0}, false); mask.setElementAt({2, 1}, true); mask.setElementAt({2, 2}, true); mask.setElementAt({2, 3}, false); MaskedArray marr(data, mask); auto result = numpy::ma::compress_nd(marr, 1); // Should have 2 columns (columns 0 and 3) if (!(result.data().getShape().size() == 2)) { std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape().size() == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.data().getShape()[0] == 3)) { std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape()[0] == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-dataframe-columns-64: .. dropdown:: columns (np_test_4_all.cpp:22531) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22521 :emphasize-lines: 11 mask.setElementAt({1, 3}, false); mask.setElementAt({2, 0}, false); mask.setElementAt({2, 1}, true); mask.setElementAt({2, 2}, true); mask.setElementAt({2, 3}, false); MaskedArray marr(data, mask); auto result = numpy::ma::compress_nd(marr, 1); // Should have 2 columns (columns 0 and 3) if (!(result.data().getShape().size() == 2)) { std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape().size() == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.data().getShape()[0] == 3)) { std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape()[0] == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-dataframe-columns-65: .. dropdown:: columns (np_test_4_all.cpp:22531) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22521 :emphasize-lines: 11 mask.setElementAt({1, 3}, false); mask.setElementAt({2, 0}, false); mask.setElementAt({2, 1}, true); mask.setElementAt({2, 2}, true); mask.setElementAt({2, 3}, false); MaskedArray marr(data, mask); auto result = numpy::ma::compress_nd(marr, 1); // Should have 2 columns (columns 0 and 3) if (!(result.data().getShape().size() == 2)) { std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape().size() == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.data().getShape()[0] == 3)) { std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape()[0] == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-dataframe-columns-66: .. dropdown:: columns (np_test_4_all.cpp:22531) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22521 :emphasize-lines: 11 mask.setElementAt({1, 3}, false); mask.setElementAt({2, 0}, false); mask.setElementAt({2, 1}, true); mask.setElementAt({2, 2}, true); mask.setElementAt({2, 3}, false); MaskedArray marr(data, mask); auto result = numpy::ma::compress_nd(marr, 1); // Should have 2 columns (columns 0 and 3) if (!(result.data().getShape().size() == 2)) { std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape().size() == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.data().getShape()[0] == 3)) { std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape()[0] == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-dataframe-count-67: .. 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-dataframe-cumprod-68: .. dropdown:: cumprod (np_test_5_all.cpp:5107) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5097 :emphasize-lines: 11 } void np_test_cumprod_1d() { std::cout << "========= cumprod 1D ======================="; // Test cumprod with 1D array numpy::NDArray arr({ 5 }); arr.setElementAt({ 0 }, 1); arr.setElementAt({ 1 }, 2); arr.setElementAt({ 2 }, 3); arr.setElementAt({ 3 }, 4); arr.setElementAt({ 4 }, 5); auto result = numpy::cumprod(arr); // Expected: [1, 2, 6, 24, 120] if (result.getElementAt({ 0 }) != 1 || result.getElementAt({ 1 }) != 2 || result.getElementAt({ 2 }) != 6 || result.getElementAt({ 3 }) != 24 || result.getElementAt({ 4 }) != 120) { std::cout << " [FAIL] : in np_test_cumprod_1d() : Incorrect cumprod result"; throw std::runtime_error("Test failed"); .. _example-dataframe-cumsum-69: .. dropdown:: cumsum (np_test_5_all.cpp:5028) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5018 :emphasize-lines: 11 namespace numpy_tests_cumulative_operations { void np_test_cumsum_1d() { std::cout << "========= cumsum 1D ======================="; // Test cumsum with 1D array numpy::NDArray arr({ 5 }); arr.setElementAt({ 0 }, 1); arr.setElementAt({ 1 }, 2); arr.setElementAt({ 2 }, 3); arr.setElementAt({ 3 }, 4); arr.setElementAt({ 4 }, 5); auto result = numpy::cumsum(arr); // Expected: [1, 3, 6, 10, 15] if (result.getElementAt({ 0 }) != 1 || result.getElementAt({ 1 }) != 3 || result.getElementAt({ 2 }) != 6 || result.getElementAt({ 3 }) != 10 || result.getElementAt({ 4 }) != 15) { std::cout << " [FAIL] : in np_test_cumsum_1d() : Incorrect cumsum result"; throw std::runtime_error("Test failed"); .. _example-dataframe-data-70: .. dropdown:: data (np_test_1_all.cpp:2084) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2074 :emphasize-lines: 11 } if (!(derived_ptr->extra == 2)) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 6: Large object handling struct LargeObject { std::vector data; LargeObject() : data(10000, 3.14159) {} // Large object }; LargeObject large; object_ large_obj(large); // Should handle large objects if (!(!large_obj.is_null())) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(large_obj.is_type())) { .. _example-dataframe-data-71: .. dropdown:: data (np_test_1_all.cpp:2084) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2074 :emphasize-lines: 11 } if (!(derived_ptr->extra == 2)) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 6: Large object handling struct LargeObject { std::vector data; LargeObject() : data(10000, 3.14159) {} // Large object }; LargeObject large; object_ large_obj(large); // Should handle large objects if (!(!large_obj.is_null())) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(large_obj.is_type())) { .. _example-dataframe-data-72: .. dropdown:: data (np_test_1_all.cpp:2084) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2074 :emphasize-lines: 11 } if (!(derived_ptr->extra == 2)) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 6: Large object handling struct LargeObject { std::vector data; LargeObject() : data(10000, 3.14159) {} // Large object }; LargeObject large; object_ large_obj(large); // Should handle large objects if (!(!large_obj.is_null())) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(large_obj.is_type())) { .. _example-dataframe-data-73: .. dropdown:: data (np_test_1_all.cpp:2084) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2074 :emphasize-lines: 11 } if (!(derived_ptr->extra == 2)) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 6: Large object handling struct LargeObject { std::vector data; LargeObject() : data(10000, 3.14159) {} // Large object }; LargeObject large; object_ large_obj(large); // Should handle large objects if (!(!large_obj.is_null())) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(large_obj.is_type())) { .. _example-dataframe-data-74: .. dropdown:: data (np_test_1_all.cpp:2084) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2074 :emphasize-lines: 11 } if (!(derived_ptr->extra == 2)) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 6: Large object handling struct LargeObject { std::vector data; LargeObject() : data(10000, 3.14159) {} // Large object }; LargeObject large; object_ large_obj(large); // Should handle large objects if (!(!large_obj.is_null())) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(large_obj.is_type())) { .. _example-dataframe-data-75: .. dropdown:: data (np_test_1_all.cpp:2084) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2074 :emphasize-lines: 11 } if (!(derived_ptr->extra == 2)) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 6: Large object handling struct LargeObject { std::vector data; LargeObject() : data(10000, 3.14159) {} // Large object }; LargeObject large; object_ large_obj(large); // Should handle large objects if (!(!large_obj.is_null())) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(large_obj.is_type())) { .. _example-dataframe-data-76: .. dropdown:: data (np_test_1_all.cpp:2084) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2074 :emphasize-lines: 11 } if (!(derived_ptr->extra == 2)) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 6: Large object handling struct LargeObject { std::vector data; LargeObject() : data(10000, 3.14159) {} // Large object }; LargeObject large; object_ large_obj(large); // Should handle large objects if (!(!large_obj.is_null())) { std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(large_obj.is_type())) { .. _example-dataframe-describe-77: .. 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-dataframe-diff-78: .. dropdown:: diff (np_test_2_all.cpp:4947) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4937 :emphasize-lines: 11 // Test matrix addition and subtraction numpy::Matrix a("1 2; 3 4"); numpy::Matrix b("5 6; 7 8"); auto sum = a + b; assert_test(std::abs(sum(0, 0) - 6.0) < 1e-10, "Matrix addition"); assert_test(std::abs(sum(1, 1) - 12.0) < 1e-10, "Matrix addition"); auto diff = b - a; assert_test(std::abs(diff(0, 0) - 4.0) < 1e-10, "Matrix subtraction"); assert_test(std::abs(diff(1, 1) - 4.0) < 1e-10, "Matrix subtraction"); // Test matrix multiplication (not element-wise!) auto product = a * b; assert_test(std::abs(product(0, 0) - 19.0) < 1e-10, "Matrix multiplication 0,0"); assert_test(std::abs(product(0, 1) - 22.0) < 1e-10, "Matrix multiplication 0,1"); assert_test(std::abs(product(1, 0) - 43.0) < 1e-10, "Matrix multiplication 1,0"); assert_test(std::abs(product(1, 1) - 50.0) < 1e-10, "Matrix multiplication 1,1"); // Test scalar multiplication .. _example-dataframe-dtype_name-79: .. 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-dataframe-dtypes-80: .. dropdown:: dtypes (np_test_4_all.cpp:10403) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10393 :emphasize-lines: 11 } catch (const std::exception& e) { std::cout << "====================================== np_test_power_scalar FAILED ==================================== "; std::cout << "Exception: " << e.what() << std::endl; return 1; } } } // namespace numpy_tests // Test file for abs() scalar support // Tests all 13 dtypes (8 int, 1 bool, 2 float, 2 complex) + edge cases // Expected: 17 tests, all passing #include #include #include #include "../numpy/np_ndarray.h" #include "../numpy/np_math_utils_sqrt.h" namespace numpy_tests { namespace numpy_tests_abs_scalar { .. _example-dataframe-end-81: .. dropdown:: end (np_test_1_all.cpp:6171) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6161 :emphasize-lines: 11 // Test sorted data generation std::vector data = gen.generate(50, DataPattern::SORTED); if (!(data.size() == 50)) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Verify data is sorted if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __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); } // std::cout << "Sorted data generation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-dataframe-end-82: .. dropdown:: end (np_test_1_all.cpp:6171) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6161 :emphasize-lines: 11 // Test sorted data generation std::vector data = gen.generate(50, DataPattern::SORTED); if (!(data.size() == 50)) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Verify data is sorted if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __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); } // std::cout << "Sorted data generation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-dataframe-end-83: .. dropdown:: end (np_test_1_all.cpp:6171) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6161 :emphasize-lines: 11 // Test sorted data generation std::vector data = gen.generate(50, DataPattern::SORTED); if (!(data.size() == 50)) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Verify data is sorted if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __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); } // std::cout << "Sorted data generation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-dataframe-end-84: .. dropdown:: end (np_test_1_all.cpp:6171) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6161 :emphasize-lines: 11 // Test sorted data generation std::vector data = gen.generate(50, DataPattern::SORTED); if (!(data.size() == 50)) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Verify data is sorted if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __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); } // std::cout << "Sorted data generation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-dataframe-end-85: .. dropdown:: end (np_test_1_all.cpp:6171) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6161 :emphasize-lines: 11 // Test sorted data generation std::vector data = gen.generate(50, DataPattern::SORTED); if (!(data.size() == 50)) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Verify data is sorted if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __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); } // std::cout << "Sorted data generation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-dataframe-file-86: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-87: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-88: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-89: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-90: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-91: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-92: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-93: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-94: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-95: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-96: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-97: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-98: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-99: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-100: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-101: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-file-102: .. dropdown:: file (np_test_1_all.cpp:27026) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27016 :emphasize-lines: 11 } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream std::ifstream file(test_filename, std::ios::binary); file.seekg(30); // Move to position 30 size_t size2 = io::get_remaining_size(file); if (size2 != 70) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2; throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size"); } // Verify position preserved auto pos = file.tellg(); if (pos != 30) { .. _example-dataframe-filter-103: .. dropdown:: filter (np_test_2_all.cpp:9555) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9545 :emphasize-lines: 11 for (int i = 0; i < size; i++) { signal[i] = std::sin(2.0f * 3.14159f * i / 8.0f) + 0.1f * (i % 3 - 1); } // std::cout << "Original Signal: "; for (int i = 0; i < size; i++) { // std::cout << std::setw(8) << std::fixed << std::setprecision(3) << signal[i] << " "; } // std::cout << std::endl; // Apply a simple smoothing filter (moving average) const int kernel_size = 3; std::vector kernel = { 1.0f / 3.0f, 1.0f / 3.0f, 1.0f / 3.0f }; // For simplicity, we'll do a basic convolution manually for demonstration for (int i = 1; i < size - 1; i++) { filtered[i] = (signal[i - 1] + signal[i] + signal[i + 1]) / 3.0f; } filtered[0] = signal[0]; filtered[size - 1] = signal[size - 1]; .. _example-dataframe-first-104: .. dropdown:: first (np_test_4_all.cpp:12410) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12400 :emphasize-lines: 11 // std::cout << "[OK] NaN-ignoring behavior tests\n"; } // Test both NaN returns first NaN void test_fmax_both_nan() { std::cout << "========= test_fmax_both_nan ===="; double nan1 = std::numeric_limits::quiet_NaN(); double nan2 = std::numeric_limits::quiet_NaN(); // If both are NaN, return first (which is still NaN) double result = numpy::fmax(nan1, nan2); if (!std::isnan(result)) { std::cout << " [FAIL] : test_fmax_both_nan failed - fmax(NaN, NaN) should be NaN"; throw std::runtime_error("fmax(NaN, NaN) should return NaN"); } // std::cout << "[OK] Both NaN returns NaN test\n"; } // Test type preservation .. _example-dataframe-flags-105: .. 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-dataframe-found-106: .. dropdown:: found (np_test_1_all.cpp:27676) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27666 :emphasize-lines: 11 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; std::cout << " -> tests passed" << std::endl; } void test_mask_rows_cols() { std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }); auto mask = numpy::array({ {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); .. _example-dataframe-found-107: .. dropdown:: found (np_test_1_all.cpp:27676) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27666 :emphasize-lines: 11 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; std::cout << " -> tests passed" << std::endl; } void test_mask_rows_cols() { std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }); auto mask = numpy::array({ {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); .. _example-dataframe-gen-108: .. dropdown:: gen (np_test_1_all.cpp:6126) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6116 :emphasize-lines: 11 } // std::cout << "BenchmarkResult storage test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_data_generator_randomBenchmarkSorting() { std::cout << "========= test_data_generator_random ======================="; DataGenerator gen(42); // Fixed seed for reproducibility // Test random data generation std::vector data = gen.generate(100, DataPattern::RANDOM); if (!(data.size() == 100)) { std::string description = std::string("test_data_generator_randomBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-dataframe-index-109: .. dropdown:: index (np_test_5_all.cpp:1283) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1273 :emphasize-lines: 11 // ============================================================================ // SEARCH OPERATION TESTS // ============================================================================ void np_test_string_index() { std::cout << "========= index search operation ======================="; std::vector strings = { "hello world", "tomorrow" }; auto arr = numpy::char_::array<32>(strings); auto indices = numpy::char_::index(arr, "o"); bool passed = (indices.getSize() == arr.size()); if (!passed) { std::cout << " [FAIL] : in np_test_string_index() : indices size mismatch"; throw std::runtime_error("np_test_string_index failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-dataframe-index-110: .. dropdown:: index (np_test_5_all.cpp:1283) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1273 :emphasize-lines: 11 // ============================================================================ // SEARCH OPERATION TESTS // ============================================================================ void np_test_string_index() { std::cout << "========= index search operation ======================="; std::vector strings = { "hello world", "tomorrow" }; auto arr = numpy::char_::array<32>(strings); auto indices = numpy::char_::index(arr, "o"); bool passed = (indices.getSize() == arr.size()); if (!passed) { std::cout << " [FAIL] : in np_test_string_index() : indices size mismatch"; throw std::runtime_error("np_test_string_index failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-dataframe-info-111: .. 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-dataframe-join-112: .. 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-dataframe-keys-113: .. dropdown:: keys (np_test_2_all.cpp:8614) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8604 :emphasize-lines: 11 if (!indices.empty()) { std::cout << " IPP empty array test: -> [FAIL]"; throw std::runtime_error("IPP empty array test: FAILED - should return empty"); } // std::cout << "[OK] IPP empty array test: PASSED" << std::endl; } // Test 6: Large array performance { const size_t n = 10000; std::vector> keys(2); keys[0].resize(n); keys[1].resize(n); std::mt19937 gen(42); std::uniform_int_distribution dist(0, 1000); for (size_t i = 0; i < n; ++i) { keys[0][i] = dist(gen); keys[1][i] = dist(gen); } .. _example-dataframe-keys-114: .. dropdown:: keys (np_test_2_all.cpp:8614) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8604 :emphasize-lines: 11 if (!indices.empty()) { std::cout << " IPP empty array test: -> [FAIL]"; throw std::runtime_error("IPP empty array test: FAILED - should return empty"); } // std::cout << "[OK] IPP empty array test: PASSED" << std::endl; } // Test 6: Large array performance { const size_t n = 10000; std::vector> keys(2); keys[0].resize(n); keys[1].resize(n); std::mt19937 gen(42); std::uniform_int_distribution dist(0, 1000); for (size_t i = 0; i < n; ++i) { keys[0][i] = dist(gen); keys[1][i] = dist(gen); } .. _example-dataframe-kurtosis-115: .. 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-dataframe-levels-116: .. dropdown:: levels (np_test_5_all.cpp:105) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 95 :emphasize-lines: 11 } std::cout << " -> tests passed" << std::endl; } // =========================================================================== // Test 2: Compression Levels // =========================================================================== void np_test_zlib_compression_levels() { std::cout << "========= compression levels (0-9) ============================="; std::vector data = create_test_data(1000, 'A'); for (int level = 0; level <= 9; ++level) { uLongf compressed_len = compressBound(static_cast(data.size())); std::vector compressed(compressed_len); int result = compress2(compressed.data(), &compressed_len, data.data(), static_cast(data.size()), level); .. _example-dataframe-mask-117: .. dropdown:: mask (np_test_1_all.cpp:27691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27681 :emphasize-lines: 11 void test_mask_rows_cols() { std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }); auto mask = numpy::array({ {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); auto result_rows = numpy::ma::mask_rows(ma); auto result_cols = numpy::ma::mask_cols(ma); // std::cout << " ma::mask_rows(): row 0 fully masked: " << (result_rows.mask().getElementAt({ 0, 0 }) ? "true" : "false") << std::endl; // std::cout << " ma::mask_cols(): column 1 fully masked: " << (result_cols.mask().getElementAt({ 1, 1 }) ? "true" : "false"); std::cout << " -> tests passed"; } void test_compress_rowcols() { std::cout << "========= ma::compress_rowcols(): remove masked rows/columns ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0} }); auto mask = numpy::array({ {false, false, false}, {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); .. _example-dataframe-mask-118: .. dropdown:: mask (np_test_1_all.cpp:27691) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27681 :emphasize-lines: 11 void test_mask_rows_cols() { std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }); auto mask = numpy::array({ {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); auto result_rows = numpy::ma::mask_rows(ma); auto result_cols = numpy::ma::mask_cols(ma); // std::cout << " ma::mask_rows(): row 0 fully masked: " << (result_rows.mask().getElementAt({ 0, 0 }) ? "true" : "false") << std::endl; // std::cout << " ma::mask_cols(): column 1 fully masked: " << (result_cols.mask().getElementAt({ 1, 1 }) ? "true" : "false"); std::cout << " -> tests passed"; } void test_compress_rowcols() { std::cout << "========= ma::compress_rowcols(): remove masked rows/columns ==="; auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0} }); auto mask = numpy::array({ {false, false, false}, {false, true, false}, {false, false, false} }); auto ma = numpy::ma::masked_array(data, mask); .. _example-dataframe-name-119: .. dropdown:: name (np_test_1_all.cpp:24865) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 24855 :emphasize-lines: 11 uint64_t before_restore = rng.next_uint64(); rng.set_state(state); uint64_t after_restore = rng.next_uint64(); if (before_restore != after_restore) { std::cout << " [FAIL] : in np_test_bitgen_mt19937() : state restore failed"; throw std::runtime_error("np_test_bitgen_mt19937 failed: state"); } // Test name if (rng.name() != "MT19937") { std::cout << " [FAIL] : in np_test_bitgen_mt19937() : incorrect name"; throw std::runtime_error("np_test_bitgen_mt19937 failed: name"); } std::cout << " -> tests passed" << std::endl; } // ============================================================================ // PCG64 TESTS // ============================================================================ .. _example-dataframe-names-120: .. dropdown:: names (np_test_2_all.cpp:18817) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18807 :emphasize-lines: 11 create_txt_file("test_auto_names.txt"); // Don't provide names - should generate f0, f1, f2, f3 auto data = numpy::io::recfromtxt(csv_test_dir + "test_auto_names.txt"); auto dtype = data.getDType(); // Verify auto-generated names if (!dtype.hasField("f0") || !dtype.hasField("f1") || !dtype.hasField("f2") || !dtype.hasField("f3")) { std::cout << " [FAIL] : Missing auto-generated field names (f0, f1, f2, f3)"; throw std::runtime_error("np_test_io_extensions_recfromtxt_auto_names failed: missing auto names"); } std::cout << " -> tests passed" << std::endl; } // ============================================================================ // ERROR HANDLING TESTS // ============================================================================ .. _example-dataframe-nbytes-121: .. 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-dataframe-ndim-122: .. 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-dataframe-objects-123: .. dropdown:: objects (np_test_1_all.cpp:2136) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2126 :emphasize-lines: 11 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(copy_ptr != large_ptr)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(copy_ptr->data.size() == 10000)) { std::string description = std::string("unknown_function():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(copy_ptr->data.size() == 10000)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test 7: Object containing other objects (if supported) object_ inner_obj(std::string("inner")); struct ObjectContainer { object_ contained; ObjectContainer(object_ obj) : contained(obj) {} }; ObjectContainer container(inner_obj); object_ container_obj(container); if (!(container_obj.is_type())) { .. _example-dataframe-of-124: .. dropdown:: of (np_test_1_all.cpp:20581) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 20571 :emphasize-lines: 11 SchurValidator> validator; SchurBenchmark benchmark("Hermitian matrices"); bool all_passed = true; // Create Hermitian matrix NDArray> matrix({ 3, 3 }); matrix.setElementAt({ 0, 0 }, std::complex(2, 0)); matrix.setElementAt({ 0, 1 }, std::complex(1, 1)); matrix.setElementAt({ 0, 2 }, std::complex(0, -1)); matrix.setElementAt({ 1, 0 }, std::complex(1, -1)); // Conjugate of (0,1) matrix.setElementAt({ 1, 1 }, std::complex(3, 0)); matrix.setElementAt({ 1, 2 }, std::complex(1, 0)); matrix.setElementAt({ 2, 0 }, std::complex(0, 1)); // Conjugate of (0,2) matrix.setElementAt({ 2, 1 }, std::complex(1, 0)); matrix.setElementAt({ 2, 2 }, std::complex(4, 0)); // std::cout << " Testing 3x3 Hermitian matrix..." << std::endl; benchmark.time_operation([&]() { auto schur_result = schur_decomposition(matrix); .. _example-dataframe-pad-125: .. dropdown:: pad (np_test_1_all.cpp:18733) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18723 :emphasize-lines: 11 std::cout << "========= testPadding ======================="; // Create test array auto array = createInt32Array({ 2, 2 }, 0); array.setElementAt({ 0, 0 }, 1); array.setElementAt({ 0, 1 }, 2); array.setElementAt({ 1, 0 }, 3); array.setElementAt({ 1, 1 }, 4); // Test constant padding auto padded_const = pad(array, 1, "constant", 0); if (!(padded_const.getShape()[0] == 4)) { std::string description = std::string("testPadding():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(padded_const.getShape()[0] == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(padded_const.getShape()[1] == 4)) { std::string description = std::string("testPadding():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(padded_const.getShape()[1] == 4)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-dataframe-pairs-126: .. dropdown:: pairs (np_test_2_all.cpp:8793) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8783 :emphasize-lines: 11 if (result != expected) { std::cout << " IPP integer msort: -> [FAIL]"; throw std::runtime_error("IPP integer msort: FAILED - incorrect sorted order"); } // std::cout << "[OK] IPP integer msort: PASSED" << std::endl; } // Test 2: Float msort with stability test { // Test stability using pairs (value, original_index) struct TestPair { double value; int original_index; bool operator==(const TestPair& other) const { return value == other.value && original_index == other.original_index; } bool operator<(const TestPair& other) const { return value < other.value; } }; .. _example-dataframe-pow-127: .. dropdown:: pow (np_test_1_all.cpp:15230) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15220 :emphasize-lines: 11 std::cout << "[FAIL] Broadcasting validation failed" << std::endl; errors++; } // Test 11: Performance with caching std::cout << "========= test_caching_performance =======================" ; int call_count = 0; auto expensive_func = [&call_count](double x) { call_count++; return std::pow(x, 3) + std::sin(x); // Simulate expensive computation }; auto cached_vectorized = numpy::vectorize(expensive_func, true, 100); numpy::NDArray test_array({ 3 }); test_array.setElementAt({ 0 }, 1.0); test_array.setElementAt({ 1 }, 2.0); test_array.setElementAt({ 2 }, 3.0); // First call .. _example-dataframe-pow-128: .. dropdown:: pow (np_test_1_all.cpp:15230) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15220 :emphasize-lines: 11 std::cout << "[FAIL] Broadcasting validation failed" << std::endl; errors++; } // Test 11: Performance with caching std::cout << "========= test_caching_performance =======================" ; int call_count = 0; auto expensive_func = [&call_count](double x) { call_count++; return std::pow(x, 3) + std::sin(x); // Simulate expensive computation }; auto cached_vectorized = numpy::vectorize(expensive_func, true, 100); numpy::NDArray test_array({ 3 }); test_array.setElementAt({ 0 }, 1.0); test_array.setElementAt({ 1 }, 2.0); test_array.setElementAt({ 2 }, 3.0); // First call .. _example-dataframe-prefix-129: .. dropdown:: prefix (np_test_1_all.cpp:9465) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9455 :emphasize-lines: 11 vstring_ short_str("A"); vstring_ long_str("AAAAA"); if (!(short_str < long_str)) { std::string description = std::string("testStringOperationEdgeCasesVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(short_str < long_str)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test with strings that are prefixes vstring_ prefix("Test"); vstring_ prefix_extended("Testing"); if (!(prefix < prefix_extended)) { std::string description = std::string("testStringOperationEdgeCasesVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(prefix < prefix_extended)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!(prefix > prefix_extended))) { std::string description = std::string("testStringOperationEdgeCasesVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!(prefix > prefix_extended))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-dataframe-prod-130: .. 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-dataframe-product-131: .. 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-dataframe-replace-132: .. 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-dataframe-representation-133: .. dropdown:: representation (np_test_2_all.cpp:13663) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13653 :emphasize-lines: 11 // no using namespace in tests - to avoid name clashes // use a separate namespace for each test group namespace numpy_tests_bitwise_repr { // ============================================================================ // BASE_REPR TESTS // ============================================================================ void np_test_base_repr_binary() { std::cout << "========= base_repr: binary representation (base=2) ======================="; // Test basic binary conversion std::string result1 = numpy::base_repr(5, 2); if (result1 != "101") { std::cout << " [FAIL] : base_repr(5, 2) returned \"" << result1 << "\", expected \"101\""; throw std::runtime_error("np_test_base_repr_binary failed"); } std::string result2 = numpy::base_repr(255, 2); if (result2 != "11111111") { .. _example-dataframe-representation-134: .. dropdown:: representation (np_test_2_all.cpp:13663) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13653 :emphasize-lines: 11 // no using namespace in tests - to avoid name clashes // use a separate namespace for each test group namespace numpy_tests_bitwise_repr { // ============================================================================ // BASE_REPR TESTS // ============================================================================ void np_test_base_repr_binary() { std::cout << "========= base_repr: binary representation (base=2) ======================="; // Test basic binary conversion std::string result1 = numpy::base_repr(5, 2); if (result1 != "101") { std::cout << " [FAIL] : base_repr(5, 2) returned \"" << result1 << "\", expected \"101\""; throw std::runtime_error("np_test_base_repr_binary failed"); } std::string result2 = numpy::base_repr(255, 2); if (result2 != "11111111") { .. _example-dataframe-result-135: .. dropdown:: result (np_test_1_all.cpp:6090) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6080 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "Timer restart test passed. Second: " << second_elapsed << " ms" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_benchmark_result_storageBenchmarkSorting() { std::cout << "========= test_benchmark_result_storage ======================="; BenchmarkResult result("TestAlgorithm", 1000, 15.5, true, 4096); if (!(result.algorithm_name == "TestAlgorithm")) { std::string description = std::string("test_benchmark_result_storageBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.algorithm_name == \"TestAlgorithm\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.array_size == 1000)) { std::string description = std::string("test_benchmark_result_storageBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.array_size == 1000)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-dataframe-sequences-136: .. dropdown:: sequences (np_test_1_all.cpp:9081) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 9071 :emphasize-lines: 11 NDArray str_array = createVariableStringArrayFromInitializerList({ "First", "Second", "Third" }); // std::cout << "Variable string array created successfully" << std::endl; std::cout << " -> tests passed" << std::endl; } void testUTF8EdgeCasesVariableStrings() { std::cout << "========= testUTF8EdgeCasesVariableStrings ======================="; // Test 1: Invalid UTF-8 sequences (should be handled gracefully) std::string invalid_utf8_orphaned = "\x80\x81\x82"; // Orphaned continuation bytes vunicode_ orphaned_test(invalid_utf8_orphaned); // Should not crash and produce some result if (!(!orphaned_test.to_utf8().empty() || orphaned_test.empty())) { std::string description = std::string("testUTF8EdgeCasesVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!orphaned_test.to_utf8().empty() || orphaned_test.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } std::string invalid_utf8_start = "\xF8\xF9\xFF"; // Invalid start bytes .. _example-dataframe-shape-137: .. dropdown:: shape (np_test_1_all.cpp:3751) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3741 :emphasize-lines: 11 } 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); } } // Check values if (!(broadcasted[0].getElementAt({0, 1}) == 2.0)) { .. _example-dataframe-shift-138: .. dropdown:: shift (np_test_1_all.cpp:2761) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2751 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(left_array.getElementAt({3}) == 16384)) { std::string description = std::string("testBitShifts():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(left_array.getElementAt({3}) == 16384)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Left shift by array\n"; // Test excessive shift (should result in 0) auto excessive_left = left_shift(arr, 20); // More than 16 bits if (!(excessive_left.getElementAt({0}) == 0)) { std::string description = std::string("testBitShifts():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(excessive_left.getElementAt({0}) == 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(excessive_left.getElementAt({1}) == 0)) { std::string description = std::string("testBitShifts():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(excessive_left.getElementAt({1}) == 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-dataframe-size-139: .. 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-dataframe-skew-140: .. 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-dataframe-ss-141: .. dropdown:: ss (np_test_1_all.cpp:25034) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 25024 :emphasize-lines: 11 } // ============================================================================ // SEEDSEQUENCE TESTS // ============================================================================ void np_test_bitgen_seedsequence() { std::cout << "========= SeedSequence ======================="; // Test construction numpy::random::SeedSequence ss(42); // Test state generation auto state = ss.generate_state(10); if (state.size() != 10) { std::cout << " [FAIL] : in np_test_bitgen_seedsequence() : generate_state size"; throw std::runtime_error("np_test_bitgen_seedsequence failed"); } // Test spawning auto children = ss.spawn(5); .. _example-dataframe-str-142: .. dropdown:: str (np_test_1_all.cpp:13279) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13269 :emphasize-lines: 11 throw std::runtime_error(description); } // std::cout << "[OK] Vectorized str_len works correctly\n"; std::cout << " -> tests passed" << std::endl; } void test_numpy_compatibility_examples() { std::cout << "========= test_numpy_compatibility_examples ======================="; // Example: numpy string slicing behavior vstring_ str("hello world"); // length = 11 // These should behave like NumPy string slicing if (!(str.slice(5, 20).to_string() == " world")) { std::string description = std::string("test_numpy_compatibility_examples():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str.slice(5, 20).to_string() == \" world\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(str.slice(-20, 5).to_string() == "hello")) { std::string description = std::string("test_numpy_compatibility_examples():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str.slice(-20, 5).to_string() == \"hello\")"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-dataframe-string-143: .. dropdown:: string (np_test_1_all.cpp:454) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 444 :emphasize-lines: 11 // Modify through different views view1.setElementAt({0, 0}, 100); view2.setElementAt({2, 1}, 200); // This is (1, 2) in original view3.setElementAt({0, 0}, 300); // This is (1, 1) in original // std::cout << "After modifications through multiple views:" << std::endl; //original.printArray(); // Verify all changes are reflected if (!(original.getElementAt({0, 0}) == 100)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({0, 0}) == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(original.getElementAt({1, 2}) == 200)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 2}) == 200)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(original.getElementAt({1, 1}) == 300)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 300)"; .. _example-dataframe-tz_convert-144: .. dropdown:: tz_convert (np_test_5_all.cpp:22899) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22889 :emphasize-lines: 11 if (floored_h.hour() != 14 || floored_h.minute() != 0 || floored_h.second() != 0) { pass = false; fail_msg = "floor to hour failed"; } // ceil to hour numpy::Timestamp ceiled_h = ts.ceil("h"); if (ceiled_h.hour() != 15 || ceiled_h.minute() != 0) { pass = false; fail_msg = "ceil to hour failed"; } // round to hour (37 minutes -> round up) numpy::Timestamp rounded_h = ts.round("h"); if (rounded_h.hour() != 15) { pass = false; fail_msg = "round to hour should be 15 (37 > 30)"; } // normalize (floor to day) numpy::Timestamp normalized = ts.normalize(); .. _example-dataframe-tz_convert-145: .. dropdown:: tz_convert (np_test_5_all.cpp:22899) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22889 :emphasize-lines: 11 if (floored_h.hour() != 14 || floored_h.minute() != 0 || floored_h.second() != 0) { pass = false; fail_msg = "floor to hour failed"; } // ceil to hour numpy::Timestamp ceiled_h = ts.ceil("h"); if (ceiled_h.hour() != 15 || ceiled_h.minute() != 0) { pass = false; fail_msg = "ceil to hour failed"; } // round to hour (37 minutes -> round up) numpy::Timestamp rounded_h = ts.round("h"); if (rounded_h.hour() != 15) { pass = false; fail_msg = "round to hour should be 15 (37 > 30)"; } // normalize (floor to day) numpy::Timestamp normalized = ts.normalize(); .. _example-dataframe-tz_localize-146: .. dropdown:: tz_localize (np_test_5_all.cpp:22892) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22882 :emphasize-lines: 11 auto pass = true; std::string fail_msg; numpy::Timestamp ts(2024, 6, 15, 14, 37, 45, 123456); // floor to hour numpy::Timestamp floored_h = ts.floor("h"); if (floored_h.hour() != 14 || floored_h.minute() != 0 || floored_h.second() != 0) { pass = false; fail_msg = "floor to hour failed"; } // ceil to hour numpy::Timestamp ceiled_h = ts.ceil("h"); if (ceiled_h.hour() != 15 || ceiled_h.minute() != 0) { pass = false; fail_msg = "ceil to hour failed"; } // round to hour (37 minutes -> round up) numpy::Timestamp rounded_h = ts.round("h"); .. _example-dataframe-tz_localize-147: .. dropdown:: tz_localize (np_test_5_all.cpp:22892) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22882 :emphasize-lines: 11 auto pass = true; std::string fail_msg; numpy::Timestamp ts(2024, 6, 15, 14, 37, 45, 123456); // floor to hour numpy::Timestamp floored_h = ts.floor("h"); if (floored_h.hour() != 14 || floored_h.minute() != 0 || floored_h.second() != 0) { pass = false; fail_msg = "floor to hour failed"; } // ceil to hour numpy::Timestamp ceiled_h = ts.ceil("h"); if (ceiled_h.hour() != 15 || ceiled_h.minute() != 0) { pass = false; fail_msg = "ceil to hour failed"; } // round to hour (37 minutes -> round up) numpy::Timestamp rounded_h = ts.round("h"); .. _example-dataframe-unused-148: .. dropdown:: unused (np_test_3_all.cpp:18289) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18279 :emphasize-lines: 11 int n = 3; int kl = 1; int ku = 1; int ldab = 2 * kl + ku + 1; // = 4 for gbtrf numpy::NDArray AB({ static_cast(ldab), static_cast(n) }); // Fill band matrix in LAPACK band storage format // Row ku = 1 contains the superdiagonal // Row kl+ku = 2 contains the diagonal // Row kl+ku+1 = 3 contains the subdiagonal AB.setElementAt({ 0, 0 }, 0.0); // unused (extra space for pivoting) AB.setElementAt({ 0, 1 }, 0.0); AB.setElementAt({ 0, 2 }, 1.0); // A[0,2] doesn't exist, just filling AB.setElementAt({ 1, 0 }, 0.0); // unused AB.setElementAt({ 1, 1 }, 1.0); // superdiagonal A[0,1] AB.setElementAt({ 1, 2 }, 1.0); // superdiagonal A[1,2] AB.setElementAt({ 2, 0 }, 4.0); // diagonal A[0,0] AB.setElementAt({ 2, 1 }, 4.0); // diagonal A[1,1] AB.setElementAt({ 2, 2 }, 4.0); // diagonal A[2,2] .. _example-dataframe-v-149: .. dropdown:: v (np_test_3_all.cpp:5664) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 5654 :emphasize-lines: 11 // std::cout << "Computed eigenvalues:" << std::endl; //eig_result.eigenvalues.printArray(); // std::cout << "Eigenvectors:" << std::endl; //eig_result.eigenvectors.printArray(); // Verify A*v = lambda*v for each eigenvector double max_residual = 0.0; for (size_t k = 0; k < 3; ++k) { // Extract k-th eigenvector NDArray v({ 3, 1 }); for (size_t i = 0; i < 3; ++i) { v.setElementAt({ i, 0 }, eig_result.eigenvectors.getElementAt({ i, k })); } complex128 lambda = eig_result.eigenvalues.getElementAt({ k }); // Compute A*v auto Av = matmul(matrix, v); // Compute lambda*v .. _example-dataframe-value-150: .. dropdown:: value (np_test_1_all.cpp:7786) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7776 :emphasize-lines: 11 } void testFloat16PrecisionFloat16() { std::cout << "========= testFloat16PrecisionFloat16 ======================="; // Test precision limits float16 small_val(0.0001f); float16 large_val(30000.0f); float16 very_small(1e-8f); // This might underflow to zero // std::cout << "Small value (0.0001): " << small_val << std::endl; // std::cout << "Large value (30000): " << large_val << std::endl; // std::cout << "Very small value (1e-8): " << very_small << std::endl; // Test conversion accuracy float original = 1.234f; float16 converted(original); float back_converted = static_cast(converted); // std::cout << "Original float: " << std::setprecision(10) << original << std::endl; // std::cout << "Float16 version: " << converted << std::endl; .. _example-dataframe-values-151: .. dropdown:: values (np_test_1_all.cpp:15133) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15123 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } else { std::cout << "[FAIL] Where function failed" << std::endl; errors++; } // Test 8: Clip function std::cout << "========= test_clip_function =======================" ; 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); .. _example-dataframe-values-152: .. dropdown:: values (np_test_1_all.cpp:15133) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15123 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } else { std::cout << "[FAIL] Where function failed" << std::endl; errors++; } // Test 8: Clip function std::cout << "========= test_clip_function =======================" ; 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); .. _example-dataframe-write-153: .. dropdown:: write (np_test_1_all.cpp:27015) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 27005 :emphasize-lines: 11 } void test_get_remaining_size() { std::cout << "========= get_remaining_size: calculate remaining file bytes ======================="; // Create temporary test file const char* test_filename = "temp_test_file_phase5.bin"; { std::ofstream out(test_filename, std::ios::binary); const char data[100] = {}; out.write(data, 100); } // Test with filename size_t size1 = io::get_remaining_size(test_filename); if (size1 != 100) { std::cout << " [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1; throw std::runtime_error("test_get_remaining_size failed: incorrect file size"); } // Test with file stream