Series#

class numpy::Series#

numpy C++ class.

Example#

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

// Use Series
Series obj;
// ... operations ...

Constructors#

Signature

Location

Example

explicit Series(const numpy::NDArray<T>& data, const std::optional<std::string>& name = std::nullopt)

df_series.h:145

Series(const std::vector<T>& data, const std::optional<std::string>& name = std::nullopt)

df_series.h:165

Series(const numpy::NDArray<T>& data, const Index<IndexT>& idx, const std::optional<std::string>& name = std::nullopt)

df_series.h:197

Series(const numpy::NDArray<T>& data, const RangeIndex& idx, const std::optional<std::string>& name = std::nullopt)

df_series.h:216

Series(const std::vector<T>& data, const Index<IndexT>& idx, const std::optional<std::string>& name = std::nullopt)

df_series.h:233

Series(const Series& other)

df_series.h:252

Series(Series&& other) noexcept

df_series.h:266

Construction#

Signature

Return Type

Location

Example

std::unique_ptr<IndexBase> make_default_index(size_t sz) const

std::unique_ptr<IndexBase>

df_series.h:5658

Array Creation#

Signature

Return Type

Location

Example

bool empty() const override

bool

df_series.h:339

View

Indexing / Selection#

Signature

Return Type

Location

Example

T at(size_t idx) const

T

df_series.h:503

View

Series<T> at_time( const std::string& time, bool asof = false ) const

Series<T>

df_series.h:5541

T get(const std::string& key, const std::optional<T>& default_value = std::nullopt) const

T

df_series.h:4693

View

bool get_value_bool(size_t idx) const override

bool

df_series.h:885

std::string get_value_str(size_t idx) const override

std::string

df_series.h:3561

T item() const

T

df_series.h:4821

View

std::vector<std::pair<std::string, T>> items() const

std::vector<std::pair<std::string, T>>

df_series.h:4835

void items(Func&& func) const

void

df_series.h:4849

size_t searchsorted(const T& value, const std::string& side = "left") const

size_t

df_series.h:5315

View

Series<T> take(const std::vector<size_t>& indices) const

Series<T>

df_series.h:670

View

Series<T> where(const numpy::NDArray<numpy::bool\_>& cond, const T& other) const

Series<T>

df_series.h:614

View

Shape Manipulation#

Signature

Return Type

Location

Example

Series<T> T\_() const

Series<T>

df_series.h:5390

numpy::NDArray<T> ravel() const

numpy::NDArray<T>

df_series.h:5119

View

Series<T> squeeze() const

Series<T>

df_series.h:5338

View

Series<T> swapaxes(int /\*axis1\*/, int /\*axis2\*/) const

Series<T>

df_series.h:5369

View

Series<T> transpose() const

Series<T>

df_series.h:5383

View

Statistics#

Signature

Return Type

Location

Example

std::optional<double> cov( const Series<T>& other, std::optional<size_t> min_periods = std::nullopt, int ddof = 1) const

std::optional<double>

df_series.h:4197

View

std::optional<T> max(bool skipna = true) const

std::optional<T>

df_series.h:1111

View

std::optional<double> mean(bool skipna = true) const

std::optional<double>

df_series.h:1011

View

std::optional<T> median(bool skipna = true) const

std::optional<T>

df_series.h:1178

View

std::optional<T> min(bool skipna = true) const

std::optional<T>

df_series.h:1075

View

std::optional<double> quantile(double q, const std::string& interpolation = "linear") const

std::optional<double>

df_series.h:1371

View

std::optional<double> std(bool skipna = true, int ddof = 1) const

std::optional<double>

df_series.h:5345

View

std::optional<double> std\_(bool skipna = true, int ddof = 1) const

std::optional<double>

df_series.h:1031

std::optional<T> sum(bool skipna = true) const

std::optional<T>

df_series.h:973

View

std::optional<double> var(bool skipna = true, int ddof = 1) const

std::optional<double>

df_series.h:1040

View

Sorting#

Signature

Return Type

Location

Example

numpy::NDArray<numpy::int64> argsort(bool ascending = true) const

numpy::NDArray<numpy::int64>

df_series.h:2180

View

Series<T> sort_index(bool ascending = true) const

Series<T>

df_series.h:2220

Series<T> sort_values(bool ascending = true, bool /\*na_position_last\*/ = true) const

Series<T>

df_series.h:2205

Math Operations#

Signature

Return Type

Location

Example

Series<T> abs() const

Series<T>

df_series.h:2039

View

