IntervalArray#

class numpy::IntervalArray#

numpy C++ class.

Example#

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

// Use IntervalArray
IntervalArray obj;
// ... operations ...

Constructors#

Signature

Location

Example

IntervalArray(const numpy::NDArray<T>& left, const numpy::NDArray<T>& right, const numpy::NDArray<numpy::bool\_>& mask, IntervalClosed closed = IntervalClosed::Right, bool copy = false)

df_interval_array.h:121

IntervalArray(const numpy::NDArray<T>& left, const numpy::NDArray<T>& right, IntervalClosed closed = IntervalClosed::Right)

df_interval_array.h:141

explicit IntervalArray(const std::vector<std::optional<std::pair<T, T>>>& values, IntervalClosed closed = IntervalClosed::Right)

df_interval_array.h:158

Construction#

Signature

Return Type

Location

Example

static IntervalArray from_arrays(const std::vector<T>& left, const std::vector<T>& right, IntervalClosed closed = IntervalClosed::Right)

static IntervalArray

df_interval_array.h:266

static IntervalArray from_arrays(const numpy::NDArray<T>& left, const numpy::NDArray<T>& right, IntervalClosed closed = IntervalClosed::Right)

static IntervalArray

df_interval_array.h:287

\* Example: from_breaks(

* Example:

df_interval_array.h:221

static IntervalArray from_breaks(const std::vector<T>& breaks, IntervalClosed closed = IntervalClosed::Right)

static IntervalArray

df_interval_array.h:227

static IntervalArray from_breaks(const numpy::NDArray<T>& breaks, IntervalClosed closed = IntervalClosed::Right)

static IntervalArray

df_interval_array.h:248

static IntervalArray from_tuples(const std::vector<std::pair<T, T>>& tuples, IntervalClosed closed = IntervalClosed::Right)

static IntervalArray

df_interval_array.h:300

Array Creation#

Signature

Return Type

Location

Example

bool empty() const

bool

df_interval_array.h:355

View

Indexing / Selection#

Signature

Return Type

Location

Example

IntervalArray take(const numpy::NDArray<numpy::int64>& indices) const

IntervalArray

df_interval_array.h:1210

View

Sorting#

Signature

Return Type

Location

Example

numpy::NDArray<numpy::int64> argsort() const

numpy::NDArray<numpy::int64>

df_interval_array.h:968

View

Set Operations#

Signature

Return Type

Location

Example

IntervalArray unique() const

IntervalArray

df_interval_array.h:1053

View

I/O#

Signature

Return Type

Location

Example

std::string to_string() const

std::string

df_interval_array.h:1180

View

std::vector<std::optional<std::pair<T, T>>> to_tuples() const

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

df_interval_array.h:841

Type Handling#

Signature

Return Type

Location

Example

IntervalArray copy() const

IntervalArray

df_interval_array.h:1312

View

Type Checking#

Signature

Return Type

Location

Example

BooleanArray is_empty() const

BooleanArray

df_interval_array.h:461

bool is_left_closed() const

bool

df_interval_array.h:383

bool is_na(size_t index) const

bool

df_interval_array.h:561

bool is_non_overlapping_monotonic() const

bool

df_interval_array.h:488

bool is_right_closed() const

bool

df_interval_array.h:390

Other Methods#

Signature

Return Type

Location

Example

numpy::int64 argmax() const

numpy::int64

df_interval_array.h:1025

View

numpy::int64 argmin() const

numpy::int64

df_interval_array.h:1001

View

IntervalClosed closed() const

IntervalClosed

df_interval_array.h:369

std::string closed_string() const

std::string

df_interval_array.h:376

static IntervalArray concat(const std::vector<IntervalArray>& arrays)

static IntervalArray

df_interval_array.h:1274

BooleanArray contains(T value) const

BooleanArray

df_interval_array.h:679

View

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

BooleanArray

df_interval_array.h:717

View

size_t count() const

size_t

df_interval_array.h:644

View

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

const numpy::NDArray<T>&

df_interval_array.h:527

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

const numpy::NDArray<T>&

df_interval_array.h:534

IntervalArray dropna() const

IntervalArray

df_interval_array.h:622

dtype_type dtype() const

dtype_type

df_interval_array.h:320

View

<< dtype().name() << "')"

<<

df_interval_array.h:1197

View

std::pair<IntegerArray<numpy::int64>, IntervalArray> factorize() const

std::pair<IntegerArray<numpy::int64>, IntervalArray>

df_interval_array.h:1107

IntervalArray fillna(const std::pair<T, T>& fill_value) const

IntervalArray

df_interval_array.h:603

bool has_na() const

bool

df_interval_array.h:657

std::string interval_to_string(size_t index) const

std::string

df_interval_array.h:1159

oss << interval_to_string(i)

oss <<

df_interval_array.h:1189

BooleanArray isna() const

BooleanArray

df_interval_array.h:576

numpy::NDArray<T> left() const

numpy::NDArray<T>

df_interval_array.h:401

View

numpy::NDArray<T> left_arr(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:234

numpy::NDArray<T> left_arr(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:273

numpy::NDArray<T> left_arr(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:302

numpy::NDArray<T> left_arr(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:1086

numpy::NDArray<T> left_arr(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:1139

size_t len() const

size_t

df_interval_array.h:362

numpy::NDArray<T> length() const

numpy::NDArray<T>

df_interval_array.h:437

View

const numpy::NDArray<numpy::bool\_>& mask() const

const numpy::NDArray<numpy::bool_>&

df_interval_array.h:541

View

numpy::NDArray<numpy::bool\_> mask_arr(std::vector<size_t>

numpy::NDArray<numpy::bool_>

df_interval_array.h:1088

FloatingArray<numpy::float64> mid() const

FloatingArray<numpy::float64>

df_interval_array.h:416

size_t nbytes() const

size_t

df_interval_array.h:334

View

constexpr int ndim() const

constexpr int

df_interval_array.h:341

View

numpy::NDArray<T> new_left(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:631

numpy::NDArray<T> new_left(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:1212

numpy::NDArray<T> new_left(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:1251

numpy::NDArray<T> new_left(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:1288

numpy::NDArray<numpy::bool\_> new_mask(std::vector<size_t>

numpy::NDArray<numpy::bool_>

df_interval_array.h:606

numpy::NDArray<numpy::bool\_> new_mask(std::vector<size_t>

numpy::NDArray<numpy::bool_>

df_interval_array.h:1214

numpy::NDArray<numpy::bool\_> new_mask(std::vector<size_t>

numpy::NDArray<numpy::bool_>

df_interval_array.h:1253

numpy::NDArray<numpy::bool\_> new_mask(std::vector<size_t>

numpy::NDArray<numpy::bool_>

df_interval_array.h:1290

numpy::NDArray<T> new_right(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:632

numpy::NDArray<T> new_right(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:1213

numpy::NDArray<T> new_right(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:1252

numpy::NDArray<T> new_right(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:1289

BooleanArray notna() const

BooleanArray

df_interval_array.h:589

BooleanArray overlaps(T other_left, T other_right, IntervalClosed other_closed) const

BooleanArray

df_interval_array.h:764

BooleanArray overlaps(T other_left, T other_right) const

BooleanArray

df_interval_array.h:812

numpy::NDArray<T> right() const

numpy::NDArray<T>

df_interval_array.h:408

View

numpy::NDArray<T> right_arr(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:235

numpy::NDArray<T> right_arr(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:274

numpy::NDArray<T> right_arr(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:303

numpy::NDArray<T> right_arr(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:1087

numpy::NDArray<T> right_arr(std::vector<size_t>

numpy::NDArray<T>

df_interval_array.h:1140

IntervalArray set_closed(IntervalClosed new_closed) const

IntervalArray

df_interval_array.h:826

IntervalArray set_closed(const std::string& new_closed) const

IntervalArray

df_interval_array.h:833

std::vector<size_t> shape() const

std::vector<size_t>

df_interval_array.h:348

View

size_t size() const

size_t

df_interval_array.h:327

View

IntervalArray slice(size_t start, size_t stop, size_t step = 1) const

IntervalArray

df_interval_array.h:1237

View

\* Encodes the array as enumerated type (codes pointing to uniques).

* Encodes the array as enumerated

df_interval_array.h:1102

View

void validate_arrays()

void

df_interval_array.h:54

void validate_bounds()

void

df_interval_array.h:81

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;
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)";
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;
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    }
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"))) {
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"))) {
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;
dtype (np_test_3_all.cpp:7942)
7932  if (info.max != expected_max) {
7933    std::cerr << "[FAIL] IInfo<uint64_t>::max mismatch";
7934    throw std::runtime_error("IInfo uint64 max test failed");
7935  }
7936  // std::cout << "[OK] IInfo<uint64_t>::max = " << info.max << std::endl;
7937
7938  std::cout << " -> tests passed" << std::endl;
7939}
7940
7941// ============================================================================
7942// dtype() Tests - DType descriptor creation
7943// ============================================================================
7944
7945void np_test_dtype_from_string_integers() {
7946  std::cout << "========= np_test_dtype_from_string_integers =======================";
7947
7948  // Test integer type strings
7949  if (dtype("int8") != DType::INT8) {
7950    std::cerr << "[FAIL] dtype(\"int8\") should return INT8";
7951    throw std::runtime_error("dtype string test failed");
7952  }
dtype (np_test_3_all.cpp:7942)
7932  if (info.max != expected_max) {
7933    std::cerr << "[FAIL] IInfo<uint64_t>::max mismatch";
7934    throw std::runtime_error("IInfo uint64 max test failed");
7935  }
7936  // std::cout << "[OK] IInfo<uint64_t>::max = " << info.max << std::endl;
7937
7938  std::cout << " -> tests passed" << std::endl;
7939}
7940
7941// ============================================================================
7942// dtype() Tests - DType descriptor creation
7943// ============================================================================
7944
7945void np_test_dtype_from_string_integers() {
7946  std::cout << "========= np_test_dtype_from_string_integers =======================";
7947
7948  // Test integer type strings
7949  if (dtype("int8") != DType::INT8) {
7950    std::cerr << "[FAIL] dtype(\"int8\") should return INT8";
7951    throw std::runtime_error("dtype string test failed");
7952  }
left (np_test_1_all.cpp:21799)
21789  }
21790
21791  void testRecFunctionsJoin() {
21792    std::cout << "========= testRecFunctionsJoin =======================";
21793
21794    auto dtype = std::make_shared<StructuredDType>(std::vector<std::pair<std::string, DType>>{
21795      {"key", DType::INT32},
21796      { "data", DType::FLOAT64 }
21797    });
21798
21799    RecordArray left(dtype, { 3 });
21800    left.setFieldValue({ 0 }, "key", static_cast<int32>(1));
21801    left.setFieldValue({ 0 }, "data", static_cast<float64>(10.0));
21802    left.setFieldValue({ 1 }, "key", static_cast<int32>(2));
21803    left.setFieldValue({ 1 }, "data", static_cast<float64>(20.0));
21804    left.setFieldValue({ 2 }, "key", static_cast<int32>(3));
21805    left.setFieldValue({ 2 }, "data", static_cast<float64>(30.0));
21806
21807    auto dtype2 = std::make_shared<StructuredDType>(std::vector<std::pair<std::string, DType>>{
21808      {"key", DType::INT32},
21809      { "info", DType::UNICODE32 }
length (np_test_1_all.cpp:7335)
7325    std::cout << " -> tests passed" << std::endl;
7326}
7327
7328void testStringTruncationStringTypes() {
7329    std::cout << "========= testStringTruncationStringTypes =======================";
7330
7331    // Test truncation behavior
7332    str8 small("This string is way too long for 8 characters");
7333    // std::cout << "Long string in str8: '" << small << "'" << std::endl;
7334    // std::cout << "Length: " << small.length() << " (max: " << str8::max_size << ")" << std::endl;
7335
7336    str16 medium("This is a medium length string that should be truncated");
7337    // std::cout << "Medium string in str16: '" << medium << "'" << std::endl;
7338    // std::cout << "Length: " << medium.length() << " (max: " << str16::max_size << ")" << std::endl;
7339
7340    std::cout << " -> tests passed" << std::endl;
7341}
7342
7343void testStringComparisonsStringTypes() {
7344    std::cout << "========= testStringComparisonsStringTypes =======================";
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);
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);
right (np_test_1_all.cpp:21812)
21802    left.setFieldValue({ 1 }, "key", static_cast<int32>(2));
21803    left.setFieldValue({ 1 }, "data", static_cast<float64>(20.0));
21804    left.setFieldValue({ 2 }, "key", static_cast<int32>(3));
21805    left.setFieldValue({ 2 }, "data", static_cast<float64>(30.0));
21806
21807    auto dtype2 = std::make_shared<StructuredDType>(std::vector<std::pair<std::string, DType>>{
21808      {"key", DType::INT32},
21809      { "info", DType::UNICODE32 }
21810    });
21811
21812    RecordArray right(dtype2, { 3 });
21813    right.setFieldValue({ 0 }, "key", static_cast<int32>(1));
21814    right.setFieldValue({ 0 }, "info", std::string("A"));
21815    right.setFieldValue({ 1 }, "key", static_cast<int32>(2));
21816    right.setFieldValue({ 1 }, "info", std::string("B"));
21817    right.setFieldValue({ 2 }, "key", static_cast<int32>(4));
21818    right.setFieldValue({ 2 }, "info", std::string("D"));
21819
21820    // std::cout << "Left array:" << std::endl;
21821    //left.printArray();
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)) {
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);
slice (np_test_1_all.cpp:13009)
12999    // Test substr valid start but excessive length
13000    auto result3 = str1.substr(2, 10);  // start=2, len=10 on string of length 5
13001    if (!(result3.to_string() == "llo")) {
13002        std::string description = std::string("test_variable_string_out_of_bounds():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result3.to_string() == \"llo\")";
13003        std::cout << std::string("[FAIL] ") + description << std::endl;
13004        throw std::runtime_error(description);
13005    }
13006    // std::cout << "[OK] vstring_ substr(2, 10) on 'hello' returns 'llo'\n";
13007
13008    // Test slice method with out-of-bounds
13009    auto result4 = str1.slice(10, 15);  // slice[10:15] on string of length 5
13010    if (!(result4.to_string() == "")) {
13011        std::string description = std::string("test_variable_string_out_of_bounds():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result4.to_string() == \"\")";
13012        std::cout << std::string("[FAIL] ") + description << std::endl;
13013        throw std::runtime_error(description);
13014    }
13015    // std::cout << "[OK] vstring_ slice(10, 15) on 'hello' returns empty string\n";
13016
13017    // Test slice with negative indices
13018    auto result5 = str1.slice(-2, -1);  // slice[-2:-1] should be "l"
13019    if (!(result5.to_string() == "l")) {
type (np_test_1_all.cpp:2240)
2230        std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(multi_array.getElementAt({0, 1}).is_type<std::string>())";
2231        std::cout << std::string("[FAIL] ") + description << std::endl;
2232        throw std::runtime_error(description);
2233    }
2234    if (!(multi_array.getElementAt({0, 2}).is_type<double>())) {
2235        std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(multi_array.getElementAt({0, 2}).is_type<double>())";
2236        std::cout << std::string("[FAIL] ") + description << std::endl;
2237        throw std::runtime_error(description);
2238    }
2239
2240    // Test 4: Arrays with all same type (homogeneous)
2241    NDArray<object_> homo_array = createObjectZeros({5});
2242    for (size_t i = 0; i < 5; ++i) {
2243        homo_array.setElementAt({i}, object_(static_cast<int>(i * 10)));
2244    }
2245
2246    // Verify all are same type
2247    for (size_t i = 0; i < 5; ++i) {
2248        object_ obj = homo_array.getElementAt({i});
2249        if (!(obj.is_type<int>())) {
2250            std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type<int>())";