vstring#

class numpy::vstring_#

numpy C++ class.

Example#

#include <numpy/np_ndarray.h>
using namespace numpy;

// Use vstring_
vstring_ obj;
// ... operations ...

Constructors#

Signature

Location

Example

vstring\_(const char \*s)

NP_VARIABLE_STRING.H:18

View

vstring\_(const std::string &s)

NP_VARIABLE_STRING.H:20

View

noexcept vstring\_(std::string &&s)

NP_VARIABLE_STRING.H:22

View

vstring\_(const vstring\_ &other)

NP_VARIABLE_STRING.H:25

View

noexcept vstring\_(vstring\_ &&other)

NP_VARIABLE_STRING.H:28

View

Operators#

Signature

Return Type

Location

Example

vstring\_ & operator=(const vstring\_ &other)

vstring_ &

NP_VARIABLE_STRING.H:31

vstring\_ & noexcept operator=(vstring\_ &&other)

vstring_ & noexcept

NP_VARIABLE_STRING.H:38

vstring\_ & operator=(const char \*s)

vstring_ &

NP_VARIABLE_STRING.H:45

vstring\_ & operator=(const std::string &s)

vstring_ &

NP_VARIABLE_STRING.H:50

vstring\_ & noexcept operator=(std::string &&s)

vstring_ & noexcept

NP_VARIABLE_STRING.H:55

char & operator[](size_tpos)

char &

NP_VARIABLE_STRING.H:69

const char & operator[](size_tpos)

const char &

NP_VARIABLE_STRING.H:70

vstring\_ operator+(const vstring\_ &other)

vstring_

NP_VARIABLE_STRING.H:119

vstring\_ & operator+=(const vstring\_ &other)

vstring_ &

NP_VARIABLE_STRING.H:123

vstring\_ & operator+=(const char \*s)

vstring_ &

NP_VARIABLE_STRING.H:128

vstring\_ & operator+=(charc)

vstring_ &

NP_VARIABLE_STRING.H:133

bool operator==(const vstring\_ &other)

bool

NP_VARIABLE_STRING.H:192

bool operator!=(const vstring\_ &other)

bool

NP_VARIABLE_STRING.H:196

bool operator<(const vstring\_ &other)

bool

NP_VARIABLE_STRING.H:200

bool operator<=(const vstring\_ &other)

bool

NP_VARIABLE_STRING.H:204

bool operator>(const vstring\_ &other)

bool

NP_VARIABLE_STRING.H:208

bool operator>=(const vstring\_ &other)

bool

NP_VARIABLE_STRING.H:212

bool operator==(const char \*s)

bool

NP_VARIABLE_STRING.H:217

bool operator!=(const char \*s)

bool

NP_VARIABLE_STRING.H:221

bool operator==(const std::string &s)

bool

NP_VARIABLE_STRING.H:226

bool operator!=(const std::string &s)

bool

NP_VARIABLE_STRING.H:230

Array Creation#

Signature

Return Type

Location

Example

bool empty()

bool

NP_VARIABLE_STRING.H:64

View

Indexing / Selection#

Signature

Return Type

Location

Example

char & at(size_tpos)

char &

NP_VARIABLE_STRING.H:72

View

const char & at(size_tpos)

const char &

NP_VARIABLE_STRING.H:73

View

char at_safe(size_tpos)

char

NP_VARIABLE_STRING.H:93

View

Shape Manipulation#

Signature

Return Type

Location

Example

void resize(size_tnew_size)

void

NP_VARIABLE_STRING.H:166

View

void resize(size_tnew_size, charc)

void

NP_VARIABLE_STRING.H:170

View

Statistics#

Signature

Return Type

Location

Example

size_t max_size()

size_t

NP_VARIABLE_STRING.H:66

I/O#

Signature

Return Type

Location

Example

std::string to_string()

std::string

NP_VARIABLE_STRING.H:235

View

Joining / Splitting#

Signature

Return Type

Location

Example

void append(const vstring\_ &other)

void

NP_VARIABLE_STRING.H:138

View

void append(const char \*s)

void

NP_VARIABLE_STRING.H:142

View

void append(size_tn, charc)

void

NP_VARIABLE_STRING.H:146

View

Other Methods#

Signature

Return Type

Location

Example

char & back()

char &

NP_VARIABLE_STRING.H:78

View

const char & back()

const char &

NP_VARIABLE_STRING.H:79

View

auto begin()

auto

NP_VARIABLE_STRING.H:248

View

auto begin()

auto

NP_VARIABLE_STRING.H:250

View

size_t byte_size()

size_t

