NPZWriter ========= .. cpp:class:: numpy::NPZWriter Input/output operations class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use NPZWriter NPZWriter obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``NPZWriter(const std::string &filename, boolcompress = false, intlevel = 6)`` - NP_NPZ_UTILS.H:216 - Math Operations --------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void add_array(const std::string &name, const NDArray&array)`` - void - NP_NPZ_UTILS.H:223 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void finalize()`` - void - NP_NPZ_UTILS.H:279 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-npzwriter-add_array-0: .. dropdown:: add_array (np_test_5_all.cpp:657) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 647 :emphasize-lines: 11 std::cout << " [FAIL] : " << message; throw std::runtime_error("Test failed: " + message); } } // ============================================================================ // NPZ FILE OPERATIONS TESTS // ============================================================================ void np_test_io_npz_writer_add_array() { std::cout << "========= NPZWriter.add_array() ================================"; ensure_test_dir(); // Create test arrays numpy::NDArray arr1_flat = numpy::arange(0, 12); numpy::NDArray arr1({ 3, 4 }); for (int i = 0; i < 12; ++i) { arr1.setElementAt({ static_cast(i / 4), static_cast(i % 4) }, i); } .. _example-npzwriter-finalize-1: .. dropdown:: finalize (np_test_5_all.cpp:682) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 672 :emphasize-lines: 11 numpy::npz::NPZWriter writer(filename, false); // No compression for this test // Test add_array functionality writer.add_array("integers", arr1); writer.add_array("floats", arr2); // std::cout << " Added 2 arrays to NPZ file" << std::endl; // std::cout << " Array 1: integers (3x4)" << std::endl; // std::cout << " Array 2: floats (10,)" << std::endl; // Note: File is written in finalize(), tested separately std::cout << " -> tests passed" << std::endl; } void np_test_io_npz_writer_finalize() { std::cout << "========= NPZWriter.finalize() ================================="; ensure_test_dir(); // Create and finalize an NPZ file