IndexBase#
-
class numpy::IndexBase#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use IndexBase
IndexBase obj;
// ... operations ...
Array Creation#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
virtual bool |
df_index_base.h:44 |
Indexing / Selection#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
virtual int64_t |
df_index_base.h:88 |
|
|
virtual std::string |
df_index_base.h:105 |
I/O#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
virtual std::string |
df_index_base.h:120 |
|
|
virtual std::vector<std::string> |
df_index_base.h:98 |
Type Checking#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
virtual bool |
df_index_base.h:134 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
df_index_base.h:151 |
|
|
virtual std::unique_ptr<IndexBase> |
df_index_base.h:111 |
|
|
virtual bool |
df_index_base.h:81 |
|
|
virtual std::string |
df_index_base.h:55 |
|
|
bool |
df_index_base.h:156 |
|
|
virtual bool |
df_index_base.h:139 |
|
|
virtual std::string |
df_index_base.h:70 |
|
|
virtual std::optional<std::string> |
df_index_base.h:60 |
|
|
virtual size_t |
df_index_base.h:50 |
|
|
virtual std::string |
df_index_base.h:125 |
|
|
virtual void |
df_index_base.h:65 |
|
|
virtual size_t |
df_index_base.h:39 |
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}
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)";
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";
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
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;
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);