vunicode#
-
class numpy::vunicode_#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use vunicode_
vunicode_ obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
NP_VARIABLE_STRING.H:389 |
|
|
NP_VARIABLE_STRING.H:391 |
|
|
NP_VARIABLE_STRING.H:393 |
|
|
NP_VARIABLE_STRING.H:395 |
|
|
NP_VARIABLE_STRING.H:398 |
|
|
NP_VARIABLE_STRING.H:400 |
Operators#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
vunicode_ & |
NP_VARIABLE_STRING.H:403 |
|
|
vunicode_ & noexcept |
NP_VARIABLE_STRING.H:410 |
|
|
vunicode_ & |
NP_VARIABLE_STRING.H:417 |
|
|
vunicode_ & |
NP_VARIABLE_STRING.H:422 |
|
|
vunicode_ & |
NP_VARIABLE_STRING.H:427 |
|
|
char32_t & |
NP_VARIABLE_STRING.H:442 |
|
|
const char32_t & |
NP_VARIABLE_STRING.H:443 |
|
|
vunicode_ |
NP_VARIABLE_STRING.H:492 |
|
|
vunicode_ & |
NP_VARIABLE_STRING.H:496 |
|
|
vunicode_ & |
NP_VARIABLE_STRING.H:501 |
|
|
bool |
NP_VARIABLE_STRING.H:552 |
|
|
bool |
NP_VARIABLE_STRING.H:556 |
|
|
bool |
NP_VARIABLE_STRING.H:560 |
|
|
bool |
NP_VARIABLE_STRING.H:564 |
|
|
bool |
NP_VARIABLE_STRING.H:568 |
|
|
bool |
NP_VARIABLE_STRING.H:572 |
Array Creation#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
NP_VARIABLE_STRING.H:437 |
Indexing / Selection#
Shape Manipulation#
Statistics#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
size_t |
NP_VARIABLE_STRING.H:439 |
I/O#
Joining / Splitting#
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
char32_t & |
NP_VARIABLE_STRING.H:451 |
|
|
const char32_t & |
NP_VARIABLE_STRING.H:452 |
|
|
auto |
NP_VARIABLE_STRING.H:591 |
|
|
auto |
NP_VARIABLE_STRING.H:593 |
|
|
size_t |
NP_VARIABLE_STRING.H:436 |
|
|
size_t |
NP_VARIABLE_STRING.H:438 |
|
|
auto |
NP_VARIABLE_STRING.H:595 |
|
|
auto |
NP_VARIABLE_STRING.H:596 |
|
|
size_t |
NP_VARIABLE_STRING.H:435 |
|
|
void |
NP_VARIABLE_STRING.H:522 |
|
|
auto |
NP_VARIABLE_STRING.H:601 |
|
|
auto |
NP_VARIABLE_STRING.H:602 |
|
|
auto |
NP_VARIABLE_STRING.H:592 |
|
|
auto |
NP_VARIABLE_STRING.H:594 |
|
|
size_t |
NP_VARIABLE_STRING.H:539 |
|
|
size_t |
NP_VARIABLE_STRING.H:543 |
|
|
char32_t & |
NP_VARIABLE_STRING.H:448 |
|
|
const char32_t & |
NP_VARIABLE_STRING.H:449 |
|
|
size_t |
NP_VARIABLE_STRING.H:434 |
|
|
void |
NP_VARIABLE_STRING.H:518 |
|
|
void |
NP_VARIABLE_STRING.H:514 |
|
|
auto |
NP_VARIABLE_STRING.H:597 |
|
|
auto |
NP_VARIABLE_STRING.H:599 |
|
|
auto |
NP_VARIABLE_STRING.H:598 |
|
|
auto |
NP_VARIABLE_STRING.H:600 |
|
|
void |
NP_VARIABLE_STRING.H:526 |
|
|
size_t |
NP_VARIABLE_STRING.H:547 |
|
|
size_t |
NP_VARIABLE_STRING.H:433 |
|
|
vunicode_ |
NP_VARIABLE_STRING.H:474 |
|
|
vunicode_ |
NP_VARIABLE_STRING.H:455 |
|
|
std::string |
NP_VARIABLE_STRING.H:356 |
|
|
std::u32string |
NP_VARIABLE_STRING.H:288 |
Code Examples#
The following examples are extracted from the test suite.
vunicode (np_test_1_all.cpp:8704)
8694 // Concatenation
8695 vunicode_ combined = str1 + str2;
8696 if (!(combined.to_utf8() == "Hello World")) {
8697 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(combined.to_utf8() == \"Hello World\")";
8698 std::cout << std::string("[FAIL] ") + description << std::endl;
8699 throw std::runtime_error(description);
8700 }
8701
8702 // Append operations
8703 vunicode_ str3("Test");
8704 str3 += vunicode_(" Unicode");
8705 if (!(str3.to_utf8() == "Test Unicode")) {
8706 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str3.to_utf8() == \"Test Unicode\")";
8707 std::cout << std::string("[FAIL] ") + description << std::endl;
8708 throw std::runtime_error(description);
8709 }
8710
8711 // Substring
8712 vunicode_ sub = combined.substr(6, 5); // "World"
8713 if (!(sub.to_utf8() == "World")) {
8714 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sub.to_utf8() == \"World\")";
vunicode (np_test_1_all.cpp:8704)
8694 // Concatenation
8695 vunicode_ combined = str1 + str2;
8696 if (!(combined.to_utf8() == "Hello World")) {
8697 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(combined.to_utf8() == \"Hello World\")";
8698 std::cout << std::string("[FAIL] ") + description << std::endl;
8699 throw std::runtime_error(description);
8700 }
8701
8702 // Append operations
8703 vunicode_ str3("Test");
8704 str3 += vunicode_(" Unicode");
8705 if (!(str3.to_utf8() == "Test Unicode")) {
8706 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str3.to_utf8() == \"Test Unicode\")";
8707 std::cout << std::string("[FAIL] ") + description << std::endl;
8708 throw std::runtime_error(description);
8709 }
8710
8711 // Substring
8712 vunicode_ sub = combined.substr(6, 5); // "World"
8713 if (!(sub.to_utf8() == "World")) {
8714 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sub.to_utf8() == \"World\")";
vunicode (np_test_1_all.cpp:8704)
8694 // Concatenation
8695 vunicode_ combined = str1 + str2;
8696 if (!(combined.to_utf8() == "Hello World")) {
8697 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(combined.to_utf8() == \"Hello World\")";
8698 std::cout << std::string("[FAIL] ") + description << std::endl;
8699 throw std::runtime_error(description);
8700 }
8701
8702 // Append operations
8703 vunicode_ str3("Test");
8704 str3 += vunicode_(" Unicode");
8705 if (!(str3.to_utf8() == "Test Unicode")) {
8706 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str3.to_utf8() == \"Test Unicode\")";
8707 std::cout << std::string("[FAIL] ") + description << std::endl;
8708 throw std::runtime_error(description);
8709 }
8710
8711 // Substring
8712 vunicode_ sub = combined.substr(6, 5); // "World"
8713 if (!(sub.to_utf8() == "World")) {
8714 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sub.to_utf8() == \"World\")";
vunicode (np_test_1_all.cpp:8704)
8694 // Concatenation
8695 vunicode_ combined = str1 + str2;
8696 if (!(combined.to_utf8() == "Hello World")) {
8697 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(combined.to_utf8() == \"Hello World\")";
8698 std::cout << std::string("[FAIL] ") + description << std::endl;
8699 throw std::runtime_error(description);
8700 }
8701
8702 // Append operations
8703 vunicode_ str3("Test");
8704 str3 += vunicode_(" Unicode");
8705 if (!(str3.to_utf8() == "Test Unicode")) {
8706 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str3.to_utf8() == \"Test Unicode\")";
8707 std::cout << std::string("[FAIL] ") + description << std::endl;
8708 throw std::runtime_error(description);
8709 }
8710
8711 // Substring
8712 vunicode_ sub = combined.substr(6, 5); // "World"
8713 if (!(sub.to_utf8() == "World")) {
8714 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sub.to_utf8() == \"World\")";
vunicode (np_test_1_all.cpp:8704)
8694 // Concatenation
8695 vunicode_ combined = str1 + str2;
8696 if (!(combined.to_utf8() == "Hello World")) {
8697 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(combined.to_utf8() == \"Hello World\")";
8698 std::cout << std::string("[FAIL] ") + description << std::endl;
8699 throw std::runtime_error(description);
8700 }
8701
8702 // Append operations
8703 vunicode_ str3("Test");
8704 str3 += vunicode_(" Unicode");
8705 if (!(str3.to_utf8() == "Test Unicode")) {
8706 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str3.to_utf8() == \"Test Unicode\")";
8707 std::cout << std::string("[FAIL] ") + description << std::endl;
8708 throw std::runtime_error(description);
8709 }
8710
8711 // Substring
8712 vunicode_ sub = combined.substr(6, 5); // "World"
8713 if (!(sub.to_utf8() == "World")) {
8714 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sub.to_utf8() == \"World\")";
vunicode (np_test_1_all.cpp:8704)
8694 // Concatenation
8695 vunicode_ combined = str1 + str2;
8696 if (!(combined.to_utf8() == "Hello World")) {
8697 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(combined.to_utf8() == \"Hello World\")";
8698 std::cout << std::string("[FAIL] ") + description << std::endl;
8699 throw std::runtime_error(description);
8700 }
8701
8702 // Append operations
8703 vunicode_ str3("Test");
8704 str3 += vunicode_(" Unicode");
8705 if (!(str3.to_utf8() == "Test Unicode")) {
8706 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str3.to_utf8() == \"Test Unicode\")";
8707 std::cout << std::string("[FAIL] ") + description << std::endl;
8708 throw std::runtime_error(description);
8709 }
8710
8711 // Substring
8712 vunicode_ sub = combined.substr(6, 5); // "World"
8713 if (!(sub.to_utf8() == "World")) {
8714 std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sub.to_utf8() == \"World\")";
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);
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);
at_safe (np_test_1_all.cpp:13109)
13099 std::cout << " -> tests passed" << std::endl;
13100 }
13101
13102 void test_character_access_bounds() {
13103 std::cout << "========= test_character_access_bounds =======================";
13104
13105 vstring_ str1("abc");
13106
13107 // Test safe character access within bounds
13108 try {
13109 char c1 = str1.at_safe(0); // Should work
13110 if (!(c1 == 'a')) {
13111 std::string description = std::string("test_character_access_bounds():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(c1 == 'a')";
13112 std::cout << std::string("[FAIL] ") + description << std::endl;
13113 throw std::runtime_error(description);
13114 }
13115 // std::cout << "[OK] at_safe(0) on 'abc' returns 'a'\n";
13116
13117 char c2 = str1.at_safe(2); // Should work
13118 if (!(c2 == 'c')) {
13119 std::string description = std::string("test_character_access_bounds():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(c2 == 'c')";
resize (np_test_2_all.cpp:8615)
8605 std::cout << " IPP empty array test: -> [FAIL]";
8606 throw std::runtime_error("IPP empty array test: FAILED - should return empty");
8607 }
8608 // std::cout << "[OK] IPP empty array test: PASSED" << std::endl;
8609 }
8610
8611 // Test 6: Large array performance
8612 {
8613 const size_t n = 10000;
8614 std::vector<std::vector<int>> keys(2);
8615 keys[0].resize(n);
8616 keys[1].resize(n);
8617
8618 std::mt19937 gen(42);
8619 std::uniform_int_distribution<int> dist(0, 1000);
8620
8621 for (size_t i = 0; i < n; ++i) {
8622 keys[0][i] = dist(gen);
8623 keys[1][i] = dist(gen);
8624 }
resize (np_test_2_all.cpp:8615)
8605 std::cout << " IPP empty array test: -> [FAIL]";
8606 throw std::runtime_error("IPP empty array test: FAILED - should return empty");
8607 }
8608 // std::cout << "[OK] IPP empty array test: PASSED" << std::endl;
8609 }
8610
8611 // Test 6: Large array performance
8612 {
8613 const size_t n = 10000;
8614 std::vector<std::vector<int>> keys(2);
8615 keys[0].resize(n);
8616 keys[1].resize(n);
8617
8618 std::mt19937 gen(42);
8619 std::uniform_int_distribution<int> dist(0, 1000);
8620
8621 for (size_t i = 0; i < n; ++i) {
8622 keys[0][i] = dist(gen);
8623 keys[1][i] = dist(gen);
8624 }
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)";
to_utf8 (np_test_1_all.cpp:8658)
8648 throw std::runtime_error(description);
8649 }
8650
8651 // ASCII string
8652 vunicode_ ascii_str("Hello");
8653 if (!(ascii_str.size() == 5)) {
8654 std::string description = std::string("testVUnicodeConstructionVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ascii_str.size() == 5)";
8655 std::cout << std::string("[FAIL] ") + description << std::endl;
8656 throw std::runtime_error(description);
8657 }
8658 if (!(ascii_str.to_utf8() == "Hello")) {
8659 std::string description = std::string("testVUnicodeConstructionVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ascii_str.to_utf8() == \"Hello\")";
8660 std::cout << std::string("[FAIL] ") + description << std::endl;
8661 throw std::runtime_error(description);
8662 }
8663
8664 // UTF-8 string with Unicode characters
8665 std::string utf8_str = "Héllo Wørld! 🌍";
8666 vunicode_ unicode_str(utf8_str);
8667 if (!(!unicode_str.empty())) {
8668 std::string description = std::string("testVUnicodeConstructionVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!unicode_str.empty())";
append (np_test_2_all.cpp:7028)
7018 throw std::runtime_error(description);
7019 }
7020 if (!(deleted_dups.getElementAt({ 2 }) == 3)) {
7021 std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(deleted_dups.getElementAt({ 2 }) == 3)";
7022 std::cout << std::string("[FAIL] ") + description << std::endl;
7023 throw std::runtime_error(description);
7024 }
7025 // std::cout << "[OK] Delete with duplicate indices works correctly\n";
7026
7027 // Test append
7028 auto appended = append(array, 100);
7029 if (!(appended.getSize() == array.getSize() + 1)) {
7030 std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(appended.getSize() == array.getSize() + 1)";
7031 std::cout << std::string("[FAIL] ") + description << std::endl;
7032 throw std::runtime_error(description);
7033 }
7034 if (!(appended.getElementAt({ appended.getSize() - 1 }) == 100)) {
7035 std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(appended.getElementAt({ appended.getSize() - 1 }) == 100)";
7036 std::cout << std::string("[FAIL] ") + description << std::endl;
7037 throw std::runtime_error(description);
7038 }
append (np_test_2_all.cpp:7028)
7018 throw std::runtime_error(description);
7019 }
7020 if (!(deleted_dups.getElementAt({ 2 }) == 3)) {
7021 std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(deleted_dups.getElementAt({ 2 }) == 3)";
7022 std::cout << std::string("[FAIL] ") + description << std::endl;
7023 throw std::runtime_error(description);
7024 }
7025 // std::cout << "[OK] Delete with duplicate indices works correctly\n";
7026
7027 // Test append
7028 auto appended = append(array, 100);
7029 if (!(appended.getSize() == array.getSize() + 1)) {
7030 std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(appended.getSize() == array.getSize() + 1)";
7031 std::cout << std::string("[FAIL] ") + description << std::endl;
7032 throw std::runtime_error(description);
7033 }
7034 if (!(appended.getElementAt({ appended.getSize() - 1 }) == 100)) {
7035 std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(appended.getElementAt({ appended.getSize() - 1 }) == 100)";
7036 std::cout << std::string("[FAIL] ") + description << std::endl;
7037 throw std::runtime_error(description);
7038 }
back (np_test_2_all.cpp:8251)
8241 // std::cout << "keys[1] = ";
8242 for (size_t i = 0; i < result.size(); ++i) {
8243 // std::cout << keys[1][result[i]] << " ";
8244 }
8245 // std::cout << "";
8246 // Expected order based on primary key (last array), then secondary
8247 // Should sort by [9,4,0,4,0,2,1] first, then by [1,5,1,4,3,4,4]
8248
8249 bool is_sorted = true;
8250 for (size_t i = 1; i < result.size(); ++i) {
8251 int prev_primary = keys.back()[result[i - 1]];
8252 int curr_primary = keys.back()[result[i]];
8253
8254 if (prev_primary > curr_primary) {
8255 is_sorted = false;
8256 break;
8257 }
8258 else if (prev_primary == curr_primary) {
8259 int prev_secondary = keys[0][result[i - 1]];
8260 int curr_secondary = keys[0][result[i]];
8261 if (prev_secondary > curr_secondary) {
back (np_test_2_all.cpp:8251)
8241 // std::cout << "keys[1] = ";
8242 for (size_t i = 0; i < result.size(); ++i) {
8243 // std::cout << keys[1][result[i]] << " ";
8244 }
8245 // std::cout << "";
8246 // Expected order based on primary key (last array), then secondary
8247 // Should sort by [9,4,0,4,0,2,1] first, then by [1,5,1,4,3,4,4]
8248
8249 bool is_sorted = true;
8250 for (size_t i = 1; i < result.size(); ++i) {
8251 int prev_primary = keys.back()[result[i - 1]];
8252 int curr_primary = keys.back()[result[i]];
8253
8254 if (prev_primary > curr_primary) {
8255 is_sorted = false;
8256 break;
8257 }
8258 else if (prev_primary == curr_primary) {
8259 int prev_secondary = keys[0][result[i - 1]];
8260 int curr_secondary = keys[0][result[i]];
8261 if (prev_secondary > curr_secondary) {
begin (np_test_1_all.cpp:6171)
6161 // Test sorted data generation
6162 std::vector<int> data = gen.generate(50, DataPattern::SORTED);
6163
6164 if (!(data.size() == 50)) {
6165 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)";
6166 std::cout << std::string("[FAIL] ") + description << std::endl;
6167 throw std::runtime_error(description);
6168 }
6169
6170 // Verify data is sorted
6171 if (!(std::is_sorted(data.begin(), data.end()))) {
6172 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))";
6173 std::cout << std::string("[FAIL] ") + description << std::endl;
6174 throw std::runtime_error(description);
6175 }
6176
6177 // std::cout << "Sorted data generation test passed" << std::endl;
6178
6179 std::cout << " -> tests passed" << std::endl;
6180}
begin (np_test_1_all.cpp:6171)
6161 // Test sorted data generation
6162 std::vector<int> data = gen.generate(50, DataPattern::SORTED);
6163
6164 if (!(data.size() == 50)) {
6165 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)";
6166 std::cout << std::string("[FAIL] ") + description << std::endl;
6167 throw std::runtime_error(description);
6168 }
6169
6170 // Verify data is sorted
6171 if (!(std::is_sorted(data.begin(), data.end()))) {
6172 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))";
6173 std::cout << std::string("[FAIL] ") + description << std::endl;
6174 throw std::runtime_error(description);
6175 }
6176
6177 // std::cout << "Sorted data generation test passed" << std::endl;
6178
6179 std::cout << " -> tests passed" << std::endl;
6180}
byte_size (np_test_1_all.cpp:8536)
8526 std::cout << std::string("[FAIL] ") + description << std::endl;
8527 throw std::runtime_error(description);
8528 }
8529
8530 // Size operations
8531 if (!(str1.size() == 5)) {
8532 std::string description = std::string("testVStringOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str1.size() == 5)";
8533 std::cout << std::string("[FAIL] ") + description << std::endl;
8534 throw std::runtime_error(description);
8535 }
8536 if (!(str1.byte_size() == 5)) {
8537 std::string description = std::string("testVStringOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str1.byte_size() == 5)";
8538 std::cout << std::string("[FAIL] ") + description << std::endl;
8539 throw std::runtime_error(description);
8540 }
8541 if (!(!str1.empty())) {
8542 std::string description = std::string("testVStringOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!str1.empty())";
8543 std::cout << std::string("[FAIL] ") + description << std::endl;
8544 throw std::runtime_error(description);
8545 }
char_count (np_test_1_all.cpp:8672)
8662 }
8663
8664 // UTF-8 string with Unicode characters
8665 std::string utf8_str = "Héllo Wørld! 🌍";
8666 vunicode_ unicode_str(utf8_str);
8667 if (!(!unicode_str.empty())) {
8668 std::string description = std::string("testVUnicodeConstructionVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!unicode_str.empty())";
8669 std::cout << std::string("[FAIL] ") + description << std::endl;
8670 throw std::runtime_error(description);
8671 }
8672 if (!(unicode_str.to_utf8() == utf8_str || unicode_str.char_count() > 0)) {
8673 std::string description = std::string("testVUnicodeConstructionVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unicode_str.to_utf8() == utf8_str || unicode_str.char_count() > 0)";
8674 std::cout << std::string("[FAIL] ") + description << std::endl;
8675 throw std::runtime_error(description);
8676 }
8677
8678 // Copy constructor
8679 vunicode_ copied(unicode_str);
8680 if (!(copied.to_utf8() == unicode_str.to_utf8())) {
8681 std::string description = std::string("testVUnicodeConstructionVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(copied.to_utf8() == unicode_str.to_utf8())";
8682 std::cout << std::string("[FAIL] ") + description << std::endl;
clear (np_test_2_all.cpp:4161)
4151 auto array = createFloat32Array({ 10, 10 }, static_cast<float>(i));
4152 temp_arrays.push_back(array);
4153
4154 auto view = array.view();
4155 temp_views.push_back(view);
4156 }
4157
4158 // std::cout << "Created 100 arrays and 100 views" << std::endl;
4159
4160 // Clear all arrays (views will keep memory alive)
4161 temp_arrays.clear();
4162 // std::cout << "Cleared original arrays" << std::endl;
4163
4164 // Verify views still work
4165 if (!(temp_views[50].getElementAt({ 5, 5 }) == 50.0f)) {
4166 std::string description = std::string("testMemoryLeakPrevention():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(temp_views[50].getElementAt({ 5, 5 }) == 50.0f)";
4167 std::cout << std::string("[FAIL] ") + description << std::endl;
4168 throw std::runtime_error(description);
4169 }
4170 // std::cout << "[OK] Views still valid after originals cleared";
end (np_test_1_all.cpp:6171)
6161 // Test sorted data generation
6162 std::vector<int> data = gen.generate(50, DataPattern::SORTED);
6163
6164 if (!(data.size() == 50)) {
6165 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)";
6166 std::cout << std::string("[FAIL] ") + description << std::endl;
6167 throw std::runtime_error(description);
6168 }
6169
6170 // Verify data is sorted
6171 if (!(std::is_sorted(data.begin(), data.end()))) {
6172 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))";
6173 std::cout << std::string("[FAIL] ") + description << std::endl;
6174 throw std::runtime_error(description);
6175 }
6176
6177 // std::cout << "Sorted data generation test passed" << std::endl;
6178
6179 std::cout << " -> tests passed" << std::endl;
6180}
end (np_test_1_all.cpp:6171)
6161 // Test sorted data generation
6162 std::vector<int> data = gen.generate(50, DataPattern::SORTED);
6163
6164 if (!(data.size() == 50)) {
6165 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)";
6166 std::cout << std::string("[FAIL] ") + description << std::endl;
6167 throw std::runtime_error(description);
6168 }
6169
6170 // Verify data is sorted
6171 if (!(std::is_sorted(data.begin(), data.end()))) {
6172 std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))";
6173 std::cout << std::string("[FAIL] ") + description << std::endl;
6174 throw std::runtime_error(description);
6175 }
6176
6177 // std::cout << "Sorted data generation test passed" << std::endl;
6178
6179 std::cout << " -> tests passed" << std::endl;
6180}
find (np_test_1_all.cpp:1324)
1314 // Test incompatible shapes
1315 auto a = createFloat64Array({2, 3});
1316 auto b = createFloat64Array({4}); // Incompatible for broadcasting
1317
1318 bool caught_exception = false;
1319 try {
1320 auto result = greater(a, b);
1321 } catch (const std::invalid_argument& e) {
1322 caught_exception = true;
1323 std::string msg(e.what());
1324 bool has_msg = msg.find("incompatible shapes") != std::string::npos;
1325 if (has_msg != true) {
1326 std::cout << "[FAIL] in testComparisonErrorHandling(): exception message missing 'incompatible shapes', got: " << msg << std::endl;
1327 throw std::runtime_error("testComparisonErrorHandling(): exception message incorrect");
1328 }
1329 }
1330 if (caught_exception != true) {
1331 std::cout << "[FAIL] in testComparisonErrorHandling(): expected exception not thrown" << std::endl;
1332 throw std::runtime_error("testComparisonErrorHandling(): shape incompatibility exception not thrown");
1333 }
1334 // std::cout << "[OK] Shape incompatibility exception handling" << std::endl;
find (np_test_1_all.cpp:1324)
1314 // Test incompatible shapes
1315 auto a = createFloat64Array({2, 3});
1316 auto b = createFloat64Array({4}); // Incompatible for broadcasting
1317
1318 bool caught_exception = false;
1319 try {
1320 auto result = greater(a, b);
1321 } catch (const std::invalid_argument& e) {
1322 caught_exception = true;
1323 std::string msg(e.what());
1324 bool has_msg = msg.find("incompatible shapes") != std::string::npos;
1325 if (has_msg != true) {
1326 std::cout << "[FAIL] in testComparisonErrorHandling(): exception message missing 'incompatible shapes', got: " << msg << std::endl;
1327 throw std::runtime_error("testComparisonErrorHandling(): exception message incorrect");
1328 }
1329 }
1330 if (caught_exception != true) {
1331 std::cout << "[FAIL] in testComparisonErrorHandling(): expected exception not thrown" << std::endl;
1332 throw std::runtime_error("testComparisonErrorHandling(): shape incompatibility exception not thrown");
1333 }
1334 // std::cout << "[OK] Shape incompatibility exception handling" << std::endl;
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 =======================";
push_back (np_test_1_all.cpp:1820)
1810 if (!(*extracted[i].get_as<int>() == values[i])) {
1811 std::string description = std::string("testObjectArrayOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*extracted[i].get_as<int>() == values[i])";
1812 std::cout << std::string("[FAIL] ") + description << std::endl;
1813 throw std::runtime_error(description);
1814 }
1815 }
1816
1817 // Test homogeneous array detection
1818 std::vector<NDArray<double>> double_arrays;
1819 for (int i = 0; i < 3; ++i) {
1820 double_arrays.push_back(NDArray<double>({2}, i * 1.5));
1821 }
1822
1823 NDArray<object_> homogeneous = createObjectArrayFromNDArrays(double_arrays);
1824 if (!(NestedArray<double>::isHomogeneousArrays(homogeneous))) {
1825 std::string description = std::string("testObjectArrayOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(NestedArray<double>::isHomogeneousArrays(homogeneous))";
1826 std::cout << std::string("[FAIL] ") + description << std::endl;
1827 throw std::runtime_error(description);
1828 }
1829
1830 // Test heterogeneous detection
rbegin (np_test_3_all.cpp:6341)
6331 }
6332
6333 void test_large_data_handling() {
6334 std::cout << "========= test_large_data_handling =======================";
6335
6336 // Test with data that exceeds typical cache sizes
6337 const size_t large_size = 50000; // Should exceed most L3 caches when using ints
6338 std::vector<int> large_data(large_size);
6339
6340 // Initialize with reverse sorted data for worst case
6341 std::iota(large_data.rbegin(), large_data.rend(), 1);
6342
6343 std::vector<int> expected = large_data;
6344 std::sort(expected.begin(), expected.end());
6345
6346 cache_oblivious_mergesort(large_data.begin(), large_data.end(), std::less<int>());
6347
6348 if (!(large_data == expected)) {
6349 std::string description = std::string("test_large_data_handling():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(large_data == expected)";
6350 std::cout << std::string("[FAIL] ") + description << std::endl;
6351 throw std::runtime_error(description);
rbegin (np_test_3_all.cpp:6341)
6331 }
6332
6333 void test_large_data_handling() {
6334 std::cout << "========= test_large_data_handling =======================";
6335
6336 // Test with data that exceeds typical cache sizes
6337 const size_t large_size = 50000; // Should exceed most L3 caches when using ints
6338 std::vector<int> large_data(large_size);
6339
6340 // Initialize with reverse sorted data for worst case
6341 std::iota(large_data.rbegin(), large_data.rend(), 1);
6342
6343 std::vector<int> expected = large_data;
6344 std::sort(expected.begin(), expected.end());
6345
6346 cache_oblivious_mergesort(large_data.begin(), large_data.end(), std::less<int>());
6347
6348 if (!(large_data == expected)) {
6349 std::string description = std::string("test_large_data_handling():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(large_data == expected)";
6350 std::cout << std::string("[FAIL] ") + description << std::endl;
6351 throw std::runtime_error(description);
rend (np_test_3_all.cpp:6341)
6331 }
6332
6333 void test_large_data_handling() {
6334 std::cout << "========= test_large_data_handling =======================";
6335
6336 // Test with data that exceeds typical cache sizes
6337 const size_t large_size = 50000; // Should exceed most L3 caches when using ints
6338 std::vector<int> large_data(large_size);
6339
6340 // Initialize with reverse sorted data for worst case
6341 std::iota(large_data.rbegin(), large_data.rend(), 1);
6342
6343 std::vector<int> expected = large_data;
6344 std::sort(expected.begin(), expected.end());
6345
6346 cache_oblivious_mergesort(large_data.begin(), large_data.end(), std::less<int>());
6347
6348 if (!(large_data == expected)) {
6349 std::string description = std::string("test_large_data_handling():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(large_data == expected)";
6350 std::cout << std::string("[FAIL] ") + description << std::endl;
6351 throw std::runtime_error(description);
rend (np_test_3_all.cpp:6341)
6331 }
6332
6333 void test_large_data_handling() {
6334 std::cout << "========= test_large_data_handling =======================";
6335
6336 // Test with data that exceeds typical cache sizes
6337 const size_t large_size = 50000; // Should exceed most L3 caches when using ints
6338 std::vector<int> large_data(large_size);
6339
6340 // Initialize with reverse sorted data for worst case
6341 std::iota(large_data.rbegin(), large_data.rend(), 1);
6342
6343 std::vector<int> expected = large_data;
6344 std::sort(expected.begin(), expected.end());
6345
6346 cache_oblivious_mergesort(large_data.begin(), large_data.end(), std::less<int>());
6347
6348 if (!(large_data == expected)) {
6349 std::string description = std::string("test_large_data_handling():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(large_data == expected)";
6350 std::cout << std::string("[FAIL] ") + description << std::endl;
6351 throw std::runtime_error(description);
reserve (np_test_1_all.cpp:6763)
6753 // arr_2d.print();
6754
6755 std::cout << " -> tests passed" << std::endl;
6756}
6757
6758void testCharArrayPerformanceCharArray() {
6759 std::cout << "========= testCharArrayPerformance =======================";
6760
6761 const size_t large_size = 1000;
6762 std::vector<std::string> large_data;
6763 large_data.reserve(large_size);
6764
6765 for (size_t i = 0; i < large_size; ++i) {
6766 large_data.push_back("String_" + std::to_string(i));
6767 }
6768
6769 // std::cout << "Creating large CharArray with " << large_size << " strings..." << std::endl;
6770 auto large_arr = array<32>(large_data);
6771
6772 // std::cout << "Performing upper case conversion..." << std::endl;
6773 auto upper_result = upper(large_arr);
rfind (np_test_5_all.cpp:1300)
1290 }
1291
1292 std::cout << " -> tests passed" << std::endl;
1293 }
1294
1295 void np_test_string_rfind() {
1296 std::cout << "========= rfind search operation =======================";
1297
1298 std::vector<std::string> strings = { "hello world hello", "test string test" };
1299 auto arr = numpy::char_::array<32>(strings);
1300 auto indices = numpy::char_::rfind(arr, "e");
1301
1302 bool passed = (indices.getSize() == arr.size());
1303
1304 if (!passed) {
1305 std::cout << " [FAIL] : in np_test_string_rfind() : indices size mismatch";
1306 throw std::runtime_error("np_test_string_rfind failed");
1307 }
1308
1309 std::cout << " -> tests passed" << std::endl;
1310 }
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")) {
substr (np_test_1_all.cpp:7373)
7363 str32 s2(" World");
7364
7365 str32 s3 = s1 + s2;
7366 // std::cout << "'" << s1 << "' + '" << s2 << "' = '" << s3 << "'" << std::endl;
7367
7368 s1 += s2;
7369 // std::cout << "After +=: '" << s1 << "'" << std::endl;
7370
7371 // Test substring
7372 str32 full("Programming");
7373 str32 sub = full.substr(0, 7);
7374 // std::cout << "Substring of '" << full << "' (0,7): '" << sub << "'" << std::endl;
7375
7376 // Test find
7377 str32 search("Hello World Programming");
7378 size_t pos = search.find(str32("World"));
7379 // std::cout << "Position of 'World' in '" << search << "': " << pos << std::endl;
7380
7381 // Test utility functions
7382 str32 lower = to_lower(str32("UPPERCASE"));
7383 str32 upper = to_upper(str32("lowercase"));
utf8_to_utf32 (np_test_1_all.cpp:12748)
12738 // std::cout << "String argsort test passed" << std::endl;
12739
12740 std::cout << " -> tests passed" << std::endl;
12741 }
12742
12743 void test_utf8_conversion() {
12744 std::cout << "========= test_utf8_conversion =======================";
12745
12746 // Test UTF-8 to UTF-32 conversion
12747 std::string utf8_str = "Hello";
12748 auto utf32_str = numpy::string_sort::detail::utf8_to_utf32(utf8_str);
12749
12750 if (!(utf32_str.size() == utf8_str.size())) {
12751 std::string description = std::string("test_utf8_conversion():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(utf32_str.size() == utf8_str.size())";
12752 std::cout << std::string("[FAIL] ") + description << std::endl;
12753 throw std::runtime_error(description);
12754 }
12755
12756 // Test with ASCII characters
12757 for (size_t i = 0; i < utf8_str.size(); ++i) {
12758 if (!(utf32_str[i] == static_cast<char32_t>(utf8_str[i]))) {