PooledArray#

class numpy::PooledArray#

numpy C++ class.

Example#

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

// Use PooledArray
PooledArray obj;
// ... operations ...

Constructors#

Signature

Location

Example

PooledArray(size_tsize)

NP_MEMORY_POOL.H:219

PooledArray(const PooledArray &)

NP_MEMORY_POOL.H:227

noexcept PooledArray(PooledArray &&other)

NP_MEMORY_POOL.H:230

Operators#

Signature

Return Type

Location

Example

PooledArray & operator=(const PooledArray &)

PooledArray &

NP_MEMORY_POOL.H:228

PooledArray & noexcept operator=(PooledArray &&other)

PooledArray & noexcept

NP_MEMORY_POOL.H:236

T & operator[](size_tindex)

T &

NP_MEMORY_POOL.H:253

const T & operator[](size_tindex)

const T &

NP_MEMORY_POOL.H:254

Other Methods#

Signature

Return Type

Location

Example

T \* begin()

T *

NP_MEMORY_POOL.H:256

View

const T \* begin()

const T *

NP_MEMORY_POOL.H:258

View

T \* data()

T *

NP_MEMORY_POOL.H:249

View

const T \* data()

const T *

NP_MEMORY_POOL.H:250

View

T \* end()

T *

NP_MEMORY_POOL.H:257

View

const T \* end()

const T *

NP_MEMORY_POOL.H:259

View

size_t size()

size_t

NP_MEMORY_POOL.H:251

View

Code Examples#

The following examples are extracted from the test suite.

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}
data (np_test_1_all.cpp:2084)
2074    }
2075    if (!(derived_ptr->extra == 2)) {
2076        std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)";
2077        std::cout << std::string("[FAIL] ") + description << std::endl;
2078        throw std::runtime_error(description);
2079    }
2080
2081    // Test 6: Large object handling
2082    struct LargeObject {
2083        std::vector<double> data;
2084        LargeObject() : data(10000, 3.14159) {}  // Large object
2085    };
2086
2087    LargeObject large;
2088    object_ large_obj(large);  // Should handle large objects
2089    if (!(!large_obj.is_null())) {
2090        std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())";
2091        std::cout << std::string("[FAIL] ") + description << std::endl;
2092        throw std::runtime_error(description);
2093    }
2094    if (!(large_obj.is_type<LargeObject>())) {
data (np_test_1_all.cpp:2084)
2074    }
2075    if (!(derived_ptr->extra == 2)) {
2076        std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)";
2077        std::cout << std::string("[FAIL] ") + description << std::endl;
2078        throw std::runtime_error(description);
2079    }
2080
2081    // Test 6: Large object handling
2082    struct LargeObject {
2083        std::vector<double> data;
2084        LargeObject() : data(10000, 3.14159) {}  // Large object
2085    };
2086
2087    LargeObject large;
2088    object_ large_obj(large);  // Should handle large objects
2089    if (!(!large_obj.is_null())) {
2090        std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())";
2091        std::cout << std::string("[FAIL] ") + description << std::endl;
2092        throw std::runtime_error(description);
2093    }
2094    if (!(large_obj.is_type<LargeObject>())) {
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}
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);