StructuredRecord#

class numpy::StructuredRecord#

numpy C++ class.

Example#

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

// Use StructuredRecord
StructuredRecord obj;
// ... operations ...

Indexing / Selection#

Signature

Return Type

Location

Example

T get(const std::string &field_name)

T

NP_STRUCTURED_DTYPE.H:225

View

Other Methods#

Signature

Return Type

Location

Example

bool hasField(const std::string &field_name)

bool

NP_STRUCTURED_DTYPE.H:239

View

void set(const std::string &field_name, const T &value)

void

NP_STRUCTURED_DTYPE.H:234

View

Code Examples#

The following examples are extracted from the test suite.

get (np_test_1_all.cpp:28526)
28516      std::cout << " -> tests passed" << std::endl;
28517    }
28518
28519    void np_test_indexing_mask_indices() {
28520      std::cout << "========= mask_indices: triangular mask indices =======================";
28521
28522      // Get upper triangular indices for 3x3 matrix
28523      auto triu_idx = numpy::mask_indices(3, "triu", 0);
28524
28525      // Should return tuple of 2 arrays
28526      bool passed = (std::get<0>(triu_idx).getSize() > 0);
28527      passed = passed && (std::get<1>(triu_idx).getSize() > 0);
28528      passed = passed && (std::get<0>(triu_idx).getSize() == std::get<1>(triu_idx).getSize());
28529
28530      // Get lower triangular indices
28531      auto tril_idx = numpy::mask_indices(3, "tril", 0);
28532      passed = passed && (std::get<0>(tril_idx).getSize() > 0);
28533      passed = passed && (std::get<1>(tril_idx).getSize() > 0);
28534
28535      if (!passed) {
28536        std::cout << "  [FAIL] : in np_test_indexing_mask_indices() : Mask indices incorrect";
hasField (np_test_2_all.cpp:18634)
18624      // Verify field count
18625      auto dtype = data.getDType();
18626      if (dtype.getFieldCount() != 5) {
18627        std::cout << "  [FAIL] : in np_test_io_extensions_recfromcsv_basic() : Expected 5 fields, got "
18628          << dtype.getFieldCount() << std::endl;
18629        throw std::runtime_error("np_test_io_extensions_recfromcsv_basic failed: wrong field count");
18630      }
18631
18632      // Verify field names
18633      if (!dtype.hasField("name") || !dtype.hasField("age") || !dtype.hasField("salary")) {
18634        std::cout << "  [FAIL] : in np_test_io_extensions_recfromcsv_basic() : Missing expected fields";
18635        throw std::runtime_error("np_test_io_extensions_recfromcsv_basic failed: missing fields");
18636      }
18637
18638      // Verify data values
18639      auto name = data.getFieldValue<numpy::str32>({ 0 }, "name");
18640      if (std::string(name) != "Alice") {
18641        std::cout << "  [FAIL] : Expected 'Alice', got '" << std::string(name) << "'";
18642        throw std::runtime_error("np_test_io_extensions_recfromcsv_basic failed: wrong name");
18643      }
set (np_test_1_all.cpp:6747)
6737    std::cout << "========= testArrayPrinting =======================";
6738
6739    // Test 1D array printing
6740    std::vector<std::string> words = {"Hello", "World", "Test"};
6741    auto arr_1d = array<16>(words);
6742    // std::cout << "1D CharArray:" << std::endl;
6743    // arr_1d.print();
6744
6745    // Test 2D array printing
6746    chararray16 arr_2d({2, 2}, "test");
6747    arr_2d.set({0, 0}, "A");
6748    arr_2d.set({0, 1}, "B");
6749    arr_2d.set({1, 0}, "C");
6750    arr_2d.set({1, 1}, "D");
6751
6752    // std::cout << "2D CharArray:" << std::endl;
6753    // arr_2d.print();
6754
6755    std::cout << " -> tests passed" << std::endl;
6756}