MemoryLayout ============ .. cpp:class:: numpy::MemoryLayout numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use MemoryLayout MemoryLayout obj; // ... operations ... Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void print()`` - void - NP_ARRAY_INFO.H:222 - :ref:`View ` * - ``std::string toString()`` - std::string - NP_ARRAY_INFO.H:211 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-memorylayout-print-0: .. dropdown:: print (np_test_1_all.cpp:6395) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6385 :emphasize-lines: 11 std::vector strings = {"Alice", "Bob", "Charlie"}; auto arr2 = array<32>(strings); // std::cout << "Created from strings vector:" << std::endl; for (size_t i = 0; i < arr2.size(); ++i) { // std::cout << "arr2[" << i << "] = '" << arr2[i] << "'"; } // Test 2D array creation chararray16 arr_2d({2, 3}, "test"); // std::cout << "Created 2D chararray16 with shape {2, 3}:"; // arr_2d.print(); std::cout << " -> tests passed" << std::endl; } void testCharArrayStringOperationsCharArray() { std::cout << "========= testStringOperations ======================="; // Test string concatenation std::vector words1 = {"Hello", "Good", "Nice"}; std::vector words2 = {" World", " Day", " Work"}; .. _example-memorylayout-tostring-1: .. dropdown:: toString (np_test_1_all.cpp:6826) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 6816 :emphasize-lines: 11 void testDatetime64CreationDateTime() { std::cout << "========= testDatetime64CreationDateTime ======================="; // Test default constructor datetime64 default_dt; if (!(default_dt.isNaT())) { std::string description = std::string("testDatetime64CreationDateTime():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(default_dt.isNaT())"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "Default datetime64 is NaT: " << default_dt.toString() << std::endl; // Test value constructor datetime64 epoch_day(0, DateTimeUnit::Day); // std::cout << "Epoch day: " << epoch_day.toString() << std::endl; // Test string constructor datetime64 date_from_string("2024-01-15"); // std::cout << "Date from string '2024-01-15': " << date_from_string.toString() << std::endl; datetime64 datetime_from_string("2024-01-15T10:30:45");