ExtensionIndex#

class numpy::ExtensionIndex#

numpy C++ class.

Example#

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

// Use ExtensionIndex
ExtensionIndex obj;
// ... operations ...

Constructors#

Signature

Location

Example

explicit ExtensionIndex(const ArrayType& array, const std::optional<std::string>& name = std::nullopt, bool copy = false)

df_extension_index.h:335

explicit ExtensionIndex(ArrayType&& array, const std::optional<std::string>& name = std::nullopt)

df_extension_index.h:346

ExtensionIndex(const ExtensionIndex& other)

df_extension_index.h:356

ExtensionIndex(ExtensionIndex&& other) noexcept = default

df_extension_index.h:370

Array Creation#

Signature

Return Type

Location

Example

bool empty() const override

bool

df_extension_index.h:408

View

Indexing / Selection#

Signature

Return Type

Location

Example

numpy::NDArray<numpy::int64> get_indexer( const ExtensionIndex<ArrayType>& target, const std::string& method = "") const

numpy::NDArray<numpy::int64>

df_extension_index.h:674

numpy::NDArray<numpy::int64> get_indexer_for( const std::vector<value_type>& values) const

numpy::NDArray<numpy::int64>

df_extension_index.h:707

std::variant<size_t, std::vector<size_t>> get_loc(const value_type& key) const

std::variant<size_t, std::vector<size_t>>

df_extension_index.h:654

int64_t get_loc_str(const std::string& key_str) const override

int64_t

df_extension_index.h:510

std::string get_value_str(size_t index) const override

std::string

df_extension_index.h:543

oss << get_value_str(i)

oss <<

df_extension_index.h:574

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

ExtensionIndex

df_extension_index.h:788

View

ExtensionIndex take_impl(const std::vector<size_t>& indices) const

ExtensionIndex

df_extension_index.h:1452

Sorting#

Signature

Return Type

Location

Example

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

numpy::NDArray<numpy::int64>

df_extension_index.h:1279

View

ExtensionIndex sort_values(bool ascending = true) const

ExtensionIndex

df_extension_index.h:1317

Linear Algebra#

Signature

Return Type

Location

Example

void invalidate_caches() const

void

df_extension_index.h:195

Comparison#

Signature

Return Type

Location

Example

bool equals(const ExtensionIndex& other) const

bool

df_extension_index.h:1372

Set Operations#

Signature

Return Type

Location

Example

numpy::NDArray<numpy::bool\_> isin(const std::vector<value_type>& values) const

numpy::NDArray<numpy::bool_>

df_extension_index.h:807

View

ExtensionIndex unique() const

ExtensionIndex

df_extension_index.h:901

View

I/O#

Signature

Return Type

Location

Example

std::vector<std::optional<value_type>> to_list() const

std::vector<std::optional<value_type>>

df_extension_index.h:625

std::string to_string() const override

std::string

df_extension_index.h:567

View

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

std::vector<std::string>

df_extension_index.h:531

Joining / Splitting#

Signature

Return Type

Location

Example

ExtensionIndex append(const ExtensionIndex& other) const

ExtensionIndex

df_extension_index.h:1107

View

ExtensionIndex delete\_(size_t loc) const

ExtensionIndex

df_extension_index.h:847

View

ExtensionIndex delete\_(const std::vector<size_t>& locs) const

ExtensionIndex

df_extension_index.h:865

View

Type Handling#

Signature

Return Type

Location

Example

ExtensionIndex copy() const

ExtensionIndex

df_extension_index.h:885

View

Type Checking#

Signature

Return Type

Location

Example

bool is_monotonic_decreasing() const

bool

df_extension_index.h:1265

bool is_monotonic_increasing() const

bool

df_extension_index.h:1255

bool is_unique() const override

bool

df_extension_index.h:466

View

Other Methods#

Signature

Return Type

Location

Example

const ArrayType& array() const

const ArrayType&

df_extension_index.h:618

View

void build_hash_table() const

void

df_extension_index.h:208

size_t cache_memory_usage() const override

size_t

df_extension_index.h:1431

void clear_cache() const override

void

df_extension_index.h:1409

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

std::unique_ptr<IndexBase>

df_extension_index.h:560

View