NP_VARIABLE_STRING.H:63

View

const char \* c_str()

const char *

NP_VARIABLE_STRING.H:239

View

size_t capacity()

size_t

NP_VARIABLE_STRING.H:65

auto cbegin()

auto

NP_VARIABLE_STRING.H:252

auto cend()

auto

NP_VARIABLE_STRING.H:253

void clear()

void

NP_VARIABLE_STRING.H:158

View

auto crbegin()

auto

NP_VARIABLE_STRING.H:258

auto crend()

auto

NP_VARIABLE_STRING.H:259

const char \* data()

const char *

NP_VARIABLE_STRING.H:243

View

auto end()

auto

NP_VARIABLE_STRING.H:249

View

auto end()

auto

NP_VARIABLE_STRING.H:251

View

size_t find(const vstring\_ &str, size_tpos = 0)

size_t

NP_VARIABLE_STRING.H:175

View

size_t find(const char \*s, size_tpos = 0)

size_t

NP_VARIABLE_STRING.H:179

View

size_t find(charc, size_tpos = 0)

size_t

NP_VARIABLE_STRING.H:183

View

char & front()

char &

NP_VARIABLE_STRING.H:75

const char & front()

const char &

NP_VARIABLE_STRING.H:76

size_t length()

size_t

NP_VARIABLE_STRING.H:62

View

void pop_back()

void

NP_VARIABLE_STRING.H:154

void push_back(charc)

void

NP_VARIABLE_STRING.H:150

View

auto rbegin()

auto

NP_VARIABLE_STRING.H:254

View

auto rbegin()

auto

NP_VARIABLE_STRING.H:256

View

auto rend()

auto

NP_VARIABLE_STRING.H:255

View

auto rend()

auto

NP_VARIABLE_STRING.H:257

View

void reserve(size_tnew_cap)

void

NP_VARIABLE_STRING.H:162

View

size_t rfind(const vstring\_ &str, size_tpos = std::string::npos)

size_t

NP_VARIABLE_STRING.H:187

View

size_t size()

size_t

NP_VARIABLE_STRING.H:61

View

vstring\_ slice(intstart, intstop = -1)

vstring_

NP_VARIABLE_STRING.H:101

View

vstring\_ substr(size_tpos = 0, size_tlen = std::string::npos)

vstring_

NP_VARIABLE_STRING.H:82

View

Code Examples#

The following examples are extracted from the test suite.

