NPZWriter#

class numpy::NPZWriter#

Input/output operations class.

Example#

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

// Use NPZWriter
NPZWriter obj;
// ... operations ...

Constructors#

Signature

Location

Example

NPZWriter(const std::string &filename, boolcompress = false, intlevel = 6)

NP_NPZ_UTILS.H:216

Math Operations#

Signature

Return Type

Location

Example

void add_array(const std::string &name, const NDArray<T>&array)

void

NP_NPZ_UTILS.H:223

View

Other Methods#

Signature

Return Type

Location

Example

void finalize()

void

NP_NPZ_UTILS.H:279

View

Code Examples#

The following examples are extracted from the test suite.

add_array (np_test_5_all.cpp:657)
647        std::cout << "  [FAIL] : " << message;
648        throw std::runtime_error("Test failed: " + message);
649      }
650    }
651
652    // ============================================================================
653    // NPZ FILE OPERATIONS TESTS
654    // ============================================================================
655
656    void np_test_io_npz_writer_add_array() {
657      std::cout << "========= NPZWriter.add_array() ================================";
658
659      ensure_test_dir();
660
661      // Create test arrays
662      numpy::NDArray<int> arr1_flat = numpy::arange<int>(0, 12);
663      numpy::NDArray<int> arr1({ 3, 4 });
664      for (int i = 0; i < 12; ++i) {
665        arr1.setElementAt({ static_cast<size_t>(i / 4), static_cast<size_t>(i % 4) }, i);
666      }
finalize (np_test_5_all.cpp:682)
672      numpy::npz::NPZWriter writer(filename, false);  // No compression for this test
673
674      // Test add_array functionality
675      writer.add_array("integers", arr1);
676      writer.add_array("floats", arr2);
677
678      // std::cout << "  Added 2 arrays to NPZ file" << std::endl;
679      // std::cout << "  Array 1: integers (3x4)" << std::endl;
680      // std::cout << "  Array 2: floats (10,)" << std::endl;
681
682      // Note: File is written in finalize(), tested separately
683
684      std::cout << " -> tests passed" << std::endl;
685    }
686
687    void np_test_io_npz_writer_finalize() {
688      std::cout << "========= NPZWriter.finalize() =================================";
689
690      ensure_test_dir();
691
692      // Create and finalize an NPZ file