StructuredArray =============== .. cpp:class:: numpy::StructuredArray numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use StructuredArray StructuredArray obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``StructuredArray(std::shared_ptrdtype, const std::vector&shape)`` - NP_STRUCTURED_ARRAY.H:52 - Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``const StructuredDType & getDType()`` - const StructuredDType & - NP_STRUCTURED_ARRAY.H:65 - :ref:`View ` * - ``StructuredValue getField(const std::vector&indices, const std::string &field_name)`` - StructuredValue - NP_STRUCTURED_ARRAY.H:218 - :ref:`View ` * - ``T getFieldValue(const std::vector&indices, const std::string &field_name)`` - T - NP_STRUCTURED_ARRAY.H:70 - :ref:`View ` * - ``std::string getFieldValue(const std::vector&indices, const std::string &field_name)`` - std::string - NP_STRUCTURED_ARRAY.H:89 - :ref:`View ` * - ``str32 getFieldValue(const std::vector&indices, const std::string &field_name)`` - str32 - NP_STRUCTURED_ARRAY.H:105 - :ref:`View ` * - ``str8 getFieldValue(const std::vector&indices, const std::string &field_name)`` - str8 - NP_STRUCTURED_ARRAY.H:124 - :ref:`View ` * - ``str16 getFieldValue(const std::vector&indices, const std::string &field_name)`` - str16 - NP_STRUCTURED_ARRAY.H:143 - :ref:`View ` * - ``str64 getFieldValue(const std::vector&indices, const std::string &field_name)`` - str64 - NP_STRUCTURED_ARRAY.H:162 - :ref:`View ` * - ``str128 getFieldValue(const std::vector&indices, const std::string &field_name)`` - str128 - NP_STRUCTURED_ARRAY.H:181 - :ref:`View ` * - ``str256 getFieldValue(const std::vector&indices, const std::string &field_name)`` - str256 - NP_STRUCTURED_ARRAY.H:200 - :ref:`View ` * - ``size_t getLinearIndex(const std::vector&indices)`` - size_t - NP_STRUCTURED_ARRAY.H:31 - * - ``StructuredRecord getRecord(const std::vector&indices)`` - StructuredRecord - NP_STRUCTURED_ARRAY.H:478 - :ref:`View ` * - ``uint8_t \* getRecordPtr(const std::vector&indices)`` - uint8_t \* - NP_STRUCTURED_ARRAY.H:46 - * - ``const std::vector& getShape()`` - const std::vector& - NP_STRUCTURED_ARRAY.H:66 - :ref:`View ` * - ``size_t getSize()`` - size_t - NP_STRUCTURED_ARRAY.H:68 - :ref:`View ` * - ``const std::vector& getStrides()`` - const std::vector& - NP_STRUCTURED_ARRAY.H:67 - :ref:`View ` Testing ------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void calculateStrides()`` - void - NP_STRUCTURED_ARRAY.H:21 - Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void printArray(std::ostream &os = std::cout)`` - void - NP_STRUCTURED_ARRAY.H:629 - :ref:`View ` * - ``void setField(const std::vector&indices, const std::string &field_name, const StructuredValue &value)`` - void - NP_STRUCTURED_ARRAY.H:425 - :ref:`View ` * - ``void setFieldFromArray(const std::string &field_name, const NDArray&values)`` - void - NP_STRUCTURED_ARRAY.H:549 - * - ``void setFieldValue(const std::vector&indices, const std::string &field_name, const T &value)`` - void - NP_STRUCTURED_ARRAY.H:82 - :ref:`View ` * - ``void setFieldValue(const std::vector&indices, const std::string &field_name, const str32 &value)`` - void - NP_STRUCTURED_ARRAY.H:115 - :ref:`View ` * - ``void setFieldValue(const std::vector&indices, const std::string &field_name, const str8 &value)`` - void - NP_STRUCTURED_ARRAY.H:134 - :ref:`View ` * - ``void setFieldValue(const std::vector&indices, const std::string &field_name, const str16 &value)`` - void - NP_STRUCTURED_ARRAY.H:153 - :ref:`View ` * - ``void setFieldValue(const std::vector&indices, const std::string &field_name, const str64 &value)`` - void - NP_STRUCTURED_ARRAY.H:172 - :ref:`View ` * - ``void setFieldValue(const std::vector&indices, const std::string &field_name, const str128 &value)`` - void - NP_STRUCTURED_ARRAY.H:191 - :ref:`View ` * - ``void setFieldValue(const std::vector&indices, const std::string &field_name, const str256 &value)`` - void - NP_STRUCTURED_ARRAY.H:210 - :ref:`View ` * - ``void setRecord(const std::vector&indices, const StructuredRecord &record)`` - void - NP_STRUCTURED_ARRAY.H:486 - * - ``std::string shapeToString(const std::vector&shape)`` - std::string - NP_STRUCTURED_ARRAY.H:634 - * - ``std::string toString()`` - std::string - NP_STRUCTURED_ARRAY.H:581 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-structuredarray-getdtype-0: .. dropdown:: getDType (np_test_1_all.cpp:7238) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 7228 :emphasize-lines: 11 // << ", size: " << TypeTraits::getTypeSize() << " bytes" << std::endl; // std::cout << " clongdouble: " << TypeTraits::getTypeName() // << ", size: " << TypeTraits::getTypeSize() << " bytes" << std::endl; // std::cout << " intp: " << TypeTraits::getTypeName() // << ", size: " << TypeTraits::getTypeSize() << " bytes" << std::endl; // std::cout << " uintp: " << TypeTraits::getTypeName() // << ", size: " << TypeTraits::getTypeSize() << " bytes" << std::endl; // std::cout << " bytes: " << TypeTraits::getTypeName() // << ", size: " << TypeTraits::getTypeSize() << " bytes" << std::endl; // Test getDType() // std::cout << "DType Enums:" << std::endl; // std::cout << " longdouble DType: " << static_cast(TypeTraits::getDType()) << std::endl; // std::cout << " clongdouble DType: " << static_cast(TypeTraits::getDType()) << std::endl; // std::cout << " intp DType: " << static_cast(TypeTraits::getDType()) << std::endl; // std::cout << " uintp DType: " << static_cast(TypeTraits::getDType()) << std::endl; // std::cout << " bytes DType: " << static_cast(TypeTraits::getDType()) << std::endl; std::cout << " -> tests passed" << std::endl; } .. _example-structuredarray-getfield-1: .. dropdown:: getField (np_test_2_all.cpp:18700) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 18690 :emphasize-lines: 11 void np_test_io_extensions_recfromcsv_dtype_detection() { std::cout << "========= recfromcsv: automatic dtype detection ======================="; create_csv_file("test_dtypes.csv"); auto data = numpy::io::recfromcsv(csv_test_dir + "test_dtypes.csv"); auto dtype = data.getDType(); // Verify string field detected auto name_dtype = dtype.getField("name").dtype; if (name_dtype != numpy::DType::STR32 && name_dtype != numpy::DType::STR16 && name_dtype != numpy::DType::STR8 && name_dtype != numpy::DType::STR64) { std::cout << " [FAIL] : Expected STRING type for name field" << std::endl; throw std::runtime_error("np_test_io_extensions_recfromcsv_dtype_detection failed: wrong name dtype"); } // Verify integer field detected auto age_dtype = dtype.getField("age").dtype; if (age_dtype != numpy::DType::INT64 && age_dtype != numpy::DType::INT32) { std::cout << " [FAIL] : Expected INT type for age field"; .. _example-structuredarray-getfieldvalue-2: .. dropdown:: getFieldValue (np_test_1_all.cpp:21586) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21576 :emphasize-lines: 11 arr.setFieldValue({ 1 }, "age", static_cast(25)); arr.setFieldValue({ 1 }, "salary", static_cast(60000.0)); arr.setFieldValue({ 2 }, "name", std::string("Charlie")); arr.setFieldValue({ 2 }, "age", static_cast(35)); arr.setFieldValue({ 2 }, "salary", static_cast(80000.0)); // std::cout << "RecordArray created with 3 records" << std::endl; //arr.printArray(); auto name_0 = arr.getFieldValue({ 0 }, "name"); auto age_1 = arr.getFieldValue({ 1 }, "age"); auto salary_2 = arr.getFieldValue({ 2 }, "salary"); // std::cout << "Field access test:" << std::endl; // std::cout << "Record 0 name: " << name_0; // std::cout << std::endl; // std::cout << "Record 1 age: " << age_1 << std::endl; // std::cout << "Record 2 salary: " << salary_2 << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-structuredarray-getfieldvalue-3: .. dropdown:: getFieldValue (np_test_1_all.cpp:21586) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21576 :emphasize-lines: 11 arr.setFieldValue({ 1 }, "age", static_cast(25)); arr.setFieldValue({ 1 }, "salary", static_cast(60000.0)); arr.setFieldValue({ 2 }, "name", std::string("Charlie")); arr.setFieldValue({ 2 }, "age", static_cast(35)); arr.setFieldValue({ 2 }, "salary", static_cast(80000.0)); // std::cout << "RecordArray created with 3 records" << std::endl; //arr.printArray(); auto name_0 = arr.getFieldValue({ 0 }, "name"); auto age_1 = arr.getFieldValue({ 1 }, "age"); auto salary_2 = arr.getFieldValue({ 2 }, "salary"); // std::cout << "Field access test:" << std::endl; // std::cout << "Record 0 name: " << name_0; // std::cout << std::endl; // std::cout << "Record 1 age: " << age_1 << std::endl; // std::cout << "Record 2 salary: " << salary_2 << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-structuredarray-getfieldvalue-4: .. dropdown:: getFieldValue (np_test_1_all.cpp:21586) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21576 :emphasize-lines: 11 arr.setFieldValue({ 1 }, "age", static_cast(25)); arr.setFieldValue({ 1 }, "salary", static_cast(60000.0)); arr.setFieldValue({ 2 }, "name", std::string("Charlie")); arr.setFieldValue({ 2 }, "age", static_cast(35)); arr.setFieldValue({ 2 }, "salary", static_cast(80000.0)); // std::cout << "RecordArray created with 3 records" << std::endl; //arr.printArray(); auto name_0 = arr.getFieldValue({ 0 }, "name"); auto age_1 = arr.getFieldValue({ 1 }, "age"); auto salary_2 = arr.getFieldValue({ 2 }, "salary"); // std::cout << "Field access test:" << std::endl; // std::cout << "Record 0 name: " << name_0; // std::cout << std::endl; // std::cout << "Record 1 age: " << age_1 << std::endl; // std::cout << "Record 2 salary: " << salary_2 << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-structuredarray-getfieldvalue-5: .. dropdown:: getFieldValue (np_test_1_all.cpp:21586) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21576 :emphasize-lines: 11 arr.setFieldValue({ 1 }, "age", static_cast(25)); arr.setFieldValue({ 1 }, "salary", static_cast(60000.0)); arr.setFieldValue({ 2 }, "name", std::string("Charlie")); arr.setFieldValue({ 2 }, "age", static_cast(35)); arr.setFieldValue({ 2 }, "salary", static_cast(80000.0)); // std::cout << "RecordArray created with 3 records" << std::endl; //arr.printArray(); auto name_0 = arr.getFieldValue({ 0 }, "name"); auto age_1 = arr.getFieldValue({ 1 }, "age"); auto salary_2 = arr.getFieldValue({ 2 }, "salary"); // std::cout << "Field access test:" << std::endl; // std::cout << "Record 0 name: " << name_0; // std::cout << std::endl; // std::cout << "Record 1 age: " << age_1 << std::endl; // std::cout << "Record 2 salary: " << salary_2 << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-structuredarray-getfieldvalue-6: .. dropdown:: getFieldValue (np_test_1_all.cpp:21586) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21576 :emphasize-lines: 11 arr.setFieldValue({ 1 }, "age", static_cast(25)); arr.setFieldValue({ 1 }, "salary", static_cast(60000.0)); arr.setFieldValue({ 2 }, "name", std::string("Charlie")); arr.setFieldValue({ 2 }, "age", static_cast(35)); arr.setFieldValue({ 2 }, "salary", static_cast(80000.0)); // std::cout << "RecordArray created with 3 records" << std::endl; //arr.printArray(); auto name_0 = arr.getFieldValue({ 0 }, "name"); auto age_1 = arr.getFieldValue({ 1 }, "age"); auto salary_2 = arr.getFieldValue({ 2 }, "salary"); // std::cout << "Field access test:" << std::endl; // std::cout << "Record 0 name: " << name_0; // std::cout << std::endl; // std::cout << "Record 1 age: " << age_1 << std::endl; // std::cout << "Record 2 salary: " << salary_2 << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-structuredarray-getfieldvalue-7: .. dropdown:: getFieldValue (np_test_1_all.cpp:21586) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21576 :emphasize-lines: 11 arr.setFieldValue({ 1 }, "age", static_cast(25)); arr.setFieldValue({ 1 }, "salary", static_cast(60000.0)); arr.setFieldValue({ 2 }, "name", std::string("Charlie")); arr.setFieldValue({ 2 }, "age", static_cast(35)); arr.setFieldValue({ 2 }, "salary", static_cast(80000.0)); // std::cout << "RecordArray created with 3 records" << std::endl; //arr.printArray(); auto name_0 = arr.getFieldValue({ 0 }, "name"); auto age_1 = arr.getFieldValue({ 1 }, "age"); auto salary_2 = arr.getFieldValue({ 2 }, "salary"); // std::cout << "Field access test:" << std::endl; // std::cout << "Record 0 name: " << name_0; // std::cout << std::endl; // std::cout << "Record 1 age: " << age_1 << std::endl; // std::cout << "Record 2 salary: " << salary_2 << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-structuredarray-getfieldvalue-8: .. dropdown:: getFieldValue (np_test_1_all.cpp:21586) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21576 :emphasize-lines: 11 arr.setFieldValue({ 1 }, "age", static_cast(25)); arr.setFieldValue({ 1 }, "salary", static_cast(60000.0)); arr.setFieldValue({ 2 }, "name", std::string("Charlie")); arr.setFieldValue({ 2 }, "age", static_cast(35)); arr.setFieldValue({ 2 }, "salary", static_cast(80000.0)); // std::cout << "RecordArray created with 3 records" << std::endl; //arr.printArray(); auto name_0 = arr.getFieldValue({ 0 }, "name"); auto age_1 = arr.getFieldValue({ 1 }, "age"); auto salary_2 = arr.getFieldValue({ 2 }, "salary"); // std::cout << "Field access test:" << std::endl; // std::cout << "Record 0 name: " << name_0; // std::cout << std::endl; // std::cout << "Record 1 age: " << age_1 << std::endl; // std::cout << "Record 2 salary: " << salary_2 << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-structuredarray-getfieldvalue-9: .. dropdown:: getFieldValue (np_test_1_all.cpp:21586) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21576 :emphasize-lines: 11 arr.setFieldValue({ 1 }, "age", static_cast(25)); arr.setFieldValue({ 1 }, "salary", static_cast(60000.0)); arr.setFieldValue({ 2 }, "name", std::string("Charlie")); arr.setFieldValue({ 2 }, "age", static_cast(35)); arr.setFieldValue({ 2 }, "salary", static_cast(80000.0)); // std::cout << "RecordArray created with 3 records" << std::endl; //arr.printArray(); auto name_0 = arr.getFieldValue({ 0 }, "name"); auto age_1 = arr.getFieldValue({ 1 }, "age"); auto salary_2 = arr.getFieldValue({ 2 }, "salary"); // std::cout << "Field access test:" << std::endl; // std::cout << "Record 0 name: " << name_0; // std::cout << std::endl; // std::cout << "Record 1 age: " << age_1 << std::endl; // std::cout << "Record 2 salary: " << salary_2 << std::endl; std::cout << " -> tests passed" << std::endl; .. _example-structuredarray-getrecord-10: .. dropdown:: getRecord (np_test_1_all.cpp:26346) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 26336 :emphasize-lines: 11 }; auto dtype = std::make_shared(fields); numpy::RecordArray arr(dtype, { 2 }); arr.setFieldValue({ 0 }, "id", numpy::int32(1)); arr.setFieldValue({ 0 }, "value", numpy::float64(10.5)); arr.setFieldValue({ 1 }, "id", numpy::int32(2)); arr.setFieldValue({ 1 }, "value", numpy::float64(20.5)); // Test basic comparison operations (indirectly tests createComparisonValue) auto rec0 = arr.getRecord({ 0 }); auto rec1 = arr.getRecord({ 1 }); // Verify records are different (basic comparison test) bool passed = true; // If we can get records without error, comparison values work if (!passed) { std::cout << " [FAIL] : in np_test_recarray_createComparisonValue() : Create comparison value failed"; throw std::runtime_error("np_test_recarray_createComparisonValue failed"); } .. _example-structuredarray-getshape-11: .. dropdown:: getShape (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-structuredarray-getsize-12: .. dropdown:: getSize (np_test_1_all.cpp:2172) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 2162 :emphasize-lines: 11 } std::cout << " -> tests passed" << std::endl; } void testArrayEdgeCases() { std::cout << "========= testArrayEdgeCases ======================="; // Test 1: Empty arrays NDArray empty_array = createObjectZeros({0}); if (!(empty_array.getSize() == 0)) { std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(empty_array.getSize() == 0)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(empty_array.getShape() == std::vector{0})) { std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(empty_array.getShape() == std::vector{0})"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-structuredarray-getstrides-13: .. dropdown:: getStrides (np_test_1_all.cpp:13373) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 13363 :emphasize-lines: 11 namespace numpy_tests { using namespace numpy; void testBasicStrides() { std::cout << "========= testBasicStrides ======================="; // Test 1D array auto array1d = createInt32Array({ 5 }, 10); const auto& strides1d = array1d.getStrides(); // std::cout << "1D array shape: (" << array1d.getShape()[0] << ")" << std::endl; // std::cout << "1D array strides: (" << strides1d[0] << ")" << std::endl; if (!(strides1d.size() == 1)) { std::string description = std::string("testBasicStrides():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(strides1d.size() == 1)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(strides1d[0] == 1)) { .. _example-structuredarray-printarray-14: .. dropdown:: printArray (np_test_1_all.cpp:67) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 57 :emphasize-lines: 11 std::vector indices(arr.getShape().size(), 0); do { if (arr.getElementAt(indices)) { return false; } } while (incrementIndices(indices, arr.getShape())); return true; } template void printArray(const NDArray& arr, const std::string& name) { std::cout << name << ": "; if (arr.getShape().size() == 1) { for (size_t i = 0; i < arr.getShape()[0]; ++i) { // std::cout << arr.getElementAt({i}) << " "; } } // std::cout << std::endl; } // Helper functions for bitwise operations tests .. _example-structuredarray-setfield-15: .. dropdown:: setField (np_test_5_all.cpp:8457) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 8447 :emphasize-lines: 11 std::cout << "========= StructuredArray::toString() basic ======================="; std::vector fields = { {"name", numpy::DType::STR_, 0, 10}, {"age", numpy::DType::INT32, 10, 4} }; auto dtype = std::make_shared(fields); numpy::StructuredArray arr(dtype, std::vector{2}); arr.setField({ 0 }, "name", numpy::StructuredValue(std::string("Alice"))); arr.setField({ 0 }, "age", numpy::StructuredValue(static_cast(30))); arr.setField({ 1 }, "name", numpy::StructuredValue(std::string("Bob"))); arr.setField({ 1 }, "age", numpy::StructuredValue(static_cast(25))); std::string result = arr.toString(); // std::cout << "Result:\n" << result << std::endl; verify_not_empty(result, "StructuredArray toString()"); .. _example-structuredarray-setfieldvalue-16: .. dropdown:: setFieldValue (np_test_1_all.cpp:21571) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21561 :emphasize-lines: 11 std::cout << "========= testBasicRecordArrayCreation ======================="; auto dtype = std::make_shared(std::vector>{ {"name", DType::UNICODE32}, { "age", DType::INT32 }, { "salary", DType::FLOAT64 } }); RecordArray arr(dtype, { 3 }); arr.setFieldValue({ 0 }, "name", std::string("Alice")); arr.setFieldValue({ 0 }, "age", static_cast(30)); arr.setFieldValue({ 0 }, "salary", static_cast(70000.0)); arr.setFieldValue({ 1 }, "name", std::string("Bob")); arr.setFieldValue({ 1 }, "age", static_cast(25)); arr.setFieldValue({ 1 }, "salary", static_cast(60000.0)); arr.setFieldValue({ 2 }, "name", std::string("Charlie")); arr.setFieldValue({ 2 }, "age", static_cast(35)); arr.setFieldValue({ 2 }, "salary", static_cast(80000.0)); .. _example-structuredarray-setfieldvalue-17: .. dropdown:: setFieldValue (np_test_1_all.cpp:21571) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21561 :emphasize-lines: 11 std::cout << "========= testBasicRecordArrayCreation ======================="; auto dtype = std::make_shared(std::vector>{ {"name", DType::UNICODE32}, { "age", DType::INT32 }, { "salary", DType::FLOAT64 } }); RecordArray arr(dtype, { 3 }); arr.setFieldValue({ 0 }, "name", std::string("Alice")); arr.setFieldValue({ 0 }, "age", static_cast(30)); arr.setFieldValue({ 0 }, "salary", static_cast(70000.0)); arr.setFieldValue({ 1 }, "name", std::string("Bob")); arr.setFieldValue({ 1 }, "age", static_cast(25)); arr.setFieldValue({ 1 }, "salary", static_cast(60000.0)); arr.setFieldValue({ 2 }, "name", std::string("Charlie")); arr.setFieldValue({ 2 }, "age", static_cast(35)); arr.setFieldValue({ 2 }, "salary", static_cast(80000.0)); .. _example-structuredarray-setfieldvalue-18: .. dropdown:: setFieldValue (np_test_1_all.cpp:21571) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21561 :emphasize-lines: 11 std::cout << "========= testBasicRecordArrayCreation ======================="; auto dtype = std::make_shared(std::vector>{ {"name", DType::UNICODE32}, { "age", DType::INT32 }, { "salary", DType::FLOAT64 } }); RecordArray arr(dtype, { 3 }); arr.setFieldValue({ 0 }, "name", std::string("Alice")); arr.setFieldValue({ 0 }, "age", static_cast(30)); arr.setFieldValue({ 0 }, "salary", static_cast(70000.0)); arr.setFieldValue({ 1 }, "name", std::string("Bob")); arr.setFieldValue({ 1 }, "age", static_cast(25)); arr.setFieldValue({ 1 }, "salary", static_cast(60000.0)); arr.setFieldValue({ 2 }, "name", std::string("Charlie")); arr.setFieldValue({ 2 }, "age", static_cast(35)); arr.setFieldValue({ 2 }, "salary", static_cast(80000.0)); .. _example-structuredarray-setfieldvalue-19: .. dropdown:: setFieldValue (np_test_1_all.cpp:21571) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21561 :emphasize-lines: 11 std::cout << "========= testBasicRecordArrayCreation ======================="; auto dtype = std::make_shared(std::vector>{ {"name", DType::UNICODE32}, { "age", DType::INT32 }, { "salary", DType::FLOAT64 } }); RecordArray arr(dtype, { 3 }); arr.setFieldValue({ 0 }, "name", std::string("Alice")); arr.setFieldValue({ 0 }, "age", static_cast(30)); arr.setFieldValue({ 0 }, "salary", static_cast(70000.0)); arr.setFieldValue({ 1 }, "name", std::string("Bob")); arr.setFieldValue({ 1 }, "age", static_cast(25)); arr.setFieldValue({ 1 }, "salary", static_cast(60000.0)); arr.setFieldValue({ 2 }, "name", std::string("Charlie")); arr.setFieldValue({ 2 }, "age", static_cast(35)); arr.setFieldValue({ 2 }, "salary", static_cast(80000.0)); .. _example-structuredarray-setfieldvalue-20: .. dropdown:: setFieldValue (np_test_1_all.cpp:21571) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21561 :emphasize-lines: 11 std::cout << "========= testBasicRecordArrayCreation ======================="; auto dtype = std::make_shared(std::vector>{ {"name", DType::UNICODE32}, { "age", DType::INT32 }, { "salary", DType::FLOAT64 } }); RecordArray arr(dtype, { 3 }); arr.setFieldValue({ 0 }, "name", std::string("Alice")); arr.setFieldValue({ 0 }, "age", static_cast(30)); arr.setFieldValue({ 0 }, "salary", static_cast(70000.0)); arr.setFieldValue({ 1 }, "name", std::string("Bob")); arr.setFieldValue({ 1 }, "age", static_cast(25)); arr.setFieldValue({ 1 }, "salary", static_cast(60000.0)); arr.setFieldValue({ 2 }, "name", std::string("Charlie")); arr.setFieldValue({ 2 }, "age", static_cast(35)); arr.setFieldValue({ 2 }, "salary", static_cast(80000.0)); .. _example-structuredarray-setfieldvalue-21: .. dropdown:: setFieldValue (np_test_1_all.cpp:21571) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21561 :emphasize-lines: 11 std::cout << "========= testBasicRecordArrayCreation ======================="; auto dtype = std::make_shared(std::vector>{ {"name", DType::UNICODE32}, { "age", DType::INT32 }, { "salary", DType::FLOAT64 } }); RecordArray arr(dtype, { 3 }); arr.setFieldValue({ 0 }, "name", std::string("Alice")); arr.setFieldValue({ 0 }, "age", static_cast(30)); arr.setFieldValue({ 0 }, "salary", static_cast(70000.0)); arr.setFieldValue({ 1 }, "name", std::string("Bob")); arr.setFieldValue({ 1 }, "age", static_cast(25)); arr.setFieldValue({ 1 }, "salary", static_cast(60000.0)); arr.setFieldValue({ 2 }, "name", std::string("Charlie")); arr.setFieldValue({ 2 }, "age", static_cast(35)); arr.setFieldValue({ 2 }, "salary", static_cast(80000.0)); .. _example-structuredarray-setfieldvalue-22: .. dropdown:: setFieldValue (np_test_1_all.cpp:21571) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21561 :emphasize-lines: 11 std::cout << "========= testBasicRecordArrayCreation ======================="; auto dtype = std::make_shared(std::vector>{ {"name", DType::UNICODE32}, { "age", DType::INT32 }, { "salary", DType::FLOAT64 } }); RecordArray arr(dtype, { 3 }); arr.setFieldValue({ 0 }, "name", std::string("Alice")); arr.setFieldValue({ 0 }, "age", static_cast(30)); arr.setFieldValue({ 0 }, "salary", static_cast(70000.0)); arr.setFieldValue({ 1 }, "name", std::string("Bob")); arr.setFieldValue({ 1 }, "age", static_cast(25)); arr.setFieldValue({ 1 }, "salary", static_cast(60000.0)); arr.setFieldValue({ 2 }, "name", std::string("Charlie")); arr.setFieldValue({ 2 }, "age", static_cast(35)); arr.setFieldValue({ 2 }, "salary", static_cast(80000.0)); .. _example-structuredarray-tostring-23: .. 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");