MemoryLayout#

class numpy::MemoryLayout#

numpy C++ class.

Example#

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

// Use MemoryLayout
MemoryLayout obj;
// ... operations ...

Other Methods#

Signature

Return Type

Location

Example

void print()

void

NP_ARRAY_INFO.H:222

View

std::string toString()

std::string

NP_ARRAY_INFO.H:211

View

Code Examples#

The following examples are extracted from the test suite.

print (np_test_1_all.cpp:6395)
6385    std::vector<std::string> strings = {"Alice", "Bob", "Charlie"};
6386    auto arr2 = array<32>(strings);
6387    // std::cout << "Created from strings vector:" << std::endl;
6388    for (size_t i = 0; i < arr2.size(); ++i) {
6389        // std::cout << "arr2[" << i << "] = '" << arr2[i] << "'";
6390    }
6391
6392    // Test 2D array creation
6393    chararray16 arr_2d({2, 3}, "test");
6394    // std::cout << "Created 2D chararray16 with shape {2, 3}:";
6395    // arr_2d.print();
6396
6397    std::cout << " -> tests passed" << std::endl;
6398}
6399
6400void testCharArrayStringOperationsCharArray() {
6401    std::cout << "========= testStringOperations =======================";
6402
6403    // Test string concatenation
6404    std::vector<std::string> words1 = {"Hello", "Good", "Nice"};
6405    std::vector<std::string> words2 = {" World", " Day", " Work"};
toString (np_test_1_all.cpp:6826)
6816void testDatetime64CreationDateTime() {
6817    std::cout << "========= testDatetime64CreationDateTime =======================";
6818
6819    // Test default constructor
6820    datetime64 default_dt;
6821    if (!(default_dt.isNaT())) {
6822        std::string description = std::string("testDatetime64CreationDateTime():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(default_dt.isNaT())";
6823        std::cout << std::string("[FAIL] ") + description << std::endl;
6824        throw std::runtime_error(description);
6825    }
6826    // std::cout << "Default datetime64 is NaT: " << default_dt.toString() << std::endl;
6827
6828    // Test value constructor
6829    datetime64 epoch_day(0, DateTimeUnit::Day);
6830    // std::cout << "Epoch day: " << epoch_day.toString() << std::endl;
6831
6832    // Test string constructor
6833    datetime64 date_from_string("2024-01-15");
6834    // std::cout << "Date from string '2024-01-15': " << date_from_string.toString() << std::endl;
6835
6836    datetime64 datetime_from_string("2024-01-15T10:30:45");