vunicode_ ========= .. cpp:class:: numpy::vunicode_ numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use vunicode_ vunicode_ obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``vunicode\_(const char \*s)`` - NP_VARIABLE_STRING.H:389 - :ref:`View ` * - ``vunicode\_(const std::string &s)`` - NP_VARIABLE_STRING.H:391 - :ref:`View ` * - ``vunicode\_(const std::u32string &s)`` - NP_VARIABLE_STRING.H:393 - :ref:`View ` * - ``noexcept vunicode\_(std::u32string &&s)`` - NP_VARIABLE_STRING.H:395 - :ref:`View ` * - ``vunicode\_(const vunicode\_ &other)`` - NP_VARIABLE_STRING.H:398 - :ref:`View ` * - ``noexcept vunicode\_(vunicode\_ &&other)`` - NP_VARIABLE_STRING.H:400 - :ref:`View ` Operators --------- .. list-table:: :widths: 40 25 15 20 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``vunicode\_ & operator=(const vunicode\_ &other)`` - vunicode\_ & - NP_VARIABLE_STRING.H:403 - * - ``vunicode\_ & noexcept operator=(vunicode\_ &&other)`` - vunicode\_ & noexcept - NP_VARIABLE_STRING.H:410 - * - ``vunicode\_ & operator=(const char \*s)`` - vunicode\_ & - NP_VARIABLE_STRING.H:417 - * - ``vunicode\_ & operator=(const std::string &s)`` - vunicode\_ & - NP_VARIABLE_STRING.H:422 - * - ``vunicode\_ & operator=(const std::u32string &s)`` - vunicode\_ & - NP_VARIABLE_STRING.H:427 - * - ``char32_t & operator[](size_tpos)`` - char32_t & - NP_VARIABLE_STRING.H:442 - * - ``const char32_t & operator[](size_tpos)`` - const char32_t & - NP_VARIABLE_STRING.H:443 - * - ``vunicode\_ operator+(const vunicode\_ &other)`` - vunicode\_ - NP_VARIABLE_STRING.H:492 - * - ``vunicode\_ & operator+=(const vunicode\_ &other)`` - vunicode\_ & - NP_VARIABLE_STRING.H:496 - * - ``vunicode\_ & operator+=(char32_tc)`` - vunicode\_ & - NP_VARIABLE_STRING.H:501 - * - ``bool operator==(const vunicode\_ &other)`` - bool - NP_VARIABLE_STRING.H:552 - * - ``bool operator!=(const vunicode\_ &other)`` - bool - NP_VARIABLE_STRING.H:556 - * - ``bool operator<(const vunicode\_ &other)`` - bool - NP_VARIABLE_STRING.H:560 - * - ``bool operator<=(const vunicode\_ &other)`` - bool - NP_VARIABLE_STRING.H:564 - * - ``bool operator>(const vunicode\_ &other)`` - bool - NP_VARIABLE_STRING.H:568 - * - ``bool operator>=(const vunicode\_ &other)`` - bool - NP_VARIABLE_STRING.H:572 - Array Creation -------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool empty()`` - bool - NP_VARIABLE_STRING.H:437 - :ref:`View ` Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``char32_t & at(size_tpos)`` - char32_t & - NP_VARIABLE_STRING.H:445 - :ref:`View ` * - ``const char32_t & at(size_tpos)`` - const char32_t & - NP_VARIABLE_STRING.H:446 - :ref:`View ` * - ``char32_t at_safe(size_tpos)`` - char32_t - NP_VARIABLE_STRING.H:466 - :ref:`View ` Shape Manipulation ------------------ .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void resize(size_tnew_size)`` - void - NP_VARIABLE_STRING.H:530 - :ref:`View ` * - ``void resize(size_tnew_size, char32_tc)`` - void - NP_VARIABLE_STRING.H:534 - :ref:`View ` Statistics ---------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``size_t max_size()`` - size_t - NP_VARIABLE_STRING.H:439 - I/O --- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``std::string to_string()`` - std::string - NP_VARIABLE_STRING.H:586 - :ref:`View ` * - ``std::u32string to_u32string()`` - std::u32string - NP_VARIABLE_STRING.H:581 - * - ``std::string to_utf8()`` - std::string - NP_VARIABLE_STRING.H:577 - :ref:`View ` Joining / Splitting ------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void append(const vunicode\_ &other)`` - void - NP_VARIABLE_STRING.H:506 - :ref:`View ` * - ``void append(size_tn, char32_tc)`` - void - NP_VARIABLE_STRING.H:510 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``char32_t & back()`` - char32_t & - NP_VARIABLE_STRING.H:451 - :ref:`View ` * - ``const char32_t & back()`` - const char32_t & - NP_VARIABLE_STRING.H:452 - :ref:`View ` * - ``auto begin()`` - auto - NP_VARIABLE_STRING.H:591 - :ref:`View ` * - ``auto begin()`` - auto - NP_VARIABLE_STRING.H:593 - :ref:`View ` * - ``size_t byte_size()`` - size_t - NP_VARIABLE_STRING.H:436 - :ref:`View ` * - ``size_t capacity()`` - size_t - NP_VARIABLE_STRING.H:438 - * - ``auto cbegin()`` - auto - NP_VARIABLE_STRING.H:595 - * - ``auto cend()`` - auto - NP_VARIABLE_STRING.H:596 - * - ``size_t char_count()`` - size_t - NP_VARIABLE_STRING.H:435 - :ref:`View ` * - ``void clear()`` - void - NP_VARIABLE_STRING.H:522 - :ref:`View ` * - ``auto crbegin()`` - auto - NP_VARIABLE_STRING.H:601 - * - ``auto crend()`` - auto - NP_VARIABLE_STRING.H:602 - * - ``auto end()`` - auto - NP_VARIABLE_STRING.H:592 - :ref:`View ` * - ``auto end()`` - auto - NP_VARIABLE_STRING.H:594 - :ref:`View ` * - ``size_t find(const vunicode\_ &str, size_tpos = 0)`` - size_t - NP_VARIABLE_STRING.H:539 - :ref:`View ` * - ``size_t find(char32_tc, size_tpos = 0)`` - size_t - NP_VARIABLE_STRING.H:543 - :ref:`View ` * - ``char32_t & front()`` - char32_t & - NP_VARIABLE_STRING.H:448 - * - ``const char32_t & front()`` - const char32_t & - NP_VARIABLE_STRING.H:449 - * - ``size_t length()`` - size_t - NP_VARIABLE_STRING.H:434 - :ref:`View ` * - ``void pop_back()`` - void - NP_VARIABLE_STRING.H:518 - * - ``void push_back(char32_tc)`` - void - NP_VARIABLE_STRING.H:514 - :ref:`View ` * - ``auto rbegin()`` - auto - NP_VARIABLE_STRING.H:597 - :ref:`View ` * - ``auto rbegin()`` - auto - NP_VARIABLE_STRING.H:599 - :ref:`View ` * - ``auto rend()`` - auto - NP_VARIABLE_STRING.H:598 - :ref:`View ` * - ``auto rend()`` - auto - NP_VARIABLE_STRING.H:600 - :ref:`View ` * - ``void reserve(size_tnew_cap)`` - void - NP_VARIABLE_STRING.H:526 - :ref:`View ` * - ``size_t rfind(const vunicode\_ &str, size_tpos = std::u32string::npos)`` - size_t - NP_VARIABLE_STRING.H:547 - :ref:`View ` * - ``size_t size()`` - size_t - NP_VARIABLE_STRING.H:433 - :ref:`View ` * - ``vunicode\_ slice(intstart, intstop = -1)`` - vunicode\_ - NP_VARIABLE_STRING.H:474 - :ref:`View ` * - ``vunicode\_ substr(size_tpos = 0, size_tlen = std::u32string::npos)`` - vunicode\_ - NP_VARIABLE_STRING.H:455 - :ref:`View ` * - ``std::string utf32_to_utf8(const std::u32string &utf32_str)`` - std::string - NP_VARIABLE_STRING.H:356 - * - ``std::u32string utf8_to_utf32(const std::string &utf8_str)`` - std::u32string - NP_VARIABLE_STRING.H:288 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-vunicode_-vunicode_-0: .. dropdown:: vunicode_ (np_test_1_all.cpp:8704) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8694 :emphasize-lines: 11 // Concatenation vunicode_ combined = str1 + str2; if (!(combined.to_utf8() == "Hello World")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(combined.to_utf8() == \"Hello World\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Append operations vunicode_ str3("Test"); str3 += vunicode_(" Unicode"); if (!(str3.to_utf8() == "Test Unicode")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str3.to_utf8() == \"Test Unicode\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Substring vunicode_ sub = combined.substr(6, 5); // "World" if (!(sub.to_utf8() == "World")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sub.to_utf8() == \"World\")"; .. _example-vunicode_-vunicode_-1: .. dropdown:: vunicode_ (np_test_1_all.cpp:8704) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8694 :emphasize-lines: 11 // Concatenation vunicode_ combined = str1 + str2; if (!(combined.to_utf8() == "Hello World")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(combined.to_utf8() == \"Hello World\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Append operations vunicode_ str3("Test"); str3 += vunicode_(" Unicode"); if (!(str3.to_utf8() == "Test Unicode")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str3.to_utf8() == \"Test Unicode\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Substring vunicode_ sub = combined.substr(6, 5); // "World" if (!(sub.to_utf8() == "World")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sub.to_utf8() == \"World\")"; .. _example-vunicode_-vunicode_-2: .. dropdown:: vunicode_ (np_test_1_all.cpp:8704) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8694 :emphasize-lines: 11 // Concatenation vunicode_ combined = str1 + str2; if (!(combined.to_utf8() == "Hello World")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(combined.to_utf8() == \"Hello World\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Append operations vunicode_ str3("Test"); str3 += vunicode_(" Unicode"); if (!(str3.to_utf8() == "Test Unicode")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str3.to_utf8() == \"Test Unicode\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Substring vunicode_ sub = combined.substr(6, 5); // "World" if (!(sub.to_utf8() == "World")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sub.to_utf8() == \"World\")"; .. _example-vunicode_-vunicode_-3: .. dropdown:: vunicode_ (np_test_1_all.cpp:8704) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8694 :emphasize-lines: 11 // Concatenation vunicode_ combined = str1 + str2; if (!(combined.to_utf8() == "Hello World")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(combined.to_utf8() == \"Hello World\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Append operations vunicode_ str3("Test"); str3 += vunicode_(" Unicode"); if (!(str3.to_utf8() == "Test Unicode")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str3.to_utf8() == \"Test Unicode\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Substring vunicode_ sub = combined.substr(6, 5); // "World" if (!(sub.to_utf8() == "World")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sub.to_utf8() == \"World\")"; .. _example-vunicode_-vunicode_-4: .. dropdown:: vunicode_ (np_test_1_all.cpp:8704) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8694 :emphasize-lines: 11 // Concatenation vunicode_ combined = str1 + str2; if (!(combined.to_utf8() == "Hello World")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(combined.to_utf8() == \"Hello World\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Append operations vunicode_ str3("Test"); str3 += vunicode_(" Unicode"); if (!(str3.to_utf8() == "Test Unicode")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str3.to_utf8() == \"Test Unicode\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Substring vunicode_ sub = combined.substr(6, 5); // "World" if (!(sub.to_utf8() == "World")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sub.to_utf8() == \"World\")"; .. _example-vunicode_-vunicode_-5: .. dropdown:: vunicode_ (np_test_1_all.cpp:8704) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8694 :emphasize-lines: 11 // Concatenation vunicode_ combined = str1 + str2; if (!(combined.to_utf8() == "Hello World")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(combined.to_utf8() == \"Hello World\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Append operations vunicode_ str3("Test"); str3 += vunicode_(" Unicode"); if (!(str3.to_utf8() == "Test Unicode")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str3.to_utf8() == \"Test Unicode\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Substring vunicode_ sub = combined.substr(6, 5); // "World" if (!(sub.to_utf8() == "World")) { std::string description = std::string("testVUnicodeOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sub.to_utf8() == \"World\")"; .. _example-vunicode_-empty-6: .. dropdown:: empty (np_test_1_all.cpp:6316) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6306 :emphasize-lines: 11 } void test_data_generator_emptyBenchmarkSorting() { std::cout << "========= test_data_generator_empty ======================="; DataGenerator gen(42); // Test empty data generation std::vector data = gen.generate(0, DataPattern::RANDOM); if (!(data.empty())) { std::string description = std::string("test_data_generator_emptyBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Empty data generation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-vunicode_-at-7: .. dropdown:: at (np_test_1_all.cpp:144) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 134 :emphasize-lines: 11 array.setElementAt({0, 0}, 1); array.setElementAt({0, 1}, 2); array.setElementAt({0, 2}, 3); array.setElementAt({1, 1}, 5); array.setElementAt({2, 2}, 9); // std::cout << "Array after setting elements:" << std::endl; //array.printArray(); // std::cout << "Element at (1,1): " << array.getElementAt({1, 1}) << std::endl; // std::cout << "Element at (2,2): " << array.getElementAt({2, 2}); std::cout << " -> tests passed" << std::endl; } void testArithmetic() { std::cout << "========= testArithmeticOperations ======================="; auto array1 = createFloat32Array({2, 2}, 5.0f); auto array2 = createFloat32Array({2, 2}, 3.0f); .. _example-vunicode_-at-8: .. dropdown:: at (np_test_1_all.cpp:144) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 134 :emphasize-lines: 11 array.setElementAt({0, 0}, 1); array.setElementAt({0, 1}, 2); array.setElementAt({0, 2}, 3); array.setElementAt({1, 1}, 5); array.setElementAt({2, 2}, 9); // std::cout << "Array after setting elements:" << std::endl; //array.printArray(); // std::cout << "Element at (1,1): " << array.getElementAt({1, 1}) << std::endl; // std::cout << "Element at (2,2): " << array.getElementAt({2, 2}); std::cout << " -> tests passed" << std::endl; } void testArithmetic() { std::cout << "========= testArithmeticOperations ======================="; auto array1 = createFloat32Array({2, 2}, 5.0f); auto array2 = createFloat32Array({2, 2}, 3.0f); .. _example-vunicode_-at_safe-9: .. dropdown:: at_safe (np_test_1_all.cpp:13109) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13099 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void test_character_access_bounds() { std::cout << "========= test_character_access_bounds ======================="; vstring_ str1("abc"); // Test safe character access within bounds try { char c1 = str1.at_safe(0); // Should work if (!(c1 == 'a')) { std::string description = std::string("test_character_access_bounds():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(c1 == 'a')"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] at_safe(0) on 'abc' returns 'a'\n"; char c2 = str1.at_safe(2); // Should work if (!(c2 == 'c')) { std::string description = std::string("test_character_access_bounds():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(c2 == 'c')"; .. _example-vunicode_-resize-10: .. dropdown:: resize (np_test_2_all.cpp:8615) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8605 :emphasize-lines: 11 std::cout << " IPP empty array test: -> [FAIL]"; throw std::runtime_error("IPP empty array test: FAILED - should return empty"); } // std::cout << "[OK] IPP empty array test: PASSED" << std::endl; } // Test 6: Large array performance { const size_t n = 10000; std::vector> keys(2); keys[0].resize(n); keys[1].resize(n); std::mt19937 gen(42); std::uniform_int_distribution dist(0, 1000); for (size_t i = 0; i < n; ++i) { keys[0][i] = dist(gen); keys[1][i] = dist(gen); } .. _example-vunicode_-resize-11: .. dropdown:: resize (np_test_2_all.cpp:8615) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8605 :emphasize-lines: 11 std::cout << " IPP empty array test: -> [FAIL]"; throw std::runtime_error("IPP empty array test: FAILED - should return empty"); } // std::cout << "[OK] IPP empty array test: PASSED" << std::endl; } // Test 6: Large array performance { const size_t n = 10000; std::vector> keys(2); keys[0].resize(n); keys[1].resize(n); std::mt19937 gen(42); std::uniform_int_distribution dist(0, 1000); for (size_t i = 0; i < n; ++i) { keys[0][i] = dist(gen); keys[1][i] = dist(gen); } .. _example-vunicode_-to_string-12: .. dropdown:: to_string (np_test_1_all.cpp:454) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 444 :emphasize-lines: 11 // Modify through different views view1.setElementAt({0, 0}, 100); view2.setElementAt({2, 1}, 200); // This is (1, 2) in original view3.setElementAt({0, 0}, 300); // This is (1, 1) in original // std::cout << "After modifications through multiple views:" << std::endl; //original.printArray(); // Verify all changes are reflected if (!(original.getElementAt({0, 0}) == 100)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({0, 0}) == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(original.getElementAt({1, 2}) == 200)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 2}) == 200)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(original.getElementAt({1, 1}) == 300)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 300)"; .. _example-vunicode_-to_utf8-13: .. dropdown:: to_utf8 (np_test_1_all.cpp:8658) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8648 :emphasize-lines: 11 throw std::runtime_error(description); } // ASCII string vunicode_ ascii_str("Hello"); if (!(ascii_str.size() == 5)) { std::string description = std::string("testVUnicodeConstructionVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ascii_str.size() == 5)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(ascii_str.to_utf8() == "Hello")) { std::string description = std::string("testVUnicodeConstructionVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(ascii_str.to_utf8() == \"Hello\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // UTF-8 string with Unicode characters std::string utf8_str = "Héllo Wørld! 🌍"; vunicode_ unicode_str(utf8_str); if (!(!unicode_str.empty())) { std::string description = std::string("testVUnicodeConstructionVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!unicode_str.empty())"; .. _example-vunicode_-append-14: .. dropdown:: append (np_test_2_all.cpp:7028) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7018 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(deleted_dups.getElementAt({ 2 }) == 3)) { std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(deleted_dups.getElementAt({ 2 }) == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Delete with duplicate indices works correctly\n"; // Test append auto appended = append(array, 100); if (!(appended.getSize() == array.getSize() + 1)) { std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(appended.getSize() == array.getSize() + 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(appended.getElementAt({ appended.getSize() - 1 }) == 100)) { std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(appended.getElementAt({ appended.getSize() - 1 }) == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-vunicode_-append-15: .. dropdown:: append (np_test_2_all.cpp:7028) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7018 :emphasize-lines: 11 throw std::runtime_error(description); } if (!(deleted_dups.getElementAt({ 2 }) == 3)) { std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(deleted_dups.getElementAt({ 2 }) == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Delete with duplicate indices works correctly\n"; // Test append auto appended = append(array, 100); if (!(appended.getSize() == array.getSize() + 1)) { std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(appended.getSize() == array.getSize() + 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(appended.getElementAt({ appended.getSize() - 1 }) == 100)) { std::string description = std::string("testModificationOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(appended.getElementAt({ appended.getSize() - 1 }) == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-vunicode_-back-16: .. dropdown:: back (np_test_2_all.cpp:8251) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8241 :emphasize-lines: 11 // std::cout << "keys[1] = "; for (size_t i = 0; i < result.size(); ++i) { // std::cout << keys[1][result[i]] << " "; } // std::cout << ""; // Expected order based on primary key (last array), then secondary // Should sort by [9,4,0,4,0,2,1] first, then by [1,5,1,4,3,4,4] bool is_sorted = true; for (size_t i = 1; i < result.size(); ++i) { int prev_primary = keys.back()[result[i - 1]]; int curr_primary = keys.back()[result[i]]; if (prev_primary > curr_primary) { is_sorted = false; break; } else if (prev_primary == curr_primary) { int prev_secondary = keys[0][result[i - 1]]; int curr_secondary = keys[0][result[i]]; if (prev_secondary > curr_secondary) { .. _example-vunicode_-back-17: .. dropdown:: back (np_test_2_all.cpp:8251) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8241 :emphasize-lines: 11 // std::cout << "keys[1] = "; for (size_t i = 0; i < result.size(); ++i) { // std::cout << keys[1][result[i]] << " "; } // std::cout << ""; // Expected order based on primary key (last array), then secondary // Should sort by [9,4,0,4,0,2,1] first, then by [1,5,1,4,3,4,4] bool is_sorted = true; for (size_t i = 1; i < result.size(); ++i) { int prev_primary = keys.back()[result[i - 1]]; int curr_primary = keys.back()[result[i]]; if (prev_primary > curr_primary) { is_sorted = false; break; } else if (prev_primary == curr_primary) { int prev_secondary = keys[0][result[i - 1]]; int curr_secondary = keys[0][result[i]]; if (prev_secondary > curr_secondary) { .. _example-vunicode_-begin-18: .. dropdown:: begin (np_test_1_all.cpp:6171) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6161 :emphasize-lines: 11 // Test sorted data generation std::vector data = gen.generate(50, DataPattern::SORTED); if (!(data.size() == 50)) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Verify data is sorted if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Sorted data generation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-vunicode_-begin-19: .. dropdown:: begin (np_test_1_all.cpp:6171) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6161 :emphasize-lines: 11 // Test sorted data generation std::vector data = gen.generate(50, DataPattern::SORTED); if (!(data.size() == 50)) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Verify data is sorted if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Sorted data generation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-vunicode_-byte_size-20: .. dropdown:: byte_size (np_test_1_all.cpp:8536) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8526 :emphasize-lines: 11 std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Size operations if (!(str1.size() == 5)) { std::string description = std::string("testVStringOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str1.size() == 5)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(str1.byte_size() == 5)) { std::string description = std::string("testVStringOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str1.byte_size() == 5)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(!str1.empty())) { std::string description = std::string("testVStringOperationsVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!str1.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-vunicode_-char_count-21: .. dropdown:: char_count (np_test_1_all.cpp:8672) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8662 :emphasize-lines: 11 } // UTF-8 string with Unicode characters std::string utf8_str = "Héllo Wørld! 🌍"; vunicode_ unicode_str(utf8_str); if (!(!unicode_str.empty())) { std::string description = std::string("testVUnicodeConstructionVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!unicode_str.empty())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(unicode_str.to_utf8() == utf8_str || unicode_str.char_count() > 0)) { std::string description = std::string("testVUnicodeConstructionVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(unicode_str.to_utf8() == utf8_str || unicode_str.char_count() > 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Copy constructor vunicode_ copied(unicode_str); if (!(copied.to_utf8() == unicode_str.to_utf8())) { std::string description = std::string("testVUnicodeConstructionVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(copied.to_utf8() == unicode_str.to_utf8())"; std::cout << std::string("[FAIL] ") + description << std::endl; .. _example-vunicode_-clear-22: .. dropdown:: clear (np_test_2_all.cpp:4161) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4151 :emphasize-lines: 11 auto array = createFloat32Array({ 10, 10 }, static_cast(i)); temp_arrays.push_back(array); auto view = array.view(); temp_views.push_back(view); } // std::cout << "Created 100 arrays and 100 views" << std::endl; // Clear all arrays (views will keep memory alive) temp_arrays.clear(); // std::cout << "Cleared original arrays" << std::endl; // Verify views still work if (!(temp_views[50].getElementAt({ 5, 5 }) == 50.0f)) { std::string description = std::string("testMemoryLeakPrevention():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(temp_views[50].getElementAt({ 5, 5 }) == 50.0f)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Views still valid after originals cleared"; .. _example-vunicode_-end-23: .. dropdown:: end (np_test_1_all.cpp:6171) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6161 :emphasize-lines: 11 // Test sorted data generation std::vector data = gen.generate(50, DataPattern::SORTED); if (!(data.size() == 50)) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Verify data is sorted if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Sorted data generation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-vunicode_-end-24: .. dropdown:: end (np_test_1_all.cpp:6171) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6161 :emphasize-lines: 11 // Test sorted data generation std::vector data = gen.generate(50, DataPattern::SORTED); if (!(data.size() == 50)) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(data.size() == 50)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Verify data is sorted if (!(std::is_sorted(data.begin(), data.end()))) { std::string description = std::string("test_data_generator_sortedBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::is_sorted(data.begin(), data.end()))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Sorted data generation test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-vunicode_-find-25: .. dropdown:: find (np_test_1_all.cpp:1324) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1314 :emphasize-lines: 11 // Test incompatible shapes auto a = createFloat64Array({2, 3}); auto b = createFloat64Array({4}); // Incompatible for broadcasting bool caught_exception = false; try { auto result = greater(a, b); } catch (const std::invalid_argument& e) { caught_exception = true; std::string msg(e.what()); bool has_msg = msg.find("incompatible shapes") != std::string::npos; if (has_msg != true) { std::cout << "[FAIL] in testComparisonErrorHandling(): exception message missing 'incompatible shapes', got: " << msg << std::endl; throw std::runtime_error("testComparisonErrorHandling(): exception message incorrect"); } } if (caught_exception != true) { std::cout << "[FAIL] in testComparisonErrorHandling(): expected exception not thrown" << std::endl; throw std::runtime_error("testComparisonErrorHandling(): shape incompatibility exception not thrown"); } // std::cout << "[OK] Shape incompatibility exception handling" << std::endl; .. _example-vunicode_-find-26: .. dropdown:: find (np_test_1_all.cpp:1324) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1314 :emphasize-lines: 11 // Test incompatible shapes auto a = createFloat64Array({2, 3}); auto b = createFloat64Array({4}); // Incompatible for broadcasting bool caught_exception = false; try { auto result = greater(a, b); } catch (const std::invalid_argument& e) { caught_exception = true; std::string msg(e.what()); bool has_msg = msg.find("incompatible shapes") != std::string::npos; if (has_msg != true) { std::cout << "[FAIL] in testComparisonErrorHandling(): exception message missing 'incompatible shapes', got: " << msg << std::endl; throw std::runtime_error("testComparisonErrorHandling(): exception message incorrect"); } } if (caught_exception != true) { std::cout << "[FAIL] in testComparisonErrorHandling(): expected exception not thrown" << std::endl; throw std::runtime_error("testComparisonErrorHandling(): shape incompatibility exception not thrown"); } // std::cout << "[OK] Shape incompatibility exception handling" << std::endl; .. _example-vunicode_-length-27: .. dropdown:: length (np_test_1_all.cpp:7335) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7325 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void testStringTruncationStringTypes() { std::cout << "========= testStringTruncationStringTypes ======================="; // Test truncation behavior str8 small("This string is way too long for 8 characters"); // std::cout << "Long string in str8: '" << small << "'" << std::endl; // std::cout << "Length: " << small.length() << " (max: " << str8::max_size << ")" << std::endl; str16 medium("This is a medium length string that should be truncated"); // std::cout << "Medium string in str16: '" << medium << "'" << std::endl; // std::cout << "Length: " << medium.length() << " (max: " << str16::max_size << ")" << std::endl; std::cout << " -> tests passed" << std::endl; } void testStringComparisonsStringTypes() { std::cout << "========= testStringComparisonsStringTypes ======================="; .. _example-vunicode_-push_back-28: .. dropdown:: push_back (np_test_1_all.cpp:1820) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1810 :emphasize-lines: 11 if (!(*extracted[i].get_as() == values[i])) { std::string description = std::string("testObjectArrayOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(*extracted[i].get_as() == values[i])"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } } // Test homogeneous array detection std::vector> double_arrays; for (int i = 0; i < 3; ++i) { double_arrays.push_back(NDArray({2}, i * 1.5)); } NDArray homogeneous = createObjectArrayFromNDArrays(double_arrays); if (!(NestedArray::isHomogeneousArrays(homogeneous))) { std::string description = std::string("testObjectArrayOperations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(NestedArray::isHomogeneousArrays(homogeneous))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test heterogeneous detection .. _example-vunicode_-rbegin-29: .. dropdown:: rbegin (np_test_3_all.cpp:6341) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6331 :emphasize-lines: 11 } void test_large_data_handling() { std::cout << "========= test_large_data_handling ======================="; // Test with data that exceeds typical cache sizes const size_t large_size = 50000; // Should exceed most L3 caches when using ints std::vector large_data(large_size); // Initialize with reverse sorted data for worst case std::iota(large_data.rbegin(), large_data.rend(), 1); std::vector expected = large_data; std::sort(expected.begin(), expected.end()); cache_oblivious_mergesort(large_data.begin(), large_data.end(), std::less()); if (!(large_data == expected)) { std::string description = std::string("test_large_data_handling():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(large_data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-vunicode_-rbegin-30: .. dropdown:: rbegin (np_test_3_all.cpp:6341) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6331 :emphasize-lines: 11 } void test_large_data_handling() { std::cout << "========= test_large_data_handling ======================="; // Test with data that exceeds typical cache sizes const size_t large_size = 50000; // Should exceed most L3 caches when using ints std::vector large_data(large_size); // Initialize with reverse sorted data for worst case std::iota(large_data.rbegin(), large_data.rend(), 1); std::vector expected = large_data; std::sort(expected.begin(), expected.end()); cache_oblivious_mergesort(large_data.begin(), large_data.end(), std::less()); if (!(large_data == expected)) { std::string description = std::string("test_large_data_handling():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(large_data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-vunicode_-rend-31: .. dropdown:: rend (np_test_3_all.cpp:6341) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6331 :emphasize-lines: 11 } void test_large_data_handling() { std::cout << "========= test_large_data_handling ======================="; // Test with data that exceeds typical cache sizes const size_t large_size = 50000; // Should exceed most L3 caches when using ints std::vector large_data(large_size); // Initialize with reverse sorted data for worst case std::iota(large_data.rbegin(), large_data.rend(), 1); std::vector expected = large_data; std::sort(expected.begin(), expected.end()); cache_oblivious_mergesort(large_data.begin(), large_data.end(), std::less()); if (!(large_data == expected)) { std::string description = std::string("test_large_data_handling():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(large_data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-vunicode_-rend-32: .. dropdown:: rend (np_test_3_all.cpp:6341) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6331 :emphasize-lines: 11 } void test_large_data_handling() { std::cout << "========= test_large_data_handling ======================="; // Test with data that exceeds typical cache sizes const size_t large_size = 50000; // Should exceed most L3 caches when using ints std::vector large_data(large_size); // Initialize with reverse sorted data for worst case std::iota(large_data.rbegin(), large_data.rend(), 1); std::vector expected = large_data; std::sort(expected.begin(), expected.end()); cache_oblivious_mergesort(large_data.begin(), large_data.end(), std::less()); if (!(large_data == expected)) { std::string description = std::string("test_large_data_handling():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(large_data == expected)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); .. _example-vunicode_-reserve-33: .. dropdown:: reserve (np_test_1_all.cpp:6763) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6753 :emphasize-lines: 11 // arr_2d.print(); std::cout << " -> tests passed" << std::endl; } void testCharArrayPerformanceCharArray() { std::cout << "========= testCharArrayPerformance ======================="; const size_t large_size = 1000; std::vector large_data; large_data.reserve(large_size); for (size_t i = 0; i < large_size; ++i) { large_data.push_back("String_" + std::to_string(i)); } // std::cout << "Creating large CharArray with " << large_size << " strings..." << std::endl; auto large_arr = array<32>(large_data); // std::cout << "Performing upper case conversion..." << std::endl; auto upper_result = upper(large_arr); .. _example-vunicode_-rfind-34: .. dropdown:: rfind (np_test_5_all.cpp:1300) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 1290 :emphasize-lines: 11 } std::cout << " -> tests passed" << std::endl; } void np_test_string_rfind() { std::cout << "========= rfind search operation ======================="; std::vector strings = { "hello world hello", "test string test" }; auto arr = numpy::char_::array<32>(strings); auto indices = numpy::char_::rfind(arr, "e"); bool passed = (indices.getSize() == arr.size()); if (!passed) { std::cout << " [FAIL] : in np_test_string_rfind() : indices size mismatch"; throw std::runtime_error("np_test_string_rfind failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-vunicode_-size-35: .. dropdown:: size (np_test_1_all.cpp:47) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 37 :emphasize-lines: 11 using namespace numpy; using namespace numpy::benchmark; using namespace numpy::char_; // Helper functions for array comparison tests namespace { const double TOLERANCE = 1e-10; bool allTrue(const NDArray& arr) { std::vector indices(arr.getShape().size(), 0); do { if (!arr.getElementAt(indices)) { return false; } } while (incrementIndices(indices, arr.getShape())); return true; } bool allFalse(const NDArray& arr) { std::vector indices(arr.getShape().size(), 0); .. _example-vunicode_-slice-36: .. dropdown:: slice (np_test_1_all.cpp:13009) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12999 :emphasize-lines: 11 // Test substr valid start but excessive length auto result3 = str1.substr(2, 10); // start=2, len=10 on string of length 5 if (!(result3.to_string() == "llo")) { std::string description = std::string("test_variable_string_out_of_bounds():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result3.to_string() == \"llo\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] vstring_ substr(2, 10) on 'hello' returns 'llo'\n"; // Test slice method with out-of-bounds auto result4 = str1.slice(10, 15); // slice[10:15] on string of length 5 if (!(result4.to_string() == "")) { std::string description = std::string("test_variable_string_out_of_bounds():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result4.to_string() == \"\")"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] vstring_ slice(10, 15) on 'hello' returns empty string\n"; // Test slice with negative indices auto result5 = str1.slice(-2, -1); // slice[-2:-1] should be "l" if (!(result5.to_string() == "l")) { .. _example-vunicode_-substr-37: .. dropdown:: substr (np_test_1_all.cpp:7373) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7363 :emphasize-lines: 11 str32 s2(" World"); str32 s3 = s1 + s2; // std::cout << "'" << s1 << "' + '" << s2 << "' = '" << s3 << "'" << std::endl; s1 += s2; // std::cout << "After +=: '" << s1 << "'" << std::endl; // Test substring str32 full("Programming"); str32 sub = full.substr(0, 7); // std::cout << "Substring of '" << full << "' (0,7): '" << sub << "'" << std::endl; // Test find str32 search("Hello World Programming"); size_t pos = search.find(str32("World")); // std::cout << "Position of 'World' in '" << search << "': " << pos << std::endl; // Test utility functions str32 lower = to_lower(str32("UPPERCASE")); str32 upper = to_upper(str32("lowercase")); .. _example-vunicode_-utf8_to_utf32-38: .. dropdown:: utf8_to_utf32 (np_test_1_all.cpp:12748) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 12738 :emphasize-lines: 11 // std::cout << "String argsort test passed" << std::endl; std::cout << " -> tests passed" << std::endl; } void test_utf8_conversion() { std::cout << "========= test_utf8_conversion ======================="; // Test UTF-8 to UTF-32 conversion std::string utf8_str = "Hello"; auto utf32_str = numpy::string_sort::detail::utf8_to_utf32(utf8_str); if (!(utf32_str.size() == utf8_str.size())) { std::string description = std::string("test_utf8_conversion():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(utf32_str.size() == utf8_str.size())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // Test with ASCII characters for (size_t i = 0; i < utf8_str.size(); ++i) { if (!(utf32_str[i] == static_cast(utf8_str[i]))) {