Series<T> add(const Series<T>& other, T fill_value = T

Series<T>

df_series.h:1637

View

Series<T> add(T scalar) const

Series<T>

df_series.h:1657

View

Series<T> add_prefix(const std::string& prefix, int axis = 0) const

Series<T>

df_series.h:3508

Series<T> add_suffix(const std::string& suffix, int axis = 0) const

Series<T>

df_series.h:3537

Series<numpy::float64> ceil() const

Series<numpy::float64>

df_series.h:1886

View

Series<numpy::float64> divide(const Series<T>& other, T fill_value = T

Series<numpy::float64>

df_series.h:1754

View

Expanding<T> expanding(size_t min_periods = 1) const

Expanding<T>

df_series.h:2719

Series<T> explode(bool ignore_index = false) const

Series<T>

df_series.h:3457

Series<numpy::float64> floor() const

Series<numpy::float64>

df_series.h:1875

View

Series<T> floordiv(const Series<T>& other) const

Series<T>

df_series.h:1769

Series<T> floordiv(T scalar) const

Series<T>

df_series.h:1786

Series<T> mod(const Series<T>& other) const

Series<T>

df_series.h:1802

View

Series<T> mod(T scalar) const

Series<T>

df_series.h:1819

View

Series<T> mode(bool dropna = true) const

Series<T>

df_series.h:1314

View

Series<T> multiply(const Series<T>& other, T fill_value = T

Series<T>

df_series.h:1719

View

Series<numpy::float64> round(int decimals = 0) const

Series<numpy::float64>

df_series.h:1862

View

Series<T> subtract(const Series<T>& other, T fill_value = T

Series<T>

df_series.h:1688

View

Series<T> truncate(const std::optional<std::string>& before = std::nullopt, const std::optional<std::string>& after = std::nullopt) const

Series<T>

df_series.h:2839

View

Linear Algebra#

Signature

Return Type

Location

Example

T dot(const Series<T>& other) const

T

df_series.h:4295

View

T dot(const numpy::NDArray<T>& other) const

T

df_series.h:4307

View

void invalidate_caches() const

void

df_series.h:5639

Random#

Signature

Return Type

Location

Example

Series<T> sample( size_t n = 1, std::optional<unsigned int> random_state = std::nullopt, bool replace = false) const

Series<T>

df_series.h:5275

View

Comparison#

Signature

Return Type

Location

Example

bool equals(const Series<T>& other) const

bool

df_series.h:4440

Set Operations#

Signature

Return Type

Location

Example

Series<T> unique() const

Series<T>

df_series.h:2384

View

I/O#

Signature

Return Type

Location

Example

void to_clipboard(bool excel = true, const std::string& sep = "\\t") const

void

df_series.h:3188

std::string to_csv(bool include_index = true, char sep = ',') const

std::string

df_series.h:2930

std::map<std::string, T> to_dict() const

std::map<std::string, T>

df_series.h:2995

void to_excel( const std::string& excel_writer, const std::string& sheet_name = "Sheet1", const std::string& na_rep = "", const std::string& float_format = "", bool header = true, bool index = true, const std::string& index_label = "", size_t startrow = 0, size_t startcol = 0, bool merge_cells = true, const std::string& inf_rep = "inf", std::optional<std::pair<size_t, size_t>> freeze_panes = std::nullopt) const

void

df_series.h:3324

std::vector<uint8_t> to_feather( const std::string& path = "", const std::string& compression = "uncompressed", int compression_level = -1, int64_t chunksize = -1, int version = 2) const

std::vector<uint8_t>

df_series.h:3417

DataFrame to_frame(const std::optional<std::string>& name = std::nullopt) const

DataFrame

df_series.h:3014

std::vector<uint8_t> to_hdf( const std::string& path_or_buf = "", const std::string& key = "data", const std::string& mode = "a", std::optional<int> complevel = std::nullopt, const std::string& complib = "zlib", bool append = false, const std::string& format = "fixed", bool index = true) const

std::vector<uint8_t>

df_series.h:3253

std::string to_json(const std::string& orient = "index") const

std::string

df_series.h:2957

std::string to_latex(bool header = true, bool index = true) const

std::string

df_series.h:3024

void to_latex(const std::string& path, bool header = true, bool index = true) const

void

df_series.h:3064

file << to_latex(header, index)

file <<

df_series.h:3069

std::vector<T> to_list() const

std::vector<T>

df_series.h:2912

std::string to_markdown(bool index = true) const

std::string

df_series.h:3080

void to_markdown(const std::string& path, bool index = true) const

void

df_series.h:3118

file << to_markdown(index)

file <<

df_series.h:3123

numpy::NDArray<T> to_numpy() const

numpy::NDArray<T>

df_series.h:2905

View

std::vector<uint8_t> to_orc( const std::string& path = "", const std::string& engine = "pyarrow", std::optional<bool> index = std::nullopt) const

std::vector<uint8_t>

df_series.h:3442

std::vector<uint8_t> to_parquet( const std::string& path = "", const std::string& engine = "pyarrow", const std::string& compression = "snappy", std::optional<bool> index = std::nullopt) const

std::vector<uint8_t>

df_series.h:3357

void to_pickle(const std::string& path) const

void

df_series.h:3143

std::optional<int64_t> 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<size_t> chunksize = std::nullopt, const std::map<std::string, std::string>& dtype =

std::optional<int64_t>

df_series.h:3287

std::vector<uint8_t> to_stata( const std::string& path = "", const std::map<std::string, std::string>& convert_dates =

std::vector<uint8_t>

df_series.h:3386

std::string to_string() const override

std::string

df_series.h:3586

View

std::vector<std::string> to_string_vector() const override

std::vector<std::string>

df_series.h:3573

std::vector<T> tolist() const

std::vector<T>

df_series.h:5376

View

Joining / Splitting#

Signature

Return Type

Location

Example

Series<T> repeat(size_t repeats) const

Series<T>

df_series.h:5212

View

Type Handling#

Signature

Return Type

Location

Example

Series<U> astype() const

Series<U>

df_series.h:2894

View

Series<T> copy(bool deep = true) const

Series<T>

df_series.h:2875

View

void copy_value_from(size_t src_idx, size_t dst_idx) override

void

df_series.h:950

Series<T> view() const

Series<T>

df_series.h:5417

View

Special Functions#

Signature

Return Type

Location

Example

Series<T> combine(const Series<T>& other, Func&& func) const

Series<T>

df_series.h:4012

View

Series<T> combine_first(const Series<T>& other) const

Series<T>

df_series.h:4030

Type Checking#

Signature

Return Type

Location

Example

bool is_na_at(size_t idx) const override

bool

df_series.h:819

Other Methods#

Signature

Return Type

Location

Example

GlobalUnlock(hMem)

df_series.h:3215

SetClipboardData(CF_TEXT, hMem)

df_series.h:3218

auto agg(Func&& func) const -> decltype(func(std::declval<std::vector<T>>()))

auto

df_series.h:2618

std::optional<double> agg(const std::string& func) const

std::optional<double>

df_series.h:2631

DataFrame agg(const std::vector<std::string>& funcs) const

DataFrame

df_series.h:2658

auto aggregate(Func&& func) const -> decltype(agg(std::forward<Func>(func)))

auto

df_series.h:2664

std::optional<double> aggregate(const std::string& func) const

std::optional<double>

df_series.h:2671

DataFrame aggregate(const std::vector<std::string>& funcs) const

DataFrame

df_series.h:2682

std::pair<Series<T>, Series<T>> align( const Series<T>& other, const std::string& join = "outer", const std::optional<T>& fill_value = std::nullopt) const

std::pair<Series<T>, Series<T>>

df_series.h:3696

auto apply(Func&& func) const -> Series<decltype(func(std::declval<T>()))>

auto

df_series.h:2544

Series<double> apply(const std::string& func) const

Series<double>

df_series.h:2562

size_t argmax() const

size_t

df_series.h:1487

View

size_t argmin() const

size_t

df_series.h:1456

View

Series<T> asfreq(const std::string& freq, const std::string& method = "") const

Series<T>

df_series.h:2787

std::optional<T> asof(const std::string& where) const

std::optional<T>

df_series.h:3775

T asof(size_t where) const

T

df_series.h:5472

Series<T> asof(const std::vector<size_t>& where) const

Series<T>

df_series.h:5519

std::optional<double> autocorr(int lag = 1) const

std::optional<double>

df_series.h:3808

std::vector<const IndexBase\*> axes() const override

std::vector<const IndexBase*>

df_series.h:485

View

Series<T> backfill(std::optional<size_t> limit = std::nullopt) const

Series<T>

df_series.h:3900

Series<numpy::bool\_> between(const T& left, const T& right, const std::string& inclusive = "both") const

Series<numpy::bool_>

df_series.h:2006

View

Series<T> between_time( const std::string& start_time, const std::string& end_time, const std::string& inclusive = "both" ) const

Series<T>

df_series.h:5565

Series<T> bfill(std::optional<size_t> limit = std::nullopt) const

Series<T>

df_series.h:3854

bool bool\_() const

bool

df_series.h:3953

View

size_t cache_memory_usage() const override

size_t

df_series.h:3675

Series<T> case_when( const std::vector<std::pair<numpy::NDArray<numpy::bool\_>, T>>& caselist, const std::optional<T>& default_value = std::nullopt) const

Series<T>

df_series.h:3976

void clear_cache() const override

void

df_series.h:3660

Series<T> clip(const T& lower, const T& upper) const

Series<T>

df_series.h:2057

View

std::unique_ptr<NDFrameBase> clone() const override

std::unique_ptr<NDFrameBase>

df_series.h:3652

View

numpy::NDArray<numpy::int64> codes_arr(

numpy::NDArray<numpy::int64>

df_series.h:4528

DataFrame compare( const Series<T>& other, int align_axis = 1, bool keep_shape = false, bool keep_equal = false ) const

DataFrame

df_series.h:4108

std::optional<double> corr( const Series<T>& other, const std::string& method = "pearson", std::optional<size_t> min_periods = std::nullopt) const

std::optional<double>

df_series.h:4122

size_t count() const override

size_t

df_series.h:702

View

Series<T> cummax(bool /\*skipna\*/ = true) const

Series<T>

df_series.h:2120

Series<T> cummin(bool /\*skipna\*/ = true) const

Series<T>

df_series.h:2101

Series<T> cumprod(bool /\*skipna\*/ = true) const

Series<T>

df_series.h:2086

View

Series<T> cumsum(bool /\*skipna\*/ = true) const

Series<T>

df_series.h:2071

View

DataFrame describe( const std::vector<double>& percentiles =

DataFrame

df_series.h:1416

View

Series<double> diff(int periods = 1) const

Series<double>

df_series.h:2139

View

Series<numpy::float64> div(const Series<T>& other, T fill_value = T

Series<numpy::float64>

df_series.h:1726

Series<numpy::float64> div(T scalar) const

Series<numpy::float64>

df_series.h:1746

std::pair<Series<T>, Series<T>> divmod(const T& other) const

std::pair<Series<T>, Series<T>>

df_series.h:4251

View

std::pair<Series<T>, Series<T>> divmod(const Series<T>& other) const

std::pair<Series<T>, Series<T>>

df_series.h:4268

View

Series<T> drop(const std::vector<std::string>& labels) const

Series<T>

df_series.h:4324

Series<T> drop_duplicates(const std::string& keep = "first") const

Series<T>

df_series.h:2466

Series<T> droplevel(int level) const

Series<T>

df_series.h:4350

Series<T> dropna() const

Series<T>

df_series.h:796

std::string dtype_name() const override

std::string

df_series.h:371

View

numpy::NDArray<numpy::bool\_> duplicated(const std::string& keep = "first") const

numpy::NDArray<numpy::bool_>

df_series.h:2427

Series<numpy::bool\_> eq(const Series<T>& other) const

Series<numpy::bool_>

df_series.h:4364

Series<numpy::bool\_> eq(const T& scalar) const

Series<numpy::bool_>

df_series.h:4368

EWM<T> ewm(double span, bool adjust = true, bool ignore_na = false) const

EWM<T>

df_series.h:2732

std::pair<numpy::NDArray<numpy::int64>, Series<T>> factorize(bool sort = false) const

std::pair<numpy::NDArray<numpy::int64>, Series<T>>

df_series.h:4471

Series<T> ffill(std::optional<size_t> limit = std::nullopt) const

Series<T>

df_series.h:3909

std::ofstream file(path)

std::ofstream

df_series.h:3065

View

std::ofstream file(path)

std::ofstream

df_series.h:3119

View

std::ofstream file(path, std::ios::binary)

std::ofstream

df_series.h:3144

View

Series<T> fillna(const T& value) const

Series<T>

df_series.h:770

void fillna_double(double value) override

void

df_series.h:836

Series<T> filter( const std::optional<std::vector<std::string>>& items = std::nullopt, const std::optional<std::string>& like = std::nullopt, const std::optional<std::string>& regex = std::nullopt) const

Series<T>

df_series.h:4622

View

Series<T> first(const std::string& offset) const

Series<T>

df_series.h:4664

View

std::optional<size_t> first_valid_index() const

std::optional<size_t>

df_series.h:2797

func(index\_->get_value_str(i), data\_.getElementAt(

df_series.h:4851

Series<numpy::bool\_> ge(const Series<T>& other) const

Series<numpy::bool_>

df_series.h:4423

Series<numpy::bool\_> ge(const T& scalar) const

Series<numpy::bool_>

df_series.h:4427

SeriesGroupBy<T, GroupT> groupby(const Series<GroupT>& by, bool sort = true) const

SeriesGroupBy<T, GroupT>

df_series.h:2760

\* Series<std::string> groups(

* Series<std::string>

df_series.h:2752

View

Series<numpy::bool\_> gt(const Series<T>& other) const

Series<numpy::bool_>

df_series.h:4412

Series<numpy::bool\_> gt(const T& scalar) const

Series<numpy::bool_>

df_series.h:4416

bool has_cached_values() const override

bool

df_series.h:3664

bool has_multiindex() const

bool

df_series.h:467

bool hasnans() const override

bool

df_series.h:681

Series<T> head(size_t n = 5) const

Series<T>

df_series.h:654

T iat(size_t idx) const

T

df_series.h:515

std::string idxmax() const

std::string

df_series.h:1525

std::string idxmin() const

std::string

df_series.h:1518

Series<T> iloc(size_t start, size_t stop, size_t step = 1) const

Series<T>

df_series.h:525

Series<T> iloc(const std::vector<size_t>& indices) const

Series<T>

df_series.h:542

const IndexBase& index() const override

const IndexBase&

df_series.h:403

View

IndexBase& index_mut()

IndexBase&

df_series.h:410

void info(std::ostream\* buf = nullptr) const

void

df_series.h:4711

View

Series<T> interpolate( const std::string& method = "linear", std::optional<size_t> limit = std::nullopt) const

Series<T>

df_series.h:4728

numpy::NDArray<numpy::bool\_> isna() const

numpy::NDArray<numpy::bool_>

df_series.h:730

numpy::NDArray<numpy::bool\_> isnull() const

numpy::NDArray<numpy::bool_>

df_series.h:4806

std::vector<std::string> keys() const

std::vector<std::string>

df_series.h:4859

View

std::optional<double> kurt(bool skipna = true) const

std::optional<double>

df_series.h:1271

std::optional<double> kurtosis(bool skipna = true) const

std::optional<double>

df_series.h:1307

View

\* For Series, the row labels (index) are prefixed.

* For Series, the row

df_series.h:3499

\* For Series, the row labels (index) are suffixed.

* For Series, the row

df_series.h:3528

Series<T> last(const std::string& offset) const

Series<T>

df_series.h:4679

std::optional<size_t> last_valid_index() const

std::optional<size_t>

df_series.h:2817

Series<numpy::bool\_> le(const Series<T>& other) const

Series<numpy::bool_>

df_series.h:4397

Series<numpy::bool\_> le(const T& scalar) const

Series<numpy::bool_>

df_series.h:4401

T loc(const std::string& label) const

T

df_series.h:563

Series<T> loc(const std::vector<std::string>& labels) const

Series<T>

df_series.h:576

Series<numpy::bool\_> lt(const Series<T>& other) const

Series<numpy::bool_>

df_series.h:4386

Series<numpy::bool\_> lt(const T& scalar) const

Series<numpy::bool_>

df_series.h:4390

Series<U> map(const std::unordered_map<T, U>& mapping) const

Series<U>

df_series.h:2572

auto map(Func&& func) const -> Series<decltype(func(std::declval<T>()))>

auto

df_series.h:2593

Series<T> mask(const numpy::NDArray<numpy::bool\_>& cond, const T& other) const

Series<T>

df_series.h:632

View

memcpy(pMem, text.c_str(), text.size() + 1)

df_series.h:3214

View

size_t memory_usage(bool index = true, bool /\*deep\*/ = false) const

size_t

df_series.h:4873

Series<T> mul(const Series<T>& other, T fill_value = T

Series<T>

df_series.h:1695

Series<T> mul(T scalar) const

Series<T>

df_series.h:1715

const MultiIndex& multiindex() const

const MultiIndex&

df_series.h:474

std::optional<std::string> name() const override

std::optional<std::string>

df_series.h:378

View

size_t nbytes() const override

size_t

df_series.h:360

View

size_t ndim() const override

size_t

df_series.h:353

View

Series<numpy::bool\_> ne(const Series<T>& other) const

Series<numpy::bool_>

df_series.h:4375

Series<numpy::bool\_> ne(const T& scalar) const

Series<numpy::bool_>

df_series.h:4379

numpy::NDArray<numpy::bool\_> new_mask(

numpy::NDArray<numpy::bool_>

df_series.h:4582

Series<T> nlargest(size_t n = 5, const std::string& keep = "first") const

Series<T>

df_series.h:4890

numpy::NDArray<numpy::bool\_> notna() const

numpy::NDArray<numpy::bool_>

df_series.h:750

numpy::NDArray<numpy::bool\_> notnull() const

numpy::NDArray<numpy::bool_>

df_series.h:4813

Series<T> nsmallest(size_t n = 5, const std::string& keep = "first") const

Series<T>

df_series.h:4943

size_t nunique(bool dropna = true) const

size_t

df_series.h:2402

Series<T> pad(std::optional<size_t> limit = std::nullopt) const

Series<T>

df_series.h:3945

View

std::vector<std::pair<T, numpy::int64>> pairs(counts.begin(), counts.end())

std::vector<std::pair<T, numpy::int64>>

df_series.h:2505

View

Series<numpy::float64> pct_change(int periods = 1) const

Series<numpy::float64>

df_series.h:1426

auto pipe(Func&& func, Args&&... args) const

auto

df_series.h:2688

T pop(size_t pos)

T

df_series.h:4544

T pop(const std::string& label)

T

df_series.h:4605

Series<numpy::float64> pow(const Series<T>& other) const

Series<numpy::float64>

df_series.h:1835

View

Series<numpy::float64> pow(double exponent) const

Series<numpy::float64>

df_series.h:1847

View

std::optional<T> prod(bool skipna = true) const

std::optional<T>

df_series.h:1147

View

std::optional<T> product(bool skipna = true) const

std::optional<T>

df_series.h:4993

View

Series<T> radd(const T& scalar) const

Series<T>

df_series.h:5000

Series<T> radd(const Series<T>& other) const

Series<T>

df_series.h:5004

Series<numpy::float64> rank(const std::string& method = "average", bool ascending = true, const std::string& na_option = "keep", bool pct = false) const

Series<numpy::float64>

df_series.h:2244

static std::vector<double> rank_values(const std::vector<double>& values)

static std::vector<double>

df_series.h:5620

Series<numpy::float64> rdiv(const T& scalar) const

Series<numpy::float64>

df_series.h:5037

std::pair<Series<T>, Series<T>> rdivmod(const T& scalar) const

std::pair<Series<T>, Series<T>>

df_series.h:5099

Series<T> reindex( const std::vector<std::string>& labels, const std::string& method = "", const std::optional<T>& fill_value = std::nullopt) const

Series<T>

df_series.h:5130

Series<T> reindex_like( const Series<T>& other, const std::string& method = "", const std::optional<T>& fill_value = std::nullopt) const

Series<T>

df_series.h:5179

Series<T> rename(const std::optional<std::string>& new_name) const

Series<T>

df_series.h:3490

Series<T> reorder_levels(const std::vector<int>& order) const

Series<T>

df_series.h:5196

Series<T> replace(const T& to_replace, const T& value) const

Series<T>

df_series.h:5232

View

Series<T> replace(const std::map<T, T>& replacements) const

Series<T>

df_series.h:5252

View

void replace_value(double to_replace, double value) override

void

df_series.h:860

std::string repr() const override

std::string

df_series.h:3615

SeriesResampler<T> resample(const std::string& freq, const std::string& closed = "left", const std::string& label = "left") const

SeriesResampler<T>

df_series.h:2777

void reset_index(bool /\*drop\*/ = true) override

void

df_series.h:444

Series<T> rfloordiv(const T& scalar) const

Series<T>

df_series.h:5056

Series<T> rmod(const T& scalar) const

Series<T>

df_series.h:5072

Series<T> rmul(const T& scalar) const

Series<T>

df_series.h:5026

Series<T> rmul(const Series<T>& other) const

Series<T>

df_series.h:5030

Rolling<T> rolling(size_t window, size_t min_periods = 1, bool center = false) const

Rolling<T>

df_series.h:2708

Series<numpy::float64> rpow(double base) const

Series<numpy::float64>

df_series.h:5088

Series<T> rsub(const T& scalar) const

Series<T>

df_series.h:5011

Series<T> rsub(const Series<T>& other) const

Series<T>

df_series.h:5019

Series<numpy::float64> rtruediv(const T& scalar) const

Series<numpy::float64>

df_series.h:5049

\* Series<double> s(

* Series<double>

df_series.h:2705

\* Series<double> s(

* Series<double>

df_series.h:2716

\* Series<double> s(

* Series<double>

df_series.h:2729

std::optional<double> sem(bool skipna = true, int ddof = 1) const

std::optional<double>

df_series.h:1223

void set_index(std::unique_ptr<IndexBase> new_index) override

void

df_series.h:417

void set_index(const Index<IndexT>& new_index)

void

df_series.h:431

void set_multiindex(MultiIndex multi_idx)

void

df_series.h:454

void set_name(const std::optional<std::string>& name) override

void

df_series.h:385

void set_value_double(size_t idx, double value) override

void

df_series.h:932

void set_value_nan(size_t idx) override

void

df_series.h:909

std::vector<size_t> shape() const override

std::vector<size_t>

df_series.h:346

View

Series<T> shift(int periods = 1, const std::optional<T>& fill_value = std::nullopt) const

Series<T>

df_series.h:2157

View

size_t size() const override

size_t

df_series.h:332

View

std::optional<double> skew(bool skipna = true) const

std::optional<double>

df_series.h:1236

View

Series<T> sub(const Series<T>& other, T fill_value = T

Series<T>

df_series.h:1664

Series<T> sub(T scalar) const

Series<T>

df_series.h:1684

Series<T> swaplevel(int i = -2, int j = -1) const

Series<T>

df_series.h:5355

Series<T> tail(size_t n = 5) const

Series<T>

df_series.h:662

Series<T> transform(Func&& func) const

Series<T>

df_series.h:2606

Series<numpy::float64> truediv(const Series<T>& other) const

Series<numpy::float64>

df_series.h:1758

Series<numpy::float64> truediv(T scalar) const

Series<numpy::float64>

df_series.h:1762

\* Returns true if value is truthy (non-zero for numeric, true for bool)

* Returns true if value is

df_series.h:883

\* For scalar types (non-list-like), this returns a copy of the Series.

* For scalar

df_series.h:3452

View

Series<T> tz_convert(const std::string& tz) const

Series<T>

df_series.h:5589

View

Series<T> tz_localize( const std::string& tz, const std::string& ambiguous = "raise" ) const

Series<T>

df_series.h:5607

View

DataFrame unstack( int level = -1, std::optional<T> fill_value = std::nullopt, bool sort = true ) const

DataFrame

df_series.h:3481

void update(const Series<T>& other)

void

df_series.h:5398

void validate_index_data_alignment() const

void

df_series.h:5650

Series<numpy::int64> value_counts(bool normalize = false, bool sort = true, bool ascending = false, bool dropna = true) const

Series<numpy::int64>

df_series.h:2482

const numpy::NDArray<T>& values() const

const numpy::NDArray<T>&

df_series.h:396

View

\* Series<double> values(

* Series<double>

df_series.h:2751

View

Series<T> xs(const std::string& key, int level = 0) const

Series<T>

df_series.h:5427

Code Examples#

The following examples are extracted from the test suite.

empty (np_test_1_all.cpp:6316)
6306}
6307
6308void test_data_generator_emptyBenchmarkSorting() {
6309    std::cout << "========= test_data_generator_empty =======================";
6310
6311    DataGenerator<int> gen(42);
6312
6313    // Test empty data generation
6314    std::vector<int> data = gen.generate(0, DataPattern::RANDOM);
6315
6316    if (!(data.empty())) {
6317        std::string description = std::string("test_data_generator_emptyBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.empty())";
6318        std::cout << std::string("[FAIL] ") + description << std::endl;
6319        throw std::runtime_error(description);
6320    }
6321
6322    // std::cout << "Empty data generation test passed" << std::endl;
6323
6324    std::cout << " -> tests passed" << std::endl;
6325}
at (np_test_1_all.cpp:144)
134    array.setElementAt({0, 0}, 1);
135    array.setElementAt({0, 1}, 2);
136    array.setElementAt({0, 2}, 3);
137    array.setElementAt({1, 1}, 5);
138    array.setElementAt({2, 2}, 9);
139
140    // std::cout << "Array after setting elements:" << std::endl;
141    //array.printArray();
142
143    // std::cout << "Element at (1,1): " << array.getElementAt({1, 1}) << std::endl;
144    // std::cout << "Element at (2,2): " << array.getElementAt({2, 2});
145
146    std::cout << " -> tests passed" << std::endl;
147}
148
149void testArithmetic() {
150    std::cout << "========= testArithmeticOperations =======================";
151
152    auto array1 = createFloat32Array({2, 2}, 5.0f);
153    auto array2 = createFloat32Array({2, 2}, 3.0f);
get (np_test_1_all.cpp:28526)
28516      std::cout << " -> tests passed" << std::endl;
28517    }
28518
28519    void np_test_indexing_mask_indices() {
28520      std::cout << "========= mask_indices: triangular mask indices =======================";
28521
28522      // Get upper triangular indices for 3x3 matrix
28523      auto triu_idx = numpy::mask_indices(3, "triu", 0);
28524
28525      // Should return tuple of 2 arrays
28526      bool passed = (std::get<0>(triu_idx).getSize() > 0);
28527      passed = passed && (std::get<1>(triu_idx).getSize() > 0);
28528      passed = passed && (std::get<0>(triu_idx).getSize() == std::get<1>(triu_idx).getSize());
28529
28530      // Get lower triangular indices
28531      auto tril_idx = numpy::mask_indices(3, "tril", 0);
28532      passed = passed && (std::get<0>(tril_idx).getSize() > 0);
28533      passed = passed && (std::get<1>(tril_idx).getSize() > 0);
28534
28535      if (!passed) {
28536        std::cout << "  [FAIL] : in np_test_indexing_mask_indices() : Mask indices incorrect";
item (np_test_4_all.cpp:20048)
20038/**
20039 * @file np_test_phase6.cpp
20040 * @brief Test suite for Phase 6A - HIGH PRIORITY NDArray methods and masked array utilities
20041 *
20042 * Tests:
20043 * - ndarray.nonzero() - Return indices of non-zero elements
20044 * - ndarray.tobytes() - Convert to bytes representation
20045 * - ndarray.tolist() - Convert to nested list string
20046 * - ndarray.fill() - Fill with scalar value (in-place)
20047 * - ndarray.item() - Get single element as scalar
20048 * - ndarray.itemset() - Set single element value
20049 * - ma.masked_all_like() - Create masked array with all elements masked
20050 *
20051 * Created: 2025-10-28
20052 * Status: Phase 6A Implementation - HIGH PRIORITY functions
20053 */
20054
20055#include "../numpy/np_ndarray.h"
20056#include "../numpy/np_masked_array.h"
20057#include <iostream>
searchsorted (np_test_2_all.cpp:8204)
8194      // Test missing NumPy functions
8195      void test_numpy_functions() {
8196        std::cout << "========= NumPy Functions Test ==========================";
8197
8198        // Test searchsorted
8199        {
8200          std::vector<int> sorted_arr = { 1, 3, 5, 7, 9 };
8201          std::vector<int> values = { 2, 6, 8 };
8202
8203          auto result = numpy::searchsorted(sorted_arr, values, "left");
8204          std::vector<size_t> expected = { 1, 3, 4 };
8205
8206          if (result != expected) {
8207            std::cout << "   searchsorted (left):                                                                   -> [FAIL]";
8208            throw std::runtime_error("searchsorted (left): FAILED - incorrect result indices");
8209          }
8210          // std::cout << "[OK] searchsorted (left): PASSED" << std::endl;
8211
8212          auto result_right = numpy::searchsorted(sorted_arr, values, "right");
8213          std::vector<size_t> expected_right = { 1, 3, 4 };
take (np_test_5_all.cpp:4313)
4303      for (size_t i = 0; i < 6; ++i) {
4304        arr.setElementAt({ i }, static_cast<int32_t>(i * 10));  // [0, 10, 20, 30, 40, 50]
4305      }
4306
4307      // Take specific indices
4308      numpy::NDArray<size_t> indices({ 3 });
4309      indices.setElementAt({ 0 }, 5);  // 50
4310      indices.setElementAt({ 1 }, 2);  // 20
4311      indices.setElementAt({ 2 }, 0);  // 0
4312
4313      auto result = numpy::take(arr, indices);
4314
4315      if (result.getSize() != 3) {
4316        std::cout << "  [FAIL] : in np_test_take_basic() : Wrong result size";
4317        throw std::runtime_error("Test failed");
4318      }
4319
4320      if (result.getElementAt({ 0 }) != 50 || result.getElementAt({ 1 }) != 20 || result.getElementAt({ 2 }) != 0) {
4321        std::cout << "  [FAIL] : in np_test_take_basic() : Wrong values extracted";
4322        throw std::runtime_error("Test failed");
4323      }
where (np_test_3_all.cpp:15253)
15243      auto y_data = createInt32Array({ 4 }, 0);
15244      y_data.setElementAt({ 0 }, 100);
15245      y_data.setElementAt({ 1 }, 200);
15246      y_data.setElementAt({ 2 }, 300);
15247      y_data.setElementAt({ 3 }, 400);
15248
15249      auto y_mask = createBoolArray({ 4 }, false);
15250      MaskedArray<int32> y(y_data, y_mask, -999);
15251
15252      // Test where() selection
15253      auto result = where(condition, x, y);
15254
15255      if (!(result.getElementAt({ 0 }) == 10)) {
15256          std::string description = std::string("test_where_selection():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 10)";
15257          std::cout << std::string("[FAIL] ") + description << std::endl;
15258          throw std::runtime_error(description);
15259      }
15260      if (!(result.getElementAt({ 1 }) == 200)) {
15261          std::string description = std::string("test_where_selection():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 200)";
15262          std::cout << std::string("[FAIL] ") + description << std::endl;
ravel (np_test_1_all.cpp:4082)
4072    std::cout << "Testing ravel function...\n";
4073
4074    // Test with 2-D array
4075    auto arr_2d = createFloat64Array({ 2, 3 });
4076    for (size_t i = 0; i < 2; ++i) {
4077        for (size_t j = 0; j < 3; ++j) {
4078            arr_2d.setElementAt({ i, j }, static_cast<double>(i * 3 + j));
4079        }
4080    }
4081
4082    auto raveled = ravel(arr_2d);
4083    if (!(raveled.getShape() == std::vector<size_t>({ 6 }))) {
4084        std::string description = std::string("testRavelFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(raveled.getShape() == std::vector<size_t>({ 6 }))";
4085        std::cout << std::string("[FAIL] ") + description << std::endl;
4086        throw std::runtime_error(description);
4087    }
4088
4089    for (size_t i = 0; i < 6; ++i) {
4090        if (!(isApproxEqualExt(raveled.getElementAt({ i }), static_cast<double>(i)))) {
4091            std::string description = std::string("testRavelFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqualExt(raveled.getElementAt({ i }), static_cast<double>(i)))";
4092            std::cout << std::string("[FAIL] ") + description << std::endl;
squeeze (np_test_1_all.cpp:18076)
18066  using namespace numpy;
18067
18068
18069  void testSqueeze() {
18070    std::cout << "========= testSqueeze =======================";
18071
18072    // Create array with singleton dimensions
18073    auto array = createInt32Array({ 1, 4, 1, 3, 1 }, 5);
18074
18075    // Test squeeze all singleton dimensions
18076    auto squeezed_all = squeeze(array);
18077    if (!(squeezed_all.getShape().size() == 2)) {
18078        std::string description = std::string("testSqueeze():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(squeezed_all.getShape().size() == 2)";
18079        std::cout << std::string("[FAIL] ") + description << std::endl;
18080        throw std::runtime_error(description);
18081    }
18082    if (!(squeezed_all.getShape()[0] == 4)) {
18083        std::string description = std::string("testSqueeze():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(squeezed_all.getShape()[0] == 4)";
18084        std::cout << std::string("[FAIL] ") + description << std::endl;
18085        throw std::runtime_error(description);
18086    }
swapaxes (np_test_2_all.cpp:3707)
3697          std::cout << std::string("[FAIL] ") + description << std::endl;
3698          throw std::runtime_error(description);
3699      }
3700      if (!(isApproxEqualMCO(rolled.getElementAt({ 0, 0 }), arr.getElementAt({ 0, 3 })))) {
3701          std::string description = std::string("testRotationFlipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqualMCO(rolled.getElementAt({ 0, 0 }), arr.getElementAt({ 0, 3 })))";
3702          std::cout << std::string("[FAIL] ") + description << std::endl;
3703          throw std::runtime_error(description);
3704      }
3705
3706      // Test swapaxes
3707      auto swapped = swapaxes(arr, 0, 1);
3708      if (!(swapped.getShape() == std::vector<size_t>({ 4, 3 }))) {
3709          std::string description = std::string("testRotationFlipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(swapped.getShape() == std::vector<size_t>({ 4, 3 }))";
3710          std::cout << std::string("[FAIL] ") + description << std::endl;
3711          throw std::runtime_error(description);
3712      }
3713      if (!(isApproxEqualMCO(swapped.getElementAt({ 0, 0 }), arr.getElementAt({ 0, 0 })))) {
3714          std::string description = std::string("testRotationFlipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isApproxEqualMCO(swapped.getElementAt({ 0, 0 }), arr.getElementAt({ 0, 0 })))";
3715          std::cout << std::string("[FAIL] ") + description << std::endl;
3716          throw std::runtime_error(description);
3717      }
transpose (np_test_2_all.cpp:4973)
4963    }
4964
4965    /**
4966     * Test matrix properties and methods
4967     */
4968    void testMatrixProperties() {
4969      std::cout << "========= testMatrixProperties =======================";
4970
4971      // Test transpose
4972      numpy::Matrix<double> m("1 2 3; 4 5 6");
4973      auto mt = m.transpose();
4974      assert_test(mt.rows() == 3, "Transpose rows");
4975      assert_test(mt.cols() == 2, "Transpose cols");
4976      assert_test(std::abs(mt(0, 1) - 4.0) < 1e-10, "Transpose element");
4977      assert_test(std::abs(mt(2, 0) - 3.0) < 1e-10, "Transpose element");
4978
4979      // Test trace for square matrix
4980      numpy::Matrix<double> square("1 2; 3 4");
4981      double tr = square.trace();
4982      assert_test(std::abs(tr - 5.0) < 1e-10, "Matrix trace");
cov (np_test_1_all.cpp:12038)
12028    data.setElementAt({ 0, 0 }, 1.0);
12029    data.setElementAt({ 0, 1 }, 2.0);
12030    data.setElementAt({ 0, 2 }, 3.0);
12031
12032    // Variable 2: [2, 4, 6] (perfectly correlated)
12033    data.setElementAt({ 1, 0 }, 2.0);
12034    data.setElementAt({ 1, 1 }, 4.0);
12035    data.setElementAt({ 1, 2 }, 6.0);
12036
12037    // Test covariance matrix
12038    auto cov_matrix = cov(data);
12039    if (!(cov_matrix.getShape()[0] == 2)) {
12040        std::string description = std::string("testCovarianceAndCorrelation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(cov_matrix.getShape()[0] == 2)";
12041        std::cout << std::string("[FAIL] ") + description << std::endl;
12042        throw std::runtime_error(description);
12043    }
12044    if (!(cov_matrix.getShape()[1] == 2)) {
12045        std::string description = std::string("testCovarianceAndCorrelation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(cov_matrix.getShape()[1] == 2)";
12046        std::cout << std::string("[FAIL] ") + description << std::endl;
12047        throw std::runtime_error(description);
12048    }
max (np_test_1_all.cpp:7274)
7264    if (sizeof(uintp) == sizeof(void*)) {
7265        // std::cout << "                -> uintp size matches pointer size";
7266    } else {
7267        // std::cout << "  ✗ uintp size doesn't match pointer size" << std::endl;
7268    }
7269
7270    // Test range limits
7271    // std::cout << "Range Information:" << std::endl;
7272    // std::cout << "  intp min: " << std::numeric_limits<intp>::min() << std::endl;
7273    // std::cout << "  intp max: " << std::numeric_limits<intp>::max() << std::endl;
7274    // std::cout << "  uintp max: " << std::numeric_limits<uintp>::max() << std::endl;
7275    // std::cout << "  longdouble digits: " << std::numeric_limits<longdouble>::digits << std::endl;
7276
7277    std::cout << " -> tests passed" << std::endl;
7278}
7279
7280void testComplexArithmeticExtendedTypes() {
7281    std::cout << "========= testComplexArithmeticExtendedTypes =======================";
7282
7283    clongdouble c1(3.0L, 4.0L);  // 3 + 4i
mean (np_test_1_all.cpp:11714)
11704    // Create test array
11705    auto array = createInt32Array({ 2, 3 }, 0);
11706    array.setElementAt({ 0, 0 }, 1);
11707    array.setElementAt({ 0, 1 }, 2);
11708    array.setElementAt({ 0, 2 }, 3);
11709    array.setElementAt({ 1, 0 }, 4);
11710    array.setElementAt({ 1, 1 }, 5);
11711    array.setElementAt({ 1, 2 }, 6);
11712
11713    // Test mean without axis
11714    auto mean_all = mean(array);
11715    if (!(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))) {
11716        std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))";
11717        std::cout << std::string("[FAIL] ") + description << std::endl;
11718        throw std::runtime_error(description);
11719    }
11720    // std::cout << "[OK] mean (all elements) works correctly\n";
11721
11722    // Test mean along axis 0
11723    auto mean_axis0 = mean(array, 0);
11724    if (!(mean_axis0.getShape()[0] == 3)) {
median (np_test_1_all.cpp:11882)
11872    std::cout << "========= testMedianAndPercentiles =======================";
11873
11874    // Test median with odd number of elements
11875    auto odd_array = createInt32Array({ 5 }, 0);
11876    odd_array.setElementAt({ 0 }, 1);
11877    odd_array.setElementAt({ 1 }, 3);
11878    odd_array.setElementAt({ 2 }, 5);
11879    odd_array.setElementAt({ 3 }, 7);
11880    odd_array.setElementAt({ 4 }, 9);
11881
11882    auto median_odd = median(odd_array);
11883    if (!(approx_equal(median_odd.getElementAt({ 0 }), 5.0, 1e-10))) {
11884        std::string description = std::string("testMedianAndPercentiles():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(median_odd.getElementAt({ 0 }), 5.0, 1e-10))";
11885        std::cout << std::string("[FAIL] ") + description << std::endl;
11886        throw std::runtime_error(description);
11887    }
11888    // std::cout << "[OK] Median with odd count works correctly\n";
11889
11890    // Test median with even number of elements
11891    auto even_array = createInt32Array({ 4 }, 0);
11892    even_array.setElementAt({ 0 }, 1);
min (np_test_1_all.cpp:2350)
2340        if (i % 3 == 0) {
2341            large_array.setElementAt({i}, object_(static_cast<int>(i)));
2342        } else if (i % 3 == 1) {
2343            large_array.setElementAt({i}, object_(static_cast<double>(i) * 0.5));
2344        } else {
2345            large_array.setElementAt({i}, object_(std::string("str") + std::to_string(i)));
2346        }
2347    }
2348
2349    // Verify pattern
2350    for (size_t i = 0; i < std::min(large_size, size_t(100)); ++i) {  // Check first 100
2351        object_ obj = large_array.getElementAt({i});
2352        if (i % 3 == 0) {
2353            if (!(obj.is_type<int>())) {
2354                std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type<int>())";
2355                std::cout << std::string("[FAIL] ") + description << std::endl;
2356                throw std::runtime_error(description);
2357            }
2358        } else if (i % 3 == 1) {
2359            if (!(obj.is_type<double>())) {
2360                std::string description = std::string("unknown_function():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type<double>())";
quantile (np_test_1_all.cpp:11929)
11919    // Test 25th percentile
11920    auto perc25 = percentile(perc_array, 25.0);
11921    if (!(approx_equal(perc25.getElementAt({ 0 }), 3.25, 1e-10))) {
11922        std::string description = std::string("testMedianAndPercentiles():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(perc25.getElementAt({ 0 }), 3.25, 1e-10))";
11923        std::cout << std::string("[FAIL] ") + description << std::endl;
11924        throw std::runtime_error(description);
11925    }
11926    // std::cout << "[OK] 25th percentile works correctly\n";
11927
11928    // Test quantile (equivalent to percentile/100)
11929    auto quant75 = quantile(perc_array, 0.75);
11930    auto perc75 = percentile(perc_array, 75.0);
11931    if (!(approx_equal(quant75.getElementAt({ 0 }), perc75.getElementAt({ 0 }), 1e-10))) {
11932        std::string description = std::string("testMedianAndPercentiles():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(quant75.getElementAt({ 0 }), perc75.getElementAt({ 0 }), 1e-10))";
11933        std::cout << std::string("[FAIL] ") + description << std::endl;
11934        throw std::runtime_error(description);
11935    }
11936    // std::cout << "[OK] Quantile function works correctly\n";
11937    std::cout << " -> tests passed" << std::endl;
11938  }
std (np_test_1_all.cpp:11836)
11826    auto var_sample = var(array, std::nullopt, 1);  // ddof=1 for sample variance
11827    double expected_sample_var = 1.25 * 4.0 / 3.0;  // Bessel's correction
11828    if (!(approx_equal(var_sample.getElementAt({ 0 }), expected_sample_var, 1e-10))) {
11829        std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(var_sample.getElementAt({ 0 }), expected_sample_var, 1e-10))";
11830        std::cout << std::string("[FAIL] ") + description << std::endl;
11831        throw std::runtime_error(description);
11832    }
11833    // std::cout << "[OK] Sample variance works correctly\n";
11834
11835    // Test standard deviation
11836    auto std_result = numpy::std(array, std::nullopt, 0);
11837    if (!(approx_equal(std_result.getElementAt({ 0 }), std::sqrt(expected_var), 1e-10))) {
11838        std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(std_result.getElementAt({ 0 }), std::sqrt(expected_var), 1e-10))";
11839        std::cout << std::string("[FAIL] ") + description << std::endl;
11840        throw std::runtime_error(description);
11841    }
11842    // std::cout << "[OK] Standard deviation works correctly\n";
11843
11844    // Test along axis
11845    auto array2d = createFloat64Array({ 2, 2 }, 0);
11846    array2d.setElementAt({ 0, 0 }, 1.0);
sum (np_test_1_all.cpp:11766)
11756        throw std::runtime_error(description);
11757    }
11758    if (!(approx_equal(mean_axis1.getElementAt({ 1 }), 5.0, 1e-10))) {
11759        std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_axis1.getElementAt({ 1 }), 5.0, 1e-10))";
11760        std::cout << std::string("[FAIL] ") + description << std::endl;
11761        throw std::runtime_error(description);
11762    }
11763    // std::cout << "[OK] mean along axis 1 works correctly\n";
11764
11765    // Test sum
11766    auto sum_all = sum(array);
11767    if (!(sum_all.getElementAt({ 0 }) == 21)) {
11768        std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sum_all.getElementAt({ 0 }) == 21)";
11769        std::cout << std::string("[FAIL] ") + description << std::endl;
11770        throw std::runtime_error(description);
11771    }
11772    // std::cout << "[OK] sum works correctly\n";
11773
11774    // Test min and max
11775    auto min_all = min(array);
11776    auto max_all = max(array);
var (np_test_1_all.cpp:11816)
11806    std::cout << "========= testVarianceAndStandardDeviation =======================";
11807
11808    // Create test array with known variance
11809    auto array = createFloat64Array({ 4 }, 0);
11810    array.setElementAt({ 0 }, 1.0);
11811    array.setElementAt({ 1 }, 2.0);
11812    array.setElementAt({ 2 }, 3.0);
11813    array.setElementAt({ 3 }, 4.0);
11814
11815    // Test variance (population)
11816    auto var_result = var(array, std::nullopt, 0);  // ddof=0 for population variance
11817    double expected_var = 1.25;  // Known variance for [1,2,3,4]
11818    if (!(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))) {
11819        std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))";
11820        std::cout << std::string("[FAIL] ") + description << std::endl;
11821        throw std::runtime_error(description);
11822    }
11823    // std::cout << "[OK] Population variance works correctly\n";
11824
11825    // Test variance (sample)
11826    auto var_sample = var(array, std::nullopt, 1);  // ddof=1 for sample variance
argsort (np_test_1_all.cpp:16841)
16831    std::cout << "========= test_argsort =======================";
16832
16833    // Test 1D array argsort
16834    NDArray<int> arr1d({ 5 });
16835    arr1d.setElementAt({ 0 }, 30);  // index 0
16836    arr1d.setElementAt({ 1 }, 10);  // index 1
16837    arr1d.setElementAt({ 2 }, 40);  // index 2
16838    arr1d.setElementAt({ 3 }, 20);  // index 3
16839    arr1d.setElementAt({ 4 }, 50);  // index 4
16840
16841    auto indices = argsort(arr1d);
16842
16843    // Expected order: 10(idx1), 20(idx3), 30(idx0), 40(idx2), 50(idx4)
16844    if (!(indices.getElementAt({ 0 }) == 1)) {
16845        std::string description = std::string("test_argsort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(indices.getElementAt({ 0 }) == 1)";
16846        std::cout << std::string("[FAIL] ") + description << std::endl;
16847        throw std::runtime_error(description);
16848    }
16849    if (!(indices.getElementAt({ 1 }) == 3)) {
16850        std::string description = std::string("test_argsort():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(indices.getElementAt({ 1 }) == 3)";
16851        std::cout << std::string("[FAIL] ") + description << std::endl;
abs (np_test_1_all.cpp:101)
 91        if (arr.getShape().size() == 1 && arr.getShape()[0] <= 10) {
 92            for (size_t i = 0; i < arr.getShape()[0]; ++i) {
 93                // std::cout << static_cast<int64_t>(arr.getElementAt({i})) << " ";
 94            }
 95        }
 96        // std::cout << std::endl;
 97    }
 98
 99    // Helper function for core array extensions tests
100    bool isApproxEqualExt(double a, double b, double tolerance = 1e-10) {
101        return std::abs(a - b) < tolerance;
102    }
103}
104
105void f_nothing() {
106    // This function does nothing and tests nothing
107    // It's a placeholder test function
108}
109
110// ------ merging np_test_advanced_indexing.cpp -- number of functions merged=16 --------------------------------
add (np_test_1_all.cpp:6410)
6400void testCharArrayStringOperationsCharArray() {
6401    std::cout << "========= testStringOperations =======================";
6402
6403    // Test string concatenation
6404    std::vector<std::string> words1 = {"Hello", "Good", "Nice"};
6405    std::vector<std::string> words2 = {" World", " Day", " Work"};
6406
6407    auto arr1 = array<32>(words1);
6408    auto arr2 = array<32>(words2);
6409
6410    auto result = add(arr1, arr2);
6411    // std::cout << "String concatenation (add):" << std::endl;
6412    for (size_t i = 0; i < result.size(); ++i) {
6413        // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'";
6414    }
6415
6416    // Test scalar addition
6417    auto scalar_result = add(arr1, "!");
6418    // std::cout << "Scalar concatenation:" << std::endl;
6419    for (size_t i = 0; i < scalar_result.size(); ++i) {
6420        // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'";
add (np_test_1_all.cpp:6410)
6400void testCharArrayStringOperationsCharArray() {
6401    std::cout << "========= testStringOperations =======================";
6402
6403    // Test string concatenation
6404    std::vector<std::string> words1 = {"Hello", "Good", "Nice"};
6405    std::vector<std::string> words2 = {" World", " Day", " Work"};
6406
6407    auto arr1 = array<32>(words1);
6408    auto arr2 = array<32>(words2);
6409
6410    auto result = add(arr1, arr2);
6411    // std::cout << "String concatenation (add):" << std::endl;
6412    for (size_t i = 0; i < result.size(); ++i) {
6413        // std::cout << "'" << arr1[i] << "' + '" << arr2[i] << "' = '" << result[i] << "'";
6414    }
6415
6416    // Test scalar addition
6417    auto scalar_result = add(arr1, "!");
6418    // std::cout << "Scalar concatenation:" << std::endl;
6419    for (size_t i = 0; i < scalar_result.size(); ++i) {
6420        // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'";
ceil (np_test_2_all.cpp:5735)
5725          throw std::runtime_error(description);
5726      }
5727      if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) {
5728          std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))";
5729          std::cout << std::string("[FAIL] ") + description << std::endl;
5730          throw std::runtime_error(description);
5731      }
5732      // std::cout << "[OK] floor function works correctly\n";
5733
5734      // Test ceil
5735      auto ceil_result = ceil(values);
5736      if (!(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))) {
5737          std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))";
5738          std::cout << std::string("[FAIL] ") + description << std::endl;
5739          throw std::runtime_error(description);
5740      }
5741      if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) {
5742          std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))";
5743          std::cout << std::string("[FAIL] ") + description << std::endl;
5744          throw std::runtime_error(description);
5745      }
divide (np_test_3_all.cpp:16880)
16870      std::cout << " -> tests passed" << std::endl;
16871    }
16872
16873    void np_test_missing_math_functions_divide_array() {
16874      std::cout << "========= divide: array-array division =======================";
16875
16876      // explicit namespace to avoid name clashes
16877      numpy::NDArray<double> a = numpy::arange<double>(10.0, 16.0, 1.0);
16878      numpy::NDArray<double> b = numpy::arange<double>(2.0, 8.0, 1.0);
16879
16880      numpy::NDArray<double> result = numpy::divide(a, b);
16881
16882      // Verify values: [10,11,12,13,14,15] / [2,3,4,5,6,7] = [5,3.666...,3,2.6,2.333...,2.142...]
16883      auto pass = true;
16884      double expected[] = { 5.0, 11.0 / 3.0, 3.0, 2.6, 14.0 / 6.0, 15.0 / 7.0 };
16885      for (size_t i = 0; i < 6 && pass; ++i) {
16886        double val = result.getElementAt({ i });
16887        double exp = expected[i];
16888        if (std::abs(val - exp) > 1e-10) {
16889          pass = false;
16890        }
floor (np_test_2_all.cpp:5721)
5711          throw std::runtime_error(description);
5712      }
5713      if (!(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))) {
5714          std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))";
5715          std::cout << std::string("[FAIL] ") + description << std::endl;
5716          throw std::runtime_error(description);
5717      }
5718      // std::cout << "[OK] round function works correctly\n";
5719
5720      // Test floor
5721      auto floor_result = floor(values);
5722      if (!(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))) {
5723          std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))";
5724          std::cout << std::string("[FAIL] ") + description << std::endl;
5725          throw std::runtime_error(description);
5726      }
5727      if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) {
5728          std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))";
5729          std::cout << std::string("[FAIL] ") + description << std::endl;
5730          throw std::runtime_error(description);
5731      }
mod (np_test_1_all.cpp:21258)
21248    a.setElementAt({ 1 }, -7);
21249    a.setElementAt({ 2 }, 7);
21250    a.setElementAt({ 3 }, -7);
21251
21252    auto b = NDArray<int32>({ 4 });
21253    b.setElementAt({ 0 }, 3);
21254    b.setElementAt({ 1 }, 3);
21255    b.setElementAt({ 2 }, -3);
21256    b.setElementAt({ 3 }, -3);
21257
21258    auto result = mod(a, b);
21259
21260    if (!(result.getElementAt({ 0 }) == 1)) {
21261        std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)";
21262        std::cout << std::string("[FAIL] ") + description << std::endl;
21263        throw std::runtime_error(description);
21264    }
21265    if (!(result.getElementAt({ 1 }) == 2)) {
21266        std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)";
21267        std::cout << std::string("[FAIL] ") + description << std::endl;
21268        throw std::runtime_error(description);
mod (np_test_1_all.cpp:21258)
21248    a.setElementAt({ 1 }, -7);
21249    a.setElementAt({ 2 }, 7);
21250    a.setElementAt({ 3 }, -7);
21251
21252    auto b = NDArray<int32>({ 4 });
21253    b.setElementAt({ 0 }, 3);
21254    b.setElementAt({ 1 }, 3);
21255    b.setElementAt({ 2 }, -3);
21256    b.setElementAt({ 3 }, -3);
21257
21258    auto result = mod(a, b);
21259
21260    if (!(result.getElementAt({ 0 }) == 1)) {
21261        std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 0 }) == 1)";
21262        std::cout << std::string("[FAIL] ") + description << std::endl;
21263        throw std::runtime_error(description);
21264    }
21265    if (!(result.getElementAt({ 1 }) == 2)) {
21266        std::string description = std::string("testModFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({ 1 }) == 2)";
21267        std::cout << std::string("[FAIL] ") + description << std::endl;
21268        throw std::runtime_error(description);
mode (np_test_4_all.cpp:20711)
20701#include <stdexcept>
20702
20703using namespace numpy;
20704
20705namespace numpy_tests {
20706namespace numpy_tests_phase6b {
20707
20708void np_test_phase6b_can_cast() {
20709    std::cout << "=== Test can_cast() ===";
20710
20711    // Test SAFE casting mode (default)
20712    {
20713        // Same type is always safe
20714        if (!(can_cast(DType::INT32, DType::INT32, CastingMode::SAFE) == true)) {
20715            std::string description = std::string("np_test_phase6b_can_cast():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(can_cast(DType::INT32, DType::INT32, CastingMode::SAFE) == true)";
20716            std::cout << std::string("[FAIL] ") + description << std::endl;
20717            throw std::runtime_error(description);
20718        }
20719        if (!(can_cast(DType::FLOAT64, DType::FLOAT64, CastingMode::SAFE) == true)) {
20720            std::string description = std::string("np_test_phase6b_can_cast():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(can_cast(DType::FLOAT64, DType::FLOAT64, CastingMode::SAFE) == true)";
20721            std::cout << std::string("[FAIL] ") + description << std::endl;
multiply (np_test_1_all.cpp:6426)
6416    // Test scalar addition
6417    auto scalar_result = add(arr1, "!");
6418    // std::cout << "Scalar concatenation:" << std::endl;
6419    for (size_t i = 0; i < scalar_result.size(); ++i) {
6420        // std::cout << "'" << arr1[i] << "' + '!' = '" << scalar_result[i] << "'";
6421    }
6422
6423    // Test string multiplication
6424    std::vector<std::string> patterns = {"Ha", "Ho", "Hi"};
6425    auto pattern_arr = array<32>(patterns);
6426    auto repeated = multiply(pattern_arr, 3);
6427    // std::cout << "String multiplication:" << std::endl;
6428    for (size_t i = 0; i < repeated.size(); ++i) {
6429        // std::cout << "'" << pattern_arr[i] << "' * 3 = '" << repeated[i] << "'";
6430    }
6431
6432    std::cout << " -> tests passed" << std::endl;
6433}
6434
6435void testCaseConversionsCharArray() {
6436    std::cout << "========= testCaseConversions =======================";
round (np_test_1_all.cpp:23769)
23759          throw std::runtime_error(description);
23760      }
23761      if (!(power_scalar_result.getShape() == array.getShape())) {
23762          std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())";
23763          std::cout << std::string("[FAIL] ") + description << std::endl;
23764          throw std::runtime_error(description);
23765      }
23766      // std::cout << "[OK] Power functions have correct signatures\n";
23767
23768      // Test rounding functions with new decimals parameter
23769      auto round_result = round(array);        // Default decimals=0
23770      auto round_decimals_result = round(array, 2);  // With decimals
23771      if (!(round_result.getShape() == array.getShape())) {
23772          std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())";
23773          std::cout << std::string("[FAIL] ") + description << std::endl;
23774          throw std::runtime_error(description);
23775      }
23776      if (!(round_decimals_result.getShape() == array.getShape())) {
23777          std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())";
23778          std::cout << std::string("[FAIL] ") + description << std::endl;
23779          throw std::runtime_error(description);
subtract (np_test_3_all.cpp:16825)
16815      std::cout << " -> tests passed" << std::endl;
16816    }
16817
16818    void np_test_missing_math_functions_subtract_array() {
16819      std::cout << "========= subtract: array-array subtraction =======================";
16820
16821      // explicit namespace to avoid name clashes
16822      numpy::NDArray<double> a = numpy::arange<double>(10.0, 16.0, 1.0);
16823      numpy::NDArray<double> b = numpy::arange<double>(0.0, 6.0, 1.0);
16824
16825      numpy::NDArray<double> result = numpy::subtract(a, b);
16826
16827      // Verify values: [10,11,12,13,14,15] - [0,1,2,3,4,5] = [10,10,10,10,10,10]
16828      auto pass = true;
16829      for (size_t i = 0; i < 6 && pass; ++i) {
16830        double val = result.getElementAt({ i });
16831        double exp = 10.0;
16832        if (std::abs(val - exp) > 1e-10) {
16833          pass = false;
16834        }
16835      }
truncate (np_test_5_all.cpp:7536)
7526      if (!passed) {
7527        std::cout << "  [FAIL] : cutdeg failed";
7528        throw std::runtime_error("np_test_cutdeg failed");
7529      }
7530
7531      std::cout << " -> tests passed" << std::endl;
7532    }
7533
7534    void np_test_truncate() {
7535      std::cout << "========= truncate: truncate to size =======================";
7536
7537      numpy::Polynomial<double> p({ 1.0, 2.0, 3.0, 4.0, 5.0 });
7538      auto truncated = p.truncate(3);  // Keep only first 3 coefficients
7539
7540      auto coefs = truncated.coefficients();
7541      bool passed = (coefs.size() == 3 &&
7542        std::abs(coefs[0] - 1.0) < 1e-10 &&
7543        std::abs(coefs[1] - 2.0) < 1e-10 &&
7544        std::abs(coefs[2] - 3.0) < 1e-10);
dot (np_test_2_all.cpp:11523)
11513      numpy::NDArray<double> v2({ 3 });
11514
11515      v1.setElementAt({ 0 }, 1.0);
11516      v1.setElementAt({ 1 }, 2.0);
11517      v1.setElementAt({ 2 }, 3.0);
11518
11519      v2.setElementAt({ 0 }, 4.0);
11520      v2.setElementAt({ 1 }, 5.0);
11521      v2.setElementAt({ 2 }, 6.0);
11522
11523      auto result = numpy::linalg::dot(v1, v2);
11524      double expected = 1.0 * 4.0 + 2.0 * 5.0 + 3.0 * 6.0; // = 32
11525
11526      // Extract scalar from 0-D array
11527      double result_value = result.getElementAt({});
11528
11529      if (std::abs(result_value - expected) > 1e-10) {
11530        std::cout << "  [FAIL] : dot product incorrect, expected " << expected << ", got " << result_value;
11531        throw std::runtime_error("dot test failed");
11532      }
dot (np_test_2_all.cpp:11523)
11513      numpy::NDArray<double> v2({ 3 });
11514
11515      v1.setElementAt({ 0 }, 1.0);
11516      v1.setElementAt({ 1 }, 2.0);
11517      v1.setElementAt({ 2 }, 3.0);
11518
11519      v2.setElementAt({ 0 }, 4.0);
11520      v2.setElementAt({ 1 }, 5.0);
11521      v2.setElementAt({ 2 }, 6.0);
11522
11523      auto result = numpy::linalg::dot(v1, v2);
11524      double expected = 1.0 * 4.0 + 2.0 * 5.0 + 3.0 * 6.0; // = 32
11525
11526      // Extract scalar from 0-D array
11527      double result_value = result.getElementAt({});
11528
11529      if (std::abs(result_value - expected) > 1e-10) {
11530        std::cout << "  [FAIL] : dot product incorrect, expected " << expected << ", got " << result_value;
11531        throw std::runtime_error("dot test failed");
11532      }
sample (np_test_1_all.cpp:22321)
22311        throw std::runtime_error(description);
22312    }
22313    for (size_t i = 0; i < 3; ++i) {
22314      double val = random_samp.getElementAt({ i });
22315      if (!(val >= 0.0 && val < 1.0)) {
22316          std::string description = std::string("testRandomUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(val >= 0.0 && val < 1.0)";
22317          std::cout << std::string("[FAIL] ") + description << std::endl;
22318          throw std::runtime_error(description);
22319      }
22320    }
22321    // std::cout << "[OK] Random sample (alias)\n";
22322
22323    auto ranf_arr = ranf<double>({ {3} });
22324    if (!(ranf_arr.getShape()[0] == 3)) {
22325        std::string description = std::string("testRandomUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ranf_arr.getShape()[0] == 3)";
22326        std::cout << std::string("[FAIL] ") + description << std::endl;
22327        throw std::runtime_error(description);
22328    }
22329    // std::cout << "[OK] ranf (alias)\n";
22330
22331    auto sample_arr = sample<double>({ {3} });
unique (np_test_1_all.cpp:6259)
6249    if (!(data.size() == 100)) {
6250        std::string description = std::string("test_data_generator_few_uniqueBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 100)";
6251        std::cout << std::string("[FAIL] ") + description << std::endl;
6252        throw std::runtime_error(description);
6253    }
6254
6255    // Count unique values
6256    std::vector<int> sorted_copy = data;
6257    std::sort(sorted_copy.begin(), sorted_copy.end());
6258    auto unique_end = std::unique(sorted_copy.begin(), sorted_copy.end());
6259    size_t unique_count = std::distance(sorted_copy.begin(), unique_end);
6260
6261    // Should have significantly fewer unique values than total elements
6262    if (!(unique_count < data.size() / 2)) {
6263        std::string description = std::string("test_data_generator_few_uniqueBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unique_count < data.size() / 2)";
6264        std::cout << std::string("[FAIL] ") + description << std::endl;
6265        throw std::runtime_error(description);
6266    }
6267
6268    // std::cout << "Few unique data generation test passed. Unique values: " << unique_count << std::endl;
to_numpy (np_test_5_all.cpp:21373)
21363    if (errors == 0) {
21364        std::cout << "np_test_timedelta_components -> tests passed" << std::endl;
21365    }
21366    return errors;
21367}
21368
21369// =============================================================================
21370// Test 4: Total Conversion Properties
21371// =============================================================================
21372int np_test_timedelta_total_conversions() {
21373    int errors = 0;
21374
21375    numpy::Timedelta td(1, 12, 0);  // 1 day 12 hours = 1.5 days = 36 hours
21376
21377    // total_seconds
21378    {
21379        double secs = td.total_seconds();
21380        double expected = (24 + 12) * 3600.0;
21381        if (std::abs(secs - expected) > 0.0001) {
21382            std::cout << "[FAIL] np_test_timedelta_total_conversions: total_seconds expected "
21383                      << expected << ", got " << secs << std::endl;
to_string (np_test_1_all.cpp:454)
444    // Modify through different views
445    view1.setElementAt({0, 0}, 100);
446    view2.setElementAt({2, 1}, 200);  // This is (1, 2) in original
447    view3.setElementAt({0, 0}, 300);  // This is (1, 1) in original
448
449    // std::cout << "After modifications through multiple views:" << std::endl;
450    //original.printArray();
451
452    // Verify all changes are reflected
453    if (!(original.getElementAt({0, 0}) == 100)) {
454        std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({0, 0}) == 100)";
455        std::cout << std::string("[FAIL] ") + description << std::endl;
456        throw std::runtime_error(description);
457    }
458    if (!(original.getElementAt({1, 2}) == 200)) {
459        std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 2}) == 200)";
460        std::cout << std::string("[FAIL] ") + description << std::endl;
461        throw std::runtime_error(description);
462    }
463    if (!(original.getElementAt({1, 1}) == 300)) {
464        std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 300)";
tolist (np_test_4_all.cpp:20046)
20036} // namespace numpy_tests
20037
20038/**
20039 * @file np_test_phase6.cpp
20040 * @brief Test suite for Phase 6A - HIGH PRIORITY NDArray methods and masked array utilities
20041 *
20042 * Tests:
20043 * - ndarray.nonzero() - Return indices of non-zero elements
20044 * - ndarray.tobytes() - Convert to bytes representation
20045 * - ndarray.tolist() - Convert to nested list string
20046 * - ndarray.fill() - Fill with scalar value (in-place)
20047 * - ndarray.item() - Get single element as scalar
20048 * - ndarray.itemset() - Set single element value
20049 * - ma.masked_all_like() - Create masked array with all elements masked
20050 *
20051 * Created: 2025-10-28
20052 * Status: Phase 6A Implementation - HIGH PRIORITY functions
20053 */
20054
20055#include "../numpy/np_ndarray.h"
repeat (np_test_1_all.cpp:18268)
18258    // Create test array
18259    auto array = createInt32Array({ 2, 3 }, 0);
18260    for (size_t i = 0; i < 2; ++i) {
18261      for (size_t j = 0; j < 3; ++j) {
18262        array.setElementAt({ i, j }, static_cast<int32_t>(i * 3 + j + 1));
18263      }
18264    }
18265
18266    // Test repeat without axis (flattened)
18267    auto repeated_flat = repeat(array, 2);
18268    if (!(repeated_flat.getShape()[0] == 12)) {
18269        std::string description = std::string("testRepeat():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(repeated_flat.getShape()[0] == 12)";
18270        std::cout << std::string("[FAIL] ") + description << std::endl;
18271        throw std::runtime_error(description);
18272    }
18273    if (!(repeated_flat.getElementAt({ 0 }) == 1)) {
18274        std::string description = std::string("testRepeat():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(repeated_flat.getElementAt({ 0 }) == 1)";
18275        std::cout << std::string("[FAIL] ") + description << std::endl;
18276        throw std::runtime_error(description);
18277    }
astype (np_test_3_all.cpp:796)
786        auto ufunc_square = numpy::frompyfunc(square, 1, 1);
787
788        numpy::NDArray<double> arr({ 3 });
789        arr.setElementAt({ 0 }, 2.0);
790        arr.setElementAt({ 1 }, 3.0);
791        arr.setElementAt({ 2 }, 4.0);
792
793        auto result = ufunc_square(arr);
794
795        // Convert back to double to check values
796        auto typed_result = numpy::astype<double>(result);
797        if (std::abs(typed_result.getElementAt({ 0 }) - 4.0) > 1e-10 ||
798          std::abs(typed_result.getElementAt({ 1 }) - 9.0) > 1e-10 ||
799          std::abs(typed_result.getElementAt({ 2 }) - 16.0) > 1e-10) {
800          std::cout << "[FAIL] Basic frompyfunc creation failed";
801          return 1;
802        }
803
804        // std::cout << "[OK] Basic frompyfunc creation works correctly" << std::endl;
805        std::cout << " -> tests passed" << std::endl;
806        return 0;
copy (np_test_1_all.cpp:9812)
9802    //original.printArray();
9803
9804    // The modification should be at position (1,1) in original
9805    if (!(original.getElementAt({1, 1}) == 9999)) {
9806        std::string description = std::string("testSliceCopyVsViewMemoryOwnership():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 9999)";
9807        std::cout << std::string("[FAIL] ") + description << std::endl;
9808        throw std::runtime_error(description);
9809    }
9810    // std::cout << "[OK] Slice view shares memory with original";
9811
9812    // Test slice copy (should be independent)
9813    auto slice_copy = original.sliceArray({{2, 4}, {2, 4}});
9814    // std::cout << "Slice copy [2:4, 2:4]:";
9815    //slice_copy.printArray();
9816
9817    slice_copy.setElementAt({0, 0}, 7777);
9818
9819    // std::cout << "After modifying slice copy at (0,0):" << std::endl;
9820    // std::cout << "Original array:" << std::endl;
9821    //original.printArray();
9822    // std::cout << "Slice copy:" << std::endl;
view (np_test_1_all.cpp:440)
430    for (size_t i = 0; i < 3; ++i) {
431        for (size_t j = 0; j < 3; ++j) {
432            original.setElementAt({i, j}, static_cast<int32_t>(i * 3 + j));
433        }
434    }
435
436    // std::cout << "Original array:" << std::endl;
437    //original.printArray();
438
439    // Create multiple views
440    auto view1 = original.view();
441    auto view2 = original.transposeView();
442    auto view3 = original.sliceView({{1, 3}, {1, 3}});
443
444    // Modify through different views
445    view1.setElementAt({0, 0}, 100);
446    view2.setElementAt({2, 1}, 200);  // This is (1, 2) in original
447    view3.setElementAt({0, 0}, 300);  // This is (1, 1) in original
448
449    // std::cout << "After modifications through multiple views:" << std::endl;
450    //original.printArray();
combine (np_test_5_all.cpp:22273)
22263      auto pass = true;
22264      std::string fail_msg;
22265
22266      // Default constructor (NaT)
22267      numpy::Timestamp nat;
22268      if (!nat.isNaT()) {
22269        pass = false;
22270        fail_msg = "Default constructor should create NaT";
22271      }
22272
22273      // Component constructor
22274      numpy::Timestamp ts1(2024, 6, 15, 14, 30, 45);
22275      if (ts1.year() != 2024 || ts1.month() != 6 || ts1.day() != 15 ||
22276          ts1.hour() != 14 || ts1.minute() != 30 || ts1.second() != 45) {
22277        pass = false;
22278        fail_msg = "Component constructor values incorrect";
22279      }
22280
22281      // With microseconds and nanoseconds
22282      numpy::Timestamp ts2(2024, 1, 1, 12, 0, 0, 123456, 789);
argmax (np_test_3_all.cpp:20521)
20511    auto result = numpy::argmin(arr);
20512    // Should return 1 (index of (1,5))
20513    if (result.getElementAt({0}) != 1) {
20514        throw std::runtime_error("argmin() failed: expected index 1");
20515    }
20516    std::cout << "PASSED\n";
20517}
20518
20519void test_argmax_complex128() {
20520    std::cout << "  Testing argmax() with complex128... ";
20521    numpy::NDArray<complex128> arr({3});
20522    arr.setElementAt({0}, complex128(3.0, 1.0));  // index 0 - largest
20523    arr.setElementAt({1}, complex128(1.0, 5.0));  // index 1
20524    arr.setElementAt({2}, complex128(2.0, 2.0));  // index 2
20525
20526    auto result = numpy::argmax(arr);
20527    // Should return 0 (index of (3,1))
20528    if (result.getElementAt({0}) != 0) {
20529        throw std::runtime_error("argmax() failed: expected index 0");
20530    }
argmin (np_test_3_all.cpp:20506)
20496    if (min_result.getElementAt({0}).real() != 2.0 || min_result.getElementAt({0}).imag() != 1.0) {
20497        throw std::runtime_error("min() tie-breaking failed: expected (2,1)");
20498    }
20499    if (max_result.getElementAt({0}).real() != 2.0 || max_result.getElementAt({0}).imag() != 5.0) {
20500        throw std::runtime_error("max() tie-breaking failed: expected (2,5)");
20501    }
20502    std::cout << "PASSED\n";
20503}
20504
20505void test_argmin_complex128() {
20506    std::cout << "  Testing argmin() with complex128... ";
20507    numpy::NDArray<complex128> arr({3});
20508    arr.setElementAt({0}, complex128(3.0, 1.0));  // index 0
20509    arr.setElementAt({1}, complex128(1.0, 5.0));  // index 1 - smallest
20510    arr.setElementAt({2}, complex128(2.0, 2.0));  // index 2
20511
20512    auto result = numpy::argmin(arr);
20513    // Should return 1 (index of (1,5))
20514    if (result.getElementAt({0}) != 1) {
20515        throw std::runtime_error("argmin() failed: expected index 1");
20516    }
axes (np_test_5_all.cpp:16631)
16621        return 0;
16622    } else {
16623        std::cout << "  [FAIL] reshape() failed" << std::endl;
16624        return 1;
16625    }
16626}
16627
16628// Test 15: transpose() - Transpose array (SKIPPED - needs implementation)
16629int test_transpose() {
16630    std::cout << "\n[TEST] ma.transpose() - SKIPPED (needs correct transpose API)" << std::endl;
16631    return 0;  // Skip for now
16632}
16633
16634// Test 16: swapaxes() - Swap two axes (SKIPPED - needs implementation)
16635int test_swapaxes() {
16636    std::cout << "\n[TEST] ma.swapaxes() - SKIPPED (needs correct swapaxes API)" << std::endl;
16637    return 0;  // Skip for now
16638}
16639
16640// Test 17: repeat() - Repeat elements
16641int test_repeat() {
between (np_test_4_all.cpp:19254)
19244    }
19245
19246    numpy::NDArray<double> x({3});
19247    double* x_data = x.data();
19248    x_data[0] = 0.5; x_data[1] = 1.5; x_data[2] = 2.5;
19249
19250    numpy::NDArray<double> result = numpy::interp(x, xp, fp);
19251    const double* result_data = result.data();
19252
19253    // Linear interpolation results (not exact function values):
19254    // x=0.5: interpolate between (0,0) and (1,1) → 0.5
19255    // x=1.5: interpolate between (1,1) and (2,4) → 2.5
19256    // x=2.5: interpolate between (2,4) and (3,9) → 6.5
19257    if (!(is_close(result_data[0], 0.5))) {
19258        std::string description = std::string("test_interp_array():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(is_close(result_data[0], 0.5))";
19259        std::cout << std::string("[FAIL] ") + description << std::endl;
19260        throw std::runtime_error(description);
19261    }
19262    if (!(is_close(result_data[1], 2.5))) {
19263        std::string description = std::string("test_interp_array():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(is_close(result_data[1], 2.5))";
19264        std::cout << std::string("[FAIL] ") + description << std::endl;
bool_ (np_test_3_all.cpp:15233)
15223      std::cout << "========= test_where_selection ====";
15224
15225      // Create condition, x, and y arrays
15226      auto cond_data = createBoolArray({ 4 }, false);
15227      cond_data.setElementAt({ 0 }, true);
15228      cond_data.setElementAt({ 1 }, false);
15229      cond_data.setElementAt({ 2 }, true);
15230      cond_data.setElementAt({ 3 }, false);
15231
15232      auto cond_mask = createBoolArray({ 4 }, false);
15233      MaskedArray<bool_> condition(cond_data, cond_mask, bool_(false));
15234
15235      auto x_data = createInt32Array({ 4 }, 0);
15236      x_data.setElementAt({ 0 }, 10);
15237      x_data.setElementAt({ 1 }, 20);
15238      x_data.setElementAt({ 2 }, 30);
15239      x_data.setElementAt({ 3 }, 40);
15240
15241      auto x_mask = createBoolArray({ 4 }, false);
15242      MaskedArray<int32> x(x_data, x_mask, -999);
clip (np_test_1_all.cpp:15142)
15132      numpy::NDArray<double> values({ 5 });
15133      values.setElementAt({ 0 }, -2.0);
15134      values.setElementAt({ 1 }, -1.0);
15135      values.setElementAt({ 2 }, 0.5);
15136      values.setElementAt({ 3 }, 2.0);
15137      values.setElementAt({ 4 }, 5.0);
15138      double min_val = -1.0;
15139      double max_val = 3.0;
15140
15141      auto clip_result = numpy::clip(values, min_val, max_val);
15142
15143      bool test8_pass = true;
15144      if (std::abs(clip_result.getElementAt({ 0 }) - (-1.0)) > 1e-10 ||
15145        std::abs(clip_result.getElementAt({ 3 }) - 2.0) > 1e-10 ||
15146        std::abs(clip_result.getElementAt({ 4 }) - 3.0) > 1e-10) {
15147        test8_pass = false;
15148      }
15149
15150      if (test8_pass) {
15151        // std::cout << "[OK] Clip function works correctly";
clone (np_test_1_all.cpp:24942)
24932      }
24933
24934      // Test reproducibility
24935      numpy::random::PCG64DXSM rng2(11111);
24936      if (rng2.next_uint64() != val) {
24937        std::cout << "  [FAIL] : in np_test_bitgen_pcg64dxsm() : not reproducible";
24938        throw std::runtime_error("np_test_bitgen_pcg64dxsm failed");
24939      }
24940
24941      // Test clone
24942      auto cloned = rng.clone();
24943      if (cloned->name() != "PCG64DXSM") {
24944        std::cout << "  [FAIL] : in np_test_bitgen_pcg64dxsm() : clone name incorrect";
24945        throw std::runtime_error("np_test_bitgen_pcg64dxsm failed");
24946      }
24947
24948      std::cout << " -> tests passed" << std::endl;
24949    }
24950
24951    // ============================================================================
24952    // PHILOX TESTS
count (np_test_1_all.cpp:3616)
3606    // Create larger arrays for performance testing
3607    auto large_arr = NDArray<double>::createOnes({100, 100});
3608    auto broadcast_arr = NDArray<double>::createOnes({1, 100});
3609
3610    // Time the operation (basic timing)
3611    auto start = std::chrono::high_resolution_clock::now();
3612    auto result = large_arr.addArrays(broadcast_arr);
3613    auto end = std::chrono::high_resolution_clock::now();
3614
3615    auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
3616    // std::cout << "Large array broadcasting took " << duration.count() << " microseconds" << std::endl;
3617
3618    // Verify result shape
3619    if (!((result.getShape() == std::vector<size_t>{100, 100}))) {
3620        std::string description = std::string("test_broadcasting_performance():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((result.getShape() == std::vector<size_t>{100, 100}))";
3621        std::cout << std::string("[FAIL] ") + description << std::endl;
3622        throw std::runtime_error(description);
3623    }
3624    if (!(result.getElementAt({50, 50}) == 2.0)) {
3625        std::string description = std::string("test_broadcasting_performance():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({50, 50}) == 2.0)";
3626        std::cout << std::string("[FAIL] ") + description << std::endl;
cumprod (np_test_5_all.cpp:5107)
5097    }
5098
5099    void np_test_cumprod_1d() {
5100      std::cout << "========= cumprod 1D =======================";
5101
5102      // Test cumprod with 1D array
5103      numpy::NDArray<int32_t> arr({ 5 });
5104      arr.setElementAt({ 0 }, 1);
5105      arr.setElementAt({ 1 }, 2);
5106      arr.setElementAt({ 2 }, 3);
5107      arr.setElementAt({ 3 }, 4);
5108      arr.setElementAt({ 4 }, 5);
5109
5110      auto result = numpy::cumprod(arr);
5111
5112      // Expected: [1, 2, 6, 24, 120]
5113      if (result.getElementAt({ 0 }) != 1 || result.getElementAt({ 1 }) != 2 ||
5114        result.getElementAt({ 2 }) != 6 || result.getElementAt({ 3 }) != 24 ||
5115        result.getElementAt({ 4 }) != 120) {
5116        std::cout << "  [FAIL] : in np_test_cumprod_1d() : Incorrect cumprod result";
5117        throw std::runtime_error("Test failed");
cumsum (np_test_5_all.cpp:5028)
5018  namespace numpy_tests_cumulative_operations {
5019
5020    void np_test_cumsum_1d() {
5021      std::cout << "========= cumsum 1D =======================";
5022
5023      // Test cumsum with 1D array
5024      numpy::NDArray<int32_t> arr({ 5 });
5025      arr.setElementAt({ 0 }, 1);
5026      arr.setElementAt({ 1 }, 2);
5027      arr.setElementAt({ 2 }, 3);
5028      arr.setElementAt({ 3 }, 4);
5029      arr.setElementAt({ 4 }, 5);
5030
5031      auto result = numpy::cumsum(arr);
5032
5033      // Expected: [1, 3, 6, 10, 15]
5034      if (result.getElementAt({ 0 }) != 1 || result.getElementAt({ 1 }) != 3 ||
5035        result.getElementAt({ 2 }) != 6 || result.getElementAt({ 3 }) != 10 ||
5036        result.getElementAt({ 4 }) != 15) {
5037        std::cout << "  [FAIL] : in np_test_cumsum_1d() : Incorrect cumsum result";
5038        throw std::runtime_error("Test failed");
describe (np_test_1_all.cpp:11448)
11438    auto moment2_result = moment(normal_data, 2);
11439    // std::cout << "2nd moment: " << moment2_result.getElementAt({ 0 }) << std::endl;
11440    if (!(moment2_result.getElementAt({ 0 }) > 0)) {
11441        std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(moment2_result.getElementAt({ 0 }) > 0)";
11442        std::cout << std::string("[FAIL] ") + description << std::endl;
11443        throw std::runtime_error(description);
11444    }
11445    // std::cout << "[OK] Moment calculation\n";
11446
11447    // Test describe
11448    auto desc_result = describe(normal_data);
11449    // std::cout << "Describe result:" << std::endl;
11450    // std::cout << "  nobs: " << desc_result.nobs << std::endl;
11451    // std::cout << "  min: " << desc_result.minmax.first << ", max: " << desc_result.minmax.second << std::endl;
11452    // std::cout << "  mean: " << desc_result.mean << std::endl;
11453    // std::cout << "  variance: " << desc_result.variance << std::endl;
11454    if (!(desc_result.nobs == 5)) {
11455        std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(desc_result.nobs == 5)";
11456        std::cout << std::string("[FAIL] ") + description << std::endl;
11457        throw std::runtime_error(description);
11458    }
diff (np_test_2_all.cpp:4947)
4937      // Test matrix addition and subtraction
4938      numpy::Matrix<double> a("1 2; 3 4");
4939      numpy::Matrix<double> b("5 6; 7 8");
4940
4941      auto sum = a + b;
4942      assert_test(std::abs(sum(0, 0) - 6.0) < 1e-10, "Matrix addition");
4943      assert_test(std::abs(sum(1, 1) - 12.0) < 1e-10, "Matrix addition");
4944
4945      auto diff = b - a;
4946      assert_test(std::abs(diff(0, 0) - 4.0) < 1e-10, "Matrix subtraction");
4947      assert_test(std::abs(diff(1, 1) - 4.0) < 1e-10, "Matrix subtraction");
4948
4949      // Test matrix multiplication (not element-wise!)
4950      auto product = a * b;
4951      assert_test(std::abs(product(0, 0) - 19.0) < 1e-10, "Matrix multiplication 0,0");
4952      assert_test(std::abs(product(0, 1) - 22.0) < 1e-10, "Matrix multiplication 0,1");
4953      assert_test(std::abs(product(1, 0) - 43.0) < 1e-10, "Matrix multiplication 1,0");
4954      assert_test(std::abs(product(1, 1) - 50.0) < 1e-10, "Matrix multiplication 1,1");
4955
4956      // Test scalar multiplication
divmod (np_test_1_all.cpp:21140)
21130    auto a = NDArray<float64>({ 3 });
21131    a.setElementAt({ 0 }, 7.0);
21132    a.setElementAt({ 1 }, -7.0);
21133    a.setElementAt({ 2 }, 7.5);
21134
21135    auto b = NDArray<float64>({ 3 });
21136    b.setElementAt({ 0 }, 3.0);
21137    b.setElementAt({ 1 }, 3.0);
21138    b.setElementAt({ 2 }, 2.0);
21139
21140    auto [quotient, remainder] = divmod(a, b);
21141
21142    if (!(quotient.getElementAt({ 0 }) == 2.0)) {
21143        std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quotient.getElementAt({ 0 }) == 2.0)";
21144        std::cout << std::string("[FAIL] ") + description << std::endl;
21145        throw std::runtime_error(description);
21146    }
21147    if (!(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)) {
21148        std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)";
21149        std::cout << std::string("[FAIL] ") + description << std::endl;
21150        throw std::runtime_error(description);
divmod (np_test_1_all.cpp:21140)
21130    auto a = NDArray<float64>({ 3 });
21131    a.setElementAt({ 0 }, 7.0);
21132    a.setElementAt({ 1 }, -7.0);
21133    a.setElementAt({ 2 }, 7.5);
21134
21135    auto b = NDArray<float64>({ 3 });
21136    b.setElementAt({ 0 }, 3.0);
21137    b.setElementAt({ 1 }, 3.0);
21138    b.setElementAt({ 2 }, 2.0);
21139
21140    auto [quotient, remainder] = divmod(a, b);
21141
21142    if (!(quotient.getElementAt({ 0 }) == 2.0)) {
21143        std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(quotient.getElementAt({ 0 }) == 2.0)";
21144        std::cout << std::string("[FAIL] ") + description << std::endl;
21145        throw std::runtime_error(description);
21146    }
21147    if (!(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)) {
21148        std::string description = std::string("testDivmodFunction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(remainder.getElementAt({ 0 }) - 1.0) < 1e-10)";
21149        std::cout << std::string("[FAIL] ") + description << std::endl;
21150        throw std::runtime_error(description);
dtype_name (np_test_2_all.cpp:3567)
3557          std::cout << std::string("[FAIL] ") + description << std::endl;
3558          throw std::runtime_error(description);
3559      }
3560      if (!(flags_info.writeable == true)) {
3561          std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(flags_info.writeable == true)";
3562          std::cout << std::string("[FAIL] ") + description << std::endl;
3563          throw std::runtime_error(description);
3564      }
3565
3566      // Test dtype functions
3567      if (!(dtype_name(arr) == "float64")) {
3568          std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(dtype_name(arr) == \"float64\")";
3569          std::cout << std::string("[FAIL] ") + description << std::endl;
3570          throw std::runtime_error(description);
3571      }
3572      if (!(dtype_itemsize(arr) == sizeof(double))) {
3573          std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(dtype_itemsize(arr) == sizeof(double))";
3574          std::cout << std::string("[FAIL] ") + description << std::endl;
3575          throw std::runtime_error(description);
3576      }
file (np_test_1_all.cpp:27026)
27016      }
27017
27018      // Test with filename
27019      size_t size1 = io::get_remaining_size(test_filename);
27020      if (size1 != 100) {
27021        std::cout << "  [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022        throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023      }
27024
27025      // Test with file stream
27026      std::ifstream file(test_filename, std::ios::binary);
27027      file.seekg(30);  // Move to position 30
27028      size_t size2 = io::get_remaining_size(file);
27029      if (size2 != 70) {
27030        std::cout << "  [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031        throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032      }
27033
27034      // Verify position preserved
27035      auto pos = file.tellg();
27036      if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016      }
27017
27018      // Test with filename
27019      size_t size1 = io::get_remaining_size(test_filename);
27020      if (size1 != 100) {
27021        std::cout << "  [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022        throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023      }
27024
27025      // Test with file stream
27026      std::ifstream file(test_filename, std::ios::binary);
27027      file.seekg(30);  // Move to position 30
27028      size_t size2 = io::get_remaining_size(file);
27029      if (size2 != 70) {
27030        std::cout << "  [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031        throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032      }
27033
27034      // Verify position preserved
27035      auto pos = file.tellg();
27036      if (pos != 30) {
file (np_test_1_all.cpp:27026)
27016      }
27017
27018      // Test with filename
27019      size_t size1 = io::get_remaining_size(test_filename);
27020      if (size1 != 100) {
27021        std::cout << "  [FAIL] : in test_get_remaining_size() : expected 100 bytes, got " << size1;
27022        throw std::runtime_error("test_get_remaining_size failed: incorrect file size");
27023      }
27024
27025      // Test with file stream
27026      std::ifstream file(test_filename, std::ios::binary);
27027      file.seekg(30);  // Move to position 30
27028      size_t size2 = io::get_remaining_size(file);
27029      if (size2 != 70) {
27030        std::cout << "  [FAIL] : in test_get_remaining_size() : expected 70 remaining bytes, got " << size2;
27031        throw std::runtime_error("test_get_remaining_size failed: incorrect remaining size");
27032      }
27033
27034      // Verify position preserved
27035      auto pos = file.tellg();
27036      if (pos != 30) {
filter (np_test_2_all.cpp:9555)
9545      for (int i = 0; i < size; i++) {
9546        signal[i] = std::sin(2.0f * 3.14159f * i / 8.0f) + 0.1f * (i % 3 - 1);
9547      }
9548
9549      // std::cout << "Original Signal: ";
9550      for (int i = 0; i < size; i++) {
9551        // std::cout << std::setw(8) << std::fixed << std::setprecision(3) << signal[i] << " ";
9552      }
9553      // std::cout << std::endl;
9554
9555      // Apply a simple smoothing filter (moving average)
9556      const int kernel_size = 3;
9557      std::vector<Ipp32f> kernel = { 1.0f / 3.0f, 1.0f / 3.0f, 1.0f / 3.0f };
9558
9559      // For simplicity, we'll do a basic convolution manually for demonstration
9560      for (int i = 1; i < size - 1; i++) {
9561        filtered[i] = (signal[i - 1] + signal[i] + signal[i + 1]) / 3.0f;
9562      }
9563      filtered[0] = signal[0];
9564      filtered[size - 1] = signal[size - 1];
first (np_test_4_all.cpp:12410)
12400    // std::cout << "[OK] NaN-ignoring behavior tests\n";
12401}
12402
12403// Test both NaN returns first NaN
12404void test_fmax_both_nan() {
12405    std::cout << "========= test_fmax_both_nan ====";
12406
12407    double nan1 = std::numeric_limits<double>::quiet_NaN();
12408    double nan2 = std::numeric_limits<double>::quiet_NaN();
12409
12410    // If both are NaN, return first (which is still NaN)
12411    double result = numpy::fmax(nan1, nan2);
12412    if (!std::isnan(result)) {
12413        std::cout << "  [FAIL] : test_fmax_both_nan failed - fmax(NaN, NaN) should be NaN";
12414        throw std::runtime_error("fmax(NaN, NaN) should return NaN");
12415    }
12416
12417    // std::cout << "[OK] Both NaN returns NaN test\n";
12418}
12419
12420// Test type preservation
groups (np_test_3_all.cpp:12782)
12772        }
12773        if (!(arr.getElementAt({ 1, 1 }) == 40)) {
12774            std::string description = std::string("np_test_io_fromregex_complex():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr.getElementAt({ 1, 1 }) == 40)";
12775            std::cout << std::string("[FAIL] ") + description << std::endl;
12776            throw std::runtime_error(description);
12777        }
12778
12779        // std::cout << "[OK] Multiple capture groups" << std::endl;
12780      }
12781
12782      // Test 2: Mixed capture groups (would need structured array for full support)
12783      {
12784        create_test_file(filename, "data: 100, 1.5\ndata: 200, 2.5\ndata: 300, 3.5\n");
12785
12786        auto arr = fromregex<double>(filename, R"(data:\s+(\d+),\s+([\d.]+))");
12787
12788        if (!(arr.getShape()[0] == 3)) {
12789            std::string description = std::string("np_test_io_fromregex_complex():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr.getShape()[0] == 3)";
12790            std::cout << std::string("[FAIL] ") + description << std::endl;
12791            throw std::runtime_error(description);
12792        }
index (np_test_5_all.cpp:1283)
1273    // ============================================================================
1274    // SEARCH OPERATION TESTS
1275    // ============================================================================
1276
1277    void np_test_string_index() {
1278      std::cout << "========= index search operation =======================";
1279
1280      std::vector<std::string> strings = { "hello world", "tomorrow" };
1281      auto arr = numpy::char_::array<32>(strings);
1282      auto indices = numpy::char_::index(arr, "o");
1283
1284      bool passed = (indices.getSize() == arr.size());
1285
1286      if (!passed) {
1287        std::cout << "  [FAIL] : in np_test_string_index() : indices size mismatch";
1288        throw std::runtime_error("np_test_string_index failed");
1289      }
1290
1291      std::cout << " -> tests passed" << std::endl;
1292    }
info (np_test_2_all.cpp:19772)
19762    // ============================================================================
19763    // INFO TESTS (using primitive types to avoid NDArray complexities)
19764    // ============================================================================
19765
19766    void np_test_introspection_info() {
19767      std::cout << "========= info: display object information =======================";
19768
19769      // Test info on primitive type
19770      int x = 42;
19771      // std::cout << "Primitive type info:" << std::endl;
19772      numpy::introspection::info(x);
19773
19774      double y = 3.14;
19775      // std::cout << "Double type info:" << std::endl;
19776      numpy::introspection::info(y, true);
19777
19778      bool passed = true;  // Just verify no exceptions
19779
19780      if (!passed) {
19781        std::cout << "  [FAIL] : in np_test_introspection_info() : info test failed";
19782        throw std::runtime_error("np_test_introspection_info failed");
keys (np_test_2_all.cpp:8614)
8604          if (!indices.empty()) {
8605            std::cout << "   IPP empty array test:                                                                   -> [FAIL]";
8606            throw std::runtime_error("IPP empty array test: FAILED - should return empty");
8607          }
8608          // std::cout << "[OK] IPP empty array test: PASSED" << std::endl;
8609        }
8610
8611        // Test 6: Large array performance
8612        {
8613          const size_t n = 10000;
8614          std::vector<std::vector<int>> keys(2);
8615          keys[0].resize(n);
8616          keys[1].resize(n);
8617
8618          std::mt19937 gen(42);
8619          std::uniform_int_distribution<int> dist(0, 1000);
8620
8621          for (size_t i = 0; i < n; ++i) {
8622            keys[0][i] = dist(gen);
8623            keys[1][i] = dist(gen);
8624          }
kurtosis (np_test_1_all.cpp:11433)
11423    // std::cout << "Skewness of [1,2,3,4,5]: " << skew_result.getElementAt({ 0 }) << std::endl;
11424    // Should be close to 0 for symmetric data
11425    if (!(std::abs(skew_result.getElementAt({ 0 })) < 0.1)) {
11426        std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(skew_result.getElementAt({ 0 })) < 0.1)";
11427        std::cout << std::string("[FAIL] ") + description << std::endl;
11428        throw std::runtime_error(description);
11429    }
11430    // std::cout << "[OK] Skewness calculation\n";
11431
11432    // Test kurtosis
11433    auto kurt_result = kurtosis(normal_data);
11434    // std::cout << "Kurtosis of [1,2,3,4,5]: " << kurt_result.getElementAt({ 0 }) << std::endl;
11435    // std::cout << "[OK] Kurtosis calculation\n";
11436
11437    // Test moment
11438    auto moment2_result = moment(normal_data, 2);
11439    // std::cout << "2nd moment: " << moment2_result.getElementAt({ 0 }) << std::endl;
11440    if (!(moment2_result.getElementAt({ 0 }) > 0)) {
11441        std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(moment2_result.getElementAt({ 0 }) > 0)";
11442        std::cout << std::string("[FAIL] ") + description << std::endl;
11443        throw std::runtime_error(description);
mask (np_test_1_all.cpp:27691)
27681    void test_mask_rows_cols() {
27682      std::cout << "========= ma::mask_rows() and ma::mask_cols(): mask operations ===";
27683
27684      auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} });
27685      auto mask = numpy::array({ {false, true, false}, {false, false, false} });
27686      auto ma = numpy::ma::masked_array(data, mask);
27687
27688      auto result_rows = numpy::ma::mask_rows(ma);
27689      auto result_cols = numpy::ma::mask_cols(ma);
27690
27691      // std::cout << "  ma::mask_rows(): row 0 fully masked: " << (result_rows.mask().getElementAt({ 0, 0 }) ? "true" : "false") << std::endl;
27692      // std::cout << "  ma::mask_cols(): column 1 fully masked: " << (result_cols.mask().getElementAt({ 1, 1 }) ? "true" : "false");
27693      std::cout << " -> tests passed";
27694    }
27695
27696    void test_compress_rowcols() {
27697      std::cout << "========= ma::compress_rowcols(): remove masked rows/columns ===";
27698
27699      auto data = numpy::array({ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}, {7.0, 8.0, 9.0} });
27700      auto mask = numpy::array({ {false, false, false}, {false, true, false}, {false, false, false} });
27701      auto ma = numpy::ma::masked_array(data, mask);
memcpy (np_test_4_all.cpp:22178)
22168            // std::cout << "[INFO] Serialized size: " << bytes.size() << " bytes" << std::endl;
22169
22170            // Check magic number
22171            if (bytes[0] != 'N' || bytes[1] != 'D' || bytes[2] != 'A' || bytes[3] != 'R') {
22172                std::cout << "  [FAIL] : Invalid magic number";
22173                throw std::runtime_error("dumps magic number test failed");
22174            }
22175
22176            // Check version (bytes 4-7, little-endian uint32)
22177            uint32_t version;
22178            std::memcpy(&version, &bytes[4], 4);
22179            if (version != 1) {
22180                std::cout << "  [FAIL] : Invalid version: " << version;
22181                throw std::runtime_error("dumps version test failed");
22182            }
22183
22184            // Check dtype size (bytes 8-11)
22185            uint32_t dtype_size;
22186            std::memcpy(&dtype_size, &bytes[8], 4);
22187            if (dtype_size != sizeof(double)) {
22188                std::cout << "  [FAIL] : Invalid dtype size: " << dtype_size;
name (np_test_1_all.cpp:24865)
24855      uint64_t before_restore = rng.next_uint64();
24856      rng.set_state(state);
24857      uint64_t after_restore = rng.next_uint64();
24858
24859      if (before_restore != after_restore) {
24860        std::cout << "  [FAIL] : in np_test_bitgen_mt19937() : state restore failed";
24861        throw std::runtime_error("np_test_bitgen_mt19937 failed: state");
24862      }
24863
24864      // Test name
24865      if (rng.name() != "MT19937") {
24866        std::cout << "  [FAIL] : in np_test_bitgen_mt19937() : incorrect name";
24867        throw std::runtime_error("np_test_bitgen_mt19937 failed: name");
24868      }
24869
24870      std::cout << " -> tests passed" << std::endl;
24871    }
24872
24873    // ============================================================================
24874    // PCG64 TESTS
24875    // ============================================================================
nbytes (np_test_2_all.cpp:3547)
3537      }
3538
3539      // Test itemsize
3540      if (!(itemsize(arr) == sizeof(double))) {
3541          std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(itemsize(arr) == sizeof(double))";
3542          std::cout << std::string("[FAIL] ") + description << std::endl;
3543          throw std::runtime_error(description);
3544      }
3545
3546      // Test nbytes
3547      if (!(nbytes(arr) == 24 * sizeof(double))) {
3548          std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(nbytes(arr) == 24 * sizeof(double))";
3549          std::cout << std::string("[FAIL] ") + description << std::endl;
3550          throw std::runtime_error(description);
3551      }
3552
3553      // Test flags
3554      auto flags_info = flags(arr);
3555      if (!(flags_info.owndata == true)) {
3556          std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(flags_info.owndata == true)";
3557          std::cout << std::string("[FAIL] ") + description << std::endl;
ndim (np_test_2_all.cpp:3526)
3516    void testArrayInfo() {
3517      std::cout << "Testing array information functions...\n";
3518
3519      // Test basic info functions
3520      auto arr = createFloat64Array({ 2, 3, 4 });
3521      for (size_t i = 0; i < arr.getSize(); ++i) {
3522        arr.setElementAt({ i / 12, (i / 4) % 3, i % 4 }, static_cast<double>(i));
3523      }
3524
3525      // Test ndim
3526      if (!(ndim(arr) == 3)) {
3527          std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ndim(arr) == 3)";
3528          std::cout << std::string("[FAIL] ") + description << std::endl;
3529          throw std::runtime_error(description);
3530      }
3531
3532      // Test size
3533      if (!(size(arr) == 24)) {
3534          std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(size(arr) == 24)";
3535          std::cout << std::string("[FAIL] ") + description << std::endl;
3536          throw std::runtime_error(description);
pad (np_test_1_all.cpp:18733)
18723    std::cout << "========= testPadding =======================";
18724
18725    // Create test array
18726    auto array = createInt32Array({ 2, 2 }, 0);
18727    array.setElementAt({ 0, 0 }, 1);
18728    array.setElementAt({ 0, 1 }, 2);
18729    array.setElementAt({ 1, 0 }, 3);
18730    array.setElementAt({ 1, 1 }, 4);
18731
18732    // Test constant padding
18733    auto padded_const = pad(array, 1, "constant", 0);
18734    if (!(padded_const.getShape()[0] == 4)) {
18735        std::string description = std::string("testPadding():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(padded_const.getShape()[0] == 4)";
18736        std::cout << std::string("[FAIL] ") + description << std::endl;
18737        throw std::runtime_error(description);
18738    }
18739    if (!(padded_const.getShape()[1] == 4)) {
18740        std::string description = std::string("testPadding():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(padded_const.getShape()[1] == 4)";
18741        std::cout << std::string("[FAIL] ") + description << std::endl;
18742        throw std::runtime_error(description);
18743    }
pairs (np_test_2_all.cpp:8793)
8783          if (result != expected) {
8784            std::cout << "   IPP integer msort:                                                                      -> [FAIL]";
8785            throw std::runtime_error("IPP integer msort: FAILED - incorrect sorted order");
8786          }
8787          // std::cout << "[OK] IPP integer msort: PASSED" << std::endl;
8788        }
8789
8790        // Test 2: Float msort with stability test
8791        {
8792          // Test stability using pairs (value, original_index)
8793          struct TestPair {
8794            double value;
8795            int original_index;
8796            bool operator==(const TestPair& other) const {
8797              return value == other.value && original_index == other.original_index;
8798            }
8799            bool operator<(const TestPair& other) const {
8800              return value < other.value;
8801            }
8802          };
pow (np_test_1_all.cpp:15230)
15220        std::cout << "[FAIL] Broadcasting validation failed" << std::endl;
15221        errors++;
15222      }
15223
15224      // Test 11: Performance with caching
15225      std::cout << "========= test_caching_performance =======================" ;
15226
15227      int call_count = 0;
15228      auto expensive_func = [&call_count](double x) {
15229        call_count++;
15230        return std::pow(x, 3) + std::sin(x);  // Simulate expensive computation
15231        };
15232
15233      auto cached_vectorized = numpy::vectorize(expensive_func, true, 100);
15234
15235      numpy::NDArray<double> test_array({ 3 });
15236      test_array.setElementAt({ 0 }, 1.0);
15237      test_array.setElementAt({ 1 }, 2.0);
15238      test_array.setElementAt({ 2 }, 3.0);
15239
15240      // First call
pow (np_test_1_all.cpp:15230)
15220        std::cout << "[FAIL] Broadcasting validation failed" << std::endl;
15221        errors++;
15222      }
15223
15224      // Test 11: Performance with caching
15225      std::cout << "========= test_caching_performance =======================" ;
15226
15227      int call_count = 0;
15228      auto expensive_func = [&call_count](double x) {
15229        call_count++;
15230        return std::pow(x, 3) + std::sin(x);  // Simulate expensive computation
15231        };
15232
15233      auto cached_vectorized = numpy::vectorize(expensive_func, true, 100);
15234
15235      numpy::NDArray<double> test_array({ 3 });
15236      test_array.setElementAt({ 0 }, 1.0);
15237      test_array.setElementAt({ 1 }, 2.0);
15238      test_array.setElementAt({ 2 }, 3.0);
15239
15240      // First call
prod (np_test_1_all.cpp:11795)
11785        throw std::runtime_error(description);
11786    }
11787    // std::cout << "[OK] min and max work correctly\n";
11788
11789    // Test product
11790    auto small_array = createInt32Array({ 3 }, 0);
11791    small_array.setElementAt({ 0 }, 2);
11792    small_array.setElementAt({ 1 }, 3);
11793    small_array.setElementAt({ 2 }, 4);
11794
11795    auto prod_result = prod(small_array);
11796    if (!(prod_result.getElementAt({ 0 }) == 24)) {
11797        std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(prod_result.getElementAt({ 0 }) == 24)";
11798        std::cout << std::string("[FAIL] ") + description << std::endl;
11799        throw std::runtime_error(description);
11800    }
11801    // std::cout << "[OK] prod works correctly\n";
11802    std::cout << " -> tests passed" << std::endl;
11803  }
11804
11805  void testVarianceAndStandardDeviation() {
product (np_test_1_all.cpp:5362)
5352    try {
5353        auto result = array1.multiplyArrays(array2);
5354        std::cout << "[FAIL] Incompatible shape multiplication should have thrown" << std::endl;
5355    } catch (const std::invalid_argument& e) {
5356        // std::cout << "[OK] Incompatible multiplication properly throws: " << e.what();
5357    }
5358
5359    // Test incompatible dot product
5360    try {
5361        auto result = array1.dotProduct(array2);  // 2x3 * 3x2 should actually work
5362        // std::cout << "[OK] Compatible dot product (2x3 * 3x2) works" << std::endl;
5363    } catch (const std::exception& e) {
5364        std::cout << "  [FAIL] : in testIncompatibleShapesErrorExtended(): Unexpected dot product error: " << e.what();
5365        throw std::runtime_error("testIncompatibleShapesErrorExtended(): Unexpected dot product error: " + std::string(e.what()));
5366    }
5367
5368    // Test truly incompatible dot product
5369    auto array3 = createInt32Array({2, 2}, 1);
5370    try {
5371        auto result = array1.dotProduct(array3);  // 2x3 * 2x2 should fail
5372        std::cout << "[FAIL] Incompatible dot product should have thrown" << std::endl;
replace (np_test_1_all.cpp:6717)
6707    std::vector<std::string> text = {"Hello world", "The world is big", "world peace"};
6708    auto arr = array<64>(text);
6709
6710    // std::cout << "Original text:" << std::endl;
6711    for (size_t i = 0; i < arr.size(); ++i) {
6712        // std::cout << "'" << arr[i] << "'";
6713    }
6714
6715    // Test replace
6716    auto replaced = replace(arr, "world", "universe");
6717    // std::cout << "After replacing 'world' with 'universe':" << std::endl;
6718    for (size_t i = 0; i < replaced.size(); ++i) {
6719        // std::cout << "'" << replaced[i] << "'";
6720    }
6721
6722    // Test replace with count limit
6723    std::vector<std::string> repeated_text = {"test test test", "more test cases", "test everything"};
6724    auto repeated_arr = array<64>(repeated_text);
6725    auto limited_replace = replace(repeated_arr, "test", "example", 1);
replace (np_test_1_all.cpp:6717)
6707    std::vector<std::string> text = {"Hello world", "The world is big", "world peace"};
6708    auto arr = array<64>(text);
6709
6710    // std::cout << "Original text:" << std::endl;
6711    for (size_t i = 0; i < arr.size(); ++i) {
6712        // std::cout << "'" << arr[i] << "'";
6713    }
6714
6715    // Test replace
6716    auto replaced = replace(arr, "world", "universe");
6717    // std::cout << "After replacing 'world' with 'universe':" << std::endl;
6718    for (size_t i = 0; i < replaced.size(); ++i) {
6719        // std::cout << "'" << replaced[i] << "'";
6720    }
6721
6722    // Test replace with count limit
6723    std::vector<std::string> repeated_text = {"test test test", "more test cases", "test everything"};
6724    auto repeated_arr = array<64>(repeated_text);
6725    auto limited_replace = replace(repeated_arr, "test", "example", 1);
shape (np_test_1_all.cpp:3751)
3741    }
3742
3743    for (size_t j = 0; j < 3; ++j) {
3744        arr3.setElementAt({0, j}, static_cast<double>((j + 1) * 100));  // [100, 200, 300]
3745    }
3746
3747    // Broadcast all arrays together
3748    std::vector<NDArray<double>> arrays = {arr1, arr2, arr3};
3749    auto broadcasted = broadcast_arrays(arrays);
3750
3751    // All should have shape (2, 3)
3752    for (const auto& arr : broadcasted) {
3753        if (!((arr.getShape() == std::vector<size_t>{2, 3}))) {
3754            std::string description = std::string("test_broadcast_arrays():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((arr.getShape() == std::vector<size_t>{2, 3}))";
3755            std::cout << std::string("[FAIL] ") + description << std::endl;
3756            throw std::runtime_error(description);
3757        }
3758    }
3759
3760    // Check values
3761    if (!(broadcasted[0].getElementAt({0, 1}) == 2.0)) {
shift (np_test_1_all.cpp:2761)
2751        throw std::runtime_error(description);
2752    }
2753    if (!(left_array.getElementAt({3}) == 16384)) {
2754        std::string description = std::string("testBitShifts():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(left_array.getElementAt({3}) == 16384)";
2755        std::cout << std::string("[FAIL] ") + description << std::endl;
2756        throw std::runtime_error(description);
2757    }
2758
2759    // std::cout << "[OK] Left shift by array\n";
2760
2761    // Test excessive shift (should result in 0)
2762    auto excessive_left = left_shift(arr, 20); // More than 16 bits
2763    if (!(excessive_left.getElementAt({0}) == 0)) {
2764        std::string description = std::string("testBitShifts():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(excessive_left.getElementAt({0}) == 0)";
2765        std::cout << std::string("[FAIL] ") + description << std::endl;
2766        throw std::runtime_error(description);
2767    }
2768    if (!(excessive_left.getElementAt({1}) == 0)) {
2769        std::string description = std::string("testBitShifts():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(excessive_left.getElementAt({1}) == 0)";
2770        std::cout << std::string("[FAIL] ") + description << std::endl;
2771        throw std::runtime_error(description);
size (np_test_1_all.cpp:47)
37using namespace numpy;
38using namespace numpy::benchmark;
39using namespace numpy::char_;
40
41// Helper functions for array comparison tests
42namespace {
43    const double TOLERANCE = 1e-10;
44
45    bool allTrue(const NDArray<bool>& arr) {
46        std::vector<size_t> indices(arr.getShape().size(), 0);
47        do {
48            if (!arr.getElementAt(indices)) {
49                return false;
50            }
51        } while (incrementIndices(indices, arr.getShape()));
52        return true;
53    }
54
55    bool allFalse(const NDArray<bool>& arr) {
56        std::vector<size_t> indices(arr.getShape().size(), 0);
skew (np_test_1_all.cpp:11422)
11412    std::cout << "========= testDistributionShapeMeasures =======================";
11413
11414    // Test skewness with known data
11415    auto normal_data = createFloat32Array({ 5 }, 0.0f);
11416    normal_data.setElementAt({ 0 }, 1.0f);
11417    normal_data.setElementAt({ 1 }, 2.0f);
11418    normal_data.setElementAt({ 2 }, 3.0f);
11419    normal_data.setElementAt({ 3 }, 4.0f);
11420    normal_data.setElementAt({ 4 }, 5.0f);
11421
11422    auto skew_result = skew(normal_data);
11423    // std::cout << "Skewness of [1,2,3,4,5]: " << skew_result.getElementAt({ 0 }) << std::endl;
11424    // Should be close to 0 for symmetric data
11425    if (!(std::abs(skew_result.getElementAt({ 0 })) < 0.1)) {
11426        std::string description = std::string("testDistributionShapeMeasures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(skew_result.getElementAt({ 0 })) < 0.1)";
11427        std::cout << std::string("[FAIL] ") + description << std::endl;
11428        throw std::runtime_error(description);
11429    }
11430    // std::cout << "[OK] Skewness calculation\n";
11431
11432    // Test kurtosis
types (np_test_1_all.cpp:2261)
2251            std::cout << std::string("[FAIL] ") + description << std::endl;
2252            throw std::runtime_error(description);
2253        }
2254        if (!(*obj.get_as<int>() == static_cast<int>(i * 10))) {
2255            std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*obj.get_as<int>() == static_cast<int>(i * 10))";
2256            std::cout << std::string("[FAIL] ") + description << std::endl;
2257            throw std::runtime_error(description);
2258        }
2259    }
2260
2261    // Test 5: Arrays with all different types (heterogeneous)
2262    NDArray<object_> hetero_array = createMixedObjectArray({
2263        object_(42),
2264        object_(3.14),
2265        object_(std::string("text")),
2266        object_(true),
2267        object_(NDArray<double>({2}, 1.5))
2268    });
2269
2270    if (!(hetero_array.getSize() == 5)) {
2271        std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(hetero_array.getSize() == 5)";
tz_convert (np_test_5_all.cpp:22899)
22889      if (floored_h.hour() != 14 || floored_h.minute() != 0 || floored_h.second() != 0) {
22890        pass = false;
22891        fail_msg = "floor to hour failed";
22892      }
22893
22894      // ceil to hour
22895      numpy::Timestamp ceiled_h = ts.ceil("h");
22896      if (ceiled_h.hour() != 15 || ceiled_h.minute() != 0) {
22897        pass = false;
22898        fail_msg = "ceil to hour failed";
22899      }
22900
22901      // round to hour (37 minutes -> round up)
22902      numpy::Timestamp rounded_h = ts.round("h");
22903      if (rounded_h.hour() != 15) {
22904        pass = false;
22905        fail_msg = "round to hour should be 15 (37 > 30)";
22906      }
22907
22908      // normalize (floor to day)
22909      numpy::Timestamp normalized = ts.normalize();
tz_localize (np_test_5_all.cpp:22892)
22882      auto pass = true;
22883      std::string fail_msg;
22884
22885      numpy::Timestamp ts(2024, 6, 15, 14, 37, 45, 123456);
22886
22887      // floor to hour
22888      numpy::Timestamp floored_h = ts.floor("h");
22889      if (floored_h.hour() != 14 || floored_h.minute() != 0 || floored_h.second() != 0) {
22890        pass = false;
22891        fail_msg = "floor to hour failed";
22892      }
22893
22894      // ceil to hour
22895      numpy::Timestamp ceiled_h = ts.ceil("h");
22896      if (ceiled_h.hour() != 15 || ceiled_h.minute() != 0) {
22897        pass = false;
22898        fail_msg = "ceil to hour failed";
22899      }
22900
22901      // round to hour (37 minutes -> round up)
22902      numpy::Timestamp rounded_h = ts.round("h");
values (np_test_1_all.cpp:15133)
15123        std::cout << " -> tests passed" << std::endl;
15124      }
15125      else {
15126        std::cout << "[FAIL] Where function failed" << std::endl;
15127        errors++;
15128      }
15129
15130      // Test 8: Clip function
15131      std::cout << "========= test_clip_function =======================" ;
15132
15133      numpy::NDArray<double> values({ 5 });
15134      values.setElementAt({ 0 }, -2.0);
15135      values.setElementAt({ 1 }, -1.0);
15136      values.setElementAt({ 2 }, 0.5);
15137      values.setElementAt({ 3 }, 2.0);
15138      values.setElementAt({ 4 }, 5.0);
15139      double min_val = -1.0;
15140      double max_val = 3.0;
15141
15142      auto clip_result = numpy::clip(values, min_val, max_val);
values (np_test_1_all.cpp:15133)
15123        std::cout << " -> tests passed" << std::endl;
15124      }
15125      else {
15126        std::cout << "[FAIL] Where function failed" << std::endl;
15127        errors++;
15128      }
15129
15130      // Test 8: Clip function
15131      std::cout << "========= test_clip_function =======================" ;
15132
15133      numpy::NDArray<double> values({ 5 });
15134      values.setElementAt({ 0 }, -2.0);
15135      values.setElementAt({ 1 }, -1.0);
15136      values.setElementAt({ 2 }, 0.5);
15137      values.setElementAt({ 3 }, 2.0);
15138      values.setElementAt({ 4 }, 5.0);
15139      double min_val = -1.0;
15140      double max_val = 3.0;
15141
15142      auto clip_result = numpy::clip(values, min_val, max_val);