NDArrayBackedExtensionIndex#
-
class numpy::NDArrayBackedExtensionIndex#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use NDArrayBackedExtensionIndex
NDArrayBackedExtensionIndex obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
df_ndarray_backed_extension_index.h:139 |
|
|
df_ndarray_backed_extension_index.h:149 |
|
|
df_ndarray_backed_extension_index.h:158 |
|
|
df_ndarray_backed_extension_index.h:166 |
Indexing / Selection#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
std::string |
df_ndarray_backed_extension_index.h:667 |
I/O#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
std::string |
df_ndarray_backed_extension_index.h:611 |
Type Handling#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
NDArrayBackedExtensionIndex |
df_ndarray_backed_extension_index.h:712 |
Type Checking#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
df_ndarray_backed_extension_index.h:486 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DatetimeArray |
df_ndarray_backed_extension_index.h:276 |
|
|
TimedeltaArray |
df_ndarray_backed_extension_index.h:293 |
|
|
DatetimeArray |
df_ndarray_backed_extension_index.h:346 |
|
|
TimedeltaArray |
df_ndarray_backed_extension_index.h:362 |
|
|
PeriodArray |
df_ndarray_backed_extension_index.h:376 |
|
|
PeriodArray |
df_ndarray_backed_extension_index.h:402 |
|
|
size_t |
df_ndarray_backed_extension_index.h:897 |
|
|
* Clears both the base class |
df_ndarray_backed_extension_index.h:875 |
|
|
void |
df_ndarray_backed_extension_index.h:878 |
|
|
std::unique_ptr<IndexBase> |
df_ndarray_backed_extension_index.h:604 |
|
|
numpy::NDArray<numpy::datetime64> |
df_ndarray_backed_extension_index.h:263 |
|
|
numpy::NDArray<numpy::timedelta64> |
df_ndarray_backed_extension_index.h:281 |
|
|
numpy::NDArray<numpy::int64> |
df_ndarray_backed_extension_index.h:298 |
|
|
numpy::NDArray<numpy::datetime64> |
df_ndarray_backed_extension_index.h:334 |
|
|
numpy::NDArray<numpy::timedelta64> |
df_ndarray_backed_extension_index.h:350 |
|
|
numpy::NDArray<numpy::int64> |
df_ndarray_backed_extension_index.h:366 |
|
|
numpy::NDArray<numpy::int64> |
df_ndarray_backed_extension_index.h:393 |
|
|
static std::string |
df_ndarray_backed_extension_index.h:733 |
|
|
std::string |
df_ndarray_backed_extension_index.h:832 |
|
|
static std::string |
df_ndarray_backed_extension_index.h:793 |
|
|
std::string |
df_ndarray_backed_extension_index.h:563 |
|
|
bool |
df_ndarray_backed_extension_index.h:888 |
|
|
std::string |
df_ndarray_backed_extension_index.h:590 |
|
|
numpy::NDArray<numpy::bool_> |
df_ndarray_backed_extension_index.h:264 |
|
|
numpy::NDArray<numpy::bool_> |
df_ndarray_backed_extension_index.h:282 |
|
|
numpy::NDArray<numpy::bool_> |
df_ndarray_backed_extension_index.h:299 |
|
|
numpy::NDArray<numpy::bool_> |
df_ndarray_backed_extension_index.h:335 |
|
|
numpy::NDArray<numpy::bool_> |
df_ndarray_backed_extension_index.h:351 |
|
|
numpy::NDArray<numpy::bool_> |
df_ndarray_backed_extension_index.h:367 |
|
|
numpy::NDArray<numpy::bool_> |
df_ndarray_backed_extension_index.h:394 |
|
|
PeriodArray arr(data, mask, |
df_ndarray_backed_extension_index.h:309 |
|
|
NDArrayBackedExtensionIndex |
df_ndarray_backed_extension_index.h:719 |
|
|
std::string |
df_ndarray_backed_extension_index.h:660 |
|
|
std::string |
df_ndarray_backed_extension_index.h:424 |
|
|
NDArrayBackedExtensionIndex |
df_ndarray_backed_extension_index.h:720 |
|
|
std::string |
df_ndarray_backed_extension_index.h:525 |
|
|
static std::string |
df_ndarray_backed_extension_index.h:540 |
|
|
* int64 |
df_ndarray_backed_extension_index.h:214 |
Internal Methods#
6 internal methods (prefixed with underscore)
Code Examples#
The following examples are extracted from the test suite.
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;
arr (np_test_1_all.cpp:1388)
1378 std::cout << std::string("[FAIL] ") + description << std::endl;
1379 throw std::runtime_error(description);
1380 }
1381 if (!(*str_obj.get_as<std::string>() == "hello")) {
1382 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*str_obj.get_as<std::string>() == \"hello\")";
1383 std::cout << std::string("[FAIL] ") + description << std::endl;
1384 throw std::runtime_error(description);
1385 }
1386
1387 // Test NDArray construction
1388 NDArray<double> arr({2, 2}, 3.14);
1389 object_ arr_obj(arr);
1390 if (!(!arr_obj.is_null())) {
1391 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!arr_obj.is_null())";
1392 std::cout << std::string("[FAIL] ") + description << std::endl;
1393 throw std::runtime_error(description);
1394 }
1395 if (!(arr_obj.is_array())) {
1396 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr_obj.is_array())";
1397 std::cout << std::string("[FAIL] ") + description << std::endl;
1398 throw std::runtime_error(description);
arr (np_test_1_all.cpp:1388)
1378 std::cout << std::string("[FAIL] ") + description << std::endl;
1379 throw std::runtime_error(description);
1380 }
1381 if (!(*str_obj.get_as<std::string>() == "hello")) {
1382 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*str_obj.get_as<std::string>() == \"hello\")";
1383 std::cout << std::string("[FAIL] ") + description << std::endl;
1384 throw std::runtime_error(description);
1385 }
1386
1387 // Test NDArray construction
1388 NDArray<double> arr({2, 2}, 3.14);
1389 object_ arr_obj(arr);
1390 if (!(!arr_obj.is_null())) {
1391 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!arr_obj.is_null())";
1392 std::cout << std::string("[FAIL] ") + description << std::endl;
1393 throw std::runtime_error(description);
1394 }
1395 if (!(arr_obj.is_array())) {
1396 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr_obj.is_array())";
1397 std::cout << std::string("[FAIL] ") + description << std::endl;
1398 throw std::runtime_error(description);
arr (np_test_1_all.cpp:1388)
1378 std::cout << std::string("[FAIL] ") + description << std::endl;
1379 throw std::runtime_error(description);
1380 }
1381 if (!(*str_obj.get_as<std::string>() == "hello")) {
1382 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*str_obj.get_as<std::string>() == \"hello\")";
1383 std::cout << std::string("[FAIL] ") + description << std::endl;
1384 throw std::runtime_error(description);
1385 }
1386
1387 // Test NDArray construction
1388 NDArray<double> arr({2, 2}, 3.14);
1389 object_ arr_obj(arr);
1390 if (!(!arr_obj.is_null())) {
1391 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!arr_obj.is_null())";
1392 std::cout << std::string("[FAIL] ") + description << std::endl;
1393 throw std::runtime_error(description);
1394 }
1395 if (!(arr_obj.is_array())) {
1396 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr_obj.is_array())";
1397 std::cout << std::string("[FAIL] ") + description << std::endl;
1398 throw std::runtime_error(description);
arr (np_test_1_all.cpp:1388)
1378 std::cout << std::string("[FAIL] ") + description << std::endl;
1379 throw std::runtime_error(description);
1380 }
1381 if (!(*str_obj.get_as<std::string>() == "hello")) {
1382 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*str_obj.get_as<std::string>() == \"hello\")";
1383 std::cout << std::string("[FAIL] ") + description << std::endl;
1384 throw std::runtime_error(description);
1385 }
1386
1387 // Test NDArray construction
1388 NDArray<double> arr({2, 2}, 3.14);
1389 object_ arr_obj(arr);
1390 if (!(!arr_obj.is_null())) {
1391 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!arr_obj.is_null())";
1392 std::cout << std::string("[FAIL] ") + description << std::endl;
1393 throw std::runtime_error(description);
1394 }
1395 if (!(arr_obj.is_array())) {
1396 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr_obj.is_array())";
1397 std::cout << std::string("[FAIL] ") + description << std::endl;
1398 throw std::runtime_error(description);
arr (np_test_1_all.cpp:1388)
1378 std::cout << std::string("[FAIL] ") + description << std::endl;
1379 throw std::runtime_error(description);
1380 }
1381 if (!(*str_obj.get_as<std::string>() == "hello")) {
1382 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*str_obj.get_as<std::string>() == \"hello\")";
1383 std::cout << std::string("[FAIL] ") + description << std::endl;
1384 throw std::runtime_error(description);
1385 }
1386
1387 // Test NDArray construction
1388 NDArray<double> arr({2, 2}, 3.14);
1389 object_ arr_obj(arr);
1390 if (!(!arr_obj.is_null())) {
1391 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!arr_obj.is_null())";
1392 std::cout << std::string("[FAIL] ") + description << std::endl;
1393 throw std::runtime_error(description);
1394 }
1395 if (!(arr_obj.is_array())) {
1396 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr_obj.is_array())";
1397 std::cout << std::string("[FAIL] ") + description << std::endl;
1398 throw std::runtime_error(description);
arr (np_test_1_all.cpp:1388)
1378 std::cout << std::string("[FAIL] ") + description << std::endl;
1379 throw std::runtime_error(description);
1380 }
1381 if (!(*str_obj.get_as<std::string>() == "hello")) {
1382 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*str_obj.get_as<std::string>() == \"hello\")";
1383 std::cout << std::string("[FAIL] ") + description << std::endl;
1384 throw std::runtime_error(description);
1385 }
1386
1387 // Test NDArray construction
1388 NDArray<double> arr({2, 2}, 3.14);
1389 object_ arr_obj(arr);
1390 if (!(!arr_obj.is_null())) {
1391 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!arr_obj.is_null())";
1392 std::cout << std::string("[FAIL] ") + description << std::endl;
1393 throw std::runtime_error(description);
1394 }
1395 if (!(arr_obj.is_array())) {
1396 std::string description = std::string("testObjectConstruction():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(arr_obj.is_array())";
1397 std::cout << std::string("[FAIL] ") + description << std::endl;
1398 throw std::runtime_error(description);
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
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>())) {
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>())) {
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>())) {
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>())) {
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>())) {
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>())) {
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>())) {
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);
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);
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);
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);
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);
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);
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);
resolution (np_test_5_all.cpp:21200)
21190 std::cout << "[FAIL] np_test_timedelta_constructors: Timedelta(30, 's') expected 30 seconds, got "
21191 << td_sec.total_seconds() << std::endl;
21192 errors++;
21193 }
21194
21195 numpy::Timedelta td_ms(500, "ms"); // 500 milliseconds
21196 std::cout << " Timedelta(500, 'ms') = " << td_ms.value() << " nanoseconds" << std::endl;
21197 int64_t expected_ms = 500 * numpy::Timedelta::NANOS_PER_MILLISECOND;
21198 if (td_ms.value() != expected_ms) {
21199 std::cout << "[FAIL] np_test_timedelta_constructors: Timedelta(500, 'ms') expected "
21200 << expected_ms << " ns, got " << td_ms.value() << std::endl;
21201 errors++;
21202 }
21203
21204 numpy::Timedelta td_us(1000, "us"); // 1000 microseconds
21205 std::cout << " Timedelta(1000, 'us') = " << td_us.value() << " nanoseconds" << std::endl;
21206 int64_t expected_us = 1000 * numpy::Timedelta::NANOS_PER_MICROSECOND;
21207 if (td_us.value() != expected_us) {
21208 std::cout << "[FAIL] np_test_timedelta_constructors: Timedelta(1000, 'us') expected "
21209 << expected_us << " ns, got " << td_us.value() << std::endl;
21210 errors++;
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);
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);