vstring (np_test_1_all.cpp:8471)
8461    // Copy assignment
8462    vstring_ other("Test");
8463    str = other;
8464    if (!(str.to_string() == "Test")) {
8465        std::string description = std::string("testVStringAssignmentVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str.to_string() == \"Test\")";
8466        std::cout << std::string("[FAIL] ") + description << std::endl;
8467        throw std::runtime_error(description);
8468    }
8469
8470    // Move assignment
8471    str = vstring_("Moved");
8472    if (!(str.to_string() == "Moved")) {
8473        std::string description = std::string("testVStringAssignmentVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str.to_string() == \"Moved\")";
8474        std::cout << std::string("[FAIL] ") + description << std::endl;
8475        throw std::runtime_error(description);
8476    }
8477    std::cout << " -> tests passed" << std::endl;
8478}
8479
8480void testVStringOperationsVariableStrings() {
8481    std::cout << "========= testVStringOperationsVariableStrings =======================";
vstring (np_test_1_all.cpp:8471)
8461    // Copy assignment
8462    vstring_ other("Test");
8463    str = other;
8464    if (!(str.to_string() == "Test")) {
8465        std::string description = std::string("testVStringAssignmentVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str.to_string() == \"Test\")";
8466        std::cout << std::string("[FAIL] ") + description << std::endl;
8467        throw std::runtime_error(description);
8468    }
8469
8470    // Move assignment
8471    str = vstring_("Moved");
8472    if (!(str.to_string() == "Moved")) {
8473        std::string description = std::string("testVStringAssignmentVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str.to_string() == \"Moved\")";
8474        std::cout << std::string("[FAIL] ") + description << std::endl;
8475        throw std::runtime_error(description);
8476    }
8477    std::cout << " -> tests passed" << std::endl;
8478}
8479
8480void testVStringOperationsVariableStrings() {
8481    std::cout << "========= testVStringOperationsVariableStrings =======================";
vstring (np_test_1_all.cpp:8471)
8461    // Copy assignment
8462    vstring_ other("Test");
8463    str = other;
8464    if (!(str.to_string() == "Test")) {
8465        std::string description = std::string("testVStringAssignmentVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str.to_string() == \"Test\")";
8466        std::cout << std::string("[FAIL] ") + description << std::endl;
8467        throw std::runtime_error(description);
8468    }
8469
8470    // Move assignment
8471    str = vstring_("Moved");
8472    if (!(str.to_string() == "Moved")) {
8473        std::string description = std::string("testVStringAssignmentVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str.to_string() == \"Moved\")";
8474        std::cout << std::string("[FAIL] ") + description << std::endl;
8475        throw std::runtime_error(description);
8476    }
8477    std::cout << " -> tests passed" << std::endl;
8478}
8479
8480void testVStringOperationsVariableStrings() {
8481    std::cout << "========= testVStringOperationsVariableStrings =======================";
vstring (np_test_1_all.cpp:8471)
8461    // Copy assignment
8462    vstring_ other("Test");
8463    str = other;
8464    if (!(str.to_string() == "Test")) {
8465        std::string description = std::string("testVStringAssignmentVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str.to_string() == \"Test\")";
8466        std::cout << std::string("[FAIL] ") + description << std::endl;
8467        throw std::runtime_error(description);
8468    }
8469
8470    // Move assignment
8471    str = vstring_("Moved");
8472    if (!(str.to_string() == "Moved")) {
8473        std::string description = std::string("testVStringAssignmentVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str.to_string() == \"Moved\")";
8474        std::cout << std::string("[FAIL] ") + description << std::endl;
8475        throw std::runtime_error(description);
8476    }
8477    std::cout << " -> tests passed" << std::endl;
8478}
8479
8480void testVStringOperationsVariableStrings() {
8481    std::cout << "========= testVStringOperationsVariableStrings =======================";
vstring (np_test_1_all.cpp:8471)
8461    // Copy assignment
8462    vstring_ other("Test");
8463    str = other;
8464    if (!(str.to_string() == "Test")) {
8465        std::string description = std::string("testVStringAssignmentVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str.to_string() == \"Test\")";
8466        std::cout << std::string("[FAIL] ") + description << std::endl;
8467        throw std::runtime_error(description);
8468    }
8469
8470    // Move assignment
8471    str = vstring_("Moved");
8472    if (!(str.to_string() == "Moved")) {
8473        std::string description = std::string("testVStringAssignmentVariableStrings():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(str.to_string() == \"Moved\")";
8474        std::cout << std::string("[FAIL] ") + description << std::endl;
8475        throw std::runtime_error(description);
8476    }
8477    std::cout << " -> tests passed" << std::endl;
8478}
8479
8480void testVStringOperationsVariableStrings() {
8481    std::cout << "========= testVStringOperationsVariableStrings =======================";
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)";
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      }
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    }
c_str (np_test_1_all.cpp:13064)
13054  }
13055
13056  void test_fixed_size_string_out_of_bounds() {
13057    std::cout << "========= test_fixed_size_string_out_of_bounds =======================";
13058
13059    // Test str_<N>
13060    str_<10> str1("hello");  // length = 5, capacity = 10
13061
13062    // Test substr out-of-bounds
13063    auto result1 = str1.substr(20, 5);
13064    if (!(std::string(result1.c_str()) == "")) {
13065        std::string description = std::string("test_fixed_size_string_out_of_bounds():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::string(result1.c_str()) == \"\")";
13066        std::cout << std::string("[FAIL] ") + description << std::endl;
13067        throw std::runtime_error(description);
13068    }
13069    // std::cout << "[OK] str_<10> substr(20, 5) on 'hello' returns empty string\n";
13070
13071    // Test slice out-of-bounds
13072    auto result2 = str1.slice(10, 15);
13073    if (!(std::string(result2.c_str()) == "")) {
13074        std::string description = std::string("test_fixed_size_string_out_of_bounds():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::string(result2.c_str()) == \"\")";
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";
data (np_test_1_all.cpp:2084)
2074    }
2075    if (!(derived_ptr->extra == 2)) {
2076        std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)";
2077        std::cout << std::string("[FAIL] ") + description << std::endl;
2078        throw std::runtime_error(description);
2079    }
2080
2081    // Test 6: Large object handling
2082    struct LargeObject {
2083        std::vector<double> data;
2084        LargeObject() : data(10000, 3.14159) {}  // Large object
2085    };
2086
2087    LargeObject large;
2088    object_ large_obj(large);  // Should handle large objects
2089    if (!(!large_obj.is_null())) {
2090        std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())";
2091        std::cout << std::string("[FAIL] ") + description << std::endl;
2092        throw std::runtime_error(description);
2093    }
2094    if (!(large_obj.is_type<LargeObject>())) {
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;
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"));