numpy::NDArray<numpy::int64> codes(std::vector<size_t>

numpy::NDArray<numpy::int64>

df_extension_index.h:1069

void compute_monotonicity() const

void

df_extension_index.h:280

bool contains(const value_type& key) const

bool

df_extension_index.h:643

View

bool contains_str(const std::string& key_str) const override

bool

df_extension_index.h:498

value_type convert_from_string(const std::string& str) const

value_type

df_extension_index.h:235

std::string convert_to_string(const value_type& val) const

std::string

df_extension_index.h:259

ExtensionIndex difference(const ExtensionIndex& other, bool sort = true) const

ExtensionIndex

df_extension_index.h:1208

View

ExtensionIndex drop(const std::vector<value_type>& labels) const

ExtensionIndex

df_extension_index.h:826

ExtensionIndex drop_duplicates(const std::string& keep = "first") const

ExtensionIndex

df_extension_index.h:925

ExtensionIndex dropna() const

ExtensionIndex

df_extension_index.h:777

std::string dtype_name() const override

std::string

df_extension_index.h:422

View

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

numpy::NDArray<numpy::bool_>

df_extension_index.h:974

void ensure_hash_table() const

void

df_extension_index.h:226

std::pair<numpy::NDArray<numpy::int64>, ExtensionIndex> factorize() const

std::pair<numpy::NDArray<numpy::int64>, ExtensionIndex>

df_extension_index.h:1066

ExtensionIndex fillna(const value_type& value) const

ExtensionIndex

df_extension_index.h:769

bool has_cached_values() const override

bool

df_extension_index.h:1418

bool has_duplicates() const override

bool

df_extension_index.h:484

bool hasnans() const

bool

df_extension_index.h:760

bool identical(const ExtensionIndex& other) const

bool

df_extension_index.h:1395

std::string inferred_type() const override

std::string

df_extension_index.h:443

ExtensionIndex intersection(const ExtensionIndex& other, bool sort = false) const

ExtensionIndex

df_extension_index.h:1115

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

numpy::NDArray<numpy::bool_>

df_extension_index.h:732

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

numpy::NDArray<numpy::bool_>

df_extension_index.h:739

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

std::optional<std::string>

df_extension_index.h:429

View

size_t nbytes() const override

size_t

df_extension_index.h:415

View

ArrayType new_array(values)

ArrayType

df_extension_index.h:1470

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

numpy::NDArray<numpy::bool_>

df_extension_index.h:746

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

numpy::NDArray<numpy::bool_>

df_extension_index.h:753

size_t nunique(bool dropna = true) const

size_t

df_extension_index.h:1033

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

ExtensionIndex

df_extension_index.h:892

std::string repr() const override

std::string

df_extension_index.h:593

ExtensionIndex result(\*this)

ExtensionIndex

df_extension_index.h:893

View

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

void

df_extension_index.h:436

size_t size() const override

size_t

df_extension_index.h:401

View

ExtensionIndex symmetric_difference(const ExtensionIndex& other, bool sort = false) const

ExtensionIndex

df_extension_index.h:1236

ExtensionIndex union\_(const ExtensionIndex& other, bool sort = false) const

ExtensionIndex

df_extension_index.h:1148

std::pair<std::vector<value_type>, std::vector<int64_t>> value_counts( bool dropna = true) const

std::pair<std::vector<value_type>, std::vector<int64_t>>

df_extension_index.h:1047

ArrayType values() const

ArrayType

df_extension_index.h:611

View

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}
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      }
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;
isin (np_test_1_all.cpp:19434)
19424        std::cout << std::string("[FAIL] ") + description << std::endl;
19425        throw std::runtime_error(description);
19426    }
19427    if (!(membership.getElementAt({ 5 }) == false)) {
19428        std::string description = std::string("testMembershipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(membership.getElementAt({ 5 }) == false)";
19429        std::cout << std::string("[FAIL] ") + description << std::endl;
19430        throw std::runtime_error(description);
19431    }
19432    // std::cout << "[OK] Membership testing (in1d) works correctly\n";
19433
19434    // Test isin (alias for in1d)
19435    auto isin_result = isin(test_array, test_values);
19436
19437    // Should be identical to in1d result
19438    for (size_t i = 0; i < membership.getSize(); ++i) {
19439      if (!(isin_result.getElementAt({ i }) == membership.getElementAt({ i }))) {
19440          std::string description = std::string("testMembershipOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(isin_result.getElementAt({ i }) == membership.getElementAt({ i }))";
19441          std::cout << std::string("[FAIL] ") + description << std::endl;
19442          throw std::runtime_error(description);
19443      }
19444    }
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_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)";
append (np_test_2_all.cpp:7028)
7018          throw std::runtime_error(description);
7019      }
7020      if (!(deleted_dups.getElementAt({ 2 }) == 3)) {
7021          std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(deleted_dups.getElementAt({ 2 }) == 3)";
7022          std::cout << std::string("[FAIL] ") + description << std::endl;
7023          throw std::runtime_error(description);
7024      }
7025      // std::cout << "[OK] Delete with duplicate indices works correctly\n";
7026
7027      // Test append
7028      auto appended = append(array, 100);
7029      if (!(appended.getSize() == array.getSize() + 1)) {
7030          std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(appended.getSize() == array.getSize() + 1)";
7031          std::cout << std::string("[FAIL] ") + description << std::endl;
7032          throw std::runtime_error(description);
7033      }
7034      if (!(appended.getElementAt({ appended.getSize() - 1 }) == 100)) {
7035          std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(appended.getElementAt({ appended.getSize() - 1 }) == 100)";
7036          std::cout << std::string("[FAIL] ") + description << std::endl;
7037          throw std::runtime_error(description);
7038      }
delete_ (np_test_4_all.cpp:18411)
18401    }
18402
18403    // ============================================================================
18404    // SPRINT 1.2: ESSENTIAL OPERATIONS TESTS
18405    // ============================================================================
18406
18407    void np_test_phase1_delete() {
18408      std::cout << "========= delete_: element deletion ====";
18409
18410      auto arr = numpy::array({10, 20, 30, 40, 50});
18411      auto result = numpy::delete_(arr, 2);  // Delete index 2 (value 30)
18412
18413      // Verify size reduced
18414      if (result.getSize() != 4) {
18415        std::cout << "  [FAIL] : delete_ result size is " << result.getSize() << ", expected 4\n";
18416        throw std::runtime_error("delete_ failed: wrong size");
18417      }
18418
18419      // Verify correct element was removed
18420      if (result.getElementAt({0}) != 10 || result.getElementAt({1}) != 20 ||
18421          result.getElementAt({2}) != 40 || result.getElementAt({3}) != 50) {
delete_ (np_test_4_all.cpp:18411)
18401    }
18402
18403    // ============================================================================
18404    // SPRINT 1.2: ESSENTIAL OPERATIONS TESTS
18405    // ============================================================================
18406
18407    void np_test_phase1_delete() {
18408      std::cout << "========= delete_: element deletion ====";
18409
18410      auto arr = numpy::array({10, 20, 30, 40, 50});
18411      auto result = numpy::delete_(arr, 2);  // Delete index 2 (value 30)
18412
18413      // Verify size reduced
18414      if (result.getSize() != 4) {
18415        std::cout << "  [FAIL] : delete_ result size is " << result.getSize() << ", expected 4\n";
18416        throw std::runtime_error("delete_ failed: wrong size");
18417      }
18418
18419      // Verify correct element was removed
18420      if (result.getElementAt({0}) != 10 || result.getElementAt({1}) != 20 ||
18421          result.getElementAt({2}) != 40 || result.getElementAt({3}) != 50) {
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;
is_unique (np_test_1_all.cpp:19676)
19666    unique_array.setElementAt({ 1 }, 2);
19667    unique_array.setElementAt({ 2 }, 3);
19668    unique_array.setElementAt({ 3 }, 4);
19669
19670    auto duplicate_array = createInt32Array({ 4 }, 0);
19671    duplicate_array.setElementAt({ 0 }, 1);
19672    duplicate_array.setElementAt({ 1 }, 2);
19673    duplicate_array.setElementAt({ 2 }, 2);  // Duplicate
19674    duplicate_array.setElementAt({ 3 }, 4);
19675
19676    if (!(set_ops::is_unique(unique_array) == true)) {
19677        std::string description = std::string("testUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(set_ops::is_unique(unique_array) == true)";
19678        std::cout << std::string("[FAIL] ") + description << std::endl;
19679        throw std::runtime_error(description);
19680    }
19681    if (!(set_ops::is_unique(duplicate_array) == false)) {
19682        std::string description = std::string("testUtilityFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(set_ops::is_unique(duplicate_array) == false)";
19683        std::cout << std::string("[FAIL] ") + description << std::endl;
19684        throw std::runtime_error(description);
19685    }
19686    // std::cout << "[OK] is_unique function works correctly\n";
array (np_test_1_all.cpp:243)
233    // std::cout << "Min: " << array.minArray() << std::endl;
234    // std::cout << "Max: " << array.maxArray() << std::endl;
235
236    std::cout << " -> tests passed" << std::endl;
237}
238
239void testReshapeAndFlatten() {
240    std::cout << "========= testReshapeAndFlatten =======================";
241
242    auto range_array = NDArray<int32>::createRange(0, 12, 1);
243    // std::cout << "Range array (0-11):" << std::endl;
244    //range_array.printArray();
245
246    auto reshaped = range_array.reshapeArray({3, 4});
247    // std::cout << "Reshaped to 3x4:";
248    //reshaped.printArray();
249
250    auto flattened = reshaped.flattenArray();
251    // std::cout << "Flattened:" << std::endl;
252    //flattened.printArray();
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
contains (np_test_2_all.cpp:10521)
10511      auto npz_file = load_npz(TEMP_DIR + "test_multiple.npz");
10512
10513      // Verify keys
10514      auto keys = npz_file.keys();
10515      if (!(keys.size() == 3)) {
10516          std::string description = std::string("testNPZOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(keys.size() == 3)";
10517          std::cout << std::string("[FAIL] ") + description << std::endl;
10518          throw std::runtime_error(description);
10519      }
10520      if (!(npz_file.contains("integers"))) {
10521          std::string description = std::string("testNPZOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(npz_file.contains(\"integers\"))";
10522          std::cout << std::string("[FAIL] ") + description << std::endl;
10523          throw std::runtime_error(description);
10524      }
10525      if (!(npz_file.contains("floats"))) {
10526          std::string description = std::string("testNPZOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(npz_file.contains(\"floats\"))";
10527          std::cout << std::string("[FAIL] ") + description << std::endl;
10528          throw std::runtime_error(description);
10529      }
10530      if (!(npz_file.contains("complex_nums"))) {
difference (np_test_1_all.cpp:19333)
19323        std::cout << std::string("[FAIL] ") + description << std::endl;
19324        throw std::runtime_error(description);
19325    }
19326    if (!(difference.getElementAt({ 2 }) == 5)) {
19327        std::string description = std::string("testSetDifferenceOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(difference.getElementAt({ 2 }) == 5)";
19328        std::cout << std::string("[FAIL] ") + description << std::endl;
19329        throw std::runtime_error(description);
19330    }
19331    // std::cout << "[OK] Set difference works correctly\n";
19332
19333    // Test symmetric difference (XOR)
19334    auto xor_result = setxor1d(arr1, arr2);
19335
19336    if (!(xor_result.getSize() == 4)) {
19337        std::string description = std::string("testSetDifferenceOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(xor_result.getSize() == 4)";
19338        std::cout << std::string("[FAIL] ") + description << std::endl;
19339        throw std::runtime_error(description);
19340    }
19341    if (!(xor_result.getElementAt({ 0 }) == 1)) {
19342        std::string description = std::string("testSetDifferenceOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(xor_result.getElementAt({ 0 }) == 1)";
19343        std::cout << std::string("[FAIL] ") + description << std::endl;
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      }
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;
result (np_test_1_all.cpp:6090)
6080        throw std::runtime_error(description);
6081    }
6082    // std::cout << "Timer restart test passed. Second: " << second_elapsed << " ms" << std::endl;
6083
6084    std::cout << " -> tests passed" << std::endl;
6085}
6086
6087void test_benchmark_result_storageBenchmarkSorting() {
6088    std::cout << "========= test_benchmark_result_storage =======================";
6089
6090    BenchmarkResult result("TestAlgorithm", 1000, 15.5, true, 4096);
6091
6092    if (!(result.algorithm_name == "TestAlgorithm")) {
6093        std::string description = std::string("test_benchmark_result_storageBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.algorithm_name == \"TestAlgorithm\")";
6094        std::cout << std::string("[FAIL] ") + description << std::endl;
6095        throw std::runtime_error(description);
6096    }
6097    if (!(result.array_size == 1000)) {
6098        std::string description = std::string("test_benchmark_result_storageBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.array_size == 1000)";
6099        std::cout << std::string("[FAIL] ") + description << std::endl;
6100        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);
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);