BooleanArray#
-
class numpy::BooleanArray#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use BooleanArray
BooleanArray obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
df_boolean_array.h:66 |
|
|
df_boolean_array.h:79 |
|
|
df_boolean_array.h:110 |
Construction#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
static BooleanArray |
df_boolean_array.h:312 |
Array Creation#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
df_boolean_array.h:167 |
Indexing / Selection#
Statistics#
Sorting#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
numpy::NDArray<size_t> |
df_boolean_array.h:789 |
Math Operations#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
BooleanArray |
df_boolean_array.h:551 |
|
|
BooleanArray |
df_boolean_array.h:554 |
|
|
BooleanArray |
df_boolean_array.h:552 |
|
|
BooleanArray |
df_boolean_array.h:553 |
Logical#
Set Operations#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
BooleanArray |
df_boolean_array.h:709 |
I/O#
Type Handling#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
BooleanArray |
df_boolean_array.h:252 |
Type Checking#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
df_boolean_array.h:223 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
* XOR always returns NA if either operand is |
df_boolean_array.h:502 |
|
|
static BooleanArray |
df_boolean_array.h:319 |
|
|
size_t |
df_boolean_array.h:388 |
|
|
const numpy::NDArray<numpy::bool_>& |
df_boolean_array.h:185 |
|
|
BooleanArray |
df_boolean_array.h:362 |
|
|
dtype_type |
df_boolean_array.h:132 |
|
|
std::pair<numpy::NDArray<numpy::int64>, BooleanArray> |
df_boolean_array.h:740 |
|
|
BooleanArray |
df_boolean_array.h:348 |
|
|
bool |
df_boolean_array.h:401 |
|
|
numpy::NDArray<numpy::bool_> |
df_boolean_array.h:234 |
|
|
size_t |
df_boolean_array.h:174 |
|
|
const numpy::NDArray<numpy::bool_>& |
df_boolean_array.h:192 |
|
|
size_t |
df_boolean_array.h:146 |
|
|
constexpr int |
df_boolean_array.h:153 |
|
|
numpy::NDArray<numpy::bool_> |
df_boolean_array.h:241 |
|
|
std::string |
df_boolean_array.h:948 |
|
|
std::vector<size_t> |
df_boolean_array.h:160 |
|
|
size_t |
df_boolean_array.h:139 |
|
|
void |
df_boolean_array.h:961 |
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);
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 }
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)) {
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);
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;
logical_and (np_test_1_all.cpp:901)
891 a.setElementAt({0}, true);
892 a.setElementAt({1}, false);
893 a.setElementAt({2}, true);
894
895 auto b = NDArray<bool>({3});
896 b.setElementAt({0}, false);
897 b.setElementAt({1}, false);
898 b.setElementAt({2}, true);
899
900 // Test logical_and
901 auto and_result = logical_and(a, b);
902 bool and_0 = and_result.getElementAt({0});
903 if (and_0 != false) { // true && false = false
904 std::cout << "[FAIL] in testLogicalOperations(): logical_and[0] = " << and_0 << ", expected false" << std::endl;
905 throw std::runtime_error("testLogicalOperations(): logical_and [0] failed");
906 }
907 bool and_1 = and_result.getElementAt({1});
908 if (and_1 != false) { // false && false = false
909 std::cout << "[FAIL] in testLogicalOperations(): logical_and[1] = " << and_1 << ", expected false" << std::endl;
910 throw std::runtime_error("testLogicalOperations(): logical_and [1] failed");
911 }
logical_not (np_test_1_all.cpp:939)
929 throw std::runtime_error("testLogicalOperations(): logical_or [1] failed");
930 }
931 bool or_2 = or_result.getElementAt({2});
932 if (or_2 != true) { // true || true = true
933 std::cout << "[FAIL] in testLogicalOperations(): logical_or[2] = " << or_2 << ", expected true" << std::endl;
934 throw std::runtime_error("testLogicalOperations(): logical_or [2] failed");
935 }
936 // std::cout << "[OK] logical_or function";
937
938 // Test logical_not
939 auto not_result = logical_not(a);
940 bool not_0 = not_result.getElementAt({0});
941 if (not_0 != false) { // !true = false
942 std::cout << "[FAIL] in testLogicalOperations(): logical_not[0] = " << not_0 << ", expected false" << std::endl;
943 throw std::runtime_error("testLogicalOperations(): logical_not [0] failed");
944 }
945 bool not_1 = not_result.getElementAt({1});
946 if (not_1 != true) { // !false = true
947 std::cout << "[FAIL] in testLogicalOperations(): logical_not[1] = " << not_1 << ", expected true" << std::endl;
948 throw std::runtime_error("testLogicalOperations(): logical_not [1] failed");
949 }
logical_or (np_test_1_all.cpp:920)
910 throw std::runtime_error("testLogicalOperations(): logical_and [1] failed");
911 }
912 bool and_2 = and_result.getElementAt({2});
913 if (and_2 != true) { // true && true = true
914 std::cout << "[FAIL] in testLogicalOperations(): logical_and[2] = " << and_2 << ", expected true" << std::endl;
915 throw std::runtime_error("testLogicalOperations(): logical_and [2] failed");
916 }
917 // std::cout << "[OK] logical_and function";
918
919 // Test logical_or
920 auto or_result = logical_or(a, b);
921 bool or_0 = or_result.getElementAt({0});
922 if (or_0 != true) { // true || false = true
923 std::cout << "[FAIL] in testLogicalOperations(): logical_or[0] = " << or_0 << ", expected true" << std::endl;
924 throw std::runtime_error("testLogicalOperations(): logical_or [0] failed");
925 }
926 bool or_1 = or_result.getElementAt({1});
927 if (or_1 != false) { // false || false = false
928 std::cout << "[FAIL] in testLogicalOperations(): logical_or[1] = " << or_1 << ", expected false" << std::endl;
929 throw std::runtime_error("testLogicalOperations(): logical_or [1] failed");
930 }
logical_xor (np_test_1_all.cpp:958)
948 throw std::runtime_error("testLogicalOperations(): logical_not [1] failed");
949 }
950 bool not_2 = not_result.getElementAt({2});
951 if (not_2 != false) { // !true = false
952 std::cout << "[FAIL] in testLogicalOperations(): logical_not[2] = " << not_2 << ", expected false" << std::endl;
953 throw std::runtime_error("testLogicalOperations(): logical_not [2] failed");
954 }
955 // std::cout << "[OK] logical_not function";
956
957 // Test logical_xor
958 auto xor_result = logical_xor(a, b);
959 bool xor_0 = xor_result.getElementAt({0});
960 if (xor_0 != true) { // true XOR false = true
961 std::cout << "[FAIL] in testLogicalOperations(): logical_xor[0] = " << xor_0 << ", expected true" << std::endl;
962 throw std::runtime_error("testLogicalOperations(): logical_xor [0] failed");
963 }
964 bool xor_1 = xor_result.getElementAt({1});
965 if (xor_1 != false) { // false XOR false = false
966 std::cout << "[FAIL] in testLogicalOperations(): logical_xor[1] = " << xor_1 << ", expected false" << std::endl;
967 throw std::runtime_error("testLogicalOperations(): logical_xor [1] failed");
968 }
all (np_test_4_all.cpp:23928)
23918 }
23919 }
23920 }
23921
23922 auto result = numpy::einsum<numpy::float64>("ijk->ik", {A});
23923
23924 if (result.getShape()[0] != 2 || result.getShape()[1] != 2) {
23925 throw std::runtime_error("einsum partial sum shape wrong");
23926 }
23927
23928 // Sum over j: 1+2+3 = 6 for all (i,k) positions
23929 if (std::abs(result.getElementAt({0, 0}) - 6.0) > 1e-10 ||
23930 std::abs(result.getElementAt({1, 1}) - 6.0) > 1e-10) {
23931 throw std::runtime_error("einsum partial sum values wrong");
23932 }
23933
23934 // std::cout << " OK: Partial sum: 'ijk->ik'\n";
23935 }
23936
23937 // Test 5: Size-1 dimension handling
23938 {
any (np_test_2_all.cpp:16758)
16748 // ANY() TESTS - SCALAR RESULT
16749 // ============================================================================
16750
16751 void np_test_logic_any_scalar_all_false() {
16752 std::cout << "========= any: all false elements =======================";
16753
16754 // Create array with all false/zero elements
16755 std::vector<double> data = { 0.0, 0.0, 0.0 };
16756 numpy::NDArray<double> arr = numpy::createArrayFromVector<double>({ 3 }, data);
16757
16758 bool result = numpy::any(arr);
16759
16760 if (result != false) {
16761 std::cout << " [FAIL] : in np_test_logic_any_scalar_all_false() : expected false for all-zero array";
16762 throw std::runtime_error("np_test_logic_any_scalar_all_false failed: expected false");
16763 }
16764
16765 std::cout << " -> tests passed" << std::endl;
16766 }
16767
16768 void np_test_logic_any_scalar_all_true() {
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)";
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;
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;
data (np_test_1_all.cpp:2084)
2074 }
2075 if (!(derived_ptr->extra == 2)) {
2076 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)";
2077 std::cout << std::string("[FAIL] ") + description << std::endl;
2078 throw std::runtime_error(description);
2079 }
2080
2081 // Test 6: Large object handling
2082 struct LargeObject {
2083 std::vector<double> data;
2084 LargeObject() : data(10000, 3.14159) {} // Large object
2085 };
2086
2087 LargeObject large;
2088 object_ large_obj(large); // Should handle large objects
2089 if (!(!large_obj.is_null())) {
2090 std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())";
2091 std::cout << std::string("[FAIL] ") + description << std::endl;
2092 throw std::runtime_error(description);
2093 }
2094 if (!(large_obj.is_type<LargeObject>())) {
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 }
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);
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);