pax_global_header00006660000000000000000000000064145372325640014525gustar00rootroot0000000000000052 comment=f40868a6a1c190c802e7d8b5987064f044bf7812 zfp-1.0.1/000077500000000000000000000000001453723256400123235ustar00rootroot00000000000000zfp-1.0.1/.github/000077500000000000000000000000001453723256400136635ustar00rootroot00000000000000zfp-1.0.1/.github/dependabot.yml000066400000000000000000000003711453723256400165140ustar00rootroot00000000000000# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file version: 2 updates: - package-ecosystem: "github-actions" directory: "/" schedule: interval: "weekly" zfp-1.0.1/.github/workflows/000077500000000000000000000000001453723256400157205ustar00rootroot00000000000000zfp-1.0.1/.github/workflows/coverage.yml000066400000000000000000000033261453723256400202420ustar00rootroot00000000000000name: Coverage Report on: workflow_run: workflows: [Tests] types: [completed] jobs: coverage: runs-on: ubuntu-latest if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Python uses: actions/setup-python@v4 with: python-version: '3.x' architecture: x64 - name: Install Dependencies run: |- sudo apt install lcov python -m pip install lcov_cobertura - name: Run CMake run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++-11 -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_FLAGS="-fprofile-arcs -ftest-coverage" -DCMAKE_C_FLAGS="-fprofile-arcs -ftest-coverage" -DBUILD_TESTING_FULL=ON -DBUILD_CFP=ON -DZFP_WITH_OPENMP=ON - name: Build run: cmake --build ${{github.workspace}}/build - name: Run Tests working-directory: ${{github.workspace}}/build run: ctest -j 8 - name: Generate Coverage Report working-directory: ${{github.workspace}}/build run: |- lcov -c --directory ${{github.workspace}}/build --output-file coverage.info lcov --remove coverage.info '${{github.workspace}}/build/tests/*' --remove coverage.info '${{github.workspace}}/tests/*' --remove coverage.info '/usr/include/*' -o coverage.info lcov_cobertura ${{github.workspace}}/build/coverage.info -d -o ${{github.workspace}}/build/coverage.xml - name: Upload Report to Codecov uses: codecov/codecov-action@v3 with: files: ${{github.workspace}}/build/coverage.xml env_vars: Actions fail_ci_if_error: true zfp-1.0.1/.github/workflows/debug-linux.yml000066400000000000000000000013271453723256400206710ustar00rootroot00000000000000name: Debug (Linux) on: [workflow_dispatch] jobs: debug: runs-on: ubuntu-latest steps: - name: Checkout Zfp uses: actions/checkout@v4 - name: Setup Python uses: actions/setup-python@v4 with: python-version: '3.x' architecture: x64 - name: Install Zfpy Dependencies run: | python -m pip install cython python -m pip install oldest-supported-numpy python -m pip install setuptools - name: Install OpenMP run: | sudo apt-get update; sudo apt-get install -y libomp5 libomp-dev - name: Setup Tmate Session uses: mxschmitt/action-tmate@v3 zfp-1.0.1/.github/workflows/debug-macos.yml000066400000000000000000000012521453723256400206310ustar00rootroot00000000000000name: Debug (MacOS) on: [workflow_dispatch] jobs: debug: runs-on: macos-latest steps: - name: Checkout Zfp uses: actions/checkout@v4 - name: Setup Python uses: actions/setup-python@v4 with: python-version: '3.x' architecture: x64 - name: Install Zfpy Dependencies run: | python -m pip install cython python -m pip install oldest-supported-numpy python -m pip install setuptools - name: Install OpenMP run: | brew install libomp - name: Setup Tmate Session uses: mxschmitt/action-tmate@v3 zfp-1.0.1/.github/workflows/tests.yml000066400000000000000000000050161453723256400176070ustar00rootroot00000000000000name: Tests on: push env: BUILD_TYPE: Release jobs: build: runs-on: ${{matrix.os}} strategy: fail-fast: false matrix: include: - os: ubuntu-latest cxx_compiler: g++-10 c_compiler: gcc-10 omp: ON target: all - os: ubuntu-latest cxx_compiler: clang++ c_compiler: clang omp: ON target: all - os: macos-latest cxx_compiler: g++-11 c_compiler: gcc-11 omp: ON target: all - os: macos-latest cxx_compiler: clang++ c_compiler: clang omp: OFF target: all steps: - uses: actions/checkout@v4 - name: Setup Python uses: actions/setup-python@v4 with: python-version: '3.x' architecture: x64 - name: Install zfpy dependencies run: | python -m pip install cython python -m pip install oldest-supported-numpy python -m pip install setuptools - name: Setup OpenMP (Linux) if: ${{matrix.os == 'ubuntu-latest' && matrix.cxx_compiler == 'clang++'}} run: sudo apt-get update; sudo apt-get install -y libomp5 libomp-dev - name: Setup OpenMP (MacOS) if: ${{matrix.os == 'macos-latest'}} run: | brew install libomp echo "CC=$(brew --prefix llvm)/bin/clang" >> $GITHUB_ENV echo "CXX=$(brew --prefix llvm)/bin/clang++" >> $GITHUB_ENV echo "LDFLAGS=\"-L$(brew --prefix llvm)/lib\"" >> $GITHUB_ENV echo "CPPFLAGS=\"-I$(brew --prefix llvm)/include\"" >> $GITHUB_ENV - name: Run CMake id: cmake run: cmake -B ${{github.workspace}}/build ${{matrix.generator}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=${{matrix.cxx_compiler}} -DCMAKE_C_COMPILER=${{matrix.c_compiler}} -DBUILD_TESTING_FULL=ON -DZFP_WITH_OPENMP=${{matrix.omp}} -DBUILD_ZFPY=ON -DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_LIBRARY=$(python -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") - name: Build id: build run: cmake --build ${{github.workspace}}/build --target ${{matrix.target}} --config ${{env.BUILD_TYPE}} - name: Run Tests id: test working-directory: ${{github.workspace}}/build run: ctest -C ${{env.BUILD_TYPE}} -VV zfp-1.0.1/.gitignore000066400000000000000000000000741453723256400143140ustar00rootroot00000000000000*.a *.o bin build lib dist wheelhouse zfpy.egg-info modules zfp-1.0.1/.readthedocs.yaml000066400000000000000000000020071453723256400155510ustar00rootroot00000000000000# Read the Docs configuration file for Sphinx projects # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details # Required version: 2 # Set the OS, Python version and other tools you might need build: os: ubuntu-22.04 tools: python: "3.12" # You can also specify other tool versions: # nodejs: "20" # rust: "1.70" # golang: "1.20" # Build documentation in the "docs/" directory with Sphinx sphinx: configuration: docs/source/conf.py # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs # builder: "dirhtml" # Fail on all warnings to avoid broken references # fail_on_warning: true # Optionally build your docs in additional formats such as PDF and ePub formats: - pdf # - epub # Optional but recommended, declare the Python requirements required # to build your documentation # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html python: install: - requirements: docs/requirements.txt zfp-1.0.1/CHANGELOG.md000066400000000000000000000363021453723256400141400ustar00rootroot00000000000000Change Log ========== --- ## 1.0.1 (2023-12-15) This patch release primarily addresses minor bug fixes and is needed to update the zfpy Python wheels. ### Added - A new build macro, `BUILD_TESTING_FULL`, specifies that all unit tests be built; `BUILD_TESTING` produces a smaller subset of tests. Full tests and documentation are now included in releases. ### Fixed - #169: `libm` dependency is not always correctly detected. - #171: `ptrdiff_t` is not always imported in Cython. - #176: cfp API is not exposed via CMake configuration file. - #177: Full test suite is not included in release. - #181: `rpath` is not set correctly in executables. - #204: Array strides are not passed by value in zFORp. - #220: Errors reported with scikit-build when building zfpy. --- ## 1.0.0 (2022-08-01) This release is not ABI compatible with prior releases due to numerous changes to function signatures and data structures like `zfp_field`. However, few of the API changes, other than to the cfp C API for compressed arrays, should impact existing code. Note that numerous header files have been renamed or moved relative to prior versions. ### Added - `zfp::const_array`: read-only variable-rate array that supports fixed-precision, fixed-accuracy, and reversible modes. - Compressed-array classes for 4D data. - `const` versions of array references, pointers, and iterators. - A more complete API for pointers and iterators. - cfp support for proxy references and pointers, iterators, and (de)serialization. - Support for pointers and iterators into array views. - `zfp::array::size_bytes()` allows querying the size of different components of an array object (e.g., payload, cache, index, metadata, ...). - Templated C++ wrappers around the low-level C API. - A generic codec for storing blocks of uncompressed scalars in zfp's C++ arrays. - Additional functions for querying `zfp_field` and `zfp_stream` structs. - `zfp_config`: struct that encapsulates compression mode and parameters. - Rounding modes for reducing bias in compression errors. - New examples: `array`, `iteratorC`, and `ppm`. ### Changed - Headers from `array/`, `cfp/include/`, and `include/` have been renamed and reorganized into a common `include/` directory. - The libzfp API is now confined to `zfp.h`, `zfp.hpp`, and `zfp.mod` for C, C++, and Fortran bindings, respectively. These all appear in the top-level `include/` directory upon installation. - C++ headers now use a `.hpp` suffix; C headers use a `.h` suffix. - C++ headers like `array/zfparray.h` have been renamed `zfp/array.hpp`. - C headers like `cfp/include/cfparrays.h` have been renamed `zfp/array.h`. - `size_t` and `ptrdiff_t` replace `uint` and `int` for array sizes and strides in the array classes and C/Fortran APIs. - `zfp_bool` replaces `int` as Boolean type in the C API. - `bitstream_offset` and `bitstream_size` replace `size_t` to ensure support for 64-bit offsets into and lengths of bit streams. Consequently, the `bitstream` API has changed accordingly. - All array and view iterators are now random-access iterators. - Array inspectors now return `const_reference` rather than a scalar type like `float` to allow obtaining a `const_pointer` to an element of an immutable array. - `zfp::array::compressed_data()` now returns `void*` instead of `uchar*`. - The array (de)serialization API has been revised, resulting in new `zfp::array::header` and `zfp::exception` classes with new exception messages. - The array `codec` class is now responsible for all details regarding compression. - The compressed-array C++ implementation has been completely refactored to make it more modular, extensible, and reusable across array types. - Array block shapes are now computed on the fly rather than stored. - The cfp C API now wraps array objects in structs. - The zfpy Python API now supports the more general `memoryview` over `bytes` objects for decompression. - The zFORp Fortran module name is now `zfp` instead of `zforp_module`. - Some command-line options for the `diffusion` example have changed. - CMake 3.9 or later is now required for CMake builds. ### Removed - `zfp::array::get_header()` has been replaced with a `zfp::array::header` constructor that accepts an array object. - `ZFP_VERSION_RELEASE` is no longer defined (use `ZFP_VERSION_PATCH`). ### Fixed - #66: `make install` overwrites googletest. - #84: Incorrect order of parameters in CUDA `memset()`. - #86: C++ compiler warns when `__STDC_VERSION__` is undefined. - #87: `CXXFLAGS` is misspelled in `cfp/src/Makefile`. - #98: `zfp_stream_maximum_size()` underestimates size in reversible mode. - #99: Incorrect `private_view` reads due to missing writeback. - #109: Unused CPython array is incompatible with PyPy. - #112: PGI compiler bug causes issues with memory alignment. - #119: All-subnormal blocks may cause floating-point overflow. - #121: CUDA bit offsets are limited to 32 bits. - #122: `make install` does not install zfp command-line utility. - #125: OpenMP bit offsets are limited to 32 bits. - #126: `make install` does not install Fortran module. - #127: Reversible mode reports incorrect compressed block size. - #150: cmocka tests do not build on macOS. - #154: Thread safety is broken in `private_view` and `private_const_view`. - `ZFP_MAX_BITS` is off by one. - `diffusionC`, `iteratorC` are not being built with `gmake`. --- ## 0.5.5 (2019-05-05) ### Added - Support for reversible (lossless) compression of floating-point and integer data. - Methods for serializing and deserializing zfp's compressed arrays. - Python bindings for compressing NumPy arrays. - Fortran bindings to zfp's high-level C API. ### Changed - The default compressed-array cache size is now a function of the total number of array elements, irrespective of array shape. ### Fixed - Incorrect handling of execution policy in zfp utility. - Incorrect handling of decompression via header in zfp utility. - Incorrect cleanup of device memory in CUDA decompress. - Missing tests for failing mallocs. - CMake does not install CFP when built. - `zfp_write_header()` and `zfp_field_metadata()` succeed even if array dimensions are too large to fit in header. --- ## 0.5.4 (2018-10-01) ### Added - Support for CUDA fixed-rate compression and decompression. - Views into compressed arrays for thread safety, nested array indexing, slicing, and array subsetting. - C language bindings for compressed arrays. - Support for compressing and decompressing 4D data. ### Changed - Execution policy now applies to both compression and decompression. - Compressed array accessors now return Scalar type instead of `const Scalar&` to avoid stale references to evicted cache lines. ### Fixed - Incorrect handling of negative strides. - Incorrect handling of arrays with more than 2^32 elements in zfp command-line tool. - `bitstream` is not C++ compatible. - Minimum cache size request is not respected. --- ## 0.5.3 (2018-03-28) ### Added - Support for OpenMP multithreaded compression (but not decompression). - Options for OpenMP execution in zfp command-line tool. - Compressed-array support for copy construction and assignment via deep copies. - Virtual destructors to enable inheritance from zfp arrays. ### Changed - `zfp_decompress()` now returns the number of compressed bytes processed so far, i.e., the same value returned by `zfp_compress()`. --- ## 0.5.2 (2017-09-28) ### Added - Iterators and proxy objects for pointers and references. - Example illustrating how to use iterators and pointers. ### Changed - Diffusion example now optionally uses iterators. - Moved internal headers under array to `array/zfp`. - Modified 64-bit integer typedefs to avoid the C89 non-compliant `long long` and allow for user-supplied types and literal suffixes. - Renamed compile-time macros that did not have a `ZFP` prefix. - Rewrote documentation in reStructuredText and added complete documentation of all public functions, classes, types, and macros. ### Fixed - Issue with setting stream word type via CMake. --- ## 0.5.1 (2017-03-28) This release primarily fixes a few minor issues but also includes changes in anticipation of a large number of planned future additions to the library. No changes have been made to the compressed format, which is backwards compatible with version 0.5.0. ### Added - High-level API support for integer types. - Example that illustrates in-place compression. - Support for CMake builds. - Documentation that discusses common issues with using zfp. ### Changed - Separated library version from CODEC version and added version string. - Corrected inconsistent naming of `BIT_STREAM` macros in code and documentation. - Renamed some of the header bit mask macros. - `stream_skip()` and `stream_flush()` now return the number of bits skipped or output. - Renamed `stream_block()` and `stream_delta()` to make it clear that they refer to strided streams. Added missing definition of `stream_stride_block()`. - Changed `int` and `uint` types in places to use `ptrdiff_t` and `size_t` where appropriate. - Changed API for `zfp_set_precision()` and `zfp_set_accuracy()` to not require the scalar type. - Added missing `static` keyword in `decode_block()`. - Changed `testzfp` to allow specifying which tests to perform on the command line. - Modified directory structure. ### Fixed - Bug that prevented defining uninitialized arrays. - Incorrect computation of array sizes in `zfp_field_size()`. - Minor issues that prevented code from compiling on Windows. - Issue with fixed-accuracy headers that caused unnecessary storage. --- ## 0.5.0 (2016-02-29) This version introduces backwards incompatible changes to the CODEC. ### Added - Modified CODEC to more efficiently encode blocks whose values are all zero or are smaller in magnitude than the absolute error tolerance. This allows representing "empty" blocks using only one bit each. - Added functions for compactly encoding the compression parameters and field meta data, e.g., for producing self-contained compressed streams. Also added functions for reading and writing a header containing these parameters. ### Changed - Changed behavior of `zfp_compress()` and `zfp_decompress()` to not automatically rewind the bit stream. This makes it easier to concatenate multiple compressed bit streams, e.g., when compressing vector fields or multiple scalars together. - Changed the zfp example program interface to allow reading and writing compressed streams, optionally with a header. The zfp tool can now be used to compress and decompress files as a stand alone utility. --- ## 0.4.1 (2015-12-28) ### Added - Added `simple.c` as a minimal example of how to call the compressor. ### Changed - Changed compilation of diffusion example to output two executables: one with and one without compression. ### Fixed - Bug that caused segmentation fault when compressing 3D arrays whose dimensions are not multiples of four. Specifically, arrays of dimensions nx * ny * nz, with ny not a multiple of four, were not handled correctly. - Modified `examples/fields.h` to ensure standard compliance. Previously, C99 support was needed to handle the hex float constants, which are not supported in C++98. --- ## 0.4.0 (2015-12-05) This version contains substantial changes to the compression algorithm that improve PSNR by about 6 dB and speed by a factor of 2-3. These changes are not backward compatible with previous versions of zfp. ### Added - Support for 31-bit and 63-bit integer data, as well as shorter integer types. - New examples for evaluating the throughput of the (de)compressor and for compressing grayscale images in the pgm format. - Frequently asked questions. ### Changed - Rewrote compression codec entirely in C to make linking and calling easier from other programming languages, and to expose the low-level interface through C instead of C++. This necessitated significant changes to the API as well. - Minor changes to the C++ compressed array API, as well as major implementation changes to support the C library. The namespace and public types are now all in lower case. ### Removed - Support for general fixed-point decorrelating transforms. --- ## 0.3.2 (2015-12-03) ### Fixed - Bug in `Array::get()` that caused the wrong cached block to be looked up, thus occasionally copying incorrect values back to parts of the array. --- ## 0.3.1 (2015-05-06) ### Fixed - Rare bug caused by exponent underflow in blocks with no normal and some subnormal numbers. --- ## 0.3.0 (2015-03-03) This version modifies the default decorrelating transform to one that uses only additions and bit shifts. This new transform, in addition to being faster, also has some theoretical optimality properties and tends to improve rate distortion. This change is not backwards compatible. ### Added - Compile-time support for parameterized transforms, e.g., to support other popular transforms like DCT, HCT, and Walsh-Hadamard. - Floating-point traits to reduce the number of template parameters. It is now possible to declare a 3D array as `Array3`, for example. - Functions for setting the array scalar type and dimensions. - `testzfp` for regression testing. ### Changed - Made forward transform range preserving: (-1, 1) is mapped to (-1, 1). Consequently Q1.62 fixed point can be used throughout. - Changed the order in which bits are emitted within each bit plane to be more intelligent. Group tests are now deferred until they are needed, i.e., just before the value bits for the group being tested. This improves the quality of fixed-rate encodings, but has no impact on compressed size. - Made several optimizations to improve performance. - Consolidated several header files. --- ## 0.2.1 (2014-12-12) ### Added - Win64 support via Microsoft Visual Studio compiler. - Documentation of the expected output for the diffusion example. ### Changed - Made several minor changes to suppress compiler warnings. ### Fixed - Broken support for IBM's `xlc` compiler. --- ## 0.2.0 (2014-12-02) The compression interface from `zfpcompress` was relocated to a separate library, called `libzfp`, and modified to be callable from C. This API now uses a parameter object (`zfp_params`) to specify array type and dimensions as well as compression parameters. ### Added - Several utility functions were added to simplify `libzfp` usage: * Functions for setting the rate, precision, and accuracy. Corresponding functions were also added to the `Codec` class. * A function for estimating the buffer size needed for compression. - The `Array` class functionality was expanded: * Support for accessing the compressed bit stream stored with an array, e.g., for offline compressed storage and for initializing an already compressed array. * Functions for dynamically specifying the cache size. * The default cache is now direct-mapped instead of two-way associative. ### Fixed - Corrected the value of the lowest possible bit plane to account for both the smallest exponent and the number of bits in the significand. - Corrected inconsistent use of rate and precision. The rate refers to the number of compressed bits per floating-point value, while the precision refers to the number of uncompressed bits. The `Array` API was changed accordingly. --- ## 0.1.0 (2014-11-12) Initial beta release. zfp-1.0.1/CITATION.cff000066400000000000000000000007021453723256400142140ustar00rootroot00000000000000cff-version: 1.1.0 message: "If you use this software, please cite it as below." authors: - family-names: Lindstrom given-names: Peter orcid: https://orcid.org/0000-0003-3817-4199 title: "Fixed-Rate Compressed Floating-Point Arrays" journal: "IEEE Transactions on Visualization and Computer Graphics" volume: 20 number: 12 start: 2674 end: 2683 year: 2014 month: 12 version: develop doi: 10.1109/TVCG.2014.2346458 date-released: 2014-11-05 zfp-1.0.1/CMakeLists.txt000066400000000000000000000313761453723256400150750ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.9) # Enable MACOSX_RPATH by default cmake_policy(SET CMP0042 NEW) # Fail immediately if not using an out-of-source build if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) message(FATAL_ERROR "In-source builds are not supported. Please create a build directory " "separate from the source directory") endif() #------------------------------------------------------------------------------# # Parse version number from zfp.h #------------------------------------------------------------------------------# file(READ ${CMAKE_CURRENT_SOURCE_DIR}/include/zfp/version.h _zfp_h_contents) string(REGEX REPLACE ".*#define[ \t]+ZFP_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" ZFP_VERSION_MAJOR ${_zfp_h_contents}) string(REGEX REPLACE ".*#define[ \t]+ZFP_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" ZFP_VERSION_MINOR ${_zfp_h_contents}) string(REGEX REPLACE ".*#define[ \t]+ZFP_VERSION_PATCH[ \t]+([0-9]+).*" "\\1" ZFP_VERSION_PATCH ${_zfp_h_contents}) string(REGEX REPLACE ".*#define[ \t]+ZFP_VERSION_TWEAK[ \t]+([0-9]+).*" "\\1" ZFP_VERSION_TWEAK ${_zfp_h_contents}) if(${ZFP_VERSION_TWEAK} EQUAL 0) set(ZFP_VERSION "${ZFP_VERSION_MAJOR}.${ZFP_VERSION_MINOR}.${ZFP_VERSION_PATCH}") else() set(ZFP_VERSION "${ZFP_VERSION_MAJOR}.${ZFP_VERSION_MINOR}.${ZFP_VERSION_PATCH}.${ZFP_VERSION_TWEAK}") endif() project(ZFP VERSION ${ZFP_VERSION}) #------------------------------------------------------------------------------# # Some boilerplate to setup nice output directories #------------------------------------------------------------------------------# include(GNUInstallDirs) set(CMAKE_INSTALL_CMAKEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/zfp CACHE STRING "Installation CMake subdirectory") list(INSERT CMAKE_MODULE_PATH 0 "${ZFP_SOURCE_DIR}/cmake") if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ZFP_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) endif() if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ZFP_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) endif() if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ZFP_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) endif() # Setup RPath set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}) #------------------------------------------------------------------------------# # Top level options #------------------------------------------------------------------------------# # Windows (Visual Studio) specific options if(MSVC) # Use this to get a usable export library when building a DLL on Windows set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) # Silence extraneous Visual Studio specific warnings add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS) add_compile_options(/wd4146) add_compile_options(/wd4305) endif() # Suggest C99 if(NOT CMAKE_C_STANDARD) set(CMAKE_C_STANDARD 99) endif() if(MSVC OR MINGW) set(CMAKE_C_STANDARD 90) endif() message(STATUS "Compiling with C standard: ${CMAKE_C_STANDARD}") # Suggest C++98 if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 98) endif() message(STATUS "Compiling with C++ standard: ${CMAKE_CXX_STANDARD}") include(CMakeDependentOption) # Typically you'd always be able to enable shared libraries but default # configurations with the Cray toolchain will explicitly disable shared lib # support and only allow static libs. Making this a cmake_dependent_option # will ensure that shared library support will be disabled if the system does # not support it. # Setup shared library / -fPIC stuff get_property(SHARED_LIBS_SUPPORTED GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS) cmake_dependent_option(BUILD_SHARED_LIBS "Whether or not to build shared libraries" ON "SHARED_LIBS_SUPPORTED" OFF) # PIC is always on for shared libs. This allows it to be selectable for # static libs. if(DEFINED ZFP_ENABLE_PIC) set(ZFP_ENABLE_PIC_DEFAULT ${ZFP_ENABLE_PIC}) elseif(DEFINED CMAKE_POSITION_INDEPENDENT_CODE) set(ZFP_ENABLE_PIC_DEFAULT ${CMAKE_POSITION_INDEPENDENT_CODE}) else() set(ZFP_ENABLE_PIC_DEFAULT ${SHARED_LIBS_SUPPORTED}) endif() cmake_dependent_option(ZFP_ENABLE_PIC "Build with Position Independent Code" ${ZFP_ENABLE_PIC_DEFAULT} "SHARED_LIBS_SUPPORTED" OFF) set(CMAKE_POSITION_INDEPENDENT_CODE ${ZFP_ENABLE_PIC}) # Compile-time options. set(ZFP_BIT_STREAM_WORD_SIZE 64 CACHE STRING "Use smaller bit stream word type for finer rate granularity") set_property(CACHE ZFP_BIT_STREAM_WORD_SIZE PROPERTY STRINGS "8;16;32;64") if(CMAKE_C_COMPILER_ID MATCHES "PGI|NVHPC") # Use default alignment to address PGI compiler bug. set(ZFP_CACHE_LINE_SIZE 0 CACHE STRING "Cache line alignment in bytes") mark_as_advanced(ZFP_CACHE_LINE_SIZE) endif() set(PPM_CHROMA 2 CACHE STRING "Chroma block dimensionality for ppm example") set_property(CACHE PPM_CHROMA PROPERTY STRINGS "1;2") set(ZFP_ROUNDING_MODE ZFP_ROUND_NEVER CACHE STRING "Rounding mode for reducing bias") set_property(CACHE ZFP_ROUNDING_MODE PROPERTY STRINGS "ZFP_ROUND_NEVER;ZFP_ROUND_FIRST;ZFP_ROUND_LAST") option(ZFP_WITH_DAZ "Treat subnormals as zero to avoid overflow" OFF) option(ZFP_WITH_CUDA "Enable CUDA parallel compression" OFF) option(ZFP_WITH_BIT_STREAM_STRIDED "Enable strided access for progressive zfp streams" OFF) mark_as_advanced(ZFP_WITH_BIT_STREAM_STRIDED) option(ZFP_WITH_TIGHT_ERROR "Reduce slack in absolute errors" OFF) option(ZFP_WITH_ALIGNED_ALLOC "Enable aligned memory allocation" OFF) mark_as_advanced(ZFP_WITH_ALIGNED_ALLOC) option(ZFP_WITH_CACHE_TWOWAY "Use two-way skew-associative cache" OFF) mark_as_advanced(ZFP_WITH_CACHE_TWOWAY) option(ZFP_WITH_CACHE_FAST_HASH "Use a faster but more collision prone hash function" OFF) mark_as_advanced(ZFP_WITH_CACHE_FAST_HASH) option(ZFP_WITH_CACHE_PROFILE "Count cache misses" OFF) mark_as_advanced(ZFP_WITH_CACHE_PROFILE) # Handle compile-time macros if((DEFINED ZFP_INT64) AND (DEFINED ZFP_INT64_SUFFIX)) list(APPEND zfp_public_defs ZFP_INT64=${ZFP_INT64}) list(APPEND zfp_public_defs ZFP_INT64_SUFFIX=${ZFP_INT64_SUFFIX}) endif() if((DEFINED ZFP_UINT64) AND (DEFINED ZFP_UINT64_SUFFIX)) list(APPEND zfp_public_defs ZFP_UINT64=${ZFP_UINT64}) list(APPEND zfp_public_defs ZFP_UINT64_SUFFIX=${ZFP_UINT64_SUFFIX}) endif() # This odd cmake pattern here lets the OpenMP feature be either auto-detected, # explicitly enabled, or explicitly disabled, instead of just on or off. if(DEFINED ZFP_WITH_OPENMP) option(ZFP_WITH_OPENMP "Enable OpenMP parallel compression" ${ZFP_WITH_OPENMP}) if(ZFP_WITH_OPENMP) if(BUILD_EXAMPLES) find_package(OpenMP COMPONENTS C CXX REQUIRED) else() find_package(OpenMP COMPONENTS C REQUIRED) endif() endif() else() if(BUILD_EXAMPLES) find_package(OpenMP COMPONENTS C CXX) else() find_package(OpenMP COMPONENTS C) endif() option(ZFP_WITH_OPENMP "Enable OpenMP parallel compression" ${OPENMP_FOUND}) endif() # Suppress CMake warning about unused variable in this file set(TOUCH_UNUSED_VARIABLE ${ZFP_OMP_TESTS_ONLY}) # Some compilers don't use explicit libraries on the link line for OpenMP but # instead need to treat the OpenMP C flags as both compile and link flags # i.e. -fopenmp for compiling and -lgomp for linking, use -fomp for both # compiling and linking if(ZFP_WITH_OPENMP AND NOT OpenMP_C_LIBRARIES) set(OpenMP_C_LIBRARIES ${OpenMP_C_FLAGS}) endif() if(ZFP_WITH_CUDA) # use CUDA_BIN_DIR hint set(ENV{CUDA_BIN_PATH} ${CUDA_BIN_DIR}) find_package(CUDA) if(NOT CUDA_FOUND) message(FATAL_ERROR "ZFP_WITH_CUDA is enabled, but a CUDA installation was not found.") endif() if(${CUDA_VERSION_MAJOR} LESS 7) message(FATAL_ERROR "zfp requires at least CUDA 7.0.") endif() endif() if(NOT (ZFP_BIT_STREAM_WORD_SIZE EQUAL 64)) list(APPEND zfp_private_defs BIT_STREAM_WORD_TYPE=uint${ZFP_BIT_STREAM_WORD_SIZE}) endif() if(DEFINED ZFP_CACHE_LINE_SIZE) # Add to zfp_public_defs since many tests currently include files from src. # list(APPEND zfp_public_defs ZFP_CACHE_LINE_SIZE=${ZFP_CACHE_LINE_SIZE}) list(APPEND zfp_private_defs ZFP_CACHE_LINE_SIZE=${ZFP_CACHE_LINE_SIZE}) endif() if(ZFP_WITH_BIT_STREAM_STRIDED) list(APPEND zfp_public_defs BIT_STREAM_STRIDED) endif() if(NOT (ZFP_ROUNDING_MODE EQUAL ZFP_ROUND_NEVER)) list(APPEND zfp_private_defs ZFP_ROUNDING_MODE=${ZFP_ROUNDING_MODE}) endif() if(ZFP_WITH_TIGHT_ERROR) if((ZFP_ROUNDING_MODE EQUAL 0) OR (ZFP_ROUNDING_MODE STREQUAL ZFP_ROUND_NEVER)) message(FATAL_ERROR "ZFP_WITH_TIGHT_ERROR requires ZFP_ROUND_FIRST or ZFP_ROUND_LAST rounding mode") endif() list(APPEND zfp_private_defs ZFP_WITH_TIGHT_ERROR) endif() if(ZFP_WITH_DAZ) list(APPEND zfp_private_defs ZFP_WITH_DAZ) endif() if(ZFP_WITH_ALIGNED_ALLOC) list(APPEND zfp_compressed_array_defs ZFP_WITH_ALIGNED_ALLOC) endif() if(ZFP_WITH_CACHE_TWOWAY) list(APPEND zfp_compressed_array_defs ZFP_WITH_CACHE_TWOWAY) endif() if(ZFP_WITH_CACHE_FAST_HASH) list(APPEND zfp_compressed_array_defs ZFP_WITH_CACHE_FAST_HASH) endif() if(ZFP_WITH_CACHE_PROFILE) list(APPEND zfp_compressed_array_defs ZFP_WITH_CACHE_PROFILE) endif() list(APPEND ppm_private_defs PPM_CHROMA=${PPM_CHROMA}) # Link libm only if necessary include(CheckCSourceCompiles) check_c_source_compiles("#include\nint main(int n,char*v[]){return sqrt(n);}" HAVE_MATH) if(NOT HAVE_MATH) set(CMAKE_REQUIRED_LIBRARIES m) check_c_source_compiles("#include\nint main(int n,char*v[]){return sqrt(n);}" HAVE_LIBM_MATH) unset(CMAKE_REQUIRED_LIBRARIES) if(NOT HAVE_LIBM_MATH) message(FATAL_ERROR "Unable to use C math library functions (with or without -lm)") endif() endif() #------------------------------------------------------------------------------# # Add source code #------------------------------------------------------------------------------# include(CTest) if(BUILD_TESTING OR BUILD_TESTING_FULL) enable_testing() endif() set(ZFP_LIBRARY_PREFIX "" CACHE STRING "Prefix to prepend to the output library name") mark_as_advanced(ZFP_LIBRARY_PREFIX) add_subdirectory(src) option(BUILD_ALL "Build all subdirectories" OFF) if(BUILD_ALL) set(BUILD_CFP ON CACHE BOOL "Build CFP arrays library" FORCE) set(BUILD_ZFORP ON CACHE BOOL "Build Fortran library" FORCE) set(BUILD_ZFPY ON CACHE BOOL "Build python bindings for zfp" FORCE) set(BUILD_UTILITIES ON CACHE BOOL "Build command line utilities for zfp" FORCE) set(BUILD_EXAMPLES ON CACHE BOOL "Build Examples" FORCE) endif() option(BUILD_CFP "Build CFP arrays library" OFF) if(BUILD_CFP) add_subdirectory(cfp) endif() option(BUILD_ZFORP "Build Fortran library" OFF) if(BUILD_ZFORP) add_subdirectory(fortran) endif() option(BUILD_ZFPY "Build python bindings for zfp" OFF) if(BUILD_ZFPY) add_subdirectory(python) endif() option(BUILD_UTILITIES "Build command line utilities for zfp" ON) if(BUILD_UTILITIES) add_subdirectory(utils) endif() option(BUILD_EXAMPLES "Build Examples" OFF) if(BUILD_EXAMPLES) add_subdirectory(examples) endif() if(BUILD_TESTING OR BUILD_TESTING_FULL) # Disable gtest install to prevent clobbering existing installations option(INSTALL_GMOCK "Install Googlemock" OFF) option(INSTALL_GTEST "Install Googletest" OFF) add_subdirectory(tests) endif() #------------------------------------------------------------------------------# # Header install #------------------------------------------------------------------------------# if(BUILD_CFP) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) else() install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PATTERN "cfp" EXCLUDE) endif() #------------------------------------------------------------------------------# # Build type: one of None, Debug, Release, RelWithDebInfo, MinSizeRel #------------------------------------------------------------------------------# if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE Release) endif() #------------------------------------------------------------------------------# # Packaging #------------------------------------------------------------------------------# # Add all targets to the build-tree export set export(TARGETS zfp NAMESPACE zfp:: FILE "${PROJECT_BINARY_DIR}/zfp-targets.cmake") if(BUILD_CFP) export(TARGETS cfp NAMESPACE zfp:: APPEND FILE "${PROJECT_BINARY_DIR}/zfp-targets.cmake") endif() configure_file(zfp-config.cmake.in "${PROJECT_BINARY_DIR}/zfp-config.cmake" @ONLY) configure_file(zfp-config-version.cmake.in "${PROJECT_BINARY_DIR}/zfp-config-version.cmake" @ONLY) # Install the zfp-config.cmake and zfp-config-version.cmake install(FILES "${PROJECT_BINARY_DIR}/zfp-config.cmake" "${PROJECT_BINARY_DIR}/zfp-config-version.cmake" DESTINATION "${CMAKE_INSTALL_CMAKEDIR}") # Install the export set for use with the install-tree install(EXPORT zfp-targets NAMESPACE zfp:: DESTINATION "${CMAKE_INSTALL_CMAKEDIR}") if(BUILD_CFP) install(EXPORT cfp-targets NAMESPACE zfp:: DESTINATION "${CMAKE_INSTALL_CMAKEDIR}") endif() zfp-1.0.1/CONTRIBUTING.md000066400000000000000000000012031453723256400145500ustar00rootroot00000000000000Contributing ============ The zfp project uses the [Gitflow](https://nvie.com/posts/a-successful-git-branching-model/) development model. Contributions should be made as pull requests on the `develop` branch. Although this branch is under continuous development, it should be robust enough to pass all regression tests. For contributions that are not production ready, please [contact us](mailto:zfp.llnl.gov) to have a separate branch created. The `master` branch is updated with each release and reflects the most recent official release of zfp. See the [Releases Page](https://github.com/LLNL/zfp/releases) for a history of releases. zfp-1.0.1/CTestConfig.cmake000066400000000000000000000011251453723256400154740ustar00rootroot00000000000000## This file should be placed in the root directory of your project. ## Then modify the CMakeLists.txt file in the root directory of your ## project to incorporate the testing dashboard. ## # The following are required to uses Dart and the Cdash dashboard ## ENABLE_TESTING() ## INCLUDE(CTest) set(CTEST_PROJECT_NAME "ZFP") set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC") set(CTEST_DROP_METHOD "https") set(CTEST_DROP_SITE "open.cdash.org") set(CTEST_DROP_LOCATION "/submit.php?project=zfp") set(CTEST_DROP_SITE_CDASH TRUE) # Test Options set(MEMORYCHECK_COMMAND_OPTIONS "--show-reachable=no") zfp-1.0.1/Config000066400000000000000000000100331453723256400134500ustar00rootroot00000000000000# compiler executables -------------------------------------------------------- CC = gcc CXX = g++ FC = gfortran # language standard ----------------------------------------------------------- # CSTD = -std=c89 CSTD = -std=c99 CXXSTD = -std=c++98 # CXXSTD = -std=c++11 FSTD = -std=f2018 -ffree-form -Wno-c-binding-type # common compiler options ----------------------------------------------------- OPTFLAGS = -O3 FLAGS = $(OPTFLAGS) -fPIC -pedantic -Wall -Wextra LDFLAGS = SOFLAGS = # OpenMP compiler options ----------------------------------------------------- # do not comment out; use "make ZFP_WITH_OPENMP=0" to disable OpenMP OMPFLAGS = -fopenmp # Apple clang OpenMP options # OMPFLAGS = -Xclang -fopenmp # optional compiler macros ---------------------------------------------------- # use smaller bit stream word type for finer rate granularity; # can bet set on command line, e.g., "make BIT_STREAM_WORD_TYPE=uint8" # DEFS += -DBIT_STREAM_WORD_TYPE=uint8 # DEFS += -DBIT_STREAM_WORD_TYPE=uint16 # DEFS += -DBIT_STREAM_WORD_TYPE=uint32 # DEFS += -DBIT_STREAM_WORD_TYPE=uint64 # reduce bias and slack in errors; can be set on command line, e.g., # "make ZFP_ROUNDING_MODE=ZFP_ROUND_FIRST" # DEFS += -DZFP_ROUNDING_MODE=ZFP_ROUND_NEVER # DEFS += -DZFP_ROUNDING_MODE=ZFP_ROUND_FIRST # DEFS += -DZFP_ROUNDING_MODE=ZFP_ROUND_LAST # DEFS += -DZFP_WITH_TIGHT_ERROR # treat subnormals as zero to avoid overflow; can be set on command line, e.g., # "make ZFP_WITH_DAZ=1" # DEFS += -DZFP_WITH_DAZ # use long long for 64-bit types # DEFS += -DZFP_INT64='long long' -DZFP_INT64_SUFFIX='ll' # DEFS += -DZFP_UINT64='unsigned long long' -DZFP_UINT64_SUFFIX='ull' # cache alignment # DEFS += -DZFP_CACHE_LINE_SIZE=256 # enable strided access for progressive zfp streams # DEFS += -DBIT_STREAM_STRIDED # use aligned memory allocation # DEFS += -DZFP_WITH_ALIGNED_ALLOC # use two-way skew-associative cache # DEFS += -DZFP_WITH_CACHE_TWOWAY # use faster but more collision prone hash function # DEFS += -DZFP_WITH_CACHE_FAST_HASH # count cache misses # DEFS += -DZFP_WITH_CACHE_PROFILE # build targets --------------------------------------------------------------- # default targets BUILD_CFP = 0 BUILD_ZFORP = 0 BUILD_UTILITIES = 1 BUILD_EXAMPLES = 0 BUILD_TESTING = 1 BUILD_SHARED_LIBS = 0 # build all targets? ifdef BUILD_ALL ifneq ($(BUILD_ALL),0) BUILD_CFP = 1 BUILD_ZFORP = 1 BUILD_UTILITIES = 1 BUILD_EXAMPLES = 1 BUILD_TESTING = 1 endif endif # build shared libraries? ifneq ($(BUILD_SHARED_LIBS),0) LIBRARY = shared LIBZFP = libzfp.so LIBCFP = libcfp.so else LIBRARY = static LIBZFP = libzfp.a LIBCFP = libcfp.a endif # operating system and compiler dependent flags ------------------------------- # macOS configuration; compile with "make OS=mac" ifeq ($(OS),mac) SOFLAGS += -undefined dynamic_lookup endif # suppress unused function warnings when compiling C89 ifeq ($(CSTD),-std=c89) FLAGS += -Wno-unused-function endif # process macros set on the command line -------------------------------------- # bit stream word type ifdef BIT_STREAM_WORD_TYPE DEFS += -DBIT_STREAM_WORD_TYPE=$(BIT_STREAM_WORD_TYPE) endif # enable OpenMP? ifdef ZFP_WITH_OPENMP ifneq ($(ZFP_WITH_OPENMP),0) ifneq ($(ZFP_WITH_OPENMP),OFF) FLAGS += $(OMPFLAGS) endif endif endif # treat subnormals as zero to avoid overflow ifdef ZFP_WITH_DAZ ifneq ($(ZFP_WITH_DAZ),0) FLAGS += -DZFP_WITH_DAZ endif endif # rounding mode and slack in error ifdef ZFP_ROUNDING_MODE FLAGS += -DZFP_ROUNDING_MODE=$(ZFP_ROUNDING_MODE) ifneq ($(ZFP_ROUNDING_MODE),0) # tight error bound requires round-first or round-last mode ifdef ZFP_WITH_TIGHT_ERROR ifneq ($(ZFP_WITH_TIGHT_ERROR),0) FLAGS += -DZFP_WITH_TIGHT_ERROR endif endif endif endif # chroma mode for ppm example ifdef PPM_CHROMA PPM_FLAGS += -DPPM_CHROMA=$(PPM_CHROMA) endif # compiler options ------------------------------------------------------------ CFLAGS = $(CSTD) $(FLAGS) $(DEFS) CXXFLAGS = $(CXXSTD) $(FLAGS) $(DEFS) FFLAGS = $(FSTD) $(FLAGS) $(DEFS) zfp-1.0.1/LICENSE000066400000000000000000000030121453723256400133240ustar00rootroot00000000000000BSD 3-Clause License Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. zfp-1.0.1/Makefile000066400000000000000000000014021453723256400137600ustar00rootroot00000000000000# see Config file for compile-time settings include Config MAKEFLAGS += --no-print-directory # default: build all targets enabled in Config all: @echo $(LIBRARY) @cd src; $(MAKE) clean $(LIBRARY) ifneq ($(BUILD_CFP),0) @cd cfp; $(MAKE) clean $(LIBRARY) endif ifneq ($(BUILD_ZFORP),0) @cd fortran; $(MAKE) clean $(LIBRARY) endif ifneq ($(BUILD_UTILITIES),0) @cd utils; $(MAKE) clean all endif ifneq ($(BUILD_TESTING),0) @cd tests; $(MAKE) clean all endif ifneq ($(BUILD_EXAMPLES),0) @cd examples; $(MAKE) clean all endif # run basic regression tests test: @cd tests; $(MAKE) test # clean all clean: @cd src; $(MAKE) clean @cd cfp; $(MAKE) clean @cd fortran; $(MAKE) clean @cd utils; $(MAKE) clean @cd tests; $(MAKE) clean @cd examples; $(MAKE) clean zfp-1.0.1/NOTICE000066400000000000000000000022171453723256400132310ustar00rootroot00000000000000This work was produced under the auspices of the U.S. Department of Energy by Lawrence Livermore National Laboratory under Contract DE-AC52-07NA27344. This work was prepared as an account of work sponsored by an agency of the United States Government. Neither the United States Government nor Lawrence Livermore National Security, LLC, nor any of their employees makes any warranty, expressed or implied, or assumes any legal liability or responsibility for the accuracy, completeness, or usefulness of any information, apparatus, product, or process disclosed, or represents that its use would not infringe privately owned rights. Reference herein to any specific commercial product, process, or service by trade name, trademark, manufacturer, or otherwise does not necessarily constitute or imply its endorsement, recommendation, or favoring by the United States Government or Lawrence Livermore National Security, LLC. The views and opinions of authors expressed herein do not necessarily state or reflect those of the United States Government or Lawrence Livermore National Security, LLC, and shall not be used for advertising or product endorsement purposes. zfp-1.0.1/README.md000066400000000000000000000114101453723256400135770ustar00rootroot00000000000000ZFP === [![Github Actions Build Status](https://github.com/LLNL/zfp/workflows/Run%20Tests/badge.svg)](https://github.com/LLNL/zfp/actions/workflows/tests.yml) [![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/qb3ld7j11segy52k/branch/develop?svg=true)](https://ci.appveyor.com/project/lindstro/zfp) [![Documentation Status](https://readthedocs.org/projects/zfp/badge/?version=release1.0.1)](https://zfp.readthedocs.io/en/release1.0.1/) [![codecov](https://codecov.io/gh/LLNL/zfp/branch/develop/graph/badge.svg?token=jqvMVvgRQ9)](https://codecov.io/gh/LLNL/zfp) [![R&D100 - Winner](https://img.shields.io/badge/R%26D100-Winner-gold)](https://www.rdworldonline.com/rd-100-winners-for-2023-are-announced-2/) zfp is a compressed format for representing multidimensional floating-point and integer arrays. zfp provides compressed-array classes that support high throughput read and write random access to individual array elements. zfp also supports serial and parallel (OpenMP and CUDA) compression of whole arrays, e.g., for applications that read and write large data sets to and from disk. zfp uses lossy but optionally error-bounded compression to achieve high compression ratios. Bit-for-bit lossless compression is also possible through one of zfp's compression modes. zfp works best for 2D, 3D, and 4D arrays that exhibit spatial correlation, such as continuous fields from physics simulations, natural images, regularly sampled terrain surfaces, etc. zfp compression of 1D arrays is possible but generally discouraged. zfp is freely available as open source and is distributed under a BSD license. zfp is primarily written in C and C++ but also includes Python and Fortran bindings. zfp conforms to various language standards, including C89, C99, C11, C++98, C++11, and C++14, and is supported on Linux, macOS, and Windows. Quick Start ----------- To download zfp, type: git clone https://github.com/LLNL/zfp.git zfp may be built using either [CMake](https://cmake.org/) or [GNU make](https://www.gnu.org/software/make/). To use CMake, type: cd zfp mkdir build cd build cmake .. cmake --build . --config Release ctest This builds the zfp library in the `build/lib` directory and the zfp command-line executable in the `build/bin` directory. It then runs the regression tests. The full test suite may be run by enabling the `BUILD_TESTING_FULL` CMake option during the build step. zfp may also be built using GNU make: cd zfp make make test Note: GNU builds are less flexible and do not support all available features, e.g., CUDA support. For further configuration and build instructions, please consult the [documentation](https://zfp.readthedocs.io/en/release1.0.1/installation.html). For examples of how to call the C library and use the C++ array classes, see the [examples](https://zfp.readthedocs.io/en/release1.0.1/examples.html) section. Documentation ------------- Full HTML [documentation](http://zfp.readthedocs.io/en/release1.0.1) is available online. A [PDF](http://readthedocs.org/projects/zfp/downloads/pdf/release1.0.1/) version is also available. Further information on the zfp software is included in these files: - Change log: see [CHANGELOG.md](./CHANGELOG.md). - Support and additional resources: see [SUPPORT.md](./SUPPORT.md). - Code contributions: see [CONTRIBUTING.md](./CONTRIBUTING.md). Authors ------- zfp was originally developed by [Peter Lindstrom](https://people.llnl.gov/pl) at [Lawrence Livermore National Laboratory](https://www.llnl.gov/). Please see the [Contributors Page](https://github.com/LLNL/zfp/graphs/contributors) for a full list of contributors. ### Citing zfp If you use zfp for scholarly research, please cite this paper: * Peter Lindstrom. [Fixed-Rate Compressed Floating-Point Arrays](https://www.researchgate.net/publication/264417607_Fixed-Rate_Compressed_Floating-Point_Arrays). IEEE Transactions on Visualization and Computer Graphics, 20(12):2674-2683, December 2014. [doi:10.1109/TVCG.2014.2346458](http://doi.org/10.1109/TVCG.2014.2346458). The algorithm implemented in the current version of zfp is described in the [documentation](https://zfp.readthedocs.io/en/latest/algorithm.html) and in the following paper: * James Diffenderfer, Alyson Fox, Jeffrey Hittinger, Geoffrey Sanders, Peter Lindstrom. [Error Analysis of ZFP Compression for Floating-Point Data](https://www.researchgate.net/publication/324908266_Error_Analysis_of_ZFP_Compression_for_Floating-Point_Data). SIAM Journal on Scientific Computing, 41(3):A1867-A1898, June 2019. [doi:10.1137/18M1168832](http://doi.org/10.1137/18M1168832). License ------- zfp is distributed under the terms of the BSD 3-Clause license. See [LICENSE](./LICENSE) and [NOTICE](./NOTICE) for details. SPDX-License-Identifier: BSD-3-Clause LLNL-CODE-663824 zfp-1.0.1/SUPPORT.md000066400000000000000000000005761453723256400140310ustar00rootroot00000000000000Support ======= For more information on zfp, please see the [zfp website](https://zfp.llnl.gov). For bug reports and feature requests, please consult the [GitHub issue tracker](https://github.com/LLNL/zfp/issues/). For questions and comments not answered here or in the [documentation](http://zfp.readthedocs.io), please contact us by email at [zfp@llnl.gov](mailto:zfp@llnl.gov). zfp-1.0.1/appveyor.sh000066400000000000000000000045341453723256400145320ustar00rootroot00000000000000#!/usr/bin/env sh set -e # pass additional args in $1 (starting with whitespace character) run_all () { run_all_cmd="ctest -V -C $BUILD_TYPE -DGENERATOR=\"$GENERATOR\" -S \"$APPVEYOR_BUILD_FOLDER/cmake/appveyor.cmake\"" eval "${run_all_cmd}$1" } # create build dir for out-of-source build mkdir build cd build # technically, flags are passed on to cmake/* and actually set there # config without OpenMP, with CFP (and custom namespace), with aligned allocations (compressed arrays) BUILD_FLAGS="" BUILD_FLAGS="$BUILD_FLAGS -DBUILD_UTILITIES=ON" BUILD_FLAGS="$BUILD_FLAGS -DBUILD_EXAMPLES=ON" BUILD_FLAGS="$BUILD_FLAGS -DBUILD_CFP=ON" BUILD_FLAGS="$BUILD_FLAGS -DCFP_NAMESPACE=cfp2" # zfpy only built for MSVC, Release builds if [ $COMPILER == "msvc" ] && [ $BUILD_TYPE == "Release" ]; then # verify active python version matches what was specified in appveyor.yml # fetch python version X.Y (single digits only) ACTIVE_PY_VERSION=$(python -c 'import platform; print(platform.python_version())' | cut -c1-3) # $PYTHON_VERSION comes from appveyor.yml and has form XY (no dot separating major and minor versions) ACTIVE_PY_VERSION=${ACTIVE_PY_VERSION:0:1}${ACTIVE_PY_VERSION:2:1} if [ $ACTIVE_PY_VERSION != $PYTHON_VERSION ]; then exit 1 fi BUILD_FLAGS="$BUILD_FLAGS -DBUILD_ZFPY=ON" fi BUILD_FLAGS="$BUILD_FLAGS -DBUILD_OPENMP=OFF" BUILD_FLAGS="$BUILD_FLAGS -DBUILD_CUDA=OFF" run_all "$BUILD_FLAGS" # build empty project requiring OpenMP, in a temp directory that ZFP is oblivious to mkdir tmpBuild cd tmpBuild # (CMAKE_SH satisfies mingw builds) set +e if [ $COMPILER != "msvc" ]; then cmake -G "$GENERATOR" "$APPVEYOR_BUILD_FOLDER/tests/ci-utils" -DCMAKE_SH=CMAKE_SH-NOTFOUND else cmake -G "$GENERATOR" "$APPVEYOR_BUILD_FOLDER/tests/ci-utils" fi if [ $? -eq 0 ]; then echo "OpenMP found, starting 2nd zfp build" set -e cd .. # keep compiled testing frameworks, to speedup Appveyor rm CMakeCache.txt # only run tests not run in previous build, due to appveyor time limit (1 hour) # but continue to build utilities & examples because some support OpenMP BUILD_FLAGS="" BUILD_FLAGS="$BUILD_FLAGS -DBUILD_UTILITIES=ON" BUILD_FLAGS="$BUILD_FLAGS -DBUILD_EXAMPLES=ON" BUILD_FLAGS="$BUILD_FLAGS -DBUILD_OPENMP=ON" BUILD_FLAGS="$BUILD_FLAGS -DOMP_TESTS_ONLY=ON" run_all "$BUILD_FLAGS" else echo "OpenMP not found, build completed." fi zfp-1.0.1/appveyor.yml000066400000000000000000000046441453723256400147230ustar00rootroot00000000000000version: 1.0.1-{build} environment: # zfpy only build for Release builds (otherwise need debug python libs python27_d.lib) matrix: - COMPILER: msvc GENERATOR: Visual Studio 15 2017 Win64 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 PLATFORM: x64 BUILD_TYPE: Release PYTHON_VERSION: 38 - COMPILER: msvc GENERATOR: Visual Studio 15 2017 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 PLATFORM: Win32 BUILD_TYPE: Release PYTHON_VERSION: 38 - COMPILER: msvc GENERATOR: Visual Studio 14 2015 Win64 PLATFORM: x64 BUILD_TYPE: Release PYTHON_VERSION: 38 - COMPILER: msvc GENERATOR: Visual Studio 14 2015 PLATFORM: Win32 BUILD_TYPE: Release PYTHON_VERSION: 38 - COMPILER: mingw GENERATOR: MinGW Makefiles PLATFORM: Win32 BUILD_TYPE: Release - COMPILER: mingw-w64 GENERATOR: MinGW Makefiles PLATFORM: x64 BUILD_TYPE: Release install: - if "%COMPILER%"=="mingw" set PATH=C:\MinGW\bin;%PATH% - if "%COMPILER%"=="mingw-w64" set PATH=C:\MinGW\bin;%PATH% # set env vars for Python system dir (assumed to always be MSVC) - ps: | if ($env:PYTHON_VERSION) { $env:PYTHON_DIR = "C:\Python$env:PYTHON_VERSION" if ($env:PLATFORM -eq "x64") { $env:PYTHON_DIR = "$env:PYTHON_DIR-x64" } $env:PYTHON_LIB_PATH = "$env:PYTHON_DIR\libs\python$env:PYTHON_VERSION.lib" } # placing these behind a conditional for some reason prevents CMake from picking up the virtualenv - if "%COMPILER%"=="msvc" if "%BUILD_TYPE%"=="Release" set PATH=%PYTHON_DIR%;%PYTHON_DIR%\Scripts;%PATH% - if "%COMPILER%"=="msvc" if "%BUILD_TYPE%"=="Release" pip install virtualenv - if "%COMPILER%"=="msvc" if "%BUILD_TYPE%"=="Release" set VIRTUALENV_NAME=pyVirtualEnv - if "%COMPILER%"=="msvc" if "%BUILD_TYPE%"=="Release" virtualenv %VIRTUALENV_NAME% - if "%COMPILER%"=="msvc" if "%BUILD_TYPE%"=="Release" "%VIRTUALENV_NAME%\\Scripts\\activate.bat" - if "%COMPILER%"=="msvc" if "%BUILD_TYPE%"=="Release" pip install -r python\requirements.txt - if "%COMPILER%"=="msvc" if "%BUILD_TYPE%"=="Release" python --version build_script: - sh appveyor.sh # uncomment to enable interactive remote desktop mode #- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) zfp-1.0.1/cfp/000077500000000000000000000000001453723256400130735ustar00rootroot00000000000000zfp-1.0.1/cfp/CMakeLists.txt000066400000000000000000000020551453723256400156350ustar00rootroot00000000000000add_library(cfp cfp.cpp) if(DEFINED CFP_NAMESPACE) list(APPEND cfp_public_defs "CFP_NAMESPACE=${CFP_NAMESPACE}") endif() list(APPEND cfp_private_defs ${zfp_compressed_array_defs}) if(WIN32 AND BUILD_SHARED_LIBS) # define ZFP_SOURCE when compiling libcfp to export symbols to Windows DLL list(APPEND cfp_public_defs ZFP_SHARED_LIBS) list(APPEND cfp_private_defs ZFP_SOURCE) endif() target_compile_definitions(cfp PUBLIC ${cfp_public_defs} PRIVATE ${cfp_private_defs}) target_include_directories(cfp PUBLIC $ $ PRIVATE ${ZFP_SOURCE_DIR}/src ) target_link_libraries(cfp zfp) set_property(TARGET cfp PROPERTY VERSION ${ZFP_VERSION}) set_property(TARGET cfp PROPERTY SOVERSION ${ZFP_VERSION_MAJOR}) set_property(TARGET cfp PROPERTY OUTPUT_NAME ${ZFP_LIBRARY_PREFIX}cfp) install(TARGETS cfp EXPORT cfp-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) zfp-1.0.1/cfp/Makefile000066400000000000000000000006721453723256400145400ustar00rootroot00000000000000include ../Config LIBDIR = ../lib TARGETS = $(LIBDIR)/libcfp.a $(LIBDIR)/libcfp.so OBJECTS = cfp.o INCS = -I../include -I../src static: $(LIBDIR)/libcfp.a shared: $(LIBDIR)/libcfp.so clean: rm -f $(TARGETS) $(OBJECTS) $(LIBDIR)/libcfp.a: $(OBJECTS) mkdir -p $(LIBDIR) rm -f $@ ar rc $@ $^ $(LIBDIR)/libcfp.so: $(OBJECTS) mkdir -p $(LIBDIR) $(CXX) $(CXXFLAGS) -shared $(SOFLAGS) $^ -o $@ .cpp.o: $(CXX) $(CXXFLAGS) $(INCS) -c $< zfp-1.0.1/cfp/cfp.cpp000066400000000000000000000520651453723256400143570ustar00rootroot00000000000000#include "cfpheader.cpp" #include "zfp/array.h" #include "cfparray1f.cpp" #include "cfparray1d.cpp" #include "cfparray2f.cpp" #include "cfparray2d.cpp" #include "cfparray3f.cpp" #include "cfparray3d.cpp" #include "cfparray4f.cpp" #include "cfparray4d.cpp" const cfp_api CFP_NAMESPACE = { // array1f { cfp_array1f_ctor_default, cfp_array1f_ctor, cfp_array1f_ctor_copy, cfp_array1f_ctor_header, cfp_array1f_dtor, cfp_array1f_deep_copy, cfp_array1f_rate, cfp_array1f_set_rate, cfp_array1f_cache_size, cfp_array1f_set_cache_size, cfp_array1f_clear_cache, cfp_array1f_flush_cache, cfp_array1f_size_bytes, cfp_array1f_compressed_size, cfp_array1f_compressed_data, cfp_array1f_size, cfp_array1f_resize, cfp_array1f_get_array, cfp_array1f_set_array, cfp_array1f_get_flat, cfp_array1f_set_flat, cfp_array1f_get, cfp_array1f_set, cfp_array1f_ref, cfp_array1f_ref_flat, cfp_array1f_ptr, cfp_array1f_ptr_flat, cfp_array1f_begin, cfp_array1f_end, { cfp_array1f_cfp_ref1f_get, cfp_array1f_cfp_ref1f_set, cfp_array1f_cfp_ref1f_ptr, cfp_array1f_cfp_ref1f_copy, }, { cfp_array1f_cfp_ptr1f_get, cfp_array1f_cfp_ptr1f_get_at, cfp_array1f_cfp_ptr1f_set, cfp_array1f_cfp_ptr1f_set_at, cfp_array1f_cfp_ptr1f_ref, cfp_array1f_cfp_ptr1f_ref_at, cfp_array1f_cfp_ptr1f_lt, cfp_array1f_cfp_ptr1f_gt, cfp_array1f_cfp_ptr1f_leq, cfp_array1f_cfp_ptr1f_geq, cfp_array1f_cfp_ptr1f_eq, cfp_array1f_cfp_ptr1f_neq, cfp_array1f_cfp_ptr1f_distance, cfp_array1f_cfp_ptr1f_next, cfp_array1f_cfp_ptr1f_prev, cfp_array1f_cfp_ptr1f_inc, cfp_array1f_cfp_ptr1f_dec, }, { cfp_array1f_cfp_iter1f_get, cfp_array1f_cfp_iter1f_get_at, cfp_array1f_cfp_iter1f_set, cfp_array1f_cfp_iter1f_set_at, cfp_array1f_cfp_iter1f_ref, cfp_array1f_cfp_iter1f_ref_at, cfp_array1f_cfp_iter1f_ptr, cfp_array1f_cfp_iter1f_ptr_at, cfp_array1f_cfp_iter1f_i, cfp_array1f_cfp_iter1f_lt, cfp_array1f_cfp_iter1f_gt, cfp_array1f_cfp_iter1f_leq, cfp_array1f_cfp_iter1f_geq, cfp_array1f_cfp_iter1f_eq, cfp_array1f_cfp_iter1f_neq, cfp_array1f_cfp_iter1f_distance, cfp_array1f_cfp_iter1f_next, cfp_array1f_cfp_iter1f_prev, cfp_array1f_cfp_iter1f_inc, cfp_array1f_cfp_iter1f_dec, }, { cfp_header_ctor_array1f, cfp_header_ctor_buffer, cfp_header_dtor, cfp_header_scalar_type, cfp_header_dimensionality, cfp_header_size_x, cfp_header_size_y, cfp_header_size_z, cfp_header_size_w, cfp_header_rate, cfp_header_data, cfp_header_size_bytes, }, }, // array1d { cfp_array1d_ctor_default, cfp_array1d_ctor, cfp_array1d_ctor_copy, cfp_array1d_ctor_header, cfp_array1d_dtor, cfp_array1d_deep_copy, cfp_array1d_rate, cfp_array1d_set_rate, cfp_array1d_cache_size, cfp_array1d_set_cache_size, cfp_array1d_clear_cache, cfp_array1d_flush_cache, cfp_array1d_size_bytes, cfp_array1d_compressed_size, cfp_array1d_compressed_data, cfp_array1d_size, cfp_array1d_resize, cfp_array1d_get_array, cfp_array1d_set_array, cfp_array1d_get_flat, cfp_array1d_set_flat, cfp_array1d_get, cfp_array1d_set, cfp_array1d_ref, cfp_array1d_ref_flat, cfp_array1d_ptr, cfp_array1d_ptr_flat, cfp_array1d_begin, cfp_array1d_end, { cfp_array1d_cfp_ref1d_get, cfp_array1d_cfp_ref1d_set, cfp_array1d_cfp_ref1d_ptr, cfp_array1d_cfp_ref1d_copy, }, { cfp_array1d_cfp_ptr1d_get, cfp_array1d_cfp_ptr1d_get_at, cfp_array1d_cfp_ptr1d_set, cfp_array1d_cfp_ptr1d_set_at, cfp_array1d_cfp_ptr1d_ref, cfp_array1d_cfp_ptr1d_ref_at, cfp_array1d_cfp_ptr1d_lt, cfp_array1d_cfp_ptr1d_gt, cfp_array1d_cfp_ptr1d_leq, cfp_array1d_cfp_ptr1d_geq, cfp_array1d_cfp_ptr1d_eq, cfp_array1d_cfp_ptr1d_neq, cfp_array1d_cfp_ptr1d_distance, cfp_array1d_cfp_ptr1d_next, cfp_array1d_cfp_ptr1d_prev, cfp_array1d_cfp_ptr1d_inc, cfp_array1d_cfp_ptr1d_dec, }, { cfp_array1d_cfp_iter1d_get, cfp_array1d_cfp_iter1d_get_at, cfp_array1d_cfp_iter1d_set, cfp_array1d_cfp_iter1d_set_at, cfp_array1d_cfp_iter1d_ref, cfp_array1d_cfp_iter1d_ref_at, cfp_array1d_cfp_iter1d_ptr, cfp_array1d_cfp_iter1d_ptr_at, cfp_array1d_cfp_iter1d_i, cfp_array1d_cfp_iter1d_lt, cfp_array1d_cfp_iter1d_gt, cfp_array1d_cfp_iter1d_leq, cfp_array1d_cfp_iter1d_geq, cfp_array1d_cfp_iter1d_eq, cfp_array1d_cfp_iter1d_neq, cfp_array1d_cfp_iter1d_distance, cfp_array1d_cfp_iter1d_next, cfp_array1d_cfp_iter1d_prev, cfp_array1d_cfp_iter1d_inc, cfp_array1d_cfp_iter1d_dec, }, { cfp_header_ctor_array1d, cfp_header_ctor_buffer, cfp_header_dtor, cfp_header_scalar_type, cfp_header_dimensionality, cfp_header_size_x, cfp_header_size_y, cfp_header_size_z, cfp_header_size_w, cfp_header_rate, cfp_header_data, cfp_header_size_bytes, }, }, // array2f { cfp_array2f_ctor_default, cfp_array2f_ctor, cfp_array2f_ctor_copy, cfp_array2f_ctor_header, cfp_array2f_dtor, cfp_array2f_deep_copy, cfp_array2f_rate, cfp_array2f_set_rate, cfp_array2f_cache_size, cfp_array2f_set_cache_size, cfp_array2f_clear_cache, cfp_array2f_flush_cache, cfp_array2f_size_bytes, cfp_array2f_compressed_size, cfp_array2f_compressed_data, cfp_array2f_size, cfp_array2f_size_x, cfp_array2f_size_y, cfp_array2f_resize, cfp_array2f_get_array, cfp_array2f_set_array, cfp_array2f_get_flat, cfp_array2f_set_flat, cfp_array2f_get, cfp_array2f_set, cfp_array2f_ref, cfp_array2f_ref_flat, cfp_array2f_ptr, cfp_array2f_ptr_flat, cfp_array2f_begin, cfp_array2f_end, { cfp_array2f_cfp_ref2f_get, cfp_array2f_cfp_ref2f_set, cfp_array2f_cfp_ref2f_ptr, cfp_array2f_cfp_ref2f_copy, }, { cfp_array2f_cfp_ptr2f_get, cfp_array2f_cfp_ptr2f_get_at, cfp_array2f_cfp_ptr2f_set, cfp_array2f_cfp_ptr2f_set_at, cfp_array2f_cfp_ptr2f_ref, cfp_array2f_cfp_ptr2f_ref_at, cfp_array2f_cfp_ptr2f_lt, cfp_array2f_cfp_ptr2f_gt, cfp_array2f_cfp_ptr2f_leq, cfp_array2f_cfp_ptr2f_geq, cfp_array2f_cfp_ptr2f_eq, cfp_array2f_cfp_ptr2f_neq, cfp_array2f_cfp_ptr2f_distance, cfp_array2f_cfp_ptr2f_next, cfp_array2f_cfp_ptr2f_prev, cfp_array2f_cfp_ptr2f_inc, cfp_array2f_cfp_ptr2f_dec, }, { cfp_array2f_cfp_iter2f_get, cfp_array2f_cfp_iter2f_get_at, cfp_array2f_cfp_iter2f_set, cfp_array2f_cfp_iter2f_set_at, cfp_array2f_cfp_iter2f_ref, cfp_array2f_cfp_iter2f_ref_at, cfp_array2f_cfp_iter2f_ptr, cfp_array2f_cfp_iter2f_ptr_at, cfp_array2f_cfp_iter2f_i, cfp_array2f_cfp_iter2f_j, cfp_array2f_cfp_iter2f_lt, cfp_array2f_cfp_iter2f_gt, cfp_array2f_cfp_iter2f_leq, cfp_array2f_cfp_iter2f_geq, cfp_array2f_cfp_iter2f_eq, cfp_array2f_cfp_iter2f_neq, cfp_array2f_cfp_iter2f_distance, cfp_array2f_cfp_iter2f_next, cfp_array2f_cfp_iter2f_prev, cfp_array2f_cfp_iter2f_inc, cfp_array2f_cfp_iter2f_dec, }, { cfp_header_ctor_array2f, cfp_header_ctor_buffer, cfp_header_dtor, cfp_header_scalar_type, cfp_header_dimensionality, cfp_header_size_x, cfp_header_size_y, cfp_header_size_z, cfp_header_size_w, cfp_header_rate, cfp_header_data, cfp_header_size_bytes, }, }, // array2d { cfp_array2d_ctor_default, cfp_array2d_ctor, cfp_array2d_ctor_copy, cfp_array2d_ctor_header, cfp_array2d_dtor, cfp_array2d_deep_copy, cfp_array2d_rate, cfp_array2d_set_rate, cfp_array2d_cache_size, cfp_array2d_set_cache_size, cfp_array2d_clear_cache, cfp_array2d_flush_cache, cfp_array2d_size_bytes, cfp_array2d_compressed_size, cfp_array2d_compressed_data, cfp_array2d_size, cfp_array2d_size_x, cfp_array2d_size_y, cfp_array2d_resize, cfp_array2d_get_array, cfp_array2d_set_array, cfp_array2d_get_flat, cfp_array2d_set_flat, cfp_array2d_get, cfp_array2d_set, cfp_array2d_ref, cfp_array2d_ref_flat, cfp_array2d_ptr, cfp_array2d_ptr_flat, cfp_array2d_begin, cfp_array2d_end, { cfp_array2d_cfp_ref2d_get, cfp_array2d_cfp_ref2d_set, cfp_array2d_cfp_ref2d_ptr, cfp_array2d_cfp_ref2d_copy, }, { cfp_array2d_cfp_ptr2d_get, cfp_array2d_cfp_ptr2d_get_at, cfp_array2d_cfp_ptr2d_set, cfp_array2d_cfp_ptr2d_set_at, cfp_array2d_cfp_ptr2d_ref, cfp_array2d_cfp_ptr2d_ref_at, cfp_array2d_cfp_ptr2d_lt, cfp_array2d_cfp_ptr2d_gt, cfp_array2d_cfp_ptr2d_leq, cfp_array2d_cfp_ptr2d_geq, cfp_array2d_cfp_ptr2d_eq, cfp_array2d_cfp_ptr2d_neq, cfp_array2d_cfp_ptr2d_distance, cfp_array2d_cfp_ptr2d_next, cfp_array2d_cfp_ptr2d_prev, cfp_array2d_cfp_ptr2d_inc, cfp_array2d_cfp_ptr2d_dec, }, { cfp_array2d_cfp_iter2d_get, cfp_array2d_cfp_iter2d_get_at, cfp_array2d_cfp_iter2d_set, cfp_array2d_cfp_iter2d_set_at, cfp_array2d_cfp_iter2d_ref, cfp_array2d_cfp_iter2d_ref_at, cfp_array2d_cfp_iter2d_ptr, cfp_array2d_cfp_iter2d_ptr_at, cfp_array2d_cfp_iter2d_i, cfp_array2d_cfp_iter2d_j, cfp_array2d_cfp_iter2d_lt, cfp_array2d_cfp_iter2d_gt, cfp_array2d_cfp_iter2d_leq, cfp_array2d_cfp_iter2d_geq, cfp_array2d_cfp_iter2d_eq, cfp_array2d_cfp_iter2d_neq, cfp_array2d_cfp_iter2d_distance, cfp_array2d_cfp_iter2d_next, cfp_array2d_cfp_iter2d_prev, cfp_array2d_cfp_iter2d_inc, cfp_array2d_cfp_iter2d_dec, }, { cfp_header_ctor_array2d, cfp_header_ctor_buffer, cfp_header_dtor, cfp_header_scalar_type, cfp_header_dimensionality, cfp_header_size_x, cfp_header_size_y, cfp_header_size_z, cfp_header_size_w, cfp_header_rate, cfp_header_data, cfp_header_size_bytes, }, }, // array3f { cfp_array3f_ctor_default, cfp_array3f_ctor, cfp_array3f_ctor_copy, cfp_array3f_ctor_header, cfp_array3f_dtor, cfp_array3f_deep_copy, cfp_array3f_rate, cfp_array3f_set_rate, cfp_array3f_cache_size, cfp_array3f_set_cache_size, cfp_array3f_clear_cache, cfp_array3f_flush_cache, cfp_array3f_size_bytes, cfp_array3f_compressed_size, cfp_array3f_compressed_data, cfp_array3f_size, cfp_array3f_size_x, cfp_array3f_size_y, cfp_array3f_size_z, cfp_array3f_resize, cfp_array3f_get_array, cfp_array3f_set_array, cfp_array3f_get_flat, cfp_array3f_set_flat, cfp_array3f_get, cfp_array3f_set, cfp_array3f_ref, cfp_array3f_ref_flat, cfp_array3f_ptr, cfp_array3f_ptr_flat, cfp_array3f_begin, cfp_array3f_end, { cfp_array3f_cfp_ref3f_get, cfp_array3f_cfp_ref3f_set, cfp_array3f_cfp_ref3f_ptr, cfp_array3f_cfp_ref3f_copy, }, { cfp_array3f_cfp_ptr3f_get, cfp_array3f_cfp_ptr3f_get_at, cfp_array3f_cfp_ptr3f_set, cfp_array3f_cfp_ptr3f_set_at, cfp_array3f_cfp_ptr3f_ref, cfp_array3f_cfp_ptr3f_ref_at, cfp_array3f_cfp_ptr3f_lt, cfp_array3f_cfp_ptr3f_gt, cfp_array3f_cfp_ptr3f_leq, cfp_array3f_cfp_ptr3f_geq, cfp_array3f_cfp_ptr3f_eq, cfp_array3f_cfp_ptr3f_neq, cfp_array3f_cfp_ptr3f_distance, cfp_array3f_cfp_ptr3f_next, cfp_array3f_cfp_ptr3f_prev, cfp_array3f_cfp_ptr3f_inc, cfp_array3f_cfp_ptr3f_dec, }, { cfp_array3f_cfp_iter3f_get, cfp_array3f_cfp_iter3f_get_at, cfp_array3f_cfp_iter3f_set, cfp_array3f_cfp_iter3f_set_at, cfp_array3f_cfp_iter3f_ref, cfp_array3f_cfp_iter3f_ref_at, cfp_array3f_cfp_iter3f_ptr, cfp_array3f_cfp_iter3f_ptr_at, cfp_array3f_cfp_iter3f_i, cfp_array3f_cfp_iter3f_j, cfp_array3f_cfp_iter3f_k, cfp_array3f_cfp_iter3f_lt, cfp_array3f_cfp_iter3f_gt, cfp_array3f_cfp_iter3f_leq, cfp_array3f_cfp_iter3f_geq, cfp_array3f_cfp_iter3f_eq, cfp_array3f_cfp_iter3f_neq, cfp_array3f_cfp_iter3f_distance, cfp_array3f_cfp_iter3f_next, cfp_array3f_cfp_iter3f_prev, cfp_array3f_cfp_iter3f_inc, cfp_array3f_cfp_iter3f_dec, }, { cfp_header_ctor_array3f, cfp_header_ctor_buffer, cfp_header_dtor, cfp_header_scalar_type, cfp_header_dimensionality, cfp_header_size_x, cfp_header_size_y, cfp_header_size_z, cfp_header_size_w, cfp_header_rate, cfp_header_data, cfp_header_size_bytes, }, }, // array3d { cfp_array3d_ctor_default, cfp_array3d_ctor, cfp_array3d_ctor_copy, cfp_array3d_ctor_header, cfp_array3d_dtor, cfp_array3d_deep_copy, cfp_array3d_rate, cfp_array3d_set_rate, cfp_array3d_cache_size, cfp_array3d_set_cache_size, cfp_array3d_clear_cache, cfp_array3d_flush_cache, cfp_array3d_size_bytes, cfp_array3d_compressed_size, cfp_array3d_compressed_data, cfp_array3d_size, cfp_array3d_size_x, cfp_array3d_size_y, cfp_array3d_size_z, cfp_array3d_resize, cfp_array3d_get_array, cfp_array3d_set_array, cfp_array3d_get_flat, cfp_array3d_set_flat, cfp_array3d_get, cfp_array3d_set, cfp_array3d_ref, cfp_array3d_ref_flat, cfp_array3d_ptr, cfp_array3d_ptr_flat, cfp_array3d_begin, cfp_array3d_end, { cfp_array3d_cfp_ref3d_get, cfp_array3d_cfp_ref3d_set, cfp_array3d_cfp_ref3d_ptr, cfp_array3d_cfp_ref3d_copy, }, { cfp_array3d_cfp_ptr3d_get, cfp_array3d_cfp_ptr3d_get_at, cfp_array3d_cfp_ptr3d_set, cfp_array3d_cfp_ptr3d_set_at, cfp_array3d_cfp_ptr3d_ref, cfp_array3d_cfp_ptr3d_ref_at, cfp_array3d_cfp_ptr3d_lt, cfp_array3d_cfp_ptr3d_gt, cfp_array3d_cfp_ptr3d_leq, cfp_array3d_cfp_ptr3d_geq, cfp_array3d_cfp_ptr3d_eq, cfp_array3d_cfp_ptr3d_neq, cfp_array3d_cfp_ptr3d_distance, cfp_array3d_cfp_ptr3d_next, cfp_array3d_cfp_ptr3d_prev, cfp_array3d_cfp_ptr3d_inc, cfp_array3d_cfp_ptr3d_dec, }, { cfp_array3d_cfp_iter3d_get, cfp_array3d_cfp_iter3d_get_at, cfp_array3d_cfp_iter3d_set, cfp_array3d_cfp_iter3d_set_at, cfp_array3d_cfp_iter3d_ref, cfp_array3d_cfp_iter3d_ref_at, cfp_array3d_cfp_iter3d_ptr, cfp_array3d_cfp_iter3d_ptr_at, cfp_array3d_cfp_iter3d_i, cfp_array3d_cfp_iter3d_j, cfp_array3d_cfp_iter3d_k, cfp_array3d_cfp_iter3d_lt, cfp_array3d_cfp_iter3d_gt, cfp_array3d_cfp_iter3d_leq, cfp_array3d_cfp_iter3d_geq, cfp_array3d_cfp_iter3d_eq, cfp_array3d_cfp_iter3d_neq, cfp_array3d_cfp_iter3d_distance, cfp_array3d_cfp_iter3d_next, cfp_array3d_cfp_iter3d_prev, cfp_array3d_cfp_iter3d_inc, cfp_array3d_cfp_iter3d_dec, }, { cfp_header_ctor_array3d, cfp_header_ctor_buffer, cfp_header_dtor, cfp_header_scalar_type, cfp_header_dimensionality, cfp_header_size_x, cfp_header_size_y, cfp_header_size_z, cfp_header_size_w, cfp_header_rate, cfp_header_data, cfp_header_size_bytes, }, }, // array4f { cfp_array4f_ctor_default, cfp_array4f_ctor, cfp_array4f_ctor_copy, cfp_array4f_ctor_header, cfp_array4f_dtor, cfp_array4f_deep_copy, cfp_array4f_rate, cfp_array4f_set_rate, cfp_array4f_cache_size, cfp_array4f_set_cache_size, cfp_array4f_clear_cache, cfp_array4f_flush_cache, cfp_array4f_size_bytes, cfp_array4f_compressed_size, cfp_array4f_compressed_data, cfp_array4f_size, cfp_array4f_size_x, cfp_array4f_size_y, cfp_array4f_size_z, cfp_array4f_size_w, cfp_array4f_resize, cfp_array4f_get_array, cfp_array4f_set_array, cfp_array4f_get_flat, cfp_array4f_set_flat, cfp_array4f_get, cfp_array4f_set, cfp_array4f_ref, cfp_array4f_ref_flat, cfp_array4f_ptr, cfp_array4f_ptr_flat, cfp_array4f_begin, cfp_array4f_end, { cfp_array4f_cfp_ref4f_get, cfp_array4f_cfp_ref4f_set, cfp_array4f_cfp_ref4f_ptr, cfp_array4f_cfp_ref4f_copy, }, { cfp_array4f_cfp_ptr4f_get, cfp_array4f_cfp_ptr4f_get_at, cfp_array4f_cfp_ptr4f_set, cfp_array4f_cfp_ptr4f_set_at, cfp_array4f_cfp_ptr4f_ref, cfp_array4f_cfp_ptr4f_ref_at, cfp_array4f_cfp_ptr4f_lt, cfp_array4f_cfp_ptr4f_gt, cfp_array4f_cfp_ptr4f_leq, cfp_array4f_cfp_ptr4f_geq, cfp_array4f_cfp_ptr4f_eq, cfp_array4f_cfp_ptr4f_neq, cfp_array4f_cfp_ptr4f_distance, cfp_array4f_cfp_ptr4f_next, cfp_array4f_cfp_ptr4f_prev, cfp_array4f_cfp_ptr4f_inc, cfp_array4f_cfp_ptr4f_dec, }, { cfp_array4f_cfp_iter4f_get, cfp_array4f_cfp_iter4f_get_at, cfp_array4f_cfp_iter4f_set, cfp_array4f_cfp_iter4f_set_at, cfp_array4f_cfp_iter4f_ref, cfp_array4f_cfp_iter4f_ref_at, cfp_array4f_cfp_iter4f_ptr, cfp_array4f_cfp_iter4f_ptr_at, cfp_array4f_cfp_iter4f_i, cfp_array4f_cfp_iter4f_j, cfp_array4f_cfp_iter4f_k, cfp_array4f_cfp_iter4f_l, cfp_array4f_cfp_iter4f_lt, cfp_array4f_cfp_iter4f_gt, cfp_array4f_cfp_iter4f_leq, cfp_array4f_cfp_iter4f_geq, cfp_array4f_cfp_iter4f_eq, cfp_array4f_cfp_iter4f_neq, cfp_array4f_cfp_iter4f_distance, cfp_array4f_cfp_iter4f_next, cfp_array4f_cfp_iter4f_prev, cfp_array4f_cfp_iter4f_inc, cfp_array4f_cfp_iter4f_dec, }, { cfp_header_ctor_array4f, cfp_header_ctor_buffer, cfp_header_dtor, cfp_header_scalar_type, cfp_header_dimensionality, cfp_header_size_x, cfp_header_size_y, cfp_header_size_z, cfp_header_size_w, cfp_header_rate, cfp_header_data, cfp_header_size_bytes, }, }, // array4d { cfp_array4d_ctor_default, cfp_array4d_ctor, cfp_array4d_ctor_copy, cfp_array4d_ctor_header, cfp_array4d_dtor, cfp_array4d_deep_copy, cfp_array4d_rate, cfp_array4d_set_rate, cfp_array4d_cache_size, cfp_array4d_set_cache_size, cfp_array4d_clear_cache, cfp_array4d_flush_cache, cfp_array4d_size_bytes, cfp_array4d_compressed_size, cfp_array4d_compressed_data, cfp_array4d_size, cfp_array4d_size_x, cfp_array4d_size_y, cfp_array4d_size_z, cfp_array4d_size_w, cfp_array4d_resize, cfp_array4d_get_array, cfp_array4d_set_array, cfp_array4d_get_flat, cfp_array4d_set_flat, cfp_array4d_get, cfp_array4d_set, cfp_array4d_ref, cfp_array4d_ref_flat, cfp_array4d_ptr, cfp_array4d_ptr_flat, cfp_array4d_begin, cfp_array4d_end, { cfp_array4d_cfp_ref4d_get, cfp_array4d_cfp_ref4d_set, cfp_array4d_cfp_ref4d_ptr, cfp_array4d_cfp_ref4d_copy, }, { cfp_array4d_cfp_ptr4d_get, cfp_array4d_cfp_ptr4d_get_at, cfp_array4d_cfp_ptr4d_set, cfp_array4d_cfp_ptr4d_set_at, cfp_array4d_cfp_ptr4d_ref, cfp_array4d_cfp_ptr4d_ref_at, cfp_array4d_cfp_ptr4d_lt, cfp_array4d_cfp_ptr4d_gt, cfp_array4d_cfp_ptr4d_leq, cfp_array4d_cfp_ptr4d_geq, cfp_array4d_cfp_ptr4d_eq, cfp_array4d_cfp_ptr4d_neq, cfp_array4d_cfp_ptr4d_distance, cfp_array4d_cfp_ptr4d_next, cfp_array4d_cfp_ptr4d_prev, cfp_array4d_cfp_ptr4d_inc, cfp_array4d_cfp_ptr4d_dec, }, { cfp_array4d_cfp_iter4d_get, cfp_array4d_cfp_iter4d_get_at, cfp_array4d_cfp_iter4d_set, cfp_array4d_cfp_iter4d_set_at, cfp_array4d_cfp_iter4d_ref, cfp_array4d_cfp_iter4d_ref_at, cfp_array4d_cfp_iter4d_ptr, cfp_array4d_cfp_iter4d_ptr_at, cfp_array4d_cfp_iter4d_i, cfp_array4d_cfp_iter4d_j, cfp_array4d_cfp_iter4d_k, cfp_array4d_cfp_iter4d_l, cfp_array4d_cfp_iter4d_lt, cfp_array4d_cfp_iter4d_gt, cfp_array4d_cfp_iter4d_leq, cfp_array4d_cfp_iter4d_geq, cfp_array4d_cfp_iter4d_eq, cfp_array4d_cfp_iter4d_neq, cfp_array4d_cfp_iter4d_distance, cfp_array4d_cfp_iter4d_next, cfp_array4d_cfp_iter4d_prev, cfp_array4d_cfp_iter4d_inc, cfp_array4d_cfp_iter4d_dec, }, { cfp_header_ctor_array4d, cfp_header_ctor_buffer, cfp_header_dtor, cfp_header_scalar_type, cfp_header_dimensionality, cfp_header_size_x, cfp_header_size_y, cfp_header_size_z, cfp_header_size_w, cfp_header_rate, cfp_header_data, cfp_header_size_bytes, }, }, }; zfp-1.0.1/cfp/cfparray1d.cpp000066400000000000000000000007531453723256400156400ustar00rootroot00000000000000#include "zfp/internal/cfp/array1d.h" #include "zfp/array1.hpp" #include "template/template.h" #define CFP_ARRAY_TYPE cfp_array1d #define CFP_REF_TYPE cfp_ref1d #define CFP_PTR_TYPE cfp_ptr1d #define CFP_ITER_TYPE cfp_iter1d #define ZFP_ARRAY_TYPE zfp::array1d #define ZFP_SCALAR_TYPE double #include "template/cfparray.cpp" #include "template/cfparray1.cpp" #undef CFP_ARRAY_TYPE #undef CFP_REF_TYPE #undef CFP_PTR_TYPE #undef CFP_ITER_TYPE #undef ZFP_ARRAY_TYPE #undef ZFP_SCALAR_TYPE zfp-1.0.1/cfp/cfparray1f.cpp000066400000000000000000000007521453723256400156410ustar00rootroot00000000000000#include "zfp/internal/cfp/array1f.h" #include "zfp/array1.hpp" #include "template/template.h" #define CFP_ARRAY_TYPE cfp_array1f #define CFP_REF_TYPE cfp_ref1f #define CFP_PTR_TYPE cfp_ptr1f #define CFP_ITER_TYPE cfp_iter1f #define ZFP_ARRAY_TYPE zfp::array1f #define ZFP_SCALAR_TYPE float #include "template/cfparray.cpp" #include "template/cfparray1.cpp" #undef CFP_ARRAY_TYPE #undef CFP_REF_TYPE #undef CFP_PTR_TYPE #undef CFP_ITER_TYPE #undef ZFP_ARRAY_TYPE #undef ZFP_SCALAR_TYPE zfp-1.0.1/cfp/cfparray2d.cpp000066400000000000000000000007531453723256400156410ustar00rootroot00000000000000#include "zfp/internal/cfp/array2d.h" #include "zfp/array2.hpp" #include "template/template.h" #define CFP_ARRAY_TYPE cfp_array2d #define CFP_REF_TYPE cfp_ref2d #define CFP_PTR_TYPE cfp_ptr2d #define CFP_ITER_TYPE cfp_iter2d #define ZFP_ARRAY_TYPE zfp::array2d #define ZFP_SCALAR_TYPE double #include "template/cfparray.cpp" #include "template/cfparray2.cpp" #undef CFP_ARRAY_TYPE #undef CFP_REF_TYPE #undef CFP_PTR_TYPE #undef CFP_ITER_TYPE #undef ZFP_ARRAY_TYPE #undef ZFP_SCALAR_TYPE zfp-1.0.1/cfp/cfparray2f.cpp000066400000000000000000000007521453723256400156420ustar00rootroot00000000000000#include "zfp/internal/cfp/array2f.h" #include "zfp/array2.hpp" #include "template/template.h" #define CFP_ARRAY_TYPE cfp_array2f #define CFP_REF_TYPE cfp_ref2f #define CFP_PTR_TYPE cfp_ptr2f #define CFP_ITER_TYPE cfp_iter2f #define ZFP_ARRAY_TYPE zfp::array2f #define ZFP_SCALAR_TYPE float #include "template/cfparray.cpp" #include "template/cfparray2.cpp" #undef CFP_ARRAY_TYPE #undef CFP_REF_TYPE #undef CFP_PTR_TYPE #undef CFP_ITER_TYPE #undef ZFP_ARRAY_TYPE #undef ZFP_SCALAR_TYPE zfp-1.0.1/cfp/cfparray3d.cpp000066400000000000000000000007531453723256400156420ustar00rootroot00000000000000#include "zfp/internal/cfp/array3d.h" #include "zfp/array3.hpp" #include "template/template.h" #define CFP_ARRAY_TYPE cfp_array3d #define CFP_REF_TYPE cfp_ref3d #define CFP_PTR_TYPE cfp_ptr3d #define CFP_ITER_TYPE cfp_iter3d #define ZFP_ARRAY_TYPE zfp::array3d #define ZFP_SCALAR_TYPE double #include "template/cfparray.cpp" #include "template/cfparray3.cpp" #undef CFP_ARRAY_TYPE #undef CFP_REF_TYPE #undef CFP_PTR_TYPE #undef CFP_ITER_TYPE #undef ZFP_ARRAY_TYPE #undef ZFP_SCALAR_TYPE zfp-1.0.1/cfp/cfparray3f.cpp000066400000000000000000000007521453723256400156430ustar00rootroot00000000000000#include "zfp/internal/cfp/array3f.h" #include "zfp/array3.hpp" #include "template/template.h" #define CFP_ARRAY_TYPE cfp_array3f #define CFP_REF_TYPE cfp_ref3f #define CFP_PTR_TYPE cfp_ptr3f #define CFP_ITER_TYPE cfp_iter3f #define ZFP_ARRAY_TYPE zfp::array3f #define ZFP_SCALAR_TYPE float #include "template/cfparray.cpp" #include "template/cfparray3.cpp" #undef CFP_ARRAY_TYPE #undef CFP_REF_TYPE #undef CFP_PTR_TYPE #undef CFP_ITER_TYPE #undef ZFP_ARRAY_TYPE #undef ZFP_SCALAR_TYPE zfp-1.0.1/cfp/cfparray4d.cpp000066400000000000000000000007531453723256400156430ustar00rootroot00000000000000#include "zfp/internal/cfp/array4d.h" #include "zfp/array4.hpp" #include "template/template.h" #define CFP_ARRAY_TYPE cfp_array4d #define CFP_REF_TYPE cfp_ref4d #define CFP_PTR_TYPE cfp_ptr4d #define CFP_ITER_TYPE cfp_iter4d #define ZFP_ARRAY_TYPE zfp::array4d #define ZFP_SCALAR_TYPE double #include "template/cfparray.cpp" #include "template/cfparray4.cpp" #undef CFP_ARRAY_TYPE #undef CFP_REF_TYPE #undef CFP_PTR_TYPE #undef CFP_ITER_TYPE #undef ZFP_ARRAY_TYPE #undef ZFP_SCALAR_TYPE zfp-1.0.1/cfp/cfparray4f.cpp000066400000000000000000000007521453723256400156440ustar00rootroot00000000000000#include "zfp/internal/cfp/array4f.h" #include "zfp/array4.hpp" #include "template/template.h" #define CFP_ARRAY_TYPE cfp_array4f #define CFP_REF_TYPE cfp_ref4f #define CFP_PTR_TYPE cfp_ptr4f #define CFP_ITER_TYPE cfp_iter4f #define ZFP_ARRAY_TYPE zfp::array4f #define ZFP_SCALAR_TYPE float #include "template/cfparray.cpp" #include "template/cfparray4.cpp" #undef CFP_ARRAY_TYPE #undef CFP_REF_TYPE #undef CFP_PTR_TYPE #undef CFP_ITER_TYPE #undef ZFP_ARRAY_TYPE #undef ZFP_SCALAR_TYPE zfp-1.0.1/cfp/cfpheader.cpp000066400000000000000000000011731453723256400155220ustar00rootroot00000000000000#include "zfp/array1.hpp" #include "zfp/array2.hpp" #include "zfp/array3.hpp" #include "zfp/array4.hpp" #include "zfp/internal/codec/zfpheader.hpp" #include "zfp/internal/cfp/header.h" #include "zfp/internal/cfp/array1f.h" #include "zfp/internal/cfp/array1d.h" #include "zfp/internal/cfp/array2f.h" #include "zfp/internal/cfp/array2d.h" #include "zfp/internal/cfp/array3f.h" #include "zfp/internal/cfp/array3d.h" #include "zfp/internal/cfp/array4f.h" #include "zfp/internal/cfp/array4d.h" #include "template/template.h" #define CFP_HEADER_TYPE cfp_header #define ZFP_HEADER_TYPE zfp::array::header #include "template/cfpheader.cpp" zfp-1.0.1/cfp/template/000077500000000000000000000000001453723256400147065ustar00rootroot00000000000000zfp-1.0.1/cfp/template/cfparray.cpp000066400000000000000000000064031453723256400172240ustar00rootroot00000000000000// common constructor, destructor static CFP_ARRAY_TYPE _t1(CFP_ARRAY_TYPE, ctor_default)() { CFP_ARRAY_TYPE a; a.object = new ZFP_ARRAY_TYPE(); return a; } static CFP_ARRAY_TYPE _t1(CFP_ARRAY_TYPE, ctor_copy)(CFP_ARRAY_TYPE src) { CFP_ARRAY_TYPE a; a.object = new ZFP_ARRAY_TYPE(*static_cast(src.object)); return a; } static CFP_ARRAY_TYPE _t1(CFP_ARRAY_TYPE, ctor_header)(CFP_HEADER_TYPE h, const void* buffer, size_t buffer_size_bytes) { CFP_ARRAY_TYPE a; a.object = new ZFP_ARRAY_TYPE(*static_cast(h.object), buffer, buffer_size_bytes); return a; } static void _t1(CFP_ARRAY_TYPE, dtor)(CFP_ARRAY_TYPE self) { delete static_cast(self.object); } // functions defined in zfparray.h (base class) static double _t1(CFP_ARRAY_TYPE, rate)(CFP_ARRAY_TYPE self) { return static_cast(self.object)->rate(); } static double _t1(CFP_ARRAY_TYPE, set_rate)(CFP_ARRAY_TYPE self, double rate) { return static_cast(self.object)->set_rate(rate); } static size_t _t1(CFP_ARRAY_TYPE, size_bytes)(CFP_ARRAY_TYPE self, uint mask) { return static_cast(self.object)->size_bytes(mask); } static size_t _t1(CFP_ARRAY_TYPE, compressed_size)(CFP_ARRAY_TYPE self) { return static_cast(self.object)->compressed_size(); } static void* _t1(CFP_ARRAY_TYPE, compressed_data)(CFP_ARRAY_TYPE self) { return static_cast(self.object)->compressed_data(); } static void _t1(CFP_ARRAY_TYPE, deep_copy)(CFP_ARRAY_TYPE self, const CFP_ARRAY_TYPE src) { *static_cast(self.object) = *static_cast(src.object); } // functions defined in subclasses static size_t _t1(CFP_ARRAY_TYPE, size)(CFP_ARRAY_TYPE self) { return static_cast(self.object)->size(); } static size_t _t1(CFP_ARRAY_TYPE, cache_size)(CFP_ARRAY_TYPE self) { return static_cast(self.object)->cache_size(); } static void _t1(CFP_ARRAY_TYPE, set_cache_size)(CFP_ARRAY_TYPE self, size_t bytes) { static_cast(self.object)->set_cache_size(bytes); } static void _t1(CFP_ARRAY_TYPE, clear_cache)(CFP_ARRAY_TYPE self) { static_cast(self.object)->clear_cache(); } static void _t1(CFP_ARRAY_TYPE, flush_cache)(CFP_ARRAY_TYPE self) { static_cast(self.object)->flush_cache(); } static void _t1(CFP_ARRAY_TYPE, get_array)(CFP_ARRAY_TYPE self, ZFP_SCALAR_TYPE * p) { static_cast(self.object)->get(p); } static void _t1(CFP_ARRAY_TYPE, set_array)(CFP_ARRAY_TYPE self, const ZFP_SCALAR_TYPE * p) { static_cast(self.object)->set(p); } static ZFP_SCALAR_TYPE _t1(CFP_ARRAY_TYPE, get_flat)(CFP_ARRAY_TYPE self, size_t i) { return static_cast(self.object)->operator[](i); } static void _t1(CFP_ARRAY_TYPE, set_flat)(CFP_ARRAY_TYPE self, size_t i, ZFP_SCALAR_TYPE val) { static_cast(self.object)->operator[](i) = val; } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_REF_TYPE, ptr)(CFP_REF_TYPE self) { CFP_PTR_TYPE p; p.reference = self; return p; } static CFP_REF_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, ref)(CFP_PTR_TYPE self) { return self.reference; } zfp-1.0.1/cfp/template/cfparray1.cpp000066400000000000000000000202631453723256400173050ustar00rootroot00000000000000static CFP_ARRAY_TYPE _t1(CFP_ARRAY_TYPE, ctor)(size_t n, double rate, const ZFP_SCALAR_TYPE* p, size_t cache_size) { CFP_ARRAY_TYPE a; a.object = new ZFP_ARRAY_TYPE(n, rate, p, cache_size); return a; } static void _t1(CFP_ARRAY_TYPE, resize)(CFP_ARRAY_TYPE self, size_t n, zfp_bool clear) { static_cast(self.object)->resize(n, !!clear); } static ZFP_SCALAR_TYPE _t1(CFP_ARRAY_TYPE, get)(CFP_ARRAY_TYPE self, size_t i) { return static_cast(self.object)->operator()(i); } static void _t1(CFP_ARRAY_TYPE, set)(CFP_ARRAY_TYPE self, size_t i, ZFP_SCALAR_TYPE val) { static_cast(self.object)->operator()(i) = val; } static CFP_REF_TYPE _t1(CFP_ARRAY_TYPE, ref)(CFP_ARRAY_TYPE self, size_t i) { CFP_REF_TYPE r; r.array = self; r.x = i; return r; } static CFP_REF_TYPE _t1(CFP_ARRAY_TYPE, ref_flat)(CFP_ARRAY_TYPE self, size_t i) { CFP_REF_TYPE r; r.array = self; r.x = i; return r; } static CFP_PTR_TYPE _t1(CFP_ARRAY_TYPE, ptr)(CFP_ARRAY_TYPE self, size_t i) { CFP_PTR_TYPE p; p.reference = _t1(CFP_ARRAY_TYPE, ref)(self, i); return p; } static CFP_PTR_TYPE _t1(CFP_ARRAY_TYPE, ptr_flat)(CFP_ARRAY_TYPE self, size_t i) { CFP_PTR_TYPE p; p.reference = _t1(CFP_ARRAY_TYPE, ref_flat)(self, i); return p; } static CFP_ITER_TYPE _t1(CFP_ARRAY_TYPE, begin)(CFP_ARRAY_TYPE self) { CFP_ITER_TYPE it; it.array = self; it.x = 0; return it; } static CFP_ITER_TYPE _t1(CFP_ARRAY_TYPE, end)(CFP_ARRAY_TYPE self) { CFP_ITER_TYPE it; it.array = self; it.x = static_cast(self.object)->size_x(); return it; } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_REF_TYPE, get)(CFP_REF_TYPE self) { return static_cast(self.array.object)->operator()(self.x); } static void _t2(CFP_ARRAY_TYPE, CFP_REF_TYPE, set)(CFP_REF_TYPE self, ZFP_SCALAR_TYPE val) { static_cast(self.array.object)->operator()(self.x) = val; } static void _t2(CFP_ARRAY_TYPE, CFP_REF_TYPE, copy)(CFP_REF_TYPE self, CFP_REF_TYPE src) { static_cast(self.array.object)->operator()(self.x) = static_cast(src.array.object)->operator()(src.x); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, lt)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && lhs.reference.x < rhs.reference.x; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, gt)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && lhs.reference.x > rhs.reference.x; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, leq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && lhs.reference.x <= rhs.reference.x; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, geq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && lhs.reference.x >= rhs.reference.x; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, eq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && lhs.reference.x == rhs.reference.x; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, neq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return !_t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, eq)(lhs, rhs); } static ptrdiff_t _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, distance)(CFP_PTR_TYPE first, CFP_PTR_TYPE last) { return last.reference.x - first.reference.x; } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(CFP_PTR_TYPE p, ptrdiff_t d) { p.reference.x += d; return p; } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, prev)(CFP_PTR_TYPE p, ptrdiff_t d) { p.reference.x -= d; return p; } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, inc)(CFP_PTR_TYPE p) { p.reference.x++; return p; } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, dec)(CFP_PTR_TYPE p) { p.reference.x--; return p; } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, get)(CFP_PTR_TYPE self) { return static_cast(self.reference.array.object)->operator()(self.reference.x); } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, get_at)(CFP_PTR_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(self, d); return static_cast(self.reference.array.object)->operator()(self.reference.x); } static void _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, set)(CFP_PTR_TYPE self, ZFP_SCALAR_TYPE val) { static_cast(self.reference.array.object)->operator()(self.reference.x) = val; } static void _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, set_at)(CFP_PTR_TYPE self, ptrdiff_t d, ZFP_SCALAR_TYPE val) { self = _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(self, d); static_cast(self.reference.array.object)->operator()(self.reference.x) = val; } static CFP_REF_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, ref_at)(CFP_PTR_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(self, d); return self.reference; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, lt)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && lhs.x < rhs.x; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, gt)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && lhs.x > rhs.x; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, leq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && lhs.x <= rhs.x; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, geq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && lhs.x >= rhs.x; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, eq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && lhs.x == rhs.x; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, neq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return !_t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, eq)(lhs, rhs); } static ptrdiff_t _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, distance)(CFP_ITER_TYPE first, CFP_ITER_TYPE last) { return last.x - first.x; } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(CFP_ITER_TYPE it, ptrdiff_t d) { it.x += d; return it; } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, prev)(CFP_ITER_TYPE it, ptrdiff_t d) { it.x -= d; return it; } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, inc)(CFP_ITER_TYPE it) { it.x++; return it; } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, dec)(CFP_ITER_TYPE it) { it.x--; return it; } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, get)(CFP_ITER_TYPE self) { return static_cast(self.array.object)->operator()(self.x); } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, get_at)(CFP_ITER_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); return static_cast(self.array.object)->operator()(self.x); } static void _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, set)(CFP_ITER_TYPE self, ZFP_SCALAR_TYPE val) { static_cast(self.array.object)->operator()(self.x) = val; } static void _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, set_at)(CFP_ITER_TYPE self, ptrdiff_t d, ZFP_SCALAR_TYPE val) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); static_cast(self.array.object)->operator()(self.x) = val; } static CFP_REF_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ref)(CFP_ITER_TYPE self) { return _t1(CFP_ARRAY_TYPE, ref)(self.array, self.x); } static CFP_REF_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ref_at)(CFP_ITER_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); return _t1(CFP_ARRAY_TYPE, ref)(self.array, self.x); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ptr)(CFP_ITER_TYPE self) { return _t1(CFP_ARRAY_TYPE, ptr)(self.array, self.x); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ptr_at)(CFP_ITER_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); return _t1(CFP_ARRAY_TYPE, ptr)(self.array, self.x); } static size_t _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, i)(CFP_ITER_TYPE self) { return self.x; } zfp-1.0.1/cfp/template/cfparray2.cpp000066400000000000000000000314361453723256400173120ustar00rootroot00000000000000// utility function: compute onedimensional offset from multidimensional index static ptrdiff_t ref_offset(const CFP_REF_TYPE& self) { size_t nx = static_cast(self.array.object)->size_x(); return static_cast(self.x + nx * self.y); } // utility function: compute multidimensional index from onedimensional offset static void ref_set_offset(CFP_REF_TYPE& self, size_t offset) { size_t nx = static_cast(self.array.object)->size_x(); self.x = offset % nx; offset /= nx; self.y = offset; } // utility function: compute onedimensional offset from multidimensional index static ptrdiff_t iter_offset(const CFP_ITER_TYPE& self) { const ZFP_ARRAY_TYPE* container = static_cast(self.array.object); size_t xmin = 0; size_t xmax = container->size_x(); size_t ymin = 0; size_t ymax = container->size_y(); size_t nx = xmax - xmin; size_t ny = ymax - ymin; size_t x = self.x; size_t y = self.y; size_t p = 0; if (y == ymax) p += nx * ny; else { size_t m = ~size_t(3); size_t by = std::max(y & m, ymin); size_t sy = std::min((by + 4) & m, ymax) - by; p += (by - ymin) * nx; size_t bx = std::max(x & m, xmin); size_t sx = std::min((bx + 4) & m, xmax) - bx; p += (bx - xmin) * sy; p += (y - by) * sx; p += (x - bx); } return static_cast(p); } // utility function: compute multidimensional index from onedimensional offset static void iter_set_offset(CFP_ITER_TYPE& self, size_t offset) { const ZFP_ARRAY_TYPE* container = static_cast(self.array.object); size_t xmin = 0; size_t xmax = container->size_x(); size_t ymin = 0; size_t ymax = container->size_y(); size_t nx = xmax - xmin; size_t ny = ymax - ymin; size_t p = offset; size_t x, y; if (p == nx * ny) { x = xmin; y = ymax; } else { size_t m = ~size_t(3); size_t by = std::max((ymin + p / nx) & m, ymin); size_t sy = std::min((by + 4) & m, ymax) - by; p -= (by - ymin) * nx; size_t bx = std::max((xmin + p / sy) & m, xmin); size_t sx = std::min((bx + 4) & m, xmax) - bx; p -= (bx - xmin) * sy; y = by + p / sx; p -= (y - by) * sx; x = bx + p; p -= (x - bx); } self.x = x; self.y = y; } static CFP_ARRAY_TYPE _t1(CFP_ARRAY_TYPE, ctor)(size_t nx, size_t ny, double rate, const ZFP_SCALAR_TYPE* p, size_t cache_size) { CFP_ARRAY_TYPE a; a.object = new ZFP_ARRAY_TYPE(nx, ny, rate, p, cache_size); return a; } static size_t _t1(CFP_ARRAY_TYPE, size_x)(CFP_ARRAY_TYPE self) { return static_cast(self.object)->size_x(); } static size_t _t1(CFP_ARRAY_TYPE, size_y)(CFP_ARRAY_TYPE self) { return static_cast(self.object)->size_y(); } static void _t1(CFP_ARRAY_TYPE, resize)(CFP_ARRAY_TYPE self, size_t nx, size_t ny, zfp_bool clear) { static_cast(self.object)->resize(nx, ny, !!clear); } static ZFP_SCALAR_TYPE _t1(CFP_ARRAY_TYPE, get)(CFP_ARRAY_TYPE self, size_t i, size_t j) { return static_cast(self.object)->operator()(i, j); } static void _t1(CFP_ARRAY_TYPE, set)(CFP_ARRAY_TYPE self, size_t i, size_t j, ZFP_SCALAR_TYPE val) { static_cast(self.object)->operator()(i, j) = val; } static CFP_REF_TYPE _t1(CFP_ARRAY_TYPE, ref)(CFP_ARRAY_TYPE self, size_t i, size_t j) { CFP_REF_TYPE r; r.array = self; r.x = i; r.y = j; return r; } static CFP_REF_TYPE _t1(CFP_ARRAY_TYPE, ref_flat)(CFP_ARRAY_TYPE self, size_t i) { CFP_REF_TYPE r; r.array = self; ref_set_offset(r, i); return r; } static CFP_PTR_TYPE _t1(CFP_ARRAY_TYPE, ptr)(CFP_ARRAY_TYPE self, size_t i, size_t j) { CFP_PTR_TYPE p; p.reference = _t1(CFP_ARRAY_TYPE, ref)(self, i, j); return p; } static CFP_PTR_TYPE _t1(CFP_ARRAY_TYPE, ptr_flat)(CFP_ARRAY_TYPE self, size_t i) { CFP_PTR_TYPE p; p.reference = _t1(CFP_ARRAY_TYPE, ref_flat)(self, i); return p; } static CFP_ITER_TYPE _t1(CFP_ARRAY_TYPE, begin)(CFP_ARRAY_TYPE self) { CFP_ITER_TYPE it; it.array = self; it.x = 0; it.y = 0; return it; } static CFP_ITER_TYPE _t1(CFP_ARRAY_TYPE, end)(CFP_ARRAY_TYPE self) { CFP_ITER_TYPE it; it.array = self; it.x = 0; it.y = static_cast(self.object)->size_y(); return it; } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_REF_TYPE, get)(CFP_REF_TYPE self) { return static_cast(self.array.object)->operator()(self.x, self.y); } static void _t2(CFP_ARRAY_TYPE, CFP_REF_TYPE, set)(CFP_REF_TYPE self, ZFP_SCALAR_TYPE val) { static_cast(self.array.object)->operator()(self.x, self.y) = val; } static void _t2(CFP_ARRAY_TYPE, CFP_REF_TYPE, copy)(CFP_REF_TYPE self, CFP_REF_TYPE src) { static_cast(self.array.object)->operator()(self.x, self.y) = static_cast(src.array.object)->operator()(src.x, src.y); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, lt)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && ref_offset(lhs.reference) < ref_offset(rhs.reference); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, gt)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && ref_offset(lhs.reference) > ref_offset(rhs.reference); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, leq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && ref_offset(lhs.reference) <= ref_offset(rhs.reference); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, geq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && ref_offset(lhs.reference) >= ref_offset(rhs.reference); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, eq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && lhs.reference.x == rhs.reference.x && lhs.reference.y == rhs.reference.y; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, neq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return !_t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, eq)(lhs, rhs); } static ptrdiff_t _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, distance)(CFP_PTR_TYPE first, CFP_PTR_TYPE last) { return ref_offset(last.reference) - ref_offset(first.reference); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(CFP_PTR_TYPE p, ptrdiff_t d) { ref_set_offset(p.reference, ref_offset(p.reference) + d); return p; } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, prev)(CFP_PTR_TYPE p, ptrdiff_t d) { return _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(p, -d); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, inc)(CFP_PTR_TYPE p) { return _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(p, +1); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, dec)(CFP_PTR_TYPE p) { return _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(p, -1); } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, get)(CFP_PTR_TYPE self) { return static_cast(self.reference.array.object)->operator()(self.reference.x, self.reference.y); } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, get_at)(CFP_PTR_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(self, d); return static_cast(self.reference.array.object)->operator()(self.reference.x, self.reference.y); } static void _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, set)(CFP_PTR_TYPE self, ZFP_SCALAR_TYPE val) { static_cast(self.reference.array.object)->operator()(self.reference.x, self.reference.y) = val; } static void _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, set_at)(CFP_PTR_TYPE self, ptrdiff_t d, ZFP_SCALAR_TYPE val) { self = _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(self, d); static_cast(self.reference.array.object)->operator()(self.reference.x, self.reference.y) = val; } static CFP_REF_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, ref_at)(CFP_PTR_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(self, d); return self.reference; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, lt)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && iter_offset(lhs) < iter_offset(rhs); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, gt)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && iter_offset(lhs) > iter_offset(rhs); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, leq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && iter_offset(lhs) <= iter_offset(rhs); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, geq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && iter_offset(lhs) >= iter_offset(rhs); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, eq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && lhs.x == rhs.x && lhs.y == rhs.y; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, neq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return !_t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, eq)(lhs, rhs); } static ptrdiff_t _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, distance)(CFP_ITER_TYPE first, CFP_ITER_TYPE last) { return iter_offset(last) - iter_offset(first); } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(CFP_ITER_TYPE it, ptrdiff_t d) { iter_set_offset(it, iter_offset(it) + d); return it; } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, prev)(CFP_ITER_TYPE it, ptrdiff_t d) { iter_set_offset(it, iter_offset(it) - d); return it; } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, inc)(CFP_ITER_TYPE it) { const ZFP_ARRAY_TYPE* container = static_cast(it.array.object); size_t xmin = 0; size_t xmax = container->size_x(); size_t ymin = 0; size_t ymax = container->size_y(); size_t m = ~size_t(3); ++it.x; if (!(it.x & 3u) || it.x == xmax) { it.x = std::max((it.x - 1) & m, xmin); ++it.y; if (!(it.y & 3u) || it.y == ymax) { it.y = std::max((it.y - 1) & m, ymin); // done with block; advance to next it.x = (it.x + 4) & m; if (it.x >= xmax) { it.x = xmin; it.y = (it.y + 4) & m; if (it.y >= ymax) it.y = ymax; } } } return it; } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, dec)(CFP_ITER_TYPE it) { const ZFP_ARRAY_TYPE* container = static_cast(it.array.object); size_t xmin = 0; size_t xmax = container->size_x(); size_t ymin = 0; size_t ymax = container->size_y(); size_t m = ~size_t(3); if (it.y == ymax) { it.x = xmax - 1; it.y = ymax - 1; } else { if (!(it.x & 3u) || it.x == xmin) { it.x = std::min((it.x + 4) & m, xmax); if (!(it.y & 3u) || it.y == ymin) { it.y = std::min((it.y + 4) & m, ymax); // done with block; advance to next it.x = (it.x - 1) & m; if (it.x <= xmin) { it.x = xmax; it.y = (it.y - 1) & m; if (it.y <= ymin) it.y = ymin; } } --it.y; } --it.x; } return it; } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, get)(CFP_ITER_TYPE self) { return static_cast(self.array.object)->operator()(self.x, self.y); } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, get_at)(CFP_ITER_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); return static_cast(self.array.object)->operator()(self.x, self.y); } static void _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, set)(CFP_ITER_TYPE self, ZFP_SCALAR_TYPE val) { static_cast(self.array.object)->operator()(self.x, self.y) = val; } static void _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, set_at)(CFP_ITER_TYPE self, ptrdiff_t d, ZFP_SCALAR_TYPE val) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); static_cast(self.array.object)->operator()(self.x, self.y) = val; } static CFP_REF_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ref)(CFP_ITER_TYPE self) { return _t1(CFP_ARRAY_TYPE, ref)(self.array, self.x, self.y); } static CFP_REF_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ref_at)(CFP_ITER_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); return _t1(CFP_ARRAY_TYPE, ref)(self.array, self.x, self.y); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ptr)(CFP_ITER_TYPE self) { return _t1(CFP_ARRAY_TYPE, ptr)(self.array, self.x, self.y); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ptr_at)(CFP_ITER_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); return _t1(CFP_ARRAY_TYPE, ptr)(self.array, self.x, self.y); } static size_t _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, i)(CFP_ITER_TYPE self) { return self.x; } static size_t _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, j)(CFP_ITER_TYPE self) { return self.y; } zfp-1.0.1/cfp/template/cfparray3.cpp000066400000000000000000000353351453723256400173150ustar00rootroot00000000000000// utility function: compute onedimensional offset from multidimensional index static ptrdiff_t ref_offset(const CFP_REF_TYPE& self) { size_t nx = static_cast(self.array.object)->size_x(); size_t ny = static_cast(self.array.object)->size_y(); return static_cast(self.x + nx * (self.y + ny * self.z)); } // utility function: compute multidimensional index from onedimensional offset static void ref_set_offset(CFP_REF_TYPE& self, size_t offset) { size_t nx = static_cast(self.array.object)->size_x(); size_t ny = static_cast(self.array.object)->size_y(); self.x = offset % nx; offset /= nx; self.y = offset % ny; offset /= ny; self.z = offset; } // utility function: compute onedimensional offset from multidimensional index static ptrdiff_t iter_offset(const CFP_ITER_TYPE& self) { const ZFP_ARRAY_TYPE* container = static_cast(self.array.object); size_t xmin = 0; size_t xmax = container->size_x(); size_t ymin = 0; size_t ymax = container->size_y(); size_t zmin = 0; size_t zmax = container->size_z(); size_t nx = xmax - xmin; size_t ny = ymax - ymin; size_t nz = zmax - zmin; size_t x = self.x; size_t y = self.y; size_t z = self.z; size_t p = 0; if (z == zmax) p += nx * ny * nz; else { size_t m = ~size_t(3); size_t bz = std::max(z & m, zmin); size_t sz = std::min((bz + 4) & m, zmax) - bz; p += (bz - zmin) * nx * ny; size_t by = std::max(y & m, ymin); size_t sy = std::min((by + 4) & m, ymax) - by; p += (by - ymin) * nx * sz; size_t bx = std::max(x & m, xmin); size_t sx = std::min((bx + 4) & m, xmax) - bx; p += (bx - xmin) * sy * sz; p += (z - bz) * sx * sy; p += (y - by) * sx; p += (x - bx); } return p; } // utility function: compute multidimensional index from onedimensional offset static void iter_set_offset(CFP_ITER_TYPE& self, size_t offset) { const ZFP_ARRAY_TYPE* container = static_cast(self.array.object); size_t xmin = 0; size_t xmax = container->size_x(); size_t ymin = 0; size_t ymax = container->size_y(); size_t zmin = 0; size_t zmax = container->size_z(); size_t nx = xmax - xmin; size_t ny = ymax - ymin; size_t nz = zmax - zmin; size_t p = offset; size_t x, y, z; if (p == nx * ny * nz) { x = xmin; y = ymin; z = zmax; } else { size_t m = ~size_t(3); size_t bz = std::max((zmin + p / (nx * ny)) & m, zmin); size_t sz = std::min((bz + 4) & m, zmax) - bz; p -= (bz - zmin) * nx * ny; size_t by = std::max((ymin + p / (nx * sz)) & m, ymin); size_t sy = std::min((by + 4) & m, ymax) - by; p -= (by - ymin) * nx * sz; size_t bx = std::max((xmin + p / (sy * sz)) & m, xmin); size_t sx = std::min((bx + 4) & m, xmax) - bx; p -= (bx - xmin) * sy * sz; z = bz + p / (sx * sy); p -= (z - bz) * sx * sy; y = by + p / sx; p -= (y - by) * sx; x = bx + p; p -= (x - bx); } self.x = x; self.y = y; self.z = z; } static CFP_ARRAY_TYPE _t1(CFP_ARRAY_TYPE, ctor)(size_t nx, size_t ny, size_t nz, double rate, const ZFP_SCALAR_TYPE* p, size_t cache_size) { CFP_ARRAY_TYPE a; a.object = new ZFP_ARRAY_TYPE(nx, ny, nz, rate, p, cache_size); return a; } static size_t _t1(CFP_ARRAY_TYPE, size_x)(CFP_ARRAY_TYPE self) { return static_cast(self.object)->size_x(); } static size_t _t1(CFP_ARRAY_TYPE, size_y)(CFP_ARRAY_TYPE self) { return static_cast(self.object)->size_y(); } static size_t _t1(CFP_ARRAY_TYPE, size_z)(CFP_ARRAY_TYPE self) { return static_cast(self.object)->size_z(); } static void _t1(CFP_ARRAY_TYPE, resize)(CFP_ARRAY_TYPE self, size_t nx, size_t ny, size_t nz, zfp_bool clear) { static_cast(self.object)->resize(nx, ny, nz, !!clear); } static ZFP_SCALAR_TYPE _t1(CFP_ARRAY_TYPE, get)(CFP_ARRAY_TYPE self, size_t i, size_t j, size_t k) { return static_cast(self.object)->operator()(i, j, k); } static void _t1(CFP_ARRAY_TYPE, set)(CFP_ARRAY_TYPE self, size_t i, size_t j, size_t k, ZFP_SCALAR_TYPE val) { static_cast(self.object)->operator()(i, j, k) = val; } static CFP_REF_TYPE _t1(CFP_ARRAY_TYPE, ref)(CFP_ARRAY_TYPE self, size_t i, size_t j, size_t k) { CFP_REF_TYPE r; r.array = self; r.x = i; r.y = j; r.z = k; return r; } static CFP_REF_TYPE _t1(CFP_ARRAY_TYPE, ref_flat)(CFP_ARRAY_TYPE self, size_t i) { CFP_REF_TYPE r; r.array = self; ref_set_offset(r, i); return r; } static CFP_PTR_TYPE _t1(CFP_ARRAY_TYPE, ptr)(CFP_ARRAY_TYPE self, size_t i, size_t j, size_t k) { CFP_PTR_TYPE p; p.reference = _t1(CFP_ARRAY_TYPE, ref)(self, i, j, k); return p; } static CFP_PTR_TYPE _t1(CFP_ARRAY_TYPE, ptr_flat)(CFP_ARRAY_TYPE self, size_t i) { CFP_PTR_TYPE p; p.reference = _t1(CFP_ARRAY_TYPE, ref_flat)(self, i); return p; } static CFP_ITER_TYPE _t1(CFP_ARRAY_TYPE, begin)(CFP_ARRAY_TYPE self) { CFP_ITER_TYPE it; it.array = self; it.x = 0; it.y = 0; it.z = 0; return it; } static CFP_ITER_TYPE _t1(CFP_ARRAY_TYPE, end)(CFP_ARRAY_TYPE self) { CFP_ITER_TYPE it; it.array = self; it.x = 0; it.y = 0; it.z = static_cast(self.object)->size_z(); return it; } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_REF_TYPE, get)(CFP_REF_TYPE self) { return static_cast(self.array.object)->operator()(self.x, self.y, self.z); } static void _t2(CFP_ARRAY_TYPE, CFP_REF_TYPE, set)(CFP_REF_TYPE self, ZFP_SCALAR_TYPE val) { static_cast(self.array.object)->operator()(self.x, self.y, self.z) = val; } static void _t2(CFP_ARRAY_TYPE, CFP_REF_TYPE, copy)(CFP_REF_TYPE self, CFP_REF_TYPE src) { static_cast(self.array.object)->operator()(self.x, self.y, self.z) = static_cast(src.array.object)->operator()(src.x, src.y, src.z); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, lt)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && ref_offset(lhs.reference) < ref_offset(rhs.reference); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, gt)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && ref_offset(lhs.reference) > ref_offset(rhs.reference); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, leq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && ref_offset(lhs.reference) <= ref_offset(rhs.reference); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, geq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && ref_offset(lhs.reference) >= ref_offset(rhs.reference); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, eq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && lhs.reference.x == rhs.reference.x && lhs.reference.y == rhs.reference.y && lhs.reference.z == rhs.reference.z; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, neq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return !_t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, eq)(lhs, rhs); } static ptrdiff_t _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, distance)(CFP_PTR_TYPE first, CFP_PTR_TYPE last) { return ref_offset(last.reference) - ref_offset(first.reference); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(CFP_PTR_TYPE p, ptrdiff_t d) { ref_set_offset(p.reference, ref_offset(p.reference) + d); return p; } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, prev)(CFP_PTR_TYPE p, ptrdiff_t d) { return _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(p, -d); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, inc)(CFP_PTR_TYPE p) { return _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(p, +1); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, dec)(CFP_PTR_TYPE p) { return _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(p, -1); } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, get)(CFP_PTR_TYPE self) { return static_cast(self.reference.array.object)->operator()(self.reference.x, self.reference.y, self.reference.z); } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, get_at)(CFP_PTR_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(self, d); return static_cast(self.reference.array.object)->operator()(self.reference.x, self.reference.y, self.reference.z); } static void _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, set)(CFP_PTR_TYPE self, ZFP_SCALAR_TYPE val) { static_cast(self.reference.array.object)->operator()(self.reference.x, self.reference.y, self.reference.z) = val; } static void _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, set_at)(CFP_PTR_TYPE self, ptrdiff_t d, ZFP_SCALAR_TYPE val) { self = _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(self, d); static_cast(self.reference.array.object)->operator()(self.reference.x, self.reference.y, self.reference.z) = val; } static CFP_REF_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, ref_at)(CFP_PTR_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(self, d); return self.reference; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, lt)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && iter_offset(lhs) < iter_offset(rhs); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, gt)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && iter_offset(lhs) > iter_offset(rhs); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, leq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && iter_offset(lhs) <= iter_offset(rhs); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, geq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && iter_offset(lhs) >= iter_offset(rhs); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, eq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, neq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return !_t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, eq)(lhs, rhs); } static ptrdiff_t _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, distance)(CFP_ITER_TYPE first, CFP_ITER_TYPE last) { return iter_offset(last) - iter_offset(first); } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(CFP_ITER_TYPE it, ptrdiff_t d) { iter_set_offset(it, iter_offset(it) + d); return it; } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, prev)(CFP_ITER_TYPE it, ptrdiff_t d) { iter_set_offset(it, iter_offset(it) - d); return it; } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, inc)(CFP_ITER_TYPE it) { const ZFP_ARRAY_TYPE* container = static_cast(it.array.object); size_t xmin = 0; size_t xmax = container->size_x(); size_t ymin = 0; size_t ymax = container->size_y(); size_t zmin = 0; size_t zmax = container->size_z(); size_t m = ~size_t(3); ++it.x; if (!(it.x & 3u) || it.x == xmax) { it.x = std::max((it.x - 1) & m, xmin); ++it.y; if (!(it.y & 3u) || it.y == ymax) { it.y = std::max((it.y - 1) & m, ymin); ++it.z; if (!(it.z & 3u) || it.z == zmax) { it.z = std::max((it.z - 1) & m, zmin); // done with block; advance to next it.x = (it.x + 4) & m; if (it.x >= xmax) { it.x = xmin; it.y = (it.y + 4) & m; if (it.y >= ymax) { it.y = ymin; it.z = (it.z + 4) & m; if (it.z >= zmax) it.z = zmax; } } } } } return it; } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, dec)(CFP_ITER_TYPE it) { const ZFP_ARRAY_TYPE* container = static_cast(it.array.object); size_t xmin = 0; size_t xmax = container->size_x(); size_t ymin = 0; size_t ymax = container->size_y(); size_t zmin = 0; size_t zmax = container->size_z(); size_t m = ~size_t(3); if (it.z == zmax) { it.x = xmax - 1; it.y = ymax - 1; it.z = zmax - 1; } else { if (!(it.x & 3u) || it.x == xmin) { it.x = std::min((it.x + 4) & m, xmax); if (!(it.y & 3u) || it.y == ymin) { it.y = std::min((it.y + 4) & m, ymax); if (!(it.z & 3u) || it.z == zmin) { it.z = std::min((it.z + 4) & m, zmax); // done with block; advance to next it.x = (it.x - 1) & m; if (it.x <= xmin) { it.x = xmax; it.y = (it.y - 1) & m; if (it.y <= ymin) { it.y = ymax; it.z = (it.z - 1) & m; if (it.z <= zmin) it.z = zmin; } } } --it.z; } --it.y; } --it.x; } return it; } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, get)(CFP_ITER_TYPE self) { return static_cast(self.array.object)->operator()(self.x, self.y, self.z); } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, get_at)(CFP_ITER_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); return static_cast(self.array.object)->operator()(self.x, self.y, self.z); } static void _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, set)(CFP_ITER_TYPE self, ZFP_SCALAR_TYPE val) { static_cast(self.array.object)->operator()(self.x, self.y, self.z) = val; } static void _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, set_at)(CFP_ITER_TYPE self, ptrdiff_t d, ZFP_SCALAR_TYPE val) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); static_cast(self.array.object)->operator()(self.x, self.y, self.z) = val; } static CFP_REF_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ref)(CFP_ITER_TYPE self) { return _t1(CFP_ARRAY_TYPE, ref)(self.array, self.x, self.y, self.z); } static CFP_REF_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ref_at)(CFP_ITER_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); return _t1(CFP_ARRAY_TYPE, ref)(self.array, self.x, self.y, self.z); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ptr)(CFP_ITER_TYPE self) { return _t1(CFP_ARRAY_TYPE, ptr)(self.array, self.x, self.y, self.z); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ptr_at)(CFP_ITER_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); return _t1(CFP_ARRAY_TYPE, ptr)(self.array, self.x, self.y, self.z); } static size_t _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, i)(CFP_ITER_TYPE self) { return self.x; } static size_t _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, j)(CFP_ITER_TYPE self) { return self.y; } static size_t _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, k)(CFP_ITER_TYPE self) { return self.z; } zfp-1.0.1/cfp/template/cfparray4.cpp000066400000000000000000000415021453723256400173070ustar00rootroot00000000000000// utility function: compute onedimensional offset from multidimensional index static ptrdiff_t ref_offset(const CFP_REF_TYPE& self) { size_t nx = static_cast(self.array.object)->size_x(); size_t ny = static_cast(self.array.object)->size_y(); size_t nz = static_cast(self.array.object)->size_z(); return static_cast(self.x + nx * (self.y + ny * (self.z + nz * self.w))); } // utility function: compute multidimensional index from onedimensional offset static void ref_set_offset(CFP_REF_TYPE& self, size_t offset) { size_t nx = static_cast(self.array.object)->size_x(); size_t ny = static_cast(self.array.object)->size_y(); size_t nz = static_cast(self.array.object)->size_z(); self.x = offset % nx; offset /= nx; self.y = offset % ny; offset /= ny; self.z = offset % nz; offset /= nz; self.w = offset; } // utility function: compute onedimensional offset from multidimensional index static ptrdiff_t iter_offset(const CFP_ITER_TYPE& self) { const ZFP_ARRAY_TYPE* container = static_cast(self.array.object); size_t xmin = 0; size_t xmax = container->size_x(); size_t ymin = 0; size_t ymax = container->size_y(); size_t zmin = 0; size_t zmax = container->size_z(); size_t wmin = 0; size_t wmax = container->size_w(); size_t nx = xmax - xmin; size_t ny = ymax - ymin; size_t nz = zmax - zmin; size_t nw = wmax - wmin; size_t x = self.x; size_t y = self.y; size_t z = self.z; size_t w = self.w; size_t p = 0; if (w == wmax) p += nx * ny * nz * nw; else { size_t m = ~size_t(3); size_t bw = std::max(w & m, wmin); size_t sw = std::min((bw + 4) & m, wmax) - bw; p += (bw - wmin) * nx * ny * nz; size_t bz = std::max(z & m, zmin); size_t sz = std::min((bz + 4) & m, zmax) - bz; p += (bz - zmin) * nx * ny * sw; size_t by = std::max(y & m, ymin); size_t sy = std::min((by + 4) & m, ymax) - by; p += (by - ymin) * nx * sz * sw; size_t bx = std::max(x & m, xmin); size_t sx = std::min((bx + 4) & m, xmax) - bx; p += (bx - xmin) * sy * sz * sw; p += (w - bw) * sx * sy * sz; p += (z - bz) * sx * sy; p += (y - by) * sx; p += (x - bx); } return static_cast(p); } // utility function: compute multidimensional index from onedimensional offset static void iter_set_offset(CFP_ITER_TYPE& self, size_t offset) { const ZFP_ARRAY_TYPE* container = static_cast(self.array.object); size_t xmin = 0; size_t xmax = container->size_x(); size_t ymin = 0; size_t ymax = container->size_y(); size_t zmin = 0; size_t zmax = container->size_z(); size_t wmin = 0; size_t wmax = container->size_w(); size_t nx = xmax - xmin; size_t ny = ymax - ymin; size_t nz = zmax - zmin; size_t nw = wmax - wmin; size_t p = offset; size_t x, y, z, w; if (p == nx * ny * nz * nw) { x = xmin; y = ymin; z = zmin; w = wmax; } else { size_t m = ~size_t(3); size_t bw = std::max((wmin + p / (nx * ny * nz)) & m, wmin); size_t sw = std::min((bw + 4) & m, wmax) - bw; p -= (bw - wmin) * nx * ny * nz; size_t bz = std::max((zmin + p / (nx * ny * sw)) & m, zmin); size_t sz = std::min((bz + 4) & m, zmax) - bz; p -= (bz - zmin) * nx * ny * sw; size_t by = std::max((ymin + p / (nx * sz * sw)) & m, ymin); size_t sy = std::min((by + 4) & m, ymax) - by; p -= (by - ymin) * nx * sz * sw; size_t bx = std::max((xmin + p / (sy * sz * sw)) & m, xmin); size_t sx = std::min((bx + 4) & m, xmax) - bx; p -= (bx - xmin) * sy * sz * sw; w = bw + p / (sx * sy * sz); p -= (w - bw) * sx * sy * sz; z = bz + p / (sx * sy); p -= (z - bz) * sx * sy; y = by + p / sx; p -= (y - by) * sx; x = bx + p; p -= (x - bx); } self.x = x; self.y = y; self.z = z; self.w = w; } static CFP_ARRAY_TYPE _t1(CFP_ARRAY_TYPE, ctor)(size_t nx, size_t ny, size_t nz, size_t nw, double rate, const ZFP_SCALAR_TYPE* p, size_t cache_size) { CFP_ARRAY_TYPE a; a.object = new ZFP_ARRAY_TYPE(nx, ny, nz, nw, rate, p, cache_size); return a; } static size_t _t1(CFP_ARRAY_TYPE, size_x)(CFP_ARRAY_TYPE self) { return static_cast(self.object)->size_x(); } static size_t _t1(CFP_ARRAY_TYPE, size_y)(CFP_ARRAY_TYPE self) { return static_cast(self.object)->size_y(); } static size_t _t1(CFP_ARRAY_TYPE, size_z)(CFP_ARRAY_TYPE self) { return static_cast(self.object)->size_z(); } static size_t _t1(CFP_ARRAY_TYPE, size_w)(CFP_ARRAY_TYPE self) { return static_cast(self.object)->size_w(); } static void _t1(CFP_ARRAY_TYPE, resize)(CFP_ARRAY_TYPE self, size_t nx, size_t ny, size_t nz, size_t nw, zfp_bool clear) { static_cast(self.object)->resize(nx, ny, nz, nw, !!clear); } static ZFP_SCALAR_TYPE _t1(CFP_ARRAY_TYPE, get)(CFP_ARRAY_TYPE self, size_t i, size_t j, size_t k, size_t l) { return static_cast(self.object)->operator()(i, j, k, l); } static void _t1(CFP_ARRAY_TYPE, set)(CFP_ARRAY_TYPE self, size_t i, size_t j, size_t k, size_t l, ZFP_SCALAR_TYPE val) { static_cast(self.object)->operator()(i, j, k, l) = val; } static CFP_REF_TYPE _t1(CFP_ARRAY_TYPE, ref)(CFP_ARRAY_TYPE self, size_t i, size_t j, size_t k, size_t l) { CFP_REF_TYPE r; r.array = self; r.x = i; r.y = j; r.z = k; r.w = l; return r; } static CFP_REF_TYPE _t1(CFP_ARRAY_TYPE, ref_flat)(CFP_ARRAY_TYPE self, size_t i) { CFP_REF_TYPE r; r.array = self; ref_set_offset(r, i); return r; } static CFP_PTR_TYPE _t1(CFP_ARRAY_TYPE, ptr)(CFP_ARRAY_TYPE self, size_t i, size_t j, size_t k, size_t l) { CFP_PTR_TYPE p; p.reference = _t1(CFP_ARRAY_TYPE, ref)(self, i, j, k, l); return p; } static CFP_PTR_TYPE _t1(CFP_ARRAY_TYPE, ptr_flat)(CFP_ARRAY_TYPE self, size_t i) { CFP_PTR_TYPE p; p.reference = _t1(CFP_ARRAY_TYPE, ref_flat)(self, i); return p; } static CFP_ITER_TYPE _t1(CFP_ARRAY_TYPE, begin)(CFP_ARRAY_TYPE self) { CFP_ITER_TYPE it; it.array = self; it.x = 0; it.y = 0; it.z = 0; it.w = 0; return it; } static CFP_ITER_TYPE _t1(CFP_ARRAY_TYPE, end)(CFP_ARRAY_TYPE self) { CFP_ITER_TYPE it; it.array = self; it.x = 0; it.y = 0; it.z = 0; it.w = static_cast(self.object)->size_w(); return it; } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_REF_TYPE, get)(CFP_REF_TYPE self) { return static_cast(self.array.object)->operator()(self.x, self.y, self.z, self.w); } static void _t2(CFP_ARRAY_TYPE, CFP_REF_TYPE, set)(CFP_REF_TYPE self, ZFP_SCALAR_TYPE val) { static_cast(self.array.object)->operator()(self.x, self.y, self.z, self.w) = val; } static void _t2(CFP_ARRAY_TYPE, CFP_REF_TYPE, copy)(CFP_REF_TYPE self, CFP_REF_TYPE src) { static_cast(self.array.object)->operator()(self.x, self.y, self.z, self.w) = static_cast(src.array.object)->operator()(src.x, src.y, src.z, src.w); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, lt)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && ref_offset(lhs.reference) < ref_offset(rhs.reference); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, gt)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && ref_offset(lhs.reference) > ref_offset(rhs.reference); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, leq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && ref_offset(lhs.reference) <= ref_offset(rhs.reference); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, geq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && ref_offset(lhs.reference) >= ref_offset(rhs.reference); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, eq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return lhs.reference.array.object == rhs.reference.array.object && lhs.reference.x == rhs.reference.x && lhs.reference.y == rhs.reference.y && lhs.reference.z == rhs.reference.z && lhs.reference.w == rhs.reference.w; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, neq)(CFP_PTR_TYPE lhs, CFP_PTR_TYPE rhs) { return !_t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, eq)(lhs, rhs); } static ptrdiff_t _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, distance)(CFP_PTR_TYPE first, CFP_PTR_TYPE last) { return ref_offset(last.reference) - ref_offset(first.reference); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(CFP_PTR_TYPE p, ptrdiff_t d) { ref_set_offset(p.reference, ref_offset(p.reference) + d); return p; } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, prev)(CFP_PTR_TYPE p, ptrdiff_t d) { return _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(p, -d); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, inc)(CFP_PTR_TYPE p) { return _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(p, +1); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, dec)(CFP_PTR_TYPE p) { return _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(p, -1); } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, get)(CFP_PTR_TYPE self) { return static_cast(self.reference.array.object)->operator()(self.reference.x, self.reference.y, self.reference.z, self.reference.w); } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, get_at)(CFP_PTR_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(self, d); return static_cast(self.reference.array.object)->operator()(self.reference.x, self.reference.y, self.reference.z, self.reference.w); } static void _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, set)(CFP_PTR_TYPE self, ZFP_SCALAR_TYPE val) { static_cast(self.reference.array.object)->operator()(self.reference.x, self.reference.y, self.reference.z, self.reference.w) = val; } static void _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, set_at)(CFP_PTR_TYPE self, ptrdiff_t d, ZFP_SCALAR_TYPE val) { self = _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(self, d); static_cast(self.reference.array.object)->operator()(self.reference.x, self.reference.y, self.reference.z, self.reference.w) = val; } static CFP_REF_TYPE _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, ref_at)(CFP_PTR_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_PTR_TYPE, next)(self, d); return self.reference; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, lt)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && iter_offset(lhs) < iter_offset(rhs); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, gt)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && iter_offset(lhs) > iter_offset(rhs); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, leq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && iter_offset(lhs) <= iter_offset(rhs); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, geq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && iter_offset(lhs) >= iter_offset(rhs); } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, eq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return lhs.array.object == rhs.array.object && lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z && lhs.w == rhs.w; } static zfp_bool _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, neq)(CFP_ITER_TYPE lhs, CFP_ITER_TYPE rhs) { return !_t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, eq)(lhs, rhs); } static ptrdiff_t _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, distance)(CFP_ITER_TYPE first, CFP_ITER_TYPE last) { return iter_offset(last) - iter_offset(first); } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(CFP_ITER_TYPE it, ptrdiff_t d) { iter_set_offset(it, iter_offset(it) + d); return it; } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, prev)(CFP_ITER_TYPE it, ptrdiff_t d) { iter_set_offset(it, iter_offset(it) - d); return it; } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, inc)(CFP_ITER_TYPE it) { const ZFP_ARRAY_TYPE* container = static_cast(it.array.object); size_t xmin = 0; size_t xmax = container->size_x(); size_t ymin = 0; size_t ymax = container->size_y(); size_t zmin = 0; size_t zmax = container->size_z(); size_t wmin = 0; size_t wmax = container->size_w(); size_t m = ~size_t(3); ++it.x; if (!(it.x & 3u) || it.x == xmax) { it.x = std::max((it.x - 1) & m, xmin); ++it.y; if (!(it.y & 3u) || it.y == ymax) { it.y = std::max((it.y - 1) & m, ymin); ++it.z; if (!(it.z & 3u) || it.z == zmax) { it.z = std::max((it.z - 1) & m, zmin); ++it.w; if (!(it.w & 3u) || it.w == wmax) { it.w = std::max((it.w - 1) & m, wmin); // done with block; advance to next it.x = (it.x + 4) & m; if (it.x >= xmax) { it.x = xmin; it.y = (it.y + 4) & m; if (it.y >= ymax) { it.y = ymin; it.z = (it.z + 4) & m; if (it.z >= zmax) { it.z = zmin; it.w = (it.w + 4) & m; if (it.w >= wmax) it.w = wmax; } } } } } } } return it; } static CFP_ITER_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, dec)(CFP_ITER_TYPE it) { const ZFP_ARRAY_TYPE* container = static_cast(it.array.object); size_t xmin = 0; size_t xmax = container->size_x(); size_t ymin = 0; size_t ymax = container->size_y(); size_t zmin = 0; size_t zmax = container->size_z(); size_t wmin = 0; size_t wmax = container->size_w(); size_t m = ~size_t(3); if (it.w == wmax) { it.x = xmax - 1; it.y = ymax - 1; it.z = zmax - 1; it.w = wmax - 1; } else { if (!(it.x & 3u) || it.x == xmin) { it.x = std::min((it.x + 4) & m, xmax); if (!(it.y & 3u) || it.y == ymin) { it.y = std::min((it.y + 4) & m, ymax); if (!(it.z & 3u) || it.z == zmin) { it.z = std::min((it.z + 4) & m, zmax); if (!(it.w & 3u) || it.w == wmin) { it.w = std::min((it.w + 4) & m, wmax); // done with block; advance to next it.x = (it.x - 1) & m; if (it.x <= xmin) { it.x = xmax; it.y = (it.y - 1) & m; if (it.y <= ymin) { it.y = ymax; it.z = (it.z - 1) & m; if (it.z <= zmin) { it.z = zmax; it.w = (it.w - 1) & m; if (it.w <= wmin) it.w = wmin; } } } } --it.w; } --it.z; } --it.y; } --it.x; } return it; } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, get)(CFP_ITER_TYPE self) { return static_cast(self.array.object)->operator()(self.x, self.y, self.z, self.w); } static ZFP_SCALAR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, get_at)(CFP_ITER_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); return static_cast(self.array.object)->operator()(self.x, self.y, self.z, self.w); } static void _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, set)(CFP_ITER_TYPE self, ZFP_SCALAR_TYPE val) { static_cast(self.array.object)->operator()(self.x, self.y, self.z, self.w) = val; } static void _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, set_at)(CFP_ITER_TYPE self, ptrdiff_t d, ZFP_SCALAR_TYPE val) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); static_cast(self.array.object)->operator()(self.x, self.y, self.z, self.w) = val; } static CFP_REF_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ref)(CFP_ITER_TYPE self) { return _t1(CFP_ARRAY_TYPE, ref)(self.array, self.x, self.y, self.z, self.w); } static CFP_REF_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ref_at)(CFP_ITER_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); return _t1(CFP_ARRAY_TYPE, ref)(self.array, self.x, self.y, self.z, self.w); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ptr)(CFP_ITER_TYPE self) { return _t1(CFP_ARRAY_TYPE, ptr)(self.array, self.x, self.y, self.z, self.w); } static CFP_PTR_TYPE _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, ptr_at)(CFP_ITER_TYPE self, ptrdiff_t d) { self = _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, next)(self, d); return _t1(CFP_ARRAY_TYPE, ptr)(self.array, self.x, self.y, self.z, self.w); } static size_t _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, i)(CFP_ITER_TYPE self) { return self.x; } static size_t _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, j)(CFP_ITER_TYPE self) { return self.y; } static size_t _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, k)(CFP_ITER_TYPE self) { return self.z; } static size_t _t2(CFP_ARRAY_TYPE, CFP_ITER_TYPE, l)(CFP_ITER_TYPE self) { return self.w; } zfp-1.0.1/cfp/template/cfpheader.cpp000066400000000000000000000103071453723256400173340ustar00rootroot00000000000000static CFP_HEADER_TYPE _t1(CFP_HEADER_TYPE, ctor_buffer)(const void* data, size_t bytes) { CFP_HEADER_TYPE h; h.object = 0; try { // construct generic header and query array type header hdr(data, bytes); uint dims = hdr.dimensionality(); zfp_type scalar_type = hdr.scalar_type(); // construct array-specific header switch (dims) { case 1: if (scalar_type == zfp_type_float) h.object = new zfp::array1f::header(data, bytes); else if (scalar_type == zfp_type_double) h.object = new zfp::array1d::header(data, bytes); break; case 2: if (scalar_type == zfp_type_float) h.object = new zfp::array2f::header(data, bytes); else if (scalar_type == zfp_type_double) h.object = new zfp::array2d::header(data, bytes); break; case 3: if (scalar_type == zfp_type_float) h.object = new zfp::array3f::header(data, bytes); else if (scalar_type == zfp_type_double) h.object = new zfp::array3d::header(data, bytes); break; case 4: if (scalar_type == zfp_type_float) h.object = new zfp::array4f::header(data, bytes); else if (scalar_type == zfp_type_double) h.object = new zfp::array4d::header(data, bytes); break; } } catch (...) {} return h; } static CFP_HEADER_TYPE _t1(CFP_HEADER_TYPE, ctor_array1f)(cfp_array1f a) { CFP_HEADER_TYPE h; h.object = new zfp::array1f::header(*static_cast(a.object)); return h; } static CFP_HEADER_TYPE _t1(CFP_HEADER_TYPE, ctor_array1d)(cfp_array1d a) { CFP_HEADER_TYPE h; h.object = new zfp::array1d::header(*static_cast(a.object)); return h; } static CFP_HEADER_TYPE _t1(CFP_HEADER_TYPE, ctor_array2f)(cfp_array2f a) { CFP_HEADER_TYPE h; h.object = new zfp::array2f::header(*static_cast(a.object)); return h; } static CFP_HEADER_TYPE _t1(CFP_HEADER_TYPE, ctor_array2d)(cfp_array2d a) { CFP_HEADER_TYPE h; h.object = new zfp::array2d::header(*static_cast(a.object)); return h; } static CFP_HEADER_TYPE _t1(CFP_HEADER_TYPE, ctor_array3f)(cfp_array3f a) { CFP_HEADER_TYPE h; h.object = new zfp::array3f::header(*static_cast(a.object)); return h; } static CFP_HEADER_TYPE _t1(CFP_HEADER_TYPE, ctor_array3d)(cfp_array3d a) { CFP_HEADER_TYPE h; h.object = new zfp::array3d::header(*static_cast(a.object)); return h; } static CFP_HEADER_TYPE _t1(CFP_HEADER_TYPE, ctor_array4f)(cfp_array4f a) { CFP_HEADER_TYPE h; h.object = new zfp::array4f::header(*static_cast(a.object)); return h; } static CFP_HEADER_TYPE _t1(CFP_HEADER_TYPE, ctor_array4d)(cfp_array4d a) { CFP_HEADER_TYPE h; h.object = new zfp::array4d::header(*static_cast(a.object)); return h; } static void _t1(CFP_HEADER_TYPE, dtor)(CFP_HEADER_TYPE self) { delete static_cast(self.object); } static zfp_type _t1(CFP_HEADER_TYPE, scalar_type)(CFP_HEADER_TYPE self) { return static_cast(self.object)->scalar_type(); } static uint _t1(CFP_HEADER_TYPE, dimensionality)(CFP_HEADER_TYPE self) { return static_cast(self.object)->dimensionality(); } static size_t _t1(CFP_HEADER_TYPE, size_x)(CFP_HEADER_TYPE self) { return static_cast(self.object)->size_x(); } static size_t _t1(CFP_HEADER_TYPE, size_y)(CFP_HEADER_TYPE self) { return static_cast(self.object)->size_y(); } static size_t _t1(CFP_HEADER_TYPE, size_z)(CFP_HEADER_TYPE self) { return static_cast(self.object)->size_z(); } static size_t _t1(CFP_HEADER_TYPE, size_w)(CFP_HEADER_TYPE self) { return static_cast(self.object)->size_w(); } static double _t1(CFP_HEADER_TYPE, rate)(CFP_HEADER_TYPE self) { return static_cast(self.object)->rate(); } static const void* _t1(CFP_HEADER_TYPE, data)(CFP_HEADER_TYPE self) { return static_cast(self.object)->data(); } static size_t _t1(CFP_HEADER_TYPE, size_bytes)(CFP_HEADER_TYPE self, uint mask) { return static_cast(self.object)->size_bytes(mask); } zfp-1.0.1/cmake/000077500000000000000000000000001453723256400134035ustar00rootroot00000000000000zfp-1.0.1/cmake/appveyor.cmake000066400000000000000000000046211453723256400162550ustar00rootroot00000000000000 set(CTEST_SOURCE_DIRECTORY "$ENV{APPVEYOR_BUILD_FOLDER}") set(CTEST_BINARY_DIRECTORY "$ENV{APPVEYOR_BUILD_FOLDER}/build") #make the appveyor job name have a nicer form for CDash string(REPLACE ", " "-" job_details "$ENV{APPVEYOR_JOB_NAME}") set(CTEST_COMMAND ctest) include(${CTEST_SOURCE_DIRECTORY}/CTestConfig.cmake) set(CTEST_SITE "appveyor") set(CTEST_CMAKE_GENERATOR "${GENERATOR}") set(CTEST_BUILD_NAME "$ENV{APPVEYOR_REPO_BRANCH}-${job_details}") set(cfg_options -DCMAKE_BUILD_TYPE=$ENV{BUILD_TYPE} -DBUILD_TESTING_FULL=ON -DBUILD_CFP=${BUILD_CFP} -DBUILD_ZFPY=${BUILD_ZFPY} -DZFP_WITH_OPENMP=${BUILD_OPENMP} -DZFP_WITH_CUDA=${BUILD_CUDA} ) # Work-around the fact that sh.exe is on the path # for appveyor mingw builds which CMake considers # to be an error. This is sorta-hacky but works for us if(NOT ${GENERATOR} MATCHES "Visual Studio") list(APPEND cfg_options -DCMAKE_SH=CMAKE_SH-NOTFOUND ) endif() # Add the variants to the testers name so that we can report multiple # times from the same CI builder if(BUILD_OPENMP) set(CTEST_SITE "${CTEST_SITE}_openmp") endif() if(BUILD_CUDA) set(CTEST_SITE "${CTEST_SITE}_cuda") endif() if(BUILD_CFP) set(CTEST_SITE "${CTEST_SITE}_cfp") if(CFP_NAMESPACE) list(APPEND cfg_options -DCFP_NAMESPACE=${CFP_NAMESPACE} ) set(CTEST_SITE "${CTEST_SITE}namespace") endif() endif() if(BUILD_ZFPY) set(CTEST_SITE "${CTEST_SITE}_zfpy$ENV{PYTHON_VERSION}") # sanitize python include dir path (ex. windows vs linux slashes) set(PYTHON_INCLUDE_DIR "") file(TO_CMAKE_PATH "${CTEST_SOURCE_DIRECTORY}\\$ENV{VIRTUALENV_NAME}\\Include" PYTHON_INCLUDE_DIR) list(APPEND cfg_options -DPYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIR} -DPYTHON_LIBRARY=$ENV{PYTHON_LIB_PATH} ) endif() if(OMP_TESTS_ONLY) list(APPEND cfg_options -DZFP_OMP_TESTS_ONLY=1 ) endif() ctest_start(Experimental TRACK AppVeyor) ctest_configure(OPTIONS "${cfg_options}") ctest_submit(PARTS Update Notes Configure) ctest_build() ctest_submit(PARTS Build) if(BUILD_OPENMP) # only run tests not run in previous build, due to appveyor time limit (1 hour) ctest_test(PARALLEL_LEVEL 6 RETURN_VALUE rv INCLUDE ".*Omp.*") else() ctest_test(PARALLEL_LEVEL 6 RETURN_VALUE rv) endif() ctest_submit(PARTS Test) if(WITH_COVERAGE) ctest_coverage() ctest_submit(PARTS Coverage) endif() if(NOT rv EQUAL 0) message(FATAL_ERROR "Test failures occurred.") endif() zfp-1.0.1/codecov.yml000066400000000000000000000001741453723256400144720ustar00rootroot00000000000000coverage: ignore: - docs/* - examples/* - src/cuda_zfp/* - src/template/cuda* - tests/* - utils/* zfp-1.0.1/docs/000077500000000000000000000000001453723256400132535ustar00rootroot00000000000000zfp-1.0.1/docs/Makefile000066400000000000000000000011771453723256400147210ustar00rootroot00000000000000# Minimal makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = /usr/bin/python3 -msphinx SPHINXPROJ = zfp SOURCEDIR = source BUILDDIR = build all: @$(MAKE) html # Put it first so that "make" without argument is like "make help". help: @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) .PHONY: help Makefile # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) zfp-1.0.1/docs/make.bat000066400000000000000000000014451453723256400146640ustar00rootroot00000000000000@ECHO OFF pushd %~dp0 REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=python -msphinx ) set SOURCEDIR=source set BUILDDIR=build set SPHINXPROJ=zfp if "%1" == "" goto help %SPHINXBUILD% >NUL 2>NUL if errorlevel 9009 ( echo. echo.The Sphinx module was not found. Make sure you have Sphinx installed, echo.then set the SPHINXBUILD environment variable to point to the full echo.path of the 'sphinx-build' executable. Alternatively you may add the echo.Sphinx directory to PATH. echo. echo.If you don't have Sphinx installed, grab it from echo.http://sphinx-doc.org/ exit /b 1 ) %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% goto end :help %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% :end popd zfp-1.0.1/docs/requirements.txt000066400000000000000000000001211453723256400165310ustar00rootroot00000000000000sphinx-fortran==1.1.1 # required by sphinx-fortran but not installed on RTD six zfp-1.0.1/docs/source/000077500000000000000000000000001453723256400145535ustar00rootroot00000000000000zfp-1.0.1/docs/source/algorithm.rst000066400000000000000000000214041453723256400172740ustar00rootroot00000000000000.. include:: defs.rst .. _algorithm: Algorithm ========= |zfp| uses two different algorithms to support :ref:`lossy ` and :ref:`lossless ` compression. These algorithms are described in detail below. .. _algorithm-lossy: Lossy Compression ----------------- The |zfp| lossy compression scheme is based on the idea of breaking a *d*-dimensional array into independent blocks of |4powd| values each, e.g., |4by4by4| values in three dimensions. Each block is compressed/decompressed entirely independently from all other blocks. In this sense, |zfp| is similar to current hardware texture compression schemes for image coding implemented on graphics cards and mobile devices. The lossy compression scheme implemented in this version of |zfp| has evolved from the method described in the :ref:`original paper `, and can conceptually be thought of as consisting of eight sequential steps (in practice some steps are consolidated or exist only for illustrative purposes): 1. The *d*-dimensional array is partitioned into blocks of dimensions |4powd|. If the array dimensions are not multiples of four, then blocks near the boundary are padded to the next multiple of four. This padding is invisible to the application. 2. The independent floating-point values in a block are converted to what is known as a block-floating-point representation, which uses a single, common floating-point exponent for all |4powd| values. The effect of this conversion is to turn each floating-point value into a 31- or 63-bit signed integer. If the values in the block are all zero or are smaller in magnitude than the fixed-accuracy tolerance (see below), then only a single bit is stored with the block to indicate that it is "empty" and expands to all zeros. Note that the block-floating-point conversion and empty-block encoding are not performed if the input data is represented as integers rather than floating-point numbers. 3. The integers are decorrelated using a custom, high-speed, near orthogonal transform similar to the discrete cosine transform used in JPEG image coding. The transform exploits separability and is implemented efficiently in-place using the lifting scheme, requiring only 2.5 *d* integer additions and 1.5 *d* bit shifts by one per integer in *d* dimensions. If the data is "smooth," then this transform will turn most integers into small signed values clustered around zero. 4. The signed integer coefficients are reordered in a manner similar to JPEG zig-zag ordering so that statistically they appear in a roughly monotonically decreasing order. Coefficients corresponding to low frequencies tend to have larger magnitude and are listed first. In 3D, coefficients corresponding to frequencies *i*, *j*, *k* in the three dimensions are ordered by *i* + *j* + *k* first and then by *i*\ :sup:`2` + *j*\ :sup:`2` + *k*\ :sup:`2`. 5. The two's complement signed integers are converted to their negabinary (base negative two) representation using one addition and one bit-wise exclusive or per integer. Because negabinary has no single dedicated sign bit, these integers are subsequently treated as unsigned. Unlike sign-magnitude representations, the leftmost one-bit in negabinary simultaneously encodes the sign and approximate magnitude of a number. Moreover, unlike two's complement, numbers small in magnitude have many leading zeros in negabinary regardless of sign, which facilitates encoding. 6. The bits that represent the list of |4powd| integers are transposed so that instead of being ordered by coefficient they are ordered by bit plane, from most to least significant bit. Viewing each bit plane as an unsigned integer, with the lowest bit corresponding to the lowest frequency coefficient, the anticipation is that the first several of these transposed integers are small, because the coefficients are assumed to be ordered by magnitude. 7. The transform coefficients are compressed losslessly using embedded coding by exploiting the property that the coefficients tend to have many leading zeros that need not be encoded explicitly. Each bit plane is encoded in two parts, from lowest to highest bit. First, the *n* lowest bits are emitted verbatim, where *n* is the smallest number such that the |4powd| |minus| *n* highest bits in all previous bit planes are all zero. Initially, *n* = 0. Then, a variable-length representation of the remaining |4powd| |minus| *n* bits, *x*, is encoded. For such an integer *x*, a single bit is emitted to indicate if *x* = 0, in which case we are done with the current bit plane. If not, then bits of *x* are emitted, starting from the lowest bit, until a one-bit is emitted. This triggers another test whether this is the highest set bit of *x*, and the result of this test is output as a single bit. If not, then the procedure repeats until all *m* of *x*'s value bits have been output, where 2\ :sup:`m-1` |leq| *x* < 2\ :sup:`m`. This can be thought of as a run-length encoding of the zeros of *x*, where the run lengths are expressed in unary. The total number of value bits, *n*, in this bit plane is then incremented by *m* before being passed to the next bit plane, which is encoded by first emitting its *n* lowest bits. The assumption is that these bits correspond to *n* coefficients whose most significant bits have already been output, i.e., these *n* bits are essentially random and not compressible. Following this, the remaining |4powd| |minus| *n* bits of the bit plane are run-length encoded as described above, which potentially results in *n* being increased. As an example, *x* = 000001001101000 with *m* = 10 is encoded as **0**\ 100\ **1**\ 1\ **1**\ 10\ **1**\ 1000\ **1**, where the bits in boldface indicate "group tests" that determine if the remainder of *x* (to the left) contains any one-bits. Again, this variable-length code is generated and parsed from right to left. 8. The embedded coder emits one bit at a time, with each successive bit potentially improving the accuracy of the approximation. The early bits are most important and have the greatest impact on accuracy, with the last few bits providing very small changes. The resulting compressed bit stream can be truncated at any point and still allow for a valid approximate reconstruction of the original block of values. The final step truncates the bit stream in one of three ways: to a fixed number of bits (the fixed-rate mode); after some fixed number of bit planes have been encoded (the fixed-precision mode); or until a lowest bit plane number has been encoded, as expressed in relation to the common floating-point exponent within the block (the fixed-accuracy mode). Various parameters are exposed for controlling the quality and compressed size of a block, and can be specified by the user at a very fine granularity. These parameters are discussed :ref:`here `. .. _algorithm-lossless: Lossless Compression -------------------- The reversible (lossless) compression algorithm shares most steps with the lossy algorithm. The main differences are steps 2, 3, and 8, which are the only sources of error. Since step 2 may introduce loss in the conversion to |zfp|'s block-floating-point representation, the reversible algorithm adds a test to see if this conversion is lossless. It does so by converting the values back to the source format and testing the result for bitwise equality with the uncompressed data. If this test passes, then a modified decorrelating transform is performed in step 3 that uses reversible integer subtraction operations only. Finally, step 8 is modified so that no one-bits are truncated in the variable-length bit stream. However, all least significant bit planes with all-zero bits are truncated, and the number of encoded bit planes is recorded in step 7. As with lossy compression, a floating-point block consisting of all ("positive") zeros is represented as a single bit, making it possible to efficiently encode sparse data. If the block-floating-point transform is not lossless, then the reversible compression algorithm falls back on a simpler scheme that reinterprets floating-point values as integers via *type punning*. This lossless conversion from floating-point to integer data replaces step 2, and the algorithm proceeds from there with the modified step 3. Moreover, this conversion ensures that special values like infinities, NaNs, and negative zero are preserved. The lossless algorithm handles integer data also, for which step 2 is omitted. zfp-1.0.1/docs/source/arrays.rst000066400000000000000000001007121453723256400166070ustar00rootroot00000000000000.. include:: defs.rst .. _arrays: Compressed-Array C++ Classes ============================ .. cpp:namespace:: zfp |zfp|'s compressed arrays are C++ classes, plus :ref:`C wrappers ` around these classes, that implement random-accessible single- and multi-dimensional floating-point arrays. Since its first release, |zfp| provides *fixed-rate* arrays, :code:`zfp::array`, that support both read and write access to individual array elements. As of |carrrelease|, |zfp| also supports read-only arrays, :code:`zfp::const_array`, for data that is static or is updated only infrequently. The read-only arrays support all of |zfp|'s :ref:`compression modes ` including variable-rate and lossless compression. For fixed-rate arrays, the storage size, specified in number of bits per array element, is set by the user. Such arbitrary storage is achieved via |zfp|'s lossy :ref:`fixed-rate compression ` mode, by partitioning each *d*-dimensional array into blocks of |4powd| values and compressing each block to a fixed number of bits. The more smoothly the array values vary along each dimension, the more accurately |zfp| can represent them. In other words, these arrays are not suitable for representing data where adjacent elements are not correlated. Rather, the expectation is that the array represents a regularly sampled and predominantly continuous function, such as a temperature field in a physics simulation. The *rate*, measured in number of bits per array element, can be specified in fractions of a bit (but see FAQs :ref:`#12 ` and :ref:`#18 ` for limitations). |zfp| supports 1D, 2D, 3D, and (as of version |4darrrelease|) 4D arrays. For higher-dimensional arrays, consider using an array of |zfp| arrays. Note that array dimensions need not be multiples of four; |zfp| transparently handles partial blocks on array boundaries. Read-only arrays allow setting compression mode and parameters on construction, and can optionally be initialized with uncompressed data. These arrays do not allow updating individual array elements, though the contents of the whole array may be updated by re-compressing and overwriting the array. This may be useful in applications that decompress the whole array, perform a computation that updates its contents (e.g., a stencil operation that advances the solution of a PDE), and then compress to memory the updated array. The C++ templated array classes are implemented entirely as header files that call the |zfp| C library to perform compression and decompression. These arrays cache decompressed blocks to reduce the number of compression and decompression calls. Whenever an array value is read, the corresponding block is first looked up in the cache, and if found the uncompressed value is returned. Otherwise the block is first decompressed and stored in the cache. Whenever an array element is written (whether actually modified or not), a "dirty bit" is set with its cached block to indicate that the block must be compressed back to persistent storage when evicted from the cache. This section documents the public interface to the array classes, including base classes and member accessor classes like proxy references/pointers, iterators, and views. The following sections are available: * :ref:`array_classes` * :ref:`carray_classes` * :ref:`caching` * :ref:`serialization` * :ref:`references` * :ref:`pointers` * :ref:`iterators` * :ref:`views` * :ref:`codec` * :ref:`index` .. _array_classes: Read-Write Fixed-Rate Arrays ---------------------------- There are eight array classes for 1D, 2D, 3D, and 4D read-write arrays, each of which can represent single- or double-precision values. Although these arrays store values in a form different from conventional single- and double-precision floating point, the user interacts with the arrays via floats and doubles. The array classes can often serve as direct substitutes for C/C++ single- and multi-dimensional floating-point arrays and STL vectors, but have the benefit of allowing fine control over storage size. All classes below belong to the :cpp:any:`zfp` namespace. .. note:: Much of the compressed-array API was modified in |zfp| |64bitrelease| to support 64-bit indexing of very large arrays. In particular, array dimensions and indices now use the :code:`size_t` type instead of :code:`uint` and strides use the :code:`ptrdiff_t` type instead of :code:`int`. .. _array_base_class: Base Class ^^^^^^^^^^ .. cpp:class:: array Virtual base class for common array functionality. ---- .. cpp:function:: zfp_type array::scalar_type() const Return the underlying scalar type (:c:type:`zfp_type`) of the array. ---- .. cpp:function:: uint array::dimensionality() const Return the dimensionality (aka. rank) of the array: 1, 2, 3, or 4. ---- .. cpp:function:: array::header array::get_header() const Deprecated function as of |zfp| |crpirelease|. See the :ref:`header` section on how to construct a header. ---- .. _array_factory: .. cpp:function:: static array* array::construct(const header& h, const void* buffer = 0, size_t buffer_size_bytes = 0) Construct a compressed-array object whose scalar type, dimensions, and rate are given by the :ref:`header
` *h*. Return a base class pointer upon success. The optional *buffer* points to compressed data that, when passed, is copied into the array. If *buffer* is absent, the array is default initialized with all zeroes. The optional *buffer_size_bytes* parameter specifies the buffer length in bytes. When passed, a comparison is made to ensure that the buffer size is at least as large as the size implied by the header. If this function fails for any reason, an :cpp:class:`exception` is thrown. Common Methods ^^^^^^^^^^^^^^ The following methods are common to 1D, 2D, 3D, and 4D arrays, but are implemented in the array class specific to each dimensionality rather than in the base class. .. cpp:function:: size_t array::size() const Total number of elements in array, e.g., *nx* |times| *ny* |times| *nz* for 3D arrays. ---- .. cpp:function:: double array::rate() const Return rate in bits per value. ---- .. cpp:function:: double array::set_rate(double rate) Set desired compression rate in bits per value. Return the closest rate supported. See FAQ :ref:`#12 ` and FAQ :ref:`#18 ` for discussions of the rate granularity. This method destroys the previous contents of the array. ---- .. cpp:function:: size_t array::size_bytes(uint mask = ZFP_DATA_ALL) const Return storage size of components of array data structure indicated by *mask*. The mask is constructed via bitwise OR of :ref:`predefined constants `. Available as of |zfp| |carrrelease|. ---- .. cpp:function:: size_t array::compressed_size() const Return number of bytes of storage for the compressed data. This amount does not include the small overhead of other class members or the size of the cache. Rather, it reflects the size of the memory buffer returned by :cpp:func:`compressed_data`. ---- .. cpp:function:: void* array::compressed_data() const Return pointer to compressed data for read or write access. The size of the buffer is given by :cpp:func:`compressed_size`. .. note:: As of |zfp| |crpirelease|, the return value is :code:`void*` rather than :code:`uchar*` to simplify pointer conversion and to dispel any misconception that the compressed data needs only :code:`uchar` alignment. Compressed streams are always word aligned (see :c:var:`stream_word_bits` and :c:macro:`BIT_STREAM_WORD_TYPE`). ---- .. cpp:function:: size_t array::cache_size() const Return the cache size in number of bytes. ---- .. cpp:function:: void array::set_cache_size(size_t bytes) Set minimum cache size in bytes. The actual size is always a power of two bytes and consists of at least one block. If *bytes* is zero, then a default cache size is used, which requires the array dimensions to be known. ---- .. cpp:function:: void array::clear_cache() const Empty cache without compressing modified cached blocks, i.e., discard any cached updates to the array. ---- .. cpp:function:: virtual void array::flush_cache() const Flush cache by compressing all modified cached blocks back to persistent storage and emptying the cache. This method should be called before writing the compressed representation of the array to disk, for instance. ---- .. cpp:function:: void array::get(Scalar* p) const Decompress entire array and store at *p*, for which sufficient storage must have been allocated. The uncompressed array is assumed to be contiguous (with default strides) and stored in the usual "row-major" order, i.e., with *x* varying faster than *y*, *y* varying faster than *z*, etc. ---- .. cpp:function:: void array::set(const Scalar* p) Initialize array by copying and compressing data stored at *p*. The uncompressed data is assumed to be stored as in the :cpp:func:`get` method. If *p* = 0, then the array is zero-initialized. ---- .. cpp:function:: const_reference array::operator[](size_t index) const Return :ref:`const reference ` to scalar stored at given flat index (inspector). For a 3D array, :code:`index = x + nx * (y + ny * z)`. .. note:: As of |zfp| |crpirelease|, the return value is no longer :code:`Scalar` but is a :ref:`const reference ` to the corresponding array element (conceptually equivalent to :code:`const Scalar&`). This API change was necessary to allow obtaining a const pointer to the element when the array itself is const qualified, e.g., :code:`const_pointer p = &a[index];`. ---- .. _lvref_idx: .. cpp:function:: reference array::operator[](size_t index) Return :ref:`proxy reference ` to scalar stored at given flat index (mutator). For a 3D array, :code:`index = x + nx * (y + ny * z)`. ---- .. cpp:function:: iterator array::begin() Return random-access mutable iterator to beginning of array. ---- .. cpp:function:: iterator array::end() Return random-access mutable iterator to end of array. As with STL iterators, the end points to a virtual element just past the last valid array element. ---- .. cpp:function:: const_iterator array::begin() const .. cpp:function:: const_iterator array::cbegin() const Return random-access const iterator to beginning of array. ---- .. cpp:function:: const_iterator array::end() const .. cpp:function:: const_iterator array::cend() const Return random-access const iterator to end of array. .. note:: Const :ref:`references `, :ref:`pointers `, and :ref:`iterators ` are available as of |zfp| |crpirelease|. 1D, 2D, 3D, and 4D Arrays ^^^^^^^^^^^^^^^^^^^^^^^^^ Below are classes and methods specific to each array dimensionality and template scalar type (:code:`float` or :code:`double`). Since the classes and methods share obvious similarities regardless of dimensionality, only one generic description for all dimensionalities is provided. Note: In the class declarations below, the class template for the scalar type is omitted for readability, e.g., :code:`class array1` is used as shorthand for :code:`template class array1`. Wherever the type :code:`Scalar` appears, it refers to this template argument. .. .. cpp:class:: template array1 : public array .. cpp:class:: template array2 : public array .. cpp:class:: template array3 : public array .. cpp:class:: template array4 : public array .. cpp:class:: array1 : public array .. cpp:class:: array2 : public array .. cpp:class:: array3 : public array .. cpp:class:: array4 : public array This is a 1D, 2D, 3D, or 4D array that inherits basic functionality from the generic :cpp:class:`array` base class. The template argument, :cpp:type:`Scalar`, specifies the floating type returned for array elements. The suffixes :code:`f` and :code:`d` can also be appended to each class to indicate float or double type, e.g., :cpp:class:`array1f` is a synonym for :cpp:class:`array1\`. ---- .. cpp:class:: arrayANY : public array Fictitious class used to refer to any one of :cpp:class:`array1`, :cpp:class:`array2`, :cpp:class:`array3`, and :cpp:class:`array4`. This class is not part of the |zfp| API. ---- .. _array_ctor_default: .. cpp:function:: array1::array1() .. cpp:function:: array2::array2() .. cpp:function:: array3::array3() .. cpp:function:: array4::array4() Default constructor. Creates an empty array whose size and rate are both zero. .. note:: The default constructor is useful when the array size or rate is not known at time of construction. Before the array can become usable, however, it must be :ref:`resized ` and its rate must be set via :cpp:func:`array::set_rate`. These two tasks can be performed in either order. Furthermore, the desired cache size should be set using :cpp:func:`array::set_cache_size`, as the default constructor creates a cache that holds only one |zfp| block, i.e., the minimum possible. ---- .. _array_ctor: .. cpp:function:: array1::array1(size_t n, double rate, const Scalar* p = 0, size_t cache_size = 0) .. cpp:function:: array2::array2(size_t nx, size_t ny, double rate, const Scalar* p = 0, size_t cache_size = 0) .. cpp:function:: array3::array3(size_t nx, size_t ny, size_t nz, double rate, const Scalar* p = 0, size_t cache_size = 0) .. cpp:function:: array4::array4(size_t nx, size_t ny, size_t nz, size_t nw, double rate, const Scalar* p = 0, size_t cache_size = 0) Constructor of array with dimensions *n* (1D), *nx* |times| *ny* (2D), *nx* |times| *ny* |times| *nz* (3D), or *nx* |times| *ny* |times| *nz* |times| *nw* (4D) using *rate* bits per value, at least *cache_size* bytes of cache, and optionally initialized from flat, uncompressed array *p*. If *cache_size* is zero, a default cache size suitable for the array dimensions is chosen. ---- .. _array_ctor_header: .. cpp:function:: array1::array1(const array::header& h, const void* buffer = 0, size_t buffer_size_bytes = 0) .. cpp:function:: array2::array2(const array::header& h, const void* buffer = 0, size_t buffer_size_bytes = 0) .. cpp:function:: array3::array3(const array::header& h, const void* buffer = 0, size_t buffer_size_bytes = 0) .. cpp:function:: array4::array4(const array::header& h, const void* buffer = 0, size_t buffer_size_bytes = 0) Constructor from previously :ref:`serialized ` compressed array. The :ref:`header
`, *h*, contains array metadata, while the optional *buffer* points to the compressed data that is to be copied to the array. The optional *buffer_size_bytes* parameter specifies the *buffer* length. If the constructor fails, an :ref:`exception ` is thrown. See :cpp:func:`array::construct` for further details on the *buffer* and *buffer_size_bytes* parameters. ---- .. _array_copy_constructor: .. cpp:function:: array1::array1(const array1& a) .. cpp:function:: array2::array2(const array2& a) .. cpp:function:: array3::array3(const array3& a) .. cpp:function:: array4::array4(const array4& a) Copy constructor. Performs a deep copy. ---- .. cpp:function:: virtual array1::~array1() .. cpp:function:: virtual array2::~array2() .. cpp:function:: virtual array3::~array3() .. cpp:function:: virtual array4::~array4() Virtual destructor (allows for inheriting from |zfp| arrays). ---- .. _array_copy: .. cpp:function:: array1& array1::operator=(const array1& a) .. cpp:function:: array2& array2::operator=(const array2& a) .. cpp:function:: array3& array3::operator=(const array3& a) .. cpp:function:: array4& array4::operator=(const array4& a) Assignment operator. Performs a deep copy. ---- .. _array_dims: .. cpp:function:: size_t array2::size_x() const .. cpp:function:: size_t array2::size_y() const .. cpp:function:: size_t array3::size_x() const .. cpp:function:: size_t array3::size_y() const .. cpp:function:: size_t array3::size_z() const .. cpp:function:: size_t array4::size_x() const .. cpp:function:: size_t array4::size_y() const .. cpp:function:: size_t array4::size_z() const .. cpp:function:: size_t array4::size_w() const Return array dimensions. ---- .. _array_resize: .. cpp:function:: void array1::resize(size_t n, bool clear = true) .. cpp:function:: void array2::resize(size_t nx, size_t ny, bool clear = true) .. cpp:function:: void array3::resize(size_t nx, size_t ny, size_t nz, bool clear = true) .. cpp:function:: void array4::resize(size_t nx, size_t ny, size_t nz, size_t nw, bool clear = true) Resize the array (all previously stored data will be lost). If *clear* is true, then the array elements are all initialized to zero. .. note:: It is often desirable (though not a requirement) to also set the cache size when resizing an array, e.g., in proportion to the array size; see :cpp:func:`array::set_cache_size`. This is particularly important when the array is default constructed, which initializes the cache size to the minimum possible of only one |zfp| block. ---- .. _array_accessor: .. cpp:function:: const_reference array1::operator()(size_t i) const .. cpp:function:: const_reference array2::operator()(size_t i, size_t j) const .. cpp:function:: const_reference array3::operator()(size_t i, size_t j, size_t k) const .. cpp:function:: const_reference array4::operator()(size_t i, size_t j, size_t k, size_t l) const Return const reference to element stored at multi-dimensional index given by *i*, *j*, *k*, and *l* (inspector). .. note:: As of |zfp| |crpirelease|, the return value is no longer :code:`Scalar` but is a :ref:`const reference ` to the corresponding array element (essentially equivalent to :code:`const Scalar&`). This API change was necessary to allow obtaining a const pointer to the element when the array itself is const qualified, e.g., :code:`const_pointer p = &a(i, j, k);`. ---- .. _lvref: .. cpp:function:: reference array1::operator()(size_t i) .. cpp:function:: reference array2::operator()(size_t i, size_t j) .. cpp:function:: reference array3::operator()(size_t i, size_t j, size_t k) .. cpp:function:: reference array4::operator()(size_t i, size_t j, size_t k, size_t l) Return :ref:`proxy reference ` to scalar stored at multi-dimensional index given by *i*, *j*, *k*, and *l* (mutator). .. _carray_classes: Read-Only Variable-Rate Arrays ------------------------------ Read-only arrays are preferable in applications that store static data, e.g., constant tables or simulation output, or data that is updated only periodically as a whole, such as when advancing the solution of a partial differential equation. Because such updates have to be applied to the whole array, one may choose to tile large arrays into smaller |zfp| arrays to support finer granularity updates. Read-only arrays have the benefit of supporting all of |zfp|'s :ref:`compression modes `, most of which provide higher accuracy per bit stored than fixed-rate mode. The read-only arrays share an API with the read-write fixed-rate arrays, with only a few differences: - All methods other than those that specify array-wide settings, such as compression mode and parameters, array dimensions, and array contents, are :code:`const` qualified. There are, thus, no methods for obtaining a writeable reference, pointer, or iterator. Consequently, one may not initialize such arrays one element at a time. Rather, the user initializes the whole array by passing a pointer to uncompressed data. - Whereas the constructors for fixed-rate arrays accept a *rate* parameter, the read-only arrays allow specifying any compression mode and corresponding parameters (if any) via a :c:type:`zfp_config` object. - Additional methods are available for setting and querying compression mode and parameters after construction. - Read-only arrays are templated on a block index class that encodes the bit offset to each block of data. Multiple index classes are available that trade compactness and speed of access. The default :cpp:class:`hybrid4` index represents 64-bit offsets using only 24 bits of amortized storage per block. An "implicit" index is available for fixed-rate read-only arrays, which computes rather than stores offsets to equal-sized blocks. .. note:: Whereas variable-rate compression almost always improves accuracy per bit of compressed data over fixed rate, one should also weigh the storage and compute overhead associated with the block index needed for variable-rate storage. The actual storage overhead can be determined by passing :c:macro:`ZFP_DATA_INDEX` to :cpp:func:`const_array::size_bytes`. This overhead tends to be small for 3D and 4D arrays. Array initialization may be done at construction time, by passing a pointer to uncompressed data, or via the method :cpp:func:`const_array::set`, which overwrites the contents of the whole array. This method may be called more than once to update (i.e., re-initialize) the array. Read-only arrays support a subset of references, pointers, iterators, and views; in particular those with a :code:`const_` prefix. Currently, not all capabilities of read-write arrays are available for read-only arrays. For example, (de)serialization and construction from a view have not yet been implemented, and there are no C bindings. Read-only arrays derive from the :ref:`array base class `. Additional methods are documented below. .. .. cpp:class:: template const_array1 : public array .. cpp:class:: template const_array2 : public array .. cpp:class:: template const_array3 : public array .. cpp:class:: template const_array4 : public array .. cpp:class:: const_array1 : public array .. cpp:class:: const_array2 : public array .. cpp:class:: const_array3 : public array .. cpp:class:: const_array4 : public array 1D, 2D, 3D, or 4D read-only array that inherits basic functionality from the generic :cpp:class:`array` base class. The template argument, :cpp:type:`Scalar`, specifies the floating type returned for array elements. The suffixes :code:`f` and :code:`d` can also be appended to each class to indicate float or double type, e.g., :cpp:class:`const_array1f` is a synonym for :cpp:class:`const_array1\`. ---- .. cpp:class:: const_array : public array Fictitious class used to denote one of the 1D, 2D, 3D, and 4D read-only array classes. This pseudo base class serves only to document the API shared among the four arrays. ---- .. _carray_ctor_default: .. cpp:function:: const_array1::const_array1() .. cpp:function:: const_array2::const_array2() .. cpp:function:: const_array3::const_array3() .. cpp:function:: const_array4::const_array4() Default constructor. Creates an empty array whose size is zero and whose compression mode is unspecified. The array's cache size is initialized to the minimum possible, which can have performance implications; see :ref:`this note `. ---- .. _carray_ctor: .. cpp:function:: const_array1::const_array1(size_t n, const zfp_config& config, const Scalar* p = 0, size_t cache_size = 0) .. cpp:function:: const_array2::const_array2(size_t nx, size_t ny, const zfp_config& config, const Scalar* p = 0, size_t cache_size = 0) .. cpp:function:: const_array3::const_array3(size_t nx, size_t ny, size_t nz, const zfp_config& config, const Scalar* p = 0, size_t cache_size = 0) .. cpp:function:: const_array4::const_array4(size_t nx, size_t ny, size_t nz, size_t nw, const zfp_config& config, const Scalar* p = 0, size_t cache_size = 0) Constructor of array with dimensions *n* (1D), *nx* |times| *ny* (2D), *nx* |times| *ny* |times| *nz* (3D), or *nx* |times| *ny* |times| *nz* |times| *nw* (4D). The compression mode and parameters are given by *config* (see :ref:`configuration `). The array uses at least *cache_size* bytes of cache, and is optionally initialized from flat, uncompressed array *p*. If *cache_size* is zero, a default cache size suitable for the array dimensions is chosen. ---- .. cpp:function:: const_array1::const_array1(const const_array1& a) .. cpp:function:: const_array2::const_array2(const const_array2& a) .. cpp:function:: const_array3::const_array3(const const_array3& a) .. cpp:function:: const_array4::const_array4(const const_array4& a) Copy constructor. Performs a deep copy. ---- .. cpp:function:: virtual const_array1::~const_array1() .. cpp:function:: virtual const_array2::~const_array2() .. cpp:function:: virtual const_array3::~const_array3() .. cpp:function:: virtual const_array4::~const_array4() Virtual destructor (allows for inheritance). ---- .. _carray_copy: .. cpp:function:: const_array1& const_array1::operator=(const const_array1& a) .. cpp:function:: const_array2& const_array2::operator=(const const_array2& a) .. cpp:function:: const_array3& const_array3::operator=(const const_array3& a) .. cpp:function:: const_array4& const_array4::operator=(const const_array4& a) Assignment operator. Performs a deep copy. ---- .. cpp:function:: size_t const_array::size() const Total number of elements in array, e.g., *nx* |times| *ny* |times| *nz* for 3D arrays. ---- .. _carray_dims: .. cpp:function:: size_t const_array2::size_x() const .. cpp:function:: size_t const_array2::size_y() const .. cpp:function:: size_t const_array3::size_x() const .. cpp:function:: size_t const_array3::size_y() const .. cpp:function:: size_t const_array3::size_z() const .. cpp:function:: size_t const_array4::size_x() const .. cpp:function:: size_t const_array4::size_y() const .. cpp:function:: size_t const_array4::size_z() const .. cpp:function:: size_t const_array4::size_w() const Return array dimensions. ---- .. _carray_resize: .. cpp:function:: void const_array1::resize(size_t n, bool clear = true) .. cpp:function:: void const_array2::resize(size_t nx, size_t ny, bool clear = true) .. cpp:function:: void const_array3::resize(size_t nx, size_t ny, size_t nz, bool clear = true) .. cpp:function:: void const_array4::resize(size_t nx, size_t ny, size_t nz, size_t nw, bool clear = true) Resize the array (all previously stored data will be lost). If *clear* is true, then the array elements are all initialized to zero. See also :ref:`this note `. ---- .. cpp:function:: zfp_mode const_array::mode() const Currently selected :ref:`compression mode `. If not yet specified, :code:`zfp_mode_null` is returned. ---- .. cpp:function:: double const_array::rate() const Return rate in compressed bits per value when :ref:`fixed-rate mode ` is enabled, else zero. ---- .. cpp:function:: uint const_array::precision() const Return precision in uncompressed bits per value when :ref:`fixed-precision mode ` is enabled, else zero. ---- .. cpp:function:: double const_array::accuracy() const Return accuracy as absolute error tolerance when :ref:`fixed-accuracy mode ` is enabled, else zero. ---- .. cpp:function:: void const_array::params(uint* minbits, uint* maxbits, uint* maxprec, int* minexp) const :ref:`Expert mode ` compression parameters (available for all compression modes). Pointers may be :code:`null` if the corresponding parameter is not requested. ---- .. cpp:function:: double const_array::set_reversible() Enable :ref:`reversible mode `. This method destroys the previous contents of the array. ---- .. cpp:function:: double const_array::set_rate(double rate) Set desired rate in compressed bits per value (enables :ref:`fixed-rate mode `). This method destroys the previous contents of the array. See also :cpp:func:`array::set_rate`. .. note:: Whereas the :ref:`read-write fixed-rate arrays ` (:cpp:class:`zfp::array`) require that block storage is word aligned, the read-only arrays (:cpp:class:`zfp::const_array`) are not subject to such restrictions and therefore support finer rate granularity. For a *d*-dimensional :cpp:class:`const_array`, the rate granularity is 4\ :sup:`-d` bits/value, e.g., a quarter bit/value for 1D arrays. ---- .. cpp:function:: uint const_array::set_precision(uint precision) Set desired precision in uncompressed bits per value (enables :ref:`fixed-precision mode `). This method destroys the previous contents of the array. ---- .. cpp:function:: double const_array::set_accuracy(double tolerance) Set desired accuracy as absolute error tolerance (enables :ref:`fixed-accuracy mode `). This method destroys the previous contents of the array. ---- .. cpp:function:: bool const_array::set_params(uint minbits, uint maxbits, uint maxprec, int minexp) Set :ref:`expert mode ` parameters. This method destroys the previous contents of the array. Return whether the codec supports the combination of parameters. ---- .. cpp:function:: void const_array::set_config(const zfp_config& config) Set compression mode and parameters given by *config* (see :ref:`configuration `). This is a more general method for setting compression parameters such as rate, precision, accuracy, and :ref:`expert mode ` parameters. ---- .. cpp:function:: size_t const_array::size_bytes(uint mask = ZFP_DATA_ALL) const Return storage size of components of array data structure indicated by *mask*. The mask is constructed via bitwise OR of :ref:`predefined constants `. ---- .. cpp:function:: size_t const_array::compressed_size() const Return number of bytes of storage for the compressed data. This amount does not include the small overhead of other class members or the size of the cache. Rather, it reflects the size of the memory buffer returned by :cpp:func:`compressed_data`. ---- .. cpp:function:: void* const_array::compressed_data() const Return pointer to compressed data for read or write access. The size of the buffer is given by :cpp:func:`compressed_size`. ---- .. cpp:function:: size_t const_array::cache_size() const Return the cache size in number of bytes. ---- .. cpp:function:: void const_array::set_cache_size(size_t bytes) Set minimum cache size in bytes. The actual size is always a power of two bytes and consists of at least one block. If *bytes* is zero, then a default cache size is used, which requires the array dimensions to be known. ---- .. cpp:function:: void const_array::clear_cache() const Empty cache. ---- .. cpp:function:: void const_array::get(Scalar* p) const Decompress entire array and store at *p*, for which sufficient storage must have been allocated. The uncompressed array is assumed to be contiguous (with default strides) and stored in the usual "row-major" order, i.e., with *x* varying faster than *y*, *y* varying faster than *z*, etc. ---- .. cpp:function:: void const_array::set(const Scalar* p, bool compact = true) Initialize array by copying and compressing floating-point data stored at *p*. If *p* = 0, then the array is zero-initialized. The uncompressed data is assumed to be stored as in the :cpp:func:`get` method. Since the size of compressed data may not be known a priori, this method conservatively allocates enough space to hold it. If *compact* is true, any unused storage for compressed data is freed after initialization. ---- .. _const_array_accessor: .. cpp:function:: const_reference const_array1::operator()(size_t i) const .. cpp:function:: const_reference const_array2::operator()(size_t i, size_t j) const .. cpp:function:: const_reference const_array3::operator()(size_t i, size_t j, size_t k) const .. cpp:function:: const_reference const_array4::operator()(size_t i, size_t j, size_t k, size_t l) const Return const reference to element stored at multi-dimensional index given by *i*, *j*, *k*, and *l* (inspector). ---- .. cpp:function:: const_reference const_array::operator[](size_t index) const Return :ref:`const reference ` to scalar stored at given flat index (inspector). For a 3D array, :code:`index = x + nx * (y + ny * z)`. ---- .. cpp:function:: const_iterator const_array::begin() const .. cpp:function:: const_iterator const_array::cbegin() const Return random-access const iterator to beginning of array. ---- .. cpp:function:: const_iterator end() const .. cpp:function:: const_iterator cend() const Return random-access const iterator to end of array. .. include:: caching.inc .. include:: serialization.inc .. include:: references.inc .. include:: pointers.inc .. include:: iterators.inc .. include:: views.inc .. include:: codec.inc .. include:: index.inc zfp-1.0.1/docs/source/bit-stream.rst000066400000000000000000000221741453723256400173620ustar00rootroot00000000000000.. include:: defs.rst .. _bs-api: Bit Stream API ============== |zfp| relies on low-level functions for bit stream I/O, e.g., for reading/writing single bits or groups of bits. |zfp|'s bit streams support random access (with some caveats) and, optionally, strided access. The functions read from and write to main memory allocated by the user. Buffer overruns are for performance reasons not guarded against. From an implementation standpoint, bit streams are read from and written to memory in increments of *words* of bits. The constant power-of-two word size is configured at :ref:`compile time `, and is limited to 8, 16, 32, or 64 bits. The bit stream API is publicly exposed and may be used to write additional information such as metadata into the |zfp| compressed stream and to manipulate whole or partial bit streams. Moreover, we envision releasing the bit stream functions as a separate library in the future that may be used, for example, in other compressors. Stream readers and writers are synchronized by making corresponding calls. For each write call, there is a corresponding read call. This ensures that reader and writer agree on the position within the stream and the number of bits buffered, if any. The API below reflects this duality. A bit stream is either in read or write mode, or either, if rewound to the beginning. When in read mode, only read calls should be made, and similarly for write mode. .. _bs-strides: Strided Streams --------------- Bit streams may be strided by sequentially reading/writing a few words at a time and then skipping over some user-specified number of words. This allows, for instance, |zfp| to interleave the first few bits of all compressed blocks in order to support progressive access. To enable strided access, which does carry a small performance penalty, the macro :c:macro:`BIT_STREAM_STRIDED` must be defined during compilation. Strides are specified in terms of a *block size*---a power-of-two number of contiguous words---and a *delta*, which specifies how many words to advance the stream by to get to the next contiguous block. These bit stream blocks are entirely independent of the |4powd| blocks used for compression in |zfp|. Setting *delta* to zero ensures a non-strided, sequential layout. .. _bs-macros: Macros ------ Two compile-time macros are used to influence the behavior: :c:macro:`BIT_STREAM_WORD_TYPE` and :c:macro:`BIT_STREAM_STRIDED`. These are documented in the :ref:`installation ` section. .. _bs-types: Types ----- .. c:type:: bitstream_word Bits are buffered and read/written in units of words. By default, the bit stream word type is 64 bits, but may be set to 8, 16, or 32 bits by setting the macro :c:macro:`BIT_STREAM_WORD_TYPE` to :c:type:`uint8`, :c:type:`uint16`, or :c:type:`uint32`, respectively. Larger words tend to give higher throughput, while 8-bit words are needed to ensure endian independence (see FAQ :ref:`#11 `). .. note:: To avoid potential name clashes, this type was renamed in |zfp| |64bitrelease| from the shorter and more ambiguous type name :code:`word`. ---- .. c:type:: bitstream_offset Type holding the offset, measured in number of bits, into the bit stream where the next bit will be read or written. This type allows referencing bits in streams at least 2\ :sup:`64` bits long. Note that it is possible that :code:`sizeof(bitstream_offset) > sizeof(size_t)` since a stream may be as long as `sizeof(size_t) * CHAR_BIT` bits. ---- .. c:type:: bitstream_size Alias for :c:type:`bitstream_offset` that signifies the bit length of a stream or substream rather than an offset into it. ---- .. c:type:: bitstream_count Type sufficient to count the number of bits read or written in functions like :c:func:`stream_read_bits` and :c:func:`stream_write_bits`. :code:`sizeof(bitstream_count) <= sizeof(bitstream_size)`. ---- .. c:type:: bitstream The bit stream struct maintains all the state associated with a bit stream. This struct is passed to all bit stream functions. Its members should not be accessed directly. :: struct bitstream { bitstream_count bits; // number of buffered bits (0 <= bits < word size) bitstream_word buffer; // incoming/outgoing bits (buffer < 2^bits) bitstream_word* ptr; // pointer to next word to be read/written bitstream_word* begin; // beginning of stream bitstream_word* end; // end of stream (not enforced) size_t mask; // one less the block size in number of words (if BIT_STREAM_STRIDED) ptrdiff_t delta; // number of words between consecutive blocks (if BIT_STREAM_STRIDED) }; .. _bs-data: Constants --------- .. c:var:: const size_t stream_word_bits The number of bits in a word. The size of a flushed bit stream will be a multiple of this number of bits. See :c:macro:`BIT_STREAM_WORD_TYPE` and :c:func:`stream_alignment`. .. _bs-functions: Functions --------- .. c:function:: bitstream* stream_open(void* buffer, size_t bytes) Allocate a :c:type:`bitstream` struct and associate it with the memory buffer allocated by the caller. ---- .. c:function:: void stream_close(bitstream* stream) Close the bit stream and deallocate *stream*. ---- .. c:function:: bitstream* stream_clone(const bitstream* stream) Create a copy of *stream* that points to the same memory buffer. ---- .. c:function:: bitstream_count stream_alignment() Word size in bits. This is a functional form of the constant :c:var:`stream_word_bits` and returns the same value. Available since |zfp| |crpirelease|. ---- .. c:function:: void* stream_data(const bitstream* stream) Return pointer to the beginning of bit stream *stream*. ---- .. c:function:: size_t stream_size(const bitstream* stream) Return position of stream pointer in number of bytes, which equals the end of stream if no seeks have been made. Note that additional bits may be buffered and not reported unless the stream has been flushed. ---- .. c:function:: size_t stream_capacity(const bitstream* stream) Return byte size of memory buffer associated with *stream* specified in :c:func:`stream_open`. ---- .. c:function:: uint stream_read_bit(bitstream* stream) Read a single bit from *stream*. ---- .. c:function:: uint stream_write_bit(bitstream* stream, uint bit) Write single *bit* to *stream*. *bit* must be one of 0 or 1. The value of *bit* is returned. ---- .. c:function:: uint64 stream_read_bits(bitstream* stream, bitstream_count n) Read and return 0 |leq| *n* |leq| 64 bits from *stream*. ---- .. c:function:: uint64 stream_write_bits(bitstream* stream, uint64 value, bitstream_count n) Write 0 |leq| *n* |leq| 64 low bits of *value* to *stream*. Return any remaining bits from *value*, i.e., *value* >> *n*. ---- .. c:function:: bitstream_offset stream_rtell(const bitstream* stream) Return bit offset to next bit to be read. ---- .. c:function:: bitstream_offset stream_wtell(const bitstream* stream) Return bit offset to next bit to be written. ---- .. c:function:: void stream_rewind(bitstream* stream) Rewind stream to beginning of memory buffer. Following this call, the stream may either be read or written. ---- .. c:function:: void stream_rseek(bitstream* stream, bitstream_offset offset) Position stream for reading at given bit offset. This places the stream in read mode. ---- .. c:function:: void stream_wseek(bitstream* stream, bitstream_offset offset) Position stream for writing at given bit offset. This places the stream in write mode. ---- .. c:function:: void stream_skip(bitstream* stream, bitstream_count n) Skip over the next *n* bits, i.e., without reading them. ---- .. c:function:: void stream_pad(bitstream* stream, bitstream_count n) Append *n* zero-bits to *stream*. ---- .. c:function:: bitstream_count stream_align(bitstream* stream) Align stream on next word boundary by skipping bits, i.e., without reading them. No skipping is done if the stream is already word aligned. Return the number of skipped bits, if any. ---- .. c:function:: bitstream_count stream_flush(bitstream* stream) Write out any remaining buffered bits. When one or more bits are buffered, append zero-bits to the stream to align it on a word boundary. Return the number of bits of padding, if any. ---- .. c:function:: void stream_copy(bitstream* dst, bitstream* src, bitstream_size n) Copy *n* bits from *src* to *dst*, advancing both bit streams. ---- .. c:function:: size_t stream_stride_block(const bitstream* stream) Return stream block size in number of words. The block size is always one word unless strided streams are enabled. See :ref:`bs-strides` for more information. ---- .. c:function:: ptrdiff_t stream_stride_delta(const bitstream* stream) Return stream delta in number of words between blocks. See :ref:`bs-strides` for more information. ---- .. c:function:: int stream_set_stride(bitstream* stream, size_t block, ptrdiff_t delta) Set block size, *block*, in number of words and spacing, *delta*, in number of blocks for :ref:`strided access `. Return nonzero upon success. Requires :c:macro:`BIT_STREAM_STRIDED`. zfp-1.0.1/docs/source/caching.inc000066400000000000000000000040621453723256400166440ustar00rootroot00000000000000.. _caching: Caching ------- As mentioned above, the array classes maintain a software write-back cache of at least one uncompressed block. When a block in this cache is evicted (e.g., due to a conflict), it is compressed back to permanent storage only if it was modified while stored in the cache. The size cache to use is specified by the user and is an important parameter that needs careful consideration in order to balance the extra memory usage, performance, and quality (recall that data loss is incurred only when a block is evicted from the cache and compressed). Although the best choice varies from one application to another, we suggest allocating at least two "layers" of blocks, e.g., 2 |times| (*nx* / 4) |times| (*ny* / 4) blocks for 3D arrays, for applications that stream through the array and perform stencil computations such as gathering data from neighboring elements. This allows limiting the cache misses to compulsory ones. If the *cache_size* parameter provided to the constructor is set to zero bytes, then a default cache size of at least |sqrt|\ *n* blocks is used, where *n* is the total number of blocks contained in the array. The cache size can be set during construction, or can be set at a later time via :cpp:func:`array::set_cache_size`. Note that if *cache_size* = 0, then the array dimensions must have already been specified for the default size to be computed correctly. When the cache is resized, it is first flushed if not already empty. The cache can also be flushed explicitly if desired by calling :cpp:func:`array::flush_cache`. To empty the cache without compressing any cached data, call :cpp:func:`array::clear_cache`. To query the byte size of the cache, use :cpp:func:`array::cache_size`. By default, a direct-mapped cache is used with a hash function that maps block indices to cache lines. A faster but more collision prone hash can be enabled by defining the preprocessor macro :c:macro:`ZFP_WITH_CACHE_FAST_HASH`. A two-way skew-associative cache is enabled by defining the preprocessor macro :c:macro:`ZFP_WITH_CACHE_TWOWAY`. zfp-1.0.1/docs/source/cfp.rst000066400000000000000000000767541453723256400161000ustar00rootroot00000000000000.. include:: defs.rst .. index:: single: cfp .. _cfp: Compressed-Array C Bindings =========================== .. cpp:namespace:: zfp |zfp| |cfprelease| adds |cfp|: C language bindings for compressed arrays via wrappers around the :ref:`C++ classes `. |zfp| |crpirelease| modifies its API (see below). The C API has been designed to facilitate working with compressed arrays without the benefits of C++ operator overloading and self-aware objects, which greatly simplify the syntax. Whereas one possible design considered is to map each C++ method to a C function with a prefix, such as :code:`zfp_array3d_get(a, i, j, k)` in place of :code:`a(i, j, k)` for accessing an element of a 3D array of doubles, such code would quickly become unwieldy when part of longer expressions. Instead, |cfp| uses the notion of nested C *namespaces* that are structs of function pointers, such as :code:`cfp.array3d`. Although this may seem no more concise than a design based on prefixes, the user may alias these namespaces (somewhat similar to C++ :code:`using namespace` declarations) using far shorter names via C macros or local variables. For instance:: const cfp_array3d_api _ = cfp.array3d; // _ is a namespace alias cfp_array3d a = _.ctor(nx, ny, nz, rate, 0, 0); double value = _.get(a, i, j, k); _.set(a, i, j, k, value + 1); which is a substitute for the C++ code :: zfp::array3d a(nx, ny, nz, rate, 0, 0); double value = a(i, j, k); a(i, j, k) = value + 1; Because the underlying C++ array objects have no corresponding C representation, and because C objects are not self aware (they have no implicit :code:`this` pointer), the C interface interacts with compressed arrays through array object *pointers*, wrapped in structs, that |cfp| converts to pointers to the corresponding C++ objects. As a consequence, |cfp| compressed arrays must be allocated on the heap and must be explicitly freed via designated destructor functions to avoid memory leaks (this is not necessary for references, pointers, and iterators, which have their own C representation). The C++ constructors are mapped to C by allocating objects via C++ :code:`new`. Moreover, the C API requires passing an array *self pointer* (wrapped within a cfp array struct) in order to manipulate the array. As with the :ref:`C++ classes `, array elements can be accessed via multidimensional array indexing, e.g., :code:`get(array, i, j)`, and via flat, linear indexing, e.g., :code:`get_flat(array, i + nx * j)`. .. note:: The |cfp| API changed in |zfp| |crpirelease| by wrapping array *self pointers* in structs to align the interface more closely with the C++ API and to avoid confusion when discussing arrays (now :code:`cfp.array` rather than :code:`cfp.array*`) and pointers to arrays (now :code:`cfp.array*` rather than :code:`cfp.array**`). Furthermore, |zfp| |crpirelease| adds support for proxy references, proxy pointers, and iterators that also wrap C++ classes. Manipulating those indirectly via pointers (like the old |cfp| arrays) would require additional user effort to destroy dynamically allocated lightweight objects and would also reduce code readability, e.g., :code:`cfp_ptr1d*` (whose corresponding C++ type is :code:`zfp::array1d::pointer*`) reads more naturally as a raw pointer to a proxy pointer than an indirectly referenced proxy pointer object that the user must remember to implicitly dereference. The following sections are available: * :ref:`cfp_arrays` * :ref:`cfp_serialization` * :ref:`cfp_references` * :ref:`cfp_pointers` * :ref:`cfp_iterators` .. _cfp_arrays: Arrays ------ |cfp| implements eight array types for 1D, 2D, 3D, and 4D arrays of floats and doubles. These array types share many functions that have the same signature. To reduce redundancy in the documentation, we define fictitious types :c:type:`cfp_arrayf` and :c:type:`cfp_arrayd` for *N*-dimensional (1 |leq| *N* |leq| 4) arrays of floats or doubles, :c:type:`cfp_array1`, :c:type:`cfp_array2`, :c:type:`cfp_array3`, and :c:type:`cfp_array4` for 1D, 2D, 3D, and 4D arrays of either floats or doubles, and :c:type:`cfp_array` for arrays of any dimensionality and type. We also make use of corresponding namespaces, e.g., :c:struct:`cfp.array1` refers to the API common to one-dimensional arrays of floats or doubles. These types and namespaces are not actually part of the |cfp| API. .. note:: The |cfp| array API makes use of :code:`const` qualifiers for :code:`struct` parameters (passed by value) merely to indicate when the corresponding object is not modified, e.g., :code:`const cfp_array1f self`. This construction serves to document functions that are analogous to :code:`const` qualified C++ member functions. .. note:: Support for 4D arrays was added to cfp in version |crpirelease|. .. c:type:: cfp_array1f .. c:type:: cfp_array1d .. c:type:: cfp_array2f .. c:type:: cfp_array2d .. c:type:: cfp_array3f .. c:type:: cfp_array3d .. c:type:: cfp_array4f .. c:type:: cfp_array4d Opaque types for 1D, 2D, 3D, and 4D compressed arrays of floats and doubles. ---- .. c:type:: cfp_array1 .. c:type:: cfp_array2 .. c:type:: cfp_array3 .. c:type:: cfp_array4 Fictitious types denoting 1D, 2D, 3D, and 4D arrays of any scalar type. ---- .. c:type:: cfp_arrayf .. c:type:: cfp_arrayd Fictitious types denoting any-dimensional arrays of floats and doubles. ---- .. c:type:: cfp_array Fictitious type denoting array of any dimensionality and scalar type. ---- .. c:struct:: cfp .. c:struct:: array1f .. c:struct:: array1d .. c:struct:: array2f .. c:struct:: array2d .. c:struct:: array3f .. c:struct:: array3d .. c:struct:: array4f .. c:struct:: array4d .. c:struct:: header Nested C "namespaces" for encapsulating the |cfp| API. The outer :c:struct:`cfp` namespace may be redefined at compile-time via the macro :c:macro:`CFP_NAMESPACE`, e.g., to avoid symbol clashes. The inner namespaces hold function pointers to the |cfp| wrappers documented below. ---- .. _cfp_ctor: .. c:function:: cfp_array1f cfp.array1f.ctor(size_t nx, double rate, const float* p, size_t cache_size) .. c:function:: cfp_array1d cfp.array1d.ctor(size_t nx, double rate, const double* p, size_t cache_size) .. c:function:: cfp_array2f cfp.array2f.ctor(size_t nx, size_t ny, double rate, const float* p, size_t cache_size) .. c:function:: cfp_array2d cfp.array2d.ctor(size_t nx, size_t ny, double rate, const double* p, size_t cache_size) .. c:function:: cfp_array3f cfp.array3f.ctor(size_t nx, size_t ny, size_t nz, double rate, const float* p, size_t cache_size) .. c:function:: cfp_array3d cfp.array3d.ctor(size_t nx, size_t ny, size_t nz, double rate, const double* p, size_t cache_size) .. c:function:: cfp_array4f cfp.array4f.ctor(size_t nx, size_t ny, size_t nz, size_t nw, double rate, const float* p, size_t cache_size) .. c:function:: cfp_array4d cfp.array4d.ctor(size_t nx, size_t ny, size_t nz, size_t nw, double rate, const double* p, size_t cache_size) :ref:`Array constructors `. If *p* is not :code:`NULL`, then the array is initialized from uncompressed storage; otherwise the array is zero initialized. *cache_size* is the minimum size cache (in bytes) to use. If *cache_size* is zero, a default size is chosen. ---- .. c:function:: cfp_array cfp.array.ctor_default() Default constructor. Allocate an empty array that later can be :ref:`resized ` and whose rate and cache size can be set by :c:func:`cfp.array.set_rate` and :c:func:`cfp.array.set_cache_size`. ---- .. c:function:: cfp_array cfp.array.ctor_copy(const cfp_array src) :ref:`Copy constructor `. ---- .. _cfp_ctor_header: .. c:function:: cfp_array cfp.array.ctor_header(const cfp_header h, const void* buffer, size_t buffer_size_bytes); Constructor from metadata given by the :ref:`header ` *h* and optionally initialized with compressed data from *buffer* of size *buffer_size_bytes*. See :ref:`corresponding C++ constructor `. ---- .. c:function:: void cfp.array.dtor(cfp_array self) Destructor. The destructor not only deallocates any compressed data owned by the array, but also frees memory for itself, invalidating the *self* object upon return. Note that the user must explicitly call the destructor to avoid memory leaks. ---- .. c:function:: void cfp.array.deep_copy(cfp_array self, const cfp_array src) Perform a deep copy of *src* analogous to the :ref:`C++ assignment operator `. ---- .. _cfp_inspectors: .. c:function:: float cfp.array1f.get(const cfp_array1f self, size_t i) .. c:function:: float cfp.array2f.get(const cfp_array2f self, size_t i, size_t j) .. c:function:: float cfp.array3f.get(const cfp_array3f self, size_t i, size_t j, size_t k) .. c:function:: float cfp.array4f.get(const cfp_array4f self, size_t i, size_t j, size_t k, size_t l) .. c:function:: double cfp.array1d.get(const cfp_array1d self, size_t i) .. c:function:: double cfp.array2d.get(const cfp_array2d self, size_t i, size_t j) .. c:function:: double cfp.array3d.get(const cfp_array3d self, size_t i, size_t j, size_t k) .. c:function:: double cfp.array4d.get(const cfp_array4d self, size_t i, size_t j, size_t k, size_t l) :ref:`Array inspectors ` via multidimensional indexing. ---- .. _cfp_mutators: .. c:function:: void cfp.array1f.set(const cfp_array1f self, size_t i, float val) .. c:function:: void cfp.array2f.set(const cfp_array2f self, size_t i, size_t j, float val) .. c:function:: void cfp.array3f.set(const cfp_array3f self, size_t i, size_t j, size_t k, float val) .. c:function:: void cfp.array4f.set(const cfp_array4f self, size_t i, size_t j, size_t k, size_t l, float val) .. c:function:: void cfp.array1d.set(const cfp_array1d self, size_t i, double val) .. c:function:: void cfp.array2d.set(const cfp_array2d self, size_t i, size_t j, double val) .. c:function:: void cfp.array3d.set(const cfp_array3d self, size_t i, size_t j, size_t k, double val) .. c:function:: void cfp.array4d.set(const cfp_array4d self, size_t i, size_t j, size_t k, size_t l, double val) :ref:`Array mutators ` for assigning values to array elements via multidimensional indexing. ---- .. c:function:: float cfp.arrayf.get_flat(const cfp_arrayf self, size_t index) .. c:function:: double cfp.arrayd.get_flat(const cfp_arrayd self, size_t index) Flat index array inspectors; see :cpp:func:`array::operator[]`. ---- .. c:function:: void cfp.arrayf.set_flat(cfp_arrayf self, size_t index, float val) .. c:function:: void cfp.arrayd.set_flat(cfp_arrayd self, size_t index, double val) Flat index array mutators; set array element with flat *index* to *val*. ---- .. c:function:: void cfp.arrayf.get_array(const cfp_arrayf self, float* p) .. c:function:: void cfp.arrayd.get_array(const cfp_arrayd self, double* p) Decompress entire array; see :cpp:func:`array::get`. ---- .. c:function:: void cfp.arrayf.set_array(cfp_arrayf self, const float* p) .. c:function:: void cfp.arrayd.set_array(cfp_arrayd self, const double* p) Initialize entire array; see :cpp:func:`array::set`. ---- .. c:function:: size_t cfp.array2.size_x(const cfp_array2 self) .. c:function:: size_t cfp.array2.size_y(const cfp_array2 self) .. c:function:: size_t cfp.array3.size_x(const cfp_array3 self) .. c:function:: size_t cfp.array3.size_y(const cfp_array3 self) .. c:function:: size_t cfp.array3.size_z(const cfp_array3 self) .. c:function:: size_t cfp.array4.size_x(const cfp_array4 self) .. c:function:: size_t cfp.array4.size_y(const cfp_array4 self) .. c:function:: size_t cfp.array4.size_z(const cfp_array4 self) .. c:function:: size_t cfp.array4.size_w(const cfp_array4 self) :ref:`Array dimensions `. ---- .. c:function:: size_t cfp.array.size(const cfp_array self) See :cpp:func:`array::size`. ---- .. _cfp_resize: .. c:function:: void cfp.array1.resize(cfp_array1 self, size_t n, zfp_bool clear) .. c:function:: void cfp.array2.resize(cfp_array2 self, size_t nx, size_t ny, zfp_bool clear) .. c:function:: void cfp.array3.resize(cfp_array3 self, size_t nx, size_t ny, size_t nz, zfp_bool clear) .. c:function:: void cfp.array4.resize(cfp_array4 self, size_t nx, size_t ny, size_t nz, size_t nw, zfp_bool clear) :ref:`Resize array `. ---- .. c:function:: double cfp.array.rate(const cfp_array self) See :cpp:func:`array::rate`. ---- .. c:function:: double cfp.array.set_rate(cfp_array self, double rate) See :cpp:func:`array::set_rate`. ---- .. c:function:: size_t cfp.array.cache_size(const cfp_array self) See :cpp:func:`array::cache_size`. ---- .. c:function:: void cfp.array.set_cache_size(cfp_array self, size_t cache_size) See :cpp:func:`array::set_cache_size`. ---- .. c:function:: void cfp.array.clear_cache(const cfp_array self) See :cpp:func:`array::clear_cache`. ---- .. c:function:: void cfp.array.flush_cache(const cfp_array self) See :cpp:func:`array::flush_cache`. ---- .. c:function:: size_t cfp.array.size_bytes(const cfp_array self, uint mask) See :cpp:func:`array::size_bytes`. ---- .. c:function:: size_t cfp.array.compressed_size(const cfp_array self) See :cpp:func:`array::compressed_size`. ---- .. c:function:: void* cfp.array.compressed_data(const cfp_array self) See :cpp:func:`array::compressed_data`. ---- .. c:function:: cfp_ref1 cfp.array1.ref(cfp_array1 self, size_t i) .. c:function:: cfp_ref2 cfp.array2.ref(cfp_array2 self, size_t i, size_t j) .. c:function:: cfp_ref3 cfp.array3.ref(cfp_array3 self, size_t i, size_t j, size_t k) .. c:function:: cfp_ref4 cfp.array4.ref(cfp_array4 self, size_t i, size_t j, size_t k, size_t l) Reference :ref:`constructor ` via multidimensional indexing. ---- .. c:function:: cfp_ref cfp.array.ref_flat(cfp_array self, size_t i) Reference :ref:`constructor ` via flat indexing. ---- .. c:function:: cfp_ptr1 cfp.array1.ptr(cfp_array1 self, size_t i) .. c:function:: cfp_ptr2 cfp.array2.ptr(cfp_array2 self, size_t i, size_t j) .. c:function:: cfp_ptr3 cfp.array3.ptr(cfp_array3 self, size_t i, size_t j, size_t k) .. c:function:: cfp_ptr4 cfp.array4.ptr(cfp_array4 self, size_t i, size_t j, size_t k, size_t l) Obtain pointer to array element via multidimensional indexing. ---- .. c:function:: cfp_ptr cfp.array.ptr_flat(cfp_array self, size_t i) Obtain pointer to array element via flat indexing. ---- .. c:function:: cfp_iter cfp.array.begin(cfp_array self) Return iterator to beginning of array; see :cpp:func:`array::begin()`. ---- .. c:function:: cfp_iter cfp.array.end(cfp_array self) Return iterator to end of array; see :cpp:func:`array::end()`. .. _cfp_serialization: Serialization ------------- .. cpp:namespace:: zfp |zfp| |crpirelease| adds |cfp| array :ref:`serialization `. Like |zfp|'s C++ arrays, |cfp| arrays can be serialized and deserialized to and from sequential storage. As with the C++ arrays, (de)serialization is done with the assistance of a header class, :c:type:`cfp_header`. Currently, |cfp| provides no :ref:`factory function `---the caller must either know which type of array (dimensionality and scalar type) to :ref:`construct ` at compile-time or obtain this information at run-time from a header :ref:`constructed ` from a memory buffer. .. _cfp_header: Header ^^^^^^ :c:type:`cfp_header` is a wrapper around :cpp:class:`array::header`. Although the header type is shared among all array types, the header API is accessed through the associated array type whose metadata the header describes. For example, :code:`cfp.array3f.header.ctor(const cfp_array3f a)` constructs a header for a :c:type:`cfp_array3f`. The header is dynamically allocated and must be explicitly destructed via :c:func:`cfp.array.header.dtor`. .. c:type:: cfp_header Wrapper around :cpp:class:`array::header`. ---- .. c:function:: cfp_header cfp.array.header.ctor(const cfp_array a); :ref:`Construct ` a header that describes the metadata of an existing array *a*. ---- .. c:function:: cfp_header cfp.array.header.ctor_buffer(const void* data, size_t size) :ref:`Construct ` a header from header *data* buffer of given byte *size*. ---- .. c:function:: void cfp.array.header.dtor(cfp_header self); Destructor. Deallocates all data associated with the header. The user must call the destructor to avoid memory leaks. ---- .. cpp:namespace:: zfp::array .. c:function:: zfp_type cfp.array.header.scalar_type(const cfp_header self); Scalar type associated with array. See :cpp:func:`header::scalar_type`. ---- .. c:function:: uint cfp.array.header.dimensionality(const cfp_header self); Dimensionality associated with array. See :cpp:func:`header::dimensionality`. ---- .. c:function:: size_t cfp.array.header.size_x(const cfp_header self); .. c:function:: size_t cfp.array.header.size_y(const cfp_header self); .. c:function:: size_t cfp.array.header.size_z(const cfp_header self); .. c:function:: size_t cfp.array.header.size_w(const cfp_header self); :ref:`Array dimensions `. Unused dimensions have a size of zero. ---- .. c:function:: double cfp.array.header.rate(const cfp_header self); Rate in bits/value. See :cpp:func:`header::rate`. ---- .. c:function:: const void* cfp.array.header.data(const cfp_header self); Pointer to header data buffer needed for serializing the header. See :cpp:func:`header::data`. ---- .. c:function:: size_t cfp.array.header.size_bytes(const cfp_header self, uint mask); When *mask* = :c:macro:`ZFP_DATA_HEADER`, byte size of header data buffer needed for serializing the header. See :cpp:func:`header::size_bytes`. Array Accessors --------------- .. cpp:namespace:: zfp::arrayANY |zfp| |crpirelease| adds |cfp| support for proxy :ref:`references ` and :ref:`pointers ` to individual array elements, as well as :ref:`iterators ` for traversing arrays. These are analogues to the corresponding C++ classes. As with :ref:`arrays `, fictitious types and namespaces are used to shorten the documentation. .. _cfp_rpi_value_semantics: .. note:: Unlike the case of arrays, for which the surrounding struct stores a pointer to the underlying array object to allow modifications of the array, the |cfp| proxy reference, proxy pointer, and iterator objects are all passed by value, and hence none of the functions below modify the *self* argument. To increment a pointer, for instance, one should call :code:`p = cfp.array.pointer.inc(p)`. Note that while the references, pointers, and iterators are not themselves modified, the array elements that they reference can be modified. .. _cfp_references: References ---------- |cfp| proxy references wrap the C++ :ref:`reference ` classes. References are constructed via :c:func:`cfp.array.ref`, :c:func:`cfp.array.pointer.ref`, and :c:func:`cfp.array.iterator.ref` (as well as associated :code:`ref_flat` and :code:`ref_at` calls). .. note:: |cfp| references exist primarily to provide parity with |zfp| references. As references do not exist in C, the preferred way of accessing arrays is via :ref:`proxy pointers `, :ref:`iterators `, or :ref:`index-based array accessors `. |cfp| references do provide the same guarantees as C++ references, functioning as aliases to initialized members of the |cfp| wrapped |zfp| array. This is with the caveat that they are only accessed via |cfp| API calls (use of the :code:`=` C assignment operator to shallow copy a :c:type:`cfp_ref` is also allowed in this case). .. c:type:: cfp_ref1f .. c:type:: cfp_ref2f .. c:type:: cfp_ref3f .. c:type:: cfp_ref4f .. c:type:: cfp_ref1d .. c:type:: cfp_ref2d .. c:type:: cfp_ref3d .. c:type:: cfp_ref4d Opaque types for proxy references to 1D, 2D, 3D, and 4D compressed float or double array elements. ---- .. c:type:: cfp_ref1 .. c:type:: cfp_ref2 .. c:type:: cfp_ref3 .. c:type:: cfp_ref4 Fictitious types denoting references into 1D, 2D, 3D, and 4D arrays of any scalar type. ---- .. c:type:: cfp_reff .. c:type:: cfp_refd Fictitious types denoting references into float or double arrays of any dimensionality. ---- .. c:type:: cfp_ref Fictitious type denoting reference into array of any dimensionality and scalar type. ---- .. c:function:: float cfp.arrayf.reference.get(const cfp_reff self) .. c:function:: double cfp.arrayd.reference.get(const cfp_refd self) Retrieve value referenced by *self*. ---- .. c:function:: void cfp.arrayf.reference.set(cfp_reff self, float val) .. c:function:: void cfp.arrayd.reference.set(cfp_refd self, double val) Update value referenced by *self*; see :cpp:func:`reference::operator=()`. ---- .. c:function:: cfp_ptr cfp.array.reference.ptr(cfp_ref self) Obtain proxy pointer to value referenced by *self*; see :cpp:func:`reference::operator&()`. ---- .. c:function:: void cfp.array.reference.copy(cfp_ref self, const cfp_ref src) Copy value referenced by *src* to value referenced by *self*; see :cpp:func:`reference::operator=()`. This performs a deep copy. This is in contrast to :code:`self = src`, which performs only a shallow copy. .. _cfp_pointers: Pointers -------- |cfp| proxy pointers wrap the C++ :ref:`pointer ` classes. Pointers are constructed via :c:func:`cfp.array.ptr` and :c:func:`cfp.array.reference.ptr` (and associated :code:`ptr_flat` and :code:`ptr_at` calls). All pointers are :ref:`passed by value ` and are themselves not modified by these functions. .. note:: As with :cpp:class:`array::pointer`, :c:type:`cfp_ptr` indexing is based on element-wise ordering and is unaware of |zfp| blocks. This may result in a suboptimal access pattern if sequentially accessing array members. To take advantage of |zfp| block traversal optimization, see :ref:`iterators `. .. c:type:: cfp_ptr1f .. c:type:: cfp_ptr2f .. c:type:: cfp_ptr3f .. c:type:: cfp_ptr4f .. c:type:: cfp_ptr1d .. c:type:: cfp_ptr2d .. c:type:: cfp_ptr3d .. c:type:: cfp_ptr4d Opaque types for proxy pointers to 1D, 2D, 3D, and 4D compressed float or double array elements. ---- .. c:type:: cfp_ptr1 .. c:type:: cfp_ptr2 .. c:type:: cfp_ptr3 .. c:type:: cfp_ptr4 Fictitious types denoting pointers into 1D, 2D, 3D, and 4D arrays of any scalar type. ---- .. c:type:: cfp_ptrf .. c:type:: cfp_ptrd Fictitious types denoting pointers into float or double arrays of any dimensionality. ---- .. c:type:: cfp_ptr Fictitious type denoting pointer into array of any dimensionality and scalar type. ---- .. c:function:: float cfp.arrayf.pointer.get(const cfp_ptrf self) .. c:function:: double cfp.arrayd.pointer.get(const cfp_ptrd self) Dereference operator; :code:`*self`. See :cpp:func:`pointer::operator*()`. ---- .. c:function:: float cfp.arrayf.pointer.get_at(const cfp_ptrf self, ptrdiff_t d) .. c:function:: double cfp.arrayd.pointer.get_at(const cfp_ptrd self, ptrdiff_t d) Offset dereference operator; :code:`self[d]`. See :cpp:func:`pointer::operator[]()`. ---- .. c:function:: void cfp.arrayf.pointer.set(cfp_ptrf self, float val) .. c:function:: void cfp.arrayd.pointer.set(cfp_ptrd self, double val) Dereference operator with assignment; :code:`*self = val`. See :cpp:func:`pointer::operator*()`. ---- .. c:function:: void cfp.arrayf.pointer.set_at(cfp_ptrf self, ptrdiff_t d, float val) .. c:function:: void cfp.arrayd.pointer.set_at(cfp_ptrd self, ptrdiff_t d, double val) Offset dereference operator with assignment; :code:`self[d] = val`. See :cpp:func:`pointer::operator[]()`. ---- .. c:function:: cfp_ref cfp.array.pointer.ref(cfp_ptr self) Get proxy reference to element stored at :code:`*self`. See :cpp:func:`pointer::operator*()`. ---- .. c:function:: cfp_ref cfp.array.pointer.ref_at(cfp_ptr self, ptrdiff_t d) Get proxy reference to element stored at :code:`self[d]`. See :cpp:func:`pointer::operator[]()`. ---- .. c:function:: zfp_bool cfp.array.pointer.lt(const cfp_ptr lhs, const cfp_ptr rhs) .. c:function:: zfp_bool cfp.array.pointer.gt(const cfp_ptr lhs, const cfp_ptr rhs) .. c:function:: zfp_bool cfp.array.pointer.leq(const cfp_ptr lhs, const cfp_ptr rhs) .. c:function:: zfp_bool cfp.array.pointer.geq(const cfp_ptr lhs, const cfp_ptr rhs) Return true if the two pointers satisfy the given :ref:`relationship `; :code:`lhs < rhs`, :code:`lhs > rhs`, :code:`lhs <= rhs`, :code:`lhs >= rhs`. ---- .. c:function:: zfp_bool cfp.array.pointer.eq(const cfp_ptr lhs, const cfp_ptr rhs) Compare two proxy pointers for equality; :code:`lhs == rhs`. The pointers must be to elements with the same index within the same array to satisfy equality. See :cpp:func:`pointer::operator==()`. ---- .. c:function:: int cfp.array.pointer.neq(const cfp_ptr lhs, const cfp_ptr rhs) Compare two proxy pointers for inequality; :code:`lhs != rhs`. The pointers are not equal if they point to different arrays or to elements with different index within the same array. See :cpp:func:`pointer::operator!=()`. ---- .. c:function:: ptrdiff_t cfp.array.pointer.distance(const cfp_ptr first, const cfp_ptr last) Return the difference between two proxy pointers in number of linear array elements; :code:`last - first`. See :cpp:func:`pointer::operator-()`. ---- .. c:function:: cfp_ptr cfp.array.pointer.next(const cfp_ptr p, ptrdiff_t d) Return the result of incrementing pointer by *d* elements; :code:`p + d`. See :cpp:func:`pointer::operator+()`. ---- .. c:function:: cfp_ptr cfp.array.pointer.prev(const cfp_ptr p, ptrdiff_t d) Return the result of decrementing pointer by *d* elements; :code:`p - d`. See :cpp:func:`pointer::operator-()`. ---- .. c:function:: cfp_ptr cfp.array.pointer.inc(const cfp_ptr p) Return the result of incrementing pointer by one element; :code:`p + 1`. See :cpp:func:`pointer::operator++()`. ---- .. c:function:: cfp_ptr cfp.array.pointer.dec(const cfp_ptr p) Return the result of decrementing pointer by one element; :code:`p - 1`. See :cpp:func:`pointer::operator--()`. .. _cfp_iterators: Iterators --------- |cfp| random-access iterators wrap the C++ :ref:`iterator ` classes. All iterators are :ref:`passed by value ` and are themselves not modified by these functions. Iterators are constructed similar to C++ iterators via :c:func:`cfp.array.begin` and :c:func:`cfp.array.end`. Iterator usage maps closely to equivalent C++ iterator syntax. For example, to set an array to all ones:: // _ and _iter are namespace aliases const cfp_array3d_api _ = cfp.array3d; const cfp_iter3d_api _iter = _.iterator; cfp_array3d a = _.ctor(nx, ny, nz, rate, 0, 0); cfp_iter3d it; for (it = _.begin(a); _iter.neq(it, _.end(a)); it = _iter.inc(it)) _iter.set(it, 1.0); .. c:type:: cfp_iter1f .. c:type:: cfp_iter2f .. c:type:: cfp_iter3f .. c:type:: cfp_iter4f .. c:type:: cfp_iter1d .. c:type:: cfp_iter2d .. c:type:: cfp_iter3d .. c:type:: cfp_iter4d Opaque types for block iterators over 1D, 2D, 3D, and 4D compressed float or double array elements. ---- .. c:type:: cfp_iter1 .. c:type:: cfp_iter2 .. c:type:: cfp_iter3 .. c:type:: cfp_iter4 Fictitious types denoting iterators over 1D, 2D, 3D, and 4D arrays of any scalar type. ---- .. c:type:: cfp_iterf .. c:type:: cfp_iterd Fictitious types denoting iterators over float or double arrays of any dimensionality. ---- .. c:type:: cfp_iter Fictitious type denoting iterator over array of any dimensionality and scalar type. ---- .. c:function:: float cfp.arrayf.iterator.get(const cfp_iterf self) .. c:function:: double cfp.arrayd.iterator.get(const cfp_iterd self) Return element referenced by iterator; :code:`*self`. See :cpp:func:`iterator::operator*()`. ---- .. c:function:: float cfp.array1f.iterator.get_at(const cfp_iter1f self, ptrdiff_t d) .. c:function:: double cfp.array1d.iterator.get_at(const cfp_iter1d self, ptrdiff_t d) Return element *d* elements (may be negative) from iterator; :code:`self[d]`. See :cpp:func:`iterator::operator[]()`. ---- .. c:function:: void cfp.arrayf.iterator.set(cfp_iterf self, float val) .. c:function:: void cfp.arrayd.iterator.set(cfp_iterd self, double val) Update element referenced by iterator; :code:`*self = val`. See :cpp:func:`iterator::operator*()`. ---- .. c:function:: void cfp.array1f.iterator.set_at(cfp_iter1 self, ptrdiff_t d, float val) .. c:function:: void cfp.array1d.iterator.set_at(cfp_iter1 self, ptrdiff_t d, double val) Update element *d* elements (may be negative) from iterator; :code:`self[d] = val`. See :cpp:func:`iterator::operator[]()`. ---- .. c:function:: cfp_ref cfp.array.iterator.ref(cfp_iter self) Return reference to element referenced by iterator; :code:`*self`. See :cpp:func:`iterator::operator*()`. ---- .. c:function:: cfp_ref cfp.array.iterator.ref_at(cfp_iter self, ptrdiff_t d) Return reference to an element offset *d* elements (may be negative) from iterator; :code:`self[d]`. See :cpp:func:`iterator::operator[]()`. ---- .. c:function:: cfp_ptr cfp.array.iterator.ptr(cfp_iter self) Return pointer to element referenced by iterator; :code:`&*self`. ---- .. c:function:: cfp_ptr cfp.array.iterator.ptr_at(cfp_iter self, ptrdiff_t d) Return pointer to element offset *d* elements (may be negative) from iterator; :code:`&self[d]`. ---- .. c:function:: size_t cfp.array.iterator.i(const cfp_iter self) .. c:function:: size_t cfp.array.iterator.j(const cfp_iter self) .. c:function:: size_t cfp.array.iterator.k(const cfp_iter self) .. c:function:: size_t cfp.array.iterator.l(const cfp_iter self) Return *i*, *j*, *k*, and *l* component of array element referenced by iterator; see :cpp:func:`iterator::i()`, :cpp:func:`iterator::j()`, :cpp:func:`iterator::k()`, and :cpp:func:`iterator::l()`. ---- .. c:function:: zfp_bool cfp.array.iterator.lt(const cfp_iter lhs, const cfp_iter rhs) .. c:function:: zfp_bool cfp.array.iterator.gt(const cfp_iter lhs, const cfp_iter rhs) .. c:function:: zfp_bool cfp.array.iterator.leq(const cfp_iter lhs, const cfp_iter rhs) .. c:function:: zfp_bool cfp.array.iterator.geq(const cfp_iter lhs, const cfp_iter rhs) Return true if the two iterators satisfy the given :ref:`relationship `; :code:`lhs < rhs`, :code:`lhs > rhs`, :code:`lhs <= rhs`, :code:`lhs >= rhs`. ---- .. c:function:: zfp_bool cfp.array.iterator.eq(const cfp_iter lhs, const cfp_iter rhs) Return whether two iterators are equal; :code:`lhs == rhs`. See :cpp:func:`iterator::operator==()`. ---- .. c:function:: zfp_bool cfp.array.iterator.neq(const cfp_iter lhs, const cfp_iter rhs) Return whether two iterators are not equal; :code:`lhs != rhs`. See :cpp:func:`iterator::operator!=()`. ---- .. c:function:: ptrdiff_t cfp.array.iterator.distance(const cfp_iter first, const cfp_iter last) Return the difference between two iterators; :code:`last - first`. See :cpp:func:`iterator::operator-()`. ---- .. c:function:: cfp_iter cfp.array.iterator.next(const cfp_iter it, ptrdiff_t d) Return the result of advancing iterator by *d* elements; :code:`it + d`. See :cpp:func:`iterator::operator+()`. ---- .. c:function:: cfp_iter cfp.array.iterator.prev(const cfp_iter it, ptrdiff_t d) Return the result of decrementing iterator by *d* elements; :code:`it - d`. See :cpp:func:`iterator::operator-()`. ---- .. c:function:: cfp_iter cfp.array.iterator.inc(const cfp_iter it) Return the result of incrementing iterator by one element; :code:`it + 1`. See :cpp:func:`iterator::operator++()`. ---- .. c:function:: cfp_iter cfp.array.iterator.dec(const cfp_iter it) Return the result of decrementing iterator by one element; :code:`it - 1`. See :cpp:func:`iterator::operator--()`. zfp-1.0.1/docs/source/codec.inc000066400000000000000000000242131453723256400163250ustar00rootroot00000000000000.. index:: single: Codec .. _codec: Codec ----- .. cpp:namespace:: zfp |zfp| arrays are partitioned into independent blocks that are compressed and decompressed using a *codec* (encoder/decoder). This codec defaults to the |zfp| compression scheme, but can in principle be any compression scheme or number representation that represents *d*-dimensional blocks of |4powd| values. The :cpp:class:`zfp::array` and :cpp:class:`zfp::const_array` classes take such a codec class as an optional template parameter. This section documents the API that prospective codecs must support to interface with the |zfp| compressed-array classes. Any one codec supports a specific scalar type (e.g., :code:`float` or :code:`double`), denoted :code:`Scalar` below, and data dimensionality (1D, 2D, 3D, or 4D). If the codec does not support a certain compression mode, it should throw an :ref:`exception ` when the user attempts to invoke that mode. Codecs reside in the :code:`zfp::codec` namespace, e.g., :code:`zfp::codec::zfp3` is the default codec for 3D arrays. As of |zfp| |cpprelease|, there is in addition to the default |zfp| codec a "generic" codec that allows storing data in |zfp| arrays in "uncompressed" form using any scalar type (specified as a template parameter). This "internal" scalar type may differ from the "external" scalar type exposed to the user through the :cpp:class:`zfp::array` API. For instance, the internal type may be :code:`float` while the external type is :code:`double`, which provides for 2:1 fixed-rate "compression" using IEEE 754 floating point. .. cpp:namespace:: zfp::codec .. cpp:class:: codec Fictitious class encapsulating the codec API. This may be thought of as a base class for the classes below specialized on dimensionality. ---- .. cpp:class:: codec1 .. cpp:class:: codec2 .. cpp:class:: codec3 .. cpp:class:: codec4 Fictitious classes encapsulating the codec API specialized for a given data dimensionality (1D, 2D, 3D, or 4D). ---- .. cpp:function:: codec& codec::operator=(const codec& c) Assignment operator. Performs a deep copy. This method is invoked when performing a :ref:`deep copy ` of an array. ---- .. cpp:function:: size_t codec::buffer_size(const zfp_field* field) const Maximum buffer size needed to encode the *field* of given scalar type and dimensions (see :c:func:`zfp_stream_maximum_size`). The size should be based on the current compression mode and parameters. This method is called to determine how large a buffer to allocate and pass to :cpp:func:`codec::open`. ---- .. cpp:function:: void codec::open(void* data, size_t size) Open codec for (de)compression to/from buffer pointed to by *data* of *size* bytes. The caller is responsible for allocating and deallocating this buffer, whose *size* is given by :cpp:func:`codec::buffer_size`. ---- .. cpp:function:: void codec::close() Close codec for (de)compression. ---- .. cpp:function:: zfp_mode codec::mode() const Currently selected :ref:`compression mode `. See :c:enum:`zfp_mode`. ---- .. cpp:function:: double codec::rate() const Rate in compressed bits/value when :ref:`fixed-rate mode ` is selected. See :c:func:`zfp_stream_rate`. ---- .. cpp:function:: uint codec::precision() const Precision in uncompressed bits/value when :ref:`fixed-precision mode ` is selected. See :c:func:`zfp_stream_precision`. ---- .. cpp:function:: double codec::accuracy() const Accuracy as absolute error tolerance when :ref:`fixed-accuracy mode ` is selected. See :c:func:`zfp_stream_accuracy`. ---- .. cpp:function:: void codec::params(uint* minbits, uint* maxbits, uint* maxprec, int* minexp) const Compression parameters for any compression mode. These pointer parameters may be :code:`null` if only a subset of parameters is requested. See :c:func:`zfp_stream_params`. ---- .. cpp:function:: void codec::set_reversible() Enable :ref:`reversible mode `. ---- .. cpp:function:: double codec::set_rate(double rate, bool align) Set desired *rate* in number of compressed bits/value. When *align* = true, blocks are word aligned, as needed for random access writes. Return the closest rate supported. See :c:func:`zfp_stream_set_rate`. ---- .. cpp:function:: uint codec::set_precision(uint precision) Set precision in number of uncompressed bits/value. Return the actual precision selected. See :c:func:`zfp_stream_set_precision`. ---- .. cpp:function:: double codec::set_accuracy(double tolerance) Set accuracy as absolute error tolerance. Return the closest tolerance supported. See :c:func:`zfp_stream_set_accuracy`. ---- .. cpp:function:: bool codec::set_params(uint minbits, uint maxbits, uint maxprec, int minexp) Set expert mode parameters. Return :code:`true` on success. See :c:func:`zfp_stream_set_params`. ---- .. cpp:function:: bool codec::set_thread_safety(bool safety) Enable or disable thread safety. This function is called whenever |zfp| is built with OpenMP support and when the number of mutable or immutable :ref:`private views ` of an array changes. When two or more private views of an array are accessed by separate threads, multiple blocks may be compressed or decompressed simultaneously. The codec then has to take care that there are no race conditions on the data structures (e.g., :c:type:`bitstream`) used for (de)compression. ---- .. cpp:function:: size_t codec::size_bytes(uint mask = ZFP_DATA_ALL) const Return storage size of components of codec data structure indicated by *mask*. The mask is constructed via bitwise OR of :ref:`predefined constants `. ---- .. cpp:function:: static size_t codec::alignment() Memory alignment in number of bytes required by codec. .. cpp:var:: static const zfp_type codec::type; :c:type:`Scalar type ` compressed by codec. ---- .. cpp:function:: size_t codec::encode_block(bitstream_offset offset, const Scalar* block) const Encode contiguous *block* of |4powd| scalars and store at specified bit *offset* within compressed-data buffer. Return the number of bits of compressed storage for the block, excluding any necessary padding. This method must flush any buffered compressed data without counting any padding (e.g., for byte alignment) in the compressed size (unless the codec requires alignment of the bit offsets). ---- .. cpp:function:: size_t codec::decode_block(bitstream_offset offset, Scalar* block) const Decode contiguous *block* of |4powd| scalars from specified bit *offset* within compressed-data buffer (see :cpp:func:`codec::encode_block`). Return number of bits of compressed data decoded, excluding any padding bits, i.e., the same value reported in encoding. ---- .. cpp:function:: size_t codec1::encode_block(bitstream_offset offset, uint shape, const Scalar* block) const .. cpp:function:: size_t codec2::encode_block(bitstream_offset offset, uint shape, const Scalar* block) const .. cpp:function:: size_t codec3::encode_block(bitstream_offset offset, uint shape, const Scalar* block) const .. cpp:function:: size_t codec4::encode_block(bitstream_offset offset, uint shape, const Scalar* block) const Encode contiguous *block* of data of given *shape* and store at specified bit *offset* within compressed-data buffer. Return the number of bits of compressed storage for the block (see also :cpp:func:`codec::encode_block`). The *shape* is a (2 |times| *d*)-bit encoding of the size of the *d*-dimensional block. For each successive pair of bits *s* of *shape*, the block size in the corresponding dimension is *n* = 4 - *s*, where 0 |leq| *s* |leq| 3. Thus, *shape* = 0 implies a full block of |4powd| values. The size of the fastest varying dimension is specified in the least significant bits of *shape*. ---- .. cpp:function:: size_t codec1::decode_block(bitstream_offset offset, uint shape, Scalar* block) const .. cpp:function:: size_t codec2::decode_block(bitstream_offset offset, uint shape, Scalar* block) const .. cpp:function:: size_t codec3::decode_block(bitstream_offset offset, uint shape, Scalar* block) const .. cpp:function:: size_t codec4::decode_block(bitstream_offset offset, uint shape, Scalar* block) const Decode contiguous *block* of data of given *shape* from specified bit *offset* within compressed-data buffer (see also :cpp:func:`codec1::encode_block`). Return number of bits of compressed data decoded, excluding any padding bits, i.e., the same value reported in encoding. ---- .. cpp:function:: size_t codec1::encode_block_strided(bitstream_offset offset, uint shape, const Scalar* p, ptrdiff_t sx) const .. cpp:function:: size_t codec2::encode_block_strided(bitstream_offset offset, uint shape, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy) const .. cpp:function:: size_t codec3::encode_block_strided(bitstream_offset offset, uint shape, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) const .. cpp:function:: size_t codec4::encode_block_strided(bitstream_offset offset, uint shape, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) const Encode block of data stored at *p* with strides *sx*, *sy*, *sz*, and *sw*. See :c:type:`zfp_field` for information on strided storage. The *shape*, *offset*, and return value are as in :cpp:func:`codec1::encode_block`. ---- .. cpp:function:: size_t codec1::decode_block_strided(bitstream_offset offset, uint shape, Scalar* p, ptrdiff_t sx) const .. cpp:function:: size_t codec2::decode_block_strided(bitstream_offset offset, uint shape, Scalar* p, ptrdiff_t sx, ptrdiff_t sy) const .. cpp:function:: size_t codec3::decode_block_strided(bitstream_offset offset, uint shape, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) const .. cpp:function:: size_t codec4::decode_block_strided(bitstream_offset offset, uint shape, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) const Decode block to strided storage pointed to by *p* with strides *sx*, *sy*, *sz*, and *sw*. See :c:type:`zfp_field` for information on strided storage. The *shape*, *offset*, and return value are as in :cpp:func:`codec1::decode_block`. zfp-1.0.1/docs/source/conf.py000066400000000000000000000125131453723256400160540ustar00rootroot00000000000000# -*- coding: utf-8 -*- # # zfp documentation build configuration file, created by # sphinx-quickstart on Mon Jul 3 18:31:07 2017. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # # import os # import sys # sys.path.insert(0, os.path.abspath('.')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. # # needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = ['sphinx.ext.imgmath', 'sphinxfortran.fortran_domain'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] source_suffix = '.rst' # The master toctree document. master_doc = 'index' # General information about the project. project = u'zfp' copyright = u'2014-2023, LLNL-CODE-663824' author = u'Peter Lindstrom, Danielle Asher' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = u'1.0' # The full version, including alpha/beta/rc tags. release = u'1.0.1' # The release date (as the RTD server is in another time zone). today = u'Dec 15, 2023' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. language = 'en' # Enable automatic numbering of figures referenced by :numref:. numfig = True # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path exclude_patterns = [] # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # html_theme = 'pyramid' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. # # html_theme_options = {} # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". #html_static_path = ['_static'] html_static_path = [] # Custom sidebar templates, must be a dictionary that maps document names # to template names. # # This is required for the alabaster theme # refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars #html_sidebars = { # '**': [ # 'about.html', # 'navigation.html', # 'relations.html', # needs 'show_related': True theme option to display # 'searchbox.html', # 'donate.html', # ] #} # -- Options for HTMLHelp output ------------------------------------------ # Output file base name for HTML help builder. htmlhelp_basename = 'zfpdoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. # # 'preamble': '', # Latex figure (float) alignment # # 'figure_align': 'htbp', 'inputenc' : '\\usepackage[utf8x]{inputenc}', 'utf8extra': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ (master_doc, 'zfp.tex', u'zfp Documentation', u'\shortstack[l]{Peter Lindstrom\\\\Danielle Asher}', 'manual'), ] # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ (master_doc, 'zfp', u'zfp Documentation', [author], 1) ] # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ (master_doc, 'zfp', u'zfp Documentation', author, 'zfp', 'One line description of project.', 'Miscellaneous'), ] zfp-1.0.1/docs/source/contributors.rst000066400000000000000000000006311453723256400200420ustar00rootroot00000000000000.. include:: defs.rst .. _contributors: Contributors ============ * |zfp| development team - Peter Lindstrom - Danielle Asher * Major contributors - Chuck Atkins - Stephen Herbein - Mark Kim - Matt Larsen - Mark Miller - Markus Salasoo - David Wade - Haiying Xu For a full list of contributors, see the `GitHub Contributors `__ page. zfp-1.0.1/docs/source/defs.rst000066400000000000000000000025231453723256400162300ustar00rootroot00000000000000.. |times| unicode:: 0x00d7 .. |minus| unicode:: 0x2212 .. |leq| unicode:: 0x2264 .. |geq| unicode:: 0x2265 .. |approx| unicode:: 0x2248 .. |sqrt| unicode:: 0x221a .. |check| unicode:: 0x2713 .. |reg| unicode:: 0x00ae .. |tm| unicode:: 0x2122 .. |zfp| replace:: zfp .. |cfp| replace:: cfp .. |zforp| replace:: zFORp .. |zfpy| replace:: zfPy .. |libzfp| replace:: :file:`libzfp` .. |libcfp| replace:: :file:`libcfp` .. |libzforp| replace:: :file:`libzFORp` .. |zfpcmd| replace:: :program:`zfp` .. |testzfp| replace:: :program:`testzfp` .. |4powd| replace:: 4\ :sup:`d` .. |4by4| replace:: 4 |times| 4 .. |4by4by4| replace:: 4 |times| 4 |times| 4 .. |4by4by4by4| replace:: 4 |times| 4 |times| 4 |times| 4 .. |proxyrelease| replace:: 0.5.2 .. |omprelease| replace:: 0.5.3 .. |dcrelease| replace:: 0.5.3 .. |4drelease| replace:: 0.5.4 .. |viewsrelease| replace:: 0.5.4 .. |cudarelease| replace:: 0.5.4 .. |cfprelease| replace:: 0.5.4 .. |revrelease| replace:: 0.5.5 .. |zforprelease| replace:: 0.5.5 .. |zfpyrelease| replace:: 0.5.5 .. |csizerelease| replace:: 0.5.5 .. |crpirelease| replace:: 1.0.0 .. |raiterrelease| replace:: 1.0.0 .. |64bitrelease| replace:: 1.0.0 .. |boolrelease| replace:: 1.0.0 .. |4darrrelease| replace:: 1.0.0 .. |fieldrelease| replace:: 1.0.0 .. |carrrelease| replace:: 1.0.0 .. |cpprelease| replace:: 1.0.0 .. |verrelease| replace:: 1.0.0 zfp-1.0.1/docs/source/directions.rst000066400000000000000000000113761453723256400174600ustar00rootroot00000000000000.. include:: defs.rst .. _directions: Future Directions ================= |zfp| is actively being developed and plans have been made to add a number of important features, including: - **Tagging of missing values**. |zfp| currently assumes that arrays are dense, i.e., each array element stores a valid numerical value. In many science applications this is not the case. For instance, in climate modeling, ocean temperature is not defined over land. In other applications, the domain is not rectangular but irregular and embedded in a rectangular array. Such examples of sparse arrays demand a mechanism to tag values as missing or indeterminate. Current solutions often rely on tagging missing values as NaNs or special, often very large sentinel values outside the normal range, which can lead to poor compression and complete loss of accuracy in nearby valid values. See FAQ :ref:`#7 `. - **Support for NaNs and infinities**. Similar to missing values, some applications store special IEEE floating-point values that are supported by |zfp| only in :ref:`reversible mode `. In fact, for all lossy compression modes, the presence of such values will currently result in undefined behavior and loss of data for all values within a block that contains non-finite values. - **Support for more general data types**. |zfp| currently does not directly support half and quad precision floating point. Nor is there support for 8- and 16-bit integers. With the emergence of new number representations like *posits* and *bfloat16*, we envision the need for a more general interface and a single unified |zfp| representation that would allow for *conversion* between |zfp| and *any* number representation. We are working on developing an uncompressed interchange format that acts like an intermediary between |zfp| and other number formats. This format decouples the |zfp| compression pipeline from the external number type and allows new number formats to be supported via user-defined conversion functions to and from the common interchange format. - **Progressive decompression**. Streaming large data sets from remote storage for visualization can be time consuming, even when the data is compressed. Progressive streaming allows the data to be reconstructed at reduced precision over the entire domain, with quality increasing progressively as more data arrives. The low-level bit stream interface already supports progressive access by interleaving bits across blocks (see FAQ :ref:`#13 `), but |zfp| lacks a high-level API for generating and accessing progressive streams. - **Parallel compression**. |zfp|'s data partitioning into blocks invites opportunities for data parallelism on multithreaded platforms by dividing the blocks among threads. An OpenMP implementation of parallel compression is available that produces compressed streams that are identical to serially compressed streams. However, parallel decompression is not yet supported. |zfp| also supports compression and decompression on the GPU via CUDA. However, only fixed-rate mode is so far supported. - **Variable-rate arrays**. |zfp| currently offers only fixed-rate compressed arrays with random-access write support; |zfp| |carrrelease| further provides read-only variable-rate arrays. Fixed-rate arrays waste bits in smooth regions with little information content while too few bits may be allocated to accurately preserve sharp features such as shocks and material interfaces, which tend to drive the physics in numerical simulations. A candidate solution has been developed for variable-rate arrays that support read-write random access with modest storage overhead. We expect to release this capability in the near future. - **Array operations**. |zfp|'s compressed arrays currently support basic indexing and initialization, but lack array-wise operations such as arithmetic, reductions, etc. Some such operations can exploit the higher precision (than IEEE-754) supported by |zfp|, as well as accelerated blockwise computations that need not fully decompress and convert the |zfp| representation to IEEE-754. - **Language bindings**. The main compression codec is written in C89 to facilitate calls from other languages. |zfp|'s compressed arrays, on the other hand, are written in C++. |zfp| |cfprelease| and |zforprelease| add C wrappers around compressed arrays and Fortran and Python bindings to the high-level C API. Work is planned to provide additional language bindings for C, C++, Fortran, and Python to expose the majority of |zfp|'s capabilities through all of these programming languages. Please `contact us `__ with requests for features not listed above. zfp-1.0.1/docs/source/disclaimer.inc000066400000000000000000000010571453723256400173650ustar00rootroot00000000000000.. note:: In multidimensional arrays, the order in which dimensions are specified is important. In |zfp|, the memory layout convention is such that *x* varies faster than *y*, which varies faster than *z*, and hence *x* should map to the innermost (rightmost) array dimension in a C array and to the leftmost dimension in a Fortran array. Getting the order of dimensions right is crucial for good compression and accuracy. See the discussion of :ref:`dimensions and strides ` and FAQ :ref:`#0 ` for further information. zfp-1.0.1/docs/source/examples.rst000066400000000000000000000174501453723256400171320ustar00rootroot00000000000000.. include:: defs.rst Code Examples ============= The :file:`examples` directory includes ten programs that make use of the compressor. .. _ex-simple: Simple Compressor ----------------- The :program:`simple` program is a minimal example that shows how to call the compressor and decompressor on a double-precision 3D array. Without the :code:`-d` option, it will compress the array and write the compressed stream to standard output. With the :code:`-d` option, it will instead read the compressed stream from standard input and decompress the array:: simple > compressed.zfp simple -d < compressed.zfp For a more elaborate use of the compressor, see the :ref:`zfp utility `. .. _ex-array: Compressed-Array C++ Classes ---------------------------- The :program:`array` program shows how to declare, write to, and read from |zfp|'s compressed-array C++ objects (in this case, 2D double-precision arrays), which is essentially as straightforward as working with STL vectors. This example initializes a 2D array with a linear ramp of 12 |times| 8 = 96 values using only four bits of storage per value, which using uncompressed storage would not be enough to distinguish more than 16 different values. For more advanced compressed-array features, see the :ref:`tutorial `. .. _ex-diffusion: Diffusion Solver ---------------- The :program:`diffusion` example is a simple forward Euler solver for the heat equation on a 2D regular grid, and is intended to show how to declare and work with |zfp|'s compressed arrays, as well as give an idea of how changing the compression parameters and cache size affects the error in the solution and solution time. The usage is:: diffusion [options] -a : absolute error tolerance (requires -c) -b : cache size in number of 4x4 blocks -c : use read-only arrays (needed for -a, -p, -R) -d : use double-precision tiled arrays -f : use single-precision tiled arrays -h : use half-precision tiled arrays -i : traverse arrays using iterators instead of integer indices -j : use OpenMP parallel execution (requires -r) -n : grid dimensions -p : precision in uncompressed bits/value (requires -c) -r : rate in compressed bits/value -R : reversible mode (requires -c) -t : number of time steps Here *rate* specifies the exact number of compressed bits to store per double-precision floating-point value; *nx* and *ny* specify the grid size (default = 128 |times| 128); *nt* specifies the number of time steps to take (the default is to run until time *t* = 1); and *blocks* is the number of uncompressed blocks to cache (default = *nx* / 2). The :code:`-i` option enables array traversal via iterators instead of indices. The :code:`-j` option enables OpenMP parallel execution, which makes use of both mutable and immutable :ref:`private views ` for thread-safe array access. Note that this example has not been optimized for parallel performance, but rather serves to show how to work with |zfp|'s compressed arrays in a multithreaded setting. This example also illustrates how :ref:`read-only arrays ` (:code:`-c`) may be used in conjunction with fixed-rate (:code:`-r`), fixed-precision (:code:`-p`), fixed-accuracy (:code:`-a`), or reversible (:code:`-R`) mode. The output lists for each time step the current rate of the state array and in parentheses any additional storage, e.g., for the block :ref:`cache ` and :ref:`index ` data structures, both in bits per array element. Running diffusion with the following arguments:: diffusion -r 8 diffusion -r 12 diffusion -r 16 diffusion -r 24 diffusion should result in this final output:: sum=0.995170 error=4.044954e-07 sum=0.998151 error=1.237837e-07 sum=0.998345 error=1.212734e-07 sum=0.998346 error=1.212716e-07 sum=0.998346 error=1.212716e-07 For speed and quality comparison, the solver solves the same problem using uncompressed double-precision row-major arrays when compression parameters are omitted. If one of :code:`-h`, :code:`-f`, :code:`-d` is specified, uncompressed tiled arrays are used. These arrays are based on the |zfp| array classes but make use of the :ref:`generic codec `, which stores blocks as uncompressed scalars of the specified type (:code:`half`, :code:`float`, or :code:`double`) while utilizing a double-precision block cache (like |zfp|'s compressed arrays). The :program:`diffusionC` program is the same example written entirely in C using the |cfp| :ref:`wrappers ` around the C++ compressed array classes. .. _ex-speed: Speed Benchmark --------------- The :program:`speed` program takes two optional parameters:: speed [rate] [blocks] It measures the throughput of compression and decompression of 3D double-precision data (in megabytes of uncompressed data per second). By default, a rate of 1 bit/value and two million blocks are processed. .. _ex-pgm: PGM Image Compression --------------------- The :program:`pgm` program illustrates how |zfp| can be used to compress grayscale images in the `pgm format `_. The usage is:: pgm output.pgm If :code:`param` is positive, it is interpreted as the rate in bits per pixel, which ensures that each block of |4by4| pixels is compressed to a fixed number of bits, as in texture compression codecs. If :code:`param` is negative, then fixed-precision mode is used with precision :code:`-param`, which tends to give higher quality for the same rate. This use of |zfp| is not intended to compete with existing texture and image compression formats, but exists merely to demonstrate how to compress 8-bit integer data with |zfp|. See FAQs :ref:`#20 ` and :ref:`#21 ` for information on the effects of setting the precision. .. _ex-ppm: PPM Image Compression --------------------- The :program:`ppm` program is analogous to the :program:`pgm` example, but has been designed for compressing color images in the `ppm format `_. Rather than compressing RGB channels independently, ppm exploits common strategies for color image compression such as color channel decorrelation and chroma subsampling. The usage is essentially the same as for :ref:`pgm `:: ppm output.ppm where a positive :code:`param` specifies the rate in bits per pixel; when negative, it specifies the precision (number of bit planes to encode) in fixed-precision mode. .. _ex-inplace: In-place Compression -------------------- The :program:`inplace` example shows how one might use zfp to perform in-place compression and decompression when memory is at a premium. Here the floating-point array is overwritten with compressed data, which is later decompressed back in place. This example also shows how to make use of some of the low-level features of zfp, such as its low-level, block-based compression API and bit stream functions that perform seeks on the bit stream. The program takes one optional argument:: inplace [tolerance] which specifies the fixed-accuracy absolute tolerance to use during compression. Please see FAQ :ref:`#19 ` for more on the limitations of in-place compression. .. _ex-iterators: Iterators --------- The :program:`iterator` example illustrates how to use |zfp|'s compressed-array iterators and pointers for traversing arrays. For instance, it gives an example of sorting a 1D compressed array using :cpp:func:`std::sort`. This example takes no command-line options. The :program:`iteratorC` example illustrates the equivalent |cfp| iterator operations. It closely follows the usage shown in the :program:`iterator` example with some minor differences. It likewise takes no command-line options. zfp-1.0.1/docs/source/execution.rst000066400000000000000000000327601453723256400173200ustar00rootroot00000000000000.. include:: defs.rst .. index:: single: Parallel execution .. _execution: Parallel Execution ================== As of |zfp| |omprelease|, parallel compression (but not decompression) is supported on multicore processors via `OpenMP `_ threads. |zfp| |cudarelease| adds `CUDA `_ support for fixed-rate compression and decompression on the GPU. Since |zfp| partitions arrays into small independent blocks, a large amount of data parallelism is inherent in the compression scheme that can be exploited. In principle, concurrency is limited only by the number of blocks that make up an array, though in practice each thread is responsible for compressing a *chunk* of several contiguous blocks. .. note:: |zfp| parallel compression is confined to shared memory on a single compute node or GPU. No effort is made to coordinate compression across distributed memory on networked compute nodes, although |zfp|'s fine-grained partitioning of arrays should facilitate distributed parallel compression. This section describes the |zfp| parallel compression algorithm and explains how to configure |libzfp| and enable parallel compression at run time via its :ref:`high-level C API `. .. note:: Parallel compression is not supported via the :ref:`low-level API `, which ignores all execution policy settings and always executes in serial. .. _exec-policies: Execution Policies ------------------ |zfp| supports multiple *execution policies*, which dictate how (e.g., sequentially, in parallel) and where (e.g., on the CPU or GPU) arrays are compressed. Currently three execution policies are available: ``serial``, ``omp``, and ``cuda``. The default mode is ``serial``, which ensures sequential compression on a single thread. The ``omp`` and ``cuda`` execution policies allow for data-parallel compression on multiple threads. The execution policy is set by :c:func:`zfp_stream_set_execution` and pertains to a particular :c:type:`zfp_stream`. Hence, each stream (and array) may use a policy suitable for that stream. For instance, very small arrays are likely best compressed in serial, while parallel compression is best reserved for very large arrays that can take the most advantage of concurrent execution. As outlined in FAQ :ref:`#23 `, the final compressed stream is independent of execution policy. Execution Parameters -------------------- Each execution policy allows tailoring the execution via its associated *execution parameters*. Examples include number of threads, chunk size, scheduling, etc. The ``serial`` and ``cuda`` policies have no parameters. The subsections below discuss the ``omp`` parameters. Whenever the execution policy is changed via :c:func:`zfp_stream_set_execution`, its parameters (if any) are initialized to their defaults, overwriting any prior setting. OpenMP Thread Count ^^^^^^^^^^^^^^^^^^^ By default, the number of threads to use is given by the current setting of the OpenMP internal control variable *nthreads-var*. Unless the calling thread has explicitly requested a thread count via the OpenMP API, this control variable usually defaults to the number of threads supported by the hardware (e.g., the number of available cores). To set the number of requested threads to be used by |zfp|, which may differ from the thread count of encapsulating or surrounding OpenMP parallel regions, call :c:func:`zfp_stream_set_omp_threads`. The user is advised to call the |zfp| API functions to modify OpenMP behavior rather than make direct OpenMP calls. For instance, use :c:func:`zfp_stream_set_omp_threads` rather than :code:`omp_set_num_threads()`. To indicate that the current OpenMP settings should be used, for instance as determined by the global OpenMP environment variable :envvar:`OMP_NUM_THREADS`, pass a thread count of zero (the default setting) to :c:func:`zfp_stream_set_omp_threads`. Note that |zfp| does not modify *nthreads-var* or other control variables but uses a :code:`num_threads` clause on the OpenMP :code:`#pragma` line. Hence, no OpenMP state is changed and any subsequent OpenMP code is not impacted by |zfp|'s parallel compression. .. index:: single: Chunks .. _chunks: OpenMP Chunk Size ^^^^^^^^^^^^^^^^^ The *d*-dimensional array is partitioned into *chunks*, with each chunk representing a contiguous sequence of :ref:`blocks ` of |4powd| array elements each. Chunks represent the unit of parallel work assigned to a thread. By default, the array is partitioned so that each thread processes one chunk. However, the user may override this behavior by setting the chunk size (in number of |zfp| blocks) via :c:func:`zfp_stream_set_omp_chunk_size`. See FAQ :ref:`#25 ` for a discussion of chunk sizes and parallel performance. OpenMP Scheduling ^^^^^^^^^^^^^^^^^ |zfp| does not specify how to schedule chunk processing. The schedule used is given by the OpenMP *def-sched-var* internal control variable. If load balance is poor, it may be improved by using smaller chunks, which may or may not impact performance depending on the OpenMP schedule in use. Future versions of |zfp| may allow specifying how threads are mapped to chunks, whether to use static or dynamic scheduling, etc. .. _exec-mode: Fixed- vs. Variable-Rate Compression ------------------------------------ Following partitioning into chunks, |zfp| assigns each chunk to a thread. If there are more chunks than threads supported, chunks are processed in unspecified order. In :ref:`variable-rate mode `, there is no way to predict the exact number of bits that each chunk compresses to. Therefore, |zfp| allocates a temporary memory buffer for each chunk. Once all chunks have been compressed, they are concatenated into a single bit stream in serial, after which the temporary buffers are deallocated. In :ref:`fixed-rate mode `, the final location of each chunk's bit stream is known ahead of time, and |zfp| may not have to allocate temporary buffers. However, if the chunks are not aligned on :ref:`word boundaries `, then race conditions may occur. In other words, for chunk size *C*, rate *R*, and word size *W*, the rate and chunk size must be such that *C* |times| |4powd| |times| *R* is a multiple of *W* to avoid temporary buffers. Since *W* is a small power of two no larger than 64, this is usually an easy requirement to satisfy. When chunks are whole multiples of the word size, no temporary buffers are allocated and the threads write compressed data directly to the target buffer. The CUDA implementation uses atomics to avoid race conditions, and therefore does not need temporary buffers, regardless of chunk alignment. Using OpenMP ------------ In order to use OpenMP compression, |zfp| must be built with OpenMP support. If built with CMake, OpenMP support is automatically enabled when available. To manually disable OpenMP support, see the :c:macro:`ZFP_WITH_OPENMP` macro. To avoid compilation errors on systems with spotty OpenMP support (e.g., macOS), OpenMP is by default disabled in GNU builds. To enable OpenMP, see :ref:`gnu_builds` and the :c:macro:`ZFP_WITH_OPENMP` macro. Using CUDA ---------- CUDA support is by default disabled. Enabling it requires an installation of CUDA and a compatible host compiler. Furthermore, the :c:macro:`ZFP_WITH_CUDA` macro must be set and |zfp| must be built with CMake. See :c:macro:`ZFP_WITH_CUDA` for further details. Device Memory Management ^^^^^^^^^^^^^^^^^^^^^^^^ The CUDA version of |zfp| supports both host and device memory. If device memory is allocated for fields or compressed streams, this is automatically detected and handled in a consistent manner. For example, with compression, if host memory pointers are provided for both the field and compressed stream, then device memory will transparently be allocated and the uncompressed data will be copied to the GPU. Once compression completes, the compressed stream is copied back to the host and device memory is deallocated. If both pointers are device pointers, then no copies are made. Additionally, any combination of mixing host and device pointers is supported. .. _cuda-limitations: CUDA Limitations ^^^^^^^^^^^^^^^^ The CUDA implementation has a number of limitations: * Only the :ref:`fixed-rate mode ` mode is supported. Other modes will be supported in a future release. * 4D arrays are not supported. * :ref:`Headers
` are not supported. Any header already present in the stream will be silently overwritten on compression. * |zfp| must be built with a :c:macro:`ZFP_BIT_STREAM_WORD_SIZE` of 64 bits. * Although :ref:`strides ` are supported, fields must be contiguous when stored in host memory, i.e., with no unused memory addresses between the minimum and maximum address spanned by the field (see :c:func:`zfp_field_is_contiguous`). This requirement avoids having to copy and allocate more temporary memory than needed to hold the array if it were not strided. Note that the strides can still be arbitrary as long as they serve only to permute the array elements. Moreover, this restriction applies only to the CUDA execution policy and the case where the uncompressed field resides on the host. We expect to address these limitations over time. Setting the Execution Policy ---------------------------- Enabling parallel compression at run time is often as simple as calling :c:func:`zfp_stream_set_execution` :: if (zfp_stream_set_execution(stream, zfp_exec_omp)) { // use OpenMP parallel compression ... zfpsize = zfp_compress(stream, field); } before calling :c:func:`zfp_compress`. Replacing :code:`zfp_exec_omp` with :code:`zfp_exec_cuda` enables CUDA execution. If OpenMP or CUDA is disabled or not supported, then the return value of functions setting these execution policies and parameters will indicate failure. Execution parameters are optional and may be set using the functions discussed above. The source code for the |zfpcmd| command-line tool includes further examples on how to set the execution policy. To use parallel compression and decompression in this tool, see the :option:`-x` command-line option. .. note:: As of |zfp| |cudarelease|, the execution policy refers to both compression and decompression. The OpenMP implementation does not yet support decompression, and hence :c:func:`zfp_decompress` will fail if the execution policy is not reset to :code:`zfp_exec_serial` before calling the decompressor. Similarly, the CUDA implementation supports only fixed-rate mode and will fail if other compression modes are specified. The following table summarizes which execution policies are supported with which :ref:`compression modes `: +---------------------------------+---------+---------+---------+ | (de)compression mode | serial | OpenMP | CUDA | +===============+=================+=========+=========+=========+ | | fixed rate | |check| | |check| | |check| | | +-----------------+---------+---------+---------+ | | fixed precision | |check| | |check| | | | compression +-----------------+---------+---------+---------+ | | fixed accuracy | |check| | |check| | | | +-----------------+---------+---------+---------+ | | reversible | |check| | |check| | | +---------------+-----------------+---------+---------+---------+ | | fixed rate | |check| | | |check| | | +-----------------+---------+---------+---------+ | | fixed precision | |check| | | | | decompression +-----------------+---------+---------+---------+ | | fixed accuracy | |check| | | | | +-----------------+---------+---------+---------+ | | reversible | |check| | | | +---------------+-----------------+---------+---------+---------+ :c:func:`zfp_compress` and :c:func:`zfp_decompress` both return zero if the current execution policy is not supported for the requested compression mode. Parallel Compression -------------------- Once the execution policy and parameters have been selected, compression is executed by calling :c:func:`zfp_compress` from a single thread. This function in turn inspects the execution policy given by the :c:type:`zfp_stream` argument and dispatches the appropriate function for executing compression. Parallel Decompression ---------------------- Parallel decompression is in principle possible using the same strategy as used for compression. However, in |zfp|'s :ref:`variable-rate modes `, the compressed blocks do not occupy fixed storage, and therefore the decompressor needs to be instructed where each compressed block resides in the bit stream to enable parallel decompression. Because the |zfp| bit stream does not currently store such information, variable-rate parallel decompression is not yet supported, though plans are to make such functionality available in the near future. The CUDA implementation supports fixed-rate decompression. OpenMP fixed-rate decompression has been implemented and will be released in the near future. Future versions of |zfp| will allow efficient encoding of block sizes and/or offsets to allow each thread to quickly locate the blocks it is responsible for decompressing, which will allow for variable-rate compression and decompression. Such capabilities are already present in the implementation of the |zfp| :ref:`read-only arrays `. zfp-1.0.1/docs/source/faq.rst000066400000000000000000001604471453723256400160700ustar00rootroot00000000000000.. include:: defs.rst .. cpp:namespace:: zfp FAQ === The following is a list of answers to frequently asked questions. For questions not answered here or elsewhere in the documentation, please `e-mail us `__. Questions answered in this FAQ: 0. :ref:`Do zfp arrays use C or Fortran order? ` #. :ref:`Can zfp compress vector fields? ` #. :ref:`Should I declare a 2D array as zfp::array1d a(nx * ny, rate)? ` #. :ref:`How can I initialize a zfp compressed array from disk? ` #. :ref:`Can I use zfp to represent dense linear algebra matrices? ` #. :ref:`Can zfp compress logically regular but geometrically irregular data? ` #. :ref:`Does zfp handle infinities, NaNs,and subnormal floating-point numbers? ` #. :ref:`Can zfp handle data with some missing values? ` #. :ref:`Can I use zfp to store integer data? ` #. :ref:`Can I compress 32-bit integers using zfp? ` #. :ref:`Why does zfp corrupt memory if my allocated buffer is too small? ` #. :ref:`Are zfp compressed streams portable across platforms? ` #. :ref:`How can I achieve finer rate granularity? ` #. :ref:`Can I generate progressive zfp streams? ` #. :ref:`How do I initialize the decompressor? ` #. :ref:`Must I use the same parameters during compression and decompression? ` #. :ref:`Do strides have to match during compression and decompression? ` #. :ref:`Why does zfp sometimes not respect my error tolerance? ` #. :ref:`Why is the actual rate sometimes not what I requested? ` #. :ref:`Can zfp perform compression in place? ` #. :ref:`Can zfp bound the point-wise relative error? ` #. :ref:`Does zfp support lossless compression? ` #. :ref:`Why is my actual, measured error so much smaller than the tolerance? ` #. :ref:`Are parallel compressed streams identical to serial streams? ` #. :ref:`Are zfp arrays and other data structures thread-safe? ` #. :ref:`Why does parallel compression performance not match my expectations? ` #. :ref:`Why are compressed arrays so slow? ` #. :ref:`Do compressed arrays use reference counting? ` #. :ref:`How large a buffer is needed for compressed storage? ` #. :ref:`How can I print array values? ` #. :ref:`What is known about zfp compression errors? ` ------------------------------------------------------------------------------- .. _q-layout: Q0: *Do zfp arrays use C or Fortran order?* *This is such an important question that we added it as question zero to our FAQ, but do not let this C'ism fool you.* A: |zfp| :ref:`compressed-array classes ` and uncompressed :ref:`fields ` assume that the leftmost index varies fastest, which often is referred to as Fortran order. By convention, |zfp| uses *x* (or *i*) to refer to the leftmost index, then *y* (or *j*), and so on. .. warning:: It is critical that the order of dimensions is specified correctly to achieve good compression and accuracy. If the order of dimensions is transposed, |zfp| will still compress the data, but with no indication that the order was wrong. Compression ratio and/or accuracy will likely suffer significantly, however. Please see :ref:`this section ` for further discussion. In C order, the rightmost index varies fastest (e.g., *x* in :code:`arr[z][y][x]`), meaning that if we increment the rightmost index we move to the next consecutive address in memory. If an uncompressed array, :code:`arr`, is stored in C order, we would for compatibility with |zfp| let *x* be the rightmost index in :code:`arr` but the leftmost index in the compressed |zfp| array, :code:`zarr`, e.g.,:: const size_t nx = 5; const size_t ny = 3; const size_t nz = 2; float arr[nz][ny][nx] = { ... }; zfp::array3 zarr(nx, ny, nz, rate, &a[0][0][0]); Then :code:`arr[z][y][x]` and :code:`zarr(x, y, z)` refer to the same element, as do :code:`(&arr[0][0][0])[sx * x + sy * y + sz * z]` and :code:`zarr[sx * x + sy * y + sz * z]`, where :: ptrdiff_t sx = &arr[0][0][1] - &arr[0][0][0]; // sx = 1 ptrdiff_t sy = &arr[0][1][0] - &arr[0][0][0]; // sy = nx = 5 ptrdiff_t sz = &arr[1][0][0] - &arr[0][0][0]; // sz = nx * ny = 15 Here *sx*, *sy*, and *sz* are the *strides* along the three dimensions, with *sx* < *sy* < *sz*. Of course, C vs. Fortran ordering matters only for multidimensional arrays and when the array dimensions (*nx*, *ny*, *nz*) are not all equal. Note that |zfp| :ref:`fields ` also support strides, which can be used to represent more general layouts than C and Fortran order, including non-contiguous storage, reversed dimensions via negative strides, and other advanced layouts. With the default strides, however, it is correct to think of |zfp| as using Fortran order. For uncompressed data stored in C order, one easily translates to |zfp| Fortran order by reversing the order of dimensions or by specifying appropriate :ref:`strides `. We further note that |zfp| provides :ref:`nested views ` of arrays that support C indexing syntax, e.g., :code:`view[z][y][x]` corresponds to :code:`arr(x, y, z)`. .. note:: The |zfp| :ref:`NumPy interface ` uses the strides of the NumPy array to infer the correct layout. Although NumPy arrays use C order by default, |zfp| handles such arrays correctly regardless of their memory layout. The actual order of dimensions for compressed storage are, however, reversed so that NumPy arrays in C order are traversed sequentially during compression. Why does |zfp| use Fortran order when C is today a far more common language? This choice is somewhat arbitrary yet has strong proponents in either camp, similar to the preference between :ref:`little and big endian ` byte order. We believe that a single 2D array storing an (*x*, *y*) image is most naturally extended to a sequence of *nt* time-varying images by *appending* (not prepending) a time dimension *t* as (*x*, *y*, *t*). This is the convention used in mathematics, e.g., we use (*x*, *y*) coordinates in 2D and (*x*, *y*, *z*) coordinates in 3D. Using Fortran order, each time slice, *t*, is still a 2D contiguous image, while C order (:code:`arr[x][y][t]`) would suggest that appending the *t* dimension now gives us *nx* 2D arrays indexed by (*y*, *t*), even though without the *t* dimension the images would be indexed by (*x*, *y*). ------------------------------------------------------------------------------- .. _q-vfields: Q1: *Can zfp compress vector fields?* I have a 2D vector field :: double velocity[ny][nx][2]; of dimensions *nx* |times| *ny*. Can I use a 3D |zfp| array to store this as:: array3d velocity(2, nx, ny, rate); A: Although this could be done, zfp assumes that consecutive values are related. The two velocity components (*vx*, *vy*) are almost assuredly independent and would not be correlated. This will severely hurt the compression rate or quality. Instead, consider storing *vx* and *vy* as two separate 2D scalar arrays:: array2d vx(nx, ny, rate); array2d vy(nx, ny, rate); or as :: array2d velocity[2] = {array2d(nx, ny, rate), array2d(nx, ny, rate)}; ------------------------------------------------------------------------------- .. _q-array2d: Q2: *Should I declare a 2D array as zfp::array1d a(nx * ny, rate)?* I have a 2D scalar field of dimensions *nx* |times| *ny* that I allocate as :: double* a = new double[nx * ny]; and index as :: a[x + nx * y] Should I use a corresponding zfp array :: array1d a(nx * ny, rate); to store my data in compressed form? A: Although this is certainly possible, if the scalar field exhibits coherence in both spatial dimensions, then far better results can be achieved by using a 2D array:: array2d a(nx, ny, rate); Although both compressed arrays can be indexed as above, the 2D array can exploit smoothness in both dimensions and improve the quality dramatically for the same rate. Since |zfp| 0.5.2, proxy pointers are also available that act much like the flat :code:`double*`. ------------------------------------------------------------------------------- .. _q-read: Q3: *How can I initialize a zfp compressed array from disk?* I have a large, uncompressed, 3D data set:: double a[nz][ny][nx]; stored on disk that I would like to read into a compressed array. This data set will not fit in memory uncompressed. What is the best way of doing this? A: Using a |zfp| array:: array3d a(nx, ny, nz, rate); the most straightforward (but perhaps not best) way is to read one floating-point value at a time and copy it into the array:: for (size_t z = 0; z < nz; z++) for (size_t y = 0; y < ny; y++) for (size_t x = 0; x < nx; x++) { double f; if (fread(&f, sizeof(f), 1, file) == 1) a(x, y, z) = f; else { // handle I/O error } } Note, however, that if the array cache is not large enough, then this may compress blocks before they have been completely filled. Therefore it is recommended that the cache holds at least one complete layer of blocks, i.e., (*nx* / 4) |times| (*ny* / 4) blocks in the example above. To avoid inadvertent evictions of partially initialized blocks, it is better to buffer four layers of *nx* |times| *ny* values each at a time, when practical, and to completely initialize one block after another, which is facilitated using |zfp|'s iterators:: double* buffer = new double[nx * ny * 4]; int zmin = -4; for (zfp::array3d::iterator it = a.begin(); it != a.end(); it++) { int x = it.i(); int y = it.j(); int z = it.k(); if (z > zmin + 3) { // read another layer of blocks if (fread(buffer, sizeof(*buffer), nx * ny * 4, file) != nx * ny * 4) { // handle I/O error } zmin += 4; } a(x, y, z) = buffer[x + nx * (y + ny * (z - zmin))]; } Iterators have been available since |zfp| 0.5.2. ------------------------------------------------------------------------------- .. _q-matrix: Q4: *Can I use zfp to represent dense linear algebra matrices?* A: Yes, but your mileage may vary. Dense matrices, unlike smooth scalar fields, rarely exhibit correlation between adjacent rows and columns. Thus, the quality or compression ratio may suffer. ------------------------------------------------------------------------------- .. _q-structured: Q5: *Can zfp compress logically regular but geometrically irregular data?* My data is logically structured but irregularly sampled, e.g., it is rectilinear, curvilinear, or Lagrangian, or uses an irregular spacing of quadrature points. Can I still use zfp to compress it? A: Yes, as long as the data is (or can be) represented as a logical multidimensional array, though your mileage may vary. |zfp| has been designed for uniformly sampled data, and compression will in general suffer the more irregular the sampling is. ------------------------------------------------------------------------------- .. _q-valid: Q6: *Does zfp handle infinities, NaNs,and subnormal floating-point numbers?* A: Yes, but only in :ref:`reversible mode `. |zfp|'s lossy compression modes currently support only finite floating-point values. If a block contains a NaN or an infinity, undefined behavior is invoked due to the C math function :c:func:`frexp` being undefined for non-numbers. Subnormal numbers are, however, handled correctly. ------------------------------------------------------------------------------- .. _q-missing: Q7: *Can zfp handle data with some missing values?* My data has some missing values that are flagged by very large numbers, e.g. 1e30. Is that OK? A: Although all finite numbers are "correctly" handled, such large sentinel values are likely to pollute nearby values, because all values within a block are expressed with respect to a common largest exponent. The presence of very large values may result in complete loss of precision of nearby, valid numbers. Currently no solution to this problem is available, but future versions of |zfp| will likely support a bit mask to tag values that should be excluded from compression. ------------------------------------------------------------------------------- .. _q-integer: Q8: *Can I use zfp to store integer data?* Can I use zfp to store integer data such as 8-bit quantized images or 16-bit digital elevation models? A: Yes (as of version 0.4.0), but the data has to be promoted to 32-bit signed integers first. This should be done one block at a time using an appropriate :code:`zfp_promote_*_to_int32` function call (see :ref:`ll-utilities`). Future versions of |zfp| may provide a high-level interface that automatically performs promotion and demotion. Note that the promotion functions shift the low-precision integers into the most significant bits of 31-bit (not 32-bit) integers and also convert unsigned to signed integers. Do use these functions rather than simply casting 8-bit integers to 32 bits to avoid wasting compressed bits to encode leading zeros. Moreover, in fixed-precision mode, set the precision relative to the precision of the (unpromoted) source data. As of version 0.5.1, integer data is supported both by the low-level API and high-level calls :c:func:`zfp_compress` and :c:func:`zfp_decompress`. ------------------------------------------------------------------------------- .. _q-int32: Q9: *Can I compress 32-bit integers using zfp?* I have some 32-bit integer data. Can I compress it using |zfp|'s 32-bit integer support? A: Yes, this can safely be done in :ref:`reversible mode `. In other (lossy) modes, the answer depends. |zfp| compression of 32-bit and 64-bit integers requires that each integer *f* have magnitude \|\ *f*\ \| < 2\ :sup:`30` and \|\ *f*\ \| < 2\ :sup:`62`, respectively. To handle signed integers that span the entire range |minus|\ 2\ :sup:`31` |leq| x < 2\ :sup:`31`, or unsigned integers 0 |leq| *x* < 2\ :sup:`32`, the data has to be promoted to 64 bits first. As with floating-point data, the integers should ideally represent a quantized continuous function rather than, say, categorical data or set of indices. Depending on compression settings and data range, the integers may or may not be losslessly compressed. If fixed-precision mode is used, the integers may be stored at less precision than requested. See :ref:`Q21 ` for more details on precision and lossless compression. ------------------------------------------------------------------------------- .. _q-overrun: Q10: *Why does zfp corrupt memory if my allocated buffer is too small?* Why does |zfp| corrupt memory rather than return an error code if not enough memory is allocated for the compressed data? A: This is for performance reasons. |zfp| was primarily designed for fast random access to fixed-rate compressed arrays, where checking for buffer overruns is unnecessary. Adding a test for every compressed byte output would significantly compromise performance. One way around this problem (when not in fixed-rate mode) is to use the :c:data:`maxbits` parameter in conjunction with the maximum precision or maximum absolute error parameters to limit the size of compressed blocks. Finally, the function :c:func:`zfp_stream_maximum_size` returns a conservative buffer size that is guaranteed to be large enough to hold the compressed data and the optional header. ------------------------------------------------------------------------------- .. index:: single: Endianness .. _q-portability: Q11: *Are zfp compressed streams portable across platforms?* Are |zfp| compressed streams portable across platforms? Are there, for example, endianness issues? A: Yes, |zfp| can write portable compressed streams. To ensure portability across different endian platforms, the bit stream must however be written in increments of single bytes on big endian processors (e.g., PowerPC, SPARC), which is achieved by compiling |zfp| with an 8-bit (single-byte) word size:: -DBIT_STREAM_WORD_TYPE=uint8 See :c:macro:`BIT_STREAM_WORD_TYPE`. Note that on little endian processors (e.g., Intel x86-64 and AMD64), the word size does not affect the bit stream produced, and thus the default word size may be used. By default, |zfp| uses a word size of 64 bits, which results in the coarsest rate granularity but fastest (de)compression. If cross-platform portability is not needed, then the maximum word size is recommended (but see also :ref:`Q12 `). When using 8-bit words, |zfp| produces a compressed stream that is byte order independent, i.e., the exact same compressed sequence of bytes is generated on little and big endian platforms. When decompressing such streams, floating-point and integer values are recovered in the native byte order of the machine performing decompression. The decompressed values can be used immediately without the need for byte swapping and without having to worry about the byte order of the computer that generated the compressed stream. Finally, |zfp| assumes that the floating-point format conforms to IEEE 754. Issues may arise on architectures that do not support IEEE floating point. ------------------------------------------------------------------------------- .. _q-granularity: Q12: *How can I achieve finer rate granularity?* A: For *d*-dimensional data, |zfp| supports a rate granularity of 1 / |4powd| bits, i.e., the rate can be specified in increments of a fraction of a bit. Such fine rate selection is always available for sequential compression (e.g., when calling :c:func:`zfp_compress`). Unlike in sequential compression, |zfp|'s :ref:`read-write compressed-array classes ` require random-access writes, which are supported only at the granularity of whole words. By default, a word is 64 bits, which gives a rate granularity of 64 / |4powd| in *d* dimensions, i.e., 16 bits in 1D, 4 bits in 2D, 1 bit in 3D, and 0.25 bits in 4D. :ref:`Read-only compressed arrays ` support the same fine granularity as sequential compression. To achieve finer granularity, build |zfp| with a smaller (but as large as possible) stream word size, e.g.:: -DBIT_STREAM_WORD_TYPE=uint8 gives the finest possible granularity, but at the expense of (de)compression speed. See :c:macro:`BIT_STREAM_WORD_TYPE`. ------------------------------------------------------------------------------- .. _q-progressive: Q13: *Can I generate progressive zfp streams?* A: Yes, but it requires some coding effort. There is currently no high-level support for progressive |zfp| streams. To implement progressive fixed-rate streams, the fixed-length bit streams should be interleaved among the blocks that make up an array. For instance, if a 3D array uses 1024 bits per block, then those 1024 bits could be broken down into, say, 16 pieces of 64 bits each, resulting in 16 discrete quality settings. By storing the blocks interleaved such that the first 64 bits of all blocks are contiguous, followed by the next 64 bits of all blocks, etc., one can achieve progressive decompression by setting the :c:member:`zfp_stream.maxbits` parameter (see :c:func:`zfp_stream_set_params`) to the number of bits per block received so far. To enable interleaving of blocks, |zfp| must first be compiled with:: -DBIT_STREAM_STRIDED to enable strided bit stream access. In the example above, if the stream word size is 64 bits and there are *n* blocks, then:: stream_set_stride(stream, m, n); implies that after every *m* 64-bit words have been decoded, the bit stream is advanced by *m* |times| *n* words to the next set of m 64-bit words associated with the block. ------------------------------------------------------------------------------- .. _q-init: Q14: *How do I initialize the decompressor?* A: The :c:type:`zfp_stream` and :c:type:`zfp_field` objects usually need to be initialized with the same values as they had during compression (but see :ref:`Q15 ` for exceptions). These objects hold the compression mode and parameters, and field data like the scalar type and dimensions. By default, these parameters are not stored with the compressed stream (the "codestream") and prior to |zfp| 0.5.0 had to be maintained separately by the application. Since version 0.5.0, functions exist for reading and writing a 12- to 19-byte header that encodes compression and field parameters. For applications that wish to embed only the compression parameters, e.g., when the field dimensions are already known, there are separate functions that encode and decode this information independently. ------------------------------------------------------------------------------- .. _q-same: Q15: *Must I use the same parameters during compression and decompression?* A: Not necessarily. When decompressing one block at a time, it is possible to use more tightly constrained :c:type:`zfp_stream` parameters during decompression than were used during compression. For instance, one may use a smaller :c:member:`zfp_stream.maxbits`, smaller :c:member:`zfp_stream.maxprec`, or larger :c:member:`zfp_stream.minexp` during decompression to process fewer compressed bits than are stored, and to decompress the array more quickly at a lower precision. This may be useful in situations where the precision and accuracy requirements are not known a priori, thus forcing conservative settings during compression, or when the compressed stream is used for multiple purposes. For instance, visualization usually has less stringent precision requirements than quantitative data analysis. This feature of decompressing to a lower precision is particularly useful when the stream is stored progressively (see :ref:`Q13 `). Note that one may not use less constrained parameters during decompression, e.g., one cannot ask for more than :c:member:`zfp_stream.maxprec` bits of precision when decompressing. Furthermore, the parameters must agree between compression and decompression when calling the high-level API function :c:func:`zfp_decompress`. Currently float arrays have a different compressed representation from compressed double arrays due to differences in exponent width. It is not possible to compress a double array and then decompress (demote) the result to floats, for instance. Future versions of the |zfp| codec may use a unified representation that does allow this. ------------------------------------------------------------------------------- .. _q-strides: Q16: *Do strides have to match during compression and decompression?* A: No. For instance, a 2D vector field:: float in[ny][nx][2]; could be compressed as two scalar fields with strides *sx* = 2, *sy* = 2 |times| *nx*, and with pointers :code:`&in[0][0][0]` and :code:`&in[0][0][1]` to the first value of each scalar field. These two scalar fields can later be decompressed as non-interleaved fields:: float out[2][ny][nx]; using strides *sx* = 1, *sy* = *nx* and pointers :code:`&out[0][0][0]` and :code:`&out[1][0][0]`. ------------------------------------------------------------------------------- .. _q-tolerance: Q17: *Why does zfp sometimes not respect my error tolerance?* A: First, |zfp| does not support :ref:`fixed-accuracy mode ` for integer data and will ignore any tolerance requested via :c:func:`zfp_stream_set_accuracy` or associated :ref:`expert mode ` parameter settings. So this FAQ pertains to floating-point data only. The short answer is that, given finite precision, the |zfp| and IEEE floating-point number systems represent distinct subsets of the reals (or, in case of |zfp|, blocks of reals). Although these subsets have significant overlap, they are not equal. Consequently, there are some combinations of floating-point values that |zfp| cannot represent exactly; conversely, there are some |zfp| blocks that cannot be represented exactly as IEEE floating point. If the user-specified tolerance is smaller than the difference between the IEEE floating-point representation to be compressed and its closest |zfp| representation, then the tolerance necessarily will be violated (except in :ref:`reversible mode `). In practice, absolute tolerances have to be extremely small relative to the numbers being compressed for this issue to occur, however. Note that this issue is not particular to |zfp| but occurs in the conversion between any two number systems of equal precision; we may just as well fault IEEE floating point for not being able to represent all |zfp| blocks accurately enough! By analogy, not all 32-bit integers can be represented exactly in 32-bit floating point. The integer 123456789 is one example; the closest float is 123456792. And, obviously, not all floats (e.g., 0.5) can be represented exactly as integers. To further demonstrate this point, let us consider a concrete example. |zfp| does not store each floating-point scalar value independently but represents a group of values (4, 16, 64, or 256 values, depending on dimensionality) as linear combinations like averages by evaluating arithmetic expressions. Just like in uncompressed IEEE floating-point arithmetic, both representation error and roundoff error in the least significant bit(s) often occur. To illustrate this, consider compressing the following 1D array of four floats :: float f[4] = { 1, 1e-1, 1e-2, 1e-3 }; using the |zfp| command-line tool:: zfp -f -1 4 -a 0 -i input.dat -o output.dat In spite of an error tolerance of zero, the reconstructed values are:: float g[4] = { 1, 1e-1, 9.999998e-03, 9.999946e-04 }; with a (computed) maximum error of 5.472e-9. Because f[3] = 1e-3 can only be approximately represented in radix-2 floating-point, the actual error is even smaller: 5.424e-9. This reconstruction error is primarily due to |zfp|'s block-floating-point representation, which expresses the four values in a block relative to a single, common binary exponent. Such exponent alignment occurs also in regular IEEE floating-point operations like addition. For instance, :: float x = (f[0] + f[3]) - 1; should of course result in :code:`x = f[3] = 1e-3`, but due to exponent alignment a few of the least significant bits of f[3] are lost in the rounded result of the addition, giving :code:`x = 1.0000467e-3` and a roundoff error of 4.668e-8. Similarly, :: float sum = f[0] + f[1] + f[2] + f[3]; should return :code:`sum = 1.111`, but is computed as 1.1110000610. Moreover, the value 1.111 cannot even be represented exactly in (radix-2) floating-point; the closest float is 1.1109999. Thus the computed error :: float error = sum - 1.111f; which itself has some roundoff error, is 1.192e-7. *Phew*! Note how the error introduced by |zfp| (5.472e-9) is in fact one to two orders of magnitude smaller than the roundoff errors (4.668e-8 and 1.192e-7) introduced by IEEE floating point in these computations. This lower error is in part due to |zfp|'s use of 30-bit significands compared to IEEE's 24-bit single-precision significands. Note that data sets with a large dynamic range, e.g., where adjacent values differ a lot in magnitude, are more susceptible to representation errors. The moral of the story is that error tolerances smaller than machine epsilon (relative to the data range) cannot always be satisfied by |zfp|. Nor are such tolerances necessarily meaningful for representing floating-point data that originated in floating-point arithmetic expressions, since accumulated roundoff errors are likely to swamp compression errors. Because such roundoff errors occur frequently in floating-point arithmetic, insisting on lossless compression on the grounds of accuracy is tenuous at best. ------------------------------------------------------------------------------- .. _q-rate: Q18: *Why is the actual rate sometimes not what I requested?* A: In principle, |zfp| allows specifying the size of a compressed block in increments of single bits, thus allowing very fine-grained tuning of the bit rate. There are, however, cases when the desired rate does not exactly agree with the effective rate, and users are encouraged to check the return value of :c:func:`zfp_stream_set_rate`, which gives the actual rate. There are several reasons why the requested rate may not be honored. First, the rate is specified in bits/value, while |zfp| always represents a block of |4powd| values in *d* dimensions, i.e., using *N* = |4powd| |times| *rate* bits. *N* must be an integer number of bits, which constrains the actual rate to be a multiple of 1 / |4powd|. The actual rate is computed by rounding |4powd| times the desired rate. Second, if the array dimensions are not multiples of four, then |zfp| pads the dimensions to the next higher multiple of four. Thus, the total number of bits for a 2D array of dimensions *nx* |times| *ny* is computed in terms of the number of blocks *bx* |times| *by*:: bitsize = (4 * bx) * (4 * by) * rate where *nx* |leq| 4 |times| bx < *nx* + 4 and *ny* |leq| 4 |times| *by* < *ny* + 4. When amortizing bitsize over the *nx* |times| *ny* values, a slightly higher rate than requested may result. Third, to support updating compressed blocks, as is needed by |zfp|'s compressed array classes, the user may request write random access to the fixed-rate stream. To support this, each block must be aligned on a stream word boundary (see :ref:`Q12 `), and therefore the rate when write random access is requested must be a multiple of *wordsize* / |4powd| bits. By default *wordsize* = 64 bits. Even when write random access is not requested, the compressed stream is written in units of *wordsize*. Hence, once the stream is flushed, either by a :c:func:`zfp_compress` or :c:func:`zfp_stream_flush` call, to output any buffered bits, its size will be a multiple of *wordsize* bits. Fourth, for floating-point data, each block must hold at least the common exponent and one additional bit, which places a lower bound on the rate. Finally, the user may optionally include a header with each array. Although the header is small, it must be accounted for in the rate. The function :c:func:`zfp_stream_maximum_size` conservatively includes space for a header, for instance. Aside from these caveats, |zfp| is guaranteed to meet the exact rate specified. ------------------------------------------------------------------------------- .. _q-inplace: Q19: *Can zfp perform compression in place?* A: Because the compressed data tends to be far smaller than the uncompressed data, it is natural to ask if the compressed stream can overwrite the uncompressed array to avoid having to allocate separate storage for the compressed stream. |zfp| does allow for the possibility of such in-place compression, but with several caveats and restrictions: 1. A bitstream must be created whose buffer points to the beginning of uncompressed (and to be compressed) storage. 2. The array must be compressed using |zfp|'s low-level API. In particular, the data must already be partitioned and organized into contiguous blocks so that all values of a block can be pulled out once and then replaced with the corresponding shorter compressed representation. 3. No one compressed block can occupy more space than its corresponding uncompressed block so that the not-yet compressed data is not overwritten. This is usually easily accomplished in fixed-rate mode, although the expert interface also allows guarding against this in all modes using the :c:member:`zfp_stream.maxbits` parameter. This parameter should be set to :code:`maxbits = 4^d * sizeof(type) * 8`, where *d* is the array dimensionality (1, 2, 3, or 4) and where *type* is the scalar type of the uncompressed data. 4. No header information may be stored in the compressed stream. In-place decompression can also be achieved, but in addition to the above constraints requires even more care: 1. The data must be decompressed in reverse block order, so that the last block is decompressed first to the end of the block array. This requires the user to maintain a pointer to uncompressed storage and to seek via :c:func:`stream_rseek` to the proper location in the compressed stream where the block is stored. 2. The space allocated to the compressed stream must be large enough to also hold the uncompressed data. An :ref:`example ` is provided that shows how in-place compression can be done. ------------------------------------------------------------------------------- .. _q-relerr: Q20: *Can zfp bound the point-wise relative error?* A: Yes, but with some caveats. First, we define the relative error in a value *f* approximated by *g* as \|\ *f* - *g*\ \| / \|\ *f*\ \|, which converges to \|\ log(*f* / *g*)\ \| = \|\ log(*f*) - \ log(*g*)\| as *g* approaches *f*, where log(*f*) denotes the natural logarithm of *f*. Below, we discuss three strategies for relative error control that may be applicable depending on the properties of the underlying floating-point data. If all floating-point values to be compressed are normalized, i.e., with no nonzero subnormal values smaller in magnitude than 2\ :sup:`-126` |approx| 10\ :sup:`-38` (for floats) or 2\ :sup:`-1022` |approx| 10\ :sup:`-308` (for doubles), then the relative error can be bounded using |zfp|'s :ref:`expert mode ` settings by invoking :ref:`reversible mode `. This is achieved by truncating (zeroing) some number of least significant bits of all floating-point values and then losslessly compressing the result. The *q* least significant bits of *n*-bit floating-point numbers (*n* = 32 for floats and *n* = 64 for doubles) are truncated by |zfp| by specifying a maximum precision of *p* = *n* |minus| *q*. The resulting point-wise relative error is then at most 2\ :sup:`q - 23` (for floats) or 2\ :sup:`q - 52` (for doubles). .. note:: For large enough *q*, floating-point exponent bits will be discarded, in which case the bound no longer holds, but then the relative error is already above 100%. Also, as mentioned, the bound does not hold for subnormals; however, such values are likely too small for relative errors to be meaningful. To bound the relative error, set the expert mode parameters to:: minbits = 0 maxbits = 0 maxprec = p minexp = ZFP_MIN_EXP - 1 = -1075 For example, using the |zfpcmd| command-line tool, set the parameters using :option:`-c` :code:`0 0 p -1075`. Note that while the above approach respects the error bound when the above conditions are met, it uses |zfp| for a purpose it was not designed for, and the compression ratio may not be competitive with those obtained using compressors designed to bound the relative error. Other forms of relative error control can be achieved using |zfp|'s lossy compression modes. In :ref:`fixed-accuracy mode `, the *absolute error* \|\ *f* - *g*\ \| is bounded by a user-specified error tolerance. For a field whose values are all positive (or all negative), we may pre-transform values by taking the natural logarithm, replacing each value *f* with log(*f*) before compression, and then exponentiating values after decompression. This ensures that \|\ log(*f*) - log(*g*)\ \| = \|\ log(*f* / *g*)\ \| is bounded. (Note, however, that many implementations of the math library make no guarantees on the accuracy of the logarithm function.) For fields whose values are signed, an approximate bound can be achieved by using log(*f*) |approx| asinh(*f* / 2), where asinh is the inverse of the hyperbolic sine function, which is defined for both positive and negative numbers. One benefit of this approach is that it de-emphasizes the importance of relative errors for small values that straddle zero, where relative errors rarely make sense, e.g., because of round-off and other errors already present in the data. Finally, in :ref:`fixed-precision mode `, the precision of |zfp| transform coefficients is fixed, resulting in an error that is no more than a constant factor of the largest (in magnitude) value, *fmax*, within the same |zfp| block. This can be thought of as a weaker version of relative error, where the error is measured relative to values in a local neighborhood. In fixed-precision mode, |zfp| cannot bound the point-wise relative error due to its use of a block-floating-point representation, in which all values within a block are represented in relation to a single common exponent. For a high enough dynamic range within a block, there may simply not be enough precision available to guard against loss. For instance, a block containing the values 2\ :sup:`0` = 1 and 2\ :sup:`-n` would require a precision of *n* + 3 bits to represent losslessly, and |zfp| uses at most 64-bit integers to represent values. Thus, if *n* |geq| 62, then 2\ :sup:`-n` is replaced with 0, which is a 100% relative error. Note that such loss also occurs when, for instance, 2\ :sup:`0` and 2\ :sup:`-n` are added using floating-point arithmetic (see also :ref:`Q17 `). As alluded to, it is possible to bound the error relative to the largest value, *fmax*, within a block, which if the magnitude of values does not change too rapidly may serve as a reasonable proxy for point-wise relative errors. One might then ask if using |zfp|'s fixed-precision mode with *p* bits of precision ensures that the block-wise relative error is at most 2\ :sup:`-p` |times| *fmax*. This is, unfortunately, not the case, because the requested precision, *p*, is ensured only for the transform coefficients. During the inverse transform of these quantized coefficients the quantization error may amplify. That being said, it is possible to derive a bound on the error in terms of *p* that would allow choosing an appropriate precision. Such a bound is derived below. Let :: emax = floor(log2(fmax)) be the largest base-2 exponent within a block. For transform coefficient precision, *p*, one can show that the maximum absolute error, *err*, is bounded by:: err <= k(d) * (2^emax / 2^p) <= k(d) * (fmax / 2^p) Here *k*\ (*d*) is a constant that depends on the data dimensionality *d*:: k(d) = 20 * (15/4)^(d-1) so that in 1D, 2D, 3D, and 4D we have:: k(1) = 20 k(2) = 125 k(3) = 1125/4 k(4) = 16876/16 Thus, to guarantee *n* bits of accuracy in the decompressed data, we need to choose a higher precision, *p*, for the transform coefficients:: p(n, d) = n + ceil(log2(k(d))) = n + 2 * d + 3 so that :: p(n, 1) = n + 5 p(n, 2) = n + 7 p(n, 3) = n + 9 p(n, 4) = n + 11 This *p* value should be used in the call to :c:func:`zfp_stream_set_precision`. Note, again, that some values in the block may have leading zeros when expressed relative to 2\ :sup:`emax`, and these leading zeros are counted toward the *n*-bit precision. Using decimal to illustrate this, suppose we used 4-digit precision for a 1D block containing these four values:: -1.41421e+1 ~ -1.414e+1 = -1414 * (10^1 / 1000) +2.71828e-1 ~ +0.027e+1 = +27 * (10^1 / 1000) +3.14159e-6 ~ +0.000e+1 = 0 * (10^1 / 1000) +1.00000e+0 ~ +0.100e+1 = +100 * (10^1 / 1000) with the values in the middle column aligned to the common base-10 exponent +1, and with the values on the right expressed as scaled integers. These are all represented using four digits of precision, but some of those digits are leading zeros. ------------------------------------------------------------------------------- .. _q-lossless: Q21: *Does zfp support lossless compression?* A: Yes. As of |zfp| |revrelease|, bit-for-bit lossless compression is supported via the :ref:`reversible compression mode `. This mode supports both integer and floating-point data. In addition, it is sometimes possible to ensure lossless compression using |zfp|'s fixed-precision and fixed-accuracy modes. For integer data, |zfp| can with few exceptions ensure lossless compression in :ref:`fixed-precision mode `. For a given *n*-bit integer type (*n* = 32 or *n* = 64), consider compressing *p*-bit signed integer data, with the sign bit counting toward the precision. In other words, there are exactly 2\ :sup:`p` possible signed integers. If the integers are unsigned, then subtract 2\ :sup:`p-1` first so that they range from |minus|\ 2\ :sup:`p-1` to 2\ :sup:`p-1` - 1. Lossless integer compression in fixed-precision mode is achieved by first promoting the *p*-bit integers to *n* - 1 bits (see :ref:`Q8 `) such that all integer values fall in [|minus|\ 2\ :sup:`30`, +2\ :sup:`30`), when *n* = 32, or in [|minus|\ 2\ :sup:`62`, +2\ :sup:`62`), when *n* = 64. In other words, the *p*-bit integers first need to be shifted left by *n* - *p* - 1 bits. After promotion, the data should be compressed in zfp's fixed-precision mode using:: q = p + 4 * d + 1 bits of precision to ensure no loss, where *d* is the data dimensionality (1 |leq| d |leq| 4). Consequently, the *p*-bit data can be losslessly compressed as long as *p* |leq| *n* - 4 |times| *d* - 1. The table below lists the maximum precision *p* that can be losslessly compressed using 32- and 64-bit integer types. = ==== ==== d n=32 n=64 = ==== ==== 1 27 59 2 23 55 3 19 51 4 15 47 = ==== ==== Although lossless compression is possible as long as the precision constraint is met, the precision needed to guarantee no loss is generally much higher than the precision intrinsic in the uncompressed data. Therefore, we recommend using the :ref:`reversible mode ` when lossless compression is desired. The minimum precision, *q*, given above is often larger than what is necessary in practice. There are worst-case inputs that do require such large *q* values, but they are quite rare. The reason for expanded precision, i.e., why *q* > *p*, is that |zfp|'s decorrelating transform computes averages of integers, and this transform is applied *d* times in *d* dimensions. Each average of two *p*-bit numbers requires *p* + 1 bits to avoid loss, and each transform can be thought of involving up to four such averaging operations. For floating-point data, fully lossless compression with |zfp| usually requires :ref:`reversible mode `, as the other compression modes are unlikely to guarantee bit-for-bit exact reconstructions. However, if the dynamic range is low or varies slowly such that values within a |4powd| block have the same or similar exponent, then the precision gained by discarding the 8 or 11 bits of the common floating-point exponents can offset the precision lost in the decorrelating transform. For instance, if all values in a block have the same exponent, then lossless compression is obtained using *q* = 26 + 4 |times| *d* |leq| 32 bits of precision for single-precision data and *q* = 55 + 4 |times| *d* |leq| 64 bits of precision for double-precision data. Of course, the constraint imposed by the available integer precision *n* implies that lossless compression of such data is possible only in 1D for single-precision data and only in 1D and 2D for double-precision data. Finally, to preserve special values such as negative zero, plus and minus infinity, and NaNs, reversible mode is needed. ------------------------------------------------------------------------------- .. _q-abserr: Q22: *Why is my actual, measured error so much smaller than the tolerance?* A: For two reasons. The way |zfp| bounds the absolute error in :ref:`fixed-accuracy mode ` is by keeping all transform coefficient bits whose place value exceeds the tolerance while discarding the less significant bits. Each such bit has a place value that is a power of two, and therefore the tolerance must first be rounded down to the next smaller power of two, which itself will introduce some slack. This possibly lower, effective tolerance is returned by the :c:func:`zfp_stream_set_accuracy` call. Second, the quantized coefficients are then put through an inverse transform. This linear transform will combine signed quantization errors that, in the worst case, may cause them to add up and increase the error, even though the average (RMS) error remains the same, i.e., some errors cancel while others compound. For *d*-dimensional data, *d* such inverse transforms are applied, with the possibility of errors cascading across transforms. To account for the worst possible case, zfp has to conservatively lower its internal error tolerance further, once for each of the *d* transform passes. Unless the data is highly oscillatory or noisy, the error is not likely to be magnified much, leaving an observed error in the decompressed data that is much lower than the prescribed tolerance. In practice, the observed maximum error tends to be about 4-8 times lower than the error tolerance for 3D data, while the difference is smaller for 2D and 1D data. We recommend experimenting with tolerances and evaluating what error levels are appropriate for each application, e.g., by starting with a low, conservative tolerance and successively doubling it. The distribution of errors produced by |zfp| is approximately Gaussian (see :ref:`Q30 `), so even if the maximum error may seem large at an individual grid point, most errors tend to be much smaller and tightly clustered around zero. ------------------------------------------------------------------------------- .. _q-parallel: Q23: *Are parallel compressed streams identical to serial streams?* A: Yes, it matters not what execution policy is used; the final compressed stream produced by :c:func:`zfp_compress` depends only on the uncompressed data and compression settings. To support future parallel decompression, in particular variable-rate streams, it will be necessary to also store an index of where (at what bit offset) each compressed block is stored in the stream. Extensions to the current |zfp| format are being considered to support parallel decompression. Regardless, the execution policy and parameters such as number of threads do not need to be the same for compression and decompression. ------------------------------------------------------------------------------- .. _q-thread-safety: Q24: *Are zfp's compressed arrays and other data structures thread-safe?* A: Yes, compressed arrays can be made thread-safe; no, data structures like :c:type:`zfp_stream` and :c:type:`bitstream` are not necessarily thread-safe. As of |zfp| |viewsrelease|, thread-safe read and write access to compressed arrays via OpenMP threads is provided through the use of :ref:`private views `, although these come with certain restrictions and requirements such as the need for the user to enforce cache coherence. Please see the documentation on :ref:`views ` for further details. As far as C objects, |zfp|'s parallel OpenMP compressor assigns one :c:type:`zfp_stream` per thread, each of which uses its own private :c:type:`bitstream`. Users who wish to make parallel calls to |zfp|'s :ref:`low-level functions ` are advised to consult the source files :file:`ompcompress.c` and :file:`parallel.c`. Finally, the |zfp| API is thread-safe as long as multiple threads do not simultaneously call API functions and pass the same :c:type:`zfp_stream` or :c:type:`bitstream` object. ------------------------------------------------------------------------------- .. _q-omp-perf: Q25: *Why does parallel compression performance not match my expectations?* A: |zfp| partitions arrays into chunks and assigns each chunk to an OpenMP thread. A chunk is a sequence of consecutive *d*-dimensional blocks, each composed of |4powd| values. If there are fewer chunks than threads, then full processor utilization will not be achieved. The number of chunks is by default set to the number of threads, but can be modified by the user via :c:func:`zfp_stream_set_omp_chunk_size`. One reason for using more chunks than threads is to provide for better load balance. If compression ratios vary significantly across the array, then threads that process easy-to-compress blocks may finish well ahead of threads in charge of difficult-to-compress blocks. By breaking chunks into smaller units, OpenMP is given the opportunity to balance the load better (though the effect of using smaller chunks depends on OpenMP thread scheduling). If chunks are too small, however, then the overhead of allocating and initializing chunks and assigning threads to them may dominate. Experimentation with chunk size may improve performance, though chunks ought to be at least several hundred blocks each. In variable-rate mode, compressed chunk sizes are not known ahead of time. Therefore the compressed chunks must be concatenated into a single stream following compression. This task is performed sequentially on a single thread, and will inevitably limit parallel efficiency. Other reasons for poor parallel performance include compressing arrays that are too small to offset the overhead of thread creation and synchronization. Arrays should ideally consist of thousands of blocks to offset the overhead of setting up parallel compression. ------------------------------------------------------------------------------- .. _q-1d-speed: Q26: *Why are compressed arrays so slow?* A: This is likely due to the use of a very small cache. Prior to |zfp| |csizerelease|, all arrays used two 'layers' of blocks as default cache size, which is reasonable for 2D and higher-dimensional arrays (as long as they are not too 'skinny'). In 1D, however, this implies that the cache holds only two blocks, which is likely to cause excessive thrashing. As of version |csizerelease|, the default cache size is roughly proportional to the square root of the total number of array elements, regardless of array dimensionality. While this tends to reduce thrashing, we suggest experimenting with larger cache sizes of at least a few kilobytes to ensure acceptable performance. Note that compressed arrays constructed with the :ref:`default constructor ` will have an initial cache size of only one block. Therefore, users should call :cpp:func:`array::set_cache_size` after :ref:`resizing ` such arrays to ensure a large enough cache. Depending on factors such as rate, cache size, array access pattern, array access primitive (e.g., indices vs. iterators), and arithmetic intensity, we usually observe an application slow-down of 1-10x when switching from uncompressed to compressed arrays. ------------------------------------------------------------------------------- .. _q-ref-count: Q27: *Do compressed arrays use reference counting?* A: It is possible to reference compressed-array elements via proxy :ref:`references ` and :ref:`pointers `, through :ref:`iterators `, and through :ref:`views `. Such indirect references are valid only during the lifetime of the underlying array. No reference counting and garbage collection is used to keep the array alive if there are external references to it. Such references become invalid once the array is destructed, and dereferencing them will likely lead to segmentation faults. ------------------------------------------------------------------------------- .. _q-max-size: Q28: *How large a buffer is needed for compressed storage?* A: :c:func:`zfp_compress` requires that memory has already been allocated to hold the compressed data. But often the compressed size is data dependent and not known a priori. The function :c:func:`zfp_stream_maximum_size` returns a buffer size that is guaranteed to be large enough. This function, which should be called *after* setting the desired compression mode and parameters, computes the largest possible compressed data size based on the current compression settings and array size. Note that by the pigeonhole principle, any (lossless) compressor must expand at least one input, so this buffer size may be larger than the size of the uncompressed input data. :c:func:`zfp_compress` returns the actual number of bytes of compressed storage. When compressing individual blocks using the :ref:`low-level API `, it is useful to know the maximum number of bits that a compressed block can occupy. In addition to the :c:macro:`ZFP_MAX_BITS` macro, the following table lists the maximum block size (in bits) for each scalar type, whether :ref:`reversible mode ` is used, and block dimensionality. +--------+---------+-------+-------+-------+-------+ | type | rev. | 1D | 2D | 3D | 4D | +========+=========+=======+=======+=======+=======+ | | | 131 | 527 | 2111 | 8447 | | int32 +---------+-------+-------+-------+-------+ | | |check| | 136 | 532 | 2116 | 8452 | +--------+---------+-------+-------+-------+-------+ | | | 140 | 536 | 2120 | 8456 | | float +---------+-------+-------+-------+-------+ | | |check| | 146 | 542 | 2126 | 8462 | +--------+---------+-------+-------+-------+-------+ | | | 259 | 1039 | 4159 | 16639 | | int64 +---------+-------+-------+-------+-------+ | | |check| | 265 | 1045 | 4165 | 16645 | +--------+---------+-------+-------+-------+-------+ | | | 271 | 1051 | 4171 | 16651 | | double +---------+-------+-------+-------+-------+ | | |check| | 278 | 1058 | 4178 | 16658 | +--------+---------+-------+-------+-------+-------+ ------------------------------------------------------------------------------- .. _q-printf: Q29: *How can I print array values?* Consider the following seemingly reasonable piece of code:: #include #include "zfp/array1.hpp" int main() { zfp::array1 a(100, 16.0); printf("%f\n", a[0]); // does not compile return 0; } The compiler will complain about :code:`a[0]` being a non-POD object. This is because :code:`a[0]` is a :ref:`proxy reference ` object rather than a :code:`double`. To make this work, :code:`a[0]` must be explicitly converted to :code:`double`, e.g., using a cast:: printf("%f\n", (double)a[0]); For similar reasons, one may not use :code:`scanf` to initialize the value of :code:`a[0]` because :code:`&a[0]` is a :ref:`proxy pointer ` object, not a :code:`double*`. Rather, one must use a temporary variable, e.g. :: double t; scanf("%lf", &t); a[0] = t; Note that using :code:`iostream`, expressions like :: std::cout << a[0] << std::endl; do work, but :: std::cin >> a[0]; does not. ------------------------------------------------------------------------------- .. _q-err-dist: Q30: *What is known about zfp compression errors?* A: Significant effort has been spent on characterizing compression errors resulting from |zfp|, as detailed in the following publications: * P. Lindstrom, "`Error Distributions of Lossy Floating-Point Compressors `__," JSM 2017 Proceedings. * J. Diffenderfer, A. Fox, J. Hittinger, G. Sanders, P. Lindstrom, "`Error Analysis of ZFP Compression for Floating-Point Data `__," SIAM Journal on Scientific Computing, 2019. * D. Hammerling, A. Baker, A. Pinard, P. Lindstrom, "`A Collaborative Effort to Improve Lossy Compression Methods for Climate Data `__," 5th International Workshop on Data Analysis and Reduction for Big Scientific Data, 2019. * A. Fox, J. Diffenderfer, J. Hittinger, G. Sanders, P. Lindstrom. "`Stability Analysis of Inline ZFP Compression for Floating-Point Data in Iterative Methods `__," SIAM Journal on Scientific Computing, 2020. In short, |zfp| compression errors are roughly normally distributed as a consequence of the central limit theorem, and can be bounded. Because the error distribution is normal and because the worst-case error is often much larger than errors observed in practice, it is common that measured errors are far smaller than the absolute error tolerance specified in :ref:`fixed-accuracy mode ` (see :ref:`Q22 `). It is known that |zfp| errors can be slightly biased and correlated (see :numref:`zfp-rounding` and the third paper above). Recent work has been done to combat such issues by supporting optional :ref:`rounding modes `. .. _zfp-rounding: .. figure:: zfp-rounding.pdf :figwidth: 90 % :align: center :alt: "zfp rounding modes" |zfp| errors are normally distributed. This figure illustrates the agreement between theoretical (lines) and observed (dots) error distributions (*X*, *Y*, *Z*, *W*) for 1D blocks. Without proper rounding (left), errors are biased and depend on the relative location within a |zfp| block, resulting in errors not centered on zero. With proper rounding (right), errors are both smaller and unbiased. zfp-1.0.1/docs/source/high-level-api.rst000066400000000000000000001041431453723256400201030ustar00rootroot00000000000000.. include:: defs.rst .. _hl-api: High-Level C API ================ The |libzfp| C API provides functionality for sequentially compressing and decompressing whole integer and floating-point arrays or single blocks. It is broken down into a :ref:`high-level API ` and a :ref:`low-level API `. The high-level API handles compression of entire arrays and supports a variety of back-ends (e.g., serial, OpenMP). The low-level API exists for processing individual, possibly partial blocks as well as reduced-precision integer data less than 32 bits wide. Both C APIs are declared in :file:`zfp.h`. The following sections are available: * :ref:`hl-macros` * :ref:`hl-types` * :ref:`hl-data` * :ref:`hl-functions` * :ref:`hl-func-bitstream` * :ref:`hl-func-stream` * :ref:`hl-func-exec` * :ref:`hl-func-config` * :ref:`hl-func-field` * :ref:`hl-func-codec` .. _hl-macros: Macros ------ .. _version-id: .. c:macro:: ZFP_VERSION_MAJOR .. c:macro:: ZFP_VERSION_MINOR .. c:macro:: ZFP_VERSION_PATCH .. c:macro:: ZFP_VERSION_TWEAK Macros identifying the |zfp| library version (*major*.\ *minor*.\ *patch*.\ *tweak*). :c:macro:`ZFP_VERSION_TWEAK` is new as of |zfp| |verrelease| and is used to mark intermediate develop versions (unofficial releases). ---- .. c:macro:: ZFP_VERSION_DEVELOP Macro signifying that the current version is an intermediate version that differs from the last official release. This macro is undefined for official releases; when defined, its value equals 1. Note that this macro may be defined even if the four :ref:`version identifiers ` have not changed. Available as of |zfp| |verrelease|. ---- .. c:macro:: ZFP_VERSION A single integer constructed from the four :ref:`version identifiers `. This integer can be generated by :c:macro:`ZFP_MAKE_VERSION` or :c:macro:`ZFP_MAKE_FULLVERSION`. Its value equals the global constant :c:data:`zfp_library_version`. .. note:: Although :c:macro:`ZFP_VERSION` increases monotonically with release date and with the four :ref:`version identifiers ` it depends on, the mapping to :c:macro:`ZFP_VERSION` changed with the introduction of :c:macro:`ZFP_VERSION_TWEAK` in |zfp| |verrelease|. Going forward, we recommend using :c:macro:`ZFP_MAKE_VERSION` or :c:macro:`ZFP_MAKE_FULLVERSION` in conditional code that depends on :c:macro:`ZFP_VERSION`, e.g., :code:`#if ZFP_VERSION >= ZFP_MAKE_VERSION(1, 0, 0)`. Note that such constructions should not be used with older versions of |zfp|, e.g., :code:`if (zfp_library_version == ZFP_MAKE_VERSION(0, 5, 5))` will not give the expected result with binary versions of |libzfp| before version |verrelease|. ---- .. c:macro:: ZFP_VERSION_STRING :c:macro:`ZFP_VERSION_STRING` is a string literal composed of the four :ref:`version identifiers `. It is a component of :c:data:`zfp_version_string`. ---- .. c:macro:: ZFP_MAKE_VERSION(major, minor, patch) .. c:macro:: ZFP_MAKE_VERSION_STRING(major, minor, patch) Utility macros for constructing :c:macro:`ZFP_VERSION` and :c:macro:`ZFP_VERSION_STRING`, respectively. Available as of |zfp| |verrelease|, these macros may be used by applications to test for a certain |zfp| version number, e.g., :code:`#if ZFP_VERSION >= ZFP_MAKE_VERSION(1, 0, 0)`. ---- .. c:macro:: ZFP_MAKE_FULLVERSION(major, minor, patch, tweak) .. c:macro:: ZFP_MAKE_FULLVERSION_STRING(major, minor, patch, tweak) Utility macros for constructing :c:macro:`ZFP_VERSION` and :c:macro:`ZFP_VERSION_STRING`, respectively. Includes tweak version used by intermediate develop versions. Available as of |zfp| |verrelease|, these macros may be used by applications to test for a certain |zfp| version number, e.g., :code:`#if ZFP_VERSION >= ZFP_MAKE_FULLVERSION(1, 0, 0, 2)`. ---- .. c:macro:: ZFP_CODEC Macro identifying the version of the compression CODEC. See also :c:data:`zfp_codec_version`. ---- .. c:macro:: ZFP_MIN_BITS .. c:macro:: ZFP_MAX_BITS .. c:macro:: ZFP_MAX_PREC .. c:macro:: ZFP_MIN_EXP Default compression parameter settings that impose no constraints. The largest possible compressed block size, corresponding to 4D blocks of doubles, is given by :c:macro:`ZFP_MAX_BITS`. See also :c:type:`zfp_stream`. ---- .. c:macro:: ZFP_META_NULL Null representation of the 52-bit encoding of field metadata. This value is returned by :c:func:`zfp_field_metadata` when the field metadata cannot be encoded in 64 bits, such as when the array dimensions are too large (see :ref:`limitations`). In addition to signaling error, this value is guaranteed not to represent valid metadata. ---- .. _header-macros: The :code:`ZFP_HEADER` bit mask specifies which portions of a header to output (if any). The constants below should be bitwise ORed together. Use :c:macro:`ZFP_HEADER_FULL` to output all header information available. The compressor and decompressor must agree on which parts of the header to read/write. See :c:func:`zfp_read_header` and :c:func:`zfp_write_header` for how to read and write header information. .. c:macro:: ZFP_HEADER_MAGIC Magic constant that identifies the data as a |zfp| stream compressed using a particular CODEC version. .. c:macro:: ZFP_HEADER_META Array size and scalar type information stored in the :c:type:`zfp_field` struct. .. c:macro:: ZFP_HEADER_MODE Compression mode and parameters stored in the :c:type:`zfp_stream` struct. .. c:macro:: ZFP_HEADER_FULL Full header information (bitwise OR of all :code:`ZFP_HEADER` constants). ---- .. c:macro:: ZFP_MAGIC_BITS .. c:macro:: ZFP_META_BITS .. c:macro:: ZFP_MODE_SHORT_BITS .. c:macro:: ZFP_MODE_LONG_BITS .. c:macro:: ZFP_HEADER_MAX_BITS .. c:macro:: ZFP_MODE_SHORT_MAX Number of bits used by each portion of the header. These macros are primarily informational and should not be accessed by the user through the high-level API. For most common compression parameter settings, only :c:macro:`ZFP_MODE_SHORT_BITS` bits of header information are stored to encode the mode (see :c:func:`zfp_stream_mode`). ---- .. _data-macros: The :code:`ZFP_DATA` bit mask specifies which portions of array data structures to compute total storage size for. These constants should be bitwise ORed together. Use :c:macro:`ZFP_DATA_ALL` to count all storage used. .. c:macro:: ZFP_DATA_UNUSED Allocated but unused data. .. c:macro:: ZFP_DATA_PADDING Padding for alignment purposes. .. c:macro:: ZFP_DATA_META Class members and other fixed-size storage. .. c:macro:: ZFP_DATA_MISC Miscellaneous uncategorized storage. .. c:macro:: ZFP_DATA_PAYLOAD Compressed data encoding array elements. .. c:macro:: ZFP_DATA_INDEX Block :ref:`index ` information. .. c:macro:: ZFP_DATA_CACHE Uncompressed :ref:`cached ` data. .. C:macro:: ZFP_DATA_HEADER :ref:`header` information. .. c:macro:: ZFP_DATA_ALL All storage (bitwise OR of all :code:`ZFP_DATA` constants). ---- .. c:macro:: ZFP_ROUND_FIRST .. c:macro:: ZFP_ROUND_NEVER .. c:macro:: ZFP_ROUND_LAST Available rounding modes for :c:macro:`ZFP_ROUNDING_MODE`, which specifies at build time how |zfp| performs rounding in lossy compression mode. .. _hl-types: Types ----- .. c:type:: zfp_stream The :c:type:`zfp_stream` struct encapsulates all information about the compressed stream for a single block or a collection of blocks that represent an array. See the section on :ref:`compression modes ` for a description of the members of this struct. :: typedef struct { uint minbits; // minimum number of bits to store per block uint maxbits; // maximum number of bits to store per block uint maxprec; // maximum number of bit planes to store int minexp; // minimum floating point bit plane number to store bitstream* stream; // compressed bit stream zfp_execution exec; // execution policy and parameters } zfp_stream; ---- .. c:type:: zfp_execution The :c:type:`zfp_stream` also stores information about how to execute compression, e.g., sequentially or in parallel. The execution is determined by the policy and any policy-specific parameters such as number of threads. :: typedef struct { zfp_exec_policy policy; // execution policy (serial, omp, cuda, ...) void* params; // execution parameters } zfp_execution; .. warning:: As of |zfp| |verrelease| :c:type:`zfp_execution` replaces the former :code:`zfp_exec_params` with a :code:`void*` to the associated :code:`zfp_exec_params` type (e.g., :c:type:`zfp_exec_params_omp`) to limit ABI-breaking changes due to future extensions to |zfp| execution policies. ---- .. c:type:: zfp_exec_policy Currently three execution policies are available: serial, OpenMP parallel, and CUDA parallel. :: typedef enum { zfp_exec_serial = 0, // serial execution (default) zfp_exec_omp = 1, // OpenMP multi-threaded execution zfp_exec_cuda = 2 // CUDA parallel execution } zfp_exec_policy; ---- .. c:type:: zfp_exec_params_omp Execution parameters for OpenMP parallel compression. These are initialized to default values. When nonzero, they indicate the number of threads to request for parallel compression and the number of consecutive blocks to assign to each thread. :: typedef struct { uint threads; // number of requested threads uint chunk_size; // number of blocks per chunk } zfp_exec_params_omp; ---- .. _mode_struct: .. c:type:: zfp_mode Enumerates the compression modes. :: typedef enum { zfp_mode_null = 0, // an invalid configuration of the 4 params zfp_mode_expert = 1, // expert mode (4 params set manually) zfp_mode_fixed_rate = 2, // fixed rate mode zfp_mode_fixed_precision = 3, // fixed precision mode zfp_mode_fixed_accuracy = 4, // fixed accuracy mode zfp_mode_reversible = 5 // reversible (lossless) mode } zfp_mode; ---- .. _config_struct: .. c:type:: zfp_config Encapsulates compression mode and parameters (if any). :: typedef struct { zfp_mode mode; // compression mode */ union { double rate; // compressed bits/value (negative for word alignment) uint precision; // uncompressed bits/value double tolerance; // absolute error tolerance struct { uint minbits; // min number of compressed bits/block uint maxbits; // max number of compressed bits/block uint maxprec; // max number of uncompressed bits/value int minexp; // min floating point bit plane number to store } expert; // expert mode arguments } arg; // arguments corresponding to compression mode } zfp_config; ---- .. c:type:: zfp_type Enumerates the scalar types supported by the compressor and describes the uncompressed array. The compressor and decompressor must use the same :c:type:`zfp_type`, e.g., one cannot compress doubles and decompress to floats or integers. :: typedef enum { zfp_type_none = 0, // unspecified type zfp_type_int32 = 1, // 32-bit signed integer zfp_type_int64 = 2, // 64-bit signed integer zfp_type_float = 3, // single precision floating point zfp_type_double = 4 // double precision floating point } zfp_type; ---- .. _field: .. index:: single: Strided Arrays .. c:type:: zfp_field The uncompressed array is described by the :c:type:`zfp_field` struct, which encodes the array's scalar type, dimensions, and memory layout. :: typedef struct { zfp_type type; // scalar type (e.g., int32, double) size_t nx, ny, nz, nw; // sizes (zero for unused dimensions) ptrdiff_t sx, sy, sz, sw; // strides (zero for contiguous array a[nw][nz][ny][nx]) void* data; // pointer to array data } zfp_field; For example, a static multidimensional C array declared as :: double array[n1][n2][n3][n4]; would be described by a :c:type:`zfp_field` with members :: type = zfp_type_double; nx = n4; ny = n3; nz = n2; nw = n1; sx = 1; sy = n4; sz = n3 * n4; sw = n2 * n3 * n4; data = &array[0][0][0][0]; The strides, when nonzero, specify how the array is laid out in memory. Strides can be used in case multiple fields are stored interleaved via "array of struct" (AoS) rather than "struct of array" (SoA) storage, or if the dimensions should be transposed during (de)compression. Strides may even be negative, allowing one or more dimensions to be traversed in reverse order. Given 4D array indices (*x*, *y*, *z*, *w*), the corresponding array element is stored at :: data[x * sx + y * sy + z * sz + w * sw] where :code:`data` is a pointer to the first array element. .. _new-field: .. warning:: The :c:type:`zfp_field` struct was modified in |zfp| |64bitrelease| to use :code:`size_t` and :code:`ptrdiff_t` for array dimensions and strides, respectively, to support 64-bit addressing of very large arrays (previously, :code:`uint` and :code:`int` were used). This ABI incompatible change may require rebuilding applications that use |zfp| and may in some cases also require code changes to handle pointers to :code:`size_t` instead of pointers to :code:`uint` (see :c:func:`zfp_field_size`, for instance). .. _indexing: .. index:: single: C order single: Fortran order .. warning:: It is paramount that the field dimensions, *nx*, *ny*, *nz*, and *nw*, and strides, *sx*, *sy*, *sz*, and *sw*, be correctly mapped to how the uncompressed array is laid out in memory. Although compression will still succeed if array dimensions are accidentally transposed, compression ratio and/or accuracy may suffer greatly. Since the leftmost index, *x*, is assumed to vary fastest, |zfp| can be thought of as assuming Fortran ordering. For C ordered arrays, the user should transpose the dimensions or specify strides to properly describe the memory layout. See :ref:`this FAQ ` for further details. .. c:type:: zfp_bool :c:type:`zfp_bool` is new as of |zfp| |boolrelease|. Although merely an alias for :code:`int`, this type serves to document that a return value or function parameter should be treated as Boolean. Two enumerated constants are available:: enum { zfp_false = 0, zfp_true = !zfp_false }; The reason why :c:type:`zfp_bool` is not an enumerated type itself is that in C++ this would require an explicit cast between the :code:`bool` type resulting from logical expressions, e.g., :code:`zfp_bool done = static_cast(queue.empty() && work == 0)`. Such casts from :code:`bool` to a non-enumerated :code:`int` are not necessary. The |zfp| |boolrelease| API has changed to use :c:type:`zfp_bool` in place of :code:`int` where appropriate; this change should not affect existing code. .. _hl-data: Constants --------- .. c:var:: const uint zfp_codec_version The version of the compression CODEC implemented by this version of the |zfp| library. The library can decompress files generated by the same CODEC only. To ensure that the :file:`zfp.h` header matches the binary library linked to, :c:data:`zfp_codec_version` should match :c:macro:`ZFP_CODEC`. ---- .. c:var:: const uint zfp_library_version The library version. The binary library and headers are compatible if :c:data:`zfp_library_version` matches :c:macro:`ZFP_VERSION`. ---- .. c:var:: const char* const zfp_version_string A constant string representing the |zfp| library version and release date. One can search for this string in executables and libraries that link to |libzfp| when built as a static library. .. _hl-functions: Functions --------- .. c:function:: size_t zfp_type_size(zfp_type type) Return byte size of the given scalar type, e.g., :code:`zfp_type_size(zfp_type_float) = 4`. .. _hl-func-bitstream: Compressed Stream ^^^^^^^^^^^^^^^^^ .. c:function:: zfp_stream* zfp_stream_open(bitstream* stream) Allocate compressed stream and associate it with bit stream for reading and writing bits to/from memory. *stream* may be :c:macro:`NULL` and attached later via :c:func:`zfp_stream_set_bit_stream`. ---- .. c:function:: void zfp_stream_close(zfp_stream* stream) Close and deallocate compressed stream. This does not affect the attached bit stream. ---- .. c:function:: void zfp_stream_rewind(zfp_stream* stream) Rewind bit stream to beginning for compression or decompression. ---- .. c:function:: bitstream* zfp_stream_bit_stream(const zfp_stream* stream) Return bit stream associated with compressed stream (see :c:func:`zfp_stream_set_bit_stream`). ---- .. c:function:: void zfp_stream_set_bit_stream(zfp_stream* stream, bitstream* bs) Associate bit stream with compressed stream. ---- .. c:function:: size_t zfp_stream_compressed_size(const zfp_stream* stream) Number of bytes of compressed storage. This function returns the current byte offset within the bit stream from the beginning of the bit stream memory buffer. To ensure all buffered compressed data has been output call :c:func:`zfp_stream_flush` first. ---- .. c:function:: size_t zfp_stream_maximum_size(const zfp_stream* stream, const zfp_field* field) Conservative estimate of the compressed byte size for the compression parameters stored in *stream* and the array whose scalar type and dimensions are given by *field*. This function may be used to determine how large a memory buffer to allocate to safely hold the entire compressed array. The buffer may then be resized (using :code:`realloc()`) after the actual number of bytes is known, as returned by :c:func:`zfp_compress`. .. _hl-func-stream: Compression Parameters ^^^^^^^^^^^^^^^^^^^^^^ .. c:function:: zfp_mode zfp_stream_compression_mode(const zfp_stream* stream) Return compression mode associated with compression parameters. Return :code:`zfp_mode_null` when compression parameters are invalid. ---- .. c:function:: void zfp_stream_set_reversible(zfp_stream* stream) Enable :ref:`reversible ` (lossless) compression. ---- .. c:function:: double zfp_stream_rate(const zfp_stream* stream, uint dims) Return rate in compressed bits per value if *stream* is in :ref:`fixed-rate mode ` (see :c:func:`zfp_stream_set_rate`), else zero. *dims* is the dimensionality of the compressed data. ---- .. c:function:: double zfp_stream_set_rate(zfp_stream* stream, double rate, zfp_type type, uint dims, zfp_bool align) Set *rate* for :ref:`fixed-rate mode ` in compressed bits per value. The target scalar *type* and array *dimensionality* are needed to correctly translate the rate to the number of bits per block. The Boolean *align* should be :code:`zfp_true` if :ref:`word alignment ` is needed, e.g., to support random access writes of blocks for |zfp|'s :ref:`compressed arrays `. Such alignment may further constrain the rate. The closest supported rate is returned, which may differ from the requested rate. ---- .. c:function:: uint zfp_stream_precision(const zfp_stream* stream) Return precision in uncompressed bits per value if *stream* is in :ref:`fixed-precision mode ` (see :c:func:`zfp_stream_set_precision`), else zero. ---- .. c:function:: uint zfp_stream_set_precision(zfp_stream* stream, uint precision) Set *precision* for :ref:`fixed-precision mode `. The precision specifies how many uncompressed bits per value to store, and indirectly governs the relative error. The actual precision is returned, e.g., in case the desired precision is out of range. To preserve a certain floating-point mantissa or integer precision in the decompressed data, see FAQ :ref:`#21 `. ---- .. c:function:: double zfp_stream_accuracy(const zfp_stream* stream) Return accuracy as an absolute error tolerance if *stream* is in :ref:`fixed-accuracy mode ` (see :c:func:`zfp_stream_set_accuracy`), else zero. ---- .. c:function:: double zfp_stream_set_accuracy(zfp_stream* stream, double tolerance) Set absolute error *tolerance* for :ref:`fixed-accuracy mode `. The tolerance ensures that values in the decompressed array differ from the input array by no more than this tolerance (in all but exceptional circumstances; see FAQ :ref:`#17 `). This compression mode should be used only with floating-point (not integer) data. ---- .. c:function:: uint64 zfp_stream_mode(const zfp_stream* stream) Return compact encoding of compression parameters. If the return value is no larger than :c:macro:`ZFP_MODE_SHORT_MAX`, then the least significant :c:macro:`ZFP_MODE_SHORT_BITS` (12 in the current version) suffice to encode the parameters. Otherwise all 64 bits are needed, and the low :c:macro:`ZFP_MODE_SHORT_BITS` bits will be all ones. Thus, this variable-length encoding can be used to economically encode and decode the compression parameters, which is especially important if the parameters are to vary spatially over small regions. Such spatially adaptive coding would have to be implemented via the :ref:`low-level API `. ---- .. c:function:: zfp_mode zfp_stream_set_mode(zfp_stream* stream, uint64 mode) Set all compression parameters from compact integer representation. See :c:func:`zfp_stream_mode` for how to encode the parameters. Return the mode associated with the newly-set compression parameters. If the decoded compression parameters are invalid, they are not set and the function returns :code:`zfp_mode_null`. ---- .. c:function:: void zfp_stream_params(const zfp_stream* stream, uint* minbits, uint* maxbits, uint* maxprec, int* minexp) Query :ref:`compression parameters `. For any parameter not needed, pass :c:macro:`NULL` for the corresponding pointer. ---- .. c:function:: zfp_bool zfp_stream_set_params(zfp_stream* stream, uint minbits, uint maxbits, uint maxprec, int minexp) Set all compression parameters directly. See the section on :ref:`expert mode ` for a discussion of the parameters. The return value is :code:`zfp_true` upon success. .. _hl-func-exec: Execution Policy ^^^^^^^^^^^^^^^^ .. c:function:: zfp_exec_policy zfp_stream_execution(const zfp_stream* stream) Return current :ref:`execution policy `. ---- .. c:function:: uint zfp_stream_omp_threads(const zfp_stream* stream) Return number of OpenMP threads to request for compression. See :c:func:`zfp_stream_set_omp_threads`. ---- .. c:function:: uint zfp_stream_omp_chunk_size(const zfp_stream* stream) Return number of blocks to compress together per OpenMP thread. See :c:func:`zfp_stream_set_omp_chunk_size`. ---- .. c:function:: zfp_bool zfp_stream_set_execution(zfp_stream* stream, zfp_exec_policy policy) Set :ref:`execution policy `. If different from the previous policy, initialize the execution parameters to their default values. :code:`zfp_true` is returned if the execution policy is supported. ---- .. c:function:: zfp_bool zfp_stream_set_omp_threads(zfp_stream* stream, uint threads) Set the number of OpenMP threads to use during compression. If *threads* is zero, then the number of threads is given by the value of the OpenMP *nthreads-var* internal control variable when :c:func:`zfp_compress` is called (usually the maximum number available). This function also sets the execution policy to OpenMP. Upon success, :code:`zfp_true` is returned. ---- .. c:function:: zfp_bool zfp_stream_set_omp_chunk_size(zfp_stream* stream, uint chunk_size) Set the number of consecutive blocks to compress together per OpenMP thread. If zero, use one chunk per thread. This function also sets the execution policy to OpenMP. Upon success, :code:`zfp_true` is returned. .. _hl-func-config: Compression Configuration ^^^^^^^^^^^^^^^^^^^^^^^^^ These functions encode a desired compression mode and associated parameters (if any) in a single struct, e.g., for configuring |zfp|'s :ref:`read-only array classes `. .. c:function:: zfp_config zfp_config_none() Unspecified configuration. ---- .. c:function:: zfp_config zfp_config_rate(double rate, zfp_bool align) :ref:`Fixed-rate mode ` using *rate* compressed bits per value. When *align* is true, word alignment is enforced to further constrain the rate (see :c:func:`zfp_stream_set_rate`). ---- .. c:function:: zfp_config zfp_config_precision(uint precision) :ref:`Fixed-precision mode ` using *precision* uncompressed bits per value (see also :c:func:`zfp_stream_set_precision`). ---- .. c:function:: zfp_config zfp_config_accuracy(double tolerance) :ref:`Fixed-accuracy mode ` with absolute error no larger than *tolerance* (see also :c:func:`zfp_stream_set_accuracy`). ---- .. c:function:: zfp_config zfp_config_reversible() :ref:`Reversible (lossless) mode ` (see also :c:func:`zfp_stream_set_reversible`). ---- .. c:function:: zfp_config zfp_config_expert(uint minbits, uint maxbits, uint maxprec, int minexp) :ref:`Expert mode ` with given parameters (see also :c:func:`zfp_stream_set_params`). .. _hl-func-field: Array Metadata ^^^^^^^^^^^^^^ .. c:function:: zfp_field* zfp_field_alloc() Allocates and returns a default initialized :c:type:`zfp_field` struct. The caller must free this struct using :c:func:`zfp_field_free`. ---- .. c:function:: zfp_field* zfp_field_1d(void* pointer, zfp_type type, size_t nx) Allocate and return a field struct that describes an existing 1D array, :code:`a[nx]`, of *nx* uncompressed scalars of given *type* stored at *pointer*, which may be :c:macro:`NULL` and specified later. ---- .. c:function:: zfp_field* zfp_field_2d(void* pointer, zfp_type type, size_t nx, size_t ny) Allocate and return a field struct that describes an existing 2D array, :code:`a[ny][nx]`, of *nx* |times| *ny* uncompressed scalars of given *type* stored at *pointer*, which may be :c:macro:`NULL` and specified later. ---- .. c:function:: zfp_field* zfp_field_3d(void* pointer, zfp_type type, size_t nx, size_t ny, size_t nz) Allocate and return a field struct that describes an existing 3D array, :code:`a[nz][ny][nx]`, of *nx* |times| *ny* |times| *nz* uncompressed scalars of given *type* stored at *pointer*, which may be :c:macro:`NULL` and specified later. ---- .. c:function:: zfp_field* zfp_field_4d(void* pointer, zfp_type type, size_t nx, size_t ny, size_t nz, size_t nw) Allocate and return a field struct that describes an existing 4D array, :code:`a[nw][nz][ny][nx]`, of *nx* |times| *ny* |times| *nz* |times| *nw* uncompressed scalars of given *type* stored at *pointer*, which may be :c:macro:`NULL` and specified later. ---- .. c:function:: void zfp_field_free(zfp_field* field) Free :c:type:`zfp_field` struct previously allocated by one of the functions above. ---- .. c:function:: void* zfp_field_pointer(const zfp_field* field) Return pointer to the first scalar in the field with index *x* = *y* = *z* = *w* = 0. ---- .. c:function:: void* zfp_field_begin(const zfp_field* field) Return pointer to the lowest memory address occupied by the field. Equals :c:func:`zfp_field_pointer` if all strides are positive. Available since |zfp| |fieldrelease|. ---- .. c:function:: zfp_type zfp_field_type(const zfp_field* field) Return array scalar type. ---- .. c:function:: uint zfp_field_precision(const zfp_field* field) Return scalar precision in number of bits, e.g., 32 for :code:`zfp_type_float`. ---- .. c:function:: uint zfp_field_dimensionality(const zfp_field* field) Return array dimensionality (1, 2, 3, or 4). ---- .. c:function:: size_t zfp_field_size(const zfp_field* field, size_t* size) Return total number of scalars stored in the array, e.g., *nx* |times| *ny* |times| *nz* for a 3D array. If *size* is not :c:macro:`NULL`, then store the number of scalars for each dimension, e.g., :code:`size[0] = nx; size[1] = ny; size[2] = nz` for a 3D array. ---- .. c:function:: size_t zfp_field_size_bytes(const zfp_field* field) Return number of bytes spanned by the field payload data. This includes gaps in memory in case the field layout, as given by the strides, is not contiguous (see :c:func:`zfp_field_is_contiguous`). Available since |zfp| |fieldrelease|. ---- .. c:function:: size_t zfp_field_blocks(const zfp_field* field) Return total number of *d*-dimensional blocks (whether partial or whole) spanning the array. Each whole block consists of |4powd| scalars. Available since |zfp| |fieldrelease|. ---- .. c:function:: zfp_bool zfp_field_stride(const zfp_field* field, ptrdiff_t* stride) Return :code:`zfp_false` if the array is stored contiguously as :code:`a[nx]`, :code:`a[ny][nx]`, :code:`a[nz][ny][nx]`, or :code:`a[nw][nz][ny][nx]` depending on dimensionality. Return :code:`zfp_true` if the array is strided and laid out differently in memory. If *stride* is not :c:macro:`NULL`, then store the stride for each dimension, e.g., :code:`stride[0] = sx; stride[1] = sy; stride[2] = sz;` for a 3D array. See :c:type:`zfp_field` for more information on strides. Return false if the array is stored contiguously (the default) as :code:`a[nx]`, :code:`a[ny][nx]`, :code:`a[nz][ny][nx]`, or :code:`a[nw][nz][ny][nx]` depending on dimensionality. Return true if nonzero strides have been specified. ---- .. c:function:: zfp_bool zfp_field_is_contiguous(const zfp_field* field) Return true if the field occupies a contiguous portion of memory. Note that the field layout may be contiguous even if a raster order traversal does not visit memory in a monotonically increasing or decreasing order, e.g., if the layout is simply a permutation of the default layout. Available since |zfp| |fieldrelease|. ---- .. c:function:: uint64 zfp_field_metadata(const zfp_field* field) Return 52-bit compact encoding of the scalar type and array dimensions. This function returns :c:macro:`ZFP_META_NULL` on failure, e.g., if the array dimensions are :ref:`too large ` to be encoded in 52 bits. ---- .. _zfp_field_set: .. c:function:: void zfp_field_set_pointer(zfp_field* field, void* pointer) Set pointer to first scalar in the array. ---- .. c:function:: zfp_type zfp_field_set_type(zfp_field* field, zfp_type type) Set array scalar type. ---- .. c:function:: void zfp_field_set_size_1d(zfp_field* field, size_t nx) Specify dimensions of 1D array :code:`a[nx]`. ---- .. c:function:: void zfp_field_set_size_2d(zfp_field* field, size_t nx, size_t ny) Specify dimensions of 2D array :code:`a[ny][nx]`. ---- .. c:function:: void zfp_field_set_size_3d(zfp_field* field, size_t nx, size_t ny, size_t nz) Specify dimensions of 3D array :code:`a[nz][ny][nx]`. ---- .. c:function:: void zfp_field_set_size_4d(zfp_field* field, size_t nx, size_t ny, size_t nz, size_t nw) Specify dimensions of 4D array :code:`a[nw][nz][ny][nx]`. ---- .. c:function:: void zfp_field_set_stride_1d(zfp_field* field, ptrdiff_t sx) Specify stride for 1D array: :code:`sx = &a[1] - &a[0]`. ---- .. c:function:: void zfp_field_set_stride_2d(zfp_field* field, ptrdiff_t sx, ptrdiff_t sy) Specify strides for 2D array: :code:`sx = &a[0][1] - &a[0][0]; sy = &a[1][0] - &a[0][0]`. ---- .. c:function:: void zfp_field_set_stride_3d(zfp_field* field, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) Specify strides for 3D array: :code:`sx = &a[0][0][1] - &a[0][0][0]; sy = &a[0][1][0] - &a[0][0][0]; sz = &a[1][0][0] - &a[0][0][0]`. ---- .. c:function:: void zfp_field_set_stride_4d(zfp_field* field, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) Specify strides for 4D array: :code:`sx = &a[0][0][0][1] - &a[0][0][0][0]; sy = &a[0][0][1][0] - &a[0][0][0][0]; sz = &a[0][1][0][0] - &a[0][0][0][0]; sw = &a[1][0][0][0] - &a[0][0][0][0]`. ---- .. c:function:: zfp_bool zfp_field_set_metadata(zfp_field* field, uint64 meta) Specify array scalar type and dimensions from compact 52-bit representation. Return :code:`zfp_true` upon success. See :c:func:`zfp_field_metadata` for how to encode *meta*. .. _hl-func-codec: Compression and Decompression ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. c:function:: size_t zfp_compress(zfp_stream* stream, const zfp_field* field) Compress the whole array described by *field* using parameters given by *stream*. Then flush the stream to emit any buffered bits and align the stream on a word boundary. The resulting byte offset within the bit stream is returned, which equals the total number of bytes of compressed storage if the stream was rewound before the :c:func:`zfp_compress` call. Zero is returned if compression failed. ---- .. c:function:: size_t zfp_decompress(zfp_stream* stream, zfp_field* field) Decompress from *stream* to array described by *field* and align the stream on the next word boundary. Upon success, the nonzero return value is the same as would be returned by a corresponding :c:func:`zfp_compress` call, i.e., the current byte offset or the number of compressed bytes consumed. Zero is returned if decompression failed. ---- .. _zfp-header: .. c:function:: size_t zfp_write_header(zfp_stream* stream, const zfp_field* field, uint mask) Write an optional variable-length header to the stream that encodes compression parameters, array metadata, etc. The header information written is determined by the bit *mask* (see :c:macro:`macros `). Unlike in :c:func:`zfp_compress`, no word alignment is enforced. See the :ref:`limitations ` section for limits on the maximum array size supported by the header. The return value is the number of bits written, or zero upon failure. ---- .. c:function:: size_t zfp_read_header(zfp_stream* stream, zfp_field* field, uint mask) Read header if one was previously written using :c:func:`zfp_write_header`. The *stream* and *field* data structures are populated with the information stored in the header, as specified by the bit *mask* (see :c:macro:`macros `). The caller must ensure that *mask* agrees between header read and write calls. The return value is the number of bits read, or zero upon failure. zfp-1.0.1/docs/source/index.inc000066400000000000000000000134041453723256400163570ustar00rootroot00000000000000.. index:: single: Index .. _index: Index ----- .. cpp:namespace:: zfp To support random access, |zfp| arrays must know where each block is stored in memory. For fixed-rate arrays, the number of compressed bits per block is constant, and the bit offset to each block can be quickly computed. For variable-rate arrays, the compressed block size is data dependent, and additional information must be stored to index the blocks. Toward this end, |zfp| arrays make use of an index class that reports the offset and size (in number of bits) of each block. The :cpp:class:`zfp::array` and :cpp:class:`zfp::const_array` classes take such an index class as a template parameter. This index class is new as of |zfp| |carrrelease|, which introduced variable-rate arrays. Because |zfp| is designed primarily for very large arrays, the bit offset may exceed 32 bits. A straightforward implementation stores the bit offset to each block as a 64-bit integer, with the block size given by the difference of consecutive offsets. However, this overhead of 64 bits/block may exceed the payload compressed data for low-dimensional arrays or in applications like visualization that may store less than one bit per value (amortized). It is therefore important to consider more compact representations of the block index. |zfp| provides multiple index classes in the :code:`zfp::index` namespace that balance storage size, range of representable block offsets and sizes, and speed of access: .. cpp:namespace:: zfp::index * :cpp:class:`implicit`: Used for fixed-rate storage where only the fixed number of bits per block is kept. This is the default index for fixed-rate arrays. * :cpp:class:`verbatim`: This and subsequent classes support variable-rate storage. A full 64-bit offset is stored per block. * :cpp:class:`hybrid4`: Four consecutive offsets are encoded together. The top 32 bits of a 44-bit base offset are stored, with the 12 least significant bits of this base set to zero. Four unsigned 16-bit deltas from the base offset complete the representation. The default for variable-rate arrays, this index offers a good tradeoff between storage, offset range, and speed. * :cpp:class:`hybrid8`: Eight consecutive offsets are encoded together as two 64-bit words that store the offset to the first block (the base offset) and the sizes of the first seven blocks, from which the eight offsets are derived as a prefix sum. One 64-bit word holds the 8 least significant bits of the base offset and block sizes. The other word holds another 2 (*d* - 1) bits for the seven block sizes plus the top 78 - 14 *d* bits of the base offset, where 1 |leq| *d* |leq| 4 is the data dimensionality. Properties of these index classes are summarized in :numref:`index-classes`. .. _index-classes: .. table:: Properties of index classes. Storage is measured in amortized bits/block; offset and size denote supported ranges in number of bits. +-------------+----------+---------+-------------+-----------+--------+ | index class | variable | storage | offset | size | speed | | | rate | | | | | +=============+==========+=========+=============+===========+========+ | implicit | | 0 | 64 | 64 | high | +-------------+----------+---------+-------------+-----------+--------+ | verbatim | |check| | 64 | 64 | 64 | high | +-------------+----------+---------+-------------+-----------+--------+ | hybrid4 | |check| | 24 | 44 | 16 | medium | +-------------+----------+---------+-------------+-----------+--------+ | hybrid8 | |check| | 16 | 86 - 14 *d* | 6 + 2 *d* | low | +-------------+----------+---------+-------------+-----------+--------+ This section documents the API that prospective block indices must support to interface with the |zfp| compressed-array classes. .. cpp:class:: index Fictitious class encapsulating the index API. ---- .. cpp:function:: index::index(size_t blocks) Construct index supporting the given number of *blocks*. ---- .. cpp:function:: size_t index::size_bytes(uint mask = ZFP_DATA_ALL) const ---- .. cpp:function:: bitstream_size index::range() const Range of bit offsets spanned by index. This equals the total number of bits of compressed-array data. ---- .. cpp:function:: size_t index::block_size(size_t block_index) const Size of compressed block in number of bits. ---- .. cpp:function:: bitstream_offset index::block_offset(size_t block_index) const Bit offset to compressed block data. ---- .. cpp:function:: void resize(size_t blocks) Resize index to accommodate requested number of blocks. Any stored index data is destroyed. ---- .. cpp:function:: void clear() Clear all data stored by index. ---- .. cpp:function:: void flush() Flush any buffered index data. This method is called after all blocks have been compressed, e.g., in :cpp:func:`array::set`. ---- .. cpp:function:: void set_block_size(size_t size) Set a fixed compressed block size in number of bits for all blocks. This method is called when fixed-rate mode is selected. ---- .. cpp:function:: void set_block_size(size_t block_index, size_t size) Set compressed block size in number of bits for a single block. For variable-rate arrays, the zero-based *block_index* is guaranteed to increase sequentially between calls. This method throws an exception if the index cannot support the block size or offset. The user may wish to restrict the block size, e.g., by setting :code:`maxbits` in :ref:`expert mode `, to guard against such overflow. ---- .. cpp:function:: static bool has_variable_rate() Return true if index supports variable-sized blocks. zfp-1.0.1/docs/source/index.rst000066400000000000000000000006421453723256400164160ustar00rootroot00000000000000.. include:: defs.rst |zfp| |release| documentation ============================= .. toctree:: :maxdepth: 2 :caption: Contents introduction license installation algorithm modes execution high-level-api low-level-api bit-stream python zforp arrays cfp tutorial zfpcmd examples testing faq issues limitations directions contributors versions zfp-1.0.1/docs/source/installation.rst000066400000000000000000000316471453723256400200210ustar00rootroot00000000000000.. include:: defs.rst .. _installation: Installation ============ |zfp| consists of four distinct parts: a compression library written in C, a set of C++ header files that implement compressed arrays and corresponding C wrappers, optional Python and Fortran bindings, and a set of C and C++ examples and utilities. The main compression codec is written in C and should conform to both the ISO C89 and C99 standards. The C++ array classes are implemented entirely in header files and can be included as is, but since they call the compression library, applications must link with |libzfp|. |zfp| is preferably built using `CMake `__, although the core library can also be built using GNU make on Linux, macOS, and MinGW. |zfp| conforms to various language standards, including C89, C99, C++98, C++11, and C++14. .. note:: |zfp| requires compiler support for 64-bit integers. .. _cmake_builds: CMake Builds ------------ To build |zfp| using `CMake `__ on Linux or macOS, start a Unix shell and type:: cd zfp-1.0.1 mkdir build cd build cmake .. make To also build the examples, replace the cmake line with:: cmake -DBUILD_EXAMPLES=ON .. By default, CMake builds will attempt to locate and use `OpenMP `__. To disable OpenMP, type:: cmake -DZFP_WITH_OPENMP=OFF .. To build |zfp| using Visual Studio on Windows, start a DOS shell and type:: cd zfp-1.0.1 mkdir build cd build cmake .. cmake --build . --config Release This builds |zfp| in release mode. Replace 'Release' with 'Debug' to build |zfp| in debug mode. See the instructions for Linux on how to change the cmake line to also build the example programs. .. _gnu_builds: GNU Builds ---------- To build |zfp| using `gcc `__ without `OpenMP `__, type:: cd zfp-1.0.1 gmake This builds |libzfp| as a static library as well as the |zfp| command-line utility. To enable OpenMP parallel compression, type:: gmake ZFP_WITH_OPENMP=1 .. note:: GNU builds expose only limited functionality of |zfp|. For instance, CUDA and Python support are not included. For full functionality, build |zfp| using CMake. Testing ------- To test that |zfp| is working properly, type:: ctest or using GNU make:: gmake test If the GNU build or regression tests fail, it is possible that some of the macros in the file :file:`Config` have to be adjusted. Also, the tests may fail due to minute differences in the computed floating-point fields being compressed, which will be indicated by checksum errors. If most tests succeed and the failures result in byte sizes and error values reasonably close to the expected values, then it is likely that the compressor is working correctly. .. index:: single: Build Targets .. _targets: Build Targets ------------- To specify which components to build, set the macros below to :code:`ON` (CMake) or :code:`1` (GNU make), e.g., :: cmake -DBUILD_UTILITIES=OFF -DBUILD_EXAMPLES=ON .. or using GNU make :: gmake BUILD_UTILITIES=0 BUILD_EXAMPLES=1 Regardless of the settings below, |libzfp| will always be built. .. c:macro:: BUILD_ALL Build all subdirectories; enable all options (except :c:macro:`BUILD_SHARED_LIBS`). Default: off. .. c:macro:: BUILD_CFP Build |libcfp| for C bindings to the compressed-array classes. Default: off. .. c:macro:: BUILD_ZFPY Build |zfpy| for Python bindings to the C API. CMake will attempt to automatically detect the Python installation to use. If CMake finds multiple Python installations, it will use the newest one. To specify a specific Python installation to use, set :c:macro:`PYTHON_LIBRARY` and :c:macro:`PYTHON_INCLUDE_DIR` on the cmake line:: cmake -DBUILD_ZFPY=ON -DPYTHON_LIBRARY=/path/to/lib/libpython2.7.so -DPYTHON_INCLUDE_DIR=/path/to/include/python2.7 .. CMake default: off. GNU make default: off and ignored. .. c:macro:: BUILD_ZFORP Build |libzforp| for Fortran bindings to the C API. Requires Fortran standard 2018 or later. GNU make users may specify the Fortran compiler to use via :: gmake BUILD_ZFORP=1 FC=/path/to/fortran-compiler Default: off. .. c:macro:: BUILD_UTILITIES Build |zfpcmd| command-line utility for compressing binary files. Default: on. .. c:macro:: BUILD_EXAMPLES Build code examples. Default: off. .. c:macro:: BUILD_TESTING Build |testzfp| tests. Default: on. .. c:macro:: BUILD_TESTING_FULL Build all unit tests. Default: off. .. c:macro:: BUILD_SHARED_LIBS Build shared objects (:file:`.so`, :file:`.dylib`, or :file:`.dll` files). CMake default: on. GNU make default: off. .. note:: On macOS, add :code:`OS=mac` when building shared libraries with GNU make. .. index:: single: Configuration .. _config: Configuration ------------- The behavior of |zfp| can be configured at compile time via a set of macros in the same manner that :ref:`build targets ` are specified, e.g., :: cmake -DZFP_WITH_OPENMP=OFF .. .. c:macro:: ZFP_INT64 .. c:macro:: ZFP_INT64_SUFFIX .. c:macro:: ZFP_UINT64 .. c:macro:: ZFP_UINT64_SUFFIX 64-bit signed and unsigned integer types and their literal suffixes. Platforms on which :code:`long int` is 32 bits wide may require :code:`long long int` as type and :code:`ll` as suffix. These macros are relevant **only** when compiling in C89 mode. When compiling in C99 mode, integer types are taken from :file:`stdint.h`. Defaults: :code:`long int`, :code:`l`, :code:`unsigned long int`, and :code:`ul`, respectively. .. c:macro:: ZFP_WITH_OPENMP CMake and GNU make macro for enabling or disabling OpenMP support. CMake builds will by default enable OpenMP when available. Set this macro to 0 or OFF to disable OpenMP support. For GNU builds, OpenMP is disabled by default. Set this macro to 1 or ON to enable OpenMP support. See also OMPFLAGS in :file:`Config` in case the compiler does not recognize ``-fopenmp``. For example, Apple clang requires ``OMPFLAGS=-Xclang -fopenmp``, ``LDFLAGS=-lomp``, and an installation of ``libomp``. CMake default: on. GNU make default: off. .. c:macro:: ZFP_WITH_CUDA CMake macro for enabling or disabling CUDA support for GPU compression and decompression. When enabled, CUDA and a compatible host compiler must be installed. For a full list of compatible compilers, please consult the `NVIDIA documentation `__. If a CUDA installation is in the user's path, it will be automatically found by CMake. Alternatively, the CUDA binary directory can be specified using the :envvar:`CUDA_BIN_DIR` environment variable. CMake default: off. GNU make default: off and ignored. .. _rounding: .. c:macro:: ZFP_ROUNDING_MODE **Experimental feature**. By default, |zfp| coefficients are truncated, not rounded, which can result in biased errors (see FAQ :ref:`#30 `). To counter this, two rounding modes are available: :code:`ZFP_ROUND_FIRST` (round during compression; analogous to mid-tread quantization) and :code:`ZFP_ROUND_LAST` (round during decompression; analogous to mid-riser quantization). With :code:`ZFP_ROUND_LAST`, the values returned on decompression are slightly modified (and usually closer to the original values) without impacting the compressed data itself. This rounding mode works with all :ref:`compression modes `. With :code:`ZFP_ROUND_FIRST`, the values are modified before compression, thus impacting the compressed stream. This rounding mode tends to be more effective at reducing bias, but is invoked only with :ref:`fixed-precision ` and :ref:`fixed-accuracy ` compression modes. Both of these rounding modes break the regression tests since they alter the compressed or decompressed representation, but they may be used with libraries built with the default rounding mode, :code:`ZFP_ROUND_NEVER`, and versions of |zfp| that do not support a rounding mode with no adverse effects. Note: :c:macro:`ZFP_ROUNDING_MODE` is currently supported only by the :code:`serial` and :code:`omp` :ref:`execution policies `. Default: :code:`ZFP_ROUND_NEVER`. .. c:macro:: ZFP_WITH_TIGHT_ERROR **Experimental feature**. When enabled, this feature takes advantage of the error reduction associated with proper rounding; see :c:macro:`ZFP_ROUNDING_MODE`. The reduced error due to rounding allows the tolerance in :ref:`fixed-accuracy mode ` to be satisfied using fewer bits of compressed data. As a result, when enabled, the observed maximum absolute error is closer to the tolerance and the compression ratio is increased. This feature requires the rounding mode to be :code:`ZFP_ROUND_FIRST` or :code:`ZFP_ROUND_LAST` and is supported only by the :code:`serial` and :code:`omp` :ref:`execution policies `. Default: undefined/off. .. c:macro:: ZFP_WITH_DAZ When enabled, blocks consisting solely of subnormal floating-point numbers (tiny numbers close to zero) are treated as blocks of all zeros (DAZ = denormals-are-zero). The main purpose of this option is to avoid the potential for floating-point overflow in the |zfp| implementation that may occur in step 2 of the :ref:`lossy compression algorithm ` when converting to |zfp|'s block-floating-point representation (see `Issue #119 `__). Such overflow tends to be benign but loses all precision and usually results in "random" subnormals upon decompression. When enabled, compressed streams may differ slightly but are decompressed correctly by libraries built without this option. This option may break some regression tests. Note: :c:macro:`ZFP_WITH_DAZ` is currently ignored by all :ref:`execution policies ` other than :code:`serial` and :code:`omp`. Default: undefined/off. .. c:macro:: ZFP_WITH_ALIGNED_ALLOC Use aligned memory allocation in an attempt to align compressed blocks on hardware cache lines. Default: undefined/off. .. c:macro:: ZFP_WITH_CACHE_TWOWAY Use a two-way skew-associative rather than direct-mapped cache. This incurs some overhead that may be offset by better cache utilization. Default: undefined/off. .. c:macro:: ZFP_WITH_CACHE_FAST_HASH Use a simpler hash function for cache line lookup. This is faster but may lead to more collisions. Default: undefined/off. .. c:macro:: ZFP_WITH_CACHE_PROFILE Enable cache profiling to gather and print statistics on cache hit and miss rates. Default: undefined/off. .. c:macro:: BIT_STREAM_WORD_TYPE Unsigned integer type used for buffering bits. Wider types tend to give higher performance at the expense of lower :ref:`bit rate granularity `. For portability of compressed files between little and big endian platforms, :c:macro:`BIT_STREAM_WORD_TYPE` should be set to :c:type:`uint8`. Default: :c:type:`uint64`. .. c:macro:: ZFP_BIT_STREAM_WORD_SIZE CMake macro for indirectly setting :c:macro:`BIT_STREAM_WORD_TYPE`. Valid values are 8, 16, 32, 64. Default: 64. .. c:macro:: BIT_STREAM_STRIDED Enable support for strided bit streams that allow for non-contiguous memory layouts, e.g., to enable progressive access. Default: undefined/off. .. c:macro:: CFP_NAMESPACE Macro for renaming the outermost |cfp| namespace, e.g., to avoid name clashes. Default: :code:`cfp`. .. c:macro:: PYTHON_LIBRARY Path to the Python library, e.g., :file:`/usr/lib/libpython2.7.so`. CMake default: undefined/off. GNU make default: off and ignored. .. c:macro:: PYTHON_INCLUDE_DIR Path to the Python include directory, e.g., :file:`/usr/include/python2.7`. CMake default: undefined/off. GNU make default: off and ignored. Dependencies ------------ The core |zfp| library and compressed arrays require only a C89 and C++98 compiler. The optional components have additional dependencies, as outlined in the sections below. CMake ^^^^^ CMake builds require version 3.9 or later. CMake is available `here `__. OpenMP ^^^^^^ OpenMP support requires OpenMP 2.0 or later. CUDA ^^^^ CUDA support requires CUDA 7.0 or later, CMake, and a compatible host compiler (see :c:macro:`ZFP_WITH_CUDA`). C/C++ ^^^^^ The |zfp| C library and |cfp| C wrappers around the compressed-array classes conform to the C90 standard (`ISO/IEC 9899:1990 `__). The C++ classes conform to the C++98 standard (`ISO/IEC 14882:1998 `__). Python ^^^^^^ The optional Python bindings require CMake and the following minimum versions: * Python: Python 2.7 & Python 3.5 * Cython: 0.22 * NumPy: 1.8.0 The necessary dependencies can be installed using ``pip`` and the |zfp| :file:`requirements.txt`:: pip install -r $ZFP_ROOT/python/requirements.txt Fortran ^^^^^^^ The optional Fortran bindings require a Fortran 2018 compiler. zfp-1.0.1/docs/source/introduction.rst000066400000000000000000000234621453723256400200350ustar00rootroot00000000000000.. include:: defs.rst .. _introduction: Introduction ============ |zfp| is an open-source library for representing multidimensional numerical arrays in compressed form to reduce storage and bandwidth requirements. |zfp| consists of four main components: * An **efficient number format** for representing small, fixed-size *blocks* of real values. The |zfp| format usually provides higher accuracy per bit stored than conventional number formats like IEEE 754 floating point. * A set of :ref:`classes ` that implement storage and manipulation of a **multidimensional array data type**. |zfp| arrays support high-speed read and write random access to individual array elements and are a drop-in replacement for :code:`std::vector` and native C/C++ arrays. |zfp| arrays provide accessors like :ref:`proxy pointers `, :ref:`iterators `, and :ref:`views `. |zfp| arrays allow specifying an exact memory footprint or an error tolerance. * A :ref:`C library ` for **streaming compression** of partial or whole arrays of integers or floating-point numbers, e.g., for applications that read and write large data sets to and from disk. This library supports fast, parallel (de)compression via OpenMP and CUDA. * A **command-line executable** for :ref:`compressing binary files ` of integer or floating-point arrays, e.g., as a substitute for general-purpose compressors like :code:`gzip`. As a compressor, |zfp| is primarily *lossy*, meaning that the numerical values are usually only approximately represented, though the user may specify error tolerances to limit the amount of loss. Fully :ref:`lossless compression `, where values are represented exactly, is also supported. |zfp| is primarily written in C and C++ but also includes :ref:`Python ` and :ref:`Fortran ` bindings. |zfp| is being developed at `Lawrence Livermore National Laboratory `__ and is supported by the U.S. Department of Energy's `Exascale Computing Project `__. |zfp| is a `2023 R&D 100 Award Winner `__. Availability ------------ |zfp| is freely available as open source on `GitHub `__ and is distributed under the terms of a permissive three-clause :ref:`BSD license `. |zfp| may be :ref:`installed ` using CMake or GNU Make. Installation from source code is recommended for users who wish to configure the internals of |zfp| and select which components (e.g., programming models, language bindings) to install. |zfp| is also available through several package managers, including Conda (both `C/C++ `__ and `Python `__ packages are available), `PIP `__, `Spack `__, and `MacPorts `__. `Linux packages `__ are available for several distributions and may be installed, for example, using :code:`apt` and :code:`yum`. .. _app-support: Application Support ------------------- |zfp| has been incorporated into several independently developed applications, plugins, and formats, such as * `Compressed file I/O `__ in `ADIOS `__. * `Compression codec `__ in the `BLOSC `__ meta compressor. * `H5Z-ZFP `__ plugin for `HDF5 `__\ |reg|. |zfp| is also one of the select compressors shipped with `HDF5 binaries `__. * `Compression functions `__ for Intel\ |reg| `Integrated Performance Primitives `__. * `Compressed MPI messages `__ in `MVAPICH2-GDR `__. * `Compressed file I/O `__ in `OpenInventor `__\ |tm|. * `Compression codec `__ underlying the `OpenZGY `__ format. * `Compressed file I/O `__ in `TTK `__. * `Third-party module `__ in `VTK `__. * `Compression worklet `__ in `VTK-m `__. * `Compression codec `__ in `Zarr `__ via `numcodecs `__. See `this list `__ for other software products that support |zfp|. Usage ----- The typical user will interact with |zfp| via one or more of its components, specifically * Via the :ref:`C API ` when doing I/O in an application or otherwise performing data (de)compression online. High-speed, parallel compression is supported via OpenMP and CUDA. * Via |zfp|'s in-memory :ref:`compressed-array classes ` when performing computations on very large arrays that demand random access to array elements, e.g., in visualization, data analysis, or even in numerical simulation. These classes can often substitute C/C++ arrays and STL vectors in applications with minimal code changes. * Via the |zfp| :ref:`command-line tool ` when compressing binary files offline. * Via :ref:`third-party ` I/O libraries or tools that support |zfp|. Technology ---------- |zfp| compresses *d*-dimensional (1D, 2D, 3D, and 4D) arrays of integer or floating-point values by partitioning the array into cubical blocks of |4powd| values, i.e., 4, 16, 64, or 256 values for 1D, 2D, 3D, and 4D arrays, respectively. Each such block is independently compressed to a fixed- or variable-length bit string, and these bit strings may be concatenated into a single stream of bits. |zfp| usually truncates each per-block bit string to a fixed number of bits to meet a storage budget or to some variable length needed to meet a given error tolerance, as dictated by the compressibility of the data. The bit string representing any given block may be truncated at any point and still yield a valid approximation. The early bits are most important; later bits progressively refine the approximation, similar to how the last few bits in a floating-point number have less significance than the first several bits. The trailing bits can usually be discarded (zeroed) with limited impact on accuracy. |zfp| was originally designed for floating-point arrays only but has been extended to also support integer data, and could for instance be used to compress images and quantized volumetric data. To achieve high compression ratios, |zfp| generally uses lossy but optionally error-bounded compression. Bit-for-bit lossless compression is also possible through one of |zfp|'s :ref:`compression modes `. |zfp| works best for 2D-4D arrays that exhibit spatial correlation, such as continuous fields from physics simulations, images, regularly sampled terrain surfaces, etc. Although |zfp| also provides support for 1D arrays, e.g., for audio signals or even unstructured floating-point streams, the compression scheme has not been well optimized for this use case, and compression ratio and quality may not be competitive with floating-point compressors designed specifically for 1D streams. In all use cases, it is important to know how to use |zfp|'s :ref:`compression modes ` as well as what the :ref:`limitations ` of |zfp| are. Although it is not critical to understand the :ref:`compression algorithm ` itself, having some familiarity with its major components may help understand what to expect and how |zfp|'s parameters influence the result. Resources --------- |zfp| is based on the :ref:`algorithm ` described in the following paper: .. _tvcg-paper: | Peter Lindstrom | "`Fixed-Rate Compressed Floating-Point Arrays `__" | IEEE Transactions on Visualization and Computer Graphics | 20(12):2674-2683, December 2014 | `doi:10.1109/TVCG.2014.2346458 `__ |zfp| has evolved since the original publication; the algorithm implemented in the current version is described in: .. _siam-paper: | James Diffenderfer, Alyson Fox, Jeffrey Hittinger, Geoffrey Sanders, Peter Lindstrom | "`Error Analysis of ZFP Compression for Floating-Point Data `__" | SIAM Journal on Scientific Computing | 41(3):A1867-A1898, 2019 | `doi:10.1137/18M1168832 `__ For more information on |zfp|, please see the |zfp| `website `__. For bug reports, please consult the `GitHub issue tracker `__. For questions, comments, and requests, please `contact us `__. zfp-1.0.1/docs/source/issues.rst000066400000000000000000000447041453723256400166310ustar00rootroot00000000000000.. include:: defs.rst .. _issues: Troubleshooting =============== This section is intended for troubleshooting problems with |zfp|, in case any arise, and primarily focuses on how to correctly make use of |zfp|. If the decompressed data looks nothing like the original data, or if the compression ratios obtained seem not so impressive, then it is very likely that array dimensions or compression parameters have not been set correctly, in which case this troubleshooting guide could help. The problems addressed in this section include: #. :ref:`Is the data dimensionality correct? ` #. :ref:`Do the compressor and decompressor agree on the dimensionality? ` #. :ref:`Have the "smooth" dimensions been identified? ` #. :ref:`Are the array dimensions correct? ` #. :ref:`Are the array dimensions large enough? ` #. :ref:`Is the data logically structured? ` #. :ref:`Is the data set embedded in a regular grid? ` #. :ref:`Have fill values, NaNs, and infinities been removed? ` #. :ref:`Is the byte order correct? ` #. :ref:`Is the floating-point precision correct? ` #. :ref:`Is the integer precision correct? ` #. :ref:`Is the data provided to the zfp executable a raw binary array? ` #. :ref:`Has the appropriate compression mode been set? ` ------------------------------------------------------------------------------- .. _p-dimensionality: P1: *Is the data dimensionality correct?* This is one of the most common problems. First, make sure that |zfp| is given the correct dimensionality of the data. For instance, an audio stream is a 1D array, an image is a 2D array, and a volume grid is a 3D array, and a time-varying volume is a 4D array. Sometimes a data set is a discrete collection of lower-dimensional objects. For instance, a stack of unrelated images (of the same size) could be represented in C as a 3D array:: imstack[count][ny][nx] but since in this case the images are unrelated, no correlation would be expected along the third dimension---the underlying dimensionality of the data is here two. In this case, the images could be compressed one at a time, or they could be compressed together by treating the array dimensions as:: imstack[count * ny][nx] Note that |zfp| partitions *d*-dimensional arrays into blocks of |4powd| values. If *ny* above is not a multiple of four, then some blocks of |4by4| pixels will contain pixels from different images, which could hurt compression and/or quality. Still, this way of creating a single image by stacking multiple images is far preferable over linearizing each image into a 1D signal, and then compressing the images as:: imstack[count][ny * nx] This loses the correlation along the *y* dimension and further introduces discontinuities unless *nx* is a multiple of four. Similarly to the example above, a 2D vector field :: vfield[ny][nx][2] could be declared as a 3D array, but the *x*- and *y*-components of the 2D vectors are likely entirely unrelated. In this case, each component needs to be compressed independently, either by rearranging the data as two scalar fields:: vfield[2][ny][nx] or by using strides (see also FAQ :ref:`#1 `). Note that in all these cases |zfp| will still compress the data, but if the dimensionality is not correct then the compression ratio will suffer. ------------------------------------------------------------------------------- .. _p-agree: P2: *Do the compressor and decompressor agree on the dimensionality?* Consider compressing a 3D array:: double a[1][1][100] with *nx* = 100, *ny* = 1, *nz* = 1, then decompressing the result to a 1D array:: double b[100] with *nx* = 100. Although the arrays *a* and *b* occupy the same amount of memory and are in C laid out similarly, these arrays are not equivalent to |zfp| because their dimensionalities differ. |zfp| uses different CODECs to (de)compress 1D, 2D, 3D, and 4D arrays, and the 1D decompressor expects a compressed bit stream that corresponds to a 1D array. What happens in practice in this case is that the array *a* is compressed using |zfp|'s 3D CODEC, which first pads the array to :: double padded[4][4][100] When this array is correctly decompressed using the 3D CODEC, the padded values are generated but discarded. |zfp|'s 1D decompressor, on the other hand, expects 100 values, not 100 |times| 4 |times| 4 = 1600 values, and therefore likely returns garbage. ------------------------------------------------------------------------------- .. _p-smooth: P3: *Have the "smooth" dimensions been identified?* Closely related to :ref:`P1 ` above, some fields simply do not vary smoothly along all dimensions, and |zfp| can do a good job compressing only those dimensions that exhibit some coherence. For instance, consider a table of stock prices indexed by date and stock:: price[stocks][dates] One could be tempted to compress this as a 2D array, but there is likely little to no correlation in prices between different stocks. Each such time series should be compressed independently as a 1D signal. What about time-varying images like a video sequence? In this case, it is likely that there is correlation over time, and that the value of a single pixel varies smoothly in time. It is also likely that each image exhibits smoothness along its two spatial dimensions. So this can be treated as a single, 3D data set. How about time-varying volumes, such as :: field[nt][nz][ny][nx] As of version |4drelease|, |zfp| supports compression of 4D arrays. Since all dimensions in this example are likely to be correlated, the 4D array can be compressed directly. Alternatively, the data could be organized by the three "smoothest" dimensions and compressed as a 3D array. Given the organization above, the array could be treated as 3D:: field[nt * nz][ny][nx] Again, do **not** compress this as a 3D array with the *innermost* dimensions unfolded:: field[nt][nz][ny * nx] ------------------------------------------------------------------------------- .. _p-dimensions: P4: *Are the array dimensions correct?* This is another common problem that seems obvious, but often the dimensions are accidentally transposed. Assuming that the smooth dimensions have been identified, it is important that the dimensions are listed in the correct order. For instance, if the data (in C notation) is organized as:: field[d1][d2][d3] then the data is organized in memory (or on disk) with the d3 dimension varying fastest, and hence *nx* = *d3*, *ny* = *d2*, *nz* = *d1* using the |zfp| naming conventions for the dimensions, e.g., the :ref:`zfp executable ` should be invoked with:: zfp -3 d3 d2 d1 in this case. Things will go horribly wrong if |zfp| in this case is called with *nx* = *d1*, *ny* = *d2*, *nz* = *d3*. The entire data set will still compress and decompress, but compression ratio and quality will likely suffer greatly. See :ref:`this FAQ ` for more details. ------------------------------------------------------------------------------- .. _p-large: P5: *Are the array dimensions large enough?* |zfp| partitions *d*-dimensional data sets into blocks of |4powd| values, e.g., in 3D a block consists of |4by4by4| values. If the dimensions are not multiples of four, then |zfp| will "pad" the array to the next larger multiple of four. Such padding can hurt compression. In particular, if one or more of the array dimensions are small, then the overhead of such padding could be significant. Consider compressing a collection of 1000 small 3D arrays:: field[1000][5][14][2] |zfp| would first logically pad this to a larger array:: field[1000][8][16][4] which is (8 |times| 16 |times| 4) / (5 |times| 14 |times| 2) ~ 3.66 times larger. Although such padding often compresses well, this still represents a significant overhead. If a large array has been partitioned into smaller pieces, it may be best to reassemble the larger array. Or, when possible, ensure that the sub-arrays have dimensions that are multiples of four. ------------------------------------------------------------------------------- .. _p-structured: P6: *Is the data logically structured?* |zfp| was designed for logically structured data, i.e., Cartesian grids. It works much like an image compressor does, which assumes that the data set is a structured array of pixels, and it assumes that values vary reasonably smoothly on average, just like natural images tend to contain large regions of uniform color or smooth color gradients, like a blue sky, smoothly varying skin tones of a human's face, etc. Many data sets are not represented on a regular grid. For instance, an array of particle *xyz* positions:: points[count][3] is a 2D array, but does not vary smoothly in either dimension. Furthermore, such unstructured data sets need not be organized in any particular order; the particles could be listed in any arbitrary order. One could attempt to sort the particles, for example by the *x* coordinate, to promote smoothness, but this would still leave the other two dimensions non-smooth. Sometimes the underlying dimensions are not even known, and only the total number of floating-point values is known. For example, suppose we only knew that the data set contained *n* = *count* |times| 3 values. One might be tempted to compress this using |zfp|'s 1-dimensional compressor, but once again this would not work well. Such abuse of |zfp| is much akin to trying to compress an image using an audio compressor like mp3, or like compressing an *n*-sample piece of music as an *n*-by-one sized image using an image compressor like JPEG. The results would likely not be very good. Some data sets are logically structured but geometrically irregular. Examples include fields stored on Lagrangian meshes that have been warped, or on spectral element grids, which use a non-uniform grid spacing. |zfp| assumes that the data has been regularly sampled in each dimension, and the more the geometry of the sampling deviates from uniform, the worse compression gets. Note that rectilinear grids with different but uniform grid spacing in each dimension are fine. If your application uses very non-uniform sampling, then resampling onto a uniform grid (if possible) may be advisable. Other data sets are "block structured" and consist of piecewise structured grids that are "glued" together. Rather than treating such data as unstructured 1D streams, consider partitioning the data set into independent (possibly overlapping) regular grids. ------------------------------------------------------------------------------- .. _p-embedded: P7: *Is the data set embedded in a regular grid?* Some applications represent irregular geometry on a Cartesian grid, and leave portions of the domain unspecified. Consider, for instance, sampling the density of the Earth onto a Cartesian grid. Here the density for grid points outside the Earth is unspecified. In this case, |zfp| does best by initializing the "background field" to all zeros. In |zfp|'s :ref:`fixed-accuracy mode `, any "empty" block that consists of all zeros is represented using a single bit, and therefore the overhead of representing empty space can be kept low. ------------------------------------------------------------------------------- .. _p-invalid: P8: *Have fill values, NaNs, and infinities been removed?* It is common to signal unspecified values using what is commonly called a "fill value," which is a special constant value that tends to be far out of range of normal values. For instance, in climate modeling the ocean temperature over land is meaningless, and it is common to use a very large temperature value such as 1e30 to signal that the temperature is undefined for such grid points. Very large fill values do not play well with |zfp|, because they both introduce artificial discontinuities and pollute nearby values by expressing them all with respect to the common largest exponent within their block. Assuming a fill value of 1e30, the value pi in the same block would be represented as:: 0.00000000000000000000000000000314159... * 1e30 Given finite precision, the small fraction would likely be replaced with zero, resulting in complete loss of the actual value being stored. Other applications use NaNs (special not-a-number values) or infinities as fill values. These are even more problematic, because they do not have a defined exponent. |zfp| relies on the C function :c:func:`frexp` to compute the exponent of the largest (in magnitude) value within a block, but produces unspecified behavior if that value is not finite. |zfp| currently has no independent mechanism for handling fill values. Ideally such special values would be signalled separately, e.g., using a bit mask, and then replaced with zeros to ensure that they both compress well and do not pollute actual data. ------------------------------------------------------------------------------- .. _p-endian: P9: *Is the byte order correct?* |zfp| generally works with the native byte order (e.g., little or big endian) of the machine it is compiled on. One needs only be concerned with byte order when reading raw, binary data into the |zfp| executable, when exchanging compressed files across platforms, and when varying the bit stream word size on big endian machines (not common). For instance, to compress a binary double-precision floating-point file stored in big endian byte order on a little endian machine, byte swapping must first be done. For example, on Linux and macOS, 8-byte doubles can be byte swapped using:: objcopy -I binary -O binary --reverse-bytes=8 big.bin little.bin See also FAQ :ref:`#11 ` for more discussion of byte order. ------------------------------------------------------------------------------- .. _p-float-precision: P10: *Is the floating-point precision correct?* Another obvious problem: Please make sure that |zfp| is told whether the data to compress is an array of single- (32-bit) or double-precision (64-bit) values, e.g., by specifying the :option:`-f` or :option:`-d` options to the :program:`zfp` executable or by passing the appropriate :c:type:`zfp_type` to the C functions. ------------------------------------------------------------------------------- .. _p-int-precision: P11: *Is the integer precision correct?* |zfp| currently supports compression of 31- or 63-bit signed integers. Shorter integers (e.g., bytes, shorts) can be compressed but must first be promoted to one of the longer types. This should always be done using |zfp|'s functions for :ref:`promotion and demotion `, which both perform bit shifting and biasing to handle both signed and unsigned types. It is not sufficient to simply cast short integers to longer integers. See also FAQs :ref:`#8 ` and :ref:`#9 `. ------------------------------------------------------------------------------- .. _p-binary: P12: *Is the data provided to the zfp executable a raw binary array?* |zfp| expects that the input file is a raw binary array of integers or floating-point values in the IEEE format, e.g., written to file using :c:func:`fwrite`. Do not hand |zfp| a text file containing ASCII floating-point numbers. Strip the file of any header information. Languages like Fortran tend to store with the array its size. No such metadata may be embedded in the file. ------------------------------------------------------------------------------- .. _p-mode: P13: *Has the appropriate compression mode been set?* |zfp| provides three different lossy :ref:`modes of compression ` that trade storage and accuracy, plus one :ref:`lossless mode `. In fixed-rate mode, the user specifies the exact number of bits (often in increments of a fraction of a bit) of compressed storage per value (but see FAQ :ref:`#18 ` for caveats). From the user's perspective, this seems a very desirable feature, since it provides for a direct mechanism for specifying how much storage to use. However, there is often a large quality penalty associated with the fixed-rate mode, because each block of |4powd| values is allocated the same number of bits. In practice, the information content over the data set varies significantly, which means that easy-to-compress regions are assigned too many bits, while too few bits are available to faithfully represent the more challenging-to-compress regions. Although one of the unique features of |zfp|, its fixed-rate mode should primarily be used only when random access to the data is needed. |zfp| also provides a fixed-precision mode, where the user specifies how many uncompressed significant bits to use to represent the floating-point fraction. This precision may not be exactly what people might normally think of. For instance, the C float type is commonly referred to as 32-bit precision. However, the sign bit and exponent account for nine of those bits and do not contribute to the number of significant bits of precision. Furthermore, for normal numbers, IEEE uses a hidden implicit one bit, so most float values actually have 24 bits of precision. Furthermore, |zfp| uses a block-floating-point representation with a single exponent per block, which may cause some small values to have several leading zero bits and therefore less precision than requested. Thus, the effective precision returned by |zfp| in its fixed-precision mode may in fact vary. In practice, the precision requested is only an upper bound, though typically at least one value within a block has the requested precision. |zfp| supports a fixed-accuracy mode, which except in rare circumstances (see FAQ :ref:`#17 `) ensures that the absolute error is bounded, i.e., the difference between any decompressed and original value is at most the tolerance specified by the user (but usually several times smaller). Whenever possible, we recommend using this compression mode, which depending on how easy the data is to compress results in the smallest compressed stream that respects the error tolerance. As of |zfp| |revrelease|, reversible (lossless) compression is available. The amount of lossless reduction of floating-point data is usually quite limited, however, especially for double-precision data. Unless a bit-for-bit exact reconstruction is needed, we strongly advocate the use of lossy compression. Finally, there is also an expert mode that allows the user to combine the constraints of fixed rate, precision, and accuracy. See the section on :ref:`compression modes ` for more details. zfp-1.0.1/docs/source/iterators.inc000066400000000000000000000206071453723256400172670ustar00rootroot00000000000000.. index:: single: Iterators .. _iterators: Iterators --------- .. cpp:namespace:: zfp .. cpp:class:: array1::const_iterator .. cpp:class:: array2::const_iterator .. cpp:class:: array3::const_iterator .. cpp:class:: array4::const_iterator .. cpp:class:: array1::iterator : public array1::const_iterator .. cpp:class:: array2::iterator : public array2::const_iterator .. cpp:class:: array3::iterator : public array3::const_iterator .. cpp:class:: array4::iterator : public array4::const_iterator Iterators provide a mechanism for traversing a possibly multi-dimensional array---or a :ref:`view ` of a subset of an array---without having to track array indices or bounds. They are also the preferred mechanism, compared to nested index loops, for initializing arrays, because they sequentially visit the array one block at a time. This allows all elements of a block to be initialized together and ensures that the block is not compressed to memory before it has been fully initialized, which might otherwise result in poor compression and, consequently, larger compression errors than when the entire block is initialized as a whole. Note that the iterator traversal order differs in this respect from traversal by :ref:`pointers `. Blocks are visited in raster order similarly to how individual array elements are indexed, that is, first by *x*, then by *y*, then by *z*, etc. Within each block, elements are visited in the same raster order. All |4powd| values in a block are visited before moving on to the next block (see :numref:`view-indexing`). As of |zfp| |raiterrelease|, all iterators provided by |zfp| are random access iterators (previously, multi-dimensional array iterators were only forward iterators). |zfp| iterators are `STL `_ compliant and can be used in STL algorithms that support random access iterators. |zfp| |crpirelease| adds :code:`const` qualified versions of iterators, given by the :code:`const_iterator` class. Such iterators are available also for :ref:`read-only arrays `. Per STL mandate, the iterators define several types: .. cpp:namespace:: zfp::arrayANY .. cpp:type:: iterator::value_type The scalar type associated with the array that the iterator points into. ---- .. cpp:type:: iterator::difference_type Difference between two iterators in number of array elements. ---- .. cpp:type:: iterator::reference The :ref:`reference ` type associated with the iterator's parent array class. ---- .. cpp:type:: iterator::pointer The :ref:`pointer ` type associated with the iterator's parent array class. ---- .. cpp:type:: iterator::iterator_category Type of iterator: :cpp:type:`std::random_access_iterator_tag`. For const iterators, the following additional types are defined: .. cpp:type:: const_iterator::const_reference The immutable reference type associated with the iterator's container class. .. cpp:type:: const_iterator::const_pointer The immutable pointer type associated with the iterator's container class. The following operations are defined on iterators: .. cpp:function:: iterator iterator::operator=(const iterator& it) .. cpp:function:: const_iterator const_iterator::operator=(const const_iterator& it) Assignment (copy) operator. Make the iterator point to the same element as *it*. ---- .. cpp:function:: reference iterator::operator*() const .. cpp:function:: const_reference const_iterator::operator*() const Dereference operator. Return (const) reference to the value pointed to by the iterator. ---- .. cpp:function:: reference iterator::operator[](difference_type d) const .. cpp:function:: const_reference const_iterator::operator[](difference_type d) const Offset dereference operator. Return (const) reference to the value *d* elements relative to the current element in the iteration sequence (*d* may be negative). This operator executes in constant time regardless of array dimensionality but is more costly than sequential iteration via :cpp:func:`iterator::operator++`. ---- .. cpp:function:: iterator iterator::operator+(difference_type d) const .. cpp:function:: const_iterator const_iterator::operator+(difference_type d) const Return a new iterator that has been incremented by *d*. ---- .. cpp:function:: iterator iterator::operator-(difference_type d) const .. cpp:function:: const_iterator const_iterator::operator-(difference_type d) const Return a new iterator that has been decremented by *d*. ---- .. cpp:function:: difference_type iterator::operator-(const iterator& it) const .. cpp:function:: difference_type const_iterator::operator-(const const_iterator& it) const Return difference between this iterator and *it* in number of elements. The difference *p* |minus| *q* between two iterators, *p* and *q*, is negative if *p* < *q*. The iterators must refer to elements in the same array. ---- .. cpp:function:: bool iterator::operator==(const iterator& it) const .. cpp:function:: bool const_iterator::operator==(const const_iterator& it) const Return true if the two iterators point to the same element. ---- .. cpp:function:: bool iterator::operator!=(const iterator& it) const .. cpp:function:: bool const_iterator::operator!=(const const_iterator& it) const Return true if the two iterators do not point to the same element. ---- .. _iter_inequalities: .. cpp:function:: bool iterator::operator<=(const iterator& it) const .. cpp:function:: bool iterator::operator>=(const iterator& it) const .. cpp:function:: bool iterator::operator<(const iterator& it) const .. cpp:function:: bool iterator::operator>(const iterator& it) const .. cpp:function:: bool const_iterator::operator<=(const const_iterator& it) const .. cpp:function:: bool const_iterator::operator>=(const const_iterator& it) const .. cpp:function:: bool const_iterator::operator<(const const_iterator& it) const .. cpp:function:: bool const_iterator::operator>(const const_iterator& it) const Return true if the two iterators satisfy the given relationship. For two iterators, *p* and *q*, within the same array, *p* < *q* if and only if *q* can be reached by incrementing *p* one or more times. ---- .. cpp:function:: iterator& iterator::operator++() .. cpp:function:: const_iterator& const_iterator::operator++() Prefix increment (:code:`++it`). Return a reference to the incremented iterator. ---- .. cpp:function:: iterator iterator::operator++(int) .. cpp:function:: const_iterator const_iterator::operator++(int) Postfix increment (:code:`it++`). Return the value of the iterator before being incremented. ---- .. cpp:function:: iterator& iterator::operator--() .. cpp:function:: const_iterator& const_iterator::operator--() Prefix decrement (:code:`--it`). Return a reference to the decremented iterator. ---- .. cpp:function:: iterator iterator::operator--(int) .. cpp:function:: const_iterator const_iterator::operator--(int) Postfix decrement (:code:`it--`). Return the value of the iterator before being decremented. ---- .. cpp:function:: iterator iterator::operator+=(difference_type d) .. cpp:function:: const_iterator const_iterator::operator+=(difference_type d) Increment iterator *d* times. Return value of incremented iterator. Although :cpp:expr:`++it` and :cpp:expr:`it += 1` are semantically equivalent, the former is more efficient for multidimensional arrays. ---- .. cpp:function:: iterator iterator::operator-=(difference_type d) .. cpp:function:: const_iterator const_iterator::operator-=(difference_type d) Decrement iterator *d* times. Return value of decremented iterator. Although :cpp:expr:`--it` and :cpp:expr:`it -= 1` are semantically equivalent, the former is more efficient for multidimensional arrays. ---- .. cpp:function:: size_t iterator::i() const .. cpp:function:: size_t iterator::j() const .. cpp:function:: size_t iterator::k() const .. cpp:function:: size_t iterator::l() const .. cpp:function:: size_t const_iterator::i() const .. cpp:function:: size_t const_iterator::j() const .. cpp:function:: size_t const_iterator::k() const .. cpp:function:: size_t const_iterator::l() const Return array index or local view index of element pointed to by the iterator. :cpp:func:`iterator::i` is defined for all arrays. :cpp:func:`iterator::j` is defined only for 2D, 3D, and 4D arrays. :cpp:func:`iterator::k` is defined only for 3D and 4D arrays. :cpp:func:`iterator::l` is defined only for 4D arrays. zfp-1.0.1/docs/source/license.rst000066400000000000000000000053411453723256400167320ustar00rootroot00000000000000.. _license: License ======= | Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC | All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the disclaimer below. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the disclaimer (as noted below) in the documentation and/or other materials provided with the distribution. 3. Neither the name of the LLNS/LLNL nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Notice ------ This work was produced under the auspices of the U.S. Department of Energy by Lawrence Livermore National Laboratory under Contract DE-AC52-07NA27344. This work was prepared as an account of work sponsored by an agency of the United States Government. Neither the United States Government nor Lawrence Livermore National Security, LLC, nor any of their employees makes any warranty, expressed or implied, or assumes any legal liability or responsibility for the accuracy, completeness, or usefulness of any information, apparatus, product, or process disclosed, or represents that its use would not infringe privately owned rights. Reference herein to any specific commercial product, process, or service by trade name, trademark, manufacturer, or otherwise does not necessarily constitute or imply its endorsement, recommendation, or favoring by the United States Government or Lawrence Livermore National Security, LLC. The views and opinions of authors expressed herein do not necessarily state or reflect those of the United States Government or Lawrence Livermore National Security, LLC, and shall not be used for advertising or product endorsement purposes. zfp-1.0.1/docs/source/limitations.rst000066400000000000000000000104301453723256400176370ustar00rootroot00000000000000.. include:: defs.rst .. _limitations: Limitations =========== |zfp| has evolved over the years from a research prototype to a production quality library. However, the API and even the compression codec are still undergoing changes as new important features are added. Below is a list of known limitations of the current version of |zfp|. See the section on :ref:`directions` for a discussion of planned features that will address some of these limitations. - Special floating-point values like infinity and NaN are supported in reversible mode but not in |zfp|'s lossy compression modes. Subnormal floating-point numbers are, however, correctly handled. There is an implicit assumption that floating point conforms to IEEE-754, though extensions to other floating-point formats should be possible with minor effort. - The optional |zfp| :ref:`header ` supports arrays with at most 2\ :sup:`48` elements. The |zfp| header limits each dimension to 2\ :sup:`48/d` elements in a *d*-dimensional array, i.e., 2\ :sup:`48`, 2\ :sup:`24`, 2\ :sup:`16`, and 2\ :sup:`12` for 1D through 4D arrays, respectively. Note that this limitation applies only to the header; array dimensions are otherwise limited only by the size supported by :code:`size_t`. - The :ref:`compressed-array classes ` have additional size restrictions. The :ref:`cache ` supports at most 2\ :sup:`p-1` - 1 blocks, where *p* is the number of bits in a :code:`uint` (usually *p* = 32). Consequently, the number of elements in a *d*-dimensional compressed array is at most |4powd| |times| (2\ :sup:`p-1` - 1), or about 8 billion elements for 1D arrays. - Conventional pointers and references to individual array elements are not available. That is, constructions like :code:`double* ptr = &a[i];` are not possible when :code:`a` is a |zfp| array. However, as of |zfp| |proxyrelease|, :ref:`proxy pointers ` are available that act much like pointers to uncompressed data. Similarly, operators :code:`[]` and :code:`()` do not return regular C++ references. Instead, a :ref:`proxy reference ` class is used (similar to how `STL bit vectors `__ are implemented). These proxy references and pointers can, however, safely be passed to functions and used where regular references and pointers can. - The :ref:`read-only array classes ` do not yet support (de)serialization. - |zfp| can potentially provide higher precision than conventional float and double arrays, but the interface currently does not expose this. For example, such added precision could be useful in finite difference computations, where catastrophic cancellation can be an issue when insufficient precision is available. - Only single and double precision floating types are supported. Generalizations to IEEE half and quad precision would be useful. For instance, compressed 64-bit-per-value storage of 128-bit quad-precision numbers could greatly improve the accuracy of double-precision floating-point computations using the same amount of storage. The |zfp| compressed-array classes do not yet support integer scalar types. - Complex-valued arrays are not directly supported. Real and imaginary components must be stored as separate arrays, which may result in lost opportunities for compression, e.g., if the complex magnitude is constant and only the phase varies. - Version |omprelease| adds support for OpenMP compression. However, OpenMP decompression is not yet supported. - Version |cudarelease| adds support for CUDA compression and decompression. However, only the fixed-rate compression mode is so far supported. The CUDA implementation is further subject to :ref:`additional limitations `. - The |cfp| :ref:`C wrappers ` for |zfp|'s compressed arrays support only a subset of the C++ API. |zfp| |4darrrelease| adds support for proxy references, pointers, and iterators, but views and read-only arrays are not yet supported. Furthermore, |cfp| works only with the |zfp| codec. - The Python and Fortran bindings do not yet support |zfp|'s compressed-array classes. Moreover, only a select subset of the :ref:`high-level API ` is available via Python. zfp-1.0.1/docs/source/low-level-api.rst000066400000000000000000000535411453723256400177720ustar00rootroot00000000000000.. include:: defs.rst .. _ll-api: Low-Level C API =============== The |libzfp| low-level C API provides functionality for compressing individual *d*-dimensional blocks of up to |4powd| values. If a block is not complete, i.e., contains fewer than |4powd| values, then |zfp|'s partial block support should be favored over padding the block with, say, zeros or other fill values. The blocks (de)compressed need not be contiguous and can be gathered from or scattered to a larger array by setting appropriate strides. As of |zfp| |cpprelease|, templated C++ wrappers are also available to simplify calling the low-level API from C++. The C API is declared in :file:`zfp.h`; the C++ wrappers are found in :file:`zfp.hpp`. .. note:: Because the unit of parallel work in |zfp| is a *block*, and because the low-level API operates on individual blocks, this API supports only the the serial :ref:`execution policy `. Any other execution policy set in :c:type:`zfp_stream` is silently ignored. For parallel execution, see the :ref:`high-level API `. The following topics are available: * :ref:`ll-stream` * :ref:`ll-encoder` * :ref:`ll-1d-encoder` * :ref:`ll-2d-encoder` * :ref:`ll-3d-encoder` * :ref:`ll-4d-encoder` * :ref:`ll-decoder` * :ref:`ll-1d-decoder` * :ref:`ll-2d-decoder` * :ref:`ll-3d-decoder` * :ref:`ll-4d-decoder` * :ref:`ll-utilities` * :ref:`ll-cpp-wrappers` .. _ll-stream: Stream Manipulation ------------------- .. c:function:: size_t zfp_stream_flush(zfp_stream* stream) Flush bit stream to write out any buffered bits. This function must be must be called after the last encode call. The bit stream is aligned on a stream word boundary following this call. The number of zero-bits written, if any, is returned. ---- .. c:function:: size_t zfp_stream_align(zfp_stream* stream) Align bit stream on next word boundary. This function is analogous to :c:func:`zfp_stream_flush`, but for decoding. That is, wherever the encoder flushes the stream, the decoder should align it to ensure synchronization between encoder and decoder. The number of bits skipped, if any, is returned. .. _ll-encoder: Encoder ------- A function is available for encoding whole or partial blocks of each scalar type and dimensionality. These functions return the number of bits of compressed storage for the block being encoded, or zero upon failure. .. _ll-1d-encoder: 1D Data ^^^^^^^ .. c:function:: size_t zfp_encode_block_int32_1(zfp_stream* stream, const int32* block) .. c:function:: size_t zfp_encode_block_int64_1(zfp_stream* stream, const int64* block) .. c:function:: size_t zfp_encode_block_float_1(zfp_stream* stream, const float* block) .. c:function:: size_t zfp_encode_block_double_1(zfp_stream* stream, const double* block) Encode 1D contiguous block of 4 values. ---- .. c:function:: size_t zfp_encode_block_strided_int32_1(zfp_stream* stream, const int32* p, ptrdiff_t sx) .. c:function:: size_t zfp_encode_block_strided_int64_1(zfp_stream* stream, const int64* p, ptrdiff_t sx) .. c:function:: size_t zfp_encode_block_strided_float_1(zfp_stream* stream, const float* p, ptrdiff_t sx) .. c:function:: size_t zfp_encode_block_strided_double_1(zfp_stream* stream, const double* p, ptrdiff_t sx) Encode 1D complete block from strided array with stride *sx*. ---- .. c:function:: size_t zfp_encode_partial_block_strided_int32_1(zfp_stream* stream, const int32* p, size_t nx, ptrdiff_t sx) .. c:function:: size_t zfp_encode_partial_block_strided_int64_1(zfp_stream* stream, const int64* p, size_t nx, ptrdiff_t sx) .. c:function:: size_t zfp_encode_partial_block_strided_float_1(zfp_stream* stream, const float* p, size_t nx, ptrdiff_t sx) .. c:function:: size_t zfp_encode_partial_block_strided_double_1(zfp_stream* stream, const double* p, size_t nx, ptrdiff_t sx) Encode 1D partial block of size *nx* from strided array with stride *sx*. .. _ll-2d-encoder: 2D Data ^^^^^^^ .. c:function:: size_t zfp_encode_block_int32_2(zfp_stream* stream, const int32* block) .. c:function:: size_t zfp_encode_block_int64_2(zfp_stream* stream, const int64* block) .. c:function:: size_t zfp_encode_block_float_2(zfp_stream* stream, const float* block) .. c:function:: size_t zfp_encode_block_double_2(zfp_stream* stream, const double* block) Encode 2D contiguous block of |4by4| values. ---- .. c:function:: size_t zfp_encode_block_strided_int32_2(zfp_stream* stream, const int32* p, ptrdiff_t sx, ptrdiff_t sy) .. c:function:: size_t zfp_encode_block_strided_int64_2(zfp_stream* stream, const int64* p, ptrdiff_t sx, ptrdiff_t sy) .. c:function:: size_t zfp_encode_block_strided_float_2(zfp_stream* stream, const float* p, ptrdiff_t sx, ptrdiff_t sy) .. c:function:: size_t zfp_encode_block_strided_double_2(zfp_stream* stream, const double* p, ptrdiff_t sx, ptrdiff_t sy) Encode 2D complete block from strided array with strides *sx* and *sy*. ---- .. c:function:: size_t zfp_encode_partial_block_strided_int32_2(zfp_stream* stream, const int32* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) .. c:function:: size_t zfp_encode_partial_block_strided_int64_2(zfp_stream* stream, const int64* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) .. c:function:: size_t zfp_encode_partial_block_strided_float_2(zfp_stream* stream, const float* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) .. c:function:: size_t zfp_encode_partial_block_strided_double_2(zfp_stream* stream, const double* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) Encode 2D partial block of size *nx* |times| *ny* from strided array with strides *sx* and *sy*. .. _ll-3d-encoder: 3D Data ^^^^^^^ .. c:function:: size_t zfp_encode_block_int32_3(zfp_stream* stream, const int32* block) .. c:function:: size_t zfp_encode_block_int64_3(zfp_stream* stream, const int64* block) .. c:function:: size_t zfp_encode_block_float_3(zfp_stream* stream, const float* block) .. c:function:: size_t zfp_encode_block_double_3(zfp_stream* stream, const double* block) Encode 3D contiguous block of |4by4by4| values. ---- .. c:function:: size_t zfp_encode_block_strided_int32_3(zfp_stream* stream, const int32* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. c:function:: size_t zfp_encode_block_strided_int64_3(zfp_stream* stream, const int64* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. c:function:: size_t zfp_encode_block_strided_float_3(zfp_stream* stream, const float* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. c:function:: size_t zfp_encode_block_strided_double_3(zfp_stream* stream, const double* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) Encode 3D complete block from strided array with strides *sx*, *sy*, and *sz*. ---- .. c:function:: size_t zfp_encode_partial_block_strided_int32_3(zfp_stream* stream, const int32* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. c:function:: size_t zfp_encode_partial_block_strided_int64_3(zfp_stream* stream, const int64* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. c:function:: size_t zfp_encode_partial_block_strided_float_3(zfp_stream* stream, const float* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. c:function:: size_t zfp_encode_partial_block_strided_double_3(zfp_stream* stream, const double* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) Encode 3D partial block of size *nx* |times| *ny* |times| *nz* from strided array with strides *sx*, *sy*, and *sz*. .. _ll-4d-encoder: 4D Data ^^^^^^^ .. c:function:: size_t zfp_encode_block_int32_4(zfp_stream* stream, const int32* block) .. c:function:: size_t zfp_encode_block_int64_4(zfp_stream* stream, const int64* block) .. c:function:: size_t zfp_encode_block_float_4(zfp_stream* stream, const float* block) .. c:function:: size_t zfp_encode_block_double_4(zfp_stream* stream, const double* block) Encode 4D contiguous block of |4by4by4by4| values. ---- .. c:function:: size_t zfp_encode_block_strided_int32_4(zfp_stream* stream, const int32* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) .. c:function:: size_t zfp_encode_block_strided_int64_4(zfp_stream* stream, const int64* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) .. c:function:: size_t zfp_encode_block_strided_float_4(zfp_stream* stream, const float* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) .. c:function:: size_t zfp_encode_block_strided_double_4(zfp_stream* stream, const double* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) Encode 4D complete block from strided array with strides *sx*, *sy*, *sz*, and *sw*. ---- .. c:function:: size_t zfp_encode_partial_block_strided_int32_4(zfp_stream* stream, const int32* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) .. c:function:: size_t zfp_encode_partial_block_strided_int64_4(zfp_stream* stream, const int64* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) .. c:function:: size_t zfp_encode_partial_block_strided_float_4(zfp_stream* stream, const float* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) .. c:function:: size_t zfp_encode_partial_block_strided_double_4(zfp_stream* stream, const double* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) Encode 4D partial block of size *nx* |times| *ny* |times| *nz* |times| *nw* from strided array with strides *sx*, *sy*, *sz*, and *sw*. .. _ll-decoder: Decoder ------- Each function below decompresses a single block and returns the number of bits of compressed storage consumed. See corresponding encoder functions above for further details. .. _ll-1d-decoder: 1D Data ^^^^^^^ .. c:function:: size_t zfp_decode_block_int32_1(zfp_stream* stream, int32* block) .. c:function:: size_t zfp_decode_block_int64_1(zfp_stream* stream, int64* block) .. c:function:: size_t zfp_decode_block_float_1(zfp_stream* stream, float* block) .. c:function:: size_t zfp_decode_block_double_1(zfp_stream* stream, double* block) Decode 1D contiguous block of 4 values. ---- .. c:function:: size_t zfp_decode_block_strided_int32_1(zfp_stream* stream, int32* p, ptrdiff_t sx) .. c:function:: size_t zfp_decode_block_strided_int64_1(zfp_stream* stream, int64* p, ptrdiff_t sx) .. c:function:: size_t zfp_decode_block_strided_float_1(zfp_stream* stream, float* p, ptrdiff_t sx) .. c:function:: size_t zfp_decode_block_strided_double_1(zfp_stream* stream, double* p, ptrdiff_t sx) Decode 1D complete block to strided array with stride *sx*. ---- .. c:function:: size_t zfp_decode_partial_block_strided_int32_1(zfp_stream* stream, int32* p, size_t nx, ptrdiff_t sx) .. c:function:: size_t zfp_decode_partial_block_strided_int64_1(zfp_stream* stream, int64* p, size_t nx, ptrdiff_t sx) .. c:function:: size_t zfp_decode_partial_block_strided_float_1(zfp_stream* stream, float* p, size_t nx, ptrdiff_t sx) .. c:function:: size_t zfp_decode_partial_block_strided_double_1(zfp_stream* stream, double* p, size_t nx, ptrdiff_t sx) Decode 1D partial block of size *nx* to strided array with stride *sx*. .. _ll-2d-decoder: 2D Data ^^^^^^^ .. c:function:: size_t zfp_decode_block_int32_2(zfp_stream* stream, int32* block) .. c:function:: size_t zfp_decode_block_int64_2(zfp_stream* stream, int64* block) .. c:function:: size_t zfp_decode_block_float_2(zfp_stream* stream, float* block) .. c:function:: size_t zfp_decode_block_double_2(zfp_stream* stream, double* block) Decode 2D contiguous block of |4by4| values. ---- .. c:function:: size_t zfp_decode_block_strided_int32_2(zfp_stream* stream, int32* p, ptrdiff_t sx, ptrdiff_t sy) .. c:function:: size_t zfp_decode_block_strided_int64_2(zfp_stream* stream, int64* p, ptrdiff_t sx, ptrdiff_t sy) .. c:function:: size_t zfp_decode_block_strided_float_2(zfp_stream* stream, float* p, ptrdiff_t sx, ptrdiff_t sy) .. c:function:: size_t zfp_decode_block_strided_double_2(zfp_stream* stream, double* p, ptrdiff_t sx, ptrdiff_t sy) Decode 2D complete block to strided array with strides *sx* and *sy*. ---- .. c:function:: size_t zfp_decode_partial_block_strided_int32_2(zfp_stream* stream, int32* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) .. c:function:: size_t zfp_decode_partial_block_strided_int64_2(zfp_stream* stream, int64* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) .. c:function:: size_t zfp_decode_partial_block_strided_float_2(zfp_stream* stream, float* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) .. c:function:: size_t zfp_decode_partial_block_strided_double_2(zfp_stream* stream, double* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) Decode 2D partial block of size *nx* |times| *ny* to strided array with strides *sx* and *sy*. .. _ll-3d-decoder: 3D Data ^^^^^^^ .. c:function:: size_t zfp_decode_block_int32_3(zfp_stream* stream, int32* block) .. c:function:: size_t zfp_decode_block_int64_3(zfp_stream* stream, int64* block) .. c:function:: size_t zfp_decode_block_float_3(zfp_stream* stream, float* block) .. c:function:: size_t zfp_decode_block_double_3(zfp_stream* stream, double* block) Decode 3D contiguous block of |4by4by4| values. ---- .. c:function:: size_t zfp_decode_block_strided_int32_3(zfp_stream* stream, int32* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. c:function:: size_t zfp_decode_block_strided_int64_3(zfp_stream* stream, int64* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. c:function:: size_t zfp_decode_block_strided_float_3(zfp_stream* stream, float* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. c:function:: size_t zfp_decode_block_strided_double_3(zfp_stream* stream, double* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) Decode 3D complete block to strided array with strides *sx*, *sy*, and *sz*. ---- .. c:function:: size_t zfp_decode_partial_block_strided_int32_3(zfp_stream* stream, int32* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. c:function:: size_t zfp_decode_partial_block_strided_int64_3(zfp_stream* stream, int64* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. c:function:: size_t zfp_decode_partial_block_strided_float_3(zfp_stream* stream, float* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. c:function:: size_t zfp_decode_partial_block_strided_double_3(zfp_stream* stream, double* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) Decode 3D partial block of size *nx* |times| *ny* |times| *nz* to strided array with strides *sx*, *sy*, and *sz*. .. _ll-4d-decoder: 4D Data ^^^^^^^ .. c:function:: size_t zfp_decode_block_int32_4(zfp_stream* stream, int32* block) .. c:function:: size_t zfp_decode_block_int64_4(zfp_stream* stream, int64* block) .. c:function:: size_t zfp_decode_block_float_4(zfp_stream* stream, float* block) .. c:function:: size_t zfp_decode_block_double_4(zfp_stream* stream, double* block) Decode 4D contiguous block of |4by4by4by4| values. ---- .. c:function:: size_t zfp_decode_block_strided_int32_4(zfp_stream* stream, int32* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) .. c:function:: size_t zfp_decode_block_strided_int64_4(zfp_stream* stream, int64* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) .. c:function:: size_t zfp_decode_block_strided_float_4(zfp_stream* stream, float* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) .. c:function:: size_t zfp_decode_block_strided_double_4(zfp_stream* stream, double* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) Decode 4D complete block to strided array with strides *sx*, *sy*, *sz*, and *sw*. ---- .. c:function:: size_t zfp_decode_partial_block_strided_int32_4(zfp_stream* stream, int32* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) .. c:function:: size_t zfp_decode_partial_block_strided_int64_4(zfp_stream* stream, int64* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) .. c:function:: size_t zfp_decode_partial_block_strided_float_4(zfp_stream* stream, float* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) .. c:function:: size_t zfp_decode_partial_block_strided_double_4(zfp_stream* stream, double* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) Decode 4D partial block of size *nx* |times| *ny* |times| *nz* |times| *nw* to strided array with strides *sx*, *sy*, *sz*, and *sw*. .. _ll-utilities: Utility Functions ----------------- These functions convert 8- and 16-bit signed and unsigned integer data to (by promoting) and from (by demoting) 32-bit integers that can be (de)compressed by |zfp|'s :code:`int32` functions. These conversion functions are preferred over simple casting since they eliminate the redundant leading zeros that would otherwise have to be compressed, and they apply the appropriate bias for unsigned integer data. ---- .. c:function:: void zfp_promote_int8_to_int32(int32* oblock, const int8* iblock, uint dims) .. c:function:: void zfp_promote_uint8_to_int32(int32* oblock, const uint8* iblock, uint dims) .. c:function:: void zfp_promote_int16_to_int32(int32* oblock, const int16* iblock, uint dims) .. c:function:: void zfp_promote_uint16_to_int32(int32* oblock, const uint16* iblock, uint dims) Convert *dims*-dimensional contiguous block to 32-bit integer type. Use *dims* = 0 to promote a single value. ---- .. c:function:: void zfp_demote_int32_to_int8(int8* oblock, const int32* iblock, uint dims) .. c:function:: void zfp_demote_int32_to_uint8(uint8* oblock, const int32* iblock, uint dims) .. c:function:: void zfp_demote_int32_to_int16(int16* oblock, const int32* iblock, uint dims) .. c:function:: void zfp_demote_int32_to_uint16(uint16* oblock, const int32* iblock, uint dims) Convert *dims*-dimensional contiguous block from 32-bit integer type. Use *dims* = 0 to demote a single value. .. _ll-cpp-wrappers: C++ Wrappers ------------ .. cpp:namespace:: zfp To facilitate calling the low-level API from C++, a number of wrappers are available (as of |zfp| |cpprelease|) that are templated on scalar type and dimensionality. Each function of the form :code:`zfp_function_type_dims`, where *type* denotes scalar type and *dims* denotes dimensionality, has a corresponding C++ wrapper :code:`zfp::function`. For example, the C function :c:func:`zfp_encode_block_float_2` has a C++ wrapper :cpp:func:`zfp::encode_block\`. Often *dims* can be inferred from the parameters of overloaded functions, in which case it is omitted as template parameter. The C++ wrappers are defined in :file:`zfp.hpp`. Encoder ^^^^^^^ .. cpp:function:: template size_t encode_block(zfp_stream* stream, const Scalar* block) Encode contiguous block of dimensionality *dims*. ---- .. cpp:function:: template size_t encode_block_strided(zfp_stream* stream, const Scalar* p, ptrdiff_t sx) .. cpp:function:: template size_t encode_block_strided(zfp_stream* stream, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy) .. cpp:function:: template size_t encode_block_strided(zfp_stream* stream, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. cpp:function:: template size_t encode_block_strided(zfp_stream* stream, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) Encode complete block from strided array with strides *sx*, *sy*, *sz*, and *sw*. ---- .. cpp:function:: template size_t encode_partial_block_strided(zfp_stream* stream, const Scalar* p, size_t nx, ptrdiff_t sx) .. cpp:function:: template size_t encode_partial_block_strided(zfp_stream* stream, const Scalar* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) .. cpp:function:: template size_t encode_partial_block_strided(zfp_stream* stream, const Scalar* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. cpp:function:: template size_t encode_partial_block_strided(zfp_stream* stream, const Scalar* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) Encode partial block of size *nx* |times| *ny* |times| *nz* |times| *nw* from strided array with strides *sx*, *sy*, *sz*, and *sw*. Decoder ^^^^^^^ .. cpp:function:: template size_t decode_block(zfp_stream* stream, Scalar* block) Decode contiguous block of dimensionality *dims*. ---- .. cpp:function:: template size_t decode_block_strided(zfp_stream* stream, Scalar* p, ptrdiff_t sx) .. cpp:function:: template size_t decode_block_strided(zfp_stream* stream, Scalar* p, ptrdiff_t sx, ptrdiff_t sy) .. cpp:function:: template size_t decode_block_strided(zfp_stream* stream, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. cpp:function:: template size_t decode_block_strided(zfp_stream* stream, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) Decode complete block to strided array with strides *sx*, *sy*, *sz*, and *sw*. ---- .. cpp:function:: template size_t decode_partial_block_strided(zfp_stream* stream, Scalar* p, size_t nx, ptrdiff_t sx) .. cpp:function:: template size_t decode_partial_block_strided(zfp_stream* stream, Scalar* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) .. cpp:function:: template size_t decode_partial_block_strided(zfp_stream* stream, Scalar* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) .. cpp:function:: template size_t decode_partial_block_strided(zfp_stream* stream, Scalar* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) Decode partial block of size *nx* |times| *ny* |times| *nz* |times| *nw* to strided array with strides *sx*, *sy*, *sz*, and *sw*. zfp-1.0.1/docs/source/modes.rst000066400000000000000000000257411453723256400164250ustar00rootroot00000000000000.. include:: defs.rst .. index:: single: Compression mode .. _modes: Compression Modes ================= |zfp| accepts one or more parameters for specifying how the data is to be compressed to meet various constraints on accuracy or size. At a high level, there are five different compression modes that are mutually exclusive: :ref:`expert `, :ref:`fixed-rate `, :ref:`fixed-precision `, :ref:`fixed-accuracy `, and :ref:`reversible ` mode. The user has to select one of these modes and its corresponding parameters. In streaming I/O applications, the :ref:`fixed-accuracy mode ` is preferred, as it provides the highest quality (in the absolute error sense) per bit of compressed storage. The :c:type:`zfp_stream` struct encapsulates the compression parameters and other information about the compressed stream. Its members should not be manipulated directly. Instead, use the access functions (see the :ref:`C API ` section) for setting and querying them. One can verify the active compression mode on a :c:type:`zfp_stream` through :c:func:`zfp_stream_compression_mode`. The members that govern the compression parameters are described below. .. _mode-expert: .. index:: single: Compression mode; Expert mode Expert Mode ----------- The most general mode is the 'expert mode,' which takes four integer parameters. Although most users will not directly select this mode, we discuss it first since the other modes can be expressed in terms of setting expert mode parameters. The four parameters denote constraints that are applied to each block in the :ref:`compression algorithm `. Compression is terminated as soon as one of these constraints is not met, which has the effect of truncating the compressed bit stream that encodes the block. The four constraints are as follows: .. c:member:: uint zfp_stream.minbits The minimum number of compressed bits used to represent a block. Usually this parameter equals one bit, unless each and every block is to be stored using a fixed number of bits to facilitate random access, in which case it should be set to the same value as :c:member:`zfp_stream.maxbits`. .. c:member:: uint zfp_stream.maxbits The maximum number of bits used to represent a block. This parameter sets a hard upper bound on compressed block size and governs the rate in :ref:`fixed-rate mode `. It may also be used as an upper storage limit to guard against buffer overruns in combination with the accuracy constraints given by :c:member:`zfp_stream.maxprec` and :c:member:`zfp_stream.minexp`. .. c:member:: uint zfp_stream.maxprec The maximum number of bit planes encoded. This parameter governs the number of most significant uncompressed bits encoded per transform coefficient. It does not directly correspond to the number of uncompressed mantissa bits for the floating-point or integer values being compressed, but is closely :ref:`related `. This is the parameter that specifies the precision in :ref:`fixed-precision mode `, and it provides a mechanism for controlling the *relative error*. Note that this parameter selects how many bits planes to encode regardless of the magnitude of the common floating-point exponent within the block. .. c:member:: int zfp_stream.minexp The smallest absolute bit plane number encoded (applies to floating-point data only; this parameter is ignored for integer data). The place value of each transform coefficient bit depends on the common floating-point exponent, *e*, that scales the integer coefficients. If the most significant coefficient bit has place value 2\ :sup:`e`, then the number of bit planes encoded is (one plus) the difference between *e* and :c:member:`zfp_stream.minexp`. As an analogy, consider representing currency in decimal. Setting :c:member:`zfp_stream.minexp` to -2 would, if generalized to base 10, ensure that amounts are represented to cent accuracy, i.e., in units of 10\ :sup:`-2` = $0.01. This parameter governs the *absolute error* in :ref:`fixed-accuracy mode `. Note that to achieve a certain accuracy in the decompressed values, the :c:member:`zfp_stream.minexp` value has to be conservatively lowered since |zfp|'s inverse transform may magnify the error (see also FAQs :ref:`#20-22 `). Care must be taken to allow all constraints to be met, as encoding terminates as soon as a single constraint is violated (except :c:member:`zfp_stream.minbits`, which is satisfied at the end of encoding by padding zeros). .. warning:: For floating-point data, the :c:member:`zfp_stream.maxbits` parameter must be large enough to allow the common block exponent and any control bits to be encoded. This implies *maxbits* |geq| 9 for single-precision data and *maxbits* |geq| 12 for double-precision data. Choosing a smaller value is of no use as it would prevent any fraction (value) bits from being encoded, resulting in an all-zero decompressed block. More importantly, such a constraint will not be respected by |zfp| for performance reasons, which if not accounted for could potentially lead to buffer overruns. As mentioned above, other combinations of constraints can be used. For example, to ensure that the compressed stream is not larger than the uncompressed one, or that it fits within the amount of memory allocated, one may in conjunction with other constraints set :: maxbits = 4^d * CHAR_BIT * sizeof(Type) where Type is either float or double. The ``minbits`` parameter is useful only in fixed-rate mode; when ``minbits`` = ``maxbits``, zero-bits are padded to blocks that compress to fewer than ``maxbits`` bits. The effects of the above four parameters are best explained in terms of the three main compression modes supported by |zfp|, described below. .. _mode-fixed-rate: .. index:: single: Compression mode; Fixed-rate mode single: Rate Fixed-Rate Mode --------------- In fixed-rate mode, each *d*-dimensional compressed block of |4powd| values is stored using a fixed number of bits given by the parameter :c:member:`zfp_stream.maxbits`. This number of compressed bits per *block* is amortized over the |4powd| values to give a *rate* in bits per *value*:: rate = maxbits / 4^d This rate is specified in the :ref:`zfp executable ` via the :option:`-r` option, and programmatically via :c:func:`zfp_stream_set_rate`, as a floating-point value. Fixed-rate mode can also be achieved via the expert mode interface by setting :: minbits = maxbits = (1 << (2 * d)) * rate maxprec = ZFP_MAX_PREC minexp = ZFP_MIN_EXP Note that each block stores a bit to indicate whether the block is empty, plus a common exponent. Hence :c:member:`zfp_stream.maxbits` must be at least 9 for single precision and 12 for double precision. Fixed-rate mode is needed to support random access to blocks, and also is the mode used in the implementation of |zfp|'s :ref:`compressed arrays `. Fixed-rate mode also ensures a predictable memory/storage footprint, but usually results in far worse accuracy per bit than the variable-rate fixed-precision and fixed-accuracy modes. .. note:: Use fixed-rate mode only if you have to bound the compressed size or need read and write random access to blocks. .. _mode-fixed-precision: .. index:: single: Compression mode; Fixed-precision mode Fixed-Precision Mode -------------------- In fixed-precision mode, the number of bits used to encode a block may vary, but the number of bit planes (i.e., the precision) encoded for the transform coefficients is fixed. To achieve the desired precision, use option :option:`-p` with the :ref:`zfp executable ` or call :c:func:`zfp_stream_set_precision`. In expert mode, fixed precision is achieved by specifying the precision in :c:member:`zfp_stream.maxprec` and fully relaxing the size constraints, i.e., :: minbits = ZFP_MIN_BITS maxbits = ZFP_MAX_BITS maxprec = precision minexp = ZFP_MIN_EXP Fixed-precision mode is preferable when relative rather than absolute errors matter. .. _mode-fixed-accuracy: .. index:: single: Compression mode; Fixed-accuracy mode Fixed-Accuracy Mode ------------------- In fixed-accuracy mode, all transform coefficient bit planes up to a minimum bit plane number are encoded. (The actual minimum bit plane is not necessarily :c:member:`zfp_stream.minexp`, but depends on the dimensionality, *d*, of the data. The reason for this is that the inverse transform incurs range expansion, and the amount of expansion depends on the number of dimensions.) Thus, :c:member:`zfp_stream.minexp` should be interpreted as the base-2 logarithm of an absolute error tolerance. In other words, given an uncompressed value, *f*, and a reconstructed value, *g*, the absolute difference \| *f* |minus| *g* \| is at most 2\ :sup:`minexp`. (Note that it is not possible to guarantee error tolerances smaller than machine epsilon relative to the largest value within a block.) This error tolerance is not always tight (especially for 3D and 4D arrays), but can conservatively be set so that even for worst-case inputs the error tolerance is respected. To achieve fixed accuracy to within 'tolerance', use option :option:`-a` with the :ref:`zfp executable ` or call :c:func:`zfp_stream_set_accuracy`. The corresponding expert mode parameters are:: minbits = ZFP_MIN_BITS maxbits = ZFP_MAX_BITS maxprec = ZFP_MAX_PREC minexp = floor(log2(tolerance)) As in fixed-precision mode, the number of bits used per block is not fixed but is dictated by the data. Use *tolerance* = 0 to achieve near-lossless compression (see :ref:`mode-reversible` for guaranteed lossless compression). Fixed-accuracy mode gives the highest quality (in terms of absolute error) for a given compression rate, and is preferable when random access is not needed. .. note:: Fixed-accuracy mode is available for floating-point (not integer) data only. .. index:: single: Compression mode; Reversible mode single: Lossless compression .. _mode-reversible: Reversible Mode --------------- As of |zfp| |revrelease|, reversible (lossless) compression is supported. As with the other compression modes, each block is compressed and decompressed independently, but reversible mode uses a different compression algorithm that ensures a bit-for-bit identical reconstruction of integer and floating-point data. For IEEE-754 floating-point data, reversible mode preserves special values such as subnormals, infinities, NaNs, and positive and negative zero. The expert mode parameters corresponding to reversible mode are:: minbits = ZFP_MIN_BITS maxbits = ZFP_MAX_BITS maxprec = ZFP_MAX_PREC minexp < ZFP_MIN_EXP Reversible mode is enabled via :c:func:`zfp_stream_set_reversible` and through the :option:`-R` command-line option in the :ref:`zfp executable `. It is supported by both the low- and high-level interfaces and by the serial and OpenMP execution policies, but it is not yet implemented in CUDA. zfp-1.0.1/docs/source/pointers.inc000066400000000000000000000152441453723256400171170ustar00rootroot00000000000000.. index:: single: Pointers .. _pointers: Pointers -------- .. cpp:namespace:: zfp .. cpp:class:: array1::const_pointer .. cpp:class:: array2::const_pointer .. cpp:class:: array3::const_pointer .. cpp:class:: array4::const_pointer .. cpp:class:: array1::pointer : public array1::const_pointer .. cpp:class:: array2::pointer : public array2::const_pointer .. cpp:class:: array3::pointer : public array3::const_pointer .. cpp:class:: array4::pointer : public array4::const_pointer Similar to :ref:`references `, |zfp| supports proxy pointers (also known as fancy pointers) to individual array elements. From the user's perspective, such pointers behave much like regular pointers to uncompressed data, e.g., instead of :: float a[ny][nx]; // uncompressed 2D array of floats float* p = &a[0][0]; // point to first array element p[nx] = 1; // set a[1][0] = 1 *++p = 2; // set a[0][1] = 2 one would write :: zfp::array2 a(nx, ny, rate); // compressed 2D array of floats zfp::array2::pointer p = &a(0, 0); // point to first array element p[nx] = 1; // set a(0, 1) = 1 *++p = 2; // set a(1, 0) = 2 However, even though |zfp|'s proxy pointers point to individual scalars, they are associated with the array that those scalars are stored in, including the array's dimensionality. Pointers into arrays of different dimensionality have incompatible type. Moreover, pointers to elements in different arrays are incompatible. For example, one cannot take the difference between pointers into two different arrays. Unlike |zfp|'s proxy references, its proxy pointers support traversing arrays using conventional pointer arithmetic. In particular, unlike the :ref:`iterators ` below, |zfp|'s pointers are oblivious to the fact that the compressed arrays are partitioned into blocks, and the pointers traverse arrays element by element as though the arrays were flattened to one-dimensional arrays. That is, if :code:`p` points to the first element of a 3D array :code:`a(nx, ny, nz)`, then :code:`a(i, j, k) == p[i + nx * (j + ny * k)]`. In other words, pointer indexing follows the same order as flat array indexing (see :cpp:func:`array::operator[]`). A pointer remains valid during the lifetime of the array into which it points. Like conventional pointers, proxy pointers can be passed to other functions and manipulated there, for instance, by passing the pointer by reference via :code:`pointer&`. As of |zfp| |crpirelease|, const qualified pointers :code:`const_pointer` are available, and conceptually are equivalent to :code:`const Scalar*`. Pointers are available for :ref:`read-only arrays ` also. The following operators are defined for proxy pointers. Below *p* refers to the pointer being acted upon. .. cpp:namespace:: zfp::arrayANY .. cpp:function:: pointer pointer::operator=(const pointer& q) .. cpp:function:: const_pointer const_pointer::operator=(const const_pointer& q) Assignment operator. Assigns *q* to *p*. ---- .. cpp:function:: reference pointer::operator*() const .. cpp:function:: const_reference const_pointer::operator*() const Dereference operator. Return proxy (const) reference to the value pointed to by *p*. ---- .. cpp:function:: reference pointer::operator[](ptrdiff_t d) const .. cpp:function:: const_reference const_pointer::operator[](ptrdiff_t d) const Offset dereference operator. Return proxy (const) reference to the value stored at :code:`p[d]`. ---- .. cpp:function:: pointer pointer::operator+(ptrdiff_t d) const .. cpp:function:: const_pointer const_pointer::operator+(ptrdiff_t d) const Return a copy of the pointer incremented by *d*. ---- .. cpp:function:: pointer pointer::operator-(ptrdiff_t d) const .. cpp:function:: const_pointer const_pointer::operator-(ptrdiff_t d) const Return a copy of the pointer decremented by *d*. ---- .. cpp:function:: ptrdiff_t pointer::operator-(const pointer& q) const .. cpp:function:: ptrdiff_t const_pointer::operator-(const const_pointer& q) const Return difference *p - q*. Defined only for pointers within the same array. ---- .. cpp:function:: bool pointer::operator==(const pointer& q) const .. cpp:function:: bool const_pointer::operator==(const const_pointer& q) const Return true if *p* and *q* point to the same array element. ---- .. cpp:function:: bool pointer::operator!=(const pointer& q) const .. cpp:function:: bool const_pointer::operator!=(const const_pointer& q) const Return true if *p* and *q* do not point to the same array element. This operator returns false if *p* and *q* do not point into the same array. ---- .. _ptr_inequalities: .. cpp:function:: bool pointer::operator<=(const pointer& q) const .. cpp:function:: bool pointer::operator>=(const pointer& q) const .. cpp:function:: bool pointer::operator<(const pointer& q) const .. cpp:function:: bool pointer::operator>(const pointer& q) const .. cpp:function:: bool const_pointer::operator<=(const const_pointer& q) const .. cpp:function:: bool const_pointer::operator>=(const const_pointer& q) const .. cpp:function:: bool const_pointer::operator<(const const_pointer& q) const .. cpp:function:: bool const_pointer::operator>(const const_pointer& q) const Return true if the two pointers satisfy the given relationship. These operators return false if *p* and *q* do not point into the same array. ---- .. cpp:function:: pointer& pointer::operator++() .. cpp:function:: const_pointer& const_pointer::operator++() Prefix increment pointer, i.e., :code:`++p`. Return reference to the incremented pointer. ---- .. cpp:function:: pointer& pointer::operator--() .. cpp:function:: const_pointer& const_pointer::operator--() Prefix decrement pointer, i.e., :code:`--p`. Return reference to the decremented pointer. ---- .. cpp:function:: pointer pointer::operator++(int) .. cpp:function:: const_pointer const_pointer::operator++(int) Postfix increment pointer, i.e., :code:`p++`. Return a copy of the pointer before it was incremented. ---- .. cpp:function:: pointer pointer::operator--(int) .. cpp:function:: const_pointer const_pointer::operator--(int) Postfix decrement pointer, i.e., :code:`p--`. Return a copy of the pointer before it was decremented. ---- .. cpp:function:: pointer pointer::operator+=(ptrdiff_t d) .. cpp:function:: const_pointer const_pointer::operator+=(ptrdiff_t d) Increment pointer by *d*. Return a copy of the incremented pointer. ---- .. cpp:function:: pointer pointer::operator-=(ptrdiff_t d) .. cpp:function:: const_pointer const_pointer::operator-=(ptrdiff_t d) Decrement pointer by *d*. Return a copy of the decremented pointer. zfp-1.0.1/docs/source/python.rst000066400000000000000000000162631453723256400166360ustar00rootroot00000000000000.. include:: defs.rst .. py:module:: zfpy .. _zfpy: Python Bindings =============== |zfp| |zfpyrelease| adds |zfpy|: Python bindings that allow compressing and decompressing `NumPy `_ integer and floating-point arrays. The |zfpy| implementation is based on `Cython `_ and requires both NumPy and Cython to be installed. Currently, |zfpy| supports only serial execution. The |zfpy| API is limited to two functions, for compression and decompression, which are described below. Compression ----------- .. py:function:: compress_numpy(arr, tolerance = -1, rate = -1, precision = -1, write_header = True) Compress NumPy array, *arr*, and return a compressed byte stream. The non-expert :ref:`compression mode ` is selected by setting one of *tolerance*, *rate*, or *precision*. If none of these arguments is specified, then :ref:`reversible mode ` is used. By default, a header that encodes array shape and scalar type as well as compression parameters is prepended, which can be omitted by setting *write_header* to *False*. If this function fails for any reason, an exception is thrown. |zfpy| compression currently requires a NumPy array (`ndarray `_) populated with the data to be compressed. The array metadata (i.e., shape, strides, and scalar type) are used to automatically populate the :c:type:`zfp_field` structure passed to :c:func:`zfp_compress`. By default, all that is required to be passed to the compression function is the NumPy array; this will result in a stream that includes a header and is losslessly compressed using the :ref:`reversible mode `. For example:: import zfpy import numpy as np my_array = np.arange(1, 20) compressed_data = zfpy.compress_numpy(my_array) decompressed_array = zfpy.decompress_numpy(compressed_data) # confirm lossless compression/decompression np.testing.assert_array_equal(my_array, decompressed_array) Using the fixed-accuracy, fixed-rate, or fixed-precision modes simply requires setting one of the *tolerance*, *rate*, or *precision* arguments, respectively. For example:: compressed_data = zfpy.compress_numpy(my_array, tolerance=1e-3) decompressed_array = zfpy.decompress_numpy(compressed_data) # Note the change from "equal" to "allclose" due to the lossy compression np.testing.assert_allclose(my_array, decompressed_array, atol=1e-3) Since NumPy arrays are C-ordered by default (i.e., the rightmost index varies fastest) and :c:func:`zfp_compress` assumes Fortran ordering (i.e., the leftmost index varies fastest), :py:func:`compress_numpy` automatically reverses the order of dimensions and strides in order to improve the expected memory access pattern during compression. The :py:func:`decompress_numpy` function also reverses the order of dimensions and strides, and therefore decompression will restore the shape of the original array. Note, however, that the |zfp| stream does not encode the memory layout of the original NumPy array, and therefore layout information like strides, contiguity, and C vs. Fortran order may not be preserved. Nevertheless, |zfpy| correctly compresses NumPy arrays with any memory layout, including Fortran ordering and non-contiguous storage. Byte streams produced by :py:func:`compress_numpy` can be decompressed by the :ref:`zfp command-line tool `. In general, they cannot be :ref:`deserialized ` as compressed arrays, however. .. note:: :py:func:`decompress_numpy` requires a header to decompress properly, so do not set *write_header* = *False* during compression if you intend to decompress the stream with |zfpy|. Decompression ------------- .. py:function:: decompress_numpy(compressed_data) Decompress a byte stream, *compressed_data*, produced by :py:func:`compress_numpy` (with header enabled) and return the decompressed NumPy array. This function throws on exception upon error. :py:func:`decompress_numpy` consumes a compressed stream that includes a header and produces a NumPy array with metadata populated based on the contents of the header. Stride information is not stored in the |zfp| header, so :py:func:`decompress_numpy` assumes that the array was compressed with the first (leftmost) dimension varying fastest (typically referred to as Fortran-ordering). The returned NumPy array is in C-ordering (the default for NumPy arrays), so the shape of the returned array is reversed from the shape information stored in the embedded header. For example, if the header declares the array to be of shape (*nx*, *ny*, *nz*) = (2, 4, 8), then the returned NumPy array will have a shape of (8, 4, 2). Since the :py:func:`compress_numpy` function also reverses the order of dimensions, arrays both compressed and decompressed with |zfpy| will have compatible shape. .. note:: Decompressing a stream without a header requires using the internal :py:func:`_decompress` Python function (or the :ref:`C API `). .. py:function:: _decompress(compressed_data, ztype, shape, out = None, tolerance = -1, rate = -1, precision = -1) Decompress a headerless compressed stream (if a header is present in the stream, it will be incorrectly interpreted as compressed data). *ztype* specifies the array scalar type while *shape* specifies the array dimensions; both must be known by the caller. The compression mode is selected by specifying one (or none) of *tolerance*, *rate*, and *precision*, as in :py:func:`compress_numpy`, and also must be known by the caller. If *out = None*, a new NumPy array is allocated. Otherwise, *out* specifies the NumPy array or memory buffer to decompress into. Regardless, the decompressed NumPy array is returned unless an error occurs, in which case an exception is thrown. In :py:func:`_decompress`, *ztype* is one of the |zfp| supported scalar types (see :c:type:`zfp_type`), which are available in |zfpy| as :: type_int32 = zfp_type_int32 type_int64 = zfp_type_int64 type_float = zfp_type_float type_double = zfp_type_double These can be manually specified (e.g., :code:`zfpy.type_int32`) or generated from a NumPy *dtype* (e.g., :code:`zfpy.dtype_to_ztype(array.dtype)`). If *out* is specified, the data is decompressed into the *out* buffer. *out* can be a NumPy array or a pointer to memory large enough to hold the decompressed data. Regardless of the type of *out* and whether it is provided, :py:func:`_decompress` always returns a NumPy array. If *out* is not provided, then the array is allocated for the user. If *out* is provided, then the returned NumPy array is just a pointer to or wrapper around the user-supplied *out*. If *out* is a NumPy array, then its shape and scalar type must match the required arguments *shape* and *ztype*. To avoid this constraint check, use :code:`out = ndarray.data` rather than :code:`out = ndarray` when calling :py:func:`_decompress`. .. warning:: :py:func:`_decompress` is an "experimental" function currently used internally for testing. It does allow decompression of streams without headers, but providing too small of an output buffer or incorrectly specifying the shape or strides can result in segmentation faults. Use with care. zfp-1.0.1/docs/source/references.inc000066400000000000000000000100471453723256400173710ustar00rootroot00000000000000.. index:: single: References .. _references: References ---------- .. cpp:namespace:: zfp .. cpp:class:: array1::const_reference .. cpp:class:: array2::const_reference .. cpp:class:: array3::const_reference .. cpp:class:: array4::const_reference .. cpp:class:: array1::reference : public array1::const_reference .. cpp:class:: array2::reference : public array2::const_reference .. cpp:class:: array3::reference : public array3::const_reference .. cpp:class:: array4::reference : public array4::const_reference Array :ref:`indexing operators ` must return lvalue references that alias array elements and serve as vehicles for assigning values to those elements. Unfortunately, |zfp| cannot simply return a standard C++ reference (e.g., :code:`float&`) to an uncompressed array element since the element in question may exist only in compressed form or as a transient cached entry that may be invalidated (evicted) at any point. To address this, |zfp| provides *proxies* for references and pointers that act much like regular references and pointers, but which refer to elements by array and index rather than by memory address. When assigning to an array element through such a proxy reference or pointer, the corresponding element is decompressed to cache (if not already cached) and immediately updated. |zfp| references may be freely passed to other functions and they remain valid during the lifetime of the corresponding array element. One may also take the address of a reference, which yields a :ref:`proxy pointer `. When a reference appears as an rvalue in an expression, it is implicitly converted to a value. |zfp| |crpirelease| adds ``const`` qualified versions of references, pointers, and iterators to support const correctness and potential performance improvements when only read access is needed. As with STL containers, the corresponding types are prefixed by ``const_``, e.g., ``const_reference``. The mutable versions of these classes inherit the read-only API from the corresponding const versions. Only references into :ref:`read-write arrays ` are discussed here; the :ref:`read-only arrays ` support the same ``const_reference`` API. .. note:: Do not confuse :code:`const_reference` and :code:`const reference`. The former is a reference to an immutable array element, while the latter means that the proxy reference object itself is immutable. References define a single type: .. cpp:namespace:: zfp::arrayANY .. cpp:type:: reference::value_type .. cpp:type:: const_reference::value_type Scalar type associated with referenced array elements. ---- The following operators are defined for |zfp| references. They act on the referenced array element in the same manner as operators defined for conventional C++ references. References are obtained via :ref:`array inspectors ` and :ref:`mutators `. ---- .. cpp:function:: value_type reference::operator value_type() const .. cpp:function:: value_type const_reference::operator value_type() const Conversion operator for dereferencing the reference. Return the value of the referenced array element. ---- .. cpp:function:: pointer reference::operator&() const .. cpp:function:: const_pointer const_reference::operator&() const Return (const) pointer to the referenced array element. ---- .. _ref_copy: .. cpp:function:: reference reference::operator=(const reference& ref) Assignment (copy) operator. The referenced element, *elem*, is assigned the value stored at the element referenced by *ref*. Return :code:`*this`. ---- .. _ref_mutators: .. cpp:function:: reference reference::operator=(Scalar val) .. cpp:function:: reference reference::operator+=(Scalar val) .. cpp:function:: reference reference::operator-=(Scalar val) .. cpp:function:: reference reference::operator*=(Scalar val) .. cpp:function:: reference reference::operator/=(Scalar val) Assignment and compound assignment operators. For a given operator :code:`op`, update the referenced element, *elem*, via *elem* :code:`op` *val*. Return :code:`*this`. zfp-1.0.1/docs/source/requirements.txt000066400000000000000000000001201453723256400200300ustar00rootroot00000000000000# force older sphinx version for readthedocs build sphinx==1.6.7 sphinx-fortran zfp-1.0.1/docs/source/serialization.inc000066400000000000000000000202611453723256400201240ustar00rootroot00000000000000.. index:: single: Serialization .. _serialization: Serialization ------------- .. cpp:namespace:: zfp |zfp|'s read-write compressed arrays can be serialized to sequential, contiguous storage and later recovered back into an object, e.g., to support I/O of compressed-array objects. Two pieces of information are needed to describe a |zfp| array: the raw compressed data, obtained via :cpp:func:`array::compressed_data` and :cpp:func:`array::compressed_size`, and a :ref:`header
` that describes the array scalar type, dimensions, and rate. The user may concatenate the header and compressed data to form a fixed-rate byte stream that can be read by the |zfp| :ref:`command-line tool `. When serializing the array, the user should first call :cpp:func:`array::flush_cache` before accessing the raw compressed data. There are two primary ways to construct a compressed-array object from compressed data: via array-specific :ref:`constructors ` and via a generic :ref:`factory function `: - When the array scalar type (i.e., :code:`float` or :code:`double`) and dimensionality (i.e., 1D, 2D, 3D, or 4D) are already known, the corresponding array :ref:`constructor ` may be used. If the scalar type and dimensionality stored in the header do not match the array class, then an :ref:`exception ` is thrown. - |zfp| provides a :ref:`factory function ` that can be used when the serialized array type is unknown but described in the header. This function returns a pointer to the abstract base class, :cpp:class:`array`, which the caller should dynamically cast to the corresponding derived array, e.g., by examining :cpp:func:`array::scalar_type` and :cpp:func:`array::dimensionality`. The (static) factory function is made available by including :file:`zfp/factory.hpp`. This header must be included *after* first including the header files associated with the compressed arrays, i.e., :file:`zfp/array1.hpp`, :file:`zfp/array2.hpp`, :file:`zfp/array3.hpp`, and :file:`zfp/array4.hpp`. Only those arrays whose header files are included can be constructed by the factory function. This design decouples the array classes so that they may be included independently, for example, to reduce compilation time. Both types of deserialization functions accept an :cpp:class:`array::header`, an optional buffer holding compressed data, and an optional buffer size. If this buffer is provided, then a separate copy of the compressed data it holds is made, which is used to initialize the array. If the optional buffer size is also provided, then these functions throw an :ref:`exception ` if the size is not at least as large as is expected from the metadata stored in the header. This safeguard is implemented to avoid accessing memory beyond the end of the buffer. If no buffer is provided, then all array elements are default initialized to zero. The array may later be initialized by directly reading/copying data into the space pointed to by :cpp:func:`array::compressed_data` and calling :cpp:func:`array::clear_cache` (in either order). Below is a simple example of serialization of a 3D compressed array of doubles (error checking has been omitted for clarity):: zfp::array3d a(nx, ny, nz, rate); ... a.flush_cache(); zfp::array::header h(a); fwrite(h.data(), h.size_bytes(), 1, file); fwrite(a.compressed_data(), a.compressed_size(), 1, file); We may then deserialize this array using the factory function. The following example reads the compressed data directly into the array without making a copy:: zfp::array::header h; fread(h.data(), h.size_bytes(), 1, file); zfp::array* p = zfp::array::construct(h); fread(p->compressed_data(), p->compressed_size(), 1, file); assert(p->dimensionality() == 3 && p->scalar_type() == zfp_type_double); zfp::array3d& a = *dynamic_cast(p); When the array is no longer in use, call :code:`delete p;` to deallocate it. .. note:: The array serialization API changed significantly in |zfp| |crpirelease|. The :cpp:func:`array::get_header` function is now deprecated and has been replaced with a :ref:`header constructor ` that takes an array as parameter. Exceptions are now part of the main :code:`zfp` namespace rather than nested within the array header. The header is no longer a simple POD data structure but should be queried for its data pointer and size. .. index:: single: Header .. _header: Header ^^^^^^ .. cpp:namespace:: zfp Short 12-byte headers are used to describe array metadata and compression parameters when serializing a compressed array. This header is the same as supported by the :c:func:`zfp_read_header` and :c:func:`zfp_write_header` functions, using :c:macro:`ZFP_HEADER_FULL` to indicate that complete metadata is to be stored in the header. The header is also compatible with the |zfp| :ref:`command-line tool `. Processing of the header may result in an :ref:`exception ` being thrown. .. note:: Compressed-array headers use |zfp|'s most concise representation of only 96 bits. Such short headers support compressed blocks up to 2048 bits long. This implies that the highest rate for 3D arrays is 2048/4\ :sup:`3` = 32 bits/value; the highest rate for 4D arrays is only 2048/4\ :sup:`4` = 8 bits/value. 3D and 4D arrays whose rate exceeds these limits cannot be serialized and result in an exception being thrown. 1D and 2D arrays support rates up to 512 and 128 bits/value, respectively, which both are large enough to represent all usable rates. .. cpp:class:: array::header The header stores information such as scalar type, array dimensions, and compression parameters such as rate. Compressed-array headers are always 96 bits long. .. cpp:namespace:: zfp::array ---- .. cpp:function:: header::header() Default constructor for header. ---- .. _header_ctor: .. cpp:function:: header::header(const array& a) Construct header for compressed-array *a*. Throws an :ref:`exception ` upon failure. ---- .. _header_ctor_buffer: .. cpp:function:: header::header(const void* buffer, size_t bytes = 0) Deserialize header from memory buffer given by *buffer* of optional size *bytes*. This memory buffer is obtained from an existing header during serialization via :cpp:func:`header::data` and :cpp:func:`header::size_bytes`. The constructor throws an :ref:`exception ` upon failure. ---- .. cpp:function:: zfp_type header::scalar_type() const Scalar type associated with array (see :cpp:func:`array::scalar_type`). ---- .. cpp:function:: uint header::dimensionality() const Dimensionality associated with array (see :cpp:func:`array::dimensionality`). ---- .. _header_dims: .. cpp:function:: size_t header::size_x() const .. cpp:function:: size_t header::size_y() const .. cpp:function:: size_t header::size_z() const .. cpp:function:: size_t header::size_w() const :ref:`Array dimensions `. Unused dimensions have a size of zero. ---- .. cpp:function:: double header::rate() const Rate in bits per value (see :cpp:func:`array::rate`); ---- .. cpp:function:: virtual const void* header::data() const = 0 Return pointer to header data. ---- .. cpp:function:: virtual size_t header::size_bytes(uint mask = ZFP_DATA_HEADER) const = 0 When *mask* = :c:macro:`ZFP_DATA_HEADER`, return header payload size in bytes pointed to by :cpp:func:`header::data`. Only those bytes are needed to (de)serialize a header. The header object stores additional (redundant) metadata whose size can be queried via :c:macro:`ZFP_DATA_META`. .. index:: single: Exceptions .. _exception: Exceptions ^^^^^^^^^^ .. cpp:class:: exception : public std::runtime_error Compressed arrays may throw this exception upon serialization, when constructing a header via its :ref:`constructor `, or deserialization, when constructing a compressed array via its :ref:`constructor ` or :ref:`factory function `. The :cpp:func:`exception::what` method returns a :code:`std::string` error message that indicates the cause of the exception. Most error messages changed in |zfp| |4darrrelease|. zfp-1.0.1/docs/source/setup.py000066400000000000000000000000461453723256400162650ustar00rootroot00000000000000from setuptools import setup setup() zfp-1.0.1/docs/source/testing.rst000066400000000000000000000015311453723256400167620ustar00rootroot00000000000000.. include:: defs.rst Regression Tests ================ The :program:`testzfp` program performs basic regression testing by exercising a small but important subset of |libzfp| and the compressed-array classes. It serves as a sanity check that |zfp| has been built properly. These tests assume the default compiler settings, i.e., with none of the settings in :file:`Config` or :file:`CMakeLists.txt` modified. By default, small, synthetic floating-point arrays are used in the test. To test larger arrays, use the :code:`large` command-line option. When large arrays are used, the (de)compression throughput is also measured and reported in number of uncompressed bytes per second. More extensive unit and functional tests are available on the |zfp| GitHub `develop branch `_ in the :file:`tests` directory. zfp-1.0.1/docs/source/tutorial.rst000066400000000000000000000632151453723256400171570ustar00rootroot00000000000000.. include:: defs.rst .. _tutorial: Tutorial ======== This tutorial provides examples that illustrate how to use the |zfp| library and compressed arrays, and includes code snippets that show the order of declarations and function calls needed to use the compressor. This tutorial is divided into three parts: the high-level |libzfp| :ref:`library `; the low-level :ref:`compression codecs `; and the :ref:`compressed array classes ` (in that order). Users interested only in the compressed arrays, which do not directly expose anything related to compression other than compression :ref:`rate control `, may safely skip the next two sections. All code examples below are for 3D arrays of doubles, but it should be clear how to modify the function calls for single precision and for 1D, 2D, or 4D arrays. .. _tut-hl: High-Level C Interface ---------------------- Users concerned only with storing their floating-point data compressed may use |zfp| as a black box that maps a possibly non-contiguous floating-point array to a compressed bit stream. The intent of |libzfp| is to provide both a high- and low-level interface to the compressor that can be called from both C and C++ (and possibly other languages). |libzfp| supports strided access, e.g., for compressing vector fields one scalar at a time, or for compressing arrays of structs. Consider compressing the 3D C/C++ array :: // define an uncompressed array double a[nz][ny][nx]; where *nx*, *ny*, and *nz* can be any positive dimensions. .. include:: disclaimer.inc To invoke the |libzfp| compressor, the dimensions and type must first be specified in a :c:type:`zfp_field` parameter object that encapsulates the type, size, and memory layout of the array:: // allocate metadata for the 3D array a[nz][ny][nx] uint dims = 3; zfp_type type = zfp_type_double; zfp_field* field = zfp_field_3d(&a[0][0][0], type, nx, ny, nz); For single-precision data, use :code:`zfp_type_float`. As of version 0.5.1, the high-level API also supports integer arrays (:code:`zfp_type_int32` and :code:`zfp_type_int64`). See FAQs :ref:`#8 ` and :ref:`#9 ` regarding integer compression. Functions similar to :c:func:`zfp_field_3d` exist for declaring 1D, 2D, and 4D arrays. If the dimensionality of the array is unknown at this point, then a generic :c:func:`zfp_field_alloc` call can be made to just allocate a :c:type:`zfp_field` struct, which can be filled in later using the :ref:`set ` functions. If the array is non-contiguous, then :c:func:`zfp_field_set_stride_3d` should be called. The :c:type:`zfp_field` parameter object holds information about the uncompressed array. To specify the compressed array, a :c:type:`zfp_stream` object must be allocated:: // allocate metadata for a compressed stream zfp_stream* zfp = zfp_stream_open(NULL); We may now specify the rate, precision, or accuracy (see :ref:`modes` for more details on the meaning of these parameters):: // set compression mode and parameters zfp_stream_set_rate(zfp, rate, type, dims, zfp_false); zfp_stream_set_precision(zfp, precision); zfp_stream_set_accuracy(zfp, tolerance); Note that only one of these three functions should be called. The return value from these functions gives the actual rate, precision, or tolerance, and may differ slightly from the argument passed due to constraints imposed by the compressor, e.g., each block must be stored using a whole number of bits at least as large as the number of bits in the floating-point exponent; the precision cannot exceed the number of bits in a floating-point value (i.e., 32 for single and 64 for double precision); and the tolerance must be a (possibly negative) power of two. The compression parameters have now been specified, but before compression can occur a buffer large enough to hold the compressed bit stream must be allocated. Another utility function exists for estimating how many bytes are needed:: // allocate buffer for compressed data size_t bufsize = zfp_stream_maximum_size(zfp, field); void* buffer = malloc(bufsize); Note that :c:func:`zfp_stream_maximum_size` returns the smallest buffer size necessary to safely compress the data---the *actual* compressed size may be smaller. If the members of :code:`zfp` and :code:`field` are for whatever reason not initialized correctly, then :c:func:`zfp_stream_maximum_size` returns 0. Before compression can commence, we must associate the allocated buffer with a bit stream used by the compressor to read and write bits:: // associate bit stream with allocated buffer bitstream* stream = stream_open(buffer, bufsize); zfp_stream_set_bit_stream(zfp, stream); Compression can be accelerated via OpenMP multithreading (since |zfp| |omprelease|) and CUDA (since |zfp| |cudarelease|). To enable OpenMP parallel compression, call:: if (!zfp_stream_set_execution(zfp, zfp_exec_omp)) { // OpenMP not available; handle error } See the section :ref:`execution` for further details on how to configure |zfp| and its run-time parameters for parallel compression. Finally, the array is compressed as follows:: // compress entire array size_t size = zfp_compress(zfp, field); If the stream was rewound before calling :c:func:`zfp_compress`, the return value is the actual number of bytes of compressed storage, and as already mentioned, *size* |leq| *bufsize*. If *size* = 0, then the compressor failed. Since |zfp| 0.5.0, the compressor does not rewind the bit stream before compressing, which allows multiple fields to be compressed one after the other. The return value from :c:func:`zfp_compress` is always the total number of bytes of compressed storage so far relative to the memory location pointed to by *buffer*. To decompress the data, the field and compression parameters must be initialized with the same values as used for compression, either via the same sequence of function calls as above or by recording these fields and setting them directly. Metadata such as array dimensions and compression parameters are by default not stored in the compressed stream. It is up to the caller to store this information, either separate from the compressed data, or via the :c:func:`zfp_write_header` and :c:func:`zfp_read_header` calls, which should precede the corresponding :c:func:`zfp_compress` and :c:func:`zfp_decompress` calls, respectively. These calls allow the user to specify what information to store in the header, including a 'magic' format identifier, the field type and dimensions, and the compression parameters (see the :ref:`ZFP_HEADER ` macros). In addition to this initialization, the bit stream has to be rewound to the beginning (before reading the header and decompressing the data):: // rewind compressed stream and decompress array zfp_stream_rewind(zfp); size_t size = zfp_decompress(zfp, field); The return value is zero if the decompressor failed. Simple Example ^^^^^^^^^^^^^^ Tying it all together, the code example below (see also the :ref:`simple ` program) shows how to compress a 3D array :code:`double array[nz][ny][nx]`:: // input: (void* array, size_t nx, size_t ny, size_t nz, double tolerance) // initialize metadata for the 3D array a[nz][ny][nx] zfp_type type = zfp_type_double; // array scalar type zfp_field* field = zfp_field_3d(array, type, nx, ny, nz); // array metadata // initialize metadata for a compressed stream zfp_stream* zfp = zfp_stream_open(NULL); // compressed stream and parameters zfp_stream_set_accuracy(zfp, tolerance); // set tolerance for fixed-accuracy mode // zfp_stream_set_precision(zfp, precision); // alternative: fixed-precision mode // zfp_stream_set_rate(zfp, rate, type, 3, zfp_false); // alternative: fixed-rate mode // allocate buffer for compressed data size_t bufsize = zfp_stream_maximum_size(zfp, field); // capacity of compressed buffer (conservative) void* buffer = malloc(bufsize); // storage for compressed stream // associate bit stream with allocated buffer bitstream* stream = stream_open(buffer, bufsize); // bit stream to compress to zfp_stream_set_bit_stream(zfp, stream); // associate with compressed stream zfp_stream_rewind(zfp); // rewind stream to beginning // compress array size_t zfpsize = zfp_compress(zfp, field); // return value is byte size of compressed stream .. _tut-ll: Low-Level C Interface --------------------- For applications that wish to compress or decompress portions of an array on demand, a low-level interface is available. Since this API is useful primarily for supporting random access, the user also needs to manipulate the :ref:`bit stream `, e.g., to position the bit pointer to where data is to be read or written. Please be advised that the bit stream functions have been optimized for speed and do not check for buffer overruns or other types of programmer error. Like the high-level API, the low-level API also makes use of the :c:type:`zfp_stream` parameter object (see previous section) to specify compression parameters and storage, but does not encapsulate array metadata in a :c:type:`zfp_field` object. Functions exist for encoding and decoding complete or partial blocks, with or without strided access. In non-strided mode, the uncompressed block to be encoded or decoded is assumed to be stored contiguously. For example, :: // compress a single contiguous block double block[4 * 4 * 4] = { /* some set of values */ }; size_t bits = zfp_encode_block_double_3(zfp, block); The return value is the number of bits of compressed storage for the block. For fixed-rate streams, if random write access is desired, then the stream should also be flushed after each block is encoded:: // flush any buffered bits zfp_stream_flush(zfp); This flushing should be done only after the last block has been compressed in fixed-precision and fixed-accuracy mode, or when random access is not needed in fixed-rate mode. The block above could also have been compressed as follows using strides:: // compress a single contiguous block using strides double block[4][4][4] = { /* some set of values */ }; ptrdiff_t sx = &block[0][0][1] - &block[0][0][0]; // x stride = 1 ptrdiff_t sy = &block[0][1][0] - &block[0][0][0]; // y stride = 4 ptrdiff_t sz = &block[1][0][0] - &block[0][0][0]; // z stride = 16 size_t bits = zfp_encode_block_strided_double_3(zfp, &block[0][0][0], sx, sy, sz); The strides are measured in number of array elements, not in bytes. For partial blocks, e.g., near the boundaries of arrays whose dimensions are not multiples of four, there are corresponding functions that accept parameters *nx*, *ny*, and *nz* to specify the actual block dimensions, with 1 |leq| *nx*, *ny*, *nz* |leq| 4. Corresponding functions exist for decompression. Such partial blocks typically do not compress as well as full blocks and should be avoided if possible. To position a bit stream for reading (decompression), use :: // position the stream at given bit offset for reading stream_rseek(stream, offset); where the offset is measured in number of bits from the beginning of the stream. For writing (compression), a corresponding call exists:: // position the stream at given bit offset for writing stream_wseek(stream, offset); Note that it is possible to decompress fewer bits than are stored with a compressed block to quickly obtain an approximation. This is done by setting :code:`zfp->maxbits` to fewer bits than used during compression. For example, to decompress only the first 256 bits of each block:: // modify decompression parameters to decode 256 bits per block uint maxbits; uint maxprec; int minexp; zfp_stream_params(zfp, NULL, &maxbits, &maxprec, &minexp); assert(maxbits >= 256); zfp_stream_set_params(zfp, 256, 256, maxprec, minexp); This feature may be combined with progressive decompression, as discussed further in FAQ :ref:`#13 `. .. _tut-arrays: Compressed C++ Arrays --------------------- .. cpp:namespace:: zfp The |zfp| compressed-array API has been designed to facilitate integration with existing applications. After initial array declaration, a |zfp| array can often be used in place of a regular C/C++ array or STL vector, e.g., using flat indexing via :code:`a[index]`, nested indexing :code:`a[k][j][i]` (via :ref:`nested views `), or using multidimensional indexing via :code:`a(i)`, :code:`a(i, j)`, :code:`a(i, j, k)`, or :code:`a(i, j, k, l)`. There are, however, some important differences. For instance, applications that rely on addresses or references to array elements may have to be modified to use special proxy classes that implement pointers and references; see :ref:`limitations`. |zfp|'s compressed arrays do not support special floating-point values like infinities and NaNs, although subnormal numbers are handled correctly. Similarly, because the compressor assumes that the array values vary smoothly, using finite but large values like :c:macro:`HUGE_VAL` in place of infinities is not advised, as this will introduce large errors in smaller values within the same block. Future extensions will provide support for a bit mask to mark the presence of non-values. The |zfp| C++ classes are implemented entirely as header files and make extensive use of C++ templates to reduce code redundancy. These classes are wrapped in the :cpp:any:`zfp` namespace. Currently, there are eight array classes for 1D, 2D, 3D, and 4D arrays, each of which can represent single- or double-precision values. Although these arrays store values in a form different from conventional single- and double-precision floating point, the user interacts with the arrays via floats and doubles. The description below is for 3D arrays of doubles---the necessary changes for other array types should be obvious. To declare and zero initialize an array, use :: // declare nx * ny * nz array of compressed doubles zfp::array3 a(nx, ny, nz, rate); This declaration is conceptually equivalent to :: double a[nz][ny][nx] = { 0.0 }; or using STL vectors :: std::vector a(nx * ny * nz, 0.0); but with the user specifying the amount of storage used via the *rate* parameter. (A predefined type :cpp:type:`array3d` also exists, while the suffix 'f' is used for floats.) .. include:: disclaimer.inc Note that the array dimensions can be arbitrary and need not be multiples of four (see above for a discussion of incomplete blocks). The *rate* argument specifies how many bits per value (amortized) to store in the compressed representation. By default, the block size is restricted to a multiple of 64 bits, and therefore the rate argument can be specified in increments of 64 / |4powd| bits in *d* dimensions, i.e. :: 1D arrays: 16-bit granularity 2D arrays: 4-bit granularity 3D arrays: 1-bit granularity 4D arrays: 1/4-bit granularity For finer granularity, the :c:macro:`BIT_STREAM_WORD_TYPE` macro needs to be set to a type narrower than 64 bits during compilation of |libzfp|, e.g., if set to :c:type:`uint8` the rate granularity becomes 8 / |4powd| bits in *d* dimensions, or :: 1D arrays: 2-bit granularity 2D arrays: 1/2-bit granularity 3D arrays: 1/8-bit granularity 4D arrays: 1/32-bit granularity Note that finer granularity usually implies slightly lower performance. Also note that because the arrays are stored compressed, their effective precision is likely to be higher than the user-specified rate. The array can also optionally be initialized from an existing contiguous floating-point array stored at *pointer* with an *x* stride of 1, *y* stride of *nx*, and *z* stride of *nx* |times| *ny*:: // declare and initialize 3D array of doubles zfp::array3d a(nx, ny, nz, rate, pointer, cache_size); The optional *cache_size* argument specifies the minimum number of bytes to allocate for the cache of uncompressed blocks (see :ref:`tut-caching` below for more details). As of |zfp| 0.5.3, entire arrays may be copied via the copy constructor or assignment operator:: zfp::array3d b(a); // declare array b to be a copy of array a zfp::array3d c; // declare empty array c c = a; // copy a to c Copies are deep and have value (not reference) semantics. In the above example, separate storage for *b* and *c* is allocated, and subsequent modifications to *b* and *c* will not modify *a*. If not already initialized, a function :cpp:func:`array::set` can be used to copy uncompressed data to the compressed array:: const double* pointer; // pointer to uncompressed, initialized data a.set(pointer); // initialize compressed array with floating-point data Similarly, an :cpp:func:`array::get` function exists for retrieving uncompressed data:: double* pointer; // pointer to where to write uncompressed data a.get(pointer); // decompress and store the array at pointer The compressed representation of an array can also be queried or initialized directly without having to convert to/from its floating-point representation:: size_t bytes = compressed_size(); // number of bytes of compressed storage void* compressed_data(); // pointer to compressed data The array can through this pointer be initialized from offline compressed storage, but only after its dimensions and rate have been specified (see above). For this to work properly, the cache must first be emptied via an :cpp:func:`array::clear_cache` call (see below). Through operator overloading, the array can be accessed in one of two ways. For read accesses, use :: double value = a[index]; // fetch value with given flat array index double value = a(i, j, k); // fetch value with 3D index (i, j, k) These access the same value if and only if :code:`index = i + nx * (j + ny * k)`. Note that 0 |leq| *i* < *nx*, 0 |leq| *j* < *ny*, and 0 |leq| *k* < *nz*, and *i* varies faster than *j*, which varies faster than *k*. |zfp| |viewsrelease| adds views to arrays, which among other things can be used to perform nested indexing:: zfp::array3d::nested_view v(&a); double value = v[k][j][i]; A view is a shallow copy of an array or a subset of an array. Array values may be written and updated using the usual set of C++ assignment and compound assignment operators. For example:: a[index] = value; // set value at flat array index a(i, j, k) += value; // increment value with 3D index (i, j, k) Whereas one might expect these operators to return a (non-const) reference to an array element, this would allow seating a reference to a value that currently is cached but is transient, which could be unsafe. Moreover, this would preclude detecting when an array element is modified. Therefore, the return type of both operators :code:`[]` and :code:`()` is a proxy reference class, similar to :code:`std::vector::reference` from the STL library. Because read accesses to a mutable object cannot call the const-qualified accessor, a proxy reference may be returned even for read calls. For example, in :: a[i] = a[i + 1]; the array :code:`a` clearly must be mutable to allow assignment to :code:`a[i]`, and therefore the read access :code:`a[i + 1]` returns type :cpp:class:`array::reference`. The value associated with the read access is obtained via an implicit conversion. When the array is const qualified, the operators :code:`[]` and :code:`()` are inspectors that return a proxy :ref:`const reference ` that implicitly converts to a value. If used as arguments in :code:`printf` or other functions that take a variable number of arguments, implicit conversion is not done and the reference has to be explicitly cast to value, e.g., :code:`printf("%f", (double)a[i]);`. Array dimensions *nx*, *ny*, *nz*, and *nw* can be queried using these functions:: size_t size(); // total number of elements nx * ny * nz * nw size_t size_x(); // nx size_t size_y(); // ny size_t size_z(); // nz size_t size_w(); // nw The array dimensions can also be changed dynamically, e.g., if not known at time of construction, using :: void resize(size_t nx, size_t ny, size_t nz, size_t nw, bool clear = true); When *clear* = true, the array is explicitly zeroed. In either case, all previous contents of the array are lost. If *nx* = *ny* = *nz* = 0, all storage is freed. Finally, the rate supported by the array may be queried via :: double rate(); // number of compressed bits per value and changed using :: void set_rate(rate); // change rate This also destroys prior contents. As of |zfp| 0.5.2, iterators and proxy objects for pointers and references are supported. Note that the decompressed value of an array element exists only intermittently, when the decompressed value is cached. It would not be safe to return a :code:`double&` reference or :code:`double*` pointer to the cached but transient value since it may be evicted from the cache at any point, thus invalidating the reference or pointer. Instead, |zfp| provides proxy objects for references and pointers that guarantee persistent access by referencing elements by array object and index. These classes perform decompression on demand, much like how Boolean vector references are implemented in the STL. As of |zfp| |raiterrelease|, all iterators for 1D-4D arrays support random access. Iterators ensure that array values are visited one block at a time, and are the preferred way of looping over array elements. Such block-by-block access is especially useful when performing write accesses since then complete blocks are updated one at a time, thus reducing the likelihood of a partially updated block being evicted from the cache and compressed, perhaps with some values in the block being uninitialized. Here is an example of initializing a 3D array:: for (zfp::array3d::iterator it = a.begin(); it != a.end(); it++) { size_t i = it.i(); size_t j = it.j(); size_t k = it.k(); a(i, j, k) = some_function(i, j, k); } Pointers to array elements are available via a special pointer class. Such pointers may be a useful way of passing (flattened) |zfp| arrays to functions that expect uncompressed arrays, e.g., by using the pointer type as template argument. For example:: template void sum(double_ptr p, size_t count) { double s = 0; for (size_t i = 0; i < count; i++) s += p[i]; return s; } Then the following are equivalent:: // sum of STL vector elements (double_ptr == double*) std::vector vec(nx * ny * nz, 0.0); double vecsum = sum(&vec[0], nx * ny * nz); // sum of zfp array elements (double_ptr == zfp::array3d::pointer) zfp::array3 array(nx, ny, nz, rate); double zfpsum = sum(&array[0], nx * ny * nz); As another example, :: for (zfp::array1d::pointer p = &a[0]; p - &a[0] < a.size(); p++) *p = 0.0; initializes a 1D array to all-zeros. Pointers visit arrays in standard row-major order, i.e. :: &a(i, j, k) == &a[0] + i + nx * (j + ny * k) == &a[i + nx * (j + ny * k)] where :code:`&a(i, j, k)` and :code:`&a[0]` are both of type :cpp:class:`array3d::pointer`. Thus, iterators and pointers do not visit arrays in the same order, except for the special case of 1D arrays. Like iterators, pointers support random access for arrays of all dimensions and behave very much like :code:`float*` and :code:`double*` built-in pointers. Proxy objects for array element references have been supported since the first release of |zfp|, and may for instance be used in place of :code:`double&`. Iterators and pointers are implemented in terms of references. The following table shows the equivalent zfp type to standard types when working with 1D arrays:: double& zfp::array1d::reference double* zfp::array1d::pointer std::vector::iterator zfp::array1d::iterator const double& zfp::array1d::const_reference const double* zfp::array1d::const_pointer std::vector::const_iterator zfp::array1d::const_iterator .. _tut-caching: Caching ^^^^^^^ As mentioned above, the array class maintains a software write-back cache of at least one uncompressed block. When a block in this cache is evicted (e.g., due to a conflict), it is compressed back to permanent storage only if it was modified while stored in the cache. The size cache to use is specified by the user and is an important parameter that needs careful consideration in order to balance the extra memory usage, performance, and accuracy (recall that data loss is incurred only when a block is evicted from the cache and compressed). Although the best choice varies from one application to another, we suggest allocating at least two layers of blocks (2 |times| (*nx* / 4) |times| (*ny* / 4) blocks) for applications that stream through the array and perform stencil computations such as gathering data from neighboring elements. This allows limiting the cache misses to compulsory ones. If the *cache_size* parameter is set to zero bytes, then a default size of |sqrt|\ *n* blocks (rounded up to the next integer power of two) is used, where *n* is the total number of blocks in the array. The cache size can be set during construction, or can be set at a later time via :: void set_cache_size(bytes); // change cache size Note that if *bytes* = 0, then the array dimensions must have already been specified for the default size to be computed correctly. When the cache is resized, it is first flushed if not already empty. The cache can also be flushed explicitly if desired by calling :: void flush_cache(); // empty cache by first compressing any modified blocks To empty the cache without compressing any cached data, call :: void clear_cache(); // empty cache without compression To query the byte size of the cache, use :: size_t cache_size(); // actual cache size in bytes zfp-1.0.1/docs/source/versions.rst000066400000000000000000000374171453723256400171710ustar00rootroot00000000000000.. include:: defs.rst Release Notes ============= 1.0.1 (2023-12-15) ------------------ This patch release primarily addresses minor bug fixes and is needed to update the zfpy Python wheels. **Added** - A new build macro, ``BUILD_TESTING_FULL``, specifies that all unit tests be built; ``BUILD_TESTING`` produces a smaller subset of tests. Full tests and documentation are now included in releases. **Fixed** - #169: `libm` dependency is not always correctly detected. - #171: `ptrdiff_t` is not always imported in Cython. - #176: cfp API is not exposed via CMake configuration file. - #177: Full test suite is not included in release. - #181: `rpath` is not set correctly in executables. - #204: Array strides are not passed by value in zFORp. - #220: Errors reported with scikit-build when building zfpy. ---- 1.0.0 (2022-08-01) ------------------ This release is not ABI compatible with prior releases due to numerous changes to function signatures and data structures like ``zfp_field``. However, few of the API changes, other than to the |cfp| C API for compressed arrays, should impact existing code. Note that numerous header files have been renamed or moved relative to prior versions. **Added** - ``zfp::const_array``: read-only variable-rate array that supports fixed-precision, fixed-accuracy, and reversible modes. - Compressed-array classes for 4D data. - ``const`` versions of array references, pointers, and iterators. - A more complete API for pointers and iterators. - |cfp| support for proxy references and pointers, iterators, and (de)serialization. - Support for pointers and iterators into array views. - ``zfp::array::size_bytes()`` allows querying the size of different components of an array object (e.g., payload, cache, index, metadata, ...). - Templated C++ wrappers around the low-level C API. - A generic codec for storing blocks of uncompressed scalars in |zfp|'s C++ arrays. - Additional functions for querying ``zfp_field`` and ``zfp_stream`` structs. - ``zfp_config``: struct that encapsulates compression mode and parameters. - Rounding modes for reducing bias in compression errors. - New examples: ``array``, ``iteratorC``, and ``ppm``. **Changed** - Headers from ``array/``, ``cfp/include/``, and ``include/`` have been renamed and reorganized into a common ``include/`` directory. * The libzfp API is now confined to ``zfp.h``, ``zfp.hpp``, and ``zfp.mod`` for C, C++, and Fortran bindings, respectively. These all appear in the top-level ``include/`` directory upon installation. * C++ headers now use a ``.hpp`` suffix; C headers use a ``.h`` suffix. * C++ headers like ``array/zfparray.h`` have been renamed ``zfp/array.hpp``. * C headers like ``cfp/include/cfparrays.h`` have been renamed ``zfp/array.h``. - ``size_t`` and ``ptrdiff_t`` replace ``uint`` and ``int`` for array sizes and strides in the array classes and C/Fortran APIs. - ``zfp_bool`` replaces ``int`` as Boolean type in the C API. - ``bitstream_offset`` and ``bitstream_size`` replace ``size_t`` to ensure support for 64-bit offsets into and lengths of bit streams. Consequently, the ``bitstream`` API has changed accordingly. - All array and view iterators are now random-access iterators. - Array inspectors now return ``const_reference`` rather than a scalar type like ``float`` to allow obtaining a ``const_pointer`` to an element of an immutable array. - ``zfp::array::compressed_data()`` now returns ``void*`` instead of ``uchar*``. - The array (de)serialization API has been revised, resulting in new ``zfp::array::header`` and ``zfp::exception`` classes with new exception messages. - The array ``codec`` class is now responsible for all details regarding compression. - The compressed-array C++ implementation has been completely refactored to make it more modular, extensible, and reusable across array types. - Array block shapes are now computed on the fly rather than stored. - The |cfp| C API now wraps array objects in structs. - The |zfpy| Python API now supports the more general ``memoryview`` over ``bytes`` objects for decompression. - The zFORp Fortran module name is now ``zfp`` instead of ``zforp_module``. - Some command-line options for the ``diffusion`` example have changed. - CMake 3.9 or later is now required for CMake builds. **Removed** - ``zfp::array::get_header()`` has been replaced with a ``zfp::array::header`` constructor that accepts an array object. - ``ZFP_VERSION_RELEASE`` is no longer defined (use ``ZFP_VERSION_PATCH``). **Fixed** - #66: ``make install`` overwrites googletest. - #84: Incorrect order of parameters in CUDA ``memset()``. - #86: C++ compiler warns when ``__STDC_VERSION__`` is undefined. - #87: ``CXXFLAGS`` is misspelled in ``cfp/src/Makefile``. - #98: ``zfp_stream_maximum_size()`` underestimates size in reversible mode. - #99: Incorrect ``private_view`` reads due to missing writeback. - #109: Unused CPython array is incompatible with PyPy. - #112: PGI compiler bug causes issues with memory alignment. - #119: All-subnormal blocks may cause floating-point overflow. - #121: CUDA bit offsets are limited to 32 bits. - #122: ``make install`` does not install |zfp| command-line utility. - #125: OpenMP bit offsets are limited to 32 bits. - #126: ``make install`` does not install Fortran module. - #127: Reversible mode reports incorrect compressed block size. - #150: cmocka tests do not build on macOS. - #154: Thread safety is broken in ``private_view`` and ``private_const_view``. - ``ZFP_MAX_BITS`` is off by one. - ``diffusionC``, ``iteratorC`` are not being built with ``gmake``. ---- 0.5.5 (2019-05-05) ------------------ **Added** - Support for reversible (lossless) compression of floating-point and integer data. - Methods for serializing and deserializing |zfp|'s compressed arrays. - Python bindings for compressing NumPy arrays. - Fortran bindings to |zfp|'s high-level C API. **Changed** - The default compressed-array cache size is now a function of the total number of array elements, irrespective of array shape. **Fixed** - Incorrect handling of execution policy in |zfp| utility. - Incorrect handling of decompression via header in |zfp| utility. - Incorrect cleanup of device memory in CUDA decompress. - Missing tests for failing mallocs. - CMake does not install CFP when built. - ``zfp_write_header()`` and ``zfp_field_metadata()`` succeed even if array dimensions are too large to fit in header. ---- 0.5.4 (2018-10-01) ------------------ **Added** - Support for CUDA fixed-rate compression and decompression. - Views into compressed arrays for thread safety, nested array indexing, slicing, and array subsetting. - C language bindings for compressed arrays. - Support for compressing and decompressing 4D data. **Changed** - Execution policy now applies to both compression and decompression. - Compressed array accessors now return Scalar type instead of ``const Scalar&`` to avoid stale references to evicted cache lines. **Fixed** - Incorrect handling of negative strides. - Incorrect handling of arrays with more than 2\ :sup:`32` elements in |zfp| command-line tool. - ``bitstream`` is not C++ compatible. - Minimum cache size request is not respected. ---- 0.5.3 (2018-03-28) ------------------ **Added** - Support for OpenMP multithreaded compression (but not decompression). - Options for OpenMP execution in |zfp| command-line tool. - Compressed-array support for copy construction and assignment via deep copies. - Virtual destructors to enable inheritance from |zfp| arrays. **Changed** - ``zfp_decompress()`` now returns the number of compressed bytes processed so far, i.e., the same value returned by ``zfp_compress()``. ---- 0.5.2 (2017-09-28) ------------------ **Added** - Iterators and proxy objects for pointers and references. - Example illustrating how to use iterators and pointers. **Changed** - Diffusion example now optionally uses iterators. - Moved internal headers under array to ``array/zfp``. - Modified 64-bit integer typedefs to avoid the C89 non-compliant ``long long`` and allow for user-supplied types and literal suffixes. - Renamed compile-time macros that did not have a ``ZFP`` prefix. - Rewrote documentation in reStructuredText and added complete documentation of all public functions, classes, types, and macros. **Fixed** - Issue with setting stream word type via CMake. ---- 0.5.1 (2017-03-28) ------------------ This release primarily fixes a few minor issues but also includes changes in anticipation of a large number of planned future additions to the library. No changes have been made to the compressed format, which is backwards compatible with version 0.5.0. **Added** - High-level API support for integer types. - Example that illustrates in-place compression. - Support for CMake builds. - Documentation that discusses common issues with using |zfp|. **Changed** - Separated library version from CODEC version and added version string. - Corrected inconsistent naming of ``BIT_STREAM`` macros in code and documentation. - Renamed some of the header bit mask macros. - ``stream_skip()`` and ``stream_flush()`` now return the number of bits skipped or output. - Renamed ``stream_block()`` and ``stream_delta()`` to make it clear that they refer to strided streams. Added missing definition of ``stream_stride_block()``. - Changed ``int`` and ``uint`` types in places to use ``ptrdiff_t`` and ``size_t`` where appropriate. - Changed API for ``zfp_set_precision()`` and ``zfp_set_accuracy()`` to not require the scalar type. - Added missing ``static`` keyword in ``decode_block()``. - Changed ``testzfp`` to allow specifying which tests to perform on the command line. - Modified directory structure. **Fixed** - Bug that prevented defining uninitialized arrays. - Incorrect computation of array sizes in ``zfp_field_size()``. - Minor issues that prevented code from compiling on Windows. - Issue with fixed-accuracy headers that caused unnecessary storage. ---- 0.5.0 (2016-02-29) ------------------ This version introduces backwards incompatible changes to the CODEC. **Added** - Modified CODEC to more efficiently encode blocks whose values are all zero or are smaller in magnitude than the absolute error tolerance. This allows representing "empty" blocks using only one bit each. - Added functions for compactly encoding the compression parameters and field meta data, e.g., for producing self-contained compressed streams. Also added functions for reading and writing a header containing these parameters. **Changed** - Changed behavior of ``zfp_compress()`` and ``zfp_decompress()`` to not automatically rewind the bit stream. This makes it easier to concatenate multiple compressed bit streams, e.g., when compressing vector fields or multiple scalars together. - Changed the |zfp| example program interface to allow reading and writing compressed streams, optionally with a header. The |zfp| tool can now be used to compress and decompress files as a stand alone utility. ---- 0.4.1 (2015-12-28) ------------------ **Added** - Added ``simple.c`` as a minimal example of how to call the compressor. **Changed** - Changed compilation of diffusion example to output two executables: one with and one without compression. **Fixed** - Bug that caused segmentation fault when compressing 3D arrays whose dimensions are not multiples of four. Specifically, arrays of dimensions *nx* |times| *ny* |times| *nz*, with *ny* not a multiple of four, were not handled correctly. - Modified ``examples/fields.h`` to ensure standard compliance. Previously, C99 support was needed to handle the hex float constants, which are not supported in C++98. ---- 0.4.0 (2015-12-05) ------------------ This version contains substantial changes to the compression algorithm that improve PSNR by about 6 dB and speed by a factor of 2-3. These changes are not backward compatible with previous versions of |zfp|. **Added** - Support for 31-bit and 63-bit integer data, as well as shorter integer types. - New examples for evaluating the throughput of the (de)compressor and for compressing grayscale images in the pgm format. - Frequently asked questions. **Changed** - Rewrote compression codec entirely in C to make linking and calling easier from other programming languages, and to expose the low-level interface through C instead of C++. This necessitated significant changes to the API as well. - Minor changes to the C++ compressed array API, as well as major implementation changes to support the C library. The namespace and public types are now all in lower case. **Removed** - Support for general fixed-point decorrelating transforms. ---- 0.3.2 (2015-12-03) ------------------ **Fixed** - Bug in ``Array::get()`` that caused the wrong cached block to be looked up, thus occasionally copying incorrect values back to parts of the array. ---- 0.3.1 (2015-05-06) ------------------ **Fixed** - Rare bug caused by exponent underflow in blocks with no normal and some subnormal numbers. ---- 0.3.0 (2015-03-03) ------------------ This version modifies the default decorrelating transform to one that uses only additions and bit shifts. This new transform, in addition to being faster, also has some theoretical optimality properties and tends to improve rate distortion. This change is not backwards compatible. **Added** - Compile-time support for parameterized transforms, e.g., to support other popular transforms like DCT, HCT, and Walsh-Hadamard. - Floating-point traits to reduce the number of template parameters. It is now possible to declare a 3D array as ``Array3``, for example. - Functions for setting the array scalar type and dimensions. - ``testzfp`` for regression testing. **Changed** - Made forward transform range preserving: (-1, 1) is mapped to (-1, 1). Consequently Q1.62 fixed point can be used throughout. - Changed the order in which bits are emitted within each bit plane to be more intelligent. Group tests are now deferred until they are needed, i.e., just before the value bits for the group being tested. This improves the quality of fixed-rate encodings, but has no impact on compressed size. - Made several optimizations to improve performance. - Consolidated several header files. ---- 0.2.1 (2014-12-12) ------------------ **Added** - Win64 support via Microsoft Visual Studio compiler. - Documentation of the expected output for the diffusion example. **Changed** - Made several minor changes to suppress compiler warnings. **Fixed** - Broken support for IBM's ``xlc`` compiler. ---- 0.2.0 (2014-12-02) ------------------ The compression interface from ``zfpcompress`` was relocated to a separate library, called ``libzfp``, and modified to be callable from C. This API now uses a parameter object (``zfp_params``) to specify array type and dimensions as well as compression parameters. **Added** - Several utility functions were added to simplify ``libzfp`` usage: * Functions for setting the rate, precision, and accuracy. Corresponding functions were also added to the ``Codec`` class. * A function for estimating the buffer size needed for compression. - The ``Array`` class functionality was expanded: * Support for accessing the compressed bit stream stored with an array, e.g., for offline compressed storage and for initializing an already compressed array. * Functions for dynamically specifying the cache size. * The default cache is now direct-mapped instead of two-way associative. **Fixed** - Corrected the value of the lowest possible bit plane to account for both the smallest exponent and the number of bits in the significand. - Corrected inconsistent use of rate and precision. The rate refers to the number of compressed bits per floating-point value, while the precision refers to the number of uncompressed bits. The ``Array`` API was changed accordingly. ---- 0.1.0 (2014-11-12) ------------------ Initial beta release. zfp-1.0.1/docs/source/view-indexing.pdf000066400000000000000000003547331453723256400200420ustar00rootroot00000000000000%PDF-1.4 7 0 obj <> stream xÚwT”k×6RÒ Ý Ý0tƒ¤tK× 13C—„„„ H·¤R‚ ‚Ò H()%)Ý”ßx<ñž÷ÿ×ú¾õ¬5ϳ¯Ýû¾ö½Ö°3ëñ+:ÂìÁj0(’_H( PÖ12€@ PÝ‚tÿ…ã±›€á *ýÊp0‰ÂT@H”¡ Ðôv‰„Ä¥…$¤@€0(õ—! . Pù@:MŒÀcW†yúÃ!Î.HTž¿>\Ü!)) ¾?ÜŠ`8Äè€.`TF;Àæ#ýÿ‚KÖ‰ô”ôõõy `pgyn>€/é0#Àp°#àWË]øÏÖðØÆ.Äo…Ì é ‚ƒ(Àâ†"P.ÞPG0€Ê0ÒÐèy‚¡¿µðþ@H@èïpzÿ þá rp€yx‚ þ¨3À âè©i ý|Ôñ—!ÈCùƒ|@w=ÊàÒA5EÕáŸý!àO$BqÿÕ£à¯0¨1«B•a`(÷«>쀚»¿àŸ‡ë…ùBÿ’œ PG§_m8z{ >„B¼¼Á*Ú  ¼0g0 %"°ìçà"ø+±¿'ø¥Ð/ÕCp 'Ìà„j q£^x€„{ƒƒÿSño OHàq@ìÁÎ(Þ?ÑQ0Øé·Œ:8Ä` DÑOüõüýeb˜# êîÿùG,¨¡¡­«¡ÄûgË+•”`~€@~q!¿° %%“ÿ;Œ>ògÿáªu‚¤~W‹Ó_ûüI®?÷ƒðïXº0qÁ®xn: ~„þÏlÿÃåÿGò_QþWžÿwEjÞîîè¹~ü?zÄÝÿO q½‘¨%СVúߦ¦àß›«v„x{ü·V B-ƒ"ÔÙýïABj?°£>éàò›/¿ñ‡¿6ÍëÃ_w €_ü/j½ÜP÷EÊ?T`Ôöü;¥*ÔæøkÍ„ÅÄ 8äDqIXL („ÚGG°ß4 @aH” Õ^0À Çûu¦('Áß-¡à߈@Ð ‚bò߀0 €yÃÿ$‚PTu¢RAØȨ܂°êòøE!(Jÿ- ‘.pðøQˆ/쟘’Á0ü7𯖼ápÔæÿAKÔ<þ’ÿ¸fÀ`?°Þô$ÌA&Òµ.òýE­"/ÿêöÂRkl’yOŒ’ãkA ‹öݬ£^JvŽUÔéúSQ#“At<{Ã~V9aóiêùH4Õž¥þÂþÇÎ`FG­óg‰ôØ•{ûÉ Äv–˜–œ)¦“×%:E֫׊oZëRÛ@é s2A1¯u=Μ™m ùÉÜŠ$‘n™ám¬ñðó z$ñ\é}<ÍÿËÄÌOß¾õåôö¤‹iuÕˆWE‘Ñh2ç <ûHC‘œ£ùÆ¡$v¦\‘"²?Þ…V0ð {t‡ ØÞ ëÄ 7Ý#ãî;3 Úm“ÆÔ=&í¦xZIi˜·¯œ½À-1°£³¼wº9±.íÞ Œh×#g«Qq¹=iГøñó^áy,5 ô¤@§¹õä(LžU1–j"Ê+âÀ1lü~Õ‹äÅÂùô ¥AŽ’@ W²ïmŸV×qh±•‹Ó”‡<Ú_0²•F†§ŸVGL$Qv2]×áØ2ý¨¡,ØlLʾ#vmpߨˆ<6Ý1‹€DÏîÒ÷žE•Šˆg0Ô=' §R¡ßh“ÜÛª(ô“U-°Œ/±NÓºû¶Sꇇ9mæ~)í]="ÌÅ[ºr‡]p«§Kúƒ•²öÇ>W½éŸÝÜkC.þwáá¼¹ï½ ¿ñ¿S…­Õʾ{>°9éúYí±bïÏA“)žýú»FåƒTvÌ)·¶}‡ÐŸ¬ðó¶ú.OÏlx×Sô8Z2/†@u¤¤ì$yK½—A+m@k‰xù6ÆU³ü͆ÛîKžÇ0iQ#7÷Äh^p¨(niû%.4ü8ág8ϧY5ŽM“9sI×LâÞ_…Ó÷/¶€Áû¡s'ìHª´9Lã”Ȱ[ö,™tOaES­H/‰3qò7®ùN43 *9wyjÅžv‚O<²ö"åqdRª£2V銵]5¶Ï¬ª:ï ØÙ”§I”Óerì’ÈŸèEÒ%R¡?©µÊ{`n’Áwò¢@ÁÆðÈ8‡§=|ÿþ>ÿ̾Æ4OÇÄháÐçjsIJâBôð@yG–?v¾rW]O¡£zÿ} ÒÛSåvv5mc/ëé¹¥ê$”zwq«ë>ÆÆcg§ëm-1m޽¯õ’ÍPijNulFV3«‹YàŠÕUÇ3s@‡¿Ã×Ê¡`Å­Ïý¥&3q© y™–(½c*òà„¦¸o·:¶½ù§ÄûâQfj]Sƒ¶ÍšÅ¡áÁÒ›•¤ÑæÌäXóû×ã‹?+£œÎOùŒÊ“Ù0ZÚo¥úNžÃ,h:¾i½M)‰mð,% <“”ÔÓ{.­PÚÀ³mõ0†(ÓämXœ Oô€?0Ioι·9Õ5 O6űô™ÔF/Ü@µœh¾LÈ\&?³©¨jxýê;1ÖGOúÇó¯ÐÜ4û·¨HFCöŸQ¬=§¦|Y¯˜j[Fž-Àì•úÒMZXÿ·Ý¹dಕŽÏÜ\3šç»ëVêõÕUÙ\á©MĶû‰™b*Ö7D7›ƒ}rÙLXj¾L–cJƉ”óÞO±jy…î±´ða¤óék a¿L8¡Â TXVŒëí¦í \k_ÍÆ‚nÚ}Fp;ç9ÚÆ ˆÓ‡Y[‰9à±"$ Ÿ‰zÛ¾Ÿt¶>#³¤JóÙz¶]J^ÿ1uFžc[Í(Í«7JšnY_ùnŠC,Y—ÐEÈ/¡»—ä§¹OV.ñ¯ü™°Íïý<ß’dÆl¯MJrË~X•§6©9kÅžÖ jR SF»£o…cí\Cœå™ –‰¤í²ÃÖC<çëåOÈK½Úº”ýï`¹¿‘Ȱ È«ïÑ%;™>Û±>ù5tLì^¼lœÌÐ^ËÜ ±o•¨z¶í…·ú=âã]ºYà³7zŠÒã…jr˜sgo%_ û06þÖ¦Go‹®9 8ËE<;”2ÊfNàh°<%.d‹¸óö-êqºª&µ9ëælag–Z-§‹ V—ô—uw$WûFLÛ9ÎÒx×¢UÂkLÓÇl„xy¸¾r/šâC{ÌFì§´åW ü»I~ðÖXkZ¨–w J~6i…™ïFÑv% ¡a»u˜U…àï^r*×§T‰ŸøÕŸF“zú¨}s¼•ÈœàÜï2€Ç17¶¦ýêèE$ëὫî;<|âZ$=žÎI cºƒÒ‰¹¤o H”Àójcxþ)gÞfIb-úœÔ›%ÄÐØáù–À*÷tç·D˜ê>x,MÍÜ(Wk§©†UÅ ;Çý›4^·ìàÙA±Þ d'ÖïÔ±¿šDëô‹3Œ¥Š˜gÔø0<‘¹ênÎ>gí zšhúÞ¬!úH=¼"_cŒ¯pRžkÇþ\˜Š½;ómåzð.mƒŒ„¦^‘Läé9Bl¦„êfÎÞÇËArj•1W× D=qÃ¥"ìý³úppŽ[Äãl¾ÍÊ aw#ÿ1p@wZÇfÙ~÷aNßøš¹áРJ±(ìLzòÝŠÑKŠÐwNÑæ›^®ÃªUÁ2xv5=JäAA°yâ6ºW*“ø`V, ¹Ohït(ƒƒ)j«t?§ˆ»¹FÜb¶ŽÏ¶,R{?\„“WGž14"Kñßðµö P™=ÿbð¼Hc&×.ǵ‘вX?¿>àÞqEè·Ztò¦bå‹G×{ú…3¦Y¶¹|Y#Þ´ïà-/`ƒ±48(z÷…Ž gm¥ÕŽ/„N·m ÞÈG³|×Ê ¢ÜúФCDopöˆ*É~gK…C ÞËìó;\&– —,éÉÜÑ^ Ýä·%z‚¸°áÌ1 ój‚ÞŠ¡ ÍÐr¢†˜·.Êî7Ÿà#Ur#Œn¦U™íd­]š°ÛWïb¾1Ì".öß½é‡u:Àšøþ£SÞ®ùbÄ}Ûük«®s¶gÓÌjÛ\´ï^¢2ŸMvg²©ÇkGÄ›fÖi¡½ëé—y'FMÄ:”NŽçš)µÂÿjõP £*Møè|¬ÏWÄàÞËIŠ‹ÒÜD•C£ƒzBÚÁ²ü®,{gêân­Ñö@’Ïj¼`zº Ñ¡«iäú–?ÉÀeð¼•Q·R`Rˆ—‰-Ä7Q¬k}Ì\[ù³×€ºMÑ"Ìå}±< “¦qŒoþèÛg{ÐzÕ0½¬¶]ŸÛŸnd9  PÚòhNtϧNØZRþZݶŽE4y1"¸œggÃBF`Á(nŦv˶$ØM1‘®@/—9K﬷’ÈAß±:4tŠºñxubWåyY 5N.¾hcgÞiX7i–¯HoMþªBšˆµWì ¡—XÝX2%4‘g<ÏLn›øq+‚³´”pØhƒ<Ó–üÄ‚ååyT:ZOÎø²þC¶å—FiE˜uªæèÇTûŒ 于¾ËM÷Tgžø-%#òË€9×nÙȺNÙäùÇÔ>Õµxœˆ=Ù,°&›PŽ˜)®ÿ:MŒéPØ5¢¦DËAθAn„¹=Œ)þ^€žÞ½{Q—m°ª²2]ªA"Ré §è í¥ø{}Ìw ¿mn¥…ФE$؃ÜÛvš1˜‡5%ÝÊJ5¾°Ùõ `R5<ŒŸ µ$š`–O>RvÏÕJS²z/&Ã&1m1uìE 4­/ ²­&·™%Á!!¼vÙ-t|ŒÄA#ƒ…Ò\Tf©TRKS&­^·:•nAäÞªÕóÓцéM Û-.°.ZòZÛcO¬}‘oß_‹JP·¯Üf‚5æhd}Í*ÝX"“²L®F¨h[—2§ÜŠ|oë\f˜=±4^•ò`ªsòíúGåAâª5Ü«ÇH‘bÓÔcI”Mˆc™ŸÑ¦Ž 4^‚˾?TýÄ"“ÏãY AC4²ÄBBÃRof+bv¹Üf@[=ØøPïÀg^ÎÔ‘pð˜ï&Ccþ>'ö3®NŸA:2ï~ù¡v“ƒ/fG4¦øR€%÷.ìK/óv}=IÃ[°@[W[øóhGÊûðÙ4ëd©5‚ýà <íè½ ;À;ѳ¼žñüÔCO"žø?U²®‚ská«\_Ežï8šö»ÑÍw¹S?§„ÎÉ™¿Ho‘UHyACܨ Ï.J’}ɲòºäžñVÙ÷-¯¤÷\SÑ S·ïS”Ûi´§B£´!õoâøOËæsez*<™_¬ g%ïŸÄÈSLÈñ^ß÷kè|AïEšçÑ~MQŸÀ°.xHJË´TÜÔ¥Ñâ¦öZfèzOÖNò¶c4öÐWÔßý B¬W–¶,…5¾ÍÍi°HkR£Es¢¯³!g ÆæˆÃ_3âëÓÆüCáûc1ÚҦÎ2ûmO>]ñÍZÎ tN´Èo§Wæ8çjð=W{+Èc&ü|Ë$ãj¶0±ªüÝOöLCzŠÜçG'-µ!ÐÞãVu¿ÓðÂé8WÓ[¯Õ‘pǼ{ûsùÈÅíȽR§šïõÏ'18˜@ƒ8\9©üÖêSÃÂÛ©ÉDg¢ì茴0ždåš/£mK3~–ÅÚO|ÿ‡ñJ˜.!3ÖLLѰT†‚5Ìþ~+K¦mÜa00o7Ÿ"›ÝŒÉµ.þ ¾[—ñkO)Ü'˜±Sò6:‘ž¸?Ò&W>­CÃ^>lPKããÆÏ_÷ŒªRŽîü@çK÷ƒÿ)àz¾U‰˜÷ȤU@qfoÎ{K³—TöösoëY²¥‘_:­Ã%­“Dˆa‡oÔÂLìÂLËc‘0ªhÕoUÂâAä>'/ å GR.ƒD'*`OH/®îEú^„lªÃñ5s£Ã1/»)ô¾J ¯äYæÀC‚EBG½¬PöŽÙÓÒq’+»êªz ¹Hu«òd5r{¼áŠ=Gð17<#š­™©dVQÃ{¨¶—š¿q^x½¶6uÅKèdSáUÃ$¸ @ß$þ”&~‰v€¹éßoé;ºõÍ:†%ñJhû¨JeŠß“Õ»\ J×.z GiÀþÌô )³™ÅXöŸ'õºìåE-, Uqw8q×ø ¸'®f¦*„@å³Ï›åUàåBÉk¤šÑ:¬ÇhÀ×áñ\—#*=üB_¨€mŒ;ÛõFgëwK~2N¨sjkÊhá™Sf ç²|¿7QrnS ²úþåûCèE¶ä §¿úÛ˜·+*ÎõoöÌ!;lä8åJ|˜U‘¹M<“ ¶•ɳQÚ†£K˜’ ¡óoÔÈúrUñ ÷c³Â·jð¶/ˆ‹I¬zV#›’@OT®ÝÃ<8yÄ÷žúä½ýmÙO&%‘Zõ ±*úyv×Ó3 Qï&ðg-ùÄòoy×Ú&|‡þͧ_õ¿ˆ°ÙbÝøð*Îu↓a@K¤ú:Î亇èbíof¯Ê&bxúœÌ{8Œý-Ç!ŽÃ€™ÖUâ$£÷ê½ œîáRI£äÚ—O^E%ëÚô}ª²Ód.«›ŠœÖAd+¥ßê•u4Æ ®,Y””<4dOš,0—:Þ\Õw>T ™:}A×›¨ìæô´˜Ó– IB_|®lŒƒîi‹Ï˜p:Ï…D¾dà§cüÙܳr“ˆ’‡eç2>s¢»7[¼|BR¦7t›—Ç•Âdw’ºF Ëh³ë<`%—tQu…m˜Î3ù¸¶ |2Y®L+LJŒò÷7Ë)<;|‹è—£[Ž(ÔbåüƒÌ“MÙ_qƒV€¡<!êò•×Ç7%çŽwÊ.dîIn¹ÞKð£yäVÇ\ÖãÑ·ÔÜèåþ6hKfÏ<ñ¶ØþÁóDrIê›X#bG]ͺDsîaž·îlpo.÷ïQ\ö=ð2PHí*mÖÙºgŠ—óL‹žÔ ž5h¶Í><ߘ¤Öwχ£äIkö…¦pòCmÕ ò±Ì½4¿à .Õku¯‘ÅFÓAíXk–&kðÀ7*Üž‘Ê×{MêNØàMë¢ÇYᙣ¼/šWé í½"nη_DB8ëð.ZÊ»¬'¯MÔ9¼éuß(ŒïBæ,2gLê:Ѭ¿±,a1qnnÖJ£MÎÿÑw÷ j½Bä{û¾Ge>¡ëÝ7CÅ8rˆþ‡¥©1\ÞvX±ø$¦XYz¬ýÓ¥ãî±1Ë4ñE…Qͤ‹„èmU¿ë±»ÞSí§ÛM—«j¯¥ÝSÜ(d»"õ¯S tÁ:./Í ;] »RvmÖãr’?ÈàÆ-81¹>Y”t)Á©´UÂ’ç ¥>—ëN¯ìvŽðòð7J.H¥Üzd¢IÀ&z×êæÆÊº¶þTž’C+ óÉï>¬Í"]§'Æ$”Ïp|öä¯ì‘-OŠ6üZ‹ßg»³‹¼8æçÝWvoûè[ïK:ÆzØNë±Ãçœ7RŸY– +§«Ö§èê.å¼p%ÖsºfÂ<ß¿]|DZoĺwù’‚Næ òrFq yœïéÇ‹O}}<~³”ýÒ½ë§qÅî5öõÐ *æ‡ù¬RÎt2ô¡M‹ Q=ÔÏ­hAëó-}m…^7;¿pYZ ù‘Š×Å#[¹ö¡ ¥v‰`ôÇŽí’wYOy4K•—ÕI–xû0|ÖC®6¸$Je ,pf%Ž(ÇävEpk£Beùpî±Ð'LÁ÷“ŒFA·ŽêR]Ì™xÆèZ><"•tœ¦è“es¦)¥¯Žo[2Dd3sxg YwõŸ_)ÃgÞ/ˆÙG~r•»ßJ„É®&Šy5/‘|¦¶OGz÷[ô8…+ž3Yg‘íæsÁ·ô—Møï´d<Ö_+’ç¤.64½v‚BF}SçW·:#è¾`}äÖ’m‘|Mñ©a0|•”8Þ"E†=En«ý¤Á¿tœhT s©›¾µê¢$pƒüÊ((Äs£¡¹ÇÓPI€¨Îž¥ï[„> »$HµÅ܈ŠIòÈ3ùÚ…}¦}ÿé;›—çæ¡jóN²;Žq¡•¯„ÖË¢5•ÜÂ1˜Q1ïhš1^4G+„eÅ ¬œiÚï|85“°Eb¨1éURW¿Š&½&ÜëÜ•=X®ÒñeÑgù™_ËÖiOHæLPu|ª¿ñ¬ÞÚÝCn"b>wÍ·ÒJ0óõÊc6&ù$CÑóÚÂN–4)l@#Cò~™¥›¶ŽR\º±|Â!ûÐ#™a+mš‹Ä<œÁ'ƒ;²p""è» ìwÙæÍ%mé¶ñ­Ó¦D~­šÓ¾ªÎ–è 9ê, /Ä6уû"L7îáÛËoZ$K9ŒO0²gI)9¶ž¥¼2-$Û{Ô‡ÇOÌÄ7´à™‘+³²¨r"Ih³î/fÙ ¥iSŸæ…+GP&y’ÐÈ€Î8¿Ô»ýøÝ endstream endobj 8 0 obj <> endobj 9 0 obj [500 500 500 500 500 500 500 500 500 500] endobj 10 0 obj <> endobj 11 0 obj <> /ProcSet [/PDF /Text]>> endobj 12 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h ÍØ/.iî\®!\r½ endstream endobj 13 0 obj <> /ProcSet [/PDF /Text]>> endobj 14 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h CÍØ/.iî\®!\rÎ endstream endobj 15 0 obj <> /ProcSet [/PDF /Text]>> endobj 16 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h #ÍØ/.iî\®!\rß endstream endobj 17 0 obj <> /ProcSet [/PDF /Text]>> endobj 18 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h cÍØ/.iî\®!\rð endstream endobj 19 0 obj <> /ProcSet [/PDF /Text]>> endobj 20 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h ÍØ/.iî\®!\s endstream endobj 21 0 obj <> /ProcSet [/PDF /Text]>> endobj 22 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h SÍØ/.iî\®!\s endstream endobj 23 0 obj <> /ProcSet [/PDF /Text]>> endobj 24 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h 3ÍØ/.iî\®!\s# endstream endobj 25 0 obj <> /ProcSet [/PDF /Text]>> endobj 26 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h sÍØ/.iî\®!\s4 endstream endobj 27 0 obj <> /ProcSet [/PDF /Text]>> endobj 28 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h ÍØ/.iî\®!\sE endstream endobj 29 0 obj <> /ProcSet [/PDF /Text]>> endobj 30 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h KÍØ/.iî\®!\sV endstream endobj 31 0 obj <> /ProcSet [/PDF /Text]>> endobj 32 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 34 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 36 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 38 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 40 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 42 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 44 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 46 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 48 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 50 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 52 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 54 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 56 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 58 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 60 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 62 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 64 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 66 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 68 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 70 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 72 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 74 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 76 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 78 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 80 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 82 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 84 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 86 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 88 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 90 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 92 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 94 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 96 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 98 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 100 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 102 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 104 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 106 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 108 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 110 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 112 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 114 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 116 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 118 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 120 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 122 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 124 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 126 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 128 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 130 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 132 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 134 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 136 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 138 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 140 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 142 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 144 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 146 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 148 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 150 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 152 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 154 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 156 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 158 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 160 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 162 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 164 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 166 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 168 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 170 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 172 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 174 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 176 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 178 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 180 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 182 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 184 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 186 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 188 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 190 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 192 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 194 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 196 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 198 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 200 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 202 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 204 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 206 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 208 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > stream xÚwT”íÖ6­€tHóÐÍÐHˆÒÝ%‚ÀÀ Ì303tI ÒJ·€H#(‚ !RÒ(Š”Ä7ê{ÞsÞóÿk}ßšµfž½÷µë¾¯ëYkx8ŒLE”!H¨“TõMMobb’¢bb$<>>¢`w´(å¬$ øÀ10ÀІ¢¼¡à×€Øúg3QÀ Gÿñ›"0>`À:ÜàŽP›á…€@Q¶9`ª­z@ÀzÂÀ_gˆ‹Šÿ]î¯ì_…àˆßÉ`GG¤»áG8Np7(`¨¡'ŠñÅ`äì†FbóÁÞ`¸Ø ø=9ÐP6ÀØÿZ툂{`Тh¸Û¯A¿Ê`OYQEº»C4ɯùÔà(¨#öØý@nÖôAüe8Á§_K@¼<@渧T[í/ÖEòoŸ3H‹‰‰Ý žÔ×úUÞÌÏú;øÛÝ (Àé8a—€Á Ø’4Ø `P^Р€ÿ üÓ" pG àu†#Hþ]ë†:ý±±—‚ûÖbXî‰b¿>?ÝÃÒ ‚D¸ùýþû~Aú*VºêZB6þ;¦¢‚ôDd¤ i1@\LF•‚þYÆ ÿk ±çj#œ€ÜŸi±Çô¯‰½ÿ"ÿ_âþYˉe-àÿ7ÉmĤű_âÿgªÿNùÿ1üW•ÿäÿ=†—›Ûï0ÿïøÿ»ÃÝüþ`Ië…Á @‰•â¿¡–Ð?¢Õ‡Bà^îÿÕÆ€±BPF8»ý}Œp´Ü 1‚caØòÇoþKenpÔ‰†ÿz­"âbbÿÃJËÑûê@c)ù;Å*çŸ-ÕŽHÈ/‰IHË` ìG‚½d¬% ˆcµúþ&1E 1Ø»^à„D‘üºQiY„Àvúåýí’@Èÿ°¥¥KÅ¿m1„ñAþ¶ÿ1‰£ …ão®`Çü—ý[ùP¨/Ô‘äÃÒQ!Â¥.¢õ¸F™ÙGdm˜hq¹ýa’U_´4†wúILïJ–渧Š=¤Ša(Ýh¦ìÁ»©@fÁ¯Ç#¾6]9¡Ó´ò18ê}+*{"oN¾w9CÙ H&çQÙô‡+T»ŒY)ì­ ¬ù’-§Î"e»%7ª×Ÿž·£7îÊ}Üg‡”i̘xå¼öÏx±VܢA+Êj”u†—™¶ùè9^,<áH¥5ŽñÄoÅ:!spaa çu_ºä·BÝžç2Uhiýu8ò†÷3Ò=ÊÑiFãðªHª–%E—wNÇTN£î™Ü4&Ûíî\Ü»[áÕˆÃÖÎé]²ž3œÝ©¿¯ ¢AÙ¿u¢>Ðy‡óUŠàå-=”vU™Œ G…‹‘£2­É@çÒfkËÒ`¼ÍøX±ö£"Fœ2]“ºHJSý\ué^¥™ò8åx8YG{°k6º"±—2åç¡Àó·ÂB­)n/äûÝǽ„Ê–h÷ÐöŠ´lMd^hþ ÙÎïwÏßŸŠ¤Fª£.Љ™ ßvzöR\q'©ï”²ÌXæëðß–¯¾Ú.eT¡›ƒX<ž?_#L \Ìzuoüéô’“é~!]Ú߇÷Åg¼?¬NnãræÓž–È(¯0|ûôü ‹–Gžô·äƒGñ(”ËñŽýÈíÍO–ƲÑW›­*TY6«oh×_„l ûΈ¥z•óýu[й…äåìHQ0UÊ@ýíŸzuUF¶Jз«–ÝgdáfˆÎLÐQÝÎv¼‘Zk4›Wú~ã Ë¡ÏM1ÜY‘rä 0hc¤Ö’.ßfM*Ö`ìsSà(.i/¶`¦± ‰X>¢]hŽ$T3|jÃ4^iÉ9èSËÕE„Î J¤*Á‰\ˆäIÜ,Úä ±˜PûÔö ×{0Z(¯ gÀš_ª>8dðbüøP±vê½\iöƒ,´þŸ‡*|Iò—GUÛ*_Þ)››_ãÞ ¦žõŸïðÜ“NÍúvXîr€ÔòŽL+𯙼w®;Èi.uÑ7ÝIå?>áð+h³Y!¸êÑsð2Ë‘ÃÚ}ƒi® £áÉ´”`x(8eëæ«S“çEòN”GàN2³h]•;dôÖ=õŸM5«¤ßЭ§S¿]‚G¾[vVÅ4¾A’»Xö*éñóbuÉâGÉÌr’,ÏöF£Ì)šîµkMeqW!œ}!!ÙJýÈØ*G{ÓùŽê‰uø]Y“ôAù}‹D;’[´m´jµœí#Èìë`;úżH»Ÿ¶§A7žÆvClï‹ñ»ÏÂ…CÍMDÍT/Ì[”“ ùÀ4ŽÉCYµH„ ƒl¹æíuÛwäI@Sô»ÍnNš=ÕŸ•ÏÍ8½~¹©Á·7%q µ’:Øo‡“ ¹Ø»|¨÷Þ¾><ñ‰ûþÒ[p„ŽÀ9Œê½&¨•IñÎbSô~Þ*¼ä½ÀœSóÜ<”®œõçãÍÇ$IÂCÑþ†bniM ?2*Y÷Âêkl¤ùŽTå«üJmhÝ¢îWC^|g•¥ôŸÄççüYSxêæ‹«üóbvÎùŽ‚ÖÍôåÕ¼ÎÙ Z¤4Ïð-/4¿ìÏ qÝAÏù—OÜæùLü¶ì5³¾ÞiÔ­Z’4§župþ²DØñÍúBy "½¯N³}buO¿‘z=Fº ;Lå¡4(©E¨ õ`ŒÃVŠ|µmY8¡ß¾u%óåf!Lq»ÉÓ’¾)ÙøâUpõbNXã™viNœ£äé”pk $èvŒ(ÕéAÎÊdö×;8û­NâåB“vlŒF÷S˜ðL£¬÷ûT$Ôl ©á¶¤Ï¯ÝŽöIºCd b–HJ‡Ë?a5´¢öá2«á¼q²µóÁÉ Ô<>¦j.8i¬ÚDêã™ÙÒ&:ÒDÎlµÁðš¥2‘öô˜zãI©‘ÒX™FÆ`f” YdíqM²©Î&»{ç}°4§ý5“l)Œ<Å•Íó–ct«GOþÍsG_'¥‡éL¼è^ÙéÄ=³neµçÊ$GÒŽUh¾ÏÉ„™§\Ÿ¤µ³e ëª|ÌT  |´F~ÝþaK[™‹k„q ÜÏŒ7ýî@ßL²-mà fîËÚ˜-½ÔëÄoÓ0KmÞŒñêóäs>¾d|¥5íæI]W8ç½Y·½ÂêW³™ V• … ÝÝ€bøÌÓŸ•Mßm‰%Ý|÷¯-®·¥V²dù4wMƒ¹+~”±¨Ä²c¢ ÉâRÃ0#4ŠâPý’÷+BÊòNOãty²LoÙJ*3åImøÖ$œ)‘Öƒ¢†U^§µL· æ“^ÄMóñŸ„¯‹†È]ö΄È(SŸ¸CñMh]Oz85I©Û„<¼=@z¾*Ïwe9ºè½ «æ1k!‰x+õ™fÂDâ[>ª¾Iwö…Š{i±ò÷Î6¨P^~5“aÞè@6Ù .rîýGÕz’NšWÇæá²kQþ>|óS}7Zý6?ÞPëž=X”/¾ÚE£ú:ãÙ(˜¢£AvÒ¹¿6™5–x_Iʂˡ.JâK§½ †ëGò@¼.°’2¾ËjcAë=O¤Ç€:/¡7wq_"¦¤¨¸EV0¾‰÷ÐFÄÌ0Ó;´žqpl÷ÒÕFG6Xõ6Sž„ä«OSµ ‘$vi¾î§DNÌ©”%_¯Ÿq¯$‘½í”{s]ª} ó: ÉYr›ÉwÔ㢓l°ëÍEÏ·[ÍL´´žZLÏë×.&nìƒO©´æínÙv¤¹8áêd½é·ÑÇáLGÕ­}<³°ÑI™`;)í[·P‡Ñ¯¿;ƒ)}¶ñÔLTs¶O”»~·l!KÇñ‚"j¦™·±} ”§(0YÁRyú‚ZúÈÎPˬ•~Ð4|?ó|ñ1ož—?]˜]Ø1ûÎÀ“Û½”*Œ=C)ú7… öñÌFd4ŒEïCãv·cê\ *æ=‡swjŒpìóâ·I»# ¾Ø½Ü«_¯7 ‘°P!øÎsVFÆL…Cülõß™H½øbTí}…#?ËäÌ÷ 8ÚsìdÅN÷´i+Ü/¦C16ý#°¹Þ!”RfÏõóø|ü5Þ µÍ®°bu|ón T(·œ‹² }€NTXW’5’§¿iZð/ûG oºš"h2 ?‡^Sß,>I{z™ÒXhîôØv˜]_˜T¿´¤è$gÖ-Ä ¯~o À¼*k¶clÙtDgÓÍ/°–”é±ó`ü%L¯H~0Òd ïÒwè™ÓWh¼H¯d}]ôøÐ¶îélˆ…âpÿÈhYr5îí’ƒ[yÍgšêМ€d1á½ã ÐÆb¢Ëê1¾£­Í*ê>ö—õ¤'ý^’I îv³v¨œÇ®¥*_$tÑÙN*pžWüeÈ-õøÞæ»c·óÈ‹®ÞÕ²,ÛU–äÔ`6Kç{$ea ‚#¶û(/®ìÅÇ} íþJN©Ø—>ãé´ËÊŒ“æ"œ¾YÓjO=Ñs!ð¦xŠXZuÍS2 öá;ÃpP+[™ÁÝMh Sm·âû±{ñxÁÒÝçÂçŸv+ôÀòr2ãÄA:ôÌI׸Eå—ZHÛÞ2Ô2íYƒí|Ø£«búñlAòÑíàI6[«y«>ðÏœJöœo{ó o' |§±Âã|>ɃAÚ>*þ71ý*;9od×›˜ßc:èˆÚRÏ3{3²Õòj,€Ëy\lµ õº‡I®ç˜«g KÃÄÂ#o]qîŒH¦ÆŽ™g•oSseµ¶Ÿªñ+µðœ7ö¸ú)Õá®Z©—·§S —_{'îÜÐUXUÛ.‘EÚƒ4×6œœ•×;»Mh«‚nÈ))½¦mJœí„Å}òÈú¶Å´“™‡²ûRxN/ZÄ$ÁšÞê]š dуçá³÷²ÍŸoØÙÓwŽÏߎB¸Sž+¯°6+ßiH(9E¿ <Ñ-b ãfcÈî6­.Še—ë}Wý5Ëá$EÒ+mɶGU"/ôH‰Å>W#x±Üoh¹B"8Ÿ-€æy3£ÝxiZR½«Ü±IOê²AþÅ%ü%;o¥InÍË=Jœ¼)wr¤Ç·Ï›Ú0£:–ì—ù!fó\™…IZ$ÁIqi{ãáM9 Ú#=—â±±1·*Å{oÉâ9[8ê¼éª!~Ca‰\)òÍŽ.Í„ º–Ù¸‘=Ïä­´0Ιˆ¶•‡ ó»ç«ÒŒµ°Æ6³Æƒ¥îøý¯‡Q‘ïuî ›†I¼yÓ9ë¸7*©æz¥^š¡yïœß6% w ­“Duì‚ÔÔ2´Þ3hÎzÿ˜ õÓµøôªHcç+ö‡ýF þÑ„)˧ ‹fiܯN¸òŸØon°»}ïy¢06n2¤2|dwNY¢ÎÔl~Ú£YO"3ï«vW¿òÍów=ší–VùºD§ ènQDâxCƒŽ9 ”Ö©Èl­Bdô:ÍA)Esñ¤8¹Ó2–òÃÁQ,í ˜ƒe’ú*´$¾fÆùÉ03µ¼m¥Ù"#1åèšþ‘Ä·~^“ý£ãV0aèÂèmξ$I>øvM„Û@ M#”Ò9ÆÎtzf]ŽGA9{w¶¯ªC¢ìñžÈÝi¨ÙŽma¹€fƒyÝ<ÁM3Ž¡ NIGÀ#C¦9ÉnnÇ„o^ß}u•z†QÍÑGaD'÷ªMœöôÍTÝêÊ/dýióóÎ>œžBCµÏy Òø NKïê«<®[×ܶϥp«öìóÐ9®r1_>­pæ;¿}®ñ_]qң믕E¹ƒ¢Êþot¿zäÝÐë s]êŠú‡ñ0—:‹Ä퓹FóáKŒQ┳Eªuy¥„ñ†/%kÑ"/l‰?kã~Wj'ÖÔÍ×ëO„™ò°rG–|N{»hJ›K<Ö«£dkëFfÂB`VÙ¿ujÆtíæ*ÿåÅYèQ«0ë*·š•·RÐ×C/£Pk‰ù¨: êfã QÒóí¯:{C¶^uq«…ÓÛÌv4nÂÙ:[¿¢ ôÎ&{èjV²ëkŠŠÛ=פÜôHU—¼'o¥5Ã,2Xº©¾mzÔ¬Êáª>Û:V¢hfºÏËKšKvœú"dzÞû »FE¾'ãrIáÊtßð=ã—y0’­iæ±¹ÅjÉ)Ë –‚cálÂû÷)H(’Ø7eCðvïQKÐ6axø¸•T%z ¯+ æýˆøñ©ò¦+W¥ñº;Þ=aóa¬QÓ¹ôíþü“N$ݼÖ´K»DÌX‘•¦Œg¸§´ã*ué].òIpÖ—®?Yåò×’'ÜÛbºm^íoEn¸š¤­_عá¥H®C¿¶Y'n¶J-ng¾ì½¡á¾»`)g¹kE(0^˰˹Sd¶O¤×®ÌylƒÙ JۻРx/Ozص‘p[‚"®µ}x‚B$GCùÈ{Fò ¢.~dsÞ™@ùäëàJ’Ž1öP7h^N³9€’•?^_åD¶¿¢a²Ý"mnH°™kµbûv0ÿÕÄò³æ) æ;óy.2ÝîÞ/uÓåh'ú*Ýk-¡r y`H13+’?lHî¶Ñ“N§U¬×®>ô¨·`÷‰´§¥=MßYh„ ×aû´à¼¤§s2&íc­¾ÆLHNêô^ljCozAåþd—’m'ûƈÚTR妵F¥ô„þ±¡ÂÌ×]LsG‰¸\lÚ"*„yRG¸Ê¼âî‡ÛÕ”¦cøB† Uu!€í™$Ϭ‹fïò8ðè&îœã@¶¬Èµ¢+mWeóO#_7Û^F1ÍWæ>úxß×*ؼfpËÅ‚º¹õæZCïf®U²çQJ€Ì#ÏÛ‰Õ弯3³®— g*·ŽTâ\4/Ùoø»”lVÌuRL{¬ç”–üdz@¬Úoå ´õÖ}¶ÇnæJù`²‡(üY ¾ýœco&D5`âyÙû3›ÐGLAG )á/ˆÌ]ÒÆ½]ÕÌÚL| ú‚/’÷4tÞ43P#ÜlûW‡é` ¹ÒO¹áìcŽðgvV–f¨iPÖ²¶ "=ã-P ćÁ8–¸%ýˆöµžÖ¬’ç]/S/‹EYRï?Öü"©eËe2.adN@^"*©ª)—Ig¾'¢5)}cʆfô¬ê!\ÀX5×HGÞ{«©BMï&Õ~"ú…Ó+þ˜=!ê˜ûj/nï·Fùîo'ãÏP nÿ¤£dœ2Œ5•çÓæþľ)Û{ýž;·qö‡‰$F%W|ÅG!ù§ÏÎ ¤+ Æ v£h¯ŠJ±;Tj–pSê›1»åúm0kT츞G9ä+‘,göý¶ÐFW{ô¸P£Õ]t!B°tR›$¹@k7ŠmÆ"þaµ¶~èAvqÛû¤«¥Ê]S ¥Ô˜í{Ä€+a¯õNdq~m&0î|ãÓÊÔ8Ršù'£Žcp±¶Ëò—]Zu!µô;mÉŸÀµ)Œ'°=Ë f³ ÍXhhhîh™džxC£¼ÅxX/^³I]žU‘ë[Â'aae+#ʽ/×ßy]™4 T'×xÙ¬Ó<Ú‚ýsÉôÑñÙÜëZÚ™á¬Æ]ÁÅ£LÊÚËWŒª7 'o*Jþ0(Û ,нºò©CÛ$€£¾í©z>À›áÆýÔÚN3 $Ÿû*ç|sHßHøì²¡ê )Ï¿bvߘÊs7Klf÷ð½bÞð`Ÿàñ;‡ð“Z–]ŠB¡+_ ü<-e n\ë'`Îú¡ŠÓ´T·d/ÿY¾¿Áiß¿F4H%æüu¦Á01™’漈 r@j±©ªg™ ¢Êÿ&Skj]pà߯ú$†jTìÛ5üÎjmŒ6ïÖ ‘ù£ì}ßÒÝ!rxÀu/¬Û° M£ŠJ'iüPý÷>/!Ý}¨o%<°å¸*Yœ›7‘ŸH> –xh¾%Çc·Òõ–øãT™Þƒ‹Â±•¥ÂÛ«ÅdmBýß3ÛÓ¯Ü8–¾íDIøDÆÏ&‹ñÞyRqs3듇ÖMáQ}}R'v—¢µÈPâ6C:eW™Z\#bÿB:‡¬¾öeLÍ Ú+(]H?fÜùÀ=!>â)¡Û¡$².zÆNLƒ{žÛípQ« .7_'Xmúw˜Ìý»2]¡aÛ‹…É·y# Qµ_Òœ}­?Sû—â»fâ·üG÷"’ endstream endobj 210 0 obj <> endobj 211 0 obj [531.3 531.3 531.3 531.3 531.3 531.3 531.3 531.3 531.3] endobj 212 0 obj <> endobj 213 0 obj <> /ProcSet [/PDF /Text]>> endobj 214 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 78>> stream xÚ3P0¢t0e äÎef€H]s 3=ss…ä\.§.}7Css=KsC…4 4T6$E!ZÃÐP36Ä‹Ë@d;—kòû endstream endobj 215 0 obj <> /ProcSet [/PDF /Text]>> endobj 216 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 78>> stream xÚ3P0¢t0e äÎef€H]s 3=ss…ä\.§.}7Css=KsC…4 4T6$E!ZÃÐL36Ä‹Ë@d;—kG endstream endobj 217 0 obj <> /ProcSet [/PDF /Text]>> endobj 218 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 77>> stream xÚ3P0¢t0e äÎef€H]s 3=ss…ä\.§.}7Css=KsC…4 4T6$E!ZÃR36Ä‹Ë@dŽ;—k¸Ò endstream endobj 219 0 obj <> /ProcSet [/PDF /Text]>> endobj 220 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 78>> stream xÚ3P0¢t0e äÎef€H]s 3=ss…ä\.§.}7Css=KsC…4 4T6$E!ZÃÐH36Ä‹Ë@d;—kü endstream endobj 221 0 obj <> /ProcSet [/PDF /Text]>> endobj 222 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h ÍØ/.iî\®!\r½ endstream endobj 223 0 obj <> /ProcSet [/PDF /Text]>> endobj 224 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h CÍØ/.iî\®!\rÎ endstream endobj 225 0 obj <> /ProcSet [/PDF /Text]>> endobj 226 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h #ÍØ/.iî\®!\rß endstream endobj 227 0 obj <> /ProcSet [/PDF /Text]>> endobj 228 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h cÍØ/.iî\®!\rð endstream endobj 229 0 obj <> /ProcSet [/PDF /Text]>> endobj 230 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h ÍØ/.iî\®!\s endstream endobj 231 0 obj <> /ProcSet [/PDF /Text]>> endobj 232 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h SÍØ/.iî\®!\s endstream endobj 233 0 obj <> /ProcSet [/PDF /Text]>> endobj 234 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h 3ÍØ/.iî\®!\s# endstream endobj 235 0 obj <> /ProcSet [/PDF /Text]>> endobj 236 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h sÍØ/.iî\®!\s4 endstream endobj 237 0 obj <> /ProcSet [/PDF /Text]>> endobj 238 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h ÍØ/.iî\®!\sE endstream endobj 239 0 obj <> /ProcSet [/PDF /Text]>> endobj 240 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 83>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4=K C˜’…h KÍØ/.iî\®!\sV endstream endobj 241 0 obj <> /ProcSet [/PDF /Text]>> endobj 242 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 244 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 246 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 248 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 250 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 252 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 254 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 256 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 258 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 260 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 262 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 264 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 266 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 268 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 270 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 272 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 274 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 276 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 278 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 280 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 282 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 284 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 286 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 288 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 290 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 292 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 294 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 296 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 298 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 300 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 302 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 304 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 306 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 308 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 310 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 312 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 314 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 316 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 318 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 320 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 322 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 324 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 326 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 328 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 330 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 332 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 334 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 336 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 338 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 340 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 342 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 344 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 346 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 348 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 350 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 352 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 354 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 356 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 358 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 360 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 362 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 364 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 366 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 368 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 370 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 372 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 374 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 376 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 378 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 380 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 382 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 384 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 386 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 388 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 390 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 392 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 394 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 396 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 398 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 400 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 402 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 404 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 406 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 408 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 410 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 412 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 414 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 416 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 418 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 79>> stream xÚ3P0¢t0e äÎef€H]s S=3K…ä\.§.}7CSK=K3#3…4 > /ProcSet [/PDF /Text]>> endobj 420 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 78>> stream xÚ3P0¢t0e äÎef€H]s 3=ss…ä\.§.}7Css=KsC…4 4T6$E!ZÃÐP36Ä‹Ë@d;—kòû endstream endobj 421 0 obj <> /ProcSet [/PDF /Text]>> endobj 422 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 78>> stream xÚ3P0¢t0e äÎef€H]s 3=ss…ä\.§.}7Css=KsC…4 4T6$E!ZÃÐL36Ä‹Ë@d;—kG endstream endobj 423 0 obj <> /ProcSet [/PDF /Text]>> endobj 424 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 77>> stream xÚ3P0¢t0e äÎef€H]s 3=ss…ä\.§.}7Css=KsC…4 4T6$E!ZÃR36Ä‹Ë@dŽ;—k¸Ò endstream endobj 425 0 obj <> /ProcSet [/PDF /Text]>> endobj 426 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 78>> stream xÚ3P0¢t0e äÎef€H]s 3=ss…ä\.§.}7Css=KsC…4 4T6$E!ZÃÐH36Ä‹Ë@d;—kü endstream endobj 427 0 obj <> stream xÚµTTß6 ˆt—4ƒtÎÐÝÝH—È 1ÔÐÒ¡”€€tI—„R‚„ÒÝ -Ý/úëÿ÷­õ¾ë®5÷>{?{Ÿ½ÏyöZMm)KGsˆ¼# ÎÁÅ Ȩik+qq@ NˆƒA ·‡üíÀ`Ѓ¸¸BaÂÿ¢È¸@Àð›,þÀTs„”Ýì\<.~a.aÀ  ýEttȂݡ–5N€²# âŠÁ ãèäåµ¶?,ô×'€Ù‚À%$$Àþ; åqZ€a50Üâð°¢Ø íh…À½þ“‚YÔw=<<8Á®œŽ.Öâ,ì(Ü q…¸¸C,¿š¨ƒ õƉÁбºþáÑv´‚{€] €ƒ=Ôs}ˆqƒYB\Ë´•TNØdÕ?ì€?wÀÅÉõwº?£%‚Â~ƒ-,œÀ0/(Ì`µ‡4äU9ážpvfù‹¶wu|ˆ»ƒ¡ö`óÂïÚÁy©gðC‹6èjáu‚»rºBí5 ü•æaŸå`–2ŽÜãW}²PˆÅÃÆ{ÿ:_;˜£Ìçoh…YZýjÄÒÍ ¨ ƒ:»A”dÿ$=˜0þ±YCà>$ÈÅ€8 ž6À_Kèx9A~;›ºðóqrtX=4ñƒZA^>®`wîâñóù·ã¿ã!³%Ô0‡XCaÿd0C¬þÀpzŒA ä€~==™¥#ÌÞëúïSJ©©H+«±ýÕóß^iiGO€‡ €ƒ› Àâãð üþ›H ý³Ð?±J0+G€Ðõ>lÔ_5»ÿ)æ?‡„ðß\êŽê…˜ÿ» ˆdñðÃõÿ,ùß!ÿJÿ•åÿ.öÿ-IÞÍÞþ7ùOÆÿ‡v€Ú{ýIy¯üaÔö¿T}Ȭ±„º9ü¯W ~ )˜õƒ¬9þ:¨«<Ôb© …[Øü¡š?캿&Î ƒh:ºB]2! ÐÿøÆÌÂîá"q}æoäaŠþ»¨ÌÂÑò׸qóñÀ..`/ Ѓ¢¸ùø>\si ñü-fæ<4è°rtÁøu®B ø—é$šÿƒ„@‹¿Ñƒp€Žö…þeùU/Ðò_ „ü ò€ÐÁ‡•ìþÒÙÿ¹Rý+óèÿ¹@§A^Ðå_„ÿ >”íñä~Håõþgã,Ü\\î‘ßØÕ¿ðïK ñ„X`ÌL:Zˆ„ÚÖ„~¼¨’¢ðàØ}|zaÀÍ1˜oŠï–}±’ ™1«R*?ÓÅ%ojÛ¦.í|‘µ8uì³^KSçÅ{ÆA#¿eMcþjòþ q<Ñçœòé$n#BŽ~Š4µp‘K7‚&U4^;º„¥u·6®/SÍçéDF¢byå—Õ[Û«Š3TI(…ôvWµàMæ½:|'¤LïVâCÖbL"ߨ§?Um½ÄHð¨Ä[îéïÇï¢êˆRvÞ8¤ƒãˉôRÊò¢VêÍçâܼ+rßI'ð1W ”!ÑVËa|ñ&Mf2"¬½xã£èFa˜®ùŠQ`Š»š‚=³œIû;d+z”ÐWt±’{å¬Í$Ÿš‡E¸~²cßPË[¦çnÎÕÅ£øxÜs¶HdQr4wÀ-ðÁvAO7{ŽŸ¯Q5‰ë7E‰ùò9ïyJãáX²d{'T$ðÖ±<üí’DrL}yÃÍšS\)ÒÒd«.›î£9ÉRnž5Z)ÜB3$âSih ñ¨ŸíêÐÁþÌ.‹öƒ€õ ß#2ã ïûåÙeöOöó+B“8wÏÚyiìðQÂYú™$âI®|´D²\Xbcät6’=É©¸ó½Äæé$èñ¡q˜eìšÚaô,©¿ó8Œæ£²;Æ.qX2,s—D^4“{ÃDjätÕ>Ì©káǾþ^~q0§C­…w±:!äð%®ªrÈ5cÄÇ Û=^ì" Àrc?òª:–T3/Bí?c6"#.|N׆Sà:B!û•DacÙXý!0ìSà°ÄÎ;øÖíhX ­ö$"]¿™#ñ'UÜâöñ|žbù£Â/Ú=Ñ ú‹`í~CâŽ-¹Øþà×+“ÉbÁ8ÄCW`$s,àV[vS? 2JÔ’UÍLǨkU…ÀF·RãÂ(¾»MÑ~5 ð2Ë_²¯n?!ºÌMƒ‰*Þ‰2ªE™#4‡Ã£ŽñˆÇUJ¢¥àüò”ºI­Ð8FÓâ ¹G8“ëwi¾›7‡R£0B†;Ëçs¼D/0«ŠkÖE|ÜËy|3^nGf'tðYÀ’å4Ÿ}JÃ1E®{“ß»§` 6 F'I  RÄ’'ækdÝ[ •O·Ï^4 ôLwžðÎLŽLØ,®}AeÇÀeP⚨Rá.ÜrÄ¢á3ïå°Ç»ßW¤¡e,yï|ÿ¢:ŠË >÷D¨LmÁ|(˜Â£Ç`,qŽÈuêŽØ¡Ç$ŽƒQ®ÐUY¿Ç< ýMœæÀR‡2$½Û >Óßp`dŒ¹£a¤L+æ…3ZQÌy<ÎíÔ\³8©+­ - QÜ$ í&â°ÌAž+7žC˜™ô Án ˆ‹è!CÍ䶇.)¾síçcQ4Z,ª—ÉxGV°¡[7‹Lf¶Ç²%ÀºÌ“^qé¸Ür­½á Ÿä©(}LkAÕÜ/äØ+VPÅcâ?£+pLá$Ñe‡ã˱pÑ©ï’ÞÎ âe›:Ñö Ðô¥™㼇¼Lîã|$Ý´úyckSE“zAʇ2[øUAK숟"ñ{Ò¿Zñ{ƒõS-¢Šmq(Ëê:¹Ø§eÀOL̪ïŸÇ4¢ÇLÌJ ¤‡V³¨LZë#' akx`¥¬´„|Ý‹K- WÛˆ|ÎÚ&ª!ÚÓ6V`ÙÁ“Ƚ°Ôq³~€>¨ìƒÝ4ÀE˜—'µð¡êŽ,EÎpԣDzuÚl¦Gåz:Ù:E3ÒqmÕ]˜eeÔ¹í^>f·ë|'Ù•vö!·ƒxI‡mbû;ɇw6xC5­ Ï ·…R[«/>¬.jߎ¼mÆ{Òü]òœˆì^yD)yČƛâ=ë³g×€~=Hù‚ìÝȘRNI¨÷iïè8ÔÐüSóÜÑÓÙD²« w1æŒ(ÑhŸåÒ#E{FÖòuìHÏLMÉÞ¾€»+Ò¦N± ‰Hf–¹7 9™P¥!v!müB|Й ÍI  ”ùÞ ù ÐŽ-Æ‹J üÉÒŸàŸ¼»K…4¸Ï†°þFªaãq‰¢IOû˜›`؉:( ]GØ­PÐùZ`”6‹Ñ’?ŽyÃbåð¹Ý®­iAë‡h¬¬2Ö1•ü6ô—Æ”ÍM¾J$ôÏÜåF/¹sÆ©#{ݸEbš÷Ìž`ç]µLà/ÿL:{–»®Ò–Å D¿Æó<='£‘4˜[äßhíØ¿ª%T@Ò¬¼¯£l¼è¾Æþö%m¾Ò—ÂGùgS¯‹!жŒÔÚ¥ðÕdÜnøý:° ëé–U Bw™“+E®~²’7/†Ïcänþ³WÙ:/^;!|©ËXá©2:[6~œ;ÝÝý¾(Eç‘M~ˆ^‰àºÉI¯„mÆÀ–ÄXÓÿå^»gÓÖ'°O…’[û¸dTWtt„þms 9p„ó›&{° ¼«óŒáMwBÌ~dçv¸ˆÏgî’ÐÆ+¾÷V çÛVæ˜hñOû[ÇÍwX~RµxQmh)Ùq²æÜ$t¸L²9/ŸGyß©m‘ÆçÆèWP¼’Ïæî-%,¬4érKhšz…¹ç]ò²Å¤™Ý‚NöQ‘MZýªwgèÊ^êk|Ž>ÂJ:FÁ44Çœ7ËxBé'Ê¥¦=%tØæü!ŸäÐmï†ìÅð¯èvzB&”qèTô'Ö)sÕ‚•]»©¯¿Yáõ1Èž$_mpa½ÕËxÄ¿´r@®LÅ£ 1”gSØå¬9-&3TÒÓSã½ÞrXp0 x”´Dó݆ÿÇUB<w Ñ9ž´8e³ü¶å¦ZŸãLOSÁPUxæÅÇ'Ý|t’WÓ—§ˆ6ø tê¹j7Â#Õ„2©dÿg·ÃãÓ‘ª=˜d˜˜3À­›ñëu0~ÍiË¥¦J¢è£¯(Ü (£F–1jÁþÌ&³&M]_YŽöO† ‡´Ù»T1έ½<šÊCiµÍ‹‹Æ7‡X}øpJz cüèr& “*Eêcv?FÄ'zœd#<éÎ*œ¾ô·?êáVᯒ~«Ú5™X!:IØ]žï€sD4»Õq¶ÇEΡ@ç<í3yõ3­,\ñïx²~š™’fOƒ–ç®ôÆ‚%贒ʴo «0ñ5¿&}Ÿ8ôo.’ŽÃó\ sGmžç~éD¸·ˆC«KÞ¦æ,Óoï 'dËTþh^­¯,^*”ú¾¢®™ñ\eÙuSõ`÷VfŒß·Ðw]ùO^ -9‡–ôebu úÄe~W$êô½qæ ùéjÁ¼Ï4 ¹©ð{Ûär’#Ïîk¶Ýó<ã8ÒÚ{•ü|¬V‡ñžŠÀ ꧺÉÁÐW4 ýhJ=Œ{·“†6Ñþâé.[žt´.)uÛ ¼µÓÜGÜK² /éµý*¯`êøNÅOÉ⃑xÆåí¯o<ŒCÍg¢Í> î¢)£ô…˜ÂÆ.-®ïXEc•ëò– ÇV~æ9ËWÍ”Ò Áð37JÓÚF4qõ/è*ÒŽ™é»SÜSb,›ït9*åկœ=®x¡)üzEs¹s[Ó°:”ÆœE¤©S*^§±–Y “‡4<’ ž§¦B£C»OMR?‰mN¤ž¤°9°·‹µcøµxý%uú0 +v#)S-GÑ'&« ;n²ù=‡¾±ËoôS¤É ¯;È“Âóênoa6µ}dÛ¤^ŒWÀëN¢ç,]ÌtˆT¶ÞvYs&QNˆ" žvSlEq>¥€´Ü Z­‰_ßÓ€•›ó«ˆŽCM”'@ÚÉèOU)—né$¬ð\¯¶Té—‘%p¬KÖÙqaÙ*ABíÙ]/JÐÑRÙŽìîjª›+@ êë·Ãý5týä²zA6yþ£Æ žþÄ?wŸ|·í^hPœT‰?ÄÈ­¥¸„é€B s厃à£Fe 5Ä›{ò%…9)ßðzÆ(i¹ße»s²øóuVìè.QÉ'ß°´)‹vu« ]î„—M,çÖ_;|®¢ßVC¸X»t^ùI$å­ò•Ô®·ýN.®}ø<ù[!ÊYLÐò\ªž¼+’Ÿ¹š!nú°wZFZB¢¡ …4eΫĺÞ% Fцß*ߊ¨g¦„µ3e¼W­81^ÀqUÐWÃ&Ó¬µPSä—ï+P<©Ä‘9ã}3æ¢ùâOw±|ÿø+˲Æ!n™¡°QDyÛË7䋯ˆWÑO¦cäkñîj·H²Š*´¿ïu%½¯ÿ JÒßâ¼šÂ‡Û ±ê‰³ªk&r91jدû©Dö,'P;nî]ÓuËÒÜ$õ¡÷î¨mEkv‰§Q0€Žœkˆú£ò¾ë¡z͹€DŠ,$zfÇÔ³ÜØ"ÅñòDä %¨¶ð­zø‡1ÓðG¹“/ß]×ÂÜSÛÂ÷Ãh~2¿þø¶G\q’wCxÞ°}þÆÇ DjhREZK£IsÊ㇮˜c—39 IÝ»‹9P¼ªú46ƒ0yPì¸3½›»Ñu¦£cEy­›ÎÓñÈòýH,áÆVóWfMÙ[ÿ­Ž(ÝO õ¯;w4»“O s¯äÅ<œ«lÝË"Jî =Ei¢øƒšˆd‰zùMÜšK}ÆÙ¡µºµÊèZX èæ”—è|H¯·\MÛ2J'-BmwE©IT—bóQÃï§^$ΪxÝÂM šåtôßgwñ0ð'U«/³ ’¹rµ¸ûÊ×'¼7¾írÚzÜÒo¨®ìxÄ)š>®dîiËù„½Î,à<®žÇÕú”ˆ •æ'© ˜Ð2kwFëhÖZæÎ¹ÑÀðר´÷ä`„áîmúKuúÍÂ6ö÷˜h‰ŠÑ·©Ð]~2ÚD–uOW©;½ÃÇA€Î¶Ã*ŒËcé­ÚDŸÙ cÕ²%W¸Q: |œù`4`ÜÍFbµå²?šóEÁ‘ùèv'µhñ»ÀkÅp‰îS¬3SÖ8‚&nÑòƒ„A׸†®ÝØ%.Õå‚9vJü"{E¨B—¤UA²ëcÈ)O^F9~ËËG µlìW–™8ÚU›LžOËA%YiŒƌ}oŽßmo*õ–rw¦ÕqIô=Ò­²ý?[«ÿ™ª‡µ´¢+\¿¥!ÃFû.;•PÇæ6îÓŠ©Ìxå· ý3óàAO= zW#w³Kö6¡–1€ÍU«˜¥0]Ív ï‹ —›rµ6ï iõ¶Uµ‚váÈfòuœ¼ØAFU#ƒI^R6Õ^ñÒ‡™ÛtŠò˜M“*æûˆ v.¼â†ÙôqH5?äàˆ%ž§[^…xmªË1›Ç±|ƒjn´›– Êfes äÙ%/ !ÅD>y‡¤Ø/¿'1ÿ^>ffG‰&¾%*±”¦Ïî1'NDÐ2£ `5F%Çåw潈{âÇÖ ùlѳÂ<þ¾ABÙ4syk,ëŽû"Ua:Ði¢úCJ F»Ò@Æ\/÷I‰ …¯Kv‰MÞ–í¹Rÿ† ú—\ªhðËAœÛŸ®*GÙdšwÍ…ÛúÕ“é`ÀI8ê?±›í{$ªœ¸}& ÷ù¦ê_J×ðº§4Çg[Ô¤Íä‡ Ahç[¥Q×OÃâ ö:C¤Ü3Úc{iîSõƒ°Œ´}·n‰ŠŒ$3¢ˆ'ñiQ½œ3”| ¢3þ”‹dÕ}´§äϺ†ù”õmtíÖ–ár"ø# [áS‡ÀE`ay$ ­~&f6']W6‰_båîùÎ jÈØ$·—ªÜ‹~<7ãÜ$¥W‚#ÕØ@„ ¾ø Œ¿X¼0˜Lª:™“¤”`•©1Ÿ‘ëJþ|Ö¾RWå®}¦Èßlà›!oÞŒu¼IAò&“hO;ÀG¨{cÜ‹´£Ü”ý AsøxÆÜ«x< ç4 ÿ¼_ö…$xJqmE+’‘7Ùµ_µ“î½ÎM4 õ0ÞmãQ|Aë)·ÃÃCQÙéOaOÚÎE7Ïä\Žñ|m)¬óÔÉàzÿ*Lz$¶ìùqÙ)™skß}ÆGŒ™K!Yó+ú~7Ï“KHé©|F™£dLžœ½ÿ{¼Ÿ“ôiJ~®ÞëAž¤#³K«CС¿ÍÄŽ>ª)øóÝ3æqKõn«!*OñžjcP^@_Gݠܶ-é5ù—¡ ×x›wÊê̇Ñß‘³Í 0ßåPѤ/íT^eU*P\éÛ9üÃU}î<<ÒERö²# ýàÙø»øÆM¹{IúÉ#5R‡2-wš”<:q¿ÃÜN¶ãäÏä2Q#ÖåöB¥Ào…H1µE? RÏÙ";µ¸ö£æWÛÕã@%ý‡¹sØÎ×ïŽ/õ-ä&Å|Ý‘¨Òˆ—¨qO…˜ïûü 34ø‚l…6‰™+ü’9”5ZN¶%®Ðåh¿%ìÎ`k+ÐüHà@`š†FV6k0=á–ÎÄñ2ää’aøª%g-6ÝT‡!è‚S#3Áû7Ú}áÖ3•Ð|¿caϳ³ÌòÅÆí½Ñ̾²'¾âþÊ Ý–IÓ f¤E ù×ÏÒÇ™O·ßGð"›ë÷’”ô"¨“®íÒ_Óçê„ø[‹¦iÍþH”^­M8’/?FÒ@Š} œ÷€§7A1&?˜ê :nEcï<{j¹B«ƒÕ»µÇ'Ø–½bbJ_J°—Õ½ ø*¦¼Ú÷‘ú.Uã»'QT¢»À• }Ϙâ ;ÈF¨:Æs@œýéçMÆKͶöºMP§‡^Ùøì£\˜¨Æ(zìK§Ú.s{ñi6Y92ÿïÛ£,Hù*& ¡°±‡r¹ÜÞ©)WìgºXüÎÕŒ4Ö©Ná¤>Äö.&ò¾{«Ww÷† +RÂä äÊ*‡iŒG¯ÑeÐID oa!CÄÐ{[#šöð[±!{æ‹^×GejI{Âζä Ý…­Cå"¼ÛêÎŽ;‡ ¼QÙóé´—óÓ‹ëËu}Œš¾èHkÎtŸûÕ<&—!ÆÕ@¹Èws°Y8#6žš(oÎét/¹’9^öE>b¢§ZÉi°–Ž|ÇÂ_¿p¸;8ß÷<"—óúæ}†„ñÕØ±Ä'8½ã¢µ·å³Ðú›Ã«Cw»lÞšÛ&4#ê} Î2çð[´D·¦Êã§Ý±hKoζ¤@ŸÔˆ[n× âütû|ê‚>ïÎ1wä7ãÌJöÚôÏÐ ;vnŸ¹'•˜ë)â#<ôT Ôʼ“J^/Ñ9K`d„‘Ý_úË[£êêjåöéü­D DõЪ ¸™|‚ã+¾åµ› ùF¦„ ?¿½¯ÆAœvrT¢Ô®$E © ¯ßÔôÓÑ5˜~¶¦'F)x9“ý¸¶CìS7 ˜³,åg¼Ôë勉m1"è•wn&~úf¶‡X¨¤,x_ü¾¨×V’««’uRøR:Œß¬µÐí š^ìäF‘Öe£Q\šHÚ©$@BÌ¡_mÍÅÒEùä¤wrkŒNî½…Üó~>é7â+IòýL¼­¯¬‚ä¸nZÄlÙ¼U³qz‹?•¼ó¨}¬ùj‚¢„‘™ºmîHG?‰"¿®èTI¤É®n5"˜ôMøk®9rpà+“…n3dçxîÍIŸŠlŒe¨x²sÞôš°Hü‰³I^7qÏšŒµÞs[ác8⪜V3·Ì¦Zt;áÏï`ÒÛÿ娳>b±+Z«äìòN§¥|W%Êhñ )l° È •7&û)jL U­ŠöÌ \•ò»ø°¢ ‘¡§zpëökÕìô%B”mˆ r Á¼Š¯åÚ“$&ágfÍ^ vš dt´kâI¬Gø*,»Wñþ.@bµPÚ¡èèÂ&0¹÷Ç3-Ã;Æð—¥;-(‡z$MM¢Â¬ñYì7e_m×ú å¾Ý'À½ªÙ “½¤ðÆëƒŸ—û1Æ–Ój`gŸžþTÜSçB±PYKR,ÊÕ&wþV”Øg5H±ÙÚ|sf¥Nû=yˆÜß×4`X”âH‰$¥¡f*/¿Kµt|3 0üé´’¤ø–fØ’ ü^¦iÙÔv>½˜âãþaÃ*+GŒÊbûL‹‡Šåî5[î'ÿ´GãýꥸÓëàÇ•ŒˆIäõ­´\á }ëþAöéhdºŸð€AÓí¨?Sg¤®2åV)üé6.RT|OõòÑýqQ5«@IûᙪO?¼s7"ÿŠJˆ*yâ3âYÛ.÷ü¦-p|QÔîdŽàÉeŠ6õ¹Õrœu–¨Ý §×Î0B˜zYs£MƒÃo³¾ ``°æ^¼È¥eºI¡×m/ëÛXÙ8æç°aíΞì™úæM°Ö¾Ÿz*‹¬Ãý ¾¤ë1r ‰¾‚3»§.O¼˜¢Žë»â¶f‘-":È~ 2Q² yK0Õuà‘yÇÅúÓ, r1¯ŠX#³6Fw $P­º2ÙÊä¾÷´ðl†îØ[ï£&yƒ·Žô`Y¥wEq!µ;+k!>ÿJ¼) endstream endobj 428 0 obj <> endobj 429 0 obj [272 272 311.3 761.6 462.4 462.4 652.8 647 649.9 625.6 704.3 583.3 556.1 652.8 686.3 266.2 459.5 674.2 528.9 849.5 686.3 722.2 622.7 722.2 630.2 544 667.8 666.7 647 919 647 647 598.4 283 489.6 283 489.6 272 272 468.7 502.3 435.2 502.3 435.2 299.2 489.6 502.3 230.3 257.5 475.1 230.3 774.3 502.3 489.6 502.3 502.3 332.8 375.3 353.6 502.3 447.9 665.5 447.9 447.9] endobj 430 0 obj <> endobj 431 0 obj <> /ProcSet [/PDF /Text]>> endobj 432 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 135>> stream xÚ3P0¢t0e äÎef€H]s C=csc…ä\.§.}7# ¸¡ž¥©©‘BHP¹…±ž™¥…BHŠB´F¦®‘¹F~f^Ij‘¦®1ˆ­id¡Q”’Zd¥©kblªQ0×(Iši$Ø•…E`•åš±!^\ ·¸s¹†pZ#< endstream endobj 433 0 obj <> /ProcSet [/PDF /Text]>> endobj 434 0 obj <>/ProcSet [/PDF /Text]>> /Filter /FlateDecode /Length 131>> stream xÚ3P0¢t0e äÎef€H]s C=csc…ä\.§.}7# ¸¡ž¥©©‘BHP¹…±ž™¥…BHŠB´FfIjQbI¾¦‘¹F‘¦®±‘™„’Zd¥©kblª‘”“¯© JΆÈ'ä+Alsd¹Ø/.‹Ü¹\C¸Xæ%5 endstream endobj 435 0 obj << /alpha100 << /CA 0.1 /ca 0.1 >> /alpha100s << /CA 0.1 >> /alpha300 << /CA 0.3 /ca 0.3 >> /alpha300s << /CA 0.3 >> /alpha500 << /CA 0.5 /ca 0.5 >> /alpha500s << /CA 0.5 >> /alpha750 << /CA 0.75 /ca 0.75 >> /alpha750s << /CA 0.75 >> /alpha1000 << /CA 1 /ca 1 >> /alpha1000s << /CA 1 >> >> endobj 436 0 obj << /Type /Pattern /PatternType 1 /PaintType 2 /TilingType 2 /BBox [ 0 0 100 4 ] /XStep 100 /YStep 4 /Resources << >> /Matrix [0.5 -0.866025 0.866025 0.5 0 0] /Length 21 /Filter /FlateDecode >> stream xÚ3P0P04b…¢T…4.U endstream endobj 437 0 obj << /Type /Pattern /PatternType 1 /PaintType 2 /TilingType 2 /BBox [ 0 0 100 4 ] /XStep 100 /YStep 4 /Resources << >> /Matrix [0.866025 0.5 -0.5 0.866025 0 0] /Length 21 /Filter /FlateDecode >> stream xÚ3P0P04b…¢T…4.U endstream endobj 438 0 obj << /Pat103 436 0 R /Pat104 437 0 R >> endobj 439 0 obj << /Length 1958 /Filter /FlateDecode >> stream xښϮô4 Å÷÷)ºf1ĉ?[„@b‡x$@è^!Øðú$m“©œ}Ò§túÇéIíééuÛOm~ü½¹oÿ~¸WL¹Ž3§úq~ûç÷à7Iqûjƒóöùás¾ŒÚÉÏ?¶ß¾ùøyD¢í÷È›_¿X)4ȳ»ŒÚÉé‹5…¶÷œÏ™¹Ï÷ ÛT;Ù¦º%³;É:¸'‰úÂÛèõ=Õ6z`¹'ÛFlåN¶þÿÀ–‘oyÊ×»žo=°Ü/Ù.ß=+=ß6z`SÏ·îÙ¶÷­´o¸}ßÜ ±®é@ÛèõÜÑ:ºG%vTâšz®mtæ‘k~È5yw¢mt†žëq»Ý¡Òsm£ŽÒËŸwqéŠ-è› Ø7H­ïû¦o£5Ó®÷%¶ÑI®+ÖFKä•«ó{›«ÿ¨êôr”¥î­øJA¶_¿¶oø¢íû¿–à ó+e…‹IåŠÁxÂ-0éØ]é]¼6:®Œâ gÁXïóy˵ѱ‹„ù2z,ßA†òxƒÇ^öéîÙÜ÷RݳLý ´Ñ;¶‡§|ùÝ››žÃM‡ÇíÆå)_ J”Œ¦#MGÆý,ñ)_ JÔ¾÷-µï¼û*^Ù£Œ77v¯ã;{_Ç»ò½/äM=߇JÞØ<òÍOùµ|¿ïkycCÏ÷¡˜7Vz¾ëjÎnìE‡j5_SQ­–ñƒGÌžK%nׄû:AAo9»®¨èÿ»ŠéšNœu3Nå5†–&,•–'¬¬jz±˜§UM'7q~µšS<°HþŠùeÿš°°ì_ƨNP3ܬ/W‘b†ËH2䙿¼C¢Žh†óH4Ÿ¯X@¢iŒ‘h(šæ"Ms Ц¹ EÓ\¢).8(šæЦ9EÓ\@¢1_1F¢iLh‹P4Í%(šæ2MsЦ8vP4ÍMsЦ¹EÓ#Ñ¢»b‚DÓXD¢i,AÑ4—¡hš+P4ʼnƒ¢iŽ hšóP4Í(šæЦ9A¢%õØ‘hKH4e(šæ MqÑAÑ4GP4Íy(šæMs EÓœ@Ñ4‘håÚúbB¢i,#Ñ4V hŠKЦ9‚¢iÎCÑ4 hšc(šæЦ¹EÓ\¢%wm})Ñ V€hˉf8B¢Î#Ñ h†c$šá‰f¸ˆD3\B¢.#Ñüµõå‚DSXqH4MsЦ¹EÓCÑ4'P4ÍE(šæMsЦ¹eOµjJ”WÈïç>§Ý¼ñž æã¥†œOØo9_xçê³aŒ¯Pçü<Ê+FÙ‡¿kÎÜÏ6lswö¯îƾ‰Û?«gkÄw°ã¨Ï£B¥‰K“¤–F‹¥5g0ºÃ¤mƒk aœK5V>§l‘ž––ϯîF¯‰Û?kgÃ%Ø~4æY.ÍÓ+W*Öï\Wæç•ÕDzó=‡ë}mûK Ù§–ºÝêô~Ÿù8 kQW << KÔÓí?¥úôÙ§8ÖrÑ®V¬_×j5Šw{ÿtZÞ³ÓûýÔ±¦Ü&$>Ö”éN¬-fwDMfž}õ@©þ¾ùìSË5…´vU¦ròÒVqS=é…à"ŠhÁ#ªçLrF4àTSØ…¥G4Õx¦²§*ÏA–àTæY–|v”zŽæòÌžRÏÑ‚‚r´`D9Z0ÁõŸ}¥‘£ ÌQƒ³³4r4à¬L\nÜÙ[â¼Ü³»Äe¹)fI–o«hv˜˜‘åhÁ„r´`F9Z°ÀõŸm&^ºo4ûL¼ôßh6šdiÀÑì4Éò½Í^“¬ýÕÙm’¥§G³ß4Š”òUh6œF‘2`†ÕC?Í–Óˆ¨ÁÙsÕ)ͦӈh@#í{Ñ€ Kо<³ó4JŠ#,)L°¤0ÃÍ/0G ÎÔÈÑ€s4 ‡9j gjäh@†9P`ŽŒ0G½)f'jähÀ s4`9jpv£xé^ÓlGñÒ¿¦Ù⥃M³!%K ›fGŠ—f-Í–/íZš=)^¶4»R²tliö¥xéMÒìLñÒ¤Ùšâ¥?I³7%Kƒ’fsŠ—VÍî/Í8ší)^Úq4ûS²ôãh6¨dù¾‚f‡J–9Í•,}Yš]*Yz”aŸÑ~ eØg,ûŒ6 (Ã>cAØgìÔ°ÏXö Â>cAØgìb`Ÿ1`}Æ‚°ÏXÞ3f1Þ3„÷Œá=cÁs4‹I0Gf˜£ ÌQÞ9tséÅxG4—Oš³qæW~Åþ·Y»}°ÿU™ñúgÍ_ Oë8z0Ïxøn³)'ñ“pu⎣[óŒ¥,Ì3ÿv..9´¿±= ²g÷,Œ³õ—ðÅ?kGO§î½íUcB÷ÏêÙ|uãö£{-xY8hÞɼ¼àói¡µ‘õÐúgíl¹¸hÁÇgmüÚiý³¯ìpÏúD7^Z Y˜iþí]sp§›ÖFÖN럵³t1ÔågGmÝÚzjý³¯ì0ÒúD7¶ZI/n+¥ðªúêæ‡ÁÚJ¹ý±­æÎzóùrë– endstream endobj 440 0 obj << /Type /Page /Contents 439 0 R /Resources << /ProcSet [/PDF/Text] /ExtGState 435 0 R /ColorSpace << /PCS [/Pattern /DeviceRGB] >> /Pattern 438 0 R /XObject << /Fm1 12 0 R /Fm2 14 0 R /Fm3 16 0 R /Fm4 18 0 R /Fm5 20 0 R /Fm6 22 0 R /Fm7 24 0 R /Fm8 26 0 R /Fm9 28 0 R /Fm10 30 0 R /Fm11 32 0 R /Fm12 34 0 R /Fm13 36 0 R /Fm14 38 0 R /Fm15 40 0 R /Fm16 42 0 R /Fm17 44 0 R /Fm18 46 0 R /Fm19 48 0 R /Fm20 50 0 R /Fm21 52 0 R /Fm22 54 0 R /Fm23 56 0 R /Fm24 58 0 R /Fm25 60 0 R /Fm26 62 0 R /Fm27 64 0 R /Fm28 66 0 R /Fm29 68 0 R /Fm30 70 0 R /Fm31 72 0 R /Fm32 74 0 R /Fm33 76 0 R /Fm34 78 0 R /Fm35 80 0 R /Fm36 82 0 R /Fm37 84 0 R /Fm38 86 0 R /Fm39 88 0 R /Fm40 90 0 R /Fm41 92 0 R /Fm42 94 0 R /Fm43 96 0 R /Fm44 98 0 R /Fm45 100 0 R /Fm46 102 0 R /Fm47 104 0 R /Fm48 106 0 R /Fm49 108 0 R /Fm50 110 0 R /Fm51 112 0 R /Fm52 114 0 R /Fm53 116 0 R /Fm54 118 0 R /Fm55 120 0 R /Fm56 122 0 R /Fm57 124 0 R /Fm58 126 0 R /Fm59 128 0 R /Fm60 130 0 R /Fm61 132 0 R /Fm62 134 0 R /Fm63 136 0 R /Fm64 138 0 R /Fm65 140 0 R /Fm66 142 0 R /Fm67 144 0 R /Fm68 146 0 R /Fm69 148 0 R /Fm70 150 0 R /Fm71 152 0 R /Fm72 154 0 R /Fm73 156 0 R /Fm74 158 0 R /Fm75 160 0 R /Fm76 162 0 R /Fm77 164 0 R /Fm78 166 0 R /Fm79 168 0 R /Fm80 170 0 R /Fm81 172 0 R /Fm82 174 0 R /Fm83 176 0 R /Fm84 178 0 R /Fm85 180 0 R /Fm86 182 0 R /Fm87 184 0 R /Fm88 186 0 R /Fm89 188 0 R /Fm90 190 0 R /Fm91 192 0 R /Fm92 194 0 R /Fm93 196 0 R /Fm94 198 0 R /Fm95 200 0 R /Fm96 202 0 R /Fm97 204 0 R /Fm98 206 0 R /Fm99 208 0 R /Fm100 214 0 R /Fm101 216 0 R /Fm102 218 0 R /Fm103 220 0 R /Fm104 222 0 R /Fm105 224 0 R /Fm106 226 0 R /Fm107 228 0 R /Fm108 230 0 R /Fm109 232 0 R /Fm110 234 0 R /Fm111 236 0 R /Fm112 238 0 R /Fm113 240 0 R /Fm114 242 0 R /Fm115 244 0 R /Fm116 246 0 R /Fm117 248 0 R /Fm118 250 0 R /Fm119 252 0 R /Fm120 254 0 R /Fm121 256 0 R /Fm122 258 0 R /Fm123 260 0 R /Fm124 262 0 R /Fm125 264 0 R /Fm126 266 0 R /Fm127 268 0 R /Fm128 270 0 R /Fm129 272 0 R /Fm130 274 0 R /Fm131 276 0 R /Fm132 278 0 R /Fm133 280 0 R /Fm134 282 0 R /Fm135 284 0 R /Fm136 286 0 R /Fm137 288 0 R /Fm138 290 0 R /Fm139 292 0 R /Fm140 294 0 R /Fm141 296 0 R /Fm142 298 0 R /Fm143 300 0 R /Fm144 302 0 R /Fm145 304 0 R /Fm146 306 0 R /Fm147 308 0 R /Fm148 310 0 R /Fm149 312 0 R /Fm150 314 0 R /Fm151 316 0 R /Fm152 318 0 R /Fm153 320 0 R /Fm154 322 0 R /Fm155 324 0 R /Fm156 326 0 R /Fm157 328 0 R /Fm158 330 0 R /Fm159 332 0 R /Fm160 334 0 R /Fm161 336 0 R /Fm162 338 0 R /Fm163 340 0 R /Fm164 342 0 R /Fm165 344 0 R /Fm166 346 0 R /Fm167 348 0 R /Fm168 350 0 R /Fm169 352 0 R /Fm170 354 0 R /Fm171 356 0 R /Fm172 358 0 R /Fm173 360 0 R /Fm174 362 0 R /Fm175 364 0 R /Fm176 366 0 R /Fm177 368 0 R /Fm178 370 0 R /Fm179 372 0 R /Fm180 374 0 R /Fm181 376 0 R /Fm182 378 0 R /Fm183 380 0 R /Fm184 382 0 R /Fm185 384 0 R /Fm186 386 0 R /Fm187 388 0 R /Fm188 390 0 R /Fm189 392 0 R /Fm190 394 0 R /Fm191 396 0 R /Fm192 398 0 R /Fm193 400 0 R /Fm194 402 0 R /Fm195 404 0 R /Fm196 406 0 R /Fm197 408 0 R /Fm198 410 0 R /Fm199 412 0 R /Fm200 414 0 R /Fm201 416 0 R /Fm202 418 0 R /Fm203 420 0 R /Fm204 422 0 R /Fm205 424 0 R /Fm206 426 0 R /Fm207 432 0 R /Fm208 434 0 R >> >> /MediaBox [ 0 0 595 842] /CropBox [10.766 556.385 592.6 785.307] /ArtBox [10.766 556.385 592.6 785.307] /Parent 2 0 R >> endobj 1 0 obj << /Type /Ipe /Length 3315 /Filter /FlateDecode >> stream xÚí]MoãȽûWì$÷7ÉÅØ@€Ù{Ê5Ζi‰0%j)zfœÁæ·§»IñC¢Ü%M;) ¤f³X|U,òu7GÏŸ²]|NË}Vlïf!a”Í‚e™&UQÞÍþ®w† ¶Ð÷7Ÿ²ísQïKŸîfù…Fˆ"1%LR9 6ÅSöœì ÝšÃwé¾zËÓ`›lÒ»Ùc²Ï–ÆíþmóXäMoR–Å—Û¤\þ´ß}ýÙìÞ%Õ:ØWeñ¢wkÛyÝžÏYž{vé¶îÐ }( H°¹™Ó€,8çAnšóC{}óéÖ¸Ög¸­ŒCy¾Ë—uV}Œ]õQ9!‹H÷]™œ‹`AÓs¢MR¾Ü.³r™§?í5ž *“íþ¹(7I¥‹{7³y½ÕÂ=ɘF´PAuøNuhzDÓBó”í_¼cù¹>õ3èÜ«²xÝb0-‹@6ä1‚qж§|Í5–´h\’Ò ÷"|,¾~WjÇPÎ <û±¹i›y Þ¶æ]sm6D`?67m3¯³­y×–ïþ÷פüÞò½, X9€ù(¨¹©$û±¹i›y]g¶5ïšëkŠís!Eº,‹ýx9Ï$­Y·É ëÄ…í±Py`;êÜ…Á¼ÙãLßÁmßë¼ïv>ð{êÖ•††'¶&ðÙV_2éeÀ>–KkLy¶M“ÒèD{úÅ3<70OÅë£áñ¬³ÃìgÝ~vyŽ.zý`õ ´Úou&Ÿ³´œŸ“üUo뢰#òÎâ9©Ú½tÁŽö¾æúaÕ7© ê3í³†ôyR®ÒÖHŽíõƒ wyª²í[P=°?{:JF†§“£6ƒ³qk²,ò¢lv—éSw3X9±X•©¾ˆmz:bó¨÷õL´Ñ‰É[šçÅ—Þ¹Æüš7úa"á¨"à^DæAb¶{-wyÙB1ó §Ìpp,èH°É[Ï<ò4Vßmߥ°.•¬?Oì·Éç·An4Ûv 5Û¾ " ¥¡®0V'¦û49º( ·Â`à#aU¯åï¯E¶ï§BÏkMÞBsdDOÏò9+ò´êsË¥æ(Ý<±Òƒ‚“:° FM—oI¿ªèÏ™]¥ø³a±êtÄl¤0Œí&Y¥Û*éyµÞ1RžRÄgÜ÷ï¬Öõ‰ež­ÖÕ0m U_[WñH©Øc†ù³×‘ŽÜvÖö(y ÏÙ «JÚ¢n®ûHiÛƒÆnlÇZ?%ûuaÄl÷òòOñ¯&''†EUõ iÀÏšêíàØ^La®cÎ×?¶J¿VgŸÌõæˆÝoC»ßÎÚýùûkÏÎnŽØ­_ûîìÖˆÕ¯«_ÏX ‰ã¡Þ±{.Šj[T=‡c4vÄ€nìVkÕËÿRßy†´ÓU¦‡ öû[ÝûÇ,H·OºS¶]cNôÀhc`yiºnÚ¾s~Î9y0oç}­Ê쩾vÕ¾_Œ™DÆ$øé?z ¹ù¹5ÆL©jlÕÀ¶yXsÖS6°ælÔ59À0sÕ¾s2fÎæáÀ˜SÑyM;äC#¸͈<†D4MˇÇËFfârÊ£ B#Ìá ¦'鎷1Á®Ð]úŒ9W½íì ÷1ÍÛZ¼ˆŸëÔŒ‘ô‘ ÉéL^wf'±Çlµµÿç!5«ê³û‡ýóÃZº¶U±ùFþÐÿ>Ýèç" 1ú¨#.чÀ!HŠ>îA…èC]£ 3 øÀiÉÀ½ßiIãÚÃŒE¾ÆªœøÒsîk¬Ê¥¯«ÂcÊ<ÏXÜ./ž±8]^>cqº¼xÆñxÙŒâÑÃŒ%Â?e‘Ž‘fl¦,1æ”kÒE%öBWœb!r… Bì!Ä®G%Ž {™F!"̰N‚4¬Œ Ík!è@ Àê:Ðò}ÐÊQÁØèHø¸PG@ŽÇ…:Ò:*ÔŒ™j cò"ÂÌ€LŽ 429*ÐÈä¨@K “£­€LŽ tdrT #(“£BC™jN LŽ 5…29*Ô ÆäR"ÂÌLŽ ´29*ÐÈä¨@+ “£™èÈä¨@ÇP&Ç„Z(“£BM¡LŽ 5ƒ29*ÔÆäq è5Y\Šªœqì!8U ÆŸÐ_¤¨Ú^¼!pðUÀôCÂsŠªŽ«€6—Úç“—ãròrc<œ¼Ü&/7ÖÞ ¸a°ü'%8ÖVü´Ç¢p‚’c]]c¢)* u µ„Ö5*Ô ZרP;ÖøA)éxá%(Æ—KvLpŒƒ,—ì˜ÇU.Ù±¶®q‰¥1`]ãBÍu µÖ5.ÔZ×S8õBh]OI~LàÔÔsq£Â8õuÉ ”¢¾.ù1RÀÐ)?F uË›“R #Âï’ ër µ‚æÓÏ]"d]®Q¡Ž ¹Æôƒ— Y—kL¨]2dÝŠÙ”dȺ³)Éu+f“’!‹PJ¾ h]OK‰lŠRd]]OI‹¬«ë)‰‘uu‰ÑE ­kTr1ZרPSh]£BÍ uiô$9´®Q¡кF…ZBëj] Æ4zrI’ ”Šì.M2R’Ý%J&Pj²»TɺºÆ4zrÉ’ ”úÄ.Y2R Ø%K&P*»dɺºž’,™@©Öé&(å:]Êd¥^§Kš¬«ë)i“ ”Úu.q2R¼Î¥N&Pª×¹äÉÊ?ã’'(…ð]òd¥è¯KžLà8„¾oœ’@Yû lR eáþCèËFTb2ÐwS)k—ø¦¤RÖ®ðMI¦¬]à›’LY[Ó¨nDèkFT ¡oQ†¾dœ’PY;WDu#B§Š˜@ÇЙ"*ÐЉ"*Ð XÓSR+t‚re‚OP®LÈ Ê• Œ¢¿.¹2RêÐ%Wfd¶~È•ý?äÊ™ÿ!Wöareïgþ‡\ÙÇÈ•9²þC®ìCäÊæ:2"2˜G°”R¦Ï PN)“ ªh—ÕhÁIئ•-8;ŸÙ<)WuZŸ“M–¿=ìóý:Ù¥ßvE¶­Ò2(ʧ´ü%ÐéßÌ—Cû…)±Qô1‘ =ÊfÂs¤™3©Š6ÔǼX¾˜`m£ W_êUj¾³þú/›ÏÉ  endstream endobj 2 0 obj << /Type /Pages /Count 1 /Kids [ 440 0 R ] >> endobj 441 0 obj <> >> endobj 442 0 obj << /Type /Catalog /Pages 2 0 R /PieceInfo 441 0 R >> endobj 443 0 obj << /Creator (Ipe 7.2.12) /Producer (Ipe 7.2.12) /CreationDate (D:20200609102515) /ModDate (D:20200609102701) >> endobj xref 0 444 0000000000 00000 f 0000108606 00000 n 0000112005 00000 n 0000000003 00000 f 0000000004 00000 f 0000000005 00000 f 0000000006 00000 f 0000000009 00000 n 0000008288 00000 n 0000008549 00000 n 0000008606 00000 n 0000008742 00000 n 0000008806 00000 n 0000009109 00000 n 0000009173 00000 n 0000009476 00000 n 0000009540 00000 n 0000009843 00000 n 0000009907 00000 n 0000010210 00000 n 0000010274 00000 n 0000010577 00000 n 0000010641 00000 n 0000010944 00000 n 0000011008 00000 n 0000011311 00000 n 0000011375 00000 n 0000011678 00000 n 0000011742 00000 n 0000012045 00000 n 0000012109 00000 n 0000012412 00000 n 0000012476 00000 n 0000012775 00000 n 0000012839 00000 n 0000013138 00000 n 0000013202 00000 n 0000013501 00000 n 0000013565 00000 n 0000013864 00000 n 0000013928 00000 n 0000014227 00000 n 0000014291 00000 n 0000014590 00000 n 0000014654 00000 n 0000014953 00000 n 0000015017 00000 n 0000015316 00000 n 0000015380 00000 n 0000015679 00000 n 0000015743 00000 n 0000016042 00000 n 0000016106 00000 n 0000016405 00000 n 0000016469 00000 n 0000016768 00000 n 0000016832 00000 n 0000017131 00000 n 0000017195 00000 n 0000017494 00000 n 0000017558 00000 n 0000017857 00000 n 0000017921 00000 n 0000018220 00000 n 0000018284 00000 n 0000018583 00000 n 0000018647 00000 n 0000018946 00000 n 0000019010 00000 n 0000019309 00000 n 0000019373 00000 n 0000019672 00000 n 0000019736 00000 n 0000020035 00000 n 0000020099 00000 n 0000020398 00000 n 0000020462 00000 n 0000020761 00000 n 0000020825 00000 n 0000021124 00000 n 0000021188 00000 n 0000021487 00000 n 0000021551 00000 n 0000021850 00000 n 0000021914 00000 n 0000022213 00000 n 0000022277 00000 n 0000022576 00000 n 0000022640 00000 n 0000022939 00000 n 0000023003 00000 n 0000023302 00000 n 0000023366 00000 n 0000023665 00000 n 0000023729 00000 n 0000024028 00000 n 0000024092 00000 n 0000024391 00000 n 0000024455 00000 n 0000024754 00000 n 0000024818 00000 n 0000025118 00000 n 0000025183 00000 n 0000025483 00000 n 0000025548 00000 n 0000025848 00000 n 0000025913 00000 n 0000026213 00000 n 0000026278 00000 n 0000026578 00000 n 0000026643 00000 n 0000026943 00000 n 0000027008 00000 n 0000027308 00000 n 0000027373 00000 n 0000027673 00000 n 0000027738 00000 n 0000028038 00000 n 0000028103 00000 n 0000028403 00000 n 0000028468 00000 n 0000028768 00000 n 0000028833 00000 n 0000029133 00000 n 0000029198 00000 n 0000029498 00000 n 0000029563 00000 n 0000029863 00000 n 0000029928 00000 n 0000030228 00000 n 0000030293 00000 n 0000030593 00000 n 0000030658 00000 n 0000030958 00000 n 0000031023 00000 n 0000031323 00000 n 0000031388 00000 n 0000031688 00000 n 0000031753 00000 n 0000032053 00000 n 0000032118 00000 n 0000032418 00000 n 0000032483 00000 n 0000032783 00000 n 0000032848 00000 n 0000033148 00000 n 0000033213 00000 n 0000033513 00000 n 0000033578 00000 n 0000033878 00000 n 0000033943 00000 n 0000034243 00000 n 0000034308 00000 n 0000034608 00000 n 0000034673 00000 n 0000034973 00000 n 0000035038 00000 n 0000035338 00000 n 0000035403 00000 n 0000035703 00000 n 0000035768 00000 n 0000036068 00000 n 0000036133 00000 n 0000036433 00000 n 0000036498 00000 n 0000036798 00000 n 0000036863 00000 n 0000037163 00000 n 0000037228 00000 n 0000037528 00000 n 0000037593 00000 n 0000037893 00000 n 0000037958 00000 n 0000038258 00000 n 0000038323 00000 n 0000038623 00000 n 0000038688 00000 n 0000038988 00000 n 0000039053 00000 n 0000039353 00000 n 0000039418 00000 n 0000039718 00000 n 0000039783 00000 n 0000040083 00000 n 0000040148 00000 n 0000040448 00000 n 0000040513 00000 n 0000040813 00000 n 0000040878 00000 n 0000041178 00000 n 0000041243 00000 n 0000041543 00000 n 0000041608 00000 n 0000041908 00000 n 0000041973 00000 n 0000042273 00000 n 0000042338 00000 n 0000042638 00000 n 0000042703 00000 n 0000043003 00000 n 0000043068 00000 n 0000043368 00000 n 0000043433 00000 n 0000043733 00000 n 0000043798 00000 n 0000044098 00000 n 0000044163 00000 n 0000044463 00000 n 0000044528 00000 n 0000044828 00000 n 0000052294 00000 n 0000052526 00000 n 0000052599 00000 n 0000052739 00000 n 0000052805 00000 n 0000053103 00000 n 0000053169 00000 n 0000053467 00000 n 0000053533 00000 n 0000053830 00000 n 0000053896 00000 n 0000054194 00000 n 0000054259 00000 n 0000054563 00000 n 0000054628 00000 n 0000054932 00000 n 0000054997 00000 n 0000055301 00000 n 0000055366 00000 n 0000055670 00000 n 0000055735 00000 n 0000056039 00000 n 0000056104 00000 n 0000056408 00000 n 0000056473 00000 n 0000056777 00000 n 0000056842 00000 n 0000057146 00000 n 0000057211 00000 n 0000057515 00000 n 0000057580 00000 n 0000057884 00000 n 0000057949 00000 n 0000058249 00000 n 0000058314 00000 n 0000058614 00000 n 0000058679 00000 n 0000058979 00000 n 0000059044 00000 n 0000059344 00000 n 0000059409 00000 n 0000059709 00000 n 0000059774 00000 n 0000060074 00000 n 0000060139 00000 n 0000060439 00000 n 0000060504 00000 n 0000060804 00000 n 0000060869 00000 n 0000061169 00000 n 0000061234 00000 n 0000061534 00000 n 0000061599 00000 n 0000061899 00000 n 0000061964 00000 n 0000062264 00000 n 0000062329 00000 n 0000062629 00000 n 0000062694 00000 n 0000062994 00000 n 0000063059 00000 n 0000063359 00000 n 0000063424 00000 n 0000063724 00000 n 0000063789 00000 n 0000064089 00000 n 0000064154 00000 n 0000064454 00000 n 0000064519 00000 n 0000064819 00000 n 0000064884 00000 n 0000065184 00000 n 0000065249 00000 n 0000065549 00000 n 0000065614 00000 n 0000065914 00000 n 0000065979 00000 n 0000066279 00000 n 0000066344 00000 n 0000066644 00000 n 0000066709 00000 n 0000067009 00000 n 0000067074 00000 n 0000067374 00000 n 0000067439 00000 n 0000067739 00000 n 0000067804 00000 n 0000068104 00000 n 0000068169 00000 n 0000068469 00000 n 0000068534 00000 n 0000068834 00000 n 0000068899 00000 n 0000069199 00000 n 0000069264 00000 n 0000069564 00000 n 0000069629 00000 n 0000069929 00000 n 0000069994 00000 n 0000070294 00000 n 0000070359 00000 n 0000070659 00000 n 0000070724 00000 n 0000071024 00000 n 0000071089 00000 n 0000071389 00000 n 0000071454 00000 n 0000071754 00000 n 0000071819 00000 n 0000072119 00000 n 0000072184 00000 n 0000072484 00000 n 0000072549 00000 n 0000072849 00000 n 0000072914 00000 n 0000073214 00000 n 0000073279 00000 n 0000073579 00000 n 0000073644 00000 n 0000073944 00000 n 0000074009 00000 n 0000074309 00000 n 0000074374 00000 n 0000074674 00000 n 0000074739 00000 n 0000075039 00000 n 0000075104 00000 n 0000075404 00000 n 0000075469 00000 n 0000075769 00000 n 0000075834 00000 n 0000076134 00000 n 0000076199 00000 n 0000076499 00000 n 0000076564 00000 n 0000076864 00000 n 0000076929 00000 n 0000077229 00000 n 0000077294 00000 n 0000077594 00000 n 0000077659 00000 n 0000077959 00000 n 0000078024 00000 n 0000078324 00000 n 0000078389 00000 n 0000078689 00000 n 0000078754 00000 n 0000079054 00000 n 0000079119 00000 n 0000079419 00000 n 0000079484 00000 n 0000079784 00000 n 0000079849 00000 n 0000080149 00000 n 0000080214 00000 n 0000080514 00000 n 0000080579 00000 n 0000080879 00000 n 0000080944 00000 n 0000081244 00000 n 0000081309 00000 n 0000081609 00000 n 0000081674 00000 n 0000081974 00000 n 0000082039 00000 n 0000082339 00000 n 0000082404 00000 n 0000082704 00000 n 0000082769 00000 n 0000083069 00000 n 0000083134 00000 n 0000083434 00000 n 0000083499 00000 n 0000083799 00000 n 0000083864 00000 n 0000084164 00000 n 0000084229 00000 n 0000084529 00000 n 0000084594 00000 n 0000084894 00000 n 0000084959 00000 n 0000085259 00000 n 0000085324 00000 n 0000085624 00000 n 0000085689 00000 n 0000085989 00000 n 0000086054 00000 n 0000086354 00000 n 0000086419 00000 n 0000086719 00000 n 0000086784 00000 n 0000087084 00000 n 0000087149 00000 n 0000087449 00000 n 0000087514 00000 n 0000087814 00000 n 0000087879 00000 n 0000088179 00000 n 0000088244 00000 n 0000088544 00000 n 0000088609 00000 n 0000088909 00000 n 0000088974 00000 n 0000089274 00000 n 0000089339 00000 n 0000089639 00000 n 0000089704 00000 n 0000090004 00000 n 0000090069 00000 n 0000090369 00000 n 0000090435 00000 n 0000090733 00000 n 0000090799 00000 n 0000091097 00000 n 0000091163 00000 n 0000091460 00000 n 0000091526 00000 n 0000091824 00000 n 0000100803 00000 n 0000101058 00000 n 0000101437 00000 n 0000101580 00000 n 0000101646 00000 n 0000102006 00000 n 0000102072 00000 n 0000102428 00000 n 0000102735 00000 n 0000102984 00000 n 0000103233 00000 n 0000103288 00000 n 0000105321 00000 n 0000112066 00000 n 0000112142 00000 n 0000112212 00000 n trailer << /Size 444 /Root 442 0 R /Info 443 0 R >> startxref 112341 %%EOF zfp-1.0.1/docs/source/views.inc000066400000000000000000001077061453723256400164160ustar00rootroot00000000000000.. index:: single: Views .. _views: Views ----- .. cpp:namespace:: zfp |zfp| |viewsrelease| adds array views. Much like how :ref:`references ` allow indirect access to single array elements, *views* provide indirect access to whole arrays, or more generally to rectangular subsets of arrays. A view of an array does not allocate any storage for the array elements. Rather, the view accesses shared storage managed by the underlying array. This allows for multiple entries into an array without the need for expensive deep copies. In a sense, views can be thought of as *shallow copies* of arrays. When a view exposes a whole array :code:`array`, it provides similar functionality to a C++ reference :code:`array&` or pointer :code:`array*` to the array. However, views are more general in that they also allow restricting access to a user-specified subset of the array, and unlike pointers also provide for the same syntax when accessing the array, e.g., :code:`array_view(i, j)` instead of :code:`(*array_ptr)(i, j)`. |zfp|'s *nested views* further provide for multidimensional array access analogous to the C/C++ nested array syntax :code:`array[i][j]`. Finally, |zfp|'s *private views* can be used to ensure thread-safe access to its compressed arrays. Access to array elements through a view is via inspectors and mutators that return a :code:`const_reference` or :code:`reference`, respectively (see :ref:`references`). As of |zfp| |crpirelease|, it is also possible to obtain pointers to array elements through views and to iterate over them. View pointers and iterators allow referencing only the elements visible through the view, e.g., a rectangular subset of an array (see :numref:`view-indexing`). Those elements are indexed as if the view were a contiguous array, and pointer arithmetic assumes that the possibly smaller view and not the underlying array is flattened. :ref:`Private views ` maintain their own cache and therefore implement their own proxy references, pointers, and iterators. .. _view-indexing: .. figure:: view-indexing.pdf :figwidth: 90 % :align: center :alt: "2D view indexing" An 11 |times| 9 element view of a 2D array of dimensions 16 |times| 12. The numbered elements indicate the order in which the view is traversed using pointers and iterators. We have :code:`view(10, 7) == (&view(0, 0))[87] == view.begin()[97] == view.end()[-2]`. With the |zfp| |carrrelease| release of :ref:`read-only arrays `, such arrays also support the two kinds of immutable views (:code:`const_view` and :code:`private_const_view`). The documentation below applies to views into read-only arrays as well. .. note:: Like iterators and proxy references and pointers, a view is valid only during the lifetime of the array that it references. **No reference counting** is done to keep the array alive. It is up to the user to ensure that the referenced array object is valid when accessed through a view. There are several types of views distinguished by these attributes: * Read-only vs. read-write access. * Shared vs. private access. * Flat vs. nested indexing. Each of these attributes is discussed in detail below in these sections: * :ref:`immutable_view` * :ref:`mutable_view` * :ref:`flat_view` * :ref:`nested_view` * :ref:`slicing` * :ref:`private_immutable_view` * :ref:`private_mutable_view` .. _immutable_view: Immutable view ^^^^^^^^^^^^^^ The most basic view is the immutable :code:`const_view`, which supports read-only access to the array elements it references. This view serves primarily as a base class for more specialized views. Its constructors allow establishing access to a whole array or to a rectangular subset of an array. Note that like references, pointers, and iterators, views are types nested within the arrays that they reference. .. .. cpp:class:: template array1::const_view .. cpp:class:: template array2::const_view .. cpp:class:: template array3::const_view .. cpp:class:: template array4::const_view .. cpp:class:: array1::const_view .. cpp:class:: array2::const_view .. cpp:class:: array3::const_view .. cpp:class:: array4::const_view Immutable view into 1D, 2D, 3D, and 4D array. ---- .. _view_ctor: .. cpp:function:: array1::const_view::const_view(array1* array) .. cpp:function:: array2::const_view::const_view(array2* array) .. cpp:function:: array3::const_view::const_view(array3* array) .. cpp:function:: array4::const_view::const_view(array4* array) Constructor for read-only access to a whole array. As already mentioned, these views are valid only during the lifetime of the underlying array object. ---- .. cpp:function:: array1::const_view::const_view(array1* array, size_t x, size_t nx) .. cpp:function:: array2::const_view::const_view(array2* array, size_t x, size_t y, size_t nx, size_t ny) .. cpp:function:: array3::const_view::const_view(array3* array, size_t x, size_t y, size_t z, size_t nx, size_t ny, size_t nz) .. cpp:function:: array4::const_view::const_view(array4* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw) Constructors for read-only access to a rectangular subset of an array. The subset is specified by an offset, e.g., (*x*, *y*, *z*) for a 3D array, and dimensions, e.g., (*nx*, *ny*, *nz*) for a 3D array. The rectangle must fit within the surrounding array. ---- .. cpp:function:: size_t array1::const_view::global_x(size_t i) const .. cpp:function:: size_t array2::const_view::global_x(size_t i) const .. cpp:function:: size_t array2::const_view::global_y(size_t j) const .. cpp:function:: size_t array3::const_view::global_x(size_t i) const .. cpp:function:: size_t array3::const_view::global_y(size_t j) const .. cpp:function:: size_t array3::const_view::global_z(size_t k) const .. cpp:function:: size_t array4::const_view::global_x(size_t i) const .. cpp:function:: size_t array4::const_view::global_y(size_t j) const .. cpp:function:: size_t array4::const_view::global_z(size_t k) const .. cpp:function:: size_t array4::const_view::global_w(size_t l) const Return global array index associated with local view index. For instance, if a 1D view has been constructed with offset *x*, then :code:`global_x(i)` returns *x* + *i*. ---- .. cpp:function:: size_t array1::const_view::size_x() const .. cpp:function:: size_t array2::const_view::size_x() const .. cpp:function:: size_t array2::const_view::size_y() const .. cpp:function:: size_t array3::const_view::size_x() const .. cpp:function:: size_t array3::const_view::size_y() const .. cpp:function:: size_t array3::const_view::size_z() const .. cpp:function:: size_t array4::const_view::size_x() const .. cpp:function:: size_t array4::const_view::size_y() const .. cpp:function:: size_t array4::const_view::size_z() const .. cpp:function:: size_t array4::const_view::size_w() const Return dimensions of view. ---- .. _view_accessor: .. cpp:function:: const_reference array1::const_view::operator()(size_t i) const .. cpp:function:: const_reference array2::const_view::operator()(size_t i, size_t j) const .. cpp:function:: const_reference array3::const_view::operator()(size_t i, size_t j, size_t k) const .. cpp:function:: const_reference array4::const_view::operator()(size_t i, size_t j, size_t k, size_t l) const Return reference to scalar stored at multi-dimensional index given by *x* + *i*, *y* + *j*, *z* + *k*, and *w* + *l*, where *x*, *y*, *z*, and *w* specify the offset into the array. ---- .. cpp:function:: const_reference array1::const_view::operator[](size_t index) const Alternative inspector for 1D arrays identical to :cpp:func:`array1::const_view::operator()`. ---- .. cpp:function:: array1::const_view::const_iterator array1::const_view::begin() const .. cpp:function:: array2::const_view::const_iterator array2::const_view::begin() const .. cpp:function:: array3::const_view::const_iterator array3::const_view::begin() const .. cpp:function:: array4::const_view::const_iterator array4::const_view::begin() const .. cpp:function:: array1::const_view::const_iterator array1::const_view::cbegin() const .. cpp:function:: array2::const_view::const_iterator array2::const_view::cbegin() const .. cpp:function:: array3::const_view::const_iterator array3::const_view::cbegin() const .. cpp:function:: array4::const_view::const_iterator array4::const_view::cbegin() const Random-access const iterator to first element of view. ---- .. cpp:function:: array1::const_view::const_iterator array1::const_view::end() const .. cpp:function:: array2::const_view::const_iterator array2::const_view::end() const .. cpp:function:: array3::const_view::const_iterator array3::const_view::end() const .. cpp:function:: array4::const_view::const_iterator array4::const_view::end() const .. cpp:function:: array1::const_view::const_iterator array1::const_view::cend() const .. cpp:function:: array2::const_view::const_iterator array2::const_view::cend() const .. cpp:function:: array3::const_view::const_iterator array3::const_view::cend() const .. cpp:function:: array4::const_view::const_iterator array4::const_view::cend() const Random-access const iterator to end of view. There are a number of common methods inherited from a base class, :code:`preview`, further up the class hierarchy. .. cpp:function:: double arrayANY::const_view::rate() const Return rate in bits per value. Same as :cpp:func:`array::rate`. ---- .. cpp:function:: size_t arrayANY::const_view::size() const Total number of elements in view, e.g., *nx* |times| *ny* |times| *nz* for 3D views. With the above definitions, the following example shows how a 2D view is constructed and accessed:: zfp::array2d a(200, 100, rate); // define 200x100 array of doubles zfp::array2d::const_view v(&a, 10, 5, 20, 20); // v is a 20x20 view into array a assert(v(2, 1) == a(12, 6)); // v(2, 1) == a(10 + 2, 5 + 1) == a(12, 6) assert(v.size() == 400); // 20x20 == 400 .. _mutable_view: Mutable view ^^^^^^^^^^^^ The basic mutable :code:`view` derives from the :code:`const_view` but adds operators for write-access. Its constructors are similar to those for the :code:`const_view`. .. .. cpp:class:: template array1::view .. cpp:class:: template array2::view .. cpp:class:: template array3::view .. cpp:class:: template array4::view .. cpp:class:: array1::view : public array1::const_view .. cpp:class:: array2::view : public array2::const_view .. cpp:class:: array3::view : public array3::const_view .. cpp:class:: array4::view : public array4::const_view Mutable view into 1D, 2D, 3D, and 4D array. ---- .. cpp:function:: array1::view::view(array1* array) .. cpp:function:: array2::view::view(array2* array) .. cpp:function:: array3::view::view(array3* array) .. cpp:function:: array4::view::view(array4* array) .. cpp:function:: array1::view::view(array1* array, size_t x, size_t nx) .. cpp:function:: array2::view::view(array2* array, size_t x, size_t y, size_t nx, size_t ny) .. cpp:function:: array3::view::view(array3* array, size_t x, size_t y, size_t z, size_t nx, size_t ny, size_t nz) .. cpp:function:: array4::view::view(array4* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw) Whole-array and sub-array mutable view constructors. See :ref:`const_view constructors ` for details. ---- .. cpp:function:: reference array1::view::operator()(size_t i) .. cpp:function:: reference array2::view::operator()(size_t i, size_t j) .. cpp:function:: reference array3::view::operator()(size_t i, size_t j, size_t k) .. cpp:function:: reference array4::view::operator()(size_t i, size_t j, size_t k, size_t l) These operators, whose arguments have the same meaning as in the :ref:`array accessors `, return :ref:`proxy references ` to individual array elements for write access. .. _flat_view: Flat view ^^^^^^^^^ The views discussed so far require multidimensional indexing, e.g., (*i*, *j*, *k*) for 3D views. Some applications prefer one-dimensional linear indexing, which is provided by the specialized flat view. For example, in a 3D view with dimensions (*nx*, *ny*, *nz*), a multidimensional index (*i*, *j*, *k*) corresponds to the flat view index :: index = i + nx * (j + ny * k) This is true regardless of the view offset (*x*, *y*, *z*). The flat view derives from the mutable view and adds :code:`operator[]` for flat indexing. This operator is essentially equivalent to :cpp:func:`array::operator[]` defined for 2D, 3D, and 4D arrays. Flat views also provide functions for converting between multidimensional and flat indices. Flat views are available only for 2D, 3D, and 4D arrays. The basic mutable view, :cpp:class:`array1::view`, for 1D arrays can be thought of as either a flat or a nested view. .. .. cpp:class:: template array2::flat_view .. cpp:class:: template array3::flat_view .. cpp:class:: template array4::flat_view .. cpp:class:: array2::flat_view : public array2::view .. cpp:class:: array3::flat_view : public array3::view .. cpp:class:: array4::flat_view : public array4::view Flat, mutable views for 2D, 3D, and 4D arrays. ---- .. cpp:function:: array2::flat_view::flat_view(array2* array) .. cpp:function:: array3::flat_view::flat_view(array3* array) .. cpp:function:: array4::flat_view::flat_view(array4* array) .. cpp:function:: array2::flat_view::flat_view(array2* array, size_t x, size_t y, size_t nx, size_t ny) .. cpp:function:: array3::flat_view::flat_view(array3* array, size_t x, size_t y, size_t z, size_t nx, size_t ny, size_t nz) .. cpp:function:: array4::flat_view::flat_view(array4* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw) Whole-array and sub-array flat view constructors. See :ref:`const_view constructors ` for details. ---- .. cpp:function:: size_t array2::flat_view::index(size_t i, size_t j) const .. cpp:function:: size_t array3::flat_view::index(size_t i, size_t j, size_t k) const .. cpp:function:: size_t array4::flat_view::index(size_t i, size_t j, size_t k, size_t l) const Return flat index associated with multidimensional index. ---- .. cpp:function:: void array2::flat_view::ij(size_t& i, size_t& j, size_t index) const .. cpp:function:: void array3::flat_view::ijk(size_t& i, size_t& j, size_t& k, size_t index) const .. cpp:function:: void array4::flat_view::ijkl(size_t& i, size_t& j, size_t& k, size_t& l, size_t index) const Convert flat index to multidimensional index. ---- .. cpp:function:: const_reference array2::flat_view::operator[](size_t index) const .. cpp:function:: const_reference array3::flat_view::operator[](size_t index) const .. cpp:function:: const_reference array4::flat_view::operator[](size_t index) const Return array element associated with given flat index. ---- .. cpp:function:: reference array2::flat_view::operator[](size_t index) .. cpp:function:: reference array3::flat_view::operator[](size_t index) .. cpp:function:: reference array4::flat_view::operator[](size_t index) Return reference to array element associated with given flat index. .. _nested_view: Nested view ^^^^^^^^^^^ C and C++ support nested arrays (arrays of arrays), e.g., :code:`double a[10][20][30]`, which are usually accessed via nested indexing :code:`a[i][j][k]`. Here :code:`a` is a 3D array, :code:`a[i]` is a 2D array, and :code:`a[i][j]` is a 1D array. This 3D array can also be accessed via flat indexing, e.g., :: a[i][j][k] == (&a[0][0][0])[600 * i + 30 * j + k] Nested views provide a mechanism to access array elements through nested indexing and to extract lower-dimensional "slices" of multidimensional arrays. Nested views are mutable. Nested views are associated with a dimensionality. For instance, if :code:`v` is a 3D nested view of a 3D array, then :code:`v[i]` is a 2D nested view (of a 3D array), :code:`v[i][j]` is a 1D nested view (of a 3D array), and :code:`v[i][j][k]` is a (reference to a) scalar array element. Note that the order of indices is reversed when using nested indexing compared to multidimensional indexing, e.g., :code:`v(i, j, k) == v[k][j][i]`. Whereas :code:`operator[]` on an array object accesses an element through flat indexing, the same array can be accessed through a nested view to in effect provide nested array indexing:: zfp::array3d a(30, 20, 10, rate); // define 30x20x10 3D array assert(a[32] == a(2, 1, 0)); // OK: flat and multidimensional indexing assert(a[32] == a[0][1][2]); // ERROR: a does not support nested indexing zfp::array3d::nested_view v(&a); // define a nested view of a assert(a[32] == v[0][1][2]); // OK: v supports nested indexing zfp::array2d b(v[5]); // define and deep copy 30x20 2D slice of a assert(a(2, 1, 5) == b(2, 1)); // OK: multidimensional indexing .. .. cpp:class:: template array2::nested_view1 .. cpp:class:: array2::nested_view1 View of a 1D slice of a 2D array. ---- .. .. cpp:class:: template array2::nested_view2 .. cpp:class:: array2::nested_view2 2D view of a 2D (sub)array. ---- .. .. cpp:class:: template array3::nested_view1 .. cpp:class:: array3::nested_view1 View of a 1D slice of a 3D array. ---- .. .. cpp:class:: template array3::nested_view2 .. cpp:class:: array3::nested_view2 View of a 2D slice of a 3D array. ---- .. .. cpp:class:: template array3::nested_view3 .. cpp:class:: array3::nested_view3 3D view of a 3D (sub)array. ---- .. .. cpp:class:: template array4::nested_view1 .. cpp:class:: array4::nested_view1 View of a 1D slice of a 4D array. ---- .. .. cpp:class:: template array4::nested_view2 .. cpp:class:: array4::nested_view2 View of a 2D slice of a 4D array. ---- .. .. cpp:class:: template array4::nested_view3 .. cpp:class:: array4::nested_view3 View of a 3D slice of a 4D array. ---- .. .. cpp:class:: template array4::nested_view4 .. cpp:class:: array4::nested_view4 4D view of a 4D (sub)array. ---- .. cpp:function:: array2::nested_view2::nested_view2(array2* array) .. cpp:function:: array3::nested_view3::nested_view3(array3* array) .. cpp:function:: array4::nested_view4::nested_view4(array4* array) .. cpp:function:: array2::nested_view2::nested_view2(array2* array, size_t x, size_t y, size_t nx, size_t ny) .. cpp:function:: array3::nested_view3::nested_view3(array3* array, size_t x, size_t y, size_t z, size_t nx, size_t ny, size_t nz) .. cpp:function:: array4::nested_view4::nested_view4(array4* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw) Whole-array and sub-array nested view constructors. See :ref:`const_view ` constructors for details. Lower-dimensional view constructors are not accessible to the user but are invoked when accessing views via nested indexing. ---- .. cpp:function:: size_t array2::nested_view1::size_x() const .. cpp:function:: size_t array2::nested_view2::size_x() const .. cpp:function:: size_t array2::nested_view2::size_y() const .. cpp:function:: size_t array3::nested_view1::size_x() const .. cpp:function:: size_t array3::nested_view2::size_x() const .. cpp:function:: size_t array3::nested_view2::size_y() const .. cpp:function:: size_t array3::nested_view3::size_x() const .. cpp:function:: size_t array3::nested_view3::size_y() const .. cpp:function:: size_t array3::nested_view3::size_z() const .. cpp:function:: size_t array4::nested_view1::size_x() const .. cpp:function:: size_t array4::nested_view2::size_x() const .. cpp:function:: size_t array4::nested_view2::size_y() const .. cpp:function:: size_t array4::nested_view3::size_x() const .. cpp:function:: size_t array4::nested_view3::size_y() const .. cpp:function:: size_t array4::nested_view3::size_z() const .. cpp:function:: size_t array4::nested_view4::size_x() const .. cpp:function:: size_t array4::nested_view4::size_y() const .. cpp:function:: size_t array4::nested_view4::size_z() const .. cpp:function:: size_t array4::nested_view4::size_w() const View dimensions. ---- .. cpp:function:: array4::nested_view3 array4::nested_view4::operator[](size_t index) const Return view to a 3D slice of 4D array. ---- .. cpp:function:: array3::nested_view2 array3::nested_view3::operator[](size_t index) const .. cpp:function:: array4::nested_view2 array4::nested_view3::operator[](size_t index) const Return view to a 2D slice of a 3D or 4D array. ---- .. cpp:function:: array2::nested_view1 array2::nested_view2::operator[](size_t index) const .. cpp:function:: array3::nested_view1 array3::nested_view2::operator[](size_t index) const .. cpp:function:: array4::nested_view1 array4::nested_view2::operator[](size_t index) const Return view to a 1D slice of a 2D, 3D, or 4D array. ---- .. cpp:function:: const_reference array2::nested_view1::operator[](size_t index) const .. cpp:function:: const_reference array3::nested_view1::operator[](size_t index) const .. cpp:function:: const_reference array4::nested_view1::operator[](size_t index) const Return scalar element of a 2D, 3D, or 4D array. ---- .. cpp:function:: reference array2::nested_view1::operator[](size_t index) .. cpp:function:: reference array3::nested_view1::operator[](size_t index) .. cpp:function:: reference array4::nested_view1::operator[](size_t index) Return reference to a scalar element of a 2D, 3D, or 4D array. ---- .. cpp:function:: const_reference array2::nested_view1::operator()(size_t i) const .. cpp:function:: const_reference array2::nested_view2::operator()(size_t i, size_t j) const .. cpp:function:: const_reference array3::nested_view1::operator()(size_t i) const .. cpp:function:: const_reference array3::nested_view2::operator()(size_t i, size_t j) const .. cpp:function:: const_reference array3::nested_view3::operator()(size_t i, size_t j, size_t k) const .. cpp:function:: const_reference array4::nested_view1::operator()(size_t i) const .. cpp:function:: const_reference array4::nested_view2::operator()(size_t i, size_t j) const .. cpp:function:: const_reference array4::nested_view3::operator()(size_t i, size_t j, size_t k) const .. cpp:function:: const_reference array4::nested_view4::operator()(size_t i, size_t j, size_t k, size_t l) const Return const reference to a scalar element of a 2D, 3D, or 4D array. ---- .. cpp:function:: reference array2::nested_view1::operator()(size_t i) .. cpp:function:: reference array2::nested_view2::operator()(size_t i, size_t j) .. cpp:function:: reference array3::nested_view1::operator()(size_t i) .. cpp:function:: reference array3::nested_view2::operator()(size_t i, size_t j) .. cpp:function:: reference array3::nested_view3::operator()(size_t i, size_t j, size_t k) .. cpp:function:: reference array4::nested_view1::operator()(size_t i) .. cpp:function:: reference array4::nested_view2::operator()(size_t i, size_t j) .. cpp:function:: reference array4::nested_view3::operator()(size_t i, size_t j, size_t k) .. cpp:function:: reference array4::nested_view4::operator()(size_t i, size_t j, size_t k, size_t l) Return reference to a scalar element of a 2D, 3D, or 4D array. .. _slicing: Slicing ^^^^^^^ Arrays can be constructed as deep copies of slices of higher-dimensional arrays, as the code example above shows (i.e., :code:`zfp::array2d b(v[5]);`). Unlike views, which have reference semantics, such array *slicing* has value semantics. In this example, 2D array *b* is initialized as a (deep) copy of a slice of 3D array *a* via nested view *v*. Subsequent modifications of *b* have no effect on *a*. Slicing is implemented as array constructors templated on views. Upon initialization, elements are copied one at a time from the view via multidimensional indexing, e.g., :code:`v(i, j, k)`. Note that view and array dimensionalities must match, but aside from this an array may be constructed from any view. Slicing needs not change the dimensionality, but can be used to copy an equidimensional subset of one array to another array, as in this example:: zfp::array3d a(30, 20, 10, rate); zfp::array3d::const_view v(&a, 1, 2, 3, 4, 5, 6); zfp::array3d b(v); assert(b(0, 0, 0) == a(1, 2, 3)); assert(b.size_x() == 4); assert(b.size_y() == 5); assert(b.size_z() == 6); Slicing adds the following templated array constructors. .. cpp:function:: template array1::array1(const View& v) .. cpp:function:: template array2::array2(const View& v) .. cpp:function:: template array3::array3(const View& v) .. cpp:function:: template array4::array4(const View& v) Construct array from a view via a deep copy. The view, *v*, must support :ref:`multidimensional indexing `. The rate for the constructed array is initialized to the rate of the array associated with the view. Note that the actual rate may differ if the constructed array is a lower-dimensional slice of a higher-dimensional array due to lower rate granularity (see FAQ :ref:`#12 `). The cache size of the constructed array is set to the default size. .. _private_immutable_view: Private immutable view ^^^^^^^^^^^^^^^^^^^^^^ |zfp|'s compressed arrays are in general not thread-safe. The main reason for this is that each array maintains its own cache of uncompressed blocks. Race conditions on the cache would occur unless it were locked upon each and every array access, which would have a prohibitive performance cost. To ensure thread-safe access, |zfp| provides private mutable and immutable views of arrays that maintain their own private caches. The :code:`private_const_view` immutable view provides read-only access to the underlying array. It is similar to a :ref:`const_view ` in this sense, but differs in that it maintains its own private cache rather than sharing the cache owned by the array. Multiple threads may thus access the same array in parallel through their own private views. .. note:: Thread safety is ensured only for OpenMP threads, and the |zfp| views must be compiled by an OpenMP compliant compiler. As the |zfp| compressed-array class implementation is defined in headers, the application code using |zfp| must also be compiled with OpenMP enabled if multithreaded access to |zfp| arrays is desired. .. note:: Private views **do not guarantee cache coherence**. If, for example, the array is modified, then already cached data in a private view is not automatically updated. It is up to the user to ensure cache coherence by flushing (compressing modified blocks) or clearing (emptying) caches when appropriate. The cache associated with a private view can be manipulated in the same way an array's cache can. For instance, the user may set the cache size on a per-view basis. Unlike with :ref:`private mutable views `, private immutable views may freely access any element in the array visible through the view, i.e., multiple threads may read the same array element simultaneously. For an example of how to use private views for both read and write multithreaded access, see the :ref:`diffusion ` code example. Private views support only multidimensional indexing, i.e., they are neither flat nor nested. .. .. cpp:class:: template array1::private_const_view .. cpp:class:: template array2::private_const_view .. cpp:class:: template array3::private_const_view .. cpp:class:: template array4::private_const_view .. _private_const_view: .. cpp:class:: array1::private_const_view .. cpp:class:: array2::private_const_view .. cpp:class:: array3::private_const_view .. cpp:class:: array4::private_const_view Immutable views of 1D, 2D, 3D, and 4D arrays with private caches. ---- .. cpp:function:: array1::private_const_view::private_const_view(array1* array) .. cpp:function:: array2::private_const_view::private_const_view(array2* array) .. cpp:function:: array3::private_const_view::private_const_view(array3* array) .. cpp:function:: array4::private_const_view::private_const_view(array4* array) .. cpp:function:: array1::private_const_view::private_const_view(array1* array, size_t x, size_t nx) .. cpp:function:: array2::private_const_view::private_const_view(array2* array, size_t x, size_t y, size_t nx, size_t ny) .. cpp:function:: array3::private_const_view::private_const_view(array3* array, size_t x, size_t y, size_t z, size_t nx, size_t ny, size_t nz) .. cpp:function:: array4::private_const_view::private_const_view(array4* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw) Whole-array and sub-array private immutable view constructors. See :ref:`const_view constructors ` for details. ---- .. cpp:function:: size_t array1::private_const_view::size_x() const .. cpp:function:: size_t array2::private_const_view::size_x() const .. cpp:function:: size_t array2::private_const_view::size_y() const .. cpp:function:: size_t array3::private_const_view::size_x() const .. cpp:function:: size_t array3::private_const_view::size_y() const .. cpp:function:: size_t array3::private_const_view::size_z() const .. cpp:function:: size_t array4::private_const_view::size_x() const .. cpp:function:: size_t array4::private_const_view::size_y() const .. cpp:function:: size_t array4::private_const_view::size_z() const .. cpp:function:: size_t array4::private_const_view::size_w() const View dimensions. ---- .. cpp:function:: const_reference array1::private_const_view::operator()(size_t i) const .. cpp:function:: const_reference array2::private_const_view::operator()(size_t i, size_t j) const .. cpp:function:: const_reference array3::private_const_view::operator()(size_t i, size_t j, size_t k) const .. cpp:function:: const_reference array4::private_const_view::operator()(size_t i, size_t j, size_t k, size_t l) const Return const reference to scalar element of a 1D, 2D, 3D, or 4D array. The following functions are common among all dimensionalities: .. cpp:function:: size_t arrayANY::private_const_view::cache_size() const .. cpp:function:: void arrayANY::private_const_view::set_cache_size(size_t csize) .. cpp:function:: void arrayANY::private_const_view::clear_cache() const Cache manipulation. See :ref:`caching` for details. .. _private_mutable_view: Private mutable view ^^^^^^^^^^^^^^^^^^^^ The mutable :code:`private_view` supports both read and write access and is backed by a private cache. Because block compression, as needed to support write access, is not an atomic operation, mutable views and multithreading imply potential race conditions on the compressed blocks stored by an array. Although locking the array or individual blocks upon compression would be a potential solution, this would either serialize compression, thus hurting performance, or add a possibly large memory overhead by maintaining a lock with each block. .. note:: To avoid multiple threads simultaneously compressing the same block, **private mutable views of an array must reference disjoint, block-aligned subarrays** for thread-safe access. Each block of |4powd| array elements must be associated with at most one private mutable view, and therefore these views must reference non-overlapping rectangular subsets that are aligned on block boundaries, except possibly for partial blocks on the array boundary. (Expert users may alternatively ensure serialization of block compression calls and cache coherence in other ways, in which case overlapping private views may be permitted.) Aside from this requirement, the user may partition the array into disjoint views in whatever manner is suitable for the application. The :code:`private_view` API supplies a very basic partitioner to facilitate this task, but may not result in optimal partitions or good load balance. When multithreaded write access is desired, any direct accesses to the array itself (i.e., not through a view) could invoke compression. Even a read access may trigger compression if a modified block is evicted from the cache. Hence, such direct array accesses should be confined to serial code sections when private views are used. As with private immutable views, **cache coherence is not enforced**. Although this is less of an issue for private mutable views due to the requirement that views may not overlap, each private mutable view overlaps an index space with the underlying array whose cache is not automatically synchronized with the view's private cache. See the :ref:`diffusion ` for an example of how to enforce cache coherence with mutable and immutable private views. The :code:`private_view` class inherits all public functions from :code:`private_const_view`. .. .. cpp:class:: template array1::private_view .. cpp:class:: template array2::private_view .. cpp:class:: template array3::private_view .. cpp:class:: template array4::private_view .. cpp:class:: array1::private_view : public array1::private_const_view .. cpp:class:: array2::private_view : public array2::private_const_view .. cpp:class:: array3::private_view : public array3::private_const_view .. cpp:class:: array4::private_view : public array4::private_const_view Mutable views of 1D, 2D, 3D, and 4D arrays with private caches. ---- .. .. cpp:class:: template array1::private_view::view_reference .. cpp:class:: template array2::private_view::view_reference .. cpp:class:: template array3::private_view::view_reference .. cpp:class:: template array4::private_view::view_reference .. cpp:class:: array1::private_view::view_reference .. cpp:class:: array2::private_view::view_reference .. cpp:class:: array3::private_view::view_reference .. cpp:class:: array4::private_view::view_reference Proxy references to array elements specialized for mutable private views. ---- .. cpp:function:: array1::private_view::private_view(array1* array) .. cpp:function:: array2::private_view::private_view(array2* array) .. cpp:function:: array3::private_view::private_view(array3* array) .. cpp:function:: array4::private_view::private_view(array4* array) .. cpp:function:: array1::private_view::private_view(array1* array, size_t x, size_t nx) .. cpp:function:: array2::private_view::private_view(array2* array, size_t x, size_t y, size_t nx, size_t ny) .. cpp:function:: array3::private_view::private_view(array3* array, size_t x, size_t y, size_t z, size_t nx, size_t ny, size_t nz) .. cpp:function:: array4::private_view::private_view(array4* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw) Whole-array and sub-array private mutable view constructors. See :ref:`const_view constructors ` for details. ---- .. cpp:function:: array1::private_view::view_reference array1::private_view::operator()(size_t i) const .. cpp:function:: array2::private_view::view_reference array2::private_view::operator()(size_t i, size_t j) const .. cpp:function:: array3::private_view::view_reference array3::private_view::operator()(size_t i, size_t j, size_t k) const .. cpp:function:: array4::private_view::view_reference array4::private_view::operator()(size_t i, size_t j, size_t k, size_t l) const Return reference to a scalar element of a 1D, 2D, 3D, or 4D array. The following functions are common among all dimensionalities: .. cpp:function:: void arrayANY::private_view::partition(size_t index, size_t count) Partition the current view into *count* roughly equal-size pieces along the view's longest dimension and modify the view's extents to match the piece indexed by *index*, with 0 |leq| *index* < *count*. These functions may be called multiple times, e.g., to recursively partition along different dimensions. The partitioner does not generate new views; it merely modifies the current values of the view's offsets and dimensions. Note that this may result in empty views whose dimensions are zero, e.g., if there are more pieces than blocks along a dimension. ---- .. cpp:function:: void arrayANY::private_view::flush_cache() const Flush cache by compressing any modified blocks and emptying the cache. zfp-1.0.1/docs/source/zforp.rst000066400000000000000000000544041453723256400164540ustar00rootroot00000000000000.. include:: defs.rst .. index:: single: zFORp .. _zforp: Fortran Bindings ================ |zfp| |zforprelease| adds |zforp|: a Fortran API providing wrappers around the :ref:`high-level C API `. Wrappers for :ref:`compressed-array classes ` will arrive in a future release. The |zforp| implementation is based on the standard :code:`iso_c_binding` module available since Fortran 2003. The use of :code:`ptrdiff_t` in the |zfp| |fieldrelease| C API, however, requires the corresponding :code:`c_ptrdiff_t` available only since Fortran 2018. Every high-level C API function can be called from a Fortran wrapper function. C structs are wrapped as Fortran derived types, each containing a single C pointer to the C struct in memory. The wrapper functions accept and return these Fortran types, so users should never need to touch the C pointers. In addition to the high-level C API, two essential functions from the :ref:`bit stream API ` for opening and closing bit streams are available. See example code :file:`tests/fortran/testFortran.f` (on the GitHub `develop branch `_) for how the Fortran API is used to compress and decompress data. .. _zforp_changes: .. note:: |zfp| |fieldrelease| simplifies the |zforp| module name from ``zforp_module`` to ``zfp``. This will likely require changing associated use statements within existing code when updating from prior versions of zFORp. Furthermore, as outlined above, the |zfp| |fieldrelease| API requires a Fortran 2018 compiler. Types ----- .. f:type:: zFORp_bitstream :f c_ptr object: A C pointer to the instance of :c:type:`bitstream` ---- .. f:type:: zFORp_stream :f c_ptr object: A C pointer to the instance of :c:type:`zfp_stream` ---- .. f:type:: zFORp_field :f c_ptr object: A C pointer to the instance of :c:type:`zfp_field` Constants --------- Enumerations ^^^^^^^^^^^^ .. _zforp_type: .. f:variable:: integer zFORp_type_none .. f:variable:: integer zFORp_type_int32 .. f:variable:: integer zFORp_type_int64 .. f:variable:: integer zFORp_type_float .. f:variable:: integer zFORp_type_double Enums wrapping :c:type:`zfp_type` ---- .. _zforp_mode: .. f:variable:: integer zFORp_mode_null .. f:variable:: integer zFORp_mode_expert .. f:variable:: integer zFORp_mode_fixed_rate .. f:variable:: integer zFORp_mode_fixed_precision .. f:variable:: integer zFORp_mode_fixed_accuracy .. f:variable:: integer zFORp_mode_reversible Enums wrapping :c:type:`zfp_mode` ---- .. _zforp_exec: .. f:variable:: integer zFORp_exec_serial .. f:variable:: integer zFORp_exec_omp .. f:variable:: integer zFORp_exec_cuda Enums wrapping :c:type:`zfp_exec_policy` Non-Enum Constants ^^^^^^^^^^^^^^^^^^ .. f:variable:: integer zFORp_version_major Wraps :c:macro:`ZFP_VERSION_MAJOR` ---- .. f:variable:: integer zFORp_version_minor Wraps :c:macro:`ZFP_VERSION_MINOR` ---- .. f:variable:: integer zFORp_version_patch Wraps :c:macro:`ZFP_VERSION_PATCH` ---- .. f:variable:: integer zFORp_version_tweak Wraps :c:macro:`ZFP_VERSION_TWEAK` ---- .. f:variable:: integer zFORp_codec_version Wraps :c:data:`zfp_codec_version` ---- .. f:variable:: integer zFORp_library_version Wraps :c:data:`zfp_library_version` ---- .. f:variable:: character(len=36) zFORp_version_string Wraps :c:data:`zfp_version_string` ---- .. f:variable:: integer zFORp_min_bits Wraps :c:macro:`ZFP_MIN_BITS` ---- .. f:variable:: integer zFORp_max_bits Wraps :c:macro:`ZFP_MAX_BITS` ---- .. f:variable:: integer zFORp_max_prec Wraps :c:macro:`ZFP_MAX_PREC` ---- .. f:variable:: integer zFORp_min_exp Wraps :c:macro:`ZFP_MIN_EXP` ---- .. _zforp_header: .. f:variable:: integer zFORp_header_magic Wraps :c:macro:`ZFP_HEADER_MAGIC` ---- .. f:variable:: integer zFORp_header_meta Wraps :c:macro:`ZFP_HEADER_META` ---- .. f:variable:: integer zFORp_header_mode Wraps :c:macro:`ZFP_HEADER_MODE` ---- .. f:variable:: integer zFORp_header_full Wraps :c:macro:`ZFP_HEADER_FULL` ---- .. f:variable:: integer zFORp_meta_null Wraps :c:macro:`ZFP_META_NULL` ---- .. f:variable:: integer zFORp_magic_bits Wraps :c:macro:`ZFP_MAGIC_BITS` ---- .. f:variable:: integer zFORp_meta_bits Wraps :c:macro:`ZFP_META_BITS` ---- .. f:variable:: integer zFORp_mode_short_bits Wraps :c:macro:`ZFP_MODE_SHORT_BITS` ---- .. f:variable:: integer zFORp_mode_long_bits Wraps :c:macro:`ZFP_MODE_LONG_BITS` ---- .. f:variable:: integer zFORp_header_max_bits Wraps :c:macro:`ZFP_HEADER_MAX_BITS` ---- .. f:variable:: integer zFORp_mode_short_max Wraps :c:macro:`ZFP_MODE_SHORT_MAX` Functions and Subroutines ------------------------- Each of the functions included here wraps a corresponding C function. Please consult the C documentation for detailed descriptions of the functions, their parameters, and their return values. Bit Stream ^^^^^^^^^^ .. f:function:: zFORp_bitstream_stream_open(buffer, bytes) Wrapper for :c:func:`stream_open` :p c_ptr buffer [in]: Memory buffer :p bytes [in]: Buffer size in bytes :ptype bytes: integer (kind=8) :r bs: Bit stream :rtype bs: zFORp_bitstream ---- .. f:subroutine:: zFORp_bitstream_stream_close(bs) Wrapper for :c:func:`stream_close` :p zFORp_bitstream bs [inout]: Bit stream Utility Functions ^^^^^^^^^^^^^^^^^ .. f:function:: zFORp_type_size(scalar_type) Wrapper for :c:func:`zfp_type_size` :p integer scalar_type [in]: :ref:`zFORp_type ` enum :r type_size: Size of described :c:type:`zfp_type`, in bytes, from C-language perspective :rtype type_size: integer (kind=8) Compressed Stream ^^^^^^^^^^^^^^^^^ .. f:function:: zFORp_stream_open(bs) Wrapper for :c:func:`zfp_stream_open` :p zFORp_bitstream bs [in]: Bit stream :r stream: Newly allocated compressed stream :rtype stream: zFORp_stream ---- .. f:subroutine:: zFORp_stream_close(stream) Wrapper for :c:func:`zfp_stream_close` :p zFORp_stream stream [inout]: Compressed stream ---- .. f:function:: zFORp_stream_bit_stream(stream) Wrapper for :c:func:`zfp_stream_bit_stream` :p zFORp_stream stream [in]: Compressed stream :r bs: Bit stream :rtype bs: zFORp_bitstream ---- .. f:function:: zFORp_stream_compression_mode(stream) Wrapper for :c:func:`zfp_stream_compression_mode` :p zFORp_stream stream [in]: Compressed stream :r mode: :ref:`zFORp_mode ` enum :rtype mode: integer ---- .. f:function:: zFORp_stream_rate(stream, dims) Wrapper for :c:func:`zfp_stream_rate` :p zFORp_stream stream [in]: Compressed stream :p integer dims [in]: Number of dimensions :r rate_result: Rate in compressed bits/scalar :rtype rate_result: real (kind=8) ---- .. f:function:: zFORp_stream_precision(stream) Wrapper for :c:func:`zfp_stream_precision` :p zFORp_stream stream [in]: Compressed stream :r prec_result: Precision in uncompressed bits/scalar :rtype prec_result: integer ---- .. f:function:: zFORp_stream_accuracy(stream) Wrapper for :c:func:`zfp_stream_accuracy` :p zFORp_stream stream [in]: Compressed stream :r tol_result: Absolute error tolerance :rtype tol_result: real (kind=8) ---- .. f:function:: zFORp_stream_mode(stream) Wrapper for :c:func:`zfp_stream_mode` :p zFORp_stream stream [in]: Compressed stream :r mode: 64-bit encoded mode :rtype mode: integer (kind=8) ---- .. f:subroutine:: zFORp_stream_params(stream, minbits, maxbits, maxprec, minexp) Wrapper for :c:func:`zfp_stream_params` :p zFORp_stream stream [in]: Compressed stream :p integer minbits [inout]: Minimum number of bits per block :p integer maxbits [inout]: Maximum number of bits per block :p integer maxprec [inout]: Maximum precision :p integer minexp [inout]: Minimum bit plane number encoded ---- .. f:function:: zFORp_stream_compressed_size(stream) Wrapper for :c:func:`zfp_stream_compressed_size` :p zFORp_stream stream [in]: Compressed stream :r compressed_size: Compressed size in bytes :rtype compressed_size: integer (kind=8) ---- .. f:function:: zFORp_stream_maximum_size(stream, field) Wrapper for :c:func:`zfp_stream_maximum_size` :p zFORp_stream stream [in]: Compressed stream :p zFORp_field field [in]: Field metadata :r max_size: Maximum possible compressed size in bytes :rtype max_size: integer (kind=8) ---- .. f:subroutine:: zFORp_stream_rewind(stream) Wrapper for :c:func:`zfp_stream_rewind` :p zFORp_stream stream [in]: Compressed stream ---- .. f:subroutine:: zFORp_stream_set_bit_stream(stream, bs) Wrapper for :c:func:`zfp_stream_set_bit_stream` :p zFORp_stream stream [in]: Compressed stream :p zFORp_bitstream bs [in]: Bit stream Compression Parameters ^^^^^^^^^^^^^^^^^^^^^^ .. f:subroutine:: zFORp_stream_set_reversible(stream) Wrapper for :c:func:`zfp_stream_set_reversible` :p zFORp_stream stream [in]: Compressed stream ---- .. f:function:: zFORp_stream_set_rate(stream, rate, scalar_type, dims, align) Wrapper for :c:func:`zfp_stream_set_rate` :p zFORp_stream stream [in]: Compressed stream :p real rate [in]: Desired rate :p integer scalar_type [in]: :ref:`zFORp_type ` enum :p integer dims [in]: Number of dimensions :p integer align [in]: Align blocks on words for write random access? :r rate_result: Actual set rate in bits/scalar :rtype rate_result: real (kind=8) ---- .. f:function:: zFORp_stream_set_precision(stream, prec) Wrapper for :c:func:`zfp_stream_set_precision` :p zFORp_stream stream [in]: Compressed stream :p integer prec [in]: Desired precision :r prec_result: Actual set precision :rtype prec_result: integer ---- .. f:function:: zFORp_stream_set_accuracy(stream, tolerance) Wrapper for :c:func:`zfp_stream_set_accuracy()` :p zFORp_stream stream [in]: Compressed stream :p tolerance [in]: Desired error tolerance :ptype tolerance: real (kind=8) :r tol_result: Actual set tolerance :rtype tol_result: real (kind=8) ---- .. f:function:: zFORp_stream_set_mode(stream, mode) Wrapper for :c:func:`zfp_stream_set_mode` :p zFORp_stream stream [in]: Compressed stream :p mode [in]: Compact encoding of compression parameters :ptype mode: integer (kind=8) :r mode_result: Newly set :ref:`zFORp_mode ` enum :rtype mode_result: integer ---- .. f:function:: zFORp_stream_set_params(stream, minbits, maxbits, maxprec, minexp) Wrapper for :c:func:`zfp_stream_set_params` :p zFORp_stream stream [in]: Compressed stream :p integer minbits [in]: Minimum number of bits per block :p integer maxbits [in]: Maximum number of bits per block :p integer maxprec [in]: Maximum precision :p integer minexp [in]: Minimum bit plane number encoded :r is_success: Indicate whether parameters were successfully set (1) or not (0) :rtype is_success: integer Execution Policy ^^^^^^^^^^^^^^^^ .. f:function:: zFORp_stream_execution(stream) Wrapper for :c:func:`zfp_stream_execution` :p zFORp_stream stream [in]: Compressed stream :r execution_policy: :ref:`zFORp_exec ` enum indicating active execution policy :rtype execution_policy: integer ---- .. f:function:: zFORp_stream_omp_threads(stream) Wrapper for :c:func:`zfp_stream_omp_threads` :p zFORp_stream stream [in]: Compressed stream :r thread_count: Number of OpenMP threads to use upon execution :rtype thread_count: integer ---- .. f:function:: zFORp_stream_omp_chunk_size(stream) Wrapper for :c:func:`zfp_stream_omp_chunk_size` :p zFORp_stream stream [in]: Compressed stream :r chunk_size_blocks: Specified chunk size, in blocks :rtype chunk_size_blocks: integer (kind=8) ---- .. f:function:: zFORp_stream_set_execution(stream, execution_policy) Wrapper for :c:func:`zfp_stream_set_execution` :p zFORp_stream stream [in]: Compressed stream :p integer execution_policy [in]: :ref:`zFORp_exec ` enum indicating desired execution policy :r is_success: Indicate whether execution policy was successfully set (1) or not (0) :rtype is_success: integer ---- .. f:function:: zFORp_stream_set_omp_threads(stream, thread_count) Wrapper for :c:func:`zfp_stream_set_omp_threads` :p zFORp_stream stream [in]: Compressed stream :p integer thread_count [in]: Desired number of OpenMP threads :r is_success: Indicate whether number of threads was successfully set (1) or not (0) :rtype is_success: integer ---- .. f:function:: zFORp_stream_set_omp_chunk_size(stream, chunk_size) Wrapper for :c:func:`zfp_stream_set_omp_chunk_size` :p zFORp_stream stream [in]: Compressed stream :p integer chunk_size [in]: Desired chunk size, in blocks :r is_success: Indicate whether chunk size was successfully set (1) or not (0) :rtype is_success: integer Array Metadata ^^^^^^^^^^^^^^ .. f:function:: zFORp_field_alloc() Wrapper for :c:func:`zfp_field_alloc` :r field: Newly allocated field :rtype field: zFORp_field ---- .. f:function:: zFORp_field_1d(uncompressed_ptr, scalar_type, nx) Wrapper for :c:func:`zfp_field_1d` :p c_ptr uncompressed_ptr [in]: Pointer to uncompressed data :p integer scalar_type [in]: :ref:`zFORp_type ` enum describing uncompressed scalar type :p integer nx [in]: Number of array elements :r field: Newly allocated field :rtype field: zFORp_field ---- .. f:function:: zFORp_field_2d(uncompressed_ptr, scalar_type, nx, ny) Wrapper for :c:func:`zfp_field_2d` :p c_ptr uncompressed_ptr [in]: Pointer to uncompressed data :p integer scalar_type [in]: :ref:`zFORp_type ` enum describing uncompressed scalar type :p integer nx [in]: Number of array elements in *x* dimension :p integer ny [in]: Number of array elements in *y* dimension :r field: Newly allocated field :rtype field: zFORp_field ---- .. f:function:: zFORp_field_3d(uncompressed_ptr, scalar_type, nx, ny, nz) Wrapper for :c:func:`zfp_field_3d` :p c_ptr uncompressed_ptr [in]: Pointer to uncompressed data :p integer scalar_type [in]: :ref:`zFORp_type ` enum describing uncompressed scalar type :p integer nx [in]: Number of array elements in *x* dimension :p integer ny [in]: Number of array elements in *y* dimension :p integer nz [in]: Number of array elements in *z* dimension :r field: Newly allocated field :rtype field: zFORp_field ---- .. f:function:: zFORp_field_4d(uncompressed_ptr, scalar_type, nx, ny, nz, nw) Wrapper for :c:func:`zfp_field_4d` :p c_ptr uncompressed_ptr [in]: Pointer to uncompressed data :p integer scalar_type [in]: :ref:`zFORp_type ` enum describing uncompressed scalar type :p integer nx [in]: Number of array elements in *x* dimension :p integer ny [in]: Number of array elements in *y* dimension :p integer nz [in]: Number of array elements in *z* dimension :p integer nw [in]: Number of array elements in *w* dimension :r field: Newly allocated field :rtype field: zFORp_field ---- .. f:subroutine:: zFORp_field_free(field) Wrapper for :c:func:`zfp_field_free` :p zFORp_field field [inout]: Field metadata ---- .. f:function:: zFORp_field_pointer(field) Wrapper for :c:func:`zfp_field_pointer` :p zFORp_field field [in]: Field metadata :r arr_ptr: Pointer to raw (uncompressed/decompressed) array :rtype arr_ptr: c_ptr ---- .. f:function:: zFORp_field_begin(field) Wrapper for :c:func:`zfp_field_begin` :p zFORp_field field [in]: Field metadata :r begin_ptr: Pointer to lowest memory address spanned by field :rtype begin_ptr: c_ptr ---- .. f:function:: zFORp_field_type(field) Wrapper for :c:func:`zfp_field_type` :p zFORp_field field [in]: Field metadata :r scalar_type: :ref:`zFORp_type ` enum describing uncompressed scalar type :rtype scalar_type: integer ---- .. f:function:: zFORp_field_precision(field) Wrapper for :c:func:`zfp_field_precision` :p zFORp_field field [in]: Field metadata :r prec: Scalar type precision in number of bits :rtype prec: integer ---- .. f:function:: zFORp_field_dimensionality(field) Wrapper for :c:func:`zfp_field_dimensionality` :p zFORp_field field [in]: Field metadata :r dims: Dimensionality of array :rtype dims: integer ---- .. f:function:: zFORp_field_size(field, size_arr) Wrapper for :c:func:`zfp_field_size` :p zFORp_field field [in]: Field metadata :p size_arr [inout]: Integer array to write field dimensions into :ptype size_arr: integer,dimension(4),target :r total_size: Total number of array elements :rtype total_size: integer (kind=8) ---- .. f:function:: zFORp_field_size_bytes(field) Wrapper for :c:func:`zfp_field_size_bytes` :p zFORp_field field [in]: Field metadata :r byte_size: Number of bytes spanned by field data including gaps (if any) :rtype byte_size: integer (kind=8) ---- .. f:function:: zFORp_field_blocks(field) Wrapper for :c:func:`zfp_field_blocks` :p zFORp_field field [in]: Field metadata :r blocks: Total number of blocks spanned by field :rtype blocks: integer (kind=8) ---- .. f:function:: zFORp_field_stride(field, stride_arr) Wrapper for :c:func:`zfp_field_stride` :p zFORp_field field [in]: Field metadata :p stride_arr [inout]: Integer array to write strides into :ptype stride_arr: integer,dimension(4),target :r is_strided: Indicate whether field is strided (1) or not (0) :rtype is_strided: integer ---- .. f:function:: zFORp_field_is_contiguous(field) Wrapper for :c:func:`zfp_field_is_contiguous` :p zFORp_field field [in]: Field metadata :r is_contiguous: Indicate whether field is contiguous (1) or not (0) :rtype is_contiguous: integer ---- .. f:function:: zFORp_field_metadata(field) Wrapper for :c:func:`zfp_field_metadata` :p zFORp_field field [in]: Field metadata :r encoded_metadata: Compact encoding of metadata :rtype encoded_metadata: integer (kind=8) ---- .. f:subroutine:: zFORp_field_set_pointer(field, arr_ptr) Wrapper for :c:func:`zfp_field_set_pointer` :p zFORp_field field [in]: Field metadata :p c_ptr arr_ptr [in]: Pointer to beginning of uncompressed array ---- .. f:function:: zFORp_field_set_type(field, scalar_type) Wrapper for :c:func:`zfp_field_set_type` :p zFORp_field field [in]: Field metadata :p integer scalar_type: :ref:`zFORp_type ` enum indicating desired scalar type :r type_result: :ref:`zFORp_type ` enum indicating actual scalar type :rtype type_result: integer ---- .. f:subroutine:: zFORp_field_set_size_1d(field, nx) Wrapper for :c:func:`zfp_field_set_size_1d` :p zFORp_field field [in]: Field metadata :p integer nx [in]: Number of array elements ---- .. f:subroutine:: zFORp_field_set_size_2d(field, nx, ny) Wrapper for :c:func:`zfp_field_set_size_2d` :p zFORp_field field [in]: Field metadata :p integer nx [in]: Number of array elements in *x* dimension :p integer ny [in]: Number of array elements in *y* dimension ---- .. f:subroutine:: zFORp_field_set_size_3d(field, nx, ny, nz) Wrapper for :c:func:`zfp_field_set_size_3d` :p zFORp_field field [in]: Field metadata :p integer nx [in]: Number of array elements in *x* dimension :p integer ny [in]: Number of array elements in *y* dimension :p integer nz [in]: Number of array elements in *z* dimension ---- .. f:subroutine:: zFORp_field_set_size_4d(field, nx, ny, nz, nw) Wrapper for :c:func:`zfp_field_set_size_4d` :p zFORp_field field [in]: Field metadata :p integer nx [in]: Number of array elements in *x* dimension :p integer ny [in]: Number of array elements in *y* dimension :p integer nz [in]: Number of array elements in *z* dimension :p integer nw [in]: Number of array elements in *w* dimension ---- .. f:subroutine:: zFORp_field_set_stride_1d(field, sx) Wrapper for :c:func:`zfp_field_set_stride_1d` :p zFORp_field field [in]: Field metadata :p integer sx [in]: Stride in number of scalars ---- .. f:subroutine:: zFORp_field_set_stride_2d(field, sx, sy) Wrapper for :c:func:`zfp_field_set_stride_2d` :p zFORp_field field [in]: Field metadata :p integer sx [in]: Stride in *x* dimension :p integer sy [in]: Stride in *y* dimension ---- .. f:subroutine:: zFORp_field_set_stride_3d(field, sx, sy, sz) Wrapper for :c:func:`zfp_field_set_stride_3d` :p zFORp_field field [in]: Field metadata :p integer sx [in]: Stride in *x* dimension :p integer sy [in]: Stride in *y* dimension :p integer sz [in]: Stride in *z* dimension ---- .. f:subroutine:: zFORp_field_set_stride_4d(field, sx, sy, sz, sw) Wrapper for :c:func:`zfp_field_set_stride_4d` :p zFORp_field field [in]: Field metadata :p integer sx [in]: Stride in *x* dimension :p integer sy [in]: Stride in *y* dimension :p integer sz [in]: Stride in *z* dimension :p integer sw [in]: Stride in *w* dimension ---- .. f:function:: zFORp_field_set_metadata(field, encoded_metadata) Wrapper for :c:func:`zfp_field_set_metadata` :p zFORp_field field [in]: Field metadata :p encoded_metadata [in]: Compact encoding of metadata :ptype encoded_metadata: integer (kind=8) :r is_success: Indicate whether metadata was successfully set (1) or not (0) :rtype is_success: integer Compression and Decompression ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. f:function:: zFORp_compress(stream, field) Wrapper for :c:func:`zfp_compress` :p zFORp_stream stream [in]: Compressed stream :p zFORp_field field [in]: Field metadata :r bitstream_offset_bytes: Bit stream offset after compression, in bytes, or zero on failure :rtype bitstream_offset_bytes: integer (kind=8) ---- .. f:function:: zFORp_decompress(stream, field) Wrapper for :c:func:`zfp_decompress` :p zFORp_stream stream [in]: Compressed stream :p zFORp_field field [in]: Field metadata :r bitstream_offset_bytes: Bit stream offset after decompression, in bytes, or zero on failure :rtype bitstream_offset_bytes: integer (kind=8) ---- .. f:function:: zFORp_write_header(stream, field, mask) Wrapper for :c:func:`zfp_write_header` :p zFORp_stream stream [in]: Compressed stream :p zFORp_field field [in]: Field metadata :p integer mask [in]: :ref:`Bit mask ` indicating which parts of header to write :r num_bits_written: Number of header bits written or zero on failure :rtype num_bits_written: integer (kind=8) ---- .. f:function:: zFORp_read_header(stream, field, mask) Wrapper for :c:func:`zfp_read_header` :p zFORp_stream stream [in]: Compressed stream :p zFORp_field field [in]: Field metadata :p integer mask [in]: :ref:`Bit mask ` indicating which parts of header to read :r num_bits_read: Number of header bits read or zero on failure :rtype num_bits_read: integer (kind=8) zfp-1.0.1/docs/source/zfp-rounding.pdf000066400000000000000000001365141453723256400177020ustar00rootroot00000000000000%PDF-1.3 %ÐÔÅØ 4 0 obj << /Length 38 /Filter /FlateDecode >> stream xÚ+ä2T0BC]s#]##…ä\.}Ï\C—|®@.f} endstream endobj 3 0 obj << /Type /Page /Contents 4 0 R /Resources 2 0 R /MediaBox [0 0 756 255] /Parent 5 0 R >> endobj 1 0 obj << /Type /XObject /Subtype /Form /FormType 1 /PTEX.FileName (./zfp-rounding.pdf) /PTEX.PageNumber 1 /PTEX.InfoDict 6 0 R /BBox [0 0 960 540] /Resources << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] /ColorSpace << /Cs1 7 0 R >>/Font << /TT2 8 0 R/TT4 9 0 R/TT6 10 0 R/TT8 11 0 R/TT10 12 0 R/TT12 13 0 R/TT14 14 0 R/TT16 15 0 R>> /XObject << /Im1 16 0 R /Im2 17 0 R /Im3 18 0 R /Im4 19 0 R /Im5 20 0 R /Im6 21 0 R /Im7 22 0 R /Im8 23 0 R >>>> /Length 21678 /Filter /FlateDecode >> stream xíK³$¹mï÷õ)ʲl÷ÈîšÊ¬¬|l5÷.¬•mu„–ЉQXŠËž‘í¯Ì~Õ£Å]X ©ÏÁI$’$H‚<øŸ×¼þçõ~½ßîügšïëq,×ãyܶõú\î×¾»þóõ߯_óãtýöÇë¤ÿýñ[Xä¯ß7^Þû/ýËÞðú÷×»þNüµ^»¼“Ÿì…Ë}Ÿø­yaPü…Û¬ Ù¯ó}ºÛ}¿>h˺Nóu~.·é±/—O5i½ßŽçý¹_§c¹Íóý¸>¶íöÜžËuÞ·å¸?¤;~wæí~¿þÏuºü¡tÌ7¿æ÷çýØïËGúõ7ÒËúiËãyŸŽU:åú¶'Mót{<žëu¹Ï·Çý¹\¾ýž§÷i[÷Î^u¿¯SP¤'æçÊ~FÏü«–}{0™ô“ýçú×çs£“Ë_ýgû+ýºŠjysíçÊ[û´öoý«ôò5Ýïc¾ÄO•výIjx!u‘L†"scn¨Nß>üé2?¡ùôáíX7Ó|é_´=zöU=úðmÞƒ“i¥¬~2íP”ÇUL2¿Ì?Tz>nÏ}÷UP'þ…‰ýÿk'¿õzÓ×µÿ?ѧÉ?³tíÇvœ'¿5^ŸJ¯}4ëªú±ÞdÐX"ï·•>>–‰Ÿ6Õž9©*ûíqìíúØŸ·É–«i>ˬSã˜X€íw–òyë~Ÿèãž°î ÓažŽže~n= ¯X»w<–µgyÛsÚ/õ3X{–e{ô,ô9,Í—?×¹a‘y:=–î‰õ9õ,Û}~tOl˽gÙ¶½ÿ°ŽëXvfBG wæžð\>lºß·©{dº/Ïž‰UýÑpÉB*Íi¹.Ó´Í'.ö™{û g:.äijFP—h»®ûÙƒ÷Ò‰kÙPÎv¦çÜŽ¼´ô¹>O\ëtûi}.½¾Lë1w\ÖòÓðO"©—¾?Zv±=ôJ3³¨@£hvT£6Âu[Ï5ßÙË:Y3Ýpé,xœô`ž¶ç‰kž[M@„¥Óž ã7Ÿ¸Ï“&Ìcê¸X—“&°NÞÑŸ¦¥ó“ï[ñ¤£{Êzßz­›×g« ÒRÖçÂ¥F´bcÏ×÷T ÖSvŒ¼–r™wf›R],YÞs°ÌŸ(«iÂm“gص±pDë*…þ’–Þ·ãaÏì‡Êº¯ëZ(ÓR4áþd©Ñ÷ @ª?÷yÊŒÞÉ›ïtܶÒRôI5a>Öç½<ƒÅ'\,ì€ú*Ñ„™ÝÕÞóÀʾ>´]—Dz¨&Ì;³±p-ûC¹6þ¿P˜ÿʵÍX´úæç¦š0¯ë}.”u²Ü/ózG„>ƒlÑö§µ‹Ãèã?Û3VŸR&ö.å¢éÊõx>yFZº3Îò V–ÉÚ7Õll:V¹Žé©\4¾ùXUxdÓ7_ØÅ‘…u~®åNÓ…²¯b"3‚˃P(ôm‘µ°$)׺Óx}FÖPZ:=÷{é ôû®\ˆŨϰS‰&`TZÿ,¬I¡Ì;«²>ƒÒɘBe)–.ì…ÊÅAÀÞ³0òÌýnm_–]5á†ékž3‚ýº?¦Ò§ 'Ñ9f¸5ÍF­X©…e]U »ÒYLÆ¿>Ïòê/, kBù4i„ÇaºÅò‘øÀ²ËÑ‚aÚL^ ZC×”'ŽU†Ÿs*ßÁÊ.:F/ÍeðŸl5Âr`öJÛ8éÐ?ÑuýmFùýÂÛtØÀòw¶QÓ7Ú¯#.v Ì,ââÕ>Élg”/ñ"†Bž^˜š*•‘–Äþþœéo—­L¬¤eù¡½Ã µoúþŠM_e¡Õ*‹VíÂN2“ÖÐÓzKŸØèy¾ž±ÏÝXsyBOå N¦–É”ø);¸ЕòŽ}W%á{xÊø<ÐjžX罨{Ç·ýºÝ—Ò üªJ‚ÉW¾t½‹*>m²ˆ’\>T¥ ‰´NúMÌ,ù2†SµdâËJkV6Ѭif‰)ϰ)*^>µTEa±^Â}(<å{Wì%Õ.¡²èQ/ŒõM¿çÂ{Ua¦‰_dѵʵÖn6ÕœéàCË3ë¬ÊÚñ0.‚ëÂÎ2¥²6ÖAdÍó¼[w±“ˆÊ±‹zÛ7l_¥ì”‹¥W¹–£B†a¥{d(™ä›=sÈn)”­L9W©59Óuå ÙòTèÉÒ?—íþT{$‚É/²˜…ªØEÖcÝ©²v$Ø3¬3" Ñöf1âT×PžAˆržÃâ¬zÀ¬.ý|Ý[ÑÛ¿D:#)cŠI!{-EgÑ(¡ø>ÈaP5¡îžÛó¡šÀb*j*ïyrX.ßs/Û ž¡ß»7v"•…Qjm—彆¨p¹€Z‹&`¥T ´rU FxO9Ø[•RN1|!;QáR -åŪ õH±³õ\;Û©hBóÌÄVÝR.H>Y•ìQ§sJ|:X`ŠžN(-{Œ-X5¡‘¾0UZé×Eúô…LA]vʉMZÊО¸@(TâT‡µz:_0ÏŠ&ø3—íÄ…1ÐÈB°L¼çw9(ôßLЄ¶¥€|EœK`2¦•òfOÅÃìw]=¤›ãwÇÃ*Áð°B`î:O8ÇÃ*Áð°J0<,އU‚áaAp<¬ +>Ìñ°xÂñ° 8V †‡U‚áaAp<¬  C§q%V|ëHÙ¯â&lY¥Šáa•âx˜S*æ±oË~ÕP «ÇÊáa Åð°Jq<¬¡V)އŠ´Ôñ°úŒãa Åð°†bx˜S*æìmVˆ^S«Ï8V)އ5ÃÊáaA <¬¡V(: {œEæ…áa•âxXC1<Ì)s ¶½áaV@ZÌ›«ÇÃxVö?žq<¬R°ðuËylˆg{ÌŠ@q< Z–[¡6+Æ$-u<Œ”ìâP“3Šáa3ljB Ë^"--Èë³ï7“ô¬Ø¶'a•<¤ì[ÒRCÆXÃËÞvY {ÄþçȈ‡úOà2dŒuÞvVGÆ*…mG4ánm«œ#c Å1,k[ßk)3 -Å9¢øhóŒ!c Å1(jÓÃåȘS.Œ9¥"c űJqd¬¡(2FKC–#c űJqd¬¡2V(ÒÒ‚Œ5'‰"ó¡‘Åž$;@CqdÌß| dÌ)k(†ŒU «â E‘±¦¥H.xH}Æ‘±†bÈX¥82V(´Ô±¦ŒU.GÆŠ!cN¹nt:h2æÏ\wGÆŠ!c•R±¶¥ŽŒ5Ï2V)ŽŒ5CÆ EZZ±¶¥ŽŒW c Å1§\sJEÆŠ!c•âÈXCQd¬ii cõGÆ*Å‘±†bÈX¡ÐRCÆš–2V¹«GÆœrÁ *ȘS*2ÖP k(†ŒUJAÆÚ–:2VŸqd¬¡2”ŠŒMud¬i+Ƙ!c £#c-ɱæ]ëÞåÈXÃèÈXK2d¬yWAƺw92Ö0:2ÖkÞU±î]ŽŒ5ŒŽŒ5$GÆšwd¬{—#c £#c-ɱæ]ëÞåÈXe d¬%šïúR£êJügÇìu-8Öup,H"ôÏŽmøœîÏpŒ'Ù&1c8´–Çë‘bŒ—pŒ8“ß[p¬üÞ€cF¨àfKŽ•'p¬pÌ3BÇ ¡ÇŒPÁ±BhÀ1#Tp Ö€cå‰+„3BÇŒPÁ±BhÀ1#Tp¬0}åt%;¸*8¡¬/Ž•GZpÌ)3JŽ)¥Çì™sJnjҀcN©à˜S*8f”sJnjҀcP¤¥ 8fÏ4à˜S*8æ” Ž)¥Çì™3JŽ9Å‚Åb("X¬¡Tp̸“èòˆágûݴЃÆÖC%Í4 Ĥô§TÞáî·òm J¥R @u&G¾Ì4~µ' @#îÏÞ!/½"°ˆ²€¶4ŽïrüL’vôï>DÇ~/dïWþnØYùÍ¢¾î¼éKŒ;1€Ä¸sÄŒD‡K޹DCÊâ‹ 'cŠ”o0”Œ ûÝ02âLJ"CgÊ4F衱XÐaƒÖJ c°'JÐ`³ø&èzGÇ@RK×;8F€PQcÇÆ-5°$µ ìa,è1GÆbµwXÈÑ‚E¬ãb@h’Êõˆ1^QÚo¸Øo°™ãb„KÚ¨.Æäó,ïñˆ1&IQsÇÅ$î éò}1FO›tÃň=¿Òï1\Œ-¹,®`^1جͺ8.&ÊiíB=E-çǼØ{"bLÐ[}³GŒ-œé ¥àb±g+"Æô<Ÿ.†h²)à¸a·¬bòæˆðB[ê¸Æ„•g,bŒ.,m\ L¼ ¢Å²$ [‡øâcâõ*Z¸Ø´ØÄ\ ˆ½h[DŒÅÆbc—ºùDÄXlP1ÆàØ7.fªæ¸˜n†Œ)p¯,lœ¾abX BñMµâb•⸘m΂íèáòíš@¦1›|ƒ‹™icñŒEŒ jàÏT\,(1†I‹‹0"ÆÊ3´4"Æ*Wƒ‹W‰£n^µ¸˜>s!º§DŒ5ÏT\ÌÞÓàbN±ˆ±ÊUp1ÅGì«ÏxÄXC±ˆ±†Rq1Þ#-mp1{3Š%n™¦] .fÏ4¸˜RÀ¼,b,dáô+c Å"Æ*Å#ÆŠâbMK#b¬>£–Eû…-.V¾0"Æ -ˆ±úk(„‡wmoq1kiƒ‹™¬sJÅÅŒâcUV‰k[êcõk(1V) .†,i©GŒÅ3.V>¨ÃÅœÔàbåU@31Ö¼Ë#ÆRƒ‹ù»\ÌßÕàbþ”GŒ5ïjp1ªÁÅü] .æO5¸X°¶ºñd°ˆ±"‘î‚$[]«OÄ´[ÄXó] .æ¯W38õ] .æOyÄXó®ó§\ ’¼«ÅÅì)¾µDŒÅ»¾Ôt’Dà '\Ì…6¸X!ý9q±šó¯Qvyp1ÒJÀÈ^ÇÅþ7ƒ’éŠ>FtŸƒb•ð¿”äÕ2¹þ7ƒ²Q“ÅBO+–#qg«Ï±>ãc•â XC1PÌ)sJk(ÿdPz€2‡ÆjÕ‰Åî&èAÛ‡Šy+*(æ” Š5Å‚ XCaR‹¿¾¡(V)Š5”â¹o¸+Ï0¦ŠE~G€b Å@±†b ˜S*(Ù%ŠUŠƒb Å@1ó’åc5·Å#ÆjþK€b‘#C,F t/y4ÌnšAi¹6ÒÒÅ<‡¸¨’A9;Š¡|•ä=ŠYîODŒ‘fùAŠEQ€b‘g ˜ç"UP,ò•‹œ¦Å"ïÉÇÈ'–Ü(¾|JCÛ‰´‘ü)Zê XͱâYó¨yXŠÕ\-Å"Ÿ«‚b‘óElšÄ‘+êyaŠEîX€bž_æÑd œ)Ù[š"*ï‰<5)«¹lšJɉ^òݤ¥ˆÛÜr⤥XysŒ¼bùeŽŒEú#c‘ çÈX¤ð92I~ZVÓ +‰‚|›‡–•TB>Í¡±šlhØXMG´Ð²š°h‘e5¥±d$dbìI¼lê‰9Ô@dþ¦&¦ìƒKOæôˆ²Èö4¤Ì²A‰/óh2ËÐ4 ÌsK &‹_Kf¥f¡>æ2tÌÓN³üÖóüW‡Æ™AÙØ~(ßç3(iiàaþÍP «ÇÃÊ)ƒòxX}Æñ°JÉgP6-ýdeÓÒÀê,Çà EZêxX}ÆãÄ*Åñ°†rÊ ¼PÉé”÷Aåõ… ʦ¥ ñkHއµ$Åúw9Ö<åxXKóî a+îœî]އ5ŒŽ‡µ¤OePvïr<¬aô8±†äxXKR<¬{—ãaÍSއµ¤OePvïr<¬at<¬%}*ƒ²}WàaÁøEFR†Ù»Z0,^4þ© ÊWê&þÃw?|ûÝüé¿~ûþúÃ著F­4Þ»Æã—iYo(ÉFvÔvó¶‰1÷õß?]ÿÏ/—OžØö;âú16 gûÛATÙ\Ò)&ìs\ÏùFn@ek¾ñ³lÊc®”…¤iœÍ欴çmá¬lYiõÙè?Ì‚‡Ã-+í¸OÁ–”¶N7+à:n’¶>nØ^ôÈ“Â~X¢YaÏ¡TÞƒ 5-m»QÉŠŽ|N72ÈžYiû aR t¾ax>“mÛˆzÄ‹Ûr0?))õ¤H lÏÛ“2{Yi ºEQœ½7ØGVÚz£¥tÉ~ÃVÈ*ÉF—?F¢át»s¬LJÛï7Ê~ГŒ»¸ß“m۩ɺÌÌíu¡ÔêœíÉ­Ä0À¶Ýˆùd¥hŠ'¶ãÆ=gÛ¶ßH§'@©ƒ“•F™Ùm£K6fù‚ØÜ tL7¶”‹‘àD‘mÛA]Jê­PØ…¢µ|YiÏ¥®à¢Àí~d‡íØÐ­‰ŽÜY‰ˆwÈ ;n”fr|#Ǩ\GrÚb»8øHªðn˜Æ9i4ë†ß”9Pi*Ðd¥3,ëSêØÜù’JÒ„n-p­7ÀødG‚KßÀ¡`›XR(˜lOs~zÀ¶ðCvnÓ˜Á*R/`’f¥-7¼ú«d|Ý(j™¶i½I X éæxJýYàn˜ˆTZ~0¨Ý‘µ™]†?lOŠ;S"'B¯ƒ@Ô#üiý'|ÕºÓ‘ U )B—•ƺ/.TêC£§ä’ d ›q˜²%¢™É¦±]ƒ,À&›Ô#¹ÛPHˆþÃmIÛÊ’“öÀ #øŽ O>’ƒurØ,ûŒ2lÛNUÁ¬´ ÕÂ&az³þìÉ5K !S›õÿ¼””¶°rš‡ÇÈM¶mÁ¦À † ãórV]‚ æ2³ÒV¾m¦K¨P¾–•Æ&r]’ŸÛ¨"[=©»Mzr«u½2¹wª²'Û†s¸¤'aã4ž´%ÅÌb'D¹vlQ<Yi;OSúXØé’IQy˜¤G^†•%¦s%…1[.ý(’lÙ*ÆõÊÜÆìÂ|Êö#FáÒŒ:ÛjVÇ 0hTkg%™³³I†‹‡ŽD‘‰<ÎÎm&™àʰ‰µEÕìܺµaRÈ1E&)ëC²iLMB½éH>V㜓ÂĶ&UŠÎÒÙõŸnÇKG2~ø³» “…x=¸8Òæ- AÂ,èGš8Íì¶½cö5»>Å£“¹‹iÍbEÄ%k$è\Gb?²+Êþ+gÒ)»Ž¨iÚãN»M ÐYi‹XKpÍmŽì‚LVÛF&  éóYaª5Ó‘l\¿‘íȃÃ% `»c¾½¤:’¥C„3 +†Ð3¹H5|jÒ‘r?µÍ²ÒÄ´^èɉóCv²agݰaèÈéAìIƒ§;O D‰M–JrØ0]P-@* '°úƒ–ä:ÓzÇ÷“•øûœþ³ãŠÙÉ……X÷¬°•kx§Ë ,/;jjZ?äÔÆ^E™¤4LkÜ’™ãìUÙŽœ™-„XÃ&"'Ó\GÎX«@ËùH ùdGÎÌhr`“]£äRŒá>NC7|Ør &Æ’´dŽ‘æDGªA˜µ~äDÃîËñ—åOï£Lkî¡#ÅØfOv$¡'§QØèÑ´ ¬ˆn H%ÛFÚj¥ì÷>°ëâ…Dì#«’˜Ö’"¥ ÇËìÜæØÅþ)(!]‚›9©$‹˜Ö"bÞÉoHö$§5üñô$wpåOvÎJ‡´˜”…a}ðØ ™lB°'*lš•¶0Ç¢z Û•=ž­àÏà Ù5 R’çN¶ "|®­'›†úJÎ`Ë { D¥GôÎGñü_,3ê;J×FV=´¶lÛ¸ŒKN(/JSËš#г夑ˆiÀÑÞÙ¬m3n›Ït ¦ °@‹}OÙX¶ähïlYiô»DQ8›µm(Ë…d±ë‡mÄÅBŽãŒI ›x{’Âظ`[²iŠ‘>îÞž¬4–F9Ù;[Vš`$X»ÂÖÌíQ—€Ÿ×Wç$r±Ç{Äj'ÐV6†llÖdsê"I]²eá~d±¤pW²é†â}dñsyø‰æ}ì=D#.¾¬xõõpãÈæÞGÁì*®5dsï#G=’ý\?dsï#Ø…fšÃnÈæÞG…ú|Ëq¹óÛ Î5C.LNu>êA{K sç£ë+Î4”æÎGúg²¹ó±7YGlá|ì ä!›;{s|ÈÆ)Hxz(—U’â|ä¤äähäPš;å¾Eâ÷’3€¤8ÍÓ“œÚî|tOOVš9ÅÕC"mV˜ùå€ R’UIHüÇ›ÂI -Í|¤÷ ‘6÷=  ÙÏɶ¹ïÑÁ‡dG‚ˆïQ\6DâewQ÷=Ê‘ƒ õ¬,s=r;^jÑ ×#‡DŽqÒèq¸ ¼Å¾À¿—”æ®G,e •ä‚®GL^rZ²²ÜóØ»PF- Ï#Ë®”ä.Z=zÎÎêãŒ{³x{§Æð#ÍóØãÕC.÷<‚ŸìÈð<Ÿ~€¼åŒÉ<Ìp*u$WÈêyT gΪó¹xÕóžkáy<Ø<@œ²MsÏ#ëñÜY Ï£.þÙ–…ã±p%-üޝÉr·ã‹ s·ãkÝnGV奺´GjnGÝzɽͭ=ŠˆÛñ5}Ĩ.nÇ×´_¬ju;2תmÔ´³×1Ù4µªÅëøÚ*^Ç×Ö¬ð:¾¶B*8"^Ç×Öãp;¾´ø»×ñµ}&¼Ž¯íjáuì5£Á¯ãk;6®ýâu|Å< ·8_²Eäðât4¯KR!Ãéh^—ä¢^Ç—Œ:‰#+^Gœ ’–”^Ç— VŽ‘ÅëøŠq,ÑgÅéh1WÉ~t§£Gxe[fNG‰'ËŸ2$hMŽòCþLƒÑH<NÇ“ûd¤þ|›8OÞ“!—9OÞ“!›9É"D5¼‡C6s:Ê< @ÏÝ'¶p:ʬ˳Ãé(î?“'(Ü“ÅéˆÃË?|•Ã4¯ã) uÈf^ÇSøìˆÍ½Ž`Ï/@1$C¯£„çŸð:¾„2É ´x_´¨a…ûI¼Ž/hrp-^ÇWÐ:BÐÌéˆû$ RzË|Ž/Á¸„ÌçøèY}Ž/!¬Õé[ô?Ò¬p:[n¬NGƒ¸s+²å‹Óñ%d¼:_Âá«ÓÑØ’m §ãkÒÂéø¢4w:¾$mÂŒŒÔ&Yæ1ðº°XjH爲98Û·mÄæèlß´!—£³/ st¶&Çf(ÍÑYc3%²9:ûš´@gûé6’©!¶&Øt²9:k+P²mβÞInNVš£³ý29úÈ@g{—öÍSCØ$7'Ù¶H ÑCJ8ë‡Ò<5¤ ²yjHˆ0dóÔ=€EØÃˆÍáÙSÅÍSCúŽ!›¥†ôñ#C.O áüFB¨ãZC6Ãg%5çòœSÉÀg%5‡ë³üH |VÂ~ÈvvÃuÈfø¬§æäTÒñYë ›ØØ 3€VG;QÌÆq9>KÉX`ÅÕÑÈ!›e†PP—€Ö¼4ÃgÉø¢§l?zf±r¸C‹~£ã³Dæ3êhäˆ-ðY‹Lvdà³DrýTV!#3„Ç£†O ?ÒñY Ø…¯¤ú{fHŸb3æø, Rf;),ðYBÄä"¿dG@‹ÙÅù!«‘Ђ0Jɬ4‡hå9_£‰Ä=¥52Ú>ée$-ZVÖ‡\››ÚÐJø TÉa „V—Èìdñ¼NŸ­¥“$›mŸ2êÈ@hu‰ÌÊŠ¬ CâY³-“à5Ágq¼HÕû¬4O 1ÇKRš´ºGìø¨? 5ÿDV˜§…t.”¡0Ï ‹h´ìÚøìKŸ}­eÏö›QÓŸµîOöcà³6ÖI |Ö4+)-ðY‰Ì¨éÅ£¶9>«S&+ÊáY›žÉ†9<{Ê-~¡ç„П’—”æð,Ö#YÚ‘>’æð¬ääȪš•f9!š·QaCažbFV˜ç„Øö”¶È уŸ©}&àÙS–ê mÏzšLVšÁ³‚‰U‘k[M 1&+Í“B°˜(‘æè¬À‹$ç$×þ@g%ÝElÁ¬´’"é.bx&[æè¬ä½L5Nq4jŽÎžÒ]FlŽÎJº‹˜ðɦ½Ô¡M ók+µ”~†?êþÀð­ŒTV¦µvÂ|•¢Uɶ†¯8NÄ~¤ÇXƒ7ÊFlÃ/lɶ†ß&O eˆ/õX"XwÈæ…ú¬¨!›ƒøÖ!É–ˆß{FÒÄ·ÁÎJ3_3i)'•Sÿ(ìdzœæ ~_ lØ4‹±ö*‚9iÄgÖ5ÊÒ*ˆo³ÒÄ×4mê0§z²‚øšþtWìð#Äï½(#¶@ñ‰‘äî(÷ŸÙ¼²“†=gI±ö¢ÉŽ _蔡Êud øV4)-Pü’+“æ ¾—ZÍ ³ k/ìš•fAÖ^F6+Í ;yÍÚ¤4‡ñ%jý¹8Š+Ìa|ìr©kŸ•æ0>•xz²ÒÆ×½& F›n/…8ሯ')-`|ËÌI¶-`|Ã³ÒÆ73+Ía|óõd¥9ŒoΞ¤´€ñ‹¯') —jÞ¥øQ“c36–nL’zPÅד•FýÊý„÷%Û4¶&î0 ¶¤4Lk¹¨þìÙµ Ÿ;=R\DyÏÆƒe]H¶;ùQ†Ò8m`®[ß¶¯¿ù‘¨Ó/r?Ìýúã·×¯ÿé»÷¿ýÓïÿû»oþøþ?üþûïþôÃï¿-wÐÌ‹GÒ.¡ñ߸p‘’§Ü°y\ßÊú1äH·ÿò"õ­úÏö÷ż{7_§ë»ß]ßüÅW×w¸þßwZñÌßV.¸ñßö+@=w¦ááz+ÛwB©Á»ßJÁHÊó½ûöóbþA?ûêúöy}ó—_]ÿõúîWC‘$¼Q&s½¾¥¦?wmþ‘?OŠ$1ƒ ÷èJÙÿ¸PÌ:ð ùWi‰Diå4ʆS¡àË%þuZ"y l#˜þË%þMZâ«Æ6n@”xçºüeªó›7I‘àY‹ÔÒZ"ÜiùåüÍW9‘”†fbl×·O{%ˆß[9gæÇ/ÐÒùúægÉn•K§¨Ì8}©Ä7"o<ó'öÒ;×i~©&þ/˜ñ¸âÓ-“»C¨zõüR‘*pÜ2в2RÔ¨ü CÆâùJÃ$Dø‰©u–øgX¡%å]]8¿û ¯¤ÊyÏã‡øùæ  ãÁÑJ¬&ÄÇš#õHÎ_ʆ#Š—mG3 è»ðóíIM#®y“cßüÑöpßj¦=?—ö°Bœ›s­û4ƒ]j˲àR(¼-ïË’$[6WLуäçétòOµ –bØ–MΈlÙo§ëZ*8{ÛÛí⿱ï”o¢Zî›ò‹,Óo§ûõ,žoV€¯DÔ›¿5òß•õà­ýzûê"£ôÞŒ0Ïàˆ”Ú‰øÈŽr¯ˆ­¼tx¢™gkÿhkWÖ«¯.ÒÝ|ü[Èo¾Îm’B'…çãsÄÒû廋ÎCòÏDq×bÉ?µÛ×®Û±zÒ¦’€›wîÿª2›ýŽÛ…‡}ðævÏLJªf“Ãu\©GŽé\pFïhÕ§QÃ~.ªÃlÊÚ€R]©³ÀϪí›)Ó`R¤©Ïý±¶Pí>1JÍ<|Ë‚+´.3ªö»jý%¥¹Øé„&lñ ESγòRìu›•Éæ‰­µ²…zó%ä²ßLó~£ŠiZ¦-픉 ¿‹¥yqž›ï÷ëÿ »¿â¸êIæ›_³Èp-5w†ïü´r †Ô“„¶S0ƒŠ¿¿þ†[1e"  YnÓ’…HçH%ym«×Eмq ­–Ǿç¬ñØ—;ëmëuÝã[9¸pv˜$©Iì3nÐÖÈlf#²å€úÉņr:bMðÝŠ·î ÁëÒ¤Ú8%mK®IRsšçh“ Lß&næõËQ?Þ¦‰À®Ä`p»6I~¼M¦AѦf¦%8ì¥ä¿\ÅrÌêÈ€Q¹ž›=’Ã$¨ sD›¾`œðÈs_gÿ¾MùqjvaZÂ1Xã–lêéËOªzÙq"´ž‚øÑ¤‡éúþ2&tÈs“ø”ä0±XVÕãÒ,Ɖi4(óEfÓ"m#޼@ŒYêä<ôƒ)Å=]˜$-Y!…K9ü‘yÀõè`&;yv7:ÇS—ï¨]é{SCyWá š–t#©o"ÒL?€S÷\¸S åËí›ü™hJ¼&(r™‹ û·ëïtÞÜ/´^֒Ϲ©2ô*;b‰]‚-ÃjÏÂù¦?‚2ä¢s- /¬#ôäÂÊeʰp$¼KºÒ¾œaii¥3qÓn;é²1IF&¸,e .¼ ÃâIÕÉ )Ô ,&ö&ÔÖ)>,ð­ôç¥y“uyÃR¿Éž©ŸíÃbóÃa¥ṵ̈A‡ú¥Ër3,bbʦtvügcá†/Ÿ9¶ñiâtcy¶ÓÑ´;%ÓF€ èòKäÞøÀ ÷RSøÉ(ÇSJá:+™gøeæÉ3AÑùYøŒf=Ú¼©tz#Φù&¦4Eç 4Ü'ôAã¾½Æ|ùüÀfj¥EZ@ó0´:Ü<åãRßd}^ÅŸÔoòg¢)ñš ¼:a4ÓTÊÿäqáÆa¦¹£|áåµ|pÿžÞ‘¶®¬wr4Ïrýá»ë?_ÿ½˜wßþˆu$ÿeÀš‘íŠcüiò[ãËѪœ§^ûh=Ö~ô£ëÉïKµbûR…›)-=q‡­X\x'¾ÌŽC®÷³ßß_rÚß'º¹'¬Ô(Š'˜37&V“ž:š= ¯àÐ ïY¸õ ìåR?½ëY2äºwÐí×T–çÊÁ02U'.¿Æfß³P.—¥æ\ÚÖ³àìí?l'9¡c!ѳg¡wHLm^z<׆…£Ú±b¥õÛ§ûÂ-é- ;˜wG‘æ´”‹Ü÷pâb«ávÇF8ylã…Tófu•f½ëºŸm˜ë;.v©×Â!°†Â\ÍÈKKŸëóĵ‚¨÷\+Õ“N¹%¢‘~a9? ?'ΔÍ3W’[v±Cœd êзôxb‚vï9Ž­çšïlÝ3¸0Y‚Kg—)UŠLƒiã`Ïe¦î‰ÂÅM-EŽ¿ÜZ×q)œ¸eY»g<»' »L×Rù“&pñýѽ4æ$‹‹M–²DŸ¸àê5=x6\Òv.ßíÇtÞ™m½ôÈêDY{M«AÁÞå›ÅþÛ…EX<*e?Ь L‹iB¥p Ö÷ Iå=à´…K)´}2M@Dyvåºs»¸QžEî®nýÂ6Tî/åÂu)EX\ÖòŒ¤N‹ô;!´…Âü.îÆåNE}í•´*.®„ëB}¹ía”U5ß:¤\ëÁ{v,éB!PCÆ,”IŸ@(ô¡´”d7åZéÕ}SM _o; …ÒtÊűÊÞ|¬ª hÖCÛu‘+2U–(„rq ¦ju°èyóB Ñ ÌßË{–‰± ;airD.ô Øšraï+—Œ¾Q6Õ ¾ú e;D(tÆ:^(OÕÖAZº°Šþ°¢XÏS²ž% S±ŒÎ² "”'ö_y}+Ñ8Ú® Xºjõeÿ–v±ß(Ú÷¬tž¼‡A¶ïaÇýa½í€ëÂj¯á\a"’²ŒÈÛ!<,¬»v9cìWŒXë-^ ,,¤ˆ‘FZ"ÃùdûÒoc}'‹úfU½Œ߬À*fO°Ýˆ²É¢QX&ü•°På¡|˜œkTi(±^ž@¡d13J·±âpíª7ê‡=à……Ì‰ÂÁ |‹ýŽ’ð;Å^ìwì~y®6éc€7®ý²–/Hš›A‚°v¯’_éw$©”••ŸM { i>ËIÜX}ù¨hÄÆ!•¿G#e'~íiÅü-„è'üÂÁ!Hû垤×.G_ó«¨ 2m4Ð y>^ëýP5‰EiŸåcÎhªš„V¬ìG¢YEoø0,¨E¤„f±]©šÝC³°CјF;WQ“kè/Jª&dUqÞ©zR§¨,Ñ$ûeŠ©Â.S4%¦K‹ªÊäSî*wÔŠ¨:-Y`U]lêÊ÷±‰‚Õé Š)*#æ-âÜ9Oô”X&V:F_J8ŒËvɈÄrî§æd]’d‰S®X¶pn¨AY—6–({¶u_þÐtv9ÞK¤fÔÑ÷eô hW†?–Ú‘R®²ÓRVgU¶c›m\S\ðeYg<™D¢ÍÒª¢JB±íáÂêu ÙXx”+¶BvÕ¬$Rض¢ÛÕEêvµ± ŠºÕ-½³&bÛ#®¯œ&|k¼²¼‹&°úö¹17deb-—-VZÊV$²ˆð·äš;QøæÍIfV:…«&„YpÙÙŠTV ;JZ–7 X íXQ)ì*½™Þ3¯>¥¥qhÚi§h]C¡Ê•èOKaÊöÌyS{†–²±žOà'.&`ÃÅ(“«Û›•—”¢¬PñÍLžaŽº€ÔV¤¸èh¸Ú–©ž¸ä¤P[!ßCDš¶sØl¸h©À9eLý )íu:`wغ÷`ö¶ L+äôf%ØÇ速 §ã%Ø­0š–²…Ÿg´^Ö`ÕÕèCÖïV¤¥l,'.rû1EyO 9w\Ø"}o°ÏôZGÔ^®ø9û^j–ؾ¥Çv:`p@e›é„Ab»8‘ ¢äM§±ZbíŸÂ6=‘°[ú‘îrt<½‹MâÌÈØž±0Ï1·u)Šaá|­ãÙè$‹ vÞ黨…zÍeÐ- k£è׉‘è̈?¶×‰5NÎÝ»¸&¸gLC6£3#»ÑYâ! n÷.:¿¤ç &ÆwYK Ðã+\ü+oÄ´PkŠ¡bìzxJÅ0÷M8+ºü$ç·ÒNƒÅ¶â:ˆ1X T£´é‰FXï(ïpX rùÚ§Ãb»ž[y‡Áb IiaÀb¼D›,gf0v{ËHÆ‹ (æ3ï0X +XuùãtZ^Á h¿.fš`–þõeÏì ãMŸ@ÅÊ8(æ_à ˜aÅ®Úi¢bµ‰ŽŠi' ŠE79*YP1ìgëê@Å|0‹árT,ÔP1²>Œÿ×O¥pT¬¨ æ¨X(–£bU÷ Ãúpýt\¬êpc¡çŒÅ\0`LA= !ܱ˜SŒù¼«ÀXÌMÆbþ^«sÜ1[¤¡ŒÕµ"€±XO »Ì±æ0ëKaÆbí `,Ö7ÆðAèÈ@0ëdc¾–V`,ÖÛÆ|M¾80V×mÆlm§¥ŒÕõß±ºG0Fžï#ŒÕ½Æ±º90V÷,ÆdŸ”}MZêÀXì}ŒùþX±ØCsÊ%€±Ø‹k(ŒÅžÀXCQ`ì‚Ýhëc Å€±†bÀXØ!Œ¹ýIK«Ï80ÖP «Æœr `Ì)@eŒUŠc Å€±J)À˜´TÏz|¡c•âÀXC1`¬¡(0Ö¶Ô±úŒLaÖÊF–cõÆœr `Ì)@eŒ5Æ*ű†¢ÀXÓÒÆê3ŒUŠc E1ocÀX}Ʊ†bÀX¥80æ”KcN¹‚°`¬¡0V)Œ5ÆÚ–:0VŸq`¬¡0V)k[êÀX¦”1gûñÚ:C6B·%5B>RØš.ùìG]Í•vȶçEІÂÈà lIa2i]eý‘4¢Ã‰p¥G¬´KV=‚í¥l›^Ég(¯À°‘\™•FÙ>âàa#»†kH“JBÒeÌéI+É“”FÙ2T9/ε*^€lÔ6 Ѐ(KOJi;T:§ÉVJ˜l¥¸Q¶mh"áÙ˜„ZI)+ŒC 1ØJݦ¤0²Í9%S[§¿dÔ#”bÑ(qPdw“J•뎓w¬zAÅ´V²m‡¬;²nY¹­¬4‰ –zäVÜ+'££”1—ÌRJ,';tK.bG7¥pYVuû8zÂVФe¥­è–¤FXI¶¬4Ö+<䀇|$ÑIiTÐÆ¦'­Ü\R‰Ó¤½Ñ%VÜ.+.Á´ÅÑO: Ù×Yidsq97lD6SH8+ &÷§)›ÄÖf¥¡ÁH‚õ’Ó^R™·,ªpQd³VWL7B*XIºór‹Ya\.ÉÙ[S±´L6Ä-9û`(Ér9«l¼qs¤G·¸ìÇ W&¥‘¯)w ¼$Û–léÇ,[RÑ/TvÐ( N!srÓ¬þgVWèÈ,©c¬(©ÕŽü)dN‡XiÓ¤4ú4‹ÝF³‡rÒ(D"D?ZÙÖ¬4–iÜ„9Ð7LÖ¤4¹aì 'åúfMV‰°wr¼Þ1œâöµ‘þÓïœlèIRàH¡NÚ$x0e%¦KÈ#O(;n’m†»—TZÉtɪ?¶5±³td_{Ø4.9v4™TWbê²+25ÖI‘£#u·IOm5®±rY HÇ+ÊF‰nJDGZ¹é¤’Py’ˆ(ºÄŠ['•›7]VÇ ©ø¢01®å”âlIiX"DÇ•Ž”ŠäɦqÈŠñ‰4¹¬s97ÛÐD<‚Ò‘ä&F…œÃè+F}RBÄó¢šL0Lvn£¬=ôd_{¤[j\sL‘IŠw*Ù4R·ÙkèHVñe›&¶µ,v˜v~M ÃX"œ”~´Ë’°­7Â>a+7d¥qG Àë?&±g¥qÚC î Î6qgä¨ûÕ¶æ‚K•5³7§‘”•ge#•§ä‚ üiÍÅ”œác©C”F‚Ÿ\¤NGÚe¹ŽÄµÀ±šLଗ¥ºKR§ ¼Û°É±oNª?«±‹£)[cRÅSXÆaÓêq!Â`Ô°üå²w:{RâQ³ÒIJ¦t ¾ j'%ç¨7ƒEu0|"t‹^®©ñ-Á¦ØãÀÄO%Gªéh\T}%#)Œªéš!.7¦R #Û42÷%º€ ää9d¥‰eÀ Åï#Ê6M k*eøíGYiÜBWÀ†ÑEBRÖûÝ€Mn¤À Ì †5N09þ"v=’k$û4é¤äÀú­UYit †lzCV¶i”0” ú%Fo¶ijYó4!ózùWRg ê˜ ´".בTM§pTV$ý)+M4Q0*»E-++RˆMÎê”ÞÉ}$–5yª£ât™ÛlÀoÒ%x¢³ÒIJ汕ï$³%›† BxèH»j/+ŒŠ3DÍÃV Å¤4úo~ FÕ×ß­ÈXÖDŒVØ4+A•_Äv©ª†n ×av‘TÃZ/}¶Æ/ÕP~#ù,™øÎ–6Ì@"gèÈ—¼ øÉå>ÒàÊ £lîÐ`KŽK# ƒôñˆä¤}Âý²Žü('÷‹ ²Ü/Ö´ÛÙý’”Öº_¯ÍPÚÉý’•æî—N!‡ÂNî—¤°ê~éÊϤ…ûÅJSd¥¹û¥¿2u(-Ü/Q…×fÈî±Ì}qq@4ï •Ü7þ‡\á|sž“zÙ¡†lá|Áx­×¸ ÙÂùR\=Yir@,ž¶Ýø sç‹^}òˆ­:_ð™ $U¤:_²ó[,†ÂÂ÷‚ñJÐ]V˜û^ôÈŒ—5ó½pÀ©øÈà#ß‹ vØ\)iÕ÷öF2›ZCiî{1S7+ ›§ø^ŠaëIPRó½à²!3)©ÿœî{%,)­ú^àÍNmåÅ÷rrÙŒz’#¢ù^:—ÍÍ}/¸lcÍ6-\/*@¡°œ’„ëE ¡e…U׋…€iIaáz»dN.$`tîzéP„Q?¶®©ý’ìÈp½t”„¹ç…kV)Øž‰AÉu#Èy^ÅÍJ ϋ̹ð ŽZžŽ^ø ’ªã…u¡:‡ÂÜñÒß):dsÇ‹˜ÓúˆR/ý­Š#iáx1à99láxéÿ¡4s¼8qTmÈ厪åR*#»@â]+޽ž¼5§‘áxQzzª…ã…røD%:b1j[8^Øó ËNšZœÈÍñ"åãP?æ~—•TN‡Åïò’¬p»¼Ö°p»¼ÖávÁâZ*¦5êp»0ÖT†pÿÉÍÝ.¯)d¸]^Sÿp»oYrÔÂë‚ÔƒPù¤öW· U½ |Ô#X<êvymÍ ·Ëk+du»¼´£ˆÅíòÒâOD“y]^Úiª×å¥}íäuÉ ZãuyeË®^—W¬ƒÆé"e³ë#G-wº¼bø„Ó¥÷ž Ô§„;]^±éªÓeô-¢†ÒÂéòйZ½.¯ØÆ$¹ÓåCœ(uº¼fõSc°8]$,,Æ ŸÊ.¯œhX¤Ìébn¤ö«I­N—WNk&uqº¼t6ÄMcNöާÔ_OY”Ùp§Ë+çÞÆéòÊ)›âætyéL¿±¯‹ºÁKcâÂFú_½.Ý¢C¶ðºÈlE‡lîuy ŠÁ"3¯‹]¥Êǘ×ÅŠ“:Y½.¯`Z?Ýëò ‚Fñ󺼀֑íN—A"iÜçò It»ù\^=‰H2ŸËK+•øÝçò  Ûú\š˜ÿ‘>VŸË+Xõ>—ä:Òú\ò0<Éë½Ï%+­÷¹$•ŸhçsÉ ;ù\rÒZå„“«f9]>š)3äú¸«fÈöqW͈í®š!Û)SÆ:rÈöqWÍí£®š!×Ç]5#¶ÖUÓøE‡lž)Ó'Ø ÙÜUÃr.µŽ’‰e`™2Ý9”Ö¸jš›[ë«il†l³†ÛÜU?d gMñðÛܲ5Î 'Hö¤+ÅY#g¯‡£žCaH‰¤°ê¬‘¬†»Ç©¤Ugˆ«)á-¼5x4ÖÙA­![xk$¾:">‡lá­‹>¢Ðl·t—¢T¹¶5Þš.Áf(,™2;K¨Kª'WŽOæ­:©$³F@ÅÕaÿÑ7Vg ñÕsZZuÖ€eR9&Ù4wÖHÐQ ŽÅ?2œ5B5ÀtÈΚ.žoÈÞ "ÿ[xkXöÒ³­I”‘%=Bµ†ÂÂ[#¶Éì0ë-¼5„>ƒ<'‡­zkF[n‘$ÊÜeˆ+ÅLJsw —HÕ„¯QË"Q$ŸâÕYQá­éB‡ÂÜ[£ rD3ت·<¡Æ—Ù8D•<‚k4ë-Ü5²Df§ÇÊ’&ÓÇÄ……·¦K ±UoMÉîH[õÖÈ ™ÔFO’g6A©YQá«‘K¨ä¶Òl¾sºd¥y’ Þ) ”lZõÕ§KRZõÕ¨Ó%+¬qÕÒ—]ú#G¦óÕŒ¤új^jÙ'œ5#i­³Fº?ÙÕYÂWä¡´È‘)ª••Κ¢ÈÉa«Î™3IYÕUÓe_Z¾ HIËJ‹N#þx(Í}53•È9ÊYYá«‘ÐjVÕd7V_Í"¸e—‘ê«‘à˜);±«³¦ìOÙ¶‰Q­)2RÚ`JZþ”´a' %Õ‘³´®ûF­qÖ›"+cFI‘)Lnت·p½Öz~£eÈà6ÀÓ–\û«³׆$åº1dÈY«3Ù0µ¨%Aæ.LV_MIZÉJ gM±ß“m gÉýºñÕH¹´¹~ _ ¾l*ö$ížÆW£‡®¬0±§ÕUSNxÉn¬®IsÌšá«ë&)­ºjd$ä<ב‘ÃL`crl\5ÈJ W¬«s¶mÕU#PÙ¹Vócd5ŽÔ“Ñrù1V%Ù´ÖS#ÅX’ÃV=5Ü“[ƒGY=5â¨dg[õÔt¹'Ciî©)5t’M«®š(&;²õÕ|™”ö _ͨiŸðÕ Ù>y~Lqºd›&PšÓùj†ÂNù1IiŸðÕŒ¤}ÂW3dû¨¯fÈõq_Íí㾚Û9?Æúq¹jNNSÿ!ÛÉé’”vvº$¥µù1Rg,+íätÉJs§Kqpf…5N—Æ{2êÈêtéÊ“ ÙÜéÂ++ɦééPË“ukäPZ8]ºyÈN—nù±U§Kqƒ$ÛÖ–'k²*‡ÒÂéRü Yiît1?HRKÜéÒ§§¿1œ.Å ’V. øÏI«N—.ÑwÈæN—>­xÈæN oôãá+|.%g%7jÏ¥KÏH«>—>|È>—.õ|È>>’Ê×Ù¶‰þju2bHÈ)I“!Ó%ñ>Ò.§’C6Q`­NÖ(²…Ó¥œ,³ms§K_{a(-œ.˜4Q aÄå>þåê0wg ¹$dM‹“±ÆÖšBC6÷¹ô3†lás!˜•˜ìd?VŸ x)!I¬>—}dõ¹îGí!“•µ8YWSeÈNÙÙ¢€ËÍ.œ8tgû1œ.^1#i5GïI­Í7ds§K_xgÈæ^oŒ2?C¶ðº K\RGÂëÒ0 §Kï²É Qj“1 jüýËÝ.}!¨!›»]°gš²SC6w»ôE®Fláv±"cÉ™ncKŽZ¤ÈtiÃo”¢•&åvt|ÈÆšÿ‘Úd#¶ð»¼Ö´ð»ÀÖyJ“p&­MVF;Ù‘‘$£Ò[v!A­6YÑ䤴𻠶qjŒÚFOXm2Ù¬¢àM,k­MF 2UÆ’*Y2`}M•á4ó¼Pf†{€qUÏKWÀqÈÅÉ:ÊͳdpÉR$Ë}QC¶H“Áz¢”l²#kšL†0Ö;^r²ÇKWRt ¬q¼pÂÉn£]–ÌJBZNû«ß¥¯Ì:üFw¼”è–¤°š%#ÑÁX„UÏKë¯r‰U­•ÉX…j9Ý!› µ4™DGõÒ![8^ºRÁ#¶(MÖåÖ ¹$`DŠõôU‡l‘%# T*~†!›¬‹ZšŒTGÜŽIí¯Y2,ÇÜ@Ÿ•æY2}õêÑGF– ËyS+{ÈY2]àà-J“GO²m‘%Ã~*ŽždOÖ,™âèIJ«®N|µ¢ú¨mÕ÷‚[£²y– Ö×È%1‹š%ƒ­&99Ù¶E– +óÁ£¬¾Ùk¢2÷-²dJå—ä¸E–ŒìP镤ú^ ®˜y2ÅLvdø^$,/ Œ:$\/th§>d ×Ë+¸î9M&Û²p½¼Y&“”Öº^òhüi2Yi½ë%©"ç4™¬°“륗öõ7?}üÈõ.òß¿½~ýOß½ÿíŸ~ÿßß}óÇ÷üá÷ß÷§~ÿm¹C»\vVž¶ßöë‚UÆ-™ûõ­,ܾ¨NÑ_¾#ÅFŸÔ°_¯ï¸ïåÝ»é~®ï~w}ó_]ßýáúßé½*Ÿ|9Õ¨åÆËfW:©——¿EwïÔ`÷í@ο ég_]ß>¯oþò«ë¿^ßýj,“í„R—×·Tåç–ÇŸ$óçY™xä* -Q¾ïja3ÿ*/’ ºÔzäTÛ?Eä_çE’°p¹§TÁùI"ÿ&/òÎ}aW"$ x~hèÃvìoÞt2/ŸVZ#PÅ«–ÙK¼ôge^ú¹Ñèìo¾êd^?%óIÆüÊúw}‹ Å5¥ä› Sóä(ë|}ó³d×>Añ¨qùÅ߈¼ñ@¶!Å-J˘ú¤Q¤›†É+IYËË|ó $ŽÛF؃E½ÏŸÒ6ÒWš&H×8~ òϱ\¯ \äúøàå_²\'Õ´&î,ú° íI¦XsCáGÛ#7Pd¶Ÿ¿”íG´¯oÐ'—.kºQ>Ùë™ÊŸjÑ¥l¨©Ù´sç8ÕÙËu„,2-ú¹´ˆ•¢oìöaðºj.p[(‹/1¯mÉ^${8 )"Y,õ¶8ù§±ØÅV°õ½’=üít}C[eGÿ«¯.o·ø]¨|Í{S~‘%û-&ÇYGß×7¿øJd½ù[#ÿ]YÞꯗ7·òëGx3†p)‡eY¹HÄ­cmk0UÇ2íü;ëZûG›»²pÑP>›¯KNÀ›¯s›wùb=QZ0>¨ öE›zû2Øk±ÒäŸ¦ç—®ç±„Òæ“:ß¹9© ›3z;p4Üon÷Ìâù$€BÐè7ëp²ѸÕªaÛ~Ž­ô–i•5 —€©ïˆü¼ú¾™2ÍY)ÂO!¼5rf¤þšùø–x51­uÁQíß/ªü)¦wñ¶6œšçÖŠÍÎdóp¾¾ºÞÍ*xgmÌ4ïg2w™Ê:w¯o˜ºµM\üw¿_þ¥ýÿûÃU6ßüš —ÛÀw~âîm*ÓLB“›Ù(ñöëo¸åR!Ò!(A˃:tvTgr%ë1êÍ—¢Ï²Z}ÏŠ ’'š÷W¿´®zír¸p¡Àòdä*ÉbQ@í—ï´õ|ܧ§ÄÚÍC M]Y XeO‘‚ßþâ+.;—õ°éV`îFŸº^P§\Û©Y#·O=~JÛŸR'ÿÉÝh?¡í²"³ ZkkÛ)xøæ/þæ«KÕ¬_‚¾9)Òj®µcLeÄ®œ–jqWÎ;LáC›´ÍtÛ÷=mšHF§–;¥{~à6î‰g,°!(ò.)"DøYи©Eî»Ô—Ë‹xD Q•&\þŒ–]Úש§L!«ÊgÛ)I¿ÐÚ¯9·ìÛë¿]§ºª§{Qöë§d“¢Ÿ{Œ‘­Ù2;³ú)«Íl[-«²lV2,=â3äMsŸPˆ (Ф£"q¬rï^ô£ÒÒʨ@árô¦»c¹eKØl˜è)àœ]°Ï  …ûüÀ*„2*F醥>åZßdãRÅŸÄ'Ù°ÔŽ·œ›–œ¨\™øøs Ë&—ù¨‚pÇ/ƒ¾Ê6QŒ:ml¡d²l$nÚû}GÒ¾”gîéæÑß^?,¼,e§>[¡  S”Ž"såRøì)ëÎæMe ª4ÿ"^íÈÅ +_è/9·+=$rÜ •ûÈVòŸ0SØÂʵ‰âCRWí:e˜²pËL“Kk‹2ÛúÕÑÊ °ÝrŠšA9@êÈ»ÄH9œ)îĦ6#7ÅTqJ;Uœ¦üàf¤öMÖåU\ Ký&&šâãòAãòƒ±+]ôgŽl­Ý°üãÿ=³Ü endstream endobj 6 0 obj << /Producer (macOS Version 11.6 \(Build 20G165\) Quartz PDFContext) /CreationDate (D:20211028010201Z00'00') /ModDate (D:20211028010201Z00'00') >> endobj 7 0 obj [/ICCBased 24 0 R] endobj 8 0 obj << /Type /Font /Subtype /TrueType /BaseFont /AAAAAC+Candara /FontDescriptor 25 0 R /ToUnicode 26 0 R /FirstChar 33 /LastChar 42 /Widths [ 549 252 350 462 486 533 491 552 473 252] >> endobj 9 0 obj << /Type /Font /Subtype /TrueType /BaseFont /AAAAAE+Candara-Bold /FontDescriptor 27 0 R /ToUnicode 28 0 R /FirstChar 33 /LastChar 49 /Widths [ 560 385 559 555 491 249 258 363 489 217 550 512 550 419 353 353 252] >> endobj 10 0 obj << /Type /Font /Subtype /TrueType /BaseFont /AAAAAG+Candara-Bold /FontDescriptor 29 0 R /ToUnicode 30 0 R /FirstChar 33 /LastChar 43 /Widths [ 658 485 556 515 491 596 697 665 645 527 574] >> endobj 11 0 obj << /Type /Font /Subtype /TrueType /BaseFont /AAAAAI+Candara-Italic /FontDescriptor 31 0 R /ToUnicode 32 0 R /FirstChar 33 /LastChar 43 /Widths [ 333 495 453 419 740 353 564 353 512 488 900] >> endobj 12 0 obj << /Type /Font /Subtype /TrueType /BaseFont /AAAAAK+Candara /FontDescriptor 33 0 R /ToUnicode 34 0 R /FirstChar 33 /LastChar 42 /Widths [ 549 252 350 462 486 533 491 552 473 252] >> endobj 13 0 obj << /Type /Font /Subtype /TrueType /BaseFont /AAAAAM+Candara-Bold /FontDescriptor 35 0 R /ToUnicode 36 0 R /FirstChar 33 /LastChar 49 /Widths [ 560 385 559 555 491 249 258 363 489 217 550 512 550 419 353 353 252] >> endobj 14 0 obj << /Type /Font /Subtype /TrueType /BaseFont /AAAAAO+Candara-Bold /FontDescriptor 37 0 R /ToUnicode 38 0 R /FirstChar 33 /LastChar 44 /Widths [ 658 485 556 515 491 596 697 665 645 630 523 526] >> endobj 15 0 obj << /Type /Font /Subtype /TrueType /BaseFont /AAAAAQ+Candara-Italic /FontDescriptor 39 0 R /ToUnicode 40 0 R /FirstChar 33 /LastChar 45 /Widths [ 333 495 206 504 740 453 419 353 564 353 512 488 900] >> endobj 16 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /Interpolate true /ColorSpace 7 0 R /SMask 41 0 R /BitsPerComponent 8 /Length 35 /Filter /FlateDecode >> stream xc`Àâ<«âÁÈ€H¹ ^Õ@dàÁÔ…f4Üi) endstream endobj 17 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /Interpolate true /ColorSpace 7 0 R /SMask 42 0 R /BitsPerComponent 8 /Length 37 /Filter /FlateDecode >> stream xc`ÀLâúÍâ'‘²Í&KSšÑâ¥Y endstream endobj 18 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /Interpolate true /ColorSpace 7 0 R /SMask 43 0 R /BitsPerComponent 8 /Length 35 /Filter /FlateDecode >> stream xc`ÀÊ'[—M²" " f¹ A\"˜ºÐŒV‚M endstream endobj 19 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /Interpolate true /ColorSpace 7 0 R /SMask 44 0 R /BitsPerComponent 8 /Length 36 /Filter /FlateDecode >> stream xc`À&›˜L13" " dO5! —¦.4£iqé endstream endobj 20 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /Interpolate true /ColorSpace 7 0 R /SMask 45 0 R /BitsPerComponent 8 /Length 35 /Filter /FlateDecode >> stream xc`Àâ<«âÁÈ€H¹ ^Õ@dàÁÔ…f4Üi) endstream endobj 21 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /Interpolate true /ColorSpace 7 0 R /SMask 46 0 R /BitsPerComponent 8 /Length 37 /Filter /FlateDecode >> stream xc`ÀLâúÍâ'‘²Í&KSšÑâ¥Y endstream endobj 22 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /Interpolate true /ColorSpace 7 0 R /SMask 47 0 R /BitsPerComponent 8 /Length 35 /Filter /FlateDecode >> stream xc`ÀÊ'[—M²" " f¹ A\"˜ºÐŒV‚M endstream endobj 23 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /Interpolate true /ColorSpace 7 0 R /SMask 48 0 R /BitsPerComponent 8 /Length 36 /Filter /FlateDecode >> stream xc`À&›˜L13" " dO5! —¦.4£iqé endstream endobj 24 0 obj << /N 3 /Alternate /DeviceRGB /Length 2612 /Filter /FlateDecode >> stream x–wTSهϽ7½Ð" %ôz Ò;HQ‰I€P†„&vDF)VdTÀG‡"cE ƒ‚b× òPÆÁQDEåÝŒk ï­5óÞšýÇYßÙç·×Ùgï}׺Pü‚ÂtX€4¡XîëÁ\ËÄ÷XÀáffGøDÔü½=™™¨HƳöî.€d»Û,¿P&sÖÿ‘"7C$ EÕ6<~&å”S³Å2ÿÊô•)2†12¡ ¢¬"ãįlö§æ+»É˜—&ä¡Yμ4žŒ»PÞš%ᣌ¡\˜%àg£|e½TIšå÷(ÓÓøœL0™_Ìç&¡l‰2Eî‰ò”Ä9¼r‹ù9hžx¦g䊉Ib¦טiåèÈfúñ³Sùb1+”ÃMáˆxLÏô´ Ž0€¯o–E%Ym™h‘í­ííYÖæhù¿Ùß~Sý=ÈzûUñ&ìÏžAŒžYßlì¬/½ö$Z›³¾•U´m@åá¬Oï ò´Þœó†l^’Äâ ' ‹ììlsŸk.+è7ûŸ‚oÊ¿†9÷™ËîûV;¦?#I3eE妧¦KDÌÌ —Ïdý÷ÿãÀ9iÍÉÃ,œŸÀñ…èUQè” „‰h»…Ø A1ØvƒjpÔzÐN‚6p\WÀ p €G@ †ÁK0Þi‚ð¢Aª¤™BÖZyCAP8ÅC‰’@ùÐ&¨*ƒª¡CP=ô#tº]ƒú Ð 4ý}„˜Óa ض€Ù°;GÂËàDxœÀÛáJ¸>·Âáð,…_“@ÈÑFXñDBX$!k‘"¤©Eš¤¹H‘q䇡a˜Æã‡YŒábVaÖbJ0Õ˜c˜VLæ6f3ù‚¥bÕ±¦X'¬?v 6›-ÄV``[°—±Øaì;ÇÀâp~¸\2n5®·׌»€ëà á&ñx¼*Þï‚Ásðb|!¾ ߯¿' Zk‚!– $l$Tçý„Â4Q¨Ot"†yÄ\b)±ŽØA¼I&N“I†$R$)™´TIj"]&=&½!“É:dGrY@^O®$Ÿ _%’?P”(&OJEBÙN9J¹@y@yC¥R ¨nÔXª˜ºZO½D}J}/G“3—ó—ãÉ­“«‘k•ë—{%O”×—w—_.Ÿ'_!Jþ¦ü¸QÁ@ÁS£°V¡Fá´Â=…IEš¢•bˆbšb‰bƒâ5ÅQ%¼’’·O©@é°Ò%¥!BÓ¥yÒ¸´M´:ÚeÚ0G7¤ûÓ“éÅôè½ô e%e[å(ååå³ÊRÂ0`ø3R¥Œ“Œ»Œó4æ¹ÏãÏÛ6¯i^ÿ¼)•ù*n*|•"•f••ªLUoÕÕªmªOÔ0j&jajÙjûÕ.«Ï§ÏwžÏ_4ÿäü‡ê°º‰z¸újõÃê=ꓚ¾U—4Æ5šnšÉšåšç4Ç´hZ µZåZçµ^0•™îÌTf%³‹9¡­®í§-Ñ>¤Ý«=­c¨³Xg£N³Î]’.[7A·\·SwBOK/X/_¯Qï¡>QŸ­Ÿ¤¿G¿[ÊÀÐ Ú`‹A›Á¨¡Š¡¿aža£ác#ª‘«Ñ*£Z£;Æ8c¶qŠñ>ã[&°‰I’IÉMSØÔÞT`ºÏ´Ï kæh&4«5»Ç¢°ÜYY¬FÖ 9Ã<È|£y›ù+ =‹X‹Ý_,í,S-ë,Y)YXm´ê°úÃÚÄšk]c}džjãc³Î¦Ýæµ­©-ßv¿í};š]°Ý»N»Ïöö"û&û1=‡x‡½÷Øtv(»„}Õëèá¸ÎñŒã'{'±ÓI§ßYÎ)ΠΣ ðÔ-rÑqá¸r‘.d.Œ_xp¡ÔUÛ•ãZëúÌM×çvÄmÄÝØ=Ùý¸û+K‘G‹Ç”§“çÏ ^ˆ—¯W‘W¯·’÷bïjï§>:>‰>>¾v¾«}/øaýývúÝó×ðçú×ûO8¬ è ¤FV> 2 uÃÁÁ»‚/Ò_$\ÔBüCv…< 5 ]ús.,4¬&ìy¸Ux~xw-bEDCÄ»HÈÒÈG‹KwFÉGÅEÕGME{E—EK—X,Y³äFŒZŒ ¦={$vr©÷ÒÝK‡ãìâ ãî.3\–³ìÚrµå©ËÏ®_ÁYq*ßÿ‰©åL®ô_¹wåד»‡û’çÆ+çñ]øeü‘—„²„ÑD—Ä]‰cI®IIãOAµàu²_òä©””£)3©Ñ©Íi„´ø´ÓB%aа+]3='½/Ã4£0CºÊiÕîU¢@Ñ‘L(sYf»˜ŽþLõHŒ$›%ƒY ³j²ÞgGeŸÊQÌæôäšänËÉóÉû~5f5wug¾vþ†üÁ5îk­…Ö®\Û¹Nw]Áºáõ¾ëm mHÙðËFËeßnŠÞÔQ Q°¾`h³ïæÆB¹BQá½-Î[lÅllíÝf³­jÛ—"^ÑõbËâŠâO%Ü’ëßY}WùÝÌö„í½¥ö¥ûwàvwÜÝéºóX™bY^ÙЮà]­åÌò¢ò·»Wì¾Va[q`id´2¨²½J¯jGÕ§ê¤êšæ½ê{·íÚÇÛ׿ßmÓÅ>¼È÷Pk­AmÅaÜá¬ÃÏë¢êº¿g_DíHñ‘ÏG…G¥ÇÂuÕ;Ô×7¨7”6’ƱãqÇoýàõC{«éP3£¹ø8!9ñâÇøïž <ÙyŠ}ªé'ýŸö¶ÐZŠZ¡ÖÜÖ‰¶¤6i{L{ßé€ÓÎ-?›ÿ|ôŒö™š³ÊgKϑΜ›9Ÿw~òBÆ…ñ‹‰‡:Wt>º´äÒ®°®ÞË—¯^ñ¹r©Û½ûüU—«g®9];}}½í†ýÖ»ž–_ì~iéµïm½ép³ý–ã­Ž¾}çú]û/Þöº}åŽÿ‹úî.¾{ÿ^Ü=é}ÞýÑ©^?Ìz8ýhýcìã¢' O*žª?­ýÕø×f©½ôì ×`ϳˆg†¸C/ÿ•ù¯OÃÏ©Ï+F´FêG­GÏŒùŒÝz±ôÅðËŒ—Óã…¿)þ¶÷•Ñ«Ÿ~wû½gbÉÄðkÑë™?JÞ¨¾9úÖömçdèäÓwi獵ŠÞ«¾?öý¡ûcôÇ‘éìOøO•Ÿ?w| üòx&mfæß÷„óû endstream endobj 25 0 obj << /Type /FontDescriptor /FontName /AAAAAC+Candara /Flags 4 /FontBBox [ -468 -284 1115 952] /ItalicAngle 0 /Ascent 725 /Descent -275 /CapHeight 644 /StemV 0 /Leading 221 /XHeight 483 /MaxWidth 1164 /FontFile2 49 0 R >> endobj 26 0 obj << /Length 247 /Filter /FlateDecode >> stream x]PAnà ¼óŠ=¦‡È˜ôR !U‰"ù´ªÛ`X[H5 Œþ}’¦Rs˜e˜æØ:ï24ï)˜3ŒÎÛ„KX“Apržµ¬3ùÎêÌÌ:²†Ìý¶dœ;?’4dYrÚ`÷jÀOeö–,&ç'Ø}û:é׿qFŸ3¥ÀâHç.:^õŒÐTë¾³¤»¼íÉõ·ñ¹EJDŽöÉ‹KÔ“ö2ɹ’ç³bèí?éùfÆû¦h•,àüÀ“B%p.°ÐÑ—ª¶…j¢Rm=þ{¦¼Súxä7kJ½–VUÒ:^cˆ%]Å6%yí endstream endobj 27 0 obj << /Type /FontDescriptor /FontName /AAAAAE+Candara-Bold /Flags 4 /FontBBox [ -496 -278 1160 952] /ItalicAngle 0 /Ascent 725 /Descent -275 /CapHeight 644 /StemV 0 /Leading 221 /XHeight 483 /MaxWidth 1194 /FontFile2 50 0 R >> endobj 28 0 obj << /Length 316 /Filter /FlateDecode >> stream x]‘ËjÃ0E÷þ -ÛE°lç ÂPR^ôAÝ~€-ƒ –…¬,ü÷½£¤)tqG3WŒFù±ynœ"“n)ŠÁ:hž.A“èél]V”ÂXo–ÎôØù,G¸]æHcã†I(• ‘ 2ǰˆ‡'3õôÈgoÁP°î,¾Žm:i/ÞÓH. ™Õµ04ທοv#‰> endobj 30 0 obj << /Length 287 /Filter /FlateDecode >> stream x]‘ÍjÃ0„ïz ÓC°ì&iÆPR>ô‡º}YZA- Y9øí;«¤)ô0‡oggY­ŠCûÜz—dñ'ÓQ’ƒó6Ò<£!ÙÓÉyQVÒ:“®”kfÔAwËœhlý0ɺRˆÌ).rõd§žî¸ö-EçOrõuèr¥;‡ðM#ù$•hiiÀ¸^õH²ÈÑuká»´¬‘úëø\Il„DyYÉL–æ  EíO$j¥šúxlyûÏ*Õ%Ñ×Öªlj–RÛm#êªBJm ã=‚«7@¨·@Í;Æ‚[1>!¸ã#ã¨3n{ „,Faïßù |êÛiÌ9F\%ÿG>Âyº}Y˜Èúÿ« endstream endobj 31 0 obj << /Type /FontDescriptor /FontName /AAAAAI+Candara-Italic /Flags 68 /FontBBox [ -402 -283 1072 952] /ItalicAngle 0 /Ascent 725 /Descent -275 /CapHeight 644 /StemV 0 /Leading 221 /XHeight 483 /MaxWidth 1113 /FontFile2 52 0 R >> endobj 32 0 obj << /Length 276 /Filter /FlateDecode >> stream x]‘ÍjÃ0„ïzŠ=¦‡`Ù4vÆPR>ô‡º}[ZA- Y9øí;RÒz˜Ã§ÝYfWÙ±}n­ ”½ûYuh4V{^æ‹WLŸyAÚ¨p£ô¦¦Þ‰ æn]O­gªkA”}À²¿ÒæIÏ?Ä·7¯Ù{¦Í×±K/ÝŹožØ’¢iHóˆq/½{í'¦,Y·­FÝ„u ×_Çç꘎üIÍš×+ö½=³¨¥lêÓ©lõ¿ÒþjÆ[g‘7u””eÙˆº(€«}ÄVK $e‘ª’r—p„P=Äæ°OÕ„B3F!Øo„˜1Þò¾»ºxµÓÁÓEâ¦ÆòýOÜì․„!†8 endstream endobj 33 0 obj << /Type /FontDescriptor /FontName /AAAAAK+Candara /Flags 4 /FontBBox [ -468 -284 1115 952] /ItalicAngle 0 /Ascent 725 /Descent -275 /CapHeight 644 /StemV 0 /Leading 221 /XHeight 483 /MaxWidth 1164 /FontFile2 53 0 R >> endobj 34 0 obj << /Length 247 /Filter /FlateDecode >> stream x]PAnà ¼óŠ=¦‡È˜ôR !U‰"ù´ªÛ`X[H5 Œþ}’¦Rs˜e˜æØ:ï24ï)˜3ŒÎÛ„KX“Apržµ¬3ùÎêÌÌ:²†Ìý¶dœ;?’4dYrÚ`÷jÀOeö–,&ç'Ø}û:é׿qFŸ3¥ÀâHç.:^õŒÐTë¾³¤»¼íÉõ·ñ¹EJDŽöÉ‹KÔ“ö2ɹ’ç³bèí?éùfÆû¦h•,àüÀ“B%p.°ÐÑ—ª¶…j¢Rm=þ{¦¼Súxä7kJ½–VUÒ:^cˆ%]Å6%yí endstream endobj 35 0 obj << /Type /FontDescriptor /FontName /AAAAAM+Candara-Bold /Flags 4 /FontBBox [ -496 -278 1160 952] /ItalicAngle 0 /Ascent 725 /Descent -275 /CapHeight 644 /StemV 0 /Leading 221 /XHeight 483 /MaxWidth 1194 /FontFile2 54 0 R >> endobj 36 0 obj << /Length 316 /Filter /FlateDecode >> stream x]‘ËjÃ0E÷þ -ÛE°lç ÂPR^ôAÝ~€-ƒ –…¬,ü÷½£¤)tqG3WŒFù±ynœ"“n)ŠÁ:hž.A“èél]V”ÂXo–ÎôØù,G¸]æHcã†I(• ‘ 2ǰˆ‡'3õôÈgoÁP°î,¾Žm:i/ÞÓH. ™Õµ04ທοv#‰> endobj 38 0 obj << /Length 291 /Filter /FlateDecode >> stream x]ÑÏjÄ ð»Oá±=,1ÙͶ…([rèšöŒN¡1bÜCÞ¾ßØízø?Ç‹C÷Ôy—dñgÓS’£ó6Ò2Ÿ£!9ÐÉyQVÒ:“.ÊkfÒAhî×%ÑÔùq–M#¤,ÞѲ¤¸Ê›G;tËk¯ÑRtþ$o>}^éÏ!|ÑD>I%ÚVZqܳ/z"YäÖMgQwiÝ ëoÇÇHâFè(®dfKKІ¢ö'Rms<¶‚¼ýW*/ÃxÙZ•mÃQª®[ÑTˆ(µ3Ì-ˆ ª˜;5³lÞ3÷ ‚jżTGæ=ˆ€Ä|pÇÔ –Ì4Ìz›Ÿñ{_~Oþ:)sŽCÊß“çÇsqž®?æÀsÈù½ÐM endstream endobj 39 0 obj << /Type /FontDescriptor /FontName /AAAAAQ+Candara-Italic /Flags 68 /FontBBox [ -402 -283 1072 952] /ItalicAngle 0 /Ascent 725 /Descent -275 /CapHeight 644 /StemV 0 /Leading 221 /XHeight 483 /MaxWidth 1113 /FontFile2 56 0 R >> endobj 40 0 obj << /Length 293 /Filter /FlateDecode >> stream x]‘ÍjÃ0„ïz ÓCðÚiþÀBJÀ‡þP·`Kk#¨e!+¿}GjšBsøvw–Õ(;×Oµ5Afo~R Ù«=ÏÓÕ+–ÆŠ¼Ú¨p£TScëDs³ÌÇÚö“,K!eöËü"W'=uük¯^³7v«Ïs“*ÍÕ¹/ÙI¢ª¤æëž[÷ÒŽ,³d]×}–5\‹c‰‹àÈNR“æÙµŠ}k%QU^.•`«ÿµò›£ëo£E^•QD»]%Ê¢BDûCÄ "*(â#"Úèˆ[ „á}ÄpŸðñ„àM«Ž@ˆh›°Bè¦á¨R7¡BÆf<ã÷Þø¢˜ü=)uõ!¥ïIùÅ\ŒåûºÉÅIߤÇA endstream endobj 41 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /ColorSpace /DeviceGray /Interpolate true /BitsPerComponent 8 /Length 27 /Filter /FlateDecode >> stream xc`ÏÇ=ÿÿÿFBDÀ’â0 9 endstream endobj 42 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /ColorSpace /DeviceGray /Interpolate true /BitsPerComponent 8 /Length 27 /Filter /FlateDecode >> stream xc`ÏÇ=ÿÿÿFBDÀ’â0 9 endstream endobj 43 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /ColorSpace /DeviceGray /Interpolate true /BitsPerComponent 8 /Length 27 /Filter /FlateDecode >> stream xc`ÏÇ=ÿÿÿFBDÀ’â0 9 endstream endobj 44 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /ColorSpace /DeviceGray /Interpolate true /BitsPerComponent 8 /Length 27 /Filter /FlateDecode >> stream xc`ÏÇ=ÿÿÿFBDÀ’â0 9 endstream endobj 45 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /ColorSpace /DeviceGray /Interpolate true /BitsPerComponent 8 /Length 27 /Filter /FlateDecode >> stream xc`ÏÇ=ÿÿÿFBDÀ’â0 9 endstream endobj 46 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /ColorSpace /DeviceGray /Interpolate true /BitsPerComponent 8 /Length 27 /Filter /FlateDecode >> stream xc`ÏÇ=ÿÿÿFBDÀ’â0 9 endstream endobj 47 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /ColorSpace /DeviceGray /Interpolate true /BitsPerComponent 8 /Length 27 /Filter /FlateDecode >> stream xc`ÏÇ=ÿÿÿFBDÀ’â0 9 endstream endobj 48 0 obj << /Type /XObject /Subtype /Image /Width 6 /Height 6 /ColorSpace /DeviceGray /Interpolate true /BitsPerComponent 8 /Length 27 /Filter /FlateDecode >> stream xc`ÏÇ=ÿÿÿFBDÀ’â0 9 endstream endobj 49 0 obj << /Length1 1368 /Length 1081 /Filter /FlateDecode >> stream xS}L[U?÷Ý×÷ í¶¶¼l­@[h§Ì‘Яñ¡–ÍgQ+#2À.›ƒ!“`B6³ 0ýEC\ÈDDÁ8“‘@Ã\ h–ÀtŠŒ-#ôâym‰ú¯'¹ï|Þß½çwî««­/54(©òÖ@@H ª]G/ùc´¦¢Ì[ôaµ»¡¼u|EU/俈z×±×K6óýèGWy}!|¸…~\µ·ª,X¯Ú£øAûÿ nÅ6þ% $à!th+±MQlU÷ãvŸ|y[ú°]ÈŒd¯¾­ßœÎ[Ïô«—Ä÷Ñ .C5éŸ$×à Ö3Y¡zé?¨J‘†öp<øpÙù2Ô“K¯B)]€t>íeðñ¯ŽA.Ö“‚ˆAß áØ Á›«0"â„Â0<ÿYðB tÂüD´$•¼J.’¡`´GeÂ}"X`7‚êÍúÀ²;Ý·Ûå´Y-‚hw»É‘²$ˆ‚ ‹ÎcµØhÏz1Ýï7§¹¼˜óóžÔç4EÚ¶’—šŸÌÉŽª°M6›ÉhS™ÝQ™Ö2øòµNR{²Ü”šnÎ:RX´µÙw¦2¥8멼âÎ@iBvàÛ`¤Dà AðWàHÒV›–yp_ZÆù´¢|wêáXk'ƒä6—£ ‘ˆ*¹­e‡Â¸œÓ[›LDºKïñ;) ógµp.§Á‘l N›hd)Ò“ì¦÷–œšSÖ'—Zß¹ÔRw‘3>`#dçÏH6›e+£ËÜüGø™RXGî91µH¹ÕíÒÙE;qpz‰ãû4š;I¤â…ð› D|³ö0 c_³3¸ÿš{dìH4{â‘X³Eô‰QŽ£ù’ÿ ‰ÐØ/Ç÷I|s3ì·qbjoo½z¿û¦®]8}Í6«+ÕÑJÄ™'H ²ÇÇ+SÂ>ÃÚåÈHZÉ*Ù[‘$rˆ­HßþÙÝs¢X[<:8z·±·c‚ GœÆ{»ßh8ê-”Û]•·ò£‡ÞrÙ ]äcñõoWxµJVƒËlw‚Ý!è“©UYNöè¢ü©¶Oí—¹rC{äW5+ì_ãˆçòWl†pó§vpsÛæý÷¹2£L§‰ïïcçibKÿ¾¿áE›YãxÚÀªY¿‰H$…±¡=\‰0ÉÄI¯|Ï®miÐOv}ÜJÆz?0}Ó;˜ñ4}¨Ê=˜B3½.!Šç¨CáWTž°¨‹tà þ>ýós#[Øê_QšWæ?›¸rù½³E]õ§Î‘ Ÿ³UMt4*±ÎÈ6Ø£3+×›†êÙÆB_`êÈHu€|GT œlwF€Çನ<´úÝô©sýD¥ï˜eû>öK6ÜÊjÙR–ü É„…Ä6ìø0ðÏEØ ©ÈÞĽÞêRo­÷o#·Dô endstream endobj 50 0 obj << /Length1 2068 /Length 1647 /Filter /FlateDecode >> stream xU{P”׿çÞï±èÂ~»ì£)Ëc÷ »FC­ìK¨º²É‚¯Hœh$T@Š€b B¬ AQFub,‰ÆhÛ$f’”˜˜TjEœŒ­“Çtjk5>ðÑ4 qîöÜ]ÒNúgï7÷»÷Ü{¿ß9çwÎ¹ßÆ WÙB!«ëÊדxƒnò×Ô6W%d*"_­®,¯HÈd Ç`5.$dðãxouÝÆ¦ y9ŽÑÚu«¿Ùÿ3Êžºò¦ |"ä¬úòºÊÄyõŽSóÿÿ ø)ºñß&,d:Aë±Q¢á\¬}ÓÄ\~á¾¢²VRfšõ¹Çßy¯`d«˜üñásóÇ ãIQõ—ø]"$~'Ÿ?'“vŽxqRô[¨âŒ…"ÞC{n‘Bi=Y.­!éNj¨Fš¥*•špí RÌld[IæÐ+d»NtdÛK?&‹EG,˜@7…ܲ‹˜É$2íah‘BT’LRðŒDdŒ¤½4“0Û||ÚÈ»ä6¤AVÀ6èkÔHgÓú<}™ž¥ÿÂSq~Ø!Ù‰ˆ*q“ï¡R³Ëï^0 üÝ­¨Þ`Зk·YUQlªBÐÝvh¬„Ž[àº0#ÏõH(ÉäÆí«W=•)pT{Òœ3Í#;ï^’£³¥ªÑ.XœÙRåÌŸå ¯,^‘òTSûÚ¼’ð–tÅfg£o…±+ì;OÒI6!Ùª' +¨+à¿7;aš°ÀfõzY6«/—¸¡%×k= aZÝùÜ3öŽ;¿íW‡þʾF0Lu¯êüéþŠE«L9:}ÿï¦þ%ûì‚m?~uê[û»4MÞE¬$ °RÝíÕUÝbÖX¶bö¡.‹,xP5‡Ý—”¦Ýê'[‡“]9ÉXy¤ïo|ägëvÌ1Í®h’JCühÊ À£]ãŸþˆµ¾½„¿üêŒ~ÔAmLÞJlÑÿxG~‹/×áó{Q¥¦j^Á»ÍŠú$vS5Õ¿Òwqä³]¥8 M»lŠ<öô––ú½`Ð=e`?þD7n®ñùvkÌ!ø"º;ÁxÄÔ|üƒNó‹0ó£Hç£u5í¢Ãcü°áqÈà£|dwÿÑØµ˜‡$?ûä[ÙeuO'ìÈ.‹ £”üwÎwÏ2ªü?“¶öhß_ùÈæ‰ôÚ’H¯¯F!6Á%î|t5&׿Þ%üÊuL.dg²ÃTÔDÒÆ© Ùm‚Æò‹ì®ðsn̬•ü"Êz¯g<ÍÎCÎñ[çœõ©;ÊœØeæ`ŸÆëAs¹½!aìÁzåïÐȇæà›Ý­-M¥¿Ù;¯äÔûoTºÚº ~²;¼ Ì|PïÏ™2½0œ?sQCûÁÌS÷Oõy3FffĆiŸ4„už!*!‘=!·ŠÚ‚¡bÃ\õè‰*Úg~°æà!ê[¦. ƒzÓ´ô׆ýe4º2ÄOëÉx}ô¹ãJ¿¸˜>PgPÚ÷ô43£ðDçvšõ&"ʨŠW˜î¾€Ëj±ùü–;ýó=sëk­-Ý|?zS³Þ¹ü0oØ}·¬ä÷;71=Uï.ȧyK¦ºà-?På\0ò¥I´ô-Ó[bw1ÿ.픿ÀÛXDÀ‹Éœ 9ULì´³pÏš»±šg}Ñ#=…üÅíóñ޾FSàm‹:æoäWy„·ñXíÿ iL\Ã!Q ‡ÃB;ckŸõUF¼QTÝS}—úÇÿÉûÛm/zp ZÖuÌkä—ñ¦üâß ›"2c®h‘ióÊë+Ê7”ç„×ÕVàÖ¿HñŒ endstream endobj 51 0 obj << /Length1 1612 /Length 1224 /Filter /FlateDecode >> stream xTklTUž¹½»Ý½ÝG÷Aa©{»t—í¾¤á °Y^þA …«tÁ jEH#©RMƒ$V¤þ‘h¢Rá_ZC „%Pª´Ñ¦4¬‰<ÛÝ©s·»iüëIΙ3g¾ïœ™¹g×Î×ëÀû@Ø’L¼ ÙM,f½ÔðÖÖœ} @ZQ_—¨·!Í2ZÏ 9˜å´ú䮯œ½–å3 ;¶äýlON&søÐǶo{"Y7¾ß0åôqýÿ‘CùC_°Àl²KØX××òC×å£åÏoÚ ›¬s@±1ë9µøá]¹´êzMÚ˜9gZ¦|Îq&²nÐ1äT&…gM¦´Æ´ì?¨ú&‹xŒ÷”C‹ô´ˆ÷x@‹¼šçÇ—vòúYÖÁné0K%çÌ¡XÀ>¶503§ K‘kd™wPÀ>}ÔÀ;ð\€[8kp/và€ Aödï+“½§@)Ìbp»fÏÎ`8‹F#ဿԠ£ÑP…Ûå4(ƒK ç i@<–Þ .Ï8p¾/™£½«\m^gyËÆý3—,öÔ¦x씽£ ¤­£GpåS{¶z+çjUë׬+ÜßøÞ¶9ªæÅ7Én-+ã“·ŒÝ—úøTV˜Ê'²VZæ°ÛÄPE4ä þR…ãq‡*R¦ŽÃ”VÕïf|=_Æ%4Ü{FMAÁÂ…=—…¤µœ…oc¢Zé—P1¿9<¤¢™óÔ½0$»Á P¦h:¦Ló»]1WÀïôøÄ!cú¸ªŠO›éÚý‚î¿î\7¢£¯/Øk;xÚÜ]pñ¤^+ÅXv6&@lž,¬˜2ÑùŒÚùàñÝUUÙÝkûæJÁeÝz’GËaô0†%ž f°ÛŸØcLwZ,XlQÑyó&Zñ6>øÞ ŸòÜR'ÇqÆ4!Èwpù³r'ˆpJê|D÷¨º­¸ð¡ÕŠåP Z'Ž–c¶µöž|DmÅ×0‰¡èÍæßN2ÛÔÇtøw >Ö'WËaî6Ïxu|`çå*#¸œ®‹\MM4Dé(6¢ XKwo´Jõ=”¾ KÔÀ %ÂÃLq¶%9…FQÑ8R5×ß^fpJZiÐY”M¢Þ’Öôp‡|R5µÍvšéUm/»?Ã5&\ºÒ\¬aRìNQ 5¾[=ʆooß°žríÌ1‰û4Mà>Wl$>»Sv¹âS;ý¼kÏ•ÝQÕã%߯Ƌ4R×úp 6.3Ç87‰4F#ùb¨ëÉf«—2‚s…Ÿ=áGa÷د҅ñnCÁnã¤é Ç÷r”Ué‚)ÓOÿÐß&œ¢6ú´‰Û„NЉL=ø×]ÅÝÝN]t/uÝø,¾¨cš9[ÍŒiÕs.- eˆ¥ÔL1.özœ‡;2ÖšÑæUqißòåés+ÅuÛôx~SÄnŽ/Êv\,ZäˆDJ嘦DÁ媻•ô»Öä?‡©Ë ®-ÜÞÕu`àR ®ÀWfÚ<½—[éGjÍì> stream xeT LSW¾?}ï•¶™må=*ÐÖdŠm ‚sA‹0fò7;„Á¤j¶êP¢™º‘ó'—¹éœD3³,ÌE£cG6D ssq[Ü‹ÎÌìGÌ¢}·;¯TH¶“¼~÷œ{ïwî¹ß¹mnj©EZÔ†(B5~ß6ü@Ú‹›ê"þWiõµ¾5ã> zê!™wΨ÷7"þs€éëkÏŸ?Îï DøÑwà'­óùkÇ×ó^À”±ã¡µ(Z=Uÿ¨Úv£kBïGBÁˆß;¹dbÔ6ᨠC4iÂQ‚Œ0VcMs½3¿nÎë~JîŠÕ†gÎ.zС.•^󇔳Úná-DP|ãû¸aejo‡Xª¶ö}™=‚‰–h:BÚX´„ÞFr¹»h%C};¢ÈFFQ= ƒm8r6âQøV¤G@(ˆè »TÒLT°mGŸ 1çã¸â$–äÂÎp½ôgõ²¡4 7YMá/Ùå‘=·Ëi·ñB²Ç“™!‰Ñ¼Àó¢àŠ8v›“ VÒ"ÅŒâ„lë 9ç}¹aWMuûì§ÅÔ;ã-N§%ÞÉYþÂYåiêÄ%‰­u–œ\kAÅòò'Ú;ÖfWÌ/®<^êpÀ¹—À4pJ„óD#Áî"Év^EäÎŒ6‹™žI”³Bë­(„V6Ò?ªÓãÃÇ®ju¸—“¼ZòJéK]Á…uš=g°lK#}/W–5VОÕ‡†áü“¹D ‰‘|€Hv;ùbÔœ?{¹ ç^þÇ­_̾ýÿàžÅî\NÑfã(N²°yº¥ÊÙø¶w%KH›NšÓuóðßÓ¬%;wZ µ6M äõíf·‹‰Ê4%ìÄy½x>»ý‹Ï˜N‡7r’“å³[þ¡›8°b3žƒ·[ÊE_Éš|@JÏŸ ø¸$!Ã!Xe’e'Ósâ円 â^1xEÜC\¹Â¶™8©õpp0Uÿnà•Óõ±{¡kŒlãzÑt” r……Ï w€yªM¥L3¨ÉX¢'{Uñ´ê¾èÓE–ô}í)UÅž¸œ®˜ö|ËÑ£9¬{c«ðæMÝ^žu)#ŽeÞ Ä‰+ù-æï3œ{%¼ktàÿ·ü¹k¬ŠßÞ‘ -d÷4íWOíÔiqÚ;‡t6ÐòàhN2qŸüH±»¨Ç«/SÚÒ—‘¦œ4¥:ÕEÖV@.)ô€ž™Ì%Jfhbµ§ ªq8'hlvÓ3ì¯U…w/rñY‡°5à¾~iëL­»¤²ÁgõÕló4]Î*[Ì>OÐÍÅå¯hŸÆ•Sõ±ì÷üyØb‹énÈ&…àÍØå xI“…ÑÝÌg-/®¾È·}ùpðžÃhSŒUÁÒ^¿Ðz€|X¡Uùx¹‹Tox™ˆ:hÿcE1Ikìv' 2uÄ—°œxYT¼±|‡œi÷råVJ”i×\²Ð®3tK=‹#÷¸?Ñ äb2‚ÆÉN“qªÙAîuÖÞÇs–m(ý´çNàz×ïcY Ka¡²¬Õ¿â]¸Wàý-PÝ1`I‹°)á’=²¨d)F"i='ØO©u÷Ù• "¿±ýì(kh)kÚ?ãë«táÿ03œH5^} U+z²Ð·n¯É7»¨ÙרPƒþ‘… endstream endobj 53 0 obj << /Length1 1368 /Length 1081 /Filter /FlateDecode >> stream x­SkL\EýæÎÝ{vKw—{vW`wa·J- û*EhÚ¨ØXC‰ºò(‘‚„nÓZ(R &¤5}`€êbC*" Æš”„4Ô‚¦¡ T«HiSR¢…üîî6©ÿdæ›3óÍ™™sfêëÊA Í@J«½µ(¤ÃöC‡T„ð8­­,÷–1¬ctWâ@hÞ‰1¡²ºÞ¯bÜ~øíÒÇóˆcª½¾?ÜD_ã­.æ«v*øáE„ÿW«Ði ø!:ì?¹…ÒWõ<=xvDZ×7g<„-ê@âhÎêûJçÇ}ÓùëYþõ’ø1Â0àÓ p¨&ý“äjXáz+R/ý‡UIÒÐ^ŽV;_Žqòèe(£ Áç`|ü[à£ã‡ù$Ä b›!!xrŽˆèPŽ÷ß ^¨….„_‰–¤‘7É92¼#íU™pؤz³>PíN·Çív9mV‹ ÚÝnGJ”, ¢ È¢3¬í]/¡»ýò<—›j~Ù“ö’¦XÛ^úZ˳¹9Ñ•6£Éf3m*Ó£Û*ÓZ&_±ÖE ãŽU˜Ò2ÌÙ‹Š#Z|'«RK²ŸË/é ¤&&â |Œ´“Hô%·q¶$í…yéYûv¥gžI/.p§؃¹v2Dnq¹Ê[$¢ÊCniÙþ0.÷DD3ЉLwè]~2Eã¼ÄY-œËip¤¨Ó&ZYŠò¤¸éÝå_¦æ”zñ|kÓç[ëÏqÆûl”lûí>Éa³lel™›ÿ ›)EuÔžã‘S‹’[Ý.]´§—8¾_£¹L*_ ¿±@Äwë0ö»>ƒkðÐ\#ãD³'…5[DOPHåxZ ùŸ‘ý™ý~d—´Ç77Ãþ¼FLm—ïõÜÐuHƒ'®°Ù5re°zZ…\èy¢*{B‚âÞ#`ÖcRQŽŠ¢U¬Š½÷I&ûÙŠôÃß=½GK´%cCcwšú:'ØHäQéZ_wÓ;‡¼Er‡±»êf~x̰¢[¢‹|¾þ-Š®V)Òjp™íN°;} µJ Ë)]”¿Ðö«ý×d.–\×üCÍŠÖ8â¹ð-›!Üüñ­ÜÜæyÿ=®ÜèשEâÆóûØÚˆÜÒ“ç7#½h3 r> stream x­U}PT׿çÞ÷±è¾]ö£)ËÇî »VCì—Pue“E#qªU Š5°&EmÔ‰±´v£m“˜iCSbjZ‰q:6NKÒ©©ÕøMS‰#p·çîÒNÓ¿{ßÜwïyï¼ß9çwιoÓÆ§«ˆl%Œ5õH|@.ùkëZª2•‘¯ÕTUT&d2Žk°$dðãú`Mý¦æIy®ÑºõkþýþÏ({ê+š'ñ‰³*ê«úêM\§Ý}âÿë.à,d&AïqP¢áþ¿Mˆ½ü“o•·‘rÓœ»äC\ñ‚ÑmbóÇÇÏ/7L &EÕŸâwIˆø|vâ,œJÚ5nà%Iѯ   ;L¼C»M ¥ d…´–D¤H8©¥i‘ªITjÆgÏf#‹Ø*2^%³Ø ¢#Û^úY"&bÁ$º‘(ä!”]ÄL¦©èC¢’d’‚:‘1“FŒÒLL  ñj'¿%w °¶C/\§F:—6ÒÓWé9úOÔŠóÃËNDT‰›|š]æøôúƒ¡`0à÷ènEõƒ¾\»Íª¨ŠbSý“‚îö°Ã㥬pÂÐâŒ<סü¥SWw¬Yý\N¤ÀQãIsz<Î4ì¼YvŽÍ•ªÇºaIfkµ3Ž+¼ªdeÊsÍëòJÃß..펫fgcl…±«ì »@ÒI6!Ùª' +h+à0;ášôÀfõzY6«/—¼©%7o;aZÓõÒ öÎ{¿PGþÚþ&0Lw¯îúþ“ŠE«‹L;6óÀï§ÿ%ûÜ¢íO¾¾í­ˆýMš!ï&V’… X©îöêªn1k,[1ûЖE<¨šÃîË J3î ÷„“­#É.Èœb¬:ÚÿW>úƒõ;ç™æVvj/+ßX-ó/,³€˜µ½ÝoËÀnXÌŸáƒ÷ë;CÎÚ¦=ï¥Wø¶‹¸"±aÉÇ.a9_Dw'x"oƒx:‚’ÿáÃ3üÌþpÒùXg}m‡˜ðù8¿ ld2øÝ3pl'ND-á!ÉÏþô•ê²:D¤“þNV—ņ٠Jþ{zæUþw‹ˆI[w¬ÿS>ºe²¼¶&ÊëîdÂf¸ÌßYƒÅµ¥o)¿z‹ ÙY„ì0d'5Q´qjBv›à†±ü¢Eûf*|Ôœ3k¥?в¾ÏóÆ sâöygCê.2/v…9ØÇñ~Ð\noH¸†{°ßDû;4òáÀ‹9xÁ¡w[ksÙ/ö-(=ý»7ªÜí=Oí ¯3Òr¦Í, çÏ^ÜØq(óôC%Ó}ÞÀìÇ‘™Y±Ú/ cŸgˆNHTOÈ­¢µ`(¤Ø°V=z¢ €ö›­=t˜ú–«ÅaPo™–ýÜp œFW…øé㽿{é„2 .¥Ö•޽½-Ì("Ñy„a}‰Œ2ªâ¦{E,$à²Zl>¿%ÀÎüðeÏü†Ú!kk?¾”#¬o>?Â÷Ü//}wWÓf¦§ê=ù4o™ÀôB7\¤eâß ª‚‹F¾,‰–½izS¼]¿N»äÏñ4ðb1§CE;í*Ü»ö~¬öE_eôho!yÇ‚&<£¯ÓøVûâÎ…›ø5áí> stream x­U{LSgÿÎ}RÚK[h‹Œ ÜVZ‘ZúÄG@Å'ó•%¾¢©ˆctcnC§fqqc.ãæÄìAöÒ1Ù_.ñ…!ˆ³NÑLœ%Œ935lÙ@yôtç–·ÿwo¾~ß¹÷;¿ßùs¾Ûí5¯T°öã+¯¾ÈbÔÓ4í¹ª›ãöuÆ„S•ÁMã6£Ù_Iâï½4Oª¬Þ^·WÑì­ÚVþøý ²íÕÁÚ8>ë!;kk°ºb|¿ÔHóäÁ¯`Üü¿~58…å3!È1­ÿM¡­ÅC9‹6ìfŒ3YZBl㉹Coi‹‹Ë~Z<–9§[ &?ãb¯™†!†#ah×íKÀºÿAÕ6)|3íIdz1‡…ø4úXH\NãV&Ô°ÐN#ŸÖ>fç°B+#?ˆ#˜Äd«ÌÀô¿L3Ou’˜HQh±$j4l1«a_²ØH‡%°¾‡?9WÄm×Ì7‹vò“ +Àͪ96Ü^Àï÷y]N‡$»ýþÍj‘dI²ÊÞ¸át¸øæ±uüÂH2ÌâÊ2 Õ•¢åú5†wÊ×ï:onj¥+ÝîrÙÓ]¢}¤_´Î6„¥™»6Û‹f¨%kW¬IÚ[»oKẒ™eëƶfgSìzꤨh£º¤<ÕË«œUõ2ŸjaÀùœ^ˆâ™µèYWá*ì„/ÐsÄÔZ^ìšï¾›Y8º¢œ0Å&´Pôo¡‡4ÙDÒgbª#;Ùlâ <þ‚,^ÎéIZª­À“,ô`oÀ1Eù6÷ë§ày˜‡½wr'&w_âŽc?®2@¼U6âÏg@ÖuÞ¸§€žrbŒSäfb’'9mVOÀêršRU‘ë°3¢´ >:¥ÃûŠ"ÚnšŽ\N¼¤Ã_‡cÆ1º ÃÀX¶¬9ºUÉl’³øî„±6ƒÒ XnÜ#„ÚÁ_ðU¼ÚJt·ÐF~¤Ruz¹‰Þ’âÔ˜UK K-pùH5A mñöN6¥% ód·qBÒHRÔASãÍÖ‡Ø~xªùð}|­þv+±M|„ïa£Œ–E{ÄRÑKuJÏh3S^ãÙ䬖dÊ¥XŠuxá!¨+$À&¼­é@¸ûÐ0÷^Ä*bÈ€h Šö.p¤ó2Ž‚¬1hZJ©fÉÌN Au¸-)±$jeó¢WÕªf+ÈJ± 1ߢÇߥ%ûJÙ)ª bÿü¥ú4ªù¶~î†A%m• JGï\3žàâ-Ä1A;EªÊQ§Ë¦'$Yf‹hµ%óO˜Zðúö]ïùtø»¢|“qz9\À‘ŠÆ¡([¿@pÁ,Øø9`GSÂŽáF;F¸Ùç’>¦Oh¹ãûÄ\æÔ2G²ÔwtÌÜ.íöiG+U¦H´†Ôn¾/òãéæéŸ†>®/)l9\Œ´ïË~»é~`Ú'Gž} ÊqGÞí§g-\âÍ[4wYEÃѳê­é{æL™T> stream x­TPTU¾?ö½·ì"°+ï!°»ë.HŠ»ûXDA01œäW®A‚:…†¶Âä¤Ú8Ød!ŽŒNNÓPŽF2Æ¢cÙTŽ•–æäL%Úè¾»}¬ÒÔ¿Ý™û¾{Þ½÷ûιçÜÛÔØ\´È‹(BU žMHmø €´çê·Ôíëizk«=ë&lätÕÂà¼pFmCSKÐ~0£~cÕ£ù!°ã<-A~ôØ < ÕëùW“Æâ óÿúèÂФQ Š€ñ?%c®gæWMÙφg£h­ºðÔ¢{íÁù¢Ëù¾aå”¶Kx}¢Á>nDÁCÚ›¾a–¬í‚}_ç& Œö"„ûÒÑRM»D–Ò›ÈDŽ¢î6ZEÇ‘Dßñûi²1TKÆüG4!¨ ¶ã ¡ˆG3À6£)0ÒÂß)H/tHÙ …¨¸Ç-CËÐô úóx>ÞŒûñ¾G¢I)5~ÚË™`Ÿ€,(D fƒÚ.Ùår:ìV /$º\éi’É uœ„âÁŸH$X$ÑÊ9Ó#bºk…:å”Ðz#Dge-B+Óéñ¡#—´:ÜÃIù›³‹èó¾y5š=6»¯d[=íË’}%õe´{ Âþ8††I-QBbPÉN»ªÐÔ4°rspÖ…¿œúÅì›ïñUç,vëüH’ÖC8ÉÄfdë–)ï»ÓðÍüU,.e:iJÕÍÃN·³fwî0A8Ø4… 'ª±­F§ƒÇ‘i Ù±3zñŒ»í‹Ï˜N‡7s’å° Ã×pËÊ­xÞa¶+ç<$cð)= |àà„4›`–]H–-œLO‹Û”o5d÷ˆ¾‹ââàÈEö²“Zù†’õ±ïµœ rª>z/TL[@ƹ4ŸÔħɀ„¨`œjd)ÝÙÇd<Þå^]0­²?òã%¦Ô}mI®˜ÌΨ¶ÓáÙ¬Ÿ{}»ðæ5Ý^žu*í£¶åùg‰—óÝZÌßeð{Ü•Ëtð¿9&Nù_9æ.³ ~G{œ6ÝÑ´]:±S§Å)ïÔq8”–úÆ2‰óø‡Ê¨ÕA]ùúÅ›ºœ4f¦(•ɲ¾ ´$ÿ=zrRK”ŒPÄš"€«šc£“žd¬Î»}á ƒÏ87ŒÍ-Î+ç·ÏÔ:ûé`2zZ_ɶNÓÅàŒ’Åìó8Ý\\ú¢ö)\>UÍ~Ë™‡Cc ¢ül1Ý j’šaîŒUNƒ›4ÝÍ<æÒ‚Ês¼÷ËCõ–è W‰¨ð­}ílë[äƒ2ýKÊGÅR¹Hàf"j£r,Š ²šc§3A©-¶åâø ¢’í·Øèq‘t+7’B û;ç’…V]h°Ô²r‡û…%/Cä8Ñnˆ˜j´‘;Õwñœå›Š>í>†ã¸žûØÅ’˜¿$cÍÏx®Ãex3DwXR‚,”p‰.ÙT²%‘”îcìÇ䎚»ìb!P‘_Ù~v˜Õ5—4ðŒtPkUèÚG9õÝZ3ËNûÂ|÷ÃÈÕpßýpÊy½l­×«¾{Fð>ÐøÀ­Yh+žÈólXçiôÌ^Ò䩯«Bš%‘ endstream endobj 2 0 obj << /XObject << /Im1 1 0 R >> /ProcSet [ /PDF ] >> endobj 5 0 obj << /Type /Pages /Count 1 /Kids [3 0 R] >> endobj 57 0 obj << /Type /Catalog /Pages 5 0 R >> endobj 58 0 obj << /Producer (pdfTeX-1.40.18) /Creator (TeX) /CreationDate (D:20211027180219-07'00') /ModDate (D:20211027180219-07'00') /Trapped /False /PTEX.Fullbanner (This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017) kpathsea version 6.2.3) >> endobj xref 0 59 0000000000 65535 f 0000000236 00000 n 0000046691 00000 n 0000000132 00000 n 0000000015 00000 n 0000046756 00000 n 0000022431 00000 n 0000022593 00000 n 0000022627 00000 n 0000022824 00000 n 0000023054 00000 n 0000023261 00000 n 0000023470 00000 n 0000023668 00000 n 0000023899 00000 n 0000024110 00000 n 0000024327 00000 n 0000024554 00000 n 0000024783 00000 n 0000025010 00000 n 0000025238 00000 n 0000025465 00000 n 0000025694 00000 n 0000025921 00000 n 0000026149 00000 n 0000028862 00000 n 0000029097 00000 n 0000029417 00000 n 0000029657 00000 n 0000030046 00000 n 0000030286 00000 n 0000030646 00000 n 0000030889 00000 n 0000031238 00000 n 0000031473 00000 n 0000031793 00000 n 0000032033 00000 n 0000032422 00000 n 0000032662 00000 n 0000033026 00000 n 0000033269 00000 n 0000033635 00000 n 0000033846 00000 n 0000034057 00000 n 0000034268 00000 n 0000034479 00000 n 0000034690 00000 n 0000034901 00000 n 0000035112 00000 n 0000035323 00000 n 0000036492 00000 n 0000038227 00000 n 0000039539 00000 n 0000040941 00000 n 0000042110 00000 n 0000043841 00000 n 0000045269 00000 n 0000046813 00000 n 0000046863 00000 n trailer << /Size 59 /Root 57 0 R /Info 58 0 R /ID [<8FFB1AB73499F228FDCCCA2E7CAD19F7> <8FFB1AB73499F228FDCCCA2E7CAD19F7>] >> startxref 47123 %%EOF zfp-1.0.1/docs/source/zfpcmd.rst000066400000000000000000000237731453723256400166040ustar00rootroot00000000000000.. include:: defs.rst .. _zfpcmd: File Compressor =============== This section describes a simple, file-based |zfp| compression tool that is part of the |zfp| distribution named |zfpcmd|. Other, third-party, file-based compression options are discussed in the :ref:`app-support` section. The |zfpcmd| executable in the :file:`bin` directory is primarily intended for evaluating the rate-distortion (compression ratio and quality) provided by the compressor, but since version 0.5.0 also allows reading and writing compressed data sets. |zfpcmd| takes as input a raw, binary array of floats, doubles, or integers in native byte order and optionally outputs a compressed or reconstructed array obtained after lossy compression followed by decompression. Various statistics on compression ratio and error are also displayed. The uncompressed input and output files should be a flattened, contiguous sequence of scalars without any header information, generated for instance by :: double* data = new double[nx * ny * nz]; // populate data FILE* file = fopen("data.bin", "wb"); fwrite(data, sizeof(*data), nx * ny * nz, file); fclose(file); |zfpcmd| requires a set of command-line options, the most important being the :option:`-i` option that specifies that the input is uncompressed. When present, :option:`-i` tells |zfpcmd| to read an uncompressed input file and compress it to memory. If desired, the compressed stream can be written to an output file using :option:`-z`. When :option:`-i` is absent, on the other hand, :option:`-z` names the compressed input (not output) file, which is then decompressed. In either case, :option:`-o` can be used to output the reconstructed array resulting from lossy compression and decompression. So, to compress a file, use :code:`-i file.in -z file.zfp`. To later decompress the file, use :code:`-z file.zfp -o file.out`. A single dash "-" can be used in place of a file name to denote standard input or output. When reading uncompressed input, the scalar type must be specified using :option:`-f` (float) or :option:`-d` (double), or using :option:`-t` for integer-valued data. In addition, the array dimensions must be specified using :option:`-1` (for 1D arrays), :option:`-2` (for 2D arrays), :option:`-3` (for 3D arrays), or :option:`-4` (for 4D arrays). For multidimensional arrays, *x* varies faster than *y*, which in turn varies faster than *z*, and so on. That is, a 4D input file corresponding to a flattened C array :code:`a[nw][nz][ny][nx]` is specified as :code:`-4 nx ny nz nw`. .. note:: Note that :code:`-2 nx ny` is not equivalent to :code:`-3 nx ny 1`, even though the same number of values are compressed. One invokes the 2D codec, while the other uses the 3D codec, which in this example has to pad the input to an *nx* |times| *ny* |times| 4 array since arrays are partitioned into blocks of dimensions |4powd|. Such padding usually negatively impacts compression. In addition to ensuring correct dimensionality, the order of dimensions also matters. For instance, :code:`-2 nx ny` is not equivalent to :code:`-2 ny nx`, i.e., with the dimensions transposed. .. include:: disclaimer.inc Using :option:`-h`, the array dimensions and type are stored in a header of the compressed stream so that they do not have to be specified on the command line during decompression. The header also stores compression parameters, which are described below. The compressor and decompressor must agree on whether headers are used, and it is up to the user to enforce this. |zfpcmd| accepts several options for specifying how the data is to be compressed. The most general of these, the :option:`-c` option, takes four constraint parameters that together can be used to achieve various effects. These constraints are:: minbits: the minimum number of bits used to represent a block maxbits: the maximum number of bits used to represent a block maxprec: the maximum number of bit planes encoded minexp: the smallest bit plane number encoded These parameters are discussed in detail in the section on :ref:`compression modes `. Options :option:`-r`, :option:`-p`, and :option:`-a` provide a simpler interface to setting all of the above parameters by invoking :ref:`fixed-rate ` (:option:`-r`), :ref:`-precision ` (:option:`-p`), and :ref:`-accuracy ` (:option:`-a`) mode. :ref:`Reversible mode ` for lossless compression is specified using :option:`-R`. Usage ----- Below is a description of each command-line option accepted by |zfpcmd|. General options ^^^^^^^^^^^^^^^ .. option:: -h Read/write array and compression parameters from/to compressed header. .. option:: -q Quiet mode; suppress diagnostic output. .. option:: -s Evaluate and print the following error statistics: * rmse: The root mean square error. * nrmse: The root mean square error normalized to the range. * maxe: The maximum absolute pointwise error. * psnr: The peak signal to noise ratio in decibels. Input and output ^^^^^^^^^^^^^^^^ .. option:: -i Name of uncompressed binary input file. Use "-" for standard input. .. option:: -o Name of decompressed binary output file. Use "-" for standard output. May be used with either :option:`-i`, :option:`-z`, or both. .. option:: -z Name of compressed input (without :option:`-i`) or output file (with :option:`-i`). Use "-" for standard input or output. When :option:`-i` is specified, data is read from the corresponding uncompressed file, compressed, and written to the compressed file specified by :option:`-z` (when present). Without :option:`-i`, compressed data is read from the file specified by :option:`-z` and decompressed. In either case, the reconstructed data can be written to the file specified by :option:`-o`. Array type and dimensions ^^^^^^^^^^^^^^^^^^^^^^^^^ .. option:: -f Single precision (float type). Shorthand for :code:`-t f32`. .. option:: -d Double precision (double type). Shorthand for :code:`-t f64`. .. option:: -t Specify scalar type as one of i32, i64, f32, f64 for 32- or 64-bit integer or floating scalar type. .. option:: -1 Dimensions of 1D C array :code:`a[nx]`. .. option:: -2 Dimensions of 2D C array :code:`a[ny][nx]`. .. option:: -3 Dimensions of 3D C array :code:`a[nz][ny][nx]`. .. option:: -4 Dimensions of 4D C array :code:`a[nw][nz][ny][nx]`. When :option:`-i` is used, the scalar type and array dimensions must be specified. One of :option:`-f`, :option:`-d`, or :option:`-t` specifies the input scalar type. :option:`-1`, :option:`-2`, :option:`-3`, or :option:`-4` specifies the array dimensions. The same parameters must be given when decompressing data (without :option:`-i`), unless a header was stored using :option:`-h` during compression. Compression parameters ^^^^^^^^^^^^^^^^^^^^^^ One of the following :ref:`compression modes ` must be selected. .. option:: -r Specify fixed rate in terms of number of compressed bits per integer or floating-point value. .. option:: -p Specify fixed precision in terms of number of uncompressed bits per value. .. option:: -a Specify fixed accuracy in terms of absolute error tolerance. .. option:: -R Reversible (lossless) mode. .. option:: -c Specify expert mode parameters. When :option:`-i` is used, the compression parameters must be specified. The same parameters must be given when decompressing data (without :option:`-i`), unless a header was stored using :option:`-h` when compressing. See the section on :ref:`compression modes ` for a discussion of these parameters. Execution parameters ^^^^^^^^^^^^^^^^^^^^ .. option:: -x Specify execution policy and parameters. The default policy is :code:`-x serial` for sequential execution. To enable OpenMP parallel compression, use the :code:`omp` policy. Without parameters, :code:`-x omp` selects OpenMP with default settings, which typically implies maximum concurrency available. Use :code:`-x omp=threads` to request a specific number of threads (see also :c:func:`zfp_stream_set_omp_threads`). A thread count of zero is ignored and results in the default number of threads. Use :code:`-x omp=threads,chunk_size` to specify the chunk size in number of blocks (see also :c:func:`zfp_stream_set_omp_chunk_size`). A chunk size of zero is ignored and results in the default size. Use :code:`-x cuda` to for parallel CUDA compression and decompression. As of |cudarelease|, the execution policy applies to both compression and decompression. If the execution policy is not supported for decompression, then |zfp| will attempt to fall back on serial decompression. This is done only when both compression and decompression are performed as part of a single execution, e.g., when specifying both :option:`-i` and :option:`-o`. Examples ^^^^^^^^ * :code:`-i file` : read uncompressed file and compress to memory * :code:`-z file` : read compressed file and decompress to memory * :code:`-i ifile -z zfile` : read uncompressed ifile, write compressed zfile * :code:`-z zfile -o ofile` : read compressed zfile, write decompressed ofile * :code:`-i ifile -o ofile` : read ifile, compress, decompress, write ofile * :code:`-i file -s` : read uncompressed file, compress to memory, print stats * :code:`-i - -o - -s` : read stdin, compress, decompress, write stdout, print stats * :code:`-f -3 100 100 100 -r 16` : 2x fixed-rate compression of 100 |times| 100 |times| 100 floats * :code:`-d -1 1000000 -r 32` : 2x fixed-rate compression of 1,000,000 doubles * :code:`-d -2 1000 1000 -p 32` : 32-bit precision compression of 1000 |times| 1000 doubles * :code:`-d -1 1000000 -a 1e-9` : compression of 1,000,000 doubles with < 10\ :sup:`-9` max error * :code:`-d -1 1000000 -c 64 64 0 -1074` : 4x fixed-rate compression of 1,000,000 doubles * :code:`-x omp=16,256` : parallel compression with 16 threads, 256-block chunks zfp-1.0.1/examples/000077500000000000000000000000001453723256400141415ustar00rootroot00000000000000zfp-1.0.1/examples/CMakeLists.txt000066400000000000000000000026061453723256400167050ustar00rootroot00000000000000add_executable(array array.cpp) target_compile_definitions(array PRIVATE ${zfp_compressed_array_defs}) target_link_libraries(array zfp) add_executable(diffusion diffusion.cpp) target_compile_definitions(diffusion PRIVATE ${zfp_compressed_array_defs}) if(ZFP_WITH_OPENMP) target_link_libraries(diffusion zfp OpenMP::OpenMP_CXX) else() target_link_libraries(diffusion zfp) endif() if(BUILD_CFP) add_executable(diffusionC diffusionC.c) target_link_libraries(diffusionC cfp) endif() add_executable(inplace inplace.c) target_link_libraries(inplace zfp) add_executable(iterator iterator.cpp) target_link_libraries(iterator zfp) target_compile_definitions(iterator PRIVATE ${zfp_compressed_array_defs}) if(BUILD_CFP) add_executable(iteratorC iteratorC.c) target_link_libraries(iteratorC cfp) endif() add_executable(pgm pgm.c) target_link_libraries(pgm zfp) add_executable(ppm ppm.c) target_link_libraries(ppm zfp) target_compile_definitions(ppm PRIVATE ${ppm_private_defs}) add_executable(simple simple.c) target_link_libraries(simple zfp) add_executable(speed speed.c) target_link_libraries(speed zfp) if(HAVE_LIBM_MATH) target_link_libraries(array m) target_link_libraries(diffusion m) if(BUILD_CFP) target_link_libraries(diffusionC m) endif() target_link_libraries(inplace m) target_link_libraries(pgm m) target_link_libraries(ppm m) target_link_libraries(simple m) endif() zfp-1.0.1/examples/Makefile000066400000000000000000000032621453723256400156040ustar00rootroot00000000000000include ../Config BINDIR = ../bin TARGETS = $(BINDIR)/array\ $(BINDIR)/diffusion\ $(BINDIR)/inplace\ $(BINDIR)/iterator\ $(BINDIR)/pgm\ $(BINDIR)/ppm\ $(BINDIR)/simple\ $(BINDIR)/speed INCS = -I../include LIBS = -L../lib -lzfp CLIBS = $(LIBS) $(LDFLAGS) -lm CXXLIBS = $(LIBS) $(LDFLAGS) # add cfp examples when BUILD_CFP is enabled ifneq ($(BUILD_CFP),0) TARGETS += $(BINDIR)/diffusionC $(BINDIR)/iteratorC endif all: $(TARGETS) $(BINDIR)/array: array.cpp ../lib/$(LIBZFP) $(CXX) $(CXXFLAGS) $(INCS) array.cpp $(CXXLIBS) -o $@ $(BINDIR)/diffusion: diffusion.cpp ../lib/$(LIBZFP) $(CXX) $(CXXFLAGS) $(INCS) diffusion.cpp $(CXXLIBS) -o $@ $(BINDIR)/diffusionC: diffusionC.o ../lib/$(LIBZFP) ../lib/$(LIBCFP) $(CXX) $(CXXFLAGS) diffusionC.o -lcfp $(CLIBS) -o $@ diffusionC.o: diffusionC.c $(CC) $(CFLAGS) $(INCS) -c diffusionC.c $(BINDIR)/inplace: inplace.c ../lib/$(LIBZFP) $(CC) $(CFLAGS) $(INCS) inplace.c $(CLIBS) -o $@ $(BINDIR)/iterator: iterator.cpp ../lib/$(LIBZFP) $(CXX) $(CXXFLAGS) $(INCS) iterator.cpp $(CXXLIBS) -o $@ $(BINDIR)/iteratorC: iteratorC.o ../lib/$(LIBZFP) ../lib/$(LIBCFP) $(CXX) $(CXXFLAGS) iteratorC.o -lcfp $(CLIBS) -o $@ iteratorC.o: iteratorC.c $(CC) $(CFLAGS) $(INCS) -c iteratorC.c $(BINDIR)/pgm: pgm.c ../lib/$(LIBZFP) $(CC) $(CFLAGS) $(INCS) pgm.c $(CLIBS) -o $@ $(BINDIR)/ppm: ppm.c ../lib/$(LIBZFP) $(CC) $(CFLAGS) $(PPM_FLAGS) $(INCS) ppm.c $(CLIBS) -o $@ $(BINDIR)/simple: simple.c ../lib/$(LIBZFP) $(CC) $(CFLAGS) $(INCS) simple.c $(CLIBS) -o $@ $(BINDIR)/speed: speed.c ../lib/$(LIBZFP) $(CC) $(CFLAGS) $(INCS) speed.c $(CLIBS) -o $@ clean: rm -f $(TARGETS) $(BINDIR)/diffusionC $(BINDIR)/iteratorC diffusionC.o iteratorC.o zfp-1.0.1/examples/array.cpp000066400000000000000000000023201453723256400157600ustar00rootroot00000000000000// simple example that shows how to work with zfp's compressed-array classes #include #include #include "zfp/array2.hpp" int main() { // array dimensions (can be arbitrary) and zfp memory footprint const size_t nx = 12; const size_t ny = 8; const double bits_per_value = 4.0; // declare 2D arrays using STL and zfp std::vector vec(nx * ny); zfp::array2 arr(nx, ny, bits_per_value); // initialize arrays to linear ramp for (size_t y = 0; y < ny; y++) for (size_t x = 0; x < nx; x++) arr(x, y) = vec[x + nx * y] = x + nx * y; // alternative initialization of entire array, arr: // arr.set(&vec[0]); // optional: force compression of cached data arr.flush_cache(); // print values for (size_t y = 0; y < ny; y++) for (size_t x = 0; x < nx; x++) std::cout << vec[x + nx * y] << " " << arr(x, y) << std::endl; // alternative using printf(); note the necessary cast: // printf("%g %g\n", vec[x + nx * y], (double)arr(x, y)); // print storage size of payload data std::cout << "vec bytes = " << vec.capacity() * sizeof(vec[0]) << std::endl; std::cout << "zfp bytes = " << arr.size_bytes(ZFP_DATA_PAYLOAD) << std::endl; return 0; } zfp-1.0.1/examples/array2d.hpp000066400000000000000000000042271453723256400162230ustar00rootroot00000000000000#ifndef ARRAY2D_HPP #define ARRAY2D_HPP #include #include typedef unsigned int uint; // uncompressed 2D double-precision array (for comparison) namespace raw { class array2d { public: // constructors array2d() : nx(0), ny(0) {} array2d(size_t nx, size_t ny, double = 0.0, const double* = 0, size_t = 0) : nx(nx), ny(ny), data(nx * ny, 0.0) {} // array size size_t size() const { return data.size(); } size_t size_x() const { return nx; } size_t size_y() const { return ny; } void resize(size_t nx, size_t ny) { this->nx = nx; this->ny = ny; data.resize(nx * ny, 0.0); } // rate in bits/value double rate() const { return CHAR_BIT * sizeof(double); } // cache size in bytes size_t cache_size() const { return 0; } // byte size of data structures size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; if (mask & ZFP_DATA_META) size += sizeof(*this); if (mask & ZFP_DATA_PAYLOAD) size += data.size() * sizeof(double); return size; } // accessors double& operator()(size_t x, size_t y) { return data[x + nx * y]; } const double& operator()(size_t x, size_t y) const { return data[x + nx * y]; } double& operator[](size_t index) { return data[index]; } const double& operator[](size_t index) const { return data[index]; } // minimal-functionality forward iterator class iterator { public: double& operator*() const { return array->operator[](index); } iterator& operator++() { index++; return *this; } iterator operator++(int) { iterator p = *this; index++; return p; } bool operator==(const iterator& it) const { return array == it.array && index == it.index; } bool operator!=(const iterator& it) const { return !operator==(it); } size_t i() const { return index % array->nx; } size_t j() const { return index / array->nx; } protected: friend class array2d; iterator(array2d* array, size_t index) : array(array), index(index) {} array2d* array; size_t index; }; iterator begin() { return iterator(this, 0); } iterator end() { return iterator(this, nx * ny); } protected: size_t nx, ny; std::vector data; }; } #endif zfp-1.0.1/examples/diffusion.cpp000066400000000000000000000355011453723256400166370ustar00rootroot00000000000000// forward Euler finite difference solution to the heat equation on a 2D grid #include #include #include #include #include #include #include #include "zfp/array2.hpp" #include "zfp/constarray2.hpp" #include "zfp/codec/gencodec.hpp" #include "array2d.hpp" // add half precision if compiler supports it #define __STDC_WANT_IEC_60559_TYPES_EXT__ #include #ifdef FLT16_MAX #define WITH_HALF 1 #else #undef WITH_HALF #endif #ifdef _OPENMP #include #endif // uncompressed tiled arrays based on zfp generic codec namespace tiled { #if WITH_HALF typedef zfp::array2< double, zfp::codec::generic2 > array2h; #endif typedef zfp::array2< double, zfp::codec::generic2 > array2f; typedef zfp::array2< double, zfp::codec::generic2 > array2d; } // enumeration of uncompressed storage types enum storage_type { type_none = 0, type_half = 1, type_float = 2, type_double = 3 }; // constants used in the solution class Constants { public: Constants(size_t nx, size_t ny, size_t nt) : nx(nx), ny(ny), nt(nt), x0((nx - 1) / 2), y0((ny - 1) / 2), k(0.04), dx(2.0 / (std::max(nx, ny) - 1)), dy(2.0 / (std::max(nx, ny) - 1)), dt(0.5 * (dx * dx + dy * dy) / (8 * k)), tfinal(nt ? nt * dt : 1.0), pi(3.14159265358979323846) {} size_t nx; // grid points in x size_t ny; // grid points in y size_t nt; // number of time steps (0 for default) size_t x0; // x location of heat source size_t y0; // y location of heat source double k; // diffusion constant double dx; // grid spacing in x double dy; // grid spacing in y double dt; // time step double tfinal; // minimum time to run solution to double pi; // 3.141... }; // compute Laplacian uxx + uyy at (x, y) template inline double laplacian(const array2d& u, size_t x, size_t y, const Constants& c) { double uxx = (u(x - 1, y) - 2 * u(x, y) + u(x + 1, y)) / (c.dx * c.dx); double uyy = (u(x, y - 1) - 2 * u(x, y) + u(x, y + 1)) / (c.dy * c.dy); return uxx + uyy; } template inline void time_step_parallel(state& u, scratch& v, const Constants& c); #ifdef _OPENMP // advance solution in parallel via thread-safe views template <> inline void time_step_parallel(zfp::array2d& u, zfp::array2d& du, const Constants& c) { // flush shared cache to ensure cache consistency across threads u.flush_cache(); // zero-initialize du du.set(0); // compute du/dt in parallel #pragma omp parallel { // create read-only private view of entire array u zfp::array2d::private_const_view myu(&u); // create read-write private view into rectangular subset of du zfp::array2d::private_view mydu(&du); mydu.partition(omp_get_thread_num(), omp_get_num_threads()); // process rectangular region owned by this thread for (size_t j = 0; j < mydu.size_y(); j++) { size_t y = mydu.global_y(j); if (1 <= y && y <= c.ny - 2) for (size_t i = 0; i < mydu.size_x(); i++) { size_t x = mydu.global_x(i); if (1 <= x && x <= c.nx - 2) mydu(i, j) = c.dt * c.k * laplacian(myu, x, y, c); } } // compress all private cached blocks to shared storage mydu.flush_cache(); } // take forward Euler step in serial for (size_t i = 0; i < u.size(); i++) u[i] += du[i]; } #else // dummy template instantiation when OpenMP support is not available template <> inline void time_step_parallel(zfp::array2d&, zfp::array2d&, const Constants&) {} #endif // dummy template instantiations; never executed template <> inline void time_step_parallel(zfp::const_array2d&, raw::array2d&, const Constants&) {} template <> inline void time_step_parallel(raw::array2d&, raw::array2d&, const Constants&) {} template <> inline void time_step_parallel(tiled::array2d&, tiled::array2d&, const Constants&) {} template <> inline void time_step_parallel(tiled::array2f&, tiled::array2f&, const Constants&) {} #if WITH_HALF template <> inline void time_step_parallel(tiled::array2h&, tiled::array2h&, const Constants&) {} #endif // advance solution using integer array indices (generic implementation) template inline void time_step_indexed(state& u, scratch& du, const Constants& c) { // compute du/dt for (size_t y = 1; y < c.ny - 1; y++) for (size_t x = 1; x < c.nx - 1; x++) du(x, y) = c.dt * c.k * laplacian(u, x, y, c); // take forward Euler step for (uint i = 0; i < u.size(); i++) u[i] += du[i]; } // advance solution using integer array indices (read-only arrays) template <> inline void time_step_indexed(zfp::const_array2d& u, raw::array2d& v, const Constants& c) { // initialize v as uncompressed copy of u u.get(&v[0]); // take forward Euler step v += (du/dt) dt for (size_t y = 1; y < c.ny - 1; y++) for (size_t x = 1; x < c.nx - 1; x++) v(x, y) += c.dt * c.k * laplacian(u, x, y, c); // update u with uncompressed copy v u.set(&v[0]); } // advance solution using array iterators (generic implementation) template inline void time_step_iterated(state& u, scratch& du, const Constants& c) { // compute du/dt for (typename scratch::iterator q = du.begin(); q != du.end(); q++) { size_t x = q.i(); size_t y = q.j(); if (1 <= x && x <= c.nx - 2 && 1 <= y && y <= c.ny - 2) *q = c.dt * c.k * laplacian(u, x, y, c); } // take forward Euler step for (typename state::iterator p = u.begin(); p != u.end(); p++) *p += du(p.i(), p.j()); } // advance solution using array iterators (read-only arrays) template <> inline void time_step_iterated(zfp::const_array2d& u, raw::array2d& v, const Constants& c) { // initialize v as uncompressed copy of u u.get(&v[0]); // take forward Euler step v += (du/dt) dt for (raw::array2d::iterator q = v.begin(); q != v.end(); q++) { size_t x = q.i(); size_t y = q.j(); if (1 <= x && x <= c.nx - 2 && 1 <= y && y <= c.ny - 2) *q += c.dt * c.k * laplacian(u, x, y, c); } // update u with uncompressed copy v u.set(&v[0]); } // set initial conditions with a point heat source (u is assumed zero-initialized) template inline void initialize(state& u, scratch&, const Constants& c) { u(c.x0, c.y0) = 1; } // set initial conditions for const_array; requires updating the whole array template <> inline void initialize(zfp::const_array2d& u, raw::array2d& v, const Constants& c) { v(c.x0, c.y0) = 1; u.set(&v[0]); } // solve heat equation template inline double solve(state& u, scratch& v, const Constants& c, bool iterator, bool parallel) { // initialize u with point heat source initialize(u, v, c); // iterate until final time double t; for (t = 0; t < c.tfinal; t += c.dt) { // print time and effective rate double rate = double(u.size_bytes(ZFP_DATA_PAYLOAD)) * CHAR_BIT / u.size(); double rest = double(u.size_bytes(ZFP_DATA_ALL ^ ZFP_DATA_PAYLOAD) * CHAR_BIT / u.size()); std::cerr << "time=" << std::setprecision(6) << std::fixed << t << " "; std::cerr << "rate=" << std::setprecision(3) << std::fixed << rate << " (+" << rest << ")" << std::endl; // advance solution one time step if (parallel) time_step_parallel(u, v, c); else if (iterator) time_step_iterated(u, v, c); else time_step_indexed(u, v, c); } return t; } // compute sum of array values template inline double total(const state& u) { double s = 0; const size_t nx = u.size_x(); const size_t ny = u.size_y(); for (size_t y = 1; y < ny - 1; y++) for (size_t x = 1; x < nx - 1; x++) s += u(x, y); return s; } // compute root mean square error with respect to exact solution template inline double error(const state& u, const Constants& c, double t) { double e = 0; for (size_t y = 1; y < c.ny - 1; y++) { double py = c.dy * ((int)y - (int)c.y0); for (size_t x = 1; x < c.nx - 1; x++) { double px = c.dx * ((int)x - (int)c.x0); double f = u(x, y); double g = c.dx * c.dy * std::exp(-(px * px + py * py) / (4 * c.k * t)) / (4 * c.pi * c.k * t); e += (f - g) * (f - g); } } return std::sqrt(e / ((c.nx - 2) * (c.ny - 2))); } // execute solver and evaluate error template inline void execute(state& u, scratch& v, size_t nt, bool iterator, bool parallel) { Constants c(u.size_x(), u.size_y(), nt); double t = solve(u, v, c, iterator, parallel); double sum = total(u); double err = error(u, c, t); std::cerr.unsetf(std::ios::fixed); std::cerr << "sum=" << std::setprecision(6) << std::fixed << sum << " error=" << std::setprecision(6) << std::scientific << err << std::endl; } // print usage information inline int usage() { std::cerr << "Usage: diffusion [options]" << std::endl; std::cerr << "Options:" << std::endl; std::cerr << "-a : use compressed arrays with given absolute error tolerance" << std::endl; std::cerr << "-b : use 'blocks' 4x4 blocks of cache" << std::endl; std::cerr << "-c : use read-only compressed arrays" << std::endl; std::cerr << "-d : use double-precision tiled arrays" << std::endl; std::cerr << "-f : use single-precision tiled arrays" << std::endl; #if WITH_HALF std::cerr << "-h : use half-precision tiled arrays" << std::endl; #endif std::cerr << "-i : traverse arrays using iterators" << std::endl; #ifdef _OPENMP std::cerr << "-j : use multithreading (only with compressed arrays)" << std::endl; #endif std::cerr << "-n : number of grid points" << std::endl; std::cerr << "-p : use compressed arrays with given precision" << std::endl; std::cerr << "-r : use compressed arrays with given compressed bits/value" << std::endl; std::cerr << "-R : use compressed arrays with lossless compression" << std::endl; std::cerr << "-t : number of time steps" << std::endl; return EXIT_FAILURE; } int main(int argc, char* argv[]) { size_t nx = 128; size_t ny = 128; size_t nt = 0; size_t cache_size = 0; zfp_config config = zfp_config_none(); bool iterator = false; bool parallel = false; bool writable = true; storage_type type = type_none; // parse command-line options for (int i = 1; i < argc; i++) if (std::string(argv[i]) == "-a") { double tolerance; if (++i == argc || sscanf(argv[i], "%lf", &tolerance) != 1) return usage(); config = zfp_config_accuracy(tolerance); } else if (std::string(argv[i]) == "-b") { if (++i == argc || (std::istringstream(argv[i]) >> cache_size).fail()) return usage(); cache_size *= 4 * 4 * sizeof(double); } else if (std::string(argv[i]) == "-c") writable = false; else if (std::string(argv[i]) == "-d") type = type_double; else if (std::string(argv[i]) == "-f") type = type_float; #if WITH_HALF else if (std::string(argv[i]) == "-h") type = type_half; #endif else if (std::string(argv[i]) == "-i") iterator = true; #ifdef _OPENMP else if (std::string(argv[i]) == "-j") parallel = true; #endif else if (std::string(argv[i]) == "-n") { if (++i == argc || (std::istringstream(argv[i]) >> nx).fail() || ++i == argc || (std::istringstream(argv[i]) >> ny).fail()) return usage(); } else if (std::string(argv[i]) == "-p") { uint precision; if (++i == argc || sscanf(argv[i], "%u", &precision) != 1) return usage(); config = zfp_config_precision(precision); } else if (std::string(argv[i]) == "-r") { double rate; if (++i == argc || sscanf(argv[i], "%lf", &rate) != 1) return usage(); config = zfp_config_rate(rate, false); } else if (std::string(argv[i]) == "-R") config = zfp_config_reversible(); else if (std::string(argv[i]) == "-t") { if (++i == argc || (std::istringstream(argv[i]) >> nt).fail()) return usage(); } else return usage(); bool compression = (config.mode != zfp_mode_null); // sanity check command-line arguments if (parallel && !compression) { fprintf(stderr, "multithreading requires compressed arrays\n"); return EXIT_FAILURE; } if (parallel && !writable) { fprintf(stderr, "multithreading requires read-write arrays\n"); return EXIT_FAILURE; } if (parallel && iterator) { fprintf(stderr, "multithreading does not support iterators\n"); return EXIT_FAILURE; } if (compression && writable && config.mode != zfp_mode_fixed_rate) { fprintf(stderr, "compression mode requires read-only arrays (-c)\n"); return EXIT_FAILURE; } if (!writable && !compression) { fprintf(stderr, "read-only arrays require compression parameters\n"); return EXIT_FAILURE; } if (compression && type != type_none) { fprintf(stderr, "tiled arrays do not support compression parameters\n"); return EXIT_FAILURE; } // if unspecified, set cache size to two layers of blocks if (!cache_size) cache_size = 2 * 4 * nx * sizeof(double); // solve problem if (compression) { // use compressed arrays if (writable) { // use read-write fixed-rate arrays zfp::array2d u(nx, ny, config.arg.rate, 0, cache_size); zfp::array2d v(nx, ny, config.arg.rate, 0, cache_size); execute(u, v, nt, iterator, parallel); } else { // use read-only variable-rate arrays zfp::const_array2d u(nx, ny, config, 0, cache_size); raw::array2d v(nx, ny); execute(u, v, nt, iterator, parallel); } } else { // use uncompressed arrays switch (type) { #if WITH_HALF case type_half: { // use zfp generic codec with tiled half-precision storage tiled::array2h u(nx, ny, sizeof(__fp16) * CHAR_BIT, 0, cache_size); tiled::array2h v(nx, ny, sizeof(__fp16) * CHAR_BIT, 0, cache_size); execute(u, v, nt, iterator, parallel); } break; #endif case type_float: { // use zfp generic codec with tiled single-precision storage tiled::array2f u(nx, ny, sizeof(float) * CHAR_BIT, 0, cache_size); tiled::array2f v(nx, ny, sizeof(float) * CHAR_BIT, 0, cache_size); execute(u, v, nt, iterator, parallel); } break; case type_double: { // use zfp generic codec with tiled double-precision storage tiled::array2d u(nx, ny, sizeof(double) * CHAR_BIT, 0, cache_size); tiled::array2d v(nx, ny, sizeof(double) * CHAR_BIT, 0, cache_size); execute(u, v, nt, iterator, parallel); } break; default: { // use uncompressed array with row-major double-precision storage raw::array2d u(nx, ny, sizeof(double) * CHAR_BIT); raw::array2d v(nx, ny, sizeof(double) * CHAR_BIT); execute(u, v, nt, iterator, parallel); } break; } } return 0; } zfp-1.0.1/examples/diffusionC.c000066400000000000000000000204241453723256400164000ustar00rootroot00000000000000/* forward Euler finite difference solution to the heat equation on a 2D grid (ported to C, from diffusion.cpp) */ #include #include #include #include "zfp/array.h" #define _ (CFP_NAMESPACE.array2d) #define MAX(x, y) (((nx) > (ny)) ? (nx) : (ny)) /* constants used in the solution */ typedef struct { size_t nx; /* grid points in x */ size_t ny; /* grid points in y */ int nt; /* number of time steps (0 for default) */ int x0; /* x location of heat source */ int y0; /* y location of heat source */ double k; /* diffusion constant */ double dx; /* grid spacing in x */ double dy; /* grid spacing in y */ double dt; /* time step */ double tfinal; /* minimum time to run solution to */ double pi; /* 3.141... */ } constants; void init_constants(constants* c, int nx, int ny, int nt) { c->nx = nx; c->ny = ny; c->nt = nt; c->x0 = (nx - 1) / 2; c->y0 = (ny - 1) / 2; c->k = 0.04; c->dx = 2.0 / (MAX(nx, ny) - 1); c->dy = 2.0 / (MAX(nx, ny) - 1); c->dt = 0.5 * (c->dx * c->dx + c->dy * c->dy) / (8 * c->k); c->tfinal = nt ? nt * c->dt : 1.0; c->pi = 3.14159265358979323846; } /* advance solution using integer array indices */ static void time_step_indexed_compressed(cfp_array2d u, const constants* c) { /* compute du/dt */ cfp_array2d du = _.ctor(c->nx, c->ny, _.rate(u), 0, _.cache_size(u)); size_t i, x, y; for (y = 1; y < c->ny - 1; y++) { for (x = 1; x < c->nx - 1; x++) { double uxx = (_.get(u, x - 1, y) - 2 * _.get(u, x, y) + _.get(u, x + 1, y)) / (c->dx * c->dx); double uyy = (_.get(u, x, y - 1) - 2 * _.get(u, x, y) + _.get(u, x, y + 1)) / (c->dy * c->dy); _.set(du, x, y, c->dt * c->k * (uxx + uyy)); } } /* take forward Euler step */ for (i = 0; i < _.size(u); i++) { /* u[i] += du[i] */ double val = _.get_flat(u, i) + _.get_flat(du, i); _.set_flat(u, i, val); } _.dtor(du); } /* advance solution using array iterators */ static void time_step_iterated_compressed(cfp_array2d u, const constants* c) { /* compute du/dt */ cfp_array2d du = _.ctor(c->nx, c->ny, _.rate(u), 0, _.cache_size(u)); cfp_iter2d p, q; for (q = _.begin(du); _.iterator.neq(q, _.end(du)); q = _.iterator.inc(q)) { size_t x = _.iterator.i(q); size_t y = _.iterator.j(q); if (1 <= x && x <= c->nx - 2 && 1 <= y && y <= c->ny - 2) { double uxx = (_.get(u, x - 1, y) - 2 * _.get(u, x, y) + _.get(u, x + 1, y)) / (c->dx * c->dx); double uyy = (_.get(u, x, y - 1) - 2 * _.get(u, x, y) + _.get(u, x, y + 1)) / (c->dy * c->dy); _.iterator.set(q, c->dt * c->k * (uxx + uyy)); } } /* take forward Euler step */ for (p = _.begin(u), q = _.begin(du); _.iterator.neq(p, _.end(u)); p = _.iterator.inc(p), q = _.iterator.inc(q)) { /* u[i] += du[i] */ double val = _.iterator.get(p) + _.iterator.get(q); _.iterator.set(p, val); } _.dtor(du); } /* advance solution using integer array indices */ static void time_step_indexed(double* u, const constants* c) { /* compute du/dt */ double* du = calloc(c->nx * c->ny, sizeof(double)); size_t i, x, y; for (y = 1; y < c->ny - 1; y++) for (x = 1; x < c->nx - 1; x++) { double uxx = (u[(x - 1) + c->nx * y] - 2 * u[x + c->nx * y] + u[(x + 1) + c->nx * y]) / (c->dx * c->dx); double uyy = (u[x + c->nx * (y - 1)] - 2 * u[x + c->nx * y] + u[x + c->nx * (y + 1)]) / (c->dy * c->dy); du[x + c->nx * y] = c->dt * c->k * (uxx + uyy); } /* take forward Euler step */ for (i = 0; i < c->nx * c->ny; i++) u[i] += du[i]; free(du); } /* solve heat equation using compressed arrays */ static double solve_compressed(cfp_array2d u, const constants* c, zfp_bool iterator) { double t; /* initialize u with point heat source (u is assumed to be zero initialized) */ _.set(u, c->x0, c->y0, 1); /* iterate until final time */ for (t = 0; t < c->tfinal; t += c->dt) { fprintf(stderr, "t=%lf\n", t); if (iterator) time_step_iterated_compressed(u, c); else time_step_indexed_compressed(u, c); } return t; } /* solve heat equation using uncompressed arrays */ static double solve(double* u, const constants* c) { double t; /* initialize u with point heat source (u is assumed to be zero initialized) */ u[c->x0 + c->nx * c->y0] = 1; /* iterate until final time */ for (t = 0; t < c->tfinal; t += c->dt) { fprintf(stderr, "t=%lf\n", t); time_step_indexed(u, c); } return t; } /* compute sum of array values */ static double total_compressed(const cfp_array2d u) { double s = 0; const size_t nx = _.size_x(u); const size_t ny = _.size_y(u); size_t x, y; for (y = 1; y < ny - 1; y++) for (x = 1; x < nx - 1; x++) s += _.get(u, x, y); return s; } /* compute sum of array values */ static double total(const double* u, size_t nx, size_t ny) { double s = 0; size_t x, y; for (y = 1; y < ny - 1; y++) for (x = 1; x < nx - 1; x++) s += u[x + nx * y]; return s; } /* compute root mean square error with respect to exact solution */ static double error_compressed(const cfp_array2d u, const constants* c, double t) { double e = 0; size_t x, y; for (y = 1; y < c->ny - 1; y++) { double py = c->dy * ((int)y - (int)c->y0); for (x = 1; x < c->nx - 1; x++) { double px = c->dx * ((int)x - (int)c->x0); double f = _.get(u, x, y); double g = c->dx * c->dy * exp(-(px * px + py * py) / (4 * c->k * t)) / (4 * c->pi * c->k * t); e += (f - g) * (f - g); } } return sqrt(e / ((c->nx - 2) * (c->ny - 2))); } /* compute root mean square error with respect to exact solution */ static double error(const double* u, const constants* c, double t) { double e = 0; size_t x, y; for (y = 1; y < c->ny - 1; y++) { double py = c->dy * ((int)y - (int)c->y0); for (x = 1; x < c->nx - 1; x++) { double px = c->dx * ((int)x - (int)c->x0); double f = u[x + c->nx * y]; double g = c->dx * c->dy * exp(-(px * px + py * py) / (4 * c->k * t)) / (4 * c->pi * c->k * t); e += (f - g) * (f - g); } } return sqrt(e / ((c->nx - 2) * (c->ny - 2))); } static int usage(void) { fprintf(stderr, "Usage: diffusionC [options]\n"); fprintf(stderr, "Options:\n"); fprintf(stderr, "-b : use 'blocks' 4x4 blocks of cache\n"); fprintf(stderr, "-i : traverse arrays using iterators\n"); fprintf(stderr, "-n : number of grid points\n"); fprintf(stderr, "-r : use compressed arrays with given compressed bits/value\n"); fprintf(stderr, "-t : number of time steps\n"); return EXIT_FAILURE; } int main(int argc, char* argv[]) { int nx = 128; int ny = 128; int nt = 0; int cache_size = 0; double rate = 64; zfp_bool iterator = zfp_false; zfp_bool compression = zfp_false; constants* c = 0; double sum; double err; /* parse command-line options */ int i; for (i = 1; i < argc; i++) { if (argv[i][0] != '-' || argv[i][2]) return usage(); switch(argv[i][1]) { case 'b': if (++i == argc || sscanf(argv[i], "%d", &cache_size) != 1) return usage(); cache_size *= (int)(4 * 4 * sizeof(double)); break; case 'i': iterator = zfp_true; break; case 'n': if (++i == argc || sscanf(argv[i], "%d", &nx) != 1 || ++i == argc || sscanf(argv[i], "%d", &ny) != 1) return usage(); break; case 'r': if (++i == argc || sscanf(argv[i], "%lf", &rate) != 1) return usage(); compression = zfp_true; break; case 't': if (++i == argc || sscanf(argv[i], "%d", &nt) != 1) return usage(); break; default: return usage(); } } c = malloc(sizeof(constants)); init_constants(c, nx, ny, nt); if (compression) { /* solve problem using compressed arrays */ cfp_array2d u = _.ctor(nx, ny, rate, 0, cache_size); double t = solve_compressed(u, c, iterator); sum = total_compressed(u); err = error_compressed(u, c, t); rate = _.rate(u); _.dtor(u); } else { /* solve problem using primitive arrays */ double* u = calloc(nx * ny, sizeof(double)); double t = solve(u, c); sum = total(u, nx, ny); err = error(u, c, t); free(u); } fprintf(stderr, "rate=%g sum=%g error=%.6e\n", rate, sum, err); free(c); return 0; } zfp-1.0.1/examples/inplace.c000066400000000000000000000105231453723256400157210ustar00rootroot00000000000000/* example illustrating in-place compression and decompression */ #include #include #include #include #include #include "zfp.h" /* compress and decompress contiguous blocks */ static int process(double* buffer, uint blocks, double tolerance) { zfp_stream* zfp; /* compressed stream */ bitstream* stream; /* bit stream to write to or read from */ size_t* offset; /* per-block bit offset in compressed stream */ double* ptr; /* pointer to block being processed */ size_t bufsize; /* byte size of uncompressed storage */ size_t zfpsize; /* byte size of compressed stream */ uint minbits; /* min bits per block */ uint maxbits; /* max bits per block */ uint maxprec; /* max precision */ int minexp; /* min bit plane encoded */ uint bits; /* size of compressed block */ uint i; /* maintain offset to beginning of each variable-length block */ offset = malloc(blocks * sizeof(size_t)); /* associate bit stream with same storage as input */ bufsize = blocks * 4 * 4 * sizeof(*buffer); stream = stream_open(buffer, bufsize); /* allocate meta data for a compressed stream */ zfp = zfp_stream_open(stream); /* set tolerance for fixed-accuracy mode */ zfp_stream_set_accuracy(zfp, tolerance); /* set maxbits to guard against prematurely overwriting the input */ zfp_stream_params(zfp, &minbits, &maxbits, &maxprec, &minexp); maxbits = 4 * 4 * sizeof(*buffer) * CHAR_BIT; zfp_stream_set_params(zfp, minbits, maxbits, maxprec, minexp); /* compress one block at a time in sequential order */ ptr = buffer; for (i = 0; i < blocks; i++) { offset[i] = stream_wtell(stream); bits = (uint)zfp_encode_block_double_2(zfp, ptr); if (!bits) { fprintf(stderr, "compression failed\n"); return 0; } printf("block #%u offset=%4u size=%4u\n", i, (uint)offset[i], bits); ptr += 4 * 4; } /* important: flush any buffered compressed bits */ stream_flush(stream); /* print out size */ zfpsize = stream_size(stream); printf("compressed %u bytes to %u bytes\n", (uint)bufsize, (uint)zfpsize); /* decompress one block at a time in reverse order */ for (i = blocks; i--;) { ptr -= 4 * 4; stream_rseek(stream, offset[i]); if (!zfp_decode_block_double_2(zfp, ptr)) { fprintf(stderr, "decompression failed\n"); return 0; } } /* clean up */ zfp_stream_close(zfp); stream_close(stream); free(offset); return 1; } int main(int argc, char* argv[]) { double tolerance = 1e-6; double* array; double* buffer; uint bx = 2; uint by = 4; uint nx = 4 * bx; uint ny = 4 * by; uint blocks = bx * by; uint x, y; uint i, j, k; int status; switch (argc) { case 2: if (sscanf(argv[1], "%lf", &tolerance) != 1) goto usage; /* FALLTHROUGH */ case 1: break; default: usage: fprintf(stderr, "Usage: inline [tolerance]\n"); return EXIT_FAILURE; } printf("tolerance=%g\n", tolerance); /* initialize array to be compressed */ printf("original %ux%u array:\n", nx, ny); array = malloc(nx * ny * sizeof(double)); for (y = 0; y < ny; y++) { for (x = 0; x < nx; x++) { double u = 2 * (x + 0.5) / nx; double v = asin(1.0) * (y + 0.5); double f = exp(-u * u) * sin(v) / v; printf("%9.6f%c", f, x == nx - 1 ? '\n' : ' '); array[x + nx * y] = f; } } /* reorganize array into 4x4 blocks */ buffer = malloc(blocks * 4 * 4 * sizeof(double)); for (k = 0; k < blocks; k++) for (j = 0; j < 4; j++) for (i = 0; i < 4; i++) { uint x = 4 * (k & 1) + i; uint y = 4 * (k / 2) + j; buffer[i + 4 * (j + 4 * k)] = array[x + nx * y]; } status = process(buffer, blocks, tolerance); if (status) { /* reorganize blocks into array */ for (k = 0; k < blocks; k++) for (j = 0; j < 4; j++) for (i = 0; i < 4; i++) { uint x = 4 * (k & 1) + i; uint y = 4 * (k / 2) + j; array[x + nx * y] = buffer[i + 4 * (j + 4 * k)]; } /* print out modified array*/ printf("decompressed %ux%u array:\n", nx, ny); for (y = 0; y < ny; y++) for (x = 0; x < nx; x++) printf("%9.6f%c", array[x + nx * y], x == nx - 1 ? '\n' : ' '); } free(buffer); free(array); return status ? EXIT_SUCCESS : EXIT_FAILURE; } zfp-1.0.1/examples/iterator.cpp000066400000000000000000000047451453723256400165100ustar00rootroot00000000000000#include #include #include #include "zfp/array1.hpp" #include "zfp/array2.hpp" #include "zfp/array3.hpp" void print1(zfp::array1::pointer p, size_t n) { for (size_t i = 0; i < n; i++) std::cout << p[i] << std::endl; } void print2(zfp::array2::pointer p, size_t n) { while (n--) std::cout << *p++ << std::endl; } void print3(zfp::array1::const_iterator begin, zfp::array1::const_iterator end) { for (zfp::array1::const_iterator p = begin; p != end; p++) std::cout << *p << std::endl; } int main() { // some fun with 1D arrays zfp::array1 v(10, 64.0); // initialize and print array of random values for (zfp::array1::iterator p = v.begin(); p != v.end(); p++) *p = rand(); std::cout << "random array" << std::endl; print1(&v[0], v.size()); std::cout << std::endl; // sorting is possible via random access iterators (1D arrays only) std::sort(v.begin(), v.end()); // print array using iteration std::cout << "sorted array" << std::endl; print3(v.begin(), v.end()); std::cout << std::endl; // some fun with 2D arrays zfp::array2 a(5, 7, 64.0); // print array indices visited in block-order traversal std::cout << "block order (x, y) indices" << std::endl; for (zfp::array2::iterator p = a.begin(); p != a.end(); p++) { std::cout << "(" << p.i() << ", " << p.j() << ")" << std::endl; *p = p.i() + 10 * p.j(); } std::cout << std::endl; // print array contents in row-major order std::cout << "row-major order yx indices" << std::endl; print2(&a[0], a.size()); std::cout << std::endl; // pointer arithmetic std::cout << a.size_x() << " * " << a.size_y() << " = " << (&*a.end() - &*a.begin()) << std::endl; // min and max values std::cout << "min = " << *std::min_element(a.begin(), a.end()) << std::endl; std::cout << "max = " << *std::max_element(a.begin(), a.end()) << std::endl; std::cout << std::endl; // some fun with 3D arrays zfp::array3 b(7, 2, 5, 64.0); // print array indices visited in block-order traversal std::cout << "block order (x, y, z) indices" << std::endl; for (zfp::array3::iterator p = b.begin(); p != b.end(); p++) std::cout << "(" << p.i() << ", " << p.j() << ", " << p.k() << ")" << std::endl; std::cout << std::endl; // pointer arithmetic std::cout << b.size_x() << " * " << b.size_y() << " * " << b.size_z() << " = " << (&*b.end() - &*b.begin()) << std::endl; return 0; } zfp-1.0.1/examples/iteratorC.c000066400000000000000000000057011453723256400162440ustar00rootroot00000000000000#include #include #include "zfp/array.h" void print1(cfp_ptr1d p, size_t n) { size_t i; const cfp_array1d_api _ = cfp.array1d; for (i = 0; i < n; i++) printf("%g\n", _.reference.get(_.pointer.ref_at(p, i))); } void print2(cfp_ptr2d p, size_t n) { const cfp_array2d_api _ = cfp.array2d; while (n--) { printf("%g\n", _.reference.get(_.pointer.ref(p))); p = _.pointer.inc(p); } } void print3(cfp_iter1d begin, cfp_iter1d end) { const cfp_array1d_api _ = cfp.array1d; cfp_iter1d p; for (p = begin; !_.iterator.eq(p, end); p = _.iterator.inc(p)) printf("%g\n", _.reference.get(_.iterator.ref(p))); } int main(void) { const cfp_array1d_api _1d = cfp.array1d; const cfp_array2d_api _2d = cfp.array2d; const cfp_array3d_api _3d = cfp.array3d; cfp_array1d v; cfp_iter1d it1; cfp_array2d a; cfp_iter2d it2; cfp_ptr2d pb2; cfp_ptr2d pe2; cfp_array3d b; cfp_iter3d it3; cfp_ptr3d pb3; cfp_ptr3d pe3; size_t i, j, k; /* some fun with 1D arrays */ v = _1d.ctor(10, 64.0, 0, 0); /* initialize and print array of random values */ for (it1 = _1d.begin(v); !_1d.iterator.eq(it1, _1d.end(v)); it1 = _1d.iterator.inc(it1)) _1d.reference.set(_1d.iterator.ref(it1), rand()); printf("random array\n"); print1(_1d.ptr(v, 0), _1d.size(v)); printf("\n"); /* some fun with 2D arrays */ a = _2d.ctor(5, 7, 64.0, 0, 0); /* print array indices visited in block-order traversal*/ printf("block order (x, y) indices\n"); for (it2 = _2d.begin(a); !_2d.iterator.eq(it2, _2d.end(a)); it2 = _2d.iterator.inc(it2)) { i = _2d.iterator.i(it2); j = _2d.iterator.j(it2); printf("(%lu, %lu)\n", (unsigned long)i, (unsigned long)j); _2d.reference.set(_2d.iterator.ref(it2), i + 10 * j); } printf("\n"); /* print array contents in row-major order */ printf("row-major order yx indices\n"); print2(_2d.ptr_flat(a, 0), _2d.size(a)); printf("\n"); /* pointer arithmetic */ pb2 = _2d.reference.ptr(_2d.iterator.ref(_2d.begin(a))); pe2 = _2d.reference.ptr(_2d.iterator.ref(_2d.end(a))); printf("%lu * %lu = %ld\n", (unsigned long)_2d.size_x(a), (unsigned long)_2d.size_y(a), (long)_2d.pointer.distance(pb2, pe2)); /* some fun with 3D arrays */ b = _3d.ctor(7, 2, 5, 64.0, 0, 0); /* print array indices visited in block-order traversal */ printf("block order (x, y, z) indices\n"); for (it3 = _3d.begin(b); !_3d.iterator.eq(it3, _3d.end(b)); it3 = _3d.iterator.inc(it3)) { i = _3d.iterator.i(it3); j = _3d.iterator.j(it3); k = _3d.iterator.k(it3); printf("(%lu, %lu, %lu)\n", (unsigned long)i, (unsigned long)j, (unsigned long)k); } printf("\n"); /* pointer arithmetic */ pb3 = _3d.reference.ptr(_3d.iterator.ref(_3d.begin(b))); pe3 = _3d.reference.ptr(_3d.iterator.ref(_3d.end(b))); printf("%lu * %lu * %lu = %ld\n", (unsigned long)_3d.size_x(b), (unsigned long)_3d.size_y(b), (unsigned long)_3d.size_z(b), (long)_3d.pointer.distance(pb3, pe3)); return 0; } zfp-1.0.1/examples/pgm.c000066400000000000000000000056331453723256400150770ustar00rootroot00000000000000/* simple example that shows how zfp can be used to compress pgm images */ #include #include #include #include #include #include "zfp.h" int main(int argc, char* argv[]) { double rate = 0; uint nx, ny; uint x, y; char line[0x100]; uchar* image; zfp_field* field; zfp_stream* zfp; bitstream* stream; void* buffer; size_t bytes; size_t size; switch (argc) { case 2: if (sscanf(argv[1], "%lf", &rate) != 1) goto usage; break; default: usage: fprintf(stderr, "Usage: pgm output.pgm\n"); return EXIT_FAILURE; } /* read pgm header */ if (!fgets(line, sizeof(line), stdin) || strcmp(line, "P5\n") || !fgets(line, sizeof(line), stdin) || sscanf(line, "%u%u", &nx, &ny) != 2 || !fgets(line, sizeof(line), stdin) || strcmp(line, "255\n")) { fprintf(stderr, "error opening image\n"); return EXIT_FAILURE; } if ((nx & 3u) || (ny & 3u)) { fprintf(stderr, "image dimensions must be multiples of four\n"); return EXIT_FAILURE; } /* read image data */ image = malloc(nx * ny); if (fread(image, sizeof(*image), nx * ny, stdin) != nx * ny) { fprintf(stderr, "error reading image\n"); return EXIT_FAILURE; } /* create input array */ field = zfp_field_2d(image, zfp_type_int32, nx, ny); /* initialize compressed stream */ zfp = zfp_stream_open(NULL); if (rate < 0) zfp_stream_set_precision(zfp, (uint)floor(0.5 - rate)); else zfp_stream_set_rate(zfp, rate, zfp_type_int32, 2, zfp_false); bytes = zfp_stream_maximum_size(zfp, field); buffer = malloc(bytes); stream = stream_open(buffer, bytes); zfp_stream_set_bit_stream(zfp, stream); zfp_field_free(field); /* compress */ for (y = 0; y < ny; y += 4) for (x = 0; x < nx; x += 4) { uchar ublock[16]; int32 iblock[16]; uint i, j; for (j = 0; j < 4; j++) for (i = 0; i < 4; i++) ublock[i + 4 * j] = image[x + i + nx * (y + j)]; zfp_promote_uint8_to_int32(iblock, ublock, 2); zfp_encode_block_int32_2(zfp, iblock); } zfp_stream_flush(zfp); size = zfp_stream_compressed_size(zfp); fprintf(stderr, "%u compressed bytes (%.2f bps)\n", (uint)size, (double)size * CHAR_BIT / (nx * ny)); /* decompress */ zfp_stream_rewind(zfp); for (y = 0; y < ny; y += 4) for (x = 0; x < nx; x += 4) { int32 iblock[16]; uchar ublock[16]; uint i, j; zfp_decode_block_int32_2(zfp, iblock); zfp_demote_int32_to_uint8(ublock, iblock, 2); for (j = 0; j < 4; j++) for (i = 0; i < 4; i++) image[x + i + nx * (y + j)] = ublock[i + 4 * j]; } zfp_stream_close(zfp); stream_close(stream); free(buffer); /* output reconstructed image */ printf("P5\n"); printf("%u %u\n", nx, ny); printf("255\n"); fwrite(image, sizeof(*image), nx * ny, stdout); free(image); return 0; } zfp-1.0.1/examples/ppm.c000066400000000000000000000255651453723256400151160ustar00rootroot00000000000000/* This simple example shows how zfp can be used to compress 8-bit color images stored in the PPM image format. This lossy compressor employs two common image compression strategies: (1) transformation to the YCoCg color space, which decorrelates color bands, and (2) chroma subsampling, which reduces spatial resolution in the Co and Cg chrominance bands. The single command-line argument selects one of two compression modes: if a positive rate (in bits/pixel) is specified, fixed-rate mode is selected; a negative integer argument, -p, sets the precision to p in fixed-precision mode. Rate allocation in fixed-rate mode assigns more bits to luma than to chroma components due to the relatively higher information content in luma after chroma subsampling. The YCoCg transform employed here has been adapted to avoid range expansion and potential overflow. Chroma subsampling is achieved by performing zfp's forward decorrelating transform and then zeroing all but the four lowest-sequency coefficients, effectively reducing each chroma block to a bilinear approximation. Because only four chroma coefficients per 4x4 pixel block are retained, an alternative to zeroing and then encoding the remaining twelve zero-valued coefficients is to treat the chroma block as being one-dimensional, with only four values, and then compressing it using zfp's 1D codec. The dimensionality of chroma blocks (1 or 2) is specified at compile time via the PPM_CHROMA macro. NOTE: To keep this example simple, only images whose dimensions are multiples of four are supported. */ #ifdef PPM_CHROMA #if PPM_CHROMA != 1 && PPM_CHROMA != 2 #error "compile with PPM_CHROMA=1 or PPM_CHROMA=2" #endif #else /* default */ #define PPM_CHROMA 2 #endif #include #include #include #include #include #include "zfp.h" /* clamp values to 31-bit range */ static void clamp(int32* block, uint n) { uint i; for (i = 0; i < n; i++) { if (block[i] < 1 - (1 << 30)) block[i] = 1 - (1 << 30); if (block[i] > (1 << 30) - 1) block[i] = (1 << 30) - 1; } } /* convert 2D block from RGB to YCoCg color space */ static void rgb2ycocg(int32 ycocg[3][16], /*const*/ int32 rgb[3][16]) { uint i; for (i = 0; i < 16; i++) { int32 r, g, b; int32 y, co, cg, t; /* fetch RGB values */ r = rgb[0][i]; g = rgb[1][i]; b = rgb[2][i]; /* perform range-preserving YCoCg forward transform */ co = (r - b) >> 1; t = b + co; cg = (g - t) >> 1; y = t + cg; /* store YCoCg values */ ycocg[0][i] = y; ycocg[1][i] = co; ycocg[2][i] = cg; } } /* convert 2D block from YCoCg to RGB color space */ static void ycocg2rgb(int32 rgb[3][16], /*const*/ int32 ycocg[3][16]) { uint i; for (i = 0; i < 16; i++) { int32 r, g, b; int32 y, co, cg, t; /* fetch YCoCg values */ y = ycocg[0][i]; co = ycocg[1][i]; cg = ycocg[2][i]; /* perform range-preserving YCoCg inverse transform */ t = y - cg; g = (cg << 1) + t; b = t - co; r = (co << 1) + b; /* store RGB values */ rgb[0][i] = r; rgb[1][i] = g; rgb[2][i] = b; } } /* perform partial forward decorrelating transform */ static void fwd_lift(int32* p, uint s) { int32 x, y, z, w; x = *p; p += s; y = *p; p += s; z = *p; p += s; w = *p; p += s; x += w; x >>= 1; w -= x; z += y; z >>= 1; y -= z; x += z; x >>= 1; z -= x; w += y; w >>= 1; y -= w; w += y >> 1; y -= w >> 1; p -= s; *p = w; p -= s; *p = z; p -= s; *p = y; p -= s; *p = x; } /* perform partial inverse decorrelating transform */ static void inv_lift(int32* p, uint s) { int32 x, y, z, w; x = *p; p += s; y = *p; p += s; z = *p; p += s; w = *p; p += s; y += w >> 1; w -= y >> 1; y += w; w <<= 1; w -= y; z += x; x <<= 1; x -= z; y += z; z <<= 1; z -= y; w += x; x <<= 1; x -= w; p -= s; *p = w; p -= s; *p = z; p -= s; *p = y; p -= s; *p = x; } /* perform chroma subsampling by discarding high-frequency components */ static void chroma_downsample(int32* block) { uint i, j; /* perform forward decorrelating transform */ for (j = 0; j < 4; j++) fwd_lift(block + 4 * j, 1); for (i = 0; i < 4; i++) fwd_lift(block + 1 * i, 4); #if PPM_CHROMA == 1 /* keep only the four lowest-sequency coefficients */ block[2] = block[4]; block[3] = block[5]; for (i = 4; i < 16; i++) block[i] = 0; /* reconstruct as 1D block */ inv_lift(block, 1); /* clamp values to 31 bits to avoid overflow */ clamp(block, 4); #else /* zero out all but four lowest-sequency coefficients */ for (j = 0; j < 4; j++) for (i = 0; i < 4; i++) if (i >= 2 || j >= 2) block[i + 4 * j] = 0; /* perform inverse decorrelating transform */ for (i = 0; i < 4; i++) inv_lift(block + 1 * i, 4); for (j = 0; j < 4; j++) inv_lift(block + 4 * j, 1); /* clamp values to 31 bits to avoid overflow */ clamp(block, 16); #endif } /* reconstruct 2D chroma block */ static void chroma_upsample(int32* block) { #if PPM_CHROMA == 1 uint i, j; /* obtain 1D block coefficients */ fwd_lift(block, 1); /* reorganize and initialize remaining 2D block coefficients */ block[4] = block[2]; block[5] = block[3]; block[2] = 0; block[3] = 0; for (i = 6; i < 16; i++) block[i] = 0; /* perform inverse decorrelating transform */ for (i = 0; i < 4; i++) inv_lift(block + 1 * i, 4); for (j = 0; j < 4; j++) inv_lift(block + 4 * j, 1); /* clamp values to 31 bits to avoid overflow */ clamp(block, 16); #else /* clamp values to 31 bits to avoid overflow */ clamp(block, 16); #endif } int main(int argc, char* argv[]) { double rate = 0; uint nx, ny; uint x, y; uint k; char line[0x100]; uchar* image; zfp_field* field; zfp_stream* zfp[3]; bitstream* stream; void* buffer; size_t bytes; size_t size; switch (argc) { case 2: if (sscanf(argv[1], "%lf", &rate) != 1) goto usage; break; default: usage: fprintf(stderr, "Usage: ppm output.ppm\n"); return EXIT_FAILURE; } /* read ppm header */ if (!fgets(line, sizeof(line), stdin) || strcmp(line, "P6\n") || !fgets(line, sizeof(line), stdin) || sscanf(line, "%u%u", &nx, &ny) != 2 || !fgets(line, sizeof(line), stdin) || strcmp(line, "255\n")) { fprintf(stderr, "error opening image\n"); return EXIT_FAILURE; } if ((nx & 3u) || (ny & 3u)) { fprintf(stderr, "image dimensions must be multiples of four\n"); return EXIT_FAILURE; } /* read image data */ image = malloc(3 * nx * ny); if (!image) { fprintf(stderr, "error allocating memory\n"); return EXIT_FAILURE; } if (fread(image, sizeof(*image), 3 * nx * ny, stdin) != 3 * nx * ny) { fprintf(stderr, "error reading image\n"); return EXIT_FAILURE; } /* initialize compressed streams */ for (k = 0; k < 3; k++) zfp[k] = zfp_stream_open(NULL); if (rate < 0) { /* use fixed-precision mode */ for (k = 0; k < 3; k++) zfp_stream_set_precision(zfp[k], (uint)floor(0.5 - rate)); } else { /* assign higher rate to luminance than to chrominance components */ #if PPM_CHROMA == 1 double chroma_rate = floor(8 * rate / 3 + 0.5) / 4; double luma_rate = rate - chroma_rate / 2; zfp_stream_set_rate(zfp[0], luma_rate, zfp_type_int32, 2, zfp_false); zfp_stream_set_rate(zfp[1], chroma_rate, zfp_type_int32, 1, zfp_false); zfp_stream_set_rate(zfp[2], chroma_rate, zfp_type_int32, 1, zfp_false); #else double chroma_rate = floor(8 * rate / 3 + 0.5) / 16; double luma_rate = rate - 2 * chroma_rate; zfp_stream_set_rate(zfp[0], luma_rate, zfp_type_int32, 2, zfp_false); zfp_stream_set_rate(zfp[1], chroma_rate, zfp_type_int32, 2, zfp_false); zfp_stream_set_rate(zfp[2], chroma_rate, zfp_type_int32, 2, zfp_false); #endif } /* determine size of compressed buffer */ bytes = 0; field = zfp_field_2d(image, zfp_type_int32, nx, ny); for (k = 0; k < 3; k++) bytes += zfp_stream_maximum_size(zfp[k], field); zfp_field_free(field); /* allocate buffer and initialize bit stream */ buffer = malloc(bytes); if (!buffer) { fprintf(stderr, "error allocating memory\n"); return EXIT_FAILURE; } stream = stream_open(buffer, bytes); /* the three zfp streams share a single bit stream */ for (k = 0; k < 3; k++) zfp_stream_set_bit_stream(zfp[k], stream); /* compress image */ for (y = 0; y < ny; y += 4) for (x = 0; x < nx; x += 4) { uchar block[3][16]; int32 rgb[3][16]; int32 ycocg[3][16]; uint i, j, k; /* fetch R, G, and B blocks */ for (k = 0; k < 3; k++) for (j = 0; j < 4; j++) for (i = 0; i < 4; i++) block[k][i + 4 * j] = image[k + 3 * (x + i + nx * (y + j))]; /* promote to 32-bit integers */ for (k = 0; k < 3; k++) zfp_promote_uint8_to_int32(rgb[k], block[k], 2); /* perform color space transform */ rgb2ycocg(ycocg, rgb); /* chroma subsample the Co and Cg bands */ for (k = 1; k < 3; k++) chroma_downsample(ycocg[k]); /* compress the Y, Co, and Cg blocks */ #if PPM_CHROMA == 1 zfp_encode_block_int32_2(zfp[0], ycocg[0]); zfp_encode_block_int32_1(zfp[1], ycocg[1]); zfp_encode_block_int32_1(zfp[2], ycocg[2]); #else for (k = 0; k < 3; k++) zfp_encode_block_int32_2(zfp[k], ycocg[k]); #endif } zfp_stream_flush(zfp[0]); size = zfp_stream_compressed_size(zfp[0]); fprintf(stderr, "%u compressed bytes (%.2f bits/pixel)\n", (uint)size, (double)size * CHAR_BIT / (nx * ny)); /* decompress image */ zfp_stream_rewind(zfp[0]); for (y = 0; y < ny; y += 4) for (x = 0; x < nx; x += 4) { uchar block[3][16]; int32 rgb[3][16]; int32 ycocg[3][16]; uint i, j, k; /* decompress the Y, Co, and Cg blocks */ #if PPM_CHROMA == 1 zfp_decode_block_int32_2(zfp[0], ycocg[0]); zfp_decode_block_int32_1(zfp[1], ycocg[1]); zfp_decode_block_int32_1(zfp[2], ycocg[2]); #else for (k = 0; k < 3; k++) zfp_decode_block_int32_2(zfp[k], ycocg[k]); #endif /* reconstruct Co and Cg chroma bands */ for (k = 1; k < 3; k++) chroma_upsample(ycocg[k]); /* perform color space transform */ ycocg2rgb(rgb, ycocg); /* demote to 8-bit integers */ for (k = 0; k < 3; k++) zfp_demote_int32_to_uint8(block[k], rgb[k], 2); /* store R, G, and B blocks */ for (k = 0; k < 3; k++) for (j = 0; j < 4; j++) for (i = 0; i < 4; i++) image[k + 3 * (x + i + nx * (y + j))] = block[k][i + 4 * j]; } /* clean up */ for (k = 0; k < 3; k++) zfp_stream_close(zfp[k]); stream_close(stream); free(buffer); /* output reconstructed image */ printf("P6\n"); printf("%u %u\n", nx, ny); printf("255\n"); if (fwrite(image, sizeof(*image), 3 * nx * ny, stdout) != 3 * nx * ny) { fprintf(stderr, "error writing image\n"); return EXIT_FAILURE; } free(image); return 0; } zfp-1.0.1/examples/simple.c000066400000000000000000000060311453723256400155760ustar00rootroot00000000000000/* minimal code example showing how to call the zfp (de)compressor */ #include #include #include #include #include "zfp.h" /* compress or decompress array */ static int compress(double* array, size_t nx, size_t ny, size_t nz, double tolerance, zfp_bool decompress) { int status = 0; /* return value: 0 = success */ zfp_type type; /* array scalar type */ zfp_field* field; /* array meta data */ zfp_stream* zfp; /* compressed stream */ void* buffer; /* storage for compressed stream */ size_t bufsize; /* byte size of compressed buffer */ bitstream* stream; /* bit stream to write to or read from */ size_t zfpsize; /* byte size of compressed stream */ /* allocate meta data for the 3D array a[nz][ny][nx] */ type = zfp_type_double; field = zfp_field_3d(array, type, nx, ny, nz); /* allocate meta data for a compressed stream */ zfp = zfp_stream_open(NULL); /* set compression mode and parameters via one of four functions */ /* zfp_stream_set_reversible(zfp); */ /* zfp_stream_set_rate(zfp, rate, type, zfp_field_dimensionality(field), zfp_false); */ /* zfp_stream_set_precision(zfp, precision); */ zfp_stream_set_accuracy(zfp, tolerance); /* allocate buffer for compressed data */ bufsize = zfp_stream_maximum_size(zfp, field); buffer = malloc(bufsize); /* associate bit stream with allocated buffer */ stream = stream_open(buffer, bufsize); zfp_stream_set_bit_stream(zfp, stream); zfp_stream_rewind(zfp); /* compress or decompress entire array */ if (decompress) { /* read compressed stream and decompress and output array */ zfpsize = fread(buffer, 1, bufsize, stdin); if (!zfp_decompress(zfp, field)) { fprintf(stderr, "decompression failed\n"); status = EXIT_FAILURE; } else fwrite(array, sizeof(double), zfp_field_size(field, NULL), stdout); } else { /* compress array and output compressed stream */ zfpsize = zfp_compress(zfp, field); if (!zfpsize) { fprintf(stderr, "compression failed\n"); status = EXIT_FAILURE; } else fwrite(buffer, 1, zfpsize, stdout); } /* clean up */ zfp_field_free(field); zfp_stream_close(zfp); stream_close(stream); free(buffer); free(array); return status; } int main(int argc, char* argv[]) { /* use -d to decompress rather than compress data */ zfp_bool decompress = (argc == 2 && !strcmp(argv[1], "-d")); /* allocate 100x100x100 array of doubles */ size_t nx = 100; size_t ny = 100; size_t nz = 100; double* array = malloc(nx * ny * nz * sizeof(double)); if (!decompress) { /* initialize array to be compressed */ size_t i, j, k; for (k = 0; k < nz; k++) for (j = 0; j < ny; j++) for (i = 0; i < nx; i++) { double x = 2.0 * i / nx; double y = 2.0 * j / ny; double z = 2.0 * k / nz; array[i + nx * (j + ny * k)] = exp(-(x * x + y * y + z * z)); } } /* compress or decompress array */ return compress(array, nx, ny, nz, 1e-3, decompress); } zfp-1.0.1/examples/speed.c000066400000000000000000000071621453723256400154130ustar00rootroot00000000000000/* measure the throughput of encoding and decoding 3D blocks of doubles */ #include #include #include #include #include "zfp.h" /* example 3D block of (reinterpreted) doubles */ static const uint64 block[] = { UINT64C(0xbf7c3a7bb8495ca9), UINT64C(0xbf79f9d9058ffdaf), UINT64C(0xbf77c7abd0b61999), UINT64C(0xbf75a42c806bd1da), UINT64C(0xbf738f8f740b8ea8), UINT64C(0xbf718a050399fef8), UINT64C(0xbf6f2772ff8c30fe), UINT64C(0xbf6b59aa63d22f68), UINT64C(0xbf67aaf8b80cff9e), UINT64C(0xbf641b9e71983592), UINT64C(0xbf60abd3f723f2b7), UINT64C(0xbf5ab7934169cc04), UINT64C(0xbf54574f6f4897d3), UINT64C(0xbf4c6e39da7fb99b), UINT64C(0xbf40ae5826a893d1), UINT64C(0xbf25bce8e19d48e1), UINT64C(0x3f253bfed65904d7), UINT64C(0x3f3f18ab46a04cf3), UINT64C(0x3f4948e7cb74278b), UINT64C(0x3f51427b51aeec2e), UINT64C(0x3f55a0716d8b4b6b), UINT64C(0x3f59be96aeaac56f), UINT64C(0x3f5d9d3ba7bfd327), UINT64C(0x3f609e608469e93e), UINT64C(0x3f624ecbcfa3832c), UINT64C(0x3f63e0202ae84b4d), UINT64C(0x3f6552a61a3f4812), UINT64C(0x3f66a6ae305af268), UINT64C(0x3f67dc910e9935bc), UINT64C(0x3f68f4af65036ff7), UINT64C(0x3f69ef71f24e7182), UINT64C(0x3f6acd4983da7d43), UINT64C(0x3f6b8eaef5b348a0), UINT64C(0x3f6c3423328ffb7a), UINT64C(0x3f6cbe2f33d33034), UINT64C(0x3f6d2d64018af3ac), UINT64C(0x3f6d825ab270c540), UINT64C(0x3f6dbdb46be996cc), UINT64C(0x3f6de01a6205cca9), UINT64C(0x3f6dea3dd7813daf), UINT64C(0x3f6ddcd81dc33335), UINT64C(0x3f6db8aa94de690f), UINT64C(0x3f6d7e7eab910d8f), UINT64C(0x3f6d2f25df44c187), UINT64C(0x3f6ccb79bc0e9844), UINT64C(0x3f6c545bdcaf1795), UINT64C(0x3f6bcab5ea9237c4), UINT64C(0x3f6b2f799dcf639b), UINT64C(0x3f6a83a0bd297862), UINT64C(0x3f69c82d1e0ec5de), UINT64C(0x3f68fe28a4990e53), UINT64C(0x3f6826a5438d8685), UINT64C(0x3f6742bcfc5cd5b2), UINT64C(0x3f665391df231599), UINT64C(0x3f655a4e0aa7d278), UINT64C(0x3f645823ac5e0b09), UINT64C(0x3f634e4d00643085), UINT64C(0x3f623e0c518426a3), UINT64C(0x3f6128abf933439a), UINT64C(0x3f600f7e5f92501c), UINT64C(0x3f5de7bbf6db0eb7), UINT64C(0x3f5bae5aa4792e11), UINT64C(0x3f5975adf0453ea2), UINT64C(0x3f57409b1fdc65c4), }; int main(int argc, char* argv[]) { uint blocks = 0x200000; double rate = 1; zfp_field* field; uint insize; zfp_stream* zfp; bitstream* stream; void* buffer; size_t bytes; clock_t c; double time; uint i; switch (argc) { case 3: sscanf(argv[2], "%u", &blocks); /* FALLTHROUGH */ case 2: sscanf(argv[1], "%lf", &rate); break; } /* declare array to compress */ field = zfp_field_3d(NULL, zfp_type_double, 4, 4, 4 * blocks); insize = blocks * sizeof(block); /* allocate storage for compressed bit stream */ zfp = zfp_stream_open(NULL); zfp_stream_set_rate(zfp, rate, zfp_field_type(field), zfp_field_dimensionality(field), zfp_false); bytes = zfp_stream_maximum_size(zfp, field); buffer = malloc(bytes); stream = stream_open(buffer, bytes); zfp_stream_set_bit_stream(zfp, stream); zfp_field_free(field); /* compress */ c = clock(); for (i = 0; i < blocks; i++) zfp_encode_block_double_3(zfp, (const double*)block); zfp_stream_flush(zfp); time = (double)(clock() - c) / CLOCKS_PER_SEC; printf("encode in=%u out=%u %.0f MB/s\n", insize, (uint)stream_size(stream), insize / (1024 * 1024 * time)); /* decompress */ zfp_stream_rewind(zfp); c = clock(); for (i = 0; i < blocks; i++) { double a[64]; zfp_decode_block_double_3(zfp, a); } time = (double)(clock() - c) / CLOCKS_PER_SEC; printf("decode in=%u out=%u %.0f MB/s\n", (uint)stream_size(stream), insize, insize / (1024 * 1024 * time)); zfp_stream_close(zfp); stream_close(stream); free(buffer); return 0; } zfp-1.0.1/fortran/000077500000000000000000000000001453723256400137765ustar00rootroot00000000000000zfp-1.0.1/fortran/CMakeLists.txt000066400000000000000000000021141453723256400165340ustar00rootroot00000000000000enable_language(Fortran) if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") set(dialect "-ffree-form -fimplicit-none") set(bounds "-fbounds-check") endif() if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") set(dialect "-stand -free -implicitnone") set(bounds "-check bounds") endif() set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/modules) set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${bounds}") set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect}") add_library(zFORp zfp.f90) target_link_libraries(zFORp PRIVATE zfp) set_property(TARGET zFORp PROPERTY VERSION ${ZFP_VERSION}) set_property(TARGET zFORp PROPERTY SOVERSION ${ZFP_VERSION_MAJOR}) set_property(TARGET zFORp PROPERTY OUTPUT_NAME ${ZFP_LIBRARY_PREFIX}zFORp) # install location for module file install(FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/zfp.mod DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) # install location for library install(TARGETS zFORp EXPORT cFORp-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) zfp-1.0.1/fortran/Makefile000066400000000000000000000011171453723256400154360ustar00rootroot00000000000000include ../Config .SUFFIXES: .f90 LIBDIR = ../lib MODDIR = ../modules TARGETS = $(LIBDIR)/libzFORp.a $(LIBDIR)/libzFORp.so $(MODDIR)/zfp.mod OBJECTS = zfp.o MODULES = zfp.mod static: $(LIBDIR)/libzFORp.a $(MODDIR)/zforp.mod shared: $(LIBDIR)/libzFORp.so $(MODDIR)/zforp.mod clean: rm -f $(TARGETS) $(OBJECTS) $(LIBDIR)/libzFORp.a: $(OBJECTS) mkdir -p $(LIBDIR) rm -f $@ ar rc $@ $^ $(LIBDIR)/libzFORp.so: $(OBJECTS) mkdir -p $(LIBDIR) $(FC) $(FFLAGS) -shared $^ -o $@ $(MODDIR)/zforp.mod: $(OBJECTS) mkdir -p $(MODDIR) mv $(MODULES) $(MODDIR) .f90.o: $(FC) $(FFLAGS) -c $< zfp-1.0.1/fortran/zfp.f90000066400000000000000000001246551453723256400151320ustar00rootroot00000000000000module zfp use, intrinsic :: iso_c_binding, only: c_int, c_int64_t, c_size_t, c_ptrdiff_t, c_double, c_ptr, c_null_ptr, c_loc implicit none private ! bind(c) on types, enums because tests written in C need to reference them type, bind(c) :: zFORp_bitstream private type(c_ptr) :: object = c_null_ptr end type zFORp_bitstream type, bind(c) :: zFORp_stream private type(c_ptr) :: object = c_null_ptr end type zFORp_stream type, bind(c) :: zFORp_field private type(c_ptr) :: object = c_null_ptr end type zFORp_field type, bind(c) :: zFORp_config private type(c_ptr) :: object = c_null_ptr end type zFORp_config enum, bind(c) enumerator :: zFORp_type_none = 0, & zFORp_type_int32 = 1, & zFORp_type_int64 = 2, & zFORp_type_float = 3, & zFORp_type_double = 4 end enum enum, bind(c) enumerator :: zFORp_mode_null = 0, & zFORp_mode_expert = 1, & zFORp_mode_fixed_rate = 2, & zFORp_mode_fixed_precision = 3, & zFORp_mode_fixed_accuracy = 4, & zFORp_mode_reversible = 5 end enum enum, bind(c) enumerator :: zFORp_exec_serial = 0, & zFORp_exec_omp = 1, & zFORp_exec_cuda = 2 end enum ! constants are hardcoded ! const_xyz holds value, but xyz is the public constant integer, parameter :: const_zFORp_version_major = 1 integer, parameter :: const_zFORp_version_minor = 0 integer, parameter :: const_zFORp_version_patch = 1 integer, parameter :: const_zFORp_version_tweak = 0 integer, protected, bind(c, name="zFORp_version_major") :: zFORp_version_major integer, protected, bind(c, name="zFORp_version_minor") :: zFORp_version_minor integer, protected, bind(c, name="zFORp_version_patch") :: zFORp_version_patch integer, protected, bind(c, name="zFORp_version_tweak") :: zFORp_version_tweak data zFORp_version_major/const_zFORp_version_major/, & zFORp_version_minor/const_zFORp_version_minor/, & zFORp_version_patch/const_zFORp_version_patch/, & zFORp_version_tweak/const_zFORp_version_tweak/ integer, parameter :: const_zFORp_codec_version = 5 integer, protected, bind(c, name="zFORp_codec_version") :: zFORp_codec_version data zFORp_codec_version/const_zFORp_codec_version/ integer, parameter :: const_zFORp_library_version = 4112 ! 0x1010 integer, protected, bind(c, name="zFORp_library_version") :: zFORp_library_version data zFORp_library_version/const_zFORp_library_version/ character(len = 36), parameter :: zFORp_version_string = 'zfp version 1.0.1 (December 15, 2023)' integer, parameter :: const_zFORp_min_bits = 1 integer, parameter :: const_zFORp_max_bits = 16658 integer, parameter :: const_zFORp_max_prec = 64 integer, parameter :: const_zFORp_min_exp = -1074 integer, protected, bind(c, name="zFORp_min_bits") :: zFORp_min_bits integer, protected, bind(c, name="zFORp_max_bits") :: zFORp_max_bits integer, protected, bind(c, name="zFORp_max_prec") :: zFORp_max_prec integer, protected, bind(c, name="zFORp_min_exp") :: zFORp_min_exp data zFORp_min_bits/const_zFORp_min_bits/, & zFORp_max_bits/const_zFORp_max_bits/, & zFORp_max_prec/const_zFORp_max_prec/, & zFORp_min_exp/const_zFORp_min_exp/ integer, parameter :: const_zFORp_header_magic = 1 integer, parameter :: const_zFORp_header_meta = 2 integer, parameter :: const_zFORp_header_mode = 4 integer, parameter :: const_zFORp_header_full = 7 integer, protected, bind(c, name="zFORp_header_magic") :: zFORp_header_magic integer, protected, bind(c, name="zFORp_header_meta") :: zFORp_header_meta integer, protected, bind(c, name="zFORp_header_mode") :: zFORp_header_mode integer, protected, bind(c, name="zFORp_header_full") :: zFORp_header_full data zFORp_header_magic/const_zFORp_header_magic/, & zFORp_header_meta/const_zFORp_header_meta/, & zFORp_header_mode/const_zFORp_header_mode/, & zFORp_header_full/const_zFORp_header_full/ integer (kind=8), parameter :: const_zFORp_meta_null = -1 integer (kind=8), protected, bind(c, name="zFORp_meta_null") :: zFORp_meta_null data zFORp_meta_null/const_zFORp_meta_null/ integer, parameter :: const_zFORp_magic_bits = 32 integer, parameter :: const_zFORp_meta_bits = 52 integer, parameter :: const_zFORp_mode_short_bits = 12 integer, parameter :: const_zFORp_mode_long_bits = 64 integer, parameter :: const_zFORp_header_max_bits = 148 integer, parameter :: const_zFORp_mode_short_max = 4094 integer, protected, bind(c, name="zFORp_magic_bits") :: zFORp_magic_bits integer, protected, bind(c, name="zFORp_meta_bits") :: zFORp_meta_bits integer, protected, bind(c, name="zFORp_mode_short_bits") :: zFORp_mode_short_bits integer, protected, bind(c, name="zFORp_mode_long_bits") :: zFORp_mode_long_bits integer, protected, bind(c, name="zFORp_header_max_bits") :: zFORp_header_max_bits integer, protected, bind(c, name="zFORp_mode_short_max") :: zFORp_mode_short_max data zFORp_magic_bits/const_zFORp_magic_bits/, & zFORp_meta_bits/const_zFORp_meta_bits/, & zFORp_mode_short_bits/const_zFORp_mode_short_bits/, & zFORp_mode_long_bits/const_zFORp_mode_long_bits/, & zFORp_header_max_bits/const_zFORp_header_max_bits/, & zFORp_mode_short_max/const_zFORp_mode_short_max/ interface ! minimal bitstream API function zfp_bitstream_stream_open(buffer, bytes) result(bs) bind(c, name="stream_open") import type(c_ptr), value :: buffer integer(c_size_t), value :: bytes type(c_ptr) :: bs end function zfp_bitstream_stream_open subroutine zfp_bitstream_stream_close(bs) bind(c, name="stream_close") import type(c_ptr), value :: bs end subroutine ! high-level API: utility functions function zfp_type_size(scalar_type) result(type_size) bind(c, name="zfp_type_size") import integer(c_int), value :: scalar_type integer(c_size_t) :: type_size end function ! high-level API: zfp_stream functions function zfp_stream_open(bs) result(stream) bind(c, name="zfp_stream_open") import type(c_ptr), value :: bs type(c_ptr) :: stream end function zfp_stream_open subroutine zfp_stream_close(stream) bind(c, name="zfp_stream_close") import type(c_ptr), value :: stream end subroutine function zfp_stream_bit_stream(stream) result(bs) bind(c, name="zfp_stream_bit_stream") import type(c_ptr), value :: stream type(c_ptr) :: bs end function function zfp_stream_compression_mode(stream) result(zfp_mode) bind(c, name="zfp_stream_compression_mode") import type(c_ptr), value :: stream integer(c_int) :: zfp_mode end function function zfp_stream_rate(stream, dims) result(rate_result) bind(c, name="zfp_stream_rate") import type(c_ptr), value :: stream integer(c_int), value :: dims real(c_double) :: rate_result end function function zfp_stream_precision(stream) result(prec_result) bind(c, name="zfp_stream_precision") import type(c_ptr), value :: stream integer(c_int) :: prec_result end function function zfp_stream_accuracy(stream) result(acc_result) bind(c, name="zfp_stream_accuracy") import type(c_ptr), value :: stream real(c_double) :: acc_result end function function zfp_stream_mode(stream) result(encoded_mode) bind(c, name="zfp_stream_mode") import type(c_ptr), value :: stream integer(c_int64_t) :: encoded_mode end function subroutine zfp_stream_params(stream, minbits, maxbits, maxprec, minexp) bind(c, name="zfp_stream_params") import type(c_ptr), value :: stream integer(c_int) :: minbits, maxbits, maxprec, minexp end subroutine function zfp_stream_compressed_size(stream) result(compressed_size) bind(c, name="zfp_stream_compressed_size") import type(c_ptr), value :: stream integer(c_size_t) compressed_size end function function zfp_stream_maximum_size(stream, field) result(max_size) bind(c, name="zfp_stream_maximum_size") import type(c_ptr), value :: stream, field integer(c_size_t) max_size end function subroutine zfp_stream_rewind(stream) bind(c, name="zfp_stream_rewind") import type(c_ptr), value :: stream end subroutine subroutine zfp_stream_set_bit_stream(stream, bs) bind(c, name="zfp_stream_set_bit_stream") import type(c_ptr), value :: stream, bs end subroutine subroutine zfp_stream_set_reversible(stream) bind(c, name="zfp_stream_set_reversible") import type(c_ptr), value :: stream end subroutine function zfp_stream_set_rate(stream, rate, scalar_type, dims, align) result(rate_result) bind(c, name="zfp_stream_set_rate") import type(c_ptr), value :: stream real(c_double), value :: rate integer(c_int), value :: scalar_type ! no unsigned int in Fortran integer(c_int), value :: dims, align real(c_double) :: rate_result end function function zfp_stream_set_precision(stream, prec) result(prec_result) bind(c, name="zfp_stream_set_precision") import type(c_ptr), value :: stream integer(c_int), value :: prec integer(c_int) prec_result end function function zfp_stream_set_accuracy(stream, acc) result(acc_result) bind(c, name="zfp_stream_set_accuracy") import type(c_ptr), value :: stream real(c_double), value :: acc real(c_double) acc_result end function function zfp_stream_set_mode(stream, encoded_mode) result(mode_result) bind(c, name="zfp_stream_set_mode") import type(c_ptr), value :: stream integer(c_int64_t), value :: encoded_mode integer(c_int) mode_result end function function zfp_stream_set_params(stream, minbits, maxbits, maxprec, minexp) & result(is_success) bind(c, name="zfp_stream_set_params") import type(c_ptr), value :: stream integer(c_int), value :: minbits, maxbits, maxprec, minexp integer(c_int) is_success end function ! high-level API: execution policy functions function zfp_stream_execution(stream) result(execution_policy) bind(c, name="zfp_stream_execution") import type(c_ptr), value :: stream integer(c_int) execution_policy end function function zfp_stream_omp_threads(stream) result(num_threads) bind(c, name="zfp_stream_omp_threads") import type(c_ptr), value :: stream integer(c_int) num_threads end function function zfp_stream_omp_chunk_size(stream) result(chunk_size_blocks) bind(c, name="zfp_stream_omp_chunk_size") import type(c_ptr), value :: stream integer(c_int) chunk_size_blocks end function function zfp_stream_set_execution(stream, execution_policy) result(is_success) bind(c, name="zfp_stream_set_execution") import type(c_ptr), value :: stream integer(c_int) execution_policy, is_success end function function zfp_stream_set_omp_threads(stream, threads) result(is_success) bind(c, name="zfp_stream_set_omp_threads") import type(c_ptr), value :: stream integer(c_int) threads, is_success end function function zfp_stream_set_omp_chunk_size(stream, chunk_size) result(is_success) bind(c, name="zfp_stream_set_omp_chunk_size") import type(c_ptr), value :: stream integer(c_int) chunk_size, is_success end function ! TODO: high-level API: zfp_config functions (resolve Fortran's lack of unions) ! zfp_config_none ! zfp_config_rate ! zfp_config_precision ! zfp_config_accuracy ! zfp_config_reversible ! zfp_config_expert ! high-level API: zfp_field functions function zfp_field_alloc() result(field) bind(c, name="zfp_field_alloc") import type(c_ptr) :: field end function function zfp_field_1d(uncompressed_ptr, scalar_type, nx) result(field) bind(c, name="zfp_field_1d") import type(c_ptr), value :: uncompressed_ptr type(c_ptr) :: field integer(c_int), value :: scalar_type integer(c_size_t), value :: nx end function function zfp_field_2d(uncompressed_ptr, scalar_type, nx, ny) result(field) bind(c, name="zfp_field_2d") import type(c_ptr), value :: uncompressed_ptr type(c_ptr) :: field integer(c_int), value :: scalar_type integer(c_size_t), value :: nx, ny end function function zfp_field_3d(uncompressed_ptr, scalar_type, nx, ny, nz) result(field) bind(c, name="zfp_field_3d") import type(c_ptr), value :: uncompressed_ptr type(c_ptr) :: field integer(c_int), value :: scalar_type integer(c_size_t), value :: nx, ny, nz end function function zfp_field_4d(uncompressed_ptr, scalar_type, nx, ny, nz, nw) result(field) bind(c, name="zfp_field_4d") import type(c_ptr), value :: uncompressed_ptr type(c_ptr) :: field integer(c_int), value :: scalar_type integer(c_size_t), value :: nx, ny, nz, nw end function subroutine zfp_field_free(field) bind(c, name="zfp_field_free") import type(c_ptr), value :: field end subroutine function zfp_field_pointer(field) result(arr_ptr) bind(c, name="zfp_field_pointer") import type(c_ptr), value :: field type(c_ptr) :: arr_ptr end function function zfp_field_begin(field) result(begin_ptr) bind(c, name="zfp_field_begin") import type(c_ptr), value :: field type(c_ptr) :: begin_ptr end function function zfp_field_type(field) result(scalar_type) bind(c, name="zfp_field_type") import type(c_ptr), value :: field integer(c_int) :: scalar_type end function function zfp_field_precision(field) result(prec) bind(c, name="zfp_field_precision") import type(c_ptr), value :: field integer(c_int) :: prec end function function zfp_field_dimensionality(field) result(dims) bind(c, name="zfp_field_dimensionality") import type(c_ptr), value :: field integer(c_int) :: dims end function function zfp_field_size(field, size_arr) result(total_size) bind(c, name="zfp_field_size") import type(c_ptr), value :: field, size_arr integer(c_size_t) :: total_size end function function zfp_field_size_bytes(field) result(byte_size) bind(c, name="zfp_field_size_bytes") import type(c_ptr), value :: field integer(c_size_t) :: byte_size end function function zfp_field_blocks(field) result(blocks) bind(c, name="zfp_field_blocks") import type(c_ptr), value :: field integer(c_size_t) :: blocks end function function zfp_field_stride(field, stride_arr) result(is_strided) bind(c, name="zfp_field_stride") import type(c_ptr), value :: field, stride_arr integer(c_int) :: is_strided end function function zfp_field_is_contiguous(field) result(is_contiguous) bind(c, name="zfp_field_is_contiguous") import type(c_ptr), value :: field integer(c_int) :: is_contiguous end function function zfp_field_metadata(field) result(encoded_metadata) bind(c, name="zfp_field_metadata") import type(c_ptr), value :: field integer(c_int64_t) :: encoded_metadata end function subroutine zfp_field_set_pointer(field, arr_ptr) bind(c, name="zfp_field_set_pointer") import type(c_ptr), value :: field, arr_ptr end subroutine function zfp_field_set_type(field, scalar_type) result(scalar_type_result) bind(c, name="zfp_field_set_type") import type(c_ptr), value :: field integer(c_int) scalar_type, scalar_type_result end function subroutine zfp_field_set_size_1d(field, nx) bind(c, name="zfp_field_set_size_1d") import type(c_ptr), value :: field integer(c_size_t) :: nx end subroutine subroutine zfp_field_set_size_2d(field, nx, ny) bind(c, name="zfp_field_set_size_2d") import type(c_ptr), value :: field integer(c_size_t) :: nx, ny end subroutine subroutine zfp_field_set_size_3d(field, nx, ny, nz) bind(c, name="zfp_field_set_size_3d") import type(c_ptr), value :: field integer(c_size_t) :: nx, ny, nz end subroutine subroutine zfp_field_set_size_4d(field, nx, ny, nz, nw) bind(c, name="zfp_field_set_size_4d") import type(c_ptr), value :: field integer(c_size_t) :: nx, ny, nz, nw end subroutine subroutine zfp_field_set_stride_1d(field, sx) bind(c, name="zfp_field_set_stride_1d") import type(c_ptr), value :: field integer(c_ptrdiff_t), value :: sx end subroutine subroutine zfp_field_set_stride_2d(field, sx, sy) bind(c, name="zfp_field_set_stride_2d") import type(c_ptr), value :: field integer(c_ptrdiff_t), value :: sx, sy end subroutine subroutine zfp_field_set_stride_3d(field, sx, sy, sz) bind(c, name="zfp_field_set_stride_3d") import type(c_ptr), value :: field integer(c_ptrdiff_t), value :: sx, sy, sz end subroutine subroutine zfp_field_set_stride_4d(field, sx, sy, sz, sw) bind(c, name="zfp_field_set_stride_4d") import type(c_ptr), value :: field integer(c_ptrdiff_t), value :: sx, sy, sz, sw end subroutine function zfp_field_set_metadata(field, encoded_metadata) result(is_success) bind(c, name="zfp_field_set_metadata") import type(c_ptr), value :: field integer(c_int64_t) :: encoded_metadata integer(c_int) :: is_success end function ! high-level API: compression and decompression function zfp_compress(stream, field) result(bitstream_offset_bytes) bind(c, name="zfp_compress") import type(c_ptr), value :: stream, field integer(c_size_t) :: bitstream_offset_bytes end function function zfp_decompress(stream, field) result(bitstream_offset_bytes) bind(c, name="zfp_decompress") import type(c_ptr), value :: stream, field integer(c_size_t) :: bitstream_offset_bytes end function function zfp_write_header(stream, field, mask) result(num_bits_written) bind(c, name="zfp_write_header") import type(c_ptr), value :: stream, field integer(c_int) :: mask integer(c_size_t) :: num_bits_written end function function zfp_read_header(stream, field, mask) result(num_bits_read) bind(c, name="zfp_read_header") import type(c_ptr), value :: stream, field integer(c_int) :: mask integer(c_size_t) :: num_bits_read end function end interface ! types public :: zFORp_bitstream, & zFORp_stream, & zFORp_field, & zFORp_config ! enums public :: zFORp_type_none, & zFORp_type_int32, & zFORp_type_int64, & zFORp_type_float, & zFORp_type_double public :: zFORp_mode_null, & zFORp_mode_expert, & zFORp_mode_fixed_rate, & zFORp_mode_fixed_precision, & zFORp_mode_fixed_accuracy, & zFORp_mode_reversible public :: zFORp_exec_serial, & zFORp_exec_omp, & zFORp_exec_cuda ! C macros -> constants public :: zFORp_version_major, & zFORp_version_minor, & zFORp_version_patch, & zFORp_version_tweak public :: zFORp_codec_version, & zFORp_library_version, & zFORp_version_string public :: zFORp_min_bits, & zFORp_max_bits, & zFORp_max_prec, & zFORp_min_exp public :: zFORp_header_magic, & zFORp_header_meta, & zFORp_header_mode, & zFORp_header_full public :: zFORp_meta_null public :: zFORp_magic_bits, & zFORp_meta_bits, & zFORp_mode_short_bits, & zFORp_mode_long_bits, & zFORp_header_max_bits, & zFORp_mode_short_max ! minimal bitstream API public :: zFORp_type_size public :: zFORp_bitstream_stream_open, & zFORp_bitstream_stream_close ! high-level API: zfp_stream functions public :: zFORp_stream_open, & zFORp_stream_close, & zFORp_stream_bit_stream, & zFORp_stream_compression_mode, & zFORp_stream_rate, & zFORp_stream_precision, & zFORp_stream_accuracy, & zFORp_stream_mode, & zFORp_stream_params, & zFORp_stream_compressed_size, & zFORp_stream_maximum_size, & zFORp_stream_rewind, & zFORp_stream_set_bit_stream, & zFORp_stream_set_reversible, & zFORp_stream_set_rate, & zFORp_stream_set_precision, & zFORp_stream_set_accuracy, & zFORp_stream_set_mode, & zFORp_stream_set_params ! high-level API: execution policy functions public :: zFORp_stream_execution, & zFORp_stream_omp_threads, & zFORp_stream_omp_chunk_size, & zFORp_stream_set_execution, & zFORp_stream_set_omp_threads, & zFORp_stream_set_omp_chunk_size ! TODO: high-level API: compression mode and parameter settings ! public :: zFORp_config_none, & ! zFORp_config_rate, & ! zFORp_config_precision, & ! zFORp_config_accuracy, & ! zFORp_config_reversible, & ! zFORp_config_expert ! high-level API: zfp_field functions public :: zFORp_field_alloc, & zFORp_field_1d, & zFORp_field_2d, & zFORp_field_3d, & zFORp_field_4d, & zFORp_field_free, & zFORp_field_pointer, & zFORp_field_begin, & zFORp_field_type, & zFORp_field_precision, & zFORp_field_dimensionality, & zFORp_field_size, & zFORp_field_size_bytes, & zFORp_field_blocks, & zFORp_field_stride, & zFORp_field_is_contiguous, & zFORp_field_metadata, & zFORp_field_set_pointer, & zFORp_field_set_type, & zFORp_field_set_size_1d, & zFORp_field_set_size_2d, & zFORp_field_set_size_3d, & zFORp_field_set_size_4d, & zFORp_field_set_stride_1d, & zFORp_field_set_stride_2d, & zFORp_field_set_stride_3d, & zFORp_field_set_stride_4d, & zFORp_field_set_metadata ! high-level API: compression and decompression public :: zFORp_compress, & zFORp_decompress, & zFORp_write_header, & zFORp_read_header contains ! minimal bitstream API function zFORp_bitstream_stream_open(buffer, bytes) result(bs) bind(c, name="zforp_bitstream_stream_open") implicit none type(zFORp_bitstream) :: bs type(c_ptr), intent(in) :: buffer integer (kind=8), intent(in) :: bytes bs%object = zfp_bitstream_stream_open(buffer, int(bytes, c_size_t)) end function zFORp_bitstream_stream_open subroutine zFORp_bitstream_stream_close(bs) bind(c, name="zforp_bitstream_stream_close") type(zFORp_bitstream), intent(inout) :: bs call zfp_bitstream_stream_close(bs%object) bs%object = c_null_ptr end subroutine zFORp_bitstream_stream_close ! high-level API: utility functions function zFORp_type_size(scalar_type) result(type_size) bind(c, name="zforp_type_size") implicit none integer, intent(in) :: scalar_type integer (kind=8) :: type_size type_size = zfp_type_size(int(scalar_type, c_int)) end function zFORp_type_size ! high-level API: zfp_stream functions function zFORp_stream_open(bs) result(stream) bind(c, name="zforp_stream_open") implicit none type(zFORp_bitstream), intent(in) :: bs type(zFORp_stream) :: stream stream%object = zfp_stream_open(bs%object) end function zFORp_stream_open subroutine zFORp_stream_close(stream) bind(c, name="zforp_stream_close") type(zFORp_stream), intent(inout) :: stream call zfp_stream_close(stream%object) stream%object = c_null_ptr end subroutine zFORp_stream_close function zFORp_stream_bit_stream(stream) result(bs) bind(c, name="zforp_stream_bit_stream") implicit none type(zFORp_stream), intent(in) :: stream type(zFORp_bitstream) :: bs bs%object = zfp_stream_bit_stream(stream%object) end function zFORp_stream_bit_stream function zFORp_stream_compression_mode(stream) result(zfp_mode) bind(c, name="zforp_stream_compression_mode") implicit none type(zFORp_stream), intent(in) :: stream integer :: zfp_mode zfp_mode = zfp_stream_compression_mode(stream%object) end function zFORp_stream_compression_mode function zFORp_stream_rate(stream, dims) result(rate_result) bind(c, name="zforp_stream_rate") implicit none type(zFORp_stream), intent(in) :: stream integer, intent(in) :: dims real (kind=8) :: rate_result rate_result = zfp_stream_rate(stream%object, int(dims, c_int)) end function zFORp_stream_rate function zFORp_stream_precision(stream) result(prec_result) bind(c, name="zforp_stream_precision") implicit none type(zFORp_stream), intent(in) :: stream integer :: prec_result prec_result = zfp_stream_precision(stream%object) end function zFORp_stream_precision function zFORp_stream_accuracy(stream) result(acc_result) bind(c, name="zforp_stream_accuracy") implicit none type(zFORp_stream), intent(in) :: stream real (kind=8) :: acc_result acc_result = zfp_stream_accuracy(stream%object) end function zFORp_stream_accuracy function zFORp_stream_mode(stream) result(encoded_mode) bind(c, name="zforp_stream_mode") implicit none type(zFORp_stream), intent(in) :: stream integer (kind=8) :: encoded_mode encoded_mode = zfp_stream_mode(stream%object) end function zFORp_stream_mode subroutine zFORp_stream_params(stream, minbits, maxbits, maxprec, minexp) bind(c, name="zforp_stream_params") type(zFORp_stream), intent(in) :: stream integer, intent(inout) :: minbits, maxbits, maxprec, minexp call zfp_stream_params(stream%object, & int(minbits, c_int), & int(maxbits, c_int), & int(maxprec, c_int), & int(minexp, c_int)) end subroutine zFORp_stream_params function zFORp_stream_compressed_size(stream) result(compressed_size) bind(c, name="zforp_stream_compressed_size") implicit none type(zFORp_stream), intent(in) :: stream integer (kind=8) :: compressed_size compressed_size = zfp_stream_compressed_size(stream%object) end function zFORp_stream_compressed_size function zFORp_stream_maximum_size(stream, field) result(max_size) bind(c, name="zforp_stream_maximum_size") implicit none type(zFORp_stream), intent(in) :: stream type(zFORp_field), intent(in) :: field integer (kind=8) :: max_size max_size = zfp_stream_maximum_size(stream%object, field%object) end function zFORp_stream_maximum_size subroutine zFORp_stream_rewind(stream) bind(c, name="zforp_stream_rewind") type(zFORp_stream), intent(in) :: stream call zfp_stream_rewind(stream%object) end subroutine zFORp_stream_rewind subroutine zFORp_stream_set_bit_stream(stream, bs) bind(c, name="zforp_stream_set_bit_stream") type(zFORp_stream), intent(in) :: stream type(zFORp_bitstream), intent(in) :: bs call zfp_stream_set_bit_stream(stream%object, bs%object) end subroutine zFORp_stream_set_bit_stream subroutine zFORp_stream_set_reversible(stream) bind(c, name="zforp_stream_set_reversible") type(zFORp_stream), intent(in) :: stream call zfp_stream_set_reversible(stream%object) end subroutine zFORp_stream_set_reversible function zFORp_stream_set_rate(stream, rate, scalar_type, dims, align) result(rate_result) bind(c, name="zforp_stream_set_rate") implicit none type(zFORp_stream), intent(in) :: stream real (kind=8), intent(in) :: rate integer, intent(in) :: scalar_type integer, intent(in) :: dims, align real (kind=8) :: rate_result rate_result = zfp_stream_set_rate(stream%object, real(rate, c_double), & int(scalar_type, c_int), int(dims, c_int), int(align, c_int)) end function zFORp_stream_set_rate function zFORp_stream_set_precision(stream, prec) result(prec_result) bind(c, name="zforp_stream_set_precision") implicit none type(zFORp_stream), intent(in) :: stream integer, intent(in) :: prec integer :: prec_result prec_result = zfp_stream_set_precision(stream%object, int(prec, c_int)) end function zFORp_stream_set_precision function zFORp_stream_set_accuracy(stream, tolerance) result(acc_result) bind(c, name="zforp_stream_set_accuracy") implicit none type(zFORp_stream), intent(in) :: stream real (kind=8), intent(in) :: tolerance real (kind=8) :: acc_result acc_result = zfp_stream_set_accuracy(stream%object, real(tolerance, c_double)) end function zFORp_stream_set_accuracy function zFORp_stream_set_mode(stream, encoded_mode) result(mode_result) bind(c, name="zforp_stream_set_mode") implicit none type(zFORp_stream), intent(in) :: stream integer (kind=8), intent(in) :: encoded_mode integer :: mode_result mode_result = zfp_stream_set_mode(stream%object, int(encoded_mode, c_int64_t)) end function zFORp_stream_set_mode function zFORp_stream_set_params(stream, minbits, maxbits, maxprec, minexp) result(is_success) & bind(c, name="zforp_stream_set_params") implicit none type(zFORp_stream), intent(in) :: stream integer, intent(in) :: minbits, maxbits, maxprec, minexp integer :: is_success is_success = zfp_stream_set_params(stream%object, & int(minbits, c_int), & int(maxbits, c_int), & int(maxprec, c_int), & int(minexp, c_int)) end function zFORp_stream_set_params ! high-level API: execution policy functions function zFORp_stream_execution(stream) result(execution_policy) bind(c, name="zforp_stream_execution") implicit none type(zFORp_stream), intent(in) :: stream integer :: execution_policy execution_policy = zfp_stream_execution(stream%object) end function zFORp_stream_execution function zFORp_stream_omp_threads(stream) result(thread_count) bind(c, name="zforp_stream_omp_threads") implicit none type(zFORp_stream), intent(in) :: stream integer :: thread_count thread_count = zfp_stream_omp_threads(stream%object) end function zFORp_stream_omp_threads function zFORp_stream_omp_chunk_size(stream) result(chunk_size_blocks) bind(c, name="zforp_stream_omp_chunk_size") implicit none type(zFORp_stream), intent(in) :: stream integer (kind=8) :: chunk_size_blocks chunk_size_blocks = zfp_stream_omp_chunk_size(stream%object) end function zFORp_stream_omp_chunk_size function zFORp_stream_set_execution(stream, execution_policy) result(is_success) bind(c, name="zforp_stream_set_execution") implicit none type(zFORp_stream), intent(in) :: stream integer, intent(in) :: execution_policy integer :: is_success is_success = zfp_stream_set_execution(stream%object, int(execution_policy, c_int)) end function zFORp_stream_set_execution function zFORp_stream_set_omp_threads(stream, thread_count) result(is_success) bind(c, name="zforp_stream_set_omp_threads") implicit none type(zFORp_stream), intent(in) :: stream integer, intent(in) :: thread_count integer :: is_success is_success = zfp_stream_set_omp_threads(stream%object, int(thread_count, c_int)) end function zFORp_stream_set_omp_threads function zFORp_stream_set_omp_chunk_size(stream, chunk_size) result(is_success) & bind(c, name="zforp_stream_set_omp_chunk_size") implicit none type(zFORp_stream), intent(in) :: stream integer, intent(in) :: chunk_size integer :: is_success is_success = zfp_stream_set_omp_chunk_size(stream%object, int(chunk_size, c_int)) end function zFORp_stream_set_omp_chunk_size ! TODO: high-level API: compression mode and parameter settings ! zfp_config_none ! zfp_config_rate ! zfp_config_precision ! zfp_config_accuracy ! zfp_config_reversible ! zfp_config_expert ! high-level API: zfp_field functions function zFORp_field_alloc() result(field) bind(c, name="zforp_field_alloc") implicit none type(zFORp_field) :: field field%object = zfp_field_alloc() end function zFORp_field_alloc function zFORp_field_1d(uncompressed_ptr, scalar_type, nx) result(field) bind(c, name="zforp_field_1d") implicit none type(c_ptr), intent(in) :: uncompressed_ptr integer, intent(in) :: scalar_type, nx type(zFORp_field) :: field field%object = zfp_field_1d(uncompressed_ptr, int(scalar_type, c_int), & int(nx, c_size_t)) end function zFORp_field_1d function zFORp_field_2d(uncompressed_ptr, scalar_type, nx, ny) result(field) bind(c, name="zforp_field_2d") implicit none type(c_ptr), intent(in) :: uncompressed_ptr integer, intent(in) :: scalar_type, nx, ny type(zFORp_field) :: field field%object = zfp_field_2d(uncompressed_ptr, int(scalar_type, c_int), & int(nx, c_size_t), int(ny, c_size_t)) end function zFORp_field_2d function zFORp_field_3d(uncompressed_ptr, scalar_type, nx, ny, nz) result(field) bind(c, name="zforp_field_3d") implicit none type(c_ptr), intent(in) :: uncompressed_ptr integer, intent(in) :: scalar_type, nx, ny, nz type(zFORp_field) :: field field%object = zfp_field_3d(uncompressed_ptr, int(scalar_type, c_int), & int(nx, c_size_t), int(ny, c_size_t), & int(nz, c_size_t)) end function zFORp_field_3d function zFORp_field_4d(uncompressed_ptr, scalar_type, nx, ny, nz, nw) result(field) bind(c, name="zforp_field_4d") implicit none type(c_ptr), intent(in) :: uncompressed_ptr integer, intent(in) :: scalar_type, nx, ny, nz, nw type(zFORp_field) :: field field%object = zfp_field_4d(uncompressed_ptr, int(scalar_type, c_int), & int(nx, c_size_t), int(ny, c_size_t), & int(nz, c_size_t), int(nw, c_size_t)) end function zFORp_field_4d subroutine zFORp_field_free(field) bind(c, name="zforp_field_free") type(zFORp_field), intent(inout) :: field call zfp_field_free(field%object) field%object = c_null_ptr end subroutine zFORp_field_free function zFORp_field_pointer(field) result(arr_ptr) bind(c, name="zforp_field_pointer") implicit none type(zFORp_field), intent(in) :: field type(c_ptr) :: arr_ptr arr_ptr = zfp_field_pointer(field%object) end function zFORp_field_pointer function zFORp_field_begin(field) result(begin_ptr) bind(c, name="zforp_field_begin") implicit none type(zFORp_field), intent(in) :: field type(c_ptr) :: begin_ptr begin_ptr = zfp_field_begin(field%object) end function zFORp_field_begin function zFORp_field_type(field) result(scalar_type) bind(c, name="zforp_field_type") implicit none type(zFORp_field), intent(in) :: field integer :: scalar_type scalar_type = zfp_field_type(field%object) end function zFORp_field_type function zFORp_field_precision(field) result(prec) bind(c, name="zforp_field_precision") implicit none type(zFORp_field), intent(in) :: field integer :: prec prec = zfp_field_precision(field%object) end function zFORp_field_precision function zFORp_field_dimensionality(field) result(dims) bind(c, name="zforp_field_dimensionality") implicit none type(zFORp_field), intent(in) :: field integer :: dims dims = zfp_field_dimensionality(field%object) end function zFORp_field_dimensionality function zFORp_field_size(field, size_arr) result(total_size) bind(c, name="zforp_field_size") implicit none type(zFORp_field), intent(in) :: field integer, dimension(4), target, intent(inout) :: size_arr integer (kind=8) :: total_size total_size = zfp_field_size(field%object, c_loc(size_arr)) end function zFORp_field_size function zFORp_field_size_bytes(field) result(byte_size) bind(c, name="zforp_field_size_bytes") implicit none type(zFORp_field), intent(in) :: field integer (kind=8) :: byte_size byte_size = zfp_field_size_bytes(field%object) end function zFORp_field_size_bytes function zFORp_field_blocks(field) result(blocks) bind(c, name="zforp_field_blocks") implicit none type(zFORp_field), intent(in) :: field integer (kind=8) :: blocks blocks = zfp_field_blocks(field%object) end function zFORp_field_blocks function zFORp_field_stride(field, stride_arr) result(is_strided) bind(c, name="zforp_field_stride") implicit none type(zFORp_field), intent(in) :: field integer, dimension(4), target, intent(inout) :: stride_arr integer :: is_strided is_strided = zfp_field_stride(field%object, c_loc(stride_arr)) end function zFORp_field_stride function zFORp_field_is_contiguous(field) result(is_contiguous) bind(c, name="zforp_field_is_contiguous") implicit none type(zFORp_field), intent(in) :: field integer :: is_contiguous is_contiguous = zfp_field_is_contiguous(field%object) end function zFORp_field_is_contiguous function zFORp_field_metadata(field) result(encoded_metadata) bind(c, name="zforp_field_metadata") implicit none type(zFORp_field), intent(in) :: field integer (kind=8) :: encoded_metadata encoded_metadata = zfp_field_metadata(field%object) end function zFORp_field_metadata subroutine zFORp_field_set_pointer(field, arr_ptr) bind(c, name="zforp_field_set_pointer") type(zFORp_field), intent(in) :: field type(c_ptr), intent(in) :: arr_ptr call zfp_field_set_pointer(field%object, arr_ptr) end subroutine zFORp_field_set_pointer function zFORp_field_set_type(field, scalar_type) result(scalar_type_result) bind(c, name="zforp_field_set_type") implicit none type(zFORp_field), intent(in) :: field integer, intent(in) :: scalar_type integer :: scalar_type_result scalar_type_result = zfp_field_set_type(field%object, int(scalar_type, c_int)) end function zFORp_field_set_type subroutine zFORp_field_set_size_1d(field, nx) bind(c, name="zforp_field_set_size_1d") type(zFORp_field), intent(in) :: field integer, intent(in) :: nx call zfp_field_set_size_1d(field%object, int(nx, c_size_t)) end subroutine zFORp_field_set_size_1d subroutine zFORp_field_set_size_2d(field, nx, ny) bind(c, name="zforp_field_set_size_2d") type(zFORp_field), intent(in) :: field integer, intent(in) :: nx, ny call zfp_field_set_size_2d(field%object, int(nx, c_size_t), int(ny, c_size_t)) end subroutine zFORp_field_set_size_2d subroutine zFORp_field_set_size_3d(field, nx, ny, nz) bind(c, name="zforp_field_set_size_3d") type(zFORp_field), intent(in) :: field integer, intent(in) :: nx, ny, nz call zfp_field_set_size_3d(field%object, int(nx, c_size_t), int(ny, c_size_t), int(nz, c_size_t)) end subroutine zFORp_field_set_size_3d subroutine zFORp_field_set_size_4d(field, nx, ny, nz, nw) bind(c, name="zforp_field_set_size_4d") type(zFORp_field), intent(in) :: field integer, intent(in) :: nx, ny, nz, nw call zfp_field_set_size_4d(field%object, int(nx, c_size_t), int(ny, c_size_t), int(nz, c_size_t), int(nw, c_size_t)) end subroutine zFORp_field_set_size_4d subroutine zFORp_field_set_stride_1d(field, sx) bind(c, name="zforp_field_set_stride_1d") type(zFORp_field), intent(in) :: field integer, intent(in) :: sx call zfp_field_set_stride_1d(field%object, int(sx, c_ptrdiff_t)) end subroutine zFORp_field_set_stride_1d subroutine zFORp_field_set_stride_2d(field, sx, sy) bind(c, name="zforp_field_set_stride_2d") type(zFORp_field), intent(in) :: field integer, intent(in) :: sx, sy call zfp_field_set_stride_2d(field%object, int(sx, c_ptrdiff_t), int(sy, c_ptrdiff_t)) end subroutine zFORp_field_set_stride_2d subroutine zFORp_field_set_stride_3d(field, sx, sy, sz) bind(c, name="zforp_field_set_stride_3d") type(zFORp_field), intent(in) :: field integer, intent(in) :: sx, sy, sz call zfp_field_set_stride_3d(field%object, int(sx, c_ptrdiff_t), int(sy, c_ptrdiff_t), int(sz, c_ptrdiff_t)) end subroutine zFORp_field_set_stride_3d subroutine zFORp_field_set_stride_4d(field, sx, sy, sz, sw) bind(c, name="zforp_field_set_stride_4d") type(zFORp_field), intent(in) :: field integer, intent(in) :: sx, sy, sz, sw call zfp_field_set_stride_4d(field%object, int(sx, c_ptrdiff_t), int(sy, c_ptrdiff_t), & int(sz, c_ptrdiff_t), int(sw, c_ptrdiff_t)) end subroutine zFORp_field_set_stride_4d function zFORp_field_set_metadata(field, encoded_metadata) result(is_success) bind(c, name="zforp_field_set_metadata") implicit none type(zFORp_field), intent(in) :: field integer (kind=8), intent(in) :: encoded_metadata integer :: is_success is_success = zfp_field_set_metadata(field%object, int(encoded_metadata, c_int64_t)) end function zFORp_field_set_metadata ! high-level API: compression and decompression function zFORp_compress(stream, field) result(bitstream_offset_bytes) bind(c, name="zforp_compress") implicit none type(zFORp_stream), intent(in) :: stream type(zFORp_field), intent(in) :: field integer (kind=8) :: bitstream_offset_bytes bitstream_offset_bytes = zfp_compress(stream%object, field%object) end function zFORp_compress function zFORp_decompress(stream, field) result(bitstream_offset_bytes) bind(c, name="zforp_decompress") implicit none type(zFORp_stream), intent(in) :: stream type(zFORp_field), intent(in) :: field integer (kind=8) :: bitstream_offset_bytes bitstream_offset_bytes = zfp_decompress(stream%object, field%object) end function zFORp_decompress function zFORp_write_header(stream, field, mask) result(num_bits_written) bind(c, name="zforp_write_header") implicit none type(zFORp_stream), intent(in) :: stream type(zFORp_field), intent(in) :: field integer, intent(in) :: mask integer (kind=8) :: num_bits_written num_bits_written = zfp_write_header(stream%object, field%object, int(mask, c_int)) end function zFORp_write_header function zFORp_read_header(stream, field, mask) result(num_bits_read) bind(c, name="zforp_read_header") implicit none type(zFORp_stream), intent(in) :: stream type(zFORp_field), intent(in) :: field integer, intent(in) :: mask integer (kind=8) :: num_bits_read num_bits_read = zfp_read_header(stream%object, field%object, int(mask, c_int)) end function zFORp_read_header end module zfp zfp-1.0.1/include/000077500000000000000000000000001453723256400137465ustar00rootroot00000000000000zfp-1.0.1/include/zfp.h000066400000000000000000001043271453723256400147250ustar00rootroot00000000000000/* ** Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC and ** other zfp project contributors. See the top-level LICENSE file for details. ** SPDX-License-Identifier: BSD-3-Clause */ #ifndef ZFP_H #define ZFP_H #include "zfp/bitstream.h" #include "zfp/version.h" #include "zfp/internal/zfp/system.h" #include "zfp/internal/zfp/types.h" /* macros ------------------------------------------------------------------ */ /* default compression parameters */ #define ZFP_MIN_BITS 1 /* minimum number of bits per block */ #define ZFP_MAX_BITS 16658 /* maximum number of bits per block */ #define ZFP_MAX_PREC 64 /* maximum precision supported */ #define ZFP_MIN_EXP -1074 /* minimum floating-point base-2 exponent */ /* header masks (enable via bitwise or; reader must use same mask) */ #define ZFP_HEADER_NONE 0x0u /* no header */ #define ZFP_HEADER_MAGIC 0x1u /* embed 64-bit magic */ #define ZFP_HEADER_META 0x2u /* embed 52-bit field metadata */ #define ZFP_HEADER_MODE 0x4u /* embed 12- or 64-bit compression mode */ #define ZFP_HEADER_FULL 0x7u /* embed all of the above */ /* bit masks for specifying storage class */ #define ZFP_DATA_UNUSED 0x01u /* allocated but unused storage */ #define ZFP_DATA_PADDING 0x02u /* padding for alignment purposes */ #define ZFP_DATA_META 0x04u /* class members and other fixed-size storage */ #define ZFP_DATA_MISC 0x08u /* miscellaneous uncategorized storage */ #define ZFP_DATA_PAYLOAD 0x10u /* compressed data */ #define ZFP_DATA_INDEX 0x20u /* variable-rate block index information */ #define ZFP_DATA_CACHE 0x40u /* uncompressed cached data */ #define ZFP_DATA_HEADER 0x80u /* header information */ #define ZFP_DATA_ALL 0xffu /* all storage */ /* field metadata indeterminate state and error code */ #define ZFP_META_NULL (UINT64C(-1)) /* number of bits per header entry */ #define ZFP_MAGIC_BITS 32 /* number of magic word bits */ #define ZFP_META_BITS 52 /* number of field metadata bits */ #define ZFP_MODE_SHORT_BITS 12 /* number of mode bits in short format */ #define ZFP_MODE_LONG_BITS 64 /* number of mode bits in long format */ #define ZFP_HEADER_MAX_BITS 148 /* max number of header bits */ #define ZFP_MODE_SHORT_MAX ((1u << ZFP_MODE_SHORT_BITS) - 2) /* rounding mode for reducing bias; see build option ZFP_ROUNDING_MODE */ #define ZFP_ROUND_FIRST (-1) /* round during compression */ #define ZFP_ROUND_NEVER 0 /* never round */ #define ZFP_ROUND_LAST 1 /* round during decompression */ /* types ------------------------------------------------------------------- */ /* Boolean constants */ enum { zfp_false = 0, /* false */ zfp_true = !zfp_false /* true */ }; typedef int zfp_bool; /* Boolean type */ /* execution policy */ typedef enum { zfp_exec_serial = 0, /* serial execution (default) */ zfp_exec_omp = 1, /* OpenMP multi-threaded execution */ zfp_exec_cuda = 2 /* CUDA parallel execution */ } zfp_exec_policy; /* OpenMP execution parameters */ typedef struct { uint threads; /* number of requested threads */ uint chunk_size; /* number of blocks per chunk (1D only) */ } zfp_exec_params_omp; typedef struct { zfp_exec_policy policy; /* execution policy (serial, omp, ...) */ void* params; /* execution parameters */ } zfp_execution; /* compressed stream; use accessors to get/set members */ typedef struct { uint minbits; /* minimum number of bits to store per block */ uint maxbits; /* maximum number of bits to store per block */ uint maxprec; /* maximum number of bit planes to store */ int minexp; /* minimum floating point bit plane number to store */ bitstream* stream; /* compressed bit stream */ zfp_execution exec; /* execution policy and parameters */ } zfp_stream; /* compression mode */ typedef enum { zfp_mode_null = 0, /* an invalid configuration of the 4 params */ zfp_mode_expert = 1, /* expert mode (4 params set manually) */ zfp_mode_fixed_rate = 2, /* fixed rate mode */ zfp_mode_fixed_precision = 3, /* fixed precision mode */ zfp_mode_fixed_accuracy = 4, /* fixed accuracy mode */ zfp_mode_reversible = 5 /* reversible (lossless) mode */ } zfp_mode; /* compression mode and parameter settings */ typedef struct { zfp_mode mode; /* compression mode */ union { double rate; /* compressed bits/value (negative for word alignment) */ uint precision; /* uncompressed bits/value */ double tolerance; /* absolute error tolerance */ struct { uint minbits; /* min number of compressed bits/block */ uint maxbits; /* max number of compressed bits/block */ uint maxprec; /* max number of uncompressed bits/value */ int minexp; /* min floating point bit plane number to store */ } expert; /* expert mode arguments */ } arg; /* arguments corresponding to compression mode */ } zfp_config; /* scalar type */ typedef enum { zfp_type_none = 0, /* unspecified type */ zfp_type_int32 = 1, /* 32-bit signed integer */ zfp_type_int64 = 2, /* 64-bit signed integer */ zfp_type_float = 3, /* single precision floating point */ zfp_type_double = 4 /* double precision floating point */ } zfp_type; /* uncompressed array; use accessors to get/set members */ typedef struct { zfp_type type; /* scalar type (e.g. int32, double) */ size_t nx, ny, nz, nw; /* sizes (zero for unused dimensions) */ ptrdiff_t sx, sy, sz, sw; /* strides (zero for contiguous array a[nw][nz][ny][nx]) */ void* data; /* pointer to array data */ } zfp_field; #ifdef __cplusplus extern "C" { #endif /* public data ------------------------------------------------------------- */ extern_ const uint zfp_codec_version; /* codec version ZFP_CODEC */ extern_ const uint zfp_library_version; /* library version ZFP_VERSION */ extern_ const char* const zfp_version_string; /* verbose version string */ /* high-level API: utility functions --------------------------------------- */ size_t /* byte size of scalar type */ zfp_type_size( zfp_type type /* scalar type */ ); /* high-level API: compressed stream construction/destruction -------------- */ /* open compressed stream and associate with bit stream */ zfp_stream* /* allocated compressed stream */ zfp_stream_open( bitstream* stream /* bit stream to read from and write to (may be NULL) */ ); /* close and deallocate compressed stream (does not affect bit stream) */ void zfp_stream_close( zfp_stream* stream /* compressed stream */ ); /* high-level API: compressed stream inspectors ---------------------------- */ /* bit stream associated with compressed stream */ bitstream* /* bit stream associated with compressed stream */ zfp_stream_bit_stream( const zfp_stream* stream /* compressed stream */ ); /* enumerated compression mode */ zfp_mode /* compression mode or zfp_mode_null if not set */ zfp_stream_compression_mode( const zfp_stream* stream /* compressed stream */ ); /* rate in compressed bits/scalar (when in fixed-rate mode) */ double /* rate or zero upon failure */ zfp_stream_rate( const zfp_stream* stream, /* compressed stream */ uint dims /* array dimensionality (1, 2, 3, or 4) */ ); /* precision in uncompressed bits/scalar (when in fixed-precision mode) */ uint /* precision or zero upon failure */ zfp_stream_precision( const zfp_stream* stream /* compressed stream */ ); /* accuracy as absolute error tolerance (when in fixed-accuracy mode) */ double /* tolerance or zero upon failure */ zfp_stream_accuracy( const zfp_stream* stream /* compressed stream */ ); /* get all compression parameters in a compact representation */ uint64 /* 12- or 64-bit encoding of parameters */ zfp_stream_mode( const zfp_stream* stream /* compressed stream */ ); /* get all compression parameters (pointers may be NULL) */ void zfp_stream_params( const zfp_stream* stream, /* compressed stream */ uint* minbits, /* minimum number of bits per 4^d block */ uint* maxbits, /* maximum number of bits per 4^d block */ uint* maxprec, /* maximum precision (# bit planes coded) */ int* minexp /* minimum base-2 exponent; error <= 2^minexp */ ); /* byte size of sequentially compressed stream (call after compression) */ size_t /* actual number of bytes of compressed storage */ zfp_stream_compressed_size( const zfp_stream* stream /* compressed stream */ ); /* conservative estimate of compressed size in bytes */ size_t /* maximum number of bytes of compressed storage */ zfp_stream_maximum_size( const zfp_stream* stream, /* compressed stream */ const zfp_field* field /* array to compress */ ); /* high-level API: initialization of compressed stream parameters ---------- */ /* rewind bit stream to beginning for compression or decompression */ void zfp_stream_rewind( zfp_stream* stream /* compressed bit stream */ ); /* associate bit stream with compressed stream */ void zfp_stream_set_bit_stream( zfp_stream* stream, /* compressed stream */ bitstream* bs /* bit stream to read from and write to */ ); /* enable reversible (lossless) compression */ void zfp_stream_set_reversible( zfp_stream* stream /* compressed stream */ ); /* set size in compressed bits/scalar (fixed-rate mode) */ double /* actual rate in compressed bits/scalar */ zfp_stream_set_rate( zfp_stream* stream, /* compressed stream */ double rate, /* desired rate in compressed bits/scalar */ zfp_type type, /* scalar type to compress */ uint dims, /* array dimensionality (1, 2, 3, or 4) */ zfp_bool align /* word-aligned blocks, e.g., for write random access */ ); /* set precision in uncompressed bits/scalar (fixed-precision mode) */ uint /* actual precision */ zfp_stream_set_precision( zfp_stream* stream, /* compressed stream */ uint precision /* desired precision in uncompressed bits/scalar */ ); /* set accuracy as absolute error tolerance (fixed-accuracy mode) */ double /* actual error tolerance */ zfp_stream_set_accuracy( zfp_stream* stream, /* compressed stream */ double tolerance /* desired error tolerance */ ); /* set parameters from compact encoding; leaves stream intact on failure */ zfp_mode /* compression mode or zfp_mode_null upon failure */ zfp_stream_set_mode( zfp_stream* stream, /* compressed stream */ uint64 mode /* 12- or 64-bit encoding of parameters */ ); /* set all parameters (expert mode); leaves stream intact on failure */ zfp_bool /* true upon success */ zfp_stream_set_params( zfp_stream* stream, /* compressed stream */ uint minbits, /* minimum number of bits per 4^d block */ uint maxbits, /* maximum number of bits per 4^d block */ uint maxprec, /* maximum precision (# bit planes coded) */ int minexp /* minimum base-2 exponent; error <= 2^minexp */ ); /* high-level API: execution policy ---------------------------------------- */ /* current execution policy */ zfp_exec_policy zfp_stream_execution( const zfp_stream* stream /* compressed stream */ ); /* number of OpenMP threads to use */ uint /* number of threads (0 for default) */ zfp_stream_omp_threads( const zfp_stream* stream /* compressed stream */ ); /* number of blocks per OpenMP chunk (1D only) */ uint /* number of blocks per chunk (0 for default) */ zfp_stream_omp_chunk_size( const zfp_stream* stream /* compressed stream */ ); /* set execution policy */ zfp_bool /* true upon success */ zfp_stream_set_execution( zfp_stream* stream, /* compressed stream */ zfp_exec_policy policy /* execution policy */ ); /* set OpenMP execution policy and number of threads */ zfp_bool /* true upon success */ zfp_stream_set_omp_threads( zfp_stream* stream, /* compressed stream */ uint threads /* number of OpenMP threads to use (0 for default) */ ); /* set OpenMP execution policy and number of blocks per chunk (1D only) */ zfp_bool /* true upon success */ zfp_stream_set_omp_chunk_size( zfp_stream* stream, /* compressed stream */ uint chunk_size /* number of blocks per chunk (0 for default) */ ); /* high-level API: compression mode and parameter settings ----------------- */ /* unspecified configuration */ zfp_config /* compression mode and parameter settings */ zfp_config_none(void); /* fixed-rate configuration */ zfp_config /* compression mode and parameter settings */ zfp_config_rate( double rate, /* desired rate in compressed bits/scalar */ zfp_bool align /* word-aligned blocks, e.g., for write random access */ ); /* fixed-precision configuration */ zfp_config /* compression mode and parameter settings */ zfp_config_precision( uint precision /* desired precision in uncompressed bits/scalar */ ); /* fixed-accuracy configuration */ zfp_config /* compression mode and parameter settings */ zfp_config_accuracy( double tolerance /* desired error tolerance */ ); /* reversible (lossless) configuration */ zfp_config /* compression mode and parameter settings */ zfp_config_reversible(void); /* expert configuration */ zfp_config /* compression mode and parameter settings */ zfp_config_expert( uint minbits, /* minimum number of bits per 4^d block */ uint maxbits, /* maximum number of bits per 4^d block */ uint maxprec, /* maximum precision (# bit planes coded) */ int minexp /* minimum base-2 exponent; error <= 2^minexp */ ); /* high-level API: uncompressed array construction/destruction ------------- */ /* allocate field struct */ zfp_field* /* pointer to default initialized field */ zfp_field_alloc(void); /* allocate metadata for 1D field f[nx] */ zfp_field* /* allocated field metadata */ zfp_field_1d( void* pointer, /* pointer to uncompressed scalars (may be NULL) */ zfp_type type, /* scalar type */ size_t nx /* number of scalars */ ); /* allocate metadata for 2D field f[ny][nx] */ zfp_field* /* allocated field metadata */ zfp_field_2d( void* pointer, /* pointer to uncompressed scalars (may be NULL) */ zfp_type type, /* scalar type */ size_t nx, /* number of scalars in x dimension */ size_t ny /* number of scalars in y dimension */ ); /* allocate metadata for 3D field f[nz][ny][nx] */ zfp_field* /* allocated field metadata */ zfp_field_3d( void* pointer, /* pointer to uncompressed scalars (may be NULL) */ zfp_type type, /* scalar type */ size_t nx, /* number of scalars in x dimension */ size_t ny, /* number of scalars in y dimension */ size_t nz /* number of scalars in z dimension */ ); /* allocate metadata for 4D field f[nw][nz][ny][nx] */ zfp_field* /* allocated field metadata */ zfp_field_4d( void* pointer, /* pointer to uncompressed scalars (may be NULL) */ zfp_type type, /* scalar type */ size_t nx, /* number of scalars in x dimension */ size_t ny, /* number of scalars in y dimension */ size_t nz, /* number of scalars in z dimension */ size_t nw /* number of scalars in w dimension */ ); /* deallocate field metadata */ void zfp_field_free( zfp_field* field /* field metadata */ ); /* high-level API: uncompressed array inspectors --------------------------- */ /* pointer to first scalar in field */ void* /* array pointer */ zfp_field_pointer( const zfp_field* field /* field metadata */ ); /* pointer to lowest memory address spanned by field */ void* zfp_field_begin( const zfp_field* field /* field metadata */ ); /* field scalar type */ zfp_type /* scalar type */ zfp_field_type( const zfp_field* field /* field metadata */ ); /* precision of field scalar type */ uint /* scalar type precision in number of bits */ zfp_field_precision( const zfp_field* field /* field metadata */ ); /* field dimensionality (1, 2, 3, or 4) */ uint /* number of dimensions */ zfp_field_dimensionality( const zfp_field* field /* field metadata */ ); /* field size in number of scalars */ size_t /* total number of scalars */ zfp_field_size( const zfp_field* field, /* field metadata */ size_t* size /* number of scalars per dimension (may be NULL) */ ); /* number of bytes spanned by field data including gaps (if any) */ size_t zfp_field_size_bytes( const zfp_field* field /* field metadata */ ); /* field size in number of blocks */ size_t /* total number of blocks */ zfp_field_blocks( const zfp_field* field /* field metadata */ ); /* field strides per dimension */ zfp_bool /* true if array is not contiguous */ zfp_field_stride( const zfp_field* field, /* field metadata */ ptrdiff_t* stride /* stride in scalars per dimension (may be NULL) */ ); /* field contiguity test */ zfp_bool /* true if field layout is contiguous */ zfp_field_is_contiguous( const zfp_field* field /* field metadata */ ); /* field scalar type and dimensions */ uint64 /* compact 52-bit encoding of metadata */ zfp_field_metadata( const zfp_field* field /* field metadata */ ); /* high-level API: uncompressed array specification ------------------------ */ /* set pointer to first scalar in field */ void zfp_field_set_pointer( zfp_field* field, /* field metadata */ void* pointer /* pointer to first scalar */ ); /* set field scalar type */ zfp_type /* actual scalar type */ zfp_field_set_type( zfp_field* field, /* field metadata */ zfp_type type /* desired scalar type */ ); /* set 1D field size */ void zfp_field_set_size_1d( zfp_field* field, /* field metadata */ size_t nx /* number of scalars */ ); /* set 2D field size */ void zfp_field_set_size_2d( zfp_field* field, /* field metadata */ size_t nx, /* number of scalars in x dimension */ size_t ny /* number of scalars in y dimension */ ); /* set 3D field size */ void zfp_field_set_size_3d( zfp_field* field, /* field metadata */ size_t nx, /* number of scalars in x dimension */ size_t ny, /* number of scalars in y dimension */ size_t nz /* number of scalars in z dimension */ ); /* set 4D field size */ void zfp_field_set_size_4d( zfp_field* field, /* field metadata */ size_t nx, /* number of scalars in x dimension */ size_t ny, /* number of scalars in y dimension */ size_t nz, /* number of scalars in z dimension */ size_t nw /* number of scalars in w dimension */ ); /* set 1D field stride in number of scalars */ void zfp_field_set_stride_1d( zfp_field* field, /* field metadata */ ptrdiff_t sx /* stride in number of scalars: &f[1] - &f[0] */ ); /* set 2D field strides in number of scalars */ void zfp_field_set_stride_2d( zfp_field* field, /* field metadata */ ptrdiff_t sx, /* stride in x dimension: &f[0][1] - &f[0][0] */ ptrdiff_t sy /* stride in y dimension: &f[1][0] - &f[0][0] */ ); /* set 3D field strides in number of scalars */ void zfp_field_set_stride_3d( zfp_field* field, /* field metadata */ ptrdiff_t sx, /* stride in x dimension: &f[0][0][1] - &f[0][0][0] */ ptrdiff_t sy, /* stride in y dimension: &f[0][1][0] - &f[0][0][0] */ ptrdiff_t sz /* stride in z dimension: &f[1][0][0] - &f[0][0][0] */ ); /* set 4D field strides in number of scalars */ void zfp_field_set_stride_4d( zfp_field* field, /* field metadata */ ptrdiff_t sx, /* stride in x dimension: &f[0][0][0][1] - &f[0][0][0][0] */ ptrdiff_t sy, /* stride in y dimension: &f[0][0][1][0] - &f[0][0][0][0] */ ptrdiff_t sz, /* stride in z dimension: &f[0][1][0][0] - &f[0][0][0][0] */ ptrdiff_t sw /* stride in w dimension: &f[1][0][0][0] - &f[0][0][0][0] */ ); /* set field scalar type and dimensions */ zfp_bool /* true upon success */ zfp_field_set_metadata( zfp_field* field, /* field metadata */ uint64 meta /* compact 52-bit encoding of metadata */ ); /* high-level API: compression and decompression --------------------------- */ /* compress entire field (nonzero return value upon success) */ size_t /* cumulative number of bytes of compressed storage */ zfp_compress( zfp_stream* stream, /* compressed stream */ const zfp_field* field /* field metadata */ ); /* decompress entire field (nonzero return value upon success) */ size_t /* cumulative number of bytes of compressed storage */ zfp_decompress( zfp_stream* stream, /* compressed stream */ zfp_field* field /* field metadata */ ); /* write compression parameters and field metadata (optional) */ size_t /* number of bits written or zero upon failure */ zfp_write_header( zfp_stream* stream, /* compressed stream */ const zfp_field* field, /* field metadata */ uint mask /* information to write */ ); /* read compression parameters and field metadata when previously written */ size_t /* number of bits read or zero upon failure */ zfp_read_header( zfp_stream* stream, /* compressed stream */ zfp_field* field, /* field metadata */ uint mask /* information to read */ ); /* low-level API: stream manipulation -------------------------------------- */ /* flush bit stream--must be called after last encode call or between seeks */ size_t zfp_stream_flush( zfp_stream* stream /* compressed bit stream */ ); /* align bit stream on next word boundary (decoding analogy to flush) */ size_t zfp_stream_align( zfp_stream* stream /* compressed bit stream */ ); /* low-level API: encoder -------------------------------------------------- */ /* The functions below all compress either a complete contiguous d-dimensional block of 4^d scalars or a complete or partial block assembled from a strided array. In the latter case, p points to the first scalar; (nx, ny, nz) specify the size of the block, with 1 <= nx, ny, nz <= 4; and (sx, sy, sz) specify the strides, i.e. the number of scalars to advance to get to the next scalar along each dimension. The functions return the number of bits of compressed storage needed for the compressed block. */ /* encode 1D contiguous block of 4 values */ size_t zfp_encode_block_int32_1(zfp_stream* stream, const int32* block); size_t zfp_encode_block_int64_1(zfp_stream* stream, const int64* block); size_t zfp_encode_block_float_1(zfp_stream* stream, const float* block); size_t zfp_encode_block_double_1(zfp_stream* stream, const double* block); /* encode 1D complete or partial block from strided array */ size_t zfp_encode_block_strided_int32_1(zfp_stream* stream, const int32* p, ptrdiff_t sx); size_t zfp_encode_block_strided_int64_1(zfp_stream* stream, const int64* p, ptrdiff_t sx); size_t zfp_encode_block_strided_float_1(zfp_stream* stream, const float* p, ptrdiff_t sx); size_t zfp_encode_block_strided_double_1(zfp_stream* stream, const double* p, ptrdiff_t sx); size_t zfp_encode_partial_block_strided_int32_1(zfp_stream* stream, const int32* p, size_t nx, ptrdiff_t sx); size_t zfp_encode_partial_block_strided_int64_1(zfp_stream* stream, const int64* p, size_t nx, ptrdiff_t sx); size_t zfp_encode_partial_block_strided_float_1(zfp_stream* stream, const float* p, size_t nx, ptrdiff_t sx); size_t zfp_encode_partial_block_strided_double_1(zfp_stream* stream, const double* p, size_t nx, ptrdiff_t sx); /* encode 2D contiguous block of 4x4 values */ size_t zfp_encode_block_int32_2(zfp_stream* stream, const int32* block); size_t zfp_encode_block_int64_2(zfp_stream* stream, const int64* block); size_t zfp_encode_block_float_2(zfp_stream* stream, const float* block); size_t zfp_encode_block_double_2(zfp_stream* stream, const double* block); /* encode 2D complete or partial block from strided array */ size_t zfp_encode_partial_block_strided_int32_2(zfp_stream* stream, const int32* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy); size_t zfp_encode_partial_block_strided_int64_2(zfp_stream* stream, const int64* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy); size_t zfp_encode_partial_block_strided_float_2(zfp_stream* stream, const float* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy); size_t zfp_encode_partial_block_strided_double_2(zfp_stream* stream, const double* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy); size_t zfp_encode_block_strided_int32_2(zfp_stream* stream, const int32* p, ptrdiff_t sx, ptrdiff_t sy); size_t zfp_encode_block_strided_int64_2(zfp_stream* stream, const int64* p, ptrdiff_t sx, ptrdiff_t sy); size_t zfp_encode_block_strided_float_2(zfp_stream* stream, const float* p, ptrdiff_t sx, ptrdiff_t sy); size_t zfp_encode_block_strided_double_2(zfp_stream* stream, const double* p, ptrdiff_t sx, ptrdiff_t sy); /* encode 3D contiguous block of 4x4x4 values */ size_t zfp_encode_block_int32_3(zfp_stream* stream, const int32* block); size_t zfp_encode_block_int64_3(zfp_stream* stream, const int64* block); size_t zfp_encode_block_float_3(zfp_stream* stream, const float* block); size_t zfp_encode_block_double_3(zfp_stream* stream, const double* block); /* encode 3D complete or partial block from strided array */ size_t zfp_encode_block_strided_int32_3(zfp_stream* stream, const int32* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); size_t zfp_encode_block_strided_int64_3(zfp_stream* stream, const int64* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); size_t zfp_encode_block_strided_float_3(zfp_stream* stream, const float* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); size_t zfp_encode_block_strided_double_3(zfp_stream* stream, const double* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); size_t zfp_encode_partial_block_strided_int32_3(zfp_stream* stream, const int32* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); size_t zfp_encode_partial_block_strided_int64_3(zfp_stream* stream, const int64* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); size_t zfp_encode_partial_block_strided_float_3(zfp_stream* stream, const float* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); size_t zfp_encode_partial_block_strided_double_3(zfp_stream* stream, const double* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); /* encode 4D contiguous block of 4x4x4x4 values */ size_t zfp_encode_block_int32_4(zfp_stream* stream, const int32* block); size_t zfp_encode_block_int64_4(zfp_stream* stream, const int64* block); size_t zfp_encode_block_float_4(zfp_stream* stream, const float* block); size_t zfp_encode_block_double_4(zfp_stream* stream, const double* block); /* encode 4D complete or partial block from strided array */ size_t zfp_encode_block_strided_int32_4(zfp_stream* stream, const int32* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); size_t zfp_encode_block_strided_int64_4(zfp_stream* stream, const int64* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); size_t zfp_encode_block_strided_float_4(zfp_stream* stream, const float* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); size_t zfp_encode_block_strided_double_4(zfp_stream* stream, const double* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); size_t zfp_encode_partial_block_strided_int32_4(zfp_stream* stream, const int32* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); size_t zfp_encode_partial_block_strided_int64_4(zfp_stream* stream, const int64* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); size_t zfp_encode_partial_block_strided_float_4(zfp_stream* stream, const float* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); size_t zfp_encode_partial_block_strided_double_4(zfp_stream* stream, const double* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); /* low-level API: decoder -------------------------------------------------- */ /* Each function below decompresses a single block and returns the number of bits of compressed storage consumed. See corresponding encoder functions above for further details. */ /* decode 1D contiguous block of 4 values */ size_t zfp_decode_block_int32_1(zfp_stream* stream, int32* block); size_t zfp_decode_block_int64_1(zfp_stream* stream, int64* block); size_t zfp_decode_block_float_1(zfp_stream* stream, float* block); size_t zfp_decode_block_double_1(zfp_stream* stream, double* block); /* decode 1D complete or partial block from strided array */ size_t zfp_decode_block_strided_int32_1(zfp_stream* stream, int32* p, ptrdiff_t sx); size_t zfp_decode_block_strided_int64_1(zfp_stream* stream, int64* p, ptrdiff_t sx); size_t zfp_decode_block_strided_float_1(zfp_stream* stream, float* p, ptrdiff_t sx); size_t zfp_decode_block_strided_double_1(zfp_stream* stream, double* p, ptrdiff_t sx); size_t zfp_decode_partial_block_strided_int32_1(zfp_stream* stream, int32* p, size_t nx, ptrdiff_t sx); size_t zfp_decode_partial_block_strided_int64_1(zfp_stream* stream, int64* p, size_t nx, ptrdiff_t sx); size_t zfp_decode_partial_block_strided_float_1(zfp_stream* stream, float* p, size_t nx, ptrdiff_t sx); size_t zfp_decode_partial_block_strided_double_1(zfp_stream* stream, double* p, size_t nx, ptrdiff_t sx); /* decode 2D contiguous block of 4x4 values */ size_t zfp_decode_block_int32_2(zfp_stream* stream, int32* block); size_t zfp_decode_block_int64_2(zfp_stream* stream, int64* block); size_t zfp_decode_block_float_2(zfp_stream* stream, float* block); size_t zfp_decode_block_double_2(zfp_stream* stream, double* block); /* decode 2D complete or partial block from strided array */ size_t zfp_decode_block_strided_int32_2(zfp_stream* stream, int32* p, ptrdiff_t sx, ptrdiff_t sy); size_t zfp_decode_block_strided_int64_2(zfp_stream* stream, int64* p, ptrdiff_t sx, ptrdiff_t sy); size_t zfp_decode_block_strided_float_2(zfp_stream* stream, float* p, ptrdiff_t sx, ptrdiff_t sy); size_t zfp_decode_block_strided_double_2(zfp_stream* stream, double* p, ptrdiff_t sx, ptrdiff_t sy); size_t zfp_decode_partial_block_strided_int32_2(zfp_stream* stream, int32* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy); size_t zfp_decode_partial_block_strided_int64_2(zfp_stream* stream, int64* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy); size_t zfp_decode_partial_block_strided_float_2(zfp_stream* stream, float* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy); size_t zfp_decode_partial_block_strided_double_2(zfp_stream* stream, double* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy); /* decode 3D contiguous block of 4x4x4 values */ size_t zfp_decode_block_int32_3(zfp_stream* stream, int32* block); size_t zfp_decode_block_int64_3(zfp_stream* stream, int64* block); size_t zfp_decode_block_float_3(zfp_stream* stream, float* block); size_t zfp_decode_block_double_3(zfp_stream* stream, double* block); /* decode 3D complete or partial block from strided array */ size_t zfp_decode_block_strided_int32_3(zfp_stream* stream, int32* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); size_t zfp_decode_block_strided_int64_3(zfp_stream* stream, int64* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); size_t zfp_decode_block_strided_float_3(zfp_stream* stream, float* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); size_t zfp_decode_block_strided_double_3(zfp_stream* stream, double* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); size_t zfp_decode_partial_block_strided_int32_3(zfp_stream* stream, int32* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); size_t zfp_decode_partial_block_strided_int64_3(zfp_stream* stream, int64* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); size_t zfp_decode_partial_block_strided_float_3(zfp_stream* stream, float* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); size_t zfp_decode_partial_block_strided_double_3(zfp_stream* stream, double* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); /* decode 4D contiguous block of 4x4x4x4 values */ size_t zfp_decode_block_int32_4(zfp_stream* stream, int32* block); size_t zfp_decode_block_int64_4(zfp_stream* stream, int64* block); size_t zfp_decode_block_float_4(zfp_stream* stream, float* block); size_t zfp_decode_block_double_4(zfp_stream* stream, double* block); /* decode 4D complete or partial block from strided array */ size_t zfp_decode_block_strided_int32_4(zfp_stream* stream, int32* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); size_t zfp_decode_block_strided_int64_4(zfp_stream* stream, int64* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); size_t zfp_decode_block_strided_float_4(zfp_stream* stream, float* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); size_t zfp_decode_block_strided_double_4(zfp_stream* stream, double* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); size_t zfp_decode_partial_block_strided_int32_4(zfp_stream* stream, int32* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); size_t zfp_decode_partial_block_strided_int64_4(zfp_stream* stream, int64* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); size_t zfp_decode_partial_block_strided_float_4(zfp_stream* stream, float* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); size_t zfp_decode_partial_block_strided_double_4(zfp_stream* stream, double* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); /* low-level API: utility functions ---------------------------------------- */ /* convert dims-dimensional contiguous block to 32-bit integer type */ void zfp_promote_int8_to_int32(int32* oblock, const int8* iblock, uint dims); void zfp_promote_uint8_to_int32(int32* oblock, const uint8* iblock, uint dims); void zfp_promote_int16_to_int32(int32* oblock, const int16* iblock, uint dims); void zfp_promote_uint16_to_int32(int32* oblock, const uint16* iblock, uint dims); /* convert dims-dimensional contiguous block from 32-bit integer type */ void zfp_demote_int32_to_int8(int8* oblock, const int32* iblock, uint dims); void zfp_demote_int32_to_uint8(uint8* oblock, const int32* iblock, uint dims); void zfp_demote_int32_to_int16(int16* oblock, const int32* iblock, uint dims); void zfp_demote_int32_to_uint16(uint16* oblock, const int32* iblock, uint dims); #ifdef __cplusplus } #endif #endif zfp-1.0.1/include/zfp.hpp000066400000000000000000000275331453723256400152700ustar00rootroot00000000000000#ifndef ZFP_HPP #define ZFP_HPP // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC and // other zfp project contributors. See the top-level LICENSE file for details. // SPDX-License-Identifier: BSD-3-Clause #include "zfp.h" // templated C++ wrappers around libzfp low-level C functions namespace zfp { // encoder declarations ------------------------------------------------------- template inline size_t encode_block(zfp_stream* zfp, const Scalar* block); template inline size_t encode_block_strided(zfp_stream* zfp, const Scalar* p, ptrdiff_t sx); template inline size_t encode_block_strided(zfp_stream* zfp, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy); template inline size_t encode_block_strided(zfp_stream* zfp, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); template inline size_t encode_block_strided(zfp_stream* zfp, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); template inline size_t encode_partial_block_strided(zfp_stream* zfp, const Scalar* p, size_t nx, ptrdiff_t sx); template inline size_t encode_partial_block_strided(zfp_stream* zfp, const Scalar* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy); template inline size_t encode_partial_block_strided(zfp_stream* zfp, const Scalar* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); template inline size_t encode_partial_block_strided(zfp_stream* zfp, const Scalar* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); // encoder specializations ---------------------------------------------------- template<> inline size_t encode_block(zfp_stream* zfp, const float* block) { return zfp_encode_block_float_1(zfp, block); } template<> inline size_t encode_block(zfp_stream* zfp, const float* block) { return zfp_encode_block_float_2(zfp, block); } template<> inline size_t encode_block(zfp_stream* zfp, const float* block) { return zfp_encode_block_float_3(zfp, block); } template<> inline size_t encode_block(zfp_stream* zfp, const float* block) { return zfp_encode_block_float_4(zfp, block); } template<> inline size_t encode_block(zfp_stream* zfp, const double* block) { return zfp_encode_block_double_1(zfp, block); } template<> inline size_t encode_block(zfp_stream* zfp, const double* block) { return zfp_encode_block_double_2(zfp, block); } template<> inline size_t encode_block(zfp_stream* zfp, const double* block) { return zfp_encode_block_double_3(zfp, block); } template<> inline size_t encode_block(zfp_stream* zfp, const double* block) { return zfp_encode_block_double_4(zfp, block); } template <> inline size_t encode_block_strided(zfp_stream* zfp, const float* p, ptrdiff_t sx) { return zfp_encode_block_strided_float_1(zfp, p, sx); } template <> inline size_t encode_block_strided(zfp_stream* zfp, const float* p, ptrdiff_t sx, ptrdiff_t sy) { return zfp_encode_block_strided_float_2(zfp, p, sx, sy); } template <> inline size_t encode_block_strided(zfp_stream* zfp, const float* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { return zfp_encode_block_strided_float_3(zfp, p, sx, sy, sz); } template <> inline size_t encode_block_strided(zfp_stream* zfp, const float* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { return zfp_encode_block_strided_float_4(zfp, p, sx, sy, sz, sw); } template <> inline size_t encode_block_strided(zfp_stream* zfp, const double* p, ptrdiff_t sx) { return zfp_encode_block_strided_double_1(zfp, p, sx); } template <> inline size_t encode_block_strided(zfp_stream* zfp, const double* p, ptrdiff_t sx, ptrdiff_t sy) { return zfp_encode_block_strided_double_2(zfp, p, sx, sy); } template <> inline size_t encode_block_strided(zfp_stream* zfp, const double* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { return zfp_encode_block_strided_double_3(zfp, p, sx, sy, sz); } template <> inline size_t encode_block_strided(zfp_stream* zfp, const double* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { return zfp_encode_block_strided_double_4(zfp, p, sx, sy, sz, sw); } template <> inline size_t encode_partial_block_strided(zfp_stream* zfp, const float* p, size_t nx, ptrdiff_t sx) { return zfp_encode_partial_block_strided_float_1(zfp, p, nx, sx); } template <> inline size_t encode_partial_block_strided(zfp_stream* zfp, const float* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) { return zfp_encode_partial_block_strided_float_2(zfp, p, nx, ny, sx, sy); } template <> inline size_t encode_partial_block_strided(zfp_stream* zfp, const float* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { return zfp_encode_partial_block_strided_float_3(zfp, p, nx, ny, nz, sx, sy, sz); } template <> inline size_t encode_partial_block_strided(zfp_stream* zfp, const float* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { return zfp_encode_partial_block_strided_float_4(zfp, p, nx, ny, nz, nw, sx, sy, sz, sw); } template <> inline size_t encode_partial_block_strided(zfp_stream* zfp, const double* p, size_t nx, ptrdiff_t sx) { return zfp_encode_partial_block_strided_double_1(zfp, p, nx, sx); } template <> inline size_t encode_partial_block_strided(zfp_stream* zfp, const double* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) { return zfp_encode_partial_block_strided_double_2(zfp, p, nx, ny, sx, sy); } template <> inline size_t encode_partial_block_strided(zfp_stream* zfp, const double* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { return zfp_encode_partial_block_strided_double_3(zfp, p, nx, ny, nz, sx, sy, sz); } template <> inline size_t encode_partial_block_strided(zfp_stream* zfp, const double* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { return zfp_encode_partial_block_strided_double_4(zfp, p, nx, ny, nz, nw, sx, sy, sz, sw); } // decoder declarations ------------------------------------------------------- template inline size_t decode_block(zfp_stream* zfp, Scalar* block); template inline size_t decode_block_strided(zfp_stream* zfp, Scalar* p, ptrdiff_t sx); template inline size_t decode_block_strided(zfp_stream* zfp, Scalar* p, ptrdiff_t sx, ptrdiff_t sy); template inline size_t decode_block_strided(zfp_stream* zfp, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); template inline size_t decode_block_strided(zfp_stream* zfp, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); template inline size_t decode_partial_block_strided(zfp_stream* zfp, Scalar* p, size_t nx, ptrdiff_t sx); template inline size_t decode_partial_block_strided(zfp_stream* zfp, Scalar* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy); template inline size_t decode_partial_block_strided(zfp_stream* zfp, Scalar* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz); template inline size_t decode_partial_block_strided(zfp_stream* zfp, Scalar* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw); // decoder specializations ---------------------------------------------------- template<> inline size_t decode_block(zfp_stream* zfp, float* block) { return zfp_decode_block_float_1(zfp, block); } template<> inline size_t decode_block(zfp_stream* zfp, float* block) { return zfp_decode_block_float_2(zfp, block); } template<> inline size_t decode_block(zfp_stream* zfp, float* block) { return zfp_decode_block_float_3(zfp, block); } template<> inline size_t decode_block(zfp_stream* zfp, float* block) { return zfp_decode_block_float_4(zfp, block); } template<> inline size_t decode_block(zfp_stream* zfp, double* block) { return zfp_decode_block_double_1(zfp, block); } template<> inline size_t decode_block(zfp_stream* zfp, double* block) { return zfp_decode_block_double_2(zfp, block); } template<> inline size_t decode_block(zfp_stream* zfp, double* block) { return zfp_decode_block_double_3(zfp, block); } template<> inline size_t decode_block(zfp_stream* zfp, double* block) { return zfp_decode_block_double_4(zfp, block); } template <> inline size_t decode_block_strided(zfp_stream* zfp, float* p, ptrdiff_t sx) { return zfp_decode_block_strided_float_1(zfp, p, sx); } template <> inline size_t decode_block_strided(zfp_stream* zfp, float* p, ptrdiff_t sx, ptrdiff_t sy) { return zfp_decode_block_strided_float_2(zfp, p, sx, sy); } template <> inline size_t decode_block_strided(zfp_stream* zfp, float* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { return zfp_decode_block_strided_float_3(zfp, p, sx, sy, sz); } template <> inline size_t decode_block_strided(zfp_stream* zfp, float* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { return zfp_decode_block_strided_float_4(zfp, p, sx, sy, sz, sw); } template <> inline size_t decode_block_strided(zfp_stream* zfp, double* p, ptrdiff_t sx) { return zfp_decode_block_strided_double_1(zfp, p, sx); } template <> inline size_t decode_block_strided(zfp_stream* zfp, double* p, ptrdiff_t sx, ptrdiff_t sy) { return zfp_decode_block_strided_double_2(zfp, p, sx, sy); } template <> inline size_t decode_block_strided(zfp_stream* zfp, double* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { return zfp_decode_block_strided_double_3(zfp, p, sx, sy, sz); } template <> inline size_t decode_block_strided(zfp_stream* zfp, double* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { return zfp_decode_block_strided_double_4(zfp, p, sx, sy, sz, sw); } template <> inline size_t decode_partial_block_strided(zfp_stream* zfp, float* p, size_t nx, ptrdiff_t sx) { return zfp_decode_partial_block_strided_float_1(zfp, p, nx, sx); } template <> inline size_t decode_partial_block_strided(zfp_stream* zfp, float* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) { return zfp_decode_partial_block_strided_float_2(zfp, p, nx, ny, sx, sy); } template <> inline size_t decode_partial_block_strided(zfp_stream* zfp, float* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { return zfp_decode_partial_block_strided_float_3(zfp, p, nx, ny, nz, sx, sy, sz); } template <> inline size_t decode_partial_block_strided(zfp_stream* zfp, float* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { return zfp_decode_partial_block_strided_float_4(zfp, p, nx, ny, nz, nw, sx, sy, sz, sw); } template <> inline size_t decode_partial_block_strided(zfp_stream* zfp, double* p, size_t nx, ptrdiff_t sx) { return zfp_decode_partial_block_strided_double_1(zfp, p, nx, sx); } template <> inline size_t decode_partial_block_strided(zfp_stream* zfp, double* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) { return zfp_decode_partial_block_strided_double_2(zfp, p, nx, ny, sx, sy); } template <> inline size_t decode_partial_block_strided(zfp_stream* zfp, double* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { return zfp_decode_partial_block_strided_double_3(zfp, p, nx, ny, nz, sx, sy, sz); } template <> inline size_t decode_partial_block_strided(zfp_stream* zfp, double* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { return zfp_decode_partial_block_strided_double_4(zfp, p, nx, ny, nz, nw, sx, sy, sz, sw); } } #endif zfp-1.0.1/include/zfp/000077500000000000000000000000001453723256400145455ustar00rootroot00000000000000zfp-1.0.1/include/zfp/array.h000066400000000000000000000013571453723256400160420ustar00rootroot00000000000000#ifndef CFP_ARRAY_H #define CFP_ARRAY_H #include #include "zfp/internal/cfp/header.h" #include "zfp/internal/cfp/array1f.h" #include "zfp/internal/cfp/array1d.h" #include "zfp/internal/cfp/array2f.h" #include "zfp/internal/cfp/array2d.h" #include "zfp/internal/cfp/array3f.h" #include "zfp/internal/cfp/array3d.h" #include "zfp/internal/cfp/array4f.h" #include "zfp/internal/cfp/array4d.h" typedef struct { cfp_array1f_api array1f; cfp_array1d_api array1d; cfp_array2f_api array2f; cfp_array2d_api array2d; cfp_array3f_api array3f; cfp_array3d_api array3d; cfp_array4f_api array4f; cfp_array4d_api array4d; } cfp_api; #ifndef CFP_NAMESPACE #define CFP_NAMESPACE cfp #endif extern_ const cfp_api CFP_NAMESPACE; #endif zfp-1.0.1/include/zfp/array.hpp000066400000000000000000000043451453723256400164020ustar00rootroot00000000000000#ifndef ZFP_ARRAY_HPP #define ZFP_ARRAY_HPP #include #include #include #include "zfp.h" #include "zfp/internal/array/exception.hpp" namespace zfp { // abstract base class for compressed array of scalars class array { public: #include "zfp/internal/array/header.hpp" // factory function (see zfpfactory.h) static zfp::array* construct(const zfp::array::header& header, const void* buffer = 0, size_t buffer_size_bytes = 0); // public virtual destructor (can delete array through base class pointer) virtual ~array() {} // underlying scalar type zfp_type scalar_type() const { return type; } // dimensionality uint dimensionality() const { return dims; } // rate in bits per value virtual double rate() const = 0; // compressed data size and buffer virtual size_t compressed_size() const = 0; virtual void* compressed_data() const = 0; protected: // default constructor array() : type(zfp_type_none), dims(0), nx(0), ny(0), nz(0), nw(0) {} // generic array with 'dims' dimensions and scalar type 'type' explicit array(uint dims, zfp_type type) : type(type), dims(dims), nx(0), ny(0), nz(0), nw(0) {} // constructor from previously-serialized compressed array explicit array(uint dims, zfp_type type, const zfp::array::header& header) : type(type), dims(dims), nx(header.size_x()), ny(header.size_y()), nz(header.size_z()), nw(header.size_w()) { if (header.scalar_type() != type) throw zfp::exception("zfp array scalar type does not match header"); if (header.dimensionality() != dims) throw zfp::exception("zfp array dimensionality does not match header"); } // copy constructor--performs a deep copy array(const array& a) { deep_copy(a); } // assignment operator--performs a deep copy array& operator=(const array& a) { deep_copy(a); return *this; } // perform a deep copy void deep_copy(const array& a) { // copy metadata type = a.type; dims = a.dims; nx = a.nx; ny = a.ny; nz = a.nz; nw = a.nw; } zfp_type type; // scalar type uint dims; // array dimensionality (1, 2, 3, or 4) size_t nx, ny, nz, nw; // array dimensions }; } #endif zfp-1.0.1/include/zfp/array1.hpp000066400000000000000000000176721453723256400164720ustar00rootroot00000000000000#ifndef ZFP_ARRAY1_HPP #define ZFP_ARRAY1_HPP #include #include #include #include "zfp/array.hpp" #include "zfp/index.hpp" #include "zfp/codec/zfpcodec.hpp" #include "zfp/internal/array/cache1.hpp" #include "zfp/internal/array/handle1.hpp" #include "zfp/internal/array/iterator1.hpp" #include "zfp/internal/array/pointer1.hpp" #include "zfp/internal/array/reference1.hpp" #include "zfp/internal/array/store1.hpp" #include "zfp/internal/array/view1.hpp" namespace zfp { // compressed 2D array of scalars template < typename Scalar, class Codec = zfp::codec::zfp1, class Index = zfp::index::implicit > class array1 : public array { public: // types utilized by nested classes typedef array1 container_type; typedef Scalar value_type; typedef Codec codec_type; typedef Index index_type; typedef zfp::internal::BlockStore1 store_type; typedef zfp::internal::BlockCache1 cache_type; typedef typename Codec::header header; // accessor classes typedef zfp::internal::dim1::const_reference const_reference; typedef zfp::internal::dim1::const_pointer const_pointer; typedef zfp::internal::dim1::const_iterator const_iterator; typedef zfp::internal::dim1::const_view const_view; typedef zfp::internal::dim1::private_const_view private_const_view; typedef zfp::internal::dim1::reference reference; typedef zfp::internal::dim1::pointer pointer; typedef zfp::internal::dim1::iterator iterator; typedef zfp::internal::dim1::view view; typedef zfp::internal::dim1::private_view private_view; // default constructor array1() : array(1, Codec::type), cache(store) {} // constructor of nx-element array using rate bits per value, at least // cache_size bytes of cache, and optionally initialized from flat array p array1(size_t nx, double rate, const value_type* p = 0, size_t cache_size = 0) : array(1, Codec::type), store(nx, zfp_config_rate(rate, true)), cache(store, cache_size) { this->nx = nx; if (p) set(p); } // constructor, from previously-serialized compressed array array1(const zfp::array::header& header, const void* buffer = 0, size_t buffer_size_bytes = 0) : array(1, Codec::type, header), store(header.size_x(), zfp_config_rate(header.rate(), true)), cache(store) { if (buffer) { if (buffer_size_bytes && buffer_size_bytes < store.compressed_size()) throw zfp::exception("buffer size is smaller than required"); std::memcpy(store.compressed_data(), buffer, store.compressed_size()); } } // copy constructor--performs a deep copy array1(const array1& a) : array(), cache(store) { deep_copy(a); } // construction from view--perform deep copy of (sub)array template array1(const View& v) : array(1, Codec::type), store(v.size_x(), zfp_config_rate(v.rate(), true)), cache(store) { this->nx = v.size_x(); // initialize array in its preferred order for (iterator it = begin(); it != end(); ++it) *it = v(it.i()); } // virtual destructor virtual ~array1() {} // assignment operator--performs a deep copy array1& operator=(const array1& a) { if (this != &a) deep_copy(a); return *this; } // total number of elements in array size_t size() const { return nx; } // array dimensions size_t size_x() const { return nx; } // resize the array (all previously stored data will be lost) void resize(size_t nx, bool clear = true) { cache.clear(); this->nx = nx; store.resize(nx, clear); } // rate in bits per value double rate() const { return store.rate(); } // set rate in bits per value double set_rate(double rate) { cache.clear(); return store.set_rate(rate, true); } // byte size of array data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += store.size_bytes(mask); size += cache.size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // number of bytes of compressed data size_t compressed_size() const { return store.compressed_size(); } // pointer to compressed data for read or write access void* compressed_data() const { cache.flush(); return store.compressed_data(); } // cache size in number of bytes size_t cache_size() const { return cache.size(); } // set minimum cache size in bytes (array dimensions must be known) void set_cache_size(size_t bytes) { cache.flush(); cache.resize(bytes); } // empty cache without compressing modified cached blocks void clear_cache() const { cache.clear(); } // flush cache by compressing all modified cached blocks void flush_cache() const { cache.flush(); } // decompress array and store at p void get(value_type* p) const { const size_t bx = store.block_size_x(); const ptrdiff_t sx = 1; size_t block_index = 0; for (size_t i = 0; i < bx; i++, p += 4) cache.get_block(block_index++, p, sx); } // initialize array by copying and compressing data stored at p void set(const value_type* p) { const size_t bx = store.block_size_x(); size_t block_index = 0; if (p) { // compress data stored at p const ptrdiff_t sx = 1; for (size_t i = 0; i < bx; i++, p += 4) cache.put_block(block_index++, p, sx); } else { // zero-initialize array const value_type block[4] = {}; while (block_index < bx) cache.put_block(block_index++, block, 1); } } // accessors const_reference operator()(size_t i) const { return const_reference(const_cast(this), i); } reference operator()(size_t i) { return reference(this, i); } // flat index accessors const_reference operator[](size_t index) const { return const_reference(const_cast(this), index); } reference operator[](size_t index) { return reference(this, index); } // random access iterators const_iterator cbegin() const { return const_iterator(this, 0); } const_iterator cend() const { return const_iterator(this, nx); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } iterator begin() { return iterator(this, 0); } iterator end() { return iterator(this, nx); } protected: friend class zfp::internal::dim1::const_handle; friend class zfp::internal::dim1::const_reference; friend class zfp::internal::dim1::const_pointer; friend class zfp::internal::dim1::const_iterator; friend class zfp::internal::dim1::const_view; friend class zfp::internal::dim1::private_const_view; friend class zfp::internal::dim1::reference; friend class zfp::internal::dim1::pointer; friend class zfp::internal::dim1::iterator; friend class zfp::internal::dim1::view; friend class zfp::internal::dim1::private_view; // perform a deep copy void deep_copy(const array1& a) { // copy base class members array::deep_copy(a); // copy persistent storage store.deep_copy(a.store); // copy cached data cache.deep_copy(a.cache); } // global index bounds size_t min_x() const { return 0; } size_t max_x() const { return nx; } // inspector value_type get(size_t i) const { return cache.get(i); } // mutators (called from proxy reference) void set(size_t i, value_type val) { cache.set(i, val); } void add(size_t i, value_type val) { cache.ref(i) += val; } void sub(size_t i, value_type val) { cache.ref(i) -= val; } void mul(size_t i, value_type val) { cache.ref(i) *= val; } void div(size_t i, value_type val) { cache.ref(i) /= val; } store_type store; // persistent storage of compressed blocks cache_type cache; // cache of decompressed blocks }; typedef array1 array1f; typedef array1 array1d; } #endif zfp-1.0.1/include/zfp/array2.hpp000066400000000000000000000224601453723256400164620ustar00rootroot00000000000000#ifndef ZFP_ARRAY2_HPP #define ZFP_ARRAY2_HPP #include #include #include #include "zfp/array.hpp" #include "zfp/index.hpp" #include "zfp/codec/zfpcodec.hpp" #include "zfp/internal/array/cache2.hpp" #include "zfp/internal/array/handle2.hpp" #include "zfp/internal/array/iterator2.hpp" #include "zfp/internal/array/pointer2.hpp" #include "zfp/internal/array/reference2.hpp" #include "zfp/internal/array/store2.hpp" #include "zfp/internal/array/view2.hpp" namespace zfp { // compressed 2D array of scalars template < typename Scalar, class Codec = zfp::codec::zfp2, class Index = zfp::index::implicit > class array2 : public array { public: // types utilized by nested classes typedef array2 container_type; typedef Scalar value_type; typedef Codec codec_type; typedef Index index_type; typedef zfp::internal::BlockStore2 store_type; typedef zfp::internal::BlockCache2 cache_type; typedef typename Codec::header header; // accessor classes typedef zfp::internal::dim2::const_reference const_reference; typedef zfp::internal::dim2::const_pointer const_pointer; typedef zfp::internal::dim2::const_iterator const_iterator; typedef zfp::internal::dim2::const_view const_view; typedef zfp::internal::dim2::private_const_view private_const_view; typedef zfp::internal::dim2::reference reference; typedef zfp::internal::dim2::pointer pointer; typedef zfp::internal::dim2::iterator iterator; typedef zfp::internal::dim2::view view; typedef zfp::internal::dim2::flat_view flat_view; typedef zfp::internal::dim2::nested_view1 nested_view1; typedef zfp::internal::dim2::nested_view2 nested_view2; typedef zfp::internal::dim2::nested_view2 nested_view; typedef zfp::internal::dim2::private_view private_view; // default constructor array2() : array(2, Codec::type), cache(store) {} // constructor of nx * ny array using rate bits per value, at least // cache_size bytes of cache, and optionally initialized from flat array p array2(size_t nx, size_t ny, double rate, const value_type* p = 0, size_t cache_size = 0) : array(2, Codec::type), store(nx, ny, zfp_config_rate(rate, true)), cache(store, cache_size) { this->nx = nx; this->ny = ny; if (p) set(p); } // constructor, from previously-serialized compressed array array2(const zfp::array::header& header, const void* buffer = 0, size_t buffer_size_bytes = 0) : array(2, Codec::type, header), store(header.size_x(), header.size_y(), zfp_config_rate(header.rate(), true)), cache(store) { if (buffer) { if (buffer_size_bytes && buffer_size_bytes < store.compressed_size()) throw zfp::exception("buffer size is smaller than required"); std::memcpy(store.compressed_data(), buffer, store.compressed_size()); } } // copy constructor--performs a deep copy array2(const array2& a) : array(), cache(store) { deep_copy(a); } // construction from view--perform deep copy of (sub)array template array2(const View& v) : array(2, Codec::type), store(v.size_x(), v.size_y(), zfp_config_rate(v.rate(), true)), cache(store) { this->nx = v.size_x(); this->ny = v.size_y(); // initialize array in its preferred order for (iterator it = begin(); it != end(); ++it) *it = v(it.i(), it.j()); } // virtual destructor virtual ~array2() {} // assignment operator--performs a deep copy array2& operator=(const array2& a) { if (this != &a) deep_copy(a); return *this; } // total number of elements in array size_t size() const { return nx * ny; } // array dimensions size_t size_x() const { return nx; } size_t size_y() const { return ny; } // resize the array (all previously stored data will be lost) void resize(size_t nx, size_t ny, bool clear = true) { cache.clear(); this->nx = nx; this->ny = ny; store.resize(nx, ny, clear); } // rate in bits per value double rate() const { return store.rate(); } // set rate in bits per value double set_rate(double rate) { cache.clear(); return store.set_rate(rate, true); } // byte size of array data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += store.size_bytes(mask); size += cache.size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // number of bytes of compressed data size_t compressed_size() const { return store.compressed_size(); } // pointer to compressed data for read or write access void* compressed_data() const { cache.flush(); return store.compressed_data(); } // cache size in number of bytes size_t cache_size() const { return cache.size(); } // set minimum cache size in bytes (array dimensions must be known) void set_cache_size(size_t bytes) { cache.flush(); cache.resize(bytes); } // empty cache without compressing modified cached blocks void clear_cache() const { cache.clear(); } // flush cache by compressing all modified cached blocks void flush_cache() const { cache.flush(); } // decompress array and store at p void get(value_type* p) const { const size_t bx = store.block_size_x(); const size_t by = store.block_size_y(); const ptrdiff_t sx = 1; const ptrdiff_t sy = static_cast(nx); size_t block_index = 0; for (size_t j = 0; j < by; j++, p += 4 * sx * ptrdiff_t(nx - bx)) for (size_t i = 0; i < bx; i++, p += 4) cache.get_block(block_index++, p, sx, sy); } // initialize array by copying and compressing data stored at p void set(const value_type* p) { const size_t bx = store.block_size_x(); const size_t by = store.block_size_y(); size_t block_index = 0; if (p) { // compress data stored at p const ptrdiff_t sx = 1; const ptrdiff_t sy = static_cast(nx); for (size_t j = 0; j < by; j++, p += 4 * sx * ptrdiff_t(nx - bx)) for (size_t i = 0; i < bx; i++, p += 4) cache.put_block(block_index++, p, sx, sy); } else { // zero-initialize array const value_type block[4 * 4] = {}; while (block_index < bx * by) cache.put_block(block_index++, block, 1, 4); } } // (i, j) accessors const_reference operator()(size_t i, size_t j) const { return const_reference(const_cast(this), i, j); } reference operator()(size_t i, size_t j) { return reference(this, i, j); } // flat index accessors const_reference operator[](size_t index) const { size_t i, j; ij(i, j, index); return const_reference(const_cast(this), i, j); } reference operator[](size_t index) { size_t i, j; ij(i, j, index); return reference(this, i, j); } // random access iterators const_iterator cbegin() const { return const_iterator(this, 0, 0); } const_iterator cend() const { return const_iterator(this, 0, ny); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } iterator begin() { return iterator(this, 0, 0); } iterator end() { return iterator(this, 0, ny); } protected: friend class zfp::internal::dim2::const_handle; friend class zfp::internal::dim2::const_reference; friend class zfp::internal::dim2::const_pointer; friend class zfp::internal::dim2::const_iterator; friend class zfp::internal::dim2::const_view; friend class zfp::internal::dim2::private_const_view; friend class zfp::internal::dim2::reference; friend class zfp::internal::dim2::pointer; friend class zfp::internal::dim2::iterator; friend class zfp::internal::dim2::view; friend class zfp::internal::dim2::flat_view; friend class zfp::internal::dim2::nested_view1; friend class zfp::internal::dim2::nested_view2; friend class zfp::internal::dim2::private_view; // perform a deep copy void deep_copy(const array2& a) { // copy base class members array::deep_copy(a); // copy persistent storage store.deep_copy(a.store); // copy cached data cache.deep_copy(a.cache); } // global index bounds size_t min_x() const { return 0; } size_t max_x() const { return nx; } size_t min_y() const { return 0; } size_t max_y() const { return ny; } // inspector value_type get(size_t i, size_t j) const { return cache.get(i, j); } // mutators (called from proxy reference) void set(size_t i, size_t j, value_type val) { cache.set(i, j, val); } void add(size_t i, size_t j, value_type val) { cache.ref(i, j) += val; } void sub(size_t i, size_t j, value_type val) { cache.ref(i, j) -= val; } void mul(size_t i, size_t j, value_type val) { cache.ref(i, j) *= val; } void div(size_t i, size_t j, value_type val) { cache.ref(i, j) /= val; } // convert flat index to (i, j) void ij(size_t& i, size_t& j, size_t index) const { i = index % nx; index /= nx; j = index; } store_type store; // persistent storage of compressed blocks cache_type cache; // cache of decompressed blocks }; typedef array2 array2f; typedef array2 array2d; } #endif zfp-1.0.1/include/zfp/array3.hpp000066400000000000000000000243441453723256400164660ustar00rootroot00000000000000#ifndef ZFP_ARRAY3_HPP #define ZFP_ARRAY3_HPP #include #include #include #include "zfp/array.hpp" #include "zfp/index.hpp" #include "zfp/codec/zfpcodec.hpp" #include "zfp/internal/array/cache3.hpp" #include "zfp/internal/array/handle3.hpp" #include "zfp/internal/array/iterator3.hpp" #include "zfp/internal/array/pointer3.hpp" #include "zfp/internal/array/reference3.hpp" #include "zfp/internal/array/store3.hpp" #include "zfp/internal/array/view3.hpp" namespace zfp { // compressed 3D array of scalars template < typename Scalar, class Codec = zfp::codec::zfp3, class Index = zfp::index::implicit > class array3 : public array { public: // types utilized by nested classes typedef array3 container_type; typedef Scalar value_type; typedef Codec codec_type; typedef Index index_type; typedef zfp::internal::BlockStore3 store_type; typedef zfp::internal::BlockCache3 cache_type; typedef typename Codec::header header; // accessor classes typedef zfp::internal::dim3::const_reference const_reference; typedef zfp::internal::dim3::const_pointer const_pointer; typedef zfp::internal::dim3::const_iterator const_iterator; typedef zfp::internal::dim3::const_view const_view; typedef zfp::internal::dim3::private_const_view private_const_view; typedef zfp::internal::dim3::reference reference; typedef zfp::internal::dim3::pointer pointer; typedef zfp::internal::dim3::iterator iterator; typedef zfp::internal::dim3::view view; typedef zfp::internal::dim3::flat_view flat_view; typedef zfp::internal::dim3::nested_view1 nested_view1; typedef zfp::internal::dim3::nested_view2 nested_view2; typedef zfp::internal::dim3::nested_view2 nested_view3; typedef zfp::internal::dim3::nested_view3 nested_view; typedef zfp::internal::dim3::private_view private_view; // default constructor array3() : array(3, Codec::type), cache(store) {} // constructor of nx * ny * nz array using rate bits per value, at least // cache_size bytes of cache, and optionally initialized from flat array p array3(size_t nx, size_t ny, size_t nz, double rate, const value_type* p = 0, size_t cache_size = 0) : array(3, Codec::type), store(nx, ny, nz, zfp_config_rate(rate, true)), cache(store, cache_size) { this->nx = nx; this->ny = ny; this->nz = nz; if (p) set(p); } // constructor, from previously-serialized compressed array array3(const zfp::array::header& header, const void* buffer = 0, size_t buffer_size_bytes = 0) : array(3, Codec::type, header), store(header.size_x(), header.size_y(), header.size_z(), zfp_config_rate(header.rate(), true)), cache(store) { if (buffer) { if (buffer_size_bytes && buffer_size_bytes < store.compressed_size()) throw zfp::exception("buffer size is smaller than required"); std::memcpy(store.compressed_data(), buffer, store.compressed_size()); } } // copy constructor--performs a deep copy array3(const array3& a) : array(), cache(store) { deep_copy(a); } // construction from view--perform deep copy of (sub)array template array3(const View& v) : array(3, Codec::type), store(v.size_x(), v.size_y(), v.size_z(), zfp_config_rate(v.rate(), true)), cache(store) { this->nx = v.size_x(); this->ny = v.size_y(); this->nz = v.size_z(); // initialize array in its preferred order for (iterator it = begin(); it != end(); ++it) *it = v(it.i(), it.j(), it.k()); } // virtual destructor virtual ~array3() {} // assignment operator--performs a deep copy array3& operator=(const array3& a) { if (this != &a) deep_copy(a); return *this; } // total number of elements in array size_t size() const { return nx * ny * nz; } // array dimensions size_t size_x() const { return nx; } size_t size_y() const { return ny; } size_t size_z() const { return nz; } // resize the array (all previously stored data will be lost) void resize(size_t nx, size_t ny, size_t nz, bool clear = true) { cache.clear(); this->nx = nx; this->ny = ny; this->nz = nz; store.resize(nx, ny, nz, clear); } // rate in bits per value double rate() const { return store.rate(); } // set rate in bits per value double set_rate(double rate) { cache.clear(); return store.set_rate(rate, true); } // byte size of array data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += store.size_bytes(mask); size += cache.size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // number of bytes of compressed data size_t compressed_size() const { return store.compressed_size(); } // pointer to compressed data for read or write access void* compressed_data() const { cache.flush(); return store.compressed_data(); } // cache size in number of bytes size_t cache_size() const { return cache.size(); } // set minimum cache size in bytes (array dimensions must be known) void set_cache_size(size_t bytes) { cache.flush(); cache.resize(bytes); } // empty cache without compressing modified cached blocks void clear_cache() const { cache.clear(); } // flush cache by compressing all modified cached blocks void flush_cache() const { cache.flush(); } // decompress array and store at p void get(value_type* p) const { const size_t bx = store.block_size_x(); const size_t by = store.block_size_y(); const size_t bz = store.block_size_z(); const ptrdiff_t sx = 1; const ptrdiff_t sy = static_cast(nx); const ptrdiff_t sz = static_cast(nx * ny); size_t block_index = 0; for (size_t k = 0; k < bz; k++, p += 4 * sy * ptrdiff_t(ny - by)) for (size_t j = 0; j < by; j++, p += 4 * sx * ptrdiff_t(nx - bx)) for (size_t i = 0; i < bx; i++, p += 4) cache.get_block(block_index++, p, sx, sy, sz); } // initialize array by copying and compressing data stored at p void set(const value_type* p) { const size_t bx = store.block_size_x(); const size_t by = store.block_size_y(); const size_t bz = store.block_size_z(); size_t block_index = 0; if (p) { // compress data stored at p const ptrdiff_t sx = 1; const ptrdiff_t sy = static_cast(nx); const ptrdiff_t sz = static_cast(nx * ny); for (size_t k = 0; k < bz; k++, p += 4 * sy * ptrdiff_t(ny - by)) for (size_t j = 0; j < by; j++, p += 4 * sx * ptrdiff_t(nx - bx)) for (size_t i = 0; i < bx; i++, p += 4) cache.put_block(block_index++, p, sx, sy, sz); } else { // zero-initialize array const value_type block[4 * 4 * 4] = {}; while (block_index < bx * by * bz) cache.put_block(block_index++, block, 1, 4, 16); } } // (i, j, k) accessors const_reference operator()(size_t i, size_t j, size_t k) const { return const_reference(const_cast(this), i, j, k); } reference operator()(size_t i, size_t j, size_t k) { return reference(this, i, j, k); } // flat index accessors const_reference operator[](size_t index) const { size_t i, j, k; ijk(i, j, k, index); return const_reference(const_cast(this), i, j, k); } reference operator[](size_t index) { size_t i, j, k; ijk(i, j, k, index); return reference(this, i, j, k); } // random access iterators const_iterator cbegin() const { return const_iterator(this, 0, 0, 0); } const_iterator cend() const { return const_iterator(this, 0, 0, nz); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } iterator begin() { return iterator(this, 0, 0, 0); } iterator end() { return iterator(this, 0, 0, nz); } protected: friend class zfp::internal::dim3::const_handle; friend class zfp::internal::dim3::const_reference; friend class zfp::internal::dim3::const_pointer; friend class zfp::internal::dim3::const_iterator; friend class zfp::internal::dim3::const_view; friend class zfp::internal::dim3::private_const_view; friend class zfp::internal::dim3::reference; friend class zfp::internal::dim3::pointer; friend class zfp::internal::dim3::iterator; friend class zfp::internal::dim3::view; friend class zfp::internal::dim3::flat_view; friend class zfp::internal::dim3::nested_view1; friend class zfp::internal::dim3::nested_view2; friend class zfp::internal::dim3::nested_view3; friend class zfp::internal::dim3::private_view; // perform a deep copy void deep_copy(const array3& a) { // copy base class members array::deep_copy(a); // copy persistent storage store.deep_copy(a.store); // copy cached data cache.deep_copy(a.cache); } // global index bounds size_t min_x() const { return 0; } size_t max_x() const { return nx; } size_t min_y() const { return 0; } size_t max_y() const { return ny; } size_t min_z() const { return 0; } size_t max_z() const { return nz; } // inspector value_type get(size_t i, size_t j, size_t k) const { return cache.get(i, j, k); } // mutators (called from proxy reference) void set(size_t i, size_t j, size_t k, value_type val) { cache.set(i, j, k, val); } void add(size_t i, size_t j, size_t k, value_type val) { cache.ref(i, j, k) += val; } void sub(size_t i, size_t j, size_t k, value_type val) { cache.ref(i, j, k) -= val; } void mul(size_t i, size_t j, size_t k, value_type val) { cache.ref(i, j, k) *= val; } void div(size_t i, size_t j, size_t k, value_type val) { cache.ref(i, j, k) /= val; } // convert flat index to (i, j, k) void ijk(size_t& i, size_t& j, size_t& k, size_t index) const { i = index % nx; index /= nx; j = index % ny; index /= ny; k = index; } store_type store; // persistent storage of compressed blocks cache_type cache; // cache of decompressed blocks }; typedef array3 array3f; typedef array3 array3d; } #endif zfp-1.0.1/include/zfp/array4.hpp000066400000000000000000000262401453723256400164640ustar00rootroot00000000000000#ifndef ZFP_ARRAY4_HPP #define ZFP_ARRAY4_HPP #include #include #include #include "zfp/array.hpp" #include "zfp/index.hpp" #include "zfp/codec/zfpcodec.hpp" #include "zfp/internal/array/cache4.hpp" #include "zfp/internal/array/handle4.hpp" #include "zfp/internal/array/iterator4.hpp" #include "zfp/internal/array/pointer4.hpp" #include "zfp/internal/array/reference4.hpp" #include "zfp/internal/array/store4.hpp" #include "zfp/internal/array/view4.hpp" namespace zfp { // compressed 3D array of scalars template < typename Scalar, class Codec = zfp::codec::zfp4, class Index = zfp::index::implicit > class array4 : public array { public: // types utilized by nested classes typedef array4 container_type; typedef Scalar value_type; typedef Codec codec_type; typedef Index index_type; typedef zfp::internal::BlockStore4 store_type; typedef zfp::internal::BlockCache4 cache_type; typedef typename Codec::header header; // accessor classes typedef zfp::internal::dim4::const_reference const_reference; typedef zfp::internal::dim4::const_pointer const_pointer; typedef zfp::internal::dim4::const_iterator const_iterator; typedef zfp::internal::dim4::const_view const_view; typedef zfp::internal::dim4::private_const_view private_const_view; typedef zfp::internal::dim4::reference reference; typedef zfp::internal::dim4::pointer pointer; typedef zfp::internal::dim4::iterator iterator; typedef zfp::internal::dim4::view view; typedef zfp::internal::dim4::flat_view flat_view; typedef zfp::internal::dim4::nested_view1 nested_view1; typedef zfp::internal::dim4::nested_view2 nested_view2; typedef zfp::internal::dim4::nested_view3 nested_view3; typedef zfp::internal::dim4::nested_view4 nested_view4; typedef zfp::internal::dim4::nested_view4 nested_view; typedef zfp::internal::dim4::private_view private_view; // default constructor array4() : array(4, Codec::type), cache(store) {} // constructor of nx * ny * nz * nw array using rate bits per value, at least // cache_size bytes of cache, and optionally initialized from flat array p array4(size_t nx, size_t ny, size_t nz, size_t nw, double rate, const value_type* p = 0, size_t cache_size = 0) : array(4, Codec::type), store(nx, ny, nz, nw, zfp_config_rate(rate, true)), cache(store, cache_size) { this->nx = nx; this->ny = ny; this->nz = nz; this->nw = nw; if (p) set(p); } // constructor, from previously-serialized compressed array array4(const zfp::array::header& header, const void* buffer = 0, size_t buffer_size_bytes = 0) : array(4, Codec::type, header), store(header.size_x(), header.size_y(), header.size_z(), header.size_w(), zfp_config_rate(header.rate(), true)), cache(store) { if (buffer) { if (buffer_size_bytes && buffer_size_bytes < store.compressed_size()) throw zfp::exception("buffer size is smaller than required"); std::memcpy(store.compressed_data(), buffer, store.compressed_size()); } } // copy constructor--performs a deep copy array4(const array4& a) : array(), cache(store) { deep_copy(a); } // construction from view--perform deep copy of (sub)array template array4(const View& v) : array(4, Codec::type), store(v.size_x(), v.size_y(), v.size_z(), v.size_w(), zfp_config_rate(v.rate(), true)), cache(store) { this->nx = v.size_x(); this->ny = v.size_y(); this->nz = v.size_z(); this->nw = v.size_w(); // initialize array in its preferred order for (iterator it = begin(); it != end(); ++it) *it = v(it.i(), it.j(), it.k(), it.l()); } // virtual destructor virtual ~array4() {} // assignment operator--performs a deep copy array4& operator=(const array4& a) { if (this != &a) deep_copy(a); return *this; } // total number of elements in array size_t size() const { return nx * ny * nz * nw; } // array dimensions size_t size_x() const { return nx; } size_t size_y() const { return ny; } size_t size_z() const { return nz; } size_t size_w() const { return nw; } // resize the array (all previously stored data will be lost) void resize(size_t nx, size_t ny, size_t nz, size_t nw, bool clear = true) { cache.clear(); this->nx = nx; this->ny = ny; this->nz = nz; this->nw = nw; store.resize(nx, ny, nz, nw, clear); } // rate in bits per value double rate() const { return store.rate(); } // set rate in bits per value double set_rate(double rate) { cache.clear(); return store.set_rate(rate, true); } // byte size of array data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += store.size_bytes(mask); size += cache.size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // number of bytes of compressed data size_t compressed_size() const { return store.compressed_size(); } // pointer to compressed data for read or write access void* compressed_data() const { cache.flush(); return store.compressed_data(); } // cache size in number of bytes size_t cache_size() const { return cache.size(); } // set minimum cache size in bytes (array dimensions must be known) void set_cache_size(size_t bytes) { cache.flush(); cache.resize(bytes); } // empty cache without compressing modified cached blocks void clear_cache() const { cache.clear(); } // flush cache by compressing all modified cached blocks void flush_cache() const { cache.flush(); } // decompress array and store at p void get(value_type* p) const { const size_t bx = store.block_size_x(); const size_t by = store.block_size_y(); const size_t bz = store.block_size_z(); const size_t bw = store.block_size_w(); const ptrdiff_t sx = 1; const ptrdiff_t sy = static_cast(nx); const ptrdiff_t sz = static_cast(nx * ny); const ptrdiff_t sw = static_cast(nx * ny * nz); size_t block_index = 0; for (size_t l = 0; l < bw; l++, p += 4 * sz * ptrdiff_t(nz - bz)) for (size_t k = 0; k < bz; k++, p += 4 * sy * ptrdiff_t(ny - by)) for (size_t j = 0; j < by; j++, p += 4 * sx * ptrdiff_t(nx - bx)) for (size_t i = 0; i < bx; i++, p += 4) cache.get_block(block_index++, p, sx, sy, sz, sw); } // initialize array by copying and compressing data stored at p void set(const value_type* p) { const size_t bx = store.block_size_x(); const size_t by = store.block_size_y(); const size_t bz = store.block_size_z(); const size_t bw = store.block_size_w(); size_t block_index = 0; if (p) { // compress data stored at p const ptrdiff_t sx = 1; const ptrdiff_t sy = static_cast(nx); const ptrdiff_t sz = static_cast(nx * ny); const ptrdiff_t sw = static_cast(nx * ny * nz); for (size_t l = 0; l < bw; l++, p += 4 * sz * ptrdiff_t(nz - bz)) for (size_t k = 0; k < bz; k++, p += 4 * sy * ptrdiff_t(ny - by)) for (size_t j = 0; j < by; j++, p += 4 * sx * ptrdiff_t(nx - bx)) for (size_t i = 0; i < bx; i++, p += 4) cache.put_block(block_index++, p, sx, sy, sz, sw); } else { // zero-initialize array const value_type block[4 * 4 * 4 * 4] = {}; while (block_index < bx * by * bz * bw) cache.put_block(block_index++, block, 1, 4, 16, 64); } } // (i, j, k) accessors const_reference operator()(size_t i, size_t j, size_t k, size_t l) const { return const_reference(const_cast(this), i, j, k, l); } reference operator()(size_t i, size_t j, size_t k, size_t l) { return reference(this, i, j, k, l); } // flat index accessors const_reference operator[](size_t index) const { size_t i, j, k, l; ijkl(i, j, k, l, index); return const_reference(const_cast(this), i, j, k, l); } reference operator[](size_t index) { size_t i, j, k, l; ijkl(i, j, k, l, index); return reference(this, i, j, k, l); } // random access iterators const_iterator cbegin() const { return const_iterator(this, 0, 0, 0, 0); } const_iterator cend() const { return const_iterator(this, 0, 0, 0, nw); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } iterator begin() { return iterator(this, 0, 0, 0, 0); } iterator end() { return iterator(this, 0, 0, 0, nw); } protected: friend class zfp::internal::dim4::const_handle; friend class zfp::internal::dim4::const_reference; friend class zfp::internal::dim4::const_pointer; friend class zfp::internal::dim4::const_iterator; friend class zfp::internal::dim4::const_view; friend class zfp::internal::dim4::private_const_view; friend class zfp::internal::dim4::reference; friend class zfp::internal::dim4::pointer; friend class zfp::internal::dim4::iterator; friend class zfp::internal::dim4::view; friend class zfp::internal::dim4::flat_view; friend class zfp::internal::dim4::nested_view1; friend class zfp::internal::dim4::nested_view2; friend class zfp::internal::dim4::nested_view3; friend class zfp::internal::dim4::nested_view4; friend class zfp::internal::dim4::private_view; // perform a deep copy void deep_copy(const array4& a) { // copy base class members array::deep_copy(a); // copy persistent storage store.deep_copy(a.store); // copy cached data cache.deep_copy(a.cache); } // global index bounds size_t min_x() const { return 0; } size_t max_x() const { return nx; } size_t min_y() const { return 0; } size_t max_y() const { return ny; } size_t min_z() const { return 0; } size_t max_z() const { return nz; } size_t min_w() const { return 0; } size_t max_w() const { return nw; } // inspector value_type get(size_t i, size_t j, size_t k, size_t l) const { return cache.get(i, j, k, l); } // mutators (called from proxy reference) void set(size_t i, size_t j, size_t k, size_t l, value_type val) { cache.set(i, j, k, l, val); } void add(size_t i, size_t j, size_t k, size_t l, value_type val) { cache.ref(i, j, k, l) += val; } void sub(size_t i, size_t j, size_t k, size_t l, value_type val) { cache.ref(i, j, k, l) -= val; } void mul(size_t i, size_t j, size_t k, size_t l, value_type val) { cache.ref(i, j, k, l) *= val; } void div(size_t i, size_t j, size_t k, size_t l, value_type val) { cache.ref(i, j, k, l) /= val; } // convert flat index to (i, j, k) void ijkl(size_t& i, size_t& j, size_t& k, size_t& l, size_t index) const { i = index % nx; index /= nx; j = index % ny; index /= ny; k = index % nz; index /= nz; l = index; } store_type store; // persistent storage of compressed blocks cache_type cache; // cache of decompressed blocks }; typedef array4 array4f; typedef array4 array4d; } #endif zfp-1.0.1/include/zfp/bitstream.h000066400000000000000000000057751453723256400167260ustar00rootroot00000000000000#ifndef ZFP_BITSTREAM_H #define ZFP_BITSTREAM_H #include #include "zfp/internal/zfp/types.h" #include "zfp/internal/zfp/system.h" /* forward declaration of opaque type */ typedef struct bitstream bitstream; /* bit offset into stream where bits are read/written */ typedef uint64 bitstream_offset; /* type for counting number of bits in a stream */ typedef bitstream_offset bitstream_size; /* type for counting a small number of bits in a stream */ typedef size_t bitstream_count; extern_ const size_t stream_word_bits; /* bit stream granularity */ #ifndef inline_ #ifdef __cplusplus extern "C" { #endif /* allocate and initialize bit stream */ bitstream* stream_open(void* buffer, size_t bytes); /* close and deallocate bit stream */ void stream_close(bitstream* stream); /* make a copy of bit stream to shared memory buffer */ bitstream* stream_clone(const bitstream* stream); /* word size in bits (equal to stream_word_bits) */ bitstream_count stream_alignment(void); /* pointer to beginning of stream */ void* stream_data(const bitstream* stream); /* current byte size of stream (if flushed) */ size_t stream_size(const bitstream* stream); /* byte capacity of stream */ size_t stream_capacity(const bitstream* stream); /* number of words per block */ size_t stream_stride_block(const bitstream* stream); /* number of blocks between consecutive blocks */ ptrdiff_t stream_stride_delta(const bitstream* stream); /* read single bit (0 or 1) */ uint stream_read_bit(bitstream* stream); /* write single bit */ uint stream_write_bit(bitstream* stream, uint bit); /* read 0 <= n <= 64 bits */ uint64 stream_read_bits(bitstream* stream, bitstream_count n); /* write 0 <= n <= 64 low bits of value and return remaining bits */ uint64 stream_write_bits(bitstream* stream, uint64 value, bitstream_count n); /* return bit offset to next bit to be read */ bitstream_offset stream_rtell(const bitstream* stream); /* return bit offset to next bit to be written */ bitstream_offset stream_wtell(const bitstream* stream); /* rewind stream to beginning */ void stream_rewind(bitstream* stream); /* position stream for reading at given bit offset */ void stream_rseek(bitstream* stream, bitstream_offset offset); /* position stream for writing at given bit offset */ void stream_wseek(bitstream* stream, bitstream_offset offset); /* skip over the next n bits */ void stream_skip(bitstream* stream, bitstream_size n); /* append n zero-bits to stream */ void stream_pad(bitstream* stream, bitstream_size n); /* align stream on next word boundary */ bitstream_count stream_align(bitstream* stream); /* flush out any remaining buffered bits */ bitstream_count stream_flush(bitstream* stream); /* copy n bits from one bit stream to another */ void stream_copy(bitstream* dst, bitstream* src, bitstream_size n); #ifdef BIT_STREAM_STRIDED /* set block size in number of words and spacing in number of blocks */ int stream_set_stride(bitstream* stream, size_t block, ptrdiff_t delta); #endif #ifdef __cplusplus } #endif #endif /* !inline_ */ #endif zfp-1.0.1/include/zfp/bitstream.inl000066400000000000000000000330441453723256400172470ustar00rootroot00000000000000/* High-speed in-memory bit stream I/O that supports reading and writing between 0 and 64 bits at a time. The implementation, which relies heavily on bit shifts, has been carefully written to ensure that all shifts are between zero and one less the width of the type being shifted to avoid undefined behavior. This occasionally causes somewhat convoluted code. The following assumptions and restrictions apply: 1. The user must allocate a memory buffer large enough to hold the bit stream, whether for reading, writing, or both. This buffer is associated with the bit stream via stream_open(buffer, bytes), which allocates and returns a pointer to an opaque bit stream struct. Call stream_close(stream) to deallocate this struct. 2. The stream is either in a read or write state (or, initially, in both states). When done writing, call stream_flush(stream) before entering read mode to ensure any buffered bits are output. To enter read mode, call stream_rewind(stream) or stream_rseek(stream, offset) to position the stream at the beginning or at a particular bit offset. Conversely, stream_rewind(stream) or stream_wseek(stream, offset) positions the stream for writing. In read mode, the following functions may be called: size_t stream_size(stream); bitstream_offset stream_rtell(stream); void stream_rewind(stream); void stream_rseek(stream, offset); void stream_skip(stream, n); bitstream_count stream_align(stream); uint stream_read_bit(stream); uint64 stream_read_bits(stream, n); Each of the above read calls has a corresponding write call: size_t stream_size(stream); bitstream_offset stream_wtell(stream); void stream_rewind(stream); void stream_wseek(stream, offset); void stream_pad(stream, n); bitstream_count stream_flush(stream); uint stream_write_bit(stream, bit); uint64 stream_write_bits(stream, value, n); 3. The stream buffer is an unsigned integer of a user-specified type given by the BIT_STREAM_WORD_TYPE macro. Bits are read and written in units of this integer word type. Supported types are 8, 16, 32, or 64 bits wide. The bit width of the buffer is denoted by 'wsize' and can be accessed either via the global constant stream_word_bits or stream_alignment(). A small wsize allows for fine granularity reads and writes, and may be preferable when working with many small blocks of data that require non-sequential access. The default maximum size of 64 bits ensures maximum speed. Note that even when wsize < 64, it is still possible to read and write up to 64 bits at a time using stream_read_bits() and stream_write_bits(). 4. If BIT_STREAM_STRIDED is defined, words read from or written to the stream may be accessed noncontiguously by setting a power-of-two block size (which by default is one word) and a block stride (defaults to zero blocks). The word pointer is always incremented by one word each time a word is accessed. Once advanced past a block boundary, the word pointer is also advanced by the stride to the next block. This feature may be used to store blocks of data interleaved, e.g., for progressive coding or for noncontiguous parallel access to the bit stream Note that the block size is measured in words, while the stride is measured in multiples of the block size. Strided access can have a significant performance penalty. 5. Multiple bits are read and written in order of least to most significant bit. Thus, the statement value = stream_write_bits(stream, value, n); is essentially equivalent to (but faster than) for (i = 0; i < n; i++, value >>= 1) stream_write_bit(stream, value & 1); when 0 <= n <= 64. The same holds for read calls, and thus value = stream_read_bits(stream, n); is essentially equivalent to for (i = 0, value = 0; i < n; i++) value += (uint64)stream_read_bit(stream) << i; Note that it is possible to write fewer bits than the argument 'value' holds (possibly even no bits), in which case any unwritten bits are shifted right to the least significant position and returned. That is, value = stream_write_bits(stream, value, n); is equivalent to for (i = 0; i < n; i++) value = stream_write_bits(stream, value, 1); 6. Although the stream_wseek(stream, offset) call allows positioning the stream for writing at any bit offset without any data loss (i.e. all previously written bits preceding the offset remain valid), for efficiency the stream_flush(stream) operation will zero all bits up to the next multiple of wsize bits, thus overwriting bits that were previously stored at that location. Consequently, random write access is effectively supported only at wsize granularity. For sequential access, the largest possible wsize is preferred due to higher speed. 7. It is up to the user to adhere to these rules. For performance reasons, no error checking is done, and in particular buffer overruns are not caught. */ #include #include #ifndef inline_ #define inline_ #endif #include "zfp/bitstream.h" /* satisfy compiler when args unused */ #define unused_(x) ((void)(x)) /* bit stream word/buffer type; granularity of stream I/O operations */ #ifdef BIT_STREAM_WORD_TYPE /* may be 8-, 16-, 32-, or 64-bit unsigned integer type */ typedef BIT_STREAM_WORD_TYPE bitstream_word; #else /* use maximum word size by default for highest speed */ typedef uint64 bitstream_word; #endif /* number of bits in a buffered word */ #define wsize ((bitstream_count)(sizeof(bitstream_word) * CHAR_BIT)) /* bit stream structure (opaque to caller) */ struct bitstream { bitstream_count bits; /* number of buffered bits (0 <= bits < wsize) */ bitstream_word buffer; /* incoming/outgoing bits (buffer < 2^bits) */ bitstream_word* ptr; /* pointer to next word to be read/written */ bitstream_word* begin; /* beginning of stream */ bitstream_word* end; /* end of stream (not enforced) */ #ifdef BIT_STREAM_STRIDED size_t mask; /* one less the block size in number of words */ ptrdiff_t delta; /* number of words between consecutive blocks */ #endif }; /* private functions ------------------------------------------------------- */ /* read a single word from memory */ static bitstream_word stream_read_word(bitstream* s) { bitstream_word w = *s->ptr++; #ifdef BIT_STREAM_STRIDED if (!((s->ptr - s->begin) & s->mask)) s->ptr += s->delta; #endif return w; } /* write a single word to memory */ static void stream_write_word(bitstream* s, bitstream_word value) { *s->ptr++ = value; #ifdef BIT_STREAM_STRIDED if (!((s->ptr - s->begin) & s->mask)) s->ptr += s->delta; #endif } /* public functions -------------------------------------------------------- */ /* word size in bits (equals bitstream_word_bits) */ inline_ bitstream_count stream_alignment(void) { return wsize; } /* pointer to beginning of stream */ inline_ void* stream_data(const bitstream* s) { return s->begin; } /* current byte size of stream (if flushed) */ inline_ size_t stream_size(const bitstream* s) { return (size_t)(s->ptr - s->begin) * sizeof(bitstream_word); } /* byte capacity of stream */ inline_ size_t stream_capacity(const bitstream* s) { return (size_t)(s->end - s->begin) * sizeof(bitstream_word); } /* number of words per block */ inline_ size_t stream_stride_block(const bitstream* s) { #ifdef BIT_STREAM_STRIDED return s->mask + 1; #else unused_(s); return 1; #endif } /* number of blocks between consecutive stream blocks */ inline_ ptrdiff_t stream_stride_delta(const bitstream* s) { #ifdef BIT_STREAM_STRIDED return s->delta / (s->mask + 1); #else unused_(s); return 0; #endif } /* read single bit (0 or 1) */ inline_ uint stream_read_bit(bitstream* s) { uint bit; if (!s->bits) { s->buffer = stream_read_word(s); s->bits = wsize; } s->bits--; bit = (uint)s->buffer & 1u; s->buffer >>= 1; return bit; } /* write single bit (must be 0 or 1) */ inline_ uint stream_write_bit(bitstream* s, uint bit) { s->buffer += (bitstream_word)bit << s->bits; if (++s->bits == wsize) { stream_write_word(s, s->buffer); s->buffer = 0; s->bits = 0; } return bit; } /* read 0 <= n <= 64 bits */ inline_ uint64 stream_read_bits(bitstream* s, bitstream_count n) { uint64 value = s->buffer; if (s->bits < n) { /* keep fetching wsize bits until enough bits are buffered */ do { /* assert: 0 <= s->bits < n <= 64 */ s->buffer = stream_read_word(s); value += (uint64)s->buffer << s->bits; s->bits += wsize; } while (sizeof(s->buffer) < sizeof(value) && s->bits < n); /* assert: 1 <= n <= s->bits < n + wsize */ s->bits -= n; if (!s->bits) { /* value holds exactly n bits; no need for masking */ s->buffer = 0; } else { /* assert: 1 <= s->bits < wsize */ s->buffer >>= wsize - s->bits; /* assert: 1 <= n <= 64 */ value &= ((uint64)2 << (n - 1)) - 1; } } else { /* assert: 0 <= n <= s->bits < wsize <= 64 */ s->bits -= n; s->buffer >>= n; value &= ((uint64)1 << n) - 1; } return value; } /* write 0 <= n <= 64 low bits of value and return remaining bits */ inline_ uint64 stream_write_bits(bitstream* s, uint64 value, bitstream_count n) { /* append bit string to buffer */ s->buffer += (bitstream_word)(value << s->bits); s->bits += n; /* is buffer full? */ if (s->bits >= wsize) { /* 1 <= n <= 64; decrement n to ensure valid right shifts below */ value >>= 1; n--; /* assert: 0 <= n < 64; wsize <= s->bits <= wsize + n */ do { /* output wsize bits while buffer is full */ s->bits -= wsize; /* assert: 0 <= s->bits <= n */ stream_write_word(s, s->buffer); /* assert: 0 <= n - s->bits < 64 */ s->buffer = (bitstream_word)(value >> (n - s->bits)); } while (sizeof(s->buffer) < sizeof(value) && s->bits >= wsize); } /* assert: 0 <= s->bits < wsize */ s->buffer &= ((bitstream_word)1 << s->bits) - 1; /* assert: 0 <= n < 64 */ return value >> n; } /* return bit offset to next bit to be read */ inline_ bitstream_offset stream_rtell(const bitstream* s) { return (bitstream_offset)(s->ptr - s->begin) * wsize - s->bits; } /* return bit offset to next bit to be written */ inline_ bitstream_offset stream_wtell(const bitstream* s) { return (bitstream_offset)(s->ptr - s->begin) * wsize + s->bits; } /* position stream for reading or writing at beginning */ inline_ void stream_rewind(bitstream* s) { s->ptr = s->begin; s->buffer = 0; s->bits = 0; } /* position stream for reading at given bit offset */ inline_ void stream_rseek(bitstream* s, bitstream_offset offset) { bitstream_count n = (bitstream_count)(offset % wsize); s->ptr = s->begin + (size_t)(offset / wsize); if (n) { s->buffer = stream_read_word(s) >> n; s->bits = wsize - n; } else { s->buffer = 0; s->bits = 0; } } /* position stream for writing at given bit offset */ inline_ void stream_wseek(bitstream* s, bitstream_offset offset) { bitstream_count n = (bitstream_count)(offset % wsize); s->ptr = s->begin + (size_t)(offset / wsize); if (n) { bitstream_word buffer = *s->ptr; buffer &= ((bitstream_word)1 << n) - 1; s->buffer = buffer; s->bits = n; } else { s->buffer = 0; s->bits = 0; } } /* skip over the next n bits (n >= 0) */ inline_ void stream_skip(bitstream* s, bitstream_size n) { stream_rseek(s, stream_rtell(s) + n); } /* append n zero-bits to stream (n >= 0) */ inline_ void stream_pad(bitstream* s, bitstream_size n) { bitstream_offset bits = s->bits; for (bits += n; bits >= wsize; bits -= wsize) { stream_write_word(s, s->buffer); s->buffer = 0; } s->bits = (bitstream_count)bits; } /* align stream on next word boundary */ inline_ bitstream_count stream_align(bitstream* s) { bitstream_count bits = s->bits; if (bits) stream_skip(s, bits); return bits; } /* write any remaining buffered bits and align stream on next word boundary */ inline_ bitstream_count stream_flush(bitstream* s) { bitstream_count bits = (wsize - s->bits) % wsize; if (bits) stream_pad(s, bits); return bits; } /* copy n bits from one bit stream to another */ inline_ void stream_copy(bitstream* dst, bitstream* src, bitstream_size n) { while (n > wsize) { bitstream_word w = (bitstream_word)stream_read_bits(src, wsize); stream_write_bits(dst, w, wsize); n -= wsize; } if (n) { bitstream_word w = (bitstream_word)stream_read_bits(src, (bitstream_count)n); stream_write_bits(dst, w, (bitstream_count)n); } } #ifdef BIT_STREAM_STRIDED /* set block size in number of words and spacing in number of blocks */ inline_ int stream_set_stride(bitstream* s, size_t block, ptrdiff_t delta) { /* ensure block size is a power of two */ if (block & (block - 1)) return 0; s->mask = block - 1; s->delta = delta * block; return 1; } #endif /* allocate and initialize bit stream to user-allocated buffer */ inline_ bitstream* stream_open(void* buffer, size_t bytes) { bitstream* s = (bitstream*)malloc(sizeof(bitstream)); if (s) { s->begin = (bitstream_word*)buffer; s->end = s->begin + bytes / sizeof(bitstream_word); #ifdef BIT_STREAM_STRIDED stream_set_stride(s, 0, 0); #endif stream_rewind(s); } return s; } /* close and deallocate bit stream */ inline_ void stream_close(bitstream* s) { free(s); } /* make a copy of bit stream to shared memory buffer */ inline_ bitstream* stream_clone(const bitstream* s) { bitstream* c = (bitstream*)malloc(sizeof(bitstream)); if (c) *c = *s; return c; } #undef unused_ zfp-1.0.1/include/zfp/codec/000077500000000000000000000000001453723256400156225ustar00rootroot00000000000000zfp-1.0.1/include/zfp/codec/gencodec.hpp000066400000000000000000000336751453723256400201200ustar00rootroot00000000000000#ifndef ZFP_GENERIC_CODEC_HPP #define ZFP_GENERIC_CODEC_HPP // This CODEC allows interfacing with the zfp::array classes via a user-facing // scalar type, ExternalType (e.g., double), while storing data in memory using // a possibly less precise scalar type, InternalType (e.g., float). Using // zfp's caching mechanism, blocks of data may reside for some time in cache // as ExternalType. This potentially allows a sequence of more precise // operations to be performed on the data before it is down-converted to // InternalType and stored to memory. When ExternalType = InternalType, this // CODEC allows defining arrays that support the full zfp array API but use // uncompressed storage. To use this CODEC, pass it as the Codec template // parameter to a zfp::array class of matching dimensionality. #include #include #include #include "zfp.h" #include "zfp/internal/array/memory.hpp" #include "zfp/internal/array/traits.hpp" namespace zfp { namespace codec { // abstract base class for storing 1D-4D uncompressed blocks of scalars template < uint dims, // data dimensionality (1-4) typename ExternalType, // scalar type exposed through array API typename InternalType = ExternalType // scalar type used for storage > class generic_base { protected: // default constructor generic_base() : bytes(0), buffer(0) {} public: // conservative buffer size for current codec settings size_t buffer_size(const zfp_field* field) const { return zfp_field_blocks(field) * block_size * sizeof(InternalType); } // open void open(void* data, size_t size) { bytes = size; buffer = static_cast(data); } // close bit stream void close() { bytes = 0; buffer = 0; } // pointer to beginning of bit stream void* data() const { return static_cast(buffer); } // compression mode zfp_mode mode() const { return zfp_mode_fixed_rate; } // rate in compressed bits/value (equals precision) double rate() const { return static_cast(precision()); } // precision in uncompressed bits/value uint precision() const { return internal_size_bits; } // accuracy as absolute error tolerance (unsupported) double accuracy() const { return -1; } // compression parameters (all compression modes) void params(uint* minbits, uint* maxbits, uint* maxprec, int* minexp) const { if (minbits) *minbits = block_size_bits; if (maxbits) *maxbits = block_size_bits; if (maxprec) *maxprec = precision(); if (minexp) *minexp = ZFP_MIN_EXP; } // enable reversible (lossless) mode void set_reversible() { throw zfp::exception("zfp generic codec does not support reversible mode"); } // set rate in compressed bits/value (equals precision) double set_rate(double rate, bool) { return static_cast(set_precision(static_cast(rate))); } // set precision in uncompressed bits/value (must equal InternalType width) uint set_precision(uint precision) { if (precision != internal_size_bits) throw zfp::exception("zfp generic codec precision mismatch"); return precision; } // set accuracy as absolute error tolerance double set_accuracy(double) { throw zfp::exception("zfp generic codec does not support fixed-accuracy mode"); return -1; } // set expert mode parameters bool set_params(uint, uint, uint, int) { throw zfp::exception("zfp generic codec does not support expert mode"); return false; } // set thread safety mode (not required by this codec) void set_thread_safety(bool) {} // byte size of codec data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // unit of allocated data in bytes static size_t alignment() { return sizeof(InternalType); } static const zfp_type type = zfp::internal::trait::type; // scalar type // zfp::codec::generic_base::header class for array (de)serialization #include "zfp/internal/codec/genheader.hpp" protected: // pointer to beginning of block InternalType* begin(bitstream_offset offset) const { if (offset % internal_size_bits) throw zfp::exception("zfp generic codec bit offset alignment error"); return buffer + offset / internal_size_bits; } // store full contiguous block to memory size_t encode_block(bitstream_offset offset, const ExternalType* block) const { InternalType* ptr = begin(offset); for (size_t n = block_size; n--;) *ptr++ = static_cast(*block++); return block_size_bits; } // load full contiguous block from memory size_t decode_block(bitstream_offset offset, ExternalType* block) const { const InternalType* ptr = begin(offset); for (size_t n = block_size; n--;) *block++ = static_cast(*ptr++); return block_size_bits; } // constants associated with template arguments static const size_t internal_size_bits = sizeof(InternalType) * CHAR_BIT; static const size_t block_size = 1u << (2 * dims); static const size_t block_size_bits = block_size * internal_size_bits; size_t bytes; // number of bytes of storage InternalType* buffer; // pointer to storage managed by block store }; // 1D codec template class generic1 : public generic_base<1, ExternalType, InternalType> { public: // encode contiguous 1D block size_t encode_block(bitstream_offset offset, uint shape, const ExternalType* block) const { return shape ? encode_block_strided(offset, shape, block, 1) : encode_block(offset, block); } // decode contiguous 1D block size_t decode_block(bitstream_offset offset, uint shape, ExternalType* block) const { return shape ? decode_block_strided(offset, shape, block, 1) : decode_block(offset, block); } // encode 1D block from strided storage size_t encode_block_strided(bitstream_offset offset, uint shape, const ExternalType* p, ptrdiff_t sx) const { InternalType* q = begin(offset); size_t nx = 4; if (shape) { nx -= shape & 3u; shape >>= 2; } for (size_t x = 0; x < nx; x++, p += sx, q++) *q = static_cast(*p); return block_size_bits; } // decode 1D block to strided storage size_t decode_block_strided(bitstream_offset offset, uint shape, ExternalType* p, ptrdiff_t sx) const { const InternalType* q = begin(offset); size_t nx = 4; if (shape) { nx -= shape & 3u; shape >>= 2; } for (size_t x = 0; x < nx; x++, p += sx, q++) *p = static_cast(*q); return block_size_bits; } protected: using generic_base<1, ExternalType, InternalType>::begin; using generic_base<1, ExternalType, InternalType>::encode_block; using generic_base<1, ExternalType, InternalType>::decode_block; using generic_base<1, ExternalType, InternalType>::block_size_bits; }; // 2D codec template class generic2 : public generic_base<2, ExternalType, InternalType> { public: // encode contiguous 2D block size_t encode_block(bitstream_offset offset, uint shape, const ExternalType* block) const { return shape ? encode_block_strided(offset, shape, block, 1, 4) : encode_block(offset, block); } // decode contiguous 2D block size_t decode_block(bitstream_offset offset, uint shape, ExternalType* block) const { return shape ? decode_block_strided(offset, shape, block, 1, 4) : decode_block(offset, block); } // encode 2D block from strided storage size_t encode_block_strided(bitstream_offset offset, uint shape, const ExternalType* p, ptrdiff_t sx, ptrdiff_t sy) const { InternalType* q = begin(offset); size_t nx = 4; size_t ny = 4; if (shape) { nx -= shape & 3u; shape >>= 2; ny -= shape & 3u; shape >>= 2; } for (size_t y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx, q += 4 - nx) for (size_t x = 0; x < nx; x++, p += sx, q++) *q = static_cast(*p); return block_size_bits; } // decode 2D block to strided storage size_t decode_block_strided(bitstream_offset offset, uint shape, ExternalType* p, ptrdiff_t sx, ptrdiff_t sy) const { const InternalType* q = begin(offset); size_t nx = 4; size_t ny = 4; if (shape) { nx -= shape & 3u; shape >>= 2; ny -= shape & 3u; shape >>= 2; } for (size_t y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx, q += 4 - nx) for (size_t x = 0; x < nx; x++, p += sx, q++) *p = static_cast(*q); return block_size_bits; } protected: using generic_base<2, ExternalType, InternalType>::begin; using generic_base<2, ExternalType, InternalType>::encode_block; using generic_base<2, ExternalType, InternalType>::decode_block; using generic_base<2, ExternalType, InternalType>::block_size_bits; }; // 3D codec template class generic3 : public generic_base<3, ExternalType, InternalType> { public: // encode contiguous 3D block size_t encode_block(bitstream_offset offset, uint shape, const ExternalType* block) const { return shape ? encode_block_strided(offset, shape, block, 1, 4, 16) : encode_block(offset, block); } // decode contiguous 3D block size_t decode_block(bitstream_offset offset, uint shape, ExternalType* block) const { return shape ? decode_block_strided(offset, shape, block, 1, 4, 16) : decode_block(offset, block); } // encode 3D block from strided storage size_t encode_block_strided(bitstream_offset offset, uint shape, const ExternalType* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) const { InternalType* q = begin(offset); size_t nx = 4; size_t ny = 4; size_t nz = 4; if (shape) { nx -= shape & 3u; shape >>= 2; ny -= shape & 3u; shape >>= 2; nz -= shape & 3u; shape >>= 2; } for (size_t z = 0; z < nz; z++, p += sz - (ptrdiff_t)ny * sy, q += 16 - 4 * ny) for (size_t y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx, q += 4 - nx) for (size_t x = 0; x < nx; x++, p += sx, q++) *q = static_cast(*p); return block_size_bits; } // decode 3D block to strided storage size_t decode_block_strided(bitstream_offset offset, uint shape, ExternalType* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) const { const InternalType* q = begin(offset); size_t nx = 4; size_t ny = 4; size_t nz = 4; if (shape) { nx -= shape & 3u; shape >>= 2; ny -= shape & 3u; shape >>= 2; nz -= shape & 3u; shape >>= 2; } for (size_t z = 0; z < nz; z++, p += sz - (ptrdiff_t)ny * sy, q += 16 - 4 * ny) for (size_t y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx, q += 4 - nx) for (size_t x = 0; x < nx; x++, p += sx, q++) *p = static_cast(*q); return block_size_bits; } protected: using generic_base<3, ExternalType, InternalType>::begin; using generic_base<3, ExternalType, InternalType>::encode_block; using generic_base<3, ExternalType, InternalType>::decode_block; using generic_base<3, ExternalType, InternalType>::block_size_bits; }; // 4D codec template class generic4 : public generic_base<4, ExternalType, InternalType> { public: // encode contiguous 4D block size_t encode_block(bitstream_offset offset, uint shape, const ExternalType* block) const { return shape ? encode_block_strided(offset, shape, block, 1, 4, 16, 64) : encode_block(offset, block); } // decode contiguous 4D block size_t decode_block(bitstream_offset offset, uint shape, ExternalType* block) const { return shape ? decode_block_strided(offset, shape, block, 1, 4, 16, 64) : decode_block(offset, block); } // encode 4D block from strided storage size_t encode_block_strided(bitstream_offset offset, uint shape, const ExternalType* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) const { InternalType* q = begin(offset); size_t nx = 4; size_t ny = 4; size_t nz = 4; size_t nw = 4; if (shape) { nx -= shape & 3u; shape >>= 2; ny -= shape & 3u; shape >>= 2; nz -= shape & 3u; shape >>= 2; nw -= shape & 3u; shape >>= 2; } for (size_t w = 0; w < nw; w++, p += sw - (ptrdiff_t)nz * sz, q += 64 - 16 * nz) for (size_t z = 0; z < nz; z++, p += sz - (ptrdiff_t)ny * sy, q += 16 - 4 * ny) for (size_t y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx, q += 4 - nx) for (size_t x = 0; x < nx; x++, p += sx, q++) *q = static_cast(*p); return block_size_bits; } // decode 4D block to strided storage size_t decode_block_strided(bitstream_offset offset, uint shape, ExternalType* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) const { const InternalType* q = begin(offset); size_t nx = 4; size_t ny = 4; size_t nz = 4; size_t nw = 4; if (shape) { nx -= shape & 3u; shape >>= 2; ny -= shape & 3u; shape >>= 2; nz -= shape & 3u; shape >>= 2; nw -= shape & 3u; shape >>= 2; } for (size_t w = 0; w < nw; w++, p += sw - (ptrdiff_t)nz * sz, q += 64 - 16 * nz) for (size_t z = 0; z < nz; z++, p += sz - (ptrdiff_t)ny * sy, q += 16 - 4 * ny) for (size_t y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx, q += 4 - nx) for (size_t x = 0; x < nx; x++, p += sx, q++) *p = static_cast(*q); return block_size_bits; } protected: using generic_base<4, ExternalType, InternalType>::begin; using generic_base<4, ExternalType, InternalType>::encode_block; using generic_base<4, ExternalType, InternalType>::decode_block; using generic_base<4, ExternalType, InternalType>::block_size_bits; }; } // codec } // zfp #endif zfp-1.0.1/include/zfp/codec/zfpcodec.hpp000066400000000000000000000422751453723256400201420ustar00rootroot00000000000000#ifndef ZFP_ZFP_CODEC_HPP #define ZFP_ZFP_CODEC_HPP #include #include #include #include "zfp.h" #include "zfp.hpp" #include "zfp/internal/array/memory.hpp" #include "zfp/internal/array/traits.hpp" namespace zfp { namespace codec { // abstract base class for zfp coding of {float, double} x {1D, 2D, 3D, 4D} data template class zfp_base { protected: // default constructor zfp_base() : stream(zfp_stream_open(0)) #ifdef _OPENMP , thread_safety(false) #endif {} // destructor ~zfp_base() { close(); zfp_stream_close(stream); } public: // assignment operator--performs deep copy zfp_base& operator=(const zfp_base& codec) { if (this != &codec) deep_copy(codec); return *this; } // conservative buffer size for current codec settings size_t buffer_size(const zfp_field* field) const { // empty field case if (!field->nx && !field->ny && !field->nz && !field->nw) return 0; // variable-rate case if (zfp_stream_compression_mode(stream) != zfp_mode_fixed_rate) return zfp_stream_maximum_size(stream, field); // fixed-rate case: exclude header size_t blocks = zfp_field_blocks(field); return zfp::internal::round_up(blocks * stream->maxbits, stream_alignment()) / CHAR_BIT; } // open bit stream void open(void* data, size_t size) { zfp_stream_set_bit_stream(stream, stream_open(data, size)); } // close bit stream void close() { stream_close(zfp_stream_bit_stream(stream)); zfp_stream_set_bit_stream(stream, 0); } // compression mode zfp_mode mode() const { return zfp_stream_compression_mode(stream); } // rate in compressed bits/value (fixed-rate mode only) double rate() const { return zfp_stream_rate(stream, dims); } // precision in uncompressed bits/value (fixed-precision mode only) uint precision() const { return zfp_stream_precision(stream); } // accuracy as absolute error tolerance (fixed-accuracy mode only) double accuracy() const { return zfp_stream_accuracy(stream); } // compression parameters (all compression modes) void params(uint* minbits, uint* maxbits, uint* maxprec, int* minexp) const { zfp_stream_params(stream, minbits, maxbits, maxprec, minexp); } // enable reversible (lossless) mode void set_reversible() { zfp_stream_set_reversible(stream); } // set rate in compressed bits/value double set_rate(double rate, bool align) { return zfp_stream_set_rate(stream, rate, type, dims, align); } // set precision in uncompressed bits/value uint set_precision(uint precision) { return zfp_stream_set_precision(stream, precision); } // set accuracy as absolute error tolerance double set_accuracy(double tolerance) { return zfp_stream_set_accuracy(stream, tolerance); } // set expert mode parameters bool set_params(uint minbits, uint maxbits, uint maxprec, int maxexp) { return zfp_stream_set_params(stream, minbits, maxbits, maxprec, maxexp) == zfp_true; } // set thread safety mode #ifdef _OPENMP void set_thread_safety(bool safety) { thread_safety = safety; } #else void set_thread_safety(bool) {} #endif // byte size of codec data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; if (mask & ZFP_DATA_META) { size += sizeof(*stream); size += sizeof(*this); } return size; } // unit of allocated data in bytes static size_t alignment() { return stream_alignment() / CHAR_BIT; } static const zfp_type type = zfp::internal::trait::type; // scalar type // zfp::codec::zfp_base::header class for array (de)serialization #include "zfp/internal/codec/zfpheader.hpp" protected: // deep copy void deep_copy(const zfp_base& codec) { stream = zfp_stream_open(0); *stream = *codec.stream; stream->stream = 0; #ifdef _OPENMP thread_safety = codec.thread_safety; #endif } // make a thread-local copy of zfp stream and bit stream zfp_stream clone_stream() const { zfp_stream zfp = *stream; zfp.stream = stream_clone(zfp.stream); return zfp; } // encode full contiguous block size_t encode_block(bitstream_offset offset, const Scalar* block) const { if (thread_safety) { // make a thread-local copy of zfp stream and bit stream zfp_stream zfp = clone_stream(); size_t size = encode_block(&zfp, offset, block); stream_close(zfp.stream); return size; } else return encode_block(stream, offset, block); } // decode full contiguous block size_t decode_block(bitstream_offset offset, Scalar* block) const { if (thread_safety) { // make a thread-local copy of zfp stream and bit stream zfp_stream zfp = clone_stream(); size_t size = decode_block(&zfp, offset, block); stream_close(zfp.stream); return size; } else return decode_block(stream, offset, block); } // encode full contiguous block static size_t encode_block(zfp_stream* zfp, bitstream_offset offset, const Scalar* block) { stream_wseek(zfp->stream, offset); size_t size = zfp::encode_block(zfp, block); stream_flush(zfp->stream); return size; } // decode full contiguous block static size_t decode_block(zfp_stream* zfp, bitstream_offset offset, Scalar* block) { stream_rseek(zfp->stream, offset); size_t size = zfp::decode_block(zfp, block); stream_align(zfp->stream); return size; } zfp_stream* stream; // compressed zfp stream #ifdef _OPENMP bool thread_safety; // thread safety state #else static const bool thread_safety = false; // not needed without OpenMP #endif }; // 1D codec template class zfp1 : public zfp_base<1, Scalar> { public: // encode contiguous 1D block size_t encode_block(bitstream_offset offset, uint shape, const Scalar* block) const { return shape ? encode_block_strided(offset, shape, block, 1) : encode_block(offset, block); } // decode contiguous 1D block size_t decode_block(bitstream_offset offset, uint shape, Scalar* block) const { return shape ? decode_block_strided(offset, shape, block, 1) : decode_block(offset, block); } // encode 1D block from strided storage size_t encode_block_strided(bitstream_offset offset, uint shape, const Scalar* p, ptrdiff_t sx) const { if (thread_safety) { // thread-safe implementation zfp_stream zfp = clone_stream(); size_t size = encode_block_strided(&zfp, offset, shape, p, sx); stream_close(zfp.stream); return size; } else return encode_block_strided(stream, offset, shape, p, sx); } // decode 1D block to strided storage size_t decode_block_strided(bitstream_offset offset, uint shape, Scalar* p, ptrdiff_t sx) const { if (thread_safety) { // thread-safe implementation zfp_stream zfp = clone_stream(); size_t size = decode_block_strided(&zfp, offset, shape, p, sx); stream_close(zfp.stream); return size; } else return decode_block_strided(stream, offset, shape, p, sx); } protected: using zfp_base<1, Scalar>::clone_stream; using zfp_base<1, Scalar>::encode_block; using zfp_base<1, Scalar>::decode_block; using zfp_base<1, Scalar>::stream; using zfp_base<1, Scalar>::thread_safety; // encode 1D block from strided storage static size_t encode_block_strided(zfp_stream* zfp, bitstream_offset offset, uint shape, const Scalar* p, ptrdiff_t sx) { size_t size; stream_wseek(zfp->stream, offset); if (shape) { uint nx = 4 - (shape & 3u); shape >>= 2; size = zfp::encode_partial_block_strided(zfp, p, nx, sx); } else size = zfp::encode_block_strided(zfp, p, sx); stream_flush(zfp->stream); return size; } // decode 1D block to strided storage static size_t decode_block_strided(zfp_stream* zfp, bitstream_offset offset, uint shape, Scalar* p, ptrdiff_t sx) { size_t size; stream_rseek(zfp->stream, offset); if (shape) { uint nx = 4 - (shape & 3u); shape >>= 2; size = zfp::decode_partial_block_strided(zfp, p, nx, sx); } else size = zfp::decode_block_strided(zfp, p, sx); stream_align(zfp->stream); return size; } }; // 2D codec template class zfp2 : public zfp_base<2, Scalar> { public: // encode contiguous 2D block size_t encode_block(bitstream_offset offset, uint shape, const Scalar* block) const { return shape ? encode_block_strided(offset, shape, block, 1, 4) : encode_block(offset, block); } // decode contiguous 2D block size_t decode_block(bitstream_offset offset, uint shape, Scalar* block) const { return shape ? decode_block_strided(offset, shape, block, 1, 4) : decode_block(offset, block); } // encode 2D block from strided storage size_t encode_block_strided(bitstream_offset offset, uint shape, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy) const { if (thread_safety) { // thread-safe implementation zfp_stream zfp = clone_stream(); size_t size = encode_block_strided(&zfp, offset, shape, p, sx, sy); stream_close(zfp.stream); return size; } else return encode_block_strided(stream, offset, shape, p, sx, sy); } // decode 2D block to strided storage size_t decode_block_strided(bitstream_offset offset, uint shape, Scalar* p, ptrdiff_t sx, ptrdiff_t sy) const { if (thread_safety) { // thread-safe implementation zfp_stream zfp = clone_stream(); size_t size = decode_block_strided(&zfp, offset, shape, p, sx, sy); stream_close(zfp.stream); return size; } else return decode_block_strided(stream, offset, shape, p, sx, sy); } protected: using zfp_base<2, Scalar>::clone_stream; using zfp_base<2, Scalar>::encode_block; using zfp_base<2, Scalar>::decode_block; using zfp_base<2, Scalar>::stream; using zfp_base<2, Scalar>::thread_safety; // encode 2D block from strided storage static size_t encode_block_strided(zfp_stream* zfp, bitstream_offset offset, uint shape, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy) { size_t size; stream_wseek(zfp->stream, offset); if (shape) { uint nx = 4 - (shape & 3u); shape >>= 2; uint ny = 4 - (shape & 3u); shape >>= 2; size = zfp::encode_partial_block_strided(zfp, p, nx, ny, sx, sy); } else size = zfp::encode_block_strided(zfp, p, sx, sy); stream_flush(zfp->stream); return size; } // decode 2D block to strided storage static size_t decode_block_strided(zfp_stream* zfp, bitstream_offset offset, uint shape, Scalar* p, ptrdiff_t sx, ptrdiff_t sy) { size_t size; stream_rseek(zfp->stream, offset); if (shape) { uint nx = 4 - (shape & 3u); shape >>= 2; uint ny = 4 - (shape & 3u); shape >>= 2; size = zfp::decode_partial_block_strided(zfp, p, nx, ny, sx, sy); } else size = zfp::decode_block_strided(zfp, p, sx, sy); stream_align(zfp->stream); return size; } }; // 3D codec template class zfp3 : public zfp_base<3, Scalar> { public: // encode contiguous 3D block size_t encode_block(bitstream_offset offset, uint shape, const Scalar* block) const { return shape ? encode_block_strided(offset, shape, block, 1, 4, 16) : encode_block(offset, block); } // decode contiguous 3D block size_t decode_block(bitstream_offset offset, uint shape, Scalar* block) const { return shape ? decode_block_strided(offset, shape, block, 1, 4, 16) : decode_block(offset, block); } // encode 3D block from strided storage size_t encode_block_strided(bitstream_offset offset, uint shape, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) const { if (thread_safety) { // thread-safe implementation zfp_stream zfp = clone_stream(); size_t size = encode_block_strided(&zfp, offset, shape, p, sx, sy, sz); stream_close(zfp.stream); return size; } else return encode_block_strided(stream, offset, shape, p, sx, sy, sz); } // decode 3D block to strided storage size_t decode_block_strided(bitstream_offset offset, uint shape, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) const { if (thread_safety) { // thread-safe implementation zfp_stream zfp = clone_stream(); size_t size = decode_block_strided(&zfp, offset, shape, p, sx, sy, sz); stream_close(zfp.stream); return size; } else return decode_block_strided(stream, offset, shape, p, sx, sy, sz); } protected: using zfp_base<3, Scalar>::clone_stream; using zfp_base<3, Scalar>::encode_block; using zfp_base<3, Scalar>::decode_block; using zfp_base<3, Scalar>::stream; using zfp_base<3, Scalar>::thread_safety; // encode 3D block from strided storage static size_t encode_block_strided(zfp_stream* zfp, bitstream_offset offset, uint shape, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { size_t size; stream_wseek(zfp->stream, offset); if (shape) { uint nx = 4 - (shape & 3u); shape >>= 2; uint ny = 4 - (shape & 3u); shape >>= 2; uint nz = 4 - (shape & 3u); shape >>= 2; size = zfp::encode_partial_block_strided(zfp, p, nx, ny, nz, sx, sy, sz); } else size = zfp::encode_block_strided(zfp, p, sx, sy, sz); stream_flush(zfp->stream); return size; } // decode 3D block to strided storage static size_t decode_block_strided(zfp_stream* zfp, bitstream_offset offset, uint shape, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { size_t size; stream_rseek(zfp->stream, offset); if (shape) { uint nx = 4 - (shape & 3u); shape >>= 2; uint ny = 4 - (shape & 3u); shape >>= 2; uint nz = 4 - (shape & 3u); shape >>= 2; size = zfp::decode_partial_block_strided(zfp, p, nx, ny, nz, sx, sy, sz); } else size = zfp::decode_block_strided(zfp, p, sx, sy, sz); stream_align(zfp->stream); return size; } }; // 4D codec template class zfp4 : public zfp_base<4, Scalar> { public: // encode contiguous 4D block size_t encode_block(bitstream_offset offset, uint shape, const Scalar* block) const { return shape ? encode_block_strided(offset, shape, block, 1, 4, 16, 64) : encode_block(offset, block); } // decode contiguous 4D block size_t decode_block(bitstream_offset offset, uint shape, Scalar* block) const { return shape ? decode_block_strided(offset, shape, block, 1, 4, 16, 64) : decode_block(offset, block); } // encode 4D block from strided storage size_t encode_block_strided(bitstream_offset offset, uint shape, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) const { if (thread_safety) { // thread-safe implementation zfp_stream zfp = clone_stream(); size_t size = encode_block_strided(&zfp, offset, shape, p, sx, sy, sz, sw); stream_close(zfp.stream); return size; } else return encode_block_strided(stream, offset, shape, p, sx, sy, sz, sw); } // decode 4D block to strided storage size_t decode_block_strided(bitstream_offset offset, uint shape, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) const { if (thread_safety) { // thread-safe implementation zfp_stream zfp = clone_stream(); size_t size = decode_block_strided(&zfp, offset, shape, p, sx, sy, sz, sw); stream_close(zfp.stream); return size; } else return decode_block_strided(stream, offset, shape, p, sx, sy, sz, sw); } protected: using zfp_base<4, Scalar>::clone_stream; using zfp_base<4, Scalar>::encode_block; using zfp_base<4, Scalar>::decode_block; using zfp_base<4, Scalar>::stream; using zfp_base<4, Scalar>::thread_safety; // encode 4D block from strided storage static size_t encode_block_strided(zfp_stream* zfp, bitstream_offset offset, uint shape, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { size_t size; stream_wseek(zfp->stream, offset); if (shape) { uint nx = 4 - (shape & 3u); shape >>= 2; uint ny = 4 - (shape & 3u); shape >>= 2; uint nz = 4 - (shape & 3u); shape >>= 2; uint nw = 4 - (shape & 3u); shape >>= 2; size = zfp::encode_partial_block_strided(zfp, p, nx, ny, nz, nw, sx, sy, sz, sw); } else size = zfp::encode_block_strided(zfp, p, sx, sy, sz, sw); stream_flush(zfp->stream); return size; } // decode 4D block to strided storage static size_t decode_block_strided(zfp_stream* zfp, bitstream_offset offset, uint shape, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { size_t size; stream_rseek(zfp->stream, offset); if (shape) { uint nx = 4 - (shape & 3u); shape >>= 2; uint ny = 4 - (shape & 3u); shape >>= 2; uint nz = 4 - (shape & 3u); shape >>= 2; uint nw = 4 - (shape & 3u); shape >>= 2; size = zfp::decode_partial_block_strided(zfp, p, nx, ny, nz, nw, sx, sy, sz, sw); } else size = zfp::decode_block_strided(zfp, p, sx, sy, sz, sw); stream_align(zfp->stream); return size; } }; } // codec } // zfp #endif zfp-1.0.1/include/zfp/constarray1.hpp000066400000000000000000000165731453723256400175400ustar00rootroot00000000000000#ifndef ZFP_CONSTARRAY1_HPP #define ZFP_CONSTARRAY1_HPP #include #include #include #include "zfp/array.hpp" #include "zfp/index.hpp" #include "zfp/codec/zfpcodec.hpp" #include "zfp/internal/array/cache1.hpp" #include "zfp/internal/array/handle1.hpp" #include "zfp/internal/array/iterator1.hpp" #include "zfp/internal/array/pointer1.hpp" #include "zfp/internal/array/reference1.hpp" #include "zfp/internal/array/store1.hpp" #include "zfp/internal/array/view1.hpp" namespace zfp { // compressed 1D array of scalars template < typename Scalar, class Codec = zfp::codec::zfp1, class Index = zfp::index::hybrid4 > class const_array1 : public array { public: // types utilized by nested classes typedef const_array1 container_type; typedef Scalar value_type; typedef Codec codec_type; typedef Index index_type; typedef zfp::internal::BlockStore1 store_type; typedef zfp::internal::BlockCache1 cache_type; typedef typename Codec::header header; // accessor classes typedef zfp::internal::dim1::const_reference const_reference; typedef zfp::internal::dim1::const_pointer const_pointer; typedef zfp::internal::dim1::const_iterator const_iterator; typedef zfp::internal::dim1::const_view const_view; typedef zfp::internal::dim1::private_const_view private_const_view; // default constructor const_array1() : array(1, Codec::type), cache(store) {} // constructor of nx-element array using given configuration, at least // cache_size bytes of cache, and optionally initialized from flat array p const_array1(size_t nx, const zfp_config& config, const value_type* p = 0, size_t cache_size = 0) : array(1, Codec::type), store(nx, config), cache(store, cache_size) { this->nx = nx; set(p); } // copy constructor--performs a deep copy const_array1(const const_array1& a) : cache(store) { deep_copy(a); } // virtual destructor virtual ~const_array1() {} // assignment operator--performs a deep copy const_array1& operator=(const const_array1& a) { if (this != &a) deep_copy(a); return *this; } // total number of elements in array size_t size() const { return nx; } // array dimensions size_t size_x() const { return nx; } // resize the array (all previously stored data will be lost) void resize(size_t nx, bool clear = true) { cache.clear(); this->nx = nx; store.resize(nx, clear); } // compression mode zfp_mode mode() const { return store.mode(); } // rate in compressed bits per value (fixed-rate mode only) double rate() const { return store.rate(); } // precision in uncompressed bits per value (fixed-precision mode only) uint precision() const { return store.precision(); } // accuracy as absolute error tolerance (fixed-accuracy mode only) double accuracy() const { return store.accuracy(); } // compression parameters (all compression modes) void params(uint* minbits, uint* maxbits, uint* maxprec, int* minexp) const { return store.params(minbits, maxbits, maxprec, minexp); } // set rate in compressed bits per value double set_rate(double rate) { cache.clear(); return store.set_rate(rate, false); } // set precision in uncompressed bits per value uint set_precision(uint precision) { cache.clear(); return store.set_precision(precision); } // set accuracy as absolute error tolerance double set_accuracy(double tolerance) { cache.clear(); return store.set_accuracy(tolerance); } // enable reversible (lossless) mode void set_reversible() { cache.clear(); store.set_reversible(); } // set expert mode compression parameters bool set_params(uint minbits, uint maxbits, uint maxprec, int minexp) { cache.clear(); return store.set_params(minbits, maxbits, maxprec, minexp); } // set compression mode and parameters void set_config(const zfp_config& config) { cache.clear(); store.set_config(config); } // byte size of array data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += store.size_bytes(mask); size += cache.size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // number of bytes of compressed data size_t compressed_size() const { return store.compressed_size(); } // pointer to compressed data for read or write access void* compressed_data() const { cache.flush(); return store.compressed_data(); } // cache size in number of bytes size_t cache_size() const { return cache.size(); } // set minimum cache size in bytes (array dimensions must be known) void set_cache_size(size_t bytes) { cache.flush(); cache.resize(bytes); } // empty cache without compressing modified cached blocks void clear_cache() const { cache.clear(); } // decompress array and store at p void get(value_type* p) const { const size_t bx = store.block_size_x(); const ptrdiff_t sx = 1; size_t block_index = 0; for (size_t i = 0; i < bx; i++, p += 4) cache.get_block(block_index++, p, sx); } // initialize array by copying and compressing data stored at p void set(const value_type* p, bool compact = true) { cache.clear(); store.clear(); const size_t bx = store.block_size_x(); size_t block_index = 0; if (p) { // compress data stored at p const ptrdiff_t sx = 1; for (size_t i = 0; i < bx; i++, p += 4) store.encode(block_index++, p, sx); } else { // zero-initialize array const value_type block[4] = {}; while (block_index < bx) store.encode(block_index++, block); } store.flush(); if (compact) store.compact(); } // accessor const_reference operator()(size_t i) const { return const_reference(const_cast(this), i); } // flat index accessor const_reference operator[](size_t index) const { return const_reference(const_cast(this), index); } // random access iterators const_iterator cbegin() const { return const_iterator(this, 0); } const_iterator cend() const { return const_iterator(this, nx); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } protected: friend class zfp::internal::dim1::const_handle; friend class zfp::internal::dim1::const_reference; friend class zfp::internal::dim1::const_pointer; friend class zfp::internal::dim1::const_iterator; friend class zfp::internal::dim1::const_view; friend class zfp::internal::dim1::private_const_view; // perform a deep copy void deep_copy(const const_array1& a) { // copy base class members array::deep_copy(a); // copy persistent storage store.deep_copy(a.store); // copy cached data cache.deep_copy(a.cache); } // global index bounds size_t min_x() const { return 0; } size_t max_x() const { return nx; } // inspector value_type get(size_t i) const { return cache.get(i); } store_type store; // persistent storage of compressed blocks cache_type cache; // cache of decompressed blocks }; typedef const_array1 const_array1f; typedef const_array1 const_array1d; } #endif zfp-1.0.1/include/zfp/constarray2.hpp000066400000000000000000000201651453723256400175310ustar00rootroot00000000000000#ifndef ZFP_CONSTARRAY2_HPP #define ZFP_CONSTARRAY2_HPP #include #include #include #include "zfp/array.hpp" #include "zfp/index.hpp" #include "zfp/codec/zfpcodec.hpp" #include "zfp/internal/array/cache2.hpp" #include "zfp/internal/array/handle2.hpp" #include "zfp/internal/array/iterator2.hpp" #include "zfp/internal/array/pointer2.hpp" #include "zfp/internal/array/reference2.hpp" #include "zfp/internal/array/store2.hpp" #include "zfp/internal/array/view2.hpp" namespace zfp { // compressed 2D array of scalars template < typename Scalar, class Codec = zfp::codec::zfp2, class Index = zfp::index::hybrid4 > class const_array2 : public array { public: // types utilized by nested classes typedef const_array2 container_type; typedef Scalar value_type; typedef Codec codec_type; typedef Index index_type; typedef zfp::internal::BlockStore2 store_type; typedef zfp::internal::BlockCache2 cache_type; typedef typename Codec::header header; // accessor classes typedef zfp::internal::dim2::const_reference const_reference; typedef zfp::internal::dim2::const_pointer const_pointer; typedef zfp::internal::dim2::const_iterator const_iterator; typedef zfp::internal::dim2::const_view const_view; typedef zfp::internal::dim2::private_const_view private_const_view; // default constructor const_array2() : array(2, Codec::type), cache(store) {} // constructor of nx * ny array using given configuration, at least // cache_size bytes of cache, and optionally initialized from flat array p const_array2(size_t nx, size_t ny, const zfp_config& config, const value_type* p = 0, size_t cache_size = 0) : array(2, Codec::type), store(nx, ny, config), cache(store, cache_size) { this->nx = nx; this->ny = ny; set(p); } // copy constructor--performs a deep copy const_array2(const const_array2& a) : cache(store) { deep_copy(a); } // virtual destructor virtual ~const_array2() {} // assignment operator--performs a deep copy const_array2& operator=(const const_array2& a) { if (this != &a) deep_copy(a); return *this; } // total number of elements in array size_t size() const { return nx * ny; } // array dimensions size_t size_x() const { return nx; } size_t size_y() const { return ny; } // resize the array (all previously stored data will be lost) void resize(size_t nx, size_t ny, bool clear = true) { cache.clear(); this->nx = nx; this->ny = ny; store.resize(nx, ny, clear); } // compression mode zfp_mode mode() const { return store.mode(); } // rate in compressed bits per value (fixed-rate mode only) double rate() const { return store.rate(); } // precision in uncompressed bits per value (fixed-precision mode only) uint precision() const { return store.precision(); } // accuracy as absolute error tolerance (fixed-accuracy mode only) double accuracy() const { return store.accuracy(); } // compression parameters (all compression modes) void params(uint* minbits, uint* maxbits, uint* maxprec, int* minexp) const { return store.params(minbits, maxbits, maxprec, minexp); } // set rate in compressed bits per value double set_rate(double rate) { cache.clear(); return store.set_rate(rate, false); } // set precision in uncompressed bits per value uint set_precision(uint precision) { cache.clear(); return store.set_precision(precision); } // set accuracy as absolute error tolerance double set_accuracy(double tolerance) { cache.clear(); return store.set_accuracy(tolerance); } // enable reversible (lossless) mode void set_reversible() { cache.clear(); store.set_reversible(); } // set expert mode compression parameters bool set_params(uint minbits, uint maxbits, uint maxprec, int minexp) { cache.clear(); return store.set_params(minbits, maxbits, maxprec, minexp); } // set compression mode and parameters void set_config(const zfp_config& config) { cache.clear(); store.set_config(config); } // byte size of array data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += store.size_bytes(mask); size += cache.size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // number of bytes of compressed data size_t compressed_size() const { return store.compressed_size(); } // pointer to compressed data for read or write access void* compressed_data() const { cache.flush(); return store.compressed_data(); } // cache size in number of bytes size_t cache_size() const { return cache.size(); } // set minimum cache size in bytes (array dimensions must be known) void set_cache_size(size_t bytes) { cache.flush(); cache.resize(bytes); } // empty cache without compressing modified cached blocks void clear_cache() const { cache.clear(); } // decompress array and store at p void get(value_type* p) const { const size_t bx = store.block_size_x(); const size_t by = store.block_size_y(); const ptrdiff_t sx = 1; const ptrdiff_t sy = static_cast(nx); size_t block_index = 0; for (size_t j = 0; j < by; j++, p += 4 * sx * (nx - bx)) for (size_t i = 0; i < bx; i++, p += 4) cache.get_block(block_index++, p, sx, sy); } // initialize array by copying and compressing data stored at p void set(const value_type* p, bool compact = true) { cache.clear(); store.clear(); const size_t bx = store.block_size_x(); const size_t by = store.block_size_y(); size_t block_index = 0; if (p) { // compress data stored at p const ptrdiff_t sx = 1; const ptrdiff_t sy = static_cast(nx); for (size_t j = 0; j < by; j++, p += 4 * sx * (nx - bx)) for (size_t i = 0; i < bx; i++, p += 4) store.encode(block_index++, p, sx, sy); } else { // zero-initialize array const value_type block[4 * 4] = {}; while (block_index < bx * by) store.encode(block_index++, block); } store.flush(); if (compact) store.compact(); } // (i, j) accessor const_reference operator()(size_t i, size_t j) const { return const_reference(const_cast(this), i, j); } // flat index accessor const_reference operator[](size_t index) const { size_t i, j; ij(i, j, index); return const_reference(const_cast(this), i, j); } // random access iterators const_iterator cbegin() const { return const_iterator(this, 0, 0); } const_iterator cend() const { return const_iterator(this, 0, ny); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } protected: friend class zfp::internal::dim2::const_handle; friend class zfp::internal::dim2::const_reference; friend class zfp::internal::dim2::const_pointer; friend class zfp::internal::dim2::const_iterator; friend class zfp::internal::dim2::const_view; friend class zfp::internal::dim2::private_const_view; // perform a deep copy void deep_copy(const const_array2& a) { // copy base class members array::deep_copy(a); // copy persistent storage store.deep_copy(a.store); // copy cached data cache.deep_copy(a.cache); } // global index bounds size_t min_x() const { return 0; } size_t max_x() const { return nx; } size_t min_y() const { return 0; } size_t max_y() const { return ny; } // inspector value_type get(size_t i, size_t j) const { return cache.get(i, j); } // convert flat index to (i, j) void ij(size_t& i, size_t& j, size_t index) const { i = index % nx; index /= nx; j = index % ny; } store_type store; // persistent storage of compressed blocks cache_type cache; // cache of decompressed blocks }; typedef const_array2 const_array2f; typedef const_array2 const_array2d; } #endif zfp-1.0.1/include/zfp/constarray3.hpp000066400000000000000000000213641453723256400175340ustar00rootroot00000000000000#ifndef ZFP_CONSTARRAY3_HPP #define ZFP_CONSTARRAY3_HPP #include #include #include #include "zfp/array.hpp" #include "zfp/index.hpp" #include "zfp/codec/zfpcodec.hpp" #include "zfp/internal/array/cache3.hpp" #include "zfp/internal/array/handle3.hpp" #include "zfp/internal/array/iterator3.hpp" #include "zfp/internal/array/pointer3.hpp" #include "zfp/internal/array/reference3.hpp" #include "zfp/internal/array/store3.hpp" #include "zfp/internal/array/view3.hpp" namespace zfp { // compressed 3D array of scalars template < typename Scalar, class Codec = zfp::codec::zfp3, class Index = zfp::index::hybrid4 > class const_array3 : public array { public: // types utilized by nested classes typedef const_array3 container_type; typedef Scalar value_type; typedef Codec codec_type; typedef Index index_type; typedef zfp::internal::BlockStore3 store_type; typedef zfp::internal::BlockCache3 cache_type; typedef typename Codec::header header; // accessor classes typedef zfp::internal::dim3::const_reference const_reference; typedef zfp::internal::dim3::const_pointer const_pointer; typedef zfp::internal::dim3::const_iterator const_iterator; typedef zfp::internal::dim3::const_view const_view; typedef zfp::internal::dim3::private_const_view private_const_view; // default constructor const_array3() : array(3, Codec::type), cache(store) {} // constructor of nx * ny * nz array using given configuration, at least // cache_size bytes of cache, and optionally initialized from flat array p const_array3(size_t nx, size_t ny, size_t nz, const zfp_config& config, const value_type* p = 0, size_t cache_size = 0) : array(3, Codec::type), store(nx, ny, nz, config), cache(store, cache_size) { this->nx = nx; this->ny = ny; this->nz = nz; set(p); } // copy constructor--performs a deep copy const_array3(const const_array3& a) : cache(store) { deep_copy(a); } // virtual destructor virtual ~const_array3() {} // assignment operator--performs a deep copy const_array3& operator=(const const_array3& a) { if (this != &a) deep_copy(a); return *this; } // total number of elements in array size_t size() const { return nx * ny * nz; } // array dimensions size_t size_x() const { return nx; } size_t size_y() const { return ny; } size_t size_z() const { return nz; } // resize the array (all previously stored data will be lost) void resize(size_t nx, size_t ny, size_t nz, bool clear = true) { cache.clear(); this->nx = nx; this->ny = ny; this->nz = nz; store.resize(nx, ny, nz, clear); } // compression mode zfp_mode mode() const { return store.mode(); } // rate in compressed bits per value (fixed-rate mode only) double rate() const { return store.rate(); } // precision in uncompressed bits per value (fixed-precision mode only) uint precision() const { return store.precision(); } // accuracy as absolute error tolerance (fixed-accuracy mode only) double accuracy() const { return store.accuracy(); } // compression parameters (all compression modes) void params(uint* minbits, uint* maxbits, uint* maxprec, int* minexp) const { return store.params(minbits, maxbits, maxprec, minexp); } // set rate in compressed bits per value double set_rate(double rate) { cache.clear(); return store.set_rate(rate, false); } // set precision in uncompressed bits per value uint set_precision(uint precision) { cache.clear(); return store.set_precision(precision); } // set accuracy as absolute error tolerance double set_accuracy(double tolerance) { cache.clear(); return store.set_accuracy(tolerance); } // enable reversible (lossless) mode void set_reversible() { cache.clear(); store.set_reversible(); } // set expert mode compression parameters bool set_params(uint minbits, uint maxbits, uint maxprec, int minexp) { cache.clear(); return store.set_params(minbits, maxbits, maxprec, minexp); } // set compression mode and parameters void set_config(const zfp_config& config) { cache.clear(); store.set_config(config); } // byte size of array data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += store.size_bytes(mask); size += cache.size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // number of bytes of compressed data size_t compressed_size() const { return store.compressed_size(); } // pointer to compressed data for read or write access void* compressed_data() const { cache.flush(); return store.compressed_data(); } // cache size in number of bytes size_t cache_size() const { return cache.size(); } // set minimum cache size in bytes (array dimensions must be known) void set_cache_size(size_t bytes) { cache.flush(); cache.resize(bytes); } // empty cache without compressing modified cached blocks void clear_cache() const { cache.clear(); } // decompress array and store at p void get(value_type* p) const { const size_t bx = store.block_size_x(); const size_t by = store.block_size_y(); const size_t bz = store.block_size_z(); const ptrdiff_t sx = 1; const ptrdiff_t sy = static_cast(nx); const ptrdiff_t sz = static_cast(nx * ny); size_t block_index = 0; for (size_t k = 0; k < bz; k++, p += 4 * sy * (ny - by)) for (size_t j = 0; j < by; j++, p += 4 * sx * (nx - bx)) for (size_t i = 0; i < bx; i++, p += 4) cache.get_block(block_index++, p, sx, sy, sz); } // initialize array by copying and compressing data stored at p void set(const value_type* p, bool compact = true) { cache.clear(); store.clear(); const size_t bx = store.block_size_x(); const size_t by = store.block_size_y(); const size_t bz = store.block_size_z(); size_t block_index = 0; if (p) { // compress data stored at p const ptrdiff_t sx = 1; const ptrdiff_t sy = static_cast(nx); const ptrdiff_t sz = static_cast(nx * ny); for (size_t k = 0; k < bz; k++, p += 4 * sy * (ny - by)) for (size_t j = 0; j < by; j++, p += 4 * sx * (nx - bx)) for (size_t i = 0; i < bx; i++, p += 4) store.encode(block_index++, p, sx, sy, sz); } else { // zero-initialize array const value_type block[4 * 4 * 4] = {}; while (block_index < bx * by * bz) store.encode(block_index++, block); } store.flush(); if (compact) store.compact(); } // (i, j, k) accessor const_reference operator()(size_t i, size_t j, size_t k) const { return const_reference(const_cast(this), i, j, k); } // flat index accessor const_reference operator[](size_t index) const { size_t i, j, k; ijk(i, j, k, index); return const_reference(const_cast(this), i, j, k); } // random access iterators const_iterator cbegin() const { return const_iterator(this, 0, 0, 0); } const_iterator cend() const { return const_iterator(this, 0, 0, nz); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } protected: friend class zfp::internal::dim3::const_handle; friend class zfp::internal::dim3::const_reference; friend class zfp::internal::dim3::const_pointer; friend class zfp::internal::dim3::const_iterator; friend class zfp::internal::dim3::const_view; friend class zfp::internal::dim3::private_const_view; // perform a deep copy void deep_copy(const const_array3& a) { // copy base class members array::deep_copy(a); // copy persistent storage store.deep_copy(a.store); // copy cached data cache.deep_copy(a.cache); } // global index bounds size_t min_x() const { return 0; } size_t max_x() const { return nx; } size_t min_y() const { return 0; } size_t max_y() const { return ny; } size_t min_z() const { return 0; } size_t max_z() const { return nz; } // inspector value_type get(size_t i, size_t j, size_t k) const { return cache.get(i, j, k); } // convert flat index to (i, j, k) void ijk(size_t& i, size_t& j, size_t& k, size_t index) const { i = index % nx; index /= nx; j = index % ny; index /= ny; k = index; } store_type store; // persistent storage of compressed blocks cache_type cache; // cache of decompressed blocks }; typedef const_array3 const_array3f; typedef const_array3 const_array3d; } #endif zfp-1.0.1/include/zfp/constarray4.hpp000066400000000000000000000226061453723256400175350ustar00rootroot00000000000000#ifndef ZFP_CONSTARRAY4_HPP #define ZFP_CONSTARRAY4_HPP #include #include #include #include "zfp/array.hpp" #include "zfp/index.hpp" #include "zfp/codec/zfpcodec.hpp" #include "zfp/internal/array/cache4.hpp" #include "zfp/internal/array/handle4.hpp" #include "zfp/internal/array/iterator4.hpp" #include "zfp/internal/array/pointer4.hpp" #include "zfp/internal/array/reference4.hpp" #include "zfp/internal/array/store4.hpp" #include "zfp/internal/array/view4.hpp" namespace zfp { // compressed 4D array of scalars template < typename Scalar, class Codec = zfp::codec::zfp4, class Index = zfp::index::hybrid4 > class const_array4 : public array { public: // types utilized by nested classes typedef const_array4 container_type; typedef Scalar value_type; typedef Codec codec_type; typedef Index index_type; typedef zfp::internal::BlockStore4 store_type; typedef zfp::internal::BlockCache4 cache_type; typedef typename Codec::header header; // accessor classes typedef zfp::internal::dim4::const_reference const_reference; typedef zfp::internal::dim4::const_pointer const_pointer; typedef zfp::internal::dim4::const_iterator const_iterator; typedef zfp::internal::dim4::const_view const_view; typedef zfp::internal::dim4::private_const_view private_const_view; // default constructor const_array4() : array(4, Codec::type), cache(store) {} // constructor of nx * ny * nz * nw array using given configuration, at least // cache_size bytes of cache, and optionally initialized from flat array p const_array4(size_t nx, size_t ny, size_t nz, size_t nw, const zfp_config& config, const value_type* p = 0, size_t cache_size = 0) : array(4, Codec::type), store(nx, ny, nz, nw, config), cache(store, cache_size) { this->nx = nx; this->ny = ny; this->nz = nz; this->nw = nw; set(p); } // copy constructor--performs a deep copy const_array4(const const_array4& a) : cache(store) { deep_copy(a); } // virtual destructor virtual ~const_array4() {} // assignment operator--performs a deep copy const_array4& operator=(const const_array4& a) { if (this != &a) deep_copy(a); return *this; } // total number of elements in array size_t size() const { return nx * ny * nz * nw; } // array dimensions size_t size_x() const { return nx; } size_t size_y() const { return ny; } size_t size_z() const { return nz; } size_t size_w() const { return nw; } // resize the array (all previously stored data will be lost) void resize(size_t nx, size_t ny, size_t nz, size_t nw, bool clear = true) { cache.clear(); this->nx = nx; this->ny = ny; this->nz = nz; this->nw = nw; store.resize(nx, ny, nz, nw, clear); } // compression mode zfp_mode mode() const { return store.mode(); } // rate in compressed bits per value (fixed-rate mode only) double rate() const { return store.rate(); } // precision in uncompressed bits per value (fixed-precision mode only) uint precision() const { return store.precision(); } // accuracy as absolute error tolerance (fixed-accuracy mode only) double accuracy() const { return store.accuracy(); } // compression parameters (all compression modes) void params(uint* minbits, uint* maxbits, uint* maxprec, int* minexp) const { return store.params(minbits, maxbits, maxprec, minexp); } // set rate in compressed bits per value double set_rate(double rate) { cache.clear(); return store.set_rate(rate, false); } // set precision in uncompressed bits per value uint set_precision(uint precision) { cache.clear(); return store.set_precision(precision); } // set accuracy as absolute error tolerance double set_accuracy(double tolerance) { cache.clear(); return store.set_accuracy(tolerance); } // enable reversible (lossless) mode void set_reversible() { cache.clear(); store.set_reversible(); } // set expert mode compression parameters bool set_params(uint minbits, uint maxbits, uint maxprec, int minexp) { cache.clear(); return store.set_params(minbits, maxbits, maxprec, minexp); } // set compression mode and parameters void set_config(const zfp_config& config) { cache.clear(); store.set_config(config); } // byte size of array data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += store.size_bytes(mask); size += cache.size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // number of bytes of compressed data size_t compressed_size() const { return store.compressed_size(); } // pointer to compressed data for read or write access void* compressed_data() const { cache.flush(); return store.compressed_data(); } // cache size in number of bytes size_t cache_size() const { return cache.size(); } // set minimum cache size in bytes (array dimensions must be known) void set_cache_size(size_t bytes) { cache.flush(); cache.resize(bytes); } // empty cache without compressing modified cached blocks void clear_cache() const { cache.clear(); } // decompress array and store at p void get(value_type* p) const { const size_t bx = store.block_size_x(); const size_t by = store.block_size_y(); const size_t bz = store.block_size_z(); const size_t bw = store.block_size_w(); const ptrdiff_t sx = 1; const ptrdiff_t sy = static_cast(nx); const ptrdiff_t sz = static_cast(nx * ny); const ptrdiff_t sw = static_cast(nx * ny * nz); size_t block_index = 0; for (size_t l = 0; l < bw; l++, p += 4 * sz * (nz - bz)) for (size_t k = 0; k < bz; k++, p += 4 * sy * (ny - by)) for (size_t j = 0; j < by; j++, p += 4 * sx * (nx - bx)) for (size_t i = 0; i < bx; i++, p += 4) cache.get_block(block_index++, p, sx, sy, sz, sw); } // initialize array by copying and compressing data stored at p void set(const value_type* p, bool compact = true) { cache.clear(); store.clear(); const size_t bx = store.block_size_x(); const size_t by = store.block_size_y(); const size_t bz = store.block_size_z(); const size_t bw = store.block_size_w(); size_t block_index = 0; if (p) { // compress data stored at p const ptrdiff_t sx = 1; const ptrdiff_t sy = static_cast(nx); const ptrdiff_t sz = static_cast(nx * ny); const ptrdiff_t sw = static_cast(nx * ny * nz); for (size_t l = 0; l < bw; l++, p += 4 * sz * (nz - bz)) for (size_t k = 0; k < bz; k++, p += 4 * sy * (ny - by)) for (size_t j = 0; j < by; j++, p += 4 * sx * (nx - bx)) for (size_t i = 0; i < bx; i++, p += 4) store.encode(block_index++, p, sx, sy, sz, sw); } else { // zero-initialize array const value_type block[4 * 4 * 4 * 4] = {}; while (block_index < bx * by * bz * bw) store.encode(block_index++, block); } store.flush(); if (compact) store.compact(); } // (i, j, k, l) accessor const_reference operator()(size_t i, size_t j, size_t k, size_t l) const { return const_reference(const_cast(this), i, j, k, l); } // flat index accessor const_reference operator[](size_t index) const { size_t i, j, k, l; ijkl(i, j, k, l, index); return const_reference(const_cast(this), i, j, k, l); } // random access iterators const_iterator cbegin() const { return const_iterator(this, 0, 0, 0, 0); } const_iterator cend() const { return const_iterator(this, 0, 0, 0, nw); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } protected: friend class zfp::internal::dim4::const_handle; friend class zfp::internal::dim4::const_reference; friend class zfp::internal::dim4::const_pointer; friend class zfp::internal::dim4::const_iterator; friend class zfp::internal::dim4::const_view; friend class zfp::internal::dim4::private_const_view; // perform a deep copy void deep_copy(const const_array4& a) { // copy base class members array::deep_copy(a); // copy persistent storage store.deep_copy(a.store); // copy cached data cache.deep_copy(a.cache); } // global index bounds size_t min_x() const { return 0; } size_t max_x() const { return nx; } size_t min_y() const { return 0; } size_t max_y() const { return ny; } size_t min_z() const { return 0; } size_t max_z() const { return nz; } size_t min_w() const { return 0; } size_t max_w() const { return nw; } // inspector value_type get(size_t i, size_t j, size_t k, size_t l) const { return cache.get(i, j, k, l); } // convert flat index to (i, j, k, l) void ijkl(size_t& i, size_t& j, size_t& k, size_t& l, size_t index) const { i = index % nx; index /= nx; j = index % ny; index /= ny; k = index % nz; index /= nz; l = index; } store_type store; // persistent storage of compressed blocks cache_type cache; // cache of decompressed blocks }; typedef const_array4 const_array4f; typedef const_array4 const_array4d; } #endif zfp-1.0.1/include/zfp/factory.hpp000066400000000000000000000060731453723256400167330ustar00rootroot00000000000000#ifndef ZFP_FACTORY_HPP #define ZFP_FACTORY_HPP // ensure zfp/array.hpp has already been included #ifndef ZFP_ARRAY_HPP #error "zfp/array.hpp must be included before zfp/factory.hpp" #endif zfp::array* zfp::array::construct(const zfp::array::header& header, const void* buffer, size_t buffer_size_bytes) { // extract metadata from header const zfp_type type = header.scalar_type(); const double rate = header.rate(); const uint dims = header.dimensionality(); const size_t nx = header.size_x(); const size_t ny = header.size_y(); const size_t nz = header.size_z(); const size_t nw = header.size_w(); // construct once (passing zfp::array::header will read it again) zfp::array* arr = 0; std::string error; switch (dims) { case 4: #ifdef ZFP_ARRAY4_HPP switch (type) { case zfp_type_float: arr = new zfp::array4f(nx, ny, nz, nw, rate); break; case zfp_type_double: arr = new zfp::array4d(nx, ny, nz, nw, rate); break; default: /* NOTREACHED */ error = "zfp scalar type not supported"; break; } #else error = "array4 not supported; include zfp/array4.hpp before zfp/factory.hpp"; #endif break; case 3: #ifdef ZFP_ARRAY3_HPP switch (type) { case zfp_type_float: arr = new zfp::array3f(nx, ny, nz, rate); break; case zfp_type_double: arr = new zfp::array3d(nx, ny, nz, rate); break; default: /* NOTREACHED */ error = "zfp scalar type not supported"; break; } #else error = "array3 not supported; include zfp/array3.hpp before zfp/factory.hpp"; #endif break; case 2: #ifdef ZFP_ARRAY2_HPP switch (type) { case zfp_type_float: arr = new zfp::array2f(nx, ny, rate); break; case zfp_type_double: arr = new zfp::array2d(nx, ny, rate); break; default: /* NOTREACHED */ error = "zfp scalar type not supported"; break; } #else error = "array2 not supported; include zfp/array2.hpp before zfp/factory.hpp"; #endif break; case 1: #ifdef ZFP_ARRAY1_HPP switch (type) { case zfp_type_float: arr = new zfp::array1f(nx, rate); break; case zfp_type_double: arr = new zfp::array1d(nx, rate); break; default: /* NOTREACHED */ error = "zfp scalar type not supported"; break; } #else error = "array1 not supported; include zfp/array1.hpp before zfp/factory.hpp"; #endif break; default: error = "zfp array dimensionality other than {1, 2, 3, 4} not supported"; break; } if (!error.empty()) throw zfp::exception(error); if (buffer) { if (buffer_size_bytes && buffer_size_bytes < arr->compressed_size()) { delete arr; throw zfp::exception("zfp buffer size is smaller than required"); } std::memcpy(arr->compressed_data(), buffer, arr->compressed_size()); } return arr; } #endif zfp-1.0.1/include/zfp/index.hpp000066400000000000000000000351341453723256400163730ustar00rootroot00000000000000#ifndef ZFP_INDEX_HPP #define ZFP_INDEX_HPP #include #include "zfp/internal/array/memory.hpp" namespace zfp { namespace index { // implicit block index (fixed-size blocks; 0 bits/block; 64-bit offsets) ----- class implicit { public: // constructor implicit(size_t blocks) : bits_per_block(0) { resize(blocks); } // destructor ~implicit() {} // byte size of index data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // range of offsets spanned by indexed data in bits bitstream_size range() const { return block_offset(blocks); } // bit size of given block size_t block_size(size_t /*block_index*/) const { return bits_per_block; } // bit offset of given block bitstream_offset block_offset(size_t block_index) const { return block_index * bits_per_block; } // reset index void clear() {} // resize index in number of blocks void resize(size_t blocks) { this->blocks = blocks; } // flush any buffered data void flush() {} // set bit size of all blocks void set_block_size(size_t size) { bits_per_block = size; } // set bit size of given block (ignored for performance reasons) void set_block_size(size_t /*block_index*/, size_t /*size*/) {} // does not support variable rate static bool has_variable_rate() { return false; } protected: size_t blocks; // number of blocks size_t bits_per_block; // fixed number of bits per block }; // verbatim block index (64 bits/block; 64-bit offsets) ----------------------- class verbatim { public: // constructor for given nbumber of blocks verbatim(size_t blocks) : data(0) { resize(blocks); } // destructor ~verbatim() { zfp::internal::deallocate(data); } // assignment operator--performs a deep copy verbatim& operator=(const verbatim& index) { if (this != &index) deep_copy(index); return *this; } // byte size of index data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; if (mask & ZFP_DATA_INDEX) size += capacity() * sizeof(*data); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // range of offsets spanned by indexed data in bits bitstream_size range() const { return block_offset(blocks); } // bit size of given block size_t block_size(size_t block_index) const { return static_cast(block_offset(block_index + 1) - block_offset(block_index)); } // bit offset of given block bitstream_offset block_offset(size_t block_index) const { return static_cast(data[block_index]); } // reset index void clear() { block = 0; } // resize index in number of blocks void resize(size_t blocks) { this->blocks = blocks; zfp::internal::reallocate(data, capacity() * sizeof(*data)); *data = 0; clear(); } // flush any buffered data void flush() {} // set bit size of all blocks void set_block_size(size_t size) { clear(); while (block < blocks) set_block_size(block, size); clear(); } // set bit size of given block (in sequential order) void set_block_size(size_t block_index, size_t size) { if (block_index != block) throw zfp::exception("zfp index supports only sequential build"); if (block == blocks) throw zfp::exception("zfp index overflow"); data[block + 1] = data[block] + size; block++; } // supports variable rate static bool has_variable_rate() { return true; } protected: // capacity of data array size_t capacity() const { return blocks + 1; } // make a deep copy of index void deep_copy(const verbatim& index) { zfp::internal::clone(data, index.data, index.capacity()); blocks = index.blocks; block = index.block; } uint64* data; // block offset array size_t blocks; // number of blocks size_t block; // current block index }; // hybrid block index (4 blocks/chunk; 24 bits/block; 44-bit offsets) --------- class hybrid4 { public: // constructor for given number of blocks hybrid4(size_t blocks) : data(0) { resize(blocks); } // destructor ~hybrid4() { zfp::internal::deallocate(data); } // assignment operator--performs a deep copy hybrid4& operator=(const hybrid4& index) { if (this != &index) deep_copy(index); return *this; } // byte size of index data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; if (mask & ZFP_DATA_INDEX) size += capacity() * sizeof(*data); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // range of offsets spanned by indexed data in bits bitstream_size range() const { return end; } // bit size of given block size_t block_size(size_t block_index) const { size_t chunk = block_index / 4; size_t which = block_index % 4; return which == 3u ? static_cast(block_offset(block_index + 1) - block_offset(block_index)) : static_cast(data[chunk].lo[which + 1] - data[chunk].lo[which]); } // bit offset of given block bitstream_offset block_offset(size_t block_index) const { // if index is being built, point offset to end if (block_index == block) return end; // index has already been built; decode offset size_t chunk = block_index / 4; size_t which = block_index % 4; return (bitstream_offset(data[chunk].hi) << shift) + data[chunk].lo[which]; } // reset index void clear() { block = 0; ptr = 0; end = 0; } void resize(size_t blocks) { this->blocks = blocks; zfp::internal::reallocate(data, capacity() * sizeof(*data)); clear(); } // flush any buffered data void flush() { while (block & 0x3u) set_block_size(block, 0); } // set bit size of all blocks void set_block_size(size_t size) { clear(); while (block < blocks) set_block_size(block, size); flush(); clear(); } // set bit size of given block (in sequential order) void set_block_size(size_t block_index, size_t size) { // ensure block_index is next in sequence if (block_index != block) throw zfp::exception("zfp index supports only sequential build"); // ensure block index is within bounds, but allow 0-size blocks for padding if (block >= blocks && size) throw zfp::exception("zfp index overflow"); // ensure block size is valid if (size > ZFP_MAX_BITS) throw zfp::exception("zfp block size is too large for hybrid4 index"); // advance end pointer end += size; // buffer chunk of 4 block sizes at a time size_t chunk = block / 4; size_t which = block % 4; buffer[which] = size; if (which == 3u) { // chunk is complete; encode it if (ptr >> (32 + shift)) throw zfp::exception("zfp block offset is too large for hybrid4 index"); // store high bits data[chunk].hi = static_cast(ptr >> shift); bitstream_offset base = bitstream_offset(data[chunk].hi) << shift; // store low bits for (uint k = 0; k < 4; k++) { data[chunk].lo[k] = static_cast(ptr - base); ptr += buffer[k]; } } block++; } // supports variable rate static bool has_variable_rate() { return true; } protected: // chunk record encoding 4 block offsets typedef struct { uint32 hi; // 32 most significant bits of 44-bit base offset uint16 lo[4]; // 16-bit offsets from base } record; // capacity of data array size_t capacity() const { return (blocks + 3) / 4; } // make a deep copy of index void deep_copy(const hybrid4& index) { zfp::internal::clone(data, index.data, index.capacity()); blocks = index.blocks; block = index.block; ptr = index.ptr; end = index.end; std::copy(index.buffer, index.buffer + 4, buffer); } static const uint shift = 12; // number of bits to shift hi bits record* data; // block offset array size_t blocks; // number of blocks size_t block; // current block index bitstream_offset end; // offset to last block bitstream_offset ptr; // offset to current chunk of blocks size_t buffer[4]; // bit sizes 4 blocks to be stored together }; // hybrid block index (8 blocks/chunk; 16 bits/block; 86-14dims bit offsets) -- template class hybrid8 { public: // constructor for given number of blocks hybrid8(size_t blocks) : data(0) { resize(blocks); } // destructor ~hybrid8() { zfp::internal::deallocate(data); } // assignment operator--performs a deep copy hybrid8& operator=(const hybrid8& index) { if (this != &index) deep_copy(index); return *this; } // byte size of index data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; if (mask & ZFP_DATA_INDEX) size += capacity() * sizeof(*data); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // range of offsets spanned by indexed data in bits bitstream_size range() const { return end; } // bit size of given block size_t block_size(size_t block_index) const { size_t chunk = block_index / 8; size_t which = block_index % 8; return which == 7u ? static_cast(block_offset(block_index + 1) - block_offset(block_index)) : size(data[2 * chunk + 0], data[2 * chunk + 1], static_cast(which)); } // bit offset of given block bitstream_offset block_offset(size_t block_index) const { // if index is being built, point offset to end if (block_index == block) return end; // index has already been built; decode offset size_t chunk = block_index / 8; size_t which = block_index % 8; return offset(data[2 * chunk + 0], data[2 * chunk + 1], static_cast(which)); } // reset index void clear() { block = 0; ptr = 0; end = 0; } void resize(size_t blocks) { this->blocks = blocks; zfp::internal::reallocate(data, capacity() * sizeof(*data)); clear(); } // flush any buffered data void flush() { while (block & 0x7u) set_block_size(block, 0); } // set bit size of all blocks void set_block_size(size_t size) { clear(); while (block < blocks) set_block_size(block, size); flush(); clear(); } // set bit size of given block (in sequential order) void set_block_size(size_t block_index, size_t size) { // ensure block_index is next in sequence if (block_index != block) throw zfp::exception("zfp index supports only sequential build"); // ensure block index is within bounds, but allow 0-size blocks for padding if (block >= blocks && size) throw zfp::exception("zfp index overflow"); // ensure block size is valid if (size >> (hbits + lbits)) throw zfp::exception("zfp block size is too large for hybrid8 index"); // advance end pointer end += size; // buffer chunk of 8 block sizes at a time size_t chunk = block / 8; size_t which = block % 8; buffer[which] = size; if (which == 7u) { // partition chunk offset into low and high bits uint64 h = ptr >> lbits; uint64 l = ptr - (h << lbits); uint64 hi = h << (7 * hbits); uint64 lo = l << (7 * lbits); // make sure base offset does not overflow if ((hi >> (7 * hbits)) != h) throw zfp::exception("zfp block offset is too large for hybrid8 index"); // store sizes of blocks 0-6 for (uint k = 0; k < 7; k++) { size = buffer[k]; ptr += size; // partition block size into hbits high and lbits low bits h = size >> lbits; l = size - (h << lbits); hi += h << ((6 - k) * hbits); lo += l << ((6 - k) * lbits); } ptr += buffer[7]; data[2 * chunk + 0] = hi; data[2 * chunk + 1] = lo; } block++; } // supports variable rate static bool has_variable_rate() { return true; } protected: // capacity of data array size_t capacity() const { return 2 * ((blocks + 7) / 8); } // make a deep copy of index void deep_copy(const hybrid8& index) { zfp::internal::clone(data, index.data, index.capacity()); blocks = index.blocks; block = index.block; ptr = index.ptr; end = index.end; std::copy(index.buffer, index.buffer + 8, buffer); } // kth size in chunk, 0 <= k <= 6 static size_t size(uint64 h, uint64 l, uint k) { // extract high and low bits h >>= (6 - k) * hbits; h &= (UINT64C(1) << hbits) - 1; l >>= (6 - k) * lbits; l &= (UINT64C(1) << lbits) - 1; // combine base offset with high and low bits return static_cast((h << lbits) + l); } // kth offset in chunk, 0 <= k <= 7 static bitstream_offset offset(uint64 h, uint64 l, uint k) { // extract all but lowest (8 * hbits) bits uint64 base = h >> (8 * hbits); h -= base << (8 * hbits); // add LSBs of base offset and k block sizes h = hsum(h >> ((7 - k) * hbits)); l = lsum(l >> ((7 - k) * lbits)); // combine base offset with high and low bits return static_cast((((base << hbits) + h) << lbits) + l); } // sum of (up to) eight packed 8-bit numbers (efficient version of sum8) static uint64 lsum(uint64 x) { // reduce in parallel uint64 y = x & UINT64C(0xff00ff00ff00ff00); x -= y; x += y >> 8; x += x >> 16; x += x >> 32; return x & UINT64C(0xffff); } // sum of (up to) eight packed h-bit numbers static uint64 hsum(uint64 x) { return sum8(x, hbits); } // compute sum of eight packed n-bit values (1 <= n <= 8) static uint64 sum8(uint64 x, uint n) { // bit masks for extracting terms of sums uint64 m3 = ~UINT64C(0) << (4 * n); uint64 m2 = m3 ^ (m3 << (4 * n)); uint64 m1 = m2 ^ (m2 >> (2 * n)); uint64 m0 = m1 ^ (m1 >> (1 * n)); uint64 y; // perform summations in parallel y = x & m0; x -= y; x += y >> n; n *= 2; // four summations y = x & m1; x -= y; x += y >> n; n *= 2; // two summations y = x & m2; x -= y; x += y >> n; n *= 2; // final summation return x; } static const uint lbits = 8; // 64 bits partitioned into 8 static const uint hbits = 2 * (dims - 1); // log2(4^d * maxprec / 2^lbits) uint64* data; // block offset array size_t blocks; // number of blocks size_t block; // current block index bitstream_offset end; // offset to last block bitstream_offset ptr; // offset to current set of blocks size_t buffer[8]; // sizes of 8 blocks to be stored together }; } // index } // zfp #endif zfp-1.0.1/include/zfp/internal/000077500000000000000000000000001453723256400163615ustar00rootroot00000000000000zfp-1.0.1/include/zfp/internal/array/000077500000000000000000000000001453723256400174775ustar00rootroot00000000000000zfp-1.0.1/include/zfp/internal/array/cache.hpp000066400000000000000000000154031453723256400212560ustar00rootroot00000000000000#ifndef ZFP_CACHE_HPP #define ZFP_CACHE_HPP #include "zfp/internal/array/memory.hpp" #ifdef ZFP_WITH_CACHE_PROFILE // maintain stats on hit and miss rates #include #endif namespace zfp { namespace internal { // direct-mapped or two-way skew-associative write-back cache template class Cache { public: // cache line index (zero is reserved for unused lines) typedef uint Index; // cache tag containing line meta data class Tag { public: Tag() : x(0) {} Tag(Index x, bool d) : x(2 * x + d) {} // cache line index Index index() const { return x >> 1; } // is line dirty? bool dirty() const { return x & 1; } // is line used? bool used() const { return x != 0; } // mark line as dirty void mark() { x |= 1u; } // mark line as unused void clear() { x = 0; } protected: Index x; }; // sequential iterator for looping over cache lines class const_iterator { public: friend class Cache; class Pair { public: Pair(Line* l, Tag t) : line(l), tag(t) {} Line* line; Tag tag; }; const_iterator& operator++() { advance(); return *this; } const_iterator operator++(int) { const_iterator iter = *this; advance(); return iter; } const Pair& operator*() const { return pair; } const Pair* operator->() const { return &pair; } operator const void*() const { return pair.line ? this : 0; } protected: const_iterator(Cache* cache) : c(cache), pair(cache->line, cache->tag[0]) { if (!pair.tag.used()) advance(); } void advance() { if (pair.line) { uint i; for (i = uint(pair.line - c->line) + 1; i <= c->mask && !c->tag[i].used(); i++); pair = (i <= c->mask ? Pair(c->line + i, c->tag[i]) : Pair(0, Tag())); } } Cache* c; Pair pair; }; // allocate cache with at least minsize lines Cache(uint minsize = 0) : mask(0), tag(0), line(0) { resize(minsize); #ifdef ZFP_WITH_CACHE_PROFILE std::cerr << "cache lines=" << size() << std::endl; hit[0][0] = hit[1][0] = miss[0] = back[0] = 0; hit[0][1] = hit[1][1] = miss[1] = back[1] = 0; #endif } // copy constructor--performs a deep copy Cache(const Cache& c) : tag(0), line(0) { deep_copy(c); } // destructor ~Cache() { zfp::internal::deallocate_aligned(tag); zfp::internal::deallocate_aligned(line); #ifdef ZFP_WITH_CACHE_PROFILE std::cerr << "cache R1=" << hit[0][0] << " R2=" << hit[1][0] << " RM=" << miss[0] << " RB=" << back[0] << " W1=" << hit[0][1] << " W2=" << hit[1][1] << " WM=" << miss[1] << " WB=" << back[1] << std::endl; #endif } // assignment operator--performs a deep copy Cache& operator=(const Cache& c) { if (this != &c) deep_copy(c); return *this; } // byte size of cache data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; if (mask & ZFP_DATA_CACHE) size += this->size() * (sizeof(*tag) + sizeof(*line)); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // cache size in number of lines uint size() const { return mask + 1; } // change cache size to at least minsize lines (all contents will be lost) void resize(uint minsize) { // compute smallest value of mask such that mask + 1 = 2^k >= minsize for (mask = minsize ? minsize - 1 : 1; mask & (mask + 1); mask |= mask + 1); zfp::internal::reallocate_aligned(tag, size() * sizeof(Tag), ZFP_MEMORY_ALIGNMENT); zfp::internal::reallocate_aligned(line, size() * sizeof(Line), ZFP_MEMORY_ALIGNMENT); clear(); } // look up cache line #x and return pointer to it if in the cache; // otherwise return null Line* lookup(Index x, bool write) { uint i = primary(x); if (tag[i].index() == x) { if (write) tag[i].mark(); return line + i; } #ifdef ZFP_WITH_CACHE_TWOWAY uint j = secondary(x); if (tag[j].index() == x) { if (write) tag[i].mark(); return line + j; } #endif return 0; } // look up cache line #x and set ptr to where x is or should be stored; // if the returned tag does not match x, then the caller must implement // write-back (if the line is in use) and then fetch the requested line Tag access(Line*& ptr, Index x, bool write) { uint i = primary(x); if (tag[i].index() == x) { ptr = line + i; if (write) tag[i].mark(); #ifdef ZFP_WITH_CACHE_PROFILE hit[0][write]++; #endif return tag[i]; } #ifdef ZFP_WITH_CACHE_TWOWAY uint j = secondary(x); if (tag[j].index() == x) { ptr = line + j; if (write) tag[j].mark(); #ifdef ZFP_WITH_CACHE_PROFILE hit[1][write]++; #endif return tag[j]; } // cache line not found; prefer primary and not dirty slots i = tag[j].used() && (!tag[i].dirty() || tag[j].dirty()) ? i : j; #endif ptr = line + i; Tag t = tag[i]; tag[i] = Tag(x, write); #ifdef ZFP_WITH_CACHE_PROFILE miss[write]++; if (tag[i].dirty()) back[write]++; #endif return t; } // clear cache without writing back void clear() { for (uint i = 0; i <= mask; i++) tag[i].clear(); } // flush cache line void flush(const Line* l) { uint i = uint(l - line); tag[i].clear(); } // return iterator to first cache line const_iterator first() { return const_iterator(this); } protected: // perform a deep copy void deep_copy(const Cache& c) { mask = c.mask; zfp::internal::clone_aligned(tag, c.tag, size(), ZFP_MEMORY_ALIGNMENT); zfp::internal::clone_aligned(line, c.line, size(), ZFP_MEMORY_ALIGNMENT); #ifdef ZFP_WITH_CACHE_PROFILE hit[0][0] = c.hit[0][0]; hit[0][1] = c.hit[0][1]; hit[1][0] = c.hit[1][0]; hit[1][1] = c.hit[1][1]; miss[0] = c.miss[0]; miss[1] = c.miss[1]; back[0] = c.back[0]; back[1] = c.back[1]; #endif } uint primary(Index x) const { return x & mask; } uint secondary(Index x) const { #ifdef ZFP_WITH_CACHE_FAST_HASH // max entropy hash for 26- to 16-bit mapping (not full avalanche) x -= x << 7; x ^= x >> 16; x -= x << 3; #else // Jenkins hash; see http://burtleburtle.net/bob/hash/integer.html x -= x << 6; x ^= x >> 17; x -= x << 9; x ^= x << 4; x -= x << 3; x ^= x << 10; x ^= x >> 15; #endif return x & mask; } Index mask; // cache line mask Tag* tag; // cache line tags Line* line; // actual decompressed cache lines #ifdef ZFP_WITH_CACHE_PROFILE uint64 hit[2][2]; // number of primary/secondary read/write hits uint64 miss[2]; // number of read/write misses uint64 back[2]; // number of write-backs due to read/writes #endif }; } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/cache1.hpp000066400000000000000000000125001453723256400213320ustar00rootroot00000000000000#ifndef ZFP_CACHE1_HPP #define ZFP_CACHE1_HPP #include "zfp/internal/array/cache.hpp" namespace zfp { namespace internal { template class BlockCache1 { public: // constructor of cache of given size BlockCache1(Store& store, size_t bytes = 0) : cache(lines(bytes, store.blocks())), store(store) {} // byte size of cache data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += cache.size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // cache size in number of bytes (cache line payload data only) size_t size() const { return cache.size() * sizeof(CacheLine); } // set minimum cache size in bytes (inferred from blocks if zero) void resize(size_t bytes) { flush(); cache.resize(lines(bytes, store.blocks())); } // empty cache without compressing modified cached blocks void clear() const { cache.clear(); } // flush cache by compressing all modified cached blocks void flush() const { for (typename zfp::internal::Cache::const_iterator p = cache.first(); p; p++) { if (p->tag.dirty()) { size_t block_index = p->tag.index() - 1; store.encode(block_index, p->line->data()); } cache.flush(p->line); } } // perform a deep copy void deep_copy(const BlockCache1& c) { cache = c.cache; } // inspector Scalar get(size_t i) const { const CacheLine* p = line(i, false); return (*p)(i); } // mutator void set(size_t i, Scalar val) { CacheLine* p = line(i, true); (*p)(i) = val; } // reference to cached element Scalar& ref(size_t i) { CacheLine* p = line(i, true); return (*p)(i); } // read-no-allocate: copy block from cache on hit, else from store without caching void get_block(size_t block_index, Scalar* p, ptrdiff_t sx) const { const CacheLine* line = cache.lookup((uint)block_index + 1, false); if (line) line->get(p, sx, store.block_shape(block_index)); else store.decode(block_index, p, sx); } // write-no-allocate: copy block to cache on hit, else to store without caching void put_block(size_t block_index, const Scalar* p, ptrdiff_t sx) { CacheLine* line = cache.lookup((uint)block_index + 1, true); if (line) line->put(p, sx, store.block_shape(block_index)); else store.encode(block_index, p, sx); } protected: // cache line representing one block of decompressed values class CacheLine { public: // accessors Scalar operator()(size_t i) const { return a[index(i)]; } Scalar& operator()(size_t i) { return a[index(i)]; } // pointer to decompressed block data const Scalar* data() const { return a; } Scalar* data() { return a; } // copy whole block from cache line void get(Scalar* p, ptrdiff_t sx) const { const Scalar* q = a; for (uint x = 0; x < 4; x++, p += sx, q++) *p = *q; } // copy partial block from cache line void get(Scalar* p, ptrdiff_t sx, uint shape) const { if (!shape) get(p, sx); else { // determine block dimensions uint nx = 4 - (shape & 3u); shape >>= 2; const Scalar* q = a; for (uint x = 0; x < nx; x++, p += sx, q++) *p = *q; } } // copy whole block to cache line void put(const Scalar* p, ptrdiff_t sx) { Scalar* q = a; for (uint x = 0; x < 4; x++, p += sx, q++) *q = *p; } // copy partial block to cache line void put(const Scalar* p, ptrdiff_t sx, uint shape) { if (!shape) put(p, sx); else { // determine block dimensions uint nx = 4 - (shape & 3u); shape >>= 2; Scalar* q = a; for (uint x = 0; x < nx; x++, p += sx, q++) *q = *p; } } protected: static size_t index(size_t i) { return (i & 3u); } Scalar a[4]; }; // return cache line for i; may require write-back and fetch CacheLine* line(size_t i, bool write) const { CacheLine* p = 0; size_t block_index = store.block_index(i); typename zfp::internal::Cache::Tag tag = cache.access(p, (uint)block_index + 1, write); size_t stored_block_index = tag.index() - 1; if (stored_block_index != block_index) { // write back occupied cache line if it is dirty if (tag.dirty()) store.encode(stored_block_index, p->data()); // fetch cache line store.decode(block_index, p->data()); } return p; } // default number of cache lines for array with given number of blocks static uint lines(size_t blocks) { // compute m = O(sqrt(n)) size_t m; for (m = 1; m * m < blocks; m *= 2); return static_cast(m); } // number of cache lines corresponding to size (or suggested size if zero) static uint lines(size_t bytes, size_t blocks) { // ensure block index fits in tag if (blocks >> ((sizeof(uint) * CHAR_BIT) - 1)) throw zfp::exception("zfp array too large for cache"); uint n = bytes ? static_cast((bytes + sizeof(CacheLine) - 1) / sizeof(CacheLine)) : lines(blocks); return std::max(n, 1u); } mutable Cache cache; // cache of decompressed blocks Store& store; // store backed by cache }; } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/cache2.hpp000066400000000000000000000136431453723256400213440ustar00rootroot00000000000000#ifndef ZFP_CACHE2_HPP #define ZFP_CACHE2_HPP #include "zfp/internal/array/cache.hpp" namespace zfp { namespace internal { template class BlockCache2 { public: // constructor of cache of given size BlockCache2(Store& store, size_t bytes = 0) : cache(lines(bytes, store.blocks())), store(store) {} // byte size of cache data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += cache.size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // cache size in number of bytes (cache line payload data only) size_t size() const { return cache.size() * sizeof(CacheLine); } // set minimum cache size in bytes (inferred from blocks if zero) void resize(size_t bytes) { flush(); cache.resize(lines(bytes, store.blocks())); } // empty cache without compressing modified cached blocks void clear() const { cache.clear(); } // flush cache by compressing all modified cached blocks void flush() const { for (typename zfp::internal::Cache::const_iterator p = cache.first(); p; p++) { if (p->tag.dirty()) { size_t block_index = p->tag.index() - 1; store.encode(block_index, p->line->data()); } cache.flush(p->line); } } // perform a deep copy void deep_copy(const BlockCache2& c) { cache = c.cache; } // inspector Scalar get(size_t i, size_t j) const { const CacheLine* p = line(i, j, false); return (*p)(i, j); } // mutator void set(size_t i, size_t j, Scalar val) { CacheLine* p = line(i, j, true); (*p)(i, j) = val; } // reference to cached element Scalar& ref(size_t i, size_t j) { CacheLine* p = line(i, j, true); return (*p)(i, j); } // read-no-allocate: copy block from cache on hit, else from store without caching void get_block(size_t block_index, Scalar* p, ptrdiff_t sx, ptrdiff_t sy) const { const CacheLine* line = cache.lookup((uint)block_index + 1, false); if (line) line->get(p, sx, sy, store.block_shape(block_index)); else store.decode(block_index, p, sx, sy); } // write-no-allocate: copy block to cache on hit, else to store without caching void put_block(size_t block_index, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy) { CacheLine* line = cache.lookup((uint)block_index + 1, true); if (line) line->put(p, sx, sy, store.block_shape(block_index)); else store.encode(block_index, p, sx, sy); } protected: // cache line representing one block of decompressed values class CacheLine { public: // accessors Scalar operator()(size_t i, size_t j) const { return a[index(i, j)]; } Scalar& operator()(size_t i, size_t j) { return a[index(i, j)]; } // pointer to decompressed block data const Scalar* data() const { return a; } Scalar* data() { return a; } // copy whole block from cache line void get(Scalar* p, ptrdiff_t sx, ptrdiff_t sy) const { const Scalar* q = a; for (uint y = 0; y < 4; y++, p += sy - 4 * sx) for (uint x = 0; x < 4; x++, p += sx, q++) *p = *q; } // copy partial block from cache line void get(Scalar* p, ptrdiff_t sx, ptrdiff_t sy, uint shape) const { if (!shape) get(p, sx, sy); else { // determine block dimensions uint nx = 4 - (shape & 3u); shape >>= 2; uint ny = 4 - (shape & 3u); shape >>= 2; const Scalar* q = a; for (uint y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx, q += 4 - nx) for (uint x = 0; x < nx; x++, p += sx, q++) *p = *q; } } // copy whole block to cache line void put(const Scalar* p, ptrdiff_t sx, ptrdiff_t sy) { Scalar* q = a; for (uint y = 0; y < 4; y++, p += sy - 4 * sx) for (uint x = 0; x < 4; x++, p += sx, q++) *q = *p; } // copy partial block to cache line void put(const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, uint shape) { if (!shape) put(p, sx, sy); else { // determine block dimensions uint nx = 4 - (shape & 3u); shape >>= 2; uint ny = 4 - (shape & 3u); shape >>= 2; Scalar* q = a; for (uint y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx, q += 4 - nx) for (uint x = 0; x < nx; x++, p += sx, q++) *q = *p; } } protected: static size_t index(size_t i, size_t j) { return (i & 3u) + 4 * (j & 3u); } Scalar a[4 * 4]; }; // return cache line for (i, j); may require write-back and fetch CacheLine* line(size_t i, size_t j, bool write) const { CacheLine* p = 0; size_t block_index = store.block_index(i, j); typename zfp::internal::Cache::Tag tag = cache.access(p, (uint)block_index + 1, write); size_t stored_block_index = tag.index() - 1; if (stored_block_index != block_index) { // write back occupied cache line if it is dirty if (tag.dirty()) store.encode(stored_block_index, p->data()); // fetch cache line store.decode(block_index, p->data()); } return p; } // default number of cache lines for array with given number of blocks static uint lines(size_t blocks) { // compute m = O(sqrt(n)) size_t m; for (m = 1; m * m < blocks; m *= 2); return static_cast(m); } // number of cache lines corresponding to size (or suggested size if zero) static uint lines(size_t bytes, size_t blocks) { // ensure block index fits in tag if (blocks >> ((sizeof(uint) * CHAR_BIT) - 1)) throw zfp::exception("zfp array too large for cache"); uint n = bytes ? static_cast((bytes + sizeof(CacheLine) - 1) / sizeof(CacheLine)) : lines(blocks); return std::max(n, 1u); } mutable Cache cache; // cache of decompressed blocks Store& store; // store backed by cache }; } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/cache3.hpp000066400000000000000000000150361453723256400213430ustar00rootroot00000000000000#ifndef ZFP_CACHE3_HPP #define ZFP_CACHE3_HPP #include "zfp/internal/array/cache.hpp" namespace zfp { namespace internal { template class BlockCache3 { public: // constructor of cache of given size BlockCache3(Store& store, size_t bytes = 0) : cache(lines(bytes, store.blocks())), store(store) {} // byte size of cache data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += cache.size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // cache size in number of bytes (cache line payload data only) size_t size() const { return cache.size() * sizeof(CacheLine); } // set minimum cache size in bytes (inferred from blocks if zero) void resize(size_t bytes) { flush(); cache.resize(lines(bytes, store.blocks())); } // empty cache without compressing modified cached blocks void clear() const { cache.clear(); } // flush cache by compressing all modified cached blocks void flush() const { for (typename zfp::internal::Cache::const_iterator p = cache.first(); p; p++) { if (p->tag.dirty()) { size_t block_index = p->tag.index() - 1; store.encode(block_index, p->line->data()); } cache.flush(p->line); } } // perform a deep copy void deep_copy(const BlockCache3& c) { cache = c.cache; } // inspector Scalar get(size_t i, size_t j, size_t k) const { const CacheLine* p = line(i, j, k, false); return (*p)(i, j, k); } // mutator void set(size_t i, size_t j, size_t k, Scalar val) { CacheLine* p = line(i, j, k, true); (*p)(i, j, k) = val; } // reference to cached element Scalar& ref(size_t i, size_t j, size_t k) { CacheLine* p = line(i, j, k, true); return (*p)(i, j, k); } // read-no-allocate: copy block from cache on hit, else from store without caching void get_block(size_t block_index, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) const { const CacheLine* line = cache.lookup((uint)block_index + 1, false); if (line) line->get(p, sx, sy, sz, store.block_shape(block_index)); else store.decode(block_index, p, sx, sy, sz); } // write-no-allocate: copy block to cache on hit, else to store without caching void put_block(size_t block_index, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) const { CacheLine* line = cache.lookup((uint)block_index + 1, true); if (line) line->put(p, sx, sy, sz, store.block_shape(block_index)); else store.encode(block_index, p, sx, sy, sz); } protected: // cache line representing one block of decompressed values class CacheLine { public: // accessors Scalar operator()(size_t i, size_t j, size_t k) const { return a[index(i, j, k)]; } Scalar& operator()(size_t i, size_t j, size_t k) { return a[index(i, j, k)]; } // pointer to decompressed block data const Scalar* data() const { return a; } Scalar* data() { return a; } // copy whole block from cache line void get(Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) const { const Scalar* q = a; for (uint z = 0; z < 4; z++, p += sz - 4 * sy) for (uint y = 0; y < 4; y++, p += sy - 4 * sx) for (uint x = 0; x < 4; x++, p += sx, q++) *p = *q; } // copy partial block from cache line void get(Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, uint shape) const { if (!shape) get(p, sx, sy, sz); else { // determine block dimensions uint nx = 4 - (shape & 3u); shape >>= 2; uint ny = 4 - (shape & 3u); shape >>= 2; uint nz = 4 - (shape & 3u); shape >>= 2; const Scalar* q = a; for (uint z = 0; z < nz; z++, p += sz - (ptrdiff_t)ny * sy, q += 16 - 4 * ny) for (uint y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx, q += 4 - nx) for (uint x = 0; x < nx; x++, p += sx, q++) *p = *q; } } // copy whole block to cache line void put(const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { Scalar* q = a; for (uint z = 0; z < 4; z++, p += sz - 4 * sy) for (uint y = 0; y < 4; y++, p += sy - 4 * sx) for (uint x = 0; x < 4; x++, p += sx, q++) *q = *p; } // copy partial block to cache line void put(const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, uint shape) { if (!shape) put(p, sx, sy, sz); else { // determine block dimensions uint nx = 4 - (shape & 3u); shape >>= 2; uint ny = 4 - (shape & 3u); shape >>= 2; uint nz = 4 - (shape & 3u); shape >>= 2; Scalar* q = a; for (uint z = 0; z < nz; z++, p += sz - (ptrdiff_t)ny * sy, q += 16 - 4 * ny) for (uint y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx, q += 4 - nx) for (uint x = 0; x < nx; x++, p += sx, q++) *q = *p; } } protected: static size_t index(size_t i, size_t j, size_t k) { return (i & 3u) + 4 * ((j & 3u) + 4 * (k & 3u)); } Scalar a[4 * 4 * 4]; }; // return cache line for (i, j, k); may require write-back and fetch CacheLine* line(size_t i, size_t j, size_t k, bool write) const { CacheLine* p = 0; size_t block_index = store.block_index(i, j, k); typename zfp::internal::Cache::Tag tag = cache.access(p, (uint)block_index + 1, write); size_t stored_block_index = tag.index() - 1; if (stored_block_index != block_index) { // write back occupied cache line if it is dirty if (tag.dirty()) store.encode(stored_block_index, p->data()); // fetch cache line store.decode(block_index, p->data()); } return p; } // default number of cache lines for array with given number of blocks static uint lines(size_t blocks) { // compute m = O(sqrt(n)) size_t m; for (m = 1; m * m < blocks; m *= 2); return static_cast(m); } // number of cache lines corresponding to size (or suggested size if zero) static uint lines(size_t bytes, size_t blocks) { // ensure block index fits in tag if (blocks >> ((sizeof(uint) * CHAR_BIT) - 1)) throw zfp::exception("zfp array too large for cache"); uint n = bytes ? static_cast((bytes + sizeof(CacheLine) - 1) / sizeof(CacheLine)) : lines(blocks); return std::max(n, 1u); } mutable Cache cache; // cache of decompressed blocks Store& store; // store backed by cache }; } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/cache4.hpp000066400000000000000000000162351453723256400213460ustar00rootroot00000000000000#ifndef ZFP_CACHE4_HPP #define ZFP_CACHE4_HPP #include "zfp/internal/array/cache.hpp" namespace zfp { namespace internal { template class BlockCache4 { public: // constructor of cache of given size BlockCache4(Store& store, size_t bytes = 0) : cache(lines(bytes, store.blocks())), store(store) {} // byte size of cache data structure components indicated by mask size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += cache.size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // cache size in number of bytes (cache line payload data only) size_t size() const { return cache.size() * sizeof(CacheLine); } // set minimum cache size in bytes (inferred from blocks if zero) void resize(size_t bytes) { flush(); cache.resize(lines(bytes, store.blocks())); } // empty cache without compressing modified cached blocks void clear() const { cache.clear(); } // flush cache by compressing all modified cached blocks void flush() const { for (typename zfp::internal::Cache::const_iterator p = cache.first(); p; p++) { if (p->tag.dirty()) { size_t block_index = p->tag.index() - 1; store.encode(block_index, p->line->data()); } cache.flush(p->line); } } // perform a deep copy void deep_copy(const BlockCache4& c) { cache = c.cache; } // inspector Scalar get(size_t i, size_t j, size_t k, size_t l) const { const CacheLine* p = line(i, j, k, l, false); return (*p)(i, j, k, l); } // mutator void set(size_t i, size_t j, size_t k, size_t l, Scalar val) { CacheLine* p = line(i, j, k, l, true); (*p)(i, j, k, l) = val; } // reference to cached element Scalar& ref(size_t i, size_t j, size_t k, size_t l) { CacheLine* p = line(i, j, k, l, true); return (*p)(i, j, k, l); } // read-no-allocate: copy block from cache on hit, else from store without caching void get_block(size_t block_index, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) const { const CacheLine* line = cache.lookup((uint)block_index + 1, false); if (line) line->get(p, sx, sy, sz, sw, store.block_shape(block_index)); else store.decode(block_index, p, sx, sy, sz, sw); } // write-no-allocate: copy block to cache on hit, else to store without caching void put_block(size_t block_index, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) const { CacheLine* line = cache.lookup((uint)block_index + 1, true); if (line) line->put(p, sx, sy, sz, sw, store.block_shape(block_index)); else store.encode(block_index, p, sx, sy, sz, sw); } protected: // cache line representing one block of decompressed values class CacheLine { public: // accessors Scalar operator()(size_t i, size_t j, size_t k, size_t l) const { return a[index(i, j, k, l)]; } Scalar& operator()(size_t i, size_t j, size_t k, size_t l) { return a[index(i, j, k, l)]; } // pointer to decompressed block data const Scalar* data() const { return a; } Scalar* data() { return a; } // copy whole block from cache line void get(Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) const { const Scalar* q = a; for (uint w = 0; w < 4; w++, p += sw - 4 * sz) for (uint z = 0; z < 4; z++, p += sz - 4 * sy) for (uint y = 0; y < 4; y++, p += sy - 4 * sx) for (uint x = 0; x < 4; x++, p += sx, q++) *p = *q; } // copy partial block from cache line void get(Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw, uint shape) const { if (!shape) get(p, sx, sy, sz, sw); else { // determine block dimensions uint nx = 4 - (shape & 3u); shape >>= 2; uint ny = 4 - (shape & 3u); shape >>= 2; uint nz = 4 - (shape & 3u); shape >>= 2; uint nw = 4 - (shape & 3u); shape >>= 2; const Scalar* q = a; for (uint w = 0; w < nw; w++, p += sw - (ptrdiff_t)nz * sz, q += 64 - 16 * nz) for (uint z = 0; z < nz; z++, p += sz - (ptrdiff_t)ny * sy, q += 16 - 4 * ny) for (uint y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx, q += 4 - nx) for (uint x = 0; x < nx; x++, p += sx, q++) *p = *q; } } // copy whole block to cache line void put(const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { Scalar* q = a; for (uint w = 0; w < 4; w++, p += sw - 4 * sz) for (uint z = 0; z < 4; z++, p += sz - 4 * sy) for (uint y = 0; y < 4; y++, p += sy - 4 * sx) for (uint x = 0; x < 4; x++, p += sx, q++) *q = *p; } // copy partial block to cache line void put(const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw, uint shape) { if (!shape) put(p, sx, sy, sz, sw); else { // determine block dimensions uint nx = 4 - (shape & 3u); shape >>= 2; uint ny = 4 - (shape & 3u); shape >>= 2; uint nz = 4 - (shape & 3u); shape >>= 2; uint nw = 4 - (shape & 3u); shape >>= 2; Scalar* q = a; for (uint w = 0; w < nw; w++, p += sw - (ptrdiff_t)nz * sz, q += 64 - 16 * nz) for (uint z = 0; z < nz; z++, p += sz - (ptrdiff_t)ny * sy, q += 16 - 4 * ny) for (uint y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx, q += 4 - nx) for (uint x = 0; x < nx; x++, p += sx, q++) *q = *p; } } protected: static size_t index(size_t i, size_t j, size_t k, size_t l) { return (i & 3u) + 4 * ((j & 3u) + 4 * ((k & 3u) + 4 * (l & 3u))); } Scalar a[4 * 4 * 4 * 4]; }; // return cache line for (i, j, k, l); may require write-back and fetch CacheLine* line(size_t i, size_t j, size_t k, size_t l, bool write) const { CacheLine* p = 0; size_t block_index = store.block_index(i, j, k, l); typename zfp::internal::Cache::Tag tag = cache.access(p, (uint)block_index + 1, write); size_t stored_block_index = tag.index() - 1; if (stored_block_index != block_index) { // write back occupied cache line if it is dirty if (tag.dirty()) store.encode(stored_block_index, p->data()); // fetch cache line store.decode(block_index, p->data()); } return p; } // default number of cache lines for array with given number of blocks static uint lines(size_t blocks) { // compute m = O(sqrt(n)) size_t m; for (m = 1; m * m < blocks; m *= 2); return static_cast(m); } // number of cache lines corresponding to size (or suggested size if zero) static uint lines(size_t bytes, size_t blocks) { // ensure block index fits in tag if (blocks >> ((sizeof(uint) * CHAR_BIT) - 1)) throw zfp::exception("zfp array too large for cache"); uint n = bytes ? static_cast((bytes + sizeof(CacheLine) - 1) / sizeof(CacheLine)) : lines(blocks); return std::max(n, 1u); } mutable Cache cache; // cache of decompressed blocks Store& store; // store backed by cache }; } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/exception.hpp000066400000000000000000000005021453723256400222030ustar00rootroot00000000000000#ifndef ZFP_EXCEPTION_HPP #define ZFP_EXCEPTION_HPP #include #include namespace zfp { // generic exception thrown by array constructors class exception : public std::runtime_error { public: exception(const std::string& msg) : runtime_error(msg) {} virtual ~exception() throw() {} }; } #endif zfp-1.0.1/include/zfp/internal/array/handle1.hpp000066400000000000000000000017351453723256400215320ustar00rootroot00000000000000#ifndef ZFP_HANDLE1_HPP #define ZFP_HANDLE1_HPP namespace zfp { namespace internal { namespace dim1 { // forward declarations template class const_reference; template class const_pointer; template class const_iterator; template class reference; template class pointer; template class iterator; // const handle to a 1D array or view element template class const_handle { public: typedef Container container_type; typedef typename container_type::value_type value_type; protected: // protected constructor explicit const_handle(const container_type* container, size_t x) : container(const_cast(container)), x(x) {} // dereference handle value_type get() const { return container->get(x); } container_type* container; // container size_t x; // global element index }; } // dim1 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/handle2.hpp000066400000000000000000000017601453723256400215310ustar00rootroot00000000000000#ifndef ZFP_HANDLE2_HPP #define ZFP_HANDLE2_HPP namespace zfp { namespace internal { namespace dim2 { // forward declarations template class const_reference; template class const_pointer; template class const_iterator; template class reference; template class pointer; template class iterator; // const handle to a 2D array or view element template class const_handle { public: typedef Container container_type; typedef typename container_type::value_type value_type; protected: // protected constructor explicit const_handle(const container_type* container, size_t x, size_t y) : container(const_cast(container)), x(x), y(y) {} // dereference handle value_type get() const { return container->get(x, y); } container_type* container; // container size_t x, y; // global element index }; } // dim2 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/handle3.hpp000066400000000000000000000020031453723256400215210ustar00rootroot00000000000000#ifndef ZFP_HANDLE3_HPP #define ZFP_HANDLE3_HPP namespace zfp { namespace internal { namespace dim3 { // forward declarations template class const_reference; template class const_pointer; template class const_iterator; template class reference; template class pointer; template class iterator; // const handle to a 3D array or view element template class const_handle { public: typedef Container container_type; typedef typename container_type::value_type value_type; protected: // protected constructor explicit const_handle(const container_type* container, size_t x, size_t y, size_t z) : container(const_cast(container)), x(x), y(y), z(z) {} // dereference handle value_type get() const { return container->get(x, y, z); } container_type* container; // container size_t x, y, z; // global element index }; } // dim3 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/handle4.hpp000066400000000000000000000020261453723256400215270ustar00rootroot00000000000000#ifndef ZFP_HANDLE4_HPP #define ZFP_HANDLE4_HPP namespace zfp { namespace internal { namespace dim4 { // forward declarations template class const_reference; template class const_pointer; template class const_iterator; template class reference; template class pointer; template class iterator; // const handle to a 4D array or view element template class const_handle { public: typedef Container container_type; typedef typename container_type::value_type value_type; protected: // protected constructor explicit const_handle(const container_type* container, size_t x, size_t y, size_t z, size_t w) : container(const_cast(container)), x(x), y(y), z(z), w(w) {} // dereference handle value_type get() const { return container->get(x, y, z, w); } container_type* container; // container size_t x, y, z, w; // global element index }; } // dim4 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/header.hpp000066400000000000000000000017531453723256400214460ustar00rootroot00000000000000// abstract base class for array header class header { public: // default constructor header() : type(zfp_type_none), nx(0), ny(0), nz(0), nw(0) {} // constructor header(const zfp::array& a) : type(a.type), nx(a.nx), ny(a.ny), nz(a.nz), nw(a.nw) {} // destructor virtual ~header() {} // array scalar type zfp_type scalar_type() const { return type; } // array dimensionality uint dimensionality() const { return nw ? 4 : nz ? 3 : ny ? 2 : nx ? 1 : 0; } // array dimensions size_t size_x() const { return nx; } size_t size_y() const { return ny; } size_t size_z() const { return nz; } size_t size_w() const { return nw; } // rate in bits per value virtual double rate() const = 0; // header payload: data pointer and byte size virtual const void* data() const = 0; virtual size_t size_bytes(uint mask = ZFP_DATA_HEADER) const = 0; protected: zfp_type type; // array scalar type size_t nx, ny, nz, nw; // array dimensions }; zfp-1.0.1/include/zfp/internal/array/iterator1.hpp000066400000000000000000000135351453723256400221310ustar00rootroot00000000000000#ifndef ZFP_ITERATOR1_HPP #define ZFP_ITERATOR1_HPP namespace zfp { namespace internal { namespace dim1 { // random access const iterator that visits 1D array or view block by block template class const_iterator : public const_handle { public: // typedefs for STL compatibility typedef Container container_type; typedef typename container_type::value_type value_type; typedef ptrdiff_t difference_type; typedef zfp::internal::dim1::reference reference; typedef zfp::internal::dim1::pointer pointer; typedef std::random_access_iterator_tag iterator_category; typedef zfp::internal::dim1::const_reference const_reference; typedef zfp::internal::dim1::const_pointer const_pointer; // default constructor const_iterator() : const_handle(0, 0) {} // constructor explicit const_iterator(const container_type* container, size_t x) : const_handle(container, x) {} // dereference iterator const_reference operator*() const { return const_reference(container, x); } const_reference operator[](difference_type d) const { return *operator+(d); } // iterator arithmetic const_iterator operator+(difference_type d) const { const_iterator it = *this; it.advance(d); return it; } const_iterator operator-(difference_type d) const { return operator+(-d); } difference_type operator-(const const_iterator& it) const { return offset() - it.offset(); } // equality operators bool operator==(const const_iterator& it) const { return container == it.container && x == it.x; } bool operator!=(const const_iterator& it) const { return !operator==(it); } // relational operators bool operator<=(const const_iterator& it) const { return container == it.container && offset() <= it.offset(); } bool operator>=(const const_iterator& it) const { return container == it.container && offset() >= it.offset(); } bool operator<(const const_iterator& it) const { return container == it.container && offset() < it.offset(); } bool operator>(const const_iterator& it) const { return container == it.container && offset() > it.offset(); } // increment and decrement const_iterator& operator++() { increment(); return *this; } const_iterator& operator--() { decrement(); return *this; } const_iterator operator++(int) { const_iterator it = *this; increment(); return it; } const_iterator operator--(int) { const_iterator it = *this; decrement(); return it; } const_iterator operator+=(difference_type d) { advance(+d); return *this; } const_iterator operator-=(difference_type d) { advance(-d); return *this; } // local container index of value referenced by iterator size_t i() const { return x - container->min_x(); } protected: // sequential offset associated with index x plus delta d difference_type offset(difference_type d = 0) const { return static_cast(x - container->min_x() + size_t(d)); } // index x associated with sequential offset p void index(size_t& x, difference_type p) const { x = container->min_x() + size_t(p); } // advance iterator by d void advance(difference_type d) { index(x, offset(d)); } // increment iterator to next element void increment() { ++x; } // decrement iterator to previous element void decrement() { --x; } using const_handle::container; using const_handle::x; }; // random access iterator that visits 1D array or view block by block template class iterator : public const_iterator { public: // typedefs for STL compatibility typedef Container container_type; typedef typename container_type::value_type value_type; typedef ptrdiff_t difference_type; typedef zfp::internal::dim1::reference reference; typedef zfp::internal::dim1::pointer pointer; typedef std::random_access_iterator_tag iterator_category; // default constructor iterator() : const_iterator(0, 0) {} // constructor explicit iterator(container_type* container, size_t i) : const_iterator(container, i) {} // dereference iterator reference operator*() const { return reference(container, x); } reference operator[](difference_type d) const { return *operator+(d); } // iterator arithmetic iterator operator+(difference_type d) const { iterator it = *this; it.advance(d); return it; } iterator operator-(difference_type d) const { return operator+(-d); } difference_type operator-(const iterator& it) const { return offset() - it.offset(); } // equality operators bool operator==(const iterator& it) const { return container == it.container && x == it.x; } bool operator!=(const iterator& it) const { return !operator==(it); } // relational operators bool operator<=(const iterator& it) const { return container == it.container && offset() <= it.offset(); } bool operator>=(const iterator& it) const { return container == it.container && offset() >= it.offset(); } bool operator<(const iterator& it) const { return container == it.container && offset() < it.offset(); } bool operator>(const iterator& it) const { return container == it.container && offset() > it.offset(); } // increment and decrement iterator& operator++() { increment(); return *this; } iterator& operator--() { decrement(); return *this; } iterator operator++(int) { iterator it = *this; increment(); return it; } iterator operator--(int) { iterator it = *this; decrement(); return it; } iterator operator+=(difference_type d) { advance(+d); return *this; } iterator operator-=(difference_type d) { advance(-d); return *this; } protected: using const_iterator::offset; using const_iterator::advance; using const_iterator::increment; using const_iterator::decrement; using const_iterator::container; using const_iterator::x; }; } // dim1 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/iterator2.hpp000066400000000000000000000207361453723256400221330ustar00rootroot00000000000000#ifndef ZFP_ITERATOR2_HPP #define ZFP_ITERATOR2_HPP namespace zfp { namespace internal { namespace dim2 { // random access const iterator that visits 2D array or view block by block template class const_iterator : public const_handle { public: // typedefs for STL compatibility typedef Container container_type; typedef typename container_type::value_type value_type; typedef ptrdiff_t difference_type; typedef zfp::internal::dim2::reference reference; typedef zfp::internal::dim2::pointer pointer; typedef std::random_access_iterator_tag iterator_category; typedef zfp::internal::dim2::const_reference const_reference; typedef zfp::internal::dim2::const_pointer const_pointer; // default constructor const_iterator() : const_handle(0, 0, 0) {} // constructor explicit const_iterator(const container_type* container, size_t x, size_t y) : const_handle(container, x, y) {} // dereference iterator const_reference operator*() const { return const_reference(container, x, y); } const_reference operator[](difference_type d) const { return *operator+(d); } // iterator arithmetic const_iterator operator+(difference_type d) const { const_iterator it = *this; it.advance(d); return it; } const_iterator operator-(difference_type d) const { return operator+(-d); } difference_type operator-(const const_iterator& it) const { return offset() - it.offset(); } // equality operators bool operator==(const const_iterator& it) const { return container == it.container && x == it.x && y == it.y; } bool operator!=(const const_iterator& it) const { return !operator==(it); } // relational operators bool operator<=(const const_iterator& it) const { return container == it.container && offset() <= it.offset(); } bool operator>=(const const_iterator& it) const { return container == it.container && offset() >= it.offset(); } bool operator<(const const_iterator& it) const { return container == it.container && offset() < it.offset(); } bool operator>(const const_iterator& it) const { return container == it.container && offset() > it.offset(); } // increment and decrement const_iterator& operator++() { increment(); return *this; } const_iterator& operator--() { decrement(); return *this; } const_iterator operator++(int) { const_iterator it = *this; increment(); return it; } const_iterator operator--(int) { const_iterator it = *this; decrement(); return it; } const_iterator operator+=(difference_type d) { advance(+d); return *this; } const_iterator operator-=(difference_type d) { advance(-d); return *this; } // local container index of value referenced by iterator size_t i() const { return x - container->min_x(); } size_t j() const { return y - container->min_y(); } protected: // sequential offset associated with index (x, y) plus delta d difference_type offset(difference_type d = 0) const { difference_type p = d; size_t xmin = container->min_x(); size_t xmax = container->max_x(); size_t ymin = container->min_y(); size_t ymax = container->max_y(); size_t nx = xmax - xmin; size_t ny = ymax - ymin; if (y == ymax) p += nx * ny; else { size_t m = ~size_t(3); size_t by = std::max(y & m, ymin); size_t sy = std::min((by + 4) & m, ymax) - by; p += (by - ymin) * nx; size_t bx = std::max(x & m, xmin); size_t sx = std::min((bx + 4) & m, xmax) - bx; p += (bx - xmin) * sy; p += (y - by) * sx; p += (x - bx); } return p; } // index (x, y) associated with sequential offset p void index(size_t& x, size_t& y, difference_type p) const { size_t xmin = container->min_x(); size_t xmax = container->max_x(); size_t ymin = container->min_y(); size_t ymax = container->max_y(); size_t nx = xmax - xmin; size_t ny = ymax - ymin; if (size_t(p) == nx * ny) { x = xmin; y = ymax; } else { size_t m = ~size_t(3); size_t by = std::max((ymin + size_t(p / ptrdiff_t(nx))) & m, ymin); size_t sy = std::min((by + 4) & m, ymax) - by; p -= (by - ymin) * nx; size_t bx = std::max((xmin + size_t(p / ptrdiff_t(sy))) & m, xmin); size_t sx = std::min((bx + 4) & m, xmax) - bx; p -= (bx - xmin) * sy; y = by + size_t(p / ptrdiff_t(sx)); p -= (y - by) * sx; x = bx + size_t(p); p -= (x - bx); } } // advance iterator by d void advance(difference_type d) { index(x, y, offset(d)); } // increment iterator to next element void increment() { size_t xmin = container->min_x(); size_t xmax = container->max_x(); size_t ymin = container->min_y(); size_t ymax = container->max_y(); size_t m = ~size_t(3); ++x; if (!(x & 3u) || x == xmax) { x = std::max((x - 1) & m, xmin); ++y; if (!(y & 3u) || y == ymax) { y = std::max((y - 1) & m, ymin); // done with block; advance to next x = (x + 4) & m; if (x >= xmax) { x = xmin; y = (y + 4) & m; if (y >= ymax) y = ymax; } } } } // decrement iterator to previous element void decrement() { size_t xmin = container->min_x(); size_t xmax = container->max_x(); size_t ymin = container->min_y(); size_t ymax = container->max_y(); size_t m = ~size_t(3); if (y == ymax) { x = xmax - 1; y = ymax - 1; } else { if (!(x & 3u) || x == xmin) { x = std::min((x + 4) & m, xmax); if (!(y & 3u) || y == ymin) { y = std::min((y + 4) & m, ymax); // done with block; advance to next x = (x - 1) & m; if (x <= xmin) { x = xmax; y = (y - 1) & m; if (y <= ymin) y = ymin; } } --y; } --x; } } using const_handle::container; using const_handle::x; using const_handle::y; }; // random access iterator that visits 2D array or view block by block template class iterator : public const_iterator { public: // typedefs for STL compatibility typedef Container container_type; typedef typename container_type::value_type value_type; typedef ptrdiff_t difference_type; typedef zfp::internal::dim2::reference reference; typedef zfp::internal::dim2::pointer pointer; typedef std::random_access_iterator_tag iterator_category; // default constructor iterator() : const_iterator(0, 0, 0) {} // constructor explicit iterator(container_type* container, size_t x, size_t y) : const_iterator(container, x, y) {} // dereference iterator reference operator*() const { return reference(container, x, y); } reference operator[](difference_type d) const { return *operator+(d); } // iterator arithmetic iterator operator+(difference_type d) const { iterator it = *this; it.advance(d); return it; } iterator operator-(difference_type d) const { return operator+(-d); } difference_type operator-(const iterator& it) const { return offset() - it.offset(); } // equality operators bool operator==(const iterator& it) const { return container == it.container && x == it.x && y == it.y; } bool operator!=(const iterator& it) const { return !operator==(it); } // relational operators bool operator<=(const iterator& it) const { return container == it.container && offset() <= it.offset(); } bool operator>=(const iterator& it) const { return container == it.container && offset() >= it.offset(); } bool operator<(const iterator& it) const { return container == it.container && offset() < it.offset(); } bool operator>(const iterator& it) const { return container == it.container && offset() > it.offset(); } // increment and decrement iterator& operator++() { increment(); return *this; } iterator& operator--() { decrement(); return *this; } iterator operator++(int) { iterator it = *this; increment(); return it; } iterator operator--(int) { iterator it = *this; decrement(); return it; } iterator operator+=(difference_type d) { advance(+d); return *this; } iterator operator-=(difference_type d) { advance(-d); return *this; } protected: using const_iterator::offset; using const_iterator::advance; using const_iterator::increment; using const_iterator::decrement; using const_iterator::container; using const_iterator::x; using const_iterator::y; }; } // dim2 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/iterator3.hpp000066400000000000000000000236631453723256400221360ustar00rootroot00000000000000#ifndef ZFP_ITERATOR3_HPP #define ZFP_ITERATOR3_HPP namespace zfp { namespace internal { namespace dim3 { // random access const iterator that visits 3D array or view block by block template class const_iterator : public const_handle { public: // typedefs for STL compatibility typedef Container container_type; typedef typename container_type::value_type value_type; typedef ptrdiff_t difference_type; typedef zfp::internal::dim3::reference reference; typedef zfp::internal::dim3::pointer pointer; typedef std::random_access_iterator_tag iterator_category; typedef zfp::internal::dim3::const_reference const_reference; typedef zfp::internal::dim3::const_pointer const_pointer; // default constructor const_iterator() : const_handle(0, 0, 0, 0) {} // constructor explicit const_iterator(const container_type* container, size_t x, size_t y, size_t z) : const_handle(container, x, y, z) {} // dereference iterator const_reference operator*() const { return const_reference(container, x, y, z); } const_reference operator[](difference_type d) const { return *operator+(d); } // iterator arithmetic const_iterator operator+(difference_type d) const { const_iterator it = *this; it.advance(d); return it; } const_iterator operator-(difference_type d) const { return operator+(-d); } difference_type operator-(const const_iterator& it) const { return offset() - it.offset(); } // equality operators bool operator==(const const_iterator& it) const { return container == it.container && x == it.x && y == it.y && z == it.z; } bool operator!=(const const_iterator& it) const { return !operator==(it); } // relational operators bool operator<=(const const_iterator& it) const { return container == it.container && offset() <= it.offset(); } bool operator>=(const const_iterator& it) const { return container == it.container && offset() >= it.offset(); } bool operator<(const const_iterator& it) const { return container == it.container && offset() < it.offset(); } bool operator>(const const_iterator& it) const { return container == it.container && offset() > it.offset(); } // increment and decrement const_iterator& operator++() { increment(); return *this; } const_iterator& operator--() { decrement(); return *this; } const_iterator operator++(int) { const_iterator it = *this; increment(); return it; } const_iterator operator--(int) { const_iterator it = *this; decrement(); return it; } const_iterator operator+=(difference_type d) { advance(+d); return *this; } const_iterator operator-=(difference_type d) { advance(-d); return *this; } // local container index of value referenced by iterator size_t i() const { return x - container->min_x(); } size_t j() const { return y - container->min_y(); } size_t k() const { return z - container->min_z(); } protected: // sequential offset associated with index (x, y, z) plus delta d difference_type offset(difference_type d = 0) const { difference_type p = d; size_t xmin = container->min_x(); size_t xmax = container->max_x(); size_t ymin = container->min_y(); size_t ymax = container->max_y(); size_t zmin = container->min_z(); size_t zmax = container->max_z(); size_t nx = xmax - xmin; size_t ny = ymax - ymin; size_t nz = zmax - zmin; if (z == zmax) p += nx * ny * nz; else { size_t m = ~size_t(3); size_t bz = std::max(z & m, zmin); size_t sz = std::min((bz + 4) & m, zmax) - bz; p += (bz - zmin) * nx * ny; size_t by = std::max(y & m, ymin); size_t sy = std::min((by + 4) & m, ymax) - by; p += (by - ymin) * nx * sz; size_t bx = std::max(x & m, xmin); size_t sx = std::min((bx + 4) & m, xmax) - bx; p += (bx - xmin) * sy * sz; p += (z - bz) * sx * sy; p += (y - by) * sx; p += (x - bx); } return p; } // index (x, y, z) associated with sequential offset p void index(size_t& x, size_t& y, size_t& z, difference_type p) const { size_t xmin = container->min_x(); size_t xmax = container->max_x(); size_t ymin = container->min_y(); size_t ymax = container->max_y(); size_t zmin = container->min_z(); size_t zmax = container->max_z(); size_t nx = xmax - xmin; size_t ny = ymax - ymin; size_t nz = zmax - zmin; if (size_t(p) == nx * ny * nz) { x = xmin; y = ymin; z = zmax; } else { size_t m = ~size_t(3); size_t bz = std::max((zmin + size_t(p / ptrdiff_t(nx * ny))) & m, zmin); size_t sz = std::min((bz + 4) & m, zmax) - bz; p -= (bz - zmin) * nx * ny; size_t by = std::max((ymin + size_t(p / ptrdiff_t(nx * sz))) & m, ymin); size_t sy = std::min((by + 4) & m, ymax) - by; p -= (by - ymin) * nx * sz; size_t bx = std::max((xmin + size_t(p / ptrdiff_t(sy * sz))) & m, xmin); size_t sx = std::min((bx + 4) & m, xmax) - bx; p -= (bx - xmin) * sy * sz; z = bz + size_t(p / ptrdiff_t(sx * sy)); p -= (z - bz) * sx * sy; y = by + size_t(p / ptrdiff_t(sx)); p -= (y - by) * sx; x = bx + size_t(p); p -= (x - bx); } } // advance iterator by d void advance(difference_type d) { index(x, y, z, offset(d)); } // increment iterator to next element void increment() { size_t xmin = container->min_x(); size_t xmax = container->max_x(); size_t ymin = container->min_y(); size_t ymax = container->max_y(); size_t zmin = container->min_z(); size_t zmax = container->max_z(); size_t m = ~size_t(3); ++x; if (!(x & 3u) || x == xmax) { x = std::max((x - 1) & m, xmin); ++y; if (!(y & 3u) || y == ymax) { y = std::max((y - 1) & m, ymin); ++z; if (!(z & 3u) || z == zmax) { z = std::max((z - 1) & m, zmin); // done with block; advance to next x = (x + 4) & m; if (x >= xmax) { x = xmin; y = (y + 4) & m; if (y >= ymax) { y = ymin; z = (z + 4) & m; if (z >= zmax) z = zmax; } } } } } } // decrement iterator to previous element void decrement() { size_t xmin = container->min_x(); size_t xmax = container->max_x(); size_t ymin = container->min_y(); size_t ymax = container->max_y(); size_t zmin = container->min_z(); size_t zmax = container->max_z(); size_t m = ~size_t(3); if (z == zmax) { x = xmax - 1; y = ymax - 1; z = zmax - 1; } else { if (!(x & 3u) || x == xmin) { x = std::min((x + 4) & m, xmax); if (!(y & 3u) || y == ymin) { y = std::min((y + 4) & m, ymax); if (!(z & 3u) || z == zmin) { z = std::min((z + 4) & m, zmax); // done with block; advance to next x = (x - 1) & m; if (x <= xmin) { x = xmax; y = (y - 1) & m; if (y <= ymin) { y = ymax; z = (z - 1) & m; if (z <= zmin) z = zmin; } } } --z; } --y; } --x; } } using const_handle::container; using const_handle::x; using const_handle::y; using const_handle::z; }; // random access iterator that visits 3D array or view block by block template class iterator : public const_iterator { public: // typedefs for STL compatibility typedef Container container_type; typedef typename container_type::value_type value_type; typedef ptrdiff_t difference_type; typedef zfp::internal::dim3::reference reference; typedef zfp::internal::dim3::pointer pointer; typedef std::random_access_iterator_tag iterator_category; // default constructor iterator() : const_iterator(0, 0, 0, 0) {} // constructor explicit iterator(container_type* container, size_t x, size_t y, size_t z) : const_iterator(container, x, y, z) {} // dereference iterator reference operator*() const { return reference(container, x, y, z); } reference operator[](difference_type d) const { return *operator+(d); } // iterator arithmetic iterator operator+(difference_type d) const { iterator it = *this; it.advance(d); return it; } iterator operator-(difference_type d) const { return operator+(-d); } difference_type operator-(const iterator& it) const { return offset() - it.offset(); } // equality operators bool operator==(const iterator& it) const { return container == it.container && x == it.x && y == it.y && z == it.z; } bool operator!=(const iterator& it) const { return !operator==(it); } // relational operators bool operator<=(const iterator& it) const { return container == it.container && offset() <= it.offset(); } bool operator>=(const iterator& it) const { return container == it.container && offset() >= it.offset(); } bool operator<(const iterator& it) const { return container == it.container && offset() < it.offset(); } bool operator>(const iterator& it) const { return container == it.container && offset() > it.offset(); } // increment and decrement iterator& operator++() { increment(); return *this; } iterator& operator--() { decrement(); return *this; } iterator operator++(int) { iterator it = *this; increment(); return it; } iterator operator--(int) { iterator it = *this; decrement(); return it; } iterator operator+=(difference_type d) { advance(+d); return *this; } iterator operator-=(difference_type d) { advance(-d); return *this; } protected: using const_iterator::offset; using const_iterator::advance; using const_iterator::increment; using const_iterator::decrement; using const_iterator::container; using const_iterator::x; using const_iterator::y; using const_iterator::z; }; } // dim3 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/iterator4.hpp000066400000000000000000000267721453723256400221430ustar00rootroot00000000000000#ifndef ZFP_ITERATOR4_HPP #define ZFP_ITERATOR4_HPP namespace zfp { namespace internal { namespace dim4 { // random access const iterator that visits 4D array or view block by block template class const_iterator : public const_handle { public: // typedefs for STL compatibility typedef Container container_type; typedef typename container_type::value_type value_type; typedef ptrdiff_t difference_type; typedef zfp::internal::dim4::reference reference; typedef zfp::internal::dim4::pointer pointer; typedef std::random_access_iterator_tag iterator_category; typedef zfp::internal::dim4::const_reference const_reference; typedef zfp::internal::dim4::const_pointer const_pointer; // default constructor const_iterator() : const_handle(0, 0, 0, 0, 0) {} // constructor explicit const_iterator(const container_type* container, size_t x, size_t y, size_t z, size_t w) : const_handle(container, x, y, z, w) {} // dereference iterator const_reference operator*() const { return const_reference(container, x, y, z, w); } const_reference operator[](difference_type d) const { return *operator+(d); } // iterator arithmetic const_iterator operator+(difference_type d) const { const_iterator it = *this; it.advance(d); return it; } const_iterator operator-(difference_type d) const { return operator+(-d); } difference_type operator-(const const_iterator& it) const { return offset() - it.offset(); } // equality operators bool operator==(const const_iterator& it) const { return container == it.container && x == it.x && y == it.y && z == it.z && w == it.w; } bool operator!=(const const_iterator& it) const { return !operator==(it); } // relational operators bool operator<=(const const_iterator& it) const { return container == it.container && offset() <= it.offset(); } bool operator>=(const const_iterator& it) const { return container == it.container && offset() >= it.offset(); } bool operator<(const const_iterator& it) const { return container == it.container && offset() < it.offset(); } bool operator>(const const_iterator& it) const { return container == it.container && offset() > it.offset(); } // increment and decrement const_iterator& operator++() { increment(); return *this; } const_iterator& operator--() { decrement(); return *this; } const_iterator operator++(int) { const_iterator it = *this; increment(); return it; } const_iterator operator--(int) { const_iterator it = *this; decrement(); return it; } const_iterator operator+=(difference_type d) { advance(+d); return *this; } const_iterator operator-=(difference_type d) { advance(-d); return *this; } // local container index of value referenced by iterator size_t i() const { return x - container->min_x(); } size_t j() const { return y - container->min_y(); } size_t k() const { return z - container->min_z(); } size_t l() const { return w - container->min_w(); } protected: // sequential offset associated with index (x, y, z, w) plus delta d difference_type offset(difference_type d = 0) const { difference_type p = d; size_t xmin = container->min_x(); size_t xmax = container->max_x(); size_t ymin = container->min_y(); size_t ymax = container->max_y(); size_t zmin = container->min_z(); size_t zmax = container->max_z(); size_t wmin = container->min_w(); size_t wmax = container->max_w(); size_t nx = xmax - xmin; size_t ny = ymax - ymin; size_t nz = zmax - zmin; size_t nw = wmax - wmin; if (w == wmax) p += nx * ny * nz * nw; else { size_t m = ~size_t(3); size_t bw = std::max(w & m, wmin); size_t sw = std::min((bw + 4) & m, wmax) - bw; p += (bw - wmin) * nx * ny * nz; size_t bz = std::max(z & m, zmin); size_t sz = std::min((bz + 4) & m, zmax) - bz; p += (bz - zmin) * nx * ny * sw; size_t by = std::max(y & m, ymin); size_t sy = std::min((by + 4) & m, ymax) - by; p += (by - ymin) * nx * sz * sw; size_t bx = std::max(x & m, xmin); size_t sx = std::min((bx + 4) & m, xmax) - bx; p += (bx - xmin) * sy * sz * sw; p += (w - bw) * sx * sy * sz; p += (z - bz) * sx * sy; p += (y - by) * sx; p += (x - bx); } return p; } // index (x, y, z, w) associated with sequential offset p void index(size_t& x, size_t& y, size_t& z, size_t& w, difference_type p) const { size_t xmin = container->min_x(); size_t xmax = container->max_x(); size_t ymin = container->min_y(); size_t ymax = container->max_y(); size_t zmin = container->min_z(); size_t zmax = container->max_z(); size_t wmin = container->min_w(); size_t wmax = container->max_w(); size_t nx = xmax - xmin; size_t ny = ymax - ymin; size_t nz = zmax - zmin; size_t nw = wmax - wmin; if (size_t(p) == nx * ny * nz * nw) { x = xmin; y = ymin; z = zmin; w = wmax; } else { size_t m = ~size_t(3); size_t bw = std::max((wmin + size_t(p / ptrdiff_t(nx * ny * nz))) & m, wmin); size_t sw = std::min((bw + 4) & m, wmax) - bw; p -= (bw - wmin) * nx * ny * nz; size_t bz = std::max((zmin + size_t(p / ptrdiff_t(nx * ny * sw))) & m, zmin); size_t sz = std::min((bz + 4) & m, zmax) - bz; p -= (bz - zmin) * nx * ny * sw; size_t by = std::max((ymin + size_t(p / ptrdiff_t(nx * sz * sw))) & m, ymin); size_t sy = std::min((by + 4) & m, ymax) - by; p -= (by - ymin) * nx * sz * sw; size_t bx = std::max((xmin + size_t(p / ptrdiff_t(sy * sz * sw))) & m, xmin); size_t sx = std::min((bx + 4) & m, xmax) - bx; p -= (bx - xmin) * sy * sz * sw; w = bw + size_t(p / ptrdiff_t(sx * sy * sz)); p -= (w - bw) * sx * sy * sz; z = bz + size_t(p / ptrdiff_t(sx * sy)); p -= (z - bz) * sx * sy; y = by + size_t(p / ptrdiff_t(sx)); p -= (y - by) * sx; x = bx + size_t(p); p -= (x - bx); } } // advance iterator by d void advance(difference_type d) { index(x, y, z, w, offset(d)); } // increment iterator to next element void increment() { size_t xmin = container->min_x(); size_t xmax = container->max_x(); size_t ymin = container->min_y(); size_t ymax = container->max_y(); size_t zmin = container->min_z(); size_t zmax = container->max_z(); size_t wmin = container->min_w(); size_t wmax = container->max_w(); size_t m = ~size_t(3); ++x; if (!(x & 3u) || x == xmax) { x = std::max((x - 1) & m, xmin); ++y; if (!(y & 3u) || y == ymax) { y = std::max((y - 1) & m, ymin); ++z; if (!(z & 3u) || z == zmax) { z = std::max((z - 1) & m, zmin); ++w; if (!(w & 3u) || w == wmax) { w = std::max((w - 1) & m, wmin); // done with block; advance to next x = (x + 4) & m; if (x >= xmax) { x = xmin; y = (y + 4) & m; if (y >= ymax) { y = ymin; z = (z + 4) & m; if (z >= zmax) { z = zmin; w = (w + 4) & m; if (w >= wmax) w = wmax; } } } } } } } } // decrement iterator to previous element void decrement() { size_t xmin = container->min_x(); size_t xmax = container->max_x(); size_t ymin = container->min_y(); size_t ymax = container->max_y(); size_t zmin = container->min_z(); size_t zmax = container->max_z(); size_t wmin = container->min_w(); size_t wmax = container->max_w(); size_t m = ~size_t(3); if (w == wmax) { x = xmax - 1; y = ymax - 1; z = zmax - 1; w = wmax - 1; } else { if (!(x & 3u) || x == xmin) { x = std::min((x + 4) & m, xmax); if (!(y & 3u) || y == ymin) { y = std::min((y + 4) & m, ymax); if (!(z & 3u) || z == zmin) { z = std::min((z + 4) & m, zmax); if (!(w & 3u) || w == wmin) { w = std::min((w + 4) & m, wmax); // done with block; advance to next x = (x - 1) & m; if (x <= xmin) { x = xmax; y = (y - 1) & m; if (y <= ymin) { y = ymax; z = (z - 1) & m; if (z <= zmin) { z = zmax; w = (w - 1) & m; if (w <= wmin) w = wmin; } } } } --w; } --z; } --y; } --x; } } using const_handle::container; using const_handle::x; using const_handle::y; using const_handle::z; using const_handle::w; }; // random access iterator that visits 4D array or view block by block template class iterator : public const_iterator { public: // typedefs for STL compatibility typedef Container container_type; typedef typename container_type::value_type value_type; typedef ptrdiff_t difference_type; typedef zfp::internal::dim4::reference reference; typedef zfp::internal::dim4::pointer pointer; typedef std::random_access_iterator_tag iterator_category; // default constructor iterator() : const_iterator(0, 0, 0, 0, 0) {} // constructor explicit iterator(container_type* container, size_t x, size_t y, size_t z, size_t w) : const_iterator(container, x, y, z, w) {} // dereference iterator reference operator*() const { return reference(container, x, y, z, w); } reference operator[](difference_type d) const { return *operator+(d); } // iterator arithmetic iterator operator+(difference_type d) const { iterator it = *this; it.advance(d); return it; } iterator operator-(difference_type d) const { return operator+(-d); } difference_type operator-(const iterator& it) const { return offset() - it.offset(); } // equality operators bool operator==(const iterator& it) const { return container == it.container && x == it.x && y == it.y && z == it.z && w == it.w; } bool operator!=(const iterator& it) const { return !operator==(it); } // relational operators bool operator<=(const iterator& it) const { return container == it.container && offset() <= it.offset(); } bool operator>=(const iterator& it) const { return container == it.container && offset() >= it.offset(); } bool operator<(const iterator& it) const { return container == it.container && offset() < it.offset(); } bool operator>(const iterator& it) const { return container == it.container && offset() > it.offset(); } // increment and decrement iterator& operator++() { increment(); return *this; } iterator& operator--() { decrement(); return *this; } iterator operator++(int) { iterator it = *this; increment(); return it; } iterator operator--(int) { iterator it = *this; decrement(); return it; } iterator operator+=(difference_type d) { advance(+d); return *this; } iterator operator-=(difference_type d) { advance(-d); return *this; } protected: using const_iterator::offset; using const_iterator::advance; using const_iterator::increment; using const_iterator::decrement; using const_iterator::container; using const_iterator::x; using const_iterator::y; using const_iterator::z; using const_iterator::w; }; } // dim4 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/memory.hpp000066400000000000000000000106511453723256400215230ustar00rootroot00000000000000#ifndef ZFP_MEMORY_HPP #define ZFP_MEMORY_HPP // Memory management for POD types only. Templated functions are provided only // to avoid the need for casts to/from void* in pass-by-reference calls. #ifdef _WIN32 extern "C" { #ifdef __MINGW32__ #include #endif #include } #endif #include #include #include // byte alignment of compressed data #ifndef ZFP_MEMORY_ALIGNMENT #define ZFP_MEMORY_ALIGNMENT 0x100u #endif #define unused_(x) ((void)(x)) namespace zfp { namespace internal { // allocate size bytes inline void* allocate(size_t size) { void* ptr = std::malloc(size); if (!ptr) throw std::bad_alloc(); return ptr; } // allocate size bytes with suggested alignment inline void* allocate_aligned(size_t size, size_t alignment) { void* ptr = 0; #ifdef ZFP_WITH_ALIGNED_ALLOC #if defined(__INTEL_COMPILER) ptr = _mm_malloc(size, alignment); #elif defined(__MINGW32__) // require: alignment is an integer power of two ptr = __mingw_aligned_malloc(size, alignment); #elif defined(_WIN32) // require: alignment is an integer power of two ptr = _aligned_malloc(size, alignment); #elif defined(__MACH__) || (_POSIX_C_SOURCE >= 200112L) || (_XOPEN_SOURCE >= 600) // require: alignment is an integer power of two >= sizeof(void*) posix_memalign(&ptr, alignment, size); #else // aligned allocation not supported; fall back on unaligned allocation unused_(alignment); ptr = allocate(size); #endif #else // aligned allocation not enabled; use unaligned allocation unused_(alignment); ptr = allocate(size); #endif if (!ptr) throw std::bad_alloc(); return ptr; } // deallocate memory pointed to by ptr inline void deallocate(void* ptr) { std::free(ptr); } // deallocate aligned memory pointed to by ptr inline void deallocate_aligned(void* ptr) { if (!ptr) return; #ifdef ZFP_WITH_ALIGNED_ALLOC #ifdef __INTEL_COMPILER _mm_free(ptr); #elif defined(__MINGW32__) __mingw_aligned_free(ptr); #elif defined(_WIN32) _aligned_free(ptr); #else std::free(ptr); #endif #else std::free(ptr); #endif } // reallocate buffer to size bytes template inline void reallocate(T*& ptr, size_t size, bool preserve = false) { if (preserve) ptr = static_cast(std::realloc(ptr, size)); else { zfp::internal::deallocate(ptr); ptr = static_cast(zfp::internal::allocate(size)); } } // reallocate buffer to new_size bytes with suggested alignment template inline void reallocate_aligned(T*& ptr, size_t new_size, size_t alignment, size_t old_size = 0) { void* p = ptr; reallocate_aligned(p, new_size, alignment, old_size); ptr = static_cast(p); } // untyped reallocate buffer to new_size bytes with suggested alignment template <> inline void reallocate_aligned(void*& ptr, size_t new_size, size_t alignment, size_t old_size) { if (old_size) { // reallocate while preserving contents void* dst = zfp::internal::allocate_aligned(new_size, alignment); std::memcpy(dst, ptr, std::min(old_size, new_size)); zfp::internal::deallocate_aligned(ptr); ptr = dst; } else { // reallocate without preserving contents zfp::internal::deallocate_aligned(ptr); ptr = zfp::internal::allocate_aligned(new_size, alignment); } } // clone array 'T src[count]' to dst template inline void clone(T*& dst, const T* src, size_t count) { zfp::internal::deallocate(dst); if (src) { dst = static_cast(zfp::internal::allocate(count * sizeof(T))); std::copy(src, src + count, dst); } else dst = 0; } // clone array 'T src[count]' to dst with suggested alignment template inline void clone_aligned(T*& dst, const T* src, size_t count, size_t alignment) { void* d = dst; const void* s = src; clone_aligned(d, s, count * sizeof(T), alignment); dst = static_cast(d); src = static_cast(s); } // untyped, aligned clone of size bytes template <> inline void clone_aligned(void*& dst, const void* src, size_t size, size_t alignment) { zfp::internal::deallocate_aligned(dst); if (src) { dst = zfp::internal::allocate_aligned(size, alignment); std::memcpy(dst, src, size); } else dst = 0; } // return smallest multiple of unit greater than or equal to size inline size_t round_up(size_t size, size_t unit) { size += unit - 1; size -= size % unit; return size; } } } #undef unused_ #endif zfp-1.0.1/include/zfp/internal/array/pointer1.hpp000066400000000000000000000116321453723256400217540ustar00rootroot00000000000000#ifndef ZFP_POINTER1_HPP #define ZFP_POINTER1_HPP namespace zfp { namespace internal { namespace dim1 { // const pointer to a 1D array or view element template class const_pointer : public const_handle { public: typedef Container container_type; typedef typename container_type::value_type value_type; // default constructor const_pointer() : const_handle(0, 0) {} #if defined(__cplusplus) && __cplusplus >= 201103L const_pointer(std::nullptr_t) : const_handle(0, 0) {} #endif // constructor explicit const_pointer(const container_type* container, size_t x) : const_handle(container, x) {} // dereference pointer const_reference operator*() const { return const_reference(container, x); } const_reference operator[](ptrdiff_t d) const { return *operator+(d); } // pointer arithmetic const_pointer operator+(ptrdiff_t d) const { const_pointer p = *this; p.advance(d); return p; } const_pointer operator-(ptrdiff_t d) const { return operator+(-d); } ptrdiff_t operator-(const const_pointer& p) const { return offset() - p.offset(); } // equality operators bool operator==(const const_pointer& p) const { return container == p.container && x == p.x; } bool operator!=(const const_pointer& p) const { return !operator==(p); } // relational operators bool operator<=(const const_pointer& p) const { return container == p.container && offset() <= p.offset(); } bool operator>=(const const_pointer& p) const { return container == p.container && offset() >= p.offset(); } bool operator<(const const_pointer& p) const { return container == p.container && offset() < p.offset(); } bool operator>(const const_pointer& p) const { return container == p.container && offset() > p.offset(); } // increment and decrement const_pointer& operator++() { increment(); return *this; } const_pointer& operator--() { decrement(); return *this; } const_pointer operator++(int) { const_pointer p = *this; increment(); return p; } const_pointer operator--(int) { const_pointer p = *this; decrement(); return p; } const_pointer operator+=(ptrdiff_t d) { advance(+d); return *this; } const_pointer operator-=(ptrdiff_t d) { advance(-d); return *this; } protected: ptrdiff_t offset(ptrdiff_t d = 0) const { return static_cast(x - container->min_x()) + d; } void index(size_t& x, ptrdiff_t p) const { x = container->min_x() + size_t(p); } void advance(ptrdiff_t d) { index(x, offset(d)); } void increment() { ++x; } void decrement() { --x; } using const_handle::container; using const_handle::x; }; // pointer to a 1D array or view element template class pointer : public const_pointer { public: typedef Container container_type; typedef typename container_type::value_type value_type; // default constructor pointer() : const_pointer(0, 0) {} #if defined(__cplusplus) && __cplusplus >= 201103L pointer(std::nullptr_t) : const_pointer(0, 0) {} #endif // constructor explicit pointer(container_type* container, size_t x) : const_pointer(container, x) {} // dereference pointer reference operator*() const { return reference(container, x); } reference operator[](ptrdiff_t d) const { return *operator+(d); } // pointer arithmetic pointer operator+(ptrdiff_t d) const { pointer p = *this; p.advance(d); return p; } pointer operator-(ptrdiff_t d) const { return operator+(-d); } ptrdiff_t operator-(const pointer& p) const { return offset() - p.offset(); } // equality operators bool operator==(const pointer& p) const { return container == p.container && x == p.x; } bool operator!=(const pointer& p) const { return !operator==(p); } // relational operators bool operator<=(const pointer& p) const { return container == p.container && offset() <= p.offset(); } bool operator>=(const pointer& p) const { return container == p.container && offset() >= p.offset(); } bool operator<(const pointer& p) const { return container == p.container && offset() < p.offset(); } bool operator>(const pointer& p) const { return container == p.container && offset() > p.offset(); } // increment and decrement pointer& operator++() { increment(); return *this; } pointer& operator--() { decrement(); return *this; } pointer operator++(int) { pointer p = *this; increment(); return p; } pointer operator--(int) { pointer p = *this; decrement(); return p; } pointer operator+=(ptrdiff_t d) { advance(+d); return *this; } pointer operator-=(ptrdiff_t d) { advance(-d); return *this; } protected: using const_pointer::offset; using const_pointer::advance; using const_pointer::increment; using const_pointer::decrement; using const_pointer::container; using const_pointer::x; }; } // dim1 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/pointer2.hpp000066400000000000000000000125711453723256400217600ustar00rootroot00000000000000#ifndef ZFP_POINTER2_HPP #define ZFP_POINTER2_HPP namespace zfp { namespace internal { namespace dim2 { // const pointer to a 2D array or view element template class const_pointer : public const_handle { public: typedef Container container_type; typedef typename container_type::value_type value_type; // default constructor const_pointer() : const_handle(0, 0, 0) {} #if defined(__cplusplus) && __cplusplus >= 201103L const_pointer(std::nullptr_t) : const_handle(0, 0, 0) {} #endif // constructor explicit const_pointer(const container_type* container, size_t x, size_t y) : const_handle(container, x, y) {} // dereference pointer const_reference operator*() const { return const_reference(container, x, y); } const_reference operator[](ptrdiff_t d) const { return *operator+(d); } // pointer arithmetic const_pointer operator+(ptrdiff_t d) const { const_pointer p = *this; p.advance(d); return p; } const_pointer operator-(ptrdiff_t d) const { return operator+(-d); } ptrdiff_t operator-(const const_pointer& p) const { return offset() - p.offset(); } // equality operators bool operator==(const const_pointer& p) const { return container == p.container && x == p.x && y == p.y; } bool operator!=(const const_pointer& p) const { return !operator==(p); } // relational operators bool operator<=(const const_pointer& p) const { return container == p.container && offset() <= p.offset(); } bool operator>=(const const_pointer& p) const { return container == p.container && offset() >= p.offset(); } bool operator<(const const_pointer& p) const { return container == p.container && offset() < p.offset(); } bool operator>(const const_pointer& p) const { return container == p.container && offset() > p.offset(); } // increment and decrement const_pointer& operator++() { increment(); return *this; } const_pointer& operator--() { decrement(); return *this; } const_pointer operator++(int) { const_pointer p = *this; increment(); return p; } const_pointer operator--(int) { const_pointer p = *this; decrement(); return p; } const_pointer operator+=(ptrdiff_t d) { advance(+d); return *this; } const_pointer operator-=(ptrdiff_t d) { advance(-d); return *this; } protected: ptrdiff_t offset(ptrdiff_t d = 0) const { return static_cast(x - container->min_x() + container->size_x() * (y - container->min_y())) + d; } void index(size_t& x, size_t& y, ptrdiff_t p) const { x = container->min_x() + size_t(p % ptrdiff_t(container->size_x())); p /= container->size_x(); y = container->min_y() + size_t(p); } void advance(ptrdiff_t d) { index(x, y, offset(d)); } void increment() { if (++x == container->max_x()) { x = container->min_x(); ++y; } } void decrement() { if (x-- == container->min_x()) { x += container->size_x(); --y; } } using const_handle::container; using const_handle::x; using const_handle::y; }; // pointer to a 2D array or view element template class pointer : public const_pointer { public: typedef Container container_type; typedef typename container_type::value_type value_type; // default constructor pointer() : const_pointer(0, 0, 0) {} #if defined(__cplusplus) && __cplusplus >= 201103L pointer(std::nullptr_t) : const_pointer(0, 0, 0) {} #endif // constructor explicit pointer(container_type* container, size_t x, size_t y) : const_pointer(container, x, y) {} // dereference pointer reference operator*() const { return reference(container, x, y); } reference operator[](ptrdiff_t d) const { return *operator+(d); } // pointer arithmetic pointer operator+(ptrdiff_t d) const { pointer p = *this; p.advance(d); return p; } pointer operator-(ptrdiff_t d) const { return operator+(-d); } ptrdiff_t operator-(const pointer& p) const { return offset() - p.offset(); } // equality operators bool operator==(const pointer& p) const { return container == p.container && x == p.x && y == p.y; } bool operator!=(const pointer& p) const { return !operator==(p); } // relational operators bool operator<=(const pointer& p) const { return container == p.container && offset() <= p.offset(); } bool operator>=(const pointer& p) const { return container == p.container && offset() >= p.offset(); } bool operator<(const pointer& p) const { return container == p.container && offset() < p.offset(); } bool operator>(const pointer& p) const { return container == p.container && offset() > p.offset(); } // increment and decrement pointer& operator++() { increment(); return *this; } pointer& operator--() { decrement(); return *this; } pointer operator++(int) { pointer p = *this; increment(); return p; } pointer operator--(int) { pointer p = *this; decrement(); return p; } pointer operator+=(ptrdiff_t d) { advance(+d); return *this; } pointer operator-=(ptrdiff_t d) { advance(-d); return *this; } protected: using const_pointer::offset; using const_pointer::advance; using const_pointer::increment; using const_pointer::decrement; using const_pointer::container; using const_pointer::x; using const_pointer::y; }; } // dim2 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/pointer3.hpp000066400000000000000000000135141453723256400217570ustar00rootroot00000000000000#ifndef ZFP_POINTER3_HPP #define ZFP_POINTER3_HPP namespace zfp { namespace internal { namespace dim3 { // const pointer to a 3D array or view element template class const_pointer : public const_handle { public: typedef Container container_type; typedef typename container_type::value_type value_type; // default constructor const_pointer() : const_handle(0, 0, 0, 0) {} #if defined(__cplusplus) && __cplusplus >= 201103L const_pointer(std::nullptr_t) : const_handle(0, 0, 0, 0) {} #endif // constructor explicit const_pointer(const container_type* container, size_t x, size_t y, size_t z) : const_handle(container, x, y, z) {} // dereference pointer const_reference operator*() const { return const_reference(container, x, y, z); } const_reference operator[](ptrdiff_t d) const { return *operator+(d); } // pointer arithmetic const_pointer operator+(ptrdiff_t d) const { const_pointer p = *this; p.advance(d); return p; } const_pointer operator-(ptrdiff_t d) const { return operator+(-d); } ptrdiff_t operator-(const const_pointer& p) const { return offset() - p.offset(); } // equality operators bool operator==(const const_pointer& p) const { return container == p.container && x == p.x && y == p.y && z == p.z; } bool operator!=(const const_pointer& p) const { return !operator==(p); } // relational operators bool operator<=(const const_pointer& p) const { return container == p.container && offset() <= p.offset(); } bool operator>=(const const_pointer& p) const { return container == p.container && offset() >= p.offset(); } bool operator<(const const_pointer& p) const { return container == p.container && offset() < p.offset(); } bool operator>(const const_pointer& p) const { return container == p.container && offset() > p.offset(); } // increment and decrement const_pointer& operator++() { increment(); return *this; } const_pointer& operator--() { decrement(); return *this; } const_pointer operator++(int) { const_pointer p = *this; increment(); return p; } const_pointer operator--(int) { const_pointer p = *this; decrement(); return p; } const_pointer operator+=(ptrdiff_t d) { advance(+d); return *this; } const_pointer operator-=(ptrdiff_t d) { advance(-d); return *this; } protected: ptrdiff_t offset(ptrdiff_t d = 0) const { return static_cast(x - container->min_x() + container->size_x() * (y - container->min_y() + container->size_y() * (z - container->min_z()))) + d; } void index(size_t& x, size_t& y, size_t& z, ptrdiff_t p) const { x = container->min_x() + size_t(p % ptrdiff_t(container->size_x())); p /= container->size_x(); y = container->min_y() + size_t(p % ptrdiff_t(container->size_y())); p /= container->size_y(); z = container->min_z() + size_t(p); } void advance(ptrdiff_t d) { index(x, y, z, offset(d)); } void increment() { if (++x == container->max_x()) { x = container->min_x(); if (++y == container->max_y()) { y = container->min_y(); ++z; } } } void decrement() { if (x-- == container->min_x()) { x += container->size_x(); if (y-- == container->min_y()) { y += container->size_y(); --z; } } } using const_handle::container; using const_handle::x; using const_handle::y; using const_handle::z; }; // pointer to a 3D array or view element template class pointer : public const_pointer { public: typedef Container container_type; typedef typename container_type::value_type value_type; // default constructor pointer() : const_pointer(0, 0, 0, 0) {} #if defined(__cplusplus) && __cplusplus >= 201103L pointer(std::nullptr_t) : const_pointer(0, 0, 0, 0) {} #endif // constructor explicit pointer(container_type* container, size_t x, size_t y, size_t z) : const_pointer(container, x, y, z) {} // dereference pointer reference operator*() const { return reference(container, x, y, z); } reference operator[](ptrdiff_t d) const { return *operator+(d); } // pointer arithmetic pointer operator+(ptrdiff_t d) const { pointer p = *this; p.advance(d); return p; } pointer operator-(ptrdiff_t d) const { return operator+(-d); } ptrdiff_t operator-(const pointer& p) const { return offset() - p.offset(); } // equality operators bool operator==(const pointer& p) const { return container == p.container && x == p.x && y == p.y && z == p.z; } bool operator!=(const pointer& p) const { return !operator==(p); } // relational operators bool operator<=(const pointer& p) const { return container == p.container && offset() <= p.offset(); } bool operator>=(const pointer& p) const { return container == p.container && offset() >= p.offset(); } bool operator<(const pointer& p) const { return container == p.container && offset() < p.offset(); } bool operator>(const pointer& p) const { return container == p.container && offset() > p.offset(); } // increment and decrement pointer& operator++() { increment(); return *this; } pointer& operator--() { decrement(); return *this; } pointer operator++(int) { pointer p = *this; increment(); return p; } pointer operator--(int) { pointer p = *this; decrement(); return p; } pointer operator+=(ptrdiff_t d) { advance(+d); return *this; } pointer operator-=(ptrdiff_t d) { advance(-d); return *this; } protected: using const_pointer::offset; using const_pointer::advance; using const_pointer::increment; using const_pointer::decrement; using const_pointer::container; using const_pointer::x; using const_pointer::y; using const_pointer::z; }; } // dim3 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/pointer4.hpp000066400000000000000000000144541453723256400217640ustar00rootroot00000000000000#ifndef ZFP_POINTER4_HPP #define ZFP_POINTER4_HPP namespace zfp { namespace internal { namespace dim4 { // const pointer to a 4D array or view element template class const_pointer : public const_handle { public: typedef Container container_type; typedef typename container_type::value_type value_type; // default constructor const_pointer() : const_handle(0, 0, 0, 0, 0) {} #if defined(__cplusplus) && __cplusplus >= 201103L const_pointer(std::nullptr_t) : const_handle(0, 0, 0, 0, 0) {} #endif // constructor explicit const_pointer(const container_type* container, size_t x, size_t y, size_t z, size_t w) : const_handle(container, x, y, z, w) {} // dereference pointer const_reference operator*() const { return const_reference(container, x, y, z, w); } const_reference operator[](ptrdiff_t d) const { return *operator+(d); } // pointer arithmetic const_pointer operator+(ptrdiff_t d) const { const_pointer p = *this; p.advance(d); return p; } const_pointer operator-(ptrdiff_t d) const { return operator+(-d); } ptrdiff_t operator-(const const_pointer& p) const { return offset() - p.offset(); } // equality operators bool operator==(const const_pointer& p) const { return container == p.container && x == p.x && y == p.y && z == p.z && w == p.w; } bool operator!=(const const_pointer& p) const { return !operator==(p); } // relational operators bool operator<=(const const_pointer& p) const { return container == p.container && offset() <= p.offset(); } bool operator>=(const const_pointer& p) const { return container == p.container && offset() >= p.offset(); } bool operator<(const const_pointer& p) const { return container == p.container && offset() < p.offset(); } bool operator>(const const_pointer& p) const { return container == p.container && offset() > p.offset(); } // increment and decrement const_pointer& operator++() { increment(); return *this; } const_pointer& operator--() { decrement(); return *this; } const_pointer operator++(int) { const_pointer p = *this; increment(); return p; } const_pointer operator--(int) { const_pointer p = *this; decrement(); return p; } const_pointer operator+=(ptrdiff_t d) { advance(+d); return *this; } const_pointer operator-=(ptrdiff_t d) { advance(-d); return *this; } protected: ptrdiff_t offset(ptrdiff_t d = 0) const { return static_cast(x - container->min_x() + container->size_x() * (y - container->min_y() + container->size_y() * (z - container->min_z() + container->size_z() * (w - container->min_w())))) + d; } void index(size_t& x, size_t& y, size_t& z, size_t & w, ptrdiff_t p) const { x = container->min_x() + size_t(p % ptrdiff_t(container->size_x())); p /= container->size_x(); y = container->min_y() + size_t(p % ptrdiff_t(container->size_y())); p /= container->size_y(); z = container->min_z() + size_t(p % ptrdiff_t(container->size_z())); p /= container->size_z(); w = container->min_w() + size_t(p); } void advance(ptrdiff_t d) { index(x, y, z, w, offset(d)); } void increment() { if (++x == container->max_x()) { x = container->min_x(); if (++y == container->max_y()) { y = container->min_y(); if (++z == container->max_z()) { z = container->min_z(); ++w; } } } } void decrement() { if (x-- == container->min_x()) { x += container->size_x(); if (y-- == container->min_y()) { y += container->size_y(); if (z-- == container->min_z()) { z += container->size_z(); --w; } } } } using const_handle::container; using const_handle::x; using const_handle::y; using const_handle::z; using const_handle::w; }; // pointer to a 4D array or view element template class pointer : public const_pointer { public: typedef Container container_type; typedef typename container_type::value_type value_type; // default constructor pointer() : const_pointer(0, 0, 0, 0, 0) {} #if defined(__cplusplus) && __cplusplus >= 201103L pointer(std::nullptr_t) : const_pointer(0, 0, 0, 0, 0) {} #endif // constructor explicit pointer(container_type* container, size_t x, size_t y, size_t z, size_t w) : const_pointer(container, x, y, z, w) {} // dereference pointer reference operator*() const { return reference(container, x, y, z, w); } reference operator[](ptrdiff_t d) const { return *operator+(d); } // pointer arithmetic pointer operator+(ptrdiff_t d) const { pointer p = *this; p.advance(d); return p; } pointer operator-(ptrdiff_t d) const { return operator+(-d); } ptrdiff_t operator-(const pointer& p) const { return offset() - p.offset(); } // equality operators bool operator==(const pointer& p) const { return container == p.container && x == p.x && y == p.y && z == p.z && w == p.w; } bool operator!=(const pointer& p) const { return !operator==(p); } // relational operators bool operator<=(const pointer& p) const { return container == p.container && offset() <= p.offset(); } bool operator>=(const pointer& p) const { return container == p.container && offset() >= p.offset(); } bool operator<(const pointer& p) const { return container == p.container && offset() < p.offset(); } bool operator>(const pointer& p) const { return container == p.container && offset() > p.offset(); } // increment and decrement pointer& operator++() { increment(); return *this; } pointer& operator--() { decrement(); return *this; } pointer operator++(int) { pointer p = *this; increment(); return p; } pointer operator--(int) { pointer p = *this; decrement(); return p; } pointer operator+=(ptrdiff_t d) { advance(+d); return *this; } pointer operator-=(ptrdiff_t d) { advance(-d); return *this; } protected: using const_pointer::offset; using const_pointer::advance; using const_pointer::increment; using const_pointer::decrement; using const_pointer::container; using const_pointer::x; using const_pointer::y; using const_pointer::z; using const_pointer::w; }; } // dim4 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/reference1.hpp000066400000000000000000000045021453723256400222300ustar00rootroot00000000000000#ifndef ZFP_REFERENCE1_HPP #define ZFP_REFERENCE1_HPP namespace zfp { namespace internal { namespace dim1 { // const reference to a 1D array or view element template class const_reference : const_handle { public: typedef Container container_type; typedef typename container_type::value_type value_type; // constructor explicit const_reference(const container_type* container, size_t x) : const_handle(container, x) {} // inspector operator value_type() const { return get(); } // pointer to referenced element const_pointer operator&() const { return const_pointer(container, x); } protected: using const_handle::get; using const_handle::container; using const_handle::x; }; // reference to a 1D array or view element template class reference : public const_reference { public: typedef Container container_type; typedef typename container_type::value_type value_type; // constructor explicit reference(container_type* container, size_t x) : const_reference(container, x) {} // copy constructor (to satisfy rule of three) reference(const reference& r) : const_reference(r.container, r.x) {} // assignment reference operator=(const reference& r) { set(r.get()); return *this; } reference operator=(value_type val) { set(val); return *this; } // compound assignment reference operator+=(value_type val) { container->add(x, val); return *this; } reference operator-=(value_type val) { container->sub(x, val); return *this; } reference operator*=(value_type val) { container->mul(x, val); return *this; } reference operator/=(value_type val) { container->div(x, val); return *this; } // pointer to referenced element pointer operator&() const { return pointer(container, x); } // swap two array elements via proxy references friend void swap(reference a, reference b) { value_type x = a.get(); value_type y = b.get(); b.set(x); a.set(y); } protected: // assign value through reference void set(value_type val) { container->set(x, val); } using const_reference::get; using const_reference::container; using const_reference::x; }; } // dim1 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/reference2.hpp000066400000000000000000000047011453723256400222320ustar00rootroot00000000000000#ifndef ZFP_REFERENCE2_HPP #define ZFP_REFERENCE2_HPP namespace zfp { namespace internal { namespace dim2 { // const reference to a 2D array or view element template class const_reference : const_handle { public: typedef Container container_type; typedef typename container_type::value_type value_type; // constructor explicit const_reference(const container_type* container, size_t x, size_t y) : const_handle(container, x, y) {} // inspector operator value_type() const { return get(); } // pointer to referenced element const_pointer operator&() const { return const_pointer(container, x, y); } protected: using const_handle::get; using const_handle::container; using const_handle::x; using const_handle::y; }; // reference to a 2D array or view element template class reference : public const_reference { public: typedef Container container_type; typedef typename container_type::value_type value_type; // constructor explicit reference(container_type* container, size_t x, size_t y) : const_reference(container, x, y) {} // copy constructor (to satisfy rule of three) reference(const reference& r) : const_reference(r.container, r.x, r.y) {} // assignment reference operator=(const reference& r) { set(r.get()); return *this; } reference operator=(value_type val) { set(val); return *this; } // compound assignment reference operator+=(value_type val) { container->add(x, y, val); return *this; } reference operator-=(value_type val) { container->sub(x, y, val); return *this; } reference operator*=(value_type val) { container->mul(x, y, val); return *this; } reference operator/=(value_type val) { container->div(x, y, val); return *this; } // pointer to referenced element pointer operator&() const { return pointer(container, x, y); } // swap two array elements via proxy references friend void swap(reference a, reference b) { value_type x = a.get(); value_type y = b.get(); b.set(x); a.set(y); } protected: // assign value through reference void set(value_type val) { container->set(x, y, val); } using const_reference::get; using const_reference::container; using const_reference::x; using const_reference::y; }; } // dim2 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/reference3.hpp000066400000000000000000000051001453723256400222250ustar00rootroot00000000000000#ifndef ZFP_REFERENCE3_HPP #define ZFP_REFERENCE3_HPP namespace zfp { namespace internal { namespace dim3 { // const reference to a 3D array or view element template class const_reference : const_handle { public: typedef Container container_type; typedef typename container_type::value_type value_type; // constructor explicit const_reference(const container_type* container, size_t x, size_t y, size_t z) : const_handle(container, x, y, z) {} // inspector operator value_type() const { return get(); } // pointer to referenced element const_pointer operator&() const { return const_pointer(container, x, y, z); } protected: using const_handle::get; using const_handle::container; using const_handle::x; using const_handle::y; using const_handle::z; }; // reference to a 3D array or view element template class reference : public const_reference { public: typedef Container container_type; typedef typename container_type::value_type value_type; // constructor explicit reference(container_type* container, size_t x, size_t y, size_t z) : const_reference(container, x, y, z) {} // copy constructor (to satisfy rule of three) reference(const reference& r) : const_reference(r.container, r.x, r.y, r.z) {} // assignment reference operator=(const reference& r) { set(r.get()); return *this; } reference operator=(value_type val) { set(val); return *this; } // compound assignment reference operator+=(value_type val) { container->add(x, y, z, val); return *this; } reference operator-=(value_type val) { container->sub(x, y, z, val); return *this; } reference operator*=(value_type val) { container->mul(x, y, z, val); return *this; } reference operator/=(value_type val) { container->div(x, y, z, val); return *this; } // pointer to referenced element pointer operator&() const { return pointer(container, x, y, z); } // swap two array elements via proxy references friend void swap(reference a, reference b) { value_type x = a.get(); value_type y = b.get(); b.set(x); a.set(y); } protected: // assign value through reference void set(value_type val) { container->set(x, y, z, val); } using const_reference::get; using const_reference::container; using const_reference::x; using const_reference::y; using const_reference::z; }; } // dim3 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/reference4.hpp000066400000000000000000000052771453723256400222450ustar00rootroot00000000000000#ifndef ZFP_REFERENCE4_HPP #define ZFP_REFERENCE4_HPP namespace zfp { namespace internal { namespace dim4 { // const reference to a 4D array or view element template class const_reference : const_handle { public: typedef Container container_type; typedef typename container_type::value_type value_type; // constructor explicit const_reference(const container_type* container, size_t x, size_t y, size_t z, size_t w) : const_handle(container, x, y, z, w) {} // inspector operator value_type() const { return get(); } // pointer to referenced element const_pointer operator&() const { return const_pointer(container, x, y, z, w); } protected: using const_handle::get; using const_handle::container; using const_handle::x; using const_handle::y; using const_handle::z; using const_handle::w; }; // reference to a 4D array or view element template class reference : public const_reference { public: typedef Container container_type; typedef typename container_type::value_type value_type; // constructor explicit reference(container_type* container, size_t x, size_t y, size_t z, size_t w) : const_reference(container, x, y, z, w) {} // copy constructor (to satisfy rule of three) reference(const reference& r) : const_reference(r.container, r.x, r.y, r.z, r.w) {} // assignment reference operator=(const reference& r) { set(r.get()); return *this; } reference operator=(value_type val) { set(val); return *this; } // compound assignment reference operator+=(value_type val) { container->add(x, y, z, w, val); return *this; } reference operator-=(value_type val) { container->sub(x, y, z, w, val); return *this; } reference operator*=(value_type val) { container->mul(x, y, z, w, val); return *this; } reference operator/=(value_type val) { container->div(x, y, z, w, val); return *this; } // pointer to referenced element pointer operator&() const { return pointer(container, x, y, z, w); } // swap two array elements via proxy references friend void swap(reference a, reference b) { value_type x = a.get(); value_type y = b.get(); b.set(x); a.set(y); } protected: // assign value through reference void set(value_type val) { container->set(x, y, z, w, val); } using const_reference::get; using const_reference::container; using const_reference::x; using const_reference::y; using const_reference::z; using const_reference::w; }; } // dim4 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/store.hpp000066400000000000000000000150241453723256400213460ustar00rootroot00000000000000#ifndef ZFP_STORE_HPP #define ZFP_STORE_HPP #include #include #include "zfp/internal/array/memory.hpp" namespace zfp { namespace internal { // base class for block store template class BlockStore { public: // compression mode zfp_mode mode() const { return codec.mode(); } // rate in bits per value (fixed-rate mode only) double rate() const { return codec.rate(); } // precision in uncompressed bits per value (fixed-precision mode only) uint precision() const { return codec.precision(); } // accuracy as absolute error tolerance (fixed-accuracy mode only) double accuracy() const { return codec.accuracy(); } // compression parameters (all compression modes) void params(uint* minbits, uint* maxbits, uint* maxprec, int* minexp) const { codec.params(minbits, maxbits, maxprec, minexp); } // enable reversible (lossless) mode void set_reversible() { set_variable_rate(); codec.set_reversible(); clear(); } // set fixed rate in compressed bits per value with optional word alignment double set_rate(double rate, bool align) { rate = codec.set_rate(rate, align); uint maxbits; codec.params(0, &maxbits, 0, 0); index.set_block_size(maxbits); alloc(true); return rate; } // set precision in uncompressed bits per value uint set_precision(uint precision) { set_variable_rate(); precision = codec.set_precision(precision); clear(); return precision; } // set accuracy as absolute error tolerance double set_accuracy(double tolerance) { set_variable_rate(); tolerance = codec.set_accuracy(tolerance); clear(); return tolerance; } // set expert mode compression parameters bool set_params(uint minbits, uint maxbits, uint maxprec, int minexp) { if (minbits != maxbits) set_variable_rate(); bool status = codec.set_params(minbits, maxbits, maxprec, minexp); clear(); return status; } // set compression mode and parameters void set_config(const zfp_config& config) { switch (config.mode) { case zfp_mode_reversible: set_reversible(); break; case zfp_mode_fixed_rate: if (config.arg.rate < 0) set_rate(-config.arg.rate, true); else set_rate(+config.arg.rate, false); break; case zfp_mode_fixed_precision: set_precision(config.arg.precision); break; case zfp_mode_fixed_accuracy: set_accuracy(config.arg.tolerance); break; case zfp_mode_expert: set_params(config.arg.expert.minbits, config.arg.expert.maxbits, config.arg.expert.maxprec, config.arg.expert.minexp); break; default: throw zfp::exception("zfp compression mode not supported by array"); } } // clear store and reallocate memory for buffer void clear() { index.clear(); alloc(true); } // flush any buffered block index data void flush() { index.flush(); } // shrink buffer to match size of compressed data void compact() { size_t size = zfp::internal::round_up(index.range(), codec.alignment() * CHAR_BIT) / CHAR_BIT; if (bytes > size) { codec.close(); zfp::internal::reallocate_aligned(data, size, ZFP_MEMORY_ALIGNMENT, bytes); bytes = size; codec.open(data, bytes); } } // increment private view reference count (for thread safety) void reference() { #ifdef _OPENMP #pragma omp critical(references) { references++; codec.set_thread_safety(references > 1); } #endif } // decrement private view reference count (for thread safety) void unreference() { #ifdef _OPENMP #pragma omp critical(references) { references--; codec.set_thread_safety(references > 1); } #endif } // byte size of store data structure components indicated by mask virtual size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += index.size_bytes(mask); size += codec.size_bytes(mask); if (mask & ZFP_DATA_PAYLOAD) size += bytes; if (mask & ZFP_DATA_META) size += sizeof(*this); return size; } // number of bytes of compressed data size_t compressed_size() const { return bytes; } // pointer to compressed data for read or write access void* compressed_data() const { return data; } protected: // protected default constructor BlockStore() : data(0), bytes(0), references(0), index(0) {} // destructor virtual ~BlockStore() { free(); } // buffer size in bytes needed for current codec settings virtual size_t buffer_size() const = 0; // number of elements per block virtual size_t block_size() const = 0; // total number of blocks virtual size_t blocks() const = 0; // ensure variable rate is supported void set_variable_rate() { if (!index.has_variable_rate()) throw zfp::exception("zfp index does not support variable rate"); } // perform a deep copy void deep_copy(const BlockStore& s) { free(); zfp::internal::clone_aligned(data, s.data, s.bytes, ZFP_MEMORY_ALIGNMENT); bytes = s.bytes; references = s.references; index = s.index; codec = s.codec; codec.open(data, bytes); } // allocate memory for block store void alloc(bool clear) { free(); bytes = buffer_size(); zfp::internal::reallocate_aligned(data, bytes, ZFP_MEMORY_ALIGNMENT); if (clear) std::fill(static_cast(data), static_cast(data) + bytes, uchar(0)); codec.open(data, bytes); } // free block store void free() { if (data) { zfp::internal::deallocate_aligned(data); data = 0; bytes = 0; codec.close(); } } // bit offset to block store bitstream_offset offset(size_t block_index) const { return index.block_offset(block_index); } // shape 0 <= m <= 3 of block containing index i, 0 <= i <= n - 1 static uint shape_code(size_t i, size_t n) { // handle partial blocks efficiently using no conditionals size_t m = i ^ n; // m < 4 iff partial block m -= 4; // m < 0 iff partial block m >>= CHAR_BIT * sizeof(m) - 2; // m = 3 iff partial block; otherwise m = 0 m &= -n; // m = 4 - w return static_cast(m); } void* data; // pointer to compressed blocks size_t bytes; // compressed data size size_t references; // private view references to array (for thread safety) Index index; // block index (size and offset) Codec codec; // compression codec }; } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/store1.hpp000066400000000000000000000065451453723256400214370ustar00rootroot00000000000000#ifndef ZFP_STORE1_HPP #define ZFP_STORE1_HPP #include "zfp/internal/array/store.hpp" namespace zfp { namespace internal { // compressed block store for 1D array template class BlockStore1 : public BlockStore { public: // default constructor BlockStore1() : nx(0), bx(0) {} // block store for array of size nx and given configuration BlockStore1(size_t nx, const zfp_config& config) { set_size(nx); this->set_config(config); } // perform a deep copy void deep_copy(const BlockStore1& s) { free(); BlockStore::deep_copy(s); nx = s.nx; bx = s.bx; } // resize array void resize(size_t nx, bool clear = true) { free(); set_size(nx); if (blocks()) alloc(clear); } // byte size of store data structure components indicated by mask virtual size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += BlockStore::size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this) - sizeof(BlockStore); return size; } // conservative buffer size virtual size_t buffer_size() const { zfp_field* field = zfp_field_1d(0, codec.type, nx); size_t size = codec.buffer_size(field); zfp_field_free(field); return size; } // number of elements per block virtual size_t block_size() const { return 4; } // total number of blocks virtual size_t blocks() const { return bx; } // array size in blocks size_t block_size_x() const { return bx; } // flat block index for element i size_t block_index(size_t i) const { return i / 4; } // encoding of block dimensions uint block_shape(size_t block_index) const { size_t i = 4 * block_index; uint mx = shape_code(i, nx); return mx; } // encode contiguous block with given index size_t encode(size_t block_index, const Scalar* block) { size_t size = codec.encode_block(offset(block_index), block_shape(block_index), block); index.set_block_size(block_index, size); return size; } // encode block with given index from strided array size_t encode(size_t block_index, const Scalar* p, ptrdiff_t sx) { size_t size = codec.encode_block_strided(offset(block_index), block_shape(block_index), p, sx); index.set_block_size(block_index, size); return size; } // decode contiguous block with given index size_t decode(size_t block_index, Scalar* block) const { return codec.decode_block(offset(block_index), block_shape(block_index), block); } // decode block with given index to strided array size_t decode(size_t block_index, Scalar* p, ptrdiff_t sx) const { return codec.decode_block_strided(offset(block_index), block_shape(block_index), p, sx); } protected: using BlockStore::alloc; using BlockStore::free; using BlockStore::offset; using BlockStore::shape_code; using BlockStore::index; using BlockStore::codec; // set array dimensions void set_size(size_t nx) { if (nx == 0) { this->nx = 0; bx = 0; } else { this->nx = nx; bx = (nx + 3) / 4; } index.resize(blocks()); } size_t nx; // array dimensions size_t bx; // array dimensions in number of blocks }; } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/store2.hpp000066400000000000000000000073631453723256400214370ustar00rootroot00000000000000#ifndef ZFP_STORE2_HPP #define ZFP_STORE2_HPP #include "zfp/internal/array/store.hpp" namespace zfp { namespace internal { // compressed block store for 2D array template class BlockStore2 : public BlockStore { public: // default constructor BlockStore2() : nx(0), ny(0), bx(0), by(0) {} // block store for array of size nx * ny and given configuration BlockStore2(size_t nx, size_t ny, const zfp_config& config) { set_size(nx, ny); this->set_config(config); } // perform a deep copy void deep_copy(const BlockStore2& s) { free(); BlockStore::deep_copy(s); nx = s.nx; ny = s.ny; bx = s.bx; by = s.by; } // resize array void resize(size_t nx, size_t ny, bool clear = true) { free(); set_size(nx, ny); if (blocks()) alloc(clear); } // byte size of store data structure components indicated by mask virtual size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += BlockStore::size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this) - sizeof(BlockStore); return size; } // conservative buffer size virtual size_t buffer_size() const { zfp_field* field = zfp_field_2d(0, codec.type, nx, ny); size_t size = codec.buffer_size(field); zfp_field_free(field); return size; } // number of elements per block virtual size_t block_size() const { return 4 * 4; } // total number of blocks virtual size_t blocks() const { return bx * by; } // array size in blocks size_t block_size_x() const { return bx; } size_t block_size_y() const { return by; } // flat block index for element (i, j) size_t block_index(size_t i, size_t j) const { return (i / 4) + bx * (j / 4); } // encoding of block dimensions uint block_shape(size_t block_index) const { size_t i = 4 * (block_index % bx); block_index /= bx; size_t j = 4 * block_index; uint mx = shape_code(i, nx); uint my = shape_code(j, ny); return mx + 4 * my; } // encode contiguous block with given index size_t encode(size_t block_index, const Scalar* block) { size_t size = codec.encode_block(offset(block_index), block_shape(block_index), block); index.set_block_size(block_index, size); return size; } // encode block with given index from strided array size_t encode(size_t block_index, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy) { size_t size = codec.encode_block_strided(offset(block_index), block_shape(block_index), p, sx, sy); index.set_block_size(block_index, size); return size; } // decode contiguous block with given index size_t decode(size_t block_index, Scalar* block) const { return codec.decode_block(offset(block_index), block_shape(block_index), block); } // decode block with given index to strided array size_t decode(size_t block_index, Scalar* p, ptrdiff_t sx, ptrdiff_t sy) const { return codec.decode_block_strided(offset(block_index), block_shape(block_index), p, sx, sy); } protected: using BlockStore::alloc; using BlockStore::free; using BlockStore::offset; using BlockStore::shape_code; using BlockStore::index; using BlockStore::codec; // set array dimensions void set_size(size_t nx, size_t ny) { if (nx == 0 || ny == 0) { this->nx = this->ny = 0; bx = by = 0; } else { this->nx = nx; this->ny = ny; bx = (nx + 3) / 4; by = (ny + 3) / 4; } index.resize(blocks()); } size_t nx, ny; // array dimensions size_t bx, by; // array dimensions in number of blocks }; } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/store3.hpp000066400000000000000000000102211453723256400214230ustar00rootroot00000000000000#ifndef ZFP_STORE3_HPP #define ZFP_STORE3_HPP #include "zfp/internal/array/store.hpp" namespace zfp { namespace internal { // compressed block store for 3D array template class BlockStore3 : public BlockStore { public: // default constructor BlockStore3() : nx(0), ny(0), nz(0), bx(0), by(0), bz(0) {} // block store for array of size nx * ny * nz and given configuration BlockStore3(size_t nx, size_t ny, size_t nz, const zfp_config& config) { set_size(nx, ny, nz); this->set_config(config); } // perform a deep copy void deep_copy(const BlockStore3& s) { free(); BlockStore::deep_copy(s); nx = s.nx; ny = s.ny; nz = s.nz; bx = s.bx; by = s.by; bz = s.bz; } // resize array void resize(size_t nx, size_t ny, size_t nz, bool clear = true) { free(); set_size(nx, ny, nz); if (blocks()) alloc(clear); } // byte size of store data structure components indicated by mask virtual size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += BlockStore::size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this) - sizeof(BlockStore); return size; } // conservative buffer size virtual size_t buffer_size() const { zfp_field* field = zfp_field_3d(0, codec.type, nx, ny, nz); size_t size = codec.buffer_size(field); zfp_field_free(field); return size; } // number of elements per block virtual size_t block_size() const { return 4 * 4 * 4; } // total number of blocks virtual size_t blocks() const { return bx * by * bz; } // array size in blocks size_t block_size_x() const { return bx; } size_t block_size_y() const { return by; } size_t block_size_z() const { return bz; } // flat block index for block containing element (i, j, k) size_t block_index(size_t i, size_t j, size_t k) const { return (i / 4) + bx * ((j / 4) + by * (k / 4)); } // encoding of block dimensions uint block_shape(size_t block_index) const { size_t i = 4 * (block_index % bx); block_index /= bx; size_t j = 4 * (block_index % by); block_index /= by; size_t k = 4 * block_index; uint mx = shape_code(i, nx); uint my = shape_code(j, ny); uint mz = shape_code(k, nz); return mx + 4 * (my + 4 * mz); } // encode contiguous block with given index size_t encode(size_t block_index, const Scalar* block) { size_t size = codec.encode_block(offset(block_index), block_shape(block_index), block); index.set_block_size(block_index, size); return size; } // encode block with given index from strided array size_t encode(size_t block_index, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { size_t size = codec.encode_block_strided(offset(block_index), block_shape(block_index), p, sx, sy, sz); index.set_block_size(block_index, size); return size; } // decode contiguous block with given index size_t decode(size_t block_index, Scalar* block) const { return codec.decode_block(offset(block_index), block_shape(block_index), block); } // decode block with given index to strided array size_t decode(size_t block_index, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) const { return codec.decode_block_strided(offset(block_index), block_shape(block_index), p, sx, sy, sz); } protected: using BlockStore::alloc; using BlockStore::free; using BlockStore::offset; using BlockStore::shape_code; using BlockStore::index; using BlockStore::codec; // set array dimensions void set_size(size_t nx, size_t ny, size_t nz) { if (nx == 0 || ny == 0 || nz == 0) { this->nx = this->ny = this->nz = 0; bx = by = bz = 0; } else { this->nx = nx; this->ny = ny; this->nz = nz; bx = (nx + 3) / 4; by = (ny + 3) / 4; bz = (nz + 3) / 4; } index.resize(blocks()); } size_t nx, ny, nz; // array dimensions size_t bx, by, bz; // array dimensions in number of blocks }; } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/store4.hpp000066400000000000000000000110151453723256400214260ustar00rootroot00000000000000#ifndef ZFP_STORE4_HPP #define ZFP_STORE4_HPP #include "zfp/internal/array/store.hpp" namespace zfp { namespace internal { // compressed block store for 4D array template class BlockStore4 : public BlockStore { public: // default constructor BlockStore4() : nx(0), ny(0), nz(0), nw(0), bx(0), by(0), bz(0), bw(0) {} // block store for array of size nx * ny * nz * nw and given configuration BlockStore4(size_t nx, size_t ny, size_t nz, size_t nw, const zfp_config& config) { set_size(nx, ny, nz, nw); this->set_config(config); } // perform a deep copy void deep_copy(const BlockStore4& s) { free(); BlockStore::deep_copy(s); nx = s.nx; ny = s.ny; nz = s.nz; nw = s.nw; bx = s.bx; by = s.by; bz = s.bz; bw = s.bw; } // resize array void resize(size_t nx, size_t ny, size_t nz, size_t nw, bool clear = true) { free(); set_size(nx, ny, nz, nw); if (blocks()) alloc(clear); } // byte size of store data structure components indicated by mask virtual size_t size_bytes(uint mask = ZFP_DATA_ALL) const { size_t size = 0; size += BlockStore::size_bytes(mask); if (mask & ZFP_DATA_META) size += sizeof(*this) - sizeof(BlockStore); return size; } // conservative buffer size virtual size_t buffer_size() const { zfp_field* field = zfp_field_4d(0, codec.type, nx, ny, nz, nw); size_t size = codec.buffer_size(field); zfp_field_free(field); return size; } // number of elements per block virtual size_t block_size() const { return 4 * 4 * 4 * 4; } // total number of blocks virtual size_t blocks() const { return bx * by * bz * bw; } // array size in blocks size_t block_size_x() const { return bx; } size_t block_size_y() const { return by; } size_t block_size_z() const { return bz; } size_t block_size_w() const { return bw; } // flat block index for element (i, j, k, l) size_t block_index(size_t i, size_t j, size_t k, size_t l) const { return (i / 4) + bx * ((j / 4) + by * ((k / 4) + bz * (l / 4))); } // encoding of block dimensions uint block_shape(size_t block_index) const { size_t i = 4 * (block_index % bx); block_index /= bx; size_t j = 4 * (block_index % by); block_index /= by; size_t k = 4 * (block_index % bz); block_index /= bz; size_t l = 4 * block_index; uint mx = shape_code(i, nx); uint my = shape_code(j, ny); uint mz = shape_code(k, nz); uint mw = shape_code(l, nw); return mx + 4 * (my + 4 * (mz + 4 * mw)); } // encode contiguous block with given index size_t encode(size_t block_index, const Scalar* block) { size_t size = codec.encode_block(offset(block_index), block_shape(block_index), block); index.set_block_size(block_index, size); return size; } // encode block with given index from strided array size_t encode(size_t block_index, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { size_t size = codec.encode_block_strided(offset(block_index), block_shape(block_index), p, sx, sy, sz, sw); index.set_block_size(block_index, size); return size; } // decode contiguous block with given index size_t decode(size_t block_index, Scalar* block) const { return codec.decode_block(offset(block_index), block_shape(block_index), block); } // decode block with given index to strided array size_t decode(size_t block_index, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) const { return codec.decode_block_strided(offset(block_index), block_shape(block_index), p, sx, sy, sz, sw); } protected: using BlockStore::alloc; using BlockStore::free; using BlockStore::offset; using BlockStore::shape_code; using BlockStore::index; using BlockStore::codec; // set array dimensions void set_size(size_t nx, size_t ny, size_t nz, size_t nw) { if (nx == 0 || ny == 0 || nz == 0 || nw == 0) { this->nx = this->ny = this->nz = this->nw = 0; bx = by = bz = bw = 0; } else { this->nx = nx; this->ny = ny; this->nz = nz; this->nw = nw; bx = (nx + 3) / 4; by = (ny + 3) / 4; bz = (nz + 3) / 4; bw = (nw + 3) / 4; } index.resize(blocks()); } size_t nx, ny, nz, nw; // array dimensions size_t bx, by, bz, bw; // array dimensions in number of blocks }; } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/traits.hpp000066400000000000000000000011071453723256400215150ustar00rootroot00000000000000#ifndef ZFP_TRAITS_HPP #define ZFP_TRAITS_HPP namespace zfp { namespace internal { // useful type traits template struct trait; /* static const zfp_type type; // corresponding zfp type static const size_t precision; // precision in number of bits */ template <> struct trait { static const zfp_type type = zfp_type_float; static const size_t precision = CHAR_BIT * sizeof(float); }; template <> struct trait { static const zfp_type type = zfp_type_double; static const size_t precision = CHAR_BIT * sizeof(double); }; } } #endif zfp-1.0.1/include/zfp/internal/array/view1.hpp000066400000000000000000000261371453723256400212540ustar00rootroot00000000000000#ifndef ZFP_VIEW1_HPP #define ZFP_VIEW1_HPP // 1D array views namespace zfp { namespace internal { namespace dim1 { // abstract view of 1D array (base class) template class preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; // rate in bits per value double rate() const { return array->rate(); } // dimensions of (sub)array size_t size() const { return nx; } // local to global array index size_t global_x(size_t i) const { return x + i; } protected: // construction and assignment--perform shallow copy of (sub)array explicit preview(container_type* array) : array(array), x(0), nx(array->size_x()) {} explicit preview(container_type* array, size_t x, size_t nx) : array(array), x(x), nx(nx) {} preview& operator=(container_type* a) { array = a; x = 0; nx = a->nx; return *this; } // global index bounds for iterators size_t min_x() const { return x; } size_t max_x() const { return x + nx; } container_type* array; // underlying container size_t x; // offset into array size_t nx; // dimensions of subarray }; // generic read-only view into a rectangular subset of a 1D array template class const_view : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim1::const_reference const_reference; typedef typename zfp::internal::dim1::const_pointer const_pointer; typedef typename zfp::internal::dim1::const_iterator const_iterator; // construction--perform shallow copy of (sub)array const_view(container_type* array) : preview(array) {} const_view(container_type* array, size_t x, size_t nx) : preview(array, x, nx) {} // dimensions of (sub)array size_t size_x() const { return nx; } // [i] inspector const_reference operator[](size_t index) const { return const_reference(this, x + index); } // (i) inspector const_reference operator()(size_t i) const { return const_reference(this, x + i); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x); } const_iterator cend() const { return const_iterator(this, x + nx); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } protected: friend class zfp::internal::dim1::const_handle; friend class zfp::internal::dim1::const_pointer; friend class zfp::internal::dim1::const_iterator; using preview::min_x; using preview::max_x; using preview::array; using preview::x; using preview::nx; // inspector value_type get(size_t x) const { return array->get(x); } }; // generic read-write view into a rectangular subset of a 1D array template class view : public const_view { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim1::const_reference const_reference; typedef typename zfp::internal::dim1::const_pointer const_pointer; typedef typename zfp::internal::dim1::const_iterator const_iterator; typedef typename zfp::internal::dim1::reference reference; typedef typename zfp::internal::dim1::pointer pointer; typedef typename zfp::internal::dim1::iterator iterator; // construction--perform shallow copy of (sub)array view(container_type* array) : const_view(array) {} view(container_type* array, size_t x, size_t nx) : const_view(array, x, nx) {} // [i] inspector const_reference operator[](size_t index) const { return const_reference(this, x + index); } // (i) inspector const_reference operator()(size_t i) const { return const_reference(this, x + i); } // [i] mutator reference operator[](size_t index) { return reference(this, x + index); } // (i) mutator reference operator()(size_t i) { return reference(this, x + i); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x); } const_iterator cend() const { return const_iterator(this, x + nx); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } iterator begin() { return iterator(this, x); } iterator end() { return iterator(this, x + nx); } protected: friend class zfp::internal::dim1::const_handle; friend class zfp::internal::dim1::const_pointer; friend class zfp::internal::dim1::const_iterator; friend class zfp::internal::dim1::reference; friend class zfp::internal::dim1::pointer; friend class zfp::internal::dim1::iterator; using const_view::min_x; using const_view::max_x; using const_view::get; using const_view::array; using const_view::x; using const_view::nx; // mutator void set(size_t x, value_type val) { array->set(x, val); } // in-place updates void add(size_t x, value_type val) { array->add(x, val); } void sub(size_t x, value_type val) { array->sub(x, val); } void mul(size_t x, value_type val) { array->mul(x, val); } void div(size_t x, value_type val) { array->div(x, val); } }; // thread-safe read-only view of 1D (sub)array with private cache template class private_const_view : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename container_type::store_type store_type; typedef typename zfp::internal::dim1::const_reference const_reference; typedef typename zfp::internal::dim1::const_pointer const_pointer; typedef typename zfp::internal::dim1::const_iterator const_iterator; // construction--perform shallow copy of (sub)array private_const_view(container_type* array, size_t cache_size = 0) : preview(array), cache(array->store, cache_size ? cache_size : array->cache.size()) { array->store.reference(); } private_const_view(container_type* array, size_t x, size_t nx, size_t cache_size = 0) : preview(array, x, nx), cache(array->store, cache_size ? cache_size : array->cache.size()) { array->store.reference(); } // destructor ~private_const_view() { array->store.unreference(); } // dimensions of (sub)array size_t size_x() const { return nx; } // cache size in number of bytes size_t cache_size() const { return cache.size(); } // set minimum cache size in bytes (array dimensions must be known) void set_cache_size(size_t bytes) { cache.resize(bytes); } // empty cache without compressing modified cached blocks void clear_cache() const { cache.clear(); } // (i) inspector const_reference operator()(size_t i) const { return const_reference(this, x + i); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x); } const_iterator cend() const { return const_iterator(this, x + nx); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } protected: friend class zfp::internal::dim1::const_handle; friend class zfp::internal::dim1::const_pointer; friend class zfp::internal::dim1::const_iterator; using preview::min_x; using preview::max_x; using preview::array; using preview::x; using preview::nx; // inspector value_type get(size_t x) const { return cache.get(x); } BlockCache1 cache; // cache of decompressed blocks }; // thread-safe read-write view of private 1D (sub)array template class private_view : public private_const_view { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim1::const_reference const_reference; typedef typename zfp::internal::dim1::const_pointer const_pointer; typedef typename zfp::internal::dim1::const_iterator const_iterator; typedef typename zfp::internal::dim1::reference reference; typedef typename zfp::internal::dim1::pointer pointer; typedef typename zfp::internal::dim1::iterator iterator; // construction--perform shallow copy of (sub)array private_view(container_type* array, size_t cache_size = 0) : private_const_view(array, cache_size) {} private_view(container_type* array, size_t x, size_t nx, size_t cache_size = 0) : private_const_view(array, x, nx, cache_size) {} // partition view into count block-aligned pieces, with 0 <= index < count void partition(size_t index, size_t count) { partition(x, nx, index, count); } // flush cache by compressing all modified cached blocks void flush_cache() const { cache.flush(); } // (i) inspector const_reference operator()(size_t i) const { return const_reference(this, x + i); } // (i) mutator reference operator()(size_t i) { return reference(this, x + i); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x); } const_iterator cend() const { return const_iterator(this, x + nx); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } iterator begin() { return iterator(this, x); } iterator end() { return iterator(this, x + nx); } protected: friend class zfp::internal::dim1::const_handle; friend class zfp::internal::dim1::const_pointer; friend class zfp::internal::dim1::const_iterator; friend class zfp::internal::dim1::reference; friend class zfp::internal::dim1::pointer; friend class zfp::internal::dim1::iterator; using private_const_view::min_x; using private_const_view::max_x; using private_const_view::get; using private_const_view::array; using private_const_view::x; using private_const_view::nx; using private_const_view::cache; // block-aligned partition of [offset, offset + size): index out of count static void partition(size_t& offset, size_t& size, size_t index, size_t count) { size_t bmin = offset / 4; size_t bmax = (offset + size + 3) / 4; size_t xmin = std::max(offset + 0, 4 * (bmin + (bmax - bmin) * (index + 0) / count)); size_t xmax = std::min(offset + size, 4 * (bmin + (bmax - bmin) * (index + 1) / count)); offset = xmin; size = xmax - xmin; } // mutator void set(size_t x, value_type val) { cache.set(x, val); } // in-place updates void add(size_t x, value_type val) { cache.ref(x) += val; } void sub(size_t x, value_type val) { cache.ref(x) -= val; } void mul(size_t x, value_type val) { cache.ref(x) *= val; } void div(size_t x, value_type val) { cache.ref(x) /= val; } }; } // dim1 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/view2.hpp000066400000000000000000000460001453723256400212440ustar00rootroot00000000000000#ifndef ZFP_VIEW2_HPP #define ZFP_VIEW2_HPP // 2D array views namespace zfp { namespace internal { namespace dim2 { // abstract view of 2D array (base class) template class preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; // rate in bits per value double rate() const { return array->rate(); } // dimensions of (sub)array size_t size() const { return nx * ny; } // local to global array indices size_t global_x(size_t i) const { return x + i; } size_t global_y(size_t j) const { return y + j; } protected: // construction and assignment--perform shallow copy of (sub)array explicit preview(container_type* array) : array(array), x(0), y(0), nx(array->size_x()), ny(array->size_y()) {} explicit preview(container_type* array, size_t x, size_t y, size_t nx, size_t ny) : array(array), x(x), y(y), nx(nx), ny(ny) {} preview& operator=(container_type* a) { array = a; x = y = 0; nx = a->nx; ny = a->ny; return *this; } // global index bounds for iterators size_t min_x() const { return x; } size_t max_x() const { return x + nx; } size_t min_y() const { return y; } size_t max_y() const { return y + ny; } container_type* array; // underlying container size_t x, y; // offset into array size_t nx, ny; // dimensions of subarray }; // generic read-only view into a rectangular subset of a 2D array template class const_view : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim2::const_reference const_reference; typedef typename zfp::internal::dim2::const_pointer const_pointer; typedef typename zfp::internal::dim2::const_iterator const_iterator; // construction--perform shallow copy of (sub)array const_view(container_type* array) : preview(array) {} const_view(container_type* array, size_t x, size_t y, size_t nx, size_t ny) : preview(array, x, y, nx, ny) {} // dimensions of (sub)array size_t size_x() const { return nx; } size_t size_y() const { return ny; } // (i, j) inspector const_reference operator()(size_t i, size_t j) const { return const_reference(this, x + i, y + j); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x, y); } const_iterator cend() const { return const_iterator(this, x, y + ny); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } protected: friend class zfp::internal::dim2::const_handle; friend class zfp::internal::dim2::const_pointer; friend class zfp::internal::dim2::const_iterator; using preview::min_x; using preview::max_x; using preview::min_y; using preview::max_y; using preview::array; using preview::x; using preview::y; using preview::nx; using preview::ny; // inspector value_type get(size_t x, size_t y) const { return array->get(x, y); } }; // generic read-write view into a rectangular subset of a 2D array template class view : public const_view { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim2::const_reference const_reference; typedef typename zfp::internal::dim2::const_pointer const_pointer; typedef typename zfp::internal::dim2::const_iterator const_iterator; typedef typename zfp::internal::dim2::reference reference; typedef typename zfp::internal::dim2::pointer pointer; typedef typename zfp::internal::dim2::iterator iterator; // construction--perform shallow copy of (sub)array view(container_type* array) : const_view(array) {} view(container_type* array, size_t x, size_t y, size_t nx, size_t ny) : const_view(array, x, y, nx, ny) {} // (i, j) inspector const_reference operator()(size_t i, size_t j) const { return const_reference(this, x + i, y + j); } // (i, j) mutator reference operator()(size_t i, size_t j) { return reference(this, x + i, y + j); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x, y); } const_iterator cend() const { return const_iterator(this, x, y + ny); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } iterator begin() { return iterator(this, x, y); } iterator end() { return iterator(this, x, y + ny); } protected: friend class zfp::internal::dim2::const_handle; friend class zfp::internal::dim2::const_pointer; friend class zfp::internal::dim2::const_iterator; friend class zfp::internal::dim2::reference; friend class zfp::internal::dim2::pointer; friend class zfp::internal::dim2::iterator; using const_view::min_x; using const_view::max_x; using const_view::min_y; using const_view::max_y; using const_view::get; using const_view::array; using const_view::x; using const_view::y; using const_view::nx; using const_view::ny; // mutator void set(size_t x, size_t y, value_type val) { array->set(x, y, val); } // in-place updates void add(size_t x, size_t y, value_type val) { array->add(x, y, val); } void sub(size_t x, size_t y, value_type val) { array->sub(x, y, val); } void mul(size_t x, size_t y, value_type val) { array->mul(x, y, val); } void div(size_t x, size_t y, value_type val) { array->div(x, y, val); } }; // flat view of 2D array (operator[] returns scalar) template class flat_view : public view { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim2::const_reference const_reference; typedef typename zfp::internal::dim2::const_pointer const_pointer; typedef typename zfp::internal::dim2::reference reference; typedef typename zfp::internal::dim2::pointer pointer; // construction--perform shallow copy of (sub)array flat_view(container_type* array) : view(array) {} flat_view(container_type* array, size_t x, size_t y, size_t nx, size_t ny) : view(array, x, y, nx, ny) {} // convert (i, j) index to flat index size_t index(size_t i, size_t j) const { return i + nx * j; } // convert flat index to (i, j) index void ij(size_t& i, size_t& j, size_t index) const { i = index % nx; index /= nx; j = index; } // flat index [] inspector const_reference operator[](size_t index) const { size_t i, j; ij(i, j, index); return const_reference(this, x + i, y + j); } // flat index [] mutator reference operator[](size_t index) { size_t i, j; ij(i, j, index); return reference(this, x + i, y + j); } // (i, j) inspector const_reference operator()(size_t i, size_t j) const { return const_reference(this, x + i, y + j); } // (i, j) mutator reference operator()(size_t i, size_t j) { return reference(this, x + i, y + j); } protected: friend class zfp::internal::dim2::const_handle; friend class zfp::internal::dim2::const_pointer; friend class zfp::internal::dim2::reference; friend class zfp::internal::dim2::pointer; using view::array; using view::x; using view::y; using view::nx; using view::ny; // inspector value_type get(size_t x, size_t y) const { return array->get(x, y); } // mutator void set(size_t x, size_t y, value_type val) { array->set(x, y, val); } // in-place updates void add(size_t x, size_t y, value_type val) { array->add(x, y, val); } void sub(size_t x, size_t y, value_type val) { array->sub(x, y, val); } void mul(size_t x, size_t y, value_type val) { array->mul(x, y, val); } void div(size_t x, size_t y, value_type val) { array->div(x, y, val); } }; // forward declaration of friends template class nested_view1; template class nested_view2; // nested view into a 1D rectangular subset of a 2D array template class nested_view1 : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim2::const_reference const_reference; typedef typename zfp::internal::dim2::const_pointer const_pointer; typedef typename zfp::internal::dim2::reference reference; typedef typename zfp::internal::dim2::pointer pointer; // dimensions of (sub)array size_t size_x() const { return nx; } // [i] inspector and mutator const_reference operator[](size_t index) const { return const_reference(this, x + index, y); } reference operator[](size_t index) { return reference(this, x + index, y); } // (i) inspector and mutator const_reference operator()(size_t i) const { return const_reference(this, x + i, y); } reference operator()(size_t i) { return reference(this, x + i, y); } protected: friend class zfp::internal::dim2::const_handle; friend class zfp::internal::dim2::const_pointer; friend class zfp::internal::dim2::reference; friend class zfp::internal::dim2::pointer; using preview::array; using preview::x; using preview::y; using preview::nx; using preview::ny; // construction--perform shallow copy of (sub)array friend class nested_view2; explicit nested_view1(container_type* array) : preview(array) {} explicit nested_view1(container_type* array, size_t x, size_t y, size_t nx, size_t ny) : preview(array, x, y, nx, ny) {} // inspector value_type get(size_t x, size_t y) const { return array->get(x, y); } // mutator void set(size_t x, size_t y, value_type val) { array->set(x, y, val); } // in-place updates void add(size_t x, size_t y, value_type val) { array->add(x, y, val); } void sub(size_t x, size_t y, value_type val) { array->sub(x, y, val); } void mul(size_t x, size_t y, value_type val) { array->mul(x, y, val); } void div(size_t x, size_t y, value_type val) { array->div(x, y, val); } }; // nested view into a 2D rectangular subset of a 2D array template class nested_view2 : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim2::const_reference const_reference; typedef typename zfp::internal::dim2::const_pointer const_pointer; typedef typename zfp::internal::dim2::reference reference; typedef typename zfp::internal::dim2::pointer pointer; // construction--perform shallow copy of (sub)array nested_view2(container_type* array) : preview(array) {} nested_view2(container_type* array, size_t x, size_t y, size_t nx, size_t ny) : preview(array, x, y, nx, ny) {} // dimensions of (sub)array size_t size_x() const { return nx; } size_t size_y() const { return ny; } // 1D view nested_view1 operator[](size_t index) const { return nested_view1(array, x, y + index, nx, 1); } // (i, j) inspector and mutator const_reference operator()(size_t i, size_t j) const { return const_reference(this, x + i, y + j); } reference operator()(size_t i, size_t j) { return reference(this, x + i, y + j); } protected: friend class zfp::internal::dim2::const_handle; friend class zfp::internal::dim2::const_pointer; friend class zfp::internal::dim2::reference; friend class zfp::internal::dim2::pointer; using preview::array; using preview::x; using preview::y; using preview::nx; using preview::ny; // inspector value_type get(size_t x, size_t y) const { return array->get(x, y); } // mutator void set(size_t x, size_t y, value_type val) { array->set(x, y, val); } // in-place updates void add(size_t x, size_t y, value_type val) { array->add(x, y, val); } void sub(size_t x, size_t y, value_type val) { array->sub(x, y, val); } void mul(size_t x, size_t y, value_type val) { array->mul(x, y, val); } void div(size_t x, size_t y, value_type val) { array->div(x, y, val); } }; // thread-safe read-only view of 2D (sub)array with private cache template class private_const_view : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename container_type::store_type store_type; typedef typename zfp::internal::dim2::const_reference const_reference; typedef typename zfp::internal::dim2::const_pointer const_pointer; typedef typename zfp::internal::dim2::const_iterator const_iterator; // construction--perform shallow copy of (sub)array private_const_view(container_type* array, size_t cache_size = 0) : preview(array), cache(array->store, cache_size ? cache_size : array->cache.size()) { array->store.reference(); } private_const_view(container_type* array, size_t x, size_t y, size_t nx, size_t ny, size_t cache_size = 0) : preview(array, x, y, nx, ny), cache(array->store, cache_size ? cache_size : array->cache.size()) { array->store.reference(); } // destructor ~private_const_view() { array->store.unreference(); } // dimensions of (sub)array size_t size_x() const { return nx; } size_t size_y() const { return ny; } // cache size in number of bytes size_t cache_size() const { return cache.size(); } // set minimum cache size in bytes (array dimensions must be known) void set_cache_size(size_t bytes) { cache.resize(bytes); } // empty cache without compressing modified cached blocks void clear_cache() const { cache.clear(); } // (i, j) inspector const_reference operator()(size_t i, size_t j) const { return const_reference(this, x + i, y + j); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x, y); } const_iterator cend() const { return const_iterator(this, x, y + ny); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } protected: friend class zfp::internal::dim2::const_handle; friend class zfp::internal::dim2::const_pointer; friend class zfp::internal::dim2::const_iterator; using preview::min_x; using preview::max_x; using preview::min_y; using preview::max_y; using preview::array; using preview::x; using preview::y; using preview::nx; using preview::ny; // inspector value_type get(size_t x, size_t y) const { return cache.get(x, y); } BlockCache2 cache; // cache of decompressed blocks }; // thread-safe read-write view of private 2D (sub)array template class private_view : public private_const_view { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim2::const_reference const_reference; typedef typename zfp::internal::dim2::const_pointer const_pointer; typedef typename zfp::internal::dim2::const_iterator const_iterator; typedef typename zfp::internal::dim2::reference reference; typedef typename zfp::internal::dim2::pointer pointer; typedef typename zfp::internal::dim2::iterator iterator; // construction--perform shallow copy of (sub)array private_view(container_type* array, size_t cache_size = 0) : private_const_view(array, cache_size) {} private_view(container_type* array, size_t x, size_t y, size_t nx, size_t ny, size_t cache_size = 0) : private_const_view(array, x, y, nx, ny, cache_size) {} // partition view into count block-aligned pieces, with 0 <= index < count void partition(size_t index, size_t count) { if (nx > ny) partition(x, nx, index, count); else partition(y, ny, index, count); } // flush cache by compressing all modified cached blocks void flush_cache() const { cache.flush(); } // (i, j) inspector const_reference operator()(size_t i, size_t j) const { return const_reference(this, x + i, y + j); } // (i, j) mutator reference operator()(size_t i, size_t j) { return reference(this, x + i, y + j); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x, y); } const_iterator cend() const { return const_iterator(this, x, y + ny); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } iterator begin() { return iterator(this, x, y); } iterator end() { return iterator(this, x, y + ny); } protected: friend class zfp::internal::dim2::const_handle; friend class zfp::internal::dim2::const_pointer; friend class zfp::internal::dim2::const_iterator; friend class zfp::internal::dim2::reference; friend class zfp::internal::dim2::pointer; friend class zfp::internal::dim2::iterator; using private_const_view::min_x; using private_const_view::max_x; using private_const_view::min_y; using private_const_view::max_y; using private_const_view::get; using private_const_view::array; using private_const_view::x; using private_const_view::y; using private_const_view::nx; using private_const_view::ny; using private_const_view::cache; // block-aligned partition of [offset, offset + size): index out of count static void partition(size_t& offset, size_t& size, size_t index, size_t count) { size_t bmin = offset / 4; size_t bmax = (offset + size + 3) / 4; size_t xmin = std::max(offset + 0, 4 * (bmin + (bmax - bmin) * (index + 0) / count)); size_t xmax = std::min(offset + size, 4 * (bmin + (bmax - bmin) * (index + 1) / count)); offset = xmin; size = xmax - xmin; } // mutator void set(size_t x, size_t y, value_type val) { cache.set(x, y, val); } // in-place updates void add(size_t x, size_t y, value_type val) { cache.ref(x, y) += val; } void sub(size_t x, size_t y, value_type val) { cache.ref(x, y) -= val; } void mul(size_t x, size_t y, value_type val) { cache.ref(x, y) *= val; } void div(size_t x, size_t y, value_type val) { cache.ref(x, y) /= val; } }; } // dim2 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/view3.hpp000066400000000000000000000567061453723256400212630ustar00rootroot00000000000000#ifndef ZFP_VIEW3_HPP #define ZFP_VIEW3_HPP // 3D array views namespace zfp { namespace internal { namespace dim3 { // abstract view of 3D array (base class) template class preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; // rate in bits per value double rate() const { return array->rate(); } // dimensions of (sub)array size_t size() const { return nx * ny * nz; } // local to global array indices size_t global_x(size_t i) const { return x + i; } size_t global_y(size_t j) const { return y + j; } size_t global_z(size_t k) const { return z + k; } protected: // construction and assignment--perform shallow copy of (sub)array explicit preview(container_type* array) : array(array), x(0), y(0), z(0), nx(array->size_x()), ny(array->size_y()), nz(array->size_z()) {} explicit preview(container_type* array, size_t x, size_t y, size_t z, size_t nx, size_t ny, size_t nz) : array(array), x(x), y(y), z(z), nx(nx), ny(ny), nz(nz) {} preview& operator=(container_type* a) { array = a; x = y = z = 0; nx = a->nx; ny = a->ny; nz = a->nz; return *this; } // global index bounds for iterators size_t min_x() const { return x; } size_t max_x() const { return x + nx; } size_t min_y() const { return y; } size_t max_y() const { return y + ny; } size_t min_z() const { return z; } size_t max_z() const { return z + nz; } container_type* array; // underlying container size_t x, y, z; // offset into array size_t nx, ny, nz; // dimensions of subarray }; // generic read-only view into a rectangular subset of a 3D array template class const_view : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim3::const_reference const_reference; typedef typename zfp::internal::dim3::const_pointer const_pointer; typedef typename zfp::internal::dim3::const_iterator const_iterator; // construction--perform shallow copy of (sub)array const_view(container_type* array) : preview(array) {} const_view(container_type* array, size_t x, size_t y, size_t z, size_t nx, size_t ny, size_t nz) : preview(array, x, y, z, nx, ny, nz) {} // dimensions of (sub)array size_t size_x() const { return nx; } size_t size_y() const { return ny; } size_t size_z() const { return nz; } // (i, j, k) inspector const_reference operator()(size_t i, size_t j, size_t k) const { return const_reference(this, x + i, y + j, z + k); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x, y, z); } const_iterator cend() const { return const_iterator(this, x, y, z + nz); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } protected: friend class zfp::internal::dim3::const_handle; friend class zfp::internal::dim3::const_pointer; friend class zfp::internal::dim3::const_iterator; using preview::min_x; using preview::max_x; using preview::min_y; using preview::max_y; using preview::min_z; using preview::max_z; using preview::array; using preview::x; using preview::y; using preview::z; using preview::nx; using preview::ny; using preview::nz; // inspector value_type get(size_t x, size_t y, size_t z) const { return array->get(x, y, z); } }; // generic read-write view into a rectangular subset of a 3D array template class view : public const_view { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim3::const_reference const_reference; typedef typename zfp::internal::dim3::const_pointer const_pointer; typedef typename zfp::internal::dim3::const_iterator const_iterator; typedef typename zfp::internal::dim3::reference reference; typedef typename zfp::internal::dim3::pointer pointer; typedef typename zfp::internal::dim3::iterator iterator; // construction--perform shallow copy of (sub)array view(container_type* array) : const_view(array) {} view(container_type* array, size_t x, size_t y, size_t z, size_t nx, size_t ny, size_t nz) : const_view(array, x, y, z, nx, ny, nz) {} // (i, j, k) inspector const_reference operator()(size_t i, size_t j, size_t k) const { return const_reference(this, x + i, y + j, z + k); } // (i, j, k) mutator reference operator()(size_t i, size_t j, size_t k) { return reference(this, x + i, y + j, z + k); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x, y, z); } const_iterator cend() const { return const_iterator(this, x, y, z + nz); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } iterator begin() { return iterator(this, x, y, z); } iterator end() { return iterator(this, x, y, z + nz); } protected: friend class zfp::internal::dim3::const_handle; friend class zfp::internal::dim3::const_pointer; friend class zfp::internal::dim3::const_iterator; friend class zfp::internal::dim3::reference; friend class zfp::internal::dim3::pointer; friend class zfp::internal::dim3::iterator; using const_view::min_x; using const_view::max_x; using const_view::min_y; using const_view::max_y; using const_view::min_z; using const_view::max_z; using const_view::get; using const_view::array; using const_view::x; using const_view::y; using const_view::z; using const_view::nx; using const_view::ny; using const_view::nz; // mutator void set(size_t x, size_t y, size_t z, value_type val) { array->set(x, y, z, val); } // in-place updates void add(size_t x, size_t y, size_t z, value_type val) { array->add(x, y, z, val); } void sub(size_t x, size_t y, size_t z, value_type val) { array->sub(x, y, z, val); } void mul(size_t x, size_t y, size_t z, value_type val) { array->mul(x, y, z, val); } void div(size_t x, size_t y, size_t z, value_type val) { array->div(x, y, z, val); } }; // flat view of 3D array (operator[] returns scalar) template class flat_view : public view { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim3::const_reference const_reference; typedef typename zfp::internal::dim3::const_pointer const_pointer; typedef typename zfp::internal::dim3::reference reference; typedef typename zfp::internal::dim3::pointer pointer; // construction--perform shallow copy of (sub)array flat_view(container_type* array) : view(array) {} flat_view(container_type* array, size_t x, size_t y, size_t z, size_t nx, size_t ny, size_t nz) : view(array, x, y, z, nx, ny, nz) {} // convert (i, j, k) index to flat index size_t index(size_t i, size_t j, size_t k) const { return i + nx * (j + ny * k); } // convert flat index to (i, j, k) index void ijk(size_t& i, size_t& j, size_t& k, size_t index) const { i = index % nx; index /= nx; j = index % ny; index /= ny; k = index; } // flat index [] inspector const_reference operator[](size_t index) const { size_t i, j, k; ijk(i, j, k, index); return const_reference(this, x + i, y + j, z + k); } // flat index [] mutator reference operator[](size_t index) { size_t i, j, k; ijk(i, j, k, index); return reference(this, x + i, y + j, z + k); } // (i, j, k) inspector const_reference operator()(size_t i, size_t j, size_t k) const { return const_reference(this, x + i, y + j, z + k); } // (i, j, k) mutator reference operator()(size_t i, size_t j, size_t k) { return reference(this, x + i, y + j, z + k); } protected: friend class zfp::internal::dim3::const_handle; friend class zfp::internal::dim3::const_pointer; friend class zfp::internal::dim3::reference; friend class zfp::internal::dim3::pointer; using view::array; using view::x; using view::y; using view::z; using view::nx; using view::ny; using view::nz; // inspector value_type get(size_t x, size_t y, size_t z) const { return array->get(x, y, z); } // mutator void set(size_t x, size_t y, size_t z, value_type val) { array->set(x, y, z, val); } // in-place updates void add(size_t x, size_t y, size_t z, value_type val) { array->add(x, y, z, val); } void sub(size_t x, size_t y, size_t z, value_type val) { array->sub(x, y, z, val); } void mul(size_t x, size_t y, size_t z, value_type val) { array->mul(x, y, z, val); } void div(size_t x, size_t y, size_t z, value_type val) { array->div(x, y, z, val); } }; // forward declaration of friends template class nested_view1; template class nested_view2; template class nested_view3; // nested view into a 1D rectangular subset of a 3D array template class nested_view1 : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim3::const_reference const_reference; typedef typename zfp::internal::dim3::const_pointer const_pointer; typedef typename zfp::internal::dim3::reference reference; typedef typename zfp::internal::dim3::pointer pointer; // dimensions of (sub)array size_t size_x() const { return nx; } // [i] inspector and mutator const_reference operator[](size_t index) const { return const_reference(this, x + index, y, z); } reference operator[](size_t index) { return reference(this, x + index, y, z); } // (i) inspector and mutator const_reference operator()(size_t i) const { return const_reference(this, x + i, y, z); } reference operator()(size_t i) { return reference(this, x + i, y, z); } protected: friend class zfp::internal::dim3::const_handle; friend class zfp::internal::dim3::const_pointer; friend class zfp::internal::dim3::reference; friend class zfp::internal::dim3::pointer; using preview::array; using preview::x; using preview::y; using preview::z; using preview::nx; using preview::ny; using preview::nz; // construction--perform shallow copy of (sub)array friend class nested_view2; explicit nested_view1(container_type* array) : preview(array) {} explicit nested_view1(container_type* array, size_t x, size_t y, size_t z, size_t nx, size_t ny, size_t nz) : preview(array, x, y, z, nx, ny, nz) {} // inspector value_type get(size_t x, size_t y, size_t z) const { return array->get(x, y, z); } // mutator void set(size_t x, size_t y, size_t z, value_type val) { array->set(x, y, z, val); } // in-place updates void add(size_t x, size_t y, size_t z, value_type val) { array->add(x, y, z, val); } void sub(size_t x, size_t y, size_t z, value_type val) { array->sub(x, y, z, val); } void mul(size_t x, size_t y, size_t z, value_type val) { array->mul(x, y, z, val); } void div(size_t x, size_t y, size_t z, value_type val) { array->div(x, y, z, val); } }; // nested view into a 2D rectangular subset of a 3D array template class nested_view2 : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim3::const_reference const_reference; typedef typename zfp::internal::dim3::const_pointer const_pointer; typedef typename zfp::internal::dim3::reference reference; typedef typename zfp::internal::dim3::pointer pointer; // construction--perform shallow copy of (sub)array nested_view2(container_type* array) : preview(array) {} nested_view2(container_type* array, size_t x, size_t y, size_t z, size_t nx, size_t ny, size_t nz) : preview(array, x, y, z, nx, ny, nz) {} // dimensions of (sub)array size_t size_x() const { return nx; } size_t size_y() const { return ny; } // 1D view nested_view1 operator[](size_t index) const { return nested_view1(array, x, y + index, z, nx, 1, 1); } // (i, j) inspector and mutator const_reference operator()(size_t i, size_t j) const { return const_reference(this, x + i, y + j, z); } reference operator()(size_t i, size_t j) { return reference(this, x + i, y + j, z); } protected: friend class zfp::internal::dim3::const_handle; friend class zfp::internal::dim3::const_pointer; friend class zfp::internal::dim3::reference; friend class zfp::internal::dim3::pointer; using preview::array; using preview::x; using preview::y; using preview::z; using preview::nx; using preview::ny; using preview::nz; // inspector value_type get(size_t x, size_t y, size_t z) const { return array->get(x, y, z); } // mutator void set(size_t x, size_t y, size_t z, value_type val) { array->set(x, y, z, val); } // in-place updates void add(size_t x, size_t y, size_t z, value_type val) { array->add(x, y, z, val); } void sub(size_t x, size_t y, size_t z, value_type val) { array->sub(x, y, z, val); } void mul(size_t x, size_t y, size_t z, value_type val) { array->mul(x, y, z, val); } void div(size_t x, size_t y, size_t z, value_type val) { array->div(x, y, z, val); } }; // nested view into a 3D rectangular subset of a 3D array template class nested_view3 : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim3::const_reference const_reference; typedef typename zfp::internal::dim3::const_pointer const_pointer; typedef typename zfp::internal::dim3::reference reference; typedef typename zfp::internal::dim3::pointer pointer; // construction--perform shallow copy of (sub)array nested_view3(container_type* array) : preview(array) {} nested_view3(container_type* array, size_t x, size_t y, size_t z, size_t nx, size_t ny, size_t nz) : preview(array, x, y, z, nx, ny, nz) {} // dimensions of (sub)array size_t size_x() const { return nx; } size_t size_y() const { return ny; } size_t size_z() const { return nz; } // 2D view nested_view2 operator[](size_t index) const { return nested_view2(array, x, y, z + index, nx, ny, 1); } // (i, j, k) inspector and mutator const_reference operator()(size_t i, size_t j, size_t k) const { return const_reference(this, x + i, y + j, z + k); } reference operator()(size_t i, size_t j, size_t k) { return reference(this, x + i, y + j, z + k); } protected: friend class zfp::internal::dim3::const_handle; friend class zfp::internal::dim3::const_pointer; friend class zfp::internal::dim3::reference; friend class zfp::internal::dim3::pointer; using preview::array; using preview::x; using preview::y; using preview::z; using preview::nx; using preview::ny; using preview::nz; // inspector value_type get(size_t x, size_t y, size_t z) const { return array->get(x, y, z); } // mutator void set(size_t x, size_t y, size_t z, value_type val) { array->set(x, y, z, val); } // in-place updates void add(size_t x, size_t y, size_t z, value_type val) { array->add(x, y, z, val); } void sub(size_t x, size_t y, size_t z, value_type val) { array->sub(x, y, z, val); } void mul(size_t x, size_t y, size_t z, value_type val) { array->mul(x, y, z, val); } void div(size_t x, size_t y, size_t z, value_type val) { array->div(x, y, z, val); } }; // thread-safe read-only view of 3D (sub)array with private cache template class private_const_view : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename container_type::store_type store_type; typedef typename zfp::internal::dim3::const_reference const_reference; typedef typename zfp::internal::dim3::const_pointer const_pointer; typedef typename zfp::internal::dim3::const_iterator const_iterator; // construction--perform shallow copy of (sub)array private_const_view(container_type* array, size_t cache_size = 0) : preview(array), cache(array->store, cache_size ? cache_size : array->cache.size()) { array->store.reference(); } private_const_view(container_type* array, size_t x, size_t y, size_t z, size_t nx, size_t ny, size_t nz, size_t cache_size = 0) : preview(array, x, y, z, nx, ny, nz), cache(array->store, cache_size ? cache_size : array->cache.size()) { array->store.reference(); } // destructor ~private_const_view() { array->store.unreference(); } // dimensions of (sub)array size_t size_x() const { return nx; } size_t size_y() const { return ny; } size_t size_z() const { return nz; } // cache size in number of bytes size_t cache_size() const { return cache.size(); } // set minimum cache size in bytes (array dimensions must be known) void set_cache_size(size_t bytes) { cache.resize(bytes); } // empty cache without compressing modified cached blocks void clear_cache() const { cache.clear(); } // (i, j, k) inspector const_reference operator()(size_t i, size_t j, size_t k) const { return const_reference(this, x + i, y + j, z + k); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x, y, z); } const_iterator cend() const { return const_iterator(this, x, y, z + nz); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } protected: friend class zfp::internal::dim3::const_handle; friend class zfp::internal::dim3::const_pointer; friend class zfp::internal::dim3::const_iterator; using preview::min_x; using preview::max_x; using preview::min_y; using preview::max_y; using preview::min_z; using preview::max_z; using preview::array; using preview::x; using preview::y; using preview::z; using preview::nx; using preview::ny; using preview::nz; // inspector value_type get(size_t x, size_t y, size_t z) const { return cache.get(x, y, z); } BlockCache3 cache; // cache of decompressed blocks }; // thread-safe read-write view of private 3D (sub)array template class private_view : public private_const_view { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim3::const_reference const_reference; typedef typename zfp::internal::dim3::const_pointer const_pointer; typedef typename zfp::internal::dim3::const_iterator const_iterator; typedef typename zfp::internal::dim3::reference reference; typedef typename zfp::internal::dim3::pointer pointer; typedef typename zfp::internal::dim3::iterator iterator; // construction--perform shallow copy of (sub)array private_view(container_type* array, size_t cache_size = 0) : private_const_view(array, cache_size) {} private_view(container_type* array, size_t x, size_t y, size_t z, size_t nx, size_t ny, size_t nz, size_t cache_size = 0) : private_const_view(array, x, y, z, nx, ny, nz, cache_size) {} // partition view into count block-aligned pieces, with 0 <= index < count void partition(size_t index, size_t count) { if (nx > std::max(ny, nz)) partition(x, nx, index, count); else if (ny > std::max(nx, nz)) partition(y, ny, index, count); else partition(z, nz, index, count); } // flush cache by compressing all modified cached blocks void flush_cache() const { cache.flush(); } // (i, j, k) inspector const_reference operator()(size_t i, size_t j, size_t k) const { return const_reference(this, x + i, y + j, z + k); } // (i, j, k) mutator reference operator()(size_t i, size_t j, size_t k) { return reference(this, x + i, y + j, z + k); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x, y, z); } const_iterator cend() const { return const_iterator(this, x, y, z + nz); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } iterator begin() { return iterator(this, x, y, z); } iterator end() { return iterator(this, x, y, z + nz); } protected: friend class zfp::internal::dim3::const_handle; friend class zfp::internal::dim3::const_pointer; friend class zfp::internal::dim3::const_iterator; friend class zfp::internal::dim3::reference; friend class zfp::internal::dim3::pointer; friend class zfp::internal::dim3::iterator; using private_const_view::min_x; using private_const_view::max_x; using private_const_view::min_y; using private_const_view::max_y; using private_const_view::min_z; using private_const_view::max_z; using private_const_view::get; using private_const_view::array; using private_const_view::x; using private_const_view::y; using private_const_view::z; using private_const_view::nx; using private_const_view::ny; using private_const_view::nz; using private_const_view::cache; // block-aligned partition of [offset, offset + size): index out of count static void partition(size_t& offset, size_t& size, size_t index, size_t count) { size_t bmin = offset / 4; size_t bmax = (offset + size + 3) / 4; size_t xmin = std::max(offset + 0, 4 * (bmin + (bmax - bmin) * (index + 0) / count)); size_t xmax = std::min(offset + size, 4 * (bmin + (bmax - bmin) * (index + 1) / count)); offset = xmin; size = xmax - xmin; } // mutator void set(size_t x, size_t y, size_t z, value_type val) { cache.set(x, y, z, val); } // in-place updates void add(size_t x, size_t y, size_t z, value_type val) { cache.ref(x, y, z) += val; } void sub(size_t x, size_t y, size_t z, value_type val) { cache.ref(x, y, z) -= val; } void mul(size_t x, size_t y, size_t z, value_type val) { cache.ref(x, y, z) *= val; } void div(size_t x, size_t y, size_t z, value_type val) { cache.ref(x, y, z) /= val; } }; } // dim3 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/array/view4.hpp000066400000000000000000000705061453723256400212560ustar00rootroot00000000000000#ifndef ZFP_VIEW4_HPP #define ZFP_VIEW4_HPP // 4D array views namespace zfp { namespace internal { namespace dim4 { // abstract view of 4D array (base class) template class preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; // rate in bits per value double rate() const { return array->rate(); } // dimensions of (sub)array size_t size() const { return nx * ny * nz * nw; } // local to global array indices size_t global_x(size_t i) const { return x + i; } size_t global_y(size_t j) const { return y + j; } size_t global_z(size_t k) const { return z + k; } size_t global_w(size_t l) const { return w + l; } protected: // construction and assignment--perform shallow copy of (sub)array explicit preview(container_type* array) : array(array), x(0), y(0), z(0), w(0), nx(array->size_x()), ny(array->size_y()), nz(array->size_z()), nw(array->size_w()) {} explicit preview(container_type* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw) : array(array), x(x), y(y), z(z), w(w), nx(nx), ny(ny), nz(nz), nw(nw) {} preview& operator=(container_type* a) { array = a; x = y = z = w = 0; nx = a->nx; ny = a->ny; nz = a->nz; nw = a->nw; return *this; } // global index bounds for iterators size_t min_x() const { return x; } size_t max_x() const { return x + nx; } size_t min_y() const { return y; } size_t max_y() const { return y + ny; } size_t min_z() const { return z; } size_t max_z() const { return z + nz; } size_t min_w() const { return w; } size_t max_w() const { return w + nw; } container_type* array; // underlying container size_t x, y, z, w; // offset into array size_t nx, ny, nz, nw; // dimensions of subarray }; // generic read-only view into a rectangular subset of a 4D array template class const_view : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim4::const_reference const_reference; typedef typename zfp::internal::dim4::const_pointer const_pointer; typedef typename zfp::internal::dim4::const_iterator const_iterator; // construction--perform shallow copy of (sub)array const_view(container_type* array) : preview(array) {} const_view(container_type* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw) : preview(array, x, y, z, w, nx, ny, nz, nw) {} // dimensions of (sub)array size_t size_x() const { return nx; } size_t size_y() const { return ny; } size_t size_z() const { return nz; } size_t size_w() const { return nw; } // (i, j, k, l) inspector const_reference operator()(size_t i, size_t j, size_t k, size_t l) const { return const_reference(this, x + i, y + j, z + k, w + l); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x, y, z, w); } const_iterator cend() const { return const_iterator(this, x, y, z, w + nw); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } protected: friend class zfp::internal::dim4::const_handle; friend class zfp::internal::dim4::const_pointer; friend class zfp::internal::dim4::const_iterator; using preview::min_x; using preview::max_x; using preview::min_y; using preview::max_y; using preview::min_z; using preview::max_z; using preview::min_w; using preview::max_w; using preview::array; using preview::x; using preview::y; using preview::z; using preview::w; using preview::nx; using preview::ny; using preview::nz; using preview::nw; // inspector value_type get(size_t x, size_t y, size_t z, size_t w) const { return array->get(x, y, z, w); } }; // generic read-write view into a rectangular subset of a 4D array template class view : public const_view { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim4::const_reference const_reference; typedef typename zfp::internal::dim4::const_pointer const_pointer; typedef typename zfp::internal::dim4::const_iterator const_iterator; typedef typename zfp::internal::dim4::reference reference; typedef typename zfp::internal::dim4::pointer pointer; typedef typename zfp::internal::dim4::iterator iterator; // construction--perform shallow copy of (sub)array view(container_type* array) : const_view(array) {} view(container_type* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw) : const_view(array, x, y, z, w, nx, ny, nz, nw) {} // (i, j, k, l) inspector const_reference operator()(size_t i, size_t j, size_t k, size_t l) const { return const_reference(this, x + i, y + j, z + k, w + l); } // (i, j, k, l) mutator reference operator()(size_t i, size_t j, size_t k, size_t l) { return reference(this, x + i, y + j, z + k, w + l); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x, y, z, w); } const_iterator cend() const { return const_iterator(this, x, y, z, w + nw); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } iterator begin() { return iterator(this, x, y, z, w); } iterator end() { return iterator(this, x, y, z, w + nw); } protected: friend class zfp::internal::dim4::const_handle; friend class zfp::internal::dim4::const_pointer; friend class zfp::internal::dim4::const_iterator; friend class zfp::internal::dim4::reference; friend class zfp::internal::dim4::pointer; friend class zfp::internal::dim4::iterator; using const_view::min_x; using const_view::max_x; using const_view::min_y; using const_view::max_y; using const_view::min_z; using const_view::max_z; using const_view::min_w; using const_view::max_w; using const_view::get; using const_view::array; using const_view::x; using const_view::y; using const_view::z; using const_view::w; using const_view::nx; using const_view::ny; using const_view::nz; using const_view::nw; // mutator void set(size_t x, size_t y, size_t z, size_t w, value_type val) { array->set(x, y, z, w, val); } // in-place updates void add(size_t x, size_t y, size_t z, size_t w, value_type val) { array->add(x, y, z, w, val); } void sub(size_t x, size_t y, size_t z, size_t w, value_type val) { array->sub(x, y, z, w, val); } void mul(size_t x, size_t y, size_t z, size_t w, value_type val) { array->mul(x, y, z, w, val); } void div(size_t x, size_t y, size_t z, size_t w, value_type val) { array->div(x, y, z, w, val); } }; // flat view of 4D array (operator[] returns scalar) template class flat_view : public view { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim4::const_reference const_reference; typedef typename zfp::internal::dim4::const_pointer const_pointer; typedef typename zfp::internal::dim4::reference reference; typedef typename zfp::internal::dim4::pointer pointer; // construction--perform shallow copy of (sub)array flat_view(container_type* array) : view(array) {} flat_view(container_type* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw) : view(array, x, y, z, w, nx, ny, nz, nw) {} // convert (i, j, k, l) index to flat index size_t index(size_t i, size_t j, size_t k, size_t l) const { return i + nx * (j + ny * (k + nz * l)); } // convert flat index to (i, j, k, l) index void ijkl(size_t& i, size_t& j, size_t& k, size_t& l, size_t index) const { i = index % nx; index /= nx; j = index % ny; index /= ny; k = index % nz; index /= nz; l = index; } // flat index [] inspector const_reference operator[](size_t index) const { size_t i, j, k, l; ijkl(i, j, k, l, index); return const_reference(this, x + i, y + j, z + k, w + l); } // flat index [] mutator reference operator[](size_t index) { size_t i, j, k, l; ijkl(i, j, k, l, index); return reference(this, x + i, y + j, z + k, w + l); } // (i, j, k, l) inspector const_reference operator()(size_t i, size_t j, size_t k, size_t l) const { return const_reference(this, x + i, y + j, z + k, w + l); } // (i, j, k, l) mutator reference operator()(size_t i, size_t j, size_t k, size_t l) { return reference(this, x + i, y + j, z + k, w + l); } protected: friend class zfp::internal::dim4::const_handle; friend class zfp::internal::dim4::const_pointer; friend class zfp::internal::dim4::reference; friend class zfp::internal::dim4::pointer; using view::array; using view::x; using view::y; using view::z; using view::w; using view::nx; using view::ny; using view::nz; using view::nw; // inspector value_type get(size_t x, size_t y, size_t z, size_t w) const { return array->get(x, y, z, w); } // mutator void set(size_t x, size_t y, size_t z, size_t w, value_type val) { array->set(x, y, z, w, val); } // in-place updates void add(size_t x, size_t y, size_t z, size_t w, value_type val) { array->add(x, y, z, w, val); } void sub(size_t x, size_t y, size_t z, size_t w, value_type val) { array->sub(x, y, z, w, val); } void mul(size_t x, size_t y, size_t z, size_t w, value_type val) { array->mul(x, y, z, w, val); } void div(size_t x, size_t y, size_t z, size_t w, value_type val) { array->div(x, y, z, w, val); } }; // forward declaration of friends template class nested_view1; template class nested_view2; template class nested_view3; template class nested_view4; // nested view into a 1D rectangular subset of a 4D array template class nested_view1 : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim4::const_reference const_reference; typedef typename zfp::internal::dim4::const_pointer const_pointer; typedef typename zfp::internal::dim4::reference reference; typedef typename zfp::internal::dim4::pointer pointer; // dimensions of (sub)array size_t size_x() const { return nx; } // [i] inspector and mutator const_reference operator[](size_t index) const { return const_reference(this, x + index, y, z, w); } reference operator[](size_t index) { return reference(this, x + index, y, z, w); } // (i) inspector and mutator const_reference operator()(size_t i) const { return const_reference(this, x + i, y, z, w); } reference operator()(size_t i) { return reference(this, x + i, y, z, w); } protected: friend class zfp::internal::dim4::const_handle; friend class zfp::internal::dim4::const_pointer; friend class zfp::internal::dim4::reference; friend class zfp::internal::dim4::pointer; using preview::array; using preview::x; using preview::y; using preview::z; using preview::w; using preview::nx; using preview::ny; using preview::nz; using preview::nw; // construction--perform shallow copy of (sub)array friend class nested_view2; explicit nested_view1(container_type* array) : preview(array) {} explicit nested_view1(container_type* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw) : preview(array, x, y, z, w, nx, ny, nz, nw) {} // inspector value_type get(size_t x, size_t y, size_t z, size_t w) const { return array->get(x, y, z, w); } // mutator void set(size_t x, size_t y, size_t z, size_t w, value_type val) { array->set(x, y, z, w, val); } // in-place updates void add(size_t x, size_t y, size_t z, size_t w, value_type val) { array->add(x, y, z, w, val); } void sub(size_t x, size_t y, size_t z, size_t w, value_type val) { array->sub(x, y, z, w, val); } void mul(size_t x, size_t y, size_t z, size_t w, value_type val) { array->mul(x, y, z, w, val); } void div(size_t x, size_t y, size_t z, size_t w, value_type val) { array->div(x, y, z, w, val); } }; // nested view into a 2D rectangular subset of a 4D array template class nested_view2 : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim4::const_reference const_reference; typedef typename zfp::internal::dim4::const_pointer const_pointer; typedef typename zfp::internal::dim4::reference reference; typedef typename zfp::internal::dim4::pointer pointer; // construction--perform shallow copy of (sub)array nested_view2(container_type* array) : preview(array) {} nested_view2(container_type* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw) : preview(array, x, y, z, w, nx, ny, nz, nw) {} // dimensions of (sub)array size_t size_x() const { return nx; } size_t size_y() const { return ny; } // 1D view nested_view1 operator[](size_t index) const { return nested_view1(array, x, y + index, z, w, nx, 1, 1, 1); } // (i, j) inspector and mutator const_reference operator()(size_t i, size_t j) const { return const_reference(this, x + i, y + j, z, w); } reference operator()(size_t i, size_t j) { return reference(this, x + i, y + j, z, w); } protected: friend class zfp::internal::dim4::const_handle; friend class zfp::internal::dim4::const_pointer; friend class zfp::internal::dim4::reference; friend class zfp::internal::dim4::pointer; using preview::array; using preview::x; using preview::y; using preview::z; using preview::w; using preview::nx; using preview::ny; using preview::nz; using preview::nw; // inspector value_type get(size_t x, size_t y, size_t z, size_t w) const { return array->get(x, y, z, w); } // mutator void set(size_t x, size_t y, size_t z, size_t w, value_type val) { array->set(x, y, z, w, val); } // in-place updates void add(size_t x, size_t y, size_t z, size_t w, value_type val) { array->add(x, y, z, w, val); } void sub(size_t x, size_t y, size_t z, size_t w, value_type val) { array->sub(x, y, z, w, val); } void mul(size_t x, size_t y, size_t z, size_t w, value_type val) { array->mul(x, y, z, w, val); } void div(size_t x, size_t y, size_t z, size_t w, value_type val) { array->div(x, y, z, w, val); } }; // nested view into a 3D rectangular subset of a 4D array template class nested_view3 : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim4::const_reference const_reference; typedef typename zfp::internal::dim4::const_pointer const_pointer; typedef typename zfp::internal::dim4::reference reference; typedef typename zfp::internal::dim4::pointer pointer; // construction--perform shallow copy of (sub)array nested_view3(container_type* array) : preview(array) {} nested_view3(container_type* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw) : preview(array, x, y, z, w, nx, ny, nz, nw) {} // dimensions of (sub)array size_t size_x() const { return nx; } size_t size_y() const { return ny; } size_t size_z() const { return nz; } // 2D view nested_view2 operator[](size_t index) const { return nested_view2(array, x, y, z + index, w, nx, ny, 1, 1); } // (i, j, k) inspector and mutator const_reference operator()(size_t i, size_t j, size_t k) const { return const_reference(this, x + i, y + j, z + k, w); } reference operator()(size_t i, size_t j, size_t k) { return reference(this, x + i, y + j, z + k, w); } protected: friend class zfp::internal::dim4::const_handle; friend class zfp::internal::dim4::const_pointer; friend class zfp::internal::dim4::reference; friend class zfp::internal::dim4::pointer; using preview::array; using preview::x; using preview::y; using preview::z; using preview::w; using preview::nx; using preview::ny; using preview::nz; using preview::nw; // inspector value_type get(size_t x, size_t y, size_t z, size_t w) const { return array->get(x, y, z, w); } // mutator void set(size_t x, size_t y, size_t z, size_t w, value_type val) { array->set(x, y, z, w, val); } // in-place updates void add(size_t x, size_t y, size_t z, size_t w, value_type val) { array->add(x, y, z, w, val); } void sub(size_t x, size_t y, size_t z, size_t w, value_type val) { array->sub(x, y, z, w, val); } void mul(size_t x, size_t y, size_t z, size_t w, value_type val) { array->mul(x, y, z, w, val); } void div(size_t x, size_t y, size_t z, size_t w, value_type val) { array->div(x, y, z, w, val); } }; // nested view into a 4D rectangular subset of a 4D array template class nested_view4 : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim4::const_reference const_reference; typedef typename zfp::internal::dim4::const_pointer const_pointer; typedef typename zfp::internal::dim4::reference reference; typedef typename zfp::internal::dim4::pointer pointer; // construction--perform shallow copy of (sub)array nested_view4(container_type* array) : preview(array) {} nested_view4(container_type* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw) : preview(array, x, y, z, w, nx, ny, nz, nw) {} // dimensions of (sub)array size_t size_x() const { return nx; } size_t size_y() const { return ny; } size_t size_z() const { return nz; } size_t size_w() const { return nw; } // 3D view nested_view3 operator[](size_t index) const { return nested_view3(array, x, y, z, w + index, nx, ny, nz, 1); } // (i, j, k, l) inspector and mutator const_reference operator()(size_t i, size_t j, size_t k, size_t l) const { return const_reference(this, x + i, y + j, z + k, w + l); } reference operator()(size_t i, size_t j, size_t k, size_t l) { return reference(this, x + i, y + j, z + k, w + l); } protected: friend class zfp::internal::dim4::const_handle; friend class zfp::internal::dim4::const_pointer; friend class zfp::internal::dim4::reference; friend class zfp::internal::dim4::pointer; using preview::array; using preview::x; using preview::y; using preview::z; using preview::w; using preview::nx; using preview::ny; using preview::nz; using preview::nw; // inspector value_type get(size_t x, size_t y, size_t z, size_t w) const { return array->get(x, y, z, w); } // mutator void set(size_t x, size_t y, size_t z, size_t w, value_type val) { array->set(x, y, z, w, val); } // in-place updates void add(size_t x, size_t y, size_t z, size_t w, value_type val) { array->add(x, y, z, w, val); } void sub(size_t x, size_t y, size_t z, size_t w, value_type val) { array->sub(x, y, z, w, val); } void mul(size_t x, size_t y, size_t z, size_t w, value_type val) { array->mul(x, y, z, w, val); } void div(size_t x, size_t y, size_t z, size_t w, value_type val) { array->div(x, y, z, w, val); } }; // thread-safe read-only view of 4D (sub)array with private cache template class private_const_view : public preview { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename container_type::store_type store_type; typedef typename zfp::internal::dim4::const_reference const_reference; typedef typename zfp::internal::dim4::const_pointer const_pointer; typedef typename zfp::internal::dim4::const_iterator const_iterator; // construction--perform shallow copy of (sub)array private_const_view(container_type* array, size_t cache_size = 0) : preview(array), cache(array->store, cache_size ? cache_size : array->cache.size()) { array->store.reference(); } private_const_view(container_type* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw, size_t cache_size = 0) : preview(array, x, y, z, w, nx, ny, nz, nw), cache(array->store, cache_size ? cache_size : array->cache.size()) { array->store.reference(); } // destructor ~private_const_view() { array->store.unreference(); } // dimensions of (sub)array size_t size_x() const { return nx; } size_t size_y() const { return ny; } size_t size_z() const { return nz; } size_t size_w() const { return nw; } // cache size in number of bytes size_t cache_size() const { return cache.size(); } // set minimum cache size in bytes (array dimensions must be known) void set_cache_size(size_t bytes) { cache.resize(bytes); } // empty cache without compressing modified cached blocks void clear_cache() const { cache.clear(); } // (i, j, k) inspector const_reference operator()(size_t i, size_t j, size_t k, size_t l) const { return const_reference(this, x + i, y + j, z + k, w + l); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x, y, z, w); } const_iterator cend() const { return const_iterator(this, x, y, z, w + nw); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } protected: friend class zfp::internal::dim4::const_handle; friend class zfp::internal::dim4::const_pointer; friend class zfp::internal::dim4::const_iterator; using preview::min_x; using preview::max_x; using preview::min_y; using preview::max_y; using preview::min_z; using preview::max_z; using preview::min_w; using preview::max_w; using preview::array; using preview::x; using preview::y; using preview::z; using preview::w; using preview::nx; using preview::ny; using preview::nz; using preview::nw; // inspector value_type get(size_t x, size_t y, size_t z, size_t w) const { return cache.get(x, y, z, w); } BlockCache4 cache; // cache of decompressed blocks }; // thread-safe read-write view of private 4D (sub)array template class private_view : public private_const_view { public: typedef Container container_type; typedef typename container_type::value_type value_type; typedef typename zfp::internal::dim4::const_reference const_reference; typedef typename zfp::internal::dim4::const_pointer const_pointer; typedef typename zfp::internal::dim4::const_iterator const_iterator; typedef typename zfp::internal::dim4::reference reference; typedef typename zfp::internal::dim4::pointer pointer; typedef typename zfp::internal::dim4::iterator iterator; // construction--perform shallow copy of (sub)array private_view(container_type* array, size_t cache_size = 0) : private_const_view(array, cache_size) {} private_view(container_type* array, size_t x, size_t y, size_t z, size_t w, size_t nx, size_t ny, size_t nz, size_t nw, size_t cache_size = 0) : private_const_view(array, x, y, z, w, nx, ny, nz, nw, cache_size) {} // partition view into count block-aligned pieces, with 0 <= index < count void partition(size_t index, size_t count) { if (std::max(nx, ny) > std::max(nz, nw)) { if (nx > ny) partition(x, nx, index, count); else partition(y, ny, index, count); } else { if (nz > nw) partition(z, nz, index, count); else partition(w, nw, index, count); } } // flush cache by compressing all modified cached blocks void flush_cache() const { cache.flush(); } // (i, j, k, l) inspector const_reference operator()(size_t i, size_t j, size_t k, size_t l) const { return const_reference(this, x + i, y + j, z + k, w + l); } // (i, j, k, l) mutator reference operator()(size_t i, size_t j, size_t k, size_t l) { return reference(this, x + i, y + j, z + k, w + l); } // random access iterators const_iterator cbegin() const { return const_iterator(this, x, y, z, w); } const_iterator cend() const { return const_iterator(this, x, y, z, w + nw); } const_iterator begin() const { return cbegin(); } const_iterator end() const { return cend(); } iterator begin() { return iterator(this, x, y, z, w); } iterator end() { return iterator(this, x, y, z, w + nw); } protected: friend class zfp::internal::dim4::const_handle; friend class zfp::internal::dim4::const_pointer; friend class zfp::internal::dim4::const_iterator; friend class zfp::internal::dim4::reference; friend class zfp::internal::dim4::pointer; friend class zfp::internal::dim4::iterator; using private_const_view::min_x; using private_const_view::max_x; using private_const_view::min_y; using private_const_view::max_y; using private_const_view::min_z; using private_const_view::max_z; using private_const_view::min_w; using private_const_view::max_w; using private_const_view::get; using private_const_view::array; using private_const_view::x; using private_const_view::y; using private_const_view::z; using private_const_view::w; using private_const_view::nx; using private_const_view::ny; using private_const_view::nz; using private_const_view::nw; using private_const_view::cache; // block-aligned partition of [offset, offset + size): index out of count static void partition(size_t& offset, size_t& size, size_t index, size_t count) { size_t bmin = offset / 4; size_t bmax = (offset + size + 3) / 4; size_t xmin = std::max(offset + 0, 4 * (bmin + (bmax - bmin) * (index + 0) / count)); size_t xmax = std::min(offset + size, 4 * (bmin + (bmax - bmin) * (index + 1) / count)); offset = xmin; size = xmax - xmin; } // mutator void set(size_t x, size_t y, size_t z, size_t w, value_type val) { cache.set(x, y, z, w, val); } // in-place updates void add(size_t x, size_t y, size_t z, size_t w, value_type val) { cache.ref(x, y, z, w) += val; } void sub(size_t x, size_t y, size_t z, size_t w, value_type val) { cache.ref(x, y, z, w) -= val; } void mul(size_t x, size_t y, size_t z, size_t w, value_type val) { cache.ref(x, y, z, w) *= val; } void div(size_t x, size_t y, size_t z, size_t w, value_type val) { cache.ref(x, y, z, w) /= val; } }; } // dim4 } // internal } // zfp #endif zfp-1.0.1/include/zfp/internal/cfp/000077500000000000000000000000001453723256400171315ustar00rootroot00000000000000zfp-1.0.1/include/zfp/internal/cfp/array1d.h000066400000000000000000000117321453723256400206510ustar00rootroot00000000000000#ifndef CFP_ARRAY_1D_H #define CFP_ARRAY_1D_H #include #include "zfp.h" typedef struct { void* object; } cfp_array1d; typedef struct { cfp_array1d array; size_t x; } cfp_ref1d; typedef struct { cfp_ref1d reference; } cfp_ptr1d; typedef struct { cfp_array1d array; size_t x; } cfp_iter1d; typedef struct { /* member functions */ double (*get)(const cfp_ref1d self); void (*set)(cfp_ref1d self, double val); cfp_ptr1d (*ptr)(cfp_ref1d self); void (*copy)(cfp_ref1d self, const cfp_ref1d src); } cfp_ref1d_api; typedef struct { /* member functions */ double (*get)(const cfp_ptr1d self); double (*get_at)(const cfp_ptr1d self, ptrdiff_t d); void (*set)(cfp_ptr1d self, double val); void (*set_at)(cfp_ptr1d self, ptrdiff_t d, double val); cfp_ref1d (*ref)(cfp_ptr1d self); cfp_ref1d (*ref_at)(cfp_ptr1d self, ptrdiff_t d); /* non-member functions */ zfp_bool (*lt)(const cfp_ptr1d lhs, const cfp_ptr1d rhs); zfp_bool (*gt)(const cfp_ptr1d lhs, const cfp_ptr1d rhs); zfp_bool (*leq)(const cfp_ptr1d lhs, const cfp_ptr1d rhs); zfp_bool (*geq)(const cfp_ptr1d lhs, const cfp_ptr1d rhs); zfp_bool (*eq)(const cfp_ptr1d lhs, const cfp_ptr1d rhs); zfp_bool (*neq)(const cfp_ptr1d lhs, const cfp_ptr1d rhs); ptrdiff_t (*distance)(const cfp_ptr1d first, const cfp_ptr1d last); cfp_ptr1d (*next)(const cfp_ptr1d p, ptrdiff_t d); cfp_ptr1d (*prev)(const cfp_ptr1d p, ptrdiff_t d); cfp_ptr1d (*inc)(const cfp_ptr1d p); cfp_ptr1d (*dec)(const cfp_ptr1d p); } cfp_ptr1d_api; typedef struct { /* member functions */ double (*get)(const cfp_iter1d self); double (*get_at)(const cfp_iter1d self, ptrdiff_t d); void (*set)(cfp_iter1d self, double val); void (*set_at)(cfp_iter1d self, ptrdiff_t d, double val); cfp_ref1d (*ref)(cfp_iter1d self); cfp_ref1d (*ref_at)(cfp_iter1d self, ptrdiff_t d); cfp_ptr1d (*ptr)(cfp_iter1d self); cfp_ptr1d (*ptr_at)(cfp_iter1d self, ptrdiff_t d); size_t (*i)(const cfp_iter1d self); /* non-member functions */ zfp_bool (*lt)(const cfp_iter1d lhs, const cfp_iter1d rhs); zfp_bool (*gt)(const cfp_iter1d lhs, const cfp_iter1d rhs); zfp_bool (*leq)(const cfp_iter1d lhs, const cfp_iter1d rhs); zfp_bool (*geq)(const cfp_iter1d lhs, const cfp_iter1d rhs); zfp_bool (*eq)(const cfp_iter1d lhs, const cfp_iter1d rhs); zfp_bool (*neq)(const cfp_iter1d lhs, const cfp_iter1d rhs); ptrdiff_t (*distance)(const cfp_iter1d first, const cfp_iter1d last); cfp_iter1d (*next)(const cfp_iter1d it, ptrdiff_t d); cfp_iter1d (*prev)(const cfp_iter1d it, ptrdiff_t d); cfp_iter1d (*inc)(const cfp_iter1d it); cfp_iter1d (*dec)(const cfp_iter1d it); } cfp_iter1d_api; typedef struct { /* constructor/destructor */ cfp_header (*ctor)(const cfp_array1d a); cfp_header (*ctor_buffer)(const void* data, size_t size); void (*dtor)(cfp_header self); /* array metadata */ zfp_type (*scalar_type)(const cfp_header self); uint (*dimensionality)(const cfp_header self); size_t (*size_x)(const cfp_header self); size_t (*size_y)(const cfp_header self); size_t (*size_z)(const cfp_header self); size_t (*size_w)(const cfp_header self); double (*rate)(const cfp_header self); /* header payload: data pointer and byte size */ const void* (*data)(const cfp_header self); size_t (*size_bytes)(const cfp_header self, uint mask); } cfp_header1d_api; typedef struct { cfp_array1d (*ctor_default)(void); cfp_array1d (*ctor)(size_t n, double rate, const double* p, size_t cache_size); cfp_array1d (*ctor_copy)(const cfp_array1d src); cfp_array1d (*ctor_header)(const cfp_header h, const void* buffer, size_t buffer_size_bytes); void (*dtor)(cfp_array1d self); void (*deep_copy)(cfp_array1d self, const cfp_array1d src); double (*rate)(const cfp_array1d self); double (*set_rate)(cfp_array1d self, double rate); size_t (*cache_size)(const cfp_array1d self); void (*set_cache_size)(cfp_array1d self, size_t bytes); void (*clear_cache)(const cfp_array1d self); void (*flush_cache)(const cfp_array1d self); size_t (*size_bytes)(const cfp_array1d self, uint mask); size_t (*compressed_size)(const cfp_array1d self); void* (*compressed_data)(const cfp_array1d self); size_t (*size)(const cfp_array1d self); void (*resize)(cfp_array1d self, size_t n, zfp_bool clear); void (*get_array)(const cfp_array1d self, double* p); void (*set_array)(cfp_array1d self, const double* p); double (*get_flat)(const cfp_array1d self, size_t i); void (*set_flat)(cfp_array1d self, size_t i, double val); double (*get)(const cfp_array1d self, size_t i); void (*set)(cfp_array1d self, size_t i, double val); cfp_ref1d (*ref)(cfp_array1d self, size_t i); cfp_ref1d (*ref_flat)(cfp_array1d self, size_t i); cfp_ptr1d (*ptr)(cfp_array1d self, size_t i); cfp_ptr1d (*ptr_flat)(cfp_array1d self, size_t i); cfp_iter1d (*begin)(cfp_array1d self); cfp_iter1d (*end)(cfp_array1d self); cfp_ref1d_api reference; cfp_ptr1d_api pointer; cfp_iter1d_api iterator; cfp_header1d_api header; } cfp_array1d_api; #endif zfp-1.0.1/include/zfp/internal/cfp/array1f.h000066400000000000000000000117111453723256400206500ustar00rootroot00000000000000#ifndef CFP_ARRAY_1F_H #define CFP_ARRAY_1F_H #include #include "zfp.h" typedef struct { void* object; } cfp_array1f; typedef struct { cfp_array1f array; size_t x; } cfp_ref1f; typedef struct { cfp_ref1f reference; } cfp_ptr1f; typedef struct { cfp_array1f array; size_t x; } cfp_iter1f; typedef struct { /* member functions */ float (*get)(const cfp_ref1f self); void (*set)(cfp_ref1f self, float val); cfp_ptr1f (*ptr)(cfp_ref1f self); void (*copy)(cfp_ref1f self, const cfp_ref1f src); } cfp_ref1f_api; typedef struct { /* member functions */ float (*get)(const cfp_ptr1f self); float (*get_at)(const cfp_ptr1f self, ptrdiff_t d); void (*set)(cfp_ptr1f self, float val); void (*set_at)(cfp_ptr1f self, ptrdiff_t d, float val); cfp_ref1f (*ref)(cfp_ptr1f self); cfp_ref1f (*ref_at)(cfp_ptr1f self, ptrdiff_t d); /* non-member functions */ zfp_bool (*lt)(const cfp_ptr1f lhs, const cfp_ptr1f rhs); zfp_bool (*gt)(const cfp_ptr1f lhs, const cfp_ptr1f rhs); zfp_bool (*leq)(const cfp_ptr1f lhs, const cfp_ptr1f rhs); zfp_bool (*geq)(const cfp_ptr1f lhs, const cfp_ptr1f rhs); zfp_bool (*eq)(const cfp_ptr1f lhs, const cfp_ptr1f rhs); zfp_bool (*neq)(const cfp_ptr1f lhs, const cfp_ptr1f rhs); ptrdiff_t (*distance)(const cfp_ptr1f first, const cfp_ptr1f last); cfp_ptr1f (*next)(const cfp_ptr1f p, ptrdiff_t d); cfp_ptr1f (*prev)(const cfp_ptr1f p, ptrdiff_t d); cfp_ptr1f (*inc)(const cfp_ptr1f p); cfp_ptr1f (*dec)(const cfp_ptr1f p); } cfp_ptr1f_api; typedef struct { /* member functions */ float (*get)(const cfp_iter1f self); float (*get_at)(const cfp_iter1f self, ptrdiff_t d); void (*set)(cfp_iter1f self, float val); void (*set_at)(cfp_iter1f self, ptrdiff_t d, float val); cfp_ref1f (*ref)(cfp_iter1f self); cfp_ref1f (*ref_at)(cfp_iter1f self, ptrdiff_t d); cfp_ptr1f (*ptr)(cfp_iter1f self); cfp_ptr1f (*ptr_at)(cfp_iter1f self, ptrdiff_t d); size_t (*i)(const cfp_iter1f self); /* non-member functions */ zfp_bool (*lt)(const cfp_iter1f lhs, const cfp_iter1f rhs); zfp_bool (*gt)(const cfp_iter1f lhs, const cfp_iter1f rhs); zfp_bool (*leq)(const cfp_iter1f lhs, const cfp_iter1f rhs); zfp_bool (*geq)(const cfp_iter1f lhs, const cfp_iter1f rhs); zfp_bool (*eq)(const cfp_iter1f lhs, const cfp_iter1f rhs); zfp_bool (*neq)(const cfp_iter1f lhs, const cfp_iter1f rhs); ptrdiff_t (*distance)(const cfp_iter1f first, const cfp_iter1f last); cfp_iter1f (*next)(const cfp_iter1f it, ptrdiff_t d); cfp_iter1f (*prev)(const cfp_iter1f it, ptrdiff_t d); cfp_iter1f (*inc)(const cfp_iter1f it); cfp_iter1f (*dec)(const cfp_iter1f it); } cfp_iter1f_api; typedef struct { /* constructor/destructor */ cfp_header (*ctor)(const cfp_array1f a); cfp_header (*ctor_buffer)(const void* data, size_t size); void (*dtor)(cfp_header self); /* array metadata */ zfp_type (*scalar_type)(const cfp_header self); uint (*dimensionality)(const cfp_header self); size_t (*size_x)(const cfp_header self); size_t (*size_y)(const cfp_header self); size_t (*size_z)(const cfp_header self); size_t (*size_w)(const cfp_header self); double (*rate)(const cfp_header self); /* header payload: data pointer and byte size */ const void* (*data)(const cfp_header self); size_t (*size_bytes)(const cfp_header self, uint mask); } cfp_header1f_api; typedef struct { cfp_array1f (*ctor_default)(void); cfp_array1f (*ctor)(size_t n, double rate, const float* p, size_t cache_size); cfp_array1f (*ctor_copy)(const cfp_array1f src); cfp_array1f (*ctor_header)(const cfp_header h, const void* buffer, size_t buffer_size_bytes); void (*dtor)(cfp_array1f self); void (*deep_copy)(cfp_array1f self, const cfp_array1f src); double (*rate)(const cfp_array1f self); double (*set_rate)(cfp_array1f self, double rate); size_t (*cache_size)(const cfp_array1f self); void (*set_cache_size)(cfp_array1f self, size_t bytes); void (*clear_cache)(const cfp_array1f self); void (*flush_cache)(const cfp_array1f self); size_t (*size_bytes)(const cfp_array1f self, uint mask); size_t (*compressed_size)(const cfp_array1f self); void* (*compressed_data)(const cfp_array1f self); size_t (*size)(const cfp_array1f self); void (*resize)(cfp_array1f self, size_t n, zfp_bool clear); void (*get_array)(const cfp_array1f self, float* p); void (*set_array)(cfp_array1f self, const float* p); float (*get_flat)(const cfp_array1f self, size_t i); void (*set_flat)(cfp_array1f self, size_t i, float val); float (*get)(const cfp_array1f self, size_t i); void (*set)(cfp_array1f self, size_t i, float val); cfp_ref1f (*ref)(cfp_array1f self, size_t i); cfp_ref1f (*ref_flat)(cfp_array1f self, size_t i); cfp_ptr1f (*ptr)(cfp_array1f self, size_t i); cfp_ptr1f (*ptr_flat)(cfp_array1f self, size_t i); cfp_iter1f (*begin)(cfp_array1f self); cfp_iter1f (*end)(cfp_array1f self); cfp_ref1f_api reference; cfp_ptr1f_api pointer; cfp_iter1f_api iterator; cfp_header1f_api header; } cfp_array1f_api; #endif zfp-1.0.1/include/zfp/internal/cfp/array2d.h000066400000000000000000000122411453723256400206460ustar00rootroot00000000000000#ifndef CFP_ARRAY_2D_H #define CFP_ARRAY_2D_H #include #include "zfp.h" typedef struct { void* object; } cfp_array2d; typedef struct { cfp_array2d array; size_t x, y; } cfp_ref2d; typedef struct { cfp_ref2d reference; } cfp_ptr2d; typedef struct { cfp_array2d array; size_t x, y; } cfp_iter2d; typedef struct { /* member functions */ double (*get)(const cfp_ref2d self); void (*set)(cfp_ref2d self, double val); cfp_ptr2d (*ptr)(cfp_ref2d self); void (*copy)(cfp_ref2d self, const cfp_ref2d src); } cfp_ref2d_api; typedef struct { /* member functions */ double (*get)(const cfp_ptr2d self); double (*get_at)(const cfp_ptr2d self, ptrdiff_t d); void (*set)(cfp_ptr2d self, double val); void (*set_at)(cfp_ptr2d self, ptrdiff_t d, double val); cfp_ref2d (*ref)(cfp_ptr2d self); cfp_ref2d (*ref_at)(cfp_ptr2d self, ptrdiff_t d); /* non-member functions */ zfp_bool (*lt)(const cfp_ptr2d lhs, const cfp_ptr2d rhs); zfp_bool (*gt)(const cfp_ptr2d lhs, const cfp_ptr2d rhs); zfp_bool (*leq)(const cfp_ptr2d lhs, const cfp_ptr2d rhs); zfp_bool (*geq)(const cfp_ptr2d lhs, const cfp_ptr2d rhs); zfp_bool (*eq)(const cfp_ptr2d lhs, const cfp_ptr2d rhs); zfp_bool (*neq)(const cfp_ptr2d lhs, const cfp_ptr2d rhs); ptrdiff_t (*distance)(const cfp_ptr2d first, const cfp_ptr2d last); cfp_ptr2d (*next)(const cfp_ptr2d p, ptrdiff_t d); cfp_ptr2d (*prev)(const cfp_ptr2d p, ptrdiff_t d); cfp_ptr2d (*inc)(const cfp_ptr2d p); cfp_ptr2d (*dec)(const cfp_ptr2d p); } cfp_ptr2d_api; typedef struct { /* member functions */ double (*get)(const cfp_iter2d self); double (*get_at)(const cfp_iter2d self, ptrdiff_t d); void (*set)(cfp_iter2d self, double value); void (*set_at)(cfp_iter2d self, ptrdiff_t d, double value); cfp_ref2d (*ref)(cfp_iter2d self); cfp_ref2d (*ref_at)(cfp_iter2d self, ptrdiff_t d); cfp_ptr2d (*ptr)(cfp_iter2d self); cfp_ptr2d (*ptr_at)(cfp_iter2d self, ptrdiff_t d); size_t (*i)(const cfp_iter2d self); size_t (*j)(const cfp_iter2d self); /* non-member functions */ zfp_bool (*lt)(const cfp_iter2d lhs, const cfp_iter2d rhs); zfp_bool (*gt)(const cfp_iter2d lhs, const cfp_iter2d rhs); zfp_bool (*leq)(const cfp_iter2d lhs, const cfp_iter2d rhs); zfp_bool (*geq)(const cfp_iter2d lhs, const cfp_iter2d rhs); zfp_bool (*eq)(const cfp_iter2d lhs, const cfp_iter2d rhs); zfp_bool (*neq)(const cfp_iter2d lhs, const cfp_iter2d rhs); ptrdiff_t (*distance)(const cfp_iter2d fist, const cfp_iter2d last); cfp_iter2d (*next)(const cfp_iter2d it, ptrdiff_t d); cfp_iter2d (*prev)(const cfp_iter2d it, ptrdiff_t d); cfp_iter2d (*inc)(const cfp_iter2d it); cfp_iter2d (*dec)(const cfp_iter2d it); } cfp_iter2d_api; typedef struct { /* constructor/destructor */ cfp_header (*ctor)(const cfp_array2d a); cfp_header (*ctor_buffer)(const void* data, size_t size); void (*dtor)(cfp_header self); /* array metadata */ zfp_type (*scalar_type)(const cfp_header self); uint (*dimensionality)(const cfp_header self); size_t (*size_x)(const cfp_header self); size_t (*size_y)(const cfp_header self); size_t (*size_z)(const cfp_header self); size_t (*size_w)(const cfp_header self); double (*rate)(const cfp_header self); /* header payload: data pointer and byte size */ const void* (*data)(const cfp_header self); size_t (*size_bytes)(const cfp_header self, uint mask); } cfp_header2d_api; typedef struct { cfp_array2d (*ctor_default)(void); cfp_array2d (*ctor)(size_t nx, size_t ny, double rate, const double* p, size_t cache_size); cfp_array2d (*ctor_copy)(const cfp_array2d src); cfp_array2d (*ctor_header)(const cfp_header h, const void* buffer, size_t buffer_size_bytes); void (*dtor)(cfp_array2d self); void (*deep_copy)(cfp_array2d self, const cfp_array2d src); double (*rate)(const cfp_array2d self); double (*set_rate)(cfp_array2d self, double rate); size_t (*cache_size)(const cfp_array2d self); void (*set_cache_size)(cfp_array2d self, size_t bytes); void (*clear_cache)(const cfp_array2d self); void (*flush_cache)(const cfp_array2d self); size_t (*size_bytes)(const cfp_array2d self, uint mask); size_t (*compressed_size)(const cfp_array2d self); void* (*compressed_data)(const cfp_array2d self); size_t (*size)(const cfp_array2d self); size_t (*size_x)(const cfp_array2d self); size_t (*size_y)(const cfp_array2d self); void (*resize)(cfp_array2d self, size_t nx, size_t ny, zfp_bool clear); void (*get_array)(const cfp_array2d self, double* p); void (*set_array)(cfp_array2d self, const double* p); double (*get_flat)(const cfp_array2d self, size_t i); void (*set_flat)(cfp_array2d self, size_t i, double val); double (*get)(const cfp_array2d self, size_t i, size_t j); void (*set)(cfp_array2d self, size_t i, size_t j, double val); cfp_ref2d (*ref)(cfp_array2d self, size_t i, size_t j); cfp_ref2d (*ref_flat)(cfp_array2d self, size_t i); cfp_ptr2d (*ptr)(cfp_array2d self, size_t i, size_t j); cfp_ptr2d (*ptr_flat)(cfp_array2d self, size_t i); cfp_iter2d (*begin)(cfp_array2d self); cfp_iter2d (*end)(cfp_array2d self); cfp_ref2d_api reference; cfp_ptr2d_api pointer; cfp_iter2d_api iterator; cfp_header2d_api header; } cfp_array2d_api; #endif zfp-1.0.1/include/zfp/internal/cfp/array2f.h000066400000000000000000000122151453723256400206510ustar00rootroot00000000000000#ifndef CFP_ARRAY_2F_H #define CFP_ARRAY_2F_H #include #include "zfp.h" typedef struct { void* object; } cfp_array2f; typedef struct { cfp_array2f array; size_t x, y; } cfp_ref2f; typedef struct { cfp_ref2f reference; } cfp_ptr2f; typedef struct { cfp_array2f array; size_t x, y; } cfp_iter2f; typedef struct { /* member functions */ float (*get)(const cfp_ref2f self); void (*set)(cfp_ref2f self, float val); cfp_ptr2f (*ptr)(cfp_ref2f self); void (*copy)(cfp_ref2f self, const cfp_ref2f src); } cfp_ref2f_api; typedef struct { /* member functions */ float (*get)(const cfp_ptr2f self); float (*get_at)(const cfp_ptr2f self, ptrdiff_t d); void (*set)(cfp_ptr2f self, float val); void (*set_at)(cfp_ptr2f self, ptrdiff_t d, float val); cfp_ref2f (*ref)(cfp_ptr2f self); cfp_ref2f (*ref_at)(cfp_ptr2f self, ptrdiff_t d); /* non-member functions */ zfp_bool (*lt)(const cfp_ptr2f lhs, const cfp_ptr2f rhs); zfp_bool (*gt)(const cfp_ptr2f lhs, const cfp_ptr2f rhs); zfp_bool (*leq)(const cfp_ptr2f lhs, const cfp_ptr2f rhs); zfp_bool (*geq)(const cfp_ptr2f lhs, const cfp_ptr2f rhs); zfp_bool (*eq)(const cfp_ptr2f lhs, const cfp_ptr2f rhs); zfp_bool (*neq)(const cfp_ptr2f lhs, const cfp_ptr2f rhs); ptrdiff_t (*distance)(const cfp_ptr2f first, const cfp_ptr2f last); cfp_ptr2f (*next)(const cfp_ptr2f p, ptrdiff_t d); cfp_ptr2f (*prev)(const cfp_ptr2f p, ptrdiff_t d); cfp_ptr2f (*inc)(const cfp_ptr2f p); cfp_ptr2f (*dec)(const cfp_ptr2f p); } cfp_ptr2f_api; typedef struct { /* member functions */ float (*get)(const cfp_iter2f self); float (*get_at)(const cfp_iter2f self, ptrdiff_t d); void (*set)(cfp_iter2f self, float val); void (*set_at)(cfp_iter2f self, ptrdiff_t d, float val); cfp_ref2f (*ref)(cfp_iter2f self); cfp_ref2f (*ref_at)(cfp_iter2f self, ptrdiff_t d); cfp_ptr2f (*ptr)(cfp_iter2f self); cfp_ptr2f (*ptr_at)(cfp_iter2f self, ptrdiff_t d); size_t (*i)(const cfp_iter2f self); size_t (*j)(const cfp_iter2f self); /* non-member functions */ zfp_bool (*lt)(const cfp_iter2f lhs, const cfp_iter2f rhs); zfp_bool (*gt)(const cfp_iter2f lhs, const cfp_iter2f rhs); zfp_bool (*leq)(const cfp_iter2f lhs, const cfp_iter2f rhs); zfp_bool (*geq)(const cfp_iter2f lhs, const cfp_iter2f rhs); zfp_bool (*eq)(const cfp_iter2f lhs, const cfp_iter2f rhs); zfp_bool (*neq)(const cfp_iter2f lhs, const cfp_iter2f rhs); ptrdiff_t (*distance)(const cfp_iter2f first, const cfp_iter2f last); cfp_iter2f (*next)(const cfp_iter2f it, ptrdiff_t d); cfp_iter2f (*prev)(const cfp_iter2f it, ptrdiff_t d); cfp_iter2f (*inc)(const cfp_iter2f it); cfp_iter2f (*dec)(const cfp_iter2f it); } cfp_iter2f_api; typedef struct { /* constructor/destructor */ cfp_header (*ctor)(const cfp_array2f a); cfp_header (*ctor_buffer)(const void* data, size_t size); void (*dtor)(cfp_header self); /* array metadata */ zfp_type (*scalar_type)(const cfp_header self); uint (*dimensionality)(const cfp_header self); size_t (*size_x)(const cfp_header self); size_t (*size_y)(const cfp_header self); size_t (*size_z)(const cfp_header self); size_t (*size_w)(const cfp_header self); double (*rate)(const cfp_header self); /* header payload: data pointer and byte size */ const void* (*data)(const cfp_header self); size_t (*size_bytes)(const cfp_header self, uint mask); } cfp_header2f_api; typedef struct { cfp_array2f (*ctor_default)(void); cfp_array2f (*ctor)(size_t nx, size_t ny, double rate, const float* p, size_t cache_size); cfp_array2f (*ctor_copy)(const cfp_array2f src); cfp_array2f (*ctor_header)(const cfp_header h, const void* buffer, size_t buffer_size_bytes); void (*dtor)(cfp_array2f self); void (*deep_copy)(cfp_array2f self, const cfp_array2f src); double (*rate)(const cfp_array2f self); double (*set_rate)(cfp_array2f self, double rate); size_t (*cache_size)(const cfp_array2f self); void (*set_cache_size)(cfp_array2f self, size_t bytes); void (*clear_cache)(const cfp_array2f self); void (*flush_cache)(const cfp_array2f self); size_t (*size_bytes)(const cfp_array2f self, uint mask); size_t (*compressed_size)(const cfp_array2f self); void* (*compressed_data)(const cfp_array2f self); size_t (*size)(const cfp_array2f self); size_t (*size_x)(const cfp_array2f self); size_t (*size_y)(const cfp_array2f self); void (*resize)(cfp_array2f self, size_t nx, size_t ny, zfp_bool clear); void (*get_array)(const cfp_array2f self, float* p); void (*set_array)(cfp_array2f self, const float* p); float (*get_flat)(const cfp_array2f self, size_t i); void (*set_flat)(cfp_array2f self, size_t i, float val); float (*get)(const cfp_array2f self, size_t i, size_t j); void (*set)(cfp_array2f self, size_t i, size_t j, float val); cfp_ref2f (*ref)(cfp_array2f self, size_t i, size_t j); cfp_ref2f (*ref_flat)(cfp_array2f self, size_t i); cfp_ptr2f (*ptr)(cfp_array2f self, size_t i, size_t j); cfp_ptr2f (*ptr_flat)(cfp_array2f self, size_t i); cfp_iter2f (*begin)(cfp_array2f self); cfp_iter2f (*end)(cfp_array2f self); cfp_ref2f_api reference; cfp_ptr2f_api pointer; cfp_iter2f_api iterator; cfp_header2f_api header; } cfp_array2f_api; #endif zfp-1.0.1/include/zfp/internal/cfp/array3d.h000066400000000000000000000124641453723256400206560ustar00rootroot00000000000000#ifndef CFP_ARRAY_3D_H #define CFP_ARRAY_3D_H #include #include "zfp.h" typedef struct { void* object; } cfp_array3d; typedef struct { cfp_array3d array; size_t x, y, z; } cfp_ref3d; typedef struct { cfp_ref3d reference; } cfp_ptr3d; typedef struct { cfp_array3d array; size_t x, y, z; } cfp_iter3d; typedef struct { /* member functions */ double (*get)(const cfp_ref3d self); void (*set)(cfp_ref3d self, double val); cfp_ptr3d (*ptr)(cfp_ref3d self); void (*copy)(cfp_ref3d self, const cfp_ref3d src); } cfp_ref3d_api; typedef struct { /* member functions */ double (*get)(const cfp_ptr3d self); double (*get_at)(const cfp_ptr3d self, ptrdiff_t d); void (*set)(cfp_ptr3d self, double val); void (*set_at)(cfp_ptr3d self, ptrdiff_t d, double val); cfp_ref3d (*ref)(cfp_ptr3d self); cfp_ref3d (*ref_at)(cfp_ptr3d self, ptrdiff_t d); /* non-member functions */ zfp_bool (*lt)(const cfp_ptr3d lhs, const cfp_ptr3d rhs); zfp_bool (*gt)(const cfp_ptr3d lhs, const cfp_ptr3d rhs); zfp_bool (*leq)(const cfp_ptr3d lhs, const cfp_ptr3d rhs); zfp_bool (*geq)(const cfp_ptr3d lhs, const cfp_ptr3d rhs); zfp_bool (*eq)(const cfp_ptr3d lhs, const cfp_ptr3d rhs); zfp_bool (*neq)(const cfp_ptr3d lhs, const cfp_ptr3d rhs); ptrdiff_t (*distance)(const cfp_ptr3d first, const cfp_ptr3d last); cfp_ptr3d (*next)(const cfp_ptr3d p, ptrdiff_t d); cfp_ptr3d (*prev)(const cfp_ptr3d p, ptrdiff_t d); cfp_ptr3d (*inc)(const cfp_ptr3d p); cfp_ptr3d (*dec)(const cfp_ptr3d p); } cfp_ptr3d_api; typedef struct { /* member functions */ double (*get)(const cfp_iter3d self); double (*get_at)(const cfp_iter3d self, ptrdiff_t d); void (*set)(cfp_iter3d self, double val); void (*set_at)(cfp_iter3d self, ptrdiff_t d, double val); cfp_ref3d (*ref)(cfp_iter3d self); cfp_ref3d (*ref_at)(cfp_iter3d self, ptrdiff_t d); cfp_ptr3d (*ptr)(cfp_iter3d self); cfp_ptr3d (*ptr_at)(cfp_iter3d self, ptrdiff_t d); size_t (*i)(const cfp_iter3d self); size_t (*j)(const cfp_iter3d self); size_t (*k)(const cfp_iter3d self); /* non-member functions */ zfp_bool (*lt)(const cfp_iter3d lhs, const cfp_iter3d rhs); zfp_bool (*gt)(const cfp_iter3d lhs, const cfp_iter3d rhs); zfp_bool (*leq)(const cfp_iter3d lhs, const cfp_iter3d rhs); zfp_bool (*geq)(const cfp_iter3d lhs, const cfp_iter3d rhs); zfp_bool (*eq)(const cfp_iter3d lhs, const cfp_iter3d rhs); zfp_bool (*neq)(const cfp_iter3d lhs, const cfp_iter3d rhs); ptrdiff_t (*distance)(const cfp_iter3d first, const cfp_iter3d last); cfp_iter3d (*next)(const cfp_iter3d it, ptrdiff_t d); cfp_iter3d (*prev)(const cfp_iter3d it, ptrdiff_t d); cfp_iter3d (*inc)(const cfp_iter3d it); cfp_iter3d (*dec)(const cfp_iter3d it); } cfp_iter3d_api; typedef struct { /* constructor/destructor */ cfp_header (*ctor)(const cfp_array3d a); cfp_header (*ctor_buffer)(const void* data, size_t size); void (*dtor)(cfp_header self); /* array metadata */ zfp_type (*scalar_type)(const cfp_header self); uint (*dimensionality)(const cfp_header self); size_t (*size_x)(const cfp_header self); size_t (*size_y)(const cfp_header self); size_t (*size_z)(const cfp_header self); size_t (*size_w)(const cfp_header self); double (*rate)(const cfp_header self); /* header payload: data pointer and byte size */ const void* (*data)(const cfp_header self); size_t (*size_bytes)(const cfp_header self, uint mask); } cfp_header3d_api; typedef struct { cfp_array3d (*ctor_default)(void); cfp_array3d (*ctor)(size_t nx, size_t ny, size_t nz, double rate, const double* p, size_t cache_size); cfp_array3d (*ctor_copy)(const cfp_array3d src); cfp_array3d (*ctor_header)(const cfp_header h, const void* buffer, size_t buffer_size_bytes); void (*dtor)(cfp_array3d self); void (*deep_copy)(cfp_array3d self, const cfp_array3d src); double (*rate)(const cfp_array3d self); double (*set_rate)(cfp_array3d self, double rate); size_t (*cache_size)(const cfp_array3d self); void (*set_cache_size)(cfp_array3d self, size_t bytes); void (*clear_cache)(const cfp_array3d self); void (*flush_cache)(const cfp_array3d self); size_t (*size_bytes)(const cfp_array3d self, uint mask); size_t (*compressed_size)(const cfp_array3d self); void* (*compressed_data)(const cfp_array3d self); size_t (*size)(const cfp_array3d self); size_t (*size_x)(const cfp_array3d self); size_t (*size_y)(const cfp_array3d self); size_t (*size_z)(const cfp_array3d self); void (*resize)(cfp_array3d self, size_t nx, size_t ny, size_t nz, zfp_bool clear); void (*get_array)(const cfp_array3d self, double* p); void (*set_array)(cfp_array3d self, const double* p); double (*get_flat)(const cfp_array3d self, size_t i); void (*set_flat)(cfp_array3d self, size_t i, double val); double (*get)(const cfp_array3d self, size_t i, size_t j, size_t k); void (*set)(cfp_array3d self, size_t i, size_t j, size_t k, double val); cfp_ref3d (*ref)(cfp_array3d self, size_t i, size_t j, size_t k); cfp_ref3d (*ref_flat)(cfp_array3d self, size_t i); cfp_ptr3d (*ptr)(cfp_array3d self, size_t i, size_t j, size_t k); cfp_ptr3d (*ptr_flat)(cfp_array3d self, size_t i); cfp_iter3d (*begin)(cfp_array3d self); cfp_iter3d (*end)(cfp_array3d self); cfp_ref3d_api reference; cfp_ptr3d_api pointer; cfp_iter3d_api iterator; cfp_header3d_api header; } cfp_array3d_api; #endif zfp-1.0.1/include/zfp/internal/cfp/array3f.h000066400000000000000000000124431453723256400206550ustar00rootroot00000000000000#ifndef CFP_ARRAY_3F_H #define CFP_ARRAY_3F_H #include #include "zfp.h" typedef struct { void* object; } cfp_array3f; typedef struct { cfp_array3f array; size_t x, y, z; } cfp_ref3f; typedef struct { cfp_ref3f reference; } cfp_ptr3f; typedef struct { cfp_array3f array; size_t x, y, z; } cfp_iter3f; typedef struct { /* member functions */ float (*get)(const cfp_ref3f self); void (*set)(cfp_ref3f self, float val); cfp_ptr3f (*ptr)(cfp_ref3f self); void (*copy)(cfp_ref3f self, const cfp_ref3f src); } cfp_ref3f_api; typedef struct { /* member functions */ float (*get)(const cfp_ptr3f self); float (*get_at)(const cfp_ptr3f self, ptrdiff_t d); void (*set)(cfp_ptr3f self, float val); void (*set_at)(cfp_ptr3f self, ptrdiff_t d, float val); cfp_ref3f (*ref)(cfp_ptr3f self); cfp_ref3f (*ref_at)(cfp_ptr3f self, ptrdiff_t d); /* non-member functions */ zfp_bool (*lt)(const cfp_ptr3f lhs, const cfp_ptr3f rhs); zfp_bool (*gt)(const cfp_ptr3f lhs, const cfp_ptr3f rhs); zfp_bool (*leq)(const cfp_ptr3f lhs, const cfp_ptr3f rhs); zfp_bool (*geq)(const cfp_ptr3f lhs, const cfp_ptr3f rhs); zfp_bool (*eq)(const cfp_ptr3f lhs, const cfp_ptr3f rhs); zfp_bool (*neq)(const cfp_ptr3f lhs, const cfp_ptr3f rhs); ptrdiff_t (*distance)(const cfp_ptr3f first, const cfp_ptr3f last); cfp_ptr3f (*next)(const cfp_ptr3f p, ptrdiff_t d); cfp_ptr3f (*prev)(const cfp_ptr3f p, ptrdiff_t d); cfp_ptr3f (*inc)(const cfp_ptr3f p); cfp_ptr3f (*dec)(const cfp_ptr3f p); } cfp_ptr3f_api; typedef struct { /* member functions */ float (*get)(const cfp_iter3f self); float (*get_at)(const cfp_iter3f self, ptrdiff_t d); void (*set)(cfp_iter3f self, float val); void (*set_at)(cfp_iter3f self, ptrdiff_t d, float val); cfp_ref3f (*ref)(cfp_iter3f self); cfp_ref3f (*ref_at)(cfp_iter3f self, ptrdiff_t d); cfp_ptr3f (*ptr)(cfp_iter3f self); cfp_ptr3f (*ptr_at)(cfp_iter3f self, ptrdiff_t d); size_t (*i)(const cfp_iter3f self); size_t (*j)(const cfp_iter3f self); size_t (*k)(const cfp_iter3f self); /* non-member functions */ zfp_bool (*lt)(const cfp_iter3f lhs, const cfp_iter3f rhs); zfp_bool (*gt)(const cfp_iter3f lhs, const cfp_iter3f rhs); zfp_bool (*leq)(const cfp_iter3f lhs, const cfp_iter3f rhs); zfp_bool (*geq)(const cfp_iter3f lhs, const cfp_iter3f rhs); zfp_bool (*eq)(const cfp_iter3f lhs, const cfp_iter3f rhs); zfp_bool (*neq)(const cfp_iter3f lhs, const cfp_iter3f rhs); ptrdiff_t (*distance)(const cfp_iter3f first, const cfp_iter3f last); cfp_iter3f (*next)(const cfp_iter3f it, ptrdiff_t d); cfp_iter3f (*prev)(const cfp_iter3f it, ptrdiff_t d); cfp_iter3f (*inc)(const cfp_iter3f it); cfp_iter3f (*dec)(const cfp_iter3f it); } cfp_iter3f_api; typedef struct { /* constructor/destructor */ cfp_header (*ctor)(const cfp_array3f a); cfp_header (*ctor_buffer)(const void* data, size_t size); void (*dtor)(cfp_header self); /* array metadata */ zfp_type (*scalar_type)(const cfp_header self); uint (*dimensionality)(const cfp_header self); size_t (*size_x)(const cfp_header self); size_t (*size_y)(const cfp_header self); size_t (*size_z)(const cfp_header self); size_t (*size_w)(const cfp_header self); double (*rate)(const cfp_header self); /* header payload: data pointer and byte size */ const void* (*data)(const cfp_header self); size_t (*size_bytes)(const cfp_header self, uint mask); } cfp_header3f_api; typedef struct { cfp_array3f (*ctor_default)(void); cfp_array3f (*ctor)(size_t nx, size_t ny, size_t nz, double rate, const float* p, size_t cache_size); cfp_array3f (*ctor_copy)(const cfp_array3f src); cfp_array3f (*ctor_header)(const cfp_header h, const void* buffer, size_t buffer_size_bytes); void (*dtor)(cfp_array3f self); void (*deep_copy)(cfp_array3f self, const cfp_array3f src); double (*rate)(const cfp_array3f self); double (*set_rate)(cfp_array3f self, double rate); size_t (*cache_size)(const cfp_array3f self); void (*set_cache_size)(cfp_array3f self, size_t bytes); void (*clear_cache)(const cfp_array3f self); void (*flush_cache)(const cfp_array3f self); size_t (*size_bytes)(const cfp_array3f self, uint mask); size_t (*compressed_size)(const cfp_array3f self); void* (*compressed_data)(const cfp_array3f self); size_t (*size)(const cfp_array3f self); size_t (*size_x)(const cfp_array3f self); size_t (*size_y)(const cfp_array3f self); size_t (*size_z)(const cfp_array3f self); void (*resize)(cfp_array3f self, size_t nx, size_t ny, size_t nz, zfp_bool clear); void (*get_array)(const cfp_array3f self, float* p); void (*set_array)(cfp_array3f self, const float* p); float (*get_flat)(const cfp_array3f self, size_t i); void (*set_flat)(cfp_array3f self, size_t i, float val); float (*get)(const cfp_array3f self, size_t i, size_t j, size_t k); void (*set)(cfp_array3f self, size_t i, size_t j, size_t k, float val); cfp_ref3f (*ref)(cfp_array3f self, size_t i, size_t j, size_t k); cfp_ref3f (*ref_flat)(cfp_array3f self, size_t i); cfp_ptr3f (*ptr)(cfp_array3f self, size_t i, size_t j, size_t k); cfp_ptr3f (*ptr_flat)(cfp_array3f self, size_t i); cfp_iter3f (*begin)(cfp_array3f self); cfp_iter3f (*end)(cfp_array3f self); cfp_ref3f_api reference; cfp_ptr3f_api pointer; cfp_iter3f_api iterator; cfp_header3f_api header; } cfp_array3f_api; #endif zfp-1.0.1/include/zfp/internal/cfp/array4d.h000066400000000000000000000127121453723256400206530ustar00rootroot00000000000000#ifndef CFP_ARRAY_4D_H #define CFP_ARRAY_4D_H #include #include "zfp.h" typedef struct { void* object; } cfp_array4d; typedef struct { cfp_array4d array; size_t x, y, z, w; } cfp_ref4d; typedef struct { cfp_ref4d reference; } cfp_ptr4d; typedef struct { cfp_array4d array; size_t x, y, z, w; } cfp_iter4d; typedef struct { /* member functions */ double (*get)(const cfp_ref4d self); void (*set)(cfp_ref4d self, double val); cfp_ptr4d (*ptr)(cfp_ref4d self); void (*copy)(cfp_ref4d self, const cfp_ref4d src); } cfp_ref4d_api; typedef struct { /* member functions */ double (*get)(const cfp_ptr4d self); double (*get_at)(const cfp_ptr4d self, ptrdiff_t d); void (*set)(cfp_ptr4d self, double val); void (*set_at)(cfp_ptr4d self, ptrdiff_t d, double val); cfp_ref4d (*ref)(cfp_ptr4d self); cfp_ref4d (*ref_at)(cfp_ptr4d self, ptrdiff_t d); /* non-member functions */ zfp_bool (*lt)(const cfp_ptr4d lhs, const cfp_ptr4d rhs); zfp_bool (*gt)(const cfp_ptr4d lhs, const cfp_ptr4d rhs); zfp_bool (*leq)(const cfp_ptr4d lhs, const cfp_ptr4d rhs); zfp_bool (*geq)(const cfp_ptr4d lhs, const cfp_ptr4d rhs); zfp_bool (*eq)(const cfp_ptr4d lhs, const cfp_ptr4d rhs); zfp_bool (*neq)(const cfp_ptr4d lhs, const cfp_ptr4d rhs); ptrdiff_t (*distance)(const cfp_ptr4d first, const cfp_ptr4d last); cfp_ptr4d (*next)(const cfp_ptr4d p, ptrdiff_t d); cfp_ptr4d (*prev)(const cfp_ptr4d p, ptrdiff_t d); cfp_ptr4d (*inc)(const cfp_ptr4d p); cfp_ptr4d (*dec)(const cfp_ptr4d p); } cfp_ptr4d_api; typedef struct { /* member functions */ double (*get)(const cfp_iter4d self); double (*get_at)(const cfp_iter4d self, ptrdiff_t d); void (*set)(cfp_iter4d self, double val); void (*set_at)(cfp_iter4d self, ptrdiff_t d, double val); cfp_ref4d (*ref)(cfp_iter4d self); cfp_ref4d (*ref_at)(cfp_iter4d self, ptrdiff_t d); cfp_ptr4d (*ptr)(cfp_iter4d self); cfp_ptr4d (*ptr_at)(cfp_iter4d self, ptrdiff_t d); size_t (*i)(const cfp_iter4d self); size_t (*j)(const cfp_iter4d self); size_t (*k)(const cfp_iter4d self); size_t (*l)(const cfp_iter4d self); /* non-member functions */ zfp_bool (*lt)(const cfp_iter4d lhs, const cfp_iter4d rhs); zfp_bool (*gt)(const cfp_iter4d lhs, const cfp_iter4d rhs); zfp_bool (*leq)(const cfp_iter4d lhs, const cfp_iter4d rhs); zfp_bool (*geq)(const cfp_iter4d lhs, const cfp_iter4d rhs); zfp_bool (*eq)(const cfp_iter4d lhs, const cfp_iter4d rhs); zfp_bool (*neq)(const cfp_iter4d lhs, const cfp_iter4d rhs); ptrdiff_t (*distance)(const cfp_iter4d first, const cfp_iter4d last); cfp_iter4d (*next)(const cfp_iter4d it, ptrdiff_t d); cfp_iter4d (*prev)(const cfp_iter4d it, ptrdiff_t d); cfp_iter4d (*inc)(const cfp_iter4d it); cfp_iter4d (*dec)(const cfp_iter4d it); } cfp_iter4d_api; typedef struct { /* constructor/destructor */ cfp_header (*ctor)(const cfp_array4d a); cfp_header (*ctor_buffer)(const void* data, size_t size); void (*dtor)(cfp_header self); /* array metadata */ zfp_type (*scalar_type)(const cfp_header self); uint (*dimensionality)(const cfp_header self); size_t (*size_x)(const cfp_header self); size_t (*size_y)(const cfp_header self); size_t (*size_z)(const cfp_header self); size_t (*size_w)(const cfp_header self); double (*rate)(const cfp_header self); /* header payload: data pointer and byte size */ const void* (*data)(const cfp_header self); size_t (*size_bytes)(const cfp_header self, uint mask); } cfp_header4d_api; typedef struct { cfp_array4d (*ctor_default)(void); cfp_array4d (*ctor)(size_t nx, size_t ny, size_t nz, size_t nw, double rate, const double* p, size_t cache_size); cfp_array4d (*ctor_copy)(const cfp_array4d src); cfp_array4d (*ctor_header)(const cfp_header h, const void* buffer, size_t buffer_size_bytes); void (*dtor)(cfp_array4d self); void (*deep_copy)(cfp_array4d self, const cfp_array4d src); double (*rate)(const cfp_array4d self); double (*set_rate)(cfp_array4d self, double rate); size_t (*cache_size)(const cfp_array4d self); void (*set_cache_size)(cfp_array4d self, size_t bytes); void (*clear_cache)(const cfp_array4d self); void (*flush_cache)(const cfp_array4d self); size_t (*size_bytes)(const cfp_array4d self, uint mask); size_t (*compressed_size)(const cfp_array4d self); void* (*compressed_data)(const cfp_array4d self); size_t (*size)(const cfp_array4d self); size_t (*size_x)(const cfp_array4d self); size_t (*size_y)(const cfp_array4d self); size_t (*size_z)(const cfp_array4d self); size_t (*size_w)(const cfp_array4d self); void (*resize)(cfp_array4d self, size_t nx, size_t ny, size_t nz, size_t nw, zfp_bool clear); void (*get_array)(const cfp_array4d self, double* p); void (*set_array)(cfp_array4d self, const double* p); double (*get_flat)(const cfp_array4d self, size_t i); void (*set_flat)(cfp_array4d self, size_t i, double val); double (*get)(const cfp_array4d self, size_t i, size_t j, size_t k, size_t l); void (*set)(cfp_array4d self, size_t i, size_t j, size_t k, size_t l, double val); cfp_ref4d (*ref)(cfp_array4d self, size_t i, size_t j, size_t k, size_t l); cfp_ref4d (*ref_flat)(cfp_array4d self, size_t i); cfp_ptr4d (*ptr)(cfp_array4d self, size_t i, size_t j, size_t k, size_t l); cfp_ptr4d (*ptr_flat)(cfp_array4d self, size_t i); cfp_iter4d (*begin)(cfp_array4d self); cfp_iter4d (*end)(cfp_array4d self); cfp_ref4d_api reference; cfp_ptr4d_api pointer; cfp_iter4d_api iterator; cfp_header4d_api header; } cfp_array4d_api; #endif zfp-1.0.1/include/zfp/internal/cfp/array4f.h000066400000000000000000000126711453723256400206610ustar00rootroot00000000000000#ifndef CFP_ARRAY_4F_H #define CFP_ARRAY_4F_H #include #include "zfp.h" typedef struct { void* object; } cfp_array4f; typedef struct { cfp_array4f array; size_t x, y, z, w; } cfp_ref4f; typedef struct { cfp_ref4f reference; } cfp_ptr4f; typedef struct { cfp_array4f array; size_t x, y, z, w; } cfp_iter4f; typedef struct { /* member functions */ float (*get)(const cfp_ref4f self); void (*set)(cfp_ref4f self, float val); cfp_ptr4f (*ptr)(cfp_ref4f self); void (*copy)(cfp_ref4f self, const cfp_ref4f src); } cfp_ref4f_api; typedef struct { /* member functions */ float (*get)(const cfp_ptr4f self); float (*get_at)(const cfp_ptr4f self, ptrdiff_t d); void (*set)(cfp_ptr4f self, float val); void (*set_at)(cfp_ptr4f self, ptrdiff_t d, float val); cfp_ref4f (*ref)(cfp_ptr4f self); cfp_ref4f (*ref_at)(cfp_ptr4f self, ptrdiff_t d); /* non-member functions */ zfp_bool (*lt)(const cfp_ptr4f lhs, const cfp_ptr4f rhs); zfp_bool (*gt)(const cfp_ptr4f lhs, const cfp_ptr4f rhs); zfp_bool (*leq)(const cfp_ptr4f lhs, const cfp_ptr4f rhs); zfp_bool (*geq)(const cfp_ptr4f lhs, const cfp_ptr4f rhs); zfp_bool (*eq)(const cfp_ptr4f lhs, const cfp_ptr4f rhs); zfp_bool (*neq)(const cfp_ptr4f lhs, const cfp_ptr4f rhs); ptrdiff_t (*distance)(const cfp_ptr4f first, const cfp_ptr4f last); cfp_ptr4f (*next)(const cfp_ptr4f p, ptrdiff_t d); cfp_ptr4f (*prev)(const cfp_ptr4f p, ptrdiff_t d); cfp_ptr4f (*inc)(const cfp_ptr4f p); cfp_ptr4f (*dec)(const cfp_ptr4f p); } cfp_ptr4f_api; typedef struct { /* member functions */ float (*get)(const cfp_iter4f self); float (*get_at)(const cfp_iter4f self, ptrdiff_t d); void (*set)(cfp_iter4f self, float val); void (*set_at)(cfp_iter4f self, ptrdiff_t d, float val); cfp_ref4f (*ref)(cfp_iter4f self); cfp_ref4f (*ref_at)(cfp_iter4f self, ptrdiff_t d); cfp_ptr4f (*ptr)(cfp_iter4f self); cfp_ptr4f (*ptr_at)(cfp_iter4f self, ptrdiff_t d); size_t (*i)(const cfp_iter4f self); size_t (*j)(const cfp_iter4f self); size_t (*k)(const cfp_iter4f self); size_t (*l)(const cfp_iter4f self); /* non-member functions */ zfp_bool (*lt)(const cfp_iter4f lhs, const cfp_iter4f rhs); zfp_bool (*gt)(const cfp_iter4f lhs, const cfp_iter4f rhs); zfp_bool (*leq)(const cfp_iter4f lhs, const cfp_iter4f rhs); zfp_bool (*geq)(const cfp_iter4f lhs, const cfp_iter4f rhs); zfp_bool (*eq)(const cfp_iter4f lhs, const cfp_iter4f rhs); zfp_bool (*neq)(const cfp_iter4f lhs, const cfp_iter4f rhs); ptrdiff_t (*distance)(const cfp_iter4f first, const cfp_iter4f last); cfp_iter4f (*next)(const cfp_iter4f it, ptrdiff_t d); cfp_iter4f (*prev)(const cfp_iter4f it, ptrdiff_t d); cfp_iter4f (*inc)(const cfp_iter4f it); cfp_iter4f (*dec)(const cfp_iter4f it); } cfp_iter4f_api; typedef struct { /* constructor/destructor */ cfp_header (*ctor)(const cfp_array4f a); cfp_header (*ctor_buffer)(const void* data, size_t size); void (*dtor)(cfp_header self); /* array metadata */ zfp_type (*scalar_type)(const cfp_header self); uint (*dimensionality)(const cfp_header self); size_t (*size_x)(const cfp_header self); size_t (*size_y)(const cfp_header self); size_t (*size_z)(const cfp_header self); size_t (*size_w)(const cfp_header self); double (*rate)(const cfp_header self); /* header payload: data pointer and byte size */ const void* (*data)(const cfp_header self); size_t (*size_bytes)(const cfp_header self, uint mask); } cfp_header4f_api; typedef struct { cfp_array4f (*ctor_default)(void); cfp_array4f (*ctor)(size_t nx, size_t ny, size_t nz, size_t nw, double rate, const float* p, size_t cache_size); cfp_array4f (*ctor_copy)(const cfp_array4f src); cfp_array4f (*ctor_header)(const cfp_header h, const void* buffer, size_t buffer_size_bytes); void (*dtor)(cfp_array4f self); void (*deep_copy)(cfp_array4f self, const cfp_array4f src); double (*rate)(const cfp_array4f self); double (*set_rate)(cfp_array4f self, double rate); size_t (*cache_size)(const cfp_array4f self); void (*set_cache_size)(cfp_array4f self, size_t bytes); void (*clear_cache)(const cfp_array4f self); void (*flush_cache)(const cfp_array4f self); size_t (*size_bytes)(const cfp_array4f self, uint mask); size_t (*compressed_size)(const cfp_array4f self); void* (*compressed_data)(const cfp_array4f self); size_t (*size)(const cfp_array4f self); size_t (*size_x)(const cfp_array4f self); size_t (*size_y)(const cfp_array4f self); size_t (*size_z)(const cfp_array4f self); size_t (*size_w)(const cfp_array4f self); void (*resize)(cfp_array4f self, size_t nx, size_t ny, size_t nz, size_t nw, zfp_bool clear); void (*get_array)(const cfp_array4f self, float* p); void (*set_array)(cfp_array4f self, const float* p); float (*get_flat)(const cfp_array4f self, size_t i); void (*set_flat)(cfp_array4f self, size_t i, float val); float (*get)(const cfp_array4f self, size_t i, size_t j, size_t k, size_t l); void (*set)(cfp_array4f self, size_t i, size_t j, size_t k, size_t l, float val); cfp_ref4f (*ref)(cfp_array4f self, size_t i, size_t j, size_t k, size_t l); cfp_ref4f (*ref_flat)(cfp_array4f self, size_t i); cfp_ptr4f (*ptr)(cfp_array4f self, size_t i, size_t j, size_t k, size_t l); cfp_ptr4f (*ptr_flat)(cfp_array4f self, size_t i); cfp_iter4f (*begin)(cfp_array4f self); cfp_iter4f (*end)(cfp_array4f self); cfp_ref4f_api reference; cfp_ptr4f_api pointer; cfp_iter4f_api iterator; cfp_header4f_api header; } cfp_array4f_api; #endif zfp-1.0.1/include/zfp/internal/cfp/header.h000066400000000000000000000001421453723256400205270ustar00rootroot00000000000000#ifndef CFP_HEADER_H #define CFP_HEADER_H typedef struct { void* object; } cfp_header; #endif zfp-1.0.1/include/zfp/internal/codec/000077500000000000000000000000001453723256400174365ustar00rootroot00000000000000zfp-1.0.1/include/zfp/internal/codec/genheader.hpp000066400000000000000000000044661453723256400221030ustar00rootroot00000000000000// zfp::codec::generic_base::header class header : public zfp::array::header { public: // serialization: construct header from array header(const zfp::array& a) : zfp::array::header(a), bit_rate(static_cast(a.rate())) { buffer[0] = magic; buffer[1] = 0; // TODO: codec identifier (dimensionality, internal type) buffer[2] = static_cast(bit_rate); buffer[3] = static_cast(type); buffer[4] = static_cast(nx); buffer[5] = static_cast(ny); buffer[6] = static_cast(nz); buffer[7] = static_cast(nw); } // deserialization: construct header from memory buffer of optional size header(const void* data, size_t bytes = 0) : bit_rate(0) { // ensure byte size matches if (bytes && bytes != byte_size) throw zfp::exception("zfp generic header length does not match expectations"); else { // copy and parse header std::memcpy(buffer, data, byte_size); if (buffer[0] != magic) throw zfp::exception("zfp generic header is corrupt"); bit_rate = static_cast(buffer[2]); type = static_cast(buffer[3]); nx = static_cast(buffer[4]); ny = static_cast(buffer[5]); nz = static_cast(buffer[6]); nw = static_cast(buffer[7]); } } virtual ~header() {} // rate in bits per value double rate() const { return static_cast(bit_rate); } // header data const void* data() const { return buffer; } // header byte size size_t size_bytes(uint mask = ZFP_DATA_HEADER) const { size_t size = 0; if (mask & ZFP_DATA_META) size += sizeof(*this) - byte_size; if (mask & ZFP_DATA_HEADER) size += byte_size; return size; } protected: // magic word static const uint64 magic = UINT64C(0x000000008570667a); // header size measured in bits, bytes, and 64-bit words static const size_t word_size = 8; static const size_t byte_size = word_size * sizeof(uint64); static const size_t bit_size = byte_size * CHAR_BIT; using zfp::array::header::type; using zfp::array::header::nx; using zfp::array::header::ny; using zfp::array::header::nz; using zfp::array::header::nw; size_t bit_rate; // array rate in bits per value uint64 buffer[word_size]; // header data }; zfp-1.0.1/include/zfp/internal/codec/zfpheader.hpp000066400000000000000000000075161453723256400221300ustar00rootroot00000000000000// zfp::codec::zfp_base::header class header : public zfp::array::header { public: // serialization: construct header from array header(const zfp::array& a) : zfp::array::header(a), bit_rate(a.rate()) { std::string error; // set up zfp stream and field for generating header bitstream* stream = stream_open(buffer, sizeof(buffer)); zfp_stream* zfp = zfp_stream_open(stream); bit_rate = zfp_stream_set_rate(zfp, bit_rate, type, dimensionality(), zfp_true); if (zfp_stream_mode(zfp) > ZFP_MODE_SHORT_MAX) error = "zfp serialization supports only short headers"; else { // set up field zfp_field* field = 0; switch (dimensionality()) { case 1: field = zfp_field_1d(0, type, nx); break; case 2: field = zfp_field_2d(0, type, nx, ny); break; case 3: field = zfp_field_3d(0, type, nx, ny, nz); break; case 4: field = zfp_field_4d(0, type, nx, ny, nz, nw); break; default: error = "zfp serialization supports only 1D, 2D, 3D, and 4D arrays"; break; } if (field) { // write header to buffer size_t bits = zfp_write_header(zfp, field, ZFP_HEADER_FULL); if (bits != bit_size) error = "zfp header length does not match expected length"; zfp_stream_flush(zfp); zfp_field_free(field); } } zfp_stream_close(zfp); stream_close(stream); if (!error.empty()) throw zfp::exception(error); } // deserialization: construct header from memory buffer of optional size header(const void* data, size_t bytes = 0) : bit_rate(0) { std::string error; // ensure byte size matches if (bytes && bytes != byte_size) error = "zfp header length does not match expectations"; else { // copy and parse header std::fill(buffer, buffer + word_size, 0); std::memcpy(buffer, data, byte_size); bitstream* stream = stream_open(buffer, sizeof(buffer)); zfp_stream* zfp = zfp_stream_open(stream); zfp_field field; size_t bits = zfp_read_header(zfp, &field, ZFP_HEADER_FULL); if (!bits) error = "zfp header is corrupt"; else if (bits != bit_size) error = "zfp deserialization supports only short headers"; else if (zfp_stream_compression_mode(zfp) != zfp_mode_fixed_rate) error = "zfp deserialization supports only fixed-rate mode"; else { // success; initialize fields type = field.type; nx = field.nx; ny = field.ny; nz = field.nz; nw = field.nw; bit_rate = double(zfp->maxbits) / (1u << (2 * dimensionality())); } zfp_stream_close(zfp); stream_close(stream); } // throw exception upon error if (!error.empty()) throw zfp::exception(error); } virtual ~header() {} // rate in bits per value double rate() const { return bit_rate; } // header data const void* data() const { return buffer; } // header byte size size_t size_bytes(uint mask = ZFP_DATA_HEADER) const { size_t size = 0; if (mask & ZFP_DATA_META) size += sizeof(*this) - byte_size; if (mask & ZFP_DATA_HEADER) size += byte_size; return size; } protected: // header size measured in bits, bytes, and 64-bit words static const size_t bit_size = ZFP_MAGIC_BITS + ZFP_META_BITS + ZFP_MODE_SHORT_BITS; static const size_t byte_size = (bit_size + CHAR_BIT - 1) / CHAR_BIT; static const size_t word_size = (byte_size + sizeof(uint64) - 1) / sizeof(uint64); using zfp::array::header::type; using zfp::array::header::nx; using zfp::array::header::ny; using zfp::array::header::nz; using zfp::array::header::nw; double bit_rate; // array rate in bits per value uint64 buffer[word_size]; // header data }; zfp-1.0.1/include/zfp/internal/zfp/000077500000000000000000000000001453723256400171605ustar00rootroot00000000000000zfp-1.0.1/include/zfp/internal/zfp/inline.h000066400000000000000000000002721453723256400206100ustar00rootroot00000000000000#ifndef ZFP_INLINE_H #define ZFP_INLINE_H #ifndef inline_ #if __STDC_VERSION__ >= 199901L #define inline_ static inline #else #define inline_ static #endif #endif #endif zfp-1.0.1/include/zfp/internal/zfp/macros.h000066400000000000000000000002071453723256400206140ustar00rootroot00000000000000#ifndef ZFP_MACROS_H #define ZFP_MACROS_H #define MIN(x, y) ((x) < (y) ? (x) : (y)) #define MAX(x, y) ((x) > (y) ? (x) : (y)) #endif zfp-1.0.1/include/zfp/internal/zfp/system.h000066400000000000000000000023031453723256400206530ustar00rootroot00000000000000#ifndef ZFP_SYSTEM_H #define ZFP_SYSTEM_H #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99: use restrict */ #define restrict_ restrict #else /* C89: no restrict keyword */ #define restrict_ #endif /* macros for exporting and importing symbols */ #if defined(_MSC_VER) && defined(ZFP_SHARED_LIBS) /* export (import) symbols when ZFP_SOURCE is (is not) defined */ #ifdef ZFP_SOURCE #ifdef __cplusplus #define extern_ extern "C" __declspec(dllexport) #else #define extern_ extern __declspec(dllexport) #endif #else #ifdef __cplusplus #define extern_ extern "C" __declspec(dllimport) #else #define extern_ extern __declspec(dllimport) #endif #endif #else /* !(_MSC_VER && ZFP_SHARED_LIBS) */ #ifdef __cplusplus #define extern_ extern "C" #else #define extern_ extern #endif #endif /* L1 cache line size for alignment purposes */ #ifndef ZFP_CACHE_LINE_SIZE #define ZFP_CACHE_LINE_SIZE 0x100 #endif /* ZFP_CACHE_LINE_SIZE=0 disables alignment */ #if defined(__GNUC__) && ZFP_CACHE_LINE_SIZE #define cache_align_(x) x __attribute__((aligned(ZFP_CACHE_LINE_SIZE))) #else #define cache_align_(x) x #endif #endif zfp-1.0.1/include/zfp/internal/zfp/types.h000066400000000000000000000071651453723256400205060ustar00rootroot00000000000000#ifndef ZFP_TYPES_H #define ZFP_TYPES_H typedef unsigned char uchar; typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long ulong; #if defined(__cplusplus) && __cplusplus >= 201103L /* C++11: use standard integer types */ #include #include #define INT64C(x) INT64_C(x) #define UINT64C(x) UINT64_C(x) #define INT64PRId PRId64 #define INT64PRIi PRIi64 #define UINT64PRIo PRIo64 #define UINT64PRIu PRIu64 #define UINT64PRIx PRIx64 #define INT64SCNd SCNd64 #define INT64SCNi SCNi64 #define UINT64SCNo SCNo64 #define UINT64SCNu SCNu64 #define UINT64SCNx SCNx64 typedef std::int8_t int8; typedef std::uint8_t uint8; typedef std::int16_t int16; typedef std::uint16_t uint16; typedef std::int32_t int32; typedef std::uint32_t uint32; typedef std::int64_t int64; typedef std::uint64_t uint64; #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99: use standard integer types */ #include #include #define INT64C(x) INT64_C(x) #define UINT64C(x) UINT64_C(x) #define INT64PRId PRId64 #define INT64PRIi PRIi64 #define UINT64PRIo PRIo64 #define UINT64PRIu PRIu64 #define UINT64PRIx PRIx64 #define INT64SCNd SCNd64 #define INT64SCNi SCNi64 #define UINT64SCNo SCNo64 #define UINT64SCNu SCNu64 #define UINT64SCNx SCNx64 typedef int8_t int8; typedef uint8_t uint8; typedef int16_t int16; typedef uint16_t uint16; typedef int32_t int32; typedef uint32_t uint32; typedef int64_t int64; typedef uint64_t uint64; #else /* C89: assume common integer types */ typedef signed char int8; typedef unsigned char uint8; typedef signed short int16; typedef unsigned short uint16; /* assume 32-bit integers (LP64, LLP64) */ typedef signed int int32; typedef unsigned int uint32; /* determine 64-bit data model */ #if defined(_WIN32) /* assume ILP32 or LLP64 (MSVC, MinGW) */ #define ZFP_LLP64 1 #else /* assume LP64 (Linux, macOS, ...) */ #define ZFP_LP64 1 #endif /* concatenation for literal suffixes */ #define _zfp_cat_(x, y) x ## y #define _zfp_cat(x, y) _zfp_cat_(x, y) /* signed 64-bit integers */ #if defined(ZFP_INT64) && defined(ZFP_INT64_SUFFIX) #define INT64C(x) _zfp_cat(x, ZFP_INT64_SUFFIX) #define INT64PRId #ZFP_INT64_SUFFIX "d" #define INT64PRIi #ZFP_INT64_SUFFIX "i" typedef ZFP_INT64 int64; #elif ZFP_LP64 #define INT64C(x) x ## l #define INT64PRId "ld" #define INT64PRIi "li" typedef signed long int64; #elif ZFP_LLP64 #define INT64C(x) x ## ll #define INT64PRId "lld" #define INT64PRIi "lli" typedef signed long long int64; #else #error "unknown 64-bit signed integer type" #endif #define INT64SCNd INT64PRId #define INT64SCNi INT64PRIi /* unsigned 64-bit integers */ #if defined(ZFP_UINT64) && defined(ZFP_UINT64_SUFFIX) #define UINT64C(x) _zfp_cat(x, ZFP_UINT64_SUFFIX) #ifdef ZFP_INT64_SUFFIX #define UINT64PRIo #ZFP_INT64_SUFFIX "o" #define UINT64PRIu #ZFP_INT64_SUFFIX "u" #define UINT64PRIx #ZFP_INT64_SUFFIX "x" #endif typedef ZFP_UINT64 uint64; #elif ZFP_LP64 #define UINT64C(x) x ## ul #define UINT64PRIo "lo" #define UINT64PRIu "lu" #define UINT64PRIx "lx" typedef unsigned long uint64; #elif ZFP_LLP64 #define UINT64C(x) x ## ull #define UINT64PRIo "llo" #define UINT64PRIu "llu" #define UINT64PRIx "llx" typedef unsigned long long uint64; #else #error "unknown 64-bit unsigned integer type" #endif #define UINT64SCNo UINT64PRIo #define UINT64SCNu UINT64PRIu #define UINT64SCNx UINT64PRIx #endif #endif zfp-1.0.1/include/zfp/version.h000066400000000000000000000030311453723256400164000ustar00rootroot00000000000000#ifndef ZFP_VERSION_H #define ZFP_VERSION_H /* library version information */ #define ZFP_VERSION_MAJOR 1 /* library major version number */ #define ZFP_VERSION_MINOR 0 /* library minor version number */ #define ZFP_VERSION_PATCH 1 /* library patch version number */ #define ZFP_VERSION_TWEAK 0 /* library tweak version number */ /* codec version number (see also zfp_codec_version) */ #define ZFP_CODEC 5 /* stringification */ #define _zfp_str_(x) # x #define _zfp_str(x) _zfp_str_(x) /* macro for generating an integer version identifier */ #define ZFP_MAKE_VERSION(major, minor, patch, tweak) \ (((major) << 12) + \ ((minor) << 8) + \ ((patch) << 4) + \ ((tweak) << 0)) /* macros for generating a version string */ #define ZFP_MAKE_VERSION_STRING(major, minor, patch) \ _zfp_str(major) "." \ _zfp_str(minor) "." \ _zfp_str(patch) #define ZFP_MAKE_FULLVERSION_STRING(major, minor, patch, tweak) \ _zfp_str(major) "." \ _zfp_str(minor) "." \ _zfp_str(patch) "." \ _zfp_str(tweak) /* library version number (see also zfp_library_version) */ #define ZFP_VERSION \ ZFP_MAKE_VERSION(ZFP_VERSION_MAJOR, ZFP_VERSION_MINOR, ZFP_VERSION_PATCH, ZFP_VERSION_TWEAK) /* library version string (see also zfp_version_string) */ #if ZFP_VERSION_TWEAK == 0 #define ZFP_VERSION_STRING \ ZFP_MAKE_VERSION_STRING(ZFP_VERSION_MAJOR, ZFP_VERSION_MINOR, ZFP_VERSION_PATCH) #else #define ZFP_VERSION_STRING \ ZFP_MAKE_FULLVERSION_STRING(ZFP_VERSION_MAJOR, ZFP_VERSION_MINOR, ZFP_VERSION_PATCH, ZFP_VERSION_TWEAK) #endif #endif zfp-1.0.1/python/000077500000000000000000000000001453723256400136445ustar00rootroot00000000000000zfp-1.0.1/python/CMakeLists.txt000066400000000000000000000022541453723256400164070ustar00rootroot00000000000000if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27.0) cmake_policy(SET CMP0148 OLD) endif () set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/scikit-build-cmake) include(UseCython) include(FindPythonExtensions) include(FindNumPy) find_package(PythonInterp REQUIRED) find_package(PythonLibs REQUIRED) find_package(PythonExtensions REQUIRED) find_package(Cython 0.28 REQUIRED) # >= v0.28 required for const memoryview support find_package(NumPy REQUIRED) include_directories(${ZFP_SOURCE_DIR}/include) include_directories(${NumPy_INCLUDE_DIR}) add_cython_target(zfpy zfpy.pyx C PY3) add_library(zfpy MODULE ${zfpy}) target_link_libraries(zfpy zfp) python_extension_module(zfpy) # Build to the current binary dir to avoid conflicts with other libraries named zfp set(PYLIB_BUILD_DIR "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Directory where zfp python library will be built") set_target_properties(zfpy PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PYLIB_BUILD_DIR}) # Install to the typical python module directory set(python_install_lib_dir "lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/") install(TARGETS zfpy LIBRARY DESTINATION ${python_install_lib_dir}) zfp-1.0.1/python/requirements.txt000066400000000000000000000000321453723256400171230ustar00rootroot00000000000000cython>=0.22 numpy>=1.8.0 zfp-1.0.1/python/scikit-build-cmake/000077500000000000000000000000001453723256400173055ustar00rootroot00000000000000zfp-1.0.1/python/scikit-build-cmake/FindCython.cmake000066400000000000000000000057271453723256400223670ustar00rootroot00000000000000#.rst: # # Find ``cython`` executable. # # This module will set the following variables in your project: # # ``CYTHON_EXECUTABLE`` # path to the ``cython`` program # # ``CYTHON_VERSION`` # version of ``cython`` # # ``CYTHON_FOUND`` # true if the program was found # # For more information on the Cython project, see https://cython.org/. # # *Cython is a language that makes writing C extensions for the Python language # as easy as Python itself.* # #============================================================================= # Copyright 2011 Kitware, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. #============================================================================= # Use the Cython executable that lives next to the Python executable # if it is a local installation. if(Python_EXECUTABLE) get_filename_component(_python_path ${Python_EXECUTABLE} PATH) elseif(Python3_EXECUTABLE) get_filename_component(_python_path ${Python3_EXECUTABLE} PATH) elseif(DEFINED PYTHON_EXECUTABLE) get_filename_component(_python_path ${PYTHON_EXECUTABLE} PATH) endif() if(DEFINED _python_path) find_program(CYTHON_EXECUTABLE NAMES cython cython.bat cython3 HINTS ${_python_path} DOC "path to the cython executable") else() find_program(CYTHON_EXECUTABLE NAMES cython cython.bat cython3 DOC "path to the cython executable") endif() if(CYTHON_EXECUTABLE) set(CYTHON_version_command ${CYTHON_EXECUTABLE} --version) execute_process(COMMAND ${CYTHON_version_command} OUTPUT_VARIABLE CYTHON_version_output ERROR_VARIABLE CYTHON_version_error RESULT_VARIABLE CYTHON_version_result OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE) if(NOT ${CYTHON_version_result} EQUAL 0) set(_error_msg "Command \"${CYTHON_version_command}\" failed with") set(_error_msg "${_error_msg} output:\n${CYTHON_version_error}") message(SEND_ERROR "${_error_msg}") else() if("${CYTHON_version_output}" MATCHES "^[Cc]ython version ([^,]+)") set(CYTHON_VERSION "${CMAKE_MATCH_1}") else() if("${CYTHON_version_error}" MATCHES "^[Cc]ython version ([^,]+)") set(CYTHON_VERSION "${CMAKE_MATCH_1}") endif() endif() endif() endif() include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cython REQUIRED_VARS CYTHON_EXECUTABLE) mark_as_advanced(CYTHON_EXECUTABLE) include(UseCython) zfp-1.0.1/python/scikit-build-cmake/FindNumPy.cmake000066400000000000000000000076131453723256400221670ustar00rootroot00000000000000#.rst: # # Find the include directory for ``numpy/arrayobject.h`` as well as other NumPy tools like ``conv-template`` and # ``from-template``. # # This module sets the following variables: # # ``NumPy_FOUND`` # True if NumPy was found. # ``NumPy_INCLUDE_DIRS`` # The include directories needed to use NumpPy. # ``NumPy_VERSION`` # The version of NumPy found. # ``NumPy_CONV_TEMPLATE_EXECUTABLE`` # Path to conv-template executable. # ``NumPy_FROM_TEMPLATE_EXECUTABLE`` # Path to from-template executable. # # The module will also explicitly define one cache variable: # # ``NumPy_INCLUDE_DIR`` # # .. note:: # # To support NumPy < v0.15.0 where ``from-template`` and ``conv-template`` are not declared as entry points, # the module emulates the behavior of standalone executables by setting the corresponding variables with the # path the the python interpreter and the path to the associated script. For example: # :: # # set(NumPy_CONV_TEMPLATE_EXECUTABLE /path/to/python /path/to/site-packages/numpy/distutils/conv_template.py CACHE STRING "Command executing conv-template program" FORCE) # # set(NumPy_FROM_TEMPLATE_EXECUTABLE /path/to/python /path/to/site-packages/numpy/distutils/from_template.py CACHE STRING "Command executing from-template program" FORCE) # if(NOT NumPy_FOUND) set(_find_extra_args) if(NumPy_FIND_REQUIRED) list(APPEND _find_extra_args REQUIRED) endif() if(NumPy_FIND_QUIET) list(APPEND _find_extra_args QUIET) endif() find_program(NumPy_CONV_TEMPLATE_EXECUTABLE NAMES conv-template) find_program(NumPy_FROM_TEMPLATE_EXECUTABLE NAMES from-template) if(PYTHON_EXECUTABLE) execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import numpy; print(numpy.get_include())" OUTPUT_VARIABLE _numpy_include_dir OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET ) execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import numpy; print(numpy.__version__)" OUTPUT_VARIABLE NumPy_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET ) # XXX This is required to support NumPy < v0.15.0. See note in module documentation above. if(NOT NumPy_CONV_TEMPLATE_EXECUTABLE) execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "from numpy.distutils import conv_template; print(conv_template.__file__)" OUTPUT_VARIABLE _numpy_conv_template_file OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET ) set(NumPy_CONV_TEMPLATE_EXECUTABLE "${PYTHON_EXECUTABLE}" "${_numpy_conv_template_file}" CACHE STRING "Command executing conv-template program" FORCE) endif() # XXX This is required to support NumPy < v0.15.0. See note in module documentation above. if(NOT NumPy_FROM_TEMPLATE_EXECUTABLE) execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "from numpy.distutils import from_template; print(from_template.__file__)" OUTPUT_VARIABLE _numpy_from_template_file OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET ) set(NumPy_FROM_TEMPLATE_EXECUTABLE "${PYTHON_EXECUTABLE}" "${_numpy_from_template_file}" CACHE STRING "Command executing from-template program" FORCE) endif() endif() endif() find_path(NumPy_INCLUDE_DIR numpy/arrayobject.h PATHS "${_numpy_include_dir}" "${PYTHON_INCLUDE_DIR}" PATH_SUFFIXES numpy/core/include ) set(NumPy_INCLUDE_DIRS ${NumPy_INCLUDE_DIR}) # handle the QUIETLY and REQUIRED arguments and set NumPy_FOUND to TRUE if # all listed variables are TRUE include(FindPackageHandleStandardArgs) find_package_handle_standard_args(NumPy REQUIRED_VARS NumPy_INCLUDE_DIR NumPy_CONV_TEMPLATE_EXECUTABLE NumPy_FROM_TEMPLATE_EXECUTABLE VERSION_VAR NumPy_VERSION ) mark_as_advanced(NumPy_INCLUDE_DIR) zfp-1.0.1/python/scikit-build-cmake/FindPythonExtensions.cmake000066400000000000000000000534541453723256400244640ustar00rootroot00000000000000#.rst: # # This module defines CMake functions to build Python extension modules and # stand-alone executables. # # The following variables are defined: # :: # # PYTHON_PREFIX - absolute path to the current Python # distribution's prefix # PYTHON_SITE_PACKAGES_DIR - absolute path to the current Python # distribution's site-packages directory # PYTHON_RELATIVE_SITE_PACKAGES_DIR - path to the current Python # distribution's site-packages directory # relative to its prefix # PYTHON_SEPARATOR - separator string for file path # components. Equivalent to ``os.sep`` in # Python. # PYTHON_PATH_SEPARATOR - separator string for PATH-style # environment variables. Equivalent to # ``os.pathsep`` in Python. # PYTHON_EXTENSION_MODULE_SUFFIX - suffix of the compiled module. For example, on # Linux, based on environment, it could be ``.cpython-35m-x86_64-linux-gnu.so``. # # # # The following functions are defined: # # .. cmake:command:: python_extension_module # # For libraries meant to be used as Python extension modules, either dynamically # loaded or directly linked. Amend the configuration of the library target # (created using ``add_library``) with additional options needed to build and # use the referenced library as a Python extension module. # # python_extension_module( # [LINKED_MODULES_VAR ] # [FORWARD_DECL_MODULES_VAR ] # [MODULE_SUFFIX ]) # # Only extension modules that are configured to be built as MODULE libraries can # be runtime-loaded through the standard Python import mechanism. All other # modules can only be included in standalone applications that are written to # expect their presence. In addition to being linked against the libraries for # these modules, such applications must forward declare their entry points and # initialize them prior to use. To generate these forward declarations and # initializations, see ``python_modules_header``. # # If ```` does not refer to a target, then it is assumed to refer to an # extension module that is not linked at all, but compiled along with other # source files directly into an executable. Adding these modules does not cause # any library configuration modifications, and they are not added to the list of # linked modules. They still must be forward declared and initialized, however, # and so are added to the forward declared modules list. # # If the associated target is of type ``MODULE_LIBRARY``, the LINK_FLAGS target # property is used to set symbol visibility and export only the module init function. # This applies to GNU and MSVC compilers. # # Options: # # ``LINKED_MODULES_VAR `` # Name of the variable referencing a list of extension modules whose libraries # must be linked into the executables of any stand-alone applications that use # them. By default, the global property ``PY_LINKED_MODULES_LIST`` is used. # # ``FORWARD_DECL_MODULES_VAR `` # Name of the variable referencing a list of extension modules whose entry # points must be forward declared and called by any stand-alone applications # that use them. By default, the global property # ``PY_FORWARD_DECL_MODULES_LIST`` is used. # # ``MODULE_SUFFIX `` # Suffix appended to the python extension module file. # The default suffix is retrieved using ``sysconfig.get_config_var("SO")"``, # if not available, the default is then ``.so`` on unix and ``.pyd`` on # windows. # Setting the variable ``PYTHON_EXTENSION_MODULE_SUFFIX`` in the caller # scope defines the value used for all extensions not having a suffix # explicitly specified using ``MODULE_SUFFIX`` parameter. # # # .. cmake:command:: python_standalone_executable # # python_standalone_executable() # # For standalone executables that initialize their own Python runtime # (such as when building source files that include one generated by Cython with # the --embed option). Amend the configuration of the executable target # (created using ``add_executable``) with additional options needed to properly # build the referenced executable. # # # .. cmake:command:: python_modules_header # # Generate a header file that contains the forward declarations and # initialization routines for the given list of Python extension modules. # ```` is the logical name for the header file (no file extensions). # ```` is the actual destination filename for the header file # (e.g.: decl_modules.h). # # python_modules_header( [HeaderFilename] # [FORWARD_DECL_MODULES_LIST ] # [HEADER_OUTPUT_VAR ] # [INCLUDE_DIR_OUTPUT_VAR ]) # # without the extension is used as the logical name. If only ```` is # # If only ```` is provided, and it ends in the ".h" extension, then it # is assumed to be the ````. The filename of the header file # provided, and it does not end in the ".h" extension, then the # ```` is assumed to ``.h``. # # The exact contents of the generated header file depend on the logical # ````. It should be set to a value that corresponds to the target # application, or for the case of multiple applications, some identifier that # conveyes its purpose. It is featured in the generated multiple inclusion # guard as well as the names of the generated initialization routines. # # The generated header file includes forward declarations for all listed # modules, as well as implementations for the following class of routines: # # ``int _(void)`` # Initializes the python extension module, ````. Returns an integer # handle to the module. # # ``void _LoadAllPythonModules(void)`` # Initializes all listed python extension modules. # # ``void CMakeLoadAllPythonModules(void);`` # Alias for ``_LoadAllPythonModules`` whose name does not depend on # ````. This function is excluded during preprocessing if the # preprocessing macro ``EXCLUDE_LOAD_ALL_FUNCTION`` is defined. # # ``void Py_Initialize_Wrapper();`` # Wrapper arpund ``Py_Initialize()`` that initializes all listed python # extension modules. This function is excluded during preprocessing if the # preprocessing macro ``EXCLUDE_PY_INIT_WRAPPER`` is defined. If this # function is generated, then ``Py_Initialize()`` is redefined to a macro # that calls this function. # # Options: # # ``FORWARD_DECL_MODULES_LIST `` # List of extension modules for which to generate forward declarations of # their entry points and their initializations. By default, the global # property ``PY_FORWARD_DECL_MODULES_LIST`` is used. # # ``HEADER_OUTPUT_VAR `` # Name of the variable to set to the path to the generated header file. By # default, ```` is used. # # ``INCLUDE_DIR_OUTPUT_VAR `` # Name of the variable to set to the path to the directory containing the # generated header file. By default, ``_INCLUDE_DIRS`` is used. # # Defined variables: # # ```` # The path to the generated header file # # ```` # Directory containing the generated header file # # # Example usage # ^^^^^^^^^^^^^ # # .. code-block:: cmake # # find_package(PythonExtensions) # find_package(Cython) # find_package(Boost COMPONENTS python) # # # Simple Cython Module -- no executables # add_cython_target(_module.pyx) # add_library(_module MODULE ${_module}) # python_extension_module(_module) # # # Mix of Cython-generated code and C++ code using Boost Python # # Stand-alone executable -- no modules # include_directories(${Boost_INCLUDE_DIRS}) # add_cython_target(main.pyx CXX EMBED_MAIN) # add_executable(main boost_python_module.cxx ${main}) # target_link_libraries(main ${Boost_LIBRARIES}) # python_standalone_executable(main) # # # stand-alone executable with three extension modules: # # one statically linked, one dynamically linked, and one loaded at runtime # # # # Freely mixes Cython-generated code, code using Boost-Python, and # # hand-written code using the CPython API. # # # module1 -- statically linked # add_cython_target(module1.pyx) # add_library(module1 STATIC ${module1}) # python_extension_module(module1 # LINKED_MODULES_VAR linked_module_list # FORWARD_DECL_MODULES_VAR fdecl_module_list) # # # module2 -- dynamically linked # include_directories(${Boost_INCLUDE_DIRS}) # add_library(module2 SHARED boost_module2.cxx) # target_link_libraries(module2 ${Boost_LIBRARIES}) # python_extension_module(module2 # LINKED_MODULES_VAR linked_module_list # FORWARD_DECL_MODULES_VAR fdecl_module_list) # # # module3 -- loaded at runtime # add_cython_target(module3a.pyx) # add_library(module3 MODULE ${module3a} module3b.cxx) # target_link_libraries(module3 ${Boost_LIBRARIES}) # python_extension_module(module3 # LINKED_MODULES_VAR linked_module_list # FORWARD_DECL_MODULES_VAR fdecl_module_list) # # # application executable -- generated header file + other source files # python_modules_header(modules # FORWARD_DECL_MODULES_LIST ${fdecl_module_list}) # include_directories(${modules_INCLUDE_DIRS}) # # add_cython_target(mainA) # add_cython_target(mainC) # add_executable(main ${mainA} mainB.cxx ${mainC} mainD.c) # # target_link_libraries(main ${linked_module_list} ${Boost_LIBRARIES}) # python_standalone_executable(main) # #============================================================================= # Copyright 2011 Kitware, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. #============================================================================= find_package(PythonInterp REQUIRED) if(SKBUILD AND NOT PYTHON_LIBRARY) set(PYTHON_LIBRARY "no-library-required") find_package(PythonLibs) unset(PYTHON_LIBRARY) unset(PYTHON_LIBRARIES) else() find_package(PythonLibs) endif() include(targetLinkLibrariesWithDynamicLookup) set(_command " import distutils.sysconfig import itertools import os import os.path import site import sys result = None rel_result = None candidate_lists = [] try: candidate_lists.append((distutils.sysconfig.get_python_lib(),)) except AttributeError: pass try: candidate_lists.append(site.getsitepackages()) except AttributeError: pass try: candidate_lists.append((site.getusersitepackages(),)) except AttributeError: pass candidates = itertools.chain.from_iterable(candidate_lists) for candidate in candidates: rel_candidate = os.path.relpath( candidate, sys.prefix) if not rel_candidate.startswith(\"..\"): result = candidate rel_result = rel_candidate break sys.stdout.write(\";\".join(( os.sep, os.pathsep, sys.prefix, result, rel_result, distutils.sysconfig.get_config_var('EXT_SUFFIX') ))) ") execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "${_command}" OUTPUT_VARIABLE _list RESULT_VARIABLE _result) list(GET _list 0 _item) set(PYTHON_SEPARATOR "${_item}") mark_as_advanced(PYTHON_SEPARATOR) list(GET _list 1 _item) set(PYTHON_PATH_SEPARATOR "${_item}") mark_as_advanced(PYTHON_PATH_SEPARATOR) list(GET _list 2 _item) set(PYTHON_PREFIX "${_item}") mark_as_advanced(PYTHON_PREFIX) list(GET _list 3 _item) set(PYTHON_SITE_PACKAGES_DIR "${_item}") mark_as_advanced(PYTHON_SITE_PACKAGES_DIR) list(GET _list 4 _item) set(PYTHON_RELATIVE_SITE_PACKAGES_DIR "${_item}") mark_as_advanced(PYTHON_RELATIVE_SITE_PACKAGES_DIR) if(NOT DEFINED PYTHON_EXTENSION_MODULE_SUFFIX) list(GET _list 5 _item) set(PYTHON_EXTENSION_MODULE_SUFFIX "${_item}") endif() function(_set_python_extension_symbol_visibility _target) if(PYTHON_VERSION_MAJOR VERSION_GREATER 2) set(_modinit_prefix "PyInit_") else() set(_modinit_prefix "init") endif() message("_modinit_prefix:${_modinit_prefix}") if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") set_target_properties(${_target} PROPERTIES LINK_FLAGS "/EXPORT:${_modinit_prefix}${_target}" ) elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # Option to not run version script. See https://github.com/scikit-build/scikit-build/issues/668 if(NOT DEFINED SKBUILD_GNU_SKIP_LOCAL_SYMBOL_EXPORT_OVERRIDE) set(SKBUILD_GNU_SKIP_LOCAL_SYMBOL_EXPORT_OVERRIDE FALSE) endif() set(_script_path ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_target}-version-script.map ) # Export all symbols. See https://github.com/scikit-build/scikit-build/issues/668 if(SKBUILD_GNU_SKIP_LOCAL_SYMBOL_EXPORT_OVERRIDE) file(WRITE ${_script_path} "{global: ${_modinit_prefix}${_target};};" ) else() file(WRITE ${_script_path} "{global: ${_modinit_prefix}${_target}; local: *;};" ) endif() if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS") set_property(TARGET ${_target} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--version-script=\"${_script_path}\"" ) else() set_property(TARGET ${_target} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-M \"${_script_path}\"" ) endif() endif() endfunction() function(python_extension_module _target) set(one_ops LINKED_MODULES_VAR FORWARD_DECL_MODULES_VAR MODULE_SUFFIX) cmake_parse_arguments(_args "" "${one_ops}" "" ${ARGN}) set(_lib_type "NA") if(TARGET ${_target}) get_property(_lib_type TARGET ${_target} PROPERTY TYPE) endif() set(_is_non_lib TRUE) set(_is_static_lib FALSE) if(_lib_type STREQUAL "STATIC_LIBRARY") set(_is_static_lib TRUE) set(_is_non_lib FALSE) endif() set(_is_shared_lib FALSE) if(_lib_type STREQUAL "SHARED_LIBRARY") set(_is_shared_lib TRUE) set(_is_non_lib FALSE) endif() set(_is_module_lib FALSE) if(_lib_type STREQUAL "MODULE_LIBRARY") set(_is_module_lib TRUE) set(_is_non_lib FALSE) endif() if(_is_static_lib OR _is_shared_lib OR _is_non_lib) if(_is_static_lib OR _is_shared_lib) if(_args_LINKED_MODULES_VAR) set(${_args_LINKED_MODULES_VAR} ${${_args_LINKED_MODULES_VAR}} ${_target} PARENT_SCOPE) else() set_property(GLOBAL APPEND PROPERTY PY_LINKED_MODULES_LIST ${_target}) endif() endif() if(_args_FORWARD_DECL_MODULES_VAR) set(${_args_FORWARD_DECL_MODULES_VAR} ${${_args_FORWARD_DECL_MODULES_VAR}} ${_target} PARENT_SCOPE) else() set_property(GLOBAL APPEND PROPERTY PY_FORWARD_DECL_MODULES_LIST ${_target}) endif() endif() if(NOT _is_non_lib) include_directories("${PYTHON_INCLUDE_DIRS}") endif() if(_is_module_lib) set_target_properties(${_target} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}") endif() if(_is_module_lib OR _is_shared_lib) if(_is_module_lib) if(NOT _args_MODULE_SUFFIX) set(_args_MODULE_SUFFIX "${PYTHON_EXTENSION_MODULE_SUFFIX}") endif() if(_args_MODULE_SUFFIX STREQUAL "" AND WIN32 AND NOT CYGWIN) set(_args_MODULE_SUFFIX ".pyd") endif() if(NOT _args_MODULE_SUFFIX STREQUAL "") set_target_properties(${_target} PROPERTIES SUFFIX ${_args_MODULE_SUFFIX}) endif() endif() target_link_libraries_with_dynamic_lookup(${_target} ${PYTHON_LIBRARIES}) if(_is_module_lib) _set_python_extension_symbol_visibility(${_target}) endif() endif() endfunction() function(python_standalone_executable _target) include_directories(${PYTHON_INCLUDE_DIRS}) target_link_libraries(${_target} ${SKBUILD_LINK_LIBRARIES_KEYWORD} ${PYTHON_LIBRARIES}) endfunction() function(python_modules_header _name) set(one_ops FORWARD_DECL_MODULES_LIST HEADER_OUTPUT_VAR INCLUDE_DIR_OUTPUT_VAR) cmake_parse_arguments(_args "" "${one_ops}" "" ${ARGN}) list(GET _args_UNPARSED_ARGUMENTS 0 _arg0) # if present, use arg0 as the input file path if(_arg0) set(_source_file ${_arg0}) # otherwise, must determine source file from name, or vice versa else() get_filename_component(_name_ext "${_name}" EXT) # if extension provided, _name is the source file if(_name_ext) set(_source_file ${_name}) get_filename_component(_name "${_source_file}" NAME_WE) # otherwise, assume the source file is ${_name}.h else() set(_source_file ${_name}.h) endif() endif() if(_args_FORWARD_DECL_MODULES_LIST) set(static_mod_list ${_args_FORWARD_DECL_MODULES_LIST}) else() get_property(static_mod_list GLOBAL PROPERTY PY_FORWARD_DECL_MODULES_LIST) endif() string(REPLACE "." "_" _header_name "${_name}") string(TOUPPER ${_header_name} _header_name_upper) set(_header_name_upper "_${_header_name_upper}_H") set(generated_file ${CMAKE_CURRENT_BINARY_DIR}/${_source_file}) set(generated_file_tmp "${generated_file}.in") file(WRITE ${generated_file_tmp} "/* Created by CMake. DO NOT EDIT; changes will be lost. */\n") set(_chunk "") set(_chunk "${_chunk}#ifndef ${_header_name_upper}\n") set(_chunk "${_chunk}#define ${_header_name_upper}\n") set(_chunk "${_chunk}\n") set(_chunk "${_chunk}#include \n") set(_chunk "${_chunk}\n") set(_chunk "${_chunk}#ifdef __cplusplus\n") set(_chunk "${_chunk}extern \"C\" {\n") set(_chunk "${_chunk}#endif /* __cplusplus */\n") set(_chunk "${_chunk}\n") set(_chunk "${_chunk}#if PY_MAJOR_VERSION < 3\n") file(APPEND ${generated_file_tmp} "${_chunk}") foreach(_module ${static_mod_list}) file(APPEND ${generated_file_tmp} "PyMODINIT_FUNC init${PYTHON_MODULE_PREFIX}${_module}(void);\n") endforeach() file(APPEND ${generated_file_tmp} "#else /* PY_MAJOR_VERSION >= 3*/\n") foreach(_module ${static_mod_list}) file(APPEND ${generated_file_tmp} "PyMODINIT_FUNC PyInit_${PYTHON_MODULE_PREFIX}${_module}(void);\n") endforeach() set(_chunk "") set(_chunk "${_chunk}#endif /* PY_MAJOR_VERSION >= 3*/\n\n") set(_chunk "${_chunk}#ifdef __cplusplus\n") set(_chunk "${_chunk}}\n") set(_chunk "${_chunk}#endif /* __cplusplus */\n") set(_chunk "${_chunk}\n") file(APPEND ${generated_file_tmp} "${_chunk}") foreach(_module ${static_mod_list}) set(_import_function "${_header_name}_${_module}") set(_prefixed_module "${PYTHON_MODULE_PREFIX}${_module}") set(_chunk "") set(_chunk "${_chunk}int ${_import_function}(void)\n") set(_chunk "${_chunk}{\n") set(_chunk "${_chunk} static char name[] = \"${_prefixed_module}\";\n") set(_chunk "${_chunk} #if PY_MAJOR_VERSION < 3\n") set(_chunk "${_chunk} return PyImport_AppendInittab(") set(_chunk "${_chunk}name, init${_prefixed_module});\n") set(_chunk "${_chunk} #else /* PY_MAJOR_VERSION >= 3 */\n") set(_chunk "${_chunk} return PyImport_AppendInittab(") set(_chunk "${_chunk}name, PyInit_${_prefixed_module});\n") set(_chunk "${_chunk} #endif /* PY_MAJOR_VERSION >= 3 */\n") set(_chunk "${_chunk}}\n\n") file(APPEND ${generated_file_tmp} "${_chunk}") endforeach() file(APPEND ${generated_file_tmp} "void ${_header_name}_LoadAllPythonModules(void)\n{\n") foreach(_module ${static_mod_list}) file(APPEND ${generated_file_tmp} " ${_header_name}_${_module}();\n") endforeach() file(APPEND ${generated_file_tmp} "}\n\n") set(_chunk "") set(_chunk "${_chunk}#ifndef EXCLUDE_LOAD_ALL_FUNCTION\n") set(_chunk "${_chunk}void CMakeLoadAllPythonModules(void)\n") set(_chunk "${_chunk}{\n") set(_chunk "${_chunk} ${_header_name}_LoadAllPythonModules();\n") set(_chunk "${_chunk}}\n") set(_chunk "${_chunk}#endif /* !EXCLUDE_LOAD_ALL_FUNCTION */\n\n") set(_chunk "${_chunk}#ifndef EXCLUDE_PY_INIT_WRAPPER\n") set(_chunk "${_chunk}static void Py_Initialize_Wrapper()\n") set(_chunk "${_chunk}{\n") set(_chunk "${_chunk} ${_header_name}_LoadAllPythonModules();\n") set(_chunk "${_chunk} Py_Initialize();\n") set(_chunk "${_chunk}}\n") set(_chunk "${_chunk}#define Py_Initialize Py_Initialize_Wrapper\n") set(_chunk "${_chunk}#endif /* !EXCLUDE_PY_INIT_WRAPPER */\n\n") set(_chunk "${_chunk}#endif /* !${_header_name_upper} */\n") file(APPEND ${generated_file_tmp} "${_chunk}") # with configure_file() cmake complains that you may not use a file created # using file(WRITE) as input file for configure_file() execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${generated_file_tmp}" "${generated_file}" OUTPUT_QUIET ERROR_QUIET) set(_header_output_var ${_name}) if(_args_HEADER_OUTPUT_VAR) set(_header_output_var ${_args_HEADER_OUTPUT_VAR}) endif() set(${_header_output_var} ${generated_file} PARENT_SCOPE) set(_include_dir_var ${_name}_INCLUDE_DIRS) if(_args_INCLUDE_DIR_OUTPUT_VAR) set(_include_dir_var ${_args_INCLUDE_DIR_OUTPUT_VAR}) endif() set(${_include_dirs_var} ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE) endfunction() include(UsePythonExtensions) zfp-1.0.1/python/scikit-build-cmake/LICENSE000066400000000000000000000053141453723256400203150ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014 Mike Sarahan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. This project borrows a great deal from the setup tools of the PyNE project. Here is its license: Copyright 2011-2014, the PyNE Development Team. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE PYNE DEVELOPMENT TEAM ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the stakeholders of the PyNE project or the employers of PyNE developers. zfp-1.0.1/python/scikit-build-cmake/UseCython.cmake000066400000000000000000000320531453723256400222330ustar00rootroot00000000000000#.rst: # # The following functions are defined: # # .. cmake:command:: add_cython_target # # Create a custom rule to generate the source code for a Python extension module # using cython. # # add_cython_target( [] # [EMBED_MAIN] # [C | CXX] # [PY2 | PY3] # [OUTPUT_VAR ]) # # ```` is the name of the new target, and ```` # is the path to a cython source file. Note that, despite the name, no new # targets are created by this function. Instead, see ``OUTPUT_VAR`` for # retrieving the path to the generated source for subsequent targets. # # If only ```` is provided, and it ends in the ".pyx" extension, then it # is assumed to be the ````. The name of the input without the # extension is used as the target name. If only ```` is provided, and it # does not end in the ".pyx" extension, then the ```` is assumed to # be ``.pyx``. # # The Cython include search path is amended with any entries found in the # ``INCLUDE_DIRECTORIES`` property of the directory containing the # ```` file. Use ``include_directories`` to add to the Cython # include search path. # # Options: # # ``EMBED_MAIN`` # Embed a main() function in the generated output (for stand-alone # applications that initialize their own Python runtime). # # ``C | CXX`` # Force the generation of either a C or C++ file. By default, a C file is # generated, unless the C language is not enabled for the project; in this # case, a C++ file is generated by default. # # ``PY2 | PY3`` # Force compilation using either Python-2 or Python-3 syntax and code # semantics. By default, Python-2 syntax and semantics are used if the major # version of Python found is 2. Otherwise, Python-3 syntax and semantics are # used. # # ``OUTPUT_VAR `` # Set the variable ```` in the parent scope to the path to the # generated source file. By default, ```` is used as the output # variable name. # # Defined variables: # # ```` # The path of the generated source file. # # Cache variables that affect the behavior include: # # ``CYTHON_ANNOTATE`` # Whether to create an annotated .html file when compiling. # # ``CYTHON_FLAGS`` # Additional flags to pass to the Cython compiler. # # Example usage # ^^^^^^^^^^^^^ # # .. code-block:: cmake # # find_package(Cython) # # # Note: In this case, either one of these arguments may be omitted; their # # value would have been inferred from that of the other. # add_cython_target(cy_code cy_code.pyx) # # add_library(cy_code MODULE ${cy_code}) # target_link_libraries(cy_code ...) # #============================================================================= # Copyright 2011 Kitware, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. #============================================================================= # Configuration options. set(CYTHON_ANNOTATE OFF CACHE BOOL "Create an annotated .html file when compiling *.pyx.") set(CYTHON_FLAGS "" CACHE STRING "Extra flags to the cython compiler.") mark_as_advanced(CYTHON_ANNOTATE CYTHON_FLAGS) set(CYTHON_CXX_EXTENSION "cxx") set(CYTHON_C_EXTENSION "c") get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) function(add_cython_target _name) set(options EMBED_MAIN C CXX PY2 PY3) set(options1 OUTPUT_VAR) cmake_parse_arguments(_args "${options}" "${options1}" "" ${ARGN}) list(GET _args_UNPARSED_ARGUMENTS 0 _arg0) # if provided, use _arg0 as the input file path if(_arg0) set(_source_file ${_arg0}) # otherwise, must determine source file from name, or vice versa else() get_filename_component(_name_ext "${_name}" EXT) # if extension provided, _name is the source file if(_name_ext) set(_source_file ${_name}) get_filename_component(_name "${_source_file}" NAME_WE) # otherwise, assume the source file is ${_name}.pyx else() set(_source_file ${_name}.pyx) endif() endif() set(_embed_main FALSE) if("C" IN_LIST languages) set(_output_syntax "C") elseif("CXX" IN_LIST languages) set(_output_syntax "CXX") else() message(FATAL_ERROR "Either C or CXX must be enabled to use Cython") endif() if(_args_EMBED_MAIN) set(_embed_main TRUE) endif() if(_args_C) set(_output_syntax "C") endif() if(_args_CXX) set(_output_syntax "CXX") endif() # Doesn't select an input syntax - Cython # defaults to 2 for Cython 2 and 3 for Cython 3 set(_input_syntax "default") if(_args_PY2) set(_input_syntax "PY2") endif() if(_args_PY3) set(_input_syntax "PY3") endif() set(embed_arg "") if(_embed_main) set(embed_arg "--embed") endif() set(cxx_arg "") set(extension "c") if(_output_syntax STREQUAL "CXX") set(cxx_arg "--cplus") set(extension "cxx") endif() set(py_version_arg "") if(_input_syntax STREQUAL "PY2") set(py_version_arg "-2") elseif(_input_syntax STREQUAL "PY3") set(py_version_arg "-3") endif() set(generated_file "${CMAKE_CURRENT_BINARY_DIR}/${_name}.${extension}") set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE) set(_output_var ${_name}) if(_args_OUTPUT_VAR) set(_output_var ${_args_OUTPUT_VAR}) endif() set(${_output_var} ${generated_file} PARENT_SCOPE) file(RELATIVE_PATH generated_file_relative ${CMAKE_BINARY_DIR} ${generated_file}) set(comment "Generating ${_output_syntax} source ${generated_file_relative}") set(cython_include_directories "") set(pxd_dependencies "") set(c_header_dependencies "") # Get the include directories. get_directory_property(cmake_include_directories DIRECTORY ${CMAKE_CURRENT_LIST_DIR} INCLUDE_DIRECTORIES) list(APPEND cython_include_directories ${cmake_include_directories}) # Determine dependencies. # Add the pxd file with the same basename as the given pyx file. get_source_file_property(pyx_location ${_source_file} LOCATION) get_filename_component(pyx_path ${pyx_location} PATH) get_filename_component(pyx_file_basename ${_source_file} NAME_WE) unset(corresponding_pxd_file CACHE) find_file(corresponding_pxd_file ${pyx_file_basename}.pxd PATHS "${pyx_path}" ${cmake_include_directories} NO_DEFAULT_PATH) if(corresponding_pxd_file) list(APPEND pxd_dependencies "${corresponding_pxd_file}") endif() # pxd files to check for additional dependencies set(pxds_to_check "${_source_file}" "${pxd_dependencies}") set(pxds_checked "") set(number_pxds_to_check 1) while(number_pxds_to_check GREATER 0) foreach(pxd ${pxds_to_check}) list(APPEND pxds_checked "${pxd}") list(REMOVE_ITEM pxds_to_check "${pxd}") # look for C headers file(STRINGS "${pxd}" extern_from_statements REGEX "cdef[ ]+extern[ ]+from.*$") foreach(statement ${extern_from_statements}) # Had trouble getting the quote in the regex string(REGEX REPLACE "cdef[ ]+extern[ ]+from[ ]+[\"]([^\"]+)[\"].*" "\\1" header "${statement}") unset(header_location CACHE) find_file(header_location ${header} PATHS ${cmake_include_directories}) if(header_location) list(FIND c_header_dependencies "${header_location}" header_idx) if(${header_idx} LESS 0) list(APPEND c_header_dependencies "${header_location}") endif() endif() endforeach() # check for pxd dependencies # Look for cimport statements. set(module_dependencies "") file(STRINGS "${pxd}" cimport_statements REGEX cimport) foreach(statement ${cimport_statements}) if(${statement} MATCHES from) string(REGEX REPLACE "from[ ]+([^ ]+).*" "\\1" module "${statement}") else() string(REGEX REPLACE "cimport[ ]+([^ ]+).*" "\\1" module "${statement}") endif() list(APPEND module_dependencies ${module}) endforeach() # check for pxi dependencies # Look for include statements. set(include_dependencies "") file(STRINGS "${pxd}" include_statements REGEX include) foreach(statement ${include_statements}) string(REGEX REPLACE "include[ ]+[\"]([^\"]+)[\"].*" "\\1" module "${statement}") list(APPEND include_dependencies ${module}) endforeach() list(REMOVE_DUPLICATES module_dependencies) list(REMOVE_DUPLICATES include_dependencies) # Add modules to the files to check, if appropriate. foreach(module ${module_dependencies}) unset(pxd_location CACHE) find_file(pxd_location ${module}.pxd PATHS "${pyx_path}" ${cmake_include_directories} NO_DEFAULT_PATH) if(pxd_location) list(FIND pxds_checked ${pxd_location} pxd_idx) if(${pxd_idx} LESS 0) list(FIND pxds_to_check ${pxd_location} pxd_idx) if(${pxd_idx} LESS 0) list(APPEND pxds_to_check ${pxd_location}) list(APPEND pxd_dependencies ${pxd_location}) endif() # if it is not already going to be checked endif() # if it has not already been checked endif() # if pxd file can be found endforeach() # for each module dependency discovered # Add includes to the files to check, if appropriate. foreach(_include ${include_dependencies}) unset(pxi_location CACHE) find_file(pxi_location ${_include} PATHS "${pyx_path}" ${cmake_include_directories} NO_DEFAULT_PATH) if(pxi_location) list(FIND pxds_checked ${pxi_location} pxd_idx) if(${pxd_idx} LESS 0) list(FIND pxds_to_check ${pxi_location} pxd_idx) if(${pxd_idx} LESS 0) list(APPEND pxds_to_check ${pxi_location}) list(APPEND pxd_dependencies ${pxi_location}) endif() # if it is not already going to be checked endif() # if it has not already been checked endif() # if include file can be found endforeach() # for each include dependency discovered endforeach() # for each include file to check list(LENGTH pxds_to_check number_pxds_to_check) endwhile() # Set additional flags. set(annotate_arg "") if(CYTHON_ANNOTATE) set(annotate_arg "--annotate") endif() set(cython_debug_arg "") set(line_directives_arg "") if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") set(cython_debug_arg "--gdb") set(line_directives_arg "--line-directives") endif() # Include directory arguments. list(REMOVE_DUPLICATES cython_include_directories) set(include_directory_arg "") foreach(_include_dir ${cython_include_directories}) set(include_directory_arg ${include_directory_arg} "--include-dir" "${_include_dir}") endforeach() list(REMOVE_DUPLICATES pxd_dependencies) list(REMOVE_DUPLICATES c_header_dependencies) string(REGEX REPLACE " " ";" CYTHON_FLAGS_LIST "${CYTHON_FLAGS}") # Add the command to run the compiler. add_custom_command(OUTPUT ${generated_file} COMMAND ${CYTHON_EXECUTABLE} ARGS ${cxx_arg} ${include_directory_arg} ${py_version_arg} ${embed_arg} ${annotate_arg} ${cython_debug_arg} ${line_directives_arg} ${CYTHON_FLAGS_LIST} ${pyx_location} --output-file ${generated_file} DEPENDS ${_source_file} ${pxd_dependencies} IMPLICIT_DEPENDS ${_output_syntax} ${c_header_dependencies} COMMENT ${comment}) # NOTE(opadron): I thought about making a proper target, but after trying it # out, I decided that it would be far too convenient to use the same name as # the target for the extension module (e.g.: for single-file modules): # # ... # add_cython_target(_module.pyx) # add_library(_module ${_module}) # ... # # The above example would not be possible since the "_module" target name # would already be taken by the cython target. Since I can't think of a # reason why someone would need the custom target instead of just using the # generated file directly, I decided to leave this commented out. # # add_custom_target(${_name} DEPENDS ${generated_file}) # Remove their visibility to the user. set(corresponding_pxd_file "" CACHE INTERNAL "") set(header_location "" CACHE INTERNAL "") set(pxd_location "" CACHE INTERNAL "") endfunction() zfp-1.0.1/python/scikit-build-cmake/UsePythonExtensions.cmake000066400000000000000000000241551453723256400243340ustar00rootroot00000000000000#.rst: # # The following functions are defined: # # .. cmake:command:: add_python_library # # Add a library that contains a mix of C, C++, Fortran, Cython, F2PY, Template, # and Tempita sources. The required targets are automatically generated to # "lower" source files from their high-level representation to a file that the # compiler can accept. # # # add_python_library( # SOURCES [source1 [source2 ...]] # [INCLUDE_DIRECTORIES [dir1 [dir2 ...]] # [LINK_LIBRARIES [lib1 [lib2 ...]] # [DEPENDS [source1 [source2 ...]]]) # # # Example usage # ^^^^^^^^^^^^^ # # .. code-block:: cmake # # find_package(PythonExtensions) # # file(GLOB arpack_sources ARPACK/SRC/*.f ARPACK/UTIL/*.f) # # add_python_library(arpack_scipy # SOURCES ${arpack_sources} # ${g77_wrapper_sources} # INCLUDE_DIRECTORIES ARPACK/SRC # ) # # .. cmake:command:: add_python_extension # # Add a extension that contains a mix of C, C++, Fortran, Cython, F2PY, Template, # and Tempita sources. The required targets are automatically generated to # "lower" source files from their high-level representation to a file that the # compiler can accept. # # # add_python_extension( # SOURCES [source1 [source2 ...]] # [INCLUDE_DIRECTORIES [dir1 [dir2 ...]] # [LINK_LIBRARIES [lib1 [lib2 ...]] # [DEPENDS [source1 [source2 ...]]]) # # # Example usage # ^^^^^^^^^^^^^ # # .. code-block:: cmake # # find_package(PythonExtensions) # # file(GLOB arpack_sources ARPACK/SRC/*.f ARPACK/UTIL/*.f) # # add_python_extension(arpack_scipy # SOURCES ${arpack_sources} # ${g77_wrapper_sources} # INCLUDE_DIRECTORIES ARPACK/SRC # ) # # #============================================================================= # Copyright 2011 Kitware, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. #============================================================================= macro(_remove_whitespace _output) string(REGEX REPLACE "[ \r\n\t]+" " " ${_output} "${${_output}}") string(STRIP "${${_output}}" ${_output}) endmacro() function(add_python_library _name) set(options STATIC SHARED MODULE) set(multiValueArgs SOURCES INCLUDE_DIRECTORIES LINK_LIBRARIES COMPILE_DEFINITIONS DEPENDS) cmake_parse_arguments(_args "${options}" "" "${multiValueArgs}" ${ARGN} ) # Validate arguments to allow simpler debugging if(NOT _args_SOURCES) message( FATAL_ERROR "You have called add_python_library for library ${_name} without " "any source files. This typically indicates a problem with " "your CMakeLists.txt file" ) endif() # Initialize the list of sources set(_sources ${_args_SOURCES}) # Generate targets for all *.src files set(_processed ) foreach(_source IN LISTS _sources) if(${_source} MATCHES ".pyf.src$" OR ${_source} MATCHES "\\.f\\.src$") if(NOT NumPy_FOUND) message( FATAL_ERROR "NumPy is required to process *.src Template files" ) endif() string(REGEX REPLACE "\\.[^.]*$" "" _source_we ${_source}) add_custom_command( OUTPUT ${_source_we} COMMAND ${NumPy_FROM_TEMPLATE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${_source} ${CMAKE_CURRENT_BINARY_DIR}/${_source_we} DEPENDS ${_source} ${_args_DEPENDS} COMMENT "Generating ${_source_we} from template ${_source}" ) list(APPEND _processed ${_source_we}) elseif(${_source} MATCHES "\\.c\\.src$") if(NOT NumPy_FOUND) message( FATAL_ERROR "NumPy is required to process *.src Template files" ) endif() string(REGEX REPLACE "\\.[^.]*$" "" _source_we ${_source}) add_custom_command( OUTPUT ${_source_we} COMMAND ${NumPy_CONV_TEMPLATE_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${_source} ${CMAKE_CURRENT_BINARY_DIR}/${_source_we} DEPENDS ${_source} ${_args_DEPENDS} COMMENT "Generating ${_source_we} from template ${_source}" ) list(APPEND _processed ${_source_we}) elseif(${_source} MATCHES "\\.pyx\\.in$") if(NOT Cython_FOUND) message( FATAL_ERROR "Cython is required to process *.in Tempita files" ) endif() string(REGEX REPLACE "\\.[^.]*$" "" _source_we ${_source}) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/${_source} ${CMAKE_CURRENT_BINARY_DIR}/${_source} COPYONLY ) set(_tempita_command " import os; import sys; from Cython.Tempita import Template; cwd = os.getcwd(); open(os.path.join(cwd, '${_source_we}'), 'w+') .write( Template.from_filename(os.path.join(cwd, '${_source}'), encoding=sys.getdefaultencoding()).substitute() ) " ) _remove_whitespace(_tempita_command) add_custom_command( OUTPUT ${_source_we} COMMAND ${PYTHON_EXECUTABLE} -c "${_tempita_command}" DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_source}" ${_args_DEPENDS} ) list(APPEND _processed ${_source_we}) else() list(APPEND _processed ${_source}) endif() endforeach() set(_sources ${_processed}) # If we're building a Python extension and we're given only Fortran sources, # We can conclude that we need to generate a Fortran interface file list(FILTER _processed EXCLUDE REGEX "(\\.f|\\.f90)$") if(NOT _processed AND _args_MODULE) if(NOT NumPy_FOUND) message( FATAL_ERROR "NumPy is required to process *.pyf F2PY files" ) endif() set(_sources_abs ) foreach(_source IN LISTS _sources) if(NOT IS_ABSOLUTE ${_source}) set(_source ${CMAKE_CURRENT_SOURCE_DIR}/${_source}) endif() list(APPEND _sources_abs ${_source}) endforeach() add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name}.pyf WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${F2PY_EXECUTABLE} ARGS -h ${_name}.pyf -m ${_name} --overwrite-signature ${_sources_abs} DEPENDS ${_sources} ${_args_DEPENDS} COMMENT "Generating ${_name} Fortran interface file" ) list(APPEND _sources ${_name}.pyf) endif() # Are there F2PY targets? set(_has_f2py_targets OFF) set(_has_cython_targets OFF) # Generate targets for all *.pyx and *.pyf files set(_processed ) foreach(_source IN LISTS _sources) if(${_source} MATCHES \\.pyx$) if(NOT Cython_FOUND) message( FATAL_ERROR "Cython is required to process *.pyx Cython files" ) endif() string(REGEX REPLACE "\\.[^.]*$" "" _pyx_target_name ${_source}) set(_has_cython_targets ON) add_cython_target(${_pyx_target_name} ${_source} OUTPUT_VAR _pyx_target_output DEPENDS ${_args_DEPENDS} ) list(APPEND _processed ${_pyx_target_output}) elseif(${_source} MATCHES \\.pyf$) if(NOT NumPy_FOUND) message( FATAL_ERROR "NumPy is required to process *.pyf F2PY files" ) endif() string(REGEX REPLACE "\\.[^.]*$" "" _pyf_target_name ${_source}) set(_has_f2py_targets ON) add_f2py_target(${_pyf_target_name} ${_source} OUTPUT_VAR _pyf_target_output DEPENDS ${_args_DEPENDS} ) list(APPEND _processed ${_pyf_target_output}) else() list(APPEND _processed ${_source}) endif() endforeach() set(_sources ${_processed}) if(_args_SHARED) add_library(${_name} SHARED ${_sources}) elseif(_args_MODULE) add_library(${_name} MODULE ${_sources}) else() # Assume static add_library(${_name} STATIC ${_sources}) endif() target_include_directories(${_name} PRIVATE ${_args_INCLUDE_DIRECTORIES}) target_link_libraries(${_name} ${SKBUILD_LINK_LIBRARIES_KEYWORD} ${_args_LINK_LIBRARIES}) if(_has_f2py_targets) target_include_directories(${_name} PRIVATE ${F2PY_INCLUDE_DIRS}) target_link_libraries(${_name} ${SKBUILD_LINK_LIBRARIES_KEYWORD} ${F2PY_LIBRARIES}) endif() if(_args_COMPILE_DEFINITIONS) target_compile_definitions(${_name} PRIVATE ${_args_COMPILE_DEFINITIONS}) endif() if(_args_DEPENDS) add_custom_target( "${_name}_depends" DEPENDS ${_args_DEPENDS} ) add_dependencies(${_name} "${_name}_depends") endif() endfunction() function(add_python_extension _name) # FIXME: make sure that extensions with the same name can happen # in multiple directories set(multiValueArgs SOURCES INCLUDE_DIRECTORIES LINK_LIBRARIES COMPILE_DEFINITIONS DEPENDS) cmake_parse_arguments(_args "" "" "${multiValueArgs}" ${ARGN} ) # Validate arguments to allow simpler debugging if(NOT _args_SOURCES) message( FATAL_ERROR "You have called add_python_extension for library ${_name} without " "any source files. This typically indicates a problem with " "your CMakeLists.txt file" ) endif() add_python_library(${_name} MODULE SOURCES ${_args_SOURCES} INCLUDE_DIRECTORIES ${_args_INCLUDE_DIRECTORIES} LINK_LIBRARIES ${_args_LINK_LIBRARIES} COMPILE_DEFINITIONS ${_args_COMPILE_DEFINITIONS} DEPENDS ${_args_DEPENDS} ) python_extension_module(${_name}) file(RELATIVE_PATH _relative "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") if(_relative STREQUAL "") set(_relative ".") endif() install( TARGETS ${_name} LIBRARY DESTINATION "${_relative}" RUNTIME DESTINATION "${_relative}" ) endfunction() zfp-1.0.1/python/scikit-build-cmake/targetLinkLibrariesWithDynamicLookup.cmake000066400000000000000000000421641453723256400276120ustar00rootroot00000000000000#.rst: # # Public Functions # ^^^^^^^^^^^^^^^^ # # The following functions are defined: # # .. cmake:command:: target_link_libraries_with_dynamic_lookup # # :: # # target_link_libraries_with_dynamic_lookup( []) # # # Useful to "weakly" link a loadable module. For example, it should be used # when compiling a loadable module when the symbols should be resolve from # the run-time environment where the module is loaded, and not a specific # system library. # # Like proper linking, except that the given ```` are not necessarily # linked. Instead, the ```` is produced in a manner that allows for # symbols unresolved within it to be resolved at runtime, presumably by the # given ````. If such a target can be produced, the provided # ```` are not actually linked. # # It links a library to a target such that the symbols are resolved at # run-time not link-time. # # The linker is checked to see if it supports undefined # symbols when linking a shared library. If it does then the library # is not linked when specified with this function. # # On platforms that do not support weak-linking, this function works just # like ``target_link_libraries``. # # .. note:: # # For OSX it uses ``undefined dynamic_lookup``. This is similar to using # ``-shared`` on Linux where undefined symbols are ignored. # # For more details, see `blog `_ # from Tim D. Smith. # # # .. cmake:command:: check_dynamic_lookup # # Check if the linker requires a command line flag to allow leaving symbols # unresolved when producing a target of type ```` that is # weakly-linked against a dependency of type ````. # # ```` # can be one of "STATIC", "SHARED", "MODULE", or "EXE". # # ```` # can be one of "STATIC", "SHARED", or "MODULE". # # Long signature: # # :: # # check_dynamic_lookup( # # # []) # # # Short signature: # # :: # # check_dynamic_lookup() # set to "MODULE" # # set to "SHARED" # # # The result is cached between invocations and recomputed only when the value # of CMake's linker flag list changes; ``CMAKE_STATIC_LINKER_FLAGS`` if # ```` is "STATIC", and ``CMAKE_SHARED_LINKER_FLAGS`` otherwise. # # # Defined variables: # # ```` # Whether the current C toolchain supports weak-linking for target binaries of # type ```` that are weakly-linked against a dependency target of # type ````. # # ```` # List of flags to add to the linker command to produce a working target # binary of type ```` that is weakly-linked against a dependency # target of type ````. # # ``HAS_DYNAMIC_LOOKUP__`` # Cached, global alias for ```` # # ``DYNAMIC_LOOKUP_FLAGS__`` # Cached, global alias for ```` # # # Private Functions # ^^^^^^^^^^^^^^^^^ # # The following private functions are defined: # # .. warning:: These functions are not part of the scikit-build API. They # exist purely as an implementation detail and may change from version # to version without notice, or even be removed. # # We mean it. # # # .. cmake:command:: _get_target_type # # :: # # _get_target_type( ) # # # Shorthand for querying an abbreviated version of the target type # of the given ````. # # ```` is set to: # # - "STATIC" for a STATIC_LIBRARY, # - "SHARED" for a SHARED_LIBRARY, # - "MODULE" for a MODULE_LIBRARY, # - and "EXE" for an EXECUTABLE. # # Defined variables: # # ```` # The abbreviated version of the ````'s type. # # # .. cmake:command:: _test_weak_link_project # # :: # # _test_weak_link_project( # # # ) # # # Attempt to compile and run a test project where a target of type # ```` is weakly-linked against a dependency of type ````: # # - ```` can be one of "STATIC", "SHARED", "MODULE", or "EXE". # - ```` can be one of "STATIC", "SHARED", or "MODULE". # # Defined variables: # # ```` # Whether the current C toolchain can produce a working target binary of type # ```` that is weakly-linked against a dependency target of type # ````. # # ```` # List of flags to add to the linker command to produce a working target # binary of type ```` that is weakly-linked against a dependency # target of type ````. # function(_get_target_type result_var target) set(target_type "SHARED_LIBRARY") if(TARGET ${target}) get_property(target_type TARGET ${target} PROPERTY TYPE) endif() set(result "STATIC") if(target_type STREQUAL "STATIC_LIBRARY") set(result "STATIC") endif() if(target_type STREQUAL "SHARED_LIBRARY") set(result "SHARED") endif() if(target_type STREQUAL "MODULE_LIBRARY") set(result "MODULE") endif() if(target_type STREQUAL "EXECUTABLE") set(result "EXE") endif() set(${result_var} ${result} PARENT_SCOPE) endfunction() function(_test_weak_link_project target_type lib_type can_weak_link_var project_name) set(gnu_ld_ignore "-Wl,--unresolved-symbols=ignore-all") set(osx_dynamic_lookup "-undefined dynamic_lookup") set(no_flag "") if(CMAKE_CROSSCOMPILING) set(link_flag_spec "no_flag") set(link_flag "${${link_flag_spec}}") set(test_skipping_reason "") set(test_pass FALSE) if(APPLE AND NOT CMAKE_CROSSCOMPILING_EMULATOR) set(link_flag_spec "osx_dynamic_lookup") set(link_flag "${${link_flag_spec}}") set(test_skipping_reason " (Cross compiling without emulator on macOS)") set(test_pass TRUE) endif() if(test_pass) set(test_description "Weak Link ${target_type} -> ${lib_type} (${link_flag_spec})") message(STATUS "Performing Test ${test_description} - Assuming Success${test_skipping_reason}") set(${can_weak_link_var} ${test_pass} PARENT_SCOPE) set(${project_name} ${link_flag} PARENT_SCOPE) return() endif() endif() foreach(link_flag_spec gnu_ld_ignore osx_dynamic_lookup no_flag) set(link_flag "${${link_flag_spec}}") set(test_project_dir "${PROJECT_BINARY_DIR}/CMakeTmp") set(test_project_dir "${test_project_dir}/${project_name}") set(test_project_dir "${test_project_dir}/${link_flag_spec}") set(test_project_dir "${test_project_dir}/${target_type}") set(test_project_dir "${test_project_dir}/${lib_type}") set(test_project_src_dir "${test_project_dir}/src") set(test_project_bin_dir "${test_project_dir}/build") file(MAKE_DIRECTORY ${test_project_src_dir}) file(MAKE_DIRECTORY ${test_project_bin_dir}) set(mod_type "STATIC") set(link_mod_lib TRUE) set(link_exe_lib TRUE) set(link_exe_mod FALSE) if("${target_type}" STREQUAL "EXE") set(link_exe_lib FALSE) set(link_exe_mod TRUE) else() set(mod_type "${target_type}") endif() if("${mod_type}" STREQUAL "MODULE") set(link_mod_lib FALSE) endif() file(WRITE "${test_project_src_dir}/CMakeLists.txt" " cmake_minimum_required(VERSION ${CMAKE_VERSION}) project(${project_name} C) include_directories(${test_project_src_dir}) add_library(number ${lib_type} number.c) add_library(counter ${mod_type} counter.c) ") if("${mod_type}" STREQUAL "MODULE") file(APPEND "${test_project_src_dir}/CMakeLists.txt" " set_target_properties(counter PROPERTIES PREFIX \"\") ") endif() if(link_mod_lib) file(APPEND "${test_project_src_dir}/CMakeLists.txt" " target_link_libraries(counter ${SKBUILD_LINK_LIBRARIES_KEYWORD} number) ") elseif(NOT link_flag STREQUAL "") file(APPEND "${test_project_src_dir}/CMakeLists.txt" " set_target_properties(counter PROPERTIES LINK_FLAGS \"${link_flag}\") ") endif() file(APPEND "${test_project_src_dir}/CMakeLists.txt" " add_executable(main main.c) ") if(link_exe_lib) file(APPEND "${test_project_src_dir}/CMakeLists.txt" " target_link_libraries(main ${SKBUILD_LINK_LIBRARIES_KEYWORD} number) ") elseif(NOT link_flag STREQUAL "") file(APPEND "${test_project_src_dir}/CMakeLists.txt" " target_link_libraries(main ${SKBUILD_LINK_LIBRARIES_KEYWORD} \"${link_flag}\") ") endif() if(link_exe_mod) file(APPEND "${test_project_src_dir}/CMakeLists.txt" " target_link_libraries(main ${SKBUILD_LINK_LIBRARIES_KEYWORD} counter) ") else() file(APPEND "${test_project_src_dir}/CMakeLists.txt" " target_link_libraries(main ${SKBUILD_LINK_LIBRARIES_KEYWORD} \"${CMAKE_DL_LIBS}\") ") endif() file(WRITE "${test_project_src_dir}/number.c" " #include static int _number; void set_number(int number) { _number = number; } int get_number() { return _number; } ") file(WRITE "${test_project_src_dir}/number.h" " #ifndef _NUMBER_H #define _NUMBER_H extern void set_number(int); extern int get_number(void); #endif ") file(WRITE "${test_project_src_dir}/counter.c" " #include int count() { int result = get_number(); set_number(result + 1); return result; } ") file(WRITE "${test_project_src_dir}/counter.h" " #ifndef _COUNTER_H #define _COUNTER_H extern int count(void); #endif ") file(WRITE "${test_project_src_dir}/main.c" " #include #include #include ") if(NOT link_exe_mod) file(APPEND "${test_project_src_dir}/main.c" " #include ") endif() file(APPEND "${test_project_src_dir}/main.c" " int my_count() { int result = get_number(); set_number(result + 1); return result; } int main(int argc, char **argv) { int result; ") if(NOT link_exe_mod) file(APPEND "${test_project_src_dir}/main.c" " void *counter_module; int (*count)(void); counter_module = dlopen(\"./counter.so\", RTLD_LAZY | RTLD_GLOBAL); if(!counter_module) goto error; count = dlsym(counter_module, \"count\"); if(!count) goto error; ") endif() file(APPEND "${test_project_src_dir}/main.c" " result = count() != 0 ? EXIT_FAILURE : my_count() != 1 ? EXIT_FAILURE : my_count() != 2 ? EXIT_FAILURE : count() != 3 ? EXIT_FAILURE : count() != 4 ? EXIT_FAILURE : count() != 5 ? EXIT_FAILURE : my_count() != 6 ? EXIT_FAILURE : EXIT_SUCCESS; ") if(NOT link_exe_mod) file(APPEND "${test_project_src_dir}/main.c" " goto done; error: fprintf(stderr, \"Error occurred:\\n %s\\n\", dlerror()); result = 1; done: if(counter_module) dlclose(counter_module); ") endif() file(APPEND "${test_project_src_dir}/main.c" " return result; } ") set(_rpath_arg) if(APPLE AND ${CMAKE_VERSION} VERSION_GREATER 2.8.11) set(_rpath_arg "-DCMAKE_MACOSX_RPATH='${CMAKE_MACOSX_RPATH}'") endif() try_compile(project_compiles "${test_project_bin_dir}" "${test_project_src_dir}" "${project_name}" CMAKE_FLAGS "-DCMAKE_SHARED_LINKER_FLAGS='${CMAKE_SHARED_LINKER_FLAGS}'" "-DCMAKE_ENABLE_EXPORTS=ON" ${_rpath_arg} OUTPUT_VARIABLE compile_output) set(project_works 1) set(run_output) if(project_compiles) execute_process(COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} "${test_project_bin_dir}/main" WORKING_DIRECTORY "${test_project_bin_dir}" RESULT_VARIABLE project_works OUTPUT_VARIABLE run_output ERROR_VARIABLE run_output) endif() set(test_description "Weak Link ${target_type} -> ${lib_type} (${link_flag_spec})") if(project_works EQUAL 0) set(project_works TRUE) message(STATUS "Performing Test ${test_description} - Success") else() set(project_works FALSE) message(STATUS "Performing Test ${test_description} - Failed") file(APPEND ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeError.log "Performing Test ${test_description} failed with the " "following output:\n" "BUILD\n-----\n${compile_output}\nRUN\n---\n${run_output}\n") endif() set(${can_weak_link_var} ${project_works} PARENT_SCOPE) if(project_works) set(${project_name} ${link_flag} PARENT_SCOPE) break() endif() endforeach() endfunction() function(check_dynamic_lookup) # Two signatures are supported: if(ARGC EQUAL "1") # # check_dynamic_lookup() # set(target_type "MODULE") set(lib_type "SHARED") set(has_dynamic_lookup_var "${ARGV0}") set(link_flags_var "unused") elseif(ARGC GREATER "2") # # check_dynamic_lookup( # # # []) # set(target_type "${ARGV0}") set(lib_type "${ARGV1}") set(has_dynamic_lookup_var "${ARGV2}") if(ARGC EQUAL "3") set(link_flags_var "unused") else() set(link_flags_var "${ARGV3}") endif() else() message(FATAL_ERROR "missing arguments") endif() _check_dynamic_lookup( ${target_type} ${lib_type} ${has_dynamic_lookup_var} ${link_flags_var} ) set(${has_dynamic_lookup_var} ${${has_dynamic_lookup_var}} PARENT_SCOPE) if(NOT "x${link_flags_var}x" STREQUAL "xunusedx") set(${link_flags_var} ${${link_flags_var}} PARENT_SCOPE) endif() endfunction() function(_check_dynamic_lookup target_type lib_type has_dynamic_lookup_var link_flags_var ) # hash the CMAKE_FLAGS passed and check cache to know if we need to rerun if("${target_type}" STREQUAL "STATIC") string(MD5 cmake_flags_hash "${CMAKE_STATIC_LINKER_FLAGS}") else() string(MD5 cmake_flags_hash "${CMAKE_SHARED_LINKER_FLAGS}") endif() set(cache_var "HAS_DYNAMIC_LOOKUP_${target_type}_${lib_type}") set(cache_hash_var "HAS_DYNAMIC_LOOKUP_${target_type}_${lib_type}_hash") set(result_var "DYNAMIC_LOOKUP_FLAGS_${target_type}_${lib_type}") if( NOT DEFINED ${cache_hash_var} OR NOT "${${cache_hash_var}}" STREQUAL "${cmake_flags_hash}") unset(${cache_var} CACHE) endif() if(NOT DEFINED ${cache_var}) if(CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR) set(skip_test TRUE) endif() _test_weak_link_project(${target_type} ${lib_type} has_dynamic_lookup link_flags) set(caveat " (when linking ${target_type} against ${lib_type})") set(${cache_var} "${has_dynamic_lookup}" CACHE BOOL "linker supports dynamic lookup for undefined symbols${caveat}") mark_as_advanced(${cache_var}) set(${result_var} "${link_flags}" CACHE STRING "linker flags for dynamic lookup${caveat}") mark_as_advanced(${result_var}) set(${cache_hash_var} "${cmake_flags_hash}" CACHE INTERNAL "hashed flags for ${cache_var} check") endif() set(${has_dynamic_lookup_var} "${${cache_var}}" PARENT_SCOPE) set(${link_flags_var} "${${result_var}}" PARENT_SCOPE) endfunction() function(target_link_libraries_with_dynamic_lookup target) _get_target_type(target_type ${target}) set(link_props) set(link_items) set(link_libs) foreach(lib ${ARGN}) _get_target_type(lib_type ${lib}) check_dynamic_lookup(${target_type} ${lib_type} has_dynamic_lookup dynamic_lookup_flags) if(has_dynamic_lookup) if(dynamic_lookup_flags) if("${target_type}" STREQUAL "EXE") list(APPEND link_items "${dynamic_lookup_flags}") else() list(APPEND link_props "${dynamic_lookup_flags}") endif() endif() elseif(${lib} MATCHES "(debug|optimized|general)") # See gh-255 else() list(APPEND link_libs "${lib}") endif() endforeach() if(link_props) list(REMOVE_DUPLICATES link_props) endif() if(link_items) list(REMOVE_DUPLICATES link_items) endif() if(link_libs) list(REMOVE_DUPLICATES link_libs) endif() if(link_props) set_target_properties(${target} PROPERTIES LINK_FLAGS "${link_props}") endif() set(links "${link_items}" "${link_libs}") if(links) target_link_libraries(${target} ${SKBUILD_LINK_LIBRARIES_KEYWORD} "${links}") endif() endfunction() zfp-1.0.1/python/zfpy.pxd000066400000000000000000000067611453723256400153630ustar00rootroot00000000000000import cython cimport libc.stdint as stdint from libc.stddef cimport ptrdiff_t cdef extern from "zfp/bitstream.h": cdef struct bitstream: pass bitstream* stream_open(void* data, size_t) void stream_close(bitstream* stream) cdef extern from "zfp.h": # enums ctypedef enum zfp_type: zfp_type_none = 0, zfp_type_int32 = 1, zfp_type_int64 = 2, zfp_type_float = 3, zfp_type_double = 4 ctypedef enum zfp_mode: zfp_mode_null = 0, zfp_mode_expert = 1, zfp_mode_fixed_rate = 2, zfp_mode_fixed_precision = 3, zfp_mode_fixed_accuracy = 4, zfp_mode_reversible = 5 # structs ctypedef struct zfp_field: zfp_type _type "type" size_t nx, ny, nz, nw ptrdiff_t sx, sy, sz, sw void* data ctypedef struct zfp_stream: pass ctypedef int zfp_bool # include #define's cython.uint ZFP_HEADER_MAGIC cython.uint ZFP_HEADER_META cython.uint ZFP_HEADER_MODE cython.uint ZFP_HEADER_FULL # function declarations zfp_stream* zfp_stream_open(bitstream* stream) void zfp_stream_close(zfp_stream* stream) stdint.uint64_t zfp_stream_mode(const zfp_stream* zfp) size_t zfp_stream_maximum_size(const zfp_stream* stream, const zfp_field* field) void zfp_stream_rewind(zfp_stream* stream) void zfp_stream_set_bit_stream(zfp_stream* stream, bitstream* bs) void zfp_stream_set_reversible(zfp_stream* stream) double zfp_stream_set_rate(zfp_stream* stream, double rate, zfp_type type, cython.uint dims, zfp_bool align) cython.uint zfp_stream_set_precision(zfp_stream* stream, cython.uint precision) double zfp_stream_set_accuracy(zfp_stream* stream, double tolerance) zfp_mode zfp_stream_set_mode(zfp_stream* stream, stdint.uint64_t mode) zfp_mode zfp_stream_compression_mode(zfp_stream* stream) double zfp_stream_accuracy(zfp_stream* stream) double zfp_stream_rate(zfp_stream* stream, cython.uint dims) cython.uint zfp_stream_precision(const zfp_stream* stream) zfp_field* zfp_field_alloc() zfp_field* zfp_field_1d(void* pointer, zfp_type, size_t nx) zfp_field* zfp_field_2d(void* pointer, zfp_type, size_t nx, size_t ny) zfp_field* zfp_field_3d(void* pointer, zfp_type, size_t nx, size_t ny, size_t nz) zfp_field* zfp_field_4d(void* pointer, zfp_type, size_t nx, size_t ny, size_t nz, size_t nw) void zfp_field_free(zfp_field* field) zfp_bool zfp_field_stride(const zfp_field* field, ptrdiff_t* stride) void zfp_field_set_pointer(zfp_field* field, void* pointer) nogil zfp_type zfp_field_set_type(zfp_field* field, zfp_type type) void zfp_field_set_stride_1d(zfp_field* field, ptrdiff_t sx) void zfp_field_set_stride_2d(zfp_field* field, ptrdiff_t sx, ptrdiff_t sy) void zfp_field_set_stride_3d(zfp_field* field, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) void zfp_field_set_stride_4d(zfp_field* field, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) size_t zfp_compress(zfp_stream* stream, const zfp_field* field) nogil size_t zfp_decompress(zfp_stream* stream, zfp_field* field) nogil size_t zfp_write_header(zfp_stream* stream, const zfp_field* field, cython.uint mask) size_t zfp_read_header(zfp_stream* stream, zfp_field* field, cython.uint mask) void zfp_stream_params(zfp_stream* stream, cython.uint* minbits, cython.uint* maxbits, cython.uint* maxprec, int* minexp); cdef gen_padded_int_list(orig_array, pad=*, length=*) zfp-1.0.1/python/zfpy.pyx000066400000000000000000000325111453723256400154000ustar00rootroot00000000000000import sys import operator import functools import cython from libc.stdlib cimport malloc, free from cython cimport view from libc.stdint cimport uint8_t import itertools if sys.version_info[0] == 2: from itertools import izip_longest as zip_longest elif sys.version_info[0] == 3: from itertools import zip_longest cimport zfpy import numpy as np cimport numpy as np # export #define's HEADER_MAGIC = ZFP_HEADER_MAGIC HEADER_META = ZFP_HEADER_META HEADER_MODE = ZFP_HEADER_MODE HEADER_FULL = ZFP_HEADER_FULL # export enums type_none = zfp_type_none type_int32 = zfp_type_int32 type_int64 = zfp_type_int64 type_float = zfp_type_float type_double = zfp_type_double mode_null = zfp_mode_null mode_expert = zfp_mode_expert mode_fixed_rate = zfp_mode_fixed_rate mode_fixed_precision = zfp_mode_fixed_precision mode_fixed_accuracy = zfp_mode_fixed_accuracy cpdef dtype_to_ztype(dtype): if dtype == np.int32: return zfp_type_int32 elif dtype == np.int64: return zfp_type_int64 elif dtype == np.float32: return zfp_type_float elif dtype == np.float64: return zfp_type_double else: raise TypeError("Unknown dtype: {}".format(dtype)) cpdef dtype_to_format(dtype): # format characters detailed here: # https://docs.python.org/3/library/array.html if dtype == np.int32: return 'i' # signed int elif dtype == np.int64: return 'q' # signed long long elif dtype == np.float32: return 'f' # float elif dtype == np.float64: return 'd' # double else: raise TypeError("Unknown dtype: {}".format(dtype)) zfp_to_dtype_map = { zfp_type_int32: np.int32, zfp_type_int64: np.int64, zfp_type_float: np.float32, zfp_type_double: np.float64, } cpdef ztype_to_dtype(zfp_type ztype): try: return zfp_to_dtype_map[ztype] except KeyError: raise ValueError("Unsupported zfp_type {}".format(ztype)) zfp_mode_map = { zfp_mode_null: "null", zfp_mode_expert: "expert", zfp_mode_reversible: "reversible", zfp_mode_fixed_accuracy: "tolerance", zfp_mode_fixed_precision: "precision", zfp_mode_fixed_rate: "rate", } cpdef zmode_to_str(zfp_mode zmode): try: return zfp_mode_map[zmode] except KeyError: raise ValueError("Unsupported zfp_mode {}".format(zmode)) cdef zfp_field* _init_field(np.ndarray arr) except NULL: shape = arr.shape cdef int ndim = arr.ndim cdef zfp_type ztype = dtype_to_ztype(arr.dtype) cdef zfp_field* field cdef void* pointer = arr.data strides = [int(x) / arr.itemsize for x in arr.strides[:ndim]] if ndim == 1: field = zfp_field_1d(pointer, ztype, shape[0]) zfp_field_set_stride_1d(field, strides[0]) elif ndim == 2: field = zfp_field_2d(pointer, ztype, shape[1], shape[0]) zfp_field_set_stride_2d(field, strides[1], strides[0]) elif ndim == 3: field = zfp_field_3d(pointer, ztype, shape[2], shape[1], shape[0]) zfp_field_set_stride_3d(field, strides[2], strides[1], strides[0]) elif ndim == 4: field = zfp_field_4d(pointer, ztype, shape[3], shape[2], shape[1], shape[0]) zfp_field_set_stride_4d(field, strides[3], strides[2], strides[1], strides[0]) else: raise RuntimeError("Greater than 4 dimensions not supported") return field cdef gen_padded_int_list(orig_array, pad=0, length=4): return [int(x) for x in itertools.islice( itertools.chain( orig_array, itertools.repeat(pad) ), length ) ] @cython.final cdef class Memory: cdef void* data def __cinit__(self, size_t size): self.data = malloc(size) if self.data == NULL: raise MemoryError() cdef void* __enter__(self): return self.data def __exit__(self, exc_type, exc_value, exc_tb): free(self.data) cpdef bytes compress_numpy( np.ndarray arr, double tolerance = -1, double rate = -1, int precision = -1, write_header=True ): # Input validation if arr is None: raise TypeError("Input array cannot be None") num_params_set = sum([1 for x in [tolerance, rate, precision] if x >= 0]) if num_params_set > 1: raise ValueError("Only one of tolerance, rate, or precision can be set") # Setup zfp structs to begin compression cdef zfp_field* field = _init_field(arr) cdef zfp_stream* stream = zfp_stream_open(NULL) cdef zfp_type ztype = zfp_type_none cdef int ndim = arr.ndim _set_compression_mode(stream, ztype, ndim, tolerance, rate, precision) # Allocate space based on the maximum size potentially required by zfp to # store the compressed array cdef bytes compress_str = None cdef size_t maxsize = zfp_stream_maximum_size(stream, field) try: with Memory(maxsize) as data: bstream = stream_open(data, maxsize) zfp_stream_set_bit_stream(stream, bstream) zfp_stream_rewind(stream) # write the full header so we can reconstruct the numpy array on # decompression if write_header and zfp_write_header(stream, field, HEADER_FULL) == 0: raise RuntimeError("Failed to write header to stream") with nogil: compressed_size = zfp_compress(stream, field) if compressed_size == 0: raise RuntimeError("Failed to write to stream") # copy the compressed data into a perfectly sized bytes object compress_str = (data)[:compressed_size] finally: zfp_field_free(field) zfp_stream_close(stream) stream_close(bstream) return compress_str cdef view.array _decompress_with_view( zfp_field* field, zfp_stream* stream, ): cdef zfp_type ztype = field[0]._type dtype = ztype_to_dtype(ztype) format_type = dtype_to_format(dtype) shape = (field[0].nw, field[0].nz, field[0].ny, field[0].nx) shape = tuple([x for x in shape if x > 0]) cdef view.array decomp_arr = view.array( shape, itemsize=np.dtype(dtype).itemsize, format=format_type, allocate_buffer=True ) cdef void* pointer = decomp_arr.data with nogil: zfp_field_set_pointer(field, pointer) ret = zfp_decompress(stream, field) if ret == 0: raise RuntimeError("error during zfp decompression") return decomp_arr cdef _decompress_with_user_array( zfp_field* field, zfp_stream* stream, void* out, ): with nogil: zfp_field_set_pointer(field, out) ret = zfp_decompress(stream, field) if ret == 0: raise RuntimeError("error during zfp decompression") cdef _set_compression_mode( zfp_stream *stream, zfp_type ztype, int ndim, double tolerance = -1, double rate = -1, int precision = -1, ): if tolerance >= 0: zfp_stream_set_accuracy(stream, tolerance) elif rate >= 0: zfp_stream_set_rate(stream, rate, ztype, ndim, 0) elif precision >= 0: zfp_stream_set_precision(stream, precision) else: zfp_stream_set_reversible(stream) cdef _validate_4d_list(in_list, list_name): # Validate that the input list is either a valid list for strides or shape # Specifically, check it is a list and the length is > 0 and <= 4 # Throws a TypeError or ValueError if invalid try: if len(in_list) > 4: raise ValueError( "User-provided {} has too many dimensions " "(up to 4 supported)" ) elif len(in_list) <= 0: raise ValueError( "User-provided {} needs at least one dimension" ) except TypeError: raise TypeError( "User-provided {} is not an iterable" ) cpdef np.ndarray _decompress( const uint8_t[::1] compressed_data, zfp_type ztype, shape, out=None, double tolerance = -1, double rate = -1, int precision = -1, ): if compressed_data is None: raise TypeError("compressed_data cannot be None") if compressed_data is out: raise ValueError("Cannot decompress in-place") _validate_4d_list(shape, "shape") cdef const void* comp_data_pointer = &compressed_data[0] cdef zfp_field* field = zfp_field_alloc() cdef bitstream* bstream = stream_open( comp_data_pointer, len(compressed_data) ) cdef zfp_stream* stream = zfp_stream_open(bstream) cdef np.ndarray output try: zfp_stream_rewind(stream) zshape = gen_padded_int_list(reversed(shape), pad=0, length=4) # set the shape, type, and compression mode # strides are set further down field[0].nx, field[0].ny, field[0].nz, field[0].nw = zshape zfp_field_set_type(field, ztype) ndim = sum([1 for x in zshape if x > 0]) _set_compression_mode(stream, ztype, ndim, tolerance, rate, precision) # pad the shape with zeros to reach len == 4 # strides = gen_padded_int_list(reversed(strides), pad=0, length=4) # field[0].sx, field[0].sy, field[0].sz, field[0].sw = strides if out is None: output = np.asarray(_decompress_with_view(field, stream)) else: dtype = zfpy.ztype_to_dtype(ztype) if isinstance(out, np.ndarray): output = out # check that numpy and user-provided types match if out.dtype != dtype: raise ValueError( "Out ndarray has dtype {} but decompression is using " "{}. Use out=ndarray.data to avoid this check.".format( out.dtype, dtype ) ) # check that numpy and user-provided shape match numpy_shape = out.shape user_shape = [x for x in shape if x > 0] if not all( [x == y for x, y in zip_longest(numpy_shape, user_shape) ] ): raise ValueError( "Out ndarray has shape {} but decompression is using " "{}. Use out=ndarray.data to avoid this check.".format( numpy_shape, user_shape ) ) else: output = np.frombuffer(out, dtype=dtype) output = output.reshape(shape) _decompress_with_user_array(field, stream, output.data) finally: zfp_field_free(field) zfp_stream_close(stream) stream_close(bstream) return output cpdef np.ndarray decompress_numpy( const uint8_t[::1] compressed_data, ): if compressed_data is None: raise TypeError("compressed_data cannot be None") cdef const void* comp_data_pointer = &compressed_data[0] cdef zfp_field* field = zfp_field_alloc() cdef bitstream* bstream = stream_open( comp_data_pointer, len(compressed_data) ) cdef zfp_stream* stream = zfp_stream_open(bstream) cdef np.ndarray output try: if zfp_read_header(stream, field, HEADER_FULL) == 0: raise ValueError("Failed to read required zfp header") output = np.asarray(_decompress_with_view(field, stream)) finally: zfp_field_free(field) zfp_stream_close(stream) stream_close(bstream) return output cpdef dict header(const uint8_t[::1] compressed_data): """Return stream header information in a python dict.""" if compressed_data is None: raise TypeError("compressed_data cannot be None") cdef const void* comp_data_pointer = &compressed_data[0] cdef zfp_field* field = zfp_field_alloc() cdef bitstream* bstream = stream_open( comp_data_pointer, len(compressed_data) ) cdef zfp_stream* stream = zfp_stream_open(bstream) cdef zfp_mode mode cdef unsigned int minbits = 0 cdef unsigned int maxbits = 0 cdef unsigned int maxprec = 0 cdef int minexp = 0 try: if zfp_read_header(stream, field, HEADER_FULL) == 0: raise ValueError("Failed to read required zfp header") mode = zfp_stream_compression_mode(stream) ndim = 0 for dim in [field.nx, field.ny, field.nz, field.nw]: ndim += int(dim > 0) zfp_stream_params(stream, &minbits, &maxbits, &maxprec, &minexp) return { "nx": int(field.nx), "ny": int(field.ny), "nz": int(field.nz), "nw": int(field.nw), "type": ztype_to_dtype(field._type), "mode": zmode_to_str(mode), "config": { "mode": int(mode), "tolerance": float(zfp_stream_accuracy(stream)), "rate": float(zfp_stream_rate(stream, ndim)), "precision": int(zfp_stream_precision(stream)), "expert": { "minbits": int(minbits), "maxbits": int(minbits), "maxprec": int(maxprec), "minexp": int(minexp), }, }, } finally: zfp_field_free(field) zfp_stream_close(stream) stream_close(bstream) zfp-1.0.1/setup.py000066400000000000000000000017201453723256400140350ustar00rootroot00000000000000from setuptools import setup, Extension import numpy as np setup( name="zfpy", version="1.0.1", author="Peter Lindstrom, Danielle Asher", author_email="zfp@llnl.gov", url="https://zfp.llnl.gov", description="zfp compression in Python", long_description="zfp is a compressed format for representing multidimensional floating-point and integer arrays. zfp provides compressed-array classes that support high throughput read and write random access to individual array elements. zfp also supports serial and parallel compression of whole arrays using both lossless and lossy compression with error tolerances. zfp is primarily written in C and C++ but also includes Python and Fortran bindings.", ext_modules=[Extension("zfpy", ["build/python/zfpy.c"], include_dirs=["include", np.get_include()], libraries=["zfp"], library_dirs=["build/lib64", "build/lib/Release"]), language_level = "3"] ) zfp-1.0.1/src/000077500000000000000000000000001453723256400131125ustar00rootroot00000000000000zfp-1.0.1/src/CMakeLists.txt000066400000000000000000000037541453723256400156630ustar00rootroot00000000000000if(ZFP_WITH_CUDA) set(CMAKE_CXX_FLAGS_PREVIOUS ${CMAKE_CXX_FLAGS}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC" ) add_subdirectory(cuda_zfp) cuda_include_directories(${PROJECT_SOURCE_DIR}/include) cuda_wrap_srcs(zfp OBJ zfp_cuda_backend_obj cuda_zfp/cuZFP.cu OPTIONS ${CMAKE_CUDA_FLAGS}) set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_PREVIOUS}) add_definitions(-DZFP_WITH_CUDA) endif() set(zfp_source zfp.c bitstream.c traitsf.h traitsd.h block1.h block2.h block3.h block4.h encode1f.c encode1d.c encode1i.c encode1l.c decode1f.c decode1d.c decode1i.c decode1l.c encode2f.c encode2d.c encode2i.c encode2l.c decode2f.c decode2d.c decode2i.c decode2l.c encode3f.c encode3d.c encode3i.c encode3l.c decode3f.c decode3d.c decode3i.c decode3l.c encode4f.c encode4d.c encode4i.c encode4l.c decode4f.c decode4d.c decode4i.c decode4l.c) add_library(zfp ${zfp_source} ${zfp_cuda_backend_obj}) add_library(zfp::zfp ALIAS zfp) if(ZFP_WITH_OPENMP) target_link_libraries(zfp PRIVATE OpenMP::OpenMP_C) endif() if(HAVE_LIBM_MATH) target_link_libraries(zfp PRIVATE m) endif() if(WIN32 AND BUILD_SHARED_LIBS) # Define ZFP_SOURCE when compiling libzfp to export symbols to Windows DLL list(APPEND zfp_public_defs ZFP_SHARED_LIBS) list(APPEND zfp_private_defs ZFP_SOURCE) endif() if(ZFP_WITH_CUDA) target_link_libraries(zfp PRIVATE ${CUDA_CUDART_LIBRARY} stdc++) endif() target_compile_definitions(zfp PRIVATE ${zfp_private_defs} PUBLIC ${zfp_public_defs} ) target_include_directories(zfp PUBLIC $ $ ) set_property(TARGET zfp PROPERTY VERSION ${ZFP_VERSION}) set_property(TARGET zfp PROPERTY SOVERSION ${ZFP_VERSION_MAJOR}) set_property(TARGET zfp PROPERTY OUTPUT_NAME ${ZFP_LIBRARY_PREFIX}zfp) install(TARGETS zfp EXPORT zfp-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) zfp-1.0.1/src/Makefile000066400000000000000000000013731453723256400145560ustar00rootroot00000000000000include ../Config LIBDIR = ../lib TARGETS = $(LIBDIR)/libzfp.a $(LIBDIR)/libzfp.so OBJECTS = bitstream.o decode1i.o decode1l.o decode1f.o decode1d.o encode1i.o encode1l.o encode1f.o encode1d.o decode2i.o decode2l.o decode2f.o decode2d.o encode2i.o encode2l.o encode2f.o encode2d.o decode3i.o decode3l.o decode3f.o decode3d.o encode3i.o encode3l.o encode3f.o encode3d.o decode4i.o decode4l.o decode4f.o decode4d.o encode4i.o encode4l.o encode4f.o encode4d.o zfp.o static: $(LIBDIR)/libzfp.a shared: $(LIBDIR)/libzfp.so clean: rm -f $(TARGETS) $(OBJECTS) $(LIBDIR)/libzfp.a: $(OBJECTS) mkdir -p $(LIBDIR) rm -f $@ ar rc $@ $^ $(LIBDIR)/libzfp.so: $(OBJECTS) mkdir -p $(LIBDIR) $(CC) $(CFLAGS) -shared $^ -o $@ .c.o: $(CC) $(CFLAGS) -I../include -c $< zfp-1.0.1/src/bitstream.c000066400000000000000000000001401453723256400152430ustar00rootroot00000000000000#include "zfp/bitstream.h" #include "zfp/bitstream.inl" const size_t stream_word_bits = wsize; zfp-1.0.1/src/block1.h000066400000000000000000000000171453723256400144340ustar00rootroot00000000000000#define DIMS 1 zfp-1.0.1/src/block2.h000066400000000000000000000000171453723256400144350ustar00rootroot00000000000000#define DIMS 2 zfp-1.0.1/src/block3.h000066400000000000000000000000171453723256400144360ustar00rootroot00000000000000#define DIMS 3 zfp-1.0.1/src/block4.h000066400000000000000000000000171453723256400144370ustar00rootroot00000000000000#define DIMS 4 zfp-1.0.1/src/cuda_zfp/000077500000000000000000000000001453723256400147055ustar00rootroot00000000000000zfp-1.0.1/src/cuda_zfp/CMakeLists.txt000066400000000000000000000007431453723256400174510ustar00rootroot00000000000000############################################################################### # # file: src/cuZFP/CMakeLists.txt # ############################################################################### set(cuZFP_sources cuZFP.cu # main entry point decode.cuh decode1.cuh decode2.cuh decode3.cuh encode.cuh encode1.cuh encode2.cuh encode3.cuh pointers.cuh type_info.cuh) set(cuZFP_headers shared.h cuZFP.h ErrorCheck.h) zfp-1.0.1/src/cuda_zfp/ErrorCheck.h000066400000000000000000000010101453723256400170750ustar00rootroot00000000000000#ifndef ERRORCHECK_H #define ERRORCHECK_H #include #include #include using std::stringstream; class ErrorCheck { public: ErrorCheck() { } void chk(std::string msg) { error = cudaGetLastError(); if (error != cudaSuccess) { std::cout << msg << " : " << error; std::cout << " " << cudaGetErrorString(error) << std::endl; } } void chk() { chk(str.str()); str.str(""); } cudaError error; stringstream str; }; #endif // ERRORCHECK_H zfp-1.0.1/src/cuda_zfp/constants.h000066400000000000000000000054541453723256400171020ustar00rootroot00000000000000#ifndef cuZFP_CONSTANTS_H #define cuZFP_CONSTANTS_H namespace cuZFP { #define index_3d(x, y, z) ((x) + 4 * ((y) + 4 * (z))) __device__ static const unsigned char perm_3d[64] = { index_3d(0, 0, 0), // 0 : 0 index_3d(1, 0, 0), // 1 : 1 index_3d(0, 1, 0), // 2 : 1 index_3d(0, 0, 1), // 3 : 1 index_3d(0, 1, 1), // 4 : 2 index_3d(1, 0, 1), // 5 : 2 index_3d(1, 1, 0), // 6 : 2 index_3d(2, 0, 0), // 7 : 2 index_3d(0, 2, 0), // 8 : 2 index_3d(0, 0, 2), // 9 : 2 index_3d(1, 1, 1), // 10 : 3 index_3d(2, 1, 0), // 11 : 3 index_3d(2, 0, 1), // 12 : 3 index_3d(0, 2, 1), // 13 : 3 index_3d(1, 2, 0), // 14 : 3 index_3d(1, 0, 2), // 15 : 3 index_3d(0, 1, 2), // 16 : 3 index_3d(3, 0, 0), // 17 : 3 index_3d(0, 3, 0), // 18 : 3 index_3d(0, 0, 3), // 19 : 3 index_3d(2, 1, 1), // 20 : 4 index_3d(1, 2, 1), // 21 : 4 index_3d(1, 1, 2), // 22 : 4 index_3d(0, 2, 2), // 23 : 4 index_3d(2, 0, 2), // 24 : 4 index_3d(2, 2, 0), // 25 : 4 index_3d(3, 1, 0), // 26 : 4 index_3d(3, 0, 1), // 27 : 4 index_3d(0, 3, 1), // 28 : 4 index_3d(1, 3, 0), // 29 : 4 index_3d(1, 0, 3), // 30 : 4 index_3d(0, 1, 3), // 31 : 4 index_3d(1, 2, 2), // 32 : 5 index_3d(2, 1, 2), // 33 : 5 index_3d(2, 2, 1), // 34 : 5 index_3d(3, 1, 1), // 35 : 5 index_3d(1, 3, 1), // 36 : 5 index_3d(1, 1, 3), // 37 : 5 index_3d(3, 2, 0), // 38 : 5 index_3d(3, 0, 2), // 39 : 5 index_3d(0, 3, 2), // 40 : 5 index_3d(2, 3, 0), // 41 : 5 index_3d(2, 0, 3), // 42 : 5 index_3d(0, 2, 3), // 43 : 5 index_3d(2, 2, 2), // 44 : 6 index_3d(3, 2, 1), // 45 : 6 index_3d(3, 1, 2), // 46 : 6 index_3d(1, 3, 2), // 47 : 6 index_3d(2, 3, 1), // 48 : 6 index_3d(2, 1, 3), // 49 : 6 index_3d(1, 2, 3), // 50 : 6 index_3d(0, 3, 3), // 51 : 6 index_3d(3, 0, 3), // 52 : 6 index_3d(3, 3, 0), // 53 : 6 index_3d(3, 2, 2), // 54 : 7 index_3d(2, 3, 2), // 55 : 7 index_3d(2, 2, 3), // 56 : 7 index_3d(1, 3, 3), // 57 : 7 index_3d(3, 1, 3), // 58 : 7 index_3d(3, 3, 1), // 59 : 7 index_3d(2, 3, 3), // 60 : 8 index_3d(3, 2, 3), // 61 : 8 index_3d(3, 3, 2), // 62 : 8 index_3d(3, 3, 3), // 63 : 9 }; #undef index_3d __device__ static const unsigned char perm_1[4] = { 0, 1, 2, 3 }; #define index(i, j) ((i) + 4 * (j)) /* order coefficients (i, j) by i + j, then i^2 + j^2 */ __device__ static const unsigned char perm_2[16] = { index(0, 0), /* 0 : 0 */ index(1, 0), /* 1 : 1 */ index(0, 1), /* 2 : 1 */ index(1, 1), /* 3 : 2 */ index(2, 0), /* 4 : 2 */ index(0, 2), /* 5 : 2 */ index(2, 1), /* 6 : 3 */ index(1, 2), /* 7 : 3 */ index(3, 0), /* 8 : 3 */ index(0, 3), /* 9 : 3 */ index(2, 2), /* 10 : 4 */ index(3, 1), /* 11 : 4 */ index(1, 3), /* 12 : 4 */ index(3, 2), /* 13 : 5 */ index(2, 3), /* 14 : 5 */ index(3, 3), /* 15 : 6 */ }; #undef index } // namespace cuZFP #endif zfp-1.0.1/src/cuda_zfp/cuZFP.cu000066400000000000000000000271771453723256400162430ustar00rootroot00000000000000#include #include "cuZFP.h" #include "encode1.cuh" #include "encode2.cuh" #include "encode3.cuh" #include "decode1.cuh" #include "decode2.cuh" #include "decode3.cuh" #include "ErrorCheck.h" #include "pointers.cuh" #include "type_info.cuh" #include #include // we need to know about bitstream, but we don't // want duplicate symbols. #ifndef inline_ #define inline_ inline #endif #include "zfp/bitstream.inl" namespace internal { bool is_contigous3d(const uint dims[3], const int3 &stride, long long int &offset) { typedef long long int int64; int64 idims[3]; idims[0] = dims[0]; idims[1] = dims[1]; idims[2] = dims[2]; int64 imin = std::min(stride.x,0) * (idims[0] - 1) + std::min(stride.y,0) * (idims[1] - 1) + std::min(stride.z,0) * (idims[2] - 1); int64 imax = std::max(stride.x,0) * (idims[0] - 1) + std::max(stride.y,0) * (idims[1] - 1) + std::max(stride.z,0) * (idims[2] - 1); offset = imin; int64 ns = idims[0] * idims[1] * idims[2]; return (imax - imin + 1 == ns); } bool is_contigous2d(const uint dims[3], const int3 &stride, long long int &offset) { typedef long long int int64; int64 idims[2]; idims[0] = dims[0]; idims[1] = dims[1]; int64 imin = std::min(stride.x,0) * (idims[0] - 1) + std::min(stride.y,0) * (idims[1] - 1); int64 imax = std::max(stride.x,0) * (idims[0] - 1) + std::max(stride.y,0) * (idims[1] - 1); offset = imin; return (imax - imin + 1) == (idims[0] * idims[1]); } bool is_contigous1d(uint dim, const int &stride, long long int &offset) { offset = 0; if(stride < 0) offset = stride * (int(dim) - 1); return std::abs(stride) == 1; } bool is_contigous(const uint dims[3], const int3 &stride, long long int &offset) { int d = 0; if(dims[0] != 0) d++; if(dims[1] != 0) d++; if(dims[2] != 0) d++; if(d == 3) { return is_contigous3d(dims, stride, offset); } else if(d == 2) { return is_contigous2d(dims, stride, offset); } else { return is_contigous1d(dims[0], stride.x, offset); } } // // encode expects device pointers // template size_t encode(uint dims[3], int3 stride, int bits_per_block, T *d_data, Word *d_stream) { int d = 0; size_t len = 1; for(int i = 0; i < 3; ++i) { if(dims[i] != 0) { d++; len *= dims[i]; } } ErrorCheck errors; size_t stream_size = 0; if(d == 1) { int dim = dims[0]; int sx = stride.x; stream_size = cuZFP::encode1(dim, sx, d_data, d_stream, bits_per_block); } else if(d == 2) { uint2 ndims = make_uint2(dims[0], dims[1]); int2 s; s.x = stride.x; s.y = stride.y; stream_size = cuZFP::encode2(ndims, s, d_data, d_stream, bits_per_block); } else if(d == 3) { int3 s; s.x = stride.x; s.y = stride.y; s.z = stride.z; uint3 ndims = make_uint3(dims[0], dims[1], dims[2]); stream_size = cuZFP::encode(ndims, s, d_data, d_stream, bits_per_block); } errors.chk("Encode"); return stream_size; } template size_t decode(uint ndims[3], int3 stride, int bits_per_block, Word *stream, T *out) { int d = 0; size_t out_size = 1; size_t stream_bytes = 0; for(int i = 0; i < 3; ++i) { if(ndims[i] != 0) { d++; out_size *= ndims[i]; } } if(d == 3) { uint3 dims = make_uint3(ndims[0], ndims[1], ndims[2]); int3 s; s.x = stride.x; s.y = stride.y; s.z = stride.z; stream_bytes = cuZFP::decode3(dims, s, stream, out, bits_per_block); } else if(d == 1) { uint dim = ndims[0]; int sx = stride.x; stream_bytes = cuZFP::decode1(dim, sx, stream, out, bits_per_block); } else if(d == 2) { uint2 dims; dims.x = ndims[0]; dims.y = ndims[1]; int2 s; s.x = stride.x; s.y = stride.y; stream_bytes = cuZFP::decode2(dims, s, stream, out, bits_per_block); } else std::cerr<<" d == "<stream->begin); assert(sizeof(bitstream_word) == sizeof(Word)); // "CUDA version currently only supports 64bit words"); if(stream_device) { return (Word*) stream->stream->begin; } Word *d_stream = NULL; size_t max_size = zfp_stream_maximum_size(stream, field); cudaMalloc(&d_stream, max_size); return d_stream; } Word *setup_device_stream_decompress(zfp_stream *stream,const zfp_field *field) { bool stream_device = cuZFP::is_gpu_ptr(stream->stream->begin); assert(sizeof(bitstream_word) == sizeof(Word)); // "CUDA version currently only supports 64bit words"); if(stream_device) { return (Word*) stream->stream->begin; } Word *d_stream = NULL; //TODO: change maximum_size to compressed stream size size_t size = zfp_stream_maximum_size(stream, field); cudaMalloc(&d_stream, size); cudaMemcpy(d_stream, stream->stream->begin, size, cudaMemcpyHostToDevice); return d_stream; } void * offset_void(zfp_type type, void *ptr, long long int offset) { void * offset_ptr = NULL; if(type == zfp_type_float) { float* data = (float*) ptr; offset_ptr = (void*)(&data[offset]); } else if(type == zfp_type_double) { double* data = (double*) ptr; offset_ptr = (void*)(&data[offset]); } else if(type == zfp_type_int32) { int * data = (int*) ptr; offset_ptr = (void*)(&data[offset]); } else if(type == zfp_type_int64) { long long int * data = (long long int*) ptr; offset_ptr = (void*)(&data[offset]); } return offset_ptr; } void *setup_device_field_compress(const zfp_field *field, const int3 &stride, long long int &offset) { bool field_device = cuZFP::is_gpu_ptr(field->data); if(field_device) { offset = 0; return field->data; } uint dims[3]; dims[0] = field->nx; dims[1] = field->ny; dims[2] = field->nz; size_t type_size = zfp_type_size(field->type); size_t field_size = 1; for(int i = 0; i < 3; ++i) { if(dims[i] != 0) { field_size *= dims[i]; } } bool contig = internal::is_contigous(dims, stride, offset); void * host_ptr = offset_void(field->type, field->data, offset);; void *d_data = NULL; if(contig) { size_t field_bytes = type_size * field_size; cudaMalloc(&d_data, field_bytes); cudaMemcpy(d_data, host_ptr, field_bytes, cudaMemcpyHostToDevice); } return offset_void(field->type, d_data, -offset); } void *setup_device_field_decompress(const zfp_field *field, const int3 &stride, long long int &offset) { bool field_device = cuZFP::is_gpu_ptr(field->data); if(field_device) { offset = 0; return field->data; } uint dims[3]; dims[0] = field->nx; dims[1] = field->ny; dims[2] = field->nz; size_t type_size = zfp_type_size(field->type); size_t field_size = 1; for(int i = 0; i < 3; ++i) { if(dims[i] != 0) { field_size *= dims[i]; } } bool contig = internal::is_contigous(dims, stride, offset); void *d_data = NULL; if(contig) { size_t field_bytes = type_size * field_size; cudaMalloc(&d_data, field_bytes); } return offset_void(field->type, d_data, -offset); } void cleanup_device_ptr(void *orig_ptr, void *d_ptr, size_t bytes, long long int offset, zfp_type type) { bool device = cuZFP::is_gpu_ptr(orig_ptr); if(device) { return; } // from whence it came void *d_offset_ptr = offset_void(type, d_ptr, offset); void *h_offset_ptr = offset_void(type, orig_ptr, offset); if(bytes > 0) { cudaMemcpy(h_offset_ptr, d_offset_ptr, bytes, cudaMemcpyDeviceToHost); } cudaFree(d_offset_ptr); } } // namespace internal size_t cuda_compress(zfp_stream *stream, const zfp_field *field) { uint dims[3]; dims[0] = field->nx; dims[1] = field->ny; dims[2] = field->nz; int3 stride; stride.x = field->sx ? field->sx : 1; stride.y = field->sy ? field->sy : field->nx; stride.z = field->sz ? field->sz : field->nx * field->ny; size_t stream_bytes = 0; long long int offset = 0; void *d_data = internal::setup_device_field_compress(field, stride, offset); if(d_data == NULL) { // null means the array is non-contiguous host mem which is not supported return 0; } Word *d_stream = internal::setup_device_stream_compress(stream, field); if(field->type == zfp_type_float) { float* data = (float*) d_data; stream_bytes = internal::encode(dims, stride, (int)stream->maxbits, data, d_stream); } else if(field->type == zfp_type_double) { double* data = (double*) d_data; stream_bytes = internal::encode(dims, stride, (int)stream->maxbits, data, d_stream); } else if(field->type == zfp_type_int32) { int * data = (int*) d_data; stream_bytes = internal::encode(dims, stride, (int)stream->maxbits, data, d_stream); } else if(field->type == zfp_type_int64) { long long int * data = (long long int*) d_data; stream_bytes = internal::encode(dims, stride, (int)stream->maxbits, data, d_stream); } internal::cleanup_device_ptr(stream->stream->begin, d_stream, stream_bytes, 0, field->type); internal::cleanup_device_ptr(field->data, d_data, 0, offset, field->type); // zfp wants to flush the stream. // set bits to wsize because we already did that. size_t compressed_size = stream_bytes / sizeof(Word); stream->stream->bits = wsize; // set stream pointer to end of stream stream->stream->ptr = stream->stream->begin + compressed_size; return stream_bytes; } void cuda_decompress(zfp_stream *stream, zfp_field *field) { uint dims[3]; dims[0] = field->nx; dims[1] = field->ny; dims[2] = field->nz; int3 stride; stride.x = field->sx ? field->sx : 1; stride.y = field->sy ? field->sy : field->nx; stride.z = field->sz ? field->sz : field->nx * field->ny; size_t decoded_bytes = 0; long long int offset = 0; void *d_data = internal::setup_device_field_decompress(field, stride, offset); if(d_data == NULL) { // null means the array is non-contiguous host mem which is not supported return; } Word *d_stream = internal::setup_device_stream_decompress(stream, field); if(field->type == zfp_type_float) { float *data = (float*) d_data; decoded_bytes = internal::decode(dims, stride, (int)stream->maxbits, d_stream, data); d_data = (void*) data; } else if(field->type == zfp_type_double) { double *data = (double*) d_data; decoded_bytes = internal::decode(dims, stride, (int)stream->maxbits, d_stream, data); d_data = (void*) data; } else if(field->type == zfp_type_int32) { int *data = (int*) d_data; decoded_bytes = internal::decode(dims, stride, (int)stream->maxbits, d_stream, data); d_data = (void*) data; } else if(field->type == zfp_type_int64) { long long int *data = (long long int*) d_data; decoded_bytes = internal::decode(dims, stride, (int)stream->maxbits, d_stream, data); d_data = (void*) data; } else { std::cerr<<"Cannot decompress: type unknown\n"; } size_t type_size = zfp_type_size(field->type); size_t field_size = 1; for(int i = 0; i < 3; ++i) { if(dims[i] != 0) { field_size *= dims[i]; } } size_t bytes = type_size * field_size; internal::cleanup_device_ptr(stream->stream->begin, d_stream, 0, 0, field->type); internal::cleanup_device_ptr(field->data, d_data, bytes, offset, field->type); // this is how zfp determines if this was a success size_t words_read = decoded_bytes / sizeof(Word); stream->stream->bits = wsize; // set stream pointer to end of stream stream->stream->ptr = stream->stream->begin + words_read; } zfp-1.0.1/src/cuda_zfp/cuZFP.h000066400000000000000000000004001453723256400160370ustar00rootroot00000000000000#ifndef cuZFP_h #define cuZFP_h #include "zfp.h" #ifdef __cplusplus extern "C" { #endif size_t cuda_compress(zfp_stream *stream, const zfp_field *field); void cuda_decompress(zfp_stream *stream, zfp_field *field); #ifdef __cplusplus } #endif #endif zfp-1.0.1/src/cuda_zfp/decode.cuh000066400000000000000000000152411453723256400166340ustar00rootroot00000000000000#ifndef CU_ZFP_DECODE_CUH #define CU_ZFP_DECODE_CUH #include "shared.h" namespace cuZFP { #if ZFP_ROUNDING_MODE == ZFP_ROUND_LAST // bias values such that truncation is equivalent to round to nearest template __device__ static void inv_round(UInt* ublock, uint m, uint prec) { // add 1/6 ulp to unbias errors if (prec < (uint)(CHAR_BIT * sizeof(UInt) - 1)) { // the first m values (0 <= m <= n) have one more bit of precision uint n = BlockSize - m; while (m--) *ublock++ += (((UInt)NBMASK >> 2) >> prec); while (n--) *ublock++ += (((UInt)NBMASK >> 1) >> prec); } } #endif // map two's complement signed integer to negabinary unsigned integer inline __device__ long long int uint2int(unsigned long long int x) { return (x ^ 0xaaaaaaaaaaaaaaaaull) - 0xaaaaaaaaaaaaaaaaull; } inline __device__ int uint2int(unsigned int x) { return (x ^ 0xaaaaaaaau) - 0xaaaaaaaau; } template class BlockReader { private: const int m_maxbits; int m_current_bit; Word *m_words; Word m_buffer; bool m_valid_block; int m_block_idx; __device__ BlockReader() : m_maxbits(0) { } public: __device__ BlockReader(Word *b, const int &maxbits, const int &block_idx, const int &num_blocks) : m_maxbits(maxbits), m_valid_block(true) { if(block_idx >= num_blocks) m_valid_block = false; size_t word_index = ((size_t)block_idx * maxbits) / (sizeof(Word) * 8); m_words = b + word_index; m_buffer = *m_words; m_current_bit = ((size_t)block_idx * maxbits) % (sizeof(Word) * 8); m_buffer >>= m_current_bit; m_block_idx = block_idx; } inline __device__ void print() { print_bits(m_buffer); } inline __device__ uint read_bit() { uint bit = m_buffer & 1; ++m_current_bit; m_buffer >>= 1; // handle moving into next word if(m_current_bit >= sizeof(Word) * 8) { m_current_bit = 0; ++m_words; m_buffer = *m_words; } return bit; } // note this assumes that n_bits is <= 64 inline __device__ uint64 read_bits(const uint &n_bits) { uint64 bits; // rem bits will always be positive int rem_bits = sizeof(Word) * 8 - m_current_bit; int first_read = min(rem_bits, n_bits); // first mask Word mask = ((Word)1<<((first_read)))-1; bits = m_buffer & mask; m_buffer >>= n_bits; m_current_bit += first_read; int next_read = 0; if(n_bits >= rem_bits) { ++m_words; m_buffer = *m_words; m_current_bit = 0; next_read = n_bits - first_read; } // this is basically a no-op when first read contained // all the bits. TODO: if we have aligned reads, this could // be a conditional without divergence mask = ((Word)1<<((next_read)))-1; bits += (m_buffer & mask) << first_read; m_buffer >>= next_read; m_current_bit += next_read; return bits; } }; // block reader template inline __device__ void decode_ints(BlockReader &reader, uint maxbits, UInt *data) { const int intprec = get_precision(); // maxprec = 64; const uint kmin = 0; //= intprec > maxprec ? intprec - maxprec : 0; uint bits = maxbits; uint k, m, n; // initialize data array to all zeros memset(data, 0, size * sizeof(UInt)); // decode one bit plane at a time from MSB to LSB for (k = intprec, m = n = 0; bits && (m = 0, k-- > kmin);) { // step 1: decode first n bits of bit plane #k m = min(n, bits); bits -= m; uint64 x = reader.read_bits(m); // step 2: unary run-length decode remainder of bit plane for (; bits && n < size; n++, m = n) { bits--; if (reader.read_bit()) { // positive group test; scan for next one-bit for (; bits && n < size - 1; n++) { bits--; if (reader.read_bit()) break; } // set bit and continue decoding bit plane x += (uint64)1 << n; } else { // negative group test; done with bit plane m = size; break; } } // step 3: deposit bit plane from x #if (CUDART_VERSION < 8000) #pragma unroll #else #pragma unroll size #endif for (uint i = 0; i < size; i++, x >>= 1) data[i] += (UInt)(x & 1u) << k; } #if ZFP_ROUNDING_MODE == ZFP_ROUND_LAST // bias values to achieve proper rounding inv_round(data, m, intprec - k); #endif } template struct inv_transform; template<> struct inv_transform<64> { template __device__ void inv_xform(Int *p) { // transform along z for (uint y = 0; y < 4; y++) for (uint x = 0; x < 4; x++) inv_lift(p + 1 * x + 4 * y); // transform along y for (uint x = 0; x < 4; x++) for (uint z = 0; z < 4; z++) inv_lift(p + 16 * z + 1 * x); // transform along x for (uint z = 0; z < 4; z++) for (uint y = 0; y < 4; y++) inv_lift(p + 4 * y + 16 * z); } }; template<> struct inv_transform<16> { template __device__ void inv_xform(Int *p) { for (uint x = 0; x < 4; ++x) inv_lift(p + 1 * x); for (uint y = 0; y < 4; ++y) inv_lift(p + 4 * y); } }; template<> struct inv_transform<4> { template __device__ void inv_xform(Int *p) { inv_lift(p); } }; template __device__ void zfp_decode(BlockReader &reader, Scalar *fblock, uint maxbits) { typedef typename zfp_traits::UInt UInt; typedef typename zfp_traits::Int Int; uint s_cont = 1; // // there is no skip path for integers so just continue // if(!is_int()) { s_cont = reader.read_bit(); } if(s_cont) { uint ebits = get_ebits() + 1; uint emax; if(!is_int()) { // read in the shared exponent emax = reader.read_bits(ebits - 1) - get_ebias(); } else { // no exponent bits ebits = 0; } maxbits -= ebits; UInt ublock[BlockSize]; decode_ints(reader, maxbits, ublock); Int iblock[BlockSize]; const unsigned char *perm = get_perm(); #if (CUDART_VERSION < 8000) #pragma unroll #else #pragma unroll BlockSize #endif for (int i = 0; i < BlockSize; ++i) iblock[perm[i]] = uint2int(ublock[i]); inv_transform trans; trans.inv_xform(iblock); Scalar inv_w = dequantize(1, emax); #if (CUDART_VERSION < 8000) #pragma unroll #else #pragma unroll BlockSize #endif for (int i = 0; i < BlockSize; ++i) fblock[i] = inv_w * (Scalar)iblock[i]; } } } // namespace cuZFP #endif zfp-1.0.1/src/cuda_zfp/decode1.cuh000066400000000000000000000070671453723256400167240ustar00rootroot00000000000000#ifndef CUZFP_DECODE1_CUH #define CUZFP_DECODE1_CUH #include "shared.h" #include "decode.cuh" #include "type_info.cuh" namespace cuZFP { template __device__ __host__ inline void scatter_partial1(const Scalar* q, Scalar* p, int nx, int sx) { uint x; for (x = 0; x < 4; x++) if (x < nx) p[x * sx] = q[x]; } template __device__ __host__ inline void scatter1(const Scalar* q, Scalar* p, int sx) { uint x; for (x = 0; x < 4; x++, p += sx) *p = *q++; } template __global__ void cudaDecode1(Word *blocks, Scalar *out, const uint dim, const int stride, const uint padded_dim, const uint total_blocks, uint maxbits) { typedef unsigned long long int ull; typedef long long int ll; typedef typename zfp_traits::UInt UInt; typedef typename zfp_traits::Int Int; const int intprec = get_precision(); const ull blockId = blockIdx.x + blockIdx.y * gridDim.x + gridDim.x * gridDim.y * blockIdx.z; // each thread gets a block so the block index is // the global thread index const ull block_idx = blockId * blockDim.x + threadIdx.x; if(block_idx >= total_blocks) return; BlockReader<4> reader(blocks, maxbits, block_idx, total_blocks); Scalar result[4] = {0,0,0,0}; zfp_decode(reader, result, maxbits); uint block; block = block_idx * 4ull; const ll offset = (ll)block * stride; bool partial = false; if(block + 4 > dim) partial = true; if(partial) { const uint nx = 4u - (padded_dim - dim); scatter_partial1(result, out + offset, nx, stride); } else { scatter1(result, out + offset, stride); } } template size_t decode1launch(uint dim, int stride, Word *stream, Scalar *d_data, uint maxbits) { const int cuda_block_size = 128; uint zfp_pad(dim); if(zfp_pad % 4 != 0) zfp_pad += 4 - dim % 4; uint zfp_blocks = (zfp_pad) / 4; if(dim % 4 != 0) zfp_blocks = (dim + (4 - dim % 4)) / 4; int block_pad = 0; if(zfp_blocks % cuda_block_size != 0) { block_pad = cuda_block_size - zfp_blocks % cuda_block_size; } size_t total_blocks = block_pad + zfp_blocks; size_t stream_bytes = calc_device_mem1d(zfp_pad, maxbits); dim3 block_size = dim3(cuda_block_size, 1, 1); dim3 grid_size = calculate_grid_size(total_blocks, cuda_block_size); #ifdef CUDA_ZFP_RATE_PRINT // setup some timing code cudaEvent_t start, stop; cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start); #endif cudaDecode1 << < grid_size, block_size >> > (stream, d_data, dim, stride, zfp_pad, zfp_blocks, // total blocks to decode maxbits); #ifdef CUDA_ZFP_RATE_PRINT cudaEventRecord(stop); cudaEventSynchronize(stop); cudaStreamSynchronize(0); float milliseconds = 0; cudaEventElapsedTime(&milliseconds, start, stop); float seconds = milliseconds / 1000.f; float rate = (float(dim) * sizeof(Scalar) ) / seconds; rate /= 1024.f; rate /= 1024.f; rate /= 1024.f; printf("Decode elapsed time: %.5f (s)\n", seconds); printf("# decode1 rate: %.2f (GB / sec) %d\n", rate, maxbits); #endif return stream_bytes; } template size_t decode1(int dim, int stride, Word *stream, Scalar *d_data, uint maxbits) { return decode1launch(dim, stride, stream, d_data, maxbits); } } // namespace cuZFP #endif zfp-1.0.1/src/cuda_zfp/decode2.cuh000066400000000000000000000104731453723256400167200ustar00rootroot00000000000000#ifndef CUZFP_DECODE2_CUH #define CUZFP_DECODE2_CUH #include "shared.h" #include "decode.cuh" #include "type_info.cuh" namespace cuZFP { template __device__ __host__ inline void scatter_partial2(const Scalar* q, Scalar* p, int nx, int ny, int sx, int sy) { uint x, y; for (y = 0; y < 4; y++) if (y < ny) { for (x = 0; x < 4; x++) if (x < nx) { *p = q[4 * y + x]; p += sx; } p += sy - nx * sx; } } template __device__ __host__ inline void scatter2(const Scalar* q, Scalar* p, int sx, int sy) { uint x, y; for (y = 0; y < 4; y++, p += sy - 4 * sx) for (x = 0; x < 4; x++, p += sx) *p = *q++; } template __global__ void cudaDecode2(Word *blocks, Scalar *out, const uint2 dims, const int2 stride, const uint2 padded_dims, uint maxbits) { typedef unsigned long long int ull; typedef long long int ll; const ull blockId = blockIdx.x + blockIdx.y * gridDim.x + gridDim.x * gridDim.y * blockIdx.z; // each thread gets a block so the block index is // the global thread index const ull block_idx = blockId * blockDim.x + threadIdx.x; const int total_blocks = (padded_dims.x * padded_dims.y) / 16; if(block_idx >= total_blocks) { return; } BlockReader reader(blocks, maxbits, block_idx, total_blocks); Scalar result[BlockSize]; memset(result, 0, sizeof(Scalar) * BlockSize); zfp_decode(reader, result, maxbits); // logical block dims uint2 block_dims; block_dims.x = padded_dims.x >> 2; block_dims.y = padded_dims.y >> 2; // logical pos in 3d array uint2 block; block.x = (block_idx % block_dims.x) * 4; block.y = ((block_idx/ block_dims.x) % block_dims.y) * 4; const ll offset = (ll)block.x * stride.x + (ll)block.y * stride.y; bool partial = false; if(block.x + 4 > dims.x) partial = true; if(block.y + 4 > dims.y) partial = true; if(partial) { const uint nx = block.x + 4 > dims.x ? dims.x - block.x : 4; const uint ny = block.y + 4 > dims.y ? dims.y - block.y : 4; scatter_partial2(result, out + offset, nx, ny, stride.x, stride.y); } else { scatter2(result, out + offset, stride.x, stride.y); } } template size_t decode2launch(uint2 dims, int2 stride, Word *stream, Scalar *d_data, uint maxbits) { const int cuda_block_size = 128; dim3 block_size; block_size = dim3(cuda_block_size, 1, 1); uint2 zfp_pad(dims); // ensure that we have block sizes // that are a multiple of 4 if(zfp_pad.x % 4 != 0) zfp_pad.x += 4 - dims.x % 4; if(zfp_pad.y % 4 != 0) zfp_pad.y += 4 - dims.y % 4; const int zfp_blocks = (zfp_pad.x * zfp_pad.y) / 16; // // we need to ensure that we launch a multiple of the // cuda block size // int block_pad = 0; if(zfp_blocks % cuda_block_size != 0) { block_pad = cuda_block_size - zfp_blocks % cuda_block_size; } size_t stream_bytes = calc_device_mem2d(zfp_pad, maxbits); size_t total_blocks = block_pad + zfp_blocks; dim3 grid_size = calculate_grid_size(total_blocks, cuda_block_size); #ifdef CUDA_ZFP_RATE_PRINT // setup some timing code cudaEvent_t start, stop; cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start); #endif cudaDecode2 << < grid_size, block_size >> > (stream, d_data, dims, stride, zfp_pad, maxbits); #ifdef CUDA_ZFP_RATE_PRINT cudaEventRecord(stop); cudaEventSynchronize(stop); cudaStreamSynchronize(0); float milliseconds = 0; cudaEventElapsedTime(&milliseconds, start, stop); float seconds = milliseconds / 1000.f; float rate = (float(dims.x * dims.y) * sizeof(Scalar) ) / seconds; rate /= 1024.f; rate /= 1024.f; rate /= 1024.f; printf("Decode elapsed time: %.5f (s)\n", seconds); printf("# decode2 rate: %.2f (GB / sec) %d\n", rate, maxbits); #endif return stream_bytes; } template size_t decode2(uint2 dims, int2 stride, Word *stream, Scalar *d_data, uint maxbits) { return decode2launch(dims, stride, stream, d_data, maxbits); } } // namespace cuZFP #endif zfp-1.0.1/src/cuda_zfp/decode3.cuh000066400000000000000000000116141453723256400167170ustar00rootroot00000000000000#ifndef CUZFP_DECODE3_CUH #define CUZFP_DECODE3_CUH #include "shared.h" #include "decode.cuh" #include "type_info.cuh" namespace cuZFP { template __device__ __host__ inline void scatter_partial3(const Scalar* q, Scalar* p, int nx, int ny, int nz, int sx, int sy, int sz) { uint x, y, z; for (z = 0; z < 4; z++) if (z < nz) { for (y = 0; y < 4; y++) if (y < ny) { for (x = 0; x < 4; x++) if (x < nx) { *p = q[16 * z + 4 * y + x]; p += sx; } p += sy - nx * sx; } p += sz - ny * sy; } } template __device__ __host__ inline void scatter3(const Scalar* q, Scalar* p, int sx, int sy, int sz) { uint x, y, z; for (z = 0; z < 4; z++, p += sz - 4 * sy) for (y = 0; y < 4; y++, p += sy - 4 * sx) for (x = 0; x < 4; x++, p += sx) *p = *q++; } template __global__ void cudaDecode3(Word *blocks, Scalar *out, const uint3 dims, const int3 stride, const uint3 padded_dims, uint maxbits) { typedef unsigned long long int ull; typedef long long int ll; const ull blockId = blockIdx.x + blockIdx.y * gridDim.x + gridDim.x * gridDim.y * blockIdx.z; // each thread gets a block so the block index is // the global thread index const ull block_idx = blockId * blockDim.x + threadIdx.x; const int total_blocks = (padded_dims.x * padded_dims.y * padded_dims.z) / 64; if(block_idx >= total_blocks) { return; } BlockReader reader(blocks, maxbits, block_idx, total_blocks); Scalar result[BlockSize]; memset(result, 0, sizeof(Scalar) * BlockSize); zfp_decode(reader, result, maxbits); // logical block dims uint3 block_dims; block_dims.x = padded_dims.x >> 2; block_dims.y = padded_dims.y >> 2; block_dims.z = padded_dims.z >> 2; // logical pos in 3d array uint3 block; block.x = (block_idx % block_dims.x) * 4; block.y = ((block_idx/ block_dims.x) % block_dims.y) * 4; block.z = (block_idx/ (block_dims.x * block_dims.y)) * 4; // default strides const ll offset = (ll)block.x * stride.x + (ll)block.y * stride.y + (ll)block.z * stride.z; bool partial = false; if(block.x + 4 > dims.x) partial = true; if(block.y + 4 > dims.y) partial = true; if(block.z + 4 > dims.z) partial = true; if(partial) { const uint nx = block.x + 4u > dims.x ? dims.x - block.x : 4; const uint ny = block.y + 4u > dims.y ? dims.y - block.y : 4; const uint nz = block.z + 4u > dims.z ? dims.z - block.z : 4; scatter_partial3(result, out + offset, nx, ny, nz, stride.x, stride.y, stride.z); } else { scatter3(result, out + offset, stride.x, stride.y, stride.z); } } template size_t decode3launch(uint3 dims, int3 stride, Word *stream, Scalar *d_data, uint maxbits) { const int cuda_block_size = 128; dim3 block_size; block_size = dim3(cuda_block_size, 1, 1); uint3 zfp_pad(dims); // ensure that we have block sizes // that are a multiple of 4 if(zfp_pad.x % 4 != 0) zfp_pad.x += 4 - dims.x % 4; if(zfp_pad.y % 4 != 0) zfp_pad.y += 4 - dims.y % 4; if(zfp_pad.z % 4 != 0) zfp_pad.z += 4 - dims.z % 4; const int zfp_blocks = (zfp_pad.x * zfp_pad.y * zfp_pad.z) / 64; // // we need to ensure that we launch a multiple of the // cuda block size // int block_pad = 0; if(zfp_blocks % cuda_block_size != 0) { block_pad = cuda_block_size - zfp_blocks % cuda_block_size; } size_t total_blocks = block_pad + zfp_blocks; size_t stream_bytes = calc_device_mem3d(zfp_pad, maxbits); dim3 grid_size = calculate_grid_size(total_blocks, cuda_block_size); #ifdef CUDA_ZFP_RATE_PRINT // setup some timing code cudaEvent_t start, stop; cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start); #endif cudaDecode3 << < grid_size, block_size >> > (stream, d_data, dims, stride, zfp_pad, maxbits); #ifdef CUDA_ZFP_RATE_PRINT cudaEventRecord(stop); cudaEventSynchronize(stop); cudaStreamSynchronize(0); float milliseconds = 0; cudaEventElapsedTime(&milliseconds, start, stop); float seconds = milliseconds / 1000.f; float rate = (float(dims.x * dims.y * dims.z) * sizeof(Scalar) ) / seconds; rate /= 1024.f; rate /= 1024.f; rate /= 1024.f; printf("Decode elapsed time: %.5f (s)\n", seconds); printf("# decode3 rate: %.2f (GB / sec) %d\n", rate, maxbits); #endif return stream_bytes; } template size_t decode3(uint3 dims, int3 stride, Word *stream, Scalar *d_data, uint maxbits) { return decode3launch(dims, stride, stream, d_data, maxbits); } } // namespace cuZFP #endif zfp-1.0.1/src/cuda_zfp/encode.cuh000066400000000000000000000276071453723256400166570ustar00rootroot00000000000000#ifndef CU_ZFP_ENCODE_CUH #define CU_ZFP_ENCODE_CUH #include "shared.h" namespace cuZFP { // maximum number of bit planes to encode __device__ static int precision(int maxexp, int maxprec, int minexp) { return min(maxprec, max(0, maxexp - minexp + 8)); } template inline __device__ void pad_block(Scalar *p, uint n, uint s) { switch (n) { case 0: p[0 * s] = 0; /* FALLTHROUGH */ case 1: p[1 * s] = p[0 * s]; /* FALLTHROUGH */ case 2: p[2 * s] = p[1 * s]; /* FALLTHROUGH */ case 3: p[3 * s] = p[0 * s]; /* FALLTHROUGH */ default: break; } } template __device__ static int exponent(Scalar x) { int e = -get_ebias(); #ifdef ZFP_WITH_DAZ // treat subnormals as zero; resolves issue #119 by avoiding overflow if (x >= get_scalar_min()) frexp(x, &e); #else if (x > 0) { frexp(x, &e); // clamp exponent in case x is subnormal; may still result in overflow e = max(e, 1 - get_ebias()); } #endif return e; } template __device__ static int max_exponent(const Scalar* p) { Scalar max_val = 0; for (int i = 0; i < BlockSize; ++i) { Scalar f = fabs(p[i]); max_val = max(max_val, f); } return exponent(max_val); } // lifting transform of 4-vector template __device__ static void fwd_lift(Int* p) { Int x = *p; p += s; Int y = *p; p += s; Int z = *p; p += s; Int w = *p; p += s; // default, non-orthogonal transform (preferred due to speed and quality) // ( 4 4 4 4) (x) // 1/16 * ( 5 1 -1 -5) (y) // (-4 4 4 -4) (z) // (-2 6 -6 2) (w) x += w; x >>= 1; w -= x; z += y; z >>= 1; y -= z; x += z; x >>= 1; z -= x; w += y; w >>= 1; y -= w; w += y >> 1; y -= w >> 1; p -= s; *p = w; p -= s; *p = z; p -= s; *p = y; p -= s; *p = x; } #if ZFP_ROUNDING_MODE == ZFP_ROUND_FIRST // bias values such that truncation is equivalent to round to nearest template __device__ static void fwd_round(Int* iblock, uint maxprec) { // add or subtract 1/6 ulp to unbias errors if (maxprec < (uint)(CHAR_BIT * sizeof(Int))) { Int bias = (static_cast::UInt>(NBMASK) >> 2) >> maxprec; uint n = BlockSize; if (maxprec & 1u) do *iblock++ += bias; while (--n); else do *iblock++ -= bias; while (--n); } } #endif template Scalar inline __device__ quantize_factor(const int &exponent, Scalar); template<> float inline __device__ quantize_factor(const int &exponent, float) { return LDEXP(1.0, get_precision() - 2 - exponent); } template<> double inline __device__ quantize_factor(const int &exponent, double) { return LDEXP(1.0, get_precision() - 2 - exponent); } template void __device__ fwd_cast(Int *iblock, const Scalar *fblock, int emax) { Scalar s = quantize_factor(emax, Scalar()); for(int i = 0; i < BlockSize; ++i) { iblock[i] = (Int) (s * fblock[i]); } } template struct transform; template<> struct transform<64> { template __device__ void fwd_xform(Int *p) { uint x, y, z; /* transform along x */ for (z = 0; z < 4; z++) for (y = 0; y < 4; y++) fwd_lift(p + 4 * y + 16 * z); /* transform along y */ for (x = 0; x < 4; x++) for (z = 0; z < 4; z++) fwd_lift(p + 16 * z + 1 * x); /* transform along z */ for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) fwd_lift(p + 1 * x + 4 * y); } }; template<> struct transform<16> { template __device__ void fwd_xform(Int *p) { uint x, y; /* transform along x */ for (y = 0; y < 4; y++) fwd_lift(p + 4 * y); /* transform along y */ for (x = 0; x < 4; x++) fwd_lift(p + 1 * x); } }; template<> struct transform<4> { template __device__ void fwd_xform(Int *p) { fwd_lift(p); } }; template __device__ void fwd_order(UInt *ublock, const Int *iblock) { const unsigned char *perm = get_perm(); for (int i = 0; i < BlockSize; ++i) { ublock[i] = int2uint(iblock[perm[i]]); } } template struct BlockWriter { uint m_word_index; uint m_start_bit; uint m_current_bit; const int m_maxbits; Word *m_stream; __device__ BlockWriter(Word *stream, const int &maxbits, const uint &block_idx) : m_current_bit(0), m_maxbits(maxbits), m_stream(stream) { m_word_index = ((size_t)block_idx * maxbits) / (sizeof(Word) * 8); m_start_bit = uint(((size_t)block_idx * maxbits) % (sizeof(Word) * 8)); } template __device__ void print_bits(T bits) { const int bit_size = sizeof(T) * 8; for(int i = bit_size - 1; i >=0; --i) { T one = 1; T mask = one << i; int val = (bits & mask) >> i; printf("%d", val); } printf("\n"); } __device__ void print(int index) { print_bits(m_stream[index]); } __device__ long long unsigned int write_bits(const long long unsigned int &bits, const uint &n_bits) { const uint wbits = sizeof(Word) * 8; uint seg_start = (m_start_bit + m_current_bit) % wbits; uint write_index = m_word_index + uint((m_start_bit + m_current_bit) / wbits); uint seg_end = seg_start + n_bits - 1; uint shift = seg_start; // we may be asked to write less bits than exist in 'bits' // so we have to make sure that anything after n is zero. // If this does not happen, then we may write into a zfp // block not at the specified index // uint zero_shift = sizeof(Word) * 8 - n_bits; Word left = (bits >> n_bits) << n_bits; Word b = bits - left; Word add = b << shift; atomicAdd(&m_stream[write_index], add); // n_bits straddles the word boundary bool straddle = seg_start < sizeof(Word) * 8 && seg_end >= sizeof(Word) * 8; if(straddle) { Word rem = b >> (sizeof(Word) * 8 - shift); atomicAdd(&m_stream[write_index + 1], rem); } m_current_bit += n_bits; return bits >> (Word)n_bits; } __device__ uint write_bit(const unsigned int &bit) { const uint wbits = sizeof(Word) * 8; uint seg_start = (m_start_bit + m_current_bit) % wbits; uint write_index = m_word_index + uint((m_start_bit + m_current_bit) / wbits); uint shift = seg_start; // we may be asked to write less bits than exist in 'bits' // so we have to make sure that anything after n is zero. // If this does not happen, then we may write into a zfp // block not at the specified index // uint zero_shift = sizeof(Word) * 8 - n_bits; Word add = (Word)bit << shift; atomicAdd(&m_stream[write_index], add); m_current_bit += 1; return bit; } }; template void inline __device__ encode_block(BlockWriter &stream, int maxbits, int maxprec, Int *iblock) { // perform decorrelating transform transform tform; tform.fwd_xform(iblock); #if ZFP_ROUNDING_MODE == ZFP_ROUND_FIRST // bias values to achieve proper rounding fwd_round(iblock, maxprec); #endif // reorder signed coefficients and convert to unsigned integer typedef typename zfp_traits::UInt UInt; UInt ublock[BlockSize]; fwd_order(ublock, iblock); // encode integer coefficients uint intprec = (uint)(CHAR_BIT * sizeof(UInt)); uint kmin = intprec > maxprec ? intprec - maxprec : 0; uint bits = maxbits; for (uint k = intprec, n = 0; bits && k-- > kmin;) { // step 1: extract bit plane #k to x uint64 x = 0; for (uint i = 0; i < BlockSize; i++) x += (uint64)((ublock[i] >> k) & 1u) << i; // step 2: encode first n bits of bit plane uint m = min(n, bits); bits -= m; x = stream.write_bits(x, m); // step 3: unary run-length encode remainder of bit plane for (; n < BlockSize && bits && (bits--, stream.write_bit(!!x)); x >>= 1, n++) for (; n < BlockSize - 1 && bits && (bits--, !stream.write_bit(x & 1u)); x >>= 1, n++) ; } } template void inline __device__ zfp_encode_block(Scalar *fblock, const int maxbits, const uint block_idx, Word *stream) { BlockWriter block_writer(stream, maxbits, block_idx); int emax = max_exponent(fblock); int maxprec = precision(emax, get_precision(), get_min_exp()); uint e = maxprec ? emax + get_ebias() : 0; if(e) { const uint ebits = get_ebits()+1; block_writer.write_bits(2 * e + 1, ebits); typedef typename zfp_traits::Int Int; Int iblock[BlockSize]; fwd_cast(iblock, fblock, emax); encode_block(block_writer, maxbits - ebits, maxprec, iblock); } } template<> void inline __device__ zfp_encode_block(int *fblock, const int maxbits, const uint block_idx, Word *stream) { BlockWriter<64> block_writer(stream, maxbits, block_idx); const int intprec = get_precision(); encode_block(block_writer, maxbits, intprec, fblock); } template<> void inline __device__ zfp_encode_block(long long int *fblock, const int maxbits, const uint block_idx, Word *stream) { BlockWriter<64> block_writer(stream, maxbits, block_idx); const int intprec = get_precision(); encode_block(block_writer, maxbits, intprec, fblock); } template<> void inline __device__ zfp_encode_block(int *fblock, const int maxbits, const uint block_idx, Word *stream) { BlockWriter<16> block_writer(stream, maxbits, block_idx); const int intprec = get_precision(); encode_block(block_writer, maxbits, intprec, fblock); } template<> void inline __device__ zfp_encode_block(long long int *fblock, const int maxbits, const uint block_idx, Word *stream) { BlockWriter<16> block_writer(stream, maxbits, block_idx); const int intprec = get_precision(); encode_block(block_writer, maxbits, intprec, fblock); } template<> void inline __device__ zfp_encode_block(int *fblock, const int maxbits, const uint block_idx, Word *stream) { BlockWriter<4> block_writer(stream, maxbits, block_idx); const int intprec = get_precision(); encode_block(block_writer, maxbits, intprec, fblock); } template<> void inline __device__ zfp_encode_block(long long int *fblock, const int maxbits, const uint block_idx, Word *stream) { BlockWriter<4> block_writer(stream, maxbits, block_idx); const int intprec = get_precision(); encode_block(block_writer, maxbits, intprec, fblock); } } // namespace cuZFP #endif zfp-1.0.1/src/cuda_zfp/encode1.cuh000066400000000000000000000074471453723256400167400ustar00rootroot00000000000000#ifndef CUZFP_ENCODE1_CUH #define CUZFP_ENCODE1_CUH #include "cuZFP.h" #include "shared.h" #include "encode.cuh" #include "type_info.cuh" #include #define ZFP_1D_BLOCK_SIZE 4 namespace cuZFP { template __device__ __host__ inline void gather_partial1(Scalar* q, const Scalar* p, int nx, int sx) { uint x; for (x = 0; x < 4; x++) if (x < nx) q[x] = p[x * sx]; pad_block(q, nx, 1); } template __device__ __host__ inline void gather1(Scalar* q, const Scalar* p, int sx) { uint x; for (x = 0; x < 4; x++, p += sx) *q++ = *p; } template __global__ void cudaEncode1(const uint maxbits, const Scalar* scalars, Word *stream, const uint dim, const int sx, const uint padded_dim, const uint tot_blocks) { typedef unsigned long long int ull; typedef long long int ll; const ull blockId = blockIdx.x + blockIdx.y * gridDim.x + gridDim.x * gridDim.y * blockIdx.z; // each thread gets a block so the block index is // the global thread index const uint block_idx = blockId * blockDim.x + threadIdx.x; if(block_idx >= tot_blocks) { // we can't launch the exact number of blocks // so just exit if this isn't real return; } uint block_dim; block_dim = padded_dim >> 2; // logical pos in 3d array uint block; block = (block_idx % block_dim) * 4; const ll offset = (ll)block * sx; Scalar fblock[ZFP_1D_BLOCK_SIZE]; bool partial = false; if(block + 4 > dim) partial = true; if(partial) { uint nx = 4 - (padded_dim - dim); gather_partial1(fblock, scalars + offset, nx, sx); } else { gather1(fblock, scalars + offset, sx); } zfp_encode_block(fblock, maxbits, block_idx, stream); } // // Launch the encode kernel // template size_t encode1launch(uint dim, int sx, const Scalar *d_data, Word *stream, const int maxbits) { const int cuda_block_size = 128; dim3 block_size = dim3(cuda_block_size, 1, 1); uint zfp_pad(dim); if(zfp_pad % 4 != 0) zfp_pad += 4 - dim % 4; const uint zfp_blocks = (zfp_pad) / 4; // // we need to ensure that we launch a multiple of the // cuda block size // int block_pad = 0; if(zfp_blocks % cuda_block_size != 0) { block_pad = cuda_block_size - zfp_blocks % cuda_block_size; } size_t total_blocks = block_pad + zfp_blocks; dim3 grid_size = calculate_grid_size(total_blocks, cuda_block_size); // size_t stream_bytes = calc_device_mem1d(zfp_pad, maxbits); // ensure we have zeros cudaMemset(stream, 0, stream_bytes); #ifdef CUDA_ZFP_RATE_PRINT cudaEvent_t start, stop; cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start); #endif cudaEncode1 <<>> (maxbits, d_data, stream, dim, sx, zfp_pad, zfp_blocks); #ifdef CUDA_ZFP_RATE_PRINT cudaEventRecord(stop); cudaEventSynchronize(stop); cudaStreamSynchronize(0); float milliseconds = 0.f; cudaEventElapsedTime(&milliseconds, start, stop); float seconds = milliseconds / 1000.f; float gb = (float(dim) * float(sizeof(Scalar))) / (1024.f * 1024.f * 1024.f); float rate = gb / seconds; printf("Encode elapsed time: %.5f (s)\n", seconds); printf("# encode1 rate: %.2f (GB / sec) %d\n", rate, maxbits); #endif return stream_bytes; } // // Encode a host vector and output a encoded device vector // template size_t encode1(int dim, int sx, Scalar *d_data, Word *stream, const int maxbits) { return encode1launch(dim, sx, d_data, stream, maxbits); } } #endif zfp-1.0.1/src/cuda_zfp/encode2.cuh000066400000000000000000000107261453723256400167330ustar00rootroot00000000000000#ifndef CUZFP_ENCODE2_CUH #define CUZFP_ENCODE2_CUH #include "cuZFP.h" #include "shared.h" #include "encode.cuh" #include "ErrorCheck.h" #include "type_info.cuh" #define ZFP_2D_BLOCK_SIZE 16 namespace cuZFP { template __device__ __host__ inline void gather_partial2(Scalar* q, const Scalar* p, int nx, int ny, int sx, int sy) { uint x, y; for (y = 0; y < 4; y++) if (y < ny) { for (x = 0; x < 4; x++) if (x < nx) { q[4 * y + x] = *p;//[x * sx]; p += sx; } pad_block(q + 4 * y, nx, 1); p += sy - nx * sx; } for (x = 0; x < 4; x++) pad_block(q + x, ny, 4); } template __device__ __host__ inline void gather2(Scalar* q, const Scalar* p, int sx, int sy) { uint x, y; for (y = 0; y < 4; y++, p += sy - 4 * sx) for (x = 0; x < 4; x++, p += sx) *q++ = *p; } template __global__ void cudaEncode2(const uint maxbits, const Scalar* scalars, Word *stream, const uint2 dims, const int2 stride, const uint2 padded_dims, const uint tot_blocks) { typedef unsigned long long int ull; typedef long long int ll; const ull blockId = blockIdx.x + blockIdx.y * gridDim.x + gridDim.x * gridDim.y * blockIdx.z; // each thread gets a block so the block index is // the global thread index const uint block_idx = blockId * blockDim.x + threadIdx.x; if(block_idx >= tot_blocks) { // we can't launch the exact number of blocks // so just exit if this isn't real return; } uint2 block_dims; block_dims.x = padded_dims.x >> 2; block_dims.y = padded_dims.y >> 2; // logical pos in 3d array uint2 block; block.x = (block_idx % block_dims.x) * 4; block.y = ((block_idx/ block_dims.x) % block_dims.y) * 4; const ll offset = (ll)block.x * stride.x + (ll)block.y * stride.y; Scalar fblock[ZFP_2D_BLOCK_SIZE]; bool partial = false; if(block.x + 4 > dims.x) partial = true; if(block.y + 4 > dims.y) partial = true; if(partial) { const uint nx = block.x + 4 > dims.x ? dims.x - block.x : 4; const uint ny = block.y + 4 > dims.y ? dims.y - block.y : 4; gather_partial2(fblock, scalars + offset, nx, ny, stride.x, stride.y); } else { gather2(fblock, scalars + offset, stride.x, stride.y); } zfp_encode_block(fblock, maxbits, block_idx, stream); } // // Launch the encode kernel // template size_t encode2launch(uint2 dims, int2 stride, const Scalar *d_data, Word *stream, const int maxbits) { const int cuda_block_size = 128; dim3 block_size = dim3(cuda_block_size, 1, 1); uint2 zfp_pad(dims); if(zfp_pad.x % 4 != 0) zfp_pad.x += 4 - dims.x % 4; if(zfp_pad.y % 4 != 0) zfp_pad.y += 4 - dims.y % 4; const uint zfp_blocks = (zfp_pad.x * zfp_pad.y) / 16; // // we need to ensure that we launch a multiple of the // cuda block size // int block_pad = 0; if(zfp_blocks % cuda_block_size != 0) { block_pad = cuda_block_size - zfp_blocks % cuda_block_size; } size_t total_blocks = block_pad + zfp_blocks; dim3 grid_size = calculate_grid_size(total_blocks, cuda_block_size); // size_t stream_bytes = calc_device_mem2d(zfp_pad, maxbits); // ensure we have zeros cudaMemset(stream, 0, stream_bytes); #ifdef CUDA_ZFP_RATE_PRINT cudaEvent_t start, stop; cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start); #endif cudaEncode2 <<>> (maxbits, d_data, stream, dims, stride, zfp_pad, zfp_blocks); #ifdef CUDA_ZFP_RATE_PRINT cudaDeviceSynchronize(); cudaEventRecord(stop); cudaEventSynchronize(stop); cudaStreamSynchronize(0); float milliseconds = 0.f; cudaEventElapsedTime(&milliseconds, start, stop); float seconds = milliseconds / 1000.f; float mb = (float(dims.x * dims.y) * sizeof(Scalar)) / (1024.f * 1024.f *1024.f); float rate = mb / seconds; printf("Encode elapsed time: %.5f (s)\n", seconds); printf("# encode2 rate: %.2f (GB / sec) %d\n", rate, maxbits); #endif return stream_bytes; } template size_t encode2(uint2 dims, int2 stride, Scalar *d_data, Word *stream, const int maxbits) { return encode2launch(dims, stride, d_data, stream, maxbits); } } #endif zfp-1.0.1/src/cuda_zfp/encode3.cuh000066400000000000000000000121511453723256400167260ustar00rootroot00000000000000#ifndef CUZFP_ENCODE3_CUH #define CUZFP_ENCODE3_CUH #include "cuZFP.h" #include "shared.h" #include "encode.cuh" #include "type_info.cuh" #define ZFP_3D_BLOCK_SIZE 64 namespace cuZFP{ template __device__ __host__ inline void gather_partial3(Scalar* q, const Scalar* p, int nx, int ny, int nz, int sx, int sy, int sz) { uint x, y, z; for (z = 0; z < 4; z++) if (z < nz) { for (y = 0; y < 4; y++) if (y < ny) { for (x = 0; x < 4; x++) if (x < nx) { q[16 * z + 4 * y + x] = *p; p += sx; } p += sy - nx * sx; pad_block(q + 16 * z + 4 * y, nx, 1); } for (x = 0; x < 4; x++) pad_block(q + 16 * z + x, ny, 4); p += sz - ny * sy; } for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) pad_block(q + 4 * y + x, nz, 16); } template __device__ __host__ inline void gather3(Scalar* q, const Scalar* p, int sx, int sy, int sz) { uint x, y, z; for (z = 0; z < 4; z++, p += sz - 4 * sy) for (y = 0; y < 4; y++, p += sy - 4 * sx) for (x = 0; x < 4; x++, p += sx) *q++ = *p; } template __global__ void cudaEncode(const uint maxbits, const Scalar* scalars, Word *stream, const uint3 dims, const int3 stride, const uint3 padded_dims, const uint tot_blocks) { typedef unsigned long long int ull; typedef long long int ll; const ull blockId = blockIdx.x + blockIdx.y * gridDim.x + gridDim.x * gridDim.y * blockIdx.z; // each thread gets a block so the block index is // the global thread index const uint block_idx = blockId * blockDim.x + threadIdx.x; if(block_idx >= tot_blocks) { // we can't launch the exact number of blocks // so just exit if this isn't real return; } uint3 block_dims; block_dims.x = padded_dims.x >> 2; block_dims.y = padded_dims.y >> 2; block_dims.z = padded_dims.z >> 2; // logical pos in 3d array uint3 block; block.x = (block_idx % block_dims.x) * 4; block.y = ((block_idx/ block_dims.x) % block_dims.y) * 4; block.z = (block_idx/ (block_dims.x * block_dims.y)) * 4; // default strides ll offset = (ll)block.x * stride.x + (ll)block.y * stride.y + (ll)block.z * stride.z; Scalar fblock[ZFP_3D_BLOCK_SIZE]; bool partial = false; if(block.x + 4 > dims.x) partial = true; if(block.y + 4 > dims.y) partial = true; if(block.z + 4 > dims.z) partial = true; if(partial) { const uint nx = block.x + 4 > dims.x ? dims.x - block.x : 4; const uint ny = block.y + 4 > dims.y ? dims.y - block.y : 4; const uint nz = block.z + 4 > dims.z ? dims.z - block.z : 4; gather_partial3(fblock, scalars + offset, nx, ny, nz, stride.x, stride.y, stride.z); } else { gather3(fblock, scalars + offset, stride.x, stride.y, stride.z); } zfp_encode_block(fblock, maxbits, block_idx, stream); } // // Launch the encode kernel // template size_t encode3launch(uint3 dims, int3 stride, const Scalar *d_data, Word *stream, const int maxbits) { const int cuda_block_size = 128; dim3 block_size = dim3(cuda_block_size, 1, 1); uint3 zfp_pad(dims); if(zfp_pad.x % 4 != 0) zfp_pad.x += 4 - dims.x % 4; if(zfp_pad.y % 4 != 0) zfp_pad.y += 4 - dims.y % 4; if(zfp_pad.z % 4 != 0) zfp_pad.z += 4 - dims.z % 4; const uint zfp_blocks = (zfp_pad.x * zfp_pad.y * zfp_pad.z) / 64; // // we need to ensure that we launch a multiple of the // cuda block size // int block_pad = 0; if(zfp_blocks % cuda_block_size != 0) { block_pad = cuda_block_size - zfp_blocks % cuda_block_size; } size_t total_blocks = block_pad + zfp_blocks; dim3 grid_size = calculate_grid_size(total_blocks, cuda_block_size); size_t stream_bytes = calc_device_mem3d(zfp_pad, maxbits); //ensure we start with 0s cudaMemset(stream, 0, stream_bytes); #ifdef CUDA_ZFP_RATE_PRINT cudaEvent_t start, stop; cudaEventCreate(&start); cudaEventCreate(&stop); cudaEventRecord(start); #endif cudaEncode <<>> (maxbits, d_data, stream, dims, stride, zfp_pad, zfp_blocks); #ifdef CUDA_ZFP_RATE_PRINT cudaEventRecord(stop); cudaEventSynchronize(stop); cudaStreamSynchronize(0); float milliseconds = 0; cudaEventElapsedTime(&milliseconds, start, stop); float seconds = milliseconds / 1000.f; float rate = (float(dims.x * dims.y * dims.z) * sizeof(Scalar) ) / seconds; rate /= 1024.f; rate /= 1024.f; rate /= 1024.f; printf("Encode elapsed time: %.5f (s)\n", seconds); printf("# encode3 rate: %.2f (GB / sec) \n", rate); #endif return stream_bytes; } // // Just pass the raw pointer to the "real" encode // template size_t encode(uint3 dims, int3 stride, Scalar *d_data, Word *stream, const int bits_per_block) { return encode3launch(dims, stride, d_data, stream, bits_per_block); } } #endif zfp-1.0.1/src/cuda_zfp/pointers.cuh000066400000000000000000000013171453723256400172530ustar00rootroot00000000000000#ifndef CUZFP_POINTERS_CUH #define CUZFP_POINTERS_CUH #include "ErrorCheck.h" #include namespace cuZFP { // https://gitlab.kitware.com/third-party/nvpipe/blob/master/encode.c bool is_gpu_ptr(const void *ptr) { cudaPointerAttributes atts; const cudaError_t perr = cudaPointerGetAttributes(&atts, ptr); // clear last error so other error checking does // not pick it up cudaError_t error = cudaGetLastError(); #if CUDART_VERSION >= 10000 return perr == cudaSuccess && (atts.type == cudaMemoryTypeDevice || atts.type == cudaMemoryTypeManaged); #else return perr == cudaSuccess && atts.memoryType == cudaMemoryTypeDevice; #endif } } // namespace cuZFP #endif zfp-1.0.1/src/cuda_zfp/shared.h000066400000000000000000000136131453723256400163300ustar00rootroot00000000000000#ifndef CUZFP_SHARED_H #define CUZFP_SHARED_H //#define CUDA_ZFP_RATE_PRINT 1 typedef unsigned long long Word; #define Wsize ((uint)(CHAR_BIT * sizeof(Word))) #include "type_info.cuh" #include "zfp.h" #include "constants.h" #include #define MAX(x, y) ((x) > (y) ? (x) : (y)) #define MIN(x, y) ((x) < (y) ? (x) : (y)) #define bitsize(x) ((uint)(CHAR_BIT * sizeof(x))) #define LDEXP(x, e) ldexp(x, e) #define NBMASK 0xaaaaaaaaaaaaaaaaull namespace cuZFP { template __device__ void print_bits(const T &bits) { const int bit_size = sizeof(T) * 8; for(int i = bit_size - 1; i >= 0; --i) { T one = 1; T mask = one << i; T val = (bits & mask) >> i ; printf("%d", (int) val); } printf("\n"); } size_t calc_device_mem1d(const int dim, const int maxbits) { const size_t vals_per_block = 4; size_t total_blocks = dim / vals_per_block; if(dim % vals_per_block != 0) { total_blocks++; } const size_t bits_per_block = maxbits; const size_t bits_per_word = sizeof(Word) * 8; const size_t total_bits = bits_per_block * total_blocks; size_t alloc_size = total_bits / bits_per_word; if(total_bits % bits_per_word != 0) alloc_size++; // ensure we have zeros return alloc_size * sizeof(Word); } size_t calc_device_mem2d(const uint2 dims, const int maxbits) { const size_t vals_per_block = 16; size_t total_blocks = (dims.x * dims.y) / vals_per_block; if((dims.x * dims.y) % vals_per_block != 0) total_blocks++; const size_t bits_per_block = maxbits; const size_t bits_per_word = sizeof(Word) * 8; const size_t total_bits = bits_per_block * total_blocks; size_t alloc_size = total_bits / bits_per_word; if(total_bits % bits_per_word != 0) alloc_size++; return alloc_size * sizeof(Word); } size_t calc_device_mem3d(const uint3 encoded_dims, const int bits_per_block) { const size_t vals_per_block = 64; const size_t size = encoded_dims.x * encoded_dims.y * encoded_dims.z; size_t total_blocks = size / vals_per_block; const size_t bits_per_word = sizeof(Word) * 8; const size_t total_bits = bits_per_block * total_blocks; const size_t alloc_size = total_bits / bits_per_word; return alloc_size * sizeof(Word); } dim3 get_max_grid_dims() { static cudaDeviceProp prop; static bool firstTime = true; if( firstTime ) { firstTime = false; int device = 0; cudaGetDeviceProperties(&prop, device); } dim3 grid_dims; grid_dims.x = prop.maxGridSize[0]; grid_dims.y = prop.maxGridSize[1]; grid_dims.z = prop.maxGridSize[2]; return grid_dims; } // size is assumed to have a pad to the nearest cuda block size dim3 calculate_grid_size(size_t size, size_t cuda_block_size) { size_t grids = size / cuda_block_size; // because of pad this will be exact dim3 max_grid_dims = get_max_grid_dims(); int dims = 1; // check to see if we need to add more grids if( grids > max_grid_dims.x) { dims = 2; } if(grids > max_grid_dims.x * max_grid_dims.y) { dims = 3; } dim3 grid_size; grid_size.x = 1; grid_size.y = 1; grid_size.z = 1; if(dims == 1) { grid_size.x = grids; } if(dims == 2) { float sq_r = sqrt((float)grids); float intpart = 0; modf(sq_r,&intpart); uint base = intpart; grid_size.x = base; grid_size.y = base; // figure out how many y to add uint rem = (size - base * base); uint y_rows = rem / base; if(rem % base != 0) y_rows ++; grid_size.y += y_rows; } if(dims == 3) { float cub_r = pow((float)grids, 1.f/3.f);; float intpart = 0; modf(cub_r,&intpart); int base = intpart; grid_size.x = base; grid_size.y = base; grid_size.z = base; // figure out how many z to add uint rem = (size - base * base * base); uint z_rows = rem / (base * base); if(rem % (base * base) != 0) z_rows ++; grid_size.z += z_rows; } return grid_size; } // map two's complement signed integer to negabinary unsigned integer inline __device__ unsigned long long int int2uint(const long long int x) { return (x + (unsigned long long int)0xaaaaaaaaaaaaaaaaull) ^ (unsigned long long int)0xaaaaaaaaaaaaaaaaull; } inline __device__ unsigned int int2uint(const int x) { return (x + (unsigned int)0xaaaaaaaau) ^ (unsigned int)0xaaaaaaaau; } template __device__ Scalar dequantize(const Int &x, const int &e); template<> __device__ double dequantize(const long long int &x, const int &e) { return LDEXP((double)x, e - ((int)(CHAR_BIT * scalar_sizeof()) - 2)); } template<> __device__ float dequantize(const int &x, const int &e) { return LDEXP((float)x, e - ((int)(CHAR_BIT * scalar_sizeof()) - 2)); } template<> __device__ int dequantize(const int &x, const int &e) { return 1; } template<> __device__ long long int dequantize(const long long int &x, const int &e) { return 1; } /* inverse lifting transform of 4-vector */ template __device__ static void inv_lift(Int* p) { Int x, y, z, w; x = *p; p += s; y = *p; p += s; z = *p; p += s; w = *p; p += s; /* ** non-orthogonal transform ** ( 4 6 -4 -1) (x) ** 1/4 * ( 4 2 4 5) (y) ** ( 4 -2 4 -5) (z) ** ( 4 -6 -4 1) (w) */ y += w >> 1; w -= y >> 1; y += w; w <<= 1; w -= y; z += x; x <<= 1; x -= z; y += z; z <<= 1; z -= y; w += x; x <<= 1; x -= w; p -= s; *p = w; p -= s; *p = z; p -= s; *p = y; p -= s; *p = x; } template __device__ inline const unsigned char* get_perm(); template<> __device__ inline const unsigned char* get_perm<64>() { return perm_3d; } template<> __device__ inline const unsigned char* get_perm<16>() { return perm_2; } template<> __device__ inline const unsigned char* get_perm<4>() { return perm_1; } } // namespace cuZFP #endif zfp-1.0.1/src/cuda_zfp/type_info.cuh000066400000000000000000000071241453723256400174060ustar00rootroot00000000000000#ifndef cuZFP_TYPE_INFO #define cuZFP_TYPE_INFO #include namespace cuZFP { template inline __host__ __device__ int get_ebias(); template<> inline __host__ __device__ int get_ebias() { return 1023; } template<> inline __host__ __device__ int get_ebias() { return 127; } template<> inline __host__ __device__ int get_ebias() { return 0; } template<> inline __host__ __device__ int get_ebias() { return 0; } template inline __host__ __device__ int get_ebits(); template<> inline __host__ __device__ int get_ebits() { return 11; } template<> inline __host__ __device__ int get_ebits() { return 8; } template<> inline __host__ __device__ int get_ebits() { return 0; } template<> inline __host__ __device__ int get_ebits() { return 0; } template inline __host__ __device__ int get_precision(); template<> inline __host__ __device__ int get_precision() { return 64; } template<> inline __host__ __device__ int get_precision() { return 64; } template<> inline __host__ __device__ int get_precision() { return 32; } template<> inline __host__ __device__ int get_precision() { return 32; } template inline __host__ __device__ int get_min_exp(); template<> inline __host__ __device__ int get_min_exp() { return -1074; } template<> inline __host__ __device__ int get_min_exp() { return -1074; } template<> inline __host__ __device__ int get_min_exp() { return 0; } template<> inline __host__ __device__ int get_min_exp() { return 0; } template inline __host__ __device__ T get_scalar_min(); template<> inline __host__ __device__ float get_scalar_min() { return FLT_MIN; } template<> inline __host__ __device__ double get_scalar_min() { return DBL_MIN; } template<> inline __host__ __device__ long long int get_scalar_min() { return 0; } template<> inline __host__ __device__ int get_scalar_min() { return 0; } template inline __host__ __device__ int scalar_sizeof(); template<> inline __host__ __device__ int scalar_sizeof() { return 8; } template<> inline __host__ __device__ int scalar_sizeof() { return 8; } template<> inline __host__ __device__ int scalar_sizeof() { return 4; } template<> inline __host__ __device__ int scalar_sizeof() { return 4; } template inline __host__ __device__ T get_nbmask(); template<> inline __host__ __device__ unsigned int get_nbmask() { return 0xaaaaaaaau; } template<> inline __host__ __device__ unsigned long long int get_nbmask() { return 0xaaaaaaaaaaaaaaaaull; } template struct zfp_traits; template<> struct zfp_traits { typedef unsigned long long int UInt; typedef long long int Int; }; template<> struct zfp_traits { typedef unsigned long long int UInt; typedef long long int Int; }; template<> struct zfp_traits { typedef unsigned int UInt; typedef int Int; }; template<> struct zfp_traits { typedef unsigned int UInt; typedef int Int; }; template inline __host__ __device__ bool is_int() { return false; } template<> inline __host__ __device__ bool is_int() { return true; } template<> inline __host__ __device__ bool is_int() { return true; } #if 0 template struct block_traits; template<> struct block_traits<1> { typedef unsigned char PlaneType; }; template<> struct block_traits<2> { typedef unsigned short PlaneType; }; #endif } // namespace cuZFP #endif zfp-1.0.1/src/decode1d.c000066400000000000000000000010151453723256400147230ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block1.h" #include "traitsd.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec1.c" #include "template/decode.c" #include "template/decodef.c" #include "template/decode1.c" #include "template/revcodecf.c" #include "template/revdecode.c" #include "template/revdecodef.c" #include "template/revdecode1.c" zfp-1.0.1/src/decode1f.c000066400000000000000000000010151453723256400147250ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block1.h" #include "traitsf.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec1.c" #include "template/decode.c" #include "template/decodef.c" #include "template/decode1.c" #include "template/revcodecf.c" #include "template/revdecode.c" #include "template/revdecodef.c" #include "template/revdecode1.c" zfp-1.0.1/src/decode1i.c000066400000000000000000000006571453723256400147430ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block1.h" #include "traitsi.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec1.c" #include "template/decode.c" #include "template/decodei.c" #include "template/decode1.c" #include "template/revdecode.c" #include "template/revdecode1.c" zfp-1.0.1/src/decode1l.c000066400000000000000000000006571453723256400147460ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block1.h" #include "traitsl.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec1.c" #include "template/decode.c" #include "template/decodei.c" #include "template/decode1.c" #include "template/revdecode.c" #include "template/revdecode1.c" zfp-1.0.1/src/decode2d.c000066400000000000000000000010151453723256400147240ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block2.h" #include "traitsd.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec2.c" #include "template/decode.c" #include "template/decodef.c" #include "template/decode2.c" #include "template/revcodecf.c" #include "template/revdecode.c" #include "template/revdecodef.c" #include "template/revdecode2.c" zfp-1.0.1/src/decode2f.c000066400000000000000000000010151453723256400147260ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block2.h" #include "traitsf.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec2.c" #include "template/decode.c" #include "template/decodef.c" #include "template/decode2.c" #include "template/revcodecf.c" #include "template/revdecode.c" #include "template/revdecodef.c" #include "template/revdecode2.c" zfp-1.0.1/src/decode2i.c000066400000000000000000000006571453723256400147440ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block2.h" #include "traitsi.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec2.c" #include "template/decode.c" #include "template/decodei.c" #include "template/decode2.c" #include "template/revdecode.c" #include "template/revdecode2.c" zfp-1.0.1/src/decode2l.c000066400000000000000000000006571453723256400147470ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block2.h" #include "traitsl.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec2.c" #include "template/decode.c" #include "template/decodei.c" #include "template/decode2.c" #include "template/revdecode.c" #include "template/revdecode2.c" zfp-1.0.1/src/decode3d.c000066400000000000000000000010151453723256400147250ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block3.h" #include "traitsd.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec3.c" #include "template/decode.c" #include "template/decodef.c" #include "template/decode3.c" #include "template/revcodecf.c" #include "template/revdecode.c" #include "template/revdecodef.c" #include "template/revdecode3.c" zfp-1.0.1/src/decode3f.c000066400000000000000000000010151453723256400147270ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block3.h" #include "traitsf.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec3.c" #include "template/decode.c" #include "template/decodef.c" #include "template/decode3.c" #include "template/revcodecf.c" #include "template/revdecode.c" #include "template/revdecodef.c" #include "template/revdecode3.c" zfp-1.0.1/src/decode3i.c000066400000000000000000000006571453723256400147450ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block3.h" #include "traitsi.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec3.c" #include "template/decode.c" #include "template/decodei.c" #include "template/decode3.c" #include "template/revdecode.c" #include "template/revdecode3.c" zfp-1.0.1/src/decode3l.c000066400000000000000000000006571453723256400147500ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block3.h" #include "traitsl.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec3.c" #include "template/decode.c" #include "template/decodei.c" #include "template/decode3.c" #include "template/revdecode.c" #include "template/revdecode3.c" zfp-1.0.1/src/decode4d.c000066400000000000000000000010151453723256400147260ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block4.h" #include "traitsd.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec4.c" #include "template/decode.c" #include "template/decodef.c" #include "template/decode4.c" #include "template/revcodecf.c" #include "template/revdecode.c" #include "template/revdecodef.c" #include "template/revdecode4.c" zfp-1.0.1/src/decode4f.c000066400000000000000000000010151453723256400147300ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block4.h" #include "traitsf.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec4.c" #include "template/decode.c" #include "template/decodef.c" #include "template/decode4.c" #include "template/revcodecf.c" #include "template/revdecode.c" #include "template/revdecodef.c" #include "template/revdecode4.c" zfp-1.0.1/src/decode4i.c000066400000000000000000000006571453723256400147460ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block4.h" #include "traitsi.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec4.c" #include "template/decode.c" #include "template/decodei.c" #include "template/decode4.c" #include "template/revdecode.c" #include "template/revdecode4.c" zfp-1.0.1/src/decode4l.c000066400000000000000000000006571453723256400147510ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block4.h" #include "traitsl.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec4.c" #include "template/decode.c" #include "template/decodei.c" #include "template/decode4.c" #include "template/revdecode.c" #include "template/revdecode4.c" zfp-1.0.1/src/encode1d.c000066400000000000000000000010151453723256400147350ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block1.h" #include "traitsd.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec1.c" #include "template/encode.c" #include "template/encodef.c" #include "template/encode1.c" #include "template/revcodecf.c" #include "template/revencode.c" #include "template/revencodef.c" #include "template/revencode1.c" zfp-1.0.1/src/encode1f.c000066400000000000000000000010151453723256400147370ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block1.h" #include "traitsf.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec1.c" #include "template/encode.c" #include "template/encodef.c" #include "template/encode1.c" #include "template/revcodecf.c" #include "template/revencode.c" #include "template/revencodef.c" #include "template/revencode1.c" zfp-1.0.1/src/encode1i.c000066400000000000000000000006571453723256400147550ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block1.h" #include "traitsi.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec1.c" #include "template/encode.c" #include "template/encodei.c" #include "template/encode1.c" #include "template/revencode.c" #include "template/revencode1.c" zfp-1.0.1/src/encode1l.c000066400000000000000000000006571453723256400147600ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block1.h" #include "traitsl.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec1.c" #include "template/encode.c" #include "template/encodei.c" #include "template/encode1.c" #include "template/revencode.c" #include "template/revencode1.c" zfp-1.0.1/src/encode2d.c000066400000000000000000000010151453723256400147360ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block2.h" #include "traitsd.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec2.c" #include "template/encode.c" #include "template/encodef.c" #include "template/encode2.c" #include "template/revcodecf.c" #include "template/revencode.c" #include "template/revencodef.c" #include "template/revencode2.c" zfp-1.0.1/src/encode2f.c000066400000000000000000000010151453723256400147400ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block2.h" #include "traitsf.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec2.c" #include "template/encode.c" #include "template/encodef.c" #include "template/encode2.c" #include "template/revcodecf.c" #include "template/revencode.c" #include "template/revencodef.c" #include "template/revencode2.c" zfp-1.0.1/src/encode2i.c000066400000000000000000000006571453723256400147560ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block2.h" #include "traitsi.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec2.c" #include "template/encode.c" #include "template/encodei.c" #include "template/encode2.c" #include "template/revencode.c" #include "template/revencode2.c" zfp-1.0.1/src/encode2l.c000066400000000000000000000006571453723256400147610ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block2.h" #include "traitsl.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec2.c" #include "template/encode.c" #include "template/encodei.c" #include "template/encode2.c" #include "template/revencode.c" #include "template/revencode2.c" zfp-1.0.1/src/encode3d.c000066400000000000000000000010151453723256400147370ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block3.h" #include "traitsd.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec3.c" #include "template/encode.c" #include "template/encodef.c" #include "template/encode3.c" #include "template/revcodecf.c" #include "template/revencode.c" #include "template/revencodef.c" #include "template/revencode3.c" zfp-1.0.1/src/encode3f.c000066400000000000000000000010151453723256400147410ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block3.h" #include "traitsf.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec3.c" #include "template/encode.c" #include "template/encodef.c" #include "template/encode3.c" #include "template/revcodecf.c" #include "template/revencode.c" #include "template/revencodef.c" #include "template/revencode3.c" zfp-1.0.1/src/encode3i.c000066400000000000000000000006571453723256400147570ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block3.h" #include "traitsi.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec3.c" #include "template/encode.c" #include "template/encodei.c" #include "template/encode3.c" #include "template/revencode.c" #include "template/revencode3.c" zfp-1.0.1/src/encode3l.c000066400000000000000000000006571453723256400147620ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block3.h" #include "traitsl.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec3.c" #include "template/encode.c" #include "template/encodei.c" #include "template/encode3.c" #include "template/revencode.c" #include "template/revencode3.c" zfp-1.0.1/src/encode4d.c000066400000000000000000000010151453723256400147400ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block4.h" #include "traitsd.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec4.c" #include "template/encode.c" #include "template/encodef.c" #include "template/encode4.c" #include "template/revcodecf.c" #include "template/revencode.c" #include "template/revencodef.c" #include "template/revencode4.c" zfp-1.0.1/src/encode4f.c000066400000000000000000000010151453723256400147420ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block4.h" #include "traitsf.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codecf.c" #include "template/codec4.c" #include "template/encode.c" #include "template/encodef.c" #include "template/encode4.c" #include "template/revcodecf.c" #include "template/revencode.c" #include "template/revencodef.c" #include "template/revencode4.c" zfp-1.0.1/src/encode4i.c000066400000000000000000000006571453723256400147600ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block4.h" #include "traitsi.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec4.c" #include "template/encode.c" #include "template/encodei.c" #include "template/encode4.c" #include "template/revencode.c" #include "template/revencode4.c" zfp-1.0.1/src/encode4l.c000066400000000000000000000006571453723256400147630ustar00rootroot00000000000000#include "zfp/internal/zfp/inline.h" #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "block4.h" #include "traitsl.h" #include "template/template.h" #include "template/codec.h" #include "zfp/bitstream.inl" #include "template/codec.c" #include "template/codec4.c" #include "template/encode.c" #include "template/encodei.c" #include "template/encode4.c" #include "template/revencode.c" #include "template/revencode4.c" zfp-1.0.1/src/share/000077500000000000000000000000001453723256400142145ustar00rootroot00000000000000zfp-1.0.1/src/share/omp.c000066400000000000000000000015641453723256400151610ustar00rootroot00000000000000#ifdef _OPENMP #include #include #include "zfp.h" /* number of omp threads to use */ static uint thread_count_omp(const zfp_stream* stream) { uint count = zfp_stream_omp_threads(stream); /* if no thread count is specified, use default number of threads */ if (!count) count = omp_get_max_threads(); return count; } /* number of chunks to partition array into */ static size_t chunk_count_omp(const zfp_stream* stream, size_t blocks, uint threads) { size_t chunk_size = (size_t)zfp_stream_omp_chunk_size(stream); /* if no chunk size is specified, assign one chunk per thread */ size_t chunks = chunk_size ? (blocks + chunk_size - 1) / chunk_size : threads; /* each chunk must contain at least one block */ chunks = MIN(chunks, blocks); /* OpenMP 2.0 loop counters must be ints */ chunks = MIN(chunks, INT_MAX); return chunks; } #endif zfp-1.0.1/src/share/parallel.c000066400000000000000000000052071453723256400161600ustar00rootroot00000000000000#ifdef _OPENMP /* block index at which chunk begins */ static size_t chunk_offset(size_t blocks, size_t chunks, size_t chunk) { return (size_t)(((uint64)blocks * (uint64)chunk) / chunks); } /* initialize per-thread bit streams for parallel compression */ static bitstream** compress_init_par(zfp_stream* stream, const zfp_field* field, size_t chunks, size_t blocks) { bitstream** bs; zfp_bool copy; size_t n = 4 * (blocks + chunks - 1) / chunks; size_t size; size_t chunk; /* determine maximum size buffer needed per thread */ zfp_field f = *field; switch (zfp_field_dimensionality(field)) { case 1: f.nx = n; break; case 2: f.nx = 4; f.ny = n; break; case 3: f.nx = 4; f.ny = 4; f.nz = n; break; case 4: f.nx = 4; f.ny = 4; f.nz = 4; f.nw = n; break; default: return NULL; } size = zfp_stream_maximum_size(stream, &f); /* avoid copies in fixed-rate mode when each bitstream is word aligned */ copy = (stream->minbits != stream->maxbits) || (stream->maxbits % stream_word_bits != 0) || (stream_wtell(stream->stream) % stream_word_bits != 0); /* set up buffer for each thread to compress to */ bs = (bitstream**)malloc(chunks * sizeof(bitstream*)); if (!bs) return NULL; for (chunk = 0; chunk < chunks; chunk++) { size_t block = chunk_offset(blocks, chunks, chunk); void* buffer = copy ? malloc(size) : (uchar*)stream_data(stream->stream) + stream_size(stream->stream) + block * (stream->maxbits / CHAR_BIT); if (!buffer) break; bs[chunk] = stream_open(buffer, size); } /* handle memory allocation failure */ if (copy && chunk < chunks) { while (chunk--) { free(stream_data(bs[chunk])); stream_close(bs[chunk]); } free(bs); bs = NULL; } return bs; } /* flush and concatenate bit streams if needed */ static void compress_finish_par(zfp_stream* stream, bitstream** src, size_t chunks) { bitstream* dst = zfp_stream_bit_stream(stream); zfp_bool copy = (stream_data(dst) != stream_data(*src)); bitstream_offset offset = stream_wtell(dst); size_t chunk; /* flush each stream and concatenate if necessary */ for (chunk = 0; chunk < chunks; chunk++) { bitstream_size bits = stream_wtell(src[chunk]); offset += bits; stream_flush(src[chunk]); /* concatenate streams if they are not already contiguous */ if (copy) { stream_rewind(src[chunk]); stream_copy(dst, src[chunk], bits); free(stream_data(src[chunk])); } stream_close(src[chunk]); } free(src); if (!copy) stream_wseek(dst, offset); } #endif zfp-1.0.1/src/template/000077500000000000000000000000001453723256400147255ustar00rootroot00000000000000zfp-1.0.1/src/template/codec.c000066400000000000000000000002421453723256400161440ustar00rootroot00000000000000/* true if max compressed size exceeds maxbits */ static int with_maxbits(uint maxbits, uint maxprec, uint size) { return (maxprec + 1) * size - 1 > maxbits; } zfp-1.0.1/src/template/codec.h000066400000000000000000000004051453723256400161520ustar00rootroot00000000000000#define PERM _t1(perm, DIMS) /* coefficient order */ #define BLOCK_SIZE (1 << (2 * DIMS)) /* values per block */ #define EBIAS ((1 << (EBITS - 1)) - 1) /* exponent bias */ #define REVERSIBLE(zfp) ((zfp)->minexp < ZFP_MIN_EXP) /* reversible mode? */ zfp-1.0.1/src/template/codec1.c000066400000000000000000000001671453723256400162330ustar00rootroot00000000000000/* order coefficients by polynomial degree/frequency */ cache_align_(static const uchar perm_1[4]) = { 0, 1, 2, 3 }; zfp-1.0.1/src/template/codec2.c000066400000000000000000000011501453723256400162250ustar00rootroot00000000000000#define index(i, j) ((i) + 4 * (j)) /* order coefficients (i, j) by i + j, then i^2 + j^2 */ cache_align_(static const uchar perm_2[16]) = { index(0, 0), /* 0 : 0 */ index(1, 0), /* 1 : 1 */ index(0, 1), /* 2 : 1 */ index(1, 1), /* 3 : 2 */ index(2, 0), /* 4 : 2 */ index(0, 2), /* 5 : 2 */ index(2, 1), /* 6 : 3 */ index(1, 2), /* 7 : 3 */ index(3, 0), /* 8 : 3 */ index(0, 3), /* 9 : 3 */ index(2, 2), /* 10 : 4 */ index(3, 1), /* 11 : 4 */ index(1, 3), /* 12 : 4 */ index(3, 2), /* 13 : 5 */ index(2, 3), /* 14 : 5 */ index(3, 3), /* 15 : 6 */ }; #undef index zfp-1.0.1/src/template/codec3.c000066400000000000000000000042161453723256400162340ustar00rootroot00000000000000#define index(i, j, k) ((i) + 4 * ((j) + 4 * (k))) /* order coefficients (i, j, k) by i + j + k, then i^2 + j^2 + k^2 */ cache_align_(static const uchar perm_3[64]) = { index(0, 0, 0), /* 0 : 0 */ index(1, 0, 0), /* 1 : 1 */ index(0, 1, 0), /* 2 : 1 */ index(0, 0, 1), /* 3 : 1 */ index(0, 1, 1), /* 4 : 2 */ index(1, 0, 1), /* 5 : 2 */ index(1, 1, 0), /* 6 : 2 */ index(2, 0, 0), /* 7 : 2 */ index(0, 2, 0), /* 8 : 2 */ index(0, 0, 2), /* 9 : 2 */ index(1, 1, 1), /* 10 : 3 */ index(2, 1, 0), /* 11 : 3 */ index(2, 0, 1), /* 12 : 3 */ index(0, 2, 1), /* 13 : 3 */ index(1, 2, 0), /* 14 : 3 */ index(1, 0, 2), /* 15 : 3 */ index(0, 1, 2), /* 16 : 3 */ index(3, 0, 0), /* 17 : 3 */ index(0, 3, 0), /* 18 : 3 */ index(0, 0, 3), /* 19 : 3 */ index(2, 1, 1), /* 20 : 4 */ index(1, 2, 1), /* 21 : 4 */ index(1, 1, 2), /* 22 : 4 */ index(0, 2, 2), /* 23 : 4 */ index(2, 0, 2), /* 24 : 4 */ index(2, 2, 0), /* 25 : 4 */ index(3, 1, 0), /* 26 : 4 */ index(3, 0, 1), /* 27 : 4 */ index(0, 3, 1), /* 28 : 4 */ index(1, 3, 0), /* 29 : 4 */ index(1, 0, 3), /* 30 : 4 */ index(0, 1, 3), /* 31 : 4 */ index(1, 2, 2), /* 32 : 5 */ index(2, 1, 2), /* 33 : 5 */ index(2, 2, 1), /* 34 : 5 */ index(3, 1, 1), /* 35 : 5 */ index(1, 3, 1), /* 36 : 5 */ index(1, 1, 3), /* 37 : 5 */ index(3, 2, 0), /* 38 : 5 */ index(3, 0, 2), /* 39 : 5 */ index(0, 3, 2), /* 40 : 5 */ index(2, 3, 0), /* 41 : 5 */ index(2, 0, 3), /* 42 : 5 */ index(0, 2, 3), /* 43 : 5 */ index(2, 2, 2), /* 44 : 6 */ index(3, 2, 1), /* 45 : 6 */ index(3, 1, 2), /* 46 : 6 */ index(1, 3, 2), /* 47 : 6 */ index(2, 3, 1), /* 48 : 6 */ index(2, 1, 3), /* 49 : 6 */ index(1, 2, 3), /* 50 : 6 */ index(0, 3, 3), /* 51 : 6 */ index(3, 0, 3), /* 52 : 6 */ index(3, 3, 0), /* 53 : 6 */ index(3, 2, 2), /* 54 : 7 */ index(2, 3, 2), /* 55 : 7 */ index(2, 2, 3), /* 56 : 7 */ index(1, 3, 3), /* 57 : 7 */ index(3, 1, 3), /* 58 : 7 */ index(3, 3, 1), /* 59 : 7 */ index(2, 3, 3), /* 60 : 8 */ index(3, 2, 3), /* 61 : 8 */ index(3, 3, 2), /* 62 : 8 */ index(3, 3, 3), /* 63 : 9 */ }; #undef index zfp-1.0.1/src/template/codec4.c000066400000000000000000000223721453723256400162400ustar00rootroot00000000000000#define index(i, j, k, l) ((i) + 4 * ((j) + 4 * ((k) + 4 * (l)))) /* order coefficients (i, j, k, l) by i + j + k + l, then i^2 + j^2 + k^2 + l^2 */ cache_align_(static const uchar perm_4[256]) = { index(0, 0, 0, 0), /* 0 : 0 */ index(1, 0, 0, 0), /* 1 : 1 */ index(0, 1, 0, 0), /* 2 : 1 */ index(0, 0, 1, 0), /* 3 : 1 */ index(0, 0, 0, 1), /* 4 : 1 */ index(1, 1, 0, 0), /* 5 : 2 */ index(0, 0, 1, 1), /* 6 : 2 */ index(1, 0, 1, 0), /* 7 : 2 */ index(0, 1, 0, 1), /* 8 : 2 */ index(1, 0, 0, 1), /* 9 : 2 */ index(0, 1, 1, 0), /* 10 : 2 */ index(2, 0, 0, 0), /* 11 : 2 */ index(0, 2, 0, 0), /* 12 : 2 */ index(0, 0, 2, 0), /* 13 : 2 */ index(0, 0, 0, 2), /* 14 : 2 */ index(0, 1, 1, 1), /* 15 : 3 */ index(1, 0, 1, 1), /* 16 : 3 */ index(1, 1, 0, 1), /* 17 : 3 */ index(1, 1, 1, 0), /* 18 : 3 */ index(2, 1, 0, 0), /* 19 : 3 */ index(2, 0, 1, 0), /* 20 : 3 */ index(2, 0, 0, 1), /* 21 : 3 */ index(0, 2, 1, 0), /* 22 : 3 */ index(0, 2, 0, 1), /* 23 : 3 */ index(1, 2, 0, 0), /* 24 : 3 */ index(0, 0, 2, 1), /* 25 : 3 */ index(1, 0, 2, 0), /* 26 : 3 */ index(0, 1, 2, 0), /* 27 : 3 */ index(1, 0, 0, 2), /* 28 : 3 */ index(0, 1, 0, 2), /* 29 : 3 */ index(0, 0, 1, 2), /* 30 : 3 */ index(3, 0, 0, 0), /* 31 : 3 */ index(0, 3, 0, 0), /* 32 : 3 */ index(0, 0, 3, 0), /* 33 : 3 */ index(0, 0, 0, 3), /* 34 : 3 */ index(1, 1, 1, 1), /* 35 : 4 */ index(2, 0, 1, 1), /* 36 : 4 */ index(2, 1, 0, 1), /* 37 : 4 */ index(2, 1, 1, 0), /* 38 : 4 */ index(1, 2, 0, 1), /* 39 : 4 */ index(1, 2, 1, 0), /* 40 : 4 */ index(0, 2, 1, 1), /* 41 : 4 */ index(1, 1, 2, 0), /* 42 : 4 */ index(0, 1, 2, 1), /* 43 : 4 */ index(1, 0, 2, 1), /* 44 : 4 */ index(0, 1, 1, 2), /* 45 : 4 */ index(1, 0, 1, 2), /* 46 : 4 */ index(1, 1, 0, 2), /* 47 : 4 */ index(2, 2, 0, 0), /* 48 : 4 */ index(0, 0, 2, 2), /* 49 : 4 */ index(2, 0, 2, 0), /* 50 : 4 */ index(0, 2, 0, 2), /* 51 : 4 */ index(2, 0, 0, 2), /* 52 : 4 */ index(0, 2, 2, 0), /* 53 : 4 */ index(3, 1, 0, 0), /* 54 : 4 */ index(3, 0, 1, 0), /* 55 : 4 */ index(3, 0, 0, 1), /* 56 : 4 */ index(0, 3, 1, 0), /* 57 : 4 */ index(0, 3, 0, 1), /* 58 : 4 */ index(1, 3, 0, 0), /* 59 : 4 */ index(0, 0, 3, 1), /* 60 : 4 */ index(1, 0, 3, 0), /* 61 : 4 */ index(0, 1, 3, 0), /* 62 : 4 */ index(1, 0, 0, 3), /* 63 : 4 */ index(0, 1, 0, 3), /* 64 : 4 */ index(0, 0, 1, 3), /* 65 : 4 */ index(2, 1, 1, 1), /* 66 : 5 */ index(1, 2, 1, 1), /* 67 : 5 */ index(1, 1, 2, 1), /* 68 : 5 */ index(1, 1, 1, 2), /* 69 : 5 */ index(1, 0, 2, 2), /* 70 : 5 */ index(1, 2, 0, 2), /* 71 : 5 */ index(1, 2, 2, 0), /* 72 : 5 */ index(2, 1, 0, 2), /* 73 : 5 */ index(2, 1, 2, 0), /* 74 : 5 */ index(0, 1, 2, 2), /* 75 : 5 */ index(2, 2, 1, 0), /* 76 : 5 */ index(0, 2, 1, 2), /* 77 : 5 */ index(2, 0, 1, 2), /* 78 : 5 */ index(0, 2, 2, 1), /* 79 : 5 */ index(2, 0, 2, 1), /* 80 : 5 */ index(2, 2, 0, 1), /* 81 : 5 */ index(3, 0, 1, 1), /* 82 : 5 */ index(3, 1, 0, 1), /* 83 : 5 */ index(3, 1, 1, 0), /* 84 : 5 */ index(1, 3, 0, 1), /* 85 : 5 */ index(1, 3, 1, 0), /* 86 : 5 */ index(0, 3, 1, 1), /* 87 : 5 */ index(1, 1, 3, 0), /* 88 : 5 */ index(0, 1, 3, 1), /* 89 : 5 */ index(1, 0, 3, 1), /* 90 : 5 */ index(0, 1, 1, 3), /* 91 : 5 */ index(1, 0, 1, 3), /* 92 : 5 */ index(1, 1, 0, 3), /* 93 : 5 */ index(3, 2, 0, 0), /* 94 : 5 */ index(3, 0, 2, 0), /* 95 : 5 */ index(3, 0, 0, 2), /* 96 : 5 */ index(0, 3, 2, 0), /* 97 : 5 */ index(0, 3, 0, 2), /* 98 : 5 */ index(2, 3, 0, 0), /* 99 : 5 */ index(0, 0, 3, 2), /* 100 : 5 */ index(2, 0, 3, 0), /* 101 : 5 */ index(0, 2, 3, 0), /* 102 : 5 */ index(2, 0, 0, 3), /* 103 : 5 */ index(0, 2, 0, 3), /* 104 : 5 */ index(0, 0, 2, 3), /* 105 : 5 */ index(2, 2, 1, 1), /* 106 : 6 */ index(1, 1, 2, 2), /* 107 : 6 */ index(2, 1, 2, 1), /* 108 : 6 */ index(1, 2, 1, 2), /* 109 : 6 */ index(2, 1, 1, 2), /* 110 : 6 */ index(1, 2, 2, 1), /* 111 : 6 */ index(0, 2, 2, 2), /* 112 : 6 */ index(2, 0, 2, 2), /* 113 : 6 */ index(2, 2, 0, 2), /* 114 : 6 */ index(2, 2, 2, 0), /* 115 : 6 */ index(3, 1, 1, 1), /* 116 : 6 */ index(1, 3, 1, 1), /* 117 : 6 */ index(1, 1, 3, 1), /* 118 : 6 */ index(1, 1, 1, 3), /* 119 : 6 */ index(3, 2, 1, 0), /* 120 : 6 */ index(3, 2, 0, 1), /* 121 : 6 */ index(3, 0, 2, 1), /* 122 : 6 */ index(3, 1, 2, 0), /* 123 : 6 */ index(3, 1, 0, 2), /* 124 : 6 */ index(3, 0, 1, 2), /* 125 : 6 */ index(0, 3, 2, 1), /* 126 : 6 */ index(1, 3, 2, 0), /* 127 : 6 */ index(1, 3, 0, 2), /* 128 : 6 */ index(0, 3, 1, 2), /* 129 : 6 */ index(2, 3, 1, 0), /* 130 : 6 */ index(2, 3, 0, 1), /* 131 : 6 */ index(1, 0, 3, 2), /* 132 : 6 */ index(0, 1, 3, 2), /* 133 : 6 */ index(2, 1, 3, 0), /* 134 : 6 */ index(2, 0, 3, 1), /* 135 : 6 */ index(0, 2, 3, 1), /* 136 : 6 */ index(1, 2, 3, 0), /* 137 : 6 */ index(2, 1, 0, 3), /* 138 : 6 */ index(2, 0, 1, 3), /* 139 : 6 */ index(0, 2, 1, 3), /* 140 : 6 */ index(1, 2, 0, 3), /* 141 : 6 */ index(1, 0, 2, 3), /* 142 : 6 */ index(0, 1, 2, 3), /* 143 : 6 */ index(3, 3, 0, 0), /* 144 : 6 */ index(0, 0, 3, 3), /* 145 : 6 */ index(3, 0, 3, 0), /* 146 : 6 */ index(0, 3, 0, 3), /* 147 : 6 */ index(3, 0, 0, 3), /* 148 : 6 */ index(0, 3, 3, 0), /* 149 : 6 */ index(1, 2, 2, 2), /* 150 : 7 */ index(2, 1, 2, 2), /* 151 : 7 */ index(2, 2, 1, 2), /* 152 : 7 */ index(2, 2, 2, 1), /* 153 : 7 */ index(3, 2, 1, 1), /* 154 : 7 */ index(3, 1, 2, 1), /* 155 : 7 */ index(3, 1, 1, 2), /* 156 : 7 */ index(1, 3, 2, 1), /* 157 : 7 */ index(1, 3, 1, 2), /* 158 : 7 */ index(2, 3, 1, 1), /* 159 : 7 */ index(1, 1, 3, 2), /* 160 : 7 */ index(2, 1, 3, 1), /* 161 : 7 */ index(1, 2, 3, 1), /* 162 : 7 */ index(2, 1, 1, 3), /* 163 : 7 */ index(1, 2, 1, 3), /* 164 : 7 */ index(1, 1, 2, 3), /* 165 : 7 */ index(3, 0, 2, 2), /* 166 : 7 */ index(3, 2, 0, 2), /* 167 : 7 */ index(3, 2, 2, 0), /* 168 : 7 */ index(2, 3, 0, 2), /* 169 : 7 */ index(2, 3, 2, 0), /* 170 : 7 */ index(0, 3, 2, 2), /* 171 : 7 */ index(2, 2, 3, 0), /* 172 : 7 */ index(0, 2, 3, 2), /* 173 : 7 */ index(2, 0, 3, 2), /* 174 : 7 */ index(0, 2, 2, 3), /* 175 : 7 */ index(2, 0, 2, 3), /* 176 : 7 */ index(2, 2, 0, 3), /* 177 : 7 */ index(1, 0, 3, 3), /* 178 : 7 */ index(1, 3, 0, 3), /* 179 : 7 */ index(1, 3, 3, 0), /* 180 : 7 */ index(3, 1, 0, 3), /* 181 : 7 */ index(3, 1, 3, 0), /* 182 : 7 */ index(0, 1, 3, 3), /* 183 : 7 */ index(3, 3, 1, 0), /* 184 : 7 */ index(0, 3, 1, 3), /* 185 : 7 */ index(3, 0, 1, 3), /* 186 : 7 */ index(0, 3, 3, 1), /* 187 : 7 */ index(3, 0, 3, 1), /* 188 : 7 */ index(3, 3, 0, 1), /* 189 : 7 */ index(2, 2, 2, 2), /* 190 : 8 */ index(3, 1, 2, 2), /* 191 : 8 */ index(3, 2, 1, 2), /* 192 : 8 */ index(3, 2, 2, 1), /* 193 : 8 */ index(2, 3, 1, 2), /* 194 : 8 */ index(2, 3, 2, 1), /* 195 : 8 */ index(1, 3, 2, 2), /* 196 : 8 */ index(2, 2, 3, 1), /* 197 : 8 */ index(1, 2, 3, 2), /* 198 : 8 */ index(2, 1, 3, 2), /* 199 : 8 */ index(1, 2, 2, 3), /* 200 : 8 */ index(2, 1, 2, 3), /* 201 : 8 */ index(2, 2, 1, 3), /* 202 : 8 */ index(3, 3, 1, 1), /* 203 : 8 */ index(1, 1, 3, 3), /* 204 : 8 */ index(3, 1, 3, 1), /* 205 : 8 */ index(1, 3, 1, 3), /* 206 : 8 */ index(3, 1, 1, 3), /* 207 : 8 */ index(1, 3, 3, 1), /* 208 : 8 */ index(2, 0, 3, 3), /* 209 : 8 */ index(2, 3, 0, 3), /* 210 : 8 */ index(2, 3, 3, 0), /* 211 : 8 */ index(3, 2, 0, 3), /* 212 : 8 */ index(3, 2, 3, 0), /* 213 : 8 */ index(0, 2, 3, 3), /* 214 : 8 */ index(3, 3, 2, 0), /* 215 : 8 */ index(0, 3, 2, 3), /* 216 : 8 */ index(3, 0, 2, 3), /* 217 : 8 */ index(0, 3, 3, 2), /* 218 : 8 */ index(3, 0, 3, 2), /* 219 : 8 */ index(3, 3, 0, 2), /* 220 : 8 */ index(3, 2, 2, 2), /* 221 : 9 */ index(2, 3, 2, 2), /* 222 : 9 */ index(2, 2, 3, 2), /* 223 : 9 */ index(2, 2, 2, 3), /* 224 : 9 */ index(2, 1, 3, 3), /* 225 : 9 */ index(2, 3, 1, 3), /* 226 : 9 */ index(2, 3, 3, 1), /* 227 : 9 */ index(3, 2, 1, 3), /* 228 : 9 */ index(3, 2, 3, 1), /* 229 : 9 */ index(1, 2, 3, 3), /* 230 : 9 */ index(3, 3, 2, 1), /* 231 : 9 */ index(1, 3, 2, 3), /* 232 : 9 */ index(3, 1, 2, 3), /* 233 : 9 */ index(1, 3, 3, 2), /* 234 : 9 */ index(3, 1, 3, 2), /* 235 : 9 */ index(3, 3, 1, 2), /* 236 : 9 */ index(0, 3, 3, 3), /* 237 : 9 */ index(3, 0, 3, 3), /* 238 : 9 */ index(3, 3, 0, 3), /* 239 : 9 */ index(3, 3, 3, 0), /* 240 : 9 */ index(3, 3, 2, 2), /* 241 : 10 */ index(2, 2, 3, 3), /* 242 : 10 */ index(3, 2, 3, 2), /* 243 : 10 */ index(2, 3, 2, 3), /* 244 : 10 */ index(3, 2, 2, 3), /* 245 : 10 */ index(2, 3, 3, 2), /* 246 : 10 */ index(1, 3, 3, 3), /* 247 : 10 */ index(3, 1, 3, 3), /* 248 : 10 */ index(3, 3, 1, 3), /* 249 : 10 */ index(3, 3, 3, 1), /* 250 : 10 */ index(2, 3, 3, 3), /* 251 : 11 */ index(3, 2, 3, 3), /* 252 : 11 */ index(3, 3, 2, 3), /* 253 : 11 */ index(3, 3, 3, 2), /* 254 : 11 */ index(3, 3, 3, 3), /* 255 : 12 */ }; #undef index zfp-1.0.1/src/template/codecf.c000066400000000000000000000016701453723256400163200ustar00rootroot00000000000000#include #include /* maximum number of bit planes to encode */ static uint precision(int maxexp, uint maxprec, int minexp, int dims) { #if (ZFP_ROUNDING_MODE != ZFP_ROUND_NEVER) && defined(ZFP_WITH_TIGHT_ERROR) return MIN(maxprec, (uint)MAX(0, maxexp - minexp + 2 * dims + 1)); #else return MIN(maxprec, (uint)MAX(0, maxexp - minexp + 2 * dims + 2)); #endif } /* map integer x relative to exponent e to floating-point number */ static Scalar _t1(dequantize, Scalar)(Int x, int e) { return LDEXP((Scalar)x, e - ((int)(CHAR_BIT * sizeof(Scalar)) - 2)); } /* inverse block-floating-point transform from signed integers */ static void _t1(inv_cast, Scalar)(const Int* iblock, Scalar* fblock, uint n, int emax) { /* compute power-of-two scale factor s */ Scalar s = _t1(dequantize, Scalar)(1, emax); /* compute p-bit float x = s*y where |y| <= 2^(p-2) - 1 */ do *fblock++ = (Scalar)(s * *iblock++); while (--n); } zfp-1.0.1/src/template/compress.c000066400000000000000000000075131453723256400167320ustar00rootroot00000000000000/* compress 1d contiguous array */ static void _t2(compress, Scalar, 1)(zfp_stream* stream, const zfp_field* field) { const Scalar* data = (const Scalar*)field->data; size_t nx = field->nx; size_t mx = nx & ~3u; size_t x; /* compress array one block of 4 values at a time */ for (x = 0; x < mx; x += 4, data += 4) _t2(zfp_encode_block, Scalar, 1)(stream, data); if (x < nx) _t2(zfp_encode_partial_block_strided, Scalar, 1)(stream, data, nx - x, 1); } /* compress 1d strided array */ static void _t2(compress_strided, Scalar, 1)(zfp_stream* stream, const zfp_field* field) { const Scalar* data = field->data; size_t nx = field->nx; ptrdiff_t sx = field->sx ? field->sx : 1; size_t x; /* compress array one block of 4 values at a time */ for (x = 0; x < nx; x += 4) { const Scalar* p = data + sx * (ptrdiff_t)x; if (nx - x < 4) _t2(zfp_encode_partial_block_strided, Scalar, 1)(stream, p, nx - x, sx); else _t2(zfp_encode_block_strided, Scalar, 1)(stream, p, sx); } } /* compress 2d strided array */ static void _t2(compress_strided, Scalar, 2)(zfp_stream* stream, const zfp_field* field) { const Scalar* data = (const Scalar*)field->data; size_t nx = field->nx; size_t ny = field->ny; ptrdiff_t sx = field->sx ? field->sx : 1; ptrdiff_t sy = field->sy ? field->sy : (ptrdiff_t)nx; size_t x, y; /* compress array one block of 4x4 values at a time */ for (y = 0; y < ny; y += 4) for (x = 0; x < nx; x += 4) { const Scalar* p = data + sx * (ptrdiff_t)x + sy * (ptrdiff_t)y; if (nx - x < 4 || ny - y < 4) _t2(zfp_encode_partial_block_strided, Scalar, 2)(stream, p, MIN(nx - x, 4u), MIN(ny - y, 4u), sx, sy); else _t2(zfp_encode_block_strided, Scalar, 2)(stream, p, sx, sy); } } /* compress 3d strided array */ static void _t2(compress_strided, Scalar, 3)(zfp_stream* stream, const zfp_field* field) { const Scalar* data = (const Scalar*)field->data; size_t nx = field->nx; size_t ny = field->ny; size_t nz = field->nz; ptrdiff_t sx = field->sx ? field->sx : 1; ptrdiff_t sy = field->sy ? field->sy : (ptrdiff_t)nx; ptrdiff_t sz = field->sz ? field->sz : (ptrdiff_t)(nx * ny); size_t x, y, z; /* compress array one block of 4x4x4 values at a time */ for (z = 0; z < nz; z += 4) for (y = 0; y < ny; y += 4) for (x = 0; x < nx; x += 4) { const Scalar* p = data + sx * (ptrdiff_t)x + sy * (ptrdiff_t)y + sz * (ptrdiff_t)z; if (nx - x < 4 || ny - y < 4 || nz - z < 4) _t2(zfp_encode_partial_block_strided, Scalar, 3)(stream, p, MIN(nx - x, 4u), MIN(ny - y, 4u), MIN(nz - z, 4u), sx, sy, sz); else _t2(zfp_encode_block_strided, Scalar, 3)(stream, p, sx, sy, sz); } } /* compress 4d strided array */ static void _t2(compress_strided, Scalar, 4)(zfp_stream* stream, const zfp_field* field) { const Scalar* data = field->data; size_t nx = field->nx; size_t ny = field->ny; size_t nz = field->nz; size_t nw = field->nw; ptrdiff_t sx = field->sx ? field->sx : 1; ptrdiff_t sy = field->sy ? field->sy : (ptrdiff_t)nx; ptrdiff_t sz = field->sz ? field->sz : (ptrdiff_t)(nx * ny); ptrdiff_t sw = field->sw ? field->sw : (ptrdiff_t)(nx * ny * nz); size_t x, y, z, w; /* compress array one block of 4x4x4x4 values at a time */ for (w = 0; w < nw; w += 4) for (z = 0; z < nz; z += 4) for (y = 0; y < ny; y += 4) for (x = 0; x < nx; x += 4) { const Scalar* p = data + sx * (ptrdiff_t)x + sy * (ptrdiff_t)y + sz * (ptrdiff_t)z + sw * (ptrdiff_t)w; if (nx - x < 4 || ny - y < 4 || nz - z < 4 || nw - w < 4) _t2(zfp_encode_partial_block_strided, Scalar, 4)(stream, p, MIN(nx - x, 4u), MIN(ny - y, 4u), MIN(nz - z, 4u), MIN(nw - w, 4u), sx, sy, sz, sw); else _t2(zfp_encode_block_strided, Scalar, 4)(stream, p, sx, sy, sz, sw); } } zfp-1.0.1/src/template/cudacompress.c000066400000000000000000000017001453723256400175570ustar00rootroot00000000000000#ifdef ZFP_WITH_CUDA #include "../cuda_zfp/cuZFP.h" static void _t2(compress_cuda, Scalar, 1)(zfp_stream* stream, const zfp_field* field) { if (zfp_stream_compression_mode(stream) == zfp_mode_fixed_rate) cuda_compress(stream, field); } /* compress 1d strided array */ static void _t2(compress_strided_cuda, Scalar, 1)(zfp_stream* stream, const zfp_field* field) { if (zfp_stream_compression_mode(stream) == zfp_mode_fixed_rate) cuda_compress(stream, field); } /* compress 2d strided array */ static void _t2(compress_strided_cuda, Scalar, 2)(zfp_stream* stream, const zfp_field* field) { if (zfp_stream_compression_mode(stream) == zfp_mode_fixed_rate) cuda_compress(stream, field); } /* compress 3d strided array */ static void _t2(compress_strided_cuda, Scalar, 3)(zfp_stream* stream, const zfp_field* field) { if (zfp_stream_compression_mode(stream) == zfp_mode_fixed_rate) cuda_compress(stream, field); } #endif zfp-1.0.1/src/template/cudadecompress.c000066400000000000000000000016651453723256400201020ustar00rootroot00000000000000#ifdef ZFP_WITH_CUDA #include "../cuda_zfp/cuZFP.h" static void _t2(decompress_cuda, Scalar, 1)(zfp_stream* stream, zfp_field* field) { if (zfp_stream_compression_mode(stream) == zfp_mode_fixed_rate) cuda_decompress(stream, field); } /* compress 1d strided array */ static void _t2(decompress_strided_cuda, Scalar, 1)(zfp_stream* stream, zfp_field* field) { if (zfp_stream_compression_mode(stream) == zfp_mode_fixed_rate) cuda_decompress(stream, field); } /* compress 2d strided array */ static void _t2(decompress_strided_cuda, Scalar, 2)(zfp_stream* stream, zfp_field* field) { if (zfp_stream_compression_mode(stream) == zfp_mode_fixed_rate) cuda_decompress(stream, field); } /* compress 3d strided array */ static void _t2(decompress_strided_cuda, Scalar, 3)(zfp_stream* stream, zfp_field* field) { if (zfp_stream_compression_mode(stream) == zfp_mode_fixed_rate) cuda_decompress(stream, field); } #endif zfp-1.0.1/src/template/decode.c000066400000000000000000000210341453723256400163140ustar00rootroot00000000000000#include static void _t2(inv_xform, Int, DIMS)(Int* p); /* private functions ------------------------------------------------------- */ /* inverse lifting transform of 4-vector */ static void _t1(inv_lift, Int)(Int* p, ptrdiff_t s) { Int x, y, z, w; x = *p; p += s; y = *p; p += s; z = *p; p += s; w = *p; p += s; /* ** non-orthogonal transform ** ( 4 6 -4 -1) (x) ** 1/4 * ( 4 2 4 5) (y) ** ( 4 -2 4 -5) (z) ** ( 4 -6 -4 1) (w) */ y += w >> 1; w -= y >> 1; y += w; w <<= 1; w -= y; z += x; x <<= 1; x -= z; y += z; z <<= 1; z -= y; w += x; x <<= 1; x -= w; p -= s; *p = w; p -= s; *p = z; p -= s; *p = y; p -= s; *p = x; } #if ZFP_ROUNDING_MODE == ZFP_ROUND_LAST /* bias values such that truncation is equivalent to round to nearest */ static void _t1(inv_round, UInt)(UInt* ublock, uint n, uint m, uint prec) { /* add 1/6 ulp to unbias errors */ if (prec < (uint)(CHAR_BIT * sizeof(UInt) - 1)) { /* the first m values (0 <= m <= n) have one more bit of precision */ n -= m; while (m--) *ublock++ += ((NBMASK >> 2) >> prec); while (n--) *ublock++ += ((NBMASK >> 1) >> prec); } } #endif /* map two's complement signed integer to negabinary unsigned integer */ static Int _t1(uint2int, UInt)(UInt x) { return (Int)((x ^ NBMASK) - NBMASK); } /* reorder unsigned coefficients and convert to signed integer */ static void _t1(inv_order, Int)(const UInt* ublock, Int* iblock, const uchar* perm, uint n) { do iblock[*perm++] = _t1(uint2int, UInt)(*ublock++); while (--n); } /* decompress sequence of size <= 64 unsigned integers */ static uint _t1(decode_few_ints, UInt)(bitstream* restrict_ stream, uint maxbits, uint maxprec, UInt* restrict_ data, uint size) { /* make a copy of bit stream to avoid aliasing */ bitstream s = *stream; uint intprec = (uint)(CHAR_BIT * sizeof(UInt)); uint kmin = intprec > maxprec ? intprec - maxprec : 0; uint bits = maxbits; uint i, k, m, n; uint64 x; /* initialize data array to all zeros */ for (i = 0; i < size; i++) data[i] = 0; /* decode one bit plane at a time from MSB to LSB */ for (k = intprec, m = n = 0; bits && (m = 0, k-- > kmin);) { /* step 1: decode first n bits of bit plane #k */ m = MIN(n, bits); bits -= m; x = stream_read_bits(&s, m); /* step 2: unary run-length decode remainder of bit plane */ for (; bits && n < size; n++, m = n) { bits--; if (stream_read_bit(&s)) { /* positive group test; scan for next one-bit */ for (; bits && n < size - 1; n++) { bits--; if (stream_read_bit(&s)) break; } /* set bit and continue decoding bit plane */ x += (uint64)1 << n; } else { /* negative group test; done with bit plane */ m = size; break; } } /* step 3: deposit bit plane from x */ for (i = 0; x; i++, x >>= 1) data[i] += (UInt)(x & 1u) << k; } #if ZFP_ROUNDING_MODE == ZFP_ROUND_LAST /* bias values to achieve proper rounding */ _t1(inv_round, UInt)(data, size, m, intprec - k); #endif *stream = s; return maxbits - bits; } /* decompress sequence of size > 64 unsigned integers */ static uint _t1(decode_many_ints, UInt)(bitstream* restrict_ stream, uint maxbits, uint maxprec, UInt* restrict_ data, uint size) { /* make a copy of bit stream to avoid aliasing */ bitstream s = *stream; uint intprec = (uint)(CHAR_BIT * sizeof(UInt)); uint kmin = intprec > maxprec ? intprec - maxprec : 0; uint bits = maxbits; uint i, k, m, n; /* initialize data array to all zeros */ for (i = 0; i < size; i++) data[i] = 0; /* decode one bit plane at a time from MSB to LSB */ for (k = intprec, m = n = 0; bits && (m = 0, k-- > kmin);) { /* step 1: decode first n bits of bit plane #k */ m = MIN(n, bits); bits -= m; for (i = 0; i < m; i++) if (stream_read_bit(&s)) data[i] += (UInt)1 << k; /* step 2: unary run-length decode remainder of bit plane */ for (; bits && n < size; n++, m = n) { bits--; if (stream_read_bit(&s)) { /* positive group test; scan for next one-bit */ for (; bits && n < size - 1; n++) { bits--; if (stream_read_bit(&s)) break; } /* set bit and continue decoding bit plane */ data[n] += (UInt)1 << k; } else { /* negative group test; done with bit plane */ m = size; break; } } } #if ZFP_ROUNDING_MODE == ZFP_ROUND_LAST /* bias values to achieve proper rounding */ _t1(inv_round, UInt)(data, size, m, intprec - k); #endif *stream = s; return maxbits - bits; } /* decompress sequence of size <= 64 unsigned integers with no rate constraint */ static uint _t1(decode_few_ints_prec, UInt)(bitstream* restrict_ stream, uint maxprec, UInt* restrict_ data, uint size) { /* make a copy of bit stream to avoid aliasing */ bitstream s = *stream; bitstream_offset offset = stream_rtell(&s); uint intprec = (uint)(CHAR_BIT * sizeof(UInt)); uint kmin = intprec > maxprec ? intprec - maxprec : 0; uint i, k, n; /* initialize data array to all zeros */ for (i = 0; i < size; i++) data[i] = 0; /* decode one bit plane at a time from MSB to LSB */ for (k = intprec, n = 0; k-- > kmin;) { /* step 1: decode first n bits of bit plane #k */ uint64 x = stream_read_bits(&s, n); /* step 2: unary run-length decode remainder of bit plane */ for (; n < size && stream_read_bit(&s); x += (uint64)1 << n, n++) for (; n < size - 1 && !stream_read_bit(&s); n++) ; /* step 3: deposit bit plane from x */ for (i = 0; x; i++, x >>= 1) data[i] += (UInt)(x & 1u) << k; } #if ZFP_ROUNDING_MODE == ZFP_ROUND_LAST /* bias values to achieve proper rounding */ _t1(inv_round, UInt)(data, size, 0, intprec - k); #endif *stream = s; return (uint)(stream_rtell(&s) - offset); } /* decompress sequence of size > 64 unsigned integers with no rate constraint */ static uint _t1(decode_many_ints_prec, UInt)(bitstream* restrict_ stream, uint maxprec, UInt* restrict_ data, uint size) { /* make a copy of bit stream to avoid aliasing */ bitstream s = *stream; bitstream_offset offset = stream_rtell(&s); uint intprec = (uint)(CHAR_BIT * sizeof(UInt)); uint kmin = intprec > maxprec ? intprec - maxprec : 0; uint i, k, n; /* initialize data array to all zeros */ for (i = 0; i < size; i++) data[i] = 0; /* decode one bit plane at a time from MSB to LSB */ for (k = intprec, n = 0; k-- > kmin;) { /* step 1: decode first n bits of bit plane #k */ for (i = 0; i < n; i++) if (stream_read_bit(&s)) data[i] += (UInt)1 << k; /* step 2: unary run-length decode remainder of bit plane */ for (; n < size && stream_read_bit(&s); data[n] += (UInt)1 << k, n++) for (; n < size - 1 && !stream_read_bit(&s); n++) ; } #if ZFP_ROUNDING_MODE == ZFP_ROUND_LAST /* bias values to achieve proper rounding */ _t1(inv_round, UInt)(data, size, 0, intprec - k); #endif *stream = s; return (uint)(stream_rtell(&s) - offset); } /* decompress sequence of size unsigned integers */ static uint _t1(decode_ints, UInt)(bitstream* restrict_ stream, uint maxbits, uint maxprec, UInt* restrict_ data, uint size) { /* use fastest available decoder implementation */ if (with_maxbits(maxbits, maxprec, size)) { /* rate constrained path: decode partial bit planes */ if (size <= 64) return _t1(decode_few_ints, UInt)(stream, maxbits, maxprec, data, size); /* 1D, 2D, 3D blocks */ else return _t1(decode_many_ints, UInt)(stream, maxbits, maxprec, data, size); /* 4D blocks */ } else { /* variable-rate path: decode whole bit planes */ if (size <= 64) return _t1(decode_few_ints_prec, UInt)(stream, maxprec, data, size); /* 1D, 2D, 3D blocks */ else return _t1(decode_many_ints_prec, UInt)(stream, maxprec, data, size); /* 4D blocks */ } } /* decode block of integers */ static uint _t2(decode_block, Int, DIMS)(bitstream* stream, uint minbits, uint maxbits, uint maxprec, Int* iblock) { uint bits; cache_align_(UInt ublock[BLOCK_SIZE]); /* decode integer coefficients */ bits = _t1(decode_ints, UInt)(stream, maxbits, maxprec, ublock, BLOCK_SIZE); /* read at least minbits bits */ if (bits < minbits) { stream_skip(stream, minbits - bits); bits = minbits; } /* reorder unsigned coefficients and convert to signed integer */ _t1(inv_order, Int)(ublock, iblock, PERM, BLOCK_SIZE); /* perform decorrelating transform */ _t2(inv_xform, Int, DIMS)(iblock); return bits; } zfp-1.0.1/src/template/decode1.c000066400000000000000000000027311453723256400164000ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* scatter 4-value block to strided array */ static void _t2(scatter, Scalar, 1)(const Scalar* q, Scalar* p, ptrdiff_t sx) { uint x; for (x = 0; x < 4; x++, p += sx) *p = *q++; } /* scatter nx-value block to strided array */ static void _t2(scatter_partial, Scalar, 1)(const Scalar* q, Scalar* p, size_t nx, ptrdiff_t sx) { size_t x; for (x = 0; x < nx; x++, p += sx) *p = *q++; } /* inverse decorrelating 1D transform */ static void _t2(inv_xform, Int, 1)(Int* p) { /* transform along x */ _t1(inv_lift, Int)(p, 1); } /* public functions -------------------------------------------------------- */ /* decode 4-value block and store at p using stride sx */ size_t _t2(zfp_decode_block_strided, Scalar, 1)(zfp_stream* stream, Scalar* p, ptrdiff_t sx) { /* decode contiguous block */ cache_align_(Scalar block[4]); size_t bits = _t2(zfp_decode_block, Scalar, 1)(stream, block); /* scatter block to strided array */ _t2(scatter, Scalar, 1)(block, p, sx); return bits; } /* decode nx-value block and store at p using stride sx */ size_t _t2(zfp_decode_partial_block_strided, Scalar, 1)(zfp_stream* stream, Scalar* p, size_t nx, ptrdiff_t sx) { /* decode contiguous block */ cache_align_(Scalar block[4]); size_t bits = _t2(zfp_decode_block, Scalar, 1)(stream, block); /* scatter block to strided array */ _t2(scatter_partial, Scalar, 1)(block, p, nx, sx); return bits; } zfp-1.0.1/src/template/decode2.c000066400000000000000000000035031453723256400163770ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* scatter 4*4 block to strided array */ static void _t2(scatter, Scalar, 2)(const Scalar* q, Scalar* p, ptrdiff_t sx, ptrdiff_t sy) { uint x, y; for (y = 0; y < 4; y++, p += sy - 4 * sx) for (x = 0; x < 4; x++, p += sx) *p = *q++; } /* scatter nx*ny block to strided array */ static void _t2(scatter_partial, Scalar, 2)(const Scalar* q, Scalar* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) { size_t x, y; for (y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx, q += 4 - nx) for (x = 0; x < nx; x++, p += sx, q++) *p = *q; } /* inverse decorrelating 2D transform */ static void _t2(inv_xform, Int, 2)(Int* p) { uint x, y; /* transform along y */ for (x = 0; x < 4; x++) _t1(inv_lift, Int)(p + 1 * x, 4); /* transform along x */ for (y = 0; y < 4; y++) _t1(inv_lift, Int)(p + 4 * y, 1); } /* public functions -------------------------------------------------------- */ /* decode 4*4 block and store at p using strides (sx, sy) */ size_t _t2(zfp_decode_block_strided, Scalar, 2)(zfp_stream* stream, Scalar* p, ptrdiff_t sx, ptrdiff_t sy) { /* decode contiguous block */ cache_align_(Scalar block[16]); size_t bits = _t2(zfp_decode_block, Scalar, 2)(stream, block); /* scatter block to strided array */ _t2(scatter, Scalar, 2)(block, p, sx, sy); return bits; } /* decode nx*ny block and store at p using strides (sx, sy) */ size_t _t2(zfp_decode_partial_block_strided, Scalar, 2)(zfp_stream* stream, Scalar* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) { /* decode contiguous block */ cache_align_(Scalar block[16]); size_t bits = _t2(zfp_decode_block, Scalar, 2)(stream, block); /* scatter block to strided array */ _t2(scatter_partial, Scalar, 2)(block, p, nx, ny, sx, sy); return bits; } zfp-1.0.1/src/template/decode3.c000066400000000000000000000044211453723256400164000ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* scatter 4*4*4 block to strided array */ static void _t2(scatter, Scalar, 3)(const Scalar* q, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { uint x, y, z; for (z = 0; z < 4; z++, p += sz - 4 * sy) for (y = 0; y < 4; y++, p += sy - 4 * sx) for (x = 0; x < 4; x++, p += sx) *p = *q++; } /* scatter nx*ny*nz block to strided array */ static void _t2(scatter_partial, Scalar, 3)(const Scalar* q, Scalar* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { size_t x, y, z; for (z = 0; z < nz; z++, p += sz - (ptrdiff_t)ny * sy, q += 4 * (4 - ny)) for (y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx, q += 1 * (4 - nx)) for (x = 0; x < nx; x++, p += sx, q++) *p = *q; } /* inverse decorrelating 3D transform */ static void _t2(inv_xform, Int, 3)(Int* p) { uint x, y, z; /* transform along z */ for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) _t1(inv_lift, Int)(p + 1 * x + 4 * y, 16); /* transform along y */ for (x = 0; x < 4; x++) for (z = 0; z < 4; z++) _t1(inv_lift, Int)(p + 16 * z + 1 * x, 4); /* transform along x */ for (z = 0; z < 4; z++) for (y = 0; y < 4; y++) _t1(inv_lift, Int)(p + 4 * y + 16 * z, 1); } /* public functions -------------------------------------------------------- */ /* decode 4*4*4 block and store at p using strides (sx, sy, sz) */ size_t _t2(zfp_decode_block_strided, Scalar, 3)(zfp_stream* stream, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { /* decode contiguous block */ cache_align_(Scalar block[64]); size_t bits = _t2(zfp_decode_block, Scalar, 3)(stream, block); /* scatter block to strided array */ _t2(scatter, Scalar, 3)(block, p, sx, sy, sz); return bits; } /* decode nx*ny*nz block and store at p using strides (sx, sy, sz) */ size_t _t2(zfp_decode_partial_block_strided, Scalar, 3)(zfp_stream* stream, Scalar* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { /* decode contiguous block */ cache_align_(Scalar block[64]); size_t bits = _t2(zfp_decode_block, Scalar, 3)(stream, block); /* scatter block to strided array */ _t2(scatter_partial, Scalar, 3)(block, p, nx, ny, nz, sx, sy, sz); return bits; } zfp-1.0.1/src/template/decode4.c000066400000000000000000000054661453723256400164130ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* scatter 4*4*4*4 block to strided array */ static void _t2(scatter, Scalar, 4)(const Scalar* q, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { uint x, y, z, w; for (w = 0; w < 4; w++, p += sw - 4 * sz) for (z = 0; z < 4; z++, p += sz - 4 * sy) for (y = 0; y < 4; y++, p += sy - 4 * sx) for (x = 0; x < 4; x++, p += sx) *p = *q++; } /* scatter nx*ny*nz*nw block to strided array */ static void _t2(scatter_partial, Scalar, 4)(const Scalar* q, Scalar* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { size_t x, y, z, w; for (w = 0; w < nw; w++, p += sw - (ptrdiff_t)nz * sz, q += 16 * (4 - nz)) for (z = 0; z < nz; z++, p += sz - (ptrdiff_t)ny * sy, q += 4 * (4 - ny)) for (y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx, q += 1 * (4 - nx)) for (x = 0; x < nx; x++, p += sx, q++) *p = *q; } /* inverse decorrelating 4D transform */ static void _t2(inv_xform, Int, 4)(Int* p) { uint x, y, z, w; /* transform along w */ for (z = 0; z < 4; z++) for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) _t1(inv_lift, Int)(p + 1 * x + 4 * y + 16 * z, 64); /* transform along z */ for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) for (w = 0; w < 4; w++) _t1(inv_lift, Int)(p + 64 * w + 1 * x + 4 * y, 16); /* transform along y */ for (x = 0; x < 4; x++) for (w = 0; w < 4; w++) for (z = 0; z < 4; z++) _t1(inv_lift, Int)(p + 16 * z + 64 * w + 1 * x, 4); /* transform along x */ for (w = 0; w < 4; w++) for (z = 0; z < 4; z++) for (y = 0; y < 4; y++) _t1(inv_lift, Int)(p + 4 * y + 16 * z + 64 * w, 1); } /* public functions -------------------------------------------------------- */ /* decode 4*4*4*4 block and store at p using strides (sx, sy, sz, sw) */ size_t _t2(zfp_decode_block_strided, Scalar, 4)(zfp_stream* stream, Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { /* decode contiguous block */ cache_align_(Scalar block[256]); size_t bits = _t2(zfp_decode_block, Scalar, 4)(stream, block); /* scatter block to strided array */ _t2(scatter, Scalar, 4)(block, p, sx, sy, sz, sw); return bits; } /* decode nx*ny*nz*nw block and store at p using strides (sx, sy, sz, sw) */ size_t _t2(zfp_decode_partial_block_strided, Scalar, 4)(zfp_stream* stream, Scalar* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { /* decode contiguous block */ cache_align_(Scalar block[256]); size_t bits = _t2(zfp_decode_block, Scalar, 4)(stream, block); /* scatter block to strided array */ _t2(scatter_partial, Scalar, 4)(block, p, nx, ny, nz, nw, sx, sy, sz, sw); return bits; } zfp-1.0.1/src/template/decodef.c000066400000000000000000000027651453723256400164740ustar00rootroot00000000000000static uint _t2(rev_decode_block, Scalar, DIMS)(zfp_stream* zfp, Scalar* fblock); /* private functions ------------------------------------------------------- */ /* decode contiguous floating-point block using lossy algorithm */ static uint _t2(decode_block, Scalar, DIMS)(zfp_stream* zfp, Scalar* fblock) { uint bits = 1; /* test if block has nonzero values */ if (stream_read_bit(zfp->stream)) { cache_align_(Int iblock[BLOCK_SIZE]); uint maxprec; int emax; /* decode common exponent */ bits += EBITS; emax = (int)stream_read_bits(zfp->stream, EBITS) - EBIAS; maxprec = precision(emax, zfp->maxprec, zfp->minexp, DIMS); /* decode integer block */ bits += _t2(decode_block, Int, DIMS)(zfp->stream, zfp->minbits - MIN(bits, zfp->minbits), zfp->maxbits - bits, maxprec, iblock); /* perform inverse block-floating-point transform */ _t1(inv_cast, Scalar)(iblock, fblock, BLOCK_SIZE, emax); } else { /* set all values to zero */ uint i; for (i = 0; i < BLOCK_SIZE; i++) *fblock++ = 0; if (zfp->minbits > bits) { stream_skip(zfp->stream, zfp->minbits - bits); bits = zfp->minbits; } } return bits; } /* public functions -------------------------------------------------------- */ /* decode contiguous floating-point block */ size_t _t2(zfp_decode_block, Scalar, DIMS)(zfp_stream* zfp, Scalar* fblock) { return REVERSIBLE(zfp) ? _t2(rev_decode_block, Scalar, DIMS)(zfp, fblock) : _t2(decode_block, Scalar, DIMS)(zfp, fblock); } zfp-1.0.1/src/template/decodei.c000066400000000000000000000007701453723256400164710ustar00rootroot00000000000000static uint _t2(rev_decode_block, Int, DIMS)(bitstream* stream, uint minbits, uint maxbits, Int* iblock); /* public functions -------------------------------------------------------- */ /* decode contiguous integer block */ size_t _t2(zfp_decode_block, Int, DIMS)(zfp_stream* zfp, Int* iblock) { return REVERSIBLE(zfp) ? _t2(rev_decode_block, Int, DIMS)(zfp->stream, zfp->minbits, zfp->maxbits, iblock) : _t2(decode_block, Int, DIMS)(zfp->stream, zfp->minbits, zfp->maxbits, zfp->maxprec, iblock); } zfp-1.0.1/src/template/decompress.c000066400000000000000000000074031453723256400172410ustar00rootroot00000000000000/* decompress 1d contiguous array */ static void _t2(decompress, Scalar, 1)(zfp_stream* stream, zfp_field* field) { Scalar* data = (Scalar*)field->data; size_t nx = field->nx; size_t mx = nx & ~3u; size_t x; /* decompress array one block of 4 values at a time */ for (x = 0; x < mx; x += 4, data += 4) _t2(zfp_decode_block, Scalar, 1)(stream, data); if (x < nx) _t2(zfp_decode_partial_block_strided, Scalar, 1)(stream, data, nx - x, 1); } /* decompress 1d strided array */ static void _t2(decompress_strided, Scalar, 1)(zfp_stream* stream, zfp_field* field) { Scalar* data = field->data; size_t nx = field->nx; ptrdiff_t sx = field->sx ? field->sx : 1; size_t x; /* decompress array one block of 4 values at a time */ for (x = 0; x < nx; x += 4) { Scalar* p = data + sx * (ptrdiff_t)x; if (nx - x < 4) _t2(zfp_decode_partial_block_strided, Scalar, 1)(stream, p, nx - x, sx); else _t2(zfp_decode_block_strided, Scalar, 1)(stream, p, sx); } } /* decompress 2d strided array */ static void _t2(decompress_strided, Scalar, 2)(zfp_stream* stream, zfp_field* field) { Scalar* data = (Scalar*)field->data; size_t nx = field->nx; size_t ny = field->ny; ptrdiff_t sx = field->sx ? field->sx : 1; ptrdiff_t sy = field->sy ? field->sy : (ptrdiff_t)nx; size_t x, y; /* decompress array one block of 4x4 values at a time */ for (y = 0; y < ny; y += 4) for (x = 0; x < nx; x += 4) { Scalar* p = data + sx * (ptrdiff_t)x + sy * (ptrdiff_t)y; if (nx - x < 4 || ny - y < 4) _t2(zfp_decode_partial_block_strided, Scalar, 2)(stream, p, MIN(nx - x, 4u), MIN(ny - y, 4u), sx, sy); else _t2(zfp_decode_block_strided, Scalar, 2)(stream, p, sx, sy); } } /* decompress 3d strided array */ static void _t2(decompress_strided, Scalar, 3)(zfp_stream* stream, zfp_field* field) { Scalar* data = (Scalar*)field->data; size_t nx = field->nx; size_t ny = field->ny; size_t nz = field->nz; ptrdiff_t sx = field->sx ? field->sx : 1; ptrdiff_t sy = field->sy ? field->sy : (ptrdiff_t)nx; ptrdiff_t sz = field->sz ? field->sz : (ptrdiff_t)(nx * ny); size_t x, y, z; /* decompress array one block of 4x4x4 values at a time */ for (z = 0; z < nz; z += 4) for (y = 0; y < ny; y += 4) for (x = 0; x < nx; x += 4) { Scalar* p = data + sx * (ptrdiff_t)x + sy * (ptrdiff_t)y + sz * (ptrdiff_t)z; if (nx - x < 4 || ny - y < 4 || nz - z < 4) _t2(zfp_decode_partial_block_strided, Scalar, 3)(stream, p, MIN(nx - x, 4u), MIN(ny - y, 4u), MIN(nz - z, 4u), sx, sy, sz); else _t2(zfp_decode_block_strided, Scalar, 3)(stream, p, sx, sy, sz); } } /* decompress 4d strided array */ static void _t2(decompress_strided, Scalar, 4)(zfp_stream* stream, zfp_field* field) { Scalar* data = field->data; size_t nx = field->nx; size_t ny = field->ny; size_t nz = field->nz; size_t nw = field->nw; ptrdiff_t sx = field->sx ? field->sx : 1; ptrdiff_t sy = field->sy ? field->sy : (ptrdiff_t)nx; ptrdiff_t sz = field->sz ? field->sz : (ptrdiff_t)(nx * ny); ptrdiff_t sw = field->sw ? field->sw : (ptrdiff_t)(nx * ny * nz); size_t x, y, z, w; /* decompress array one block of 4x4x4x4 values at a time */ for (w = 0; w < nw; w += 4) for (z = 0; z < nz; z += 4) for (y = 0; y < ny; y += 4) for (x = 0; x < nx; x += 4) { Scalar* p = data + sx * (ptrdiff_t)x + sy * (ptrdiff_t)y + sz * (ptrdiff_t)z + sw * (ptrdiff_t)w; if (nx - x < 4 || ny - y < 4 || nz - z < 4 || nw - w < 4) _t2(zfp_decode_partial_block_strided, Scalar, 4)(stream, p, MIN(nx - x, 4u), MIN(ny - y, 4u), MIN(nz - z, 4u), MIN(nw - w, 4u), sx, sy, sz, sw); else _t2(zfp_decode_block_strided, Scalar, 4)(stream, p, sx, sy, sz, sw); } } zfp-1.0.1/src/template/encode.c000066400000000000000000000204541453723256400163330ustar00rootroot00000000000000#include static void _t2(fwd_xform, Int, DIMS)(Int* p); /* private functions ------------------------------------------------------- */ /* pad partial block of width n <= 4 and stride s */ static void _t1(pad_block, Scalar)(Scalar* p, size_t n, ptrdiff_t s) { switch (n) { case 0: p[0 * s] = 0; /* FALLTHROUGH */ case 1: p[1 * s] = p[0 * s]; /* FALLTHROUGH */ case 2: p[2 * s] = p[1 * s]; /* FALLTHROUGH */ case 3: p[3 * s] = p[0 * s]; /* FALLTHROUGH */ default: break; } } /* forward lifting transform of 4-vector */ static void _t1(fwd_lift, Int)(Int* p, ptrdiff_t s) { Int x, y, z, w; x = *p; p += s; y = *p; p += s; z = *p; p += s; w = *p; p += s; /* ** non-orthogonal transform ** ( 4 4 4 4) (x) ** 1/16 * ( 5 1 -1 -5) (y) ** (-4 4 4 -4) (z) ** (-2 6 -6 2) (w) */ x += w; x >>= 1; w -= x; z += y; z >>= 1; y -= z; x += z; x >>= 1; z -= x; w += y; w >>= 1; y -= w; w += y >> 1; y -= w >> 1; p -= s; *p = w; p -= s; *p = z; p -= s; *p = y; p -= s; *p = x; } #if ZFP_ROUNDING_MODE == ZFP_ROUND_FIRST /* bias values such that truncation is equivalent to round to nearest */ static void _t1(fwd_round, Int)(Int* iblock, uint n, uint maxprec) { /* add or subtract 1/6 ulp to unbias errors */ if (maxprec < (uint)(CHAR_BIT * sizeof(Int))) { Int bias = (NBMASK >> 2) >> maxprec; if (maxprec & 1u) do *iblock++ += bias; while (--n); else do *iblock++ -= bias; while (--n); } } #endif /* map two's complement signed integer to negabinary unsigned integer */ static UInt _t1(int2uint, Int)(Int x) { return ((UInt)x + NBMASK) ^ NBMASK; } /* reorder signed coefficients and convert to unsigned integer */ static void _t1(fwd_order, Int)(UInt* ublock, const Int* iblock, const uchar* perm, uint n) { do *ublock++ = _t1(int2uint, Int)(iblock[*perm++]); while (--n); } /* compress sequence of size <= 64 unsigned integers */ static uint _t1(encode_few_ints, UInt)(bitstream* restrict_ stream, uint maxbits, uint maxprec, const UInt* restrict_ data, uint size) { /* make a copy of bit stream to avoid aliasing */ bitstream s = *stream; uint intprec = (uint)(CHAR_BIT * sizeof(UInt)); uint kmin = intprec > maxprec ? intprec - maxprec : 0; uint bits = maxbits; uint i, k, m, n; uint64 x; /* encode one bit plane at a time from MSB to LSB */ for (k = intprec, n = 0; bits && k-- > kmin;) { /* step 1: extract bit plane #k to x */ x = 0; for (i = 0; i < size; i++) x += (uint64)((data[i] >> k) & 1u) << i; /* step 2: encode first n bits of bit plane */ m = MIN(n, bits); bits -= m; x = stream_write_bits(&s, x, m); /* step 3: unary run-length encode remainder of bit plane */ for (; bits && n < size; x >>= 1, n++) { bits--; if (stream_write_bit(&s, !!x)) { /* positive group test (x != 0); scan for one-bit */ for (; bits && n < size - 1; x >>= 1, n++) { bits--; if (stream_write_bit(&s, x & 1u)) break; } } else { /* negative group test (x == 0); done with bit plane */ break; } } } *stream = s; return maxbits - bits; } /* compress sequence of size > 64 unsigned integers */ static uint _t1(encode_many_ints, UInt)(bitstream* restrict_ stream, uint maxbits, uint maxprec, const UInt* restrict_ data, uint size) { /* make a copy of bit stream to avoid aliasing */ bitstream s = *stream; uint intprec = (uint)(CHAR_BIT * sizeof(UInt)); uint kmin = intprec > maxprec ? intprec - maxprec : 0; uint bits = maxbits; uint i, k, m, n, c; /* encode one bit plane at a time from MSB to LSB */ for (k = intprec, n = 0; bits && k-- > kmin;) { /* step 1: encode first n bits of bit plane #k */ m = MIN(n, bits); bits -= m; for (i = 0; i < m; i++) stream_write_bit(&s, (data[i] >> k) & 1u); /* step 2: count remaining one-bits in bit plane */ c = 0; for (i = m; i < size; i++) c += (data[i] >> k) & 1u; /* step 3: unary run-length encode remainder of bit plane */ for (; bits && n < size; n++) { bits--; if (stream_write_bit(&s, !!c)) { /* positive group test (c > 0); scan for one-bit */ for (c--; bits && n < size - 1; n++) { bits--; if (stream_write_bit(&s, (data[n] >> k) & 1u)) break; } } else { /* negative group test (c == 0); done with bit plane */ break; } } } *stream = s; return maxbits - bits; } /* compress sequence of size <= 64 unsigned integers with no rate constraint */ static uint _t1(encode_few_ints_prec, UInt)(bitstream* restrict_ stream, uint maxprec, const UInt* restrict_ data, uint size) { /* make a copy of bit stream to avoid aliasing */ bitstream s = *stream; bitstream_offset offset = stream_wtell(&s); uint intprec = (uint)(CHAR_BIT * sizeof(UInt)); uint kmin = intprec > maxprec ? intprec - maxprec : 0; uint i, k, n; /* encode one bit plane at a time from MSB to LSB */ for (k = intprec, n = 0; k-- > kmin;) { /* step 1: extract bit plane #k to x */ uint64 x = 0; for (i = 0; i < size; i++) x += (uint64)((data[i] >> k) & 1u) << i; /* step 2: encode first n bits of bit plane */ x = stream_write_bits(&s, x, n); /* step 3: unary run-length encode remainder of bit plane */ for (; n < size && stream_write_bit(&s, !!x); x >>= 1, n++) for (; n < size - 1 && !stream_write_bit(&s, x & 1u); x >>= 1, n++) ; } *stream = s; return (uint)(stream_wtell(&s) - offset); } /* compress sequence of size > 64 unsigned integers with no rate constraint */ static uint _t1(encode_many_ints_prec, UInt)(bitstream* restrict_ stream, uint maxprec, const UInt* restrict_ data, uint size) { /* make a copy of bit stream to avoid aliasing */ bitstream s = *stream; bitstream_offset offset = stream_wtell(&s); uint intprec = (uint)(CHAR_BIT * sizeof(UInt)); uint kmin = intprec > maxprec ? intprec - maxprec : 0; uint i, k, n, c; /* encode one bit plane at a time from MSB to LSB */ for (k = intprec, n = 0; k-- > kmin;) { /* step 1: encode first n bits of bit plane #k */ for (i = 0; i < n; i++) stream_write_bit(&s, (data[i] >> k) & 1u); /* step 2: count remaining one-bits in bit plane */ c = 0; for (i = n; i < size; i++) c += (data[i] >> k) & 1u; /* step 3: unary run-length encode remainder of bit plane */ for (; n < size && stream_write_bit(&s, !!c); n++) for (c--; n < size - 1 && !stream_write_bit(&s, (data[n] >> k) & 1u); n++) ; } *stream = s; return (uint)(stream_wtell(&s) - offset); } /* compress sequence of size unsigned integers */ static uint _t1(encode_ints, UInt)(bitstream* restrict_ stream, uint maxbits, uint maxprec, const UInt* restrict_ data, uint size) { /* use fastest available encoder implementation */ if (with_maxbits(maxbits, maxprec, size)) { /* rate constrained path: encode partial bit planes */ if (size <= 64) return _t1(encode_few_ints, UInt)(stream, maxbits, maxprec, data, size); /* 1D, 2D, 3D blocks */ else return _t1(encode_many_ints, UInt)(stream, maxbits, maxprec, data, size); /* 4D blocks */ } else { /* variable-rate path: encode whole bit planes */ if (size <= 64) return _t1(encode_few_ints_prec, UInt)(stream, maxprec, data, size); /* 1D, 2D, 3D blocks */ else return _t1(encode_many_ints_prec, UInt)(stream, maxprec, data, size); /* 4D blocks */ } } /* encode block of integers */ static uint _t2(encode_block, Int, DIMS)(bitstream* stream, uint minbits, uint maxbits, uint maxprec, Int* iblock) { uint bits; cache_align_(UInt ublock[BLOCK_SIZE]); /* perform decorrelating transform */ _t2(fwd_xform, Int, DIMS)(iblock); #if ZFP_ROUNDING_MODE == ZFP_ROUND_FIRST /* bias values to achieve proper rounding */ _t1(fwd_round, Int)(iblock, BLOCK_SIZE, maxprec); #endif /* reorder signed coefficients and convert to unsigned integer */ _t1(fwd_order, Int)(ublock, iblock, PERM, BLOCK_SIZE); /* encode integer coefficients */ bits = _t1(encode_ints, UInt)(stream, maxbits, maxprec, ublock, BLOCK_SIZE); /* write at least minbits bits by padding with zeros */ if (bits < minbits) { stream_pad(stream, minbits - bits); bits = minbits; } return bits; } zfp-1.0.1/src/template/encode1.c000066400000000000000000000027011453723256400164070ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* gather 4-value block from strided array */ static void _t2(gather, Scalar, 1)(Scalar* q, const Scalar* p, ptrdiff_t sx) { uint x; for (x = 0; x < 4; x++, p += sx) *q++ = *p; } /* gather nx-value block from strided array */ static void _t2(gather_partial, Scalar, 1)(Scalar* q, const Scalar* p, size_t nx, ptrdiff_t sx) { size_t x; for (x = 0; x < nx; x++, p += sx) q[x] = *p; _t1(pad_block, Scalar)(q, nx, 1); } /* forward decorrelating 1D transform */ static void _t2(fwd_xform, Int, 1)(Int* p) { /* transform along x */ _t1(fwd_lift, Int)(p, 1); } /* public functions -------------------------------------------------------- */ /* encode 4-value block stored at p using stride sx */ size_t _t2(zfp_encode_block_strided, Scalar, 1)(zfp_stream* stream, const Scalar* p, ptrdiff_t sx) { /* gather block from strided array */ cache_align_(Scalar block[4]); _t2(gather, Scalar, 1)(block, p, sx); /* encode block */ return _t2(zfp_encode_block, Scalar, 1)(stream, block); } /* encode nx-value block stored at p using stride sx */ size_t _t2(zfp_encode_partial_block_strided, Scalar, 1)(zfp_stream* stream, const Scalar* p, size_t nx, ptrdiff_t sx) { /* gather block from strided array */ cache_align_(Scalar block[4]); _t2(gather_partial, Scalar, 1)(block, p, nx, sx); /* encode block */ return _t2(zfp_encode_block, Scalar, 1)(stream, block); } zfp-1.0.1/src/template/encode2.c000066400000000000000000000035671453723256400164230ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* gather 4*4 block from strided array */ static void _t2(gather, Scalar, 2)(Scalar* q, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy) { uint x, y; for (y = 0; y < 4; y++, p += sy - 4 * sx) for (x = 0; x < 4; x++, p += sx) *q++ = *p; } /* gather nx*ny block from strided array */ static void _t2(gather_partial, Scalar, 2)(Scalar* q, const Scalar* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) { size_t x, y; for (y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx) { for (x = 0; x < nx; x++, p += sx) q[4 * y + x] = *p; _t1(pad_block, Scalar)(q + 4 * y, nx, 1); } for (x = 0; x < 4; x++) _t1(pad_block, Scalar)(q + x, ny, 4); } /* forward decorrelating 2D transform */ static void _t2(fwd_xform, Int, 2)(Int* p) { uint x, y; /* transform along x */ for (y = 0; y < 4; y++) _t1(fwd_lift, Int)(p + 4 * y, 1); /* transform along y */ for (x = 0; x < 4; x++) _t1(fwd_lift, Int)(p + 1 * x, 4); } /* public functions -------------------------------------------------------- */ /* encode 4*4 block stored at p using strides (sx, sy) */ size_t _t2(zfp_encode_block_strided, Scalar, 2)(zfp_stream* stream, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy) { /* gather block from strided array */ cache_align_(Scalar block[16]); _t2(gather, Scalar, 2)(block, p, sx, sy); /* encode block */ return _t2(zfp_encode_block, Scalar, 2)(stream, block); } /* encode nx*ny block stored at p using strides (sx, sy) */ size_t _t2(zfp_encode_partial_block_strided, Scalar, 2)(zfp_stream* stream, const Scalar* p, size_t nx, size_t ny, ptrdiff_t sx, ptrdiff_t sy) { /* gather block from strided array */ cache_align_(Scalar block[16]); _t2(gather_partial, Scalar, 2)(block, p, nx, ny, sx, sy); /* encode block */ return _t2(zfp_encode_block, Scalar, 2)(stream, block); } zfp-1.0.1/src/template/encode3.c000066400000000000000000000047011453723256400164130ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* gather 4*4*4 block from strided array */ static void _t2(gather, Scalar, 3)(Scalar* q, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { uint x, y, z; for (z = 0; z < 4; z++, p += sz - 4 * sy) for (y = 0; y < 4; y++, p += sy - 4 * sx) for (x = 0; x < 4; x++, p += sx) *q++ = *p; } /* gather nx*ny*nz block from strided array */ static void _t2(gather_partial, Scalar, 3)(Scalar* q, const Scalar* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { size_t x, y, z; for (z = 0; z < nz; z++, p += sz - (ptrdiff_t)ny * sy) { for (y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx) { for (x = 0; x < nx; x++, p += sx) q[16 * z + 4 * y + x] = *p; _t1(pad_block, Scalar)(q + 16 * z + 4 * y, nx, 1); } for (x = 0; x < 4; x++) _t1(pad_block, Scalar)(q + 16 * z + x, ny, 4); } for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) _t1(pad_block, Scalar)(q + 4 * y + x, nz, 16); } /* forward decorrelating 3D transform */ static void _t2(fwd_xform, Int, 3)(Int* p) { uint x, y, z; /* transform along x */ for (z = 0; z < 4; z++) for (y = 0; y < 4; y++) _t1(fwd_lift, Int)(p + 4 * y + 16 * z, 1); /* transform along y */ for (x = 0; x < 4; x++) for (z = 0; z < 4; z++) _t1(fwd_lift, Int)(p + 16 * z + 1 * x, 4); /* transform along z */ for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) _t1(fwd_lift, Int)(p + 1 * x + 4 * y, 16); } /* public functions -------------------------------------------------------- */ /* encode 4*4*4 block stored at p using strides (sx, sy, sz) */ size_t _t2(zfp_encode_block_strided, Scalar, 3)(zfp_stream* stream, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { /* gather block from strided array */ cache_align_(Scalar block[64]); _t2(gather, Scalar, 3)(block, p, sx, sy, sz); /* encode block */ return _t2(zfp_encode_block, Scalar, 3)(stream, block); } /* encode nx*ny*nz block stored at p using strides (sx, sy, sz) */ size_t _t2(zfp_encode_partial_block_strided, Scalar, 3)(zfp_stream* stream, const Scalar* p, size_t nx, size_t ny, size_t nz, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { /* gather block from strided array */ cache_align_(Scalar block[64]); _t2(gather_partial, Scalar, 3)(block, p, nx, ny, nz, sx, sy, sz); /* encode block */ return _t2(zfp_encode_block, Scalar, 3)(stream, block); } zfp-1.0.1/src/template/encode4.c000066400000000000000000000062401453723256400164140ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* gather 4*4*4*4 block from strided array */ static void _t2(gather, Scalar, 4)(Scalar* q, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { uint x, y, z, w; for (w = 0; w < 4; w++, p += sw - 4 * sz) for (z = 0; z < 4; z++, p += sz - 4 * sy) for (y = 0; y < 4; y++, p += sy - 4 * sx) for (x = 0; x < 4; x++, p += sx) *q++ = *p; } /* gather nx*ny*nz*nw block from strided array */ static void _t2(gather_partial, Scalar, 4)(Scalar* q, const Scalar* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { size_t x, y, z, w; for (w = 0; w < nw; w++, p += sw - (ptrdiff_t)nz * sz) { for (z = 0; z < nz; z++, p += sz - (ptrdiff_t)ny * sy) { for (y = 0; y < ny; y++, p += sy - (ptrdiff_t)nx * sx) { for (x = 0; x < nx; x++, p += sx) q[64 * w + 16 * z + 4 * y + x] = *p; _t1(pad_block, Scalar)(q + 64 * w + 16 * z + 4 * y, nx, 1); } for (x = 0; x < 4; x++) _t1(pad_block, Scalar)(q + 64 * w + 16 * z + x, ny, 4); } for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) _t1(pad_block, Scalar)(q + 64 * w + 4 * y + x, nz, 16); } for (z = 0; z < 4; z++) for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) _t1(pad_block, Scalar)(q + 16 * z + 4 * y + x, nw, 64); } /* forward decorrelating 4D transform */ static void _t2(fwd_xform, Int, 4)(Int* p) { uint x, y, z, w; /* transform along x */ for (w = 0; w < 4; w++) for (z = 0; z < 4; z++) for (y = 0; y < 4; y++) _t1(fwd_lift, Int)(p + 4 * y + 16 * z + 64 * w, 1); /* transform along y */ for (x = 0; x < 4; x++) for (w = 0; w < 4; w++) for (z = 0; z < 4; z++) _t1(fwd_lift, Int)(p + 16 * z + 64 * w + 1 * x, 4); /* transform along z */ for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) for (w = 0; w < 4; w++) _t1(fwd_lift, Int)(p + 64 * w + 1 * x + 4 * y, 16); /* transform along w */ for (z = 0; z < 4; z++) for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) _t1(fwd_lift, Int)(p + 1 * x + 4 * y + 16 * z, 64); } /* public functions -------------------------------------------------------- */ /* encode 4*4*4*4 block stored at p using strides (sx, sy, sz, sw) */ size_t _t2(zfp_encode_block_strided, Scalar, 4)(zfp_stream* stream, const Scalar* p, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { /* gather block from strided array */ cache_align_(Scalar block[256]); _t2(gather, Scalar, 4)(block, p, sx, sy, sz, sw); /* encode block */ return _t2(zfp_encode_block, Scalar, 4)(stream, block); } /* encode nx*ny*nz*nw block stored at p using strides (sx, sy, sz, sw) */ size_t _t2(zfp_encode_partial_block_strided, Scalar, 4)(zfp_stream* stream, const Scalar* p, size_t nx, size_t ny, size_t nz, size_t nw, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { /* gather block from strided array */ cache_align_(Scalar block[256]); _t2(gather_partial, Scalar, 4)(block, p, nx, ny, nz, nw, sx, sy, sz, sw); /* encode block */ return _t2(zfp_encode_block, Scalar, 4)(stream, block); } zfp-1.0.1/src/template/encodef.c000066400000000000000000000057411453723256400165030ustar00rootroot00000000000000#include #include #include static uint _t2(rev_encode_block, Scalar, DIMS)(zfp_stream* zfp, const Scalar* fblock); /* private functions ------------------------------------------------------- */ /* return normalized floating-point exponent for x >= 0 */ static int _t1(exponent, Scalar)(Scalar x) { /* use e = -EBIAS when x = 0 */ int e = -EBIAS; #ifdef ZFP_WITH_DAZ /* treat subnormals as zero; resolves issue #119 by avoiding overflow */ if (x >= SCALAR_MIN) FREXP(x, &e); #else if (x > 0) { FREXP(x, &e); /* clamp exponent in case x is subnormal; may still result in overflow */ e = MAX(e, 1 - EBIAS); } #endif return e; } /* compute maximum floating-point exponent in block of n values */ static int _t1(exponent_block, Scalar)(const Scalar* p, uint n) { Scalar max = 0; do { Scalar f = FABS(*p++); if (max < f) max = f; } while (--n); return _t1(exponent, Scalar)(max); } /* map floating-point number x to integer relative to exponent e */ static Scalar _t1(quantize, Scalar)(Scalar x, int e) { return LDEXP(x, ((int)(CHAR_BIT * sizeof(Scalar)) - 2) - e); } /* forward block-floating-point transform to signed integers */ static void _t1(fwd_cast, Scalar)(Int* iblock, const Scalar* fblock, uint n, int emax) { /* compute power-of-two scale factor s */ Scalar s = _t1(quantize, Scalar)(1, emax); /* compute p-bit int y = s*x where x is floating and |y| <= 2^(p-2) - 1 */ do *iblock++ = (Int)(s * *fblock++); while (--n); } /* encode contiguous floating-point block using lossy algorithm */ static uint _t2(encode_block, Scalar, DIMS)(zfp_stream* zfp, const Scalar* fblock) { uint bits = 1; /* compute maximum exponent */ int emax = _t1(exponent_block, Scalar)(fblock, BLOCK_SIZE); uint maxprec = precision(emax, zfp->maxprec, zfp->minexp, DIMS); uint e = maxprec ? (uint)(emax + EBIAS) : 0; /* encode block only if biased exponent is nonzero */ if (e) { cache_align_(Int iblock[BLOCK_SIZE]); /* encode common exponent; LSB indicates that exponent is nonzero */ bits += EBITS; stream_write_bits(zfp->stream, 2 * e + 1, bits); /* perform forward block-floating-point transform */ _t1(fwd_cast, Scalar)(iblock, fblock, BLOCK_SIZE, emax); /* encode integer block */ bits += _t2(encode_block, Int, DIMS)(zfp->stream, zfp->minbits - MIN(bits, zfp->minbits), zfp->maxbits - bits, maxprec, iblock); } else { /* write single zero-bit to indicate that all values are zero */ stream_write_bit(zfp->stream, 0); if (zfp->minbits > bits) { stream_pad(zfp->stream, zfp->minbits - bits); bits = zfp->minbits; } } return bits; } /* public functions -------------------------------------------------------- */ /* encode contiguous floating-point block */ size_t _t2(zfp_encode_block, Scalar, DIMS)(zfp_stream* zfp, const Scalar* fblock) { return REVERSIBLE(zfp) ? _t2(rev_encode_block, Scalar, DIMS)(zfp, fblock) : _t2(encode_block, Scalar, DIMS)(zfp, fblock); } zfp-1.0.1/src/template/encodei.c000066400000000000000000000012311453723256400164740ustar00rootroot00000000000000static uint _t2(rev_encode_block, Int, DIMS)(bitstream* stream, uint minbits, uint maxbits, uint maxprec, Int* iblock); /* public functions -------------------------------------------------------- */ /* encode contiguous integer block */ size_t _t2(zfp_encode_block, Int, DIMS)(zfp_stream* zfp, const Int* iblock) { cache_align_(Int block[BLOCK_SIZE]); uint i; /* copy block */ for (i = 0; i < BLOCK_SIZE; i++) block[i] = iblock[i]; return REVERSIBLE(zfp) ? _t2(rev_encode_block, Int, DIMS)(zfp->stream, zfp->minbits, zfp->maxbits, zfp->maxprec, block) : _t2(encode_block, Int, DIMS)(zfp->stream, zfp->minbits, zfp->maxbits, zfp->maxprec, block); } zfp-1.0.1/src/template/ompcompress.c000066400000000000000000000226771453723256400174560ustar00rootroot00000000000000#ifdef _OPENMP /* compress 1d contiguous array in parallel */ static void _t2(compress_omp, Scalar, 1)(zfp_stream* stream, const zfp_field* field) { /* array metadata */ const Scalar* data = (const Scalar*)field->data; size_t nx = field->nx; /* number of omp threads, blocks, and chunks */ uint threads = thread_count_omp(stream); size_t blocks = (nx + 3) / 4; size_t chunks = chunk_count_omp(stream, blocks, threads); int chunk; /* OpenMP 2.0 requires int loop counter */ /* allocate per-thread streams */ bitstream** bs = compress_init_par(stream, field, chunks, blocks); if (!bs) return; /* compress chunks of blocks in parallel */ #pragma omp parallel for num_threads(threads) for (chunk = 0; chunk < (int)chunks; chunk++) { /* determine range of block indices assigned to this thread */ size_t bmin = chunk_offset(blocks, chunks, chunk + 0); size_t bmax = chunk_offset(blocks, chunks, chunk + 1); size_t block; /* set up thread-local bit stream */ zfp_stream s = *stream; zfp_stream_set_bit_stream(&s, bs[chunk]); /* compress sequence of blocks */ for (block = bmin; block < bmax; block++) { /* determine block origin x within array */ const Scalar* p = data; size_t x = 4 * block; p += x; /* compress partial or full block */ if (nx - x < 4u) _t2(zfp_encode_partial_block_strided, Scalar, 1)(&s, p, nx - x, 1); else _t2(zfp_encode_block, Scalar, 1)(&s, p); } } /* concatenate per-thread streams */ compress_finish_par(stream, bs, chunks); } /* compress 1d strided array in parallel */ static void _t2(compress_strided_omp, Scalar, 1)(zfp_stream* stream, const zfp_field* field) { /* array metadata */ const Scalar* data = (const Scalar*)field->data; size_t nx = field->nx; ptrdiff_t sx = field->sx ? field->sx : 1; /* number of omp threads, blocks, and chunks */ uint threads = thread_count_omp(stream); size_t blocks = (nx + 3) / 4; size_t chunks = chunk_count_omp(stream, blocks, threads); int chunk; /* OpenMP 2.0 requires int loop counter */ /* allocate per-thread streams */ bitstream** bs = compress_init_par(stream, field, chunks, blocks); if (!bs) return; /* compress chunks of blocks in parallel */ #pragma omp parallel for num_threads(threads) for (chunk = 0; chunk < (int)chunks; chunk++) { /* determine range of block indices assigned to this thread */ size_t bmin = chunk_offset(blocks, chunks, chunk + 0); size_t bmax = chunk_offset(blocks, chunks, chunk + 1); size_t block; /* set up thread-local bit stream */ zfp_stream s = *stream; zfp_stream_set_bit_stream(&s, bs[chunk]); /* compress sequence of blocks */ for (block = bmin; block < bmax; block++) { /* determine block origin x within array */ const Scalar* p = data; size_t x = 4 * block; p += sx * (ptrdiff_t)x; /* compress partial or full block */ if (nx - x < 4u) _t2(zfp_encode_partial_block_strided, Scalar, 1)(&s, p, nx - x, sx); else _t2(zfp_encode_block_strided, Scalar, 1)(&s, p, sx); } } /* concatenate per-thread streams */ compress_finish_par(stream, bs, chunks); } /* compress 2d strided array in parallel */ static void _t2(compress_strided_omp, Scalar, 2)(zfp_stream* stream, const zfp_field* field) { /* array metadata */ const Scalar* data = (const Scalar*)field->data; size_t nx = field->nx; size_t ny = field->ny; ptrdiff_t sx = field->sx ? field->sx : 1; ptrdiff_t sy = field->sy ? field->sy : (ptrdiff_t)nx; /* number of omp threads, blocks, and chunks */ uint threads = thread_count_omp(stream); size_t bx = (nx + 3) / 4; size_t by = (ny + 3) / 4; size_t blocks = bx * by; size_t chunks = chunk_count_omp(stream, blocks, threads); int chunk; /* OpenMP 2.0 requires int loop counter */ /* allocate per-thread streams */ bitstream** bs = compress_init_par(stream, field, chunks, blocks); if (!bs) return; /* compress chunks of blocks in parallel */ #pragma omp parallel for num_threads(threads) for (chunk = 0; chunk < (int)chunks; chunk++) { /* determine range of block indices assigned to this thread */ size_t bmin = chunk_offset(blocks, chunks, chunk + 0); size_t bmax = chunk_offset(blocks, chunks, chunk + 1); size_t block; /* set up thread-local bit stream */ zfp_stream s = *stream; zfp_stream_set_bit_stream(&s, bs[chunk]); /* compress sequence of blocks */ for (block = bmin; block < bmax; block++) { /* determine block origin (x, y) within array */ const Scalar* p = data; size_t b = block; size_t x, y; x = 4 * (b % bx); b /= bx; y = 4 * b; p += sx * (ptrdiff_t)x + sy * (ptrdiff_t)y; /* compress partial or full block */ if (nx - x < 4u || ny - y < 4u) _t2(zfp_encode_partial_block_strided, Scalar, 2)(&s, p, MIN(nx - x, 4u), MIN(ny - y, 4u), sx, sy); else _t2(zfp_encode_block_strided, Scalar, 2)(&s, p, sx, sy); } } /* concatenate per-thread streams */ compress_finish_par(stream, bs, chunks); } /* compress 3d strided array in parallel */ static void _t2(compress_strided_omp, Scalar, 3)(zfp_stream* stream, const zfp_field* field) { /* array metadata */ const Scalar* data = (const Scalar*)field->data; size_t nx = field->nx; size_t ny = field->ny; size_t nz = field->nz; ptrdiff_t sx = field->sx ? field->sx : 1; ptrdiff_t sy = field->sy ? field->sy : (ptrdiff_t)nx; ptrdiff_t sz = field->sz ? field->sz : (ptrdiff_t)(nx * ny); /* number of omp threads, blocks, and chunks */ uint threads = thread_count_omp(stream); size_t bx = (nx + 3) / 4; size_t by = (ny + 3) / 4; size_t bz = (nz + 3) / 4; size_t blocks = bx * by * bz; size_t chunks = chunk_count_omp(stream, blocks, threads); int chunk; /* OpenMP 2.0 requires int loop counter */ /* allocate per-thread streams */ bitstream** bs = compress_init_par(stream, field, chunks, blocks); if (!bs) return; /* compress chunks of blocks in parallel */ #pragma omp parallel for num_threads(threads) for (chunk = 0; chunk < (int)chunks; chunk++) { /* determine range of block indices assigned to this thread */ size_t bmin = chunk_offset(blocks, chunks, chunk + 0); size_t bmax = chunk_offset(blocks, chunks, chunk + 1); size_t block; /* set up thread-local bit stream */ zfp_stream s = *stream; zfp_stream_set_bit_stream(&s, bs[chunk]); /* compress sequence of blocks */ for (block = bmin; block < bmax; block++) { /* determine block origin (x, y, z) within array */ const Scalar* p = data; size_t b = block; size_t x, y, z; x = 4 * (b % bx); b /= bx; y = 4 * (b % by); b /= by; z = 4 * b; p += sx * (ptrdiff_t)x + sy * (ptrdiff_t)y + sz * (ptrdiff_t)z; /* compress partial or full block */ if (nx - x < 4u || ny - y < 4u || nz - z < 4u) _t2(zfp_encode_partial_block_strided, Scalar, 3)(&s, p, MIN(nx - x, 4u), MIN(ny - y, 4u), MIN(nz - z, 4u), sx, sy, sz); else _t2(zfp_encode_block_strided, Scalar, 3)(&s, p, sx, sy, sz); } } /* concatenate per-thread streams */ compress_finish_par(stream, bs, chunks); } /* compress 4d strided array in parallel */ static void _t2(compress_strided_omp, Scalar, 4)(zfp_stream* stream, const zfp_field* field) { /* array metadata */ const Scalar* data = field->data; size_t nx = field->nx; size_t ny = field->ny; size_t nz = field->nz; size_t nw = field->nw; ptrdiff_t sx = field->sx ? field->sx : 1; ptrdiff_t sy = field->sy ? field->sy : (ptrdiff_t)nx; ptrdiff_t sz = field->sz ? field->sz : (ptrdiff_t)(nx * ny); ptrdiff_t sw = field->sw ? field->sw : (ptrdiff_t)(nx * ny * nz); /* number of omp threads, blocks, and chunks */ uint threads = thread_count_omp(stream); size_t bx = (nx + 3) / 4; size_t by = (ny + 3) / 4; size_t bz = (nz + 3) / 4; size_t bw = (nw + 3) / 4; size_t blocks = bx * by * bz * bw; size_t chunks = chunk_count_omp(stream, blocks, threads); int chunk; /* OpenMP 2.0 requires int loop counter */ /* allocate per-thread streams */ bitstream** bs = compress_init_par(stream, field, chunks, blocks); if (!bs) return; /* compress chunks of blocks in parallel */ #pragma omp parallel for num_threads(threads) for (chunk = 0; chunk < (int)chunks; chunk++) { /* determine range of block indices assigned to this thread */ size_t bmin = chunk_offset(blocks, chunks, chunk + 0); size_t bmax = chunk_offset(blocks, chunks, chunk + 1); size_t block; /* set up thread-local bit stream */ zfp_stream s = *stream; zfp_stream_set_bit_stream(&s, bs[chunk]); /* compress sequence of blocks */ for (block = bmin; block < bmax; block++) { /* determine block origin (x, y, z, w) within array */ const Scalar* p = data; size_t b = block; size_t x, y, z, w; x = 4 * (b % bx); b /= bx; y = 4 * (b % by); b /= by; z = 4 * (b % bz); b /= bz; w = 4 * b; p += sx * (ptrdiff_t)x + sy * (ptrdiff_t)y + sz * (ptrdiff_t)z + sw * (ptrdiff_t)w; /* compress partial or full block */ if (nx - x < 4u || ny - y < 4u || nz - z < 4u || nw - w < 4u) _t2(zfp_encode_partial_block_strided, Scalar, 4)(&s, p, MIN(nx - x, 4u), MIN(ny - y, 4u), MIN(nz - z, 4u), MIN(nw - w, 4u), sx, sy, sz, sw); else _t2(zfp_encode_block_strided, Scalar, 4)(&s, p, sx, sy, sz, sw); } } /* concatenate per-thread streams */ compress_finish_par(stream, bs, chunks); } #endif zfp-1.0.1/src/template/revcodecf.c000066400000000000000000000005261453723256400170340ustar00rootroot00000000000000/* inverse block-floating-point transform from signed integers */ static void _t1(rev_inv_cast, Scalar)(const Int* iblock, Scalar* fblock, uint n, int emax) { /* test for all-zero block, which needs special treatment */ if (emax != -EBIAS) _t1(inv_cast, Scalar)(iblock, fblock, n, emax); else while (n--) *fblock++ = 0; } zfp-1.0.1/src/template/revdecode.c000066400000000000000000000026021453723256400170310ustar00rootroot00000000000000static void _t2(rev_inv_xform, Int, DIMS)(Int* p); /* private functions ------------------------------------------------------- */ /* reversible inverse lifting transform of 4-vector */ static void _t1(rev_inv_lift, Int)(Int* p, uint s) { Int x, y, z, w; x = *p; p += s; y = *p; p += s; z = *p; p += s; w = *p; p += s; /* ** high-order Lorenzo transform (P4 Pascal matrix) ** ( 1 0 0 0) (x) ** ( 1 1 0 0) (y) ** ( 1 2 1 0) (z) ** ( 1 3 3 1) (w) */ w += z; z += y; w += z; y += x; z += y; w += z; p -= s; *p = w; p -= s; *p = z; p -= s; *p = y; p -= s; *p = x; } /* decode block of integers using reversible algorithm */ static uint _t2(rev_decode_block, Int, DIMS)(bitstream* stream, uint minbits, uint maxbits, Int* iblock) { /* decode number of significant bits */ uint bits = PBITS; uint prec = (uint)stream_read_bits(stream, PBITS) + 1; cache_align_(UInt ublock[BLOCK_SIZE]); /* decode integer coefficients */ bits += _t1(decode_ints, UInt)(stream, maxbits - bits, prec, ublock, BLOCK_SIZE); /* read at least minbits bits */ if (bits < minbits) { stream_skip(stream, minbits - bits); bits = minbits; } /* reorder unsigned coefficients and convert to signed integer */ _t1(inv_order, Int)(ublock, iblock, PERM, BLOCK_SIZE); /* perform decorrelating transform */ _t2(rev_inv_xform, Int, DIMS)(iblock); return bits; } zfp-1.0.1/src/template/revdecode1.c000066400000000000000000000003621453723256400171130ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* reversible inverse decorrelating 1D transform */ static void _t2(rev_inv_xform, Int, 1)(Int* p) { /* transform along x */ _t1(rev_inv_lift, Int)(p, 1); } zfp-1.0.1/src/template/revdecode2.c000066400000000000000000000006011453723256400171100ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* reversible inverse decorrelating 2D transform */ static void _t2(rev_inv_xform, Int, 2)(Int* p) { uint x, y; /* transform along y */ for (x = 0; x < 4; x++) _t1(rev_inv_lift, Int)(p + 1 * x, 4); /* transform along x */ for (y = 0; y < 4; y++) _t1(rev_inv_lift, Int)(p + 4 * y, 1); } zfp-1.0.1/src/template/revdecode3.c000066400000000000000000000011271453723256400171150ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* reversible inverse decorrelating 3D transform */ static void _t2(rev_inv_xform, Int, 3)(Int* p) { uint x, y, z; /* transform along z */ for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) _t1(rev_inv_lift, Int)(p + 1 * x + 4 * y, 16); /* transform along y */ for (x = 0; x < 4; x++) for (z = 0; z < 4; z++) _t1(rev_inv_lift, Int)(p + 16 * z + 1 * x, 4); /* transform along x */ for (z = 0; z < 4; z++) for (y = 0; y < 4; y++) _t1(rev_inv_lift, Int)(p + 4 * y + 16 * z, 1); } zfp-1.0.1/src/template/revdecode4.c000066400000000000000000000016031453723256400171150ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* reversible inverse decorrelating 4D transform */ static void _t2(rev_inv_xform, Int, 4)(Int* p) { uint x, y, z, w; /* transform along w */ for (z = 0; z < 4; z++) for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) _t1(rev_inv_lift, Int)(p + 1 * x + 4 * y + 16 * z, 64); /* transform along z */ for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) for (w = 0; w < 4; w++) _t1(rev_inv_lift, Int)(p + 64 * w + 1 * x + 4 * y, 16); /* transform along y */ for (x = 0; x < 4; x++) for (w = 0; w < 4; w++) for (z = 0; z < 4; z++) _t1(rev_inv_lift, Int)(p + 16 * z + 64 * w + 1 * x, 4); /* transform along x */ for (w = 0; w < 4; w++) for (z = 0; z < 4; z++) for (y = 0; y < 4; y++) _t1(rev_inv_lift, Int)(p + 4 * y + 16 * z + 64 * w, 1); } zfp-1.0.1/src/template/revdecodef.c000066400000000000000000000036771453723256400172140ustar00rootroot00000000000000#include /* private functions ------------------------------------------------------- */ /* reinterpret two's complement integers as floating values */ static void _t1(rev_inv_reinterpret, Scalar)(Int* iblock, Scalar* fblock, uint n) { /* convert two's complement integers to sign-magnitude integers */ uint i; for (i = 0; i < n; i++) { Int x = iblock[i]; if (x < 0) iblock[i] = (Int)((UInt)x ^ TCMASK); } /* reinterpret sign-magnitude integers as floating values */ memcpy(fblock, iblock, n * sizeof(*fblock)); } /* decode contiguous floating-point block using reversible algorithm */ static uint _t2(rev_decode_block, Scalar, DIMS)(zfp_stream* zfp, Scalar* fblock) { uint bits = 0; cache_align_(Int iblock[BLOCK_SIZE]); /* test whether block is all-zero */ bits++; if (stream_read_bit(zfp->stream)) { /* non-zero block; test whether to use block-floating-point transform */ bits++; if (stream_read_bit(zfp->stream)) { /* decode integer block */ bits += _t2(rev_decode_block, Int, DIMS)(zfp->stream, zfp->minbits - MIN(bits, zfp->minbits), zfp->maxbits - bits, iblock); /* reinterpret integers as floating values */ _t1(rev_inv_reinterpret, Scalar)(iblock, fblock, BLOCK_SIZE); } else { /* decode common exponent */ int emax; bits += EBITS; emax = (int)stream_read_bits(zfp->stream, EBITS) - EBIAS; /* decode integer block */ bits += _t2(rev_decode_block, Int, DIMS)(zfp->stream, zfp->minbits - MIN(bits, zfp->minbits), zfp->maxbits - bits, iblock); /* perform inverse block-floating-point transform */ _t1(rev_inv_cast, Scalar)(iblock, fblock, BLOCK_SIZE, emax); } } else { /* all-zero block; set all values to zero */ uint i; for (i = 0; i < BLOCK_SIZE; i++) *fblock++ = 0; if (zfp->minbits > bits) { stream_skip(zfp->stream, zfp->minbits - bits); bits = zfp->minbits; } } return bits; } zfp-1.0.1/src/template/revencode.c000066400000000000000000000037061453723256400170510ustar00rootroot00000000000000static void _t2(rev_fwd_xform, Int, DIMS)(Int* p); /* private functions ------------------------------------------------------- */ /* reversible forward lifting transform of 4-vector */ static void _t1(rev_fwd_lift, Int)(Int* p, uint s) { Int x, y, z, w; x = *p; p += s; y = *p; p += s; z = *p; p += s; w = *p; p += s; /* ** high-order Lorenzo transform ** ( 1 0 0 0) (x) ** (-1 1 0 0) (y) ** ( 1 -2 1 0) (z) ** (-1 3 -3 1) (w) */ w -= z; z -= y; y -= x; w -= z; z -= y; w -= z; p -= s; *p = w; p -= s; *p = z; p -= s; *p = y; p -= s; *p = x; } /* return precision required to encode block reversibly */ static uint _t1(rev_precision, UInt)(const UInt* block, uint n) { uint p = 0; uint s; /* compute bitwise OR of all values */ UInt m = 0; while (n--) m |= *block++; /* count trailing zeros via binary search */ for (s = (uint)(CHAR_BIT * sizeof(UInt)); m; s /= 2) if ((UInt)(m << (s - 1))) { m <<= s - 1; m <<= 1; p += s; } return p; } /* encode block of integers using reversible algorithm */ static uint _t2(rev_encode_block, Int, DIMS)(bitstream* stream, uint minbits, uint maxbits, uint maxprec, Int* iblock) { uint bits = PBITS; uint prec; cache_align_(UInt ublock[BLOCK_SIZE]); /* perform decorrelating transform */ _t2(rev_fwd_xform, Int, DIMS)(iblock); /* reorder signed coefficients and convert to unsigned integer */ _t1(fwd_order, Int)(ublock, iblock, PERM, BLOCK_SIZE); /* determine and encode number of significant bits */ prec = _t1(rev_precision, UInt)(ublock, BLOCK_SIZE); prec = MIN(prec, maxprec); prec = MAX(prec, 1); stream_write_bits(stream, prec - 1, PBITS); /* encode integer coefficients */ bits += _t1(encode_ints, UInt)(stream, maxbits - bits, prec, ublock, BLOCK_SIZE); /* write at least minbits bits by padding with zeros */ if (bits < minbits) { stream_pad(stream, minbits - bits); bits = minbits; } return bits; } zfp-1.0.1/src/template/revencode1.c000066400000000000000000000003621453723256400171250ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* reversible forward decorrelating 1D transform */ static void _t2(rev_fwd_xform, Int, 1)(Int* p) { /* transform along x */ _t1(rev_fwd_lift, Int)(p, 1); } zfp-1.0.1/src/template/revencode2.c000066400000000000000000000006011453723256400171220ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* reversible forward decorrelating 2D transform */ static void _t2(rev_fwd_xform, Int, 2)(Int* p) { uint x, y; /* transform along x */ for (y = 0; y < 4; y++) _t1(rev_fwd_lift, Int)(p + 4 * y, 1); /* transform along y */ for (x = 0; x < 4; x++) _t1(rev_fwd_lift, Int)(p + 1 * x, 4); } zfp-1.0.1/src/template/revencode3.c000066400000000000000000000011271453723256400171270ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* reversible forward decorrelating 3D transform */ static void _t2(rev_fwd_xform, Int, 3)(Int* p) { uint x, y, z; /* transform along x */ for (z = 0; z < 4; z++) for (y = 0; y < 4; y++) _t1(rev_fwd_lift, Int)(p + 4 * y + 16 * z, 1); /* transform along y */ for (x = 0; x < 4; x++) for (z = 0; z < 4; z++) _t1(rev_fwd_lift, Int)(p + 16 * z + 1 * x, 4); /* transform along z */ for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) _t1(rev_fwd_lift, Int)(p + 1 * x + 4 * y, 16); } zfp-1.0.1/src/template/revencode4.c000066400000000000000000000016031453723256400171270ustar00rootroot00000000000000/* private functions ------------------------------------------------------- */ /* reversible forward decorrelating 4D transform */ static void _t2(rev_fwd_xform, Int, 4)(Int* p) { uint x, y, z, w; /* transform along x */ for (w = 0; w < 4; w++) for (z = 0; z < 4; z++) for (y = 0; y < 4; y++) _t1(rev_fwd_lift, Int)(p + 4 * y + 16 * z + 64 * w, 1); /* transform along y */ for (x = 0; x < 4; x++) for (w = 0; w < 4; w++) for (z = 0; z < 4; z++) _t1(rev_fwd_lift, Int)(p + 16 * z + 64 * w + 1 * x, 4); /* transform along z */ for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) for (w = 0; w < 4; w++) _t1(rev_fwd_lift, Int)(p + 64 * w + 1 * x + 4 * y, 16); /* transform along w */ for (z = 0; z < 4; z++) for (y = 0; y < 4; y++) for (x = 0; x < 4; x++) _t1(rev_fwd_lift, Int)(p + 1 * x + 4 * y + 16 * z, 64); } zfp-1.0.1/src/template/revencodef.c000066400000000000000000000051641453723256400172170ustar00rootroot00000000000000#include /* private functions ------------------------------------------------------- */ /* test if block-floating-point encoding is reversible */ static int _t1(rev_fwd_reversible, Scalar)(const Int* iblock, const Scalar* fblock, uint n, int emax) { /* reconstruct block */ cache_align_(Scalar gblock[BLOCK_SIZE]); _t1(rev_inv_cast, Scalar)(iblock, gblock, n, emax); /* perform bit-wise comparison */ return !memcmp(fblock, gblock, n * sizeof(*fblock)); } /* forward block-floating-point transform to signed integers */ static void _t1(rev_fwd_cast, Scalar)(Int* iblock, const Scalar* fblock, uint n, int emax) { /* test for all-zero block, which needs special treatment */ if (emax != -EBIAS) _t1(fwd_cast, Scalar)(iblock, fblock, BLOCK_SIZE, emax); else while (n--) *iblock++ = 0; } /* reinterpret floating values as two's complement integers */ static void _t1(rev_fwd_reinterpret, Scalar)(Int* iblock, const Scalar* fblock, uint n) { /* reinterpret floating values as sign-magnitude integers */ memcpy(iblock, fblock, n * sizeof(*iblock)); /* convert sign-magnitude integers to two's complement integers */ while (n--) { Int x = *iblock; if (x < 0) *iblock = (Int)((UInt)x ^ TCMASK); iblock++; } } /* encode contiguous floating-point block using reversible algorithm */ static uint _t2(rev_encode_block, Scalar, DIMS)(zfp_stream* zfp, const Scalar* fblock) { uint bits = 0; cache_align_(Int iblock[BLOCK_SIZE]); /* compute maximum exponent */ int emax = _t1(exponent_block, Scalar)(fblock, BLOCK_SIZE); /* perform forward block-floating-point transform */ _t1(rev_fwd_cast, Scalar)(iblock, fblock, BLOCK_SIZE, emax); /* test if block-floating-point transform is reversible */ if (_t1(rev_fwd_reversible, Scalar)(iblock, fblock, BLOCK_SIZE, emax)) { /* transform is reversible; test if block has any non-zeros */ uint e = (uint)(emax + EBIAS); if (e) { /* encode common exponent */ bits += 2; stream_write_bits(zfp->stream, 1, 2); bits += EBITS; stream_write_bits(zfp->stream, e, EBITS); } else { /* emit single bit for all-zero block */ bits++; stream_write_bit(zfp->stream, 0); return bits; } } else { /* transform is irreversible; reinterpret floating values as integers */ _t1(rev_fwd_reinterpret, Scalar)(iblock, fblock, BLOCK_SIZE); bits += 2; stream_write_bits(zfp->stream, 3, 2); } /* losslessly encode integers */ bits += _t2(rev_encode_block, Int, DIMS)(zfp->stream, zfp->minbits - MIN(bits, zfp->minbits), zfp->maxbits - bits, zfp->maxprec, iblock); return bits; } zfp-1.0.1/src/template/template.h000066400000000000000000000004641453723256400167150ustar00rootroot00000000000000#ifndef TEMPLATE_H #define TEMPLATE_H /* concatenation */ #define _cat2(x, y) x ## _ ## y #define _cat3(x, y, z) x ## _ ## y ## _ ## z /* 1- and 2-argument function templates */ #define _t1(function, arg) _cat2(function, arg) #define _t2(function, type, dims) _cat3(function, type, dims) #endif zfp-1.0.1/src/traitsd.h000066400000000000000000000013611453723256400147360ustar00rootroot00000000000000/* double-precision floating-point traits */ #define Scalar double /* floating-point type */ #define Int int64 /* corresponding signed integer type */ #define UInt uint64 /* corresponding unsigned integer type */ #define EBITS 11 /* number of exponent bits */ #define PBITS 6 /* number of bits needed to encode precision */ #define NBMASK UINT64C(0xaaaaaaaaaaaaaaaa) /* negabinary mask */ #define TCMASK UINT64C(0x7fffffffffffffff) /* two's complement mask */ #define SCALAR_MIN DBL_MIN /* smallest positive normal number */ #define FABS(x) fabs(x) #define FREXP(x, e) frexp(x, e) #define LDEXP(x, e) ldexp(x, e) zfp-1.0.1/src/traitsf.h000066400000000000000000000014411453723256400147370ustar00rootroot00000000000000/* single-precision floating-point traits */ #define Scalar float /* floating-point type */ #define Int int32 /* corresponding signed integer type */ #define UInt uint32 /* corresponding unsigned integer type */ #define EBITS 8 /* number of exponent bits */ #define PBITS 5 /* number of bits needed to encode precision */ #define NBMASK 0xaaaaaaaau /* negabinary mask */ #define TCMASK 0x7fffffffu /* two's complement mask */ #define SCALAR_MIN FLT_MIN /* smallest positive normal number */ #if __STDC_VERSION__ >= 199901L #define FABS(x) fabsf(x) #define FREXP(x, e) frexpf(x, e) #define LDEXP(x, e) ldexpf(x, e) #else #define FABS(x) (float)fabs(x) #define FREXP(x, e) (void)frexp(x, e) #define LDEXP(x, e) (float)ldexp(x, e) #endif zfp-1.0.1/src/traitsi.h000066400000000000000000000005171453723256400147450ustar00rootroot00000000000000/* 32-bit integer traits */ #define Scalar int32 /* integer type */ #define Int int32 /* corresponding signed integer type */ #define UInt uint32 /* corresponding unsigned integer type */ #define PBITS 5 /* number of bits needed to encode precision */ #define NBMASK 0xaaaaaaaau /* negabinary mask */ zfp-1.0.1/src/traitsl.h000066400000000000000000000006371453723256400147530ustar00rootroot00000000000000/* 64-bit integer traits */ #define Scalar int64 /* integer type */ #define Int int64 /* corresponding signed integer type */ #define UInt uint64 /* corresponding unsigned integer type */ #define PBITS 6 /* number of bits needed to encode precision */ #define NBMASK UINT64C(0xaaaaaaaaaaaaaaaa) /* negabinary mask */ zfp-1.0.1/src/zfp.c000066400000000000000000001024151453723256400140600ustar00rootroot00000000000000#include #include #include #include #include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "zfp/version.h" #include "template/template.h" /* public data ------------------------------------------------------------- */ const uint zfp_codec_version = ZFP_CODEC; const uint zfp_library_version = ZFP_VERSION; const char* const zfp_version_string = "zfp version " ZFP_VERSION_STRING " (December 15, 2023)"; /* private functions ------------------------------------------------------- */ static size_t field_index_span(const zfp_field* field, ptrdiff_t* min, ptrdiff_t* max) { /* compute strides */ ptrdiff_t sx = field->sx ? field->sx : 1; ptrdiff_t sy = field->sy ? field->sy : (ptrdiff_t)field->nx; ptrdiff_t sz = field->sz ? field->sz : (ptrdiff_t)(field->nx * field->ny); ptrdiff_t sw = field->sw ? field->sw : (ptrdiff_t)(field->nx * field->ny * field->nz); /* compute largest offsets from base pointer */ ptrdiff_t dx = field->nx ? sx * (ptrdiff_t)(field->nx - 1) : 0; ptrdiff_t dy = field->ny ? sy * (ptrdiff_t)(field->ny - 1) : 0; ptrdiff_t dz = field->nz ? sz * (ptrdiff_t)(field->nz - 1) : 0; ptrdiff_t dw = field->nw ? sw * (ptrdiff_t)(field->nw - 1) : 0; /* compute lowest and highest offset */ ptrdiff_t imin = MIN(dx, 0) + MIN(dy, 0) + MIN(dz, 0) + MIN(dw, 0); ptrdiff_t imax = MAX(dx, 0) + MAX(dy, 0) + MAX(dz, 0) + MAX(dw, 0); if (min) *min = imin; if (max) *max = imax; return (size_t)(imax - imin + 1); } static zfp_bool is_reversible(const zfp_stream* zfp) { return zfp->minexp < ZFP_MIN_EXP; } /* shared code across template instances ------------------------------------*/ #include "share/parallel.c" #include "share/omp.c" /* template instantiation of integer and float compressor -------------------*/ #define Scalar int32 #include "template/compress.c" #include "template/decompress.c" #include "template/ompcompress.c" #include "template/cudacompress.c" #include "template/cudadecompress.c" #undef Scalar #define Scalar int64 #include "template/compress.c" #include "template/decompress.c" #include "template/ompcompress.c" #include "template/cudacompress.c" #include "template/cudadecompress.c" #undef Scalar #define Scalar float #include "template/compress.c" #include "template/decompress.c" #include "template/ompcompress.c" #include "template/cudacompress.c" #include "template/cudadecompress.c" #undef Scalar #define Scalar double #include "template/compress.c" #include "template/decompress.c" #include "template/ompcompress.c" #include "template/cudacompress.c" #include "template/cudadecompress.c" #undef Scalar /* public functions: miscellaneous ----------------------------------------- */ size_t zfp_type_size(zfp_type type) { switch (type) { case zfp_type_int32: return sizeof(int32); case zfp_type_int64: return sizeof(int64); case zfp_type_float: return sizeof(float); case zfp_type_double: return sizeof(double); default: return 0; } } /* public functions: fields ------------------------------------------------ */ zfp_field* zfp_field_alloc(void) { zfp_field* field = (zfp_field*)malloc(sizeof(zfp_field)); if (field) { field->type = zfp_type_none; field->nx = field->ny = field->nz = field->nw = 0; field->sx = field->sy = field->sz = field->sw = 0; field->data = 0; } return field; } zfp_field* zfp_field_1d(void* data, zfp_type type, size_t nx) { zfp_field* field = zfp_field_alloc(); if (field) { field->type = type; field->nx = nx; field->data = data; } return field; } zfp_field* zfp_field_2d(void* data, zfp_type type, size_t nx, size_t ny) { zfp_field* field = zfp_field_alloc(); if (field) { field->type = type; field->nx = nx; field->ny = ny; field->data = data; } return field; } zfp_field* zfp_field_3d(void* data, zfp_type type, size_t nx, size_t ny, size_t nz) { zfp_field* field = zfp_field_alloc(); if (field) { field->type = type; field->nx = nx; field->ny = ny; field->nz = nz; field->data = data; } return field; } zfp_field* zfp_field_4d(void* data, zfp_type type, size_t nx, size_t ny, size_t nz, size_t nw) { zfp_field* field = zfp_field_alloc(); if (field) { field->type = type; field->nx = nx; field->ny = ny; field->nz = nz; field->nw = nw; field->data = data; } return field; } void zfp_field_free(zfp_field* field) { free(field); } void* zfp_field_pointer(const zfp_field* field) { return field->data; } void* zfp_field_begin(const zfp_field* field) { if (field->data) { ptrdiff_t min; field_index_span(field, &min, NULL); return (void*)((uchar*)field->data + min * (ptrdiff_t)zfp_type_size(field->type)); } else return NULL; } zfp_type zfp_field_type(const zfp_field* field) { return field->type; } uint zfp_field_precision(const zfp_field* field) { return (uint)(CHAR_BIT * zfp_type_size(field->type)); } uint zfp_field_dimensionality(const zfp_field* field) { return field->nx ? field->ny ? field->nz ? field->nw ? 4 : 3 : 2 : 1 : 0; } size_t zfp_field_size(const zfp_field* field, size_t* size) { if (size) switch (zfp_field_dimensionality(field)) { case 4: size[3] = field->nw; /* FALLTHROUGH */ case 3: size[2] = field->nz; /* FALLTHROUGH */ case 2: size[1] = field->ny; /* FALLTHROUGH */ case 1: size[0] = field->nx; break; } return MAX(field->nx, 1u) * MAX(field->ny, 1u) * MAX(field->nz, 1u) * MAX(field->nw, 1u); } size_t zfp_field_size_bytes(const zfp_field* field) { return field_index_span(field, NULL, NULL) * zfp_type_size(field->type); } size_t zfp_field_blocks(const zfp_field* field) { size_t bx = (field->nx + 3) / 4; size_t by = (field->ny + 3) / 4; size_t bz = (field->nz + 3) / 4; size_t bw = (field->nw + 3) / 4; switch (zfp_field_dimensionality(field)) { case 1: return bx; case 2: return bx * by; case 3: return bx * by * bz; case 4: return bx * by * bz * bw; default: return 0; } } zfp_bool zfp_field_stride(const zfp_field* field, ptrdiff_t* stride) { if (stride) switch (zfp_field_dimensionality(field)) { case 4: stride[3] = field->sw ? field->sw : (ptrdiff_t)(field->nx * field->ny * field->nz); /* FALLTHROUGH */ case 3: stride[2] = field->sz ? field->sz : (ptrdiff_t)(field->nx * field->ny); /* FALLTHROUGH */ case 2: stride[1] = field->sy ? field->sy : (ptrdiff_t)field->nx; /* FALLTHROUGH */ case 1: stride[0] = field->sx ? field->sx : 1; break; } return field->sx || field->sy || field->sz || field->sw; } zfp_bool zfp_field_is_contiguous(const zfp_field* field) { return field_index_span(field, NULL, NULL) == zfp_field_size(field, NULL); } uint64 zfp_field_metadata(const zfp_field* field) { uint64 meta = 0; /* 48 bits for dimensions */ switch (zfp_field_dimensionality(field)) { case 1: if ((uint64)(field->nx - 1) >> 48) return ZFP_META_NULL; meta <<= 48; meta += field->nx - 1; break; case 2: if (((field->nx - 1) >> 24) || ((field->ny - 1) >> 24)) return ZFP_META_NULL; meta <<= 24; meta += field->ny - 1; meta <<= 24; meta += field->nx - 1; break; case 3: if (((field->nx - 1) >> 16) || ((field->ny - 1) >> 16) || ((field->nz - 1) >> 16)) return ZFP_META_NULL; meta <<= 16; meta += field->nz - 1; meta <<= 16; meta += field->ny - 1; meta <<= 16; meta += field->nx - 1; break; case 4: if (((field->nx - 1) >> 12) || ((field->ny - 1) >> 12) || ((field->nz - 1) >> 12) || ((field->nw - 1) >> 12)) return ZFP_META_NULL; meta <<= 12; meta += field->nw - 1; meta <<= 12; meta += field->nz - 1; meta <<= 12; meta += field->ny - 1; meta <<= 12; meta += field->nx - 1; break; } /* 2 bits for dimensionality (1D, 2D, 3D, 4D) */ meta <<= 2; meta += zfp_field_dimensionality(field) - 1; /* 2 bits for scalar type */ meta <<= 2; meta += field->type - 1; return meta; } void zfp_field_set_pointer(zfp_field* field, void* data) { field->data = data; } zfp_type zfp_field_set_type(zfp_field* field, zfp_type type) { switch (type) { case zfp_type_int32: case zfp_type_int64: case zfp_type_float: case zfp_type_double: field->type = type; return type; default: return zfp_type_none; } } void zfp_field_set_size_1d(zfp_field* field, size_t n) { field->nx = n; field->ny = 0; field->nz = 0; field->nw = 0; } void zfp_field_set_size_2d(zfp_field* field, size_t nx, size_t ny) { field->nx = nx; field->ny = ny; field->nz = 0; field->nw = 0; } void zfp_field_set_size_3d(zfp_field* field, size_t nx, size_t ny, size_t nz) { field->nx = nx; field->ny = ny; field->nz = nz; field->nw = 0; } void zfp_field_set_size_4d(zfp_field* field, size_t nx, size_t ny, size_t nz, size_t nw) { field->nx = nx; field->ny = ny; field->nz = nz; field->nw = nw; } void zfp_field_set_stride_1d(zfp_field* field, ptrdiff_t sx) { field->sx = sx; field->sy = 0; field->sz = 0; field->sw = 0; } void zfp_field_set_stride_2d(zfp_field* field, ptrdiff_t sx, ptrdiff_t sy) { field->sx = sx; field->sy = sy; field->sz = 0; field->sw = 0; } void zfp_field_set_stride_3d(zfp_field* field, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz) { field->sx = sx; field->sy = sy; field->sz = sz; field->sw = 0; } void zfp_field_set_stride_4d(zfp_field* field, ptrdiff_t sx, ptrdiff_t sy, ptrdiff_t sz, ptrdiff_t sw) { field->sx = sx; field->sy = sy; field->sz = sz; field->sw = sw; } zfp_bool zfp_field_set_metadata(zfp_field* field, uint64 meta) { uint64 dims; /* ensure value is in range */ if (meta >> ZFP_META_BITS) return zfp_false; field->type = (zfp_type)((meta & 0x3u) + 1); meta >>= 2; dims = (meta & 0x3u) + 1; meta >>= 2; switch (dims) { case 1: /* currently dimensions are limited to 2^32 - 1 */ field->nx = (size_t)(meta & UINT64C(0x0000ffffffff)) + 1; meta >>= 48; field->ny = 0; field->nz = 0; field->nw = 0; break; case 2: field->nx = (size_t)(meta & UINT64C(0xffffff)) + 1; meta >>= 24; field->ny = (size_t)(meta & UINT64C(0xffffff)) + 1; meta >>= 24; field->nz = 0; field->nw = 0; break; case 3: field->nx = (size_t)(meta & UINT64C(0xffff)) + 1; meta >>= 16; field->ny = (size_t)(meta & UINT64C(0xffff)) + 1; meta >>= 16; field->nz = (size_t)(meta & UINT64C(0xffff)) + 1; meta >>= 16; field->nw = 0; break; case 4: field->nx = (size_t)(meta & UINT64C(0xfff)) + 1; meta >>= 12; field->ny = (size_t)(meta & UINT64C(0xfff)) + 1; meta >>= 12; field->nz = (size_t)(meta & UINT64C(0xfff)) + 1; meta >>= 12; field->nw = (size_t)(meta & UINT64C(0xfff)) + 1; meta >>= 12; break; } field->sx = field->sy = field->sz = field->sw = 0; return zfp_true; } /* public functions: compression mode and parameter settings --------------- */ zfp_config zfp_config_none(void) { zfp_config config; config.mode = zfp_mode_null; return config; } zfp_config zfp_config_rate( double rate, zfp_bool align ) { zfp_config config; config.mode = zfp_mode_fixed_rate; config.arg.rate = align ? -rate : +rate; return config; } zfp_config zfp_config_precision( uint precision ) { zfp_config config; config.mode = zfp_mode_fixed_precision; config.arg.precision = precision; return config; } zfp_config zfp_config_accuracy( double tolerance ) { zfp_config config; config.mode = zfp_mode_fixed_accuracy; config.arg.tolerance = tolerance; return config; } zfp_config zfp_config_reversible(void) { zfp_config config; config.mode = zfp_mode_reversible; return config; } zfp_config zfp_config_expert( uint minbits, uint maxbits, uint maxprec, int minexp ) { zfp_config config; config.mode = zfp_mode_expert; config.arg.expert.minbits = minbits; config.arg.expert.maxbits = maxbits; config.arg.expert.maxprec = maxprec; config.arg.expert.minexp = minexp; return config; } /* public functions: zfp compressed stream --------------------------------- */ zfp_stream* zfp_stream_open(bitstream* stream) { zfp_stream* zfp = (zfp_stream*)malloc(sizeof(zfp_stream)); if (zfp) { zfp->stream = stream; zfp->minbits = ZFP_MIN_BITS; zfp->maxbits = ZFP_MAX_BITS; zfp->maxprec = ZFP_MAX_PREC; zfp->minexp = ZFP_MIN_EXP; zfp->exec.policy = zfp_exec_serial; zfp->exec.params = NULL; } return zfp; } void zfp_stream_close(zfp_stream* zfp) { if (zfp->exec.params != NULL) free(zfp->exec.params); free(zfp); } bitstream* zfp_stream_bit_stream(const zfp_stream* zfp) { return zfp->stream; } zfp_mode zfp_stream_compression_mode(const zfp_stream* zfp) { if (zfp->minbits > zfp->maxbits || !(0 < zfp->maxprec && zfp->maxprec <= 64)) return zfp_mode_null; /* default values are considered expert mode */ if (zfp->minbits == ZFP_MIN_BITS && zfp->maxbits == ZFP_MAX_BITS && zfp->maxprec == ZFP_MAX_PREC && zfp->minexp == ZFP_MIN_EXP) return zfp_mode_expert; /* fixed rate? */ if (zfp->minbits == zfp->maxbits && 1 <= zfp->maxbits && zfp->maxbits <= ZFP_MAX_BITS && zfp->maxprec >= ZFP_MAX_PREC && zfp->minexp == ZFP_MIN_EXP) return zfp_mode_fixed_rate; /* fixed precision? */ if (zfp->minbits <= ZFP_MIN_BITS && zfp->maxbits >= ZFP_MAX_BITS && zfp->maxprec >= 1 && zfp->minexp == ZFP_MIN_EXP) return zfp_mode_fixed_precision; /* fixed accuracy? */ if (zfp->minbits <= ZFP_MIN_BITS && zfp->maxbits >= ZFP_MAX_BITS && zfp->maxprec >= ZFP_MAX_PREC && zfp->minexp >= ZFP_MIN_EXP) return zfp_mode_fixed_accuracy; /* reversible? */ if (zfp->minbits <= ZFP_MIN_BITS && zfp->maxbits >= ZFP_MAX_BITS && zfp->maxprec >= ZFP_MAX_PREC && zfp->minexp < ZFP_MIN_EXP) return zfp_mode_reversible; return zfp_mode_expert; } double zfp_stream_rate(const zfp_stream* zfp, uint dims) { return (zfp_stream_compression_mode(zfp) == zfp_mode_fixed_rate) ? (double)zfp->maxbits / (1u << (2 * dims)) : 0.0; } uint zfp_stream_precision(const zfp_stream* zfp) { return (zfp_stream_compression_mode(zfp) == zfp_mode_fixed_precision) ? zfp->maxprec : 0; } double zfp_stream_accuracy(const zfp_stream* zfp) { return (zfp_stream_compression_mode(zfp) == zfp_mode_fixed_accuracy) ? ldexp(1.0, zfp->minexp) : 0.0; } uint64 zfp_stream_mode(const zfp_stream* zfp) { uint64 mode = 0; uint minbits; uint maxbits; uint maxprec; uint minexp; /* common configurations mapped to short representation */ switch (zfp_stream_compression_mode(zfp)) { case zfp_mode_fixed_rate: if (zfp->maxbits <= 2048) /* maxbits is [1, 2048] */ /* returns [0, 2047] */ return (zfp->maxbits - 1); else break; case zfp_mode_fixed_precision: if (zfp->maxprec <= 128) /* maxprec is [1, 128] */ /* returns [2048, 2175] */ return (zfp->maxprec - 1) + (2048); else break; case zfp_mode_fixed_accuracy: if (zfp->minexp <= 843) /* minexp is [ZFP_MIN_EXP=-1074, 843] */ /* returns [2177, ZFP_MODE_SHORT_MAX=4094] */ /* +1 because skipped 2176 */ return (uint64)(zfp->minexp - ZFP_MIN_EXP) + (2048 + 128 + 1); else break; case zfp_mode_reversible: /* returns 2176 */ return 2048 + 128; default: break; } /* encode each parameter separately */ minbits = MAX(1, MIN(zfp->minbits, 0x8000u)) - 1; maxbits = MAX(1, MIN(zfp->maxbits, 0x8000u)) - 1; maxprec = MAX(1, MIN(zfp->maxprec, 0x0080u)) - 1; minexp = (uint)MAX(0, MIN(zfp->minexp + 16495, 0x7fff)); mode <<= 15; mode += minexp; mode <<= 7; mode += maxprec; mode <<= 15; mode += maxbits; mode <<= 15; mode += minbits; mode <<= 12; mode += 0xfffu; return mode; } void zfp_stream_params(const zfp_stream* zfp, uint* minbits, uint* maxbits, uint* maxprec, int* minexp) { if (minbits) *minbits = zfp->minbits; if (maxbits) *maxbits = zfp->maxbits; if (maxprec) *maxprec = zfp->maxprec; if (minexp) *minexp = zfp->minexp; } size_t zfp_stream_compressed_size(const zfp_stream* zfp) { return stream_size(zfp->stream); } size_t zfp_stream_maximum_size(const zfp_stream* zfp, const zfp_field* field) { zfp_bool reversible = is_reversible(zfp); uint dims = zfp_field_dimensionality(field); size_t blocks = zfp_field_blocks(field); uint values = 1u << (2 * dims); uint maxbits = 0; if (!dims) return 0; switch (field->type) { case zfp_type_int32: maxbits += reversible ? 5 : 0; break; case zfp_type_int64: maxbits += reversible ? 6 : 0; break; case zfp_type_float: maxbits += reversible ? 1 + 1 + 8 + 5 : 1 + 8; break; case zfp_type_double: maxbits += reversible ? 1 + 1 + 11 + 6 : 1 + 11; break; default: return 0; } maxbits += values - 1 + values * MIN(zfp->maxprec, zfp_field_precision(field)); maxbits = MIN(maxbits, zfp->maxbits); maxbits = MAX(maxbits, zfp->minbits); return ((ZFP_HEADER_MAX_BITS + blocks * maxbits + stream_word_bits - 1) & ~(stream_word_bits - 1)) / CHAR_BIT; } void zfp_stream_set_bit_stream(zfp_stream* zfp, bitstream* stream) { zfp->stream = stream; } void zfp_stream_set_reversible(zfp_stream* zfp) { zfp->minbits = ZFP_MIN_BITS; zfp->maxbits = ZFP_MAX_BITS; zfp->maxprec = ZFP_MAX_PREC; zfp->minexp = ZFP_MIN_EXP - 1; } double zfp_stream_set_rate(zfp_stream* zfp, double rate, zfp_type type, uint dims, zfp_bool align) { uint n = 1u << (2 * dims); uint bits = (uint)floor(n * rate + 0.5); switch (type) { case zfp_type_float: bits = MAX(bits, 1 + 8u); break; case zfp_type_double: bits = MAX(bits, 1 + 11u); break; default: break; } if (align) { /* for write random access, round up to next multiple of stream word size */ bits += (uint)stream_word_bits - 1; bits &= ~(stream_word_bits - 1); } zfp->minbits = bits; zfp->maxbits = bits; zfp->maxprec = ZFP_MAX_PREC; zfp->minexp = ZFP_MIN_EXP; return (double)bits / n; } uint zfp_stream_set_precision(zfp_stream* zfp, uint precision) { zfp->minbits = ZFP_MIN_BITS; zfp->maxbits = ZFP_MAX_BITS; zfp->maxprec = precision ? MIN(precision, ZFP_MAX_PREC) : ZFP_MAX_PREC; zfp->minexp = ZFP_MIN_EXP; return zfp->maxprec; } double zfp_stream_set_accuracy(zfp_stream* zfp, double tolerance) { int emin = ZFP_MIN_EXP; if (tolerance > 0) { /* tolerance = x * 2^emin, with 0.5 <= x < 1 */ frexp(tolerance, &emin); emin--; /* assert: 2^emin <= tolerance < 2^(emin+1) */ } zfp->minbits = ZFP_MIN_BITS; zfp->maxbits = ZFP_MAX_BITS; zfp->maxprec = ZFP_MAX_PREC; zfp->minexp = emin; return tolerance > 0 ? ldexp(1.0, emin) : 0; } zfp_mode zfp_stream_set_mode(zfp_stream* zfp, uint64 mode) { uint minbits, maxbits, maxprec; int minexp; if (mode <= ZFP_MODE_SHORT_MAX) { /* 12-bit (short) encoding of one of four modes */ if (mode < 2048) { /* fixed rate */ minbits = maxbits = (uint)mode + 1; maxprec = ZFP_MAX_PREC; minexp = ZFP_MIN_EXP; } else if (mode < (2048 + 128)) { /* fixed precision */ minbits = ZFP_MIN_BITS; maxbits = ZFP_MAX_BITS; maxprec = (uint)mode + 1 - (2048); minexp = ZFP_MIN_EXP; } else if (mode == (2048 + 128)) { /* reversible */ minbits = ZFP_MIN_BITS; maxbits = ZFP_MAX_BITS; maxprec = ZFP_MAX_PREC; minexp = ZFP_MIN_EXP - 1; } else { /* fixed accuracy */ minbits = ZFP_MIN_BITS; maxbits = ZFP_MAX_BITS; maxprec = ZFP_MAX_PREC; minexp = (int)mode + ZFP_MIN_EXP - (2048 + 128 + 1); } } else { /* 64-bit encoding */ mode >>= 12; minbits = (uint)(mode & 0x7fffu) + 1; mode >>= 15; maxbits = (uint)(mode & 0x7fffu) + 1; mode >>= 15; maxprec = (uint)(mode & 0x007fu) + 1; mode >>= 7; minexp = (int)(mode & 0x7fffu) - 16495; } if (!zfp_stream_set_params(zfp, minbits, maxbits, maxprec, minexp)) return zfp_mode_null; return zfp_stream_compression_mode(zfp); } zfp_bool zfp_stream_set_params(zfp_stream* zfp, uint minbits, uint maxbits, uint maxprec, int minexp) { if (minbits > maxbits || !(0 < maxprec && maxprec <= 64)) return zfp_false; zfp->minbits = minbits; zfp->maxbits = maxbits; zfp->maxprec = maxprec; zfp->minexp = minexp; return zfp_true; } size_t zfp_stream_flush(zfp_stream* zfp) { return stream_flush(zfp->stream); } size_t zfp_stream_align(zfp_stream* zfp) { return stream_align(zfp->stream); } void zfp_stream_rewind(zfp_stream* zfp) { stream_rewind(zfp->stream); } /* public functions: execution policy -------------------------------------- */ zfp_exec_policy zfp_stream_execution(const zfp_stream* zfp) { return zfp->exec.policy; } uint zfp_stream_omp_threads(const zfp_stream* zfp) { if (zfp->exec.policy == zfp_exec_omp) return ((zfp_exec_params_omp*)zfp->exec.params)->threads; return 0u; } uint zfp_stream_omp_chunk_size(const zfp_stream* zfp) { if (zfp->exec.policy == zfp_exec_omp) return ((zfp_exec_params_omp*)zfp->exec.params)->chunk_size; return 0u; } zfp_bool zfp_stream_set_execution(zfp_stream* zfp, zfp_exec_policy policy) { switch (policy) { case zfp_exec_serial: if (zfp->exec.policy != policy && zfp->exec.params != NULL) { free(zfp->exec.params); zfp->exec.params = NULL; } break; #ifdef ZFP_WITH_CUDA case zfp_exec_cuda: if (zfp->exec.policy != policy && zfp->exec.params != NULL) { free(zfp->exec.params); zfp->exec.params = NULL; } break; #endif case zfp_exec_omp: #ifdef _OPENMP if (zfp->exec.policy != policy) { if (zfp->exec.params != NULL) { free(zfp->exec.params); } zfp_exec_params_omp* params = malloc(sizeof(zfp_exec_params_omp)); params->threads = 0; params->chunk_size = 0; zfp->exec.params = (void*)params; } break; #else return zfp_false; #endif default: return zfp_false; } zfp->exec.policy = policy; return zfp_true; } zfp_bool zfp_stream_set_omp_threads(zfp_stream* zfp, uint threads) { if (!zfp_stream_set_execution(zfp, zfp_exec_omp)) return zfp_false; ((zfp_exec_params_omp*)zfp->exec.params)->threads = threads; return zfp_true; } zfp_bool zfp_stream_set_omp_chunk_size(zfp_stream* zfp, uint chunk_size) { if (!zfp_stream_set_execution(zfp, zfp_exec_omp)) return zfp_false; ((zfp_exec_params_omp*)zfp->exec.params)->chunk_size = chunk_size; return zfp_true; } /* public functions: utility functions --------------------------------------*/ void zfp_promote_int8_to_int32(int32* oblock, const int8* iblock, uint dims) { uint count = 1u << (2 * dims); while (count--) *oblock++ = (int32)*iblock++ << 23; } void zfp_promote_uint8_to_int32(int32* oblock, const uint8* iblock, uint dims) { uint count = 1u << (2 * dims); while (count--) *oblock++ = ((int32)*iblock++ - 0x80) << 23; } void zfp_promote_int16_to_int32(int32* oblock, const int16* iblock, uint dims) { uint count = 1u << (2 * dims); while (count--) *oblock++ = (int32)*iblock++ << 15; } void zfp_promote_uint16_to_int32(int32* oblock, const uint16* iblock, uint dims) { uint count = 1u << (2 * dims); while (count--) *oblock++ = ((int32)*iblock++ - 0x8000) << 15; } void zfp_demote_int32_to_int8(int8* oblock, const int32* iblock, uint dims) { uint count = 1u << (2 * dims); while (count--) { int32 i = *iblock++ >> 23; *oblock++ = (int8)MAX(-0x80, MIN(i, 0x7f)); } } void zfp_demote_int32_to_uint8(uint8* oblock, const int32* iblock, uint dims) { uint count = 1u << (2 * dims); while (count--) { int32 i = (*iblock++ >> 23) + 0x80; *oblock++ = (uint8)MAX(0x00, MIN(i, 0xff)); } } void zfp_demote_int32_to_int16(int16* oblock, const int32* iblock, uint dims) { uint count = 1u << (2 * dims); while (count--) { int32 i = *iblock++ >> 15; *oblock++ = (int16)MAX(-0x8000, MIN(i, 0x7fff)); } } void zfp_demote_int32_to_uint16(uint16* oblock, const int32* iblock, uint dims) { uint count = 1u << (2 * dims); while (count--) { int32 i = (*iblock++ >> 15) + 0x8000; *oblock++ = (uint16)MAX(0x0000, MIN(i, 0xffff)); } } /* public functions: compression and decompression --------------------------*/ size_t zfp_compress(zfp_stream* zfp, const zfp_field* field) { /* function table [execution][strided][dimensionality][scalar type] */ void (*ftable[3][2][4][4])(zfp_stream*, const zfp_field*) = { /* serial */ {{{ compress_int32_1, compress_int64_1, compress_float_1, compress_double_1 }, { compress_strided_int32_2, compress_strided_int64_2, compress_strided_float_2, compress_strided_double_2 }, { compress_strided_int32_3, compress_strided_int64_3, compress_strided_float_3, compress_strided_double_3 }, { compress_strided_int32_4, compress_strided_int64_4, compress_strided_float_4, compress_strided_double_4 }}, {{ compress_strided_int32_1, compress_strided_int64_1, compress_strided_float_1, compress_strided_double_1 }, { compress_strided_int32_2, compress_strided_int64_2, compress_strided_float_2, compress_strided_double_2 }, { compress_strided_int32_3, compress_strided_int64_3, compress_strided_float_3, compress_strided_double_3 }, { compress_strided_int32_4, compress_strided_int64_4, compress_strided_float_4, compress_strided_double_4 }}}, /* OpenMP */ #ifdef _OPENMP {{{ compress_omp_int32_1, compress_omp_int64_1, compress_omp_float_1, compress_omp_double_1 }, { compress_strided_omp_int32_2, compress_strided_omp_int64_2, compress_strided_omp_float_2, compress_strided_omp_double_2 }, { compress_strided_omp_int32_3, compress_strided_omp_int64_3, compress_strided_omp_float_3, compress_strided_omp_double_3 }, { compress_strided_omp_int32_4, compress_strided_omp_int64_4, compress_strided_omp_float_4, compress_strided_omp_double_4 }}, {{ compress_strided_omp_int32_1, compress_strided_omp_int64_1, compress_strided_omp_float_1, compress_strided_omp_double_1 }, { compress_strided_omp_int32_2, compress_strided_omp_int64_2, compress_strided_omp_float_2, compress_strided_omp_double_2 }, { compress_strided_omp_int32_3, compress_strided_omp_int64_3, compress_strided_omp_float_3, compress_strided_omp_double_3 }, { compress_strided_omp_int32_4, compress_strided_omp_int64_4, compress_strided_omp_float_4, compress_strided_omp_double_4 }}}, #else {{{ NULL }}}, #endif /* CUDA */ #ifdef ZFP_WITH_CUDA {{{ compress_cuda_int32_1, compress_cuda_int64_1, compress_cuda_float_1, compress_cuda_double_1 }, { compress_strided_cuda_int32_2, compress_strided_cuda_int64_2, compress_strided_cuda_float_2, compress_strided_cuda_double_2 }, { compress_strided_cuda_int32_3, compress_strided_cuda_int64_3, compress_strided_cuda_float_3, compress_strided_cuda_double_3 }, { NULL, NULL, NULL, NULL }}, {{ compress_strided_cuda_int32_1, compress_strided_cuda_int64_1, compress_strided_cuda_float_1, compress_strided_cuda_double_1 }, { compress_strided_cuda_int32_2, compress_strided_cuda_int64_2, compress_strided_cuda_float_2, compress_strided_cuda_double_2 }, { compress_strided_cuda_int32_3, compress_strided_cuda_int64_3, compress_strided_cuda_float_3, compress_strided_cuda_double_3 }, { NULL, NULL, NULL, NULL }}}, #else {{{ NULL }}}, #endif }; uint exec = zfp->exec.policy; uint strided = (uint)zfp_field_stride(field, NULL); uint dims = zfp_field_dimensionality(field); uint type = field->type; void (*compress)(zfp_stream*, const zfp_field*); switch (type) { case zfp_type_int32: case zfp_type_int64: case zfp_type_float: case zfp_type_double: break; default: return 0; } /* return 0 if compression mode is not supported */ compress = ftable[exec][strided][dims - 1][type - zfp_type_int32]; if (!compress) return 0; /* compress field and align bit stream on word boundary */ compress(zfp, field); stream_flush(zfp->stream); return stream_size(zfp->stream); } size_t zfp_decompress(zfp_stream* zfp, zfp_field* field) { /* function table [execution][strided][dimensionality][scalar type] */ void (*ftable[3][2][4][4])(zfp_stream*, zfp_field*) = { /* serial */ {{{ decompress_int32_1, decompress_int64_1, decompress_float_1, decompress_double_1 }, { decompress_strided_int32_2, decompress_strided_int64_2, decompress_strided_float_2, decompress_strided_double_2 }, { decompress_strided_int32_3, decompress_strided_int64_3, decompress_strided_float_3, decompress_strided_double_3 }, { decompress_strided_int32_4, decompress_strided_int64_4, decompress_strided_float_4, decompress_strided_double_4 }}, {{ decompress_strided_int32_1, decompress_strided_int64_1, decompress_strided_float_1, decompress_strided_double_1 }, { decompress_strided_int32_2, decompress_strided_int64_2, decompress_strided_float_2, decompress_strided_double_2 }, { decompress_strided_int32_3, decompress_strided_int64_3, decompress_strided_float_3, decompress_strided_double_3 }, { decompress_strided_int32_4, decompress_strided_int64_4, decompress_strided_float_4, decompress_strided_double_4 }}}, /* OpenMP; not yet supported */ {{{ NULL }}}, /* CUDA */ #ifdef ZFP_WITH_CUDA {{{ decompress_cuda_int32_1, decompress_cuda_int64_1, decompress_cuda_float_1, decompress_cuda_double_1 }, { decompress_strided_cuda_int32_2, decompress_strided_cuda_int64_2, decompress_strided_cuda_float_2, decompress_strided_cuda_double_2 }, { decompress_strided_cuda_int32_3, decompress_strided_cuda_int64_3, decompress_strided_cuda_float_3, decompress_strided_cuda_double_3 }, { NULL, NULL, NULL, NULL }}, {{ decompress_strided_cuda_int32_1, decompress_strided_cuda_int64_1, decompress_strided_cuda_float_1, decompress_strided_cuda_double_1 }, { decompress_strided_cuda_int32_2, decompress_strided_cuda_int64_2, decompress_strided_cuda_float_2, decompress_strided_cuda_double_2 }, { decompress_strided_cuda_int32_3, decompress_strided_cuda_int64_3, decompress_strided_cuda_float_3, decompress_strided_cuda_double_3 }, { NULL, NULL, NULL, NULL }}}, #else {{{ NULL }}}, #endif }; uint exec = zfp->exec.policy; uint strided = (uint)zfp_field_stride(field, NULL); uint dims = zfp_field_dimensionality(field); uint type = field->type; void (*decompress)(zfp_stream*, zfp_field*); switch (type) { case zfp_type_int32: case zfp_type_int64: case zfp_type_float: case zfp_type_double: break; default: return 0; } /* return 0 if decompression mode is not supported */ decompress = ftable[exec][strided][dims - 1][type - zfp_type_int32]; if (!decompress) return 0; /* decompress field and align bit stream on word boundary */ decompress(zfp, field); stream_align(zfp->stream); return stream_size(zfp->stream); } size_t zfp_write_header(zfp_stream* zfp, const zfp_field* field, uint mask) { size_t bits = 0; uint64 meta = 0; /* first make sure field dimensions fit in header */ if (mask & ZFP_HEADER_META) { meta = zfp_field_metadata(field); if (meta == ZFP_META_NULL) return 0; } /* 32-bit magic */ if (mask & ZFP_HEADER_MAGIC) { stream_write_bits(zfp->stream, 'z', 8); stream_write_bits(zfp->stream, 'f', 8); stream_write_bits(zfp->stream, 'p', 8); stream_write_bits(zfp->stream, zfp_codec_version, 8); bits += ZFP_MAGIC_BITS; } /* 52-bit field metadata */ if (mask & ZFP_HEADER_META) { stream_write_bits(zfp->stream, meta, ZFP_META_BITS); bits += ZFP_META_BITS; } /* 12- or 64-bit compression parameters */ if (mask & ZFP_HEADER_MODE) { uint64 mode = zfp_stream_mode(zfp); uint size = mode > ZFP_MODE_SHORT_MAX ? ZFP_MODE_LONG_BITS : ZFP_MODE_SHORT_BITS; stream_write_bits(zfp->stream, mode, size); bits += size; } return bits; } size_t zfp_read_header(zfp_stream* zfp, zfp_field* field, uint mask) { size_t bits = 0; if (mask & ZFP_HEADER_MAGIC) { if (stream_read_bits(zfp->stream, 8) != 'z' || stream_read_bits(zfp->stream, 8) != 'f' || stream_read_bits(zfp->stream, 8) != 'p' || stream_read_bits(zfp->stream, 8) != zfp_codec_version) return 0; bits += ZFP_MAGIC_BITS; } if (mask & ZFP_HEADER_META) { uint64 meta = stream_read_bits(zfp->stream, ZFP_META_BITS); if (!zfp_field_set_metadata(field, meta)) return 0; bits += ZFP_META_BITS; } if (mask & ZFP_HEADER_MODE) { uint64 mode = stream_read_bits(zfp->stream, ZFP_MODE_SHORT_BITS); bits += ZFP_MODE_SHORT_BITS; if (mode > ZFP_MODE_SHORT_MAX) { uint size = ZFP_MODE_LONG_BITS - ZFP_MODE_SHORT_BITS; mode += stream_read_bits(zfp->stream, size) << ZFP_MODE_SHORT_BITS; bits += size; } if (zfp_stream_set_mode(zfp, mode) == zfp_mode_null) return 0; } return bits; } zfp-1.0.1/tests/000077500000000000000000000000001453723256400134655ustar00rootroot00000000000000zfp-1.0.1/tests/CMakeLists.txt000066400000000000000000000117471453723256400162370ustar00rootroot00000000000000if(BUILD_TESTING OR BUILD_TESTING_FULL) # testzfp add_executable(testzfp testzfp.cpp) target_link_libraries(testzfp zfp) target_compile_definitions(testzfp PRIVATE ${zfp_compressed_array_defs}) add_test(NAME testzfp COMMAND testzfp) # testviews add_executable(testviews testviews.cpp) if(ZFP_WITH_OPENMP) target_link_libraries(testviews zfp OpenMP::OpenMP_C) else() target_link_libraries(testviews zfp) endif() target_compile_definitions(testviews PRIVATE ${zfp_compressed_array_defs}) add_test(NAME testviews COMMAND testviews) endif() if(BUILD_TESTING_FULL) set(CMAKE_CXX_STANDARD 11) # CMAKE_SH-NOTFOUND needed for mingw builds if(MINGW) list(APPEND CMOCKA_ARGS "-DCMAKE_SH=CMAKE_SH-NOTFOUND") list(APPEND GTEST_ARGS "-DCMAKE_SH=CMAKE_SH-NOTFOUND") endif() # clone cmocka 1.1.0 into /build list(APPEND CMOCKA_ARGS "-DWITH_STATIC_LIB=ON;-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER};-DUNIT_TESTING=OFF") include(ExternalProject) ExternalProject_Add( cmocka_cloned GIT_REPOSITORY https://gitlab.com/cmocka/cmocka.git GIT_TAG cmocka-1.1.5 SOURCE_DIR "${CMAKE_BINARY_DIR}/cmocka-src" BINARY_DIR "${CMAKE_BINARY_DIR}/cmocka-build" CMAKE_ARGS "${CMOCKA_ARGS}" INSTALL_COMMAND "" STEP_TARGETS build EXCLUDE_FROM_ALL TRUE ) ExternalProject_Get_Property(cmocka_cloned source_dir binary_dir) # name static library cmocka, wire up against cmocka_cloned add_library(cmocka STATIC IMPORTED GLOBAL) # choose proper library path & extension if(MSVC) set(IMPORTED_LOCATION_PATH "${binary_dir}/src/${CMAKE_BUILD_TYPE}/cmocka-static.lib") else() set(IMPORTED_LOCATION_PATH "${binary_dir}/src/libcmocka-static.a") endif() set_property(TARGET cmocka PROPERTY IMPORTED_LOCATION "${IMPORTED_LOCATION_PATH}" ) add_dependencies(cmocka cmocka_cloned) include_directories(${source_dir}/include) # include home dir so #include statements are clear in test files include_directories(${ZFP_SOURCE_DIR} ${ZFP_SOURCE_DIR}/include) # access to constants/ and utils/ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) # suppress warnings for all targets if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") add_compile_options(-Wno-unused-function) endif() # -Wno-variadic-macros was not working for gcc...revisit if(CMAKE_C_COMPILER_ID STREQUAL "Clang") add_compile_options(-Wno-gnu-zero-variadic-macro-arguments) endif() # suppress googletest warning "conversion from 'float' to 'testing::internal::BiggestInt', possible loss of data" if(MSVC) add_compile_options(/wd4244) endif() add_subdirectory(utils) add_subdirectory(src) if(BUILD_CFP) add_subdirectory(cfp) endif() if(BUILD_ZFORP) add_subdirectory(fortran) endif() # needed to compile gtest on MSVC if(MSVC) list(APPEND GTEST_ARGS "/D:_SILENCE_TR1_DEPRECATION_NAMESPACE_WARNING=1") endif() # TODO: spend time getting googletest to compile on MinGW # checksums are generated through C tests, no need to compile C++ tests if((NOT MINGW) AND (NOT DEFINED ZFP_OMP_TESTS_ONLY) AND (NOT PRINT_CHECKSUMS)) # clone googletest into build/ configure_file(CMakeLists.txt.in ${ZFP_BINARY_DIR}/tests/googletest-download/CMakeLists.txt) execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${GTEST_ARGS} . RESULT_VARIABLE result WORKING_DIRECTORY ${ZFP_BINARY_DIR}/tests/googletest-download ) if(result) message(FATAL_ERROR "CMake step for googletest failed: ${result}") endif() # build gtest execute_process(COMMAND ${CMAKE_COMMAND} --build . RESULT_VARIABLE result WORKING_DIRECTORY ${ZFP_BINARY_DIR}/tests/googletest-download ) if(result) message(FATAL_ERROR "Build step for googletest failed: ${result}") endif() set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) add_subdirectory(${ZFP_BINARY_DIR}/tests/googletest-src ${ZFP_BINARY_DIR}/tests/googletest-build ) if(CMAKE_VERSION VERSION_LESS 2.8.11) include_directories("${gtest_SOURCE_DIR}/include") endif() # needed to compile zfp tests with gtest on MSVC if(MSVC) target_compile_definitions(gtest_main INTERFACE GTEST_LINKED_AS_SHARED_LIBRARY=1) endif() add_subdirectory(array) endif() option(ZFP_BUILD_TESTING_SMALL "Enable small-sized array testing" ON) if(ZFP_BUILD_TESTING_SMALL) foreach(D IN ITEMS 1 2 3 4) foreach(P IN ITEMS 32 64) add_test(NAME small-arrays-${D}d-fp${P} COMMAND testzfp small ${D}d fp${P}) endforeach() endforeach() endif() option(ZFP_BUILD_TESTING_LARGE "Enable large-sized array testing" OFF) if(ZFP_BUILD_TESTING_LARGE) foreach(D IN ITEMS 1 2 3 4) foreach(P IN ITEMS 32 64) add_test(NAME large-arrays-${D}d-fp${P} COMMAND testzfp large ${D}d fp${P}) endforeach() endforeach() endif() if(BUILD_ZFPY) add_subdirectory(python) endif() endif() zfp-1.0.1/tests/CMakeLists.txt.in000066400000000000000000000010001453723256400166210ustar00rootroot00000000000000cmake_minimum_required(VERSION 2.8.7) project(googletest-download NONE) include(ExternalProject) ExternalProject_Add( googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG e2239ee6043f73722e7aa812a459f54a28552929 #703bd9caab50b139428cea1aaff9974ebee5742e SOURCE_DIR "${ZFP_BINARY_DIR}/tests/googletest-src" BINARY_DIR "${ZFP_BINARY_DIR}/tests/googletest-build" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" TEST_COMMAND "" ) zfp-1.0.1/tests/Makefile000066400000000000000000000006631453723256400151320ustar00rootroot00000000000000include ../Config BINDIR = ../bin TARGETS = $(BINDIR)/testzfp $(BINDIR)/testviews INCS = -I../include LIBS = -L../lib -lzfp $(LDFLAGS) all: $(TARGETS) $(BINDIR)/testzfp: testzfp.cpp ../lib/$(LIBZFP) $(CXX) $(CXXFLAGS) $(INCS) testzfp.cpp $(LIBS) -o $@ $(BINDIR)/testviews: testviews.cpp ../lib/$(LIBZFP) $(CXX) $(CXXFLAGS) $(INCS) testviews.cpp $(LIBS) -o $@ test: $(BINDIR)/testzfp $(BINDIR)/testzfp clean: rm -f $(TARGETS) zfp-1.0.1/tests/array/000077500000000000000000000000001453723256400146035ustar00rootroot00000000000000zfp-1.0.1/tests/array/CMakeLists.txt000066400000000000000000000002571453723256400173470ustar00rootroot00000000000000include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(array) add_subdirectory(constArray) add_subdirectory(decode) add_subdirectory(encode) add_subdirectory(zfp) zfp-1.0.1/tests/array/array/000077500000000000000000000000001453723256400157215ustar00rootroot00000000000000zfp-1.0.1/tests/array/array/CMakeLists.txt000066400000000000000000000054711453723256400204700ustar00rootroot00000000000000function(zfp_add_cpp_tests dims type bits) # test compressed array class set(test_name testArray${dims}${type}) add_executable(${test_name} ${test_name}.cpp) target_link_libraries(${test_name} gtest gtest_main zfp zfpHashLib genSmoothRandNumsLib zfpChecksumsLib) target_compile_definitions(${test_name} PRIVATE ${zfp_compressed_array_defs}) add_test(NAME ${test_name} COMMAND ${test_name}) # test class's references set(test_name testArray${dims}${type}Refs) add_executable(${test_name} ${test_name}.cpp) target_link_libraries(${test_name} gtest gtest_main zfp zfpHashLib rand${bits}Lib) target_compile_definitions(${test_name} PRIVATE ${zfp_compressed_array_defs}) add_test(NAME ${test_name} COMMAND ${test_name}) # test class's pointers set(test_name testArray${dims}${type}Ptrs) add_executable(${test_name} ${test_name}.cpp) target_link_libraries(${test_name} gtest gtest_main zfp) target_compile_definitions(${test_name} PRIVATE ${zfp_compressed_array_defs}) add_test(NAME ${test_name} COMMAND ${test_name}) # test class's iterators set(test_name testArray${dims}${type}Iters) add_executable(${test_name} ${test_name}.cpp) target_link_libraries(${test_name} gtest gtest_main zfp) target_compile_definitions(${test_name} PRIVATE ${zfp_compressed_array_defs}) add_test(NAME ${test_name} COMMAND ${test_name}) # test class's views set(test_name testArray${dims}${type}Views) add_executable(${test_name} ${test_name}.cpp) target_link_libraries(${test_name} gtest gtest_main zfp) target_compile_definitions(${test_name} PRIVATE ${zfp_compressed_array_defs}) add_test(NAME ${test_name} COMMAND ${test_name}) # test class's view pointers set(test_name testArray${dims}${type}ViewPtrs) add_executable(${test_name} ${test_name}.cpp) target_link_libraries(${test_name} gtest gtest_main zfp) target_compile_definitions(${test_name} PRIVATE ${zfp_compressed_array_defs}) add_test(NAME ${test_name} COMMAND ${test_name}) # test class's view iterators set(test_name testArray${dims}${type}ViewIters) add_executable(${test_name} ${test_name}.cpp) target_link_libraries(${test_name} gtest gtest_main zfp) target_compile_definitions(${test_name} PRIVATE ${zfp_compressed_array_defs}) add_test(NAME ${test_name} COMMAND ${test_name}) endfunction() zfp_add_cpp_tests(1 f 32) zfp_add_cpp_tests(2 f 32) zfp_add_cpp_tests(3 f 32) zfp_add_cpp_tests(4 f 32) zfp_add_cpp_tests(1 d 64) zfp_add_cpp_tests(2 d 64) zfp_add_cpp_tests(3 d 64) zfp_add_cpp_tests(4 d 64) # test zfp::array::construct() invalid cases set(test_name testConstruct) add_executable(testConstruct testConstruct.cpp) target_link_libraries(testConstruct gtest gtest_main zfp) target_compile_definitions(testConstruct PRIVATE ${zfp_compressed_array_defs}) add_test(NAME testConstruct COMMAND testConstruct) zfp-1.0.1/tests/array/array/testArray1Base.cpp000066400000000000000000000121751453723256400212650ustar00rootroot00000000000000/* TODO: figure out templated tests (TYPED_TEST) */ /* const_view */ TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromConstView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::const_view v(&arr, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromConstView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); /* create view and construct from it */ ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, viewLenX); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); } TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromConstView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); /* create view and construct from it */ ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, viewLenX); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i), arr2(i)); } /* verify it's a deep copy */ arr(offsetX + 0) = 999.; EXPECT_NE(arr(offsetX), arr2(0)); } /* view */ TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::view v(&arr, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); /* create view and construct from it */ ZFP_ARRAY_TYPE::view v(&arr, offsetX, viewLenX); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); } TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); /* create view and construct from it */ ZFP_ARRAY_TYPE::view v(&arr, offsetX, viewLenX); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i), arr2(i)); } /* verify it's a deep copy */ arr(offsetX + 0) = 999.; EXPECT_NE(arr(offsetX), arr2(0)); } /* private_const_view */ TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromPrivateConstView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::private_const_view v(&arr, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromPrivateConstView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, viewLenX); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); } TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromPrivateConstView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, viewLenX); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i), arr2(i)); } /* verify it's a deep copy */ arr(offsetX + 0) = 999.; EXPECT_NE(arr(offsetX), arr2(0)); } /* private_view */ TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromPrivateView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::private_view v(&arr, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromPrivateView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_view v(&arr, offsetX, viewLenX); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); } TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromPrivateView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_view v(&arr, offsetX, viewLenX); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i), arr2(i)); } /* verify it's a deep copy */ arr(offsetX + 0) = 999.; EXPECT_NE(arr(offsetX), arr2(0)); } zfp-1.0.1/tests/array/array/testArray1ItersBase.cpp000066400000000000000000000234731453723256400222770ustar00rootroot00000000000000TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_applyBrackets_then_returnsReferenceAtBracketPosition) { size_t i = 1, i2 = 2; arr[i] = VAL; iter = arr.begin() + i2; EXPECT_EQ(VAL, iter[i - i2]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_postDecrementIterator_then_advancedAfterEval) { arr[1] = VAL; iter = arr.begin(); iter++; SCALAR d = *iter--; EXPECT_EQ(VAL, d); EXPECT_EQ(0u, iter.i()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_preDecrementIterator_then_advancedBeforeEval) { arr[1] = VAL; iter = arr.begin(); iter++; EXPECT_EQ(0, *--iter); EXPECT_EQ(0u, iter.i()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_iteratorPlusEquals_then_iterAdvanced) { size_t i = 2; arr[i] = VAL; iter = arr.begin(); iter += i; EXPECT_EQ(i, iter.i()); EXPECT_EQ(VAL, *iter); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_iteratorMinusEquals_then_iterAdvanced) { size_t iFromEnd = 2; arr[ARRAY_SIZE - iFromEnd] = VAL; iter = arr.end(); iter -= iFromEnd; EXPECT_EQ(ARRAY_SIZE - iFromEnd, iter.i()); EXPECT_EQ(VAL, *iter); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_incrementIterator_then_positionTraversesCorrectly) { // force partial block EXPECT_NE(0u, arr.size() % BLOCK_SIDE_LEN); iter = arr.begin(); size_t totalBlocks = (arr.size() + 3) / 4; for (size_t count = 0; count < totalBlocks; count++) { // determine if block is complete or partial size_t distanceFromEnd = arr.size() - iter.i(); size_t blockLen = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; // ensure entries lie in same block size_t blockStartIndex = iter.i(); for (size_t i = 0; i < blockLen; i++) { EXPECT_EQ(blockStartIndex + i, iter.i()); iter++; } } // EXPECT_EQ(arr.end(), iter); // triggers googletest issue #742 EXPECT_TRUE(arr.end() == iter); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_decrementIterator_then_positionTraversesCorrectly) { // force partial block EXPECT_NE(0u, arr.size() % BLOCK_SIDE_LEN); iter = arr.end(); size_t totalBlocks = (arr.size() + 3) / 4; for (size_t count = 0; count < totalBlocks; count++) { iter--; // determine if block is complete or partial size_t blockEndIndex = iter.i(); size_t blockLen = (blockEndIndex % BLOCK_SIDE_LEN) + 1; // ensure entries lie in same block for (size_t i = 1; i < blockLen; i++) { iter--; EXPECT_EQ(blockEndIndex - i, iter.i()); } } // EXPECT_EQ(arr.begin(), iter); // triggers googletest issue #742 EXPECT_TRUE(arr.begin() == iter); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_subtractTwoIterators_then_resultIsDifference) { iter = arr.begin(); iter2 = arr.end(); EXPECT_EQ(ARRAY_SIZE, iter2 - iter); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_addToIterator_then_returnsAdvancedIter) { ptrdiff_t i = 2; arr[i] = VAL; iter = arr.begin(); EXPECT_EQ(VAL, *(iter + i)); EXPECT_EQ(i, (iter + i).i()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_subtractFromIterator_then_returnsAdvancedIter) { size_t iFromEnd = 1; arr[ARRAY_SIZE - iFromEnd] = VAL; iter = arr.end(); EXPECT_EQ(VAL, *(iter - iFromEnd)); EXPECT_EQ(ARRAY_SIZE - iFromEnd, (iter - iFromEnd).i()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayIteratorsWithSecondIndexedHigherThanFirst_when_compareFirstLessThanEqualToSecond_then_resultTrue) { iter = arr.begin(); iter2 = iter + 1; EXPECT_TRUE(iter <= iter2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayAndIndexIterators_when_compareLessThanEqualTo_then_resultTrue) { iter = arr.begin(); iter2 = arr.begin(); EXPECT_TRUE(iter <= iter2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayIteratorsWithFirstIndexedHigherThanSecond_when_compareFirstGreaterThanEqualToSecond_then_resultTrue) { iter = arr.begin() + 1; iter2 = arr.begin(); EXPECT_TRUE(iter >= iter2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayAndIndexIterators_when_compareGreaterThanEqualTo_then_resultTrue) { iter = arr.begin(); iter2 = arr.begin(); EXPECT_TRUE(iter >= iter2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayIteratorsWithSecondIndexedHigherThanFirst_when_compareFirstLessThanSecond_then_resultTrue) { iter = arr.begin(); iter2 = iter + 1; EXPECT_TRUE(iter < iter2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayAndIndexIterators_when_compareLessThan_then_resultFalse) { iter = arr.begin(); iter2 = arr.begin(); EXPECT_FALSE(iter < iter2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayIteratorsWithFirstIndexedHigherThanSecond_when_compareFirstGreaterThanSecond_then_resultTrue) { iter = arr.begin() + 1; iter2 = arr.begin(); EXPECT_TRUE(iter > iter2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayAndIndexIterators_when_compareGreaterThan_then_resultFalse) { iter = arr.begin(); iter2 = arr.begin(); EXPECT_FALSE(iter > iter2); } // const iterators TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_applyBrackets_then_returnsConstReferenceAtBracketPosition) { size_t i = 1, i2 = 2; arr[i] = VAL; citer = arr.cbegin() + i2; EXPECT_EQ(VAL, citer[i - i2]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_postDecrementConstIterator_then_advancedAfterEval) { arr[1] = VAL; citer = arr.cbegin(); citer++; SCALAR d = *citer--; EXPECT_EQ(VAL, d); EXPECT_EQ(0u, citer.i()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_preDecrementConstIterator_then_advancedBeforeEval) { arr[1] = VAL; citer = arr.cbegin(); citer++; EXPECT_EQ(0, *--citer); EXPECT_EQ(0u, citer.i()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_const_iteratorPlusEquals_then_iterAdvanced) { size_t i = 2; arr[i] = VAL; citer = arr.cbegin(); citer += i; EXPECT_EQ(i, citer.i()); EXPECT_EQ(VAL, *citer); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_const_iteratorMinusEquals_then_iterAdvanced) { size_t iFromEnd = 2; arr[ARRAY_SIZE - iFromEnd] = VAL; citer = arr.cend(); citer -= iFromEnd; EXPECT_EQ(ARRAY_SIZE - iFromEnd, citer.i()); EXPECT_EQ(VAL, *citer); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_incrementConstIterator_then_positionTraversesCorrectly) { // force partial block EXPECT_NE(0u, arr.size() % BLOCK_SIDE_LEN); citer = arr.cbegin(); size_t totalBlocks = (arr.size() + 3) / 4; for (size_t count = 0; count < totalBlocks; count++) { // determine if block is complete or partial size_t distanceFromEnd = arr.size() - citer.i(); size_t blockLen = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; // ensure entries lie in same block size_t blockStartIndex = citer.i(); for (size_t i = 0; i < blockLen; i++) { EXPECT_EQ(blockStartIndex + i, citer.i()); citer++; } } // EXPECT_EQ(arr.cend(), citer); // triggers googletest issue #742 EXPECT_TRUE(arr.cend() == citer); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_decrementConstIterator_then_positionTraversesCorrectly) { // force partial block EXPECT_NE(0u, arr.size() % BLOCK_SIDE_LEN); citer = arr.cend(); size_t totalBlocks = (arr.size() + 3) / 4; for (size_t count = 0; count < totalBlocks; count++) { citer--; // determine if block is complete or partial size_t blockEndIndex = citer.i(); size_t blockLen = (blockEndIndex % BLOCK_SIDE_LEN) + 1; // ensure entries lie in same block for (size_t i = 1; i < blockLen; i++) { citer--; EXPECT_EQ(blockEndIndex - i, citer.i()); } } // EXPECT_EQ(arr.cbegin(), citer); // triggers googletest issue #742 EXPECT_TRUE(arr.cbegin() == citer); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_subtractTwoConstIterators_then_resultIsDifference) { citer = arr.cbegin(); citer2 = arr.cend(); EXPECT_EQ(ARRAY_SIZE, citer2 - citer); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_addToConstIterator_then_returnsAdvancedIter) { size_t i = 2; arr[i] = VAL; citer = arr.cbegin(); EXPECT_EQ(VAL, *(citer + i)); EXPECT_EQ(i, (citer + i).i()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_subtractFromConstIterator_then_returnsAdvancedIter) { size_t iFromEnd = 1; arr[ARRAY_SIZE - iFromEnd] = VAL; citer = arr.cend(); EXPECT_EQ(VAL, *(citer - iFromEnd)); EXPECT_EQ(ARRAY_SIZE - iFromEnd, (citer - iFromEnd).i()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayConstIteratorsWithSecondIndexedHigherThanFirst_when_compareFirstLessThanEqualToSecond_then_resultTrue) { citer = arr.cbegin(); citer2 = citer + 1; EXPECT_TRUE(citer <= citer2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayAndIndexConstIterators_when_compareLessThanEqualTo_then_resultTrue) { citer = arr.cbegin(); citer2 = arr.cbegin(); EXPECT_TRUE(citer <= citer2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayConstIteratorsWithFirstIndexedHigherThanSecond_when_compareFirstGreaterThanEqualToSecond_then_resultTrue) { citer = arr.cbegin() + 1; citer2 = arr.cbegin(); EXPECT_TRUE(citer >= citer2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayAndIndexConstIterators_when_compareGreaterThanEqualTo_then_resultTrue) { citer = arr.cbegin(); citer2 = arr.cbegin(); EXPECT_TRUE(citer >= citer2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayConstIteratorsWithSecondIndexedHigherThanFirst_when_compareFirstLessThanSecond_then_resultTrue) { citer = arr.cbegin(); citer2 = citer + 1; EXPECT_TRUE(citer < citer2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayAndIndexConstIterators_when_compareLessThan_then_resultFalse) { citer = arr.cbegin(); citer2 = arr.cbegin(); EXPECT_FALSE(citer < citer2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayConstIteratorsWithFirstIndexedHigherThanSecond_when_compareFirstGreaterThanSecond_then_resultTrue) { citer = arr.cbegin() + 1; citer2 = arr.cbegin(); EXPECT_TRUE(citer > citer2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayAndIndexConstIterators_when_compareGreaterThan_then_resultFalse) { citer = arr.cbegin(); citer2 = arr.cbegin(); EXPECT_FALSE(citer > citer2); } zfp-1.0.1/tests/array/array/testArray1RefsBase.cpp000066400000000000000000000014141453723256400220770ustar00rootroot00000000000000TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_resize_then_sizeChanges) { EXPECT_EQ(ARRAY_SIZE, arr.size()); size_t newLen = ARRAY_SIZE + 1; arr.resize(newLen); EXPECT_EQ(newLen, arr.size()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_getIndexWithParentheses_then_refReturned) { size_t i = 1; arr(i) = VAL; EXPECT_EQ(VAL, arr(i)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, given_constCompressedArray_when_getIndexWithBrackets_then_valReturned) { size_t i = 1; arr[i] = VAL; const array1 arrConst = arr; EXPECT_EQ(VAL, arrConst[i]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, given_constCompressedArray_when_getIndexWithParentheses_then_valReturned) { size_t i = 1; arr[i] = VAL; const array1 arrConst = arr; EXPECT_EQ(VAL, arrConst(i)); } zfp-1.0.1/tests/array/array/testArray1ViewsBase.cpp000066400000000000000000000113001453723256400222700ustar00rootroot00000000000000/* preview */ /* this also tests const_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_previewFullConstructor1D_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::const_view v(&arr, offset, viewLen); EXPECT_EQ(viewLen, v.size()); EXPECT_EQ(offset, v.global_x(0)); } /* const_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_constView_when_sizeX_then_viewXLenReturned) { ZFP_ARRAY_TYPE::const_view v(&arr, offset, viewLen); EXPECT_EQ(viewLen, v.size_x()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_constView_when_accessorBrackets_then_correctEntriesReturned) { ZFP_ARRAY_TYPE::const_view v(&arr, offset, viewLen); for (size_t i = 0; i < viewLen; i++) { EXPECT_EQ(arr[offset + i], v[i]); } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_constView_when_accessorParens_then_correctEntriesReturned) { ZFP_ARRAY_TYPE::const_view v(&arr, offset, viewLen); for (size_t i = 0; i < viewLen; i++) { EXPECT_EQ(arr[offset + i], v(i)); } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_constViewFullConstructor_then_isShallowCopyOfCompressedArray) { ZFP_ARRAY_TYPE::const_view v(&arr, 1, 1); /* indices of view and arr */ size_t vI = 2; size_t aI = v.global_x(vI); SCALAR oldVal = arr[aI]; EXPECT_EQ(oldVal, v(vI)); arr[aI] += 1; SCALAR newVal = arr[aI]; EXPECT_NE(oldVal, newVal); EXPECT_EQ(newVal, v(vI)); } /* view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_viewFullConstructor_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::view v(&arr, offset, viewLen); EXPECT_EQ(viewLen, v.size_x()); EXPECT_EQ(offset, v.global_x(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_view_when_setEntryWithBrackets_then_originalArrayUpdated) { ZFP_ARRAY_TYPE::view v(&arr, offset, viewLen); size_t i = 1; SCALAR val = 3.14; EXPECT_NE(val, arr(offset + i)); v[i] = val; EXPECT_EQ(arr(offset + i), v(i)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_viewFullConstructor_then_isShallowCopyOfCompressedArray) { ZFP_ARRAY_TYPE::view v(&arr, 1, 1); /* indices of view and arr */ size_t vI = 2; size_t aI = v.global_x(vI); SCALAR oldVal = arr[aI]; EXPECT_EQ(oldVal, v(vI)); arr[aI] += 1; SCALAR newVal = arr[aI]; EXPECT_NE(oldVal, newVal); EXPECT_EQ(newVal, v(vI)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_view_when_setEntryWithParens_then_originalArrayUpdated) { ZFP_ARRAY_TYPE::view v(&arr, offset, viewLen); size_t i = 1; SCALAR val = 3.14; EXPECT_NE(val, arr(offset + i)); v(i) = val; EXPECT_EQ(arr(offset + i), v(i)); } /* private_const_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_privateConstViewFullConstructor_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::private_const_view v(&arr, offset, viewLen); EXPECT_EQ(viewLen, v.size()); EXPECT_EQ(viewLen, v.size_x()); EXPECT_EQ(offset, v.global_x(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_privateConstView_when_sizeX_then_viewLenReturned) { ZFP_ARRAY_TYPE::private_const_view v(&arr, offset, viewLen); EXPECT_EQ(viewLen, v.size_x()); } /* private_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_privateViewFullConstructor_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::private_view v(&arr, offset, viewLen); EXPECT_EQ(viewLen, v.size()); EXPECT_EQ(viewLen, v.size_x()); EXPECT_EQ(offset, v.global_x(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_privateView_when_partitionWithLimitOnCount_then_setsUniqueBlockBounds) { size_t count = 3; size_t prevOffset, prevLen, offset, len; /* partition such that each gets at least 1 block */ size_t blockSideLen = 4; size_t arrBlockCount = (arr.size_x() + (blockSideLen - 1)) / blockSideLen; EXPECT_LE(count, arrBlockCount); /* base case */ ZFP_ARRAY_TYPE::private_view v(&arr); v.partition(0, count); /* expect to start at first index, zero */ prevOffset = v.global_x(0); EXPECT_EQ(0, prevOffset); /* expect to have at least 1 block */ prevLen = v.size_x(); EXPECT_LE(blockSideLen, prevLen); /* successive cases are compared to previous */ for (size_t i = 1; i < count - 1; i++) { ZFP_ARRAY_TYPE::private_view v2(&arr); v2.partition(i, count); /* expect blocks continue where previous left off */ offset = v2.global_x(0); EXPECT_EQ(prevOffset + prevLen, offset); /* expect to have at least 1 block */ len = v2.size_x(); EXPECT_LE(blockSideLen, len); prevOffset = offset; prevLen = len; } /* last partition case */ ZFP_ARRAY_TYPE::private_view v3(&arr); v3.partition(count - 1, count); /* expect blocks continue where previous left off */ offset = v3.global_x(0); EXPECT_EQ(prevOffset + prevLen, offset); /* last partition could hold a partial block */ len = v3.size_x(); EXPECT_LT(0u, len); /* expect to end on final index */ EXPECT_EQ(arr.size_x(), offset + len); } zfp-1.0.1/tests/array/array/testArray1d.cpp000066400000000000000000000020531453723256400206300ustar00rootroot00000000000000#include "zfp/array1.hpp" #include "zfp/array3.hpp" #include "zfp/array4.hpp" #include "zfp/factory.hpp" #include "zfp/array2.hpp" using namespace zfp; extern "C" { #include "constants/1dDouble.h" } #include "gtest/gtest.h" #include "utils/gtestDoubleEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class Array1dTestEnv : public ArrayDoubleTestEnv { public: virtual int getDims() { return 1; } }; Array1dTestEnv* const testEnv = new Array1dTestEnv; class Array1dTest : public ArrayNdTestFixture {}; #define TEST_FIXTURE Array1dTest #define ZFP_ARRAY_TYPE array1d #define ZFP_ARRAY_TYPE_WRONG_SCALAR array1f #define ZFP_ARRAY_TYPE_WRONG_DIM array2d #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM array2f #define ZFP_ARRAY_NOT_INCLUDED_TYPE array3d #define UINT uint64 #define SCALAR double #define DIMS 1 #include "testArrayBase.cpp" #include "testArray1Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/array/testArray1dIters.cpp000066400000000000000000000003671453723256400216450ustar00rootroot00000000000000#include "zfp/array1.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array1dTest #define ARRAY_DIMS_SCALAR_TEST_ITERS Array1dTestIters #include "utils/gtest1dTest.h" #include "testArrayItersBase.cpp" #include "testArray1ItersBase.cpp" zfp-1.0.1/tests/array/array/testArray1dPtrs.cpp000066400000000000000000000003211453723256400214750ustar00rootroot00000000000000#include "zfp/array1.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array1dTest #define ARRAY_DIMS_SCALAR_TEST_PTRS Array1dTestPtrs #include "utils/gtest1dTest.h" #include "testArrayPtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray1dRefs.cpp000066400000000000000000000004371453723256400214540ustar00rootroot00000000000000#include "zfp/array1.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array1dTest #define ARRAY_DIMS_SCALAR_TEST_REFS Array1dTestRefs #include "utils/gtest1dTest.h" #include "testArrayRefsBase.cpp" #include "testArray1RefsBase.cpp" zfp-1.0.1/tests/array/array/testArray1dViewIters.cpp000066400000000000000000000005221453723256400224710ustar00rootroot00000000000000#include "zfp/array1.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array1dTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_ITERS Array1dTestViewIters #include "utils/gtest1dTest.h" #define ZFP_ARRAY_TYPE array1d #define SCALAR double #define DIMS 1 #include "testArrayViewItersBase.cpp" zfp-1.0.1/tests/array/array/testArray1dViewPtrs.cpp000066400000000000000000000005171453723256400223370ustar00rootroot00000000000000#include "zfp/array1.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array1dTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_PTRS Array1dTestViewPtrs #include "utils/gtest1dTest.h" #define ZFP_ARRAY_TYPE array1d #define SCALAR double #define DIMS 1 #include "testArrayViewPtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray1dViews.cpp000066400000000000000000000005501453723256400216460ustar00rootroot00000000000000#include "zfp/array1.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array1dTest #define ARRAY_DIMS_SCALAR_TEST_VIEWS Array1dTestViews #include "utils/gtest1dTest.h" #define ZFP_ARRAY_TYPE array1d #define SCALAR double #define DIMS 1 #include "testArrayViewsBase.cpp" #include "testArray1ViewsBase.cpp" zfp-1.0.1/tests/array/array/testArray1f.cpp000066400000000000000000000020471453723256400206350ustar00rootroot00000000000000#include "zfp/array1.hpp" #include "zfp/array3.hpp" #include "zfp/array4.hpp" #include "zfp/factory.hpp" #include "zfp/array2.hpp" using namespace zfp; extern "C" { #include "constants/1dFloat.h" } #include "gtest/gtest.h" #include "utils/gtestFloatEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class Array1fTestEnv : public ArrayFloatTestEnv { public: virtual int getDims() { return 1; } }; Array1fTestEnv* const testEnv = new Array1fTestEnv; class Array1fTest : public ArrayNdTestFixture {}; #define TEST_FIXTURE Array1fTest #define ZFP_ARRAY_TYPE array1f #define ZFP_ARRAY_TYPE_WRONG_SCALAR array1d #define ZFP_ARRAY_TYPE_WRONG_DIM array2f #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM array2d #define ZFP_ARRAY_NOT_INCLUDED_TYPE array3f #define UINT uint32 #define SCALAR float #define DIMS 1 #include "testArrayBase.cpp" #include "testArray1Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/array/testArray1fIters.cpp000066400000000000000000000003671453723256400216470ustar00rootroot00000000000000#include "zfp/array1.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array1fTest #define ARRAY_DIMS_SCALAR_TEST_ITERS Array1fTestIters #include "utils/gtest1fTest.h" #include "testArrayItersBase.cpp" #include "testArray1ItersBase.cpp" zfp-1.0.1/tests/array/array/testArray1fPtrs.cpp000066400000000000000000000003211453723256400214770ustar00rootroot00000000000000#include "zfp/array1.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array1fTest #define ARRAY_DIMS_SCALAR_TEST_PTRS Array1fTestPtrs #include "utils/gtest1fTest.h" #include "testArrayPtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray1fRefs.cpp000066400000000000000000000004371453723256400214560ustar00rootroot00000000000000#include "zfp/array1.hpp" using namespace zfp; extern "C" { #include "utils/rand32.h" } #define ARRAY_DIMS_SCALAR_TEST Array1fTest #define ARRAY_DIMS_SCALAR_TEST_REFS Array1fTestRefs #include "utils/gtest1fTest.h" #include "testArrayRefsBase.cpp" #include "testArray1RefsBase.cpp" zfp-1.0.1/tests/array/array/testArray1fViewIters.cpp000066400000000000000000000005211453723256400224720ustar00rootroot00000000000000#include "zfp/array1.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array1fTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_ITERS Array1fTestViewIters #include "utils/gtest1fTest.h" #define ZFP_ARRAY_TYPE array1f #define SCALAR float #define DIMS 1 #include "testArrayViewItersBase.cpp" zfp-1.0.1/tests/array/array/testArray1fViewPtrs.cpp000066400000000000000000000005161453723256400223400ustar00rootroot00000000000000#include "zfp/array1.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array1fTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_PTRS Array1fTestViewPtrs #include "utils/gtest1fTest.h" #define ZFP_ARRAY_TYPE array1f #define SCALAR float #define DIMS 1 #include "testArrayViewPtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray1fViews.cpp000066400000000000000000000005471453723256400216560ustar00rootroot00000000000000#include "zfp/array1.hpp" using namespace zfp; extern "C" { #include "utils/rand32.h" } #define ARRAY_DIMS_SCALAR_TEST Array1fTest #define ARRAY_DIMS_SCALAR_TEST_VIEWS Array1fTestViews #include "utils/gtest1fTest.h" #define ZFP_ARRAY_TYPE array1f #define SCALAR float #define DIMS 1 #include "testArrayViewsBase.cpp" #include "testArray1ViewsBase.cpp" zfp-1.0.1/tests/array/array/testArray2Base.cpp000066400000000000000000000277541453723256400212770ustar00rootroot00000000000000/* TODO: figure out templated tests (TYPED_TEST) */ /* const_view */ TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromConstView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::const_view v(&arr, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromConstView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); /* create view and construct from it */ ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromConstView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); /* create view and construct from it */ ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j), arr2(i, j)); } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY), arr2(0, 0)); } /* view */ TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::view v(&arr, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); /* create view and construct from it */ ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); /* create view and construct from it */ ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j), arr2(i, j)); } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY), arr2(0, 0)); } /* flat_view */ TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromFlatView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::flat_view v(&arr, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromFlatView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); /* create view and construct from it */ ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromFlatView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); /* create view and construct from it */ ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j), arr2(i, j)); } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY), arr2(0, 0)); } /* nested_view */ TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromNestedView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::nested_view v(&arr, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); /* rate may be increased when moving to lower dimension compressed array */ EXPECT_LE(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromNestedView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromNestedView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j), arr2(i, j)); } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY), arr2(0, 0)); } /* nested_view1 (unique) */ TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromNestedView1_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::nested_view v(&arr, 1, 1, 1, 1); ZFP_ARRAY_TYPE::nested_view1 v2 = v[0]; array1 arr2(v2); /* rate may be increased when moving to lower dimension compressed array */ EXPECT_LE(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromNestedView1_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE::nested_view1 v2 = v[0]; array1 arr2(v2); EXPECT_EQ(v.size_x(), arr2.size_x()); } TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromNestedView1_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); size_t y = 1; ZFP_ARRAY_TYPE::nested_view1 v2 = v[y]; array1 arr2(v2); /* verify array entries */ for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + y), arr2(i)); } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + y) = 999.; EXPECT_NE(arr(offsetX, offsetY + y), arr2(0)); } /* private_const_view */ TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromPrivateConstView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::private_const_view v(&arr, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromPrivateConstView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromPrivateConstView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j), arr2(i, j)); } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY), arr2(0, 0)); } /* private_view */ TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromPrivateView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::private_view v(&arr, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromPrivateView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromPrivateView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j), arr2(i, j)); } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY), arr2(0, 0)); } zfp-1.0.1/tests/array/array/testArray2ItersBase.cpp000066400000000000000000000050051453723256400222670ustar00rootroot00000000000000TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_partialBlocks_when_incrementIterator_then_positionTraversesCorrectly) { // force partial block traversal EXPECT_NE(0u, arr.size_x() % BLOCK_SIDE_LEN); EXPECT_NE(0u, arr.size_y() % BLOCK_SIDE_LEN); size_t totalBlocksX = (arr.size_x() + 3) / 4; size_t totalBlocksY = (arr.size_y() + 3) / 4; size_t totalBlocks = totalBlocksX * totalBlocksY; iter = arr.begin(); for (size_t count = 0; count < totalBlocks; count++) { // determine if block is complete or partial size_t distanceFromEnd = arr.size_x() - iter.i(); size_t blockLenX = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; distanceFromEnd = arr.size_y() - iter.j(); size_t blockLenY = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; // ensure entries lie in same block size_t blockStartIndexI = iter.i(); size_t blockStartIndexJ = iter.j(); for (size_t j = 0; j < blockLenY; j++) { for (size_t i = 0; i < blockLenX; i++) { EXPECT_EQ(blockStartIndexI + i, iter.i()); EXPECT_EQ(blockStartIndexJ + j, iter.j()); iter++; } } } // EXPECT_EQ(arr.end(), iter); // triggers googletest issue #742 EXPECT_TRUE(arr.end() == iter); } // const iterators TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_partialBlocks_when_incrementConstIterator_then_positionTraversesCorrectly) { // force partial block traversal EXPECT_NE(0u, arr.size_x() % BLOCK_SIDE_LEN); EXPECT_NE(0u, arr.size_y() % BLOCK_SIDE_LEN); size_t totalBlocksX = (arr.size_x() + 3) / 4; size_t totalBlocksY = (arr.size_y() + 3) / 4; size_t totalBlocks = totalBlocksX * totalBlocksY; citer = arr.cbegin(); for (size_t count = 0; count < totalBlocks; count++) { // determine if block is complete or partial size_t distanceFromEnd = arr.size_x() - citer.i(); size_t blockLenX = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; distanceFromEnd = arr.size_y() - citer.j(); size_t blockLenY = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; // ensure entries lie in same block size_t blockStartIndexI = citer.i(); size_t blockStartIndexJ = citer.j(); for (size_t j = 0; j < blockLenY; j++) { for (size_t i = 0; i < blockLenX; i++) { EXPECT_EQ(blockStartIndexI + i, citer.i()); EXPECT_EQ(blockStartIndexJ + j, citer.j()); citer++; } } } // EXPECT_EQ(arr.cend(), citer); // triggers googletest issue #742 EXPECT_TRUE(arr.cend() == citer); } zfp-1.0.1/tests/array/array/testArray2PtrsBase.cpp000066400000000000000000000007621453723256400221360ustar00rootroot00000000000000TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_pointerAtXBoundary_when_increment_then_pointerPositionTraversesCorrectly) { size_t i = arr.size_x() - 1; size_t j = 2; arr(0, j+1) = VAL; ptr = &arr(i, j); EXPECT_EQ(VAL, *++ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_pointerAtXBoundary_when_decrement_then_pointerPositionTraversesCorrectly) { size_t i = 0; size_t j = 2; size_t iNext = arr.size_x() - 1; arr(iNext, j-1) = VAL; ptr = &arr(i, j); EXPECT_EQ(VAL, *--ptr); } zfp-1.0.1/tests/array/array/testArray2RefsBase.cpp000066400000000000000000000025201453723256400220770ustar00rootroot00000000000000TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_resize_then_sizeChanges) { EXPECT_EQ(ARRAY_SIZE_X, arr.size_x()); EXPECT_EQ(ARRAY_SIZE_Y, arr.size_y()); EXPECT_EQ(ARRAY_SIZE_X * ARRAY_SIZE_Y, arr.size()); size_t newLenX = ARRAY_SIZE_X + 1; size_t newLenY = ARRAY_SIZE_Y - 2; arr.resize(newLenX, newLenY); EXPECT_EQ(newLenX, arr.size_x()); EXPECT_EQ(newLenY, arr.size_y()); EXPECT_EQ(newLenX * newLenY, arr.size()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_getIndexWithParentheses_then_refReturned) { size_t i = 1, j = 1; arr(i, j) = VAL; EXPECT_EQ(VAL, arr(i, j)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_indexWithBracketsAlongsideParentheses_then_indexedProperly) { size_t i = 1, j = 1; size_t absIndex = j * arr.size_x() + i; arr[absIndex] = VAL; EXPECT_EQ(VAL, arr(i, j)); arr(i, j) /= VAL; EXPECT_EQ(1, arr[absIndex]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, given_constCompressedArray_when_getIndexWithBrackets_then_valReturned) { size_t i = 1; arr[i] = VAL; const array2 arrConst = arr; EXPECT_EQ(VAL, arrConst[i]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, given_constCompressedArray_when_getIndexWithParentheses_then_valReturned) { size_t i = 1, j = 1; size_t absIndex = j * arr.size_x() + i; arr[absIndex] = VAL; const array2 arrConst = arr; EXPECT_EQ(VAL, arrConst(i, j)); } zfp-1.0.1/tests/array/array/testArray2ViewsBase.cpp000066400000000000000000000254601453723256400223050ustar00rootroot00000000000000/* preview */ /* this also tests const_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_previewFullConstructor2D_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); EXPECT_EQ(viewLenX * viewLenY, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); } /* const_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_constView_when_sizeXY_then_viewXYLenReturned) { ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_constView_when_accessorParens_then_correctEntriesReturned) { ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { size_t offset = (offsetY + j) * arr.size_x() + offsetX + i; EXPECT_EQ(arr[offset], v(i, j)); } } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_constViewFullConstructor_then_isShallowCopyOfCompressedArray) { ZFP_ARRAY_TYPE::const_view v(&arr, 1, 1, 1, 1); /* indices of view and arr */ size_t vIX = 2; size_t aIX = v.global_x(vIX); size_t vIY = 2; size_t aIY = v.global_y(vIY); SCALAR oldVal = arr(aIX, aIY); EXPECT_EQ(oldVal, v(vIX, vIY)); arr(aIX, aIY) += 1; SCALAR newVal = arr(aIX, aIY); EXPECT_NE(oldVal, newVal); EXPECT_EQ(newVal, v(vIX, vIY)); } /* view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_viewFullConstructor_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, viewLenX, viewLenY); EXPECT_EQ(viewLenX * viewLenY, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_viewFullConstructor_then_isShallowCopyOfCompressedArray) { ZFP_ARRAY_TYPE::view v(&arr, 1, 1, 1, 1); /* indices of view and arr */ size_t vIX = 2; size_t aIX = v.global_x(vIX); size_t vIY = 2; size_t aIY = v.global_y(vIY); SCALAR oldVal = arr(aIX, aIY); EXPECT_EQ(oldVal, v(vIX, vIY)); arr(aIX, aIY) += 1; SCALAR newVal = arr(aIX, aIY); EXPECT_NE(oldVal, newVal); EXPECT_EQ(newVal, v(vIX, vIY)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_view_when_setEntryWithParens_then_originalArrayUpdated) { ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, viewLenX, viewLenY); size_t i = 1, j = 2; SCALAR val = 3.14; EXPECT_NE(val, arr(offsetX + i, offsetY + j)); v(i, j) = val; EXPECT_EQ(arr(offsetX + i, offsetY + j), v(i, j)); } /* flat_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_flatViewFullConstructor_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); EXPECT_EQ(viewLenX * viewLenY, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_flatViewFullConstructor_then_isShallowCopyOfCompressedArray) { ZFP_ARRAY_TYPE::flat_view v(&arr, 1, 1, 1, 1); /* indices of view and arr */ size_t vIX = 2; size_t aIX = v.global_x(vIX); size_t vIY = 2; size_t aIY = v.global_y(vIY); SCALAR oldVal = arr(aIX, aIY); EXPECT_EQ(oldVal, v(vIX, vIY)); arr(aIX, aIY) += 1; SCALAR newVal = arr(aIX, aIY); EXPECT_NE(oldVal, newVal); EXPECT_EQ(newVal, v(vIX, vIY)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_flatView_when_index_then_returnsFlatIndex) { ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); size_t i = 2, j = 1; EXPECT_EQ(j*viewLenX + i, v.index(i, j)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_flatView_when_ij_then_returnsUnflatIndices) { ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); size_t i = 2, j = 1; size_t flatIndex = v.index(i, j); size_t vI, vJ; v.ij(vI, vJ, flatIndex); EXPECT_EQ(i, vI); EXPECT_EQ(j, vJ); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_flatView_when_bracketAccessor_then_returnsValAtFlattenedIndex) { ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); size_t i = 2, j = 1; size_t arrOffset = (offsetY + j)*arr.size_x() + (offsetX + i); EXPECT_EQ(arr[arrOffset], v[v.index(i, j)]); } /* nested_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_nestedView2FullConstructor2D_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); EXPECT_EQ(viewLenX * viewLenY, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView_when_parensAccessor_then_returnsValue) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); /* indices for view and array */ size_t vI = 1; size_t vJ = 2; size_t aI = offsetX + vI; size_t aJ = offsetY + vJ; arr(aI, aJ) = 5.5; EXPECT_EQ(arr(aI, aJ), v(vI, vJ)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView_when_parensMutator_then_setsValue) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); /* indices for view and array */ size_t vI = 1; size_t vJ = 2; size_t aI = offsetX + vI; size_t aJ = offsetY + vJ; SCALAR val = 5.5; v(vI, vJ) = val; EXPECT_EQ(val, arr(aI, aJ)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView2_when_bracketIndex_then_returnsSliceFromView) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); /* test slice length */ EXPECT_EQ(viewLenX, v[0].size_x()); } /* nested_view1 */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView1_when_bracketAccessor_then_returnsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); /* indices for view and array */ size_t vJ = 2; size_t aJ = offsetY + vJ; /* initialize values into row that will become slice */ for (size_t aI = 0; aI < arr.size_x(); aI++) { arr(aI, aJ) = (SCALAR)aI; } EXPECT_EQ(viewLenX, v[vJ].size_x()); for (size_t vI = 0; vI < viewLenX; vI++) { EXPECT_EQ(arr(offsetX + vI, aJ), v[vJ][vI]); } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView1_when_parensAccessor_then_returnsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); /* indices for view and array */ size_t vJ = 2; size_t aJ = offsetY + vJ; /* initialize values into row that will become slice */ for (size_t aI = 0; aI < arr.size_x(); aI++) { arr(aI, aJ) = (SCALAR)aI; } EXPECT_EQ(viewLenX, v[vJ].size_x()); for (size_t vI = 0; vI < viewLenX; vI++) { EXPECT_EQ(arr(offsetX + vI, aJ), v[vJ](vI)); } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView1_when_bracketMutator_then_setsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); /* indices for view and array */ size_t vJ = 2; size_t aJ = offsetY + vJ; /* initialize values into slice */ for (size_t vI = 0; vI < v[vJ].size_x(); vI++) { v[vJ][vI] = (SCALAR)vI; } for (size_t vI = 0; vI < v[vJ].size_x(); vI++) { EXPECT_EQ(v[vJ][vI], arr(offsetX + vI, aJ)); } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView1_when_parensMutator_then_setsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); /* indices for view and array */ size_t vJ = 2; size_t aJ = offsetY + vJ; /* initialize values into slice */ for (size_t vI = 0; vI < v[vJ].size_x(); vI++) { v[vJ](vI) = (SCALAR)vI; } for (size_t vI = 0; vI < v[vJ].size_x(); vI++) { EXPECT_EQ(v[vJ][vI], arr(offsetX + vI, aJ)); } } /* private_const_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_privateConstViewFullConstructor_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); EXPECT_EQ(viewLenX * viewLenY, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_privateConstView_when_sizeXY_then_viewLenReturned) { ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); } /* private_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_privateViewFullConstructor_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::private_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); EXPECT_EQ(viewLenX * viewLenY, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_privateView_when_partitionWithLimitOnCount_then_setsUniqueBlockBoundsAlongLongerDimension) { const size_t count = 3; size_t prevOffsetX, prevLenX, offsetX, lenX; /* partition such that each gets at least 1 block */ const size_t blockSideLen = 4; size_t arrBlockCountX = (arr.size_x() + (blockSideLen - 1)) / blockSideLen; size_t arrBlockCountY = (arr.size_y() + (blockSideLen - 1)) / blockSideLen; /* ensure partition will happen along X */ EXPECT_GT(arrBlockCountX, arrBlockCountY); EXPECT_LE(count, arrBlockCountX); /* construct view */ ZFP_ARRAY_TYPE::private_view v(&arr); size_t offsetY = v.global_y(0); size_t lenY = v.size_y(); /* base case */ v.partition(0, count); /* along X, expect to start at first index, zero */ prevOffsetX = v.global_x(0); EXPECT_EQ(0, prevOffsetX); /* expect to have at least 1 block */ prevLenX = v.size_x(); EXPECT_LE(blockSideLen, prevLenX); /* along Y, expect no changes */ EXPECT_EQ(offsetY, v.global_y(0)); EXPECT_EQ(lenY, v.size_y()); /* successive cases are compared to previous */ for (size_t i = 1; i < count - 1; i++) { ZFP_ARRAY_TYPE::private_view v2(&arr); v2.partition(i, count); /* along X, expect blocks continue where previous left off */ offsetX = v2.global_x(0); EXPECT_EQ(prevOffsetX + prevLenX, offsetX); /* expect to have at least 1 block */ lenX = v2.size_x(); EXPECT_LE(blockSideLen, lenX); /* along Y, expect no changes */ EXPECT_EQ(offsetY, v2.global_y(0)); EXPECT_EQ(lenY, v2.size_y()); prevOffsetX = offsetX; prevLenX = lenX; } /* last partition case */ ZFP_ARRAY_TYPE::private_view v3(&arr); v3.partition(count - 1, count); /* along X, expect blocks continue where previous left off */ offsetX = v3.global_x(0); EXPECT_EQ(prevOffsetX + prevLenX, offsetX); /* last partition could hold a partial block */ lenX = v3.size_x(); EXPECT_LT(0u, lenX); /* expect to end on final index */ EXPECT_EQ(arr.size_x(), offsetX + lenX); /* along Y, expect no changes */ EXPECT_EQ(offsetY, v3.global_y(0)); EXPECT_EQ(lenY, v3.size_y()); } zfp-1.0.1/tests/array/array/testArray2d.cpp000066400000000000000000000020531453723256400206310ustar00rootroot00000000000000#include "zfp/array1.hpp" #include "zfp/array2.hpp" #include "zfp/array4.hpp" #include "zfp/factory.hpp" #include "zfp/array3.hpp" using namespace zfp; extern "C" { #include "constants/2dDouble.h" } #include "gtest/gtest.h" #include "utils/gtestDoubleEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class Array2dTestEnv : public ArrayDoubleTestEnv { public: virtual int getDims() { return 2; } }; Array2dTestEnv* const testEnv = new Array2dTestEnv; class Array2dTest : public ArrayNdTestFixture {}; #define TEST_FIXTURE Array2dTest #define ZFP_ARRAY_TYPE array2d #define ZFP_ARRAY_TYPE_WRONG_SCALAR array2f #define ZFP_ARRAY_TYPE_WRONG_DIM array3d #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM array3f #define ZFP_ARRAY_NOT_INCLUDED_TYPE array1d #define UINT uint64 #define SCALAR double #define DIMS 2 #include "testArrayBase.cpp" #include "testArray2Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/array/testArray2dIters.cpp000066400000000000000000000003671453723256400216460ustar00rootroot00000000000000#include "zfp/array2.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array2dTest #define ARRAY_DIMS_SCALAR_TEST_ITERS Array2dTestIters #include "utils/gtest2dTest.h" #include "testArrayItersBase.cpp" #include "testArray2ItersBase.cpp" zfp-1.0.1/tests/array/array/testArray2dPtrs.cpp000066400000000000000000000003631453723256400215040ustar00rootroot00000000000000#include "zfp/array2.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array2dTest #define ARRAY_DIMS_SCALAR_TEST_PTRS Array2dTestPtrs #include "utils/gtest2dTest.h" #include "testArrayPtrsBase.cpp" #include "testArray2PtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray2dRefs.cpp000066400000000000000000000004371453723256400214550ustar00rootroot00000000000000#include "zfp/array2.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array2dTest #define ARRAY_DIMS_SCALAR_TEST_REFS Array2dTestRefs #include "utils/gtest2dTest.h" #include "testArrayRefsBase.cpp" #include "testArray2RefsBase.cpp" zfp-1.0.1/tests/array/array/testArray2dViewIters.cpp000066400000000000000000000005221453723256400224720ustar00rootroot00000000000000#include "zfp/array2.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array2dTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_ITERS Array2dTestViewIters #include "utils/gtest2dTest.h" #define ZFP_ARRAY_TYPE array2d #define SCALAR double #define DIMS 2 #include "testArrayViewItersBase.cpp" zfp-1.0.1/tests/array/array/testArray2dViewPtrs.cpp000066400000000000000000000005171453723256400223400ustar00rootroot00000000000000#include "zfp/array2.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array2dTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_PTRS Array2dTestViewPtrs #include "utils/gtest2dTest.h" #define ZFP_ARRAY_TYPE array2d #define SCALAR double #define DIMS 2 #include "testArrayViewPtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray2dViews.cpp000066400000000000000000000005501453723256400216470ustar00rootroot00000000000000#include "zfp/array2.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array2dTest #define ARRAY_DIMS_SCALAR_TEST_VIEWS Array2dTestViews #include "utils/gtest2dTest.h" #define ZFP_ARRAY_TYPE array2d #define SCALAR double #define DIMS 2 #include "testArrayViewsBase.cpp" #include "testArray2ViewsBase.cpp" zfp-1.0.1/tests/array/array/testArray2f.cpp000066400000000000000000000020471453723256400206360ustar00rootroot00000000000000#include "zfp/array1.hpp" #include "zfp/array2.hpp" #include "zfp/array4.hpp" #include "zfp/factory.hpp" #include "zfp/array3.hpp" using namespace zfp; extern "C" { #include "constants/2dFloat.h" } #include "gtest/gtest.h" #include "utils/gtestFloatEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class Array2fTestEnv : public ArrayFloatTestEnv { public: virtual int getDims() { return 2; } }; Array2fTestEnv* const testEnv = new Array2fTestEnv; class Array2fTest : public ArrayNdTestFixture {}; #define TEST_FIXTURE Array2fTest #define ZFP_ARRAY_TYPE array2f #define ZFP_ARRAY_TYPE_WRONG_SCALAR array2d #define ZFP_ARRAY_TYPE_WRONG_DIM array3f #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM array3d #define ZFP_ARRAY_NOT_INCLUDED_TYPE array1f #define UINT uint32 #define SCALAR float #define DIMS 2 #include "testArrayBase.cpp" #include "testArray2Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/array/testArray2fIters.cpp000066400000000000000000000003671453723256400216500ustar00rootroot00000000000000#include "zfp/array2.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array2fTest #define ARRAY_DIMS_SCALAR_TEST_ITERS Array2fTestIters #include "utils/gtest2fTest.h" #include "testArrayItersBase.cpp" #include "testArray2ItersBase.cpp" zfp-1.0.1/tests/array/array/testArray2fPtrs.cpp000066400000000000000000000003631453723256400215060ustar00rootroot00000000000000#include "zfp/array2.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array2fTest #define ARRAY_DIMS_SCALAR_TEST_PTRS Array2fTestPtrs #include "utils/gtest2fTest.h" #include "testArrayPtrsBase.cpp" #include "testArray2PtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray2fRefs.cpp000066400000000000000000000004371453723256400214570ustar00rootroot00000000000000#include "zfp/array2.hpp" using namespace zfp; extern "C" { #include "utils/rand32.h" } #define ARRAY_DIMS_SCALAR_TEST Array2fTest #define ARRAY_DIMS_SCALAR_TEST_REFS Array2fTestRefs #include "utils/gtest2fTest.h" #include "testArrayRefsBase.cpp" #include "testArray2RefsBase.cpp" zfp-1.0.1/tests/array/array/testArray2fViewIters.cpp000066400000000000000000000005211453723256400224730ustar00rootroot00000000000000#include "zfp/array2.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array2fTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_ITERS Array2fTestViewIters #include "utils/gtest2fTest.h" #define ZFP_ARRAY_TYPE array2f #define SCALAR float #define DIMS 2 #include "testArrayViewItersBase.cpp" zfp-1.0.1/tests/array/array/testArray2fViewPtrs.cpp000066400000000000000000000005161453723256400223410ustar00rootroot00000000000000#include "zfp/array2.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array2fTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_PTRS Array2fTestViewPtrs #include "utils/gtest2fTest.h" #define ZFP_ARRAY_TYPE array2f #define SCALAR float #define DIMS 2 #include "testArrayViewPtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray2fViews.cpp000066400000000000000000000005471453723256400216570ustar00rootroot00000000000000#include "zfp/array2.hpp" using namespace zfp; extern "C" { #include "utils/rand32.h" } #define ARRAY_DIMS_SCALAR_TEST Array2fTest #define ARRAY_DIMS_SCALAR_TEST_VIEWS Array2fTestViews #include "utils/gtest2fTest.h" #define ZFP_ARRAY_TYPE array2f #define SCALAR float #define DIMS 2 #include "testArrayViewsBase.cpp" #include "testArray2ViewsBase.cpp" zfp-1.0.1/tests/array/array/testArray3Base.cpp000066400000000000000000000420121453723256400212600ustar00rootroot00000000000000/* TODO: figure out templated tests (TYPED_TEST) */ /* const_view */ TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromConstView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::const_view v(&arr, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromConstView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); EXPECT_EQ(v.size_z(), arr2.size_z()); } TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromConstView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t k = 0; k < viewLenZ; k++) { for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + k), arr2(i, j, k)); } } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0, offsetZ + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY, offsetZ), arr2(0, 0, 0)); } /* view */ TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::view v(&arr, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); EXPECT_EQ(v.size_z(), arr2.size_z()); } TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t k = 0; k < viewLenZ; k++) { for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + k), arr2(i, j, k)); } } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0, offsetZ + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY, offsetZ), arr2(0, 0, 0)); } /* flat_view */ TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromFlatView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::flat_view v(&arr, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromFlatView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); EXPECT_EQ(v.size_z(), arr2.size_z()); } TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromFlatView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t k = 0; k < viewLenZ; k++) { for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + k), arr2(i, j, k)); } } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0, offsetZ + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY, offsetZ), arr2(0, 0, 0)); } /* nested_view */ TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromNestedView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::nested_view v(&arr, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); /* rate may be increased when moving to lower dimension compressed array */ EXPECT_LE(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromNestedView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); EXPECT_EQ(v.size_z(), arr2.size_z()); } TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromNestedView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t k = 0; k < viewLenZ; k++) { for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + k), arr2(i, j, k)); } } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0, offsetZ + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY, offsetZ), arr2(0, 0, 0)); } /* nested_view2 (unique) */ TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromNestedView2_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::nested_view v(&arr, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE::nested_view2 v2 = v[0]; array2 arr2(v2); /* rate may be increased when moving to lower dimension compressed array */ EXPECT_LE(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromNestedView2_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE::nested_view2 v2 = v[0]; array2 arr2(v2); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromNestedView2_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); size_t z = 1; ZFP_ARRAY_TYPE::nested_view2 v2 = v[z]; array2 arr2(v2); /* verify array entries */ for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + z), arr2(i, j)); } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0, offsetZ + z) = 999.; EXPECT_NE(arr(offsetX, offsetY, offsetZ + z), arr2(0, 0)); } /* nested_view1 (unique) */ TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromNestedView1_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::nested_view v(&arr, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE::nested_view1 v2 = v[0][0]; array1 arr2(v2); /* rate may be increased when moving to lower dimension compressed array */ EXPECT_LE(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromNestedView1_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE::nested_view1 v2 = v[0][0]; array1 arr2(v2); EXPECT_EQ(v.size_x(), arr2.size_x()); } TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromNestedView1_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); size_t y = 1; size_t z = 0; ZFP_ARRAY_TYPE::nested_view1 v2 = v[z][y]; array1 arr2(v2); /* verify array entries */ for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + y, offsetZ + z), arr2(i)); } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + y, offsetZ + z) = 999.; EXPECT_NE(arr(offsetX, offsetY + y, offsetZ + z), arr2(0)); } /* private_const_view */ TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromPrivateConstView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::private_const_view v(&arr, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromPrivateConstView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); EXPECT_EQ(v.size_z(), arr2.size_z()); } TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromPrivateConstView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t k = 0; k < viewLenZ; k++) { for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + k), arr2(i, j, k)); } } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0, offsetZ + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY, offsetZ), arr2(0, 0, 0)); } /* private_view */ TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromPrivateView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::private_view v(&arr, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromPrivateView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); EXPECT_EQ(v.size_z(), arr2.size_z()); } TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromPrivateView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t k = 0; k < viewLenZ; k++) { for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + k), arr2(i, j, k)); } } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0, offsetZ + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY, offsetZ), arr2(0, 0, 0)); } zfp-1.0.1/tests/array/array/testArray3ItersBase.cpp000066400000000000000000000064721453723256400223010ustar00rootroot00000000000000TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_partialBlocks_when_incrementIterator_then_positionTraversesCorrectly) { // force partial block traversal EXPECT_NE(0u, arr.size_x() % BLOCK_SIDE_LEN); EXPECT_NE(0u, arr.size_y() % BLOCK_SIDE_LEN); EXPECT_NE(0u, arr.size_z() % BLOCK_SIDE_LEN); size_t totalBlocksX = (arr.size_x() + 3) / 4; size_t totalBlocksY = (arr.size_y() + 3) / 4; size_t totalBlocksZ = (arr.size_z() + 3) / 4; size_t totalBlocks = totalBlocksX * totalBlocksY * totalBlocksZ; iter = arr.begin(); for (size_t count = 0; count < totalBlocks; count++) { // determine if block is complete or partial size_t distanceFromEnd = arr.size_x() - iter.i(); size_t blockLenX = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; distanceFromEnd = arr.size_y() - iter.j(); size_t blockLenY = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; distanceFromEnd = arr.size_z() - iter.k(); size_t blockLenZ = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; // ensure entries lie in same block size_t blockStartIndexI = iter.i(); size_t blockStartIndexJ = iter.j(); size_t blockStartIndexK = iter.k(); for (size_t k = 0; k < blockLenZ; k++) { for (size_t j = 0; j < blockLenY; j++) { for (size_t i = 0; i < blockLenX; i++) { EXPECT_EQ(blockStartIndexI + i, iter.i()); EXPECT_EQ(blockStartIndexJ + j, iter.j()); EXPECT_EQ(blockStartIndexK + k, iter.k()); iter++; } } } } // EXPECT_EQ(arr.end(), iter); // triggers googletest issue #742 EXPECT_TRUE(arr.end() == iter); } // const iterators TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_partialBlocks_when_incrementConstIterator_then_positionTraversesCorrectly) { // force partial block traversal EXPECT_NE(0u, arr.size_x() % BLOCK_SIDE_LEN); EXPECT_NE(0u, arr.size_y() % BLOCK_SIDE_LEN); EXPECT_NE(0u, arr.size_z() % BLOCK_SIDE_LEN); size_t totalBlocksX = (arr.size_x() + 3) / 4; size_t totalBlocksY = (arr.size_y() + 3) / 4; size_t totalBlocksZ = (arr.size_z() + 3) / 4; size_t totalBlocks = totalBlocksX * totalBlocksY * totalBlocksZ; citer = arr.cbegin(); for (size_t count = 0; count < totalBlocks; count++) { // determine if block is complete or partial size_t distanceFromEnd = arr.size_x() - citer.i(); size_t blockLenX = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; distanceFromEnd = arr.size_y() - citer.j(); size_t blockLenY = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; distanceFromEnd = arr.size_z() - citer.k(); size_t blockLenZ = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; // ensure entries lie in same block size_t blockStartIndexI = citer.i(); size_t blockStartIndexJ = citer.j(); size_t blockStartIndexK = citer.k(); for (size_t k = 0; k < blockLenZ; k++) { for (size_t j = 0; j < blockLenY; j++) { for (size_t i = 0; i < blockLenX; i++) { EXPECT_EQ(blockStartIndexI + i, citer.i()); EXPECT_EQ(blockStartIndexJ + j, citer.j()); EXPECT_EQ(blockStartIndexK + k, citer.k()); citer++; } } } } // EXPECT_EQ(arr.cend(), citer); // triggers googletest issue #742 EXPECT_TRUE(arr.cend() == citer); } zfp-1.0.1/tests/array/array/testArray3PtrsBase.cpp000066400000000000000000000021651453723256400221360ustar00rootroot00000000000000TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_pointerAtXBoundary_when_increment_then_pointerPositionTraversesCorrectly) { size_t i = arr.size_x() - 1; size_t j = 2; size_t k = 4; arr(0, j+1, k) = VAL; ptr = &arr(i, j, k); EXPECT_EQ(VAL, *++ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_pointerAtXBoundary_when_decrement_then_pointerPositionTraversesCorrectly) { size_t i = 0; size_t j = 2; size_t k = 3; size_t iNext = arr.size_x() - 1; arr(iNext, j-1, k) = VAL; ptr = &arr(i, j, k); EXPECT_EQ(VAL, *--ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_pointerAtXYBoundary_when_increment_then_pointerPositionTraversesCorrectly) { size_t i = arr.size_x() - 1; size_t j = arr.size_y() - 1; size_t k = 4; arr(0, 0, k+1) = VAL; ptr = &arr(i, j, k); EXPECT_EQ(VAL, *++ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_pointerAtXYBoundary_when_decrement_then_pointerPositionTraversesCorrectly) { size_t i = 0; size_t j = 0; size_t k = 3; size_t iNext = arr.size_x() - 1; size_t jNext = arr.size_y() - 1; arr(iNext, jNext, k-1) = VAL; ptr = &arr(i, j, k); EXPECT_EQ(VAL, *--ptr); } zfp-1.0.1/tests/array/array/testArray3RefsBase.cpp000066400000000000000000000031141453723256400221000ustar00rootroot00000000000000TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_resize_then_sizeChanges) { EXPECT_EQ(ARRAY_SIZE_X, arr.size_x()); EXPECT_EQ(ARRAY_SIZE_Y, arr.size_y()); EXPECT_EQ(ARRAY_SIZE_Z, arr.size_z()); EXPECT_EQ(ARRAY_SIZE_X * ARRAY_SIZE_Y * ARRAY_SIZE_Z, arr.size()); size_t newLenX = ARRAY_SIZE_X + 1; size_t newLenY = ARRAY_SIZE_Y - 2; size_t newLenZ = ARRAY_SIZE_Z + 5; arr.resize(newLenX, newLenY, newLenZ); EXPECT_EQ(newLenX, arr.size_x()); EXPECT_EQ(newLenY, arr.size_y()); EXPECT_EQ(newLenZ, arr.size_z()); EXPECT_EQ(newLenX * newLenY * newLenZ, arr.size()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_getIndexWithParentheses_then_refReturned) { size_t i = 1, j = 1, k = 1; arr(i, j, k) = VAL; EXPECT_EQ(VAL, arr(i, j, k)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_indexWithBracketsAlongsideParentheses_then_indexedProperly) { size_t i = 1, j = 1, k = 1; size_t absIndex = k * arr.size_x() * arr.size_y() + j * arr.size_x() + i; arr[absIndex] = VAL; EXPECT_EQ(VAL, arr(i, j, k)); arr(i, j, k) /= VAL; EXPECT_EQ(1, arr[absIndex]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, given_constCompressedArray_when_getIndexWithBrackets_then_valReturned) { size_t i = 1; arr[i] = VAL; const array3 arrConst = arr; EXPECT_EQ(VAL, arrConst[i]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, given_constCompressedArray_when_getIndexWithParentheses_then_valReturned) { size_t i = 1, j = 1, k = 1; size_t absIndex = k * arr.size_x() * arr.size_y() + j * arr.size_x() + i; arr[absIndex] = VAL; const array3 arrConst = arr; EXPECT_EQ(VAL, arrConst(i, j, k)); } zfp-1.0.1/tests/array/array/testArray3ViewsBase.cpp000066400000000000000000000344341453723256400223070ustar00rootroot00000000000000/* preview */ /* this also tests const_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_previewFullConstructor3D_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); EXPECT_EQ(viewLenX * viewLenY * viewLenZ, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); EXPECT_EQ(offsetZ, v.global_z(0)); } /* const_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_constView_when_sizeXYZ_then_viewXYZLenReturned) { ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_constView_when_accessorParens_then_correctEntriesReturned) { ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); for (size_t k = 0; k < viewLenZ; k++) { for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { size_t offset = (offsetZ + k)*arr.size_x()*arr.size_y() + (offsetY + j)*arr.size_x() + offsetX + i; EXPECT_EQ(arr[offset], v(i, j, k)); } } } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_constViewFullConstructor_then_isShallowCopyOfCompressedArray) { ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); /* indices of view and arr */ size_t vIX = 2; size_t aIX = v.global_x(vIX); size_t vIY = 2; size_t aIY = v.global_y(vIY); size_t vIZ = 1; size_t aIZ = v.global_z(vIZ); SCALAR oldVal = arr(aIX, aIY, aIZ); EXPECT_EQ(oldVal, v(vIX, vIY, vIZ)); arr(aIX, aIY, aIZ) += 1; SCALAR newVal = arr(aIX, aIY, aIZ); EXPECT_NE(oldVal, newVal); EXPECT_EQ(newVal, v(vIX, vIY, vIZ)); } /* view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_viewFullConstructor_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); EXPECT_EQ(viewLenX * viewLenY * viewLenZ, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); EXPECT_EQ(offsetZ, v.global_z(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_viewFullConstructor_then_isShallowCopyOfCompressedArray) { ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); /* indices of view and arr */ size_t vIX = 2; size_t aIX = v.global_x(vIX); size_t vIY = 2; size_t aIY = v.global_y(vIY); size_t vIZ = 1; size_t aIZ = v.global_z(vIZ); SCALAR oldVal = arr(aIX, aIY, aIZ); EXPECT_EQ(oldVal, v(vIX, vIY, vIZ)); arr(aIX, aIY, aIZ) += 1; SCALAR newVal = arr(aIX, aIY, aIZ); EXPECT_NE(oldVal, newVal); EXPECT_EQ(newVal, v(vIX, vIY, vIZ)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_view_when_setEntryWithParens_then_originalArrayUpdated) { ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); size_t i = 1, j = 2, k = 1; SCALAR val = 3.14; EXPECT_NE(val, arr(offsetX + i, offsetY + j, offsetZ + k)); v(i, j, k) = val; EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + k), v(i, j, k)); } /* flat_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_flatViewFullConstructor_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); EXPECT_EQ(viewLenX * viewLenY * viewLenZ, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); EXPECT_EQ(offsetZ, v.global_z(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_flatViewFullConstructor_then_isShallowCopyOfCompressedArray) { ZFP_ARRAY_TYPE::flat_view v(&arr, 1, 1, 1, 1, 1, 1); /* indices of view and arr */ size_t vIX = 2; size_t aIX = v.global_x(vIX); size_t vIY = 2; size_t aIY = v.global_y(vIY); size_t vIZ = 1; size_t aIZ = v.global_z(vIZ); SCALAR oldVal = arr(aIX, aIY, aIZ); EXPECT_EQ(oldVal, v(vIX, vIY, vIZ)); arr(aIX, aIY, aIZ) += 1; SCALAR newVal = arr(aIX, aIY, aIZ); EXPECT_NE(oldVal, newVal); EXPECT_EQ(newVal, v(vIX, vIY, vIZ)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_flatView_when_index_then_returnsFlatIndex) { ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); size_t i = 2, j = 1, k = 2; EXPECT_EQ(k*viewLenX*viewLenY + j*viewLenX + i, v.index(i, j, k)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_flatView_when_ijk_then_returnsUnflatIndices) { ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); size_t i = 2, j = 1, k = 2; size_t flatIndex = v.index(i, j, k); size_t vI, vJ, vK; v.ijk(vI, vJ, vK, flatIndex); EXPECT_EQ(i, vI); EXPECT_EQ(j, vJ); EXPECT_EQ(k, vK); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_flatView_when_bracketAccessor_then_returnsValAtFlattenedIndex) { ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); size_t i = 2, j = 1, k = 2; size_t arrOffset = (offsetZ + k)*arr.size_x()*arr.size_y() + (offsetY + j)*arr.size_x() + (offsetX + i); EXPECT_EQ(arr[arrOffset], v[v.index(i, j, k)]); } /* nested_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_nestedViewFullConstructor3D_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); EXPECT_EQ(viewLenX * viewLenY * viewLenZ, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); EXPECT_EQ(offsetZ, v.global_z(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView_when_parensAccessor_then_returnsValue) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); /* indices for view and array */ size_t vI = 1; size_t vJ = 2; size_t vK = 1; size_t aI = offsetX + vI; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; arr(aI, aJ, aK) = 5.5; EXPECT_EQ(arr(aI, aJ, aK), v(vI, vJ, vK)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView_when_parensMutator_then_setsValue) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); /* indices for view and array */ size_t vI = 1; size_t vJ = 2; size_t vK = 1; size_t aI = offsetX + vI; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; SCALAR val = 5.5; v(vI, vJ, vK) = val; EXPECT_EQ(val, arr(aI, aJ, aK)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView_when_bracketIndex_then_returnsSliceFromView) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); /* test slice length */ EXPECT_EQ(viewLenX, v[0].size_x()); EXPECT_EQ(viewLenY, v[0].size_y()); } /* nested_view2 */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView2_when_parensAccessor_then_returnsValue) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); /* indices for view and array */ size_t vI = 1; size_t vJ = 2; size_t vK = 1; size_t aI = offsetX + vI; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; arr(aI, aJ, aK) = 5.5; EXPECT_EQ(arr(aI, aJ, aK), v[vK](vI, vJ)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView2_when_parensMutator_then_setsValue) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); /* indices for view and array */ size_t vI = 1; size_t vJ = 2; size_t vK = 1; size_t aI = offsetX + vI; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; SCALAR val = 5.5; v[vK](vI, vJ) = val; EXPECT_EQ(val, arr(aI, aJ, aK)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView2_when_bracketIndex_then_returnsSliceFromView) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); /* test slice length */ EXPECT_EQ(viewLenX, v[0][0].size_x()); } /* nested_view1 */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView1_when_bracketAccessor_then_returnsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); /* indices for view and array */ size_t vJ = 2; size_t vK = 1; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; /* initialize values into row that will become slice */ for (size_t aI = 0; aI < arr.size_x(); aI++) { arr(aI, aJ, aK) = (SCALAR)aI; } EXPECT_EQ(viewLenX, v[vK][vJ].size_x()); for (size_t vI = 0; vI < viewLenX; vI++) { EXPECT_EQ(arr(offsetX + vI, aJ, aK), v[vK][vJ][vI]); } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView1_when_parensAccessor_then_returnsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); /* indices for view and array */ size_t vJ = 2; size_t vK = 1; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; /* initialize values into row that will become slice */ for (size_t aI = 0; aI < arr.size_x(); aI++) { arr(aI, aJ, aK) = (SCALAR)aI; } EXPECT_EQ(viewLenX, v[vK][vJ].size_x()); for (size_t vI = 0; vI < viewLenX; vI++) { EXPECT_EQ(arr(offsetX + vI, aJ, aK), v[vK][vJ](vI)); } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView1_when_bracketMutator_then_setsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); /* indices for view and array */ size_t vJ = 2; size_t vK = 1; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; /* initialize values into slice */ for (size_t vI = 0; vI < v[vK][vJ].size_x(); vI++) { v[vK][vJ][vI] = (SCALAR)vI; } for (size_t vI = 0; vI < v[vK][vJ].size_x(); vI++) { EXPECT_EQ(v[vK][vJ][vI], arr(offsetX + vI, aJ, aK)); } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView1_when_parensMutator_then_setsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); /* indices for view and array */ size_t vJ = 2; size_t vK = 1; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; /* initialize values into slice */ for (size_t vI = 0; vI < v[vK][vJ].size_x(); vI++) { v[vK][vJ](vI) = (SCALAR)vI; } for (size_t vI = 0; vI < v[vK][vJ].size_x(); vI++) { EXPECT_EQ(v[vK][vJ][vI], arr(offsetX + vI, aJ, aK)); } } /* private_const_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_privateConstViewFullConstructor_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); EXPECT_EQ(viewLenX * viewLenY * viewLenZ, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); EXPECT_EQ(offsetZ, v.global_z(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_privateConstView_when_sizeXYZ_then_viewLenReturned) { ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); } /* private_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_privateViewFullConstructor_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::private_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); EXPECT_EQ(viewLenX * viewLenY * viewLenZ, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); EXPECT_EQ(offsetZ, v.global_z(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_privateView_when_partitionWithLimitOnCount_then_setsUniqueBlockBoundsAlongLongestDimension) { const size_t count = 3; size_t prevOffsetY, prevLenY, offsetY, lenY; /* partition such that each gets at least 1 block */ const size_t blockSideLen = 4; size_t arrBlockCountX = (arr.size_x() + (blockSideLen - 1)) / blockSideLen; size_t arrBlockCountY = (arr.size_y() + (blockSideLen - 1)) / blockSideLen; size_t arrBlockCountZ = (arr.size_z() + (blockSideLen - 1)) / blockSideLen; /* ensure partition will happen along Y */ EXPECT_GT(arrBlockCountY, std::max(arrBlockCountX, arrBlockCountZ)); EXPECT_LE(count, arrBlockCountY); /* construct view */ ZFP_ARRAY_TYPE::private_view v(&arr); /* get original dimensions that should stay constant */ size_t offsetX = v.global_x(0); size_t offsetZ = v.global_z(0); size_t lenX = v.size_x(); size_t lenZ = v.size_z(); /* base case */ v.partition(0, count); /* along Y, expect to start at first index, zero */ prevOffsetY = v.global_y(0); EXPECT_EQ(0, prevOffsetY); /* expect to have at least 1 block */ prevLenY = v.size_y(); EXPECT_LE(blockSideLen, prevLenY); /* along X and Z, expect no changes */ EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetZ, v.global_z(0)); EXPECT_EQ(lenX, v.size_x()); EXPECT_EQ(lenZ, v.size_z()); /* successive cases are compared to previous */ for (size_t i = 1; i < count - 1; i++) { ZFP_ARRAY_TYPE::private_view v2(&arr); v2.partition(i, count); /* along Y, expect blocks continue where previous left off */ offsetY = v2.global_y(0); EXPECT_EQ(prevOffsetY + prevLenY, offsetY); /* expect to have at least 1 block */ lenY = v2.size_y(); EXPECT_LE(blockSideLen, lenY); /* along X and Z, expect no changes */ EXPECT_EQ(offsetX, v2.global_x(0)); EXPECT_EQ(offsetZ, v2.global_z(0)); EXPECT_EQ(lenX, v2.size_x()); EXPECT_EQ(lenZ, v2.size_z()); prevOffsetY = offsetY; prevLenY = lenY; } /* last partition case */ ZFP_ARRAY_TYPE::private_view v3(&arr); v3.partition(count - 1, count); /* along Y, expect blocks continue where previous left off */ offsetY = v3.global_y(0); EXPECT_EQ(prevOffsetY + prevLenY, offsetY); /* last partition could hold a partial block */ lenY = v3.size_y(); EXPECT_LT(0u, lenY); /* expect to end on final index */ EXPECT_EQ(arr.size_y(), offsetY + lenY); /* along X and Z, expect no changes */ EXPECT_EQ(offsetX, v3.global_x(0)); EXPECT_EQ(offsetZ, v3.global_z(0)); EXPECT_EQ(lenX, v3.size_x()); EXPECT_EQ(lenZ, v3.size_z()); } zfp-1.0.1/tests/array/array/testArray3d.cpp000066400000000000000000000020531453723256400206320ustar00rootroot00000000000000#include "zfp/array1.hpp" #include "zfp/array2.hpp" #include "zfp/array3.hpp" #include "zfp/factory.hpp" #include "zfp/array4.hpp" using namespace zfp; extern "C" { #include "constants/3dDouble.h" } #include "gtest/gtest.h" #include "utils/gtestDoubleEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class Array3dTestEnv : public ArrayDoubleTestEnv { public: virtual int getDims() { return 3; } }; Array3dTestEnv* const testEnv = new Array3dTestEnv; class Array3dTest : public ArrayNdTestFixture {}; #define TEST_FIXTURE Array3dTest #define ZFP_ARRAY_TYPE array3d #define ZFP_ARRAY_TYPE_WRONG_SCALAR array3f #define ZFP_ARRAY_TYPE_WRONG_DIM array4d #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM array4f #define ZFP_ARRAY_NOT_INCLUDED_TYPE array2d #define UINT uint64 #define SCALAR double #define DIMS 3 #include "testArrayBase.cpp" #include "testArray3Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/array/testArray3dIters.cpp000066400000000000000000000003671453723256400216470ustar00rootroot00000000000000#include "zfp/array3.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array3dTest #define ARRAY_DIMS_SCALAR_TEST_ITERS Array3dTestIters #include "utils/gtest3dTest.h" #include "testArrayItersBase.cpp" #include "testArray3ItersBase.cpp" zfp-1.0.1/tests/array/array/testArray3dPtrs.cpp000066400000000000000000000003631453723256400215050ustar00rootroot00000000000000#include "zfp/array3.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array3dTest #define ARRAY_DIMS_SCALAR_TEST_PTRS Array3dTestPtrs #include "utils/gtest3dTest.h" #include "testArrayPtrsBase.cpp" #include "testArray3PtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray3dRefs.cpp000066400000000000000000000004371453723256400214560ustar00rootroot00000000000000#include "zfp/array3.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array3dTest #define ARRAY_DIMS_SCALAR_TEST_REFS Array3dTestRefs #include "utils/gtest3dTest.h" #include "testArrayRefsBase.cpp" #include "testArray3RefsBase.cpp" zfp-1.0.1/tests/array/array/testArray3dViewIters.cpp000066400000000000000000000005221453723256400224730ustar00rootroot00000000000000#include "zfp/array3.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array3dTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_ITERS Array3dTestViewIters #include "utils/gtest3dTest.h" #define ZFP_ARRAY_TYPE array3d #define SCALAR double #define DIMS 3 #include "testArrayViewItersBase.cpp" zfp-1.0.1/tests/array/array/testArray3dViewPtrs.cpp000066400000000000000000000005171453723256400223410ustar00rootroot00000000000000#include "zfp/array3.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array3dTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_PTRS Array3dTestViewPtrs #include "utils/gtest3dTest.h" #define ZFP_ARRAY_TYPE array3d #define SCALAR double #define DIMS 3 #include "testArrayViewPtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray3dViews.cpp000066400000000000000000000005501453723256400216500ustar00rootroot00000000000000#include "zfp/array3.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array3dTest #define ARRAY_DIMS_SCALAR_TEST_VIEWS Array3dTestViews #include "utils/gtest3dTest.h" #define ZFP_ARRAY_TYPE array3d #define SCALAR double #define DIMS 3 #include "testArrayViewsBase.cpp" #include "testArray3ViewsBase.cpp" zfp-1.0.1/tests/array/array/testArray3f.cpp000066400000000000000000000020471453723256400206370ustar00rootroot00000000000000#include "zfp/array1.hpp" #include "zfp/array2.hpp" #include "zfp/array3.hpp" #include "zfp/factory.hpp" #include "zfp/array4.hpp" using namespace zfp; extern "C" { #include "constants/3dFloat.h" } #include "gtest/gtest.h" #include "utils/gtestFloatEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class Array3fTestEnv : public ArrayFloatTestEnv { public: virtual int getDims() { return 3; } }; Array3fTestEnv* const testEnv = new Array3fTestEnv; class Array3fTest : public ArrayNdTestFixture {}; #define TEST_FIXTURE Array3fTest #define ZFP_ARRAY_TYPE array3f #define ZFP_ARRAY_TYPE_WRONG_SCALAR array3d #define ZFP_ARRAY_TYPE_WRONG_DIM array4f #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM array4d #define ZFP_ARRAY_NOT_INCLUDED_TYPE array2f #define UINT uint32 #define SCALAR float #define DIMS 3 #include "testArrayBase.cpp" #include "testArray3Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/array/testArray3fIters.cpp000066400000000000000000000003671453723256400216510ustar00rootroot00000000000000#include "zfp/array3.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array3fTest #define ARRAY_DIMS_SCALAR_TEST_ITERS Array3fTestIters #include "utils/gtest3fTest.h" #include "testArrayItersBase.cpp" #include "testArray3ItersBase.cpp" zfp-1.0.1/tests/array/array/testArray3fPtrs.cpp000066400000000000000000000003631453723256400215070ustar00rootroot00000000000000#include "zfp/array3.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array3fTest #define ARRAY_DIMS_SCALAR_TEST_PTRS Array3fTestPtrs #include "utils/gtest3fTest.h" #include "testArrayPtrsBase.cpp" #include "testArray3PtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray3fRefs.cpp000066400000000000000000000004371453723256400214600ustar00rootroot00000000000000#include "zfp/array3.hpp" using namespace zfp; extern "C" { #include "utils/rand32.h" } #define ARRAY_DIMS_SCALAR_TEST Array3fTest #define ARRAY_DIMS_SCALAR_TEST_REFS Array3fTestRefs #include "utils/gtest3fTest.h" #include "testArrayRefsBase.cpp" #include "testArray3RefsBase.cpp" zfp-1.0.1/tests/array/array/testArray3fViewIters.cpp000066400000000000000000000005211453723256400224740ustar00rootroot00000000000000#include "zfp/array3.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array3fTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_ITERS Array3fTestViewIters #include "utils/gtest3fTest.h" #define ZFP_ARRAY_TYPE array3f #define SCALAR float #define DIMS 3 #include "testArrayViewItersBase.cpp" zfp-1.0.1/tests/array/array/testArray3fViewPtrs.cpp000066400000000000000000000005161453723256400223420ustar00rootroot00000000000000#include "zfp/array3.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array3fTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_PTRS Array3fTestViewPtrs #include "utils/gtest3fTest.h" #define ZFP_ARRAY_TYPE array3f #define SCALAR float #define DIMS 3 #include "testArrayViewPtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray3fViews.cpp000066400000000000000000000005471453723256400216600ustar00rootroot00000000000000#include "zfp/array3.hpp" using namespace zfp; extern "C" { #include "utils/rand32.h" } #define ARRAY_DIMS_SCALAR_TEST Array3fTest #define ARRAY_DIMS_SCALAR_TEST_VIEWS Array3fTestViews #include "utils/gtest3fTest.h" #define ZFP_ARRAY_TYPE array3f #define SCALAR float #define DIMS 3 #include "testArrayViewsBase.cpp" #include "testArray3ViewsBase.cpp" zfp-1.0.1/tests/array/array/testArray4Base.cpp000066400000000000000000000555021453723256400212710ustar00rootroot00000000000000/* TODO: figure out templated tests (TYPED_TEST) */ /* const_view */ TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromConstView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::const_view v(&arr, 1, 1, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromConstView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); EXPECT_EQ(v.size_z(), arr2.size_z()); EXPECT_EQ(v.size_w(), arr2.size_w()); } TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromConstView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t l = 0; l < viewLenW; l++) { for (size_t k = 0; k < viewLenZ; k++) { for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + k, offsetW + l), arr2(i, j, k, l)); } } } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0, offsetZ + 0, offsetW + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY, offsetZ, offsetW), arr2(0, 0, 0, 0)); } /* view */ TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::view v(&arr, 1, 1, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); EXPECT_EQ(v.size_z(), arr2.size_z()); EXPECT_EQ(v.size_w(), arr2.size_w()); } TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t l = 0; l < viewLenW; l++) { for (size_t k = 0; k < viewLenZ; k++) { for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + k, offsetW + l), arr2(i, j, k, l)); } } } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0, offsetZ + 0, offsetW + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY, offsetZ, offsetW), arr2(0, 0, 0, 0)); } /* flat_view */ TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromFlatView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::flat_view v(&arr, 1, 1, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromFlatView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); EXPECT_EQ(v.size_z(), arr2.size_z()); EXPECT_EQ(v.size_w(), arr2.size_w()); } TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromFlatView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t l = 0; l < viewLenW; l++) { for (size_t k = 0; k < viewLenZ; k++) { for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + k, offsetW + l), arr2(i, j, k, l)); } } } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0, offsetZ + 0, offsetW + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY, offsetZ, offsetW), arr2(0, 0, 0, 0)); } /* nested_view */ TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromNestedView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::nested_view v(&arr, 1, 1, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); /* rate may be increased when moving to lower dimension compressed array */ EXPECT_LE(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromNestedView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); EXPECT_EQ(v.size_z(), arr2.size_z()); EXPECT_EQ(v.size_w(), arr2.size_w()); } TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromNestedView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t l = 0; l < viewLenW; l++) { for (size_t k = 0; k < viewLenZ; k++) { for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + k, offsetW + l), arr2(i, j, k, l)); } } } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0, offsetZ + 0, offsetW + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY, offsetZ, offsetW), arr2(0, 0, 0, 0)); } /* nested_view3 (unique) */ TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromNestedView3_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::nested_view v(&arr, 1, 1, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE::nested_view3 v2 = v[0]; array3 arr2(v2); /* rate may be increased when moving to lower dimension compressed array */ EXPECT_LE(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromNestedView3_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE::nested_view3 v2 = v[0]; array3 arr2(v2); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); EXPECT_EQ(v.size_z(), arr2.size_z()); } TEST_P(TEST_FIXTURE, when_construct3dCompressedArrayFromNestedView3_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); size_t w = 1; ZFP_ARRAY_TYPE::nested_view3 v2 = v[w]; array3 arr2(v2); /* verify array entries */ for (size_t k = 0; k < viewLenZ; k++) { for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + k, offsetW + w), arr2(i, j, k)); } } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0, offsetZ + 0, offsetW + w) = 999.; EXPECT_NE(arr(offsetX, offsetY, offsetZ, offsetW + w), arr2(0, 0, 0)); } /* nested_view2 (unique) */ TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromNestedView2_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::nested_view v(&arr, 1, 1, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE::nested_view2 v2 = v[0][0]; array2 arr2(v2); /* rate may be increased when moving to lower dimension compressed array */ EXPECT_LE(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromNestedView2_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE::nested_view2 v2 = v[0][0]; array2 arr2(v2); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); } TEST_P(TEST_FIXTURE, when_construct2dCompressedArrayFromNestedView2_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); size_t z = 1; size_t w = 0; ZFP_ARRAY_TYPE::nested_view2 v2 = v[w][z]; array2 arr2(v2); /* verify array entries */ for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + z, offsetW + w), arr2(i, j)); } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0, offsetZ + z, offsetW + w) = 999.; EXPECT_NE(arr(offsetX, offsetY, offsetZ + z, offsetW + w), arr2(0, 0)); } /* nested_view1 (unique) */ TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromNestedView1_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::nested_view v(&arr, 1, 1, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE::nested_view1 v2 = v[0][0][0]; array1 arr2(v2); /* rate may be increased when moving to lower dimension compressed array */ EXPECT_LE(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromNestedView1_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE::nested_view1 v2 = v[0][0][0]; array1 arr2(v2); EXPECT_EQ(v.size_x(), arr2.size_x()); } TEST_P(TEST_FIXTURE, when_construct1dCompressedArrayFromNestedView1_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); size_t y = 2; size_t z = 1; size_t w = 0; ZFP_ARRAY_TYPE::nested_view1 v2 = v[w][z][y]; array1 arr2(v2); /* verify array entries */ for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + y, offsetZ + z, offsetW + w), arr2(i)); } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + y, offsetZ + z, offsetW + w) = 999.; EXPECT_NE(arr(offsetX, offsetY + y, offsetZ + z, offsetW + w), arr2(0)); } /* private_const_view */ TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromPrivateConstView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::private_const_view v(&arr, 1, 1, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromPrivateConstView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); EXPECT_EQ(v.size_z(), arr2.size_z()); EXPECT_EQ(v.size_w(), arr2.size_w()); } TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromPrivateConstView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t l = 0; l < viewLenW; l++) { for (size_t k = 0; k < viewLenZ; k++) { for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + k, offsetW + l), arr2(i, j, k, l)); } } } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0, offsetZ + 0, offsetW + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY, offsetZ, offsetW), arr2(0, 0, 0, 0)); } /* private_view */ TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromPrivateView_then_rateConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); ZFP_ARRAY_TYPE::private_view v(&arr, 1, 1, 1, 1, 1, 1, 1, 1); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(arr.rate(), arr2.rate()); } TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromPrivateView_then_sizeConserved) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE arr2(v); EXPECT_EQ(v.size_x(), arr2.size_x()); EXPECT_EQ(v.size_y(), arr2.size_y()); EXPECT_EQ(v.size_z(), arr2.size_z()); EXPECT_EQ(v.size_w(), arr2.size_w()); } TEST_P(TEST_FIXTURE, when_construct4dCompressedArrayFromPrivateView_then_performsDeepCopy) { ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); size_t offsetX = 5; size_t viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); size_t offsetY = 1; size_t viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); size_t offsetZ = 0; size_t viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); size_t offsetW = 1; size_t viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); /* create view and construct from it */ ZFP_ARRAY_TYPE::private_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE arr2(v); /* verify array entries */ for (size_t l = 0; l < viewLenW; l++) { for (size_t k = 0; k < viewLenZ; k++) { for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + k, offsetW + l), arr2(i, j, k, l)); } } } } /* verify it's a deep copy */ arr(offsetX + 0, offsetY + 0, offsetZ + 0, offsetW + 0) = 999.; EXPECT_NE(arr(offsetX, offsetY, offsetZ, offsetW), arr2(0, 0, 0, 0)); } zfp-1.0.1/tests/array/array/testArray4ItersBase.cpp000066400000000000000000000101771453723256400222770ustar00rootroot00000000000000TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_partialBlocks_when_incrementIterator_then_positionTraversesCorrectly) { // force partial block traversal EXPECT_NE(0u, arr.size_x() % BLOCK_SIDE_LEN); EXPECT_NE(0u, arr.size_y() % BLOCK_SIDE_LEN); EXPECT_NE(0u, arr.size_z() % BLOCK_SIDE_LEN); EXPECT_NE(0u, arr.size_w() % BLOCK_SIDE_LEN); size_t totalBlocksX = (arr.size_x() + 3) / 4; size_t totalBlocksY = (arr.size_y() + 3) / 4; size_t totalBlocksZ = (arr.size_z() + 3) / 4; size_t totalBlocksW = (arr.size_w() + 3) / 4; size_t totalBlocks = totalBlocksX * totalBlocksY * totalBlocksZ * totalBlocksW; iter = arr.begin(); for (size_t count = 0; count < totalBlocks; count++) { // determine if block is complete or partial size_t distanceFromEnd = arr.size_x() - iter.i(); size_t blockLenX = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; distanceFromEnd = arr.size_y() - iter.j(); size_t blockLenY = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; distanceFromEnd = arr.size_z() - iter.k(); size_t blockLenZ = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; distanceFromEnd = arr.size_w() - iter.l(); size_t blockLenW = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; // ensure entries lie in same block size_t blockStartIndexI = iter.i(); size_t blockStartIndexJ = iter.j(); size_t blockStartIndexK = iter.k(); size_t blockStartIndexL = iter.l(); for (size_t l = 0; l < blockLenW; l++) { for (size_t k = 0; k < blockLenZ; k++) { for (size_t j = 0; j < blockLenY; j++) { for (size_t i = 0; i < blockLenX; i++) { EXPECT_EQ(blockStartIndexI + i, iter.i()); EXPECT_EQ(blockStartIndexJ + j, iter.j()); EXPECT_EQ(blockStartIndexK + k, iter.k()); EXPECT_EQ(blockStartIndexL + l, iter.l()); iter++; } } } } } // EXPECT_EQ(arr.end(), iter); // triggers googletest issue #742 EXPECT_TRUE(arr.end() == iter); } // const iterators TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_partialBlocks_when_incrementConstIterator_then_positionTraversesCorrectly) { // force partial block traversal EXPECT_NE(0u, arr.size_x() % BLOCK_SIDE_LEN); EXPECT_NE(0u, arr.size_y() % BLOCK_SIDE_LEN); EXPECT_NE(0u, arr.size_z() % BLOCK_SIDE_LEN); EXPECT_NE(0u, arr.size_w() % BLOCK_SIDE_LEN); size_t totalBlocksX = (arr.size_x() + 3) / 4; size_t totalBlocksY = (arr.size_y() + 3) / 4; size_t totalBlocksZ = (arr.size_z() + 3) / 4; size_t totalBlocksW = (arr.size_w() + 3) / 4; size_t totalBlocks = totalBlocksX * totalBlocksY * totalBlocksZ * totalBlocksW; citer = arr.cbegin(); for (size_t count = 0; count < totalBlocks; count++) { // determine if block is complete or partial size_t distanceFromEnd = arr.size_x() - citer.i(); size_t blockLenX = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; distanceFromEnd = arr.size_y() - citer.j(); size_t blockLenY = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; distanceFromEnd = arr.size_z() - citer.k(); size_t blockLenZ = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; distanceFromEnd = arr.size_w() - citer.l(); size_t blockLenW = distanceFromEnd < BLOCK_SIDE_LEN ? distanceFromEnd : BLOCK_SIDE_LEN; // ensure entries lie in same block size_t blockStartIndexI = citer.i(); size_t blockStartIndexJ = citer.j(); size_t blockStartIndexK = citer.k(); size_t blockStartIndexL = citer.l(); for (size_t l = 0; l < blockLenW; l++) { for (size_t k = 0; k < blockLenZ; k++) { for (size_t j = 0; j < blockLenY; j++) { for (size_t i = 0; i < blockLenX; i++) { EXPECT_EQ(blockStartIndexI + i, citer.i()); EXPECT_EQ(blockStartIndexJ + j, citer.j()); EXPECT_EQ(blockStartIndexK + k, citer.k()); EXPECT_EQ(blockStartIndexL + l, citer.l()); citer++; } } } } } // EXPECT_EQ(arr.cend(), citer); // triggers googletest issue #742 EXPECT_TRUE(arr.cend() == citer); } zfp-1.0.1/tests/array/array/testArray4PtrsBase.cpp000066400000000000000000000036101453723256400221330ustar00rootroot00000000000000TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_pointerAtXBoundary_when_increment_then_pointerPositionTraversesCorrectly) { size_t i = arr.size_x() - 1; size_t j = 2; size_t k = 4; size_t l = 3; arr(0, j+1, k, l) = VAL; ptr = &arr(i, j, k, l); EXPECT_EQ(VAL, *++ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_pointerAtXBoundary_when_decrement_then_pointerPositionTraversesCorrectly) { size_t i = 0; size_t j = 2; size_t k = 3; size_t l = 1; size_t iNext = arr.size_x() - 1; arr(iNext, j-1, k, l) = VAL; ptr = &arr(i, j, k, l); EXPECT_EQ(VAL, *--ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_pointerAtXYBoundary_when_increment_then_pointerPositionTraversesCorrectly) { size_t i = arr.size_x() - 1; size_t j = arr.size_y() - 1; size_t k = 4; size_t l = 3; arr(0, 0, k+1, l) = VAL; ptr = &arr(i, j, k, l); EXPECT_EQ(VAL, *++ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_pointerAtXYBoundary_when_decrement_then_pointerPositionTraversesCorrectly) { size_t i = 0; size_t j = 0; size_t k = 3; size_t l = 1; size_t iNext = arr.size_x() - 1; size_t jNext = arr.size_y() - 1; arr(iNext, jNext, k-1, l) = VAL; ptr = &arr(i, j, k, l); EXPECT_EQ(VAL, *--ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_pointerAtXYZBoundary_when_increment_then_pointerPositionTraversesCorrectly) { size_t i = arr.size_x() - 1; size_t j = arr.size_y() - 1; size_t k = arr.size_z() - 1; size_t l = 3; arr(0, 0, 0, l+1) = VAL; ptr = &arr(i, j, k, l); EXPECT_EQ(VAL, *++ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_pointerAtXYZBoundary_when_decrement_then_pointerPositionTraversesCorrectly) { size_t i = 0; size_t j = 0; size_t k = 0; size_t l = 1; size_t iNext = arr.size_x() - 1; size_t jNext = arr.size_y() - 1; size_t kNext = arr.size_z() - 1; arr(iNext, jNext, kNext, l-1) = VAL; ptr = &arr(i, j, k, l); EXPECT_EQ(VAL, *--ptr); } zfp-1.0.1/tests/array/array/testArray4RefsBase.cpp000066400000000000000000000035461453723256400221120ustar00rootroot00000000000000TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_resize_then_sizeChanges) { EXPECT_EQ(ARRAY_SIZE_X, arr.size_x()); EXPECT_EQ(ARRAY_SIZE_Y, arr.size_y()); EXPECT_EQ(ARRAY_SIZE_Z, arr.size_z()); EXPECT_EQ(ARRAY_SIZE_W, arr.size_w()); EXPECT_EQ(ARRAY_SIZE_X * ARRAY_SIZE_Y * ARRAY_SIZE_Z * ARRAY_SIZE_W, arr.size()); size_t newLenX = ARRAY_SIZE_X + 1; size_t newLenY = ARRAY_SIZE_Y - 2; size_t newLenZ = ARRAY_SIZE_Z + 5; size_t newLenW = ARRAY_SIZE_W - 3; arr.resize(newLenX, newLenY, newLenZ, newLenW); EXPECT_EQ(newLenX, arr.size_x()); EXPECT_EQ(newLenY, arr.size_y()); EXPECT_EQ(newLenZ, arr.size_z()); EXPECT_EQ(newLenW, arr.size_w()); EXPECT_EQ(newLenX * newLenY * newLenZ * newLenW, arr.size()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_getIndexWithParentheses_then_refReturned) { size_t i = 1, j = 1, k = 1, l = 1; arr(i, j, k, l) = VAL; EXPECT_EQ(VAL, arr(i, j, k, l)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_indexWithBracketsAlongsideParentheses_then_indexedProperly) { size_t i = 1, j = 1, k = 1, l = 1; size_t absIndex = l * arr.size_x() * arr.size_y() * arr.size_z() + k * arr.size_x() * arr.size_y() + j * arr.size_x() + i; arr[absIndex] = VAL; EXPECT_EQ(VAL, arr(i, j, k, l)); arr(i, j, k, l) /= VAL; EXPECT_EQ(1, arr[absIndex]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, given_constCompressedArray_when_getIndexWithBrackets_then_valReturned) { size_t i = 1; arr[i] = VAL; const array4 arrConst = arr; EXPECT_EQ(VAL, arrConst[i]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, given_constCompressedArray_when_getIndexWithParentheses_then_valReturned) { size_t i = 1, j = 1, k = 1, l = 1; size_t absIndex = l * arr.size_x() * arr.size_y() * arr.size_z() + k * arr.size_x() * arr.size_y() + j * arr.size_x() + i; arr[absIndex] = VAL; const array4 arrConst = arr; EXPECT_EQ(VAL, arrConst(i, j, k, l)); } zfp-1.0.1/tests/array/array/testArray4ViewsBase.cpp000066400000000000000000000473571453723256400223200ustar00rootroot00000000000000/* preview */ /* this also tests const_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_previewFullConstructor4D_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); EXPECT_EQ(viewLenX * viewLenY * viewLenZ * viewLenW, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); EXPECT_EQ(viewLenW, v.size_w()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); EXPECT_EQ(offsetZ, v.global_z(0)); EXPECT_EQ(offsetW, v.global_w(0)); } /* const_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_constView_when_sizeXYZ_then_viewXYZLenReturned) { ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_constView_when_accessorParens_then_correctEntriesReturned) { ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); for (size_t l = 0; l < viewLenW; l++) { for (size_t k = 0; k < viewLenZ; k++) { for (size_t j = 0; j < viewLenY; j++) { for (size_t i = 0; i < viewLenX; i++) { size_t offset = (offsetW + l)*arr.size_x()*arr.size_y()*arr.size_z() + (offsetZ + k)*arr.size_x()*arr.size_y() + (offsetY + j)*arr.size_x() + offsetX + i; EXPECT_EQ(arr[offset], v(i, j, k, l)); } } } } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_constViewFullConstructor_then_isShallowCopyOfCompressedArray) { ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* indices of view and arr */ size_t vIX = 2; size_t aIX = v.global_x(vIX); size_t vIY = 2; size_t aIY = v.global_y(vIY); size_t vIZ = 1; size_t aIZ = v.global_z(vIZ); size_t vIW = 1; size_t aIW = v.global_w(vIW); SCALAR oldVal = arr(aIX, aIY, aIZ, aIW); EXPECT_EQ(oldVal, v(vIX, vIY, vIZ, vIW)); arr(aIX, aIY, aIZ, aIW) += 1; SCALAR newVal = arr(aIX, aIY, aIZ, aIW); EXPECT_NE(oldVal, newVal); EXPECT_EQ(newVal, v(vIX, vIY, vIZ, vIW)); } /* view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_viewFullConstructor_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); EXPECT_EQ(viewLenX * viewLenY * viewLenZ * viewLenW, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); EXPECT_EQ(viewLenW, v.size_w()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); EXPECT_EQ(offsetZ, v.global_z(0)); EXPECT_EQ(offsetW, v.global_w(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_viewFullConstructor_then_isShallowCopyOfCompressedArray) { ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* indices of view and arr */ size_t vIX = 2; size_t aIX = v.global_x(vIX); size_t vIY = 2; size_t aIY = v.global_y(vIY); size_t vIZ = 1; size_t aIZ = v.global_z(vIZ); size_t vIW = 1; size_t aIW = v.global_w(vIW); SCALAR oldVal = arr(aIX, aIY, aIZ, aIW); EXPECT_EQ(oldVal, v(vIX, vIY, vIZ, vIW)); arr(aIX, aIY, aIZ, aIW) += 1; SCALAR newVal = arr(aIX, aIY, aIZ, aIW); EXPECT_NE(oldVal, newVal); EXPECT_EQ(newVal, v(vIX, vIY, vIZ, vIW)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_view_when_setEntryWithParens_then_originalArrayUpdated) { ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); size_t i = 1, j = 2, k = 1, l = 2; SCALAR val = 3.14; EXPECT_NE(val, arr(offsetX + i, offsetY + j, offsetZ + k, offsetW + l)); v(i, j, k, l) = val; EXPECT_EQ(arr(offsetX + i, offsetY + j, offsetZ + k, offsetW + l), v(i, j, k, l)); } /* flat_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_flatViewFullConstructor_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); EXPECT_EQ(viewLenX * viewLenY * viewLenZ * viewLenW, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); EXPECT_EQ(viewLenW, v.size_w()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); EXPECT_EQ(offsetZ, v.global_z(0)); EXPECT_EQ(offsetW, v.global_w(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_flatViewFullConstructor_then_isShallowCopyOfCompressedArray) { ZFP_ARRAY_TYPE::flat_view v(&arr, 1, 1, 1, 1, 1, 1, 1, 1); /* indices of view and arr */ size_t vIX = 2; size_t aIX = v.global_x(vIX); size_t vIY = 2; size_t aIY = v.global_y(vIY); size_t vIZ = 1; size_t aIZ = v.global_z(vIZ); size_t vIW = 1; size_t aIW = v.global_w(vIW); SCALAR oldVal = arr(aIX, aIY, aIZ, aIW); EXPECT_EQ(oldVal, v(vIX, vIY, vIZ, vIW)); arr(aIX, aIY, aIZ, aIW) += 1; SCALAR newVal = arr(aIX, aIY, aIZ, aIW); EXPECT_NE(oldVal, newVal); EXPECT_EQ(newVal, v(vIX, vIY, vIZ, vIW)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_flatView_when_index_then_returnsFlatIndex) { ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); size_t i = 2, j = 1, k = 1, l = 2; EXPECT_EQ(l*viewLenX*viewLenY*viewLenZ + k*viewLenX*viewLenY + j*viewLenX + i, v.index(i, j, k, l)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_flatView_when_ijkl_then_returnsUnflatIndices) { ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); size_t i = 2, j = 1, k = 1, l = 2; size_t flatIndex = v.index(i, j, k, l); size_t vI, vJ, vK, vL; v.ijkl(vI, vJ, vK, vL, flatIndex); EXPECT_EQ(i, vI); EXPECT_EQ(j, vJ); EXPECT_EQ(k, vK); EXPECT_EQ(l, vL); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_flatView_when_bracketAccessor_then_returnsValAtFlattenedIndex) { ZFP_ARRAY_TYPE::flat_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); size_t i = 2, j = 1, k = 1, l = 2; size_t arrOffset = (offsetW + l)*arr.size_x()*arr.size_y()*arr.size_z() + (offsetZ + k)*arr.size_x()*arr.size_y() + (offsetY + j)*arr.size_x() + (offsetX + i); EXPECT_EQ(arr[arrOffset], v[v.index(i, j, k, l)]); } /* nested_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_nestedViewFullConstructor4D_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); EXPECT_EQ(viewLenX * viewLenY * viewLenZ * viewLenW, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); EXPECT_EQ(viewLenW, v.size_w()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); EXPECT_EQ(offsetZ, v.global_z(0)); EXPECT_EQ(offsetW, v.global_w(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView_when_parensAccessor_then_returnsValue) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* indices for view and array */ size_t vI = 1; size_t vJ = 2; size_t vK = 1; size_t vL = 2; size_t aI = offsetX + vI; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; size_t aL = offsetW + vL; arr(aI, aJ, aK, aL) = 5.5; EXPECT_EQ(arr(aI, aJ, aK, aL), v(vI, vJ, vK, vL)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView_when_parensMutator_then_setsValue) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* indices for view and array */ size_t vI = 1; size_t vJ = 2; size_t vK = 1; size_t vL = 2; size_t aI = offsetX + vI; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; size_t aL = offsetW + vL; SCALAR val = 5.5; v(vI, vJ, vK, vL) = val; EXPECT_EQ(val, arr(aI, aJ, aK, aL)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView_when_bracketIndex_then_returnsSliceFromView) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* test slice length */ EXPECT_EQ(viewLenX, v[0].size_x()); EXPECT_EQ(viewLenY, v[0].size_y()); EXPECT_EQ(viewLenZ, v[0].size_z()); } /* nested_view3 */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView3_when_parensAccessor_then_returnsValue) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* indices for view and array */ size_t vI = 1; size_t vJ = 2; size_t vK = 1; size_t vL = 2; size_t aI = offsetX + vI; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; size_t aL = offsetW + vL; arr(aI, aJ, aK, aL) = 5.5; EXPECT_EQ(arr(aI, aJ, aK, aL), v[vL](vI, vJ, vK)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView3_when_parensMutator_then_setsValue) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* indices for view and array */ size_t vI = 1; size_t vJ = 2; size_t vK = 1; size_t vL = 2; size_t aI = offsetX + vI; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; size_t aL = offsetW + vL; SCALAR val = 5.5; v[vL](vI, vJ, vK) = val; EXPECT_EQ(val, arr(aI, aJ, aK, aL)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView3_when_bracketIndex_then_returnsSliceFromView) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* test slice length */ EXPECT_EQ(viewLenX, v[0][0][0].size_x()); } /* nested_view2 */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView2_when_bracketAccessor_then_returnsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* indices for view and array */ size_t vK = 1; size_t vL = 2; size_t aK = offsetZ + vK; size_t aL = offsetW + vL; /* initialize values into row that will become slice */ for (size_t aJ = 0; aJ < arr.size_y(); aJ++) { for (size_t aI = 0; aI < arr.size_x(); aI++) { arr(aI, aJ, aK, aL) = (SCALAR)(aI + aJ); } } EXPECT_EQ(viewLenX, v[vL][vK].size_x()); EXPECT_EQ(viewLenY, v[vL][vK].size_y()); for (size_t vJ = 0; vJ < viewLenY; vJ++) { for (size_t vI = 0; vI < viewLenX; vI++) { EXPECT_EQ(arr(offsetX + vI, offsetY + vJ, aK, aL), v[vL][vK][vJ][vI]); } } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView2_when_parensAccessor_then_returnsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* indices for view and array */ size_t vK = 1; size_t vL = 2; size_t aK = offsetZ + vK; size_t aL = offsetW + vL; /* initialize values into row that will become slice */ for (size_t aJ = 0; aJ < arr.size_y(); aJ++) { for (size_t aI = 0; aI < arr.size_x(); aI++) { arr(aI, aJ, aK, aL) = (SCALAR)(aI + aJ); } } EXPECT_EQ(viewLenX, v[vL][vK].size_x()); EXPECT_EQ(viewLenY, v[vL][vK].size_y()); for (size_t vJ = 0; vJ < viewLenY; vJ++) { for (size_t vI = 0; vI < viewLenX; vI++) { EXPECT_EQ(arr(offsetX + vI, offsetY + vJ, aK, aL), v[vL][vK](vI, vJ)); } } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView2_when_bracketMutator_then_setsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* indices for view and array */ size_t vK = 1; size_t vL = 2; size_t aK = offsetZ + vK; size_t aL = offsetW + vL; /* initialize values into slice */ for (size_t vJ = 0; vJ < v[vL][vK].size_y(); vJ++) { for (size_t vI = 0; vI < v[vL][vK].size_x(); vI++) { v[vL][vK][vJ][vI] = (SCALAR)(vI + vJ); } } for (size_t vJ = 0; vJ < v[vL][vK].size_y(); vJ++) { for (size_t vI = 0; vI < v[vL][vK].size_x(); vI++) { EXPECT_EQ(v[vL][vK][vJ][vI], arr(offsetX + vI, offsetY + vJ, aK, aL)); } } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView2_when_parensMutator_then_setsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* indices for view and array */ size_t vK = 1; size_t vL = 2; size_t aK = offsetZ + vK; size_t aL = offsetW + vL; /* initialize values into slice */ for (size_t vJ = 0; vJ < v[vL][vK].size_y(); vJ++) { for (size_t vI = 0; vI < v[vL][vK].size_x(); vI++) { v[vL][vK][vJ](vI) = (SCALAR)(vI + vJ); } } for (size_t vJ = 0; vJ < v[vL][vK].size_y(); vJ++) { for (size_t vI = 0; vI < v[vL][vK].size_x(); vI++) { EXPECT_EQ(v[vL][vK][vJ][vI], arr(offsetX + vI, offsetY + vJ, aK, aL)); } } } /* nested_view1 */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView1_when_bracketAccessor_then_returnsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* indices for view and array */ size_t vJ = 2; size_t vK = 1; size_t vL = 1; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; size_t aL = offsetW + vL; /* initialize values into row that will become slice */ for (size_t aI = 0; aI < arr.size_x(); aI++) { arr(aI, aJ, aK, aL) = (SCALAR)aI; } EXPECT_EQ(viewLenX, v[vL][vK][vJ].size_x()); for (size_t vI = 0; vI < viewLenX; vI++) { EXPECT_EQ(arr(offsetX + vI, aJ, aK, aL), v[vL][vK][vJ][vI]); } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView1_when_parensAccessor_then_returnsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* indices for view and array */ size_t vJ = 2; size_t vK = 1; size_t vL = 2; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; size_t aL = offsetW + vL; /* initialize values into row that will become slice */ for (size_t aI = 0; aI < arr.size_x(); aI++) { arr(aI, aJ, aK, aL) = (SCALAR)aI; } EXPECT_EQ(viewLenX, v[vL][vK][vJ].size_x()); for (size_t vI = 0; vI < viewLenX; vI++) { EXPECT_EQ(arr(offsetX + vI, aJ, aK, aL), v[vL][vK][vJ](vI)); } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView1_when_bracketMutator_then_setsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* indices for view and array */ size_t vJ = 2; size_t vK = 1; size_t vL = 2; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; size_t aL = offsetW + vL; /* initialize values into slice */ for (size_t vI = 0; vI < v[vL][vK][vJ].size_x(); vI++) { v[vL][vK][vJ][vI] = (SCALAR)vI; } for (size_t vI = 0; vI < v[vL][vK][vJ].size_x(); vI++) { EXPECT_EQ(v[vL][vK][vJ][vI], arr(offsetX + vI, aJ, aK, aL)); } } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_nestedView1_when_parensMutator_then_setsVal) { ZFP_ARRAY_TYPE::nested_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); /* indices for view and array */ size_t vJ = 2; size_t vK = 1; size_t vL = 2; size_t aJ = offsetY + vJ; size_t aK = offsetZ + vK; size_t aL = offsetW + vL; /* initialize values into slice */ for (size_t vI = 0; vI < v[vL][vK][vJ].size_x(); vI++) { v[vL][vK][vJ](vI) = (SCALAR)vI; } for (size_t vI = 0; vI < v[vL][vK][vJ].size_x(); vI++) { EXPECT_EQ(v[vL][vK][vJ][vI], arr(offsetX + vI, aJ, aK, aL)); } } /* private_const_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_privateConstViewFullConstructor_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); EXPECT_EQ(viewLenX * viewLenY * viewLenZ * viewLenW, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); EXPECT_EQ(viewLenW, v.size_w()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); EXPECT_EQ(offsetZ, v.global_z(0)); EXPECT_EQ(offsetW, v.global_w(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_privateConstView_when_sizeXYZ_then_viewLenReturned) { ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); EXPECT_EQ(viewLenW, v.size_w()); } /* private_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_privateViewFullConstructor_then_lengthAndOffsetSet) { ZFP_ARRAY_TYPE::private_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); EXPECT_EQ(viewLenX * viewLenY * viewLenZ * viewLenW, v.size()); EXPECT_EQ(viewLenX, v.size_x()); EXPECT_EQ(viewLenY, v.size_y()); EXPECT_EQ(viewLenZ, v.size_z()); EXPECT_EQ(viewLenW, v.size_w()); EXPECT_EQ(offsetX, v.global_x(0)); EXPECT_EQ(offsetY, v.global_y(0)); EXPECT_EQ(offsetZ, v.global_z(0)); EXPECT_EQ(offsetW, v.global_w(0)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_privateView_when_partitionWithLimitOnCount_then_setsUniqueBlockBoundsAlongLongestDimension) { const size_t count = 3; size_t prevOffsetX, prevLenX, offsetX, lenX; /* partition such that each gets at least 1 block */ const size_t blockSideLen = 4; size_t arrBlockCountX = (arr.size_x() + (blockSideLen - 1)) / blockSideLen; size_t arrBlockCountY = (arr.size_y() + (blockSideLen - 1)) / blockSideLen; size_t arrBlockCountZ = (arr.size_z() + (blockSideLen - 1)) / blockSideLen; size_t arrBlockCountW = (arr.size_w() + (blockSideLen - 1)) / blockSideLen; /* ensure partition will happen along X */ EXPECT_GT(arrBlockCountX, std::max(std::max(arrBlockCountY, arrBlockCountZ), arrBlockCountW)); EXPECT_LE(count, arrBlockCountY); /* construct view */ ZFP_ARRAY_TYPE::private_view v(&arr); /* get original dimensions that should stay constant */ size_t offsetY = v.global_y(0); size_t offsetZ = v.global_z(0); size_t offsetW = v.global_w(0); size_t lenY = v.size_y(); size_t lenZ = v.size_z(); size_t lenW = v.size_w(); /* base case */ v.partition(0, count); /* along X, expect to start at first index, zero */ prevOffsetX = v.global_x(0); EXPECT_EQ(0, prevOffsetX); /* expect to have at least 1 block */ prevLenX = v.size_x(); EXPECT_LE(blockSideLen, prevLenX); /* along Y, Z, and W, expect no changes */ EXPECT_EQ(offsetY, v.global_y(0)); EXPECT_EQ(offsetZ, v.global_z(0)); EXPECT_EQ(offsetW, v.global_w(0)); EXPECT_EQ(lenY, v.size_y()); EXPECT_EQ(lenZ, v.size_z()); EXPECT_EQ(lenW, v.size_w()); /* successive cases are compared to previous */ for (size_t i = 1; i < count - 1; i++) { ZFP_ARRAY_TYPE::private_view v2(&arr); v2.partition(i, count); /* along X, expect blocks continue where previous left off */ offsetX = v2.global_x(0); EXPECT_EQ(prevOffsetX + prevLenX, offsetX); /* expect to have at least 1 block */ lenX = v2.size_x(); EXPECT_LE(blockSideLen, lenX); /* along Y, Z, and W, expect no changes */ EXPECT_EQ(offsetY, v2.global_y(0)); EXPECT_EQ(offsetZ, v2.global_z(0)); EXPECT_EQ(offsetW, v2.global_w(0)); EXPECT_EQ(lenY, v2.size_y()); EXPECT_EQ(lenZ, v2.size_z()); EXPECT_EQ(lenW, v2.size_w()); prevOffsetX = offsetX; prevLenX = lenX; } /* last partition case */ ZFP_ARRAY_TYPE::private_view v3(&arr); v3.partition(count - 1, count); /* along X, expect blocks continue where previous left off */ offsetX = v3.global_x(0); EXPECT_EQ(prevOffsetX + prevLenX, offsetX); /* last partition could hold a partial block */ lenX = v3.size_x(); EXPECT_LT(0u, lenX); /* expect to end on final index */ EXPECT_EQ(arr.size_x(), offsetX + lenX); /* along Y, Z, and W, expect no changes */ EXPECT_EQ(offsetY, v3.global_y(0)); EXPECT_EQ(offsetZ, v3.global_z(0)); EXPECT_EQ(offsetW, v3.global_w(0)); EXPECT_EQ(lenY, v3.size_y()); EXPECT_EQ(lenZ, v3.size_z()); EXPECT_EQ(lenW, v3.size_w()); } zfp-1.0.1/tests/array/array/testArray4d.cpp000066400000000000000000000020531453723256400206330ustar00rootroot00000000000000#include "zfp/array2.hpp" #include "zfp/array3.hpp" #include "zfp/array4.hpp" #include "zfp/factory.hpp" #include "zfp/array1.hpp" using namespace zfp; extern "C" { #include "constants/4dDouble.h" } #include "gtest/gtest.h" #include "utils/gtestDoubleEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class Array4dTestEnv : public ArrayDoubleTestEnv { public: virtual int getDims() { return 4; } }; Array4dTestEnv* const testEnv = new Array4dTestEnv; class Array4dTest : public ArrayNdTestFixture {}; #define TEST_FIXTURE Array4dTest #define ZFP_ARRAY_TYPE array4d #define ZFP_ARRAY_TYPE_WRONG_SCALAR array4f #define ZFP_ARRAY_TYPE_WRONG_DIM array1d #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM array1f #define ZFP_ARRAY_NOT_INCLUDED_TYPE array2d #define UINT uint64 #define SCALAR double #define DIMS 4 #include "testArrayBase.cpp" #include "testArray4Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/array/testArray4dIters.cpp000066400000000000000000000003671453723256400216500ustar00rootroot00000000000000#include "zfp/array4.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array4dTest #define ARRAY_DIMS_SCALAR_TEST_ITERS Array4dTestIters #include "utils/gtest4dTest.h" #include "testArrayItersBase.cpp" #include "testArray4ItersBase.cpp" zfp-1.0.1/tests/array/array/testArray4dPtrs.cpp000066400000000000000000000003631453723256400215060ustar00rootroot00000000000000#include "zfp/array4.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array4dTest #define ARRAY_DIMS_SCALAR_TEST_PTRS Array4dTestPtrs #include "utils/gtest4dTest.h" #include "testArrayPtrsBase.cpp" #include "testArray4PtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray4dRefs.cpp000066400000000000000000000004371453723256400214570ustar00rootroot00000000000000#include "zfp/array4.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array4dTest #define ARRAY_DIMS_SCALAR_TEST_REFS Array4dTestRefs #include "utils/gtest4dTest.h" #include "testArrayRefsBase.cpp" #include "testArray4RefsBase.cpp" zfp-1.0.1/tests/array/array/testArray4dViewIters.cpp000066400000000000000000000005221453723256400224740ustar00rootroot00000000000000#include "zfp/array4.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array4dTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_ITERS Array4dTestViewIters #include "utils/gtest4dTest.h" #define ZFP_ARRAY_TYPE array4d #define SCALAR double #define DIMS 4 #include "testArrayViewItersBase.cpp" zfp-1.0.1/tests/array/array/testArray4dViewPtrs.cpp000066400000000000000000000005171453723256400223420ustar00rootroot00000000000000#include "zfp/array4.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array4dTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_PTRS Array4dTestViewPtrs #include "utils/gtest4dTest.h" #define ZFP_ARRAY_TYPE array4d #define SCALAR double #define DIMS 4 #include "testArrayViewPtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray4dViews.cpp000066400000000000000000000005501453723256400216510ustar00rootroot00000000000000#include "zfp/array4.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array4dTest #define ARRAY_DIMS_SCALAR_TEST_VIEWS Array4dTestViews #include "utils/gtest4dTest.h" #define ZFP_ARRAY_TYPE array4d #define SCALAR double #define DIMS 4 #include "testArrayViewsBase.cpp" #include "testArray4ViewsBase.cpp" zfp-1.0.1/tests/array/array/testArray4f.cpp000066400000000000000000000020471453723256400206400ustar00rootroot00000000000000#include "zfp/array2.hpp" #include "zfp/array3.hpp" #include "zfp/array4.hpp" #include "zfp/factory.hpp" #include "zfp/array1.hpp" using namespace zfp; extern "C" { #include "constants/4dFloat.h" } #include "gtest/gtest.h" #include "utils/gtestFloatEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class Array4fTestEnv : public ArrayFloatTestEnv { public: virtual int getDims() { return 4; } }; Array4fTestEnv* const testEnv = new Array4fTestEnv; class Array4fTest : public ArrayNdTestFixture {}; #define TEST_FIXTURE Array4fTest #define ZFP_ARRAY_TYPE array4f #define ZFP_ARRAY_TYPE_WRONG_SCALAR array4d #define ZFP_ARRAY_TYPE_WRONG_DIM array1f #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM array1d #define ZFP_ARRAY_NOT_INCLUDED_TYPE array2f #define UINT uint32 #define SCALAR float #define DIMS 4 #include "testArrayBase.cpp" #include "testArray4Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/array/testArray4fIters.cpp000066400000000000000000000003671453723256400216520ustar00rootroot00000000000000#include "zfp/array4.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array4fTest #define ARRAY_DIMS_SCALAR_TEST_ITERS Array4fTestIters #include "utils/gtest4fTest.h" #include "testArrayItersBase.cpp" #include "testArray4ItersBase.cpp" zfp-1.0.1/tests/array/array/testArray4fPtrs.cpp000066400000000000000000000003631453723256400215100ustar00rootroot00000000000000#include "zfp/array4.hpp" using namespace zfp; #define ARRAY_DIMS_SCALAR_TEST Array4fTest #define ARRAY_DIMS_SCALAR_TEST_PTRS Array4fTestPtrs #include "utils/gtest4fTest.h" #include "testArrayPtrsBase.cpp" #include "testArray4PtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray4fRefs.cpp000066400000000000000000000004371453723256400214610ustar00rootroot00000000000000#include "zfp/array4.hpp" using namespace zfp; extern "C" { #include "utils/rand32.h" } #define ARRAY_DIMS_SCALAR_TEST Array4fTest #define ARRAY_DIMS_SCALAR_TEST_REFS Array4fTestRefs #include "utils/gtest4fTest.h" #include "testArrayRefsBase.cpp" #include "testArray4RefsBase.cpp" zfp-1.0.1/tests/array/array/testArray4fViewIters.cpp000066400000000000000000000005211453723256400224750ustar00rootroot00000000000000#include "zfp/array4.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array4fTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_ITERS Array4fTestViewIters #include "utils/gtest4fTest.h" #define ZFP_ARRAY_TYPE array4f #define SCALAR float #define DIMS 4 #include "testArrayViewItersBase.cpp" zfp-1.0.1/tests/array/array/testArray4fViewPtrs.cpp000066400000000000000000000005161453723256400223430ustar00rootroot00000000000000#include "zfp/array4.hpp" using namespace zfp; extern "C" { #include "utils/rand64.h" } #define ARRAY_DIMS_SCALAR_TEST Array4fTest #define ARRAY_DIMS_SCALAR_TEST_VIEW_PTRS Array4fTestViewPtrs #include "utils/gtest4fTest.h" #define ZFP_ARRAY_TYPE array4f #define SCALAR float #define DIMS 4 #include "testArrayViewPtrsBase.cpp" zfp-1.0.1/tests/array/array/testArray4fViews.cpp000066400000000000000000000005471453723256400216610ustar00rootroot00000000000000#include "zfp/array4.hpp" using namespace zfp; extern "C" { #include "utils/rand32.h" } #define ARRAY_DIMS_SCALAR_TEST Array4fTest #define ARRAY_DIMS_SCALAR_TEST_VIEWS Array4fTestViews #include "utils/gtest4fTest.h" #define ZFP_ARRAY_TYPE array4f #define SCALAR float #define DIMS 4 #include "testArrayViewsBase.cpp" #include "testArray4ViewsBase.cpp" zfp-1.0.1/tests/array/array/testArrayBase.cpp000066400000000000000000000763121453723256400212070ustar00rootroot00000000000000extern "C" { #include "utils/testMacros.h" #include "utils/zfpChecksums.h" #include "utils/zfpHash.h" } #include #include TEST_F(TEST_FIXTURE, when_constructorCalled_then_rateSetWithWriteRandomAccess) { double rate = ZFP_RATE_PARAM_BITS; #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, rate); EXPECT_LT(rate, arr.rate()); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, rate); EXPECT_LT(rate, arr.rate()); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, rate); // alignment in 3D supports integer fixed-rates [1, 64] (use <=) EXPECT_LE(rate, arr.rate()); #elif DIMS == 4 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, rate); // alignment in 4D supports integer fixed-rates [1, 64] (use <=) EXPECT_LE(rate, arr.rate()); #endif } TEST_F(TEST_FIXTURE, when_constructorCalledWithCacheSize_then_minCacheSizeEnforced) { size_t cacheSize = 300; #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, ZFP_RATE_PARAM_BITS, 0, cacheSize); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, ZFP_RATE_PARAM_BITS, 0, cacheSize); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, ZFP_RATE_PARAM_BITS, 0, cacheSize); #elif DIMS == 4 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, ZFP_RATE_PARAM_BITS, 0, cacheSize); #endif EXPECT_LE(cacheSize, arr.cache_size()); } TEST_F(TEST_FIXTURE, when_setRate_then_compressionRateChanged) { double oldRate = ZFP_RATE_PARAM_BITS; #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, oldRate, inputDataArr); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, oldRate, inputDataArr); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, oldRate, inputDataArr); #elif DIMS == 4 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, oldRate, inputDataArr); #endif double actualOldRate = arr.rate(); size_t oldCompressedSize = arr.compressed_size(); uint64 oldChecksum = hashBitstream((uint64*)arr.compressed_data(), oldCompressedSize); double newRate = oldRate - 10; EXPECT_LT(1, newRate); arr.set_rate(newRate); EXPECT_GT(actualOldRate, arr.rate()); arr.set(inputDataArr); size_t newCompressedSize = arr.compressed_size(); uint64 checksum = hashBitstream((uint64*)arr.compressed_data(), newCompressedSize); EXPECT_PRED_FORMAT2(ExpectNeqPrintHexPred, oldChecksum, checksum); EXPECT_GT(oldCompressedSize, newCompressedSize); } void VerifyProperHeaderWritten(const zfp::array::header& h, size_t chosenSizeX, size_t chosenSizeY, size_t chosenSizeZ, size_t chosenSizeW, double chosenRate) { // copy header into aligned memory suitable for bitstream r/w size_t byte_size = h.size_bytes(); size_t num_64bit_entries = (byte_size + sizeof(uint64) - 1) / sizeof(uint64); uint64* buffer = new uint64[num_64bit_entries]; memcpy(buffer, h.data(), h.size_bytes()); // verify valid header (manually through C API) bitstream* stream = stream_open(buffer, byte_size); zfp_stream* zfp = zfp_stream_open(stream); zfp_field* field = zfp_field_alloc(); EXPECT_EQ(ZFP_HEADER_SIZE_BITS, zfp_read_header(zfp, field, ZFP_HEADER_FULL)); // verify header contents EXPECT_EQ(chosenSizeX, field->nx); EXPECT_EQ(chosenSizeY, field->ny); EXPECT_EQ(chosenSizeZ, field->nz); EXPECT_EQ(chosenSizeW, field->nw); EXPECT_EQ(ZFP_TYPE, field->type); // to verify rate, we can only compare the 4 compression-param basis zfp_stream* expectedZfpStream = zfp_stream_open(0); zfp_stream_set_rate(expectedZfpStream, chosenRate, ZFP_TYPE, testEnv->getDims(), zfp_true); EXPECT_EQ(expectedZfpStream->minbits, zfp->minbits); EXPECT_EQ(expectedZfpStream->maxbits, zfp->maxbits); EXPECT_EQ(expectedZfpStream->maxprec, zfp->maxprec); EXPECT_EQ(expectedZfpStream->minexp, zfp->minexp); zfp_stream_close(expectedZfpStream); zfp_stream_close(zfp); zfp_field_free(field); stream_close(stream); delete[] buffer; } TEST_F(TEST_FIXTURE, when_writeHeader_then_cCompatibleHeaderWritten) { double chosenRate = ZFP_RATE_PARAM_BITS; size_t chosenSizeX, chosenSizeY, chosenSizeZ, chosenSizeW; #if DIMS == 1 chosenSizeX = 55; chosenSizeY = 0; chosenSizeZ = 0; chosenSizeW = 0; ZFP_ARRAY_TYPE arr(chosenSizeX, chosenRate); #elif DIMS == 2 chosenSizeX = 55; chosenSizeY = 23; chosenSizeZ = 0; chosenSizeW = 0; ZFP_ARRAY_TYPE arr(chosenSizeX, chosenSizeY, chosenRate); #elif DIMS == 3 chosenSizeX = 55; chosenSizeY = 23; chosenSizeZ = 31; chosenSizeW = 0; ZFP_ARRAY_TYPE arr(chosenSizeX, chosenSizeY, chosenSizeZ, chosenRate); #elif DIMS == 4 // max rate for short headers for 4D arrays chosenRate = std::min(chosenRate, 8.0); chosenSizeX = 55; chosenSizeY = 23; chosenSizeZ = 31; chosenSizeW = 10; ZFP_ARRAY_TYPE arr(chosenSizeX, chosenSizeY, chosenSizeZ, chosenSizeW, chosenRate); #endif ZFP_ARRAY_TYPE::header header(arr); chosenRate = arr.rate(); VerifyProperHeaderWritten(header, chosenSizeX, chosenSizeY, chosenSizeZ, chosenSizeW, chosenRate); } TEST_F(TEST_FIXTURE, when_generateRandomData_then_checksumMatches) { uint64 key1, key2; computeKeyOriginalInput(ARRAY_TEST, dimLens, &key1, &key2); EXPECT_PRED_FORMAT2(ExpectEqPrintHexPred, getChecksumByKey(DIMS, ZFP_TYPE, key1, key2), _catFunc2(hashArray, SCALAR_BITS)((UINT*)inputDataArr, inputDataTotalLen, 1)); } void FailWhenNoExceptionThrown() { FAIL() << "No exception was thrown when one was expected"; } void FailAndPrintException(std::exception const & e) { FAIL() << "Unexpected exception thrown: " << typeid(e).name() << std::endl << "With message: " << e.what(); } TEST_F(TEST_FIXTURE, when_constructorFromSerializedWithInvalidHeader_then_exceptionThrown) { uchar buffer[0x100] = {}; try { ZFP_ARRAY_TYPE::header h(buffer); ZFP_ARRAY_TYPE arr(h, NULL); FailWhenNoExceptionThrown(); } catch (zfp::exception const & e) { EXPECT_EQ(e.what(), std::string("zfp header is corrupt")); } catch (std::exception const & e) { FailAndPrintException(e); } } TEST_F(TEST_FIXTURE, given_zfpHeaderForCertainDimensionalityButHeaderMissing_when_construct_expect_zfpArrayHeaderExceptionThrown) { uint missingDim = (DIMS % 4) + 1; zfp_stream_set_rate(stream, 8, ZFP_TYPE, missingDim, zfp_true); zfp_field_set_type(field, ZFP_TYPE); switch (missingDim) { case 1: zfp_field_set_size_1d(field, 12); break; case 2: zfp_field_set_size_2d(field, 12, 12); break; case 3: zfp_field_set_size_3d(field, 12, 12, 12); break; case 4: zfp_field_set_size_4d(field, 12, 12, 12, 12); break; } // write header to buffer with C API zfp_stream_rewind(stream); EXPECT_EQ(ZFP_HEADER_SIZE_BITS, zfp_write_header(stream, field, ZFP_HEADER_FULL)); zfp_stream_flush(stream); ZFP_ARRAY_TYPE::header h(buffer); try { zfp::array* arr = zfp::array::construct(h); FailWhenNoExceptionThrown(); } catch (zfp::exception const & e) { std::stringstream ss; ss << "array" << missingDim << " not supported; include zfp/array" << missingDim << ".hpp before zfp/factory.hpp"; EXPECT_EQ(e.what(), ss.str()); } catch (std::exception const & e) { FailAndPrintException(e); } } TEST_F(TEST_FIXTURE, given_serializedCompressedArrayFromWrongScalarType_when_constructorFromSerialized_then_exceptionThrown) { #if DIMS == 1 ZFP_ARRAY_TYPE_WRONG_SCALAR arr(inputDataSideLen, ZFP_RATE_PARAM_BITS); #elif DIMS == 2 ZFP_ARRAY_TYPE_WRONG_SCALAR arr(inputDataSideLen, inputDataSideLen, ZFP_RATE_PARAM_BITS); #elif DIMS == 3 ZFP_ARRAY_TYPE_WRONG_SCALAR arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, ZFP_RATE_PARAM_BITS); #elif DIMS == 4 // max rate for short headers for 4D arrays ZFP_ARRAY_TYPE_WRONG_SCALAR arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, std::min(ZFP_RATE_PARAM_BITS, 8)); #endif ZFP_ARRAY_TYPE_WRONG_SCALAR::header h(arr); try { ZFP_ARRAY_TYPE arr2(h, arr.compressed_data()); FailWhenNoExceptionThrown(); } catch (zfp::exception const & e) { EXPECT_EQ(e.what(), std::string("zfp array scalar type does not match header")); } catch (std::exception const & e) { FailAndPrintException(e); } } TEST_F(TEST_FIXTURE, given_serializedCompressedArrayFromWrongDimensionality_when_constructorFromSerialized_then_exceptionThrown) { #if DIMS == 1 ZFP_ARRAY_TYPE_WRONG_DIM arr(100, 100, ZFP_RATE_PARAM_BITS); #elif DIMS == 2 ZFP_ARRAY_TYPE_WRONG_DIM arr(100, 100, 100, ZFP_RATE_PARAM_BITS); #elif DIMS == 3 ZFP_ARRAY_TYPE_WRONG_DIM arr(100, 100, 100, 100, ZFP_RATE_PARAM_BITS); #elif DIMS == 4 ZFP_ARRAY_TYPE_WRONG_DIM arr(100, ZFP_RATE_PARAM_BITS); #endif try { ZFP_ARRAY_TYPE_WRONG_DIM::header h(arr); try { ZFP_ARRAY_TYPE arr2(h, arr.compressed_data()); FailWhenNoExceptionThrown(); } catch (zfp::exception const & e) { // short headers are available in (1D, 2D, and) 3D when ZFP_RATE_PARAM_BITS <= 32 EXPECT_LT(arr.dimensionality(), 4u); EXPECT_EQ(e.what(), std::string("zfp array dimensionality does not match header")); } catch (std::exception const & e) { FailAndPrintException(e); } } catch (zfp::exception const & e) { // short headers for 4D arrays requires ZFP_RATE_PARAM_BITS <= 8, which is violated EXPECT_EQ(arr.dimensionality(), 4); EXPECT_EQ(e.what(), std::string("zfp serialization supports only short headers")); } catch (std::exception const & e) { FailAndPrintException(e); } } TEST_F(TEST_FIXTURE, given_serializedNonFixedRateHeader_when_constructorFromSerialized_then_exceptionThrown) { // create a compressed stream through C API // (one that is not supported with compressed arrays) zfp_field* field; #if DIMS == 1 field = zfp_field_1d(inputDataArr, ZFP_TYPE, inputDataSideLen); #elif DIMS == 2 field = zfp_field_2d(inputDataArr, ZFP_TYPE, inputDataSideLen, inputDataSideLen); #elif DIMS == 3 field = zfp_field_3d(inputDataArr, ZFP_TYPE, inputDataSideLen, inputDataSideLen, inputDataSideLen); #elif DIMS == 4 field = zfp_field_4d(inputDataArr, ZFP_TYPE, inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen); #endif zfp_stream* stream = zfp_stream_open(NULL); size_t bufsizeBytes = zfp_stream_maximum_size(stream, field); uchar* buffer = new uchar[bufsizeBytes]; memset(buffer, 0, bufsizeBytes); bitstream* bs = stream_open(buffer, bufsizeBytes); zfp_stream_set_bit_stream(stream, bs); zfp_stream_rewind(stream); zfp_stream_set_precision(stream, 10); EXPECT_NE(zfp_mode_fixed_rate, zfp_stream_compression_mode(stream)); // write header size_t writtenBits = zfp_write_header(stream, field, ZFP_HEADER_FULL); EXPECT_EQ(ZFP_HEADER_SIZE_BITS, writtenBits); zfp_stream_flush(stream); // copy header into header size_t headerSizeBytes = DIV_ROUND_UP(writtenBits, CHAR_BIT); // compress data uchar* compressedDataPtr = (uchar*)stream_data(bs) + headerSizeBytes; zfp_compress(stream, field); // close/free C API things (keep buffer) zfp_field_free(field); zfp_stream_close(stream); stream_close(bs); try { ZFP_ARRAY_TYPE::header h(buffer, headerSizeBytes); ZFP_ARRAY_TYPE arr2(h, compressedDataPtr, bufsizeBytes - headerSizeBytes); FailWhenNoExceptionThrown(); } catch (zfp::exception const & e) { EXPECT_EQ(e.what(), std::string("zfp deserialization supports only fixed-rate mode")); } catch (std::exception const & e) { FailAndPrintException(e); } delete[] buffer; } TEST_F(TEST_FIXTURE, given_serializedNonFixedRateWrongScalarTypeWrongDimensionalityHeader_when_constructorFromSerialized_then_exceptionsThrown) { // create a compressed stream through C API // (one that is not supported with compressed arrays) zfp_field* field; // (inputDataSideLen specific to that dimensionality, can request too much memory if fitted to higher dimensionality) #if DIMS == 1 field = zfp_field_1d(inputDataArr, zfp_type_int32, 100); #elif DIMS == 2 field = zfp_field_2d(inputDataArr, zfp_type_int32, 100, 100); #elif DIMS == 3 field = zfp_field_3d(inputDataArr, zfp_type_int32, 100, 100, 100); #elif DIMS == 4 field = zfp_field_4d(inputDataArr, zfp_type_int32, 30, 30, 30, 30); #endif zfp_stream* stream = zfp_stream_open(NULL); size_t bufsizeBytes = zfp_stream_maximum_size(stream, field); uchar* buffer = new uchar[bufsizeBytes]; memset(buffer, 0, bufsizeBytes); bitstream* bs = stream_open(buffer, bufsizeBytes); zfp_stream_set_bit_stream(stream, bs); zfp_stream_rewind(stream); zfp_stream_set_precision(stream, 10); EXPECT_NE(zfp_mode_fixed_rate, zfp_stream_compression_mode(stream)); // write header size_t writtenBits = zfp_write_header(stream, field, ZFP_HEADER_FULL); EXPECT_EQ(ZFP_HEADER_SIZE_BITS, writtenBits); zfp_stream_flush(stream); // copy header into header size_t headerSizeBytes = (writtenBits + CHAR_BIT - 1) / CHAR_BIT; // compress data uchar* compressedDataPtr = (uchar*)stream_data(bs) + headerSizeBytes; zfp_compress(stream, field); // close/free C API things (keep buffer) zfp_field_free(field); zfp_stream_close(stream); stream_close(bs); try { ZFP_ARRAY_TYPE::header h(buffer, headerSizeBytes); ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM arr2(h, compressedDataPtr, bufsizeBytes - headerSizeBytes); FailWhenNoExceptionThrown(); } catch (zfp::exception const & e) { // exception must match one of these EXPECT_TRUE( e.what() == std::string("zfp array scalar type does not match header") || e.what() == std::string("zfp array dimensionality does not match header") || e.what() == std::string("zfp serialization supports only float and double") || e.what() == std::string("zfp deserialization supports only fixed-rate mode") ); // print exception if any of above were not met if (HasFailure()) { FailAndPrintException(e); } } catch (std::exception const & e) { FailAndPrintException(e); } delete[] buffer; } TEST_F(TEST_FIXTURE, given_compatibleHeaderWrittenViaCApi_when_constructorFromSerialized_then_successWithParamsSet) { // create a compressed stream through C API // (one that is supported with compressed arrays) zfp_field* field; #if DIMS == 1 field = zfp_field_1d(inputDataArr, ZFP_TYPE, inputDataSideLen); #elif DIMS == 2 field = zfp_field_2d(inputDataArr, ZFP_TYPE, inputDataSideLen, inputDataSideLen); #elif DIMS == 3 field = zfp_field_3d(inputDataArr, ZFP_TYPE, inputDataSideLen, inputDataSideLen, inputDataSideLen); #elif DIMS == 4 field = zfp_field_4d(inputDataArr, ZFP_TYPE, inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen); #endif zfp_stream* stream = zfp_stream_open(NULL); double rate = zfp_stream_set_rate(stream, 8, ZFP_TYPE, DIMS, zfp_true); EXPECT_EQ(zfp_mode_fixed_rate, zfp_stream_compression_mode(stream)); size_t bufsizeBytes = zfp_stream_maximum_size(stream, field); uchar* buffer = new uchar[bufsizeBytes]; memset(buffer, 0, bufsizeBytes); bitstream* bs = stream_open(buffer, bufsizeBytes); zfp_stream_set_bit_stream(stream, bs); zfp_stream_rewind(stream); // write header size_t writtenBits = zfp_write_header(stream, field, ZFP_HEADER_FULL); EXPECT_EQ(ZFP_HEADER_SIZE_BITS, writtenBits); zfp_stream_flush(stream); // copy header into header size_t headerSizeBytes = (writtenBits + CHAR_BIT - 1) / CHAR_BIT; // compress data uchar* compressedDataPtr = (uchar*)stream_data(bs) + headerSizeBytes; zfp_compress(stream, field); try { ZFP_ARRAY_TYPE::header h(buffer, headerSizeBytes); ZFP_ARRAY_TYPE arr2(h, compressedDataPtr, bufsizeBytes - headerSizeBytes); EXPECT_EQ(arr2.dimensionality(), zfp_field_dimensionality(field)); EXPECT_EQ(arr2.scalar_type(), zfp_field_type(field)); size_t n[4]; EXPECT_EQ(arr2.size(), zfp_field_size(field, n)); #if DIMS == 1 EXPECT_EQ(arr2.size_x(), n[0]); #elif DIMS == 2 EXPECT_EQ(arr2.size_x(), n[0]); EXPECT_EQ(arr2.size_y(), n[1]); #elif DIMS == 3 EXPECT_EQ(arr2.size_x(), n[0]); EXPECT_EQ(arr2.size_y(), n[1]); EXPECT_EQ(arr2.size_z(), n[2]); #elif DIMS == 4 EXPECT_EQ(arr2.size_x(), n[0]); EXPECT_EQ(arr2.size_y(), n[1]); EXPECT_EQ(arr2.size_z(), n[2]); EXPECT_EQ(arr2.size_w(), n[3]); #endif EXPECT_EQ(arr2.rate(), rate); } catch (std::exception const & e) { FailAndPrintException(e); } zfp_stream_close(stream); stream_close(bs); zfp_field_free(field); delete[] buffer; } TEST_F(TEST_FIXTURE, given_incompleteChunkOfSerializedCompressedArray_when_constructorFromSerialized_then_exceptionThrown) { #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, ZFP_RATE_PARAM_BITS); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, ZFP_RATE_PARAM_BITS); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, ZFP_RATE_PARAM_BITS); #elif DIMS == 4 // max rate for short headers for 4D arrays ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, std::min(ZFP_RATE_PARAM_BITS, 8)); #endif ZFP_ARRAY_TYPE::header h(arr); try { ZFP_ARRAY_TYPE arr2(h, arr.compressed_data(), arr.compressed_size() - 1); FailWhenNoExceptionThrown(); } catch (zfp::exception const & e) { EXPECT_EQ(e.what(), std::string("buffer size is smaller than required")); } catch (std::exception const & e) { FailAndPrintException(e); } } TEST_F(TEST_FIXTURE, given_serializedCompressedArrayHeader_when_factoryFuncConstruct_then_correctTypeConstructed) { #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, ZFP_RATE_PARAM_BITS); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, ZFP_RATE_PARAM_BITS); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, ZFP_RATE_PARAM_BITS); #elif DIMS == 4 // max rate for short headers for 4D arrays ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, std::min(ZFP_RATE_PARAM_BITS, 8)); #endif ZFP_ARRAY_TYPE::header h(arr); array* arr2 = zfp::array::construct(h); ASSERT_TRUE(arr2 != 0); ASSERT_TRUE(dynamic_cast(arr2) != NULL); ASSERT_TRUE(dynamic_cast(arr2) == NULL); delete arr2; } TEST_F(TEST_FIXTURE, given_serializedCompressedArray_when_factoryFuncConstruct_then_correctTypeConstructedWithPopulatedEntries) { #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, ZFP_RATE_PARAM_BITS); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, ZFP_RATE_PARAM_BITS); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, ZFP_RATE_PARAM_BITS); #elif DIMS == 4 // max rate for short headers for 4D arrays ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, std::min(ZFP_RATE_PARAM_BITS, 8)); #endif arr[1] = 999999.; ZFP_ARRAY_TYPE::header h(arr); array* arr2 = zfp::array::construct(h, arr.compressed_data(), arr.compressed_size()); ASSERT_TRUE(arr2 != 0); EXPECT_EQ(arr.compressed_size(), arr2->compressed_size()); ASSERT_TRUE(std::memcmp(arr.compressed_data(), arr2->compressed_data(), arr.compressed_size()) == 0); delete arr2; } TEST_F(TEST_FIXTURE, given_uncompatibleSerializedMem_when_factoryFuncConstruct_then_throwsZfpHeaderException) { size_t dummyLen = 1024; uchar* dummyMem = new uchar[dummyLen]; memset(dummyMem, 0, dummyLen); try { ZFP_ARRAY_TYPE::header h(dummyMem); array* arr = zfp::array::construct(h, dummyMem, dummyLen); } catch (zfp::exception const & e) { EXPECT_EQ(e.what(), std::string("zfp header is corrupt")); } catch (std::exception const & e) { FailAndPrintException(e); } delete[] dummyMem; } #if DIMS == 1 // with write random access in 1D, fixed-rate params rounded up to multiples of 16 INSTANTIATE_TEST_SUITE_P(TestManyCompressionRates, TEST_FIXTURE, ::testing::Values(1, 2)); #else INSTANTIATE_TEST_SUITE_P(TestManyCompressionRates, TEST_FIXTURE, ::testing::Values(0, 1, 2)); #endif TEST_P(TEST_FIXTURE, given_dataset_when_set_then_underlyingBitstreamChecksumMatches) { #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate()); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate()); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate()); #elif DIMS == 4 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate()); #endif uint64 key1, key2; computeKey(ARRAY_TEST, COMPRESSED_BITSTREAM, dimLens, zfp_mode_fixed_rate, GetParam(), &key1, &key2); uint64 expectedChecksum = getChecksumByKey(DIMS, ZFP_TYPE, key1, key2); uint64 checksum = hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size()); EXPECT_PRED_FORMAT2(ExpectNeqPrintHexPred, expectedChecksum, checksum); arr.set(inputDataArr); checksum = hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size()); EXPECT_PRED_FORMAT2(ExpectEqPrintHexPred, expectedChecksum, checksum); } TEST_P(TEST_FIXTURE, given_setArray_when_get_then_decompressedValsReturned) { #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); #elif DIMS == 4 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); #endif SCALAR* decompressedArr = new SCALAR[inputDataTotalLen]; arr.get(decompressedArr); uint64 key1, key2; computeKey(ARRAY_TEST, DECOMPRESSED_ARRAY, dimLens, zfp_mode_fixed_rate, GetParam(), &key1, &key2); uint64 expectedChecksum = getChecksumByKey(DIMS, ZFP_TYPE, key1, key2); uint64 checksum = _catFunc2(hashArray, SCALAR_BITS)((UINT*)decompressedArr, inputDataTotalLen, 1); EXPECT_PRED_FORMAT2(ExpectEqPrintHexPred, expectedChecksum, checksum); delete[] decompressedArr; } TEST_P(TEST_FIXTURE, given_populatedCompressedArray_when_resizeWithClear_then_bitstreamZeroed) { #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate()); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate()); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate()); #elif DIMS == 4 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate()); #endif arr.set(inputDataArr); EXPECT_NE(0u, hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size())); #if DIMS == 1 arr.resize(inputDataSideLen + 1, true); #elif DIMS == 2 arr.resize(inputDataSideLen + 1, inputDataSideLen + 1, true); #elif DIMS == 3 arr.resize(inputDataSideLen + 1, inputDataSideLen + 1, inputDataSideLen + 1, true); #elif DIMS == 4 arr.resize(inputDataSideLen + 1, inputDataSideLen + 1, inputDataSideLen + 1, inputDataSideLen + 1, true); #endif EXPECT_EQ(0u, hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size())); } TEST_P(TEST_FIXTURE, when_configureCompressedArrayFromDefaultConstructor_then_bitstreamChecksumMatches) { ZFP_ARRAY_TYPE arr; #if DIMS == 1 arr.resize(inputDataSideLen, false); #elif DIMS == 2 arr.resize(inputDataSideLen, inputDataSideLen, false); #elif DIMS == 3 arr.resize(inputDataSideLen, inputDataSideLen, inputDataSideLen, false); #elif DIMS == 4 arr.resize(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, false); #endif arr.set_rate(getRate()); arr.set(inputDataArr); uint64 key1, key2; computeKey(ARRAY_TEST, COMPRESSED_BITSTREAM, dimLens, zfp_mode_fixed_rate, GetParam(), &key1, &key2); uint64 expectedChecksum = getChecksumByKey(DIMS, ZFP_TYPE, key1, key2); uint64 checksum = hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size()); EXPECT_PRED_FORMAT2(ExpectEqPrintHexPred, expectedChecksum, checksum); } // assumes arr1 was given a dirty cache // this irreversibly changes arr1 (clears entries) void CheckDeepCopyPerformedViaDirtyCache(ZFP_ARRAY_TYPE& arr1, ZFP_ARRAY_TYPE& arr2, void* arr1UnflushedBitstreamPtr) { // flush arr2 first, to ensure arr1 remains unflushed uint64 checksum = hashBitstream((uint64*)arr2.compressed_data(), arr2.compressed_size()); uint64 arr1UnflushedChecksum = hashBitstream((uint64*)arr1UnflushedBitstreamPtr, arr1.compressed_size()); EXPECT_PRED_FORMAT2(ExpectNeqPrintHexPred, arr1UnflushedChecksum, checksum); // flush arr1, compute its checksum, clear its bitstream, re-compute arr2's checksum uint64 expectedChecksum = hashBitstream((uint64*)arr1.compressed_data(), arr1.compressed_size()); #if DIMS == 1 arr1.resize(arr1.size(), true); #elif DIMS == 2 arr1.resize(arr1.size_x(), arr1.size_y(), true); #elif DIMS == 3 arr1.resize(arr1.size_x(), arr1.size_y(), arr1.size_z(), true); #elif DIMS == 4 arr1.resize(arr1.size_x(), arr1.size_y(), arr1.size_z(), arr1.size_w(), true); #endif checksum = hashBitstream((uint64*)arr2.compressed_data(), arr2.compressed_size()); EXPECT_PRED_FORMAT2(ExpectEqPrintHexPred, expectedChecksum, checksum); } // this irreversibly changes arr1 (resize + clears entries) void CheckMemberVarsCopied(ZFP_ARRAY_TYPE& arr1, const ZFP_ARRAY_TYPE& arr2, bool assertCacheSize) { double oldRate = arr1.rate(); size_t oldCompressedSize = arr1.compressed_size(); size_t oldCacheSize = arr1.cache_size(); #if DIMS == 1 size_t oldSizeX = arr1.size(); arr1.resize(oldSizeX - 10); #elif DIMS == 2 size_t oldSizeX = arr1.size_x(); size_t oldSizeY = arr1.size_y(); arr1.resize(oldSizeX - 10, oldSizeY - 5); #elif DIMS == 3 size_t oldSizeX = arr1.size_x(); size_t oldSizeY = arr1.size_y(); size_t oldSizeZ = arr1.size_z(); arr1.resize(oldSizeX - 10, oldSizeY - 5, oldSizeZ - 8); #elif DIMS == 4 size_t oldSizeX = arr1.size_x(); size_t oldSizeY = arr1.size_y(); size_t oldSizeZ = arr1.size_z(); size_t oldSizeW = arr1.size_w(); arr1.resize(oldSizeX - 10, oldSizeY - 5, oldSizeZ - 8, oldSizeW - 3); #endif arr1.set_rate(oldRate + 10); arr1.set(inputDataArr); arr1.set_cache_size(oldCacheSize + 10); EXPECT_EQ(oldRate, arr2.rate()); EXPECT_EQ(oldCompressedSize, arr2.compressed_size()); if (assertCacheSize) EXPECT_EQ(oldCacheSize, arr2.cache_size()); #if DIMS == 1 EXPECT_EQ(oldSizeX, arr2.size()); #elif DIMS == 2 EXPECT_EQ(oldSizeX, arr2.size_x()); EXPECT_EQ(oldSizeY, arr2.size_y()); #elif DIMS == 3 EXPECT_EQ(oldSizeX, arr2.size_x()); EXPECT_EQ(oldSizeY, arr2.size_y()); EXPECT_EQ(oldSizeZ, arr2.size_z()); #elif DIMS == 4 EXPECT_EQ(oldSizeX, arr2.size_x()); EXPECT_EQ(oldSizeY, arr2.size_y()); EXPECT_EQ(oldSizeZ, arr2.size_z()); EXPECT_EQ(oldSizeW, arr2.size_w()); #endif } TEST_P(TEST_FIXTURE, given_compressedArray_when_copyConstructor_then_memberVariablesCopied) { #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr, 128); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr, 128); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr, 128); #elif DIMS == 4 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr, 128); #endif ZFP_ARRAY_TYPE arr2(arr); CheckMemberVarsCopied(arr, arr2, true); } TEST_P(TEST_FIXTURE, given_compressedArray_when_copyConstructor_then_deepCopyPerformed) { #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); #elif DIMS == 4 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); #endif // create arr with dirty cache void* arrUnflushedBitstreamPtr = arr.compressed_data(); arr[0] = 999999; ZFP_ARRAY_TYPE arr2(arr); CheckDeepCopyPerformedViaDirtyCache(arr, arr2, arrUnflushedBitstreamPtr); } TEST_P(TEST_FIXTURE, given_compressedArray_when_setSecondArrayEqualToFirst_then_memberVariablesCopied) { #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr, 128); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr, 128); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr, 128); #elif DIMS == 4 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr, 128); #endif ZFP_ARRAY_TYPE arr2 = arr; CheckMemberVarsCopied(arr, arr2, true); } TEST_P(TEST_FIXTURE, given_compressedArray_when_setSecondArrayEqualToFirst_then_deepCopyPerformed) { #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); #elif DIMS == 4 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); #endif // create arr with dirty cache void* arrUnflushedBitstreamPtr = arr.compressed_data(); arr[0] = 999999; ZFP_ARRAY_TYPE arr2 = arr; CheckDeepCopyPerformedViaDirtyCache(arr, arr2, arrUnflushedBitstreamPtr); } void CheckHeadersEquivalent(const ZFP_ARRAY_TYPE& arr1, const ZFP_ARRAY_TYPE& arr2) { ZFP_ARRAY_TYPE::header h[2] = { arr1, arr2 }; uint64 header1Checksum = hashBitstream((uint64*)(h[0].data()), BITS_TO_BYTES(ZFP_HEADER_SIZE_BITS)); uint64 header2Checksum = hashBitstream((uint64*)(h[1].data()), BITS_TO_BYTES(ZFP_HEADER_SIZE_BITS)); EXPECT_PRED_FORMAT2(ExpectEqPrintHexPred, header1Checksum, header2Checksum); } // this clears arr1's entries void CheckDeepCopyPerformed(ZFP_ARRAY_TYPE& arr1, ZFP_ARRAY_TYPE& arr2) { // flush arr1, compute its checksum, clear its bitstream, re-compute arr2's checksum uint64 expectedChecksum = hashBitstream((uint64*)arr1.compressed_data(), arr1.compressed_size()); #if DIMS == 1 arr1.resize(arr1.size(), true); #elif DIMS == 2 arr1.resize(arr1.size_x(), arr1.size_y(), true); #elif DIMS == 3 arr1.resize(arr1.size_x(), arr1.size_y(), arr1.size_z(), true); #elif DIMS == 4 arr1.resize(arr1.size_x(), arr1.size_y(), arr1.size_z(), arr1.size_w(), true); #endif uint64 checksum = hashBitstream((uint64*)arr2.compressed_data(), arr2.compressed_size()); EXPECT_PRED_FORMAT2(ExpectEqPrintHexPred, expectedChecksum, checksum); } TEST_P(TEST_FIXTURE, given_serializedCompressedArray_when_constructorFromSerialized_then_constructedArrIsBasicallyADeepCopy) { #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, getRate(), inputDataArr); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); #elif DIMS == 4 // max rate for short headers for 4D arrays if (getRate() > 8) return; ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, getRate(), inputDataArr); #endif ZFP_ARRAY_TYPE::header h(arr); ZFP_ARRAY_TYPE arr2(h, arr.compressed_data(), arr.compressed_size()); CheckHeadersEquivalent(arr, arr2); CheckDeepCopyPerformed(arr, arr2); // cache size not preserved CheckMemberVarsCopied(arr, arr2, false); } zfp-1.0.1/tests/array/array/testArrayItersBase.cpp000066400000000000000000000123471453723256400222140ustar00rootroot00000000000000#include "gtest/gtest.h" // assumes macros ARRAY_DIMS_SCALAR_TEST, ARRAY_DIMS_SCALAR_TEST_ITERS defined class ARRAY_DIMS_SCALAR_TEST_ITERS : public ARRAY_DIMS_SCALAR_TEST {}; const SCALAR VAL = (SCALAR) 4; TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_constructedIteratorWithBegin_then_initializedToFirstPosition) { iter = arr.begin(); EXPECT_EQ(0u, ARRAY_DIMS_SCALAR_TEST::IterAbsOffset(iter)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_dereferenceIterator_then_returnsReference) { arr[0] = VAL; iter = arr.begin(); EXPECT_EQ(VAL, *iter); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_postIncrementIterator_then_advancedAfterEval) { arr[0] = VAL; iter = arr.begin(); SCALAR d = *iter++; EXPECT_EQ(VAL, d); EXPECT_EQ(1u, ARRAY_DIMS_SCALAR_TEST::IterAbsOffset(iter)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_constructedIteratorWithEnd_then_initializedAfterLastEntry) { iter = arr.begin(); for (size_t i = 0; i < arr.size(); i++, iter++); EXPECT_EQ(ARRAY_DIMS_SCALAR_TEST::IterAbsOffset(iter), ARRAY_DIMS_SCALAR_TEST::IterAbsOffset(arr.end())); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_preIncrementInterator_then_matchIteratorOffsetFromBeginning) { iter = iter2 = arr.begin(); for (size_t i = 0; iter != arr.end(); ++iter, ++i) ASSERT_TRUE(iter == iter2 + i); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_preDecrementInterator_then_matchIteratorOffsetFromEnd) { iter = iter2 = arr.end(); ptrdiff_t i = 0; do { --iter; --i; ASSERT_TRUE(iter == iter2 + i); } while (iter != arr.begin()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_preIncrementIterator_then_advancedBeforeEval) { arr[0] = VAL; iter = arr.begin(); EXPECT_EQ(0, *++iter); EXPECT_EQ(1u, ARRAY_DIMS_SCALAR_TEST::IterAbsOffset(iter)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_iterator_when_setAnotherIteratorEqualToThat_then_newIterPointsToSame) { arr[1] = VAL; iter = arr.begin(); iter2 = iter; EXPECT_EQ(ARRAY_DIMS_SCALAR_TEST::IterAbsOffset(iter), ARRAY_DIMS_SCALAR_TEST::IterAbsOffset(iter2)); EXPECT_EQ(VAL, *++iter2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayAndIndexIterators_when_compareForEquality_then_resultTrue) { iter = arr.begin()++; iter2 = arr.begin()++; EXPECT_TRUE(iter == iter2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_differentIndexIterators_when_compareForInequality_then_resultTrue) { iter = arr.begin(); iter2 = arr.end(); EXPECT_TRUE(iter != iter2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_differentArrayIterators_when_compareForInequality_then_resultTrue) { iter = arr.begin(); iter2 = arr2.begin(); EXPECT_TRUE(iter != iter2); } // const iterators TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_constructedConstIteratorWithBegin_then_initializedToFirstPosition) { citer = arr.cbegin(); EXPECT_EQ(0u, ARRAY_DIMS_SCALAR_TEST::IterAbsOffset(citer)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_dereferenceConstIterator_then_returnsReference) { arr[0] = VAL; citer = arr.cbegin(); EXPECT_EQ(VAL, *citer); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_postIncrementConstIterator_then_advancedAfterEval) { arr[0] = VAL; citer = arr.cbegin(); SCALAR d = *citer++; EXPECT_EQ(VAL, d); EXPECT_EQ(1u, ARRAY_DIMS_SCALAR_TEST::IterAbsOffset(citer)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_constructedConstIteratorWithEnd_then_initializedAfterLastEntry) { citer = arr.cbegin(); for (size_t i = 0; i < arr.size(); i++, citer++); EXPECT_EQ(ARRAY_DIMS_SCALAR_TEST::IterAbsOffset(citer), ARRAY_DIMS_SCALAR_TEST::IterAbsOffset(arr.cend())); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_preIncrementConstInterator_then_matchIteratorOffsetFromBeginning) { citer = citer2 = arr.cbegin(); for (size_t i = 0; citer != arr.cend(); ++citer, ++i) EXPECT_TRUE(citer == citer2 + i); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_preDecrementConstInterator_then_matchIteratorOffsetFromEnd) { citer = citer2 = arr.cend(); ptrdiff_t i = 0; do { --citer; --i; EXPECT_TRUE(citer == citer2 + i); } while (citer != arr.cbegin()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, when_preIncrementConstIterator_then_advancedBeforeEval) { arr[0] = VAL; citer = arr.cbegin(); EXPECT_EQ(0, *++citer); EXPECT_EQ(1u, ARRAY_DIMS_SCALAR_TEST::IterAbsOffset(citer)); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_const_iterator_when_setAnotherConstIteratorEqualToThat_then_newIterPointsToSame) { arr[1] = VAL; citer = arr.cbegin(); citer2 = citer; EXPECT_EQ(ARRAY_DIMS_SCALAR_TEST::IterAbsOffset(citer), ARRAY_DIMS_SCALAR_TEST::IterAbsOffset(citer2)); EXPECT_EQ(VAL, *++citer2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_sameArrayAndIndexConstIterators_when_compareForEquality_then_resultTrue) { citer = arr.cbegin()++; citer2 = arr.cbegin()++; EXPECT_TRUE(citer == citer2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_differentIndexConstIterators_when_compareForInequality_then_resultTrue) { citer = arr.cbegin(); citer2 = arr.cend(); EXPECT_TRUE(citer != citer2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_ITERS, given_differentArrayConstIterators_when_compareForInequality_then_resultTrue) { citer = arr.cbegin(); citer2 = arr2.cbegin(); EXPECT_TRUE(iter != iter2); } int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/array/testArrayPtrsBase.cpp000066400000000000000000000200561453723256400220520ustar00rootroot00000000000000#include "gtest/gtest.h" // assumes macros ARRAY_DIMS_SCALAR_TEST, ARRAY_DIMS_SCALAR_TEST_PTRS defined class ARRAY_DIMS_SCALAR_TEST_PTRS : public ARRAY_DIMS_SCALAR_TEST {}; const SCALAR VAL = (SCALAR) 4; TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryPointer_when_dereference_then_originalValueReturned) { arr[0] = VAL; SCALAR d = *(&arr[0]); EXPECT_EQ(VAL, d); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryPointer_when_setAnotherPtrEqualToThat_then_newPtrPointsToSameVal) { ptr = &arr[0]; ptr2 = ptr; *ptr = VAL; EXPECT_EQ(VAL, *ptr2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryPointer_when_postIncrement_then_ptrAdvancedAfterEval) { arr[1] = VAL; ptr = &arr[0]; SCALAR d = *ptr++; EXPECT_EQ(0, d); EXPECT_EQ(VAL, *ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryPointer_when_postDecrement_then_ptrAdvancedAfterEval) { arr[0] = VAL; ptr = &arr[1]; SCALAR d = *ptr--; EXPECT_EQ(0, d); EXPECT_EQ(VAL, *ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, when_preIncrementPointer_then_matchPointerOffsetFromBeginning) { ptr = ptr2 = &arr[0]; for (size_t i = 0; i != arr.size(); ++i, ++ptr) EXPECT_TRUE(ptr == ptr2 + i); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, when_preDecrementPointer_then_matchPointerOffsetFromEnd) { ptr = ptr2 = &arr[arr.size() - 1]; for (size_t i = 0; i != arr.size(); ++i, --ptr) EXPECT_TRUE(ptr == ptr2 - i); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryPointer_when_preIncrement_then_ptrAdvancedBeforeEval) { arr[1] = VAL; ptr = &arr[0]; EXPECT_EQ(VAL, *++ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryPointer_when_preDecrement_then_ptrAdvancedBeforeEval) { arr[0] = VAL; ptr = &arr[1]; EXPECT_EQ(VAL, *--ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryPointer_when_addToPointer_then_ptrAdvanced) { arr[2] = VAL; ptr = &arr[0]; ptr = ptr + 2; EXPECT_EQ(VAL, *ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryPointer_when_advanceUsingBrackets_then_returnsReferenceAtAdvancedLocation) { arr[2] = VAL; ptr = &arr[0]; EXPECT_EQ(VAL, ptr[2]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryPointer_when_pointerPlusEquals_then_ptrAdvanced) { arr[2] = VAL; ptr = &arr[0]; ptr += 2; EXPECT_EQ(VAL, *ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryPointer_when_subtractFromPointer_then_ptrMovedBack) { arr[0] = VAL; ptr = &arr[2]; ptr = ptr - 2; EXPECT_EQ(VAL, *ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryPointer_when_pointerMinusEquals_then_ptrMovedBack) { arr[0] = VAL; ptr = &arr[2]; ptr -= 2; EXPECT_EQ(VAL, *ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryPointers_when_subtractPointers_then_resultIsEntryDifference) { int i2 = 2; int i = 0; ptr2 = &arr[i2]; ptr = &arr[i]; EXPECT_EQ(i2 - i, ptr2 - ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_sameEntryPointers_when_compareForEquality_then_resultTrue) { int i = 0; ptr = &arr[i] + 2; ptr2 = &arr[i + 2]; EXPECT_TRUE(ptr == ptr2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_differentEntryPointers_when_compareForInequality_then_resultTrue) { int i = 0; ptr = &arr[i]; ptr2 = &arr[i + 2]; EXPECT_TRUE(ptr != ptr2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_differentArrayPointers_when_compareForInequality_then_resultTrue) { int i = 0; ptr = &arr[i]; ptr2 = &arr2[i]; EXPECT_TRUE(ptr != ptr2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_increasingEntryPointers_when_compareForLessThan_then_resultTrue) { int i = 0; ptr = &arr[i]; ptr2 = &arr[i + 2]; EXPECT_TRUE(ptr < ptr2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_increasingEntryPointers_when_compareForLessThanOrEqual_then_resultTrue) { int i = 0; ptr = &arr[i]; ptr2 = &arr[i + 2]; EXPECT_TRUE(ptr <= ptr); EXPECT_TRUE(ptr <= ptr2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_decreasingEntryPointers_when_compareForGreaterThan_then_resultTrue) { int i = 0; ptr = &arr[i]; ptr2 = &arr[i + 2]; EXPECT_TRUE(ptr2 > ptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_decreasingEntryPointers_when_compareForGreaterThanOrEqual_then_resultTrue) { int i = 0; ptr = &arr[i]; ptr2 = &arr[i + 2]; EXPECT_TRUE(ptr >= ptr); EXPECT_TRUE(ptr2 >= ptr); } // const pointers TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryConstPointer_when_postIncrement_then_ptrAdvancedAfterEval) { arr[1] = VAL; cptr = &arr[0]; SCALAR d = *cptr++; EXPECT_EQ(0, d); EXPECT_EQ(VAL, *cptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryConstPointer_when_postDecrement_then_ptrAdvancedAfterEval) { arr[0] = VAL; cptr = &arr[1]; SCALAR d = *cptr--; EXPECT_EQ(0, d); EXPECT_EQ(VAL, *cptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, when_preIncrementConstPointer_then_matchPointerOffsetFromBeginning) { cptr = cptr2 = &arr[0]; for (size_t i = 0; i != arr.size(); ++i, ++cptr) EXPECT_TRUE(cptr == cptr2 + i); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, when_preDecrementConstPointer_then_matchPointerOffsetFromEnd) { cptr = cptr2 = &arr[arr.size() - 1]; for (size_t i = 0; i != arr.size(); ++i, --cptr) EXPECT_TRUE(cptr == cptr2 - i); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryConstPointer_when_preIncrement_then_ptrAdvancedBeforeEval) { arr[1] = VAL; cptr = &arr[0]; EXPECT_EQ(VAL, *++cptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryConstPointer_when_preDecrement_then_ptrAdvancedBeforeEval) { arr[0] = VAL; cptr = &arr[1]; EXPECT_EQ(VAL, *--cptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryConstPointer_when_addToPointer_then_ptrAdvanced) { arr[2] = VAL; cptr = &arr[0]; cptr = ptr + 2; EXPECT_EQ(VAL, *cptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryConstPointer_when_advanceUsingBrackets_then_returnsReferenceAtAdvancedLocation) { arr[2] = VAL; cptr = &arr[0]; EXPECT_EQ(VAL, cptr[2]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryConstPointer_when_pointerPlusEquals_then_ptrAdvanced) { arr[2] = VAL; cptr = &arr[0]; cptr += 2; EXPECT_EQ(VAL, *cptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryConstPointer_when_subtractFromPointer_then_ptrMovedBack) { arr[0] = VAL; cptr = &arr[2]; cptr = cptr - 2; EXPECT_EQ(VAL, *cptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryConstPointer_when_pointerMinusEquals_then_ptrMovedBack) { arr[0] = VAL; cptr = &arr[2]; cptr -= 2; EXPECT_EQ(VAL, *cptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_entryConstPointers_when_subtractPointers_then_resultIsEntryDifference) { int i2 = 2; int i = 0; cptr2 = &arr[i2]; cptr = &arr[i]; EXPECT_EQ(i2 - i, cptr2 - cptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_sameEntryConstPointers_when_compareForEquality_then_resultTrue) { int i = 0; cptr = &arr[i] + 2; cptr2 = &arr[i + 2]; EXPECT_TRUE(cptr == cptr2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_differentEntryConstPointers_when_compareForInequality_then_resultTrue) { int i = 0; cptr = &arr[i]; cptr2 = &arr[i + 2]; EXPECT_TRUE(cptr != cptr2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_differentArrayConstPointers_when_compareForInequality_then_resultTrue) { int i = 0; cptr = &arr[i]; cptr2 = &arr2[i]; EXPECT_TRUE(cptr != cptr2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_increasingEntryConstPointers_when_compareForLessThan_then_resultTrue) { int i = 0; cptr = &arr[i]; cptr2 = &arr[i + 2]; EXPECT_TRUE(cptr < cptr2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_increasingEntryConstPointers_when_compareForLessThanOrEqual_then_resultTrue) { int i = 0; cptr = &arr[i]; cptr2 = &arr[i + 2]; EXPECT_TRUE(cptr <= cptr); EXPECT_TRUE(cptr <= cptr2); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_decreasingEntryConstPointers_when_compareForGreaterThan_then_resultTrue) { int i = 0; cptr = &arr[i]; cptr2 = &arr[i + 2]; EXPECT_TRUE(cptr2 > cptr); } TEST_F(ARRAY_DIMS_SCALAR_TEST_PTRS, given_decreasingEntryConstPointers_when_compareForGreaterThanOrEqual_then_resultTrue) { int i = 0; cptr = &arr[i]; cptr2 = &arr[i + 2]; EXPECT_TRUE(cptr >= cptr); EXPECT_TRUE(cptr2 >= cptr); } int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/array/testArrayRefsBase.cpp000066400000000000000000000062061453723256400220220ustar00rootroot00000000000000#include "gtest/gtest.h" #include "utils/predicates.h" extern "C" { #include "utils/zfpHash.h" } // assumes macros ARRAY_DIMS_SCALAR_TEST, ARRAY_DIMS_SCALAR_TEST_REFS defined class ARRAY_DIMS_SCALAR_TEST_REFS : public ARRAY_DIMS_SCALAR_TEST {}; const SCALAR VAL = (SCALAR) 4; TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_setEntryWithEquals_then_entrySetInCacheOnly) { // compressed_data() automatically flushes cache, so call it before setting entries void* bitstreamPtr = arr.compressed_data(); size_t bitstreamLen = arr.compressed_size(); uint64 initializedChecksum = hashBitstream((uint64*)bitstreamPtr, bitstreamLen); arr[0] = VAL; uint64 checksum = hashBitstream((uint64*)bitstreamPtr, bitstreamLen); EXPECT_PRED_FORMAT2(ExpectEqPrintHexPred, initializedChecksum, checksum); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, given_dirtyCacheEntries_when_clearCache_then_cacheCleared) { uint64 initializedChecksum = hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size()); arr[0] = VAL; arr.clear_cache(); uint64 checksum = hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size()); EXPECT_PRED_FORMAT2(ExpectEqPrintHexPred, initializedChecksum, checksum); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, given_setEntryWithEquals_when_flushCache_then_entryWrittenToBitstream) { uint64 initializedChecksum = hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size()); arr[0] = VAL; uint64 checksum = hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size()); EXPECT_PRED_FORMAT2(ExpectNeqPrintHexPred, initializedChecksum, checksum); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_setCacheSize_then_properlySet) { size_t oldSize = arr.cache_size(); size_t newSize = oldSize * 2; arr.set_cache_size(newSize); EXPECT_EQ(newSize, arr.cache_size()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_getIndexWithBrackets_then_refReturned) { size_t i = 0; arr[i] = VAL; EXPECT_EQ(VAL, arr[i]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_setEntryWithAnotherEntryValue_then_valueSet) { size_t i = 0, i2 = 1; arr[i] = VAL; arr[i2] = arr[i]; EXPECT_EQ(VAL, arr[i2]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_plusEqualsOnEntry_then_valueSet) { size_t i = 0, i2 = 1; arr[i] = VAL; arr[i2] = VAL; arr[i2] += arr[i]; EXPECT_EQ(2 * VAL, arr[i2]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_minusEqualsOnEntry_then_valueSet) { size_t i = 0, i2 = 1; arr[i] = VAL; arr[i2] = VAL; arr[i2] -= arr[i]; EXPECT_EQ(0, arr[i2]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_timesEqualsOnEntry_then_valueSet) { size_t i = 0, i2 = 1; arr[i] = VAL; arr[i2] = VAL; arr[i2] *= arr[i]; EXPECT_EQ(VAL * VAL, arr[i2]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_divideEqualsOnEntry_then_valueSet) { size_t i = 0, i2 = 1; arr[i] = VAL; arr[i2] = VAL; arr[i2] /= arr[i]; EXPECT_EQ(1, arr[i2]); } TEST_F(ARRAY_DIMS_SCALAR_TEST_REFS, when_swapTwoEntries_then_valuesSwapped) { size_t i = 0, i2 = 1; arr[i] = VAL; swap(arr[i], arr[i2]); EXPECT_EQ(0, arr[i]); EXPECT_EQ(VAL, arr[i2]); } int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/array/testArrayViewItersBase.cpp000066400000000000000000000062401453723256400230420ustar00rootroot00000000000000#include "gtest/gtest.h" #include "utils/predicates.h" // assumes macros ARRAY_DIMS_SCALAR_TEST, ARRAY_DIMS_SCALAR_TEST_VIEW_ITERS defined class ARRAY_DIMS_SCALAR_TEST_VIEW_ITERS : public ARRAY_DIMS_SCALAR_TEST {}; // views TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEW_ITERS, when_preIncrementInterator_then_matchIteratorOffsetFromBeginning) { #if DIMS == 1 ZFP_ARRAY_TYPE::view v(&arr, offset, viewLen); #elif DIMS == 2 ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, viewLenX, viewLenY); #elif DIMS == 3 ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); #elif DIMS == 4 ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); #endif ZFP_ARRAY_TYPE::view::iterator iter = v.begin(); ZFP_ARRAY_TYPE::view::iterator iter2 = iter; for (size_t i = 0; iter != v.end(); ++iter, ++i) EXPECT_TRUE(iter == iter2 + i); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEW_ITERS, when_preDecrementInterator_then_matchIteratorOffsetFromEnd) { #if DIMS == 1 ZFP_ARRAY_TYPE::view v(&arr, offset, viewLen); #elif DIMS == 2 ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, viewLenX, viewLenY); #elif DIMS == 3 ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); #elif DIMS == 4 ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); #endif ZFP_ARRAY_TYPE::view::iterator iter = v.end(); ZFP_ARRAY_TYPE::view::iterator iter2 = iter; ptrdiff_t i = 0; do { --iter; --i; EXPECT_TRUE(iter == iter2 + i); } while (iter != v.begin()); } // const views TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEW_ITERS, when_preIncrementConstInterator_then_matchIteratorOffsetFromBeginning) { #if DIMS == 1 ZFP_ARRAY_TYPE::const_view v(&arr, offset, viewLen); #elif DIMS == 2 ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); #elif DIMS == 3 ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); #elif DIMS == 4 ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); #endif ZFP_ARRAY_TYPE::const_view::const_iterator iter = v.begin(); ZFP_ARRAY_TYPE::const_view::const_iterator iter2 = iter; for (size_t i = 0; iter != v.end(); ++iter, ++i) EXPECT_TRUE(iter == iter2 + i); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEW_ITERS, when_preDecrementConstInterator_then_matchIteratorOffsetFromEnd) { #if DIMS == 1 ZFP_ARRAY_TYPE::const_view v(&arr, offset, viewLen); #elif DIMS == 2 ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); #elif DIMS == 3 ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); #elif DIMS == 4 ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); #endif ZFP_ARRAY_TYPE::const_view::const_iterator iter = v.end(); ZFP_ARRAY_TYPE::const_view::const_iterator iter2 = iter; ptrdiff_t i = 0; do { --iter; --i; EXPECT_TRUE(iter == iter2 + i); } while (iter != v.begin()); } int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/array/testArrayViewPtrsBase.cpp000066400000000000000000000076621453723256400227150ustar00rootroot00000000000000#include "gtest/gtest.h" #include "utils/predicates.h" // assumes macros ARRAY_DIMS_SCALAR_TEST, ARRAY_DIMS_SCALAR_TEST_VIEW_PTRS defined class ARRAY_DIMS_SCALAR_TEST_VIEW_PTRS : public ARRAY_DIMS_SCALAR_TEST {}; // views TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEW_PTRS, when_preIncrementInterator_then_matchPointerOffsetFromBeginning) { #if DIMS == 1 ZFP_ARRAY_TYPE::view v(&arr, offset, viewLen); ZFP_ARRAY_TYPE::view::pointer ptr = &v(0); #elif DIMS == 2 ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE::view::pointer ptr = &v(0, 0); #elif DIMS == 3 ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE::view::pointer ptr = &v(0, 0, 0); #elif DIMS == 4 ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE::view::pointer ptr = &v(0, 0, 0, 0); #endif ZFP_ARRAY_TYPE::view::pointer ptr2 = ptr; for (size_t i = 0; i != v.size(); ++i, ++ptr) EXPECT_TRUE(ptr == ptr2 + i); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEW_PTRS, when_preDecrementInterator_then_matchPointerOffsetFromEnd) { #if DIMS == 1 ZFP_ARRAY_TYPE::view v(&arr, offset, viewLen); ZFP_ARRAY_TYPE::view::pointer ptr = &v(viewLen - 1); #elif DIMS == 2 ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE::view::pointer ptr = &v(viewLenX - 1, viewLenY - 1); #elif DIMS == 3 ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE::view::pointer ptr = &v(viewLenX - 1, viewLenY - 1, viewLenZ - 1); #elif DIMS == 4 ZFP_ARRAY_TYPE::view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE::view::pointer ptr = &v(viewLenX - 1, viewLenY - 1, viewLenZ - 1, viewLenW - 1); #endif ZFP_ARRAY_TYPE::view::pointer ptr2 = ptr; for (size_t i = 0; i != v.size(); ++i, --ptr) EXPECT_TRUE(ptr == ptr2 - i); } // const views TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEW_PTRS, when_preIncrementConstInterator_then_matchPointerOffsetFromBeginning) { #if DIMS == 1 ZFP_ARRAY_TYPE::const_view v(&arr, offset, viewLen); ZFP_ARRAY_TYPE::const_view::const_pointer ptr = &v(0); #elif DIMS == 2 ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE::const_view::const_pointer ptr = &v(0, 0); #elif DIMS == 3 ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE::const_view::const_pointer ptr = &v(0, 0, 0); #elif DIMS == 4 ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE::const_view::const_pointer ptr = &v(0, 0, 0, 0); #endif ZFP_ARRAY_TYPE::const_view::const_pointer ptr2 = ptr; for (size_t i = 0; i != v.size(); ++i, ++ptr) EXPECT_TRUE(ptr == ptr2 + i); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEW_PTRS, when_preDecrementConstInterator_then_matchPointerOffsetFromEnd) { #if DIMS == 1 ZFP_ARRAY_TYPE::const_view v(&arr, offset, viewLen); ZFP_ARRAY_TYPE::const_view::const_pointer ptr = &v(viewLen - 1); #elif DIMS == 2 ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); ZFP_ARRAY_TYPE::const_view::const_pointer ptr = &v(viewLenX - 1, viewLenY - 1); #elif DIMS == 3 ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); ZFP_ARRAY_TYPE::const_view::const_pointer ptr = &v(viewLenX - 1, viewLenY - 1, viewLenZ - 1); #elif DIMS == 4 ZFP_ARRAY_TYPE::const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); ZFP_ARRAY_TYPE::const_view::const_pointer ptr = &v(viewLenX - 1, viewLenY - 1, viewLenZ - 1, viewLenW - 1); #endif ZFP_ARRAY_TYPE::const_view::const_pointer ptr2 = ptr; for (size_t i = 0; i != v.size(); ++i, --ptr) EXPECT_TRUE(ptr == ptr2 - i); } int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/array/testArrayViewsBase.cpp000066400000000000000000000313331453723256400222170ustar00rootroot00000000000000#include "gtest/gtest.h" #include "utils/predicates.h" // assumes macros ARRAY_DIMS_SCALAR_TEST, ARRAY_DIMS_SCALAR_TEST_VIEWS defined class ARRAY_DIMS_SCALAR_TEST_VIEWS : public ARRAY_DIMS_SCALAR_TEST {}; /* preview, through const_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_constView_when_rate_then_rateReturned) { ZFP_ARRAY_TYPE::const_view v(&arr); EXPECT_EQ(arr.rate(), v.rate()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_previewMinConstructor_then_spansEntireArray) { ZFP_ARRAY_TYPE::const_view v(&arr); EXPECT_EQ(arr.size(), v.size()); EXPECT_EQ(arr.size_x(), v.size_x()); EXPECT_EQ(0, v.global_x(0)); #if DIMS >= 2 EXPECT_EQ(arr.size_y(), v.size_y()); EXPECT_EQ(0, v.global_y(0)); #endif #if DIMS >= 3 EXPECT_EQ(arr.size_z(), v.size_z()); EXPECT_EQ(0, v.global_z(0)); #endif #if DIMS >= 4 EXPECT_EQ(arr.size_w(), v.size_w()); EXPECT_EQ(0, v.global_w(0)); #endif } /* const_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_constViewMinConstructor_then_spansEntireArray) { ZFP_ARRAY_TYPE::const_view v(&arr); EXPECT_EQ(arr.size(), v.size()); EXPECT_EQ(arr.size_x(), v.size_x()); EXPECT_EQ(0, v.global_x(0)); #if DIMS >= 2 EXPECT_EQ(arr.size_y(), v.size_y()); EXPECT_EQ(0, v.global_y(0)); #endif #if DIMS >= 3 EXPECT_EQ(arr.size_z(), v.size_z()); EXPECT_EQ(0, v.global_z(0)); #endif #if DIMS >= 4 EXPECT_EQ(arr.size_w(), v.size_w()); EXPECT_EQ(0, v.global_w(0)); #endif } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_constViewMinConstructor_then_isShallowCopyOfCompressedArray) { ZFP_ARRAY_TYPE::const_view v(&arr); size_t i = 0; SCALAR val; size_t arrOffset = i; #if DIMS >= 2 size_t j = 0; arrOffset += j*arr.size_x(); #endif #if DIMS >= 3 size_t k = 0; arrOffset = k*arr.size_x()*arr.size_y(); #endif #if DIMS >= 4 size_t l = 0; arrOffset = l*arr.size_x()*arr.size_y()*arr.size_z(); #endif #if DIMS == 1 val = v(i); #elif DIMS == 2 val = v(i, j); #elif DIMS == 3 val = v(i, j, k); #elif DIMS == 4 val = v(i, j, k, l); #endif SCALAR oldVal = arr[arrOffset]; EXPECT_EQ(oldVal, val); arr[arrOffset] += 1; SCALAR newVal = arr[arrOffset]; EXPECT_NE(oldVal, newVal); #if DIMS == 1 val = v(i); #elif DIMS == 2 val = v(i, j); #elif DIMS == 3 val = v(i, j, k); #elif DIMS == 4 val = v(i, j, k, l); #endif EXPECT_EQ(newVal, val); } /* view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_viewMinConstructor_then_spansEntireArray) { ZFP_ARRAY_TYPE::view v(&arr); EXPECT_EQ(arr.size(), v.size()); EXPECT_EQ(arr.size_x(), v.size_x()); EXPECT_EQ(0, v.global_x(0)); #if DIMS >= 2 EXPECT_EQ(arr.size_y(), v.size_y()); EXPECT_EQ(0, v.global_y(0)); #endif #if DIMS >= 3 EXPECT_EQ(arr.size_z(), v.size_z()); EXPECT_EQ(0, v.global_z(0)); #endif #if DIMS >= 4 EXPECT_EQ(arr.size_w(), v.size_w()); EXPECT_EQ(0, v.global_w(0)); #endif } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_viewMinConstructor_then_isShallowCopyOfCompressedArray) { ZFP_ARRAY_TYPE::view v(&arr); size_t i = 0; SCALAR val; size_t arrOffset = i; #if DIMS >= 2 size_t j = 0; arrOffset += j*arr.size_x(); #endif #if DIMS >= 3 size_t k = 0; arrOffset += k*arr.size_x()*arr.size_y(); #endif #if DIMS >= 4 size_t l = 0; arrOffset += l*arr.size_x()*arr.size_y()*arr.size_z(); #endif #if DIMS == 1 val = v(i); #elif DIMS == 2 val = v(i, j); #elif DIMS == 3 val = v(i, j, k); #elif DIMS == 4 val = v(i, j, k, l); #endif SCALAR oldVal = arr[arrOffset]; EXPECT_EQ(oldVal, val); arr[arrOffset] += 1; SCALAR newVal = arr[arrOffset]; EXPECT_NE(oldVal, newVal); #if DIMS == 1 val = v(i); #elif DIMS == 2 val = v(i, j); #elif DIMS == 3 val = v(i, j, k); #elif DIMS == 4 val = v(i, j, k, l); #endif EXPECT_EQ(newVal, val); } #if DIMS >= 2 /* flat_view (only in 2D, 3D, 4D) */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_flatViewMinConstructor_then_spansEntireArray) { ZFP_ARRAY_TYPE::flat_view v(&arr); EXPECT_EQ(arr.size(), v.size()); EXPECT_EQ(arr.size_x(), v.size_x()); EXPECT_EQ(0, v.global_x(0)); #if DIMS >= 2 EXPECT_EQ(arr.size_y(), v.size_y()); EXPECT_EQ(0, v.global_y(0)); #endif #if DIMS >= 3 EXPECT_EQ(arr.size_z(), v.size_z()); EXPECT_EQ(0, v.global_z(0)); #endif #if DIMS >= 4 EXPECT_EQ(arr.size_w(), v.size_w()); EXPECT_EQ(0, v.global_w(0)); #endif } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_flatViewMinConstructor_then_isShallowCopyOfCompressedArray) { ZFP_ARRAY_TYPE::flat_view v(&arr); size_t i = 0; SCALAR val; size_t arrOffset = i; #if DIMS >= 2 size_t j = 0; arrOffset += j*arr.size_x(); #endif #if DIMS >= 3 size_t k = 0; arrOffset += k*arr.size_x()*arr.size_y(); #endif #if DIMS >= 4 size_t l = 0; arrOffset += l*arr.size_x()*arr.size_y()*arr.size_z(); #endif #if DIMS == 1 val = v(i); #elif DIMS == 2 val = v(i, j); #elif DIMS == 3 val = v(i, j, k); #elif DIMS == 4 val = v(i, j, k, l); #endif SCALAR oldVal = arr[arrOffset]; EXPECT_EQ(oldVal, val); arr[arrOffset] += 1; SCALAR newVal = arr[arrOffset]; EXPECT_NE(oldVal, newVal); #if DIMS == 1 val = v(i); #elif DIMS == 2 val = v(i, j); #elif DIMS == 3 val = v(i, j, k); #elif DIMS == 4 val = v(i, j, k, l); #endif EXPECT_EQ(newVal, val); } /* nested_view (only in 2D, 3D, 4D) */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_nestedViewMinConstructor_then_spansEntireArray) { ZFP_ARRAY_TYPE::nested_view v(&arr); EXPECT_EQ(arr.size(), v.size()); EXPECT_EQ(arr.size_x(), v.size_x()); EXPECT_EQ(0, v.global_x(0)); EXPECT_EQ(arr.size_y(), v.size_y()); EXPECT_EQ(0, v.global_y(0)); #if DIMS >= 3 EXPECT_EQ(arr.size_z(), v.size_z()); EXPECT_EQ(0, v.global_z(0)); #endif #if DIMS >= 4 EXPECT_EQ(arr.size_w(), v.size_w()); EXPECT_EQ(0, v.global_w(0)); #endif } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_nestedViewMinConstructor_then_isShallowCopyOfCompressedArray) { ZFP_ARRAY_TYPE::nested_view v(&arr); size_t i = 0; SCALAR val; size_t arrOffset = i; size_t j = 0; arrOffset += j*arr.size_x(); #if DIMS >= 3 size_t k = 0; arrOffset += k*arr.size_x()*arr.size_y(); #endif #if DIMS >= 4 size_t l = 0; arrOffset += l*arr.size_x()*arr.size_y()*arr.size_w(); #endif #if DIMS == 2 val = v(i, j); #elif DIMS == 3 val = v(i, j, k); #elif DIMS == 4 val = v(i, j, k, l); #endif SCALAR oldVal = arr[arrOffset]; EXPECT_EQ(oldVal, val); arr[arrOffset] += 1; SCALAR newVal = arr[arrOffset]; EXPECT_NE(oldVal, newVal); #if DIMS == 2 val = v(i, j); #elif DIMS == 3 val = v(i, j, k); #elif DIMS == 4 val = v(i, j, k, l); #endif EXPECT_EQ(newVal, val); } #endif /* private_const_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_privateConstViewMinConstructor_then_spansEntireArray) { ZFP_ARRAY_TYPE::private_const_view v(&arr); EXPECT_EQ(v.size(), arr.size()); EXPECT_EQ(v.size_x(), arr.size_x()); EXPECT_EQ(v.global_x(0), 0); #if DIMS >= 2 EXPECT_EQ(v.size_y(), arr.size_y()); EXPECT_EQ(0, v.global_y(0)); #endif #if DIMS >= 3 EXPECT_EQ(v.size_z(), arr.size_z()); EXPECT_EQ(0, v.global_z(0)); #endif #if DIMS >= 4 EXPECT_EQ(v.size_w(), arr.size_w()); EXPECT_EQ(0, v.global_w(0)); #endif } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_privateConstViewMinConstructor_then_cacheSizeEqualToArrayCacheSize) { arr.set_cache_size(999); size_t cacheSize = arr.cache_size(); ZFP_ARRAY_TYPE::private_const_view v(&arr); EXPECT_EQ(cacheSize, v.cache_size()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_privateConstViewFullConstructor_then_cacheSizeEqualToArrayCacheSize) { arr.set_cache_size(999); size_t cacheSize = arr.cache_size(); size_t offsetX = 5, viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); #if DIMS >= 2 size_t offsetY = 1, viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); #endif #if DIMS >= 3 size_t offsetZ = 0, viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); #endif #if DIMS >= 4 size_t offsetW = 1, viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); #endif #if DIMS == 1 ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, viewLenX); #elif DIMS == 2 ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); #elif DIMS == 3 ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); #elif DIMS == 4 ZFP_ARRAY_TYPE::private_const_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); #endif EXPECT_EQ(cacheSize, v.cache_size()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_privateConstView_when_setCacheSize_then_isSet) { arr.set_cache_size(4096); ZFP_ARRAY_TYPE::private_const_view v(&arr); size_t cacheSize = v.cache_size(); v.set_cache_size(cacheSize / 2); EXPECT_NE(cacheSize, v.cache_size()); } /* this also verifies underlying array is shallow copy */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_privateConstViewWithDirtyCache_when_clearCache_then_entriesCleared) { SCALAR val = 3.3; size_t i = 2; size_t arrOffset = i; #if DIMS >= 2 size_t j = 1; arrOffset += j*arr.size_x(); #endif #if DIMS >= 3 size_t k = 1; arrOffset += k*arr.size_x()*arr.size_y(); #endif #if DIMS >= 4 size_t l = 1; arrOffset += l*arr.size_x()*arr.size_y()*arr.size_z(); #endif arr[arrOffset] = val; arr.flush_cache(); /* has its own cache */ ZFP_ARRAY_TYPE::private_const_view v(&arr); #if DIMS == 1 val = v(i); #elif DIMS == 2 val = v(i, j); #elif DIMS == 3 val = v(i, j, k); #elif DIMS == 4 val = v(i, j, k, l); #endif EXPECT_EQ(arr[arrOffset], val); /* accessing v() fetched block into view-cache */ arr[arrOffset] = 0; arr.flush_cache(); /* block already in view-cache, not fetched from mem */ #if DIMS == 1 val = v(i); #elif DIMS == 2 val = v(i, j); #elif DIMS == 3 val = v(i, j, k); #elif DIMS == 4 val = v(i, j, k, l); #endif EXPECT_NE(arr[arrOffset], val); /* re-loading the block has updated value */ v.clear_cache(); #if DIMS == 1 val = v(i); #elif DIMS == 2 val = v(i, j); #elif DIMS == 3 val = v(i, j, k); #elif DIMS == 4 val = v(i, j, k, l); #endif EXPECT_EQ(arr[arrOffset], val); } /* private_view */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_privateViewMinConstructor_then_spansEntireArray) { ZFP_ARRAY_TYPE::private_view v(&arr); EXPECT_EQ(v.size(), arr.size()); EXPECT_EQ(v.size_x(), arr.size_x()); EXPECT_EQ(0, v.global_x(0)); #if DIMS >= 2 EXPECT_EQ(v.size_y(), arr.size_y()); EXPECT_EQ(0, v.global_y(0)); #endif #if DIMS >= 3 EXPECT_EQ(v.size_z(), arr.size_z()); EXPECT_EQ(0, v.global_z(0)); #endif #if DIMS >= 4 EXPECT_EQ(v.size_w(), arr.size_w()); EXPECT_EQ(0, v.global_w(0)); #endif } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_privateViewMinConstructor_then_cacheSizeEqualToArrayCacheSize) { arr.set_cache_size(999); size_t cacheSize = arr.cache_size(); ZFP_ARRAY_TYPE::private_view v(&arr); EXPECT_EQ(cacheSize, v.cache_size()); } TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, when_privateViewFullConstructor_then_cacheSizeEqualToArrayCacheSize) { arr.set_cache_size(999); size_t cacheSize = arr.cache_size(); size_t offsetX = 5, viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); #if DIMS >= 2 size_t offsetY = 1, viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); #endif #if DIMS >= 3 size_t offsetZ = 0, viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); #endif #if DIMS >= 4 size_t offsetW = 1, viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); #endif #if DIMS == 1 ZFP_ARRAY_TYPE::private_view v(&arr, offsetX, viewLenX); #elif DIMS == 2 ZFP_ARRAY_TYPE::private_view v(&arr, offsetX, offsetY, viewLenX, viewLenY); #elif DIMS == 3 ZFP_ARRAY_TYPE::private_view v(&arr, offsetX, offsetY, offsetZ, viewLenX, viewLenY, viewLenZ); #elif DIMS == 4 ZFP_ARRAY_TYPE::private_view v(&arr, offsetX, offsetY, offsetZ, offsetW, viewLenX, viewLenY, viewLenZ, viewLenW); #endif EXPECT_EQ(cacheSize, v.cache_size()); } /* this also verifies underlying array is shallow copy */ TEST_F(ARRAY_DIMS_SCALAR_TEST_VIEWS, given_privateViewWithDirtyCache_when_flushCache_thenValuesPersistedToArray) { SCALAR val = 5.5; const size_t i = 3; size_t arrOffset = i; #if DIMS >= 2 size_t j = 1; arrOffset += j*arr.size_x(); #endif #if DIMS >= 3 size_t k = 1; arrOffset += k*arr.size_x()*arr.size_y(); #endif #if DIMS >= 4 size_t l = 1; arrOffset += l*arr.size_x()*arr.size_y()*arr.size_z(); #endif /* has its own cache */ ZFP_ARRAY_TYPE::private_view v(&arr); #if DIMS == 1 v(i) = val; #elif DIMS == 2 v(i, j) = val; #elif DIMS == 3 v(i, j, k) = val; #elif DIMS == 4 v(i, j, k, l) = val; #endif EXPECT_NE(val, arr[arrOffset]); /* setting and accessing v() and arr[] fetched blocks into both caches */ v.flush_cache(); EXPECT_NE(val, arr[arrOffset]); /* force arr to re-decode block from mem */ arr.clear_cache(); EXPECT_EQ(val, arr[arrOffset]); } int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/array/testConstruct.cpp000066400000000000000000000101311453723256400213050ustar00rootroot00000000000000#include "zfp/array2.hpp" #include "zfp/array3.hpp" #include "zfp/factory.hpp" using namespace zfp; #include "gtest/gtest.h" #include "utils/gtestTestEnv.h" #include "utils/gtestCApiTest.h" #define TEST_FIXTURE ZfpArrayConstructTest TestEnv* const testEnv = new TestEnv; // this file tests exceptions thrown from zfp::array::construct() that cannot be // generalized and run on every {1/2/3 x f/d} combination, or need not be run // multiple times void FailWhenNoExceptionThrown() { FAIL() << "No exception was thrown when one was expected"; } void FailAndPrintException(std::exception const & e) { FAIL() << "Unexpected exception thrown: " << typeid(e).name() << std::endl << "With message: " << e.what(); } TEST_F(TEST_FIXTURE, given_zfpHeaderForIntegerData_when_construct_expect_zfpArrayHeaderExceptionThrown) { zfp_type zfpType = zfp_type_int32; zfp_stream_set_rate(stream, 16, zfpType, 2, zfp_true); zfp_field_set_type(field, zfpType); zfp_field_set_size_2d(field, 12, 12); // write header to buffer with C API zfp_stream_rewind(stream); EXPECT_EQ(ZFP_HEADER_SIZE_BITS, zfp_write_header(stream, field, ZFP_HEADER_FULL)); zfp_stream_flush(stream); zfp::codec::zfp2::header h(buffer); try { zfp::array* arr = zfp::array::construct(h); FailWhenNoExceptionThrown(); } catch (zfp::exception const & e) { EXPECT_EQ(e.what(), std::string("zfp scalar type not supported")); } catch (std::exception const & e) { FailAndPrintException(e); } } TEST_F(TEST_FIXTURE, given_onlyInclude2D3D_and_zfpHeaderFor1D_when_construct_expect_zfpArrayHeaderExceptionThrown) { zfp_type zfpType = zfp_type_float; zfp_stream_set_rate(stream, 12, zfpType, 1, zfp_true); zfp_field_set_type(field, zfpType); zfp_field_set_size_1d(field, 12); // write header to buffer with C API zfp_stream_rewind(stream); EXPECT_EQ(ZFP_HEADER_SIZE_BITS, zfp_write_header(stream, field, ZFP_HEADER_FULL)); zfp_stream_flush(stream); zfp::codec::zfp1::header h(buffer); try { zfp::array* arr = zfp::array::construct(h); FailWhenNoExceptionThrown(); } catch (zfp::exception const & e) { EXPECT_EQ(e.what(), std::string("array1 not supported; include zfp/array1.hpp before zfp/factory.hpp")); } catch (std::exception const & e) { FailAndPrintException(e); } } TEST_F(TEST_FIXTURE, given_validHeaderBuffer_withBufferSizeTooLow_when_construct_expect_zfpArrayHeaderExceptionThrown) { zfp::array3d arr(12, 12, 12, 32); zfp::array3d::header h(arr); try { zfp::array* arr2 = zfp::array::construct(h, arr.compressed_data(), 1); FailWhenNoExceptionThrown(); } catch (zfp::exception const & e) { EXPECT_EQ(e.what(), std::string("zfp buffer size is smaller than required")); } catch (std::exception const & e) { FailAndPrintException(e); } } TEST_F(TEST_FIXTURE, given_compressedArrayWithLongHeader_when_writeHeader_expect_zfpArrayHeaderExceptionThrown) { zfp::array3d arr(12, 12, 12, 33); try { zfp::array3d::header h(arr); FailWhenNoExceptionThrown(); } catch (zfp::exception const & e) { EXPECT_EQ(e.what(), std::string("zfp serialization supports only short headers")); } catch (std::exception const & e) { FailAndPrintException(e); } } TEST_F(TEST_FIXTURE, when_headerFrom2DArray_expect_MatchingMetadata) { zfp::array2d arr(7, 8, 32); zfp::array2d::header h(arr); EXPECT_EQ(h.scalar_type(), arr.scalar_type()); EXPECT_EQ(h.rate(), arr.rate()); EXPECT_EQ(h.dimensionality(), arr.dimensionality()); EXPECT_EQ(h.size_x(), arr.size_x()); EXPECT_EQ(h.size_y(), arr.size_y()); } TEST_F(TEST_FIXTURE, when_headerFrom3DArray_expect_MatchingMetadata) { zfp::array3d arr(7, 8, 9, 32); zfp::array3d::header h(arr); EXPECT_EQ(h.scalar_type(), arr.scalar_type()); EXPECT_EQ(h.rate(), arr.rate()); EXPECT_EQ(h.dimensionality(), arr.dimensionality()); EXPECT_EQ(h.size_x(), arr.size_x()); EXPECT_EQ(h.size_y(), arr.size_y()); EXPECT_EQ(h.size_z(), arr.size_z()); } int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/constArray/000077500000000000000000000000001453723256400167305ustar00rootroot00000000000000zfp-1.0.1/tests/array/constArray/CMakeLists.txt000066400000000000000000000012021453723256400214630ustar00rootroot00000000000000function(zfp_add_cpp_tests dims type bits) # test compressed const array class set(test_name testConstArray${dims}${type}) add_executable(${test_name} ${test_name}.cpp) target_link_libraries(${test_name} gtest gtest_main zfp zfpHashLib genSmoothRandNumsLib zfpChecksumsLib) target_compile_definitions(${test_name} PRIVATE ${zfp_compressed_array_defs}) add_test(NAME ${test_name} COMMAND ${test_name}) endfunction() zfp_add_cpp_tests(1 f 32) zfp_add_cpp_tests(2 f 32) zfp_add_cpp_tests(3 f 32) zfp_add_cpp_tests(4 f 32) zfp_add_cpp_tests(1 d 64) zfp_add_cpp_tests(2 d 64) zfp_add_cpp_tests(3 d 64) zfp_add_cpp_tests(4 d 64) zfp-1.0.1/tests/array/constArray/testConstArray1Base.cpp000066400000000000000000000000011453723256400232640ustar00rootroot00000000000000 zfp-1.0.1/tests/array/constArray/testConstArray1d.cpp000066400000000000000000000023201453723256400226430ustar00rootroot00000000000000#include "zfp/constarray1.hpp" #include "zfp/constarray2.hpp" #include "zfp/constarray3.hpp" #include "zfp/constarray4.hpp" #include "zfp/factory.hpp" using namespace zfp; extern "C" { #include "constants/1dDouble.h" } #include "gtest/gtest.h" #include "utils/gtestDoubleEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class CArray1dTestEnv : public ArrayDoubleTestEnv { public: virtual int getDims() { return 1; } }; CArray1dTestEnv* const testEnv = new CArray1dTestEnv; class CArray1dTest : public CArrayNdTestFixture {}; #define TEST_FIXTURE CArray1dTest #define ZFP_ARRAY_TYPE const_array1d #define ZFP_FULL_ARRAY_TYPE(BLOCK_TYPE) const_array1, BLOCK_TYPE> #define ZFP_ARRAY_TYPE_WRONG_SCALAR const_array1f #define ZFP_ARRAY_TYPE_WRONG_DIM const_array2d #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM const_array2f #define ZFP_ARRAY_NOT_INCLUDED_TYPE const_array3d #define UINT uint64 #define SCALAR double #define DIMS 1 #include "testConstArrayBase.cpp" #include "testConstArray1Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/constArray/testConstArray1f.cpp000066400000000000000000000023121453723256400226460ustar00rootroot00000000000000#include "zfp/constarray1.hpp" #include "zfp/constarray2.hpp" #include "zfp/constarray3.hpp" #include "zfp/constarray4.hpp" #include "zfp/factory.hpp" using namespace zfp; extern "C" { #include "constants/1dFloat.h" } #include "gtest/gtest.h" #include "utils/gtestFloatEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class CArray1fTestEnv : public ArrayFloatTestEnv { public: virtual int getDims() { return 1; } }; CArray1fTestEnv* const testEnv = new CArray1fTestEnv; class CArray1fTest : public CArrayNdTestFixture {}; #define TEST_FIXTURE CArray1fTest #define ZFP_ARRAY_TYPE const_array1f #define ZFP_FULL_ARRAY_TYPE(BLOCK_TYPE) const_array1, BLOCK_TYPE> #define ZFP_ARRAY_TYPE_WRONG_SCALAR const_array1d #define ZFP_ARRAY_TYPE_WRONG_DIM const_array2f #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM const_array2d #define ZFP_ARRAY_NOT_INCLUDED_TYPE const_array3f #define UINT uint32 #define SCALAR float #define DIMS 1 #include "testConstArrayBase.cpp" #include "testConstArray1Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/constArray/testConstArray2Base.cpp000066400000000000000000000000001453723256400232640ustar00rootroot00000000000000zfp-1.0.1/tests/array/constArray/testConstArray2d.cpp000066400000000000000000000023201453723256400226440ustar00rootroot00000000000000#include "zfp/constarray1.hpp" #include "zfp/constarray2.hpp" #include "zfp/constarray3.hpp" #include "zfp/constarray4.hpp" #include "zfp/factory.hpp" using namespace zfp; extern "C" { #include "constants/2dDouble.h" } #include "gtest/gtest.h" #include "utils/gtestDoubleEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class CArray2dTestEnv : public ArrayDoubleTestEnv { public: virtual int getDims() { return 2; } }; CArray2dTestEnv* const testEnv = new CArray2dTestEnv; class CArray2dTest : public CArrayNdTestFixture {}; #define TEST_FIXTURE CArray2dTest #define ZFP_ARRAY_TYPE const_array2d #define ZFP_FULL_ARRAY_TYPE(BLOCK_TYPE) const_array2, BLOCK_TYPE> #define ZFP_ARRAY_TYPE_WRONG_SCALAR const_array2f #define ZFP_ARRAY_TYPE_WRONG_DIM const_array3d #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM const_array3f #define ZFP_ARRAY_NOT_INCLUDED_TYPE const_array1d #define UINT uint64 #define SCALAR double #define DIMS 2 #include "testConstArrayBase.cpp" #include "testConstArray2Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/constArray/testConstArray2f.cpp000066400000000000000000000023121453723256400226470ustar00rootroot00000000000000#include "zfp/constarray1.hpp" #include "zfp/constarray2.hpp" #include "zfp/constarray3.hpp" #include "zfp/constarray4.hpp" #include "zfp/factory.hpp" using namespace zfp; extern "C" { #include "constants/2dFloat.h" } #include "gtest/gtest.h" #include "utils/gtestFloatEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class CArray2fTestEnv : public ArrayFloatTestEnv { public: virtual int getDims() { return 2; } }; CArray2fTestEnv* const testEnv = new CArray2fTestEnv; class CArray2fTest : public CArrayNdTestFixture {}; #define TEST_FIXTURE CArray2fTest #define ZFP_ARRAY_TYPE const_array2f #define ZFP_FULL_ARRAY_TYPE(BLOCK_TYPE) const_array2, BLOCK_TYPE> #define ZFP_ARRAY_TYPE_WRONG_SCALAR const_array2d #define ZFP_ARRAY_TYPE_WRONG_DIM const_array3f #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM const_array3d #define ZFP_ARRAY_NOT_INCLUDED_TYPE const_array1f #define UINT uint32 #define SCALAR float #define DIMS 2 #include "testConstArrayBase.cpp" #include "testConstArray2Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/constArray/testConstArray3Base.cpp000066400000000000000000000000001453723256400232650ustar00rootroot00000000000000zfp-1.0.1/tests/array/constArray/testConstArray3d.cpp000066400000000000000000000023201453723256400226450ustar00rootroot00000000000000#include "zfp/constarray1.hpp" #include "zfp/constarray2.hpp" #include "zfp/constarray3.hpp" #include "zfp/constarray4.hpp" #include "zfp/factory.hpp" using namespace zfp; extern "C" { #include "constants/3dDouble.h" } #include "gtest/gtest.h" #include "utils/gtestDoubleEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class CArray3dTestEnv : public ArrayDoubleTestEnv { public: virtual int getDims() { return 3; } }; CArray3dTestEnv* const testEnv = new CArray3dTestEnv; class CArray3dTest : public CArrayNdTestFixture {}; #define TEST_FIXTURE CArray3dTest #define ZFP_ARRAY_TYPE const_array3d #define ZFP_FULL_ARRAY_TYPE(BLOCK_TYPE) const_array3, BLOCK_TYPE> #define ZFP_ARRAY_TYPE_WRONG_SCALAR const_array3f #define ZFP_ARRAY_TYPE_WRONG_DIM const_array4d #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM const_array4f #define ZFP_ARRAY_NOT_INCLUDED_TYPE const_array2d #define UINT uint64 #define SCALAR double #define DIMS 3 #include "testConstArrayBase.cpp" #include "testConstArray3Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/constArray/testConstArray3f.cpp000066400000000000000000000023121453723256400226500ustar00rootroot00000000000000#include "zfp/constarray1.hpp" #include "zfp/constarray2.hpp" #include "zfp/constarray3.hpp" #include "zfp/constarray4.hpp" #include "zfp/factory.hpp" using namespace zfp; extern "C" { #include "constants/3dFloat.h" } #include "gtest/gtest.h" #include "utils/gtestFloatEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class CArray3fTestEnv : public ArrayFloatTestEnv { public: virtual int getDims() { return 3; } }; CArray3fTestEnv* const testEnv = new CArray3fTestEnv; class CArray3fTest : public CArrayNdTestFixture {}; #define TEST_FIXTURE CArray3fTest #define ZFP_ARRAY_TYPE const_array3f #define ZFP_FULL_ARRAY_TYPE(BLOCK_TYPE) const_array3, BLOCK_TYPE> #define ZFP_ARRAY_TYPE_WRONG_SCALAR const_array3d #define ZFP_ARRAY_TYPE_WRONG_DIM const_array4f #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM const_array4d #define ZFP_ARRAY_NOT_INCLUDED_TYPE const_array2f #define UINT uint32 #define SCALAR float #define DIMS 3 #include "testConstArrayBase.cpp" #include "testConstArray3Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/constArray/testConstArray4Base.cpp000066400000000000000000000000001453723256400232660ustar00rootroot00000000000000zfp-1.0.1/tests/array/constArray/testConstArray4d.cpp000066400000000000000000000023201453723256400226460ustar00rootroot00000000000000#include "zfp/constarray1.hpp" #include "zfp/constarray2.hpp" #include "zfp/constarray3.hpp" #include "zfp/constarray4.hpp" #include "zfp/factory.hpp" using namespace zfp; extern "C" { #include "constants/4dDouble.h" } #include "gtest/gtest.h" #include "utils/gtestDoubleEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class CArray4dTestEnv : public ArrayDoubleTestEnv { public: virtual int getDims() { return 4; } }; CArray4dTestEnv* const testEnv = new CArray4dTestEnv; class CArray4dTest : public CArrayNdTestFixture {}; #define TEST_FIXTURE CArray4dTest #define ZFP_ARRAY_TYPE const_array4d #define ZFP_FULL_ARRAY_TYPE(BLOCK_TYPE) const_array4, BLOCK_TYPE> #define ZFP_ARRAY_TYPE_WRONG_SCALAR const_array4f #define ZFP_ARRAY_TYPE_WRONG_DIM const_array1d #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM const_array1f #define ZFP_ARRAY_NOT_INCLUDED_TYPE const_array2d #define UINT uint64 #define SCALAR double #define DIMS 4 #include "testConstArrayBase.cpp" #include "testConstArray4Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/constArray/testConstArray4f.cpp000066400000000000000000000023121453723256400226510ustar00rootroot00000000000000#include "zfp/constarray1.hpp" #include "zfp/constarray2.hpp" #include "zfp/constarray3.hpp" #include "zfp/constarray4.hpp" #include "zfp/factory.hpp" using namespace zfp; extern "C" { #include "constants/4dFloat.h" } #include "gtest/gtest.h" #include "utils/gtestFloatEnv.h" #include "utils/gtestBaseFixture.h" #include "utils/predicates.h" class CArray4fTestEnv : public ArrayFloatTestEnv { public: virtual int getDims() { return 4; } }; CArray4fTestEnv* const testEnv = new CArray4fTestEnv; class CArray4fTest : public CArrayNdTestFixture {}; #define TEST_FIXTURE CArray4fTest #define ZFP_ARRAY_TYPE const_array4f #define ZFP_FULL_ARRAY_TYPE(BLOCK_TYPE) const_array4, BLOCK_TYPE> #define ZFP_ARRAY_TYPE_WRONG_SCALAR const_array4d #define ZFP_ARRAY_TYPE_WRONG_DIM const_array1f #define ZFP_ARRAY_TYPE_WRONG_SCALAR_DIM const_array1d #define ZFP_ARRAY_NOT_INCLUDED_TYPE const_array2f #define UINT uint32 #define SCALAR float #define DIMS 4 #include "testConstArrayBase.cpp" #include "testConstArray4Base.cpp" int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/array/constArray/testConstArrayBase.cpp000066400000000000000000000263621453723256400232250ustar00rootroot00000000000000extern "C" { #include "utils/testMacros.h" #include "utils/zfpChecksums.h" #include "utils/zfpHash.h" } void FailWhenNoExceptionThrown() { FAIL() << "No exception was thrown when one was expected"; } void FailAndPrintException(std::exception const & e) { FAIL() << "Unexpected exception thrown: " << typeid(e).name() << std::endl << "With message: " << e.what(); } TEST_F(TEST_FIXTURE, when_constructorCalledForRate_then_rateSet) { double rate = ZFP_RATE_PARAM_BITS; zfp_config config = zfp_config_rate(rate, true); #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, config); EXPECT_LT(rate, arr.rate()); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, config); EXPECT_LT(rate, arr.rate()); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, config); // alignment in 3D supports integer fixed-rates [1, 64] (use <=) EXPECT_LE(rate, arr.rate()); #elif DIMS == 4 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, config); // alignment in 4D supports integer fixed-rates [1, 64] (use <=) EXPECT_LE(rate, arr.rate()); #endif } TEST_F(TEST_FIXTURE, when_setRate_then_compressionRateChanged) { zfp_config config = zfp_config_rate(ZFP_RATE_PARAM_BITS, true); #if DIMS == 1 ZFP_ARRAY_TYPE arr(inputDataSideLen, config, inputDataArr); #elif DIMS == 2 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, config, inputDataArr); #elif DIMS == 3 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, config, inputDataArr); #elif DIMS == 4 ZFP_ARRAY_TYPE arr(inputDataSideLen, inputDataSideLen, inputDataSideLen, inputDataSideLen, config, inputDataArr); #endif double actualOldRate = arr.rate(); size_t oldCompressedSize = arr.compressed_size(); uint64 oldChecksum = hashBitstream((uint64*)arr.compressed_data(), oldCompressedSize); double newRate = ZFP_RATE_PARAM_BITS - 10; EXPECT_LT(1, newRate); arr.set_rate(newRate); EXPECT_GT(actualOldRate, arr.rate()); arr.set(inputDataArr); size_t newCompressedSize = arr.compressed_size(); uint64 checksum = hashBitstream((uint64*)arr.compressed_data(), newCompressedSize); EXPECT_PRED_FORMAT2(ExpectNeqPrintHexPred, oldChecksum, checksum); EXPECT_GT(oldCompressedSize, newCompressedSize); } #if DIMS == 1 INSTANTIATE_TEST_SUITE_P(TestManyCompressionModes, TEST_FIXTURE, ::testing::Values( testConfig(TEST_RATE,1,TEST_INDEX_IMP), testConfig(TEST_RATE,2,TEST_INDEX_IMP), testConfig(TEST_PREC,0,TEST_INDEX_IMP), testConfig(TEST_PREC,1,TEST_INDEX_IMP), testConfig(TEST_PREC,2,TEST_INDEX_IMP), testConfig(TEST_ACCU,0,TEST_INDEX_IMP), testConfig(TEST_ACCU,1,TEST_INDEX_IMP), testConfig(TEST_ACCU,2,TEST_INDEX_IMP), testConfig(TEST_RVRS,0,TEST_INDEX_IMP), testConfig(TEST_RATE,1,TEST_INDEX_VRB), testConfig(TEST_RATE,2,TEST_INDEX_VRB), testConfig(TEST_PREC,0,TEST_INDEX_VRB), testConfig(TEST_PREC,1,TEST_INDEX_VRB), testConfig(TEST_PREC,2,TEST_INDEX_VRB), testConfig(TEST_ACCU,0,TEST_INDEX_VRB), testConfig(TEST_ACCU,1,TEST_INDEX_VRB), testConfig(TEST_ACCU,2,TEST_INDEX_VRB), testConfig(TEST_RVRS,0,TEST_INDEX_VRB), testConfig(TEST_RATE,1,TEST_INDEX_HY4), testConfig(TEST_RATE,2,TEST_INDEX_HY4), testConfig(TEST_PREC,0,TEST_INDEX_HY4), testConfig(TEST_PREC,1,TEST_INDEX_HY4), testConfig(TEST_PREC,2,TEST_INDEX_HY4), testConfig(TEST_ACCU,0,TEST_INDEX_HY4), testConfig(TEST_ACCU,1,TEST_INDEX_HY4), testConfig(TEST_ACCU,2,TEST_INDEX_HY4), testConfig(TEST_RVRS,0,TEST_INDEX_HY4), testConfig(TEST_RATE,1,TEST_INDEX_HY8), testConfig(TEST_RATE,2,TEST_INDEX_HY8), testConfig(TEST_PREC,0,TEST_INDEX_HY8), testConfig(TEST_PREC,1,TEST_INDEX_HY8), testConfig(TEST_PREC,2,TEST_INDEX_HY8), testConfig(TEST_ACCU,0,TEST_INDEX_HY8), testConfig(TEST_ACCU,1,TEST_INDEX_HY8), testConfig(TEST_ACCU,2,TEST_INDEX_HY8), testConfig(TEST_RVRS,0,TEST_INDEX_HY8) ), TEST_FIXTURE::PrintToStringParamName() ); #else INSTANTIATE_TEST_SUITE_P(TestManyCompressionModes, TEST_FIXTURE, ::testing::Values( testConfig(TEST_RATE,0,TEST_INDEX_IMP), testConfig(TEST_RATE,1,TEST_INDEX_IMP), testConfig(TEST_RATE,2,TEST_INDEX_IMP), testConfig(TEST_PREC,0,TEST_INDEX_IMP), testConfig(TEST_PREC,1,TEST_INDEX_IMP), testConfig(TEST_PREC,2,TEST_INDEX_IMP), testConfig(TEST_ACCU,0,TEST_INDEX_IMP), testConfig(TEST_ACCU,1,TEST_INDEX_IMP), testConfig(TEST_ACCU,2,TEST_INDEX_IMP), testConfig(TEST_RVRS,0,TEST_INDEX_IMP), testConfig(TEST_RATE,1,TEST_INDEX_VRB), testConfig(TEST_RATE,2,TEST_INDEX_VRB), testConfig(TEST_PREC,0,TEST_INDEX_VRB), testConfig(TEST_PREC,1,TEST_INDEX_VRB), testConfig(TEST_PREC,2,TEST_INDEX_VRB), testConfig(TEST_ACCU,0,TEST_INDEX_VRB), testConfig(TEST_ACCU,1,TEST_INDEX_VRB), testConfig(TEST_ACCU,2,TEST_INDEX_VRB), testConfig(TEST_RVRS,0,TEST_INDEX_VRB), testConfig(TEST_RATE,1,TEST_INDEX_HY4), testConfig(TEST_RATE,2,TEST_INDEX_HY4), testConfig(TEST_PREC,0,TEST_INDEX_HY4), testConfig(TEST_PREC,1,TEST_INDEX_HY4), testConfig(TEST_PREC,2,TEST_INDEX_HY4), testConfig(TEST_ACCU,0,TEST_INDEX_HY4), testConfig(TEST_ACCU,1,TEST_INDEX_HY4), testConfig(TEST_ACCU,2,TEST_INDEX_HY4), testConfig(TEST_RVRS,0,TEST_INDEX_HY4), testConfig(TEST_RATE,1,TEST_INDEX_HY8), testConfig(TEST_RATE,2,TEST_INDEX_HY8), testConfig(TEST_PREC,0,TEST_INDEX_HY8), testConfig(TEST_PREC,1,TEST_INDEX_HY8), testConfig(TEST_PREC,2,TEST_INDEX_HY8), testConfig(TEST_ACCU,0,TEST_INDEX_HY8), testConfig(TEST_ACCU,1,TEST_INDEX_HY8), testConfig(TEST_ACCU,2,TEST_INDEX_HY8), testConfig(TEST_RVRS,0,TEST_INDEX_HY8) ), TEST_FIXTURE::PrintToStringParamName() ); #endif TEST_P(TEST_FIXTURE, when_constructorCalledWithCacheSize_then_minCacheSizeEnforced) { size_t cacheSize = 300; zfp_config config = getConfig(); switch(std::get<2>(GetParam())) { case TEST_INDEX_IMP: { if (std::get<0>(GetParam()) == TEST_RATE) { ZFP_FULL_ARRAY_TYPE(TEST_INDEX_TYPE_IMP) arr(_repeat_arg(inputDataSideLen, DIMS), config); EXPECT_LE(cacheSize, arr.cache_size()); } else { GTEST_SKIP() << "[ SKIPPED ] Implicit index only supported for fixed rate" << std::endl; } break; } case TEST_INDEX_VRB: { ZFP_FULL_ARRAY_TYPE(TEST_INDEX_TYPE_VRB) arr(_repeat_arg(inputDataSideLen, DIMS), config); EXPECT_LE(cacheSize, arr.cache_size()); break; } case TEST_INDEX_HY4: { ZFP_FULL_ARRAY_TYPE(TEST_INDEX_TYPE_HY4) arr(_repeat_arg(inputDataSideLen, DIMS), config); EXPECT_LE(cacheSize, arr.cache_size()); break; } case TEST_INDEX_HY8: { ZFP_FULL_ARRAY_TYPE(TEST_INDEX_TYPE_HY8) arr(_repeat_arg(inputDataSideLen, DIMS), config); EXPECT_LE(cacheSize, arr.cache_size()); break; } } } TEST_P(TEST_FIXTURE, given_dataset_when_set_then_underlyingBitstreamChecksumMatches) { zfp_config config = getConfig(); uint64 key1, key2; switch(std::get<2>(GetParam())) { case TEST_INDEX_IMP: { if (std::get<0>(GetParam()) == TEST_RATE) { ZFP_FULL_ARRAY_TYPE(TEST_INDEX_TYPE_IMP) arr(_repeat_arg(inputDataSideLen, DIMS), config); computeKey(ARRAY_TEST, COMPRESSED_BITSTREAM, dimLens, config.mode, std::get<1>(GetParam()), &key1, &key2); uint64 expectedChecksum = getChecksumByKey(DIMS, ZFP_TYPE, key1, key2); uint64 checksum = hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size()); EXPECT_PRED_FORMAT2(ExpectNeqPrintHexPred, expectedChecksum, checksum); arr.set(inputDataArr); checksum = hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size()); EXPECT_PRED_FORMAT2(ExpectEqPrintHexPred, expectedChecksum, checksum); } else { GTEST_SKIP() << "[ SKIPPED ] Implicit index only supported for fixed rate" << std::endl; } break; } case TEST_INDEX_VRB: { ZFP_FULL_ARRAY_TYPE(TEST_INDEX_TYPE_VRB) arr(_repeat_arg(inputDataSideLen, DIMS), config); computeKey(ARRAY_TEST, COMPRESSED_BITSTREAM, dimLens, config.mode, std::get<1>(GetParam()), &key1, &key2); uint64 expectedChecksum = getChecksumByKey(DIMS, ZFP_TYPE, key1, key2); uint64 checksum = hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size()); EXPECT_PRED_FORMAT2(ExpectNeqPrintHexPred, expectedChecksum, checksum); arr.set(inputDataArr); checksum = hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size()); EXPECT_PRED_FORMAT2(ExpectEqPrintHexPred, expectedChecksum, checksum); break; } case TEST_INDEX_HY4: { ZFP_FULL_ARRAY_TYPE(TEST_INDEX_TYPE_HY4) arr(_repeat_arg(inputDataSideLen, DIMS), config); computeKey(ARRAY_TEST, COMPRESSED_BITSTREAM, dimLens, config.mode, std::get<1>(GetParam()), &key1, &key2); uint64 expectedChecksum = getChecksumByKey(DIMS, ZFP_TYPE, key1, key2); uint64 checksum = hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size()); EXPECT_PRED_FORMAT2(ExpectNeqPrintHexPred, expectedChecksum, checksum); arr.set(inputDataArr); checksum = hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size()); EXPECT_PRED_FORMAT2(ExpectEqPrintHexPred, expectedChecksum, checksum); break; } case TEST_INDEX_HY8: { ZFP_FULL_ARRAY_TYPE(TEST_INDEX_TYPE_HY8) arr(_repeat_arg(inputDataSideLen, DIMS), config); computeKey(ARRAY_TEST, COMPRESSED_BITSTREAM, dimLens, config.mode, std::get<1>(GetParam()), &key1, &key2); uint64 expectedChecksum = getChecksumByKey(DIMS, ZFP_TYPE, key1, key2); uint64 checksum = hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size()); EXPECT_PRED_FORMAT2(ExpectNeqPrintHexPred, expectedChecksum, checksum); arr.set(inputDataArr); checksum = hashBitstream((uint64*)arr.compressed_data(), arr.compressed_size()); EXPECT_PRED_FORMAT2(ExpectEqPrintHexPred, expectedChecksum, checksum); break; } } } TEST_P(TEST_FIXTURE, when_implicitIndexForNonRate_then_exceptionThrown) { zfp_config config = getConfig(); if (std::get<2>(GetParam()) != TEST_INDEX_IMP || std::get<0>(GetParam()) == zfp_mode_fixed_rate) GTEST_SKIP(); try { ZFP_FULL_ARRAY_TYPE(TEST_INDEX_TYPE_IMP) arr(_repeat_arg(inputDataSideLen, DIMS), config); FailWhenNoExceptionThrown(); } catch (zfp::exception const&) { /* hitting this block is test success so do nothing */ } catch (std::exception const& e) { FailAndPrintException(e); } } zfp-1.0.1/tests/array/decode/000077500000000000000000000000001453723256400160265ustar00rootroot00000000000000zfp-1.0.1/tests/array/decode/CMakeLists.txt000066400000000000000000000015321453723256400205670ustar00rootroot00000000000000function(zfp_add_cpp_tests dims type bits) # test templated block encoding set(test_name testTemplatedDecode${dims}${type}) add_executable(${test_name} ${test_name}.cpp) target_link_libraries(${test_name} gtest gtest_main zfp rand${bits}Lib) target_compile_definitions(${test_name} PRIVATE ${zfp_compressed_array_defs}) add_test(NAME ${test_name} COMMAND ${test_name}) endfunction() zfp_add_cpp_tests(1 f 32) zfp_add_cpp_tests(2 f 32) zfp_add_cpp_tests(3 f 32) zfp_add_cpp_tests(4 f 32) zfp_add_cpp_tests(1 d 64) zfp_add_cpp_tests(2 d 64) zfp_add_cpp_tests(3 d 64) zfp_add_cpp_tests(4 d 64) #zfp_add_cpp_tests(1 Int32 32) #zfp_add_cpp_tests(2 Int32 32) #zfp_add_cpp_tests(3 Int32 32) #zfp_add_cpp_tests(4 Int32 32) #zfp_add_cpp_tests(1 Int64 64) #zfp_add_cpp_tests(2 Int64 64) #zfp_add_cpp_tests(3 Int64 64) #zfp_add_cpp_tests(4 Int64 64) zfp-1.0.1/tests/array/decode/testTemplatedDecode1d.cpp000066400000000000000000000012311453723256400226770ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/1dDouble.h" #include "utils/rand64.h" } #define ZFP_FIELD_FUNC zfp_field_1d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_double_1 #define ZFP_DECODE_BLOCK_FUNC zfp_decode_block_double_1 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_double_1 #define ZFP_DECODE_BLOCK_STRIDED_FUNC zfp_decode_block_strided_double_1 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_double_1 #define ZFP_DECODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_decode_partial_block_strided_double_1 #define SCALAR double #define DIMS 1 #include "testTemplatedDecodeBase.cpp" zfp-1.0.1/tests/array/decode/testTemplatedDecode1f.cpp000066400000000000000000000012211453723256400227000ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/1dFloat.h" #include "utils/rand32.h" } #define ZFP_FIELD_FUNC zfp_field_1d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_float_1 #define ZFP_DECODE_BLOCK_FUNC zfp_decode_block_float_1 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_float_1 #define ZFP_DECODE_BLOCK_STRIDED_FUNC zfp_decode_block_strided_float_1 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_float_1 #define ZFP_DECODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_decode_partial_block_strided_float_1 #define SCALAR float #define DIMS 1 #include "testTemplatedDecodeBase.cpp" zfp-1.0.1/tests/array/decode/testTemplatedDecode2d.cpp000066400000000000000000000012311453723256400227000ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/2dDouble.h" #include "utils/rand64.h" } #define ZFP_FIELD_FUNC zfp_field_2d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_double_2 #define ZFP_DECODE_BLOCK_FUNC zfp_decode_block_double_2 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_double_2 #define ZFP_DECODE_BLOCK_STRIDED_FUNC zfp_decode_block_strided_double_2 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_double_2 #define ZFP_DECODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_decode_partial_block_strided_double_2 #define SCALAR double #define DIMS 2 #include "testTemplatedDecodeBase.cpp" zfp-1.0.1/tests/array/decode/testTemplatedDecode2f.cpp000066400000000000000000000012211453723256400227010ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/2dFloat.h" #include "utils/rand32.h" } #define ZFP_FIELD_FUNC zfp_field_2d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_float_2 #define ZFP_DECODE_BLOCK_FUNC zfp_decode_block_float_2 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_float_2 #define ZFP_DECODE_BLOCK_STRIDED_FUNC zfp_decode_block_strided_float_2 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_float_2 #define ZFP_DECODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_decode_partial_block_strided_float_2 #define SCALAR float #define DIMS 2 #include "testTemplatedDecodeBase.cpp" zfp-1.0.1/tests/array/decode/testTemplatedDecode3d.cpp000066400000000000000000000012311453723256400227010ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/3dDouble.h" #include "utils/rand64.h" } #define ZFP_FIELD_FUNC zfp_field_3d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_double_3 #define ZFP_DECODE_BLOCK_FUNC zfp_decode_block_double_3 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_double_3 #define ZFP_DECODE_BLOCK_STRIDED_FUNC zfp_decode_block_strided_double_3 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_double_3 #define ZFP_DECODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_decode_partial_block_strided_double_3 #define SCALAR double #define DIMS 3 #include "testTemplatedDecodeBase.cpp" zfp-1.0.1/tests/array/decode/testTemplatedDecode3f.cpp000066400000000000000000000012211453723256400227020ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/3dFloat.h" #include "utils/rand32.h" } #define ZFP_FIELD_FUNC zfp_field_3d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_float_3 #define ZFP_DECODE_BLOCK_FUNC zfp_decode_block_float_3 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_float_3 #define ZFP_DECODE_BLOCK_STRIDED_FUNC zfp_decode_block_strided_float_3 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_float_3 #define ZFP_DECODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_decode_partial_block_strided_float_3 #define SCALAR float #define DIMS 3 #include "testTemplatedDecodeBase.cpp" zfp-1.0.1/tests/array/decode/testTemplatedDecode4d.cpp000066400000000000000000000012311453723256400227020ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/4dDouble.h" #include "utils/rand64.h" } #define ZFP_FIELD_FUNC zfp_field_4d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_double_4 #define ZFP_DECODE_BLOCK_FUNC zfp_decode_block_double_4 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_double_4 #define ZFP_DECODE_BLOCK_STRIDED_FUNC zfp_decode_block_strided_double_4 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_double_4 #define ZFP_DECODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_decode_partial_block_strided_double_4 #define SCALAR double #define DIMS 4 #include "testTemplatedDecodeBase.cpp" zfp-1.0.1/tests/array/decode/testTemplatedDecode4f.cpp000066400000000000000000000012211453723256400227030ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/4dFloat.h" #include "utils/rand32.h" } #define ZFP_FIELD_FUNC zfp_field_4d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_float_4 #define ZFP_DECODE_BLOCK_FUNC zfp_decode_block_float_4 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_float_4 #define ZFP_DECODE_BLOCK_STRIDED_FUNC zfp_decode_block_strided_float_4 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_float_4 #define ZFP_DECODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_decode_partial_block_strided_float_4 #define SCALAR float #define DIMS 4 #include "testTemplatedDecodeBase.cpp" zfp-1.0.1/tests/array/decode/testTemplatedDecodeBase.cpp000066400000000000000000000440111453723256400232500ustar00rootroot00000000000000extern "C" { #include "utils/testMacros.h" #include "utils/zfpChecksums.h" #include "utils/zfpHash.h" } #include "src/template/codec.h" #include "gtest/gtest.h" #define SX 2 #define SY (3 * BLOCK_SIDE_LEN*SX) #define SZ (2 * BLOCK_SIDE_LEN*SY) #define SW (3 * BLOCK_SIDE_LEN*SZ) #define PX 1 #define PY 2 #define PZ 3 #define PW 4 #define DUMMY_VAL 99 #define ASSERT_SCALAR_EQ(x, y) ASSERT_NEAR(x, y, 1e-32) void populateArray(SCALAR** dataArr) { *dataArr = new SCALAR[BLOCK_SIZE]; ASSERT_TRUE(*dataArr != nullptr); for (int i = 0; i < BLOCK_SIZE; i++) { #ifdef FL_PT_DATA (*dataArr)[i] = nextSignedRandFlPt(); #else (*dataArr)[i] = nextSignedRandInt(); #endif } } void populateStridedArray(SCALAR** dataArr, SCALAR dummyVal) { #if DIMS == 1 size_t countX = BLOCK_SIDE_LEN * SX; *dataArr = (SCALAR*)malloc(sizeof(SCALAR) * countX); ASSERT_TRUE(*dataArr != nullptr); for (size_t i = 0; i < countX; i++) { if (i % SX) { (*dataArr)[i] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArr)[i] = nextSignedRandFlPt(); #else (*dataArr)[i] = nextSignedRandInt(); #endif } } #elif DIMS == 2 size_t countX = BLOCK_SIDE_LEN * SX; size_t countY = SY / SX; *dataArr = (SCALAR*)malloc(sizeof(SCALAR) * countX * countY); ASSERT_TRUE(*dataArr != nullptr); for (size_t j = 0; j < countY; j++) { for (size_t i = 0; i < countX; i++) { size_t index = countX*j + i; if (i % (countX/BLOCK_SIDE_LEN) || j % (countY/BLOCK_SIDE_LEN)) { (*dataArr)[index] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArr)[index] = nextSignedRandFlPt(); #else (*dataArr)[index] = nextSignedRandInt(); #endif } } } #elif DIMS == 3 size_t countX = BLOCK_SIDE_LEN * SX; size_t countY = SY / SX; size_t countZ = SZ / SY; *dataArr = (SCALAR*)malloc(sizeof(SCALAR) * countX * countY * countZ); ASSERT_TRUE(*dataArr != nullptr); for (size_t k = 0; k < countZ; k++) { for (size_t j = 0; j < countY; j++) { for (size_t i = 0; i < countX; i++) { size_t index = countX*countY*k + countX*j + i; if (i % (countX/BLOCK_SIDE_LEN) || j % (countY/BLOCK_SIDE_LEN) || k % (countZ/BLOCK_SIDE_LEN)) { (*dataArr)[index] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArr)[index] = nextSignedRandFlPt(); #else (*dataArr)[index] = nextSignedRandInt(); #endif } } } } #elif DIMS == 4 size_t countX = BLOCK_SIDE_LEN * SX; size_t countY = SY / SX; size_t countZ = SZ / SY; size_t countW = SW / SZ; *dataArr = (SCALAR*)malloc(sizeof(SCALAR) * countX * countY * countZ * countW); ASSERT_TRUE(*dataArr != nullptr); for (size_t l = 0; l < countW; l++) { for (size_t k = 0; k < countZ; k++) { for (size_t j = 0; j < countY; j++) { for (size_t i = 0; i < countX; i++) { size_t index = countX*countY*countZ*l + countX*countY*k + countX*j + i; if (i % (countX/BLOCK_SIDE_LEN) || j % (countY/BLOCK_SIDE_LEN) || k % (countZ/BLOCK_SIDE_LEN) || l % (countW/BLOCK_SIDE_LEN)) { (*dataArr)[index] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArr)[index] = nextSignedRandFlPt(); #else (*dataArr)[index] = nextSignedRandInt(); #endif } } } } } #endif } void assertStridedBlockEntriesEqual(SCALAR* data1, SCALAR* data2) { #if DIMS == 1 size_t countX = BLOCK_SIDE_LEN * SX; for (size_t i = 0; i < countX; i++) { if (!(i % (countX/BLOCK_SIDE_LEN))) { ASSERT_SCALAR_EQ(data1[i], data2[i]) << "index " << i << " mismatch: " << data1[i] << " != " << data2[i]; } } #elif DIMS == 2 size_t countX = BLOCK_SIDE_LEN * SX; size_t countY = SY / SX; for (size_t j = 0; j < countY; j++) { for (size_t i = 0; i < countX; i++) { if (!(i % (countX/BLOCK_SIDE_LEN)) && !(j % (countY/BLOCK_SIDE_LEN))) { ASSERT_SCALAR_EQ(data1[countX*j + i], data2[countX*j + i]) << "index " << (countX*j + i) << " mismatch: " << data1[countX*j + i] << " != " << data2[countX*j + i]; } } } #elif DIMS == 3 size_t countX = BLOCK_SIDE_LEN * SX; size_t countY = SY / SX; size_t countZ = SZ / SY; for (size_t k = 0; k < countZ; k++) { for (size_t j = 0; j < countY; j++) { for (size_t i = 0; i < countX; i++) { if (!(i % (countX/BLOCK_SIDE_LEN)) && !(j % (countY/BLOCK_SIDE_LEN)) && !(k % (countZ/BLOCK_SIDE_LEN))) { ASSERT_SCALAR_EQ(data1[countX*countY*k + countX*j + i], data2[countX*countY*k + countX*j + i]) << "index " << (countX*countY*k + countX*j + i) << " mismatch: " << data1[countX*countY*k + countX*j + i] << " != " << data2[countX*countY*k + countX*j + i]; } } } } #elif DIMS == 4 size_t countX = BLOCK_SIDE_LEN * SX; size_t countY = SY / SX; size_t countZ = SZ / SY; size_t countW = SW / SZ; for (size_t l = 0; l < countW; l++) { for (size_t k = 0; k < countZ; k++) { for (size_t j = 0; j < countY; j++) { for (size_t i = 0; i < countX; i++) { if (!(i % (countX/BLOCK_SIDE_LEN)) && !(j % (countY/BLOCK_SIDE_LEN)) && !(k % (countZ/BLOCK_SIDE_LEN)) && !(l % (countW/BLOCK_SIDE_LEN))) { ASSERT_SCALAR_EQ(data1[countX*countY*countZ*l + countX*countY*k + countX*j + i], data2[countX*countY*countZ*l + countX*countY*k + countX*j + i]) << "index " << (countX*countY*countZ*l + countX*countY*k + countX*j + i) << " mismatch: " << data1[countX*countY*countZ*l + countX*countY*k + countX*j + i] << " != " << data2[countX*countY*countZ*l + countX*countY*k + countX*j + i]; } } } } } #endif } void assertPartialBlockEntriesEqual(SCALAR* data1, SCALAR* data2) { #if DIMS == 1 size_t countX = BLOCK_SIDE_LEN * SX; for (size_t i = 0; i < countX; i++) { if (i/(countX/BLOCK_SIDE_LEN) < PX && !(i % (countX/BLOCK_SIDE_LEN))) { ASSERT_SCALAR_EQ(data1[i], data2[i]) << "index " << i << " mismatch: " << data1[i] << " != " << data2[i]; } } #elif DIMS == 2 size_t countX = BLOCK_SIDE_LEN * SX; size_t countY = SY / SX; for (size_t j = 0; j < countY; j++) { for (size_t i = 0; i < countX; i++) { if (i/(countX/BLOCK_SIDE_LEN) < PX && j/(countY/BLOCK_SIDE_LEN) < PY && !(i % (countX/BLOCK_SIDE_LEN)) && !(j % (countY/BLOCK_SIDE_LEN))) { ASSERT_SCALAR_EQ(data1[countX*j + i], data2[countX*j + i]) << "index " << (countX*j + i) << " mismatch: " << data1[countX*j + i] << " != " << data2[countX*j + i]; } } } #elif DIMS == 3 size_t countX = BLOCK_SIDE_LEN * SX; size_t countY = SY / SX; size_t countZ = SZ / SY; for (size_t k = 0; k < countZ; k++) { for (size_t j = 0; j < countY; j++) { for (size_t i = 0; i < countX; i++) { if (i/(countX/BLOCK_SIDE_LEN) < PX && j/(countY/BLOCK_SIDE_LEN) < PY && k/(countZ/BLOCK_SIDE_LEN) < PZ && !(i % (countX/BLOCK_SIDE_LEN)) && !(j % (countY/BLOCK_SIDE_LEN)) && !(k % (countZ/BLOCK_SIDE_LEN))) { ASSERT_SCALAR_EQ(data1[countX*countY*k + countX*j + i], data2[countX*countY*k + countX*j + i]) << "index " << (countX*countY*k + countX*j + i) << " mismatch: " << data1[countX*countY*k + countX*j + i] << " != " << data2[countX*countY*k + countX*j + i]; } } } } #elif DIMS == 4 size_t countX = BLOCK_SIDE_LEN * SX; size_t countY = SY / SX; size_t countZ = SZ / SY; size_t countW = SW / SZ; for (size_t l = 0; l < countW; l++) { for (size_t k = 0; k < countZ; k++) { for (size_t j = 0; j < countY; j++) { for (size_t i = 0; i < countX; i++) { if (i/(countX/BLOCK_SIDE_LEN) < PX && j/(countY/BLOCK_SIDE_LEN) < PY && k/(countZ/BLOCK_SIDE_LEN) < PZ && l/(countW/BLOCK_SIDE_LEN) < PW && !(i % (countX/BLOCK_SIDE_LEN)) && !(j % (countY/BLOCK_SIDE_LEN)) && !(k % (countZ/BLOCK_SIDE_LEN)) && !(l % (countW/BLOCK_SIDE_LEN))) { ASSERT_SCALAR_EQ(data1[countX*countY*countZ*l + countX*countY*k + countX*j + i], data2[countX*countY*countZ*l + countX*countY*k + countX*j + i]) << "index " << (countX*countY*countZ*l + countX*countY*k + countX*j + i) << " mismatch: " << data1[countX*countY*countZ*l + countX*countY*k + countX*j + i] << " != " << data2[countX*countY*countZ*l + countX*countY*k + countX*j + i]; } } } } } #endif } void setupStream(zfp_field** field, zfp_stream** stream, bool isStrided = false) { *stream = zfp_stream_open(NULL); //zfp_stream_set_rate(*stream, ZFP_RATE_PARAM_BITS, ZFP_TYPE, DIMS, zfp_false); zfp_stream_set_accuracy(*stream, 0); size_t bufsizeBytes = zfp_stream_maximum_size(*stream, *field); char* buffer = (char*)calloc(bufsizeBytes, sizeof(char)); ASSERT_TRUE(buffer != nullptr); bitstream* s = stream_open(buffer, bufsizeBytes); ASSERT_TRUE(s != nullptr); if (isStrided) { switch (DIMS) { case 1: { zfp_field_set_stride_1d(*field, SX); break; } case 2: { zfp_field_set_stride_2d(*field, SX, SY); break; } case 3: { zfp_field_set_stride_3d(*field, SX, SY, SZ); break; } case 4: { zfp_field_set_stride_4d(*field, SX, SY, SZ, SW); break; } } } zfp_stream_set_bit_stream(*stream, s); } TEST(TemplatedDecodeTests, given_TemplatedDecodeBlock_resultsMatchNonTemplated) { SCALAR* dataArr; populateArray(&dataArr); zfp_field* field = ZFP_FIELD_FUNC(dataArr, ZFP_TYPE, _repeat_arg(BLOCK_SIDE_LEN, DIMS)); zfp_stream* stream; setupStream(&field, &stream); ZFP_ENCODE_BLOCK_FUNC(stream, dataArr); zfp_stream_flush(stream); zfp_stream_rewind(stream); zfp_stream* tstream; setupStream(&field, &tstream); encode_block(tstream, dataArr); zfp_stream_flush(tstream); zfp_stream_rewind(tstream); SCALAR* data1 = new SCALAR[BLOCK_SIZE]; size_t sz = ZFP_DECODE_BLOCK_FUNC(stream, data1); SCALAR* data2 = new SCALAR[BLOCK_SIZE]; size_t tsz = decode_block(tstream, data2); ASSERT_TRUE(sz == tsz); for (int i = 0; i < BLOCK_SIZE; i++) ASSERT_SCALAR_EQ(data1[i], data2[i]); zfp_field_free(field); stream_close(zfp_stream_bit_stream(stream)); stream_close(zfp_stream_bit_stream(tstream)); zfp_stream_close(stream); zfp_stream_close(tstream); delete[] dataArr; delete[] data1; delete[] data2; } TEST(TemplatedDecodeTests, given_TemplatedDecodeBlockStrided_resultsMatchNonTemplated) { size_t countX = 4 * SX; #if DIMS > 1 size_t countY = SY / SX; #endif #if DIMS > 2 size_t countZ = SZ / SY; #endif #if DIMS == 4 size_t countW = SW / SZ; #endif SCALAR* dataArr; populateStridedArray(&dataArr, DUMMY_VAL); ASSERT_TRUE(dataArr != nullptr); zfp_field* field = ZFP_FIELD_FUNC(dataArr, ZFP_TYPE, _repeat_arg(BLOCK_SIDE_LEN, DIMS)); zfp_stream* stream; zfp_stream* tstream; setupStream(&field, &stream, true); setupStream(&field, &tstream, true); #if DIMS == 1 ZFP_ENCODE_BLOCK_STRIDED_FUNC(stream, dataArr, SX); encode_block_strided(tstream, dataArr, SX); #elif DIMS == 2 ZFP_ENCODE_BLOCK_STRIDED_FUNC(stream, dataArr, SX, SY); encode_block_strided(tstream, dataArr, SX, SY); #elif DIMS == 3 ZFP_ENCODE_BLOCK_STRIDED_FUNC(stream, dataArr, SX, SY, SZ); encode_block_strided(tstream, dataArr, SX, SY, SZ); #elif DIMS == 4 ZFP_ENCODE_BLOCK_STRIDED_FUNC(stream, dataArr, SX, SY, SZ, SW); encode_block_strided(tstream, dataArr, SX, SY, SZ, SW); #endif zfp_stream_flush(stream); zfp_stream_rewind(stream); zfp_stream_flush(tstream); zfp_stream_rewind(tstream); #if DIMS == 1 SCALAR *data1 = (SCALAR*)malloc(sizeof(SCALAR) * countX); ASSERT_TRUE(data1 != nullptr); SCALAR *data2 = (SCALAR*)malloc(sizeof(SCALAR) * countX); ASSERT_TRUE(data2 != nullptr); size_t sz = ZFP_DECODE_BLOCK_STRIDED_FUNC(stream, data1, SX); size_t tsz = decode_block_strided(tstream, data2, SX); #elif DIMS == 2 SCALAR *data1 = (SCALAR*)malloc(sizeof(SCALAR) * countX * countY); ASSERT_TRUE(data1 != nullptr); SCALAR *data2 = (SCALAR*)malloc(sizeof(SCALAR) * countX * countY); ASSERT_TRUE(data2 != nullptr); size_t sz = ZFP_DECODE_BLOCK_STRIDED_FUNC(stream, data1, SX, SY); size_t tsz = decode_block_strided(tstream, data2, SX, SY); #elif DIMS == 3 SCALAR *data1 = (SCALAR*)malloc(sizeof(SCALAR) * countX * countY * countZ); ASSERT_TRUE(data1 != nullptr); SCALAR *data2 = (SCALAR*)malloc(sizeof(SCALAR) * countX * countY * countZ); ASSERT_TRUE(data2 != nullptr); size_t sz = ZFP_DECODE_BLOCK_STRIDED_FUNC(stream, data1, SX, SY, SZ); size_t tsz = decode_block_strided(tstream, data2, SX, SY, SZ); #elif DIMS == 4 SCALAR *data1 = (SCALAR*)malloc(sizeof(SCALAR) * countX * countY * countZ * countW); ASSERT_TRUE(data1 != nullptr); SCALAR *data2 = (SCALAR*)malloc(sizeof(SCALAR) * countX * countY * countZ * countW); ASSERT_TRUE(data2 != nullptr); size_t sz = ZFP_DECODE_BLOCK_STRIDED_FUNC(stream, data1, SX, SY, SZ, SW); size_t tsz = decode_block_strided(tstream, data2, SX, SY, SZ, SW); #endif ASSERT_TRUE(sz == tsz); assertStridedBlockEntriesEqual(data1, data2); zfp_field_free(field); stream_close(zfp_stream_bit_stream(stream)); stream_close(zfp_stream_bit_stream(tstream)); zfp_stream_close(stream); zfp_stream_close(tstream); free(dataArr); free(data1); free(data2); } TEST(TemplatedDecodeTests, given_TemplatedDecodePartialBlockStrided_resultsMatchNonTemplated) { size_t countX = 4 * SX; #if DIMS > 1 size_t countY = SY / SX; #endif #if DIMS > 2 size_t countZ = SZ / SY; #endif #if DIMS == 4 size_t countW = SW / SZ; #endif SCALAR* dataArr; populateStridedArray(&dataArr, DUMMY_VAL); ASSERT_TRUE(dataArr != nullptr); zfp_field* field = ZFP_FIELD_FUNC(dataArr, ZFP_TYPE, _repeat_arg(BLOCK_SIDE_LEN, DIMS)); zfp_stream* stream; zfp_stream* tstream; setupStream(&field, &stream, true); setupStream(&field, &tstream, true); #if DIMS == 1 size_t sz = ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC(stream, dataArr, PX, SX); size_t tsz = encode_partial_block_strided(tstream, dataArr, PX, SX); #elif DIMS == 2 size_t sz = ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC(stream, dataArr, PX, PY, SX, SY); size_t tsz = encode_partial_block_strided(tstream, dataArr, PX, PY, SX, SY); #elif DIMS == 3 size_t sz = ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC(stream, dataArr, PX, PY, PZ, SX, SY, SZ); size_t tsz = encode_partial_block_strided(tstream, dataArr, PX, PY, PZ, SX, SY, SZ); #elif DIMS == 4 size_t sz = ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC(stream, dataArr, PX, PY, PZ, PW, SX, SY, SZ, SW); size_t tsz = encode_partial_block_strided(tstream, dataArr, PX, PY, PZ, PW, SX, SY, SZ, SW); #endif zfp_stream_flush(stream); zfp_stream_rewind(stream); zfp_stream_flush(tstream); zfp_stream_rewind(tstream); #if DIMS == 1 SCALAR *data1 = (SCALAR*)malloc(sizeof(SCALAR) * countX); ASSERT_TRUE(data1 != nullptr); SCALAR *data2 = (SCALAR*)malloc(sizeof(SCALAR) * countX); ASSERT_TRUE(data2 != nullptr); size_t d_sz = ZFP_DECODE_PARTIAL_BLOCK_STRIDED_FUNC(stream, data1, PX, SX); size_t d_tsz = decode_partial_block_strided(tstream, data2, PX, SX); #elif DIMS == 2 SCALAR *data1 = (SCALAR*)malloc(sizeof(SCALAR) * countX * countY); ASSERT_TRUE(data1 != nullptr); SCALAR *data2 = (SCALAR*)malloc(sizeof(SCALAR) * countX * countY); ASSERT_TRUE(data2 != nullptr); size_t d_sz = ZFP_DECODE_PARTIAL_BLOCK_STRIDED_FUNC(stream, data1, PX, PY, SX, SY); size_t d_tsz = decode_partial_block_strided(tstream, data2, PX, PY, SX, SY); #elif DIMS == 3 SCALAR *data1 = (SCALAR*)malloc(sizeof(SCALAR) * countX * countY * countZ); ASSERT_TRUE(data1 != nullptr); SCALAR *data2 = (SCALAR*)malloc(sizeof(SCALAR) * countX * countY * countZ); ASSERT_TRUE(data2 != nullptr); size_t d_sz = ZFP_DECODE_PARTIAL_BLOCK_STRIDED_FUNC(stream, data1, PX, PY, PZ, SX, SY, SZ); size_t d_tsz = decode_partial_block_strided(tstream, data2, PX, PY, PZ, SX, SY, SZ); #elif DIMS == 4 SCALAR *data1 = (SCALAR*)malloc(sizeof(SCALAR) * countX * countY * countZ * countW); ASSERT_TRUE(data1 != nullptr); SCALAR *data2 = (SCALAR*)malloc(sizeof(SCALAR) * countX * countY * countZ * countW); ASSERT_TRUE(data2 != nullptr); size_t d_sz = ZFP_DECODE_PARTIAL_BLOCK_STRIDED_FUNC(stream, data1, PX, PY, PZ, PW, SX, SY, SZ, SW); size_t d_tsz = decode_partial_block_strided(tstream, data2, PX, PY, PZ, PW, SX, SY, SZ, SW); #endif ASSERT_TRUE(d_sz == d_tsz); assertPartialBlockEntriesEqual(data1, data2); zfp_field_free(field); stream_close(zfp_stream_bit_stream(stream)); stream_close(zfp_stream_bit_stream(tstream)); zfp_stream_close(stream); zfp_stream_close(tstream); free(dataArr); free(data1); free(data2); } zfp-1.0.1/tests/array/encode/000077500000000000000000000000001453723256400160405ustar00rootroot00000000000000zfp-1.0.1/tests/array/encode/CMakeLists.txt000066400000000000000000000015331453723256400206020ustar00rootroot00000000000000function(zfp_add_cpp_tests dims type bits) # test templated block encoding set(test_name testTemplatedEncode${dims}${type}) add_executable(${test_name} ${test_name}.cpp) target_link_libraries(${test_name} gtest gtest_main zfp rand${bits}Lib) target_compile_definitions(${test_name} PRIVATE ${zfp_compressed_array_defs}) add_test(NAME ${test_name} COMMAND ${test_name}) endfunction() zfp_add_cpp_tests(1 f 32) zfp_add_cpp_tests(2 f 32) zfp_add_cpp_tests(3 f 32) zfp_add_cpp_tests(4 f 32) zfp_add_cpp_tests(1 d 64) zfp_add_cpp_tests(2 d 64) zfp_add_cpp_tests(3 d 64) zfp_add_cpp_tests(4 d 64) #zfp_add_cpp_tests(1 Int32 32) #zfp_add_cpp_tests(2 Int32 32) #zfp_add_cpp_tests(3 Int32 32) #zfp_add_cpp_tests(4 Int32 32) #zfp_add_cpp_tests(1 Int64 64) #zfp_add_cpp_tests(2 Int64 64) #zfp_add_cpp_tests(3 Int64 64) #zfp_add_cpp_tests(4 Int64 64) zfp-1.0.1/tests/array/encode/testTemplatedEncode1d.cpp000066400000000000000000000007011453723256400227240ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/1dDouble.h" #include "utils/rand64.h" } #define ZFP_FIELD_FUNC zfp_field_1d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_double_1 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_double_1 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_double_1 #define SCALAR double #define DIMS 1 #include "testTemplatedEncodeBase.cpp" zfp-1.0.1/tests/array/encode/testTemplatedEncode1f.cpp000066400000000000000000000006741453723256400227370ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/1dFloat.h" #include "utils/rand32.h" } #define ZFP_FIELD_FUNC zfp_field_1d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_float_1 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_float_1 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_float_1 #define SCALAR float #define DIMS 1 #include "testTemplatedEncodeBase.cpp" zfp-1.0.1/tests/array/encode/testTemplatedEncode2d.cpp000066400000000000000000000007011453723256400227250ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/2dDouble.h" #include "utils/rand64.h" } #define ZFP_FIELD_FUNC zfp_field_2d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_double_2 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_double_2 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_double_2 #define SCALAR double #define DIMS 2 #include "testTemplatedEncodeBase.cpp" zfp-1.0.1/tests/array/encode/testTemplatedEncode2f.cpp000066400000000000000000000006741453723256400227400ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/2dFloat.h" #include "utils/rand32.h" } #define ZFP_FIELD_FUNC zfp_field_2d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_float_2 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_float_2 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_float_2 #define SCALAR float #define DIMS 2 #include "testTemplatedEncodeBase.cpp" zfp-1.0.1/tests/array/encode/testTemplatedEncode3d.cpp000066400000000000000000000007011453723256400227260ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/3dDouble.h" #include "utils/rand64.h" } #define ZFP_FIELD_FUNC zfp_field_3d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_double_3 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_double_3 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_double_3 #define SCALAR double #define DIMS 3 #include "testTemplatedEncodeBase.cpp" zfp-1.0.1/tests/array/encode/testTemplatedEncode3f.cpp000066400000000000000000000006741453723256400227410ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/3dFloat.h" #include "utils/rand32.h" } #define ZFP_FIELD_FUNC zfp_field_3d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_float_3 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_float_3 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_float_3 #define SCALAR float #define DIMS 3 #include "testTemplatedEncodeBase.cpp" zfp-1.0.1/tests/array/encode/testTemplatedEncode4d.cpp000066400000000000000000000007051453723256400227330ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/4dDouble.h" #include "utils/rand64.h" } #define ZFP_FIELD_FUNC zfp_field_4d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_double_4 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_double_4 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_double_4 #define SCALAR double #define DIMS 4 #include "testTemplatedEncodeBase.cpp" zfp-1.0.1/tests/array/encode/testTemplatedEncode4f.cpp000066400000000000000000000006741453723256400227420ustar00rootroot00000000000000#include "zfp.hpp" using namespace zfp; extern "C" { #include "constants/4dFloat.h" #include "utils/rand32.h" } #define ZFP_FIELD_FUNC zfp_field_4d #define ZFP_ENCODE_BLOCK_FUNC zfp_encode_block_float_4 #define ZFP_ENCODE_BLOCK_STRIDED_FUNC zfp_encode_block_strided_float_4 #define ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC zfp_encode_partial_block_strided_float_4 #define SCALAR float #define DIMS 4 #include "testTemplatedEncodeBase.cpp" zfp-1.0.1/tests/array/encode/testTemplatedEncodeBase.cpp000066400000000000000000000225061453723256400233010ustar00rootroot00000000000000extern "C" { #include "utils/testMacros.h" #include "utils/zfpChecksums.h" #include "utils/zfpHash.h" } #include "src/template/codec.h" #include "gtest/gtest.h" #define SX 2 #define SY (3 * BLOCK_SIDE_LEN*SX) #define SZ (2 * BLOCK_SIDE_LEN*SY) #define SW (3 * BLOCK_SIDE_LEN*SZ) #define PX 1 #define PY 2 #define PZ 3 #define PW 4 #define DUMMY_VAL 99 void populateArray(SCALAR** dataArr) { *dataArr = new SCALAR[BLOCK_SIZE]; ASSERT_TRUE(*dataArr != nullptr); for (int i = 0; i < BLOCK_SIZE; i++) { #ifdef FL_PT_DATA (*dataArr)[i] = nextSignedRandFlPt(); #else (*dataArr)[i] = nextSignedRandInt(); #endif } } void populateStridedArray(SCALAR** dataArr, SCALAR dummyVal) { size_t i, j, k, l, countX, countY, countZ, countW; switch(DIMS) { case 1: countX = BLOCK_SIDE_LEN * SX; *dataArr = new SCALAR[countX]; ASSERT_TRUE(*dataArr != nullptr); for (i = 0; i < countX; i++) { if (i % SX) { (*dataArr)[i] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArr)[i] = nextSignedRandFlPt(); #else (*dataArr)[i] = nextSignedRandInt(); #endif } } break; case 2: countX = BLOCK_SIDE_LEN * SX; countY = SY / SX; *dataArr = new SCALAR[countX * countY]; ASSERT_TRUE(*dataArr != nullptr); for (j = 0; j < countY; j++) { for (i = 0; i < countX; i++) { size_t index = countX*j + i; if (i % (countX/BLOCK_SIDE_LEN) || j % (countY/BLOCK_SIDE_LEN)) { (*dataArr)[index] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArr)[index] = nextSignedRandFlPt(); #else (*dataArr)[index] = nextSignedRandInt(); #endif } } } break; case 3: countX = BLOCK_SIDE_LEN * SX; countY = SY / SX; countZ = SZ / SY; *dataArr = new SCALAR[countX * countY * countZ]; ASSERT_TRUE(*dataArr != nullptr); for (k = 0; k < countZ; k++) { for (j = 0; j < countY; j++) { for (i = 0; i < countX; i++) { size_t index = countX*countY*k + countX*j + i; if (i % (countX/BLOCK_SIDE_LEN) || j % (countY/BLOCK_SIDE_LEN) || k % (countZ/BLOCK_SIDE_LEN)) { (*dataArr)[index] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArr)[index] = nextSignedRandFlPt(); #else (*dataArr)[index] = nextSignedRandInt(); #endif } } } } break; case 4: countX = BLOCK_SIDE_LEN * SX; countY = SY / SX; countZ = SZ / SY; countW = SW / SZ; *dataArr = new SCALAR[countX * countY * countZ * countW]; ASSERT_TRUE(*dataArr != nullptr); for (l = 0; l < countW; l++) { for (k = 0; k < countZ; k++) { for (j = 0; j < countY; j++) { for (i = 0; i < countX; i++) { size_t index = countX*countY*countZ*l + countX*countY*k + countX*j + i; if (i % (countX/BLOCK_SIDE_LEN) || j % (countY/BLOCK_SIDE_LEN) || k % (countZ/BLOCK_SIDE_LEN) || l % (countW/BLOCK_SIDE_LEN)) { (*dataArr)[index] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArr)[index] = nextSignedRandFlPt(); #else (*dataArr)[index] = nextSignedRandInt(); #endif } } } } } break; } } void setupStream(zfp_field** field, zfp_stream** stream, bool isStrided = false) { *stream = zfp_stream_open(NULL); zfp_stream_set_rate(*stream, ZFP_RATE_PARAM_BITS, ZFP_TYPE, DIMS, zfp_false); size_t bufsizeBytes = zfp_stream_maximum_size(*stream, *field); char* buffer = (char*)calloc(bufsizeBytes, sizeof(char)); ASSERT_TRUE(buffer != nullptr); bitstream* s = stream_open(buffer, bufsizeBytes); ASSERT_TRUE(s != nullptr); if (isStrided) { switch (DIMS) { case 1: { zfp_field_set_stride_1d(*field, SX); break; } case 2: { zfp_field_set_stride_2d(*field, SX, SY); break; } case 3: { zfp_field_set_stride_3d(*field, SX, SY, SZ); break; } case 4: { zfp_field_set_stride_4d(*field, SX, SY, SZ, SW); break; } } } zfp_stream_set_bit_stream(*stream, s); } bool streamsEqual(zfp_stream** stream1, zfp_stream** stream2) { bitstream* s1 = zfp_stream_bit_stream(*stream1); size_t sz1 = stream_size(s1); char* data1 = (char*)stream_data(s1); zfp_stream_flush(*stream1); bitstream* s2 = zfp_stream_bit_stream(*stream2); size_t sz2 = stream_size(s2); char* data2 = (char*)stream_data(s2); zfp_stream_flush(*stream2); for (size_t i = 0; i < sz1; i++) if (data1[i] != data2[i]) return false; return true; } TEST(TemplatedEncodeTests, given_TemplatedEncodeBlock_resultsMatchNonTemplated) { SCALAR* dataArr; populateArray(&dataArr); zfp_field* field = ZFP_FIELD_FUNC(dataArr, ZFP_TYPE, _repeat_arg(BLOCK_SIDE_LEN, DIMS)); zfp_stream* stream = zfp_stream_open(NULL); setupStream(&field, &stream); size_t sz = ZFP_ENCODE_BLOCK_FUNC(stream, dataArr); zfp_stream* tstream = zfp_stream_open(NULL); setupStream(&field, &tstream); size_t tsz = encode_block(tstream, dataArr); ASSERT_TRUE(sz == tsz); ASSERT_TRUE(streamsEqual(&stream, &tstream)); zfp_field_free(field); stream_close(zfp_stream_bit_stream(stream)); stream_close(zfp_stream_bit_stream(tstream)); zfp_stream_close(stream); zfp_stream_close(tstream); delete[] dataArr; } TEST(TemplatedEncodeTests, given_TemplatedEncodeBlockStrided_resultsMatchNonTemplated) { SCALAR* dataArr; populateStridedArray(&dataArr, DUMMY_VAL); zfp_field* field = ZFP_FIELD_FUNC(dataArr, ZFP_TYPE, _repeat_arg(BLOCK_SIDE_LEN, DIMS)); zfp_stream* stream = zfp_stream_open(NULL); setupStream(&field, &stream, true); zfp_stream* tstream = zfp_stream_open(NULL); setupStream(&field, &tstream, true); #if DIMS == 1 size_t sz = ZFP_ENCODE_BLOCK_STRIDED_FUNC(stream, dataArr, SX); size_t tsz = encode_block_strided(tstream, dataArr, SX); #elif DIMS == 2 size_t sz = ZFP_ENCODE_BLOCK_STRIDED_FUNC(stream, dataArr, SX, SY); size_t tsz = encode_block_strided(tstream, dataArr, SX, SY); #elif DIMS == 3 size_t sz = ZFP_ENCODE_BLOCK_STRIDED_FUNC(stream, dataArr, SX, SY, SZ); size_t tsz = encode_block_strided(tstream, dataArr, SX, SY, SZ); #elif DIMS == 4 size_t sz = ZFP_ENCODE_BLOCK_STRIDED_FUNC(stream, dataArr, SX, SY, SZ, SW); size_t tsz = encode_block_strided(tstream, dataArr, SX, SY, SZ, SW); #endif ASSERT_TRUE(sz == tsz); ASSERT_TRUE(streamsEqual(&stream, &tstream)); zfp_field_free(field); stream_close(zfp_stream_bit_stream(stream)); stream_close(zfp_stream_bit_stream(tstream)); zfp_stream_close(stream); zfp_stream_close(tstream); delete[] dataArr; } TEST(TemplatedEncodeTests, given_TemplatedEncodePartialBlockStrided_resultsMatchNonTemplated) { SCALAR* dataArr; populateStridedArray(&dataArr, DUMMY_VAL); zfp_field* field = ZFP_FIELD_FUNC(dataArr, ZFP_TYPE, _repeat_arg(BLOCK_SIDE_LEN, DIMS)); zfp_stream* stream = zfp_stream_open(NULL); setupStream(&field, &stream, true); zfp_stream* tstream = zfp_stream_open(NULL); setupStream(&field, &tstream, true); #if DIMS == 1 size_t sz = ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC(stream, dataArr, PX, SX); size_t tsz = encode_partial_block_strided(tstream, dataArr, PX, SX); #elif DIMS == 2 size_t sz = ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC(stream, dataArr, PX, PY, SX, SY); size_t tsz = encode_partial_block_strided(tstream, dataArr, PX, PY, SX, SY); #elif DIMS == 3 size_t sz = ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC(stream, dataArr, PX, PY, PZ, SX, SY, SZ); size_t tsz = encode_partial_block_strided(tstream, dataArr, PX, PY, PZ, SX, SY, SZ); #elif DIMS == 4 size_t sz = ZFP_ENCODE_PARTIAL_BLOCK_STRIDED_FUNC(stream, dataArr, PX, PY, PZ, PW, SX, SY, SZ, SW); size_t tsz = encode_partial_block_strided(tstream, dataArr, PX, PY, PZ, PW, SX, SY, SZ, SW); #endif ASSERT_TRUE(sz == tsz); ASSERT_TRUE(streamsEqual(&stream, &tstream)); zfp_field_free(field); stream_close(zfp_stream_bit_stream(stream)); stream_close(zfp_stream_bit_stream(tstream)); zfp_stream_close(stream); zfp_stream_close(tstream); delete[] dataArr; } zfp-1.0.1/tests/array/utils/000077500000000000000000000000001453723256400157435ustar00rootroot00000000000000zfp-1.0.1/tests/array/utils/commonMacros.h000066400000000000000000000003151453723256400205500ustar00rootroot00000000000000#include "zfp.h" #define DIV_ROUND_UP(x, y) (((x) + (y) - 1) / (y)) #define BITS_TO_BYTES(x) DIV_ROUND_UP(x, CHAR_BIT) #define ZFP_HEADER_SIZE_BITS (ZFP_MAGIC_BITS + ZFP_META_BITS + ZFP_MODE_SHORT_BITS) zfp-1.0.1/tests/array/utils/gtest1dTest.h000066400000000000000000000023541453723256400203330ustar00rootroot00000000000000#include "gtest/gtest.h" extern "C" { #include "constants/universalConsts.h" } #define SCALAR double const size_t ARRAY_SIZE = 11; class Array1dTest : public ::testing::Test { public: size_t IterAbsOffset(array1d::iterator iter) { return iter.i(); } size_t IterAbsOffset(array1d::const_iterator citer) { return citer.i(); } protected: virtual void SetUp() { arr.resize(ARRAY_SIZE, true); arr2.resize(ARRAY_SIZE, true); arr.set_rate(ZFP_RATE_PARAM_BITS); arr2.set_rate(ZFP_RATE_PARAM_BITS); offset = 5; viewLen = 3; EXPECT_LT(offset + viewLen, arr.size_x()); } static array1d arr, arr2; static array1d::pointer ptr, ptr2; static array1d::const_pointer cptr, cptr2; static array1d::iterator iter, iter2; static array1d::const_iterator citer, citer2; static size_t offset, viewLen; }; array1d Array1dTest::arr(ARRAY_SIZE, ZFP_RATE_PARAM_BITS); array1d Array1dTest::arr2(ARRAY_SIZE, ZFP_RATE_PARAM_BITS); array1d::pointer Array1dTest::ptr, Array1dTest::ptr2; array1d::const_pointer Array1dTest::cptr, Array1dTest::cptr2; array1d::iterator Array1dTest::iter, Array1dTest::iter2; array1d::const_iterator Array1dTest::citer, Array1dTest::citer2; size_t Array1dTest::offset, Array1dTest::viewLen; zfp-1.0.1/tests/array/utils/gtest1fTest.h000066400000000000000000000023531453723256400203340ustar00rootroot00000000000000#include "gtest/gtest.h" extern "C" { #include "constants/universalConsts.h" } #define SCALAR float const size_t ARRAY_SIZE = 11; class Array1fTest : public ::testing::Test { public: size_t IterAbsOffset(array1f::iterator iter) { return iter.i(); } size_t IterAbsOffset(array1f::const_iterator citer) { return citer.i(); } protected: virtual void SetUp() { arr.resize(ARRAY_SIZE, true); arr2.resize(ARRAY_SIZE, true); arr.set_rate(ZFP_RATE_PARAM_BITS); arr2.set_rate(ZFP_RATE_PARAM_BITS); offset = 5; viewLen = 3; EXPECT_LT(offset + viewLen, arr.size_x()); } static array1f arr, arr2; static array1f::pointer ptr, ptr2; static array1f::const_pointer cptr, cptr2; static array1f::iterator iter, iter2; static array1f::const_iterator citer, citer2; static size_t offset, viewLen; }; array1f Array1fTest::arr(ARRAY_SIZE, ZFP_RATE_PARAM_BITS); array1f Array1fTest::arr2(ARRAY_SIZE, ZFP_RATE_PARAM_BITS); array1f::pointer Array1fTest::ptr, Array1fTest::ptr2; array1f::const_pointer Array1fTest::cptr, Array1fTest::cptr2; array1f::iterator Array1fTest::iter, Array1fTest::iter2; array1f::const_iterator Array1fTest::citer, Array1fTest::citer2; size_t Array1fTest::offset, Array1fTest::viewLen; zfp-1.0.1/tests/array/utils/gtest2dTest.h000066400000000000000000000030371453723256400203330ustar00rootroot00000000000000#include "gtest/gtest.h" extern "C" { #include "constants/universalConsts.h" } #define SCALAR double const size_t ARRAY_SIZE_X = 11; const size_t ARRAY_SIZE_Y = 5; class Array2dTest : public ::testing::Test { public: size_t IterAbsOffset(array2d::iterator iter) { return iter.i() + ARRAY_SIZE_X * iter.j(); } size_t IterAbsOffset(array2d::const_iterator citer) { return citer.i() + ARRAY_SIZE_X * citer.j(); } protected: virtual void SetUp() { arr.resize(ARRAY_SIZE_X, ARRAY_SIZE_Y, true); arr2.resize(ARRAY_SIZE_X, ARRAY_SIZE_Y, true); arr.set_rate(ZFP_RATE_PARAM_BITS); arr2.set_rate(ZFP_RATE_PARAM_BITS); offsetX = 5; viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); offsetY = 1; viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); } static array2d arr, arr2; static array2d::pointer ptr, ptr2; static array2d::const_pointer cptr, cptr2; static array2d::iterator iter, iter2; static array2d::const_iterator citer, citer2; static size_t offsetX, offsetY, viewLenX, viewLenY; }; array2d Array2dTest::arr(ARRAY_SIZE_X, ARRAY_SIZE_Y, ZFP_RATE_PARAM_BITS); array2d Array2dTest::arr2(ARRAY_SIZE_X, ARRAY_SIZE_Y, ZFP_RATE_PARAM_BITS); array2d::pointer Array2dTest::ptr, Array2dTest::ptr2; array2d::const_pointer Array2dTest::cptr, Array2dTest::cptr2; array2d::iterator Array2dTest::iter, Array2dTest::iter2; array2d::const_iterator Array2dTest::citer, Array2dTest::citer2; size_t Array2dTest::offsetX, Array2dTest::offsetY, Array2dTest::viewLenX, Array2dTest::viewLenY; zfp-1.0.1/tests/array/utils/gtest2fTest.h000066400000000000000000000030361453723256400203340ustar00rootroot00000000000000#include "gtest/gtest.h" extern "C" { #include "constants/universalConsts.h" } #define SCALAR float const size_t ARRAY_SIZE_X = 11; const size_t ARRAY_SIZE_Y = 5; class Array2fTest : public ::testing::Test { public: size_t IterAbsOffset(array2f::iterator iter) { return iter.i() + ARRAY_SIZE_X * iter.j(); } size_t IterAbsOffset(array2f::const_iterator citer) { return citer.i() + ARRAY_SIZE_X * citer.j(); } protected: virtual void SetUp() { arr.resize(ARRAY_SIZE_X, ARRAY_SIZE_Y, true); arr2.resize(ARRAY_SIZE_X, ARRAY_SIZE_Y, true); arr.set_rate(ZFP_RATE_PARAM_BITS); arr2.set_rate(ZFP_RATE_PARAM_BITS); offsetX = 5; viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); offsetY = 1; viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); } static array2f arr, arr2; static array2f::pointer ptr, ptr2; static array2f::const_pointer cptr, cptr2; static array2f::iterator iter, iter2; static array2f::const_iterator citer, citer2; static size_t offsetX, offsetY, viewLenX, viewLenY; }; array2f Array2fTest::arr(ARRAY_SIZE_X, ARRAY_SIZE_Y, ZFP_RATE_PARAM_BITS); array2f Array2fTest::arr2(ARRAY_SIZE_X, ARRAY_SIZE_Y, ZFP_RATE_PARAM_BITS); array2f::pointer Array2fTest::ptr, Array2fTest::ptr2; array2f::const_pointer Array2fTest::cptr, Array2fTest::cptr2; array2f::iterator Array2fTest::iter, Array2fTest::iter2; array2f::const_iterator Array2fTest::citer, Array2fTest::citer2; size_t Array2fTest::offsetX, Array2fTest::offsetY, Array2fTest::viewLenX, Array2fTest::viewLenY; zfp-1.0.1/tests/array/utils/gtest3dTest.h000066400000000000000000000035661453723256400203430ustar00rootroot00000000000000#include "gtest/gtest.h" extern "C" { #include "constants/universalConsts.h" } #define SCALAR double const size_t ARRAY_SIZE_X = 11; const size_t ARRAY_SIZE_Y = 18; const size_t ARRAY_SIZE_Z = 5; class Array3dTest : public ::testing::Test { public: size_t IterAbsOffset(array3d::iterator iter) { return iter.i() + ARRAY_SIZE_X * iter.j() + ARRAY_SIZE_X * ARRAY_SIZE_Y * iter.k(); } size_t IterAbsOffset(array3d::const_iterator citer) { return citer.i() + ARRAY_SIZE_X * citer.j() + ARRAY_SIZE_X * ARRAY_SIZE_Y * citer.k(); } protected: virtual void SetUp() { arr.resize(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, true); arr2.resize(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, true); arr.set_rate(ZFP_RATE_PARAM_BITS); arr2.set_rate(ZFP_RATE_PARAM_BITS); offsetX = 5; viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); offsetY = 1; viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); offsetZ = 0; viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); } static array3d arr, arr2; static array3d::pointer ptr, ptr2; static array3d::const_pointer cptr, cptr2; static array3d::iterator iter, iter2; static array3d::const_iterator citer, citer2; static size_t offsetX, offsetY, offsetZ; static size_t viewLenX, viewLenY, viewLenZ; }; array3d Array3dTest::arr(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, ZFP_RATE_PARAM_BITS); array3d Array3dTest::arr2(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, ZFP_RATE_PARAM_BITS); array3d::pointer Array3dTest::ptr, Array3dTest::ptr2; array3d::const_pointer Array3dTest::cptr, Array3dTest::cptr2; array3d::iterator Array3dTest::iter, Array3dTest::iter2; array3d::const_iterator Array3dTest::citer, Array3dTest::citer2; size_t Array3dTest::offsetX, Array3dTest::offsetY, Array3dTest::offsetZ; size_t Array3dTest::viewLenX, Array3dTest::viewLenY, Array3dTest::viewLenZ; zfp-1.0.1/tests/array/utils/gtest3fTest.h000066400000000000000000000035651453723256400203440ustar00rootroot00000000000000#include "gtest/gtest.h" extern "C" { #include "constants/universalConsts.h" } #define SCALAR float const size_t ARRAY_SIZE_X = 11; const size_t ARRAY_SIZE_Y = 18; const size_t ARRAY_SIZE_Z = 5; class Array3fTest : public ::testing::Test { public: size_t IterAbsOffset(array3f::iterator iter) { return iter.i() + ARRAY_SIZE_X * iter.j() + ARRAY_SIZE_X * ARRAY_SIZE_Y * iter.k(); } size_t IterAbsOffset(array3f::const_iterator citer) { return citer.i() + ARRAY_SIZE_X * citer.j() + ARRAY_SIZE_X * ARRAY_SIZE_Y * citer.k(); } protected: virtual void SetUp() { arr.resize(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, true); arr2.resize(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, true); arr.set_rate(ZFP_RATE_PARAM_BITS); arr2.set_rate(ZFP_RATE_PARAM_BITS); offsetX = 5; viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); offsetY = 1; viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); offsetZ = 0; viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); } static array3f arr, arr2; static array3f::pointer ptr, ptr2; static array3f::const_pointer cptr, cptr2; static array3f::iterator iter, iter2; static array3f::const_iterator citer, citer2; static size_t offsetX, offsetY, offsetZ; static size_t viewLenX, viewLenY, viewLenZ; }; array3f Array3fTest::arr(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, ZFP_RATE_PARAM_BITS); array3f Array3fTest::arr2(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, ZFP_RATE_PARAM_BITS); array3f::pointer Array3fTest::ptr, Array3fTest::ptr2; array3f::const_pointer Array3fTest::cptr, Array3fTest::cptr2; array3f::iterator Array3fTest::iter, Array3fTest::iter2; array3f::const_iterator Array3fTest::citer, Array3fTest::citer2; size_t Array3fTest::offsetX, Array3fTest::offsetY, Array3fTest::offsetZ; size_t Array3fTest::viewLenX, Array3fTest::viewLenY, Array3fTest::viewLenZ; zfp-1.0.1/tests/array/utils/gtest4dTest.h000066400000000000000000000043221453723256400203330ustar00rootroot00000000000000#include "gtest/gtest.h" extern "C" { #include "constants/universalConsts.h" } #define SCALAR double const size_t ARRAY_SIZE_X = 14; const size_t ARRAY_SIZE_Y = 9; const size_t ARRAY_SIZE_Z = 7; const size_t ARRAY_SIZE_W = 6; class Array4dTest : public ::testing::Test { public: size_t IterAbsOffset(array4d::iterator iter) { return iter.i() + ARRAY_SIZE_X * iter.j() + ARRAY_SIZE_X * ARRAY_SIZE_Y * iter.k() + ARRAY_SIZE_X * ARRAY_SIZE_Y * ARRAY_SIZE_Z * iter.l(); } size_t IterAbsOffset(array4d::const_iterator citer) { return citer.i() + ARRAY_SIZE_X * citer.j() + ARRAY_SIZE_X * ARRAY_SIZE_Y * citer.k() + ARRAY_SIZE_X * ARRAY_SIZE_Y * ARRAY_SIZE_Z * citer.l(); } protected: virtual void SetUp() { arr.resize(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, ARRAY_SIZE_W, true); arr2.resize(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, ARRAY_SIZE_W, true); arr.set_rate(ZFP_RATE_PARAM_BITS); arr2.set_rate(ZFP_RATE_PARAM_BITS); offsetX = 5; viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); offsetY = 1; viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); offsetZ = 0; viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); offsetW = 1; viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); } static array4d arr, arr2; static array4d::pointer ptr, ptr2; static array4d::const_pointer cptr, cptr2; static array4d::iterator iter, iter2; static array4d::const_iterator citer, citer2; static size_t offsetX, offsetY, offsetZ, offsetW; static size_t viewLenX, viewLenY, viewLenZ, viewLenW; }; array4d Array4dTest::arr(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, ARRAY_SIZE_W, ZFP_RATE_PARAM_BITS); array4d Array4dTest::arr2(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, ARRAY_SIZE_W, ZFP_RATE_PARAM_BITS); array4d::pointer Array4dTest::ptr, Array4dTest::ptr2; array4d::const_pointer Array4dTest::cptr, Array4dTest::cptr2; array4d::iterator Array4dTest::iter, Array4dTest::iter2; array4d::const_iterator Array4dTest::citer, Array4dTest::citer2; size_t Array4dTest::offsetX, Array4dTest::offsetY, Array4dTest::offsetZ, Array4dTest::offsetW; size_t Array4dTest::viewLenX, Array4dTest::viewLenY, Array4dTest::viewLenZ, Array4dTest::viewLenW; zfp-1.0.1/tests/array/utils/gtest4fTest.h000066400000000000000000000043211453723256400203340ustar00rootroot00000000000000#include "gtest/gtest.h" extern "C" { #include "constants/universalConsts.h" } #define SCALAR float const size_t ARRAY_SIZE_X = 14; const size_t ARRAY_SIZE_Y = 9; const size_t ARRAY_SIZE_Z = 7; const size_t ARRAY_SIZE_W = 6; class Array4fTest : public ::testing::Test { public: size_t IterAbsOffset(array4f::iterator iter) { return iter.i() + ARRAY_SIZE_X * iter.j() + ARRAY_SIZE_X * ARRAY_SIZE_Y * iter.k() + ARRAY_SIZE_X * ARRAY_SIZE_Y * ARRAY_SIZE_Z * iter.l(); } size_t IterAbsOffset(array4f::const_iterator citer) { return citer.i() + ARRAY_SIZE_X * citer.j() + ARRAY_SIZE_X * ARRAY_SIZE_Y * citer.k() + ARRAY_SIZE_X * ARRAY_SIZE_Y * ARRAY_SIZE_Z * citer.l(); } protected: virtual void SetUp() { arr.resize(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, ARRAY_SIZE_W, true); arr2.resize(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, ARRAY_SIZE_W, true); arr.set_rate(ZFP_RATE_PARAM_BITS); arr2.set_rate(ZFP_RATE_PARAM_BITS); offsetX = 5; viewLenX = 3; EXPECT_LT(offsetX + viewLenX, arr.size_x()); offsetY = 1; viewLenY = 3; EXPECT_LT(offsetY + viewLenY, arr.size_y()); offsetZ = 0; viewLenZ = 2; EXPECT_LT(offsetZ + viewLenZ, arr.size_z()); offsetW = 1; viewLenW = 4; EXPECT_LT(offsetW + viewLenW, arr.size_w()); } static array4f arr, arr2; static array4f::pointer ptr, ptr2; static array4f::const_pointer cptr, cptr2; static array4f::iterator iter, iter2; static array4f::const_iterator citer, citer2; static size_t offsetX, offsetY, offsetZ, offsetW; static size_t viewLenX, viewLenY, viewLenZ, viewLenW; }; array4f Array4fTest::arr(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, ARRAY_SIZE_W, ZFP_RATE_PARAM_BITS); array4f Array4fTest::arr2(ARRAY_SIZE_X, ARRAY_SIZE_Y, ARRAY_SIZE_Z, ARRAY_SIZE_W, ZFP_RATE_PARAM_BITS); array4f::pointer Array4fTest::ptr, Array4fTest::ptr2; array4f::const_pointer Array4fTest::cptr, Array4fTest::cptr2; array4f::iterator Array4fTest::iter, Array4fTest::iter2; array4f::const_iterator Array4fTest::citer, Array4fTest::citer2; size_t Array4fTest::offsetX, Array4fTest::offsetY, Array4fTest::offsetZ, Array4fTest::offsetW; size_t Array4fTest::viewLenX, Array4fTest::viewLenY, Array4fTest::viewLenZ, Array4fTest::viewLenW; zfp-1.0.1/tests/array/utils/gtestBaseFixture.h000066400000000000000000000075271453723256400214170ustar00rootroot00000000000000#include "gtest/gtest.h" #include #include #include // assumes a constants/.h is already included class ArrayNdTestFixture : public ::testing::TestWithParam { protected: double getRate() { return std::ldexp(1.0, GetParam() + 3); } }; typedef std::tuple testConfig; #define TEST_RATE zfp_mode_fixed_rate #define TEST_PREC zfp_mode_fixed_precision #define TEST_ACCU zfp_mode_fixed_accuracy #define TEST_RVRS zfp_mode_reversible #define TEST_INDEX_IMP 0 #define TEST_INDEX_VRB 1 #define TEST_INDEX_HY4 2 #define TEST_INDEX_HY8 3 #define TEST_INDEX_TYPE_IMP zfp::index::implicit #define TEST_INDEX_TYPE_VRB zfp::index::verbatim #define TEST_INDEX_TYPE_HY4 zfp::index::hybrid4 #define TEST_INDEX_TYPE_HY8 zfp::index::hybrid8 class CArrayNdTestFixture : public ::testing::TestWithParam { protected: static double getRate(int param) { return std::ldexp(1.0, param + 3); } static unsigned int getPrecision(int param) { return 1u << (param + 3); } static double getTolerance(int param) { return std::ldexp(1.0, -(1u << param)); } // get(0): config mode selection // get(1): config mode value selection // get(2): block index type selection zfp_config getConfig() { zfp_config config; switch(std::get<0>(GetParam())) { case zfp_mode_fixed_rate: { //TODO: check with/without align? config = zfp_config_rate(getRate(std::get<1>(GetParam())), true); break; } case zfp_mode_fixed_precision: { config = zfp_config_precision(getPrecision(std::get<1>(GetParam()))); break; } case zfp_mode_fixed_accuracy: { config = zfp_config_accuracy(getTolerance(std::get<1>(GetParam()))); break; } case zfp_mode_reversible: { config = zfp_config_reversible(); break; } case zfp_mode_expert: { //TODO: do we need this one? //config = zfp_config_expert(uint minbits, uint maxbits, uint maxprec, int minexp); //break; } default: { config = zfp_config_none(); break; } } return config; } public: struct PrintToStringParamName { static std::string IndexToStr(int idx) { switch (idx) { case TEST_INDEX_IMP: { return "Implicit"; } case TEST_INDEX_VRB: { return "Verbatim"; } case TEST_INDEX_HY4: { return "Hybrid4"; } case TEST_INDEX_HY8: { return "Hybrid8"; } default: { return "BadIdxType"; } } } template std::string operator()(const testing::TestParamInfo& info) const { std::stringstream out; switch(std::get<0>(info.param)) { case zfp_mode_fixed_rate: { out << "Fixed_Rate_val" << std::get<1>(info.param) << "_idx" << IndexToStr(std::get<2>(info.param)); break; } case zfp_mode_fixed_precision: { out << "Fixed_Precision_val" << std::get<1>(info.param) << "_idx" << IndexToStr(std::get<2>(info.param)); break; } case zfp_mode_fixed_accuracy: { out << "Fixed_Accuracy_val" << std::get<1>(info.param) << "_idx" << IndexToStr(std::get<2>(info.param)); break; } case zfp_mode_reversible: { out << "Reversible_idx" << IndexToStr(std::get<2>(info.param)); break; } case zfp_mode_expert: { out << "Expert_val" << std::get<1>(info.param) << "_idx" << IndexToStr(std::get<2>(info.param)); break; } } return out.str(); } }; }; zfp-1.0.1/tests/array/utils/gtestCApiTest.h000066400000000000000000000014651453723256400206450ustar00rootroot00000000000000#include "gtest/gtest.h" #include "commonMacros.h" class ZfpArrayConstructTest : public ::testing::Test { protected: virtual void SetUp() { size_t num_64bit_entries = DIV_ROUND_UP(ZFP_HEADER_SIZE_BITS, CHAR_BIT * sizeof(uint64)); buffer = new uint64[num_64bit_entries]; bs = stream_open(buffer, num_64bit_entries * sizeof(uint64)); stream = zfp_stream_open(bs); field = zfp_field_alloc(); } virtual void TearDown() { zfp_field_free(field); zfp_stream_close(stream); stream_close(bs); delete[] buffer; } static uint64* buffer; static bitstream* bs; static zfp_stream* stream; static zfp_field* field; }; uint64* ZfpArrayConstructTest::buffer; bitstream* ZfpArrayConstructTest::bs; zfp_stream* ZfpArrayConstructTest::stream; zfp_field* ZfpArrayConstructTest::field; zfp-1.0.1/tests/array/utils/gtestDoubleEnv.h000066400000000000000000000022021453723256400210420ustar00rootroot00000000000000#include "gtest/gtest.h" #include "zfp.h" #include "commonMacros.h" extern "C" { #include "utils/genSmoothRandNums.h" } #define SCALAR double #define ZFP_TYPE zfp_type_double const size_t MIN_TOTAL_ELEMENTS = 1000000; size_t inputDataSideLen, inputDataTotalLen; size_t dimLens[4]; double* inputDataArr; uint64* buffer; bitstream* bs; zfp_stream* stream; zfp_field* field; class ArrayDoubleTestEnv : public ::testing::Environment { public: virtual int getDims() = 0; virtual void SetUp() { generateSmoothRandDoubles(MIN_TOTAL_ELEMENTS, getDims(), &inputDataArr, &inputDataSideLen, &inputDataTotalLen); for (int i = 0; i < 4; i++) { dimLens[i] = (i < getDims()) ? inputDataSideLen : 0; } size_t num_64bit_entries = DIV_ROUND_UP(ZFP_HEADER_SIZE_BITS, CHAR_BIT * sizeof(uint64)); buffer = new uint64[num_64bit_entries]; bs = stream_open(buffer, num_64bit_entries * sizeof(uint64)); stream = zfp_stream_open(bs); field = zfp_field_alloc(); } virtual void TearDown() { free(inputDataArr); zfp_field_free(field); zfp_stream_close(stream); stream_close(bs); delete[] buffer; } }; zfp-1.0.1/tests/array/utils/gtestFloatEnv.h000066400000000000000000000021751453723256400207060ustar00rootroot00000000000000#include "gtest/gtest.h" #include "zfp.h" #include "commonMacros.h" extern "C" { #include "utils/genSmoothRandNums.h" } #define SCALAR float #define ZFP_TYPE zfp_type_float const size_t MIN_TOTAL_ELEMENTS = 1000000; size_t inputDataSideLen, inputDataTotalLen; size_t dimLens[4]; float* inputDataArr; uint64* buffer; bitstream* bs; zfp_stream* stream; zfp_field* field; class ArrayFloatTestEnv : public ::testing::Environment { public: virtual int getDims() = 0; virtual void SetUp() { generateSmoothRandFloats(MIN_TOTAL_ELEMENTS, getDims(), &inputDataArr, &inputDataSideLen, &inputDataTotalLen); for (int i = 0; i < 4; i++) { dimLens[i] = (i < getDims()) ? inputDataSideLen : 0; } size_t num_64bit_entries = DIV_ROUND_UP(ZFP_HEADER_SIZE_BITS, CHAR_BIT * sizeof(uint64)); buffer = new uint64[num_64bit_entries]; bs = stream_open(buffer, num_64bit_entries * sizeof(uint64)); stream = zfp_stream_open(bs); field = zfp_field_alloc(); } virtual void TearDown() { free(inputDataArr); zfp_field_free(field); zfp_stream_close(stream); stream_close(bs); delete[] buffer; } }; zfp-1.0.1/tests/array/utils/gtestSingleFixture.h000066400000000000000000000001751453723256400217560ustar00rootroot00000000000000#include "gtest/gtest.h" class TestFixture : public ::testing::TestWithParam { protected: virtual void SetUp() {} }; zfp-1.0.1/tests/array/utils/gtestTestEnv.h000066400000000000000000000002151453723256400205510ustar00rootroot00000000000000#include "gtest/gtest.h" class TestEnv : public ::testing::Environment { public: virtual void SetUp() {} virtual void TearDown() {} }; zfp-1.0.1/tests/array/utils/predicates.h000066400000000000000000000032211453723256400202350ustar00rootroot00000000000000#include "zfp/array1.hpp" #include "gtest/gtest.h" testing::AssertionResult ExpectEqPrintHexPred(const char* expected_expr, const char* actual_expr, uint64 expected, uint64 actual) { if (actual == expected) return testing::AssertionSuccess(); std::stringstream ss, msg; std::string expected_str, actual_str; ss.str(""); ss << std::showbase << std::hex << expected; expected_str = ss.str(); ss.str(""); ss << std::showbase << std::hex << actual; actual_str = ss.str(); msg << "\t Expected: " << expected_expr; if (expected_str != expected_expr) { msg << "\n\t Which is: " << std::showbase << std::hex << expected; } msg << "\nTo be equal to: " << actual_expr; if (actual_str != actual_expr) { msg << "\n\t Which is: " << std::showbase << std::hex << actual; } return testing::AssertionFailure() << msg.str(); } testing::AssertionResult ExpectNeqPrintHexPred(const char* expected_expr, const char* actual_expr, uint64 expected, uint64 actual) { if (actual != expected) return testing::AssertionSuccess(); std::stringstream ss, msg; std::string expected_str, actual_str; ss.str(""); ss << std::showbase << std::hex << expected; expected_str = ss.str(); ss.str(""); ss << std::showbase << std::hex << actual; actual_str = ss.str(); msg << "\t Expected: " << expected_expr; if (expected_str != expected_expr) { msg << "\n\t Which is: " << std::showbase << std::hex << expected; } msg << "\nNot to be equal to: " << actual_expr; if (actual_str != actual_expr) { msg << "\n\t Which is: " << std::showbase << std::hex << actual; } return testing::AssertionFailure() << msg.str(); } zfp-1.0.1/tests/array/zfp/000077500000000000000000000000001453723256400154025ustar00rootroot00000000000000zfp-1.0.1/tests/array/zfp/CMakeLists.txt000066400000000000000000000004571453723256400201500ustar00rootroot00000000000000if(ZFP_WITH_ALIGNED_ALLOC) add_executable(testAlignedMemory testAlignedMemory.cpp) target_link_libraries(testAlignedMemory gtest gtest_main zfp) target_compile_definitions(testAlignedMemory PRIVATE ${zfp_compressed_array_defs}) add_test(NAME testAlignedMemory COMMAND testAlignedMemory) endif() zfp-1.0.1/tests/array/zfp/testAlignedMemory.cpp000066400000000000000000000015651453723256400215510ustar00rootroot00000000000000#include "zfp/array3.hpp" using namespace zfp; #include "gtest/gtest.h" #include "../utils/gtestTestEnv.h" #include "../utils/gtestSingleFixture.h" #include "../utils/predicates.h" #include TestEnv* const testEnv = new TestEnv; class AlignedMemoryTest : public TestFixture {}; #define TEST_FIXTURE AlignedMemoryTest INSTANTIATE_TEST_SUITE_P(TestManyMemoryAlignments, TEST_FIXTURE, ::testing::Range(4, 11)); TEST_P(TEST_FIXTURE, when_allocateAlignedMem_expect_addressAligned) { size_t alignmentBytes = (size_t)(1u << GetParam()); void* ptr = allocate_aligned(30, alignmentBytes); uintptr_t address = (uintptr_t)ptr; EXPECT_EQ(address % alignmentBytes, 0); deallocate_aligned(ptr); } int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); static_cast(::testing::AddGlobalTestEnvironment(testEnv)); return RUN_ALL_TESTS(); } zfp-1.0.1/tests/cfp/000077500000000000000000000000001453723256400142355ustar00rootroot00000000000000zfp-1.0.1/tests/cfp/CMakeLists.txt000066400000000000000000000012301453723256400167710ustar00rootroot00000000000000function(cfp_add_test dims type bits) set(test_name testCfpArray${dims}${type}) add_executable(${test_name} ${test_name}.c) target_link_libraries(${test_name} cmocka cfp zfpHashLib genSmoothRandNumsLib zfpChecksumsLib) add_test(NAME ${test_name} COMMAND ${test_name}) endfunction() cfp_add_test(1 f 32) cfp_add_test(2 f 32) cfp_add_test(3 f 32) cfp_add_test(4 f 32) cfp_add_test(1 d 64) cfp_add_test(2 d 64) cfp_add_test(3 d 64) cfp_add_test(4 d 64) if(DEFINED CFP_NAMESPACE) add_executable(testCfpNamespace testCfpNamespace.c) target_link_libraries(testCfpNamespace cmocka cfp) add_test(NAME testCfpNamespace COMMAND testCfpNamespace) endif() zfp-1.0.1/tests/cfp/testCfpArray1_source.c000066400000000000000000000476451453723256400204710ustar00rootroot00000000000000// ############### // cfp_array tests // ############### static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_ctor_expect_paramsSet)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size(cfpArr), bundle->totalDataLen); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.rate(cfpArr) >= bundle->rate); uchar* compressedPtr = CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(cfpArr); size_t compressedSize = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(cfpArr); assert_int_not_equal(hashBitstream((uint64*)compressedPtr, compressedSize), 0); // sets a minimum cache size assert_true(CFP_NAMESPACE.SUB_NAMESPACE.cache_size(cfpArr) >= bundle->csize); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _header_expect_matchingMetadata)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE srcCfpArr = bundle->cfpArr; CFP_HEADER_TYPE srcCfpHdr = CFP_NAMESPACE.SUB_NAMESPACE.header.ctor(srcCfpArr); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.scalar_type(srcCfpHdr), SCALAR_TYPE); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.dimensionality(srcCfpHdr), 1); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.rate(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.rate(srcCfpArr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.size_x(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.size(srcCfpArr)), // cleanup CFP_NAMESPACE.SUB_NAMESPACE.header.dtor(srcCfpHdr); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_resize_expect_sizeChanged)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t newSize = 999; assert_int_not_equal(CFP_NAMESPACE.SUB_NAMESPACE.size(cfpArr), newSize); CFP_NAMESPACE.SUB_NAMESPACE.resize(cfpArr, newSize, 1); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size(cfpArr), newSize); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_set_expect_entryWrittenToCacheOnly)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; // getting the ptr automatically flushes cache, so do this before setting an entry uchar* compressedDataPtr = CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(cfpArr); size_t compressedSize = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(cfpArr); uchar* oldMemory = malloc(compressedSize * sizeof(uchar)); memcpy(oldMemory, compressedDataPtr, compressedSize); CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, 1, VAL); assert_memory_equal(compressedDataPtr, oldMemory, compressedSize); free(oldMemory); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_get_expect_entryReturned)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1; CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, i, VAL); // dirty cache doesn't immediately apply compression assert_true(CFP_NAMESPACE.SUB_NAMESPACE.get(cfpArr, i) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_ref_expect_arrayObjectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i); assert_ptr_equal(cfpArrRef.array.object, cfpArr.object); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_ptr_expect_arrayObjectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArr.object); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_begin_expect_objectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 0); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_end_expect_objectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.end(cfpArr); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, SIZE_X); } // ############# // cfp_ref tests // ############# static void _catFunc3(given_, CFP_REF_TYPE, _when_get_expect_entryReturned)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i); CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, i, VAL); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.reference.get(cfpArrRef) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_REF_TYPE, _when_set_expect_arrayUpdated)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i); CFP_NAMESPACE.SUB_NAMESPACE.reference.set(cfpArrRef, VAL); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.get(cfpArr, i) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_REF_TYPE, _when_copy_expect_arrayUpdated)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, i1, VAL); CFP_REF_TYPE cfpArrRef_a = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i1); CFP_REF_TYPE cfpArrRef_b = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i2); CFP_NAMESPACE.SUB_NAMESPACE.reference.copy(cfpArrRef_b, cfpArrRef_a); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.get(cfpArr, i2) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_REF_TYPE, _when_ptr_expect_addressMatches)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i); CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.reference.ptr(cfpArrRef); assert_ptr_equal(cfpArrRef.array.object, cfpArrPtr.reference.array.object); } // ############# // cfp_ptr tests // ############# static void _catFunc3(given_, CFP_PTR_TYPE, _when_get_set_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1; SCALAR val = 5; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i); CFP_NAMESPACE.SUB_NAMESPACE.pointer.set(cfpArrPtr, val); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get(cfpArrPtr) < 1e-12); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get(cfpArrPtr) > -1e-12); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_get_at_set_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, io = 3; SCALAR val = 5; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i); CFP_NAMESPACE.SUB_NAMESPACE.pointer.set_at(cfpArrPtr, io, val); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get_at(cfpArrPtr, io) < 1e-12); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get_at(cfpArrPtr, io) > -1e-12); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_ref_expect_addressMatches)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.pointer.ref(cfpArrPtr); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArrRef.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_ref_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1; size_t oi = 10; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.pointer.ref_at(cfpArrPtr, oi); assert_int_equal(cfpArrPtr.reference.x + oi, cfpArrRef.x); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArrRef.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_lt_expect_less)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 5; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.lt(cfpArrPtrA, cfpArrPtrB)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_gt_expect_greater)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 5; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.gt(cfpArrPtrB, cfpArrPtrA)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_leq_expect_less_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 5; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.leq(cfpArrPtrA, cfpArrPtrA)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.leq(cfpArrPtrA, cfpArrPtrB)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_geq_expect_greater_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 5; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.geq(cfpArrPtrA, cfpArrPtrA)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.geq(cfpArrPtrB, cfpArrPtrA)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_eq_expect_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.eq(cfpArrPtrA, cfpArrPtrA)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_neq_expect_not_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 5; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.neq(cfpArrPtrA, cfpArrPtrB)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_distance_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 5; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.pointer.distance(cfpArrPtrA, cfpArrPtrB), (int)cfpArrPtrB.reference.x - (int)cfpArrPtrA.reference.x); assert_ptr_equal(cfpArrPtrA.reference.array.object, cfpArrPtrB.reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_next_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, oi = 10; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.next(cfpArrPtr, oi); assert_int_equal(cfpArrPtr.reference.x, i + oi); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i).reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_prev_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 15, oi = 10; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.prev(cfpArrPtr, oi); assert_int_equal(cfpArrPtr.reference.x, i - oi); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i).reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_inc_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.inc(cfpArrPtr); assert_int_equal(cfpArrPtr.reference.x, i + 1); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i).reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_dec_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.dec(cfpArrPtr); assert_int_equal(cfpArrPtr.reference.x, i - 1); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i).reference.array.object); } // ############## // cfp_iter tests // ############## static void _catFunc3(given_, CFP_ITER_TYPE, _when_ref_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ref(cfpArrIter); assert_ptr_equal(cfpArrRef.array.object, cfpArr.object); assert_int_equal(cfpArrRef.x, 0); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_ref_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t io = 5; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ref_at(cfpArrIter, io); assert_ptr_equal(cfpArrRef.array.object, cfpArr.object); assert_int_equal(cfpArrRef.x, io); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_ptr_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ptr(cfpArrIter); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArr.object); assert_int_equal(cfpArrPtr.reference.x, 0); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_ptr_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t io = 5; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ptr_at(cfpArrIter, io); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArr.object); assert_int_equal(cfpArrPtr.reference.x, io); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_inc_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.inc(cfpArrIter); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 1); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_dec_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter.x = 4; cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.dec(cfpArrIter); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 3); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_next_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter, 4); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter, 3); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 7); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_prev_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter, 7); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.prev(cfpArrIter, 3); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 4); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_distance_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 3); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 7); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.iterator.distance(cfpArrIter1, cfpArrIter2), 4); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.iterator.distance(cfpArrIter2, CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr)), -7); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_lt_expect_less)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 3); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 7); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.lt(cfpArrIter1, cfpArrIter2)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_gt_expect_greater)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 3); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 7); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.gt(cfpArrIter2, cfpArrIter1)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_leq_expect_less_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 3); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 7); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.leq(cfpArrIter1, cfpArrIter1)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.leq(cfpArrIter1, cfpArrIter2)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_geq_expect_greater_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 3); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 7); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.geq(cfpArrIter1, cfpArrIter1)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.geq(cfpArrIter2, cfpArrIter1)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_get_index_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); size_t idx = CFP_NAMESPACE.SUB_NAMESPACE.iterator.i(cfpArrIter); assert_int_equal(idx, 0u); } zfp-1.0.1/tests/cfp/testCfpArray1d.c000066400000000000000000000205421453723256400172400ustar00rootroot00000000000000#include "src/traitsd.h" #include "src/block1.h" #include "constants/1dDouble.h" #define CFP_ARRAY_TYPE cfp_array1d #define CFP_REF_TYPE cfp_ref1d #define CFP_PTR_TYPE cfp_ptr1d #define CFP_ITER_TYPE cfp_iter1d #define SUB_NAMESPACE array1d #define SCALAR double #define SCALAR_TYPE zfp_type_double #define DIMENSIONALITY 1 #include "testCfpArray_source.c" #include "testCfpArray1_source.c" int main() { const struct CMUnitTest tests[] = { cmocka_unit_test(when_seededRandomSmoothDataGenerated_expect_ChecksumMatches), cmocka_unit_test(given_cfp_array1d_when_defaultCtor_expect_returnsNonNullPtr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_ctor_expect_paramsSet, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_copyCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_copyCtor_expect_cacheCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_headerCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_header_expect_matchingMetadata, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_header_when_bufferCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_header_when_bufferCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_setRate_expect_rateSet, setupCfpArrMinimal, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_setCacheSize_expect_cacheSizeSet, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_with_dirtyCache_when_flushCache_expect_cacheEntriesPersistedToMemory, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_clearCache_expect_cacheCleared, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_resize_expect_sizeChanged, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_setFlat_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_getFlat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_set_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_ref_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_ptr_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_ref_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_ptr_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_begin_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_end_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref1d_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref1d_when_set_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref1d_when_ptr_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref1d_when_copy_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1d_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1d_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1d_when_ref_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1d_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1d_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1d_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1d_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1d_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1d_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1d_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1d_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1d_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1d_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1d_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1d_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_ref_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_ptr_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_ptr_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_iterate_touch_all, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1d_when_get_index_expect_correct, setupCfpArrSmall, teardownCfpArr), // fixed rate rounds up to multiples of 16 (omit fixed rate 8) cmocka_unit_test_setup_teardown(given_cfp_array1d_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate1, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate2, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate1, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1d_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate2, teardownCfpArr), }; return cmocka_run_group_tests(tests, prepCommonSetupVars, teardownCommonSetupVars); } zfp-1.0.1/tests/cfp/testCfpArray1f.c000066400000000000000000000205361453723256400172450ustar00rootroot00000000000000#include "src/traitsf.h" #include "src/block1.h" #include "constants/1dFloat.h" #define CFP_ARRAY_TYPE cfp_array1f #define CFP_REF_TYPE cfp_ref1f #define CFP_PTR_TYPE cfp_ptr1f #define CFP_ITER_TYPE cfp_iter1f #define SUB_NAMESPACE array1f #define SCALAR float #define SCALAR_TYPE zfp_type_float #define DIMENSIONALITY 1 #include "testCfpArray_source.c" #include "testCfpArray1_source.c" int main() { const struct CMUnitTest tests[] = { cmocka_unit_test(when_seededRandomSmoothDataGenerated_expect_ChecksumMatches), cmocka_unit_test(given_cfp_array1f_when_defaultCtor_expect_returnsNonNullPtr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_ctor_expect_paramsSet, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_copyCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_copyCtor_expect_cacheCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_headerCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_header_expect_matchingMetadata, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_header_when_bufferCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_header_when_bufferCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_setRate_expect_rateSet, setupCfpArrMinimal, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_setCacheSize_expect_cacheSizeSet, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_with_dirtyCache_when_flushCache_expect_cacheEntriesPersistedToMemory, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_clearCache_expect_cacheCleared, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_resize_expect_sizeChanged, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_setFlat_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_getFlat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_set_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_ref_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_ptr_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_ref_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_ptr_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_begin_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_end_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref1f_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref1f_when_set_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref1f_when_ptr_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref1f_when_copy_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1f_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1f_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1f_when_ref_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1f_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1f_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1f_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1f_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1f_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1f_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1f_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1f_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1f_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1f_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1f_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr1f_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_ref_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_ptr_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_ptr_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_iterate_touch_all, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter1f_when_get_index_expect_correct, setupCfpArrSmall, teardownCfpArr), // fixed rate rounds up to multiples of 16 (omit fixed rate 8) cmocka_unit_test_setup_teardown(given_cfp_array1f_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate1, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate2, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate1, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array1f_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate2, teardownCfpArr), }; return cmocka_run_group_tests(tests, prepCommonSetupVars, teardownCommonSetupVars); } zfp-1.0.1/tests/cfp/testCfpArray2_source.c000066400000000000000000000547531453723256400204700ustar00rootroot00000000000000// ############### // cfp_array tests // ############### static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_ctor_expect_paramsSet)(void **state) { struct setupVars *bundle = *state; size_t csize = 300; CFP_ARRAY_TYPE cfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor(bundle->dataSideLen, bundle->dataSideLen, bundle->rate, bundle->dataArr, csize); assert_non_null(cfpArr.object); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size(cfpArr), bundle->totalDataLen); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.rate(cfpArr) >= bundle->rate); uchar* compressedPtr = CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(cfpArr); size_t compressedSize = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(cfpArr); assert_int_not_equal(hashBitstream((uint64*)compressedPtr, compressedSize), 0); // sets a minimum cache size assert_true(CFP_NAMESPACE.SUB_NAMESPACE.cache_size(cfpArr) >= csize); CFP_NAMESPACE.SUB_NAMESPACE.dtor(cfpArr); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _header_expect_matchingMetadata)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE srcCfpArr = bundle->cfpArr; CFP_HEADER_TYPE srcCfpHdr = CFP_NAMESPACE.SUB_NAMESPACE.header.ctor(srcCfpArr); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.scalar_type(srcCfpHdr), SCALAR_TYPE); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.dimensionality(srcCfpHdr), 2); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.rate(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.rate(srcCfpArr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.size_x(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.size_x(srcCfpArr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.size_y(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.size_y(srcCfpArr)); // cleanup CFP_NAMESPACE.SUB_NAMESPACE.header.dtor(srcCfpHdr); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_resize_expect_sizeChanged)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t newSizeX = 81, newSizeY = 123; assert_int_not_equal(CFP_NAMESPACE.SUB_NAMESPACE.size(cfpArr), newSizeX * newSizeY); CFP_NAMESPACE.SUB_NAMESPACE.resize(cfpArr, newSizeX, newSizeY, 1); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr), newSizeX); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr), newSizeY); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size(cfpArr), newSizeX * newSizeY); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_set_expect_entryWrittenToCacheOnly)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; // getting the ptr automatically flushes cache, so do this before setting an entry uchar* compressedDataPtr = CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(cfpArr); size_t compressedSize = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(cfpArr); uchar* oldMemory = malloc(compressedSize * sizeof(uchar)); memcpy(oldMemory, compressedDataPtr, compressedSize); CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, 1, 1, (SCALAR)VAL); assert_memory_equal(compressedDataPtr, oldMemory, compressedSize); free(oldMemory); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_get_expect_entryReturned)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2; CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, i, j, (SCALAR)VAL); // dirty cache doesn't immediately apply compression assert_true(CFP_NAMESPACE.SUB_NAMESPACE.get(cfpArr, i, j) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_ref_expect_arrayObjectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i, j); assert_ptr_equal(cfpArrRef.array.object, cfpArr.object); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_ptr_expect_arrayObjectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArr.object); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_begin_expect_objectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 0); assert_int_equal(cfpArrIter.y, 0); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_end_expect_objectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.end(cfpArr); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 0); assert_int_equal(cfpArrIter.y, SIZE_Y); } // ############# // cfp_ref tests // ############# static void _catFunc3(given_, CFP_REF_TYPE, _when_get_expect_entryReturned)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i, j); CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, i, j, VAL); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.reference.get(cfpArrRef) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_REF_TYPE, _when_set_expect_arrayUpdated)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i, j); CFP_NAMESPACE.SUB_NAMESPACE.reference.set(cfpArrRef, VAL); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.get(cfpArr, i, j) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_REF_TYPE, _when_copy_expect_arrayUpdated)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, j1 = 2, i2 = 2, j2 = 1; CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, i1, j1, VAL); CFP_REF_TYPE cfpArrRef_a = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i1, j1); CFP_REF_TYPE cfpArrRef_b = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i2, j2); CFP_NAMESPACE.SUB_NAMESPACE.reference.copy(cfpArrRef_b, cfpArrRef_a); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.get(cfpArr, i2, j2) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_REF_TYPE, _when_ptr_expect_addressMatches)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i, j); CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.reference.ptr(cfpArrRef); assert_ptr_equal(cfpArrRef.array.object, cfpArrPtr.reference.array.object); } // ############# // cfp_ptr tests // ############# static void _catFunc3(given_, CFP_PTR_TYPE, _when_get_set_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2; SCALAR val = 5; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j); CFP_NAMESPACE.SUB_NAMESPACE.pointer.set(cfpArrPtr, val); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get(cfpArrPtr) < 1e-12); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get(cfpArrPtr) > -1e-12); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_get_at_set_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, io = 3; SCALAR val = 5; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j); CFP_NAMESPACE.SUB_NAMESPACE.pointer.set_at(cfpArrPtr, io, val); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get_at(cfpArrPtr, io) < 1e-12); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get_at(cfpArrPtr, io) > -1e-12); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_ref_expect_addressMatches)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.pointer.ref(cfpArrPtr); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArrRef.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_ref_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2; size_t oi = 10; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.pointer.ref_at(cfpArrPtr, oi); assert_int_equal(cfpArrPtr.reference.x + oi, cfpArrRef.x); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArrRef.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_lt_expect_less)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 1, j2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.lt(cfpArrPtrA, cfpArrPtrB)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_gt_expect_greater)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 1, j2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.gt(cfpArrPtrB, cfpArrPtrA)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_leq_expect_less_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 1, j2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.leq(cfpArrPtrA, cfpArrPtrA)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.leq(cfpArrPtrA, cfpArrPtrB)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_geq_expect_greater_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 1, j2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.geq(cfpArrPtrA, cfpArrPtrA)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.geq(cfpArrPtrB, cfpArrPtrA)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_eq_expect_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1; size_t j1 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.eq(cfpArrPtrA, cfpArrPtrA)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_neq_expect_not_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 2, j2 = 1; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.neq(cfpArrPtrA, cfpArrPtrB)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_distance_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 2, j2 = 1; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2); assert_int_equal((int)CFP_NAMESPACE.SUB_NAMESPACE.pointer.distance(cfpArrPtrA, cfpArrPtrB), (int)(i2 + j2*CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr)) - (int)(i1 + j1*CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr))); assert_ptr_equal(cfpArrPtrA.reference.array.object, cfpArrPtrB.reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_next_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, oi = 10; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.next(cfpArrPtr, oi); size_t idx = (i + CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * j) + oi; size_t x = idx % CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); size_t y = idx / CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); assert_int_equal(cfpArrPtr.reference.x, x); assert_int_equal(cfpArrPtr.reference.y, y); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j).reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_prev_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 8, j = 2, oi = 5; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.prev(cfpArrPtr, oi); size_t idx = (i + CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * j) - oi; size_t x = idx % CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); size_t y = idx / CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); assert_int_equal(cfpArrPtr.reference.x, x); assert_int_equal(cfpArrPtr.reference.y, y); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j).reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_inc_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.inc(cfpArrPtr); size_t idx = (i + CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * j) + 1; size_t x = idx % CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); size_t y = idx / CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); assert_int_equal(cfpArrPtr.reference.x, x); assert_int_equal(cfpArrPtr.reference.y, y); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j).reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_dec_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.dec(cfpArrPtr); size_t idx = (i + CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * j) - 1; size_t x = idx % CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); size_t y = idx / CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); assert_int_equal(cfpArrPtr.reference.x, x); assert_int_equal(cfpArrPtr.reference.y, y); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j).reference.array.object); } // ############## // cfp_iter tests // ############## static void _catFunc3(given_, CFP_ITER_TYPE, _when_ref_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ref(cfpArrIter); assert_ptr_equal(cfpArrRef.array.object, cfpArr.object); assert_int_equal(cfpArrRef.x, 0); assert_int_equal(cfpArrRef.y, 0); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_ref_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t io = 21; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ref_at(cfpArrIter, io); assert_ptr_equal(cfpArrRef.array.object, cfpArr.object); assert_int_equal(cfpArrRef.x, 5); assert_int_equal(cfpArrRef.y, 1); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_ptr_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ptr(cfpArrIter); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArr.object); assert_int_equal(cfpArrPtr.reference.x, 0); assert_int_equal(cfpArrPtr.reference.y, 0); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_ptr_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t io = 21; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ptr_at(cfpArrIter, io); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArr.object); assert_int_equal(cfpArrPtr.reference.x, 5); assert_int_equal(cfpArrPtr.reference.y, 1); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_inc_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.inc(cfpArrIter); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 1); assert_int_equal(cfpArrIter.y, 0); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_dec_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter.x = 4; cfpArrIter.y = 0; cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.dec(cfpArrIter); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 3); assert_int_equal(cfpArrIter.y, 3); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_next_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter, 16); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter, 15); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 7); assert_int_equal(cfpArrIter.y, 3); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_prev_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter, 31); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.prev(cfpArrIter, 15); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 4); assert_int_equal(cfpArrIter.y, 0); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_distance_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 15); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 31); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.iterator.distance(cfpArrIter1, cfpArrIter2), 16); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.iterator.distance(cfpArrIter2, CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr)), -31); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_lt_expect_less)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 15); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 31); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.lt(cfpArrIter1, cfpArrIter2)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_gt_expect_greater)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 15); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 31); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.gt(cfpArrIter2, cfpArrIter1)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_leq_expect_less_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 15); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 31); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.leq(cfpArrIter1, cfpArrIter1)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.leq(cfpArrIter1, cfpArrIter2)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_geq_expect_greater_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 15); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 31); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.geq(cfpArrIter1, cfpArrIter1)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.geq(cfpArrIter2, cfpArrIter1)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_get_index_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter.x = 1; cfpArrIter.y = 3; size_t i_idx = CFP_NAMESPACE.SUB_NAMESPACE.iterator.i(cfpArrIter); size_t j_idx = CFP_NAMESPACE.SUB_NAMESPACE.iterator.j(cfpArrIter); assert_int_equal(i_idx, 1u); assert_int_equal(j_idx, 3u); } zfp-1.0.1/tests/cfp/testCfpArray2d.c000066400000000000000000000210711453723256400172370ustar00rootroot00000000000000#include "src/traitsd.h" #include "src/block2.h" #include "constants/2dDouble.h" #define CFP_ARRAY_TYPE cfp_array2d #define CFP_REF_TYPE cfp_ref2d #define CFP_PTR_TYPE cfp_ptr2d #define CFP_ITER_TYPE cfp_iter2d #define SUB_NAMESPACE array2d #define SCALAR double #define SCALAR_TYPE zfp_type_double #define DIMENSIONALITY 2 #include "testCfpArray_source.c" #include "testCfpArray2_source.c" int main() { const struct CMUnitTest tests[] = { cmocka_unit_test(when_seededRandomSmoothDataGenerated_expect_ChecksumMatches), cmocka_unit_test(given_cfp_array2d_when_defaultCtor_expect_returnsNonNullPtr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_ctor_expect_paramsSet, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_copyCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_copyCtor_expect_cacheCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_headerCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_header_expect_matchingMetadata, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_header_when_bufferCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_header_when_bufferCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_setRate_expect_rateSet, setupCfpArrMinimal, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_setCacheSize_expect_cacheSizeSet, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_with_dirtyCache_when_flushCache_expect_cacheEntriesPersistedToMemory, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_clearCache_expect_cacheCleared, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_resize_expect_sizeChanged, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_setFlat_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_getFlat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_set_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_ref_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_ptr_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_ref_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_ptr_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_begin_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_end_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref2d_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref2d_when_set_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref2d_when_ptr_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref2d_when_copy_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2d_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2d_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2d_when_ref_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2d_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2d_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2d_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2d_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2d_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2d_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2d_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2d_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2d_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2d_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2d_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2d_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_ref_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_ptr_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_ptr_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_iterate_touch_all, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2d_when_get_index_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate0, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate1, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate2, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate0, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate1, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2d_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate2, teardownCfpArr), }; return cmocka_run_group_tests(tests, prepCommonSetupVars, teardownCommonSetupVars); } zfp-1.0.1/tests/cfp/testCfpArray2f.c000066400000000000000000000210661453723256400172450ustar00rootroot00000000000000#include "src/traitsf.h" #include "src/block2.h" #include "constants/2dFloat.h" #define CFP_ARRAY_TYPE cfp_array2f #define CFP_REF_TYPE cfp_ref2f #define CFP_PTR_TYPE cfp_ptr2f #define CFP_ITER_TYPE cfp_iter2f #define SUB_NAMESPACE array2f #define SCALAR float #define SCALAR_TYPE zfp_type_float #define DIMENSIONALITY 2 #include "testCfpArray_source.c" #include "testCfpArray2_source.c" int main() { const struct CMUnitTest tests[] = { cmocka_unit_test(when_seededRandomSmoothDataGenerated_expect_ChecksumMatches), cmocka_unit_test(given_cfp_array2f_when_defaultCtor_expect_returnsNonNullPtr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_ctor_expect_paramsSet, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_copyCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_copyCtor_expect_cacheCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_headerCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_header_expect_matchingMetadata, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_header_when_bufferCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_header_when_bufferCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_setRate_expect_rateSet, setupCfpArrMinimal, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_setCacheSize_expect_cacheSizeSet, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_with_dirtyCache_when_flushCache_expect_cacheEntriesPersistedToMemory, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_clearCache_expect_cacheCleared, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_resize_expect_sizeChanged, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_setFlat_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_getFlat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_set_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_ref_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_ptr_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_ref_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_ptr_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_begin_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_end_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref2f_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref2f_when_set_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref2f_when_ptr_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref2f_when_copy_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2f_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2f_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2f_when_ref_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2f_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2f_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2f_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2f_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2f_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2f_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2f_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2f_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2f_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2f_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2f_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr2f_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_ref_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_ptr_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_ptr_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_iterate_touch_all, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter2f_when_get_index_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate0, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate1, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate2, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate0, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate1, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array2f_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate2, teardownCfpArr), }; return cmocka_run_group_tests(tests, prepCommonSetupVars, teardownCommonSetupVars); } zfp-1.0.1/tests/cfp/testCfpArray3_source.c000066400000000000000000000614721453723256400204650ustar00rootroot00000000000000// ############### // cfp_array tests // ############### static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_ctor_expect_paramsSet)(void **state) { struct setupVars *bundle = *state; size_t csize = 300; CFP_ARRAY_TYPE cfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor(bundle->dataSideLen, bundle->dataSideLen, bundle->dataSideLen, bundle->rate, bundle->dataArr, csize); assert_non_null(cfpArr.object); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size(cfpArr), bundle->totalDataLen); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.rate(cfpArr) >= bundle->rate); uchar* compressedPtr = CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(cfpArr); size_t compressedSize = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(cfpArr); assert_int_not_equal(hashBitstream((uint64*)compressedPtr, compressedSize), 0); // sets a minimum cache size assert_true(CFP_NAMESPACE.SUB_NAMESPACE.cache_size(cfpArr) >= csize); CFP_NAMESPACE.SUB_NAMESPACE.dtor(cfpArr); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _header_expect_matchingMetadata)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE srcCfpArr = bundle->cfpArr; CFP_HEADER_TYPE srcCfpHdr = CFP_NAMESPACE.SUB_NAMESPACE.header.ctor(srcCfpArr); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.scalar_type(srcCfpHdr), SCALAR_TYPE); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.dimensionality(srcCfpHdr), 3); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.rate(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.rate(srcCfpArr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.size_x(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.size_x(srcCfpArr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.size_y(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.size_y(srcCfpArr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.size_z(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.size_z(srcCfpArr)); // cleanup CFP_NAMESPACE.SUB_NAMESPACE.header.dtor(srcCfpHdr); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_resize_expect_sizeChanged)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t newSizeX = 81, newSizeY = 123, newSizeZ = 14; assert_int_not_equal(CFP_NAMESPACE.SUB_NAMESPACE.size(cfpArr), newSizeX * newSizeY * newSizeZ); CFP_NAMESPACE.SUB_NAMESPACE.resize(cfpArr, newSizeX, newSizeY, newSizeZ, 1); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr), newSizeX); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr), newSizeY); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr), newSizeZ); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size(cfpArr), newSizeX * newSizeY * newSizeZ); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_set_expect_entryWrittenToCacheOnly)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; // getting the ptr automatically flushes cache, so do this before setting an entry uchar* compressedDataPtr = CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(cfpArr); size_t compressedSize = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(cfpArr); uchar* oldMemory = malloc(compressedSize * sizeof(uchar)); memcpy(oldMemory, compressedDataPtr, compressedSize); CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, 1, 1, 1, (SCALAR)VAL); assert_memory_equal(compressedDataPtr, oldMemory, compressedSize); free(oldMemory); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_get_expect_entryReturned)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1; CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, i, j, k, (SCALAR)VAL); // dirty cache doesn't immediately apply compression assert_true(CFP_NAMESPACE.SUB_NAMESPACE.get(cfpArr, i, j, k) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_ref_expect_arrayObjectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i, j, k); assert_ptr_equal(cfpArrRef.array.object, cfpArr.object); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_ptr_expect_arrayObjectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArr.object); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_begin_expect_objectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 0); assert_int_equal(cfpArrIter.y, 0); assert_int_equal(cfpArrIter.z, 0); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_end_expect_objectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.end(cfpArr); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 0); assert_int_equal(cfpArrIter.y, 0); assert_int_equal(cfpArrIter.z, SIZE_Z); } // ############# // cfp_ref tests // ############# static void _catFunc3(given_, CFP_REF_TYPE, _when_get_expect_entryReturned)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i, j, k); CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, i, j, k, VAL); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.reference.get(cfpArrRef) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_REF_TYPE, _when_set_expect_arrayUpdated)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i, j, k); CFP_NAMESPACE.SUB_NAMESPACE.reference.set(cfpArrRef, VAL); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.get(cfpArr, i, j, k) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_REF_TYPE, _when_copy_expect_arrayUpdated)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, j1 = 2, k1 = 1, i2 = 2, j2 = 1, k2 = 2; CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, i1, j1, k1, VAL); CFP_REF_TYPE cfpArrRef_a = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i1, j1, k1); CFP_REF_TYPE cfpArrRef_b = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i2, j2, k2); CFP_NAMESPACE.SUB_NAMESPACE.reference.copy(cfpArrRef_b, cfpArrRef_a); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.get(cfpArr, i2, j2, k2) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_REF_TYPE, _when_ptr_expect_addressMatches)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i, j, k); CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.reference.ptr(cfpArrRef); assert_ptr_equal(cfpArrRef.array.object, cfpArrPtr.reference.array.object); } // ############# // cfp_ptr tests // ############# static void _catFunc3(given_, CFP_PTR_TYPE, _when_get_set_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 3; SCALAR val = 5; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k); CFP_NAMESPACE.SUB_NAMESPACE.pointer.set(cfpArrPtr, val); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get(cfpArrPtr) < 1e-12); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get(cfpArrPtr) > -1e-12); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_get_at_set_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 3, io = 4; SCALAR val = 5; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k); CFP_NAMESPACE.SUB_NAMESPACE.pointer.set_at(cfpArrPtr, io, val); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get_at(cfpArrPtr, io) < 1e-12); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get_at(cfpArrPtr, io) > -1e-12); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_ref_expect_addressMatches)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.pointer.ref(cfpArrPtr); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArrRef.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_ref_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1; size_t oi = 10; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.pointer.ref_at(cfpArrPtr, oi); assert_int_equal(cfpArrPtr.reference.x + oi, cfpArrRef.x); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArrRef.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_lt_expect_less)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 1, j2 = 2; size_t k1 = 1, k2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1, k1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2, k2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.lt(cfpArrPtrA, cfpArrPtrB)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_gt_expect_greater)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 1, j2 = 2; size_t k1 = 1, k2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1, k1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2, k2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.gt(cfpArrPtrB, cfpArrPtrA)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_leq_expect_less_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 1, j2 = 2; size_t k1 = 1, k2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1, k1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2, k2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.leq(cfpArrPtrA, cfpArrPtrA)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.leq(cfpArrPtrA, cfpArrPtrB)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_geq_expect_greater_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 1, j2 = 2; size_t k1 = 1, k2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1, k1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2, k2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.geq(cfpArrPtrA, cfpArrPtrA)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.geq(cfpArrPtrB, cfpArrPtrA)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_eq_expect_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, j1 = 2, k1 = 1; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1, k1); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.eq(cfpArrPtrA, cfpArrPtrA)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_neq_expect_not_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 2, j2 = 1; size_t k1 = 1, k2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1, k1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2, k2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.neq(cfpArrPtrA, cfpArrPtrB)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_distance_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2, k1 = 1; size_t j1 = 2, j2 = 1, k2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1, k1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2, k2); assert_int_equal((int)CFP_NAMESPACE.SUB_NAMESPACE.pointer.distance(cfpArrPtrA, cfpArrPtrB), (int)(i2 + j2*CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) + k2*CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr)*CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr)) - (int)(i1 + j1*CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) + k1*CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr)*CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr))); assert_ptr_equal(cfpArrPtrA.reference.array.object, cfpArrPtrB.reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_next_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1, oi = 10; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.next(cfpArrPtr, oi); size_t idx = (i + CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * (j + CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * k)) + oi; size_t x = idx % CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); size_t y = (idx / CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr)) % CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr); size_t z = idx / (CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr)); assert_int_equal(cfpArrPtr.reference.x, x); assert_int_equal(cfpArrPtr.reference.y, y); assert_int_equal(cfpArrPtr.reference.z, z); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k).reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_prev_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 8, j = 4, k = 1, oi = 10; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.prev(cfpArrPtr, oi); size_t idx = (i + CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * (j + CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * k)) - oi; size_t x = idx % CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); size_t y = (idx / CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr)) % CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr); size_t z = idx / (CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr)); assert_int_equal(cfpArrPtr.reference.x, x); assert_int_equal(cfpArrPtr.reference.y, y); assert_int_equal(cfpArrPtr.reference.z, z); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k).reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_inc_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.inc(cfpArrPtr); size_t idx = (i + CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * (j + CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * k)) + 1; size_t x = idx % CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); size_t y = (idx / CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr)) % CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr); size_t z = idx / (CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr)); assert_int_equal(cfpArrPtr.reference.x, x); assert_int_equal(cfpArrPtr.reference.y, y); assert_int_equal(cfpArrPtr.reference.z, z); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k).reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_dec_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.dec(cfpArrPtr); size_t idx = (i + CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * (j + CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * k)) - 1; size_t x = idx % CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); size_t y = (idx / CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr)) % CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr); size_t z = idx / (CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr)); assert_int_equal(cfpArrPtr.reference.x, x); assert_int_equal(cfpArrPtr.reference.y, y); assert_int_equal(cfpArrPtr.reference.z, z); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k).reference.array.object); } // ############## // cfp_iter tests // ############## static void _catFunc3(given_, CFP_ITER_TYPE, _when_ref_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ref(cfpArrIter); assert_ptr_equal(cfpArrRef.array.object, cfpArr.object); assert_int_equal(cfpArrRef.x, 0); assert_int_equal(cfpArrRef.y, 0); assert_int_equal(cfpArrRef.z, 0); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_ref_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t io = 1749; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ref_at(cfpArrIter, io); assert_ptr_equal(cfpArrRef.array.object, cfpArr.object); assert_int_equal(cfpArrRef.x, 5); assert_int_equal(cfpArrRef.y, 1); assert_int_equal(cfpArrRef.z, 4); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_ptr_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ptr(cfpArrIter); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArr.object); assert_int_equal(cfpArrPtr.reference.x, 0); assert_int_equal(cfpArrPtr.reference.y, 0); assert_int_equal(cfpArrPtr.reference.z, 0); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_ptr_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t io = 1749; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ptr_at(cfpArrIter, io); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArr.object); assert_int_equal(cfpArrPtr.reference.x, 5); assert_int_equal(cfpArrPtr.reference.y, 1); assert_int_equal(cfpArrPtr.reference.z, 4); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_inc_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.inc(cfpArrIter); assert_int_equal(cfpArrIter.x, 1); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_dec_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter.x = 4; cfpArrIter.y = 0; cfpArrIter.z = 0; cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.dec(cfpArrIter); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 3); assert_int_equal(cfpArrIter.y, 3); assert_int_equal(cfpArrIter.z, 3); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_next_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter, 64); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter, 63); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 7); assert_int_equal(cfpArrIter.y, 3); assert_int_equal(cfpArrIter.z, 3); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_prev_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter, 127); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.prev(cfpArrIter, 63); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 4); assert_int_equal(cfpArrIter.y, 0); assert_int_equal(cfpArrIter.z, 0); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_distance_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 63); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 127); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.iterator.distance(cfpArrIter1, cfpArrIter2), 64); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.iterator.distance(cfpArrIter2, CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr)), -127); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_lt_expect_less)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 63); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 127); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.lt(cfpArrIter1, cfpArrIter2)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_gt_expect_greater)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 63); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 127); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.gt(cfpArrIter2, cfpArrIter1)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_leq_expect_less_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 63); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 127); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.leq(cfpArrIter1, cfpArrIter1)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.leq(cfpArrIter1, cfpArrIter2)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_geq_expect_greater_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 63); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 127); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.geq(cfpArrIter1, cfpArrIter1)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.geq(cfpArrIter2, cfpArrIter1)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_get_index_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter.x = 1; cfpArrIter.y = 3; cfpArrIter.z = 2; size_t i_idx = CFP_NAMESPACE.SUB_NAMESPACE.iterator.i(cfpArrIter); size_t j_idx = CFP_NAMESPACE.SUB_NAMESPACE.iterator.j(cfpArrIter); size_t k_idx = CFP_NAMESPACE.SUB_NAMESPACE.iterator.k(cfpArrIter); assert_int_equal(i_idx, 1u); assert_int_equal(j_idx, 3u); assert_int_equal(k_idx, 2u); } zfp-1.0.1/tests/cfp/testCfpArray3d.c000066400000000000000000000210711453723256400172400ustar00rootroot00000000000000#include "src/traitsd.h" #include "src/block3.h" #include "constants/3dDouble.h" #define CFP_ARRAY_TYPE cfp_array3d #define CFP_REF_TYPE cfp_ref3d #define CFP_PTR_TYPE cfp_ptr3d #define CFP_ITER_TYPE cfp_iter3d #define SUB_NAMESPACE array3d #define SCALAR double #define SCALAR_TYPE zfp_type_double #define DIMENSIONALITY 3 #include "testCfpArray_source.c" #include "testCfpArray3_source.c" int main() { const struct CMUnitTest tests[] = { cmocka_unit_test(when_seededRandomSmoothDataGenerated_expect_ChecksumMatches), cmocka_unit_test(given_cfp_array3d_when_defaultCtor_expect_returnsNonNullPtr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_ctor_expect_paramsSet, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_copyCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_copyCtor_expect_cacheCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_headerCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_header_expect_matchingMetadata, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_header_when_bufferCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_header_when_bufferCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_setRate_expect_rateSet, setupCfpArrMinimal, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_setCacheSize_expect_cacheSizeSet, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_with_dirtyCache_when_flushCache_expect_cacheEntriesPersistedToMemory, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_clearCache_expect_cacheCleared, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_resize_expect_sizeChanged, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_setFlat_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_getFlat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_set_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_ref_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_ptr_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_ref_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_ptr_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_begin_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_end_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref3d_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref3d_when_set_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref3d_when_ptr_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref3d_when_copy_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3d_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3d_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3d_when_ref_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3d_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3d_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3d_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3d_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3d_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3d_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3d_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3d_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3d_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3d_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3d_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3d_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_ref_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_ptr_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_ptr_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_iterate_touch_all, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3d_when_get_index_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate0, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate1, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate2, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate0, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate1, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3d_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate2, teardownCfpArr), }; return cmocka_run_group_tests(tests, prepCommonSetupVars, teardownCommonSetupVars); } zfp-1.0.1/tests/cfp/testCfpArray3f.c000066400000000000000000000210661453723256400172460ustar00rootroot00000000000000#include "src/traitsf.h" #include "src/block3.h" #include "constants/3dFloat.h" #define CFP_ARRAY_TYPE cfp_array3f #define CFP_REF_TYPE cfp_ref3f #define CFP_PTR_TYPE cfp_ptr3f #define CFP_ITER_TYPE cfp_iter3f #define SUB_NAMESPACE array3f #define SCALAR float #define SCALAR_TYPE zfp_type_float #define DIMENSIONALITY 3 #include "testCfpArray_source.c" #include "testCfpArray3_source.c" int main() { const struct CMUnitTest tests[] = { cmocka_unit_test(when_seededRandomSmoothDataGenerated_expect_ChecksumMatches), cmocka_unit_test(given_cfp_array3f_when_defaultCtor_expect_returnsNonNullPtr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_ctor_expect_paramsSet, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_copyCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_copyCtor_expect_cacheCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_headerCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_header_expect_matchingMetadata, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_header_when_bufferCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_header_when_bufferCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_setRate_expect_rateSet, setupCfpArrMinimal, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_setCacheSize_expect_cacheSizeSet, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_with_dirtyCache_when_flushCache_expect_cacheEntriesPersistedToMemory, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_clearCache_expect_cacheCleared, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_resize_expect_sizeChanged, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_setFlat_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_getFlat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_set_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_ref_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_ptr_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_ref_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_ptr_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_begin_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_end_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref3f_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref3f_when_set_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref3f_when_ptr_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref3f_when_copy_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3f_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3f_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3f_when_ref_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3f_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3f_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3f_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3f_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3f_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3f_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3f_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3f_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3f_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3f_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3f_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr3f_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_ref_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_ptr_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_ptr_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_iterate_touch_all, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter3f_when_get_index_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate0, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate1, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate2, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate0, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate1, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array3f_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate2, teardownCfpArr), }; return cmocka_run_group_tests(tests, prepCommonSetupVars, teardownCommonSetupVars); } zfp-1.0.1/tests/cfp/testCfpArray4_source.c000066400000000000000000000705161453723256400204650ustar00rootroot00000000000000// ############### // cfp_array tests // ############### static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_ctor_expect_paramsSet)(void **state) { struct setupVars *bundle = *state; size_t csize = 300; CFP_ARRAY_TYPE cfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor(bundle->dataSideLen, bundle->dataSideLen, bundle->dataSideLen, bundle->dataSideLen, bundle->rate, bundle->dataArr, csize); assert_non_null(cfpArr.object); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size(cfpArr), bundle->totalDataLen); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.rate(cfpArr) >= bundle->rate); uchar* compressedPtr = CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(cfpArr); size_t compressedSize = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(cfpArr); assert_int_not_equal(hashBitstream((uint64*)compressedPtr, compressedSize), 0); // sets a minimum cache size assert_true(CFP_NAMESPACE.SUB_NAMESPACE.cache_size(cfpArr) >= csize); CFP_NAMESPACE.SUB_NAMESPACE.dtor(cfpArr); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _header_expect_matchingMetadata)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE srcCfpArr = bundle->cfpArr; CFP_HEADER_TYPE srcCfpHdr = CFP_NAMESPACE.SUB_NAMESPACE.header.ctor(srcCfpArr); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.scalar_type(srcCfpHdr), SCALAR_TYPE); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.dimensionality(srcCfpHdr), 4); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.rate(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.rate(srcCfpArr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.size_x(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.size_x(srcCfpArr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.size_y(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.size_y(srcCfpArr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.size_z(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.size_z(srcCfpArr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.size_w(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.size_w(srcCfpArr)); // cleanup CFP_NAMESPACE.SUB_NAMESPACE.header.dtor(srcCfpHdr); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_resize_expect_sizeChanged)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t newSizeX = 81, newSizeY = 123, newSizeZ = 14, newSizeW = 6; assert_int_not_equal(CFP_NAMESPACE.SUB_NAMESPACE.size(cfpArr), newSizeX * newSizeY * newSizeZ * newSizeW); CFP_NAMESPACE.SUB_NAMESPACE.resize(cfpArr, newSizeX, newSizeY, newSizeZ, newSizeW, 1); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr), newSizeX); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr), newSizeY); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr), newSizeZ); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size_w(cfpArr), newSizeW); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size(cfpArr), newSizeX * newSizeY * newSizeZ * newSizeW); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_set_expect_entryWrittenToCacheOnly)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; // getting the ptr automatically flushes cache, so do this before setting an entry uchar* compressedDataPtr = CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(cfpArr); size_t compressedSize = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(cfpArr); uchar* oldMemory = malloc(compressedSize * sizeof(uchar)); memcpy(oldMemory, compressedDataPtr, compressedSize); CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, 1, 1, 1, 1, (SCALAR)VAL); assert_memory_equal(compressedDataPtr, oldMemory, compressedSize); free(oldMemory); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_get_expect_entryReturned)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1, l = 1; CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, i, j, k, l, (SCALAR)VAL); // dirty cache doesn't immediately apply compression assert_true(CFP_NAMESPACE.SUB_NAMESPACE.get(cfpArr, i, j, k, l) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_ref_expect_arrayObjectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1, l = 1; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i, j, k, l); assert_ptr_equal(cfpArrRef.array.object, cfpArr.object); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_ptr_expect_arrayObjectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1, l = 1; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k, l); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArr.object); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_begin_expect_objectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 0); assert_int_equal(cfpArrIter.y, 0); assert_int_equal(cfpArrIter.z, 0); assert_int_equal(cfpArrIter.w, 0); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_end_expect_objectValid)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.end(cfpArr); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 0); assert_int_equal(cfpArrIter.y, 0); assert_int_equal(cfpArrIter.z, 0); assert_int_equal(cfpArrIter.w, SIZE_W); } // ############# // cfp_ref tests // ############# static void _catFunc3(given_, CFP_REF_TYPE, _when_get_expect_entryReturned)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1, l = 1; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i, j, k, l); CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, i, j, k, l, VAL); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.reference.get(cfpArrRef) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_REF_TYPE, _when_set_expect_arrayUpdated)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1, l = 1; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i, j, k, l); CFP_NAMESPACE.SUB_NAMESPACE.reference.set(cfpArrRef, VAL); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.get(cfpArr, i, j, k, l) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_REF_TYPE, _when_copy_expect_arrayUpdated)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, j1 = 2, k1 = 1, l1 = 1, i2 = 2, j2 = 1, k2 = 2, l2 = 2; CFP_NAMESPACE.SUB_NAMESPACE.set(cfpArr, i1, j1, k1, l1, VAL); CFP_REF_TYPE cfpArrRef_a = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i1, j1, k1, l1); CFP_REF_TYPE cfpArrRef_b = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i2, j2, k2, l2); CFP_NAMESPACE.SUB_NAMESPACE.reference.copy(cfpArrRef_b, cfpArrRef_a); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.get(cfpArr, i2, j2, k2, l2) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_REF_TYPE, _when_ptr_expect_addressMatches)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1, l = 1; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref(cfpArr, i, j, k, l); CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.reference.ptr(cfpArrRef); assert_ptr_equal(cfpArrRef.array.object, cfpArrPtr.reference.array.object); } // ############# // cfp_ptr tests // ############# static void _catFunc3(given_, CFP_PTR_TYPE, _when_get_set_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 3, l = 4; SCALAR val = 5; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k, l); CFP_NAMESPACE.SUB_NAMESPACE.pointer.set(cfpArrPtr, val); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get(cfpArrPtr) < 1e-12); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get(cfpArrPtr) > -1e-12); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_get_at_set_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 3, l = 4, io = 5; SCALAR val = 5; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k, l); CFP_NAMESPACE.SUB_NAMESPACE.pointer.set_at(cfpArrPtr, io, val); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get_at(cfpArrPtr, io) < 1e-12); assert_true(val - CFP_NAMESPACE.SUB_NAMESPACE.pointer.get_at(cfpArrPtr, io) > -1e-12); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_ref_expect_addressMatches)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1, l = 1; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k, l); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.pointer.ref(cfpArrPtr); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArrRef.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_ref_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1, l = 1; size_t oi = 10; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k, l); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.pointer.ref_at(cfpArrPtr, oi); assert_int_equal(cfpArrPtr.reference.x + oi, cfpArrRef.x); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArrRef.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_lt_expect_less)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 1, j2 = 2; size_t k1 = 1, k2 = 2; size_t l1 = 1, l2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1, k1, l1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2, k2, l2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.lt(cfpArrPtrA, cfpArrPtrB)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_gt_expect_greater)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 1, j2 = 2; size_t k1 = 1, k2 = 2; size_t l1 = 1, l2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1, k1, l1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2, k2, l2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.gt(cfpArrPtrB, cfpArrPtrA)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_leq_expect_less_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 1, j2 = 2; size_t k1 = 1, k2 = 2; size_t l1 = 1, l2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1, k1, l1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2, k2, l2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.leq(cfpArrPtrA, cfpArrPtrA)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.leq(cfpArrPtrA, cfpArrPtrB)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_geq_expect_greater_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 1, j2 = 2; size_t k1 = 1, k2 = 2; size_t l1 = 1, l2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1, k1, l1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2, k2, l2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.geq(cfpArrPtrA, cfpArrPtrA)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.geq(cfpArrPtrB, cfpArrPtrA)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_eq_expect_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, j1 = 2, k1 = 1, l1 = 1; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1, k1, l1); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.eq(cfpArrPtrA, cfpArrPtrA)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_neq_expect_not_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2; size_t j1 = 2, j2 = 1; size_t k1 = 1, k2 = 2; size_t l1 = 1, l2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1, k1, l1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2, k2, l2); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.neq(cfpArrPtrA, cfpArrPtrB)); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_distance_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i1 = 1, i2 = 2, k1 = 1, l1 = 1; size_t j1 = 2, j2 = 1, k2 = 2, l2 = 2; CFP_PTR_TYPE cfpArrPtrA = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i1, j1, k1, l1); CFP_PTR_TYPE cfpArrPtrB = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i2, j2, k2, l2); assert_int_equal((int)CFP_NAMESPACE.SUB_NAMESPACE.pointer.distance(cfpArrPtrA, cfpArrPtrB), (int)(i2 + j2*CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) + k2*CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr)*CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) + l2*CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr)*CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr)*CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr)) - (int)(i1 + j1*CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) + k1*CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr)*CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) + l1*CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr)*CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr)*CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr))); assert_ptr_equal(cfpArrPtrA.reference.array.object, cfpArrPtrB.reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_next_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1, l = 1, oi = 10; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k, l); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.next(cfpArrPtr, oi); size_t idx = (i + CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * (j + CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * (k + CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr) * l))) + oi; size_t x = idx % CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); size_t y = ((idx - x) / CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr)) % CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr); size_t z = ((idx - y * CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) - x) / (CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr))) % CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr); size_t w = (idx - z * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) - y * CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) - x) / (CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr)); assert_int_equal(cfpArrPtr.reference.x, x); assert_int_equal(cfpArrPtr.reference.y, y); assert_int_equal(cfpArrPtr.reference.z, z); assert_int_equal(cfpArrPtr.reference.w, w); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k, l).reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_prev_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 8, j = 4, k = 1, l = 1, oi = 10; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k, l); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.prev(cfpArrPtr, oi); size_t idx = (i + CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * (j + CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * (k + CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr) * l))) - oi; size_t x = idx % CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); size_t y = ((idx - x) / CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr)) % CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr); size_t z = ((idx - y * CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) - x) / (CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr))) % CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr); size_t w = (idx - z * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) - y * CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) - x) / (CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr)); assert_int_equal(cfpArrPtr.reference.x, x); assert_int_equal(cfpArrPtr.reference.y, y); assert_int_equal(cfpArrPtr.reference.z, z); assert_int_equal(cfpArrPtr.reference.w, w); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k, l).reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_inc_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1, l = 1; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k, l); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.inc(cfpArrPtr); size_t idx = (i + CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * (j + CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * (k + CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr) * l))) + 1; size_t x = idx % CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); size_t y = ((idx - x) / CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr)) % CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr); size_t z = ((idx - y * CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) - x) / (CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr))) % CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr); size_t w = (idx - z * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) - y * CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) - x) / (CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr)); assert_int_equal(cfpArrPtr.reference.x, x); assert_int_equal(cfpArrPtr.reference.y, y); assert_int_equal(cfpArrPtr.reference.z, z); assert_int_equal(cfpArrPtr.reference.w, w); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k, l).reference.array.object); } static void _catFunc3(given_, CFP_PTR_TYPE, _when_dec_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 1, j = 2, k = 1, l = 1; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k, l); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.dec(cfpArrPtr); size_t idx = (i + CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * (j + CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * (k + CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr) * l))) - 1; size_t x = idx % CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr); size_t y = ((idx - x) / CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr)) % CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr); size_t z = ((idx - y * CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) - x) / (CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr))) % CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr); size_t w = (idx - z * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) - y * CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) - x) / (CFP_NAMESPACE.SUB_NAMESPACE.size_x(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_y(cfpArr) * CFP_NAMESPACE.SUB_NAMESPACE.size_z(cfpArr)); assert_int_equal(cfpArrPtr.reference.x, x); assert_int_equal(cfpArrPtr.reference.y, y); assert_int_equal(cfpArrPtr.reference.z, z); assert_int_equal(cfpArrPtr.reference.w, w); assert_ptr_equal(cfpArrPtr.reference.array.object, CFP_NAMESPACE.SUB_NAMESPACE.ptr(cfpArr, i, j, k, l).reference.array.object); } // ############## // cfp_iter tests // ############## static void _catFunc3(given_, CFP_ITER_TYPE, _when_ref_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ref(cfpArrIter); assert_ptr_equal(cfpArrRef.array.object, cfpArr.object); assert_int_equal(cfpArrRef.x, 0); assert_int_equal(cfpArrRef.y, 0); assert_int_equal(cfpArrRef.z, 0); assert_int_equal(cfpArrRef.w, 0); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_ref_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t io = 38709; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ref_at(cfpArrIter, io); assert_ptr_equal(cfpArrRef.array.object, cfpArr.object); assert_int_equal(cfpArrRef.x, 5); assert_int_equal(cfpArrRef.y, 1); assert_int_equal(cfpArrRef.z, 4); assert_int_equal(cfpArrRef.w, 4); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_ptr_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ptr(cfpArrIter); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArr.object); assert_int_equal(cfpArrPtr.reference.x, 0); assert_int_equal(cfpArrPtr.reference.y, 0); assert_int_equal(cfpArrPtr.reference.z, 0); assert_int_equal(cfpArrPtr.reference.w, 0); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_ptr_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t io = 38709; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.iterator.ptr_at(cfpArrIter, io); assert_ptr_equal(cfpArrPtr.reference.array.object, cfpArr.object); assert_int_equal(cfpArrPtr.reference.x, 5); assert_int_equal(cfpArrPtr.reference.y, 1); assert_int_equal(cfpArrPtr.reference.z, 4); assert_int_equal(cfpArrPtr.reference.w, 4); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_inc_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.inc(cfpArrIter); assert_int_equal(cfpArrIter.x, 1); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_dec_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter.x = 4; cfpArrIter.y = 0; cfpArrIter.z = 0; cfpArrIter.w = 0; cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.dec(cfpArrIter); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 3); assert_int_equal(cfpArrIter.y, 3); assert_int_equal(cfpArrIter.z, 3); assert_int_equal(cfpArrIter.w, 3); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_next_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter, 256); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter, 255); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 7); assert_int_equal(cfpArrIter.y, 3); assert_int_equal(cfpArrIter.z, 3); assert_int_equal(cfpArrIter.w, 3); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_prev_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter, 511); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.prev(cfpArrIter, 255); assert_ptr_equal(cfpArrIter.array.object, cfpArr.object); assert_int_equal(cfpArrIter.x, 4); assert_int_equal(cfpArrIter.y, 0); assert_int_equal(cfpArrIter.z, 0); assert_int_equal(cfpArrIter.w, 0); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_distance_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 255); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 511); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.iterator.distance(cfpArrIter1, cfpArrIter2), 256); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.iterator.distance(cfpArrIter2, CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr)), -511); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_lt_expect_less)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 255); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 511); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.lt(cfpArrIter1, cfpArrIter2)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_gt_expect_greater)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 255); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 511); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.gt(cfpArrIter2, cfpArrIter1)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_leq_expect_less_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 255); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 511); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.leq(cfpArrIter1, cfpArrIter1)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.leq(cfpArrIter1, cfpArrIter2)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_geq_expect_greater_or_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter1, 255); cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.iterator.next(cfpArrIter2, 511); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.geq(cfpArrIter1, cfpArrIter1)); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.geq(cfpArrIter2, cfpArrIter1)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_get_index_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); cfpArrIter.x = 1; cfpArrIter.y = 3; cfpArrIter.z = 2; cfpArrIter.w = 1; size_t i_idx = CFP_NAMESPACE.SUB_NAMESPACE.iterator.i(cfpArrIter); size_t j_idx = CFP_NAMESPACE.SUB_NAMESPACE.iterator.j(cfpArrIter); size_t k_idx = CFP_NAMESPACE.SUB_NAMESPACE.iterator.k(cfpArrIter); size_t l_idx = CFP_NAMESPACE.SUB_NAMESPACE.iterator.l(cfpArrIter); assert_int_equal(i_idx, 1u); assert_int_equal(j_idx, 3u); assert_int_equal(k_idx, 2u); assert_int_equal(l_idx, 1u); } zfp-1.0.1/tests/cfp/testCfpArray4d.c000066400000000000000000000201531453723256400172410ustar00rootroot00000000000000#include "src/traitsd.h" #include "src/block4.h" #include "constants/4dDouble.h" #define CFP_ARRAY_TYPE cfp_array4d #define CFP_REF_TYPE cfp_ref4d #define CFP_PTR_TYPE cfp_ptr4d #define CFP_ITER_TYPE cfp_iter4d #define SUB_NAMESPACE array4d #define SCALAR double #define SCALAR_TYPE zfp_type_double #define DIMENSIONALITY 4 #include "testCfpArray_source.c" #include "testCfpArray4_source.c" int main() { const struct CMUnitTest tests[] = { cmocka_unit_test(when_seededRandomSmoothDataGenerated_expect_ChecksumMatches), cmocka_unit_test(given_cfp_array4d_when_defaultCtor_expect_returnsNonNullPtr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_ctor_expect_paramsSet, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_copyCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_copyCtor_expect_cacheCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_headerCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_header_expect_matchingMetadata, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_header_when_bufferCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_header_when_bufferCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_setRate_expect_rateSet, setupCfpArrMinimal, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_setCacheSize_expect_cacheSizeSet, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_with_dirtyCache_when_flushCache_expect_cacheEntriesPersistedToMemory, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_clearCache_expect_cacheCleared, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_resize_expect_sizeChanged, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_setFlat_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_getFlat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_set_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_ref_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_ptr_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_ref_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_ptr_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_begin_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_end_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref4d_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref4d_when_set_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref4d_when_ptr_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref4d_when_copy_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4d_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4d_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4d_when_ref_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4d_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4d_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4d_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4d_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4d_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4d_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4d_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4d_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4d_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4d_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4d_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4d_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_ref_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_ptr_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_ptr_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_iterate_touch_all, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4d_when_get_index_expect_correct, setupCfpArrSmall, teardownCfpArr), /* NOTE: 4D arrays only support 8bit rates so setupFixedRate1 and 2 aren't used for testing here */ cmocka_unit_test_setup_teardown(given_cfp_array4d_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate0, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4d_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate0, teardownCfpArr), }; return cmocka_run_group_tests(tests, prepCommonSetupVars, teardownCommonSetupVars); } zfp-1.0.1/tests/cfp/testCfpArray4f.c000066400000000000000000000201501453723256400172400ustar00rootroot00000000000000#include "src/traitsf.h" #include "src/block4.h" #include "constants/4dFloat.h" #define CFP_ARRAY_TYPE cfp_array4f #define CFP_REF_TYPE cfp_ref4f #define CFP_PTR_TYPE cfp_ptr4f #define CFP_ITER_TYPE cfp_iter4f #define SUB_NAMESPACE array4f #define SCALAR float #define SCALAR_TYPE zfp_type_float #define DIMENSIONALITY 4 #include "testCfpArray_source.c" #include "testCfpArray4_source.c" int main() { const struct CMUnitTest tests[] = { cmocka_unit_test(when_seededRandomSmoothDataGenerated_expect_ChecksumMatches), cmocka_unit_test(given_cfp_array4f_when_defaultCtor_expect_returnsNonNullPtr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_ctor_expect_paramsSet, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_copyCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_copyCtor_expect_cacheCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_headerCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_header_expect_matchingMetadata, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_header_when_bufferCtor_expect_copied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_header_when_bufferCtor_expect_paramsCopied, setupCfpArrLargeComplete, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_setRate_expect_rateSet, setupCfpArrMinimal, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_setCacheSize_expect_cacheSizeSet, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_with_dirtyCache_when_flushCache_expect_cacheEntriesPersistedToMemory, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_clearCache_expect_cacheCleared, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_resize_expect_sizeChanged, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_setFlat_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_getFlat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_set_expect_entryWrittenToCacheOnly, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_ref_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_ptr_expect_arrayObjectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_ref_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_ptr_flat_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_begin_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_end_expect_objectValid, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref4f_when_get_expect_entryReturned, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref4f_when_set_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref4f_when_ptr_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ref4f_when_copy_expect_arrayUpdated, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4f_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4f_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4f_when_ref_expect_addressMatches, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4f_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4f_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4f_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4f_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4f_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4f_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4f_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4f_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4f_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4f_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4f_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_ptr4f_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_get_set_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_get_at_set_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_ref_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_ref_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_ptr_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_ptr_at_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_lt_expect_less, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_gt_expect_greater, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_leq_expect_less_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_geq_expect_greater_or_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_eq_expect_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_neq_expect_not_equal, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_distance_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_next_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_prev_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_inc_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_dec_expect_correct, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_iterate_touch_all, setupCfpArrSmall, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_iter4f_when_get_index_expect_correct, setupCfpArrSmall, teardownCfpArr), /* NOTE: 4D arrays only support 8bit rates so setupFixedRate1 and 2 aren't used for testing here */ cmocka_unit_test_setup_teardown(given_cfp_array4f_when_setArray_expect_compressedStreamChecksumMatches, setupFixedRate0, teardownCfpArr), cmocka_unit_test_setup_teardown(given_cfp_array4f_when_getArray_expect_decompressedArrChecksumMatches, setupFixedRate0, teardownCfpArr), }; return cmocka_run_group_tests(tests, prepCommonSetupVars, teardownCommonSetupVars); } zfp-1.0.1/tests/cfp/testCfpArray_source.c000066400000000000000000000505211453723256400203730ustar00rootroot00000000000000#include #include #include #include #include #include #include #include #include "zfp/array.h" #include "zfp.h" #include "utils/genSmoothRandNums.h" #include "utils/testMacros.h" #include "utils/zfpChecksums.h" #include "utils/zfpHash.h" #define SIZE_X 20 #define SIZE_Y 21 #define SIZE_Z 22 #define SIZE_W 5 #define VAL 12345678.9 #define MIN_TOTAL_ELEMENTS 1000000 #define CFP_HEADER_TYPE cfp_header struct setupVars { size_t dataSideLen; size_t totalDataLen; Scalar* dataArr; Scalar* decompressedArr; // dimensions of data that gets compressed (currently same as dataSideLen) size_t dimLens[4]; CFP_ARRAY_TYPE cfpArr; int paramNum; double rate; size_t csize; }; // run this once per (datatype, DIM) combination for performance static int setupRandomData(void** state) { struct setupVars *bundle = *state; switch(ZFP_TYPE) { case zfp_type_float: generateSmoothRandFloats(MIN_TOTAL_ELEMENTS, DIMS, (float**)&bundle->dataArr, &bundle->dataSideLen, &bundle->totalDataLen); break; case zfp_type_double: generateSmoothRandDoubles(MIN_TOTAL_ELEMENTS, DIMS, (double**)&bundle->dataArr, &bundle->dataSideLen, &bundle->totalDataLen); break; default: fail_msg("Invalid zfp_type during setupRandomData()"); break; } assert_non_null(bundle->dataArr); // for now, entire randomly generated array always entirely compressed int i; for (i = 0; i < 4; i++) { bundle->dimLens[i] = (i < DIMS) ? bundle->dataSideLen : 0; } bundle->decompressedArr = malloc(bundle->totalDataLen * sizeof(Scalar)); assert_non_null(bundle->decompressedArr); *state = bundle; return 0; } static int prepCommonSetupVars(void** state) { struct setupVars *bundle = calloc(1, sizeof(struct setupVars)); assert_non_null(bundle); bundle->rate = ZFP_RATE_PARAM_BITS; bundle->csize = 300; *state = bundle; return setupRandomData(state); } static int teardownRandomData(void** state) { struct setupVars *bundle = *state; free(bundle->dataArr); free(bundle->decompressedArr); return 0; } static int teardownCommonSetupVars(void** state) { struct setupVars *bundle = *state; int result = teardownRandomData(state); free(bundle); return result; } static int setupCfpArrMinimal(void** state) { struct setupVars *bundle = *state; bundle->cfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor_default(); assert_non_null(bundle->cfpArr.object); return 0; } static int setupCfpArrSizeRate(void** state, size_t sizeX, size_t sizeY, size_t sizeZ, size_t sizeW) { struct setupVars *bundle = *state; #if DIMS == 1 bundle->cfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor(sizeX, bundle->rate, 0, 0); #elif DIMS == 2 bundle->cfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor(sizeX, sizeY, bundle->rate, 0, 0); #elif DIMS == 3 bundle->cfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor(sizeX, sizeY, sizeZ, bundle->rate, 0, 0); #else /* NOTE: 4d rate is capped at 8 bits */ bundle->cfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor(sizeX, sizeY, sizeZ, sizeW, 8, 0, 0); #endif assert_non_null(bundle->cfpArr.object); return 0; } static int setupCfpArrLargeComplete(void **state) { struct setupVars *bundle = *state; #if DIMS == 1 bundle->cfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor(bundle->dataSideLen, bundle->rate, bundle->dataArr, bundle->csize); #elif DIMS == 2 bundle->cfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor(bundle->dataSideLen, bundle->dataSideLen, bundle->rate, bundle->dataArr, bundle->csize); #elif DIMS == 3 bundle->cfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor(bundle->dataSideLen, bundle->dataSideLen, bundle->dataSideLen, bundle->rate, bundle->dataArr, bundle->csize); #else /* NOTE: 4d rate is capped at 8 bits */ bundle->cfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor(bundle->dataSideLen, bundle->dataSideLen, bundle->dataSideLen, bundle->dataSideLen, 8, bundle->dataArr, bundle->csize); #endif assert_non_null(bundle->cfpArr.object); return 0; } static int setupCfpArrLarge(void** state) { struct setupVars *bundle = *state; return setupCfpArrSizeRate(state, bundle->dataSideLen, bundle->dataSideLen, bundle->dataSideLen, bundle->dataSideLen); } static int setupCfpArrSmall(void** state) { return setupCfpArrSizeRate(state, SIZE_X, SIZE_Y, SIZE_Z, SIZE_W); } static int teardownCfpArr(void** state) { struct setupVars *bundle = *state; CFP_NAMESPACE.SUB_NAMESPACE.dtor(bundle->cfpArr); return 0; } // assumes setupRandomData() already run (having set some setupVars members) static int loadFixedRateVars(void **state, int paramNum) { struct setupVars *bundle = *state; bundle->paramNum = paramNum; #if DIMS == 4 // 4d (de)serialization rate limit if (bundle->paramNum != 0) { fail_msg("Unknown paramNum during loadFixedRateVars()"); } #else if (bundle->paramNum > 2 || bundle->paramNum < 0) { fail_msg("Unknown paramNum during loadFixedRateVars()"); } #endif bundle->rate = (double)(1u << (bundle->paramNum + 3)); *state = bundle; return setupCfpArrLarge(state); } static int setupFixedRate0(void **state) { return loadFixedRateVars(state, 0); } static int setupFixedRate1(void **state) { return loadFixedRateVars(state, 1); } static int setupFixedRate2(void **state) { return loadFixedRateVars(state, 2); } // dataArr and the struct itself are freed in teardownCommonSetupVars() static int teardown(void **state) { struct setupVars *bundle = *state; free(bundle->decompressedArr); return 0; } static void when_seededRandomSmoothDataGenerated_expect_ChecksumMatches(void **state) { struct setupVars *bundle = *state; UInt checksum = _catFunc2(hashArray, SCALAR_BITS)((const UInt*)bundle->dataArr, bundle->totalDataLen, 1); uint64 key1, key2; computeKeyOriginalInput(ARRAY_TEST, bundle->dimLens, &key1, &key2); uint64 expectedChecksum = getChecksumByKey(DIMS, ZFP_TYPE, key1, key2); assert_int_equal(checksum, expectedChecksum); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_defaultCtor_expect_returnsNonNullPtr)(void **state) { CFP_ARRAY_TYPE cfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor_default(); assert_non_null(cfpArr.object); CFP_NAMESPACE.SUB_NAMESPACE.dtor(cfpArr); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_copyCtor_expect_paramsCopied)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE srcCfpArr = bundle->cfpArr; CFP_ARRAY_TYPE newCfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor_copy(srcCfpArr); // verify size assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.size(newCfpArr), CFP_NAMESPACE.SUB_NAMESPACE.size(srcCfpArr)); // verify rate assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.rate(newCfpArr), CFP_NAMESPACE.SUB_NAMESPACE.rate(srcCfpArr)); // verify compressed size, data size_t newDataSize = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(newCfpArr); size_t srcDataSize = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(srcCfpArr); assert_int_equal(newDataSize, srcDataSize); uchar* newData = CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(newCfpArr); uchar* srcData = CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(srcCfpArr); assert_memory_equal(newData, srcData, newDataSize); // verify cache size assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.cache_size(newCfpArr), CFP_NAMESPACE.SUB_NAMESPACE.cache_size(srcCfpArr)); CFP_NAMESPACE.SUB_NAMESPACE.dtor(newCfpArr); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_copyCtor_expect_cacheCopied)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE srcCfpArr = bundle->cfpArr; // get ptr to compressed data (automatically flushes cache) uchar* srcData = CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(srcCfpArr); // create dirty cache size_t i = 5; CFP_NAMESPACE.SUB_NAMESPACE.set_flat(srcCfpArr, i, (SCALAR)VAL); // exec copy constructor CFP_ARRAY_TYPE newCfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor_copy(srcCfpArr); size_t newDataSize = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(newCfpArr); size_t srcDataSize = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(srcCfpArr); assert_int_equal(newDataSize, srcDataSize); // getting data ptr to copy-constructed array requires a flush (no way to avoid) uchar* newData = CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(newCfpArr); assert_memory_not_equal(newData, srcData, newDataSize); // verify flush brings both to same state CFP_NAMESPACE.SUB_NAMESPACE.flush_cache(srcCfpArr); assert_memory_equal(newData, srcData, newDataSize); // verify compressed value is the same assert_true(CFP_NAMESPACE.SUB_NAMESPACE.get_flat(newCfpArr, i) == CFP_NAMESPACE.SUB_NAMESPACE.get_flat(srcCfpArr, i)); CFP_NAMESPACE.SUB_NAMESPACE.dtor(newCfpArr); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_headerCtor_expect_copied)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE srcCfpArr = bundle->cfpArr; // get header CFP_HEADER_TYPE srcCfpHdr = CFP_NAMESPACE.SUB_NAMESPACE.header.ctor(srcCfpArr); // get compressed bitstream void* srcBuff = (void*)CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(srcCfpArr); size_t srcSz = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(srcCfpArr); // exec construct from header + stream CFP_ARRAY_TYPE newCfpArr = CFP_NAMESPACE.SUB_NAMESPACE.ctor_header(srcCfpHdr, srcBuff, srcSz); // verify reconstruction from header + stream results in equivalent array data void* newBuff = (void*)CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(newCfpArr); size_t newSz = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(newCfpArr); assert_int_equal(srcSz, newSz); assert_memory_equal(srcBuff, newBuff, newSz); // cleanup CFP_NAMESPACE.SUB_NAMESPACE.header.dtor(srcCfpHdr); CFP_NAMESPACE.SUB_NAMESPACE.dtor(newCfpArr); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _header_when_bufferCtor_expect_copied)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE srcCfpArr = bundle->cfpArr; // get header CFP_HEADER_TYPE srcCfpHdr = CFP_NAMESPACE.SUB_NAMESPACE.header.ctor(srcCfpArr); const void* srcBuff = CFP_NAMESPACE.SUB_NAMESPACE.header.data(srcCfpHdr); size_t srcSz = CFP_NAMESPACE.SUB_NAMESPACE.header.size_bytes(srcCfpHdr, ZFP_DATA_HEADER); // exec new header construct from source header CFP_HEADER_TYPE newCfpHdr = CFP_NAMESPACE.SUB_NAMESPACE.header.ctor_buffer(srcBuff, srcSz); const void* newBuff = CFP_NAMESPACE.SUB_NAMESPACE.header.data(newCfpHdr); size_t newSz = CFP_NAMESPACE.SUB_NAMESPACE.header.size_bytes(newCfpHdr, ZFP_DATA_HEADER); assert_int_equal(srcSz, newSz); assert_memory_equal(srcBuff, newBuff, newSz); // cleanup CFP_NAMESPACE.SUB_NAMESPACE.header.dtor(srcCfpHdr); CFP_NAMESPACE.SUB_NAMESPACE.header.dtor(newCfpHdr); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _header_when_bufferCtor_expect_paramsCopied)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE srcCfpArr = bundle->cfpArr; // get header CFP_HEADER_TYPE srcCfpHdr = CFP_NAMESPACE.SUB_NAMESPACE.header.ctor(srcCfpArr); const void* hBuff = CFP_NAMESPACE.SUB_NAMESPACE.header.data(srcCfpHdr); size_t hSz = CFP_NAMESPACE.SUB_NAMESPACE.header.size_bytes(srcCfpHdr, ZFP_DATA_HEADER); // exec new header construct from source header CFP_HEADER_TYPE newCfpHdr = CFP_NAMESPACE.SUB_NAMESPACE.header.ctor_buffer(hBuff, hSz); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.scalar_type(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.header.scalar_type(newCfpHdr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.dimensionality(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.header.dimensionality(newCfpHdr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.rate(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.header.rate(newCfpHdr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.size_bytes(srcCfpHdr, ZFP_DATA_HEADER), CFP_NAMESPACE.SUB_NAMESPACE.header.size_bytes(newCfpHdr, ZFP_DATA_HEADER)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.size_x(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.header.size_x(newCfpHdr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.size_y(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.header.size_y(newCfpHdr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.size_z(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.header.size_z(newCfpHdr)); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.header.size_w(srcCfpHdr), CFP_NAMESPACE.SUB_NAMESPACE.header.size_w(newCfpHdr)); // cleanup CFP_NAMESPACE.SUB_NAMESPACE.header.dtor(srcCfpHdr); CFP_NAMESPACE.SUB_NAMESPACE.header.dtor(newCfpHdr); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_setRate_expect_rateSet)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.rate(cfpArr), 0); double rate = CFP_NAMESPACE.SUB_NAMESPACE.set_rate(cfpArr, bundle->rate); assert_int_not_equal(CFP_NAMESPACE.SUB_NAMESPACE.rate(cfpArr), 0); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.rate(cfpArr) == rate); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_setCacheSize_expect_cacheSizeSet)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t oldCsize = CFP_NAMESPACE.SUB_NAMESPACE.cache_size(cfpArr); size_t newCsize = oldCsize + 999; // set_cache_size() accepts a minimum cache size CFP_NAMESPACE.SUB_NAMESPACE.set_cache_size(cfpArr, newCsize); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.cache_size(cfpArr) >= newCsize); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _with_dirtyCache_when_flushCache_expect_cacheEntriesPersistedToMemory)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; // getting the ptr automatically flushes cache, so do this before setting an entry uchar* compressedDataPtr = CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(cfpArr); size_t compressedSize = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(cfpArr); uchar* oldMemory = malloc(compressedSize * sizeof(uchar)); memcpy(oldMemory, compressedDataPtr, compressedSize); CFP_NAMESPACE.SUB_NAMESPACE.set_flat(cfpArr, 0, (SCALAR)VAL); CFP_NAMESPACE.SUB_NAMESPACE.flush_cache(cfpArr); assert_memory_not_equal(compressedDataPtr, oldMemory, compressedSize); free(oldMemory); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_clearCache_expect_cacheCleared)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; SCALAR prevVal = CFP_NAMESPACE.SUB_NAMESPACE.get_flat(cfpArr, 0); CFP_NAMESPACE.SUB_NAMESPACE.set_flat(cfpArr, 0, (SCALAR)VAL); CFP_NAMESPACE.SUB_NAMESPACE.clear_cache(cfpArr); CFP_NAMESPACE.SUB_NAMESPACE.flush_cache(cfpArr); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.get_flat(cfpArr, 0) == prevVal); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_setFlat_expect_entryWrittenToCacheOnly)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; // getting the ptr automatically flushes cache, so do this before setting an entry uchar* compressedDataPtr = CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(cfpArr); size_t compressedSize = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(cfpArr); uchar* oldMemory = malloc(compressedSize * sizeof(uchar)); memcpy(oldMemory, compressedDataPtr, compressedSize); CFP_NAMESPACE.SUB_NAMESPACE.set_flat(cfpArr, 0, (SCALAR)VAL); assert_memory_equal(compressedDataPtr, oldMemory, compressedSize); free(oldMemory); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_getFlat_expect_entryReturned)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_NAMESPACE.SUB_NAMESPACE.set_flat(cfpArr, 0, (SCALAR)VAL); // dirty cache preserves exact value (compression not applied until flush) assert_true(CFP_NAMESPACE.SUB_NAMESPACE.get_flat(cfpArr, 0) == (SCALAR)VAL); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_setArray_expect_compressedStreamChecksumMatches)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; uchar* compressedPtr = CFP_NAMESPACE.SUB_NAMESPACE.compressed_data(cfpArr); CFP_NAMESPACE.SUB_NAMESPACE.set_array(cfpArr, bundle->dataArr); size_t compressedSize = CFP_NAMESPACE.SUB_NAMESPACE.compressed_size(cfpArr); uint64 checksum = hashBitstream((uint64*)compressedPtr, compressedSize); uint64 key1, key2; computeKey(ARRAY_TEST, COMPRESSED_BITSTREAM, bundle->dimLens, zfp_mode_fixed_rate, bundle->paramNum, &key1, &key2); uint64 expectedChecksum = getChecksumByKey(DIMS, ZFP_TYPE, key1, key2); assert_int_equal(checksum, expectedChecksum); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_getArray_expect_decompressedArrChecksumMatches)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_NAMESPACE.SUB_NAMESPACE.set_array(cfpArr, bundle->dataArr); CFP_NAMESPACE.SUB_NAMESPACE.get_array(cfpArr, bundle->decompressedArr); UInt checksum = _catFunc2(hashArray, SCALAR_BITS)((UInt*)bundle->decompressedArr, bundle->totalDataLen, 1); uint64 key1, key2; computeKey(ARRAY_TEST, DECOMPRESSED_ARRAY, bundle->dimLens, zfp_mode_fixed_rate, bundle->paramNum, &key1, &key2); uint64 expectedChecksum = getChecksumByKey(DIMS, ZFP_TYPE, key1, key2); assert_int_equal(checksum, expectedChecksum); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_ref_flat_expect_entryReturned)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 10; CFP_REF_TYPE cfpArrRef = CFP_NAMESPACE.SUB_NAMESPACE.ref_flat(cfpArr, i); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.reference.get(cfpArrRef) == CFP_NAMESPACE.SUB_NAMESPACE.get_flat(cfpArr, i)); } static void _catFunc3(given_, CFP_ARRAY_TYPE, _when_ptr_flat_expect_entryReturned)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 10; CFP_PTR_TYPE cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr_flat(cfpArr, i); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.reference.get(cfpArrPtr.reference) == CFP_NAMESPACE.SUB_NAMESPACE.get_flat(cfpArr, i)); } // ############## // cfp_iter tests // ############## static void _catFunc3(given_, CFP_ITER_TYPE, _when_get_set_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; SCALAR val = 5; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_NAMESPACE.SUB_NAMESPACE.iterator.set(cfpArrIter, val); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.iterator.get(cfpArrIter), val); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_get_at_set_at_expect_correct)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; size_t i = 3; SCALAR val = 5; CFP_ITER_TYPE cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_NAMESPACE.SUB_NAMESPACE.iterator.set_at(cfpArrIter, i, val); assert_int_equal(CFP_NAMESPACE.SUB_NAMESPACE.iterator.get_at(cfpArrIter, i), val); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_iterate_touch_all)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter; CFP_PTR_TYPE cfpArrPtr; SCALAR val = -1; for (cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_NAMESPACE.SUB_NAMESPACE.iterator.neq(cfpArrIter, CFP_NAMESPACE.SUB_NAMESPACE.end(cfpArr)); cfpArrIter = CFP_NAMESPACE.SUB_NAMESPACE.iterator.inc(cfpArrIter)) { CFP_NAMESPACE.SUB_NAMESPACE.iterator.set(cfpArrIter, val); } for (cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.ptr_flat(cfpArr, 0); CFP_NAMESPACE.SUB_NAMESPACE.pointer.leq(cfpArrPtr, CFP_NAMESPACE.SUB_NAMESPACE.ptr_flat(cfpArr, CFP_NAMESPACE.SUB_NAMESPACE.size(cfpArr) - 1)); cfpArrPtr = CFP_NAMESPACE.SUB_NAMESPACE.pointer.inc(cfpArrPtr)) { assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.get(cfpArrPtr) - val < 1e-12); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.pointer.get(cfpArrPtr) - val > -1e-12); } } static void _catFunc3(given_, CFP_ITER_TYPE, _when_eq_expect_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.eq(cfpArrIter1, cfpArrIter1)); } static void _catFunc3(given_, CFP_ITER_TYPE, _when_neq_expect_not_equal)(void **state) { struct setupVars *bundle = *state; CFP_ARRAY_TYPE cfpArr = bundle->cfpArr; CFP_ITER_TYPE cfpArrIter1 = CFP_NAMESPACE.SUB_NAMESPACE.begin(cfpArr); CFP_ITER_TYPE cfpArrIter2 = CFP_NAMESPACE.SUB_NAMESPACE.end(cfpArr); assert_true(CFP_NAMESPACE.SUB_NAMESPACE.iterator.neq(cfpArrIter1, cfpArrIter2)); } zfp-1.0.1/tests/cfp/testCfpNamespace.c000066400000000000000000000012001453723256400176170ustar00rootroot00000000000000#include #include #include #include #include "zfp/array.h" /* only run this test when compiling with CFP_NAMESPACE=cfp2 */ /* test fails if compiler errors out */ static void given_cfpCompiledWithNamespace_cfp2_when_linkToCfpLib_expect_namespacePersists(void** state) { cfp_array1d arr = cfp2.array1d.ctor_default(); assert_non_null(arr.object); cfp2.array1d.dtor(arr); } int main() { const struct CMUnitTest tests[] = { cmocka_unit_test(given_cfpCompiledWithNamespace_cfp2_when_linkToCfpLib_expect_namespacePersists), }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/ci-utils/000077500000000000000000000000001453723256400152165ustar00rootroot00000000000000zfp-1.0.1/tests/ci-utils/CMakeLists.txt000066400000000000000000000003031453723256400177520ustar00rootroot00000000000000# This empty project is used to determine if OpenMP is available on CI machines # without compiling any ZFP code. cmake_minimum_required(VERSION 3.9) find_package(OpenMP COMPONENTS C REQUIRED) zfp-1.0.1/tests/constants/000077500000000000000000000000001453723256400155015ustar00rootroot00000000000000zfp-1.0.1/tests/constants/1dDouble.h000066400000000000000000000001251453723256400173070ustar00rootroot00000000000000#include "universalConsts.h" #include "doubleConsts.h" #define DIM_INT_STR 1dDouble zfp-1.0.1/tests/constants/1dFloat.h000066400000000000000000000001231453723256400171400ustar00rootroot00000000000000#include "universalConsts.h" #include "floatConsts.h" #define DIM_INT_STR 1dFloat zfp-1.0.1/tests/constants/1dInt32.h000066400000000000000000000001231453723256400167720ustar00rootroot00000000000000#include "universalConsts.h" #include "int32Consts.h" #define DIM_INT_STR 1dInt32 zfp-1.0.1/tests/constants/1dInt64.h000066400000000000000000000001231453723256400167770ustar00rootroot00000000000000#include "universalConsts.h" #include "int64Consts.h" #define DIM_INT_STR 1dInt64 zfp-1.0.1/tests/constants/2dDouble.h000066400000000000000000000001251453723256400173100ustar00rootroot00000000000000#include "universalConsts.h" #include "doubleConsts.h" #define DIM_INT_STR 2dDouble zfp-1.0.1/tests/constants/2dFloat.h000066400000000000000000000001231453723256400171410ustar00rootroot00000000000000#include "universalConsts.h" #include "floatConsts.h" #define DIM_INT_STR 2dFloat zfp-1.0.1/tests/constants/2dInt32.h000066400000000000000000000001231453723256400167730ustar00rootroot00000000000000#include "universalConsts.h" #include "int32Consts.h" #define DIM_INT_STR 2dInt32 zfp-1.0.1/tests/constants/2dInt64.h000066400000000000000000000001231453723256400170000ustar00rootroot00000000000000#include "universalConsts.h" #include "int64Consts.h" #define DIM_INT_STR 2dInt64 zfp-1.0.1/tests/constants/3dDouble.h000066400000000000000000000001251453723256400173110ustar00rootroot00000000000000#include "universalConsts.h" #include "doubleConsts.h" #define DIM_INT_STR 3dDouble zfp-1.0.1/tests/constants/3dFloat.h000066400000000000000000000001231453723256400171420ustar00rootroot00000000000000#include "universalConsts.h" #include "floatConsts.h" #define DIM_INT_STR 3dFloat zfp-1.0.1/tests/constants/3dInt32.h000066400000000000000000000001231453723256400167740ustar00rootroot00000000000000#include "universalConsts.h" #include "int32Consts.h" #define DIM_INT_STR 3dInt32 zfp-1.0.1/tests/constants/3dInt64.h000066400000000000000000000001231453723256400170010ustar00rootroot00000000000000#include "universalConsts.h" #include "int64Consts.h" #define DIM_INT_STR 3dInt64 zfp-1.0.1/tests/constants/4dDouble.h000066400000000000000000000001251453723256400173120ustar00rootroot00000000000000#include "universalConsts.h" #include "doubleConsts.h" #define DIM_INT_STR 4dDouble zfp-1.0.1/tests/constants/4dFloat.h000066400000000000000000000001231453723256400171430ustar00rootroot00000000000000#include "universalConsts.h" #include "floatConsts.h" #define DIM_INT_STR 4dFloat zfp-1.0.1/tests/constants/4dInt32.h000066400000000000000000000001231453723256400167750ustar00rootroot00000000000000#include "universalConsts.h" #include "int32Consts.h" #define DIM_INT_STR 4dInt32 zfp-1.0.1/tests/constants/4dInt64.h000066400000000000000000000001231453723256400170020ustar00rootroot00000000000000#include "universalConsts.h" #include "int64Consts.h" #define DIM_INT_STR 4dInt64 zfp-1.0.1/tests/constants/checksums/000077500000000000000000000000001453723256400174665ustar00rootroot00000000000000zfp-1.0.1/tests/constants/checksums/1dDouble.h000066400000000000000000000043001453723256400212730ustar00rootroot00000000000000static const checksum_tuples _1dDoubleChecksums[35] = { {UINT64C(0x0), UINT64C(0x3), UINT64C(0xb519ca1b83e2b23f)}, {UINT64C(0xa0), UINT64C(0x3), UINT64C(0xd1a4b883363919a6)}, {UINT64C(0xd1), UINT64C(0x3), UINT64C(0x0)}, {UINT64C(0xd2), UINT64C(0x3), UINT64C(0xc1de1da8)}, {UINT64C(0xd3), UINT64C(0x3), UINT64C(0xeb469308)}, {UINT64C(0xd4), UINT64C(0x3), UINT64C(0x97d201d8)}, {UINT64C(0xd5), UINT64C(0x3), UINT64C(0x49dccd6ddfc3e6d0)}, {UINT64C(0xd6), UINT64C(0x3), UINT64C(0xcfe894df52ba0b77)}, {UINT64C(0xd7), UINT64C(0x3), UINT64C(0xdac7d74cdcc77f2)}, {UINT64C(0xd8), UINT64C(0x3), UINT64C(0xaea40aaff9d6d766)}, {UINT64C(0xd9), UINT64C(0x3), UINT64C(0xadd892805c539502)}, {UINT64C(0xda), UINT64C(0x3), UINT64C(0x30cf22a9e4dafb50)}, {UINT64C(0x2a0), UINT64C(0x3), UINT64C(0x7e0c5012d3011a34)}, {UINT64C(0x120), UINT64C(0x3), UINT64C(0xf034a06e00000000)}, {UINT64C(0x320), UINT64C(0x3), UINT64C(0x907a60b70d3a1692)}, {UINT64C(0x400), UINT64C(0x100000), UINT64C(0x49d66cd3c1044484)}, {UINT64C(0x4b0), UINT64C(0x100000), UINT64C(0xd19e1bd58ae7b771)}, {UINT64C(0x530), UINT64C(0x100000), UINT64C(0xe823070a00000000)}, {UINT64C(0x4b1), UINT64C(0x100000), UINT64C(0xd1de17cee7c8de3b)}, {UINT64C(0x531), UINT64C(0x100000), UINT64C(0x174e113400000000)}, {UINT64C(0x4b2), UINT64C(0x100000), UINT64C(0x89204000682034e7)}, {UINT64C(0x532), UINT64C(0x100000), UINT64C(0xa8c3e7eef220a0e4)}, {UINT64C(0x4a0), UINT64C(0x100000), UINT64C(0x713fc507f37f624d)}, {UINT64C(0x520), UINT64C(0x100000), UINT64C(0xeecbcbd400000000)}, {UINT64C(0x4a1), UINT64C(0x100000), UINT64C(0xa9c0457b722fce7c)}, {UINT64C(0x521), UINT64C(0x100000), UINT64C(0x5763edcdef7122e3)}, {UINT64C(0x4a2), UINT64C(0x100000), UINT64C(0xb6569815387d0248)}, {UINT64C(0x522), UINT64C(0x100000), UINT64C(0x84a661bb59df99b6)}, {UINT64C(0x4c0), UINT64C(0x100000), UINT64C(0x492797c144b2f5aa)}, {UINT64C(0x540), UINT64C(0x100000), UINT64C(0x33931390025a6c7)}, {UINT64C(0x4c1), UINT64C(0x100000), UINT64C(0x5f530b841d8ad3b2)}, {UINT64C(0x541), UINT64C(0x100000), UINT64C(0x1245fb8d26d1004b)}, {UINT64C(0x4c2), UINT64C(0x100000), UINT64C(0x8aaa2c3635420ca1)}, {UINT64C(0x542), UINT64C(0x100000), UINT64C(0x495d680180ba02ab)}, {UINT64C(0x4d0), UINT64C(0x100000), UINT64C(0x268fd6fbede5ed59)}, }; zfp-1.0.1/tests/constants/checksums/1dFloat.h000066400000000000000000000041601453723256400211320ustar00rootroot00000000000000static const checksum_tuples _1dFloatChecksums[35] = { {UINT64C(0x0), UINT64C(0x3), UINT64C(0xa35730c2)}, {UINT64C(0xa0), UINT64C(0x3), UINT64C(0x40bdf65ac73b115c)}, {UINT64C(0xd1), UINT64C(0x3), UINT64C(0x0)}, {UINT64C(0xd2), UINT64C(0x3), UINT64C(0x7baad4bceaf3d5c4)}, {UINT64C(0xd3), UINT64C(0x3), UINT64C(0xe3aab612eaf3d5c4)}, {UINT64C(0xd4), UINT64C(0x3), UINT64C(0x71d55b09a42ac833)}, {UINT64C(0xd5), UINT64C(0x3), UINT64C(0x8ca6efaedb5cd44e)}, {UINT64C(0xd6), UINT64C(0x3), UINT64C(0x15845a4aad908133)}, {UINT64C(0xd7), UINT64C(0x3), UINT64C(0xd277135bdcf92823)}, {UINT64C(0xd8), UINT64C(0x3), UINT64C(0xed4fc9b68f3c00b8)}, {UINT64C(0xd9), UINT64C(0x3), UINT64C(0x9fd129bea6d1bbd5)}, {UINT64C(0xda), UINT64C(0x3), UINT64C(0xaee692dd4f340c9f)}, {UINT64C(0x2a0), UINT64C(0x3), UINT64C(0xb4fe1804c2e28f46)}, {UINT64C(0x120), UINT64C(0x3), UINT64C(0xe7f64d14)}, {UINT64C(0x320), UINT64C(0x3), UINT64C(0x6bc01e0)}, {UINT64C(0x400), UINT64C(0x100000), UINT64C(0x81123c83)}, {UINT64C(0x4b0), UINT64C(0x100000), UINT64C(0x6698eeddef2c576f)}, {UINT64C(0x530), UINT64C(0x100000), UINT64C(0x7582fd98)}, {UINT64C(0x4b1), UINT64C(0x100000), UINT64C(0xd2f86ca7a1a270e6)}, {UINT64C(0x531), UINT64C(0x100000), UINT64C(0xa6e9b884)}, {UINT64C(0x4b2), UINT64C(0x100000), UINT64C(0x5b428a8dde9cc0c1)}, {UINT64C(0x532), UINT64C(0x100000), UINT64C(0x81123c83)}, {UINT64C(0x4a0), UINT64C(0x100000), UINT64C(0x4271157f4d1561e4)}, {UINT64C(0x520), UINT64C(0x100000), UINT64C(0xc298af05)}, {UINT64C(0x4a1), UINT64C(0x100000), UINT64C(0x450fcb1330dab01a)}, {UINT64C(0x521), UINT64C(0x100000), UINT64C(0xfe1c110c)}, {UINT64C(0x4a2), UINT64C(0x100000), UINT64C(0xae3f40d6903e54eb)}, {UINT64C(0x522), UINT64C(0x100000), UINT64C(0x81123c83)}, {UINT64C(0x4c0), UINT64C(0x100000), UINT64C(0xe8cef6c8c8ac1e62)}, {UINT64C(0x540), UINT64C(0x100000), UINT64C(0xaef278e8)}, {UINT64C(0x4c1), UINT64C(0x100000), UINT64C(0x83fe1bf6d49a1b6e)}, {UINT64C(0x541), UINT64C(0x100000), UINT64C(0x60361242)}, {UINT64C(0x4c2), UINT64C(0x100000), UINT64C(0xe7ab29faf14866d1)}, {UINT64C(0x542), UINT64C(0x100000), UINT64C(0x67e8c596)}, {UINT64C(0x4d0), UINT64C(0x100000), UINT64C(0xed4507b04c0b7919)}, }; zfp-1.0.1/tests/constants/checksums/1dInt32.h000066400000000000000000000022261453723256400207650ustar00rootroot00000000000000static const checksum_tuples _1dInt32Checksums[19] = { {UINT64C(0x0), UINT64C(0x3), UINT64C(0xf3e7c054)}, {UINT64C(0xa0), UINT64C(0x3), UINT64C(0xc9d92bd5bdfd2c41)}, {UINT64C(0x2a0), UINT64C(0x3), UINT64C(0x2b7ac04c5f2c27f9)}, {UINT64C(0x120), UINT64C(0x3), UINT64C(0x4b38a824)}, {UINT64C(0x320), UINT64C(0x3), UINT64C(0xfbfb6da8)}, {UINT64C(0x400), UINT64C(0x1000), UINT64C(0x224cbf63)}, {UINT64C(0x4b0), UINT64C(0x1000), UINT64C(0xd31e1d4f3028cea)}, {UINT64C(0x530), UINT64C(0x1000), UINT64C(0xae502d39)}, {UINT64C(0x4b1), UINT64C(0x1000), UINT64C(0x2d76d29099fb22ec)}, {UINT64C(0x531), UINT64C(0x1000), UINT64C(0xdf369702)}, {UINT64C(0x4b2), UINT64C(0x1000), UINT64C(0xb90d9da736a534a9)}, {UINT64C(0x532), UINT64C(0x1000), UINT64C(0x8e2310b0)}, {UINT64C(0x4a0), UINT64C(0x1000), UINT64C(0x804c71c729a559cf)}, {UINT64C(0x520), UINT64C(0x1000), UINT64C(0xff2890c)}, {UINT64C(0x4a1), UINT64C(0x1000), UINT64C(0xbe1ef33c903369a4)}, {UINT64C(0x521), UINT64C(0x1000), UINT64C(0x35a6f08e)}, {UINT64C(0x4a2), UINT64C(0x1000), UINT64C(0x8c1e4b2bdfca4bca)}, {UINT64C(0x522), UINT64C(0x1000), UINT64C(0x8e2310b0)}, {UINT64C(0x4d0), UINT64C(0x1000), UINT64C(0xcd449c2be8c8a337)}, }; zfp-1.0.1/tests/constants/checksums/1dInt64.h000066400000000000000000000023451453723256400207740ustar00rootroot00000000000000static const checksum_tuples _1dInt64Checksums[19] = { {UINT64C(0x0), UINT64C(0x3), UINT64C(0x10decbfab896db77)}, {UINT64C(0xa0), UINT64C(0x3), UINT64C(0x103c2fc57809b590)}, {UINT64C(0x2a0), UINT64C(0x3), UINT64C(0x5a808f85fa746948)}, {UINT64C(0x120), UINT64C(0x3), UINT64C(0x321e0ab000000000)}, {UINT64C(0x320), UINT64C(0x3), UINT64C(0x1e0e4631271d520e)}, {UINT64C(0x400), UINT64C(0x1000), UINT64C(0x261f22581146db18)}, {UINT64C(0x4b0), UINT64C(0x1000), UINT64C(0xd31e1d4f3028cea)}, {UINT64C(0x530), UINT64C(0x1000), UINT64C(0xae502d3900000000)}, {UINT64C(0x4b1), UINT64C(0x1000), UINT64C(0x2d76d29099fb22ec)}, {UINT64C(0x531), UINT64C(0x1000), UINT64C(0xdf36970200000000)}, {UINT64C(0x4b2), UINT64C(0x1000), UINT64C(0x2fa06f3672c34330)}, {UINT64C(0x532), UINT64C(0x1000), UINT64C(0xc64d5c7c923c2a4e)}, {UINT64C(0x4a0), UINT64C(0x1000), UINT64C(0x804c71c729a559cf)}, {UINT64C(0x520), UINT64C(0x1000), UINT64C(0xff2890c00000000)}, {UINT64C(0x4a1), UINT64C(0x1000), UINT64C(0xdf50079b903369a4)}, {UINT64C(0x521), UINT64C(0x1000), UINT64C(0xea935b1000000000)}, {UINT64C(0x4a2), UINT64C(0x1000), UINT64C(0x9de253002800ea54)}, {UINT64C(0x522), UINT64C(0x1000), UINT64C(0xebb9a3b522e681e)}, {UINT64C(0x4d0), UINT64C(0x1000), UINT64C(0x718abd28a6b2f034)}, }; zfp-1.0.1/tests/constants/checksums/2dDouble.h000066400000000000000000000045271453723256400213070ustar00rootroot00000000000000static const checksum_tuples _2dDoubleChecksums[35] = { {UINT64C(0x0), UINT64C(0x3000003), UINT64C(0x1c772c230f3ccbb4)}, {UINT64C(0xa0), UINT64C(0x3000003), UINT64C(0xc0a1814da6ce303b)}, {UINT64C(0xd1), UINT64C(0x3000003), UINT64C(0x0)}, {UINT64C(0xd2), UINT64C(0x3000003), UINT64C(0x83b0d73d)}, {UINT64C(0xd3), UINT64C(0x3000003), UINT64C(0x289bae9d)}, {UINT64C(0xd4), UINT64C(0x3000003), UINT64C(0x5d6e57cf)}, {UINT64C(0xd5), UINT64C(0x3000003), UINT64C(0x52a77478bd871422)}, {UINT64C(0xd6), UINT64C(0x3000003), UINT64C(0x5f99e005089267e0)}, {UINT64C(0xd7), UINT64C(0x3000003), UINT64C(0x7d108dc9451d2cb7)}, {UINT64C(0xd8), UINT64C(0x3000003), UINT64C(0x34c72b14e6ed9d8c)}, {UINT64C(0xd9), UINT64C(0x3000003), UINT64C(0xba67c09098a3d01a)}, {UINT64C(0xda), UINT64C(0x3000003), UINT64C(0x7d108dc9271c8a60)}, {UINT64C(0x2a0), UINT64C(0x3000003), UINT64C(0xf47a9d0740fd12f1)}, {UINT64C(0x120), UINT64C(0x3000003), UINT64C(0x7ac02ede00000000)}, {UINT64C(0x320), UINT64C(0x3000003), UINT64C(0x12ef3cd64903bcca)}, {UINT64C(0x400), UINT64C(0x400000400), UINT64C(0x856a073a7252dd4)}, {UINT64C(0x4b0), UINT64C(0x400000400), UINT64C(0xe4efc0e6e0c4937f)}, {UINT64C(0x530), UINT64C(0x400000400), UINT64C(0x8e010bbc00000000)}, {UINT64C(0x4b1), UINT64C(0x400000400), UINT64C(0x26ab1ab12b69d8e7)}, {UINT64C(0x531), UINT64C(0x400000400), UINT64C(0xa296ec5400000000)}, {UINT64C(0x4b2), UINT64C(0x400000400), UINT64C(0xd7605316605ae257)}, {UINT64C(0x532), UINT64C(0x400000400), UINT64C(0x626c78e0852013ee)}, {UINT64C(0x4a0), UINT64C(0x400000400), UINT64C(0x10288c2054631266)}, {UINT64C(0x520), UINT64C(0x400000400), UINT64C(0xd5495117b8fe1c02)}, {UINT64C(0x4a1), UINT64C(0x400000400), UINT64C(0xb1d8865622fe6fc0)}, {UINT64C(0x521), UINT64C(0x400000400), UINT64C(0x9437836903fc33a1)}, {UINT64C(0x4a2), UINT64C(0x400000400), UINT64C(0x816b6359b90eaba1)}, {UINT64C(0x522), UINT64C(0x400000400), UINT64C(0x124ac89d7f6e6511)}, {UINT64C(0x4c0), UINT64C(0x400000400), UINT64C(0x7cb428be5481bd7b)}, {UINT64C(0x540), UINT64C(0x400000400), UINT64C(0x2229f480c522c420)}, {UINT64C(0x4c1), UINT64C(0x400000400), UINT64C(0xf94462ab31afa215)}, {UINT64C(0x541), UINT64C(0x400000400), UINT64C(0x25f62aac2713f851)}, {UINT64C(0x4c2), UINT64C(0x400000400), UINT64C(0x8beb41214f9ee0d6)}, {UINT64C(0x542), UINT64C(0x400000400), UINT64C(0x94fd382138403fb1)}, {UINT64C(0x4d0), UINT64C(0x400000400), UINT64C(0x1481e46e30d0f3ab)}, }; zfp-1.0.1/tests/constants/checksums/2dFloat.h000066400000000000000000000044011453723256400211310ustar00rootroot00000000000000static const checksum_tuples _2dFloatChecksums[35] = { {UINT64C(0x0), UINT64C(0x3000003), UINT64C(0xd61ebeeb)}, {UINT64C(0xa0), UINT64C(0x3000003), UINT64C(0xda4c301a8e0f8cee)}, {UINT64C(0xd1), UINT64C(0x3000003), UINT64C(0x0)}, {UINT64C(0xd2), UINT64C(0x3000003), UINT64C(0xeabd0942eaf3d5c4)}, {UINT64C(0xd3), UINT64C(0x3000003), UINT64C(0x37364bbaeaf3d5c4)}, {UINT64C(0xd4), UINT64C(0x3000003), UINT64C(0x1bab25dda42ac833)}, {UINT64C(0xd5), UINT64C(0x3000003), UINT64C(0x15efe9eb467df9de)}, {UINT64C(0xd6), UINT64C(0x3000003), UINT64C(0x646c26ae1386d3f)}, {UINT64C(0xd7), UINT64C(0x3000003), UINT64C(0x927724ec9f90816d)}, {UINT64C(0xd8), UINT64C(0x3000003), UINT64C(0x8d27f49059a9fe98)}, {UINT64C(0xd9), UINT64C(0x3000003), UINT64C(0x9d4930c42f82c1fb)}, {UINT64C(0xda), UINT64C(0x3000003), UINT64C(0x11acf6d756257748)}, {UINT64C(0x2a0), UINT64C(0x3000003), UINT64C(0x584942f81bec40fb)}, {UINT64C(0x120), UINT64C(0x3000003), UINT64C(0xd183b619)}, {UINT64C(0x320), UINT64C(0x3000003), UINT64C(0x713809a7)}, {UINT64C(0x400), UINT64C(0x400000400), UINT64C(0xe4bfe4e)}, {UINT64C(0x4b0), UINT64C(0x400000400), UINT64C(0x8417e3e4287f38b5)}, {UINT64C(0x530), UINT64C(0x400000400), UINT64C(0x9b77e022)}, {UINT64C(0x4b1), UINT64C(0x400000400), UINT64C(0xf5356ab8f5b59e8a)}, {UINT64C(0x531), UINT64C(0x400000400), UINT64C(0x541a3433)}, {UINT64C(0x4b2), UINT64C(0x400000400), UINT64C(0xa537f64220d1fc1d)}, {UINT64C(0x532), UINT64C(0x400000400), UINT64C(0xe4bfe4e)}, {UINT64C(0x4a0), UINT64C(0x400000400), UINT64C(0xd183e05b7c3be5eb)}, {UINT64C(0x520), UINT64C(0x400000400), UINT64C(0x5198a34b)}, {UINT64C(0x4a1), UINT64C(0x400000400), UINT64C(0x254679da05758c1a)}, {UINT64C(0x521), UINT64C(0x400000400), UINT64C(0xb9126f4)}, {UINT64C(0x4a2), UINT64C(0x400000400), UINT64C(0x72cd5c52aa46c2da)}, {UINT64C(0x522), UINT64C(0x400000400), UINT64C(0xe4bfe4e)}, {UINT64C(0x4c0), UINT64C(0x400000400), UINT64C(0x211f16ea5922b678)}, {UINT64C(0x540), UINT64C(0x400000400), UINT64C(0x2e0e3c8b)}, {UINT64C(0x4c1), UINT64C(0x400000400), UINT64C(0xf2a1526474d8ee29)}, {UINT64C(0x541), UINT64C(0x400000400), UINT64C(0xb6a7efcb)}, {UINT64C(0x4c2), UINT64C(0x400000400), UINT64C(0x53ed9feb9ca6dd1a)}, {UINT64C(0x542), UINT64C(0x400000400), UINT64C(0x18bad4a1)}, {UINT64C(0x4d0), UINT64C(0x400000400), UINT64C(0xe91cd56d5db78ef)}, }; zfp-1.0.1/tests/constants/checksums/2dInt32.h000066400000000000000000000023551453723256400207710ustar00rootroot00000000000000static const checksum_tuples _2dInt32Checksums[19] = { {UINT64C(0x0), UINT64C(0x3000003), UINT64C(0x94aada73)}, {UINT64C(0xa0), UINT64C(0x3000003), UINT64C(0x1264830f387e560)}, {UINT64C(0x2a0), UINT64C(0x3000003), UINT64C(0xf09d2faf2ba66c16)}, {UINT64C(0x120), UINT64C(0x3000003), UINT64C(0x3ece4105)}, {UINT64C(0x320), UINT64C(0x3000003), UINT64C(0xbb514638)}, {UINT64C(0x400), UINT64C(0x40000040), UINT64C(0xbafc4f7c)}, {UINT64C(0x4b0), UINT64C(0x40000040), UINT64C(0x2a2ecc3532b9e47c)}, {UINT64C(0x530), UINT64C(0x40000040), UINT64C(0xa0b51de9)}, {UINT64C(0x4b1), UINT64C(0x40000040), UINT64C(0xa68050a6f03bbeac)}, {UINT64C(0x531), UINT64C(0x40000040), UINT64C(0x8d1227ea)}, {UINT64C(0x4b2), UINT64C(0x40000040), UINT64C(0x298cca6049cda102)}, {UINT64C(0x532), UINT64C(0x40000040), UINT64C(0xb331c139)}, {UINT64C(0x4a0), UINT64C(0x40000040), UINT64C(0x419666be07f8fd5b)}, {UINT64C(0x520), UINT64C(0x40000040), UINT64C(0xc955273b)}, {UINT64C(0x4a1), UINT64C(0x40000040), UINT64C(0x1bb735117e4b84c0)}, {UINT64C(0x521), UINT64C(0x40000040), UINT64C(0xb2cff311)}, {UINT64C(0x4a2), UINT64C(0x40000040), UINT64C(0x45e684a399d342bf)}, {UINT64C(0x522), UINT64C(0x40000040), UINT64C(0xb331c139)}, {UINT64C(0x4d0), UINT64C(0x40000040), UINT64C(0x55be045ea7268027)}, }; zfp-1.0.1/tests/constants/checksums/2dInt64.h000066400000000000000000000024741453723256400210000ustar00rootroot00000000000000static const checksum_tuples _2dInt64Checksums[19] = { {UINT64C(0x0), UINT64C(0x3000003), UINT64C(0x60569371027435a7)}, {UINT64C(0xa0), UINT64C(0x3000003), UINT64C(0x74905e21b1d68ae2)}, {UINT64C(0x2a0), UINT64C(0x3000003), UINT64C(0xc83e2f319f07372e)}, {UINT64C(0x120), UINT64C(0x3000003), UINT64C(0x8cdc228000000000)}, {UINT64C(0x320), UINT64C(0x3000003), UINT64C(0x6bd17a493be325d1)}, {UINT64C(0x400), UINT64C(0x40000040), UINT64C(0xf57fe1822b2a33c8)}, {UINT64C(0x4b0), UINT64C(0x40000040), UINT64C(0x2a2ecc3532b9e47c)}, {UINT64C(0x530), UINT64C(0x40000040), UINT64C(0xa0b51de900000000)}, {UINT64C(0x4b1), UINT64C(0x40000040), UINT64C(0xa68050a6f03bbeac)}, {UINT64C(0x531), UINT64C(0x40000040), UINT64C(0x8d1227ea00000000)}, {UINT64C(0x4b2), UINT64C(0x40000040), UINT64C(0x7abe90820ae730a)}, {UINT64C(0x532), UINT64C(0x40000040), UINT64C(0x4384aefdd310e015)}, {UINT64C(0x4a0), UINT64C(0x40000040), UINT64C(0x419666be07f8fd5b)}, {UINT64C(0x520), UINT64C(0x40000040), UINT64C(0xc955273b00000000)}, {UINT64C(0x4a1), UINT64C(0x40000040), UINT64C(0xd9cd09fd7e4b84c0)}, {UINT64C(0x521), UINT64C(0x40000040), UINT64C(0x74b2370100000000)}, {UINT64C(0x4a2), UINT64C(0x40000040), UINT64C(0x8bed6d7ee10836ae)}, {UINT64C(0x522), UINT64C(0x40000040), UINT64C(0xe0b475056c768219)}, {UINT64C(0x4d0), UINT64C(0x40000040), UINT64C(0xaced76ad1c2ebb9)}, }; zfp-1.0.1/tests/constants/checksums/3dDouble.h000066400000000000000000000046401453723256400213040ustar00rootroot00000000000000static const checksum_tuples _3dDoubleChecksums[35] = { {UINT64C(0x0), UINT64C(0x300030003), UINT64C(0x5f9e82c4fef6f593)}, {UINT64C(0xa0), UINT64C(0x300030003), UINT64C(0x20a6c761afd4380b)}, {UINT64C(0xd1), UINT64C(0x300030003), UINT64C(0x0)}, {UINT64C(0xd2), UINT64C(0x300030003), UINT64C(0x927724ecdcf219fb)}, {UINT64C(0xd3), UINT64C(0x300030003), UINT64C(0x393a6de095b240e0)}, {UINT64C(0xd4), UINT64C(0x300030003), UINT64C(0x9c9d36f01c36b045)}, {UINT64C(0xd5), UINT64C(0x300030003), UINT64C(0xa71ba2fe0b649fc)}, {UINT64C(0xd6), UINT64C(0x300030003), UINT64C(0x7e8c15054d871bd9)}, {UINT64C(0xd7), UINT64C(0x300030003), UINT64C(0xe4eab78245c08a26)}, {UINT64C(0xd8), UINT64C(0x300030003), UINT64C(0x5ac46921892607c6)}, {UINT64C(0xd9), UINT64C(0x300030003), UINT64C(0xbfb026919c6944c4)}, {UINT64C(0xda), UINT64C(0x300030003), UINT64C(0xf3420697931ed828)}, {UINT64C(0x2a0), UINT64C(0x300030003), UINT64C(0x9a658e0fe05b9657)}, {UINT64C(0x120), UINT64C(0x300030003), UINT64C(0x4f653444ff3fdbe4)}, {UINT64C(0x320), UINT64C(0x300030003), UINT64C(0x7e8c64faafedcb18)}, {UINT64C(0x400), UINT64C(0x8000800080), UINT64C(0xb29ddfb4a7719b6a)}, {UINT64C(0x4b0), UINT64C(0x8000800080), UINT64C(0x6b5b0dab297c9d33)}, {UINT64C(0x530), UINT64C(0x8000800080), UINT64C(0x1e497b1f00000000)}, {UINT64C(0x4b1), UINT64C(0x8000800080), UINT64C(0xe933645e8cf7a7c9)}, {UINT64C(0x531), UINT64C(0x8000800080), UINT64C(0xdce089f900000000)}, {UINT64C(0x4b2), UINT64C(0x8000800080), UINT64C(0xc3d061d1944a8106)}, {UINT64C(0x532), UINT64C(0x8000800080), UINT64C(0x3817c78441377d10)}, {UINT64C(0x4a0), UINT64C(0x8000800080), UINT64C(0xd3b75ae8488a556d)}, {UINT64C(0x520), UINT64C(0x8000800080), UINT64C(0xf4bd2afd74af921)}, {UINT64C(0x4a1), UINT64C(0x8000800080), UINT64C(0x8d8d80142436d812)}, {UINT64C(0x521), UINT64C(0x8000800080), UINT64C(0x9103ee0106602bb1)}, {UINT64C(0x4a2), UINT64C(0x8000800080), UINT64C(0x64e50911ed54c0ef)}, {UINT64C(0x522), UINT64C(0x8000800080), UINT64C(0xcd7da85356f9db40)}, {UINT64C(0x4c0), UINT64C(0x8000800080), UINT64C(0xca9d4c2be9c2a15b)}, {UINT64C(0x540), UINT64C(0x8000800080), UINT64C(0x8eaf0fa126b3de89)}, {UINT64C(0x4c1), UINT64C(0x8000800080), UINT64C(0x8f79006fd9e45619)}, {UINT64C(0x541), UINT64C(0x8000800080), UINT64C(0xb0dd4ed6a7196f47)}, {UINT64C(0x4c2), UINT64C(0x8000800080), UINT64C(0x5c056eecba4d5349)}, {UINT64C(0x542), UINT64C(0x8000800080), UINT64C(0x3262044561f9cceb)}, {UINT64C(0x4d0), UINT64C(0x8000800080), UINT64C(0xaf95ff6301796621)}, }; zfp-1.0.1/tests/constants/checksums/3dFloat.h000066400000000000000000000044661453723256400211450ustar00rootroot00000000000000static const checksum_tuples _3dFloatChecksums[35] = { {UINT64C(0x0), UINT64C(0x300030003), UINT64C(0x54572f34)}, {UINT64C(0xa0), UINT64C(0x300030003), UINT64C(0x6ad38b388f18d118)}, {UINT64C(0xd1), UINT64C(0x300030003), UINT64C(0x0)}, {UINT64C(0xd2), UINT64C(0x300030003), UINT64C(0x4e0632d046a7a0e)}, {UINT64C(0xd3), UINT64C(0x300030003), UINT64C(0xf375ed06da7f218c)}, {UINT64C(0xd4), UINT64C(0x300030003), UINT64C(0x79aaf683295b4527)}, {UINT64C(0xd5), UINT64C(0x300030003), UINT64C(0xc71006bf172ec200)}, {UINT64C(0xd6), UINT64C(0x300030003), UINT64C(0x163602c727dbbba2)}, {UINT64C(0xd7), UINT64C(0x300030003), UINT64C(0xda199ff1947e73d2)}, {UINT64C(0xd8), UINT64C(0x300030003), UINT64C(0x84db4dd6885773b5)}, {UINT64C(0xd9), UINT64C(0x300030003), UINT64C(0x68a0b34799c2f1f8)}, {UINT64C(0xda), UINT64C(0x300030003), UINT64C(0xd4b6310ae6d2d4de)}, {UINT64C(0x2a0), UINT64C(0x300030003), UINT64C(0x256107e3209389ee)}, {UINT64C(0x120), UINT64C(0x300030003), UINT64C(0xd822c66d)}, {UINT64C(0x320), UINT64C(0x300030003), UINT64C(0xc3e0b4fb)}, {UINT64C(0x400), UINT64C(0x8000800080), UINT64C(0xdbe7e231)}, {UINT64C(0x4b0), UINT64C(0x8000800080), UINT64C(0xe3b79c04a6174576)}, {UINT64C(0x530), UINT64C(0x8000800080), UINT64C(0x6ea0403c)}, {UINT64C(0x4b1), UINT64C(0x8000800080), UINT64C(0xb666d473ca7d7e1c)}, {UINT64C(0x531), UINT64C(0x8000800080), UINT64C(0xc2408604)}, {UINT64C(0x4b2), UINT64C(0x8000800080), UINT64C(0xb0c2a41ec2111183)}, {UINT64C(0x532), UINT64C(0x8000800080), UINT64C(0x97a819ae)}, {UINT64C(0x4a0), UINT64C(0x8000800080), UINT64C(0x5ec963fda5ed8273)}, {UINT64C(0x520), UINT64C(0x8000800080), UINT64C(0xb0695ba7)}, {UINT64C(0x4a1), UINT64C(0x8000800080), UINT64C(0xa72b103d6027cbef)}, {UINT64C(0x521), UINT64C(0x8000800080), UINT64C(0xcdd7c8b6)}, {UINT64C(0x4a2), UINT64C(0x8000800080), UINT64C(0x4e2c7e0bf502c3a1)}, {UINT64C(0x522), UINT64C(0x8000800080), UINT64C(0x97a819ae)}, {UINT64C(0x4c0), UINT64C(0x8000800080), UINT64C(0xdb9351a2125e34e4)}, {UINT64C(0x540), UINT64C(0x8000800080), UINT64C(0x3518c38f)}, {UINT64C(0x4c1), UINT64C(0x8000800080), UINT64C(0x2fd5a60cdd2227e)}, {UINT64C(0x541), UINT64C(0x8000800080), UINT64C(0x4f0985dd)}, {UINT64C(0x4c2), UINT64C(0x8000800080), UINT64C(0x73829fdec12a0374)}, {UINT64C(0x542), UINT64C(0x8000800080), UINT64C(0xcb6afbd)}, {UINT64C(0x4d0), UINT64C(0x8000800080), UINT64C(0xb6475a8758f10fe0)}, }; zfp-1.0.1/tests/constants/checksums/3dInt32.h000066400000000000000000000024231453723256400207660ustar00rootroot00000000000000static const checksum_tuples _3dInt32Checksums[19] = { {UINT64C(0x0), UINT64C(0x300030003), UINT64C(0xab8e83e9)}, {UINT64C(0xa0), UINT64C(0x300030003), UINT64C(0xda55ac5950c74c2)}, {UINT64C(0x2a0), UINT64C(0x300030003), UINT64C(0xb85a3bd936a5c392)}, {UINT64C(0x120), UINT64C(0x300030003), UINT64C(0xdbb57cfa)}, {UINT64C(0x320), UINT64C(0x300030003), UINT64C(0x205d2fad)}, {UINT64C(0x400), UINT64C(0x1000100010), UINT64C(0xad7ade47)}, {UINT64C(0x4b0), UINT64C(0x1000100010), UINT64C(0xc92ee0e3f6e6aa91)}, {UINT64C(0x530), UINT64C(0x1000100010), UINT64C(0xd2482c01)}, {UINT64C(0x4b1), UINT64C(0x1000100010), UINT64C(0x21b0a7777c2c5b2d)}, {UINT64C(0x531), UINT64C(0x1000100010), UINT64C(0x9436e0c7)}, {UINT64C(0x4b2), UINT64C(0x1000100010), UINT64C(0xfe72d7ca4ce4cd2b)}, {UINT64C(0x532), UINT64C(0x1000100010), UINT64C(0xea428b3e)}, {UINT64C(0x4a0), UINT64C(0x1000100010), UINT64C(0x32942f0afdb349c2)}, {UINT64C(0x520), UINT64C(0x1000100010), UINT64C(0xb3d2ff2c)}, {UINT64C(0x4a1), UINT64C(0x1000100010), UINT64C(0x3a036901bbfdee14)}, {UINT64C(0x521), UINT64C(0x1000100010), UINT64C(0xb9258768)}, {UINT64C(0x4a2), UINT64C(0x1000100010), UINT64C(0x8a8ae9c57224ef8e)}, {UINT64C(0x522), UINT64C(0x1000100010), UINT64C(0xea428b3e)}, {UINT64C(0x4d0), UINT64C(0x1000100010), UINT64C(0xf0ab4d96d89cc545)}, }; zfp-1.0.1/tests/constants/checksums/3dInt64.h000066400000000000000000000025441453723256400207770ustar00rootroot00000000000000static const checksum_tuples _3dInt64Checksums[19] = { {UINT64C(0x0), UINT64C(0x300030003), UINT64C(0xcc5133515849571c)}, {UINT64C(0xa0), UINT64C(0x300030003), UINT64C(0x6c0ff959c2207d41)}, {UINT64C(0x2a0), UINT64C(0x300030003), UINT64C(0xd6b771a93e2404f4)}, {UINT64C(0x120), UINT64C(0x300030003), UINT64C(0x4b9f52d500000000)}, {UINT64C(0x320), UINT64C(0x300030003), UINT64C(0xc78c8cca00000000)}, {UINT64C(0x400), UINT64C(0x1000100010), UINT64C(0xee34e487f557278f)}, {UINT64C(0x4b0), UINT64C(0x1000100010), UINT64C(0xc92ee0e3f6e6aa91)}, {UINT64C(0x530), UINT64C(0x1000100010), UINT64C(0xd2482c0100000000)}, {UINT64C(0x4b1), UINT64C(0x1000100010), UINT64C(0x21b0a7777c2c5b2d)}, {UINT64C(0x531), UINT64C(0x1000100010), UINT64C(0x9436e0c700000000)}, {UINT64C(0x4b2), UINT64C(0x1000100010), UINT64C(0xa8b1239155fdd8ab)}, {UINT64C(0x532), UINT64C(0x1000100010), UINT64C(0xc723b42e1e4f2274)}, {UINT64C(0x4a0), UINT64C(0x1000100010), UINT64C(0x32942f0afdb349c2)}, {UINT64C(0x520), UINT64C(0x1000100010), UINT64C(0xb3d2ff2c00000000)}, {UINT64C(0x4a1), UINT64C(0x1000100010), UINT64C(0x84e238f16919a151)}, {UINT64C(0x521), UINT64C(0x1000100010), UINT64C(0x879bc89700000000)}, {UINT64C(0x4a2), UINT64C(0x1000100010), UINT64C(0x4e6417e960207269)}, {UINT64C(0x522), UINT64C(0x1000100010), UINT64C(0xc348c52175d9ec77)}, {UINT64C(0x4d0), UINT64C(0x1000100010), UINT64C(0x43c8d544f70dccc5)}, }; zfp-1.0.1/tests/constants/checksums/4dDouble.h000066400000000000000000000047031453723256400213050ustar00rootroot00000000000000static const checksum_tuples _4dDoubleChecksums[35] = { {UINT64C(0x0), UINT64C(0x3003003003), UINT64C(0x61f9b8c3ddcbe9b)}, {UINT64C(0xa0), UINT64C(0x3003003003), UINT64C(0x3bd0d8f2da9e9acf)}, {UINT64C(0xd1), UINT64C(0x3003003003), UINT64C(0x0)}, {UINT64C(0xd2), UINT64C(0x3003003003), UINT64C(0xd7e189562d39c484)}, {UINT64C(0xd3), UINT64C(0x3003003003), UINT64C(0x10254b13cbda2b97)}, {UINT64C(0xd4), UINT64C(0x3003003003), UINT64C(0x8126589d3735e9d)}, {UINT64C(0xd5), UINT64C(0x3003003003), UINT64C(0x81c6ab2ae3cbfbac)}, {UINT64C(0xd6), UINT64C(0x3003003003), UINT64C(0xb7521b04e50f0123)}, {UINT64C(0xd7), UINT64C(0x3003003003), UINT64C(0x2d382b62747da555)}, {UINT64C(0xd8), UINT64C(0x3003003003), UINT64C(0xdff214dccadfe445)}, {UINT64C(0xd9), UINT64C(0x3003003003), UINT64C(0xdab8e4ea9761352b)}, {UINT64C(0xda), UINT64C(0x3003003003), UINT64C(0x65fa916b3e3e928e)}, {UINT64C(0x2a0), UINT64C(0x3003003003), UINT64C(0x1dbd79f0a52ec95b)}, {UINT64C(0x120), UINT64C(0x3003003003), UINT64C(0xbf4272427fcd2646)}, {UINT64C(0x320), UINT64C(0x3003003003), UINT64C(0xdf41e51abd93ea8a)}, {UINT64C(0x400), UINT64C(0x20020020020), UINT64C(0xe1c8a968261e4559)}, {UINT64C(0x4b0), UINT64C(0x20020020020), UINT64C(0x7a0d035888f5d7e3)}, {UINT64C(0x530), UINT64C(0x20020020020), UINT64C(0x9940d71100000000)}, {UINT64C(0x4b1), UINT64C(0x20020020020), UINT64C(0xc0f286466ade809e)}, {UINT64C(0x531), UINT64C(0x20020020020), UINT64C(0xaead20c8a88f2622)}, {UINT64C(0x4b2), UINT64C(0x20020020020), UINT64C(0xbfd8f5f591cb0f2d)}, {UINT64C(0x532), UINT64C(0x20020020020), UINT64C(0x4de9a84f4ab886fa)}, {UINT64C(0x4a0), UINT64C(0x20020020020), UINT64C(0x94219b32ec93e2a9)}, {UINT64C(0x520), UINT64C(0x20020020020), UINT64C(0xa1ca18c21794908b)}, {UINT64C(0x4a1), UINT64C(0x20020020020), UINT64C(0x464485425bf411aa)}, {UINT64C(0x521), UINT64C(0x20020020020), UINT64C(0x7abae3fe33d0ce6a)}, {UINT64C(0x4a2), UINT64C(0x20020020020), UINT64C(0x8ca875e7386e2cea)}, {UINT64C(0x522), UINT64C(0x20020020020), UINT64C(0x6a44d79a5a33d47d)}, {UINT64C(0x4c0), UINT64C(0x20020020020), UINT64C(0xc0b867f744b71cc0)}, {UINT64C(0x540), UINT64C(0x20020020020), UINT64C(0xb8f1525cd842fbd5)}, {UINT64C(0x4c1), UINT64C(0x20020020020), UINT64C(0x6a1908a569eb1a99)}, {UINT64C(0x541), UINT64C(0x20020020020), UINT64C(0xb14abd4386fddb81)}, {UINT64C(0x4c2), UINT64C(0x20020020020), UINT64C(0xb920196fca3513eb)}, {UINT64C(0x542), UINT64C(0x20020020020), UINT64C(0x249da35a6e8ca411)}, {UINT64C(0x4d0), UINT64C(0x20020020020), UINT64C(0xd72af5ab206ebe50)}, }; zfp-1.0.1/tests/constants/checksums/4dFloat.h000066400000000000000000000045301453723256400211360ustar00rootroot00000000000000static const checksum_tuples _4dFloatChecksums[35] = { {UINT64C(0x0), UINT64C(0x3003003003), UINT64C(0x8c5867f7)}, {UINT64C(0xa0), UINT64C(0x3003003003), UINT64C(0x26580b0af77ece38)}, {UINT64C(0xd1), UINT64C(0x3003003003), UINT64C(0x0)}, {UINT64C(0xd2), UINT64C(0x3003003003), UINT64C(0xbd6cb9cd6d2735e7)}, {UINT64C(0xd3), UINT64C(0x3003003003), UINT64C(0x943b526033810b7b)}, {UINT64C(0xd4), UINT64C(0x3003003003), UINT64C(0x4a1da930b29a371d)}, {UINT64C(0xd5), UINT64C(0x3003003003), UINT64C(0x276e4805f1ee4de9)}, {UINT64C(0xd6), UINT64C(0x3003003003), UINT64C(0xcd3a562a15f5f5e9)}, {UINT64C(0xd7), UINT64C(0x3003003003), UINT64C(0x241372c19e9d3507)}, {UINT64C(0xd8), UINT64C(0x3003003003), UINT64C(0xbfeec5a9344e5b48)}, {UINT64C(0xd9), UINT64C(0x3003003003), UINT64C(0xeac7292d88f982bf)}, {UINT64C(0xda), UINT64C(0x3003003003), UINT64C(0x667025a3a09f4198)}, {UINT64C(0x2a0), UINT64C(0x3003003003), UINT64C(0xb47c6e115d00b400)}, {UINT64C(0x120), UINT64C(0x3003003003), UINT64C(0xda2b72f9)}, {UINT64C(0x320), UINT64C(0x3003003003), UINT64C(0xfc12ceb2)}, {UINT64C(0x400), UINT64C(0x20020020020), UINT64C(0x725f89ff)}, {UINT64C(0x4b0), UINT64C(0x20020020020), UINT64C(0x59e13fe363db5c6f)}, {UINT64C(0x530), UINT64C(0x20020020020), UINT64C(0xb444287b)}, {UINT64C(0x4b1), UINT64C(0x20020020020), UINT64C(0x23d6299eeaa79a9e)}, {UINT64C(0x531), UINT64C(0x20020020020), UINT64C(0x52fe0450)}, {UINT64C(0x4b2), UINT64C(0x20020020020), UINT64C(0x69ff59c816afd8bd)}, {UINT64C(0x532), UINT64C(0x20020020020), UINT64C(0xd916b61)}, {UINT64C(0x4a0), UINT64C(0x20020020020), UINT64C(0xeaae9de596da1479)}, {UINT64C(0x520), UINT64C(0x20020020020), UINT64C(0xf29a4049)}, {UINT64C(0x4a1), UINT64C(0x20020020020), UINT64C(0xf0e8cdfbb12d5bdb)}, {UINT64C(0x521), UINT64C(0x20020020020), UINT64C(0x8bc47f0d)}, {UINT64C(0x4a2), UINT64C(0x20020020020), UINT64C(0x669314f4f9637698)}, {UINT64C(0x522), UINT64C(0x20020020020), UINT64C(0xd916b61)}, {UINT64C(0x4c0), UINT64C(0x20020020020), UINT64C(0xc22cce8aa431fffb)}, {UINT64C(0x540), UINT64C(0x20020020020), UINT64C(0x83f41e)}, {UINT64C(0x4c1), UINT64C(0x20020020020), UINT64C(0x4b0af02b26351468)}, {UINT64C(0x541), UINT64C(0x20020020020), UINT64C(0x425b2a0d)}, {UINT64C(0x4c2), UINT64C(0x20020020020), UINT64C(0xedc915189e4764f2)}, {UINT64C(0x542), UINT64C(0x20020020020), UINT64C(0x3ca6456a)}, {UINT64C(0x4d0), UINT64C(0x20020020020), UINT64C(0xf2a9c72c87868054)}, }; zfp-1.0.1/tests/constants/checksums/4dInt32.h000066400000000000000000000024271453723256400207730ustar00rootroot00000000000000static const checksum_tuples _4dInt32Checksums[19] = { {UINT64C(0x0), UINT64C(0x3003003003), UINT64C(0x8b21ff0)}, {UINT64C(0xa0), UINT64C(0x3003003003), UINT64C(0xf89b3fdf64ff5b5b)}, {UINT64C(0x2a0), UINT64C(0x3003003003), UINT64C(0x8d094f52b8fd6250)}, {UINT64C(0x120), UINT64C(0x3003003003), UINT64C(0xcaa8e882)}, {UINT64C(0x320), UINT64C(0x3003003003), UINT64C(0x86320cb4)}, {UINT64C(0x400), UINT64C(0x8008008008), UINT64C(0x89f6c535)}, {UINT64C(0x4b0), UINT64C(0x8008008008), UINT64C(0x38d58bf8bf7f5b07)}, {UINT64C(0x530), UINT64C(0x8008008008), UINT64C(0xbd347efd)}, {UINT64C(0x4b1), UINT64C(0x8008008008), UINT64C(0xb9f8a476db61b946)}, {UINT64C(0x531), UINT64C(0x8008008008), UINT64C(0x6f0e9866)}, {UINT64C(0x4b2), UINT64C(0x8008008008), UINT64C(0xb44975c2cdae2907)}, {UINT64C(0x532), UINT64C(0x8008008008), UINT64C(0x539b74c9)}, {UINT64C(0x4a0), UINT64C(0x8008008008), UINT64C(0xabd0b79d9c135337)}, {UINT64C(0x520), UINT64C(0x8008008008), UINT64C(0x5a8a7db4)}, {UINT64C(0x4a1), UINT64C(0x8008008008), UINT64C(0xe331fda805ba7319)}, {UINT64C(0x521), UINT64C(0x8008008008), UINT64C(0xec560874)}, {UINT64C(0x4a2), UINT64C(0x8008008008), UINT64C(0xc934178cb9e06ff5)}, {UINT64C(0x522), UINT64C(0x8008008008), UINT64C(0x539b74c9)}, {UINT64C(0x4d0), UINT64C(0x8008008008), UINT64C(0x8c888a65b12c884)}, }; zfp-1.0.1/tests/constants/checksums/4dInt64.h000066400000000000000000000025501453723256400207750ustar00rootroot00000000000000static const checksum_tuples _4dInt64Checksums[19] = { {UINT64C(0x0), UINT64C(0x3003003003), UINT64C(0xc9f0cadc2b040375)}, {UINT64C(0xa0), UINT64C(0x3003003003), UINT64C(0xbe695ffaef2d6055)}, {UINT64C(0x2a0), UINT64C(0x3003003003), UINT64C(0x3bf1627a5fd514a7)}, {UINT64C(0x120), UINT64C(0x3003003003), UINT64C(0x83e0508600000000)}, {UINT64C(0x320), UINT64C(0x3003003003), UINT64C(0xa194665700000000)}, {UINT64C(0x400), UINT64C(0x8008008008), UINT64C(0x3c7a84c24a0d97db)}, {UINT64C(0x4b0), UINT64C(0x8008008008), UINT64C(0x38d58bf8bf7f5b07)}, {UINT64C(0x530), UINT64C(0x8008008008), UINT64C(0xbd347efd00000000)}, {UINT64C(0x4b1), UINT64C(0x8008008008), UINT64C(0xb9f8a476db61b946)}, {UINT64C(0x531), UINT64C(0x8008008008), UINT64C(0x6f0e986600000000)}, {UINT64C(0x4b2), UINT64C(0x8008008008), UINT64C(0xf1324a2092943e33)}, {UINT64C(0x532), UINT64C(0x8008008008), UINT64C(0x6b2d4650a70cb4be)}, {UINT64C(0x4a0), UINT64C(0x8008008008), UINT64C(0xabd0b79d9c135337)}, {UINT64C(0x520), UINT64C(0x8008008008), UINT64C(0x5a8a7db400000000)}, {UINT64C(0x4a1), UINT64C(0x8008008008), UINT64C(0x4269d84b05ba7319)}, {UINT64C(0x521), UINT64C(0x8008008008), UINT64C(0x73c78b5d00000000)}, {UINT64C(0x4a2), UINT64C(0x8008008008), UINT64C(0x3009aef996d98fa)}, {UINT64C(0x522), UINT64C(0x8008008008), UINT64C(0x230d83c5490fa7dd)}, {UINT64C(0x4d0), UINT64C(0x8008008008), UINT64C(0x6e014f2638fd24d2)}, }; zfp-1.0.1/tests/constants/doubleConsts.h000066400000000000000000000001131453723256400203110ustar00rootroot00000000000000#define FL_PT_DATA #define SCALAR_BITS 64 #define ZFP_TYPE zfp_type_double zfp-1.0.1/tests/constants/floatConsts.h000066400000000000000000000001121453723256400201430ustar00rootroot00000000000000#define FL_PT_DATA #define SCALAR_BITS 32 #define ZFP_TYPE zfp_type_float zfp-1.0.1/tests/constants/int32Consts.h000066400000000000000000000000671453723256400200060ustar00rootroot00000000000000#define SCALAR_BITS 32 #define ZFP_TYPE zfp_type_int32 zfp-1.0.1/tests/constants/int64Consts.h000066400000000000000000000000671453723256400200130ustar00rootroot00000000000000#define SCALAR_BITS 64 #define ZFP_TYPE zfp_type_int64 zfp-1.0.1/tests/constants/universalConsts.h000066400000000000000000000001301453723256400210460ustar00rootroot00000000000000#define BLOCK_SIDE_LEN 4 #define ZFP_RATE_PARAM_BITS 19 #define ZFP_PREC_PARAM_BITS 22 zfp-1.0.1/tests/fortran/000077500000000000000000000000001453723256400151405ustar00rootroot00000000000000zfp-1.0.1/tests/fortran/CMakeLists.txt000066400000000000000000000011621453723256400177000ustar00rootroot00000000000000enable_language(Fortran) if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU") set(dialect "-ffree-form -std=f2008 -fimplicit-none") set(bounds "-fbounds-check") endif() if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel") set(dialect "-stand f08 -free -implicitnone") set(bounds "-check bounds") endif() set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/modules) set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} ${bounds}") set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect}") add_executable(testFortran testFortran.f) target_link_libraries(testFortran zFORp) add_test(NAME testFortran COMMAND testFortran) zfp-1.0.1/tests/fortran/testFortran.f000066400000000000000000000052201453723256400176210ustar00rootroot00000000000000program main use zfp use iso_c_binding ! loop counters integer i, j ! input/decompressed arrays integer xLen, yLen integer, dimension(:, :), allocatable, target :: input_array integer, dimension(:, :), allocatable, target :: decompressed_array type(c_ptr) :: array_c_ptr integer error, max_abs_error ! zfp_field type(zFORp_field) :: field ! bitstream character, dimension(:), allocatable, target :: buffer type(c_ptr) :: buffer_c_ptr integer (kind=8) buffer_size_bytes, bitstream_offset_bytes type(zFORp_bitstream) :: bitstream, queried_bitstream ! zfp_stream type(zFORp_stream) :: stream real (kind=8) :: desired_rate, rate_result integer :: dims, wra integer :: zfp_type ! initialize input and decompressed arrays xLen = 8 yLen = 8 allocate(input_array(xLen, yLen)) do i = 1, xLen do j = 1, yLen input_array(i, j) = i * i + j * (j + 1) enddo enddo allocate(decompressed_array(xLen, yLen)) ! setup zfp_field array_c_ptr = c_loc(input_array) zfp_type = zFORp_type_int32 field = zFORp_field_2d(array_c_ptr, zfp_type, xLen, yLen) ! setup bitstream buffer_size_bytes = 256 allocate(buffer(buffer_size_bytes)) buffer_c_ptr = c_loc(buffer) bitstream = zFORp_bitstream_stream_open(buffer_c_ptr, buffer_size_bytes) ! setup zfp_stream stream = zFORp_stream_open(bitstream) desired_rate = 8.0 dims = 2 wra = 0 zfp_type = zFORp_type_float rate_result = zFORp_stream_set_rate(stream, desired_rate, zfp_type, dims, wra) queried_bitstream = zFORp_stream_bit_stream(stream) ! compress bitstream_offset_bytes = zFORp_compress(stream, field) write(*, *) "After compression, bitstream offset at " write(*, *) bitstream_offset_bytes ! decompress call zFORp_stream_rewind(stream) array_c_ptr = c_loc(decompressed_array) call zFORp_field_set_pointer(field, array_c_ptr) bitstream_offset_bytes = zFORp_decompress(stream, field) write(*, *) "After decompression, bitstream offset at " write(*, *) bitstream_offset_bytes max_abs_error = 0 do i = 1, xLen do j = 1, yLen error = abs(decompressed_array(i, j) - input_array(i, j)) max_abs_error = max(error, max_abs_error) enddo enddo write(*, *) "Max absolute error: " write(*, *) max_abs_error write(*, *) "Absolute errors: " write(*, *) abs(input_array - decompressed_array) ! zfp library info write(*, *) zFORp_version_string write(*, *) zFORp_meta_null ! deallocations call zFORp_stream_close(stream) call zFORp_bitstream_stream_close(queried_bitstream) call zFORp_field_free(field) deallocate(buffer) deallocate(input_array) deallocate(decompressed_array) end program main zfp-1.0.1/tests/gitlab/000077500000000000000000000000001453723256400147275ustar00rootroot00000000000000zfp-1.0.1/tests/gitlab/corona-jobs.yml000066400000000000000000000005501453723256400176660ustar00rootroot00000000000000########### # HIP GPU # ########### rocm-3.10.0_build: variables: ci_cmake: "cmake/3.21.1" ci_cmp_mod: "rocm/3.10.0" ci_cmp_path: "/opt/rocm-3.10.0/hip" extends: [.hip, .corona_build_gpu] needs: [] rocm-3.10.0_test: variables: ci_test_regex: "Hip" extends: [.corona_test_gpu] needs: [rocm-3.10.0_build] zfp-1.0.1/tests/gitlab/corona-templates.yml000066400000000000000000000003251453723256400207270ustar00rootroot00000000000000.corona_job: tags: - batch - corona .corona_build_gpu: extends: [.build_gpu, .corona_job] .corona_test_gpu: variables: ci_test_regex: "." extends: [.test_gpu, .corona_job] zfp-1.0.1/tests/gitlab/gitlab-ci.yml000066400000000000000000000074121453723256400173110ustar00rootroot00000000000000##################### # Global Parameters # ##################### variables: GIT_SUBMODULE_STRATEGY: recursive LLNL_SLURM_SCHEDULER_PARAMETERS: "--nodes=1 -A asccasc -t 00:20:00" LLNL_SERVICE_USER: zfp stages: - build - test #################### # Global Templates # #################### # Build Stage Templates .build: stage: build artifacts: when: always paths: - build .build_cpu: before_script: - |- if [ "$ci_c_cmp" != "gcc" ]; then module --latest load gcc if (( $(gcc -dumpversion | sed 's/\..*//') < 5 )); then echo "unable to find new enough gcc to support ${ci_c_cmp} build" exit 1 fi export GXX_PATH=$(dirname $(which gcc))/../ fi - module reset - module load $ci_cmake - module load $ci_cmp_mod - |- if [ "$ci_lang" == "cpp" ]; then export CXX=$(which $ci_cxx_cmp) export CC=$(which $ci_c_cmp) if [ -z ${CXX} ]; then echo "cxx compiler not set" exit 1 elif [ -z ${CC} ]; then echo "c compiler not set" exit 1 fi elif [ "$ci_lang" == "c" ]; then export CC=$(which $ci_c_cmp) if [ -z ${CC} ]; then echo "c compiler not set" exit 1 fi fi script: - mkdir build - cd build - |- export ci_cmake_cmp_flags="" if [ "$ci_c_cmp" == "icc" ]; then export ci_cmake_cmp_flags="-DCMAKE_CXX_FLAGS=-gcc-name=${GXX_PATH}/bin/gcc -DCMAKE_C_FLAGS=-gcc-name=${GXX_PATH}/bin/gcc" elif [ "$ci_c_cmp" == "clang" ]; then export ci_cmake_cmp_flags="-DCMAKE_CXX_FLAGS=--gcc-toolchain=${GXX_PATH} -DCMAKE_C_FLAGS=--gcc-toolchain=${GXX_PATH}" fi - cmake -DBUILD_TESTING_FULL=ON -DBUILD_UTILITIES=OFF -DZFP_WITH_CUDA=OFF ${ci_cmake_flags} ${ci_cmake_cmp_flags} .. - cmake --build . extends: [.build] .build_gpu: before_script: - module reset - module load $ci_cmake - module load $ci_cmp_mod - module load $ci_gcc_mod script: - mkdir build - cd build - cmake -DBUILD_TESTING_FULL=ON -DZFP_WITH_OPENMP=OFF -DBUILD_UTILITIES=OFF ${ci_cmake_flags} .. - make -j extends: [.build] # Test Stage Templates .test: stage: test artifacts: when: on_failure paths: - build/Testing .test_cpu: script: - cd build - ctest -E "(Cuda|Hip)" -R "${ci_test_regex}" extends: [.test] .test_gpu: script: - cd build - ctest -R "${ci_test_regex}" extends: [.test] # Language Templates .cpp: variables: ci_lang: "cpp" ci_cmake_flags: "-DBUILD_CFP=OFF -DBUILD_ZFPY=OFF -DBUILD_ZFORP=OFF" .c: variables: ci_lang: "c" ci_cmake_flags: "-DBUILD_CFP=ON -DBUILD_ZFPY=OFF -DBUILD_ZFORP=OFF -DZFP_WITH_OPENMP=OFF" .cuda: variables: ci_lang: "cuda" ci_cmake_flags: "-DZFP_WITH_CUDA=ON" #.hip: # variables: # ci_lang: "hip" # ci_cmake_flags: "-DZFP_WITH_HIP=ON -DHIP_PATH=${ci_cmp_path} -DCMAKE_CXX_STANDARD=11 -DCMAKE_C_STANDARD=11 -DCMAKE_C_COMPILER=hipcc -DCMAKE_CXX_COMPILER=hipcc" ############ # Includes # ############ include: - local: tests/gitlab/pascal-templates.yml - local: tests/gitlab/pascal-jobs.yml - local: tests/gitlab/quartz-templates.yml - local: tests/gitlab/quartz-jobs.yml # - local: tests/gitlab/corona-templates.yml # - local: tests/gitlab/corona-jobs.yml zfp-1.0.1/tests/gitlab/pascal-jobs.yml000066400000000000000000000005421453723256400176510ustar00rootroot00000000000000############ # CUDA GPU # ############ cuda-11.8.0_build: variables: ci_cmake: "cmake/3.14.5" ci_cmp_mod: "cuda/11.8.0" ci_gcc_mod: "gcc/10.3.1" extends: [.cuda, .pascal_build_gpu] needs: [] cuda-11.8.0_test: variables: ci_test_regex: "Cuda" extends: [.pascal_test_gpu] needs: [cuda-11.8.0_build] zfp-1.0.1/tests/gitlab/pascal-templates.yml000066400000000000000000000003251453723256400207110ustar00rootroot00000000000000.pascal_job: tags: - batch - pascal .pascal_build_gpu: extends: [.build_gpu, .pascal_job] .pascal_test_gpu: variables: ci_test_regex: "." extends: [.test_gpu, .pascal_job] zfp-1.0.1/tests/gitlab/quartz-jobs.yml000066400000000000000000000024131453723256400177330ustar00rootroot00000000000000########### # CXX CPU # ########### cpp_gnu-10.3.1_build: variables: ci_cmake: "cmake/3.14.5" ci_cxx_cmp: "g++" ci_c_cmp: "gcc" ci_cmp_mod: "gcc/10.3.1" extends: [.cpp, .quartz_build_cpu] needs: [] cpp_gnu-10.3.1_test: extends: [.quartz_test_cpu] needs: [cpp_gnu-10.3.1_build] cpp_clang-14.0.6_build: variables: ci_cmake: "cmake/3.14.5" ci_cxx_cmp: "clang++" ci_c_cmp: "clang" ci_cmp_mod: "clang/14.0.6" extends: [.cpp, .quartz_build_cpu] needs: [] cpp_clang-14.0.6_test: extends: [.quartz_test_cpu] needs: [cpp_clang-14.0.6_build] cpp_intel-2022.1.0_build: variables: ci_cmake: "cmake/3.14.5" ci_cxx_cmp: "icpc" ci_c_cmp: "icc" ci_cmp_mod: "intel/2022.1.0" extends: [.cpp, .quartz_build_cpu] needs: [] cpp_intel-2022.1.0_test: extends: [.quartz_test_cpu] needs: [cpp_intel-2022.1.0_build] ######### # C CPU # ######### c_gnu-10.3.1_build: variables: ci_cmake: "cmake/3.14.5" ci_c_cmp: "gcc" ci_cmp_mod: "gcc/10.3.1" extends: [.c, .quartz_build_cpu] needs: [] c_gnu-10.3.1_test: variables: ci_test_regex: "Cfp" extends: [.quartz_test_cpu] needs: [c_gnu-10.3.1_build] zfp-1.0.1/tests/gitlab/quartz-templates.yml000066400000000000000000000003251453723256400207740ustar00rootroot00000000000000.quartz_job: tags: - batch - quartz .quartz_build_cpu: extends: [.build_cpu, .quartz_job] .quartz_test_cpu: variables: ci_test_regex: "." extends: [.test_cpu, .quartz_job] zfp-1.0.1/tests/python/000077500000000000000000000000001453723256400150065ustar00rootroot00000000000000zfp-1.0.1/tests/python/CMakeLists.txt000066400000000000000000000026141453723256400175510ustar00rootroot00000000000000if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27.0) cmake_policy(SET CMP0148 OLD) endif () set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/python/scikit-build-cmake) find_package(PythonInterp REQUIRED) find_package(PythonLibs REQUIRED) find_package(PythonExtensions REQUIRED) find_package(Cython REQUIRED) find_package(NumPy REQUIRED) include_directories(${ZFP_SOURCE_DIR}/include) include_directories(${ZFP_SOURCE_DIR}/python) include_directories(${NumPy_INCLUDE_DIR}) include_directories(${ZFP_SOURCE_DIR}/tests/python) include_directories(${ZFP_SOURCE_DIR}/tests/utils) include_directories(${ZFP_SOURCE_DIR}) add_cython_target(test_utils test_utils.pyx C PY3) add_library(test_utils MODULE ${test_utils}) target_link_libraries(test_utils zfp genSmoothRandNumsLib stridedOperationsLib zfpCompressionParamsLib zfpChecksumsLib zfpHashLib) python_extension_module(test_utils) set_target_properties(test_utils PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PYLIB_BUILD_DIR}) set(TEST_PYTHON_PATH "${PYLIB_BUILD_DIR}") if(MSVC) set(TEST_PYTHON_PATH "${TEST_PYTHON_PATH}/${CMAKE_BUILD_TYPE}") endif() if(DEFINED ENV{PYTHONPATH}) set(TEST_PYTHON_PATH "${TEST_PYTHON_PATH}:$ENV{PYTHONPATH}") endif() add_test(NAME test_numpy COMMAND ${PYTHON_EXECUTABLE} test_numpy.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) set_tests_properties(test_numpy PROPERTIES ENVIRONMENT PYTHONPATH=${TEST_PYTHON_PATH}) zfp-1.0.1/tests/python/test_numpy.py000066400000000000000000000232141453723256400175710ustar00rootroot00000000000000#!/usr/bin/env python import unittest import zfpy import test_utils import numpy as np try: from packaging.version import parse as version_parse except ImportError: version_parse = None class TestNumpy(unittest.TestCase): def lossless_round_trip(self, orig_array): compressed_array = zfpy.compress_numpy(orig_array, write_header=True) decompressed_array = zfpy.decompress_numpy(compressed_array) self.assertIsNone(np.testing.assert_array_equal(decompressed_array, orig_array)) def test_different_dimensions(self): for dimensions in range(1, 5): shape = [5] * dimensions c_array = np.random.rand(*shape) self.lossless_round_trip(c_array) shape = range(2, 2 + dimensions) c_array = np.random.rand(*shape) self.lossless_round_trip(c_array) def test_different_dtypes(self): shape = (5, 5) num_elements = shape[0] * shape[1] for dtype in [np.float32, np.float64]: elements = np.random.random_sample(num_elements) elements = elements.astype(dtype, casting="same_kind") array = np.reshape(elements, newshape=shape) self.lossless_round_trip(array) if (version_parse is not None and (version_parse(np.__version__) >= version_parse("1.11.0")) ): for dtype in [np.int32, np.int64]: array = np.random.randint(2**30, size=shape, dtype=dtype) self.lossless_round_trip(array) else: array = np.random.randint(2**30, size=shape) self.lossless_round_trip(array) def test_advanced_decompression_checksum(self): ndims = 2 ztype = zfpy.type_float random_array = test_utils.getRandNumpyArray(ndims, ztype) mode = zfpy.mode_fixed_accuracy compress_param_num = 1 compression_kwargs = { "tolerance": test_utils.computeParameterValue( mode, compress_param_num ), } compressed_array = zfpy.compress_numpy( random_array, write_header=False, **compression_kwargs ) # Decompression using the "advanced" interface which enforces no header, # and the user must provide all the metadata decompressed_array = np.empty_like(random_array) zfpy._decompress( compressed_array, ztype, random_array.shape, out=decompressed_array, **compression_kwargs ) decompressed_array_dims = decompressed_array.shape + tuple(0 for i in range(4 - decompressed_array.ndim)) decompressed_checksum = test_utils.getChecksumDecompArray( decompressed_array_dims, ztype, mode, compress_param_num ) actual_checksum = test_utils.hashNumpyArray( decompressed_array ) self.assertEqual(decompressed_checksum, actual_checksum) def test_memview_advanced_decompression_checksum(self): ndims = 2 ztype = zfpy.type_float random_array = test_utils.getRandNumpyArray(ndims, ztype) mode = zfpy.mode_fixed_accuracy compress_param_num = 1 compression_kwargs = { "tolerance": test_utils.computeParameterValue( mode, compress_param_num ), } compressed_array_tmp = zfpy.compress_numpy( random_array, write_header=False, **compression_kwargs ) mem = memoryview(compressed_array_tmp) compressed_array = np.array(mem, copy=False) # Decompression using the "advanced" interface which enforces no header, # and the user must provide all the metadata decompressed_array = np.empty_like(random_array) zfpy._decompress( compressed_array, ztype, random_array.shape, out=decompressed_array, **compression_kwargs ) decompressed_array_dims = decompressed_array.shape + tuple(0 for i in range(4 - decompressed_array.ndim)) decompressed_checksum = test_utils.getChecksumDecompArray( decompressed_array_dims, ztype, mode, compress_param_num ) actual_checksum = test_utils.hashNumpyArray( decompressed_array ) self.assertEqual(decompressed_checksum, actual_checksum) def test_advanced_decompression_nonsquare(self): for dimensions in range(1, 5): shape = range(2, 2 + dimensions) random_array = np.random.rand(*shape) decompressed_array = np.empty_like(random_array) compressed_array = zfpy.compress_numpy( random_array, write_header=False, ) zfpy._decompress( compressed_array, zfpy.dtype_to_ztype(random_array.dtype), random_array.shape, out= decompressed_array, ) self.assertIsNone(np.testing.assert_array_equal(decompressed_array, random_array)) def test_utils(self): for ndims in range(1, 5): for ztype, ztype_str in [ (zfpy.type_float, "float"), (zfpy.type_double, "double"), (zfpy.type_int32, "int32"), (zfpy.type_int64, "int64"), ]: orig_random_array = test_utils.getRandNumpyArray(ndims, ztype) orig_random_array_dims = orig_random_array.shape + tuple(0 for i in range(4 - orig_random_array.ndim)) orig_checksum = test_utils.getChecksumOrigArray(orig_random_array_dims, ztype) actual_checksum = test_utils.hashNumpyArray(orig_random_array) self.assertEqual(orig_checksum, actual_checksum) for stride_str, stride_config in [ ("as_is", test_utils.stride_as_is), ("permuted", test_utils.stride_permuted), ("interleaved", test_utils.stride_interleaved), #("reversed", test_utils.stride_reversed), ]: # permuting a 1D array is not supported if stride_config == test_utils.stride_permuted and ndims == 1: continue random_array = test_utils.generateStridedRandomNumpyArray( stride_config, orig_random_array ) random_array_dims = random_array.shape + tuple(0 for i in range(4 - random_array.ndim)) self.assertTrue(np.equal(orig_random_array, random_array).all()) for compress_param_num in range(3): modes = [(zfpy.mode_fixed_accuracy, "tolerance"), (zfpy.mode_fixed_precision, "precision"), (zfpy.mode_fixed_rate, "rate")] if ztype in [zfpy.type_int32, zfpy.type_int64]: modes = [modes[-1]] # only fixed-rate is supported for integers for mode, mode_str in modes: # Compression compression_kwargs = { mode_str: test_utils.computeParameterValue( mode, compress_param_num ), } compressed_array = zfpy.compress_numpy( random_array, write_header=False, **compression_kwargs ) compressed_checksum = test_utils.getChecksumCompArray( random_array_dims, ztype, mode, compress_param_num ) actual_checksum = test_utils.hashCompressedArray( compressed_array ) self.assertEqual(compressed_checksum, actual_checksum) # Decompression decompressed_checksum = test_utils.getChecksumDecompArray( random_array_dims, ztype, mode, compress_param_num ) # Decompression using the "public" interface # requires a header, so re-compress with the header # included in the stream compressed_array_tmp = zfpy.compress_numpy( random_array, write_header=True, **compression_kwargs ) mem = memoryview(compressed_array_tmp) compressed_array = np.array(mem, copy=False) decompressed_array = zfpy.decompress_numpy( compressed_array, ) actual_checksum = test_utils.hashNumpyArray( decompressed_array ) self.assertEqual(decompressed_checksum, actual_checksum) if __name__ == "__main__": unittest.main(verbosity=2) zfp-1.0.1/tests/python/test_utils.pyx000066400000000000000000000417151453723256400177570ustar00rootroot00000000000000# TODO: update zfpChecksums cython import cython from libc.stdlib cimport malloc, free cimport libc.stdint as stdint from libc.stddef cimport ptrdiff_t from cython cimport view from itertools import islice, repeat, chain import zfpy cimport zfpy import numpy as np cimport numpy as np ctypedef stdint.int32_t int32_t ctypedef stdint.int64_t int64_t ctypedef stdint.uint32_t uint32_t ctypedef stdint.uint64_t uint64_t cdef extern from "genSmoothRandNums.h": size_t intPow(size_t base, int exponent) void generateSmoothRandInts64(size_t minTotalElements, int numDims, int amplitudeExp, int64_t** outputArr, size_t* outputSideLen, size_t* outputTotalLen) void generateSmoothRandInts32(size_t minTotalElements, int numDims, int amplitudeExp, int32_t** outputArr32Ptr, size_t* outputSideLen, size_t* outputTotalLen) void generateSmoothRandFloats(size_t minTotalElements, int numDims, float** outputArrPtr, size_t* outputSideLen, size_t* outputTotalLen) void generateSmoothRandDoubles(size_t minTotalElements, int numDims, double** outputArrPtr, size_t* outputSideLen, size_t* outputTotalLen) cdef extern from "stridedOperations.h": ctypedef enum stride_config: AS_IS = 0, PERMUTED = 1, INTERLEAVED = 2, REVERSED = 3 void reverseArray(void* inputArr, void* outputArr, size_t inputArrLen, zfpy.zfp_type zfpType) void interleaveArray(void* inputArr, void* outputArr, size_t inputArrLen, zfpy.zfp_type zfpType) int permuteSquareArray(void* inputArr, void* outputArr, size_t sideLen, int dims, zfpy.zfp_type zfpType) void getReversedStrides(int dims, size_t n[4], ptrdiff_t s[4]) void getInterleavedStrides(int dims, size_t n[4], ptrdiff_t s[4]) void getPermutedStrides(int dims, size_t n[4], ptrdiff_t s[4]) cdef extern from "zfpCompressionParams.h": int computeFixedPrecisionParam(int param) size_t computeFixedRateParam(int param) double computeFixedAccuracyParam(int param) cdef extern from "zfp.h": ctypedef enum zfp_type: zfp_type_none = 0, zfp_type_int32 = 1, zfp_type_int64 = 2, zfp_type_float = 3, zfp_type_double = 4 cdef extern from "zfpChecksums.h": ctypedef enum test_type: BLOCK_FULL_TEST = 0, BLOCK_PARTIAL_TEST = 1, ARRAY_TEST = 2 ctypedef enum subject: ORIGINAL_INPUT = 0, COMPRESSED_BITSTREAM = 1, DECOMPRESSED_ARRAY = 2, void computeKeyOriginalInput(test_type tt, size_t n[4], uint64_t* key1, uint64_t* key2) void computeKey(test_type tt, subject sjt, size_t n[4], zfpy.zfp_mode mode, int miscParam, uint64_t* key1, uint64_t* key2) uint64_t getChecksumByKey(int dims, zfp_type type, uint64_t key1, uint64_t key2) cdef extern from "zfpHash.h": uint64_t hashBitstream(uint64_t* ptrStart, size_t bufsizeBytes) uint32_t hashArray32(const uint32_t* arr, size_t nx, ptrdiff_t sx) uint32_t hashStridedArray32(const uint32_t* arr, size_t n[4], ptrdiff_t s[4]) uint64_t hashArray64(const uint64_t* arr, size_t nx, ptrdiff_t sx) uint64_t hashStridedArray64(const uint64_t* arr, size_t n[4], ptrdiff_t s[4]) # enums stride_as_is = AS_IS stride_permuted = PERMUTED stride_interleaved = INTERLEAVED stride_reversed = REVERSED # functions cdef validate_num_dimensions(int dims): if dims > 4 or dims < 1: raise ValueError("Unsupported number of dimensions: {}".format(dims)) cdef validate_ztype(zfpy.zfp_type ztype): if ztype not in [ zfpy.type_float, zfpy.type_double, zfpy.type_int32, zfpy.type_int64 ]: raise ValueError("Unsupported ztype: {}".format(ztype)) cdef validate_mode(zfpy.zfp_mode mode): if mode not in [ zfpy.mode_fixed_rate, zfpy.mode_fixed_precision, zfpy.mode_fixed_accuracy, ]: raise ValueError("Unsupported mode: {}".format(mode)) cdef validate_compress_param(int comp_param): if comp_param not in range(3): # i.e., [0, 1, 2] raise ValueError( "Unsupported compression parameter number: {}".format(comp_param) ) cpdef getRandNumpyArray( int numDims, zfpy.zfp_type ztype, ): validate_num_dimensions(numDims) validate_ztype(ztype) cdef size_t minTotalElements = 0 cdef int amplitudeExp = 0 if ztype in [zfpy.type_float, zfpy.type_double]: minTotalElements = 1000000 elif ztype in [zfpy.type_int32, zfpy.type_int64]: minTotalElements = 4096 cdef int64_t* outputArrInt64 = NULL cdef int32_t* outputArrInt32 = NULL cdef float* outputArrFloat = NULL cdef double* outputArrDouble = NULL cdef size_t outputSideLen = 0 cdef size_t outputTotalLen = 0 cdef view.array viewArr = None if ztype == zfpy.type_int64: amplitudeExp = 64 - 2 generateSmoothRandInts64(minTotalElements, numDims, amplitudeExp, &outputArrInt64, &outputSideLen, &outputTotalLen) if numDims == 1: viewArr = outputArrInt64 elif numDims == 2: viewArr = outputArrInt64 elif numDims == 3: viewArr = outputArrInt64 elif numDims == 4: viewArr = outputArrInt64 elif ztype == zfpy.type_int32: amplitudeExp = 32 - 2 generateSmoothRandInts32(minTotalElements, numDims, amplitudeExp, &outputArrInt32, &outputSideLen, &outputTotalLen) if numDims == 1: viewArr = outputArrInt32 elif numDims == 2: viewArr = outputArrInt32 elif numDims == 3: viewArr = outputArrInt32 elif numDims == 4: viewArr = outputArrInt32 elif ztype == zfpy.type_float: generateSmoothRandFloats(minTotalElements, numDims, &outputArrFloat, &outputSideLen, &outputTotalLen) if numDims == 1: viewArr = outputArrFloat elif numDims == 2: viewArr = outputArrFloat elif numDims == 3: viewArr = outputArrFloat elif numDims == 4: viewArr = outputArrFloat elif ztype == zfpy.type_double: generateSmoothRandDoubles(minTotalElements, numDims, &outputArrDouble, &outputSideLen, &outputTotalLen) if numDims == 1: viewArr = outputArrDouble elif numDims == 2: viewArr = outputArrDouble elif numDims == 3: viewArr = outputArrDouble elif numDims == 4: viewArr = outputArrDouble else: raise ValueError("Unknown zfp_type: {}".format(ztype)) return np.asarray(viewArr) # ====================================================== # TODO: examine best way to add python block level support cdef uint64_t getChecksumOriginalDataBlock( int dims, zfpy.zfp_type ztype ): return 0 cdef uint64_t getChecksumEncodedBlock( int dims, zfpy.zfp_type ztype ): return 0 cdef uint64_t getChecksumEncodedPartialBlock( int dims, zfpy.zfp_type ztype ): return 0 cdef uint64_t getChecksumDecodedBlock( int dims, zfpy.zfp_type ztype ): return 0 cdef uint64_t getChecksumDecodedPartialBlock( int dims, zfpy.zfp_type ztype ): return 0 # ====================================================== cdef uint64_t getChecksumOriginalDataArray( int ndims, size_t[4] dims, zfpy.zfp_type ztype ): cdef uint64_t[1] key1, key2 computeKeyOriginalInput(ARRAY_TEST, dims, key1, key2) return getChecksumByKey(ndims, ztype, key1[0], key2[0]) cdef uint64_t getChecksumCompressedBitstream( int ndims, size_t[4] dims, zfpy.zfp_type ztype, zfpy.zfp_mode mode, int compressParamNum ): cdef uint64_t[1] key1, key2 computeKey(ARRAY_TEST, COMPRESSED_BITSTREAM, dims, mode, compressParamNum, key1, key2) return getChecksumByKey(ndims, ztype, key1[0], key2[0]) cdef uint64_t getChecksumDecompressedArray( int ndims, size_t[4] dims, zfpy.zfp_type ztype, zfpy.zfp_mode mode, int compressParamNum ): cdef uint64_t[1] key1, key2 computeKey(ARRAY_TEST, DECOMPRESSED_ARRAY, dims, mode, compressParamNum, key1, key2) return getChecksumByKey(ndims, ztype, key1[0], key2[0]) cpdef uint64_t getChecksumOrigArray( dims, zfpy.zfp_type ztype ): cdef int ndims = 4-dims.count(0) validate_num_dimensions(ndims) validate_ztype(ztype) cdef size_t[4] d for i in range(len(dims)): d[i] = dims[i] return getChecksumOriginalDataArray(ndims, d, ztype) cpdef uint64_t getChecksumCompArray( dims, zfpy.zfp_type ztype, zfpy.zfp_mode mode, int compressParamNum ): cdef int ndims = 4-dims.count(0) validate_num_dimensions(ndims) validate_ztype(ztype) validate_mode(mode) validate_compress_param(compressParamNum) cdef size_t[4] d for i in range(len(dims)): d[i] = dims[i] return getChecksumCompressedBitstream(ndims, d, ztype, mode, compressParamNum) cpdef uint64_t getChecksumDecompArray( dims, zfpy.zfp_type ztype, zfpy.zfp_mode mode, int compressParamNum ): cdef int ndims = 4-dims.count(0) validate_num_dimensions(ndims) validate_ztype(ztype) validate_mode(mode) validate_compress_param(compressParamNum) cdef size_t[4] d for i in range(len(dims)): d[i] = dims[i] return getChecksumDecompressedArray(ndims, d, ztype, mode, compressParamNum) cpdef computeParameterValue(zfpy.zfp_mode mode, int param): validate_mode(mode) validate_compress_param(param) if mode == zfpy.mode_fixed_accuracy: return computeFixedAccuracyParam(param) elif mode == zfpy.mode_fixed_precision: return computeFixedPrecisionParam(param) elif mode == zfpy.mode_fixed_rate: return computeFixedRateParam(param) cpdef hashStridedArray( bytes inarray, zfpy.zfp_type ztype, shape, strides, ): cdef char* array = inarray cdef size_t[4] padded_shape for i in range(4): padded_shape[i] = zfpy.gen_padded_int_list(shape)[i] cdef ptrdiff_t[4] padded_strides for i in range(4): padded_strides[i] = zfpy.gen_padded_int_list(strides)[i] if ztype == zfpy.type_int32 or ztype == zfpy.type_float: return hashStridedArray32(array, padded_shape, padded_strides) elif ztype == zfpy.type_int64 or ztype == zfpy.type_double: return hashStridedArray64(array, padded_shape, padded_strides) cpdef hashNumpyArray( np.ndarray nparray, stride_config stride_conf = AS_IS, ): dtype = nparray.dtype if dtype not in [np.int32, np.float32, np.int64, np.float64]: raise ValueError("Unsupported numpy type: {}".format(dtype)) if stride_conf not in [AS_IS, PERMUTED, INTERLEAVED, REVERSED]: raise ValueError("Unsupported stride config: {}".format(stride_conf)) size = int(nparray.size) cdef ptrdiff_t[4] strides cdef size_t[4] shape if stride_conf in [AS_IS, INTERLEAVED]: stride_width = 1 if stride_conf is AS_IS else 2 if dtype == np.int32 or dtype == np.float32: return hashArray32(nparray.data, size, stride_width) elif dtype == np.int64 or dtype == np.float64: return hashArray64(nparray.data, size, stride_width) elif stride_conf in [REVERSED, PERMUTED]: for i in range(4): strides[i] = zfpy.gen_padded_int_list( [x for x in nparray.strides[:nparray.ndim]][i] ) for i in range(4): shape[i] = zfpy.gen_padded_int_list( [x for x in nparray.shape[:nparray.ndim]][i] ) if dtype == np.int32 or dtype == np.float32: return hashStridedArray32(nparray.data, shape, strides) elif dtype == np.int64 or dtype == np.float64: return hashStridedArray64(nparray.data, shape, strides) cpdef hashCompressedArray( bytes array, ): cdef const char* c_array = array return hashBitstream( c_array, len(array)) cpdef generateStridedRandomNumpyArray( stride_config stride, np.ndarray randomArray, ): cdef int ndim = randomArray.ndim shape = [int(x) for x in randomArray.shape[:ndim]] dtype = randomArray.dtype cdef zfpy.zfp_type ztype = zfpy.dtype_to_ztype(dtype) cdef ptrdiff_t[4] strides for i in range(4): strides[i] = 0 cdef size_t[4] dims for i in range(4): dims[i] = zfpy.gen_padded_int_list(shape)[i] cdef size_t inputLen = len(randomArray) cdef void* output_array_ptr = NULL cdef np.ndarray output_array = None cdef view.array output_array_view = None if stride == AS_IS: # return an unmodified copy return randomArray.copy(order='K') elif stride == PERMUTED: if ndim == 1: raise ValueError("Permutation not supported on 1D arrays") output_array = np.empty_like(randomArray, order='K') getPermutedStrides(ndim, dims, strides) for i in range(4): strides[i] = int(strides[i]) * (randomArray.itemsize) ret = permuteSquareArray( randomArray.data, output_array.data, dims[0], ndim, ztype ) if ret != 0: raise RuntimeError("Error permuting square array") return np.lib.stride_tricks.as_strided( output_array, shape=[x for x in dims[:ndim]], strides=reversed([x for x in strides[:ndim]]), ) elif stride == INTERLEAVED: num_elements = np.prod(shape) new_shape = [x for x in dims if x > 0] new_shape[-1] *= 2 for i in range(4): dims[i] = zfpy.gen_padded_int_list(new_shape, pad=0, length=4)[i] output_array = np.empty( new_shape, dtype=dtype ) interleaveArray( randomArray.data, output_array.data, num_elements, ztype ) getInterleavedStrides(ndim, dims, strides) for i in range(4): strides[i] = int(strides[i]) * (randomArray.itemsize) return np.lib.stride_tricks.as_strided( output_array, shape=shape, strides=reversed([x for x in strides[:ndim]]), ) else: raise ValueError("Unsupported_config: {|}".format(stride)) zfp-1.0.1/tests/src/000077500000000000000000000000001453723256400142545ustar00rootroot00000000000000zfp-1.0.1/tests/src/CMakeLists.txt000066400000000000000000000003361453723256400170160ustar00rootroot00000000000000# compile tests if(NOT DEFINED ZFP_OMP_TESTS_ONLY) add_subdirectory(inline) add_subdirectory(misc) add_subdirectory(encode) add_subdirectory(decode) endif() add_subdirectory(endtoend) add_subdirectory(execPolicy) zfp-1.0.1/tests/src/decode/000077500000000000000000000000001453723256400154775ustar00rootroot00000000000000zfp-1.0.1/tests/src/decode/CMakeLists.txt000066400000000000000000000033171453723256400202430ustar00rootroot00000000000000function(zfp_add_block_tests dims type bits) set(block_test_name testZfpDecodeBlock${dims}d${type}) add_executable(${block_test_name} ${block_test_name}.c) target_link_libraries(${block_test_name} cmocka zfp rand${bits}Lib zfpHashLib zfpChecksumsLib) if(HAVE_LIBM_MATH) target_link_libraries(${block_test_name} m) endif() target_compile_definitions(${block_test_name} PRIVATE ${zfp_private_defs}) if(PRINT_CHECKSUMS) target_compile_definitions(${block_test_name} PUBLIC PRINT_CHECKSUMS) endif() add_test(NAME ${block_test_name} COMMAND ${block_test_name}) set(strided_block_test_name testZfpDecodeBlockStrided${dims}d${type}) add_executable(${strided_block_test_name} ${strided_block_test_name}.c) target_link_libraries(${strided_block_test_name} cmocka zfp rand${bits}Lib zfpHashLib zfpChecksumsLib) if(HAVE_LIBM_MATH) target_link_libraries(${strided_block_test_name} m) endif() target_compile_definitions(${strided_block_test_name} PRIVATE ${zfp_private_defs}) if(PRINT_CHECKSUMS) target_compile_definitions(${strided_block_test_name} PUBLIC PRINT_CHECKSUMS) endif() add_test(NAME ${strided_block_test_name} COMMAND ${strided_block_test_name}) endfunction() zfp_add_block_tests(1 Int32 32) zfp_add_block_tests(1 Int64 64) zfp_add_block_tests(2 Int32 32) zfp_add_block_tests(2 Int64 64) zfp_add_block_tests(3 Int32 32) zfp_add_block_tests(3 Int64 64) zfp_add_block_tests(4 Int32 32) zfp_add_block_tests(4 Int64 64) zfp_add_block_tests(1 Float 32) zfp_add_block_tests(1 Double 64) zfp_add_block_tests(2 Float 32) zfp_add_block_tests(2 Double 64) zfp_add_block_tests(3 Float 32) zfp_add_block_tests(3 Double 64) zfp_add_block_tests(4 Float 32) zfp_add_block_tests(4 Double 64) zfp-1.0.1/tests/src/decode/testZfpDecodeBlock1dDouble.c000066400000000000000000000004051453723256400227400ustar00rootroot00000000000000#include "src/decode1d.c" #include "constants/1dDouble.h" #include "utils/rand64.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlock1dFloat.c000066400000000000000000000004041453723256400225720ustar00rootroot00000000000000#include "src/decode1f.c" #include "constants/1dFloat.h" #include "utils/rand32.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlock1dInt32.c000066400000000000000000000004041453723256400224240ustar00rootroot00000000000000#include "src/decode1i.c" #include "constants/1dInt32.h" #include "utils/rand32.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlock1dInt64.c000066400000000000000000000004041453723256400224310ustar00rootroot00000000000000#include "src/decode1l.c" #include "constants/1dInt64.h" #include "utils/rand64.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlock2dDouble.c000066400000000000000000000004051453723256400227410ustar00rootroot00000000000000#include "src/decode2d.c" #include "constants/2dDouble.h" #include "utils/rand64.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlock2dFloat.c000066400000000000000000000004041453723256400225730ustar00rootroot00000000000000#include "src/decode2f.c" #include "constants/2dFloat.h" #include "utils/rand32.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlock2dInt32.c000066400000000000000000000004041453723256400224250ustar00rootroot00000000000000#include "src/decode2i.c" #include "constants/2dInt32.h" #include "utils/rand32.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlock2dInt64.c000066400000000000000000000004041453723256400224320ustar00rootroot00000000000000#include "src/decode2l.c" #include "constants/2dInt64.h" #include "utils/rand64.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlock3dDouble.c000066400000000000000000000004051453723256400227420ustar00rootroot00000000000000#include "src/decode3d.c" #include "constants/3dDouble.h" #include "utils/rand64.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlock3dFloat.c000066400000000000000000000004041453723256400225740ustar00rootroot00000000000000#include "src/decode3f.c" #include "constants/3dFloat.h" #include "utils/rand32.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlock3dInt32.c000066400000000000000000000004041453723256400224260ustar00rootroot00000000000000#include "src/decode3i.c" #include "constants/3dInt32.h" #include "utils/rand32.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlock3dInt64.c000066400000000000000000000004041453723256400224330ustar00rootroot00000000000000#include "src/decode3l.c" #include "constants/3dInt64.h" #include "utils/rand64.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlock4dDouble.c000066400000000000000000000004051453723256400227430ustar00rootroot00000000000000#include "src/decode4d.c" #include "constants/4dDouble.h" #include "utils/rand64.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlock4dFloat.c000066400000000000000000000004041453723256400225750ustar00rootroot00000000000000#include "src/decode4f.c" #include "constants/4dFloat.h" #include "utils/rand32.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlock4dInt32.c000066400000000000000000000004041453723256400224270ustar00rootroot00000000000000#include "src/decode4i.c" #include "constants/4dInt32.h" #include "utils/rand32.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlock4dInt64.c000066400000000000000000000004041453723256400224340ustar00rootroot00000000000000#include "src/decode4l.c" #include "constants/4dInt64.h" #include "utils/rand64.h" #include "zfpDecodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided1dDouble.c000066400000000000000000000004231453723256400242570ustar00rootroot00000000000000#include "src/decode1d.c" #include "constants/1dDouble.h" #include "utils/rand64.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided1dFloat.c000066400000000000000000000004221453723256400241110ustar00rootroot00000000000000#include "src/decode1f.c" #include "constants/1dFloat.h" #include "utils/rand32.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided1dInt32.c000066400000000000000000000004221453723256400237430ustar00rootroot00000000000000#include "src/decode1i.c" #include "constants/1dInt32.h" #include "utils/rand32.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided1dInt64.c000066400000000000000000000004221453723256400237500ustar00rootroot00000000000000#include "src/decode1l.c" #include "constants/1dInt64.h" #include "utils/rand64.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided2dDouble.c000066400000000000000000000004231453723256400242600ustar00rootroot00000000000000#include "src/decode2d.c" #include "constants/2dDouble.h" #include "utils/rand64.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided2dFloat.c000066400000000000000000000004221453723256400241120ustar00rootroot00000000000000#include "src/decode2f.c" #include "constants/2dFloat.h" #include "utils/rand32.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided2dInt32.c000066400000000000000000000004221453723256400237440ustar00rootroot00000000000000#include "src/decode2i.c" #include "constants/2dInt32.h" #include "utils/rand32.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided2dInt64.c000066400000000000000000000004221453723256400237510ustar00rootroot00000000000000#include "src/decode2l.c" #include "constants/2dInt64.h" #include "utils/rand64.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided3dDouble.c000066400000000000000000000004231453723256400242610ustar00rootroot00000000000000#include "src/decode3d.c" #include "constants/3dDouble.h" #include "utils/rand64.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided3dFloat.c000066400000000000000000000004221453723256400241130ustar00rootroot00000000000000#include "src/decode3f.c" #include "constants/3dFloat.h" #include "utils/rand32.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided3dInt32.c000066400000000000000000000004221453723256400237450ustar00rootroot00000000000000#include "src/decode3i.c" #include "constants/3dInt32.h" #include "utils/rand32.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided3dInt64.c000066400000000000000000000004221453723256400237520ustar00rootroot00000000000000#include "src/decode3l.c" #include "constants/3dInt64.h" #include "utils/rand64.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided4dDouble.c000066400000000000000000000004231453723256400242620ustar00rootroot00000000000000#include "src/decode4d.c" #include "constants/4dDouble.h" #include "utils/rand64.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided4dFloat.c000066400000000000000000000004221453723256400241140ustar00rootroot00000000000000#include "src/decode4f.c" #include "constants/4dFloat.h" #include "utils/rand32.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided4dInt32.c000066400000000000000000000004221453723256400237460ustar00rootroot00000000000000#include "src/decode4i.c" #include "constants/4dInt32.h" #include "utils/rand32.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testZfpDecodeBlockStrided4dInt64.c000066400000000000000000000004221453723256400237530ustar00rootroot00000000000000#include "src/decode4l.c" #include "constants/4dInt64.h" #include "utils/rand64.h" #include "zfpDecodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/decode/testcases/000077500000000000000000000000001453723256400174755ustar00rootroot00000000000000zfp-1.0.1/tests/src/decode/testcases/block.c000066400000000000000000000013751453723256400207410ustar00rootroot00000000000000// requires #include "utils/testMacros.h", do outside of main() #ifndef PRINT_CHECKSUMS _cmocka_unit_test_setup_teardown(when_seededRandomDataGenerated_expect_ChecksumMatches, setup, teardown), #endif _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_DecodeBlock_expect_ReturnValReflectsNumBitsReadFromBitstream), setup, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_DecodeBlock_expect_ArrayChecksumMatches), setup, teardown), #ifdef FL_PT_DATA // reversible compression and decompression of blocks containing special floating-point values _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_DecodeSpecialBlocks_expect_ArraysMatchBitForBit), setupSpecial, teardown), #endif zfp-1.0.1/tests/src/decode/testcases/blockStrided.c000066400000000000000000000026211453723256400222530ustar00rootroot00000000000000// requires #include "utils/testMacros.h", do outside of main() // remove redundant checksum tests already run in non-strided tests #ifndef PRINT_CHECKSUMS _cmocka_unit_test_setup_teardown(when_seededRandomDataGenerated_expect_ChecksumMatches, setup, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_DecodeBlockStrided_expect_ReturnValReflectsNumBitsReadFromBitstream), setup, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_DecodeBlockStrided_expect_OnlyStridedEntriesChangedInDestinationArray), setup, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_DecodeBlockStrided_expect_ArrayChecksumMatches), setup, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_DecodePartialBlockStrided_expect_ReturnValReflectsNumBitsReadFromBitstream), setup, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_DecodePartialBlockStrided_expect_NonStridedEntriesUnchangedInDestinationArray), setup, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_DecodePartialBlockStrided_expect_EntriesOutsidePartialBlockBoundsUnchangedInDestinationArray), setup, teardown), #endif _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_DecodePartialBlockStrided_expect_ArrayChecksumMatches), setup, teardown), zfp-1.0.1/tests/src/decode/zfpDecodeBlockBase.c000066400000000000000000000156711453723256400213260ustar00rootroot00000000000000#include #include #include #include #include #include #include #include "utils/testMacros.h" #include "utils/zfpChecksums.h" #include "utils/zfpHash.h" struct setupVars { size_t dimLens[4]; Scalar* dataArr; void* buffer; size_t bufsizeBytes; zfp_stream* stream; }; static void populateInitialArray(Scalar** dataArrPtr) { size_t i; *dataArrPtr = malloc(sizeof(Scalar) * BLOCK_SIZE); assert_non_null(*dataArrPtr); for (i = 0; i < BLOCK_SIZE; i++) { #ifdef FL_PT_DATA (*dataArrPtr)[i] = nextSignedRandFlPt(); #else (*dataArrPtr)[i] = nextSignedRandInt(); #endif } } static void populateInitialArraySpecial(Scalar* dataArr, int index) { #ifdef FL_PT_DATA // IEEE-754 special values static const uint32 special_float_values[] = { 0x00000000u, // +0 0x80000000u, // -0 0x00000001u, // +FLT_TRUE_MIN 0x80000001u, // -FLT_TRUE_MIN 0x7f7fffffu, // +FLT_MAX 0xff7fffffu, // -FLT_MAX 0x7f800000u, // +infinity 0xff800000u, // -infinity 0x7fc00000u, // qNaN 0x7fa00000u, // sNaN }; static const uint64 special_double_values[] = { UINT64C(0x0000000000000000), // +0 UINT64C(0x8000000000000000), // -0 UINT64C(0x0000000000000001), // +DBL_TRUE_MIN UINT64C(0x8000000000000001), // -DBL_TRUE_MIN UINT64C(0x7fefffffffffffff), // +DBL_MAX UINT64C(0xffefffffffffffff), // -DBL_MAX UINT64C(0x7ff0000000000000), // +infinity UINT64C(0xfff0000000000000), // -infinity UINT64C(0x7ff8000000000000), // qNaN UINT64C(0x7ff4000000000000), // sNaN }; #endif size_t i; for (i = 0; i < BLOCK_SIZE; i++) { #ifdef FL_PT_DATA // generate special values if ((i & 3u) == 0) { switch(ZFP_TYPE) { case zfp_type_float: memcpy(dataArr + i, &special_float_values[index], sizeof(Scalar)); break; case zfp_type_double: memcpy(dataArr + i, &special_double_values[index], sizeof(Scalar)); break; } } else dataArr[i] = 0; #else dataArr[i] = nextSignedRandInt(); #endif } } static void setupZfpStream(struct setupVars* bundle, int specialValueIndex) { memset(bundle->dimLens, 0, sizeof(bundle->dimLens)); #if DIMS >= 1 bundle->dimLens[0] = BLOCK_SIDE_LEN; #endif #if DIMS >= 2 bundle->dimLens[1] = BLOCK_SIDE_LEN; #endif #if DIMS >= 3 bundle->dimLens[2] = BLOCK_SIDE_LEN; #endif #if DIMS >= 4 bundle->dimLens[3] = BLOCK_SIDE_LEN; #endif size_t* n = bundle->dimLens; zfp_type type = ZFP_TYPE; zfp_field* field; switch(DIMS) { case 1: field = zfp_field_1d(bundle->dataArr, type, n[0]); break; case 2: field = zfp_field_2d(bundle->dataArr, type, n[0], n[1]); break; case 3: field = zfp_field_3d(bundle->dataArr, type, n[0], n[1], n[2]); break; case 4: field = zfp_field_4d(bundle->dataArr, type, n[0], n[1], n[2], n[3]); break; } zfp_stream* stream = zfp_stream_open(NULL); if (specialValueIndex >= 0) { zfp_stream_set_reversible(stream); } else { zfp_stream_set_rate(stream, ZFP_RATE_PARAM_BITS, type, DIMS, zfp_false); } size_t bufsizeBytes = zfp_stream_maximum_size(stream, field); char* buffer = calloc(bufsizeBytes, sizeof(char)); assert_non_null(buffer); bitstream* s = stream_open(buffer, bufsizeBytes); assert_non_null(s); zfp_stream_set_bit_stream(stream, s); zfp_stream_rewind(stream); zfp_field_free(field); bundle->bufsizeBytes = bufsizeBytes; bundle->buffer = buffer; bundle->stream = stream; } static int setup(void **state) { struct setupVars *bundle = malloc(sizeof(struct setupVars)); assert_non_null(bundle); resetRandGen(); populateInitialArray(&bundle->dataArr); setupZfpStream(bundle, -1); *state = bundle; return 0; } static int setupSpecial(void **state) { struct setupVars *bundle = malloc(sizeof(struct setupVars)); assert_non_null(bundle); bundle->dataArr = malloc(sizeof(Scalar) * BLOCK_SIZE); assert_non_null(bundle->dataArr); resetRandGen(); setupZfpStream(bundle, 0); *state = bundle; return 0; } static int teardown(void **state) { struct setupVars *bundle = *state; stream_close(bundle->stream->stream); zfp_stream_close(bundle->stream); free(bundle->buffer); free(bundle->dataArr); free(bundle); return 0; } static void when_seededRandomDataGenerated_expect_ChecksumMatches(void **state) { struct setupVars *bundle = *state; UInt checksum = _catFunc2(hashArray, SCALAR_BITS)((const UInt*)bundle->dataArr, BLOCK_SIZE, 1); uint64 key1, key2; computeKeyOriginalInput(BLOCK_FULL_TEST, bundle->dimLens, &key1, &key2); ASSERT_EQ_CHECKSUM(DIMS, ZFP_TYPE, checksum, key1, key2); } static void _catFunc3(given_, DIM_INT_STR, Block_when_DecodeBlock_expect_ReturnValReflectsNumBitsReadFromBitstream)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; bitstream* s = zfp_stream_bit_stream(stream); _t2(zfp_encode_block, Scalar, DIMS)(stream, bundle->dataArr); zfp_stream_flush(stream); zfp_stream_rewind(stream); size_t returnValBits = _t2(zfp_decode_block, Scalar, DIMS)(stream, bundle->dataArr); assert_int_equal(returnValBits, stream_rtell(s)); } static void _catFunc3(given_, DIM_INT_STR, Block_when_DecodeBlock_expect_ArrayChecksumMatches)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; _t2(zfp_encode_block, Scalar, DIMS)(stream, bundle->dataArr); zfp_stream_flush(stream); zfp_stream_rewind(stream); Scalar* decodedDataArr = calloc(BLOCK_SIZE, sizeof(Scalar)); assert_non_null(decodedDataArr); _t2(zfp_decode_block, Scalar, DIMS)(stream, decodedDataArr); UInt checksum = _catFunc2(hashArray, SCALAR_BITS)((const UInt*)decodedDataArr, BLOCK_SIZE, 1); free(decodedDataArr); uint64 key1, key2; computeKey(BLOCK_FULL_TEST, DECOMPRESSED_ARRAY, bundle->dimLens, zfp_mode_fixed_rate, 0, &key1, &key2); ASSERT_EQ_CHECKSUM(DIMS, ZFP_TYPE, checksum, key1, key2); } static void _catFunc3(given_, DIM_INT_STR, Block_when_DecodeSpecialBlocks_expect_ArraysMatchBitForBit)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; int failures = 0; int i; for (i = 0; i < 10; i++) { populateInitialArraySpecial(bundle->dataArr, i); _t2(zfp_encode_block, Scalar, DIMS)(stream, bundle->dataArr); zfp_stream_flush(stream); zfp_stream_rewind(stream); Scalar* decodedDataArr = calloc(BLOCK_SIZE, sizeof(Scalar)); assert_non_null(decodedDataArr); _t2(zfp_decode_block, Scalar, DIMS)(stream, decodedDataArr); if (memcmp(bundle->dataArr, decodedDataArr, BLOCK_SIZE * sizeof(Scalar)) != 0) { printf("Decode special Block testcase %d failed\n", i); failures++; } free(decodedDataArr); // reset/zero bitstream, rewind for next iteration memset(bundle->buffer, 0, bundle->bufsizeBytes); zfp_stream_rewind(stream); } if (failures > 0) { fail_msg("At least 1 special block testcase failed\n"); } } zfp-1.0.1/tests/src/decode/zfpDecodeBlockStridedBase.c000066400000000000000000000401461453723256400226400ustar00rootroot00000000000000#include #include #include #include #include #include #include "utils/testMacros.h" #include "utils/zfpChecksums.h" #include "utils/zfpHash.h" #define SX 2 #define SY (3 * BLOCK_SIDE_LEN*SX) #define SZ (2 * BLOCK_SIDE_LEN*SY) #define SW (3 * BLOCK_SIDE_LEN*SZ) #define PX 1 #define PY 2 #define PZ 3 #define PW 4 #define DUMMY_VAL 99 struct setupVars { size_t dimLens[4]; Scalar* dataArr; Scalar* decodedDataArr; void* buffer; zfp_stream* stream; }; // write random output to strided entries, dummyVal elsewhere // returns number of elements in allocated array size_t initializeStridedArray(Scalar** dataArrPtr, Scalar dummyVal) { size_t arrayLen; int i, j, k, l, countX, countY, countZ, countW; // absolute entry (i,j,k,l) // 0 <= i < countX, (same for j,countY and k,countZ and l,countW) // strided entry iff // i % countX/BLOCK_SIDE_LEN == 0 (and so on for j, k, l) switch (DIMS) { case 1: countX = BLOCK_SIDE_LEN * SX; arrayLen = countX; *dataArrPtr = malloc(sizeof(Scalar) * arrayLen); assert_non_null(*dataArrPtr); for (i = 0; i < countX; i++) { if (i % SX) { (*dataArrPtr)[i] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArrPtr)[i] = nextSignedRandFlPt(); #else (*dataArrPtr)[i] = nextSignedRandInt(); #endif } } break; case 2: countX = BLOCK_SIDE_LEN * SX; countY = SY / SX; arrayLen = countX * countY; *dataArrPtr = malloc(sizeof(Scalar) * arrayLen); assert_non_null(*dataArrPtr); for (j = 0; j < countY; j++) { for (i = 0; i < countX; i++) { size_t index = countX*j + i; if (i % (countX/BLOCK_SIDE_LEN) || j % (countY/BLOCK_SIDE_LEN)) { (*dataArrPtr)[index] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArrPtr)[index] = nextSignedRandFlPt(); #else (*dataArrPtr)[index] = nextSignedRandInt(); #endif } } } break; case 3: countX = BLOCK_SIDE_LEN * SX; countY = SY / SX; countZ = SZ / SY; arrayLen = countX * countY * countZ; *dataArrPtr = malloc(sizeof(Scalar) * arrayLen); assert_non_null(*dataArrPtr); for (k = 0; k < countZ; k++) { for (j = 0; j < countY; j++) { for (i = 0; i < countX; i++) { size_t index = countX*countY*k + countX*j + i; if (i % (countX/BLOCK_SIDE_LEN) || j % (countY/BLOCK_SIDE_LEN) || k % (countZ/BLOCK_SIDE_LEN)) { (*dataArrPtr)[index] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArrPtr)[index] = nextSignedRandFlPt(); #else (*dataArrPtr)[index] = nextSignedRandInt(); #endif } } } } break; case 4: countX = BLOCK_SIDE_LEN * SX; countY = SY / SX; countZ = SZ / SY; countW = SW / SZ; arrayLen = countX * countY * countZ * countW; *dataArrPtr = malloc(sizeof(Scalar) * arrayLen); assert_non_null(*dataArrPtr); for (l = 0; l < countW; l++) { for (k = 0; k < countZ; k++) { for (j = 0; j < countY; j++) { for (i = 0; i < countX; i++) { size_t index = countX*countY*countZ*l + countX*countY*k + countX*j + i; if (i % (countX/BLOCK_SIDE_LEN) || j % (countY/BLOCK_SIDE_LEN) || k % (countZ/BLOCK_SIDE_LEN) || l % (countW/BLOCK_SIDE_LEN)) { (*dataArrPtr)[index] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArrPtr)[index] = nextSignedRandFlPt(); #else (*dataArrPtr)[index] = nextSignedRandInt(); #endif } } } } } break; } return arrayLen; } static void setupZfpStream(struct setupVars* bundle) { memset(bundle->dimLens, 0, sizeof(bundle->dimLens)); #if DIMS >= 1 bundle->dimLens[0] = BLOCK_SIDE_LEN; #endif #if DIMS >= 2 bundle->dimLens[1] = BLOCK_SIDE_LEN; #endif #if DIMS >= 3 bundle->dimLens[2] = BLOCK_SIDE_LEN; #endif #if DIMS >= 4 bundle->dimLens[3] = BLOCK_SIDE_LEN; #endif size_t* n = bundle->dimLens; zfp_type type = ZFP_TYPE; zfp_field* field; switch(DIMS) { case 1: field = zfp_field_1d(bundle->dataArr, type, n[0]); zfp_field_set_stride_1d(field, SX); break; case 2: field = zfp_field_2d(bundle->dataArr, type, n[0], n[1]); zfp_field_set_stride_2d(field, SX, SY); break; case 3: field = zfp_field_3d(bundle->dataArr, type, n[0], n[1], n[2]); zfp_field_set_stride_3d(field, SX, SY, SZ); break; case 4: field = zfp_field_4d(bundle->dataArr, type, n[0], n[1], n[2], n[3]); zfp_field_set_stride_4d(field, SX, SY, SZ, SW); break; } zfp_stream* stream = zfp_stream_open(NULL); zfp_stream_set_rate(stream, ZFP_RATE_PARAM_BITS, type, DIMS, zfp_false); size_t bufsizeBytes = zfp_stream_maximum_size(stream, field); char* buffer = calloc(bufsizeBytes, sizeof(char)); assert_non_null(buffer); bitstream* s = stream_open(buffer, bufsizeBytes); assert_non_null(s); zfp_stream_set_bit_stream(stream, s); zfp_stream_rewind(stream); zfp_field_free(field); bundle->buffer = buffer; bundle->stream = stream; } static int setup(void **state) { struct setupVars *bundle = malloc(sizeof(struct setupVars)); assert_non_null(bundle); resetRandGen(); size_t arrayLen = initializeStridedArray(&bundle->dataArr, DUMMY_VAL); bundle->decodedDataArr = calloc(arrayLen, sizeof(Scalar)); assert_non_null(bundle->decodedDataArr); setupZfpStream(bundle); *state = bundle; return 0; } static int teardown(void **state) { struct setupVars *bundle = *state; stream_close(bundle->stream->stream); zfp_stream_close(bundle->stream); free(bundle->buffer); free(bundle->decodedDataArr); free(bundle->dataArr); free(bundle); return 0; } UInt hashStridedBlock(Scalar* dataArr) { ptrdiff_t s[4] = {SX, SY, SZ, SW}; size_t n[4]; int i; for (i = 0; i < 4; i++) { n[i] = (i < DIMS) ? BLOCK_SIDE_LEN : 0; } return _catFunc2(hashStridedArray, SCALAR_BITS)((const UInt*)dataArr, n, s); } size_t encodeBlockStrided(zfp_stream* stream, Scalar* dataArr) { size_t numBitsWritten; switch (DIMS) { case 1: numBitsWritten = _t2(zfp_encode_block_strided, Scalar, 1)(stream, dataArr, SX); break; case 2: numBitsWritten = _t2(zfp_encode_block_strided, Scalar, 2)(stream, dataArr, SX, SY); break; case 3: numBitsWritten = _t2(zfp_encode_block_strided, Scalar, 3)(stream, dataArr, SX, SY, SZ); break; case 4: numBitsWritten = _t2(zfp_encode_block_strided, Scalar, 4)(stream, dataArr, SX, SY, SZ, SW); break; } return numBitsWritten; } size_t encodePartialBlockStrided(zfp_stream* stream, Scalar* dataArr) { size_t numBitsWritten; switch (DIMS) { case 1: numBitsWritten = _t2(zfp_encode_partial_block_strided, Scalar, 1)(stream, dataArr, PX, SX); break; case 2: numBitsWritten = _t2(zfp_encode_partial_block_strided, Scalar, 2)(stream, dataArr, PX, PY, SX, SY); break; case 3: numBitsWritten = _t2(zfp_encode_partial_block_strided, Scalar, 3)(stream, dataArr, PX, PY, PZ, SX, SY, SZ); break; case 4: numBitsWritten = _t2(zfp_encode_partial_block_strided, Scalar, 4)(stream, dataArr, PX, PY, PZ, PW, SX, SY, SZ, SW); break; } return numBitsWritten; } size_t decodeBlockStrided(zfp_stream* stream, Scalar* dataArr) { size_t numBitsRead; switch (DIMS) { case 1: numBitsRead = _t2(zfp_decode_block_strided, Scalar, 1)(stream, dataArr, SX); break; case 2: numBitsRead = _t2(zfp_decode_block_strided, Scalar, 2)(stream, dataArr, SX, SY); break; case 3: numBitsRead = _t2(zfp_decode_block_strided, Scalar, 3)(stream, dataArr, SX, SY, SZ); break; case 4: numBitsRead = _t2(zfp_decode_block_strided, Scalar, 4)(stream, dataArr, SX, SY, SZ, SW); break; } return numBitsRead; } size_t decodePartialBlockStrided(zfp_stream* stream, Scalar* dataArr) { size_t numBitsRead; switch (DIMS) { case 1: numBitsRead = _t2(zfp_decode_partial_block_strided, Scalar, 1)(stream, dataArr, PX, SX); break; case 2: numBitsRead = _t2(zfp_decode_partial_block_strided, Scalar, 2)(stream, dataArr, PX, PY, SX, SY); break; case 3: numBitsRead = _t2(zfp_decode_partial_block_strided, Scalar, 3)(stream, dataArr, PX, PY, PZ, SX, SY, SZ); break; case 4: numBitsRead = _t2(zfp_decode_partial_block_strided, Scalar, 4)(stream, dataArr, PX, PY, PZ, PW, SX, SY, SZ, SW); break; } return numBitsRead; } void assertNonStridedEntriesZero(Scalar* data) { size_t i, j, k, l, countX, countY, countZ, countW; switch (DIMS) { case 1: countX = BLOCK_SIDE_LEN * SX; for (i = 0; i < countX; i++) { if (i % SX) { assert_true(data[i] == 0.); } } break; case 2: countX = BLOCK_SIDE_LEN * SX; countY = SY / SX; for (j = 0; j < countY; j++) { for (i = 0; i < countX; i++) { if (i % (countX/BLOCK_SIDE_LEN) || j % (countY/BLOCK_SIDE_LEN)) { assert_true(data[countX*j + i] == 0.); } } } break; case 3: countX = BLOCK_SIDE_LEN * SX; countY = SY / SX; countZ = SZ / SY; for (k = 0; k < countZ; k++) { for (j = 0; j < countY; j++) { for (i = 0; i < countX; i++) { if (i % (countX/BLOCK_SIDE_LEN) || j % (countY/BLOCK_SIDE_LEN) || k % (countZ/BLOCK_SIDE_LEN)) { assert_true(data[countX*countY*k + countX*j + i] == 0.); } } } } break; case 4: countX = BLOCK_SIDE_LEN * SX; countY = SY / SX; countZ = SZ / SY; countW = SW / SZ; for (l = 0; l < countW; l++) { for (k = 0; k < countZ; k++) { for (j = 0; j < countY; j++) { for (i = 0; i < countX; i++) { if (i % (countX/BLOCK_SIDE_LEN) || j % (countY/BLOCK_SIDE_LEN) || k % (countZ/BLOCK_SIDE_LEN) || l % (countW/BLOCK_SIDE_LEN)) { assert_true(data[countX*countY*countZ*l + countX*countY*k + countX*j + i] == 0.); } } } } } break; } } void assertEntriesOutsidePartialBlockBoundsZero(Scalar* data) { size_t i, j, k, l, countX, countY, countZ, countW; switch (DIMS) { case 1: countX = BLOCK_SIDE_LEN * SX; for (i = 0; i < countX; i++) { if (i/SX >= PX) { assert_true(data[i] == 0.); } } break; case 2: countX = BLOCK_SIDE_LEN * SX; countY = SY / SX; for (j = 0; j < countY; j++) { for (i = 0; i < countX; i++) { if (i/(countX/BLOCK_SIDE_LEN) >= PX || j/(countY/BLOCK_SIDE_LEN) >= PY) { assert_true(data[countX*j + i] == 0.); } } } break; case 3: countX = BLOCK_SIDE_LEN * SX; countY = SY / SX; countZ = SZ / SY; for (k = 0; k < countZ; k++) { for (j = 0; j < countY; j++) { for (i = 0; i < countX; i++) { if (i/(countX/BLOCK_SIDE_LEN) >= PX || j/(countY/BLOCK_SIDE_LEN) >= PY || k/(countZ/BLOCK_SIDE_LEN) >= PZ) { assert_true(data[countX*countY*k + countX*j + i] == 0.); } } } } break; case 4: countX = BLOCK_SIDE_LEN * SX; countY = SY / SX; countZ = SZ / SY; countW = SW / SZ; for (l = 0; l < countW; l++) { for (k = 0; k < countZ; k++) { for (j = 0; j < countY; j++) { for (i = 0; i < countX; i++) { if (i/(countX/BLOCK_SIDE_LEN) >= PX || j/(countY/BLOCK_SIDE_LEN) >= PY || k/(countZ/BLOCK_SIDE_LEN) >= PZ || l/(countW/BLOCK_SIDE_LEN) >= PW) { assert_true(data[countX*countY*countZ*l + countX*countY*k + countX*j + i] == 0.); } } } } } break; } } static void when_seededRandomDataGenerated_expect_ChecksumMatches(void **state) { struct setupVars *bundle = *state; UInt checksum = hashStridedBlock(bundle->dataArr); uint64 key1, key2; computeKeyOriginalInput(BLOCK_FULL_TEST, bundle->dimLens, &key1, &key2); ASSERT_EQ_CHECKSUM(DIMS, ZFP_TYPE, checksum, key1, key2); } static void _catFunc3(given_, DIM_INT_STR, Block_when_DecodeBlockStrided_expect_ReturnValReflectsNumBitsReadFromBitstream)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; bitstream* s = zfp_stream_bit_stream(stream); encodeBlockStrided(stream, bundle->dataArr); zfp_stream_flush(stream); zfp_stream_rewind(stream); size_t returnValBits = decodeBlockStrided(stream, bundle->decodedDataArr); assert_int_equal(returnValBits, stream_rtell(s)); } static void _catFunc3(given_, DIM_INT_STR, Block_when_DecodeBlockStrided_expect_OnlyStridedEntriesChangedInDestinationArray)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; encodeBlockStrided(stream, bundle->dataArr); zfp_stream_flush(stream); zfp_stream_rewind(stream); decodeBlockStrided(stream, bundle->decodedDataArr); assertNonStridedEntriesZero(bundle->decodedDataArr); } static void _catFunc3(given_, DIM_INT_STR, Block_when_DecodeBlockStrided_expect_ArrayChecksumMatches)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; encodeBlockStrided(stream, bundle->dataArr); zfp_stream_flush(stream); zfp_stream_rewind(stream); decodeBlockStrided(stream, bundle->decodedDataArr); UInt checksum = hashStridedBlock(bundle->decodedDataArr); uint64 key1, key2; computeKey(BLOCK_FULL_TEST, DECOMPRESSED_ARRAY, bundle->dimLens, zfp_mode_fixed_rate, 0, &key1, &key2); ASSERT_EQ_CHECKSUM(DIMS, ZFP_TYPE, checksum, key1, key2); } static void _catFunc3(given_, DIM_INT_STR, Block_when_DecodePartialBlockStrided_expect_ReturnValReflectsNumBitsReadFromBitstream)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; bitstream* s = zfp_stream_bit_stream(stream); encodePartialBlockStrided(stream, bundle->dataArr); zfp_stream_flush(stream); zfp_stream_rewind(stream); size_t returnValBits = decodePartialBlockStrided(stream, bundle->decodedDataArr); assert_int_equal(returnValBits, stream_rtell(s)); } static void _catFunc3(given_, DIM_INT_STR, Block_when_DecodePartialBlockStrided_expect_NonStridedEntriesUnchangedInDestinationArray)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; encodePartialBlockStrided(stream, bundle->dataArr); zfp_stream_flush(stream); zfp_stream_rewind(stream); decodePartialBlockStrided(stream, bundle->decodedDataArr); assertNonStridedEntriesZero(bundle->decodedDataArr); } static void _catFunc3(given_, DIM_INT_STR, Block_when_DecodePartialBlockStrided_expect_EntriesOutsidePartialBlockBoundsUnchangedInDestinationArray)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; encodePartialBlockStrided(stream, bundle->dataArr); zfp_stream_flush(stream); zfp_stream_rewind(stream); decodePartialBlockStrided(stream, bundle->decodedDataArr); assertEntriesOutsidePartialBlockBoundsZero(bundle->decodedDataArr); } static void _catFunc3(given_, DIM_INT_STR, Block_when_DecodePartialBlockStrided_expect_ArrayChecksumMatches)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; encodePartialBlockStrided(stream, bundle->dataArr); zfp_stream_flush(stream); zfp_stream_rewind(stream); decodePartialBlockStrided(stream, bundle->decodedDataArr); UInt checksum = hashStridedBlock(bundle->decodedDataArr); uint64 key1, key2; computeKey(BLOCK_PARTIAL_TEST, DECOMPRESSED_ARRAY, bundle->dimLens, zfp_mode_fixed_rate, 0, &key1, &key2); ASSERT_EQ_CHECKSUM(DIMS, ZFP_TYPE, checksum, key1, key2); } zfp-1.0.1/tests/src/encode/000077500000000000000000000000001453723256400155115ustar00rootroot00000000000000zfp-1.0.1/tests/src/encode/CMakeLists.txt000066400000000000000000000033171453723256400202550ustar00rootroot00000000000000function(zfp_add_block_tests dims type bits) set(block_test_name testZfpEncodeBlock${dims}d${type}) add_executable(${block_test_name} ${block_test_name}.c) target_link_libraries(${block_test_name} cmocka zfp rand${bits}Lib zfpHashLib zfpChecksumsLib) if(HAVE_LIBM_MATH) target_link_libraries(${block_test_name} m) endif() target_compile_definitions(${block_test_name} PRIVATE ${zfp_private_defs}) if(PRINT_CHECKSUMS) target_compile_definitions(${block_test_name} PUBLIC PRINT_CHECKSUMS) endif() add_test(NAME ${block_test_name} COMMAND ${block_test_name}) set(strided_block_test_name testZfpEncodeBlockStrided${dims}d${type}) add_executable(${strided_block_test_name} ${strided_block_test_name}.c) target_link_libraries(${strided_block_test_name} cmocka zfp rand${bits}Lib zfpHashLib zfpChecksumsLib) if(HAVE_LIBM_MATH) target_link_libraries(${strided_block_test_name} m) endif() target_compile_definitions(${strided_block_test_name} PRIVATE ${zfp_private_defs}) if(PRINT_CHECKSUMS) target_compile_definitions(${strided_block_test_name} PUBLIC PRINT_CHECKSUMS) endif() add_test(NAME ${strided_block_test_name} COMMAND ${strided_block_test_name}) endfunction() zfp_add_block_tests(1 Int32 32) zfp_add_block_tests(1 Int64 64) zfp_add_block_tests(2 Int32 32) zfp_add_block_tests(2 Int64 64) zfp_add_block_tests(3 Int32 32) zfp_add_block_tests(3 Int64 64) zfp_add_block_tests(4 Int32 32) zfp_add_block_tests(4 Int64 64) zfp_add_block_tests(1 Float 32) zfp_add_block_tests(1 Double 64) zfp_add_block_tests(2 Float 32) zfp_add_block_tests(2 Double 64) zfp_add_block_tests(3 Float 32) zfp_add_block_tests(3 Double 64) zfp_add_block_tests(4 Float 32) zfp_add_block_tests(4 Double 64) zfp-1.0.1/tests/src/encode/testZfpEncodeBlock1dDouble.c000066400000000000000000000004051453723256400227640ustar00rootroot00000000000000#include "src/encode1d.c" #include "constants/1dDouble.h" #include "utils/rand64.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlock1dFloat.c000066400000000000000000000004041453723256400226160ustar00rootroot00000000000000#include "src/encode1f.c" #include "constants/1dFloat.h" #include "utils/rand32.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlock1dInt32.c000066400000000000000000000004041453723256400224500ustar00rootroot00000000000000#include "src/encode1i.c" #include "constants/1dInt32.h" #include "utils/rand32.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlock1dInt64.c000066400000000000000000000004041453723256400224550ustar00rootroot00000000000000#include "src/encode1l.c" #include "constants/1dInt64.h" #include "utils/rand64.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlock2dDouble.c000066400000000000000000000004051453723256400227650ustar00rootroot00000000000000#include "src/encode2d.c" #include "constants/2dDouble.h" #include "utils/rand64.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlock2dFloat.c000066400000000000000000000004041453723256400226170ustar00rootroot00000000000000#include "src/encode2f.c" #include "constants/2dFloat.h" #include "utils/rand32.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlock2dInt32.c000066400000000000000000000004041453723256400224510ustar00rootroot00000000000000#include "src/encode2i.c" #include "constants/2dInt32.h" #include "utils/rand32.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlock2dInt64.c000066400000000000000000000004041453723256400224560ustar00rootroot00000000000000#include "src/encode2l.c" #include "constants/2dInt64.h" #include "utils/rand64.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlock3dDouble.c000066400000000000000000000004051453723256400227660ustar00rootroot00000000000000#include "src/encode3d.c" #include "constants/3dDouble.h" #include "utils/rand64.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlock3dFloat.c000066400000000000000000000004041453723256400226200ustar00rootroot00000000000000#include "src/encode3f.c" #include "constants/3dFloat.h" #include "utils/rand32.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlock3dInt32.c000066400000000000000000000004041453723256400224520ustar00rootroot00000000000000#include "src/encode3i.c" #include "constants/3dInt32.h" #include "utils/rand32.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlock3dInt64.c000066400000000000000000000004041453723256400224570ustar00rootroot00000000000000#include "src/encode3l.c" #include "constants/3dInt64.h" #include "utils/rand64.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlock4dDouble.c000066400000000000000000000004051453723256400227670ustar00rootroot00000000000000#include "src/encode4d.c" #include "constants/4dDouble.h" #include "utils/rand64.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlock4dFloat.c000066400000000000000000000004041453723256400226210ustar00rootroot00000000000000#include "src/encode4f.c" #include "constants/4dFloat.h" #include "utils/rand32.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlock4dInt32.c000066400000000000000000000004041453723256400224530ustar00rootroot00000000000000#include "src/encode4i.c" #include "constants/4dInt32.h" #include "utils/rand32.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlock4dInt64.c000066400000000000000000000004041453723256400224600ustar00rootroot00000000000000#include "src/encode4l.c" #include "constants/4dInt64.h" #include "utils/rand64.h" #include "zfpEncodeBlockBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/block.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided1dDouble.c000066400000000000000000000004231453723256400243030ustar00rootroot00000000000000#include "src/encode1d.c" #include "constants/1dDouble.h" #include "utils/rand64.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided1dFloat.c000066400000000000000000000004221453723256400241350ustar00rootroot00000000000000#include "src/encode1f.c" #include "constants/1dFloat.h" #include "utils/rand32.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided1dInt32.c000066400000000000000000000004221453723256400237670ustar00rootroot00000000000000#include "src/encode1i.c" #include "constants/1dInt32.h" #include "utils/rand32.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided1dInt64.c000066400000000000000000000004221453723256400237740ustar00rootroot00000000000000#include "src/encode1l.c" #include "constants/1dInt64.h" #include "utils/rand64.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided2dDouble.c000066400000000000000000000004231453723256400243040ustar00rootroot00000000000000#include "src/encode2d.c" #include "constants/2dDouble.h" #include "utils/rand64.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided2dFloat.c000066400000000000000000000004221453723256400241360ustar00rootroot00000000000000#include "src/encode2f.c" #include "constants/2dFloat.h" #include "utils/rand32.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided2dInt32.c000066400000000000000000000004221453723256400237700ustar00rootroot00000000000000#include "src/encode2i.c" #include "constants/2dInt32.h" #include "utils/rand32.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided2dInt64.c000066400000000000000000000004221453723256400237750ustar00rootroot00000000000000#include "src/encode2l.c" #include "constants/2dInt64.h" #include "utils/rand64.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided3dDouble.c000066400000000000000000000004231453723256400243050ustar00rootroot00000000000000#include "src/encode3d.c" #include "constants/3dDouble.h" #include "utils/rand64.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided3dFloat.c000066400000000000000000000004221453723256400241370ustar00rootroot00000000000000#include "src/encode3f.c" #include "constants/3dFloat.h" #include "utils/rand32.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided3dInt32.c000066400000000000000000000004221453723256400237710ustar00rootroot00000000000000#include "src/encode3i.c" #include "constants/3dInt32.h" #include "utils/rand32.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided3dInt64.c000066400000000000000000000004221453723256400237760ustar00rootroot00000000000000#include "src/encode3l.c" #include "constants/3dInt64.h" #include "utils/rand64.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided4dDouble.c000066400000000000000000000004231453723256400243060ustar00rootroot00000000000000#include "src/encode4d.c" #include "constants/4dDouble.h" #include "utils/rand64.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided4dFloat.c000066400000000000000000000004221453723256400241400ustar00rootroot00000000000000#include "src/encode4f.c" #include "constants/4dFloat.h" #include "utils/rand32.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided4dInt32.c000066400000000000000000000004221453723256400237720ustar00rootroot00000000000000#include "src/encode4i.c" #include "constants/4dInt32.h" #include "utils/rand32.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testZfpEncodeBlockStrided4dInt64.c000066400000000000000000000004221453723256400237770ustar00rootroot00000000000000#include "src/encode4l.c" #include "constants/4dInt64.h" #include "utils/rand64.h" #include "zfpEncodeBlockStridedBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/blockStrided.c" }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/encode/testcases/000077500000000000000000000000001453723256400175075ustar00rootroot00000000000000zfp-1.0.1/tests/src/encode/testcases/block.c000066400000000000000000000013251453723256400207460ustar00rootroot00000000000000// requires #include "utils/testMacros.h", do outside of main() _cmocka_unit_test_setup_teardown(when_seededRandomDataGenerated_expect_ChecksumMatches, setup, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_EncodeBlock_expect_ReturnValReflectsNumBitsWrittenToBitstream), setup, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_EncodeBlock_expect_BitstreamChecksumMatches), setup, teardown), #ifdef FL_PT_DATA // reversible compression of blocks containing special floating-point values _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_EncodeSpecialBlocks_expect_BitstreamChecksumMatches), setupSpecial, teardown), #endif zfp-1.0.1/tests/src/encode/testcases/blockStrided.c000066400000000000000000000025271453723256400222720ustar00rootroot00000000000000// requires #include "utils/testMacros.h", do outside of main() // omit redundant checksums covered in non-strided block tests #ifndef PRINT_CHECKSUMS _cmocka_unit_test_setup_teardown(when_seededRandomDataGenerated_expect_ChecksumMatches, setup, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_EncodeBlockStrided_expect_ReturnValReflectsNumBitsWrittenToBitstream), setup, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_EncodeBlockStrided_expect_OnlyStridedEntriesUsed), setup, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_EncodeBlockStrided_expect_BitstreamChecksumMatches), setup, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_EncodePartialBlockStrided_expect_ReturnValReflectsNumBitsWrittenToBitstream), setup, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_EncodePartialBlockStrided_expect_OnlyStridedEntriesUsed), setup, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_EncodePartialBlockStrided_expect_OnlyEntriesWithinPartialBlockBoundsUsed), setup, teardown), #endif _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Block_when_EncodePartialBlockStrided_expect_BitstreamChecksumMatches), setup, teardown), zfp-1.0.1/tests/src/encode/zfpEncodeBlockBase.c000066400000000000000000000154751453723256400213540ustar00rootroot00000000000000#include #include #include #include #include #include #include #include "utils/testMacros.h" #include "utils/zfpChecksums.h" #include "utils/zfpHash.h" struct setupVars { size_t dimLens[4]; Scalar* dataArr; void* buffer; size_t bufsizeBytes; zfp_stream* stream; }; static void populateInitialArray(Scalar** dataArrPtr) { size_t i; *dataArrPtr = malloc(sizeof(Scalar) * BLOCK_SIZE); assert_non_null(*dataArrPtr); for (i = 0; i < BLOCK_SIZE; i++) { #ifdef FL_PT_DATA (*dataArrPtr)[i] = nextSignedRandFlPt(); #else (*dataArrPtr)[i] = nextSignedRandInt(); #endif } } static void populateInitialArraySpecial(Scalar* dataArr, int index) { #ifdef FL_PT_DATA // IEEE-754 special values static const uint32 special_float_values[] = { 0x00000000u, // +0 0x80000000u, // -0 0x00000001u, // +FLT_TRUE_MIN 0x80000001u, // -FLT_TRUE_MIN 0x7f7fffffu, // +FLT_MAX 0xff7fffffu, // -FLT_MAX 0x7f800000u, // +infinity 0xff800000u, // -infinity 0x7fc00000u, // qNaN 0x7fa00000u, // sNaN }; static const uint64 special_double_values[] = { UINT64C(0x0000000000000000), // +0 UINT64C(0x8000000000000000), // -0 UINT64C(0x0000000000000001), // +DBL_TRUE_MIN UINT64C(0x8000000000000001), // -DBL_TRUE_MIN UINT64C(0x7fefffffffffffff), // +DBL_MAX UINT64C(0xffefffffffffffff), // -DBL_MAX UINT64C(0x7ff0000000000000), // +infinity UINT64C(0xfff0000000000000), // -infinity UINT64C(0x7ff8000000000000), // qNaN UINT64C(0x7ff4000000000000), // sNaN }; #endif size_t i; for (i = 0; i < BLOCK_SIZE; i++) { #ifdef FL_PT_DATA // generate special values if ((i & 3u) == 0) { switch(ZFP_TYPE) { case zfp_type_float: memcpy(dataArr + i, &special_float_values[index], sizeof(Scalar)); break; case zfp_type_double: memcpy(dataArr + i, &special_double_values[index], sizeof(Scalar)); break; } } else dataArr[i] = 0; #else dataArr[i] = nextSignedRandInt(); #endif } } // specialValueIndex -1 implies test without special values static void setupZfpStream(struct setupVars* bundle, int specialValueIndex) { memset(bundle->dimLens, 0, sizeof(bundle->dimLens)); #if DIMS >= 1 bundle->dimLens[0] = BLOCK_SIDE_LEN; #endif #if DIMS >= 2 bundle->dimLens[1] = BLOCK_SIDE_LEN; #endif #if DIMS >= 3 bundle->dimLens[2] = BLOCK_SIDE_LEN; #endif #if DIMS >= 4 bundle->dimLens[3] = BLOCK_SIDE_LEN; #endif size_t* n = bundle->dimLens; zfp_type type = ZFP_TYPE; zfp_field* field; switch (DIMS) { case 1: field = zfp_field_1d(bundle->dataArr, type, n[0]); break; case 2: field = zfp_field_2d(bundle->dataArr, type, n[0], n[1]); break; case 3: field = zfp_field_3d(bundle->dataArr, type, n[0], n[1], n[2]); break; case 4: field = zfp_field_4d(bundle->dataArr, type, n[0], n[1], n[2], n[3]); break; } zfp_stream* stream = zfp_stream_open(NULL); if (specialValueIndex >= 0) { zfp_stream_set_reversible(stream); } else { zfp_stream_set_rate(stream, ZFP_RATE_PARAM_BITS, type, DIMS, zfp_false); } size_t bufsizeBytes = zfp_stream_maximum_size(stream, field); char* buffer = calloc(bufsizeBytes, sizeof(char)); assert_non_null(buffer); bitstream* s = stream_open(buffer, bufsizeBytes); assert_non_null(s); zfp_stream_set_bit_stream(stream, s); zfp_stream_rewind(stream); zfp_field_free(field); bundle->bufsizeBytes = bufsizeBytes; bundle->buffer = buffer; bundle->stream = stream; } static int setup(void **state) { struct setupVars *bundle = malloc(sizeof(struct setupVars)); assert_non_null(bundle); resetRandGen(); populateInitialArray(&bundle->dataArr); setupZfpStream(bundle, -1); *state = bundle; return 0; } static int setupSpecial(void **state) { struct setupVars *bundle = malloc(sizeof(struct setupVars)); assert_non_null(bundle); bundle->dataArr = malloc(sizeof(Scalar) * BLOCK_SIZE); assert_non_null(bundle->dataArr); setupZfpStream(bundle, 0); *state = bundle; return 0; } static int teardown(void **state) { struct setupVars *bundle = *state; stream_close(bundle->stream->stream); zfp_stream_close(bundle->stream); free(bundle->buffer); free(bundle->dataArr); free(bundle); return 0; } static void when_seededRandomDataGenerated_expect_ChecksumMatches(void **state) { struct setupVars *bundle = *state; UInt checksum = _catFunc2(hashArray, SCALAR_BITS)((const UInt*)bundle->dataArr, BLOCK_SIZE, 1); uint64 key1, key2; computeKeyOriginalInput(BLOCK_FULL_TEST, bundle->dimLens, &key1, &key2); // random data checksum only run for full block, and for non-special values ASSERT_EQ_CHECKSUM(DIMS, ZFP_TYPE, checksum, key1, key2); } static void _catFunc3(given_, DIM_INT_STR, Block_when_EncodeBlock_expect_ReturnValReflectsNumBitsWrittenToBitstream)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; bitstream* s = zfp_stream_bit_stream(stream); size_t returnValBits = _t2(zfp_encode_block, Scalar, DIMS)(stream, bundle->dataArr); // do not flush, otherwise extra zeros included in count assert_int_equal(returnValBits, stream_wtell(s)); } static void _catFunc3(given_, DIM_INT_STR, Block_when_EncodeBlock_expect_BitstreamChecksumMatches)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; bitstream* s = zfp_stream_bit_stream(stream); _t2(zfp_encode_block, Scalar, DIMS)(stream, bundle->dataArr); zfp_stream_flush(stream); uint64 checksum = hashBitstream(stream_data(s), stream_size(s)); uint64 key1, key2; computeKey(BLOCK_FULL_TEST, COMPRESSED_BITSTREAM, bundle->dimLens, zfp_mode_fixed_rate, 0, &key1, &key2); ASSERT_EQ_CHECKSUM(DIMS, ZFP_TYPE, checksum, key1, key2); } static void _catFunc3(given_, DIM_INT_STR, Block_when_EncodeSpecialBlocks_expect_BitstreamChecksumMatches)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; bitstream* s = zfp_stream_bit_stream(stream); int failures = 0; int i; for (i = 0; i < 10; i++) { populateInitialArraySpecial(bundle->dataArr, i); _t2(zfp_encode_block, Scalar, DIMS)(stream, bundle->dataArr); zfp_stream_flush(stream); uint64 checksum = hashBitstream(stream_data(s), stream_size(s)); uint64 key1, key2; computeKey(BLOCK_FULL_TEST, COMPRESSED_BITSTREAM, bundle->dimLens, zfp_mode_reversible, i + 1, &key1, &key2); if (COMPARE_NEQ_CHECKSUM(DIMS, ZFP_TYPE, checksum, key1, key2)) { printf("Special Block testcase %d failed\n", i); failures++; } // reset/zero bitstream, rewind for next iteration memset(bundle->buffer, 0, bundle->bufsizeBytes); zfp_stream_rewind(stream); } if (failures > 0) { fail_msg("At least 1 special block testcase failed\n"); } } zfp-1.0.1/tests/src/encode/zfpEncodeBlockStridedBase.c000066400000000000000000000327751453723256400226750ustar00rootroot00000000000000#include #include #include #include #include #include #include "utils/testMacros.h" #include "utils/zfpChecksums.h" #include "utils/zfpHash.h" #define SX 2 #define SY (3 * BLOCK_SIDE_LEN*SX) #define SZ (2 * BLOCK_SIDE_LEN*SY) #define SW (3 * BLOCK_SIDE_LEN*SZ) #define PX 1 #define PY 2 #define PZ 3 #define PW 4 #define DUMMY_VAL 99 struct setupVars { size_t dimLens[4]; Scalar* dataArr; void* buffer; zfp_stream* stream; }; // write random output to strided entries, dummyVal elsewhere void initializeStridedArray(Scalar** dataArrPtr, Scalar dummyVal) { size_t i, j, k, l, countX, countY, countZ, countW; // absolute entry (i,j,k,l) // 0 <= i < countX, (same for j,countY and k,countZ and l,countW) // strided entry iff // i % countX/BLOCK_SIDE_LEN == 0 (and so on for j,k,l) switch(DIMS) { case 1: countX = BLOCK_SIDE_LEN * SX; *dataArrPtr = malloc(sizeof(Scalar) * countX); assert_non_null(*dataArrPtr); for (i = 0; i < countX; i++) { if (i % SX) { (*dataArrPtr)[i] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArrPtr)[i] = nextSignedRandFlPt(); #else (*dataArrPtr)[i] = nextSignedRandInt(); #endif } } break; case 2: countX = BLOCK_SIDE_LEN * SX; countY = SY / SX; *dataArrPtr = malloc(sizeof(Scalar) * countX * countY); assert_non_null(*dataArrPtr); for (j = 0; j < countY; j++) { for (i = 0; i < countX; i++) { size_t index = countX*j + i; if (i % (countX/BLOCK_SIDE_LEN) || j % (countY/BLOCK_SIDE_LEN)) { (*dataArrPtr)[index] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArrPtr)[index] = nextSignedRandFlPt(); #else (*dataArrPtr)[index] = nextSignedRandInt(); #endif } } } break; case 3: countX = BLOCK_SIDE_LEN * SX; countY = SY / SX; countZ = SZ / SY; *dataArrPtr = malloc(sizeof(Scalar) * countX * countY * countZ); assert_non_null(*dataArrPtr); for (k = 0; k < countZ; k++) { for (j = 0; j < countY; j++) { for (i = 0; i < countX; i++) { size_t index = countX*countY*k + countX*j + i; if (i % (countX/BLOCK_SIDE_LEN) || j % (countY/BLOCK_SIDE_LEN) || k % (countZ/BLOCK_SIDE_LEN)) { (*dataArrPtr)[index] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArrPtr)[index] = nextSignedRandFlPt(); #else (*dataArrPtr)[index] = nextSignedRandInt(); #endif } } } } break; case 4: countX = BLOCK_SIDE_LEN * SX; countY = SY / SX; countZ = SZ / SY; countW = SW / SZ; *dataArrPtr = malloc(sizeof(Scalar) * countX * countY * countZ * countW); assert_non_null(*dataArrPtr); for (l = 0; l < countW; l++) { for (k = 0; k < countZ; k++) { for (j = 0; j < countY; j++) { for (i = 0; i < countX; i++) { size_t index = countX*countY*countZ*l + countX*countY*k + countX*j + i; if (i % (countX/BLOCK_SIDE_LEN) || j % (countY/BLOCK_SIDE_LEN) || k % (countZ/BLOCK_SIDE_LEN) || l % (countW/BLOCK_SIDE_LEN)) { (*dataArrPtr)[index] = dummyVal; } else { #ifdef FL_PT_DATA (*dataArrPtr)[index] = nextSignedRandFlPt(); #else (*dataArrPtr)[index] = nextSignedRandInt(); #endif } } } } } break; } } static void setupZfpStream(struct setupVars* bundle) { memset(bundle->dimLens, 0, sizeof(bundle->dimLens)); #if DIMS >= 1 bundle->dimLens[0] = BLOCK_SIDE_LEN; #endif #if DIMS >= 2 bundle->dimLens[1] = BLOCK_SIDE_LEN; #endif #if DIMS >= 3 bundle->dimLens[2] = BLOCK_SIDE_LEN; #endif #if DIMS >= 4 bundle->dimLens[3] = BLOCK_SIDE_LEN; #endif size_t* n = bundle->dimLens; zfp_type type = ZFP_TYPE; zfp_field* field; switch(DIMS) { case 1: field = zfp_field_1d(bundle->dataArr, type, n[0]); zfp_field_set_stride_1d(field, SX); break; case 2: field = zfp_field_2d(bundle->dataArr, type, n[0], n[1]); zfp_field_set_stride_2d(field, SX, SY); break; case 3: field = zfp_field_3d(bundle->dataArr, type, n[0], n[1], n[2]); zfp_field_set_stride_3d(field, SX, SY, SZ); break; case 4: field = zfp_field_4d(bundle->dataArr, type, n[0], n[1], n[2], n[3]); zfp_field_set_stride_4d(field, SX, SY, SZ, SW); break; } zfp_stream* stream = zfp_stream_open(NULL); zfp_stream_set_rate(stream, ZFP_RATE_PARAM_BITS, type, DIMS, zfp_false); size_t bufsizeBytes = zfp_stream_maximum_size(stream, field); char* buffer = calloc(bufsizeBytes, sizeof(char)); assert_non_null(buffer); bitstream* s = stream_open(buffer, bufsizeBytes); assert_non_null(s); zfp_stream_set_bit_stream(stream, s); zfp_stream_rewind(stream); zfp_field_free(field); bundle->buffer = buffer; bundle->stream = stream; } static int setup(void **state) { struct setupVars *bundle = malloc(sizeof(struct setupVars)); assert_non_null(bundle); resetRandGen(); initializeStridedArray(&bundle->dataArr, DUMMY_VAL); setupZfpStream(bundle); *state = bundle; return 0; } static int teardown(void **state) { struct setupVars *bundle = *state; stream_close(bundle->stream->stream); zfp_stream_close(bundle->stream); free(bundle->buffer); free(bundle->dataArr); free(bundle); return 0; } size_t encodeBlockStrided(zfp_stream* stream, Scalar* dataArr) { size_t numBitsWritten; switch (DIMS) { case 1: numBitsWritten = _t2(zfp_encode_block_strided, Scalar, 1)(stream, dataArr, SX); break; case 2: numBitsWritten = _t2(zfp_encode_block_strided, Scalar, 2)(stream, dataArr, SX, SY); break; case 3: numBitsWritten = _t2(zfp_encode_block_strided, Scalar, 3)(stream, dataArr, SX, SY, SZ); break; case 4: numBitsWritten = _t2(zfp_encode_block_strided, Scalar, 4)(stream, dataArr, SX, SY, SZ, SW); break; } return numBitsWritten; } size_t encodePartialBlockStrided(zfp_stream* stream, Scalar* dataArr) { size_t numBitsWritten; switch (DIMS) { case 1: numBitsWritten = _t2(zfp_encode_partial_block_strided, Scalar, 1)(stream, dataArr, PX, SX); break; case 2: numBitsWritten = _t2(zfp_encode_partial_block_strided, Scalar, 2)(stream, dataArr, PX, PY, SX, SY); break; case 3: numBitsWritten = _t2(zfp_encode_partial_block_strided, Scalar, 3)(stream, dataArr, PX, PY, PZ, SX, SY, SZ); break; case 4: numBitsWritten = _t2(zfp_encode_partial_block_strided, Scalar, 4)(stream, dataArr, PX, PY, PZ, PW, SX, SY, SZ, SW); break; } return numBitsWritten; } static void when_seededRandomDataGenerated_expect_ChecksumMatches(void **state) { struct setupVars *bundle = *state; ptrdiff_t s[4] = {SX, SY, SZ, SW}; size_t n[4]; int i; for (i = 0; i < 4; i++) { n[i] = (i < DIMS) ? BLOCK_SIDE_LEN : 0; } UInt checksum = _catFunc2(hashStridedArray, SCALAR_BITS)((const UInt*)bundle->dataArr, n, s); uint64 key1, key2; computeKeyOriginalInput(BLOCK_FULL_TEST, bundle->dimLens, &key1, &key2); // entire block is populated, but later tests restrict to reading partial block ASSERT_EQ_CHECKSUM(DIMS, ZFP_TYPE, checksum, key1, key2); } static void _catFunc3(given_, DIM_INT_STR, Block_when_EncodeBlockStrided_expect_ReturnValReflectsNumBitsWrittenToBitstream)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; bitstream* s = zfp_stream_bit_stream(stream); size_t returnValBits = encodeBlockStrided(stream, bundle->dataArr); // do not flush, otherwise extra zeros included in count assert_int_equal(returnValBits, stream_wtell(s)); } static void _catFunc3(given_, DIM_INT_STR, Block_when_EncodeBlockStrided_expect_OnlyStridedEntriesUsed)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; bitstream* s = zfp_stream_bit_stream(stream); // encode original block encodeBlockStrided(stream, bundle->dataArr); zfp_stream_flush(stream); uint64 originalChecksum = hashBitstream(stream_data(s), stream_size(s)); // zero bitstream's memory size_t writtenBits = stream_wtell(s); stream_rewind(s); stream_pad(s, (uint)writtenBits); stream_rewind(s); // tweak non-strided (unused) entries resetRandGen(); free(bundle->dataArr); initializeStridedArray(&bundle->dataArr, DUMMY_VAL + 1); // encode new block encodeBlockStrided(stream, bundle->dataArr); zfp_stream_flush(stream); uint64 newChecksum = hashBitstream(stream_data(s), stream_size(s)); // do not use ASSERT_CHECKSUM macro because both always computed locally assert_int_equal(newChecksum, originalChecksum); } static void _catFunc3(given_, DIM_INT_STR, Block_when_EncodeBlockStrided_expect_BitstreamChecksumMatches)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; bitstream* s = zfp_stream_bit_stream(stream); encodeBlockStrided(stream, bundle->dataArr); zfp_stream_flush(stream); uint64 checksum = hashBitstream(stream_data(s), stream_size(s)); uint64 key1, key2; computeKey(BLOCK_FULL_TEST, COMPRESSED_BITSTREAM, bundle->dimLens, zfp_mode_fixed_rate, 0, &key1, &key2); ASSERT_EQ_CHECKSUM(DIMS, ZFP_TYPE, checksum, key1, key2); } static void _catFunc3(given_, DIM_INT_STR, Block_when_EncodePartialBlockStrided_expect_ReturnValReflectsNumBitsWrittenToBitstream)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; bitstream* s = zfp_stream_bit_stream(stream); size_t returnValBits = encodePartialBlockStrided(stream, bundle->dataArr); // do not flush, otherwise extra zeros included in count assert_int_equal(returnValBits, stream_wtell(s)); } static void _catFunc3(given_, DIM_INT_STR, Block_when_EncodePartialBlockStrided_expect_OnlyStridedEntriesUsed)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; bitstream* s = zfp_stream_bit_stream(stream); // encode original block encodePartialBlockStrided(stream, bundle->dataArr); zfp_stream_flush(stream); uint64 originalChecksum = hashBitstream(stream_data(s), stream_size(s)); // zero bitstream's memory size_t writtenBits = stream_wtell(s); stream_rewind(s); stream_pad(s, (uint)writtenBits); stream_rewind(s); // tweak non-strided (unused) entries resetRandGen(); free(bundle->dataArr); initializeStridedArray(&bundle->dataArr, DUMMY_VAL + 1); // encode new block encodePartialBlockStrided(stream, bundle->dataArr); zfp_stream_flush(stream); uint64 newChecksum = hashBitstream(stream_data(s), stream_size(s)); // do not use ASSERT_CHECKSUM macro because both always computed locally assert_int_equal(newChecksum, originalChecksum); } static void _catFunc3(given_, DIM_INT_STR, Block_when_EncodePartialBlockStrided_expect_OnlyEntriesWithinPartialBlockBoundsUsed)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; bitstream* s = zfp_stream_bit_stream(stream); // encode original block encodePartialBlockStrided(stream, bundle->dataArr); zfp_stream_flush(stream); uint64 originalChecksum = hashBitstream(stream_data(s), stream_size(s)); // zero bitstream's memory size_t writtenBits = stream_wtell(s); stream_rewind(s); stream_pad(s, (uint)writtenBits); stream_rewind(s); // tweak block entries outside partial block subset // block entry (i, j, k, l) size_t i, j, k, l; switch(DIMS) { case 1: for (i = PX; i < BLOCK_SIDE_LEN; i++) { bundle->dataArr[SX*i] = DUMMY_VAL; } break; case 2: for (j = 0; j < BLOCK_SIDE_LEN; j++) { for (i = 0; i < BLOCK_SIDE_LEN; i++) { if (i >= PX || j >= PY) { bundle->dataArr[SY*j + SX*i] = DUMMY_VAL; } } } break; case 3: for (k = 0; k < BLOCK_SIDE_LEN; k++) { for (j = 0; j < BLOCK_SIDE_LEN; j++) { for (i = 0; i < BLOCK_SIDE_LEN; i++) { if (i >= PX || j >= PY || k >= PZ) { bundle->dataArr[SZ*k + SY*j + SX*i] = DUMMY_VAL; } } } } break; case 4: for (l = 0; l < BLOCK_SIDE_LEN; l++) { for (k = 0; k < BLOCK_SIDE_LEN; k++) { for (j = 0; j < BLOCK_SIDE_LEN; j++) { for (i = 0; i < BLOCK_SIDE_LEN; i++) { if (i >= PX || j >= PY || k >= PZ) { bundle->dataArr[SW*l + SZ*k + SY*j + SX*i] = DUMMY_VAL; } } } } } break; } // encode new block encodePartialBlockStrided(stream, bundle->dataArr); zfp_stream_flush(stream); uint64 newChecksum = hashBitstream(stream_data(s), stream_size(s)); // do not use ASSERT_CHECKSUM macro because both always computed locally assert_int_equal(newChecksum, originalChecksum); } static void _catFunc3(given_, DIM_INT_STR, Block_when_EncodePartialBlockStrided_expect_BitstreamChecksumMatches)(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; bitstream* s = zfp_stream_bit_stream(stream); encodePartialBlockStrided(stream, bundle->dataArr); zfp_stream_flush(stream); uint64 checksum = hashBitstream(stream_data(s), stream_size(s)); uint64 key1, key2; computeKey(BLOCK_PARTIAL_TEST, COMPRESSED_BITSTREAM, bundle->dimLens, zfp_mode_fixed_rate, 0, &key1, &key2); ASSERT_EQ_CHECKSUM(DIMS, ZFP_TYPE, checksum, key1, key2); } zfp-1.0.1/tests/src/endtoend/000077500000000000000000000000001453723256400160545ustar00rootroot00000000000000zfp-1.0.1/tests/src/endtoend/CMakeLists.txt000066400000000000000000000046611453723256400206230ustar00rootroot00000000000000function(zfp_add_test dims type bits) if(NOT DEFINED ZFP_OMP_TESTS_ONLY) set(serial_test_name testZfpSerial${dims}d${type}) add_executable(${serial_test_name} ${serial_test_name}.c) target_link_libraries(${serial_test_name} cmocka zfp zfpHashLib genSmoothRandNumsLib stridedOperationsLib zfpChecksumsLib zfpCompressionParamsLib zfpTimerLib) if(HAVE_LIBM_MATH) target_link_libraries(${serial_test_name} m) endif() target_compile_definitions(${serial_test_name} PRIVATE ${zfp_private_defs}) if(PRINT_CHECKSUMS) target_compile_definitions(${serial_test_name} PUBLIC PRINT_CHECKSUMS) endif() add_test(NAME ${serial_test_name} COMMAND ${serial_test_name}) endif() if(ZFP_WITH_OPENMP) set(omp_test_name testZfpOmp${dims}d${type}) add_executable(${omp_test_name} ${omp_test_name}.c) target_compile_definitions(${omp_test_name} PRIVATE ${zfp_private_defs}) target_link_libraries(${omp_test_name} cmocka zfp zfpHashLib genSmoothRandNumsLib stridedOperationsLib zfpChecksumsLib zfpTimerLib zfpCompressionParamsLib OpenMP::OpenMP_C) if(HAVE_LIBM_MATH) target_link_libraries(${omp_test_name} m) endif() add_test(NAME ${omp_test_name} COMMAND ${omp_test_name}) set_property(TEST ${omp_test_name} PROPERTY RUN_SERIAL TRUE) endif() if(NOT DEFINED ZFP_OMP_TESTS_ONLY) if(ZFP_WITH_CUDA) add_definitions(-DZFP_WITH_CUDA) set(cuda_test_name testZfpCuda${dims}d${type}) add_executable(${cuda_test_name} ${cuda_test_name}.c) target_compile_definitions(${cuda_test_name} PRIVATE ${zfp_private_defs}) target_link_libraries(${cuda_test_name} cmocka zfp zfpHashLib genSmoothRandNumsLib stridedOperationsLib zfpChecksumsLib zfpTimerLib zfpCompressionParamsLib) if(HAVE_LIBM_MATH) target_link_libraries(${cuda_test_name} m) endif() add_test(NAME ${cuda_test_name} COMMAND ${cuda_test_name}) set_property(TEST ${cuda_test_name} PROPERTY RUN_SERIAL TRUE) endif() endif() endfunction() zfp_add_test(1 Int32 32) zfp_add_test(1 Int64 64) zfp_add_test(2 Int32 32) zfp_add_test(2 Int64 64) zfp_add_test(3 Int32 32) zfp_add_test(3 Int64 64) zfp_add_test(4 Int32 32) zfp_add_test(4 Int64 64) zfp_add_test(1 Float 32) zfp_add_test(1 Double 64) zfp_add_test(2 Float 32) zfp_add_test(2 Double 64) zfp_add_test(3 Float 32) zfp_add_test(3 Double 64) zfp_add_test(4 Float 32) zfp_add_test(4 Double 64) zfp-1.0.1/tests/src/endtoend/cudaExecBase.c000066400000000000000000000123731453723256400205420ustar00rootroot00000000000000#ifdef ZFP_WITH_CUDA #include #define PREPEND_CUDA(x) Cuda_ ## x #define DESCRIPTOR_INTERMEDIATE(x) PREPEND_CUDA(x) #define DESCRIPTOR DESCRIPTOR_INTERMEDIATE(DIM_INT_STR) #define ZFP_TEST_CUDA #include "zfpEndtoendBase.c" // cuda entry functions static void _catFunc3(given_, DESCRIPTOR, ReversedArray_when_ZfpCompressDecompressFixedRate_expect_BitstreamAndArrayChecksumsMatch)(void **state) { struct setupVars *bundle = *state; if (bundle->stride != REVERSED) { fail_msg("Invalid stride during test"); } runCompressDecompressTests(state, zfp_mode_fixed_rate, 1); } static void _catFunc3(given_, DESCRIPTOR, PermutedArray_when_ZfpCompressDecompressFixedRate_expect_BitstreamAndArrayChecksumsMatch)(void **state) { struct setupVars *bundle = *state; if (bundle->stride != PERMUTED) { fail_msg("Invalid stride during test"); } runCompressDecompressTests(state, zfp_mode_fixed_rate, 1); } // returns 0 on success, 1 on test failure static int runZfpCompressDecompressIsNoop(void **state) { struct setupVars *bundle = *state; zfp_field* field = bundle->field; zfp_stream* stream = bundle->stream; bitstream* s = zfp_stream_bit_stream(stream); // grab bitstream member vars bitstream_count bits = s->bits; bitstream_word buffer = s->buffer; bitstream_word* ptr = s->ptr; size_t streamSize = stream_size(s); // perform compression, expect bitstream not to advance if (zfp_compress(stream, field) != streamSize) { printf("Compression advanced the bitstream when expected to be a no-op\n"); return 1; } // expect bitstream untouched if ((s->bits != bits) || (s->buffer != buffer) || (s->ptr != ptr) || (*s->ptr != *ptr)) { printf("Compression modified the bitstream when expected to be a no-op\n"); return 1; } // perform decompression, expect bitstream not to advance if (zfp_decompress(stream, field) != streamSize) { printf("Decompression advanced the bitstream when expected to be a no-op\n"); return 1; } // expect bitstream untouched if ((s->bits != bits) || (s->buffer != buffer) || (s->ptr != ptr) || (*s->ptr != *ptr)) { printf("Decompression modified the bitstream when expected to be a no-op\n"); return 1; } return 0; } static void runCompressDecompressNoopTest(void **state, zfp_mode mode) { struct setupVars *bundle = *state; if (setupCompressParam(bundle, mode, 1) == 1) { fail_msg("ERROR while setting zfp mode"); } if (runZfpCompressDecompressIsNoop(state) == 1) { fail_msg("Compression/Decompression no-op test failed"); } } static void _catFunc3(given_, DESCRIPTOR, InterleavedArray_when_ZfpCompressDecompressFixedRate_expect_BitstreamUntouchedAndReturnsZero)(void **state) { struct setupVars *bundle = *state; if (bundle->stride != INTERLEAVED) { fail_msg("Invalid stride during test"); } runCompressDecompressNoopTest(state, zfp_mode_fixed_rate); } static void _catFunc3(given_, DESCRIPTOR, Array_when_ZfpCompressDecompressFixedRate_expect_BitstreamAndArrayChecksumsMatch)(void **state) { runCompressDecompressTests(state, zfp_mode_fixed_rate, 3); } // cover all non=fixed-rate modes (except expert) static void _catFunc3(given_, DESCRIPTOR, Array_when_ZfpCompressDecompressNonFixedRate_expect_BitstreamUntouchedAndReturnsZero)(void **state) { struct setupVars *bundle = *state; // loop over fixed prec, fixed acc, reversible zfp_mode mode; int failures = 0; for (mode = zfp_mode_fixed_precision; mode <= zfp_mode_reversible; mode++) { zfp_type type = zfp_field_type(bundle->field); if ((mode == zfp_mode_fixed_accuracy) && (type == zfp_type_int32 || type == zfp_type_int64)) { // skip fixed accuracy when unsupported continue; } if (setupCompressParam(bundle, mode, 1) == 1) { failures++; continue; } if (runZfpCompressDecompressIsNoop(state) == 1) { failures++; } } if (failures > 0) { fail_msg("Compression/Decompression no-op test failed\n"); } } static void _catFunc3(given_, DESCRIPTOR, InterleavedArray_when_ZfpCompressFixedRate_expect_BitstreamUntouchedAndReturnsZero)(void **state) { struct setupVars *bundle = *state; if (bundle->stride != INTERLEAVED) { fail_msg("Invalid stride during test"); } else if (zfp_stream_compression_mode(bundle->stream) != zfp_mode_fixed_rate) { fail_msg("Invalid zfp mode during test"); } runCompressDecompressNoopTest(state, zfp_mode_fixed_rate); } #if DIMS == 4 static void _catFunc3(given_Cuda_, DIM_INT_STR, Array_when_ZfpCompressDecompress_expect_BitstreamUntouchedAndReturnsZero)(void **state) { runCompressDecompressNoopTest(state, zfp_mode_fixed_rate); } #endif /* setup functions */ static int setupCudaConfig(void **state, stride_config stride) { int result = initZfpStreamAndField(state, stride); struct setupVars *bundle = *state; assert_int_equal(zfp_stream_set_execution(bundle->stream, zfp_exec_cuda), 1); return result; } static int setupPermuted(void **state) { return setupCudaConfig(state, PERMUTED); } static int setupInterleaved(void **state) { return setupCudaConfig(state, INTERLEAVED); } static int setupReversed(void **state) { return setupCudaConfig(state, REVERSED); } static int setupDefaultStride(void **state) { return setupCudaConfig(state, AS_IS); } #endif zfp-1.0.1/tests/src/endtoend/ompExecBase.c000066400000000000000000000132701453723256400204160ustar00rootroot00000000000000#ifdef _OPENMP #include #include #define PREPEND_OPENMP(x) OpenMP_ ## x #define DESCRIPTOR_INTERMEDIATE(x) PREPEND_OPENMP(x) #define DESCRIPTOR DESCRIPTOR_INTERMEDIATE(DIM_INT_STR) #define ZFP_TEST_OMP #include "zfpEndtoendBase.c" static size_t computeTotalBlocks(zfp_field* field) { size_t bx = 1; size_t by = 1; size_t bz = 1; size_t bw = 1; switch (zfp_field_dimensionality(field)) { case 4: bw = (field->nw + 3) / 4; case 3: bz = (field->nz + 3) / 4; case 2: by = (field->ny + 3) / 4; case 1: bx = (field->nx + 3) / 4; return bx * by * bz * bw; } return 0; } /* returns actual chunk size (in blocks), not the parameter stored (zero implies failure) */ static uint setChunkSize(void **state, uint threadCount, int param) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; uint chunk_size = 0; switch (param) { case 2: // largest chunk size: total num blocks chunk_size = (uint)computeTotalBlocks(bundle->field); break; case 1: // smallest chunk size: 1 block chunk_size = 1u; break; case 0: // default chunk size (0 implies 1 chunk per thread) chunk_size = (uint)((computeTotalBlocks(bundle->field) + threadCount - 1) / threadCount); break; default: printf("Unsupported chunkParam\n"); return 0; } if (chunk_size == 0) { printf("Chunk size was computed to be 0 blocks\n"); return 0; } else if (zfp_stream_set_omp_chunk_size(stream, chunk_size) == 0) { printf("zfp_stream_set_omp_chunk_size(stream, %u) failed (returned 0)\n", chunk_size); return 0; } return chunk_size; } static uint setThreadCount(struct setupVars *bundle, int param) { zfp_stream* stream = bundle->stream; uint threadParam = (uint)param; uint actualThreadCount = threadParam ? threadParam : omp_get_max_threads(); if (zfp_stream_set_omp_threads(stream, threadParam) == 0) { return 0; } else { return actualThreadCount; } } // OpenMP endtoend entry functions // pass doDecompress=0 because decompression not yet supported // loop across 3 compression parameters // returns 0 on success, 1 on test failure static int runCompressAcrossThreadsChunks(void **state, zfp_mode mode) { struct setupVars *bundle = *state; int failures = 0; int threadParam, chunkParam; // run across 3 thread counts for (threadParam = 0; threadParam < 3; threadParam++) { uint threadCount = setThreadCount(bundle, threadParam); if (threadCount == 0) { printf("Threadcount was 0\n"); failures += 3; continue; } else { printf("\t\tThread count: %u\n", threadCount); } for (chunkParam = 0; chunkParam < 3; chunkParam++) { uint chunkSize = setChunkSize(state, threadCount, chunkParam); if (chunkSize == 0) { printf("ERROR: Computed chunk size was 0 blocks\n"); failures++; continue; } else { printf("\t\t\tChunk size: %u blocks\n", chunkSize); } int numCompressParams = (mode == zfp_mode_reversible) ? 1 : 3; failures += runCompressDecompressAcrossParamsGivenMode(state, 0, mode, numCompressParams); } } if (failures > 0) { fail_msg("Overall compress/decompress test failure\n"); } return failures > 0; } static void _catFunc3(given_, DESCRIPTOR, Array_when_ZfpCompressFixedPrecision_expect_BitstreamChecksumsMatch)(void **state) { runCompressAcrossThreadsChunks(state, zfp_mode_fixed_precision); } static void _catFunc3(given_, DESCRIPTOR, Array_when_ZfpCompressFixedRate_expect_BitstreamChecksumsMatch)(void **state) { runCompressAcrossThreadsChunks(state, zfp_mode_fixed_rate); } #ifdef FL_PT_DATA static void _catFunc3(given_, DESCRIPTOR, Array_when_ZfpCompressFixedAccuracy_expect_BitstreamChecksumsMatch)(void **state) { runCompressAcrossThreadsChunks(state, zfp_mode_fixed_accuracy); } #endif static void _catFunc3(given_, DESCRIPTOR, Array_when_ZfpCompressReversible_expect_BitstreamChecksumsMatch)(void **state) { runCompressAcrossThreadsChunks(state, zfp_mode_reversible); } static void _catFunc3(given_, DESCRIPTOR, ReversedArray_when_ZfpCompressFixedPrecision_expect_BitstreamChecksumsMatch)(void **state) { struct setupVars *bundle = *state; if (bundle->stride != REVERSED) { fail_msg("Invalid stride during test"); } runCompressAcrossThreadsChunks(state, zfp_mode_fixed_precision); } static void _catFunc3(given_, DESCRIPTOR, InterleavedArray_when_ZfpCompressFixedPrecision_expect_BitstreamChecksumsMatch)(void **state) { struct setupVars *bundle = *state; if (bundle->stride != INTERLEAVED) { fail_msg("Invalid stride during test"); } runCompressAcrossThreadsChunks(state, zfp_mode_fixed_precision); } static void _catFunc3(given_, DESCRIPTOR, PermutedArray_when_ZfpCompressFixedPrecision_expect_BitstreamChecksumsMatch)(void **state) { struct setupVars *bundle = *state; if (bundle->stride != PERMUTED) { fail_msg("Invalid stride during test"); } runCompressAcrossThreadsChunks(state, zfp_mode_fixed_precision); } /* setup functions (pre-test) */ static int setupOmpConfig(void **state, stride_config stride) { int result = initZfpStreamAndField(state, stride); struct setupVars *bundle = *state; assert_int_equal(zfp_stream_set_execution(bundle->stream, zfp_exec_omp), 1); return result; } /* entry functions */ static int setupPermuted(void **state) { return setupOmpConfig(state, PERMUTED); } static int setupInterleaved(void **state) { return setupOmpConfig(state, INTERLEAVED); } static int setupReversed(void **state) { return setupOmpConfig(state, REVERSED); } static int setupDefaultStride(void **state) { return setupOmpConfig(state, AS_IS); } // end #ifdef _OPENMP #endif zfp-1.0.1/tests/src/endtoend/serialExecBase.c000066400000000000000000000212611453723256400211010ustar00rootroot00000000000000#define DESCRIPTOR DIM_INT_STR #define ZFP_TEST_SERIAL #include "zfpEndtoendBase.c" // entry functions static void _catFunc3(given_, DESCRIPTOR, Array_when_ZfpCompressDecompressFixedPrecision_expect_BitstreamAndArrayChecksumsMatch)(void **state) { runCompressDecompressTests(state, zfp_mode_fixed_precision, 3); } static void _catFunc3(given_, DESCRIPTOR, Array_when_ZfpCompressDecompressFixedRate_expect_BitstreamAndArrayChecksumsMatch)(void **state) { runCompressDecompressTests(state, zfp_mode_fixed_rate, 3); } #ifdef FL_PT_DATA static void _catFunc3(given_, DESCRIPTOR, Array_when_ZfpCompressDecompressFixedAccuracy_expect_BitstreamAndArrayChecksumsMatch)(void **state) { runCompressDecompressTests(state, zfp_mode_fixed_accuracy, 3); } #endif static void _catFunc3(given_, DESCRIPTOR, Array_when_ZfpCompressDecompressReversible_expect_BitstreamAndArrayChecksumsMatch)(void **state) { struct setupVars *bundle = *state; if (setupCompressParam(bundle, zfp_mode_reversible, 0) == 1) { fail_msg("ERROR setting zfp mode"); } runCompressDecompressReversible(bundle, 1); } static void _catFunc3(given_, DESCRIPTOR, ReversedArray_when_ZfpCompressDecompressFixedPrecision_expect_BitstreamAndArrayChecksumsMatch)(void **state) { struct setupVars *bundle = *state; if (bundle->stride != REVERSED) { fail_msg("Invalid stride during test"); } runCompressDecompressTests(state, zfp_mode_fixed_precision, 1); } static void _catFunc3(given_, DESCRIPTOR, InterleavedArray_when_ZfpCompressDecompressFixedPrecision_expect_BitstreamAndArrayChecksumsMatch)(void **state) { struct setupVars *bundle = *state; if (bundle->stride != INTERLEAVED) { fail_msg("Invalid stride during test"); } runCompressDecompressTests(state, zfp_mode_fixed_precision, 1); } static void _catFunc3(given_, DESCRIPTOR, PermutedArray_when_ZfpCompressDecompressFixedPrecision_expect_BitstreamAndArrayChecksumsMatch)(void **state) { struct setupVars *bundle = *state; if (bundle->stride != PERMUTED) { fail_msg("Invalid stride during test"); } runCompressDecompressTests(state, zfp_mode_fixed_precision, 1); } static void _catFunc3(given_, DESCRIPTOR, ZfpStream_when_SetRateWithWriteRandomAccess_expect_RateRoundedUpProperly)(void **state) { zfp_stream* zfp = zfp_stream_open(NULL); // align currently requires blocks to start at the beginning of a word // rate will be rounded up such that a block fills the rest of the word // (would be wasted space otherwise, padded with zeros) double rateWithoutAlign = zfp_stream_set_rate(zfp, ZFP_RATE_PARAM_BITS, ZFP_TYPE, DIMS, zfp_false); double rateWithAlign = zfp_stream_set_rate(zfp, ZFP_RATE_PARAM_BITS, ZFP_TYPE, DIMS, zfp_true); if (!(rateWithAlign >= rateWithoutAlign)) { fail_msg("rateWithAlign (%lf) >= rateWithoutAlign (%lf) failed\n", rateWithAlign, rateWithoutAlign); } uint bitsPerBlock = (uint)floor(rateWithAlign * intPow(4, DIMS) + 0.5); assert_int_equal(0, bitsPerBlock % stream_word_bits); zfp_stream_close(zfp); } // returns 0 on success, 1 on test failure static int isCompressedBitrateComparableToChosenRate(struct setupVars* bundle) { zfp_field* field = bundle->field; zfp_stream* stream = bundle->stream; // integer arithmetic allows exact comparison size_t compressedBytes = zfp_compress(stream, field); if (compressedBytes == 0) { printf("Compression failed\n"); return 1; } size_t compressedBits = compressedBytes * 8; // compute padded lengths (multiples of block-side-len, 4) size_t paddedNx = (bundle->randomGenArrSideLen[0] + 3) & ~0x3; size_t paddedNy = (bundle->randomGenArrSideLen[1] + 3) & ~0x3; size_t paddedNz = (bundle->randomGenArrSideLen[2] + 3) & ~0x3; size_t paddedNw = (bundle->randomGenArrSideLen[3] + 3) & ~0x3; size_t paddedArrayLen = 1; switch (DIMS) { case 4: paddedArrayLen *= paddedNw; case 3: paddedArrayLen *= paddedNz; case 2: paddedArrayLen *= paddedNy; case 1: paddedArrayLen *= paddedNx; } // expect bitrate to scale wrt padded array length size_t expectedTotalBits = bundle->rateParam * paddedArrayLen; // account for zfp_compress() ending with stream_flush() expectedTotalBits = (expectedTotalBits + stream_word_bits - 1) & ~(stream_word_bits - 1); if(compressedBits != expectedTotalBits) { printf("compressedBits (%lu) == expectedTotalBits (%lu) failed, given fixed-rate %zu\n", (unsigned long)compressedBits, (unsigned long)expectedTotalBits, bundle->rateParam); return 1; } else { return 0; } } static void _catFunc3(given_, DESCRIPTOR, Array_when_ZfpCompressFixedRate_expect_CompressedBitrateComparableToChosenRate)(void **state) { struct setupVars *bundle = *state; int failures = 0; int compressParam; for (compressParam = 0; compressParam < 3; compressParam++) { if (setupCompressParam(bundle, zfp_mode_fixed_rate, compressParam) == 1) { failures++; continue; } failures += isCompressedBitrateComparableToChosenRate(bundle); zfp_stream_rewind(bundle->stream); memset(bundle->buffer, 0, bundle->bufsizeBytes); } if (failures > 0) { fail_msg("Compressed bitrate test failure\n"); } } #ifdef FL_PT_DATA // returns 0 on all tests pass, 1 on test failure static int isCompressedValuesWithinAccuracy(struct setupVars* bundle) { zfp_field* field = bundle->field; zfp_stream* stream = bundle->stream; size_t compressedBytes = zfp_compress(stream, field); if (compressedBytes == 0) { printf("Compression failed\n"); return 1; } // zfp_decompress() will write to bundle->decompressedArr // assert bitstream ends in same location zfp_stream_rewind(stream); size_t result = zfp_decompress(stream, bundle->decompressField); if (result != compressedBytes) { printf("Decompression advanced the bitstream to a different position than after compression: %zu != %zu\n", result, compressedBytes); return 1; } ptrdiff_t strides[4]; zfp_field_stride(field, strides); // apply strides ptrdiff_t offset = 0; size_t* n = bundle->randomGenArrSideLen; float maxDiffF = 0; double maxDiffD = 0; size_t i, j, k, l; for (l = (n[3] ? n[3] : 1); l--; offset += strides[3] - n[2]*strides[2]) { for (k = (n[2] ? n[2] : 1); k--; offset += strides[2] - n[1]*strides[1]) { for (j = (n[1] ? n[1] : 1); j--; offset += strides[1] - n[0]*strides[0]) { for (i = (n[0] ? n[0] : 1); i--; offset += strides[0]) { float absDiffF; double absDiffD; switch(ZFP_TYPE) { case zfp_type_float: absDiffF = fabsf((float)bundle->decompressedArr[offset] - (float)bundle->compressedArr[offset]); if(absDiffF > bundle->accParam) { printf("Compressed error %f was greater than supplied tolerance %lf\n", absDiffF, bundle->accParam); return 1; } if (absDiffF > maxDiffF) { maxDiffF = absDiffF; } break; case zfp_type_double: absDiffD = fabs(bundle->decompressedArr[offset] - bundle->compressedArr[offset]); if(absDiffD > bundle->accParam) { printf("Compressed error %lf was greater than supplied tolerance %lf\n", absDiffD, bundle->accParam); return 1; } if (absDiffD > maxDiffD) { maxDiffD = absDiffD; } break; default: printf("Test requires zfp_type float or double\n"); return 1; } } } } } if (ZFP_TYPE == zfp_type_float) { printf("\t\t\t\tMax abs error: %f\n", maxDiffF); } else { printf("\t\t\t\tMax abs error: %lf\n", maxDiffD); } return 0; } static void _catFunc3(given_, DESCRIPTOR, Array_when_ZfpCompressFixedAccuracy_expect_CompressedValuesWithinAccuracy)(void **state) { struct setupVars *bundle = *state; int failures = 0; int compressParam; for (compressParam = 0; compressParam < 3; compressParam++) { if (setupCompressParam(bundle, zfp_mode_fixed_accuracy, compressParam) == 1) { failures++; continue; } failures += isCompressedValuesWithinAccuracy(bundle); zfp_stream_rewind(bundle->stream); memset(bundle->buffer, 0, bundle->bufsizeBytes); } if (failures > 0) { fail_msg("Compressed value accuracy test failure\n"); } } // #endif FL_PT_DATA #endif // setup functions static int setupPermuted(void **state) { return initZfpStreamAndField(state, PERMUTED); } static int setupInterleaved(void **state) { return initZfpStreamAndField(state, INTERLEAVED); } static int setupReversed(void **state) { return initZfpStreamAndField(state, REVERSED); } static int setupDefaultStride(void **state) { return initZfpStreamAndField(state, AS_IS); } zfp-1.0.1/tests/src/endtoend/testZfpCuda1dDouble.c000066400000000000000000000003761453723256400220420ustar00rootroot00000000000000#include "src/encode1d.c" #include "constants/1dDouble.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpCuda1dFloat.c000066400000000000000000000003751453723256400216740ustar00rootroot00000000000000#include "src/encode1f.c" #include "constants/1dFloat.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpCuda1dInt32.c000066400000000000000000000003751453723256400215260ustar00rootroot00000000000000#include "src/encode1i.c" #include "constants/1dInt32.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpCuda1dInt64.c000066400000000000000000000003751453723256400215330ustar00rootroot00000000000000#include "src/encode1l.c" #include "constants/1dInt64.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpCuda2dDouble.c000066400000000000000000000003761453723256400220430ustar00rootroot00000000000000#include "src/encode2d.c" #include "constants/2dDouble.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpCuda2dFloat.c000066400000000000000000000003751453723256400216750ustar00rootroot00000000000000#include "src/encode2f.c" #include "constants/2dFloat.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpCuda2dInt32.c000066400000000000000000000003751453723256400215270ustar00rootroot00000000000000#include "src/encode2i.c" #include "constants/2dInt32.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpCuda2dInt64.c000066400000000000000000000003751453723256400215340ustar00rootroot00000000000000#include "src/encode2l.c" #include "constants/2dInt64.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpCuda3dDouble.c000066400000000000000000000003761453723256400220440ustar00rootroot00000000000000#include "src/encode3d.c" #include "constants/3dDouble.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpCuda3dFloat.c000066400000000000000000000003751453723256400216760ustar00rootroot00000000000000#include "src/encode3f.c" #include "constants/3dFloat.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpCuda3dInt32.c000066400000000000000000000003751453723256400215300ustar00rootroot00000000000000#include "src/encode3i.c" #include "constants/3dInt32.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpCuda3dInt64.c000066400000000000000000000003751453723256400215350ustar00rootroot00000000000000#include "src/encode3l.c" #include "constants/3dInt64.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpCuda4dDouble.c000066400000000000000000000003761453723256400220450ustar00rootroot00000000000000#include "src/encode4d.c" #include "constants/4dDouble.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpCuda4dFloat.c000066400000000000000000000003751453723256400216770ustar00rootroot00000000000000#include "src/encode4f.c" #include "constants/4dFloat.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpCuda4dInt32.c000066400000000000000000000003751453723256400215310ustar00rootroot00000000000000#include "src/encode4i.c" #include "constants/4dInt32.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpCuda4dInt64.c000066400000000000000000000003751453723256400215360ustar00rootroot00000000000000#include "src/encode4l.c" #include "constants/4dInt64.h" #include "cudaExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/cuda.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp1dDouble.c000066400000000000000000000003741453723256400217170ustar00rootroot00000000000000#include "src/encode1d.c" #include "constants/1dDouble.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp1dFloat.c000066400000000000000000000003731453723256400215510ustar00rootroot00000000000000#include "src/encode1f.c" #include "constants/1dFloat.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp1dInt32.c000066400000000000000000000003731453723256400214030ustar00rootroot00000000000000#include "src/encode1i.c" #include "constants/1dInt32.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp1dInt64.c000066400000000000000000000003731453723256400214100ustar00rootroot00000000000000#include "src/encode1l.c" #include "constants/1dInt64.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp2dDouble.c000066400000000000000000000003741453723256400217200ustar00rootroot00000000000000#include "src/encode2d.c" #include "constants/2dDouble.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp2dFloat.c000066400000000000000000000003731453723256400215520ustar00rootroot00000000000000#include "src/encode2f.c" #include "constants/2dFloat.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp2dInt32.c000066400000000000000000000003731453723256400214040ustar00rootroot00000000000000#include "src/encode2i.c" #include "constants/2dInt32.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp2dInt64.c000066400000000000000000000003731453723256400214110ustar00rootroot00000000000000#include "src/encode2l.c" #include "constants/2dInt64.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp3dDouble.c000066400000000000000000000003741453723256400217210ustar00rootroot00000000000000#include "src/encode3d.c" #include "constants/3dDouble.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp3dFloat.c000066400000000000000000000003731453723256400215530ustar00rootroot00000000000000#include "src/encode3f.c" #include "constants/3dFloat.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp3dInt32.c000066400000000000000000000003731453723256400214050ustar00rootroot00000000000000#include "src/encode3i.c" #include "constants/3dInt32.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp3dInt64.c000066400000000000000000000003731453723256400214120ustar00rootroot00000000000000#include "src/encode3l.c" #include "constants/3dInt64.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp4dDouble.c000066400000000000000000000003741453723256400217220ustar00rootroot00000000000000#include "src/encode4d.c" #include "constants/4dDouble.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp4dFloat.c000066400000000000000000000003731453723256400215540ustar00rootroot00000000000000#include "src/encode4f.c" #include "constants/4dFloat.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp4dInt32.c000066400000000000000000000003731453723256400214060ustar00rootroot00000000000000#include "src/encode4i.c" #include "constants/4dInt32.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpOmp4dInt64.c000066400000000000000000000003731453723256400214130ustar00rootroot00000000000000#include "src/encode4l.c" #include "constants/4dInt64.h" #include "ompExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/omp.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial1dDouble.c000066400000000000000000000004021453723256400223730ustar00rootroot00000000000000#include "src/encode1d.c" #include "constants/1dDouble.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial1dFloat.c000066400000000000000000000004011453723256400222250ustar00rootroot00000000000000#include "src/encode1f.c" #include "constants/1dFloat.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial1dInt32.c000066400000000000000000000004011453723256400220570ustar00rootroot00000000000000#include "src/encode1i.c" #include "constants/1dInt32.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial1dInt64.c000066400000000000000000000004011453723256400220640ustar00rootroot00000000000000#include "src/encode1l.c" #include "constants/1dInt64.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial2dDouble.c000066400000000000000000000004021453723256400223740ustar00rootroot00000000000000#include "src/encode2d.c" #include "constants/2dDouble.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial2dFloat.c000066400000000000000000000004011453723256400222260ustar00rootroot00000000000000#include "src/encode2f.c" #include "constants/2dFloat.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial2dInt32.c000066400000000000000000000004011453723256400220600ustar00rootroot00000000000000#include "src/encode2i.c" #include "constants/2dInt32.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial2dInt64.c000066400000000000000000000004011453723256400220650ustar00rootroot00000000000000#include "src/encode2l.c" #include "constants/2dInt64.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial3dDouble.c000066400000000000000000000004021453723256400223750ustar00rootroot00000000000000#include "src/encode3d.c" #include "constants/3dDouble.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial3dFloat.c000066400000000000000000000004011453723256400222270ustar00rootroot00000000000000#include "src/encode3f.c" #include "constants/3dFloat.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial3dInt32.c000066400000000000000000000004011453723256400220610ustar00rootroot00000000000000#include "src/encode3i.c" #include "constants/3dInt32.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial3dInt64.c000066400000000000000000000004011453723256400220660ustar00rootroot00000000000000#include "src/encode3l.c" #include "constants/3dInt64.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial4dDouble.c000066400000000000000000000004021453723256400223760ustar00rootroot00000000000000#include "src/encode4d.c" #include "constants/4dDouble.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial4dFloat.c000066400000000000000000000004011453723256400222300ustar00rootroot00000000000000#include "src/encode4f.c" #include "constants/4dFloat.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial4dInt32.c000066400000000000000000000004011453723256400220620ustar00rootroot00000000000000#include "src/encode4i.c" #include "constants/4dInt32.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testZfpSerial4dInt64.c000066400000000000000000000004011453723256400220670ustar00rootroot00000000000000#include "src/encode4l.c" #include "constants/4dInt64.h" #include "serialExecBase.c" int main() { const struct CMUnitTest tests[] = { #include "testcases/serial.c" }; return cmocka_run_group_tests(tests, setupRandomData, teardownRandomData); } zfp-1.0.1/tests/src/endtoend/testcases/000077500000000000000000000000001453723256400200525ustar00rootroot00000000000000zfp-1.0.1/tests/src/endtoend/testcases/cuda.c000066400000000000000000000027041453723256400211350ustar00rootroot00000000000000// requires #include "utils/testMacros.h", do outside of main() #if DIMS < 4 _cmocka_unit_test(when_seededRandomSmoothDataGenerated_expect_ChecksumMatches), /* strided */ /* contiguous layout supported */ _cmocka_unit_test_setup_teardown(_catFunc3(given_Cuda_, DIM_INT_STR, ReversedArray_when_ZfpCompressDecompressFixedRate_expect_BitstreamAndArrayChecksumsMatch), setupReversed, teardown), #if DIMS >= 2 _cmocka_unit_test_setup_teardown(_catFunc3(given_Cuda_, DIM_INT_STR, PermutedArray_when_ZfpCompressDecompressFixedRate_expect_BitstreamAndArrayChecksumsMatch), setupPermuted, teardown), #endif /* non-contiguous unsupported */ _cmocka_unit_test_setup_teardown(_catFunc3(given_Cuda_, DIM_INT_STR, InterleavedArray_when_ZfpCompressDecompressFixedRate_expect_BitstreamUntouchedAndReturnsZero), setupInterleaved, teardown), /* fixed-rate */ _cmocka_unit_test_setup_teardown(_catFunc3(given_Cuda_, DIM_INT_STR, Array_when_ZfpCompressDecompressFixedRate_expect_BitstreamAndArrayChecksumsMatch), setupDefaultStride, teardown), /* non fixed-rate modes unsupported */ _cmocka_unit_test_setup_teardown(_catFunc3(given_Cuda_, DIM_INT_STR, Array_when_ZfpCompressDecompressNonFixedRate_expect_BitstreamUntouchedAndReturnsZero), setupDefaultStride, teardown), #else /* 4d compression unsupported */ _cmocka_unit_test_setup_teardown(_catFunc3(given_Cuda_, DIM_INT_STR, Array_when_ZfpCompressDecompress_expect_BitstreamUntouchedAndReturnsZero), setupDefaultStride, teardown), #endif zfp-1.0.1/tests/src/endtoend/testcases/omp.c000066400000000000000000000027211453723256400210130ustar00rootroot00000000000000// requires #include "utils/testMacros.h", do outside of main() _cmocka_unit_test(when_seededRandomSmoothDataGenerated_expect_ChecksumMatches), // OpenMP decompression not yet supported /* strided tests */ _cmocka_unit_test_setup_teardown(_catFunc3(given_OpenMP_, DIM_INT_STR, ReversedArray_when_ZfpCompressFixedPrecision_expect_BitstreamChecksumsMatch), setupReversed, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_OpenMP_, DIM_INT_STR, InterleavedArray_when_ZfpCompressFixedPrecision_expect_BitstreamChecksumsMatch), setupInterleaved, teardown), #if DIMS >= 2 _cmocka_unit_test_setup_teardown(_catFunc3(given_OpenMP_, DIM_INT_STR, PermutedArray_when_ZfpCompressFixedPrecision_expect_BitstreamChecksumsMatch), setupPermuted, teardown), #endif /* non-strided tests */ _cmocka_unit_test_setup_teardown(_catFunc3(given_OpenMP_, DIM_INT_STR, Array_when_ZfpCompressFixedPrecision_expect_BitstreamChecksumsMatch), setupDefaultStride, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_OpenMP_, DIM_INT_STR, Array_when_ZfpCompressFixedRate_expect_BitstreamChecksumsMatch), setupDefaultStride, teardown), #ifdef FL_PT_DATA _cmocka_unit_test_setup_teardown(_catFunc3(given_OpenMP_, DIM_INT_STR, Array_when_ZfpCompressFixedAccuracy_expect_BitstreamChecksumsMatch), setupDefaultStride, teardown), #endif _cmocka_unit_test_setup_teardown(_catFunc3(given_OpenMP_, DIM_INT_STR, Array_when_ZfpCompressReversible_expect_BitstreamChecksumsMatch), setupDefaultStride, teardown), zfp-1.0.1/tests/src/endtoend/testcases/serial.c000066400000000000000000000040441453723256400214770ustar00rootroot00000000000000// requires #include "utils/testMacros.h", do outside of main() _cmocka_unit_test(when_seededRandomSmoothDataGenerated_expect_ChecksumMatches), #ifndef PRINT_CHECKSUMS /* strided tests */ _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, ReversedArray_when_ZfpCompressDecompressFixedPrecision_expect_BitstreamAndArrayChecksumsMatch), setupReversed, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, InterleavedArray_when_ZfpCompressDecompressFixedPrecision_expect_BitstreamAndArrayChecksumsMatch), setupInterleaved, teardown), #if DIMS >= 2 _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, PermutedArray_when_ZfpCompressDecompressFixedPrecision_expect_BitstreamAndArrayChecksumsMatch), setupPermuted, teardown), #endif #endif /* fixed-precision */ _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Array_when_ZfpCompressDecompressFixedPrecision_expect_BitstreamAndArrayChecksumsMatch), setupDefaultStride, teardown), /* fixed-rate */ _cmocka_unit_test(_catFunc3(given_, DIM_INT_STR, ZfpStream_when_SetRateWithWriteRandomAccess_expect_RateRoundedUpProperly)), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Array_when_ZfpCompressDecompressFixedRate_expect_BitstreamAndArrayChecksumsMatch), setupDefaultStride, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Array_when_ZfpCompressFixedRate_expect_CompressedBitrateComparableToChosenRate), setupDefaultStride, teardown), #ifdef FL_PT_DATA /* fixed-accuracy */ _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Array_when_ZfpCompressDecompressFixedAccuracy_expect_BitstreamAndArrayChecksumsMatch), setupDefaultStride, teardown), _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Array_when_ZfpCompressFixedAccuracy_expect_CompressedValuesWithinAccuracy), setupDefaultStride, teardown), #endif /* reversible */ _cmocka_unit_test_setup_teardown(_catFunc3(given_, DIM_INT_STR, Array_when_ZfpCompressDecompressReversible_expect_BitstreamAndArrayChecksumsMatch), setupDefaultStride, teardown), zfp-1.0.1/tests/src/endtoend/zfpEndtoendBase.c000066400000000000000000000426531453723256400213050ustar00rootroot00000000000000#include #include #include #include #include #include #include #include #include "utils/genSmoothRandNums.h" #include "utils/stridedOperations.h" #include "utils/testMacros.h" #include "utils/zfpChecksums.h" #include "utils/zfpCompressionParams.h" #include "utils/zfpHash.h" #include "utils/zfpTimer.h" #ifdef FL_PT_DATA #define MIN_TOTAL_ELEMENTS 1000000 #else #define MIN_TOTAL_ELEMENTS 4096 #endif struct setupVars { // randomly generated array // this entire dataset eventually gets compressed // its data gets copied and possibly rearranged, into compressedArr size_t randomGenArrSideLen[4]; size_t totalRandomGenArrLen; Scalar* randomGenArr; // these arrays/dims may include stride-space Scalar* compressedArr; Scalar* decompressedArr; size_t bufsizeBytes; void* buffer; // dimensions of data that gets compressed (currently same as randomGenArrSideLen) size_t dimLens[4]; zfp_field* field; zfp_field* decompressField; zfp_stream* stream; zfp_mode mode; // compressParamNum is 0, 1, or 2 // used to compute fixed mode param // and to select proper checksum to compare against int compressParamNum; size_t rateParam; int precParam; double accParam; stride_config stride; zfp_timer* timer; }; // run this once per (datatype, DIM) combination for performance static int setupRandomData(void** state) { int i; struct setupVars *bundle = calloc(1, sizeof(struct setupVars)); assert_non_null(bundle); switch (ZFP_TYPE) { #ifdef FL_PT_DATA case zfp_type_float: generateSmoothRandFloats(MIN_TOTAL_ELEMENTS, DIMS, (float**)&bundle->randomGenArr, &bundle->randomGenArrSideLen[0], &bundle->totalRandomGenArrLen); break; case zfp_type_double: generateSmoothRandDoubles(MIN_TOTAL_ELEMENTS, DIMS, (double**)&bundle->randomGenArr, &bundle->randomGenArrSideLen[0], &bundle->totalRandomGenArrLen); break; #else case zfp_type_int32: generateSmoothRandInts32(MIN_TOTAL_ELEMENTS, DIMS, 32 - 2, (int32**)&bundle->randomGenArr, &bundle->randomGenArrSideLen[0], &bundle->totalRandomGenArrLen); break; case zfp_type_int64: generateSmoothRandInts64(MIN_TOTAL_ELEMENTS, DIMS, 64 - 2, (int64**)&bundle->randomGenArr, &bundle->randomGenArrSideLen[0], &bundle->totalRandomGenArrLen); break; #endif default: fail_msg("Invalid zfp_type during setupRandomData()"); break; } assert_non_null(bundle->randomGenArr); // set remaining indices (square for now) for (i = 0; i < 4; i++) { bundle->randomGenArrSideLen[i] = (i < DIMS) ? bundle->randomGenArrSideLen[0] : 0; // for now, entire randomly generated array always entirely compressed bundle->dimLens[i] = bundle->randomGenArrSideLen[i]; } *state = bundle; return 0; } static int teardownRandomData(void** state) { struct setupVars *bundle = *state; free(bundle->randomGenArr); free(bundle); return 0; } static void setupZfpFields(struct setupVars* bundle, ptrdiff_t s[4]) { size_t* n = bundle->dimLens; // setup zfp_fields: source/destination arrays for compression/decompression zfp_type type = ZFP_TYPE; zfp_field* field; zfp_field* decompressField; switch (DIMS) { case 1: field = zfp_field_1d(bundle->compressedArr, type, n[0]); zfp_field_set_stride_1d(field, s[0]); decompressField = zfp_field_1d(bundle->decompressedArr, type, n[0]); zfp_field_set_stride_1d(decompressField, s[0]); break; case 2: field = zfp_field_2d(bundle->compressedArr, type, n[0], n[1]); zfp_field_set_stride_2d(field, s[0], s[1]); decompressField = zfp_field_2d(bundle->decompressedArr, type, n[0], n[1]); zfp_field_set_stride_2d(decompressField, s[0], s[1]); break; case 3: field = zfp_field_3d(bundle->compressedArr, type, n[0], n[1], n[2]); zfp_field_set_stride_3d(field, s[0], s[1], s[2]); decompressField = zfp_field_3d(bundle->decompressedArr, type, n[0], n[1], n[2]); zfp_field_set_stride_3d(decompressField, s[0], s[1], s[2]); break; case 4: field = zfp_field_4d(bundle->compressedArr, type, n[0], n[1], n[2], n[3]); zfp_field_set_stride_4d(field, s[0], s[1], s[2], s[3]); decompressField = zfp_field_4d(bundle->decompressedArr, type, n[0], n[1], n[2], n[3]); zfp_field_set_stride_4d(decompressField, s[0], s[1], s[2], s[3]); break; } bundle->field = field; bundle->decompressField = decompressField; } static void allocateFieldArrays(stride_config stride, size_t totalRandomGenArrLen, Scalar** compressedArrPtr, Scalar** decompressedArrPtr) { size_t totalEntireDataLen = totalRandomGenArrLen; if (stride == INTERLEAVED) totalEntireDataLen *= 2; // allocate arrays which we directly compress or decompress into *compressedArrPtr = calloc(totalEntireDataLen, sizeof(Scalar)); assert_non_null(*compressedArrPtr); *decompressedArrPtr = malloc(sizeof(Scalar) * totalEntireDataLen); assert_non_null(*decompressedArrPtr); } static void generateStridedRandomArray(stride_config stride, Scalar* randomGenArr, zfp_type type, size_t n[4], ptrdiff_t s[4], Scalar** compressedArrPtr, Scalar** decompressedArrPtr) { int dims, i; for (i = 0; i < 4; i++) { if (n[i] == 0) { break; } } dims = i; size_t totalRandomGenArrLen = 1; for (i = 0; i < dims; i++) { totalRandomGenArrLen *= n[i]; } // identify strides and produce compressedArr switch(stride) { case REVERSED: getReversedStrides(dims, n, s); reverseArray(randomGenArr, *compressedArrPtr, totalRandomGenArrLen, type); // adjust pointer to last element, so strided traverse is valid *compressedArrPtr += totalRandomGenArrLen - 1; *decompressedArrPtr += totalRandomGenArrLen - 1; break; case INTERLEAVED: getInterleavedStrides(dims, n, s); interleaveArray(randomGenArr, *compressedArrPtr, totalRandomGenArrLen, ZFP_TYPE); break; case PERMUTED: getPermutedStrides(dims, n, s); if (permuteSquareArray(randomGenArr, *compressedArrPtr, n[0], dims, type)) { fail_msg("Unexpected dims value in permuteSquareArray()"); } break; case AS_IS: // no-op memcpy(*compressedArrPtr, randomGenArr, totalRandomGenArrLen * sizeof(Scalar)); break; } } static void initStridedFields(struct setupVars* bundle, stride_config stride) { // apply stride permutations on randomGenArr, into compressedArr, which gets compressed bundle->stride = stride; allocateFieldArrays(stride, bundle->totalRandomGenArrLen, &bundle->compressedArr, &bundle->decompressedArr); ptrdiff_t s[4] = {0}; generateStridedRandomArray(stride, bundle->randomGenArr, ZFP_TYPE, bundle->randomGenArrSideLen, s, &bundle->compressedArr, &bundle->decompressedArr); setupZfpFields(bundle, s); } static void setupZfpStream(struct setupVars* bundle) { // setup zfp_stream (compression settings) zfp_stream* stream = zfp_stream_open(NULL); assert_non_null(stream); bundle->bufsizeBytes = zfp_stream_maximum_size(stream, bundle->field); char* buffer = calloc(bundle->bufsizeBytes, sizeof(char)); assert_non_null(buffer); bitstream* s = stream_open(buffer, bundle->bufsizeBytes); assert_non_null(s); zfp_stream_set_bit_stream(stream, s); zfp_stream_rewind(stream); bundle->stream = stream; bundle->buffer = buffer; } // returns 1 on failure, 0 on success static int setupCompressParam(struct setupVars* bundle, zfp_mode zfpMode, int compressParamNum) { bundle->mode = zfpMode; // set compression mode for this compressParamNum if (compressParamNum > 2 || compressParamNum < 0) { printf("ERROR: Unknown compressParamNum %d during setupCompressParam()\n", compressParamNum); return 1; } bundle->compressParamNum = compressParamNum; switch(zfpMode) { case zfp_mode_fixed_precision: bundle->precParam = computeFixedPrecisionParam(bundle->compressParamNum); zfp_stream_set_precision(bundle->stream, bundle->precParam); printf("\t\t\t\tFixed precision param: %u\n", bundle->precParam); break; case zfp_mode_fixed_rate: bundle->rateParam = computeFixedRateParam(bundle->compressParamNum); zfp_stream_set_rate(bundle->stream, (double)bundle->rateParam, ZFP_TYPE, DIMS, zfp_false); printf("\t\t\t\tFixed rate param: %lu\n", (unsigned long)bundle->rateParam); break; #ifdef FL_PT_DATA case zfp_mode_fixed_accuracy: bundle->accParam = computeFixedAccuracyParam(bundle->compressParamNum); zfp_stream_set_accuracy(bundle->stream, bundle->accParam); printf("\t\t\t\tFixed accuracy param: %lf\n", bundle->accParam); break; #endif case zfp_mode_reversible: zfp_stream_set_reversible(bundle->stream); printf("\t\t\t\tReversible mode\n"); break; default: printf("ERROR: Invalid zfp mode %d during setupCompressParam()\n", zfpMode); return 1; } return 0; } // assumes setupRandomData() already run (having set some setupVars members) static int initZfpStreamAndField(void **state, stride_config stride) { struct setupVars *bundle = *state; initStridedFields(bundle, stride); setupZfpStream(bundle); bundle->timer = zfp_timer_alloc(); *state = bundle; return 0; } // randomGenArr and the struct itself are freed in teardownRandomData() static int teardown(void **state) { struct setupVars *bundle = *state; stream_close(bundle->stream->stream); zfp_stream_close(bundle->stream); zfp_field_free(bundle->field); zfp_field_free(bundle->decompressField); free(bundle->buffer); if (bundle->stride == REVERSED) { // for convenience, we adjusted negative strided arrays to point to last element bundle->compressedArr -= bundle->totalRandomGenArrLen - 1; bundle->decompressedArr -= bundle->totalRandomGenArrLen - 1; } free(bundle->decompressedArr); free(bundle->compressedArr); zfp_timer_free(bundle->timer); return 0; } static void when_seededRandomSmoothDataGenerated_expect_ChecksumMatches(void **state) { struct setupVars *bundle = *state; UInt checksum = _catFunc2(hashArray, SCALAR_BITS)((const UInt*)bundle->randomGenArr, bundle->totalRandomGenArrLen, 1); uint64 key1, key2; computeKeyOriginalInput(ARRAY_TEST, bundle->dimLens, &key1, &key2); ASSERT_EQ_CHECKSUM(DIMS, ZFP_TYPE, checksum, key1, key2); } // returns 1 on failure, 0 on success static int runZfpCompress(zfp_stream* stream, const zfp_field* field, zfp_timer* timer, size_t* compressedBytes) { // perform compression and time it if (zfp_timer_start(timer)) { printf("ERROR: Unknown platform (none of linux, win, osx) when starting timer\n"); return 1; } *compressedBytes = zfp_compress(stream, field); double time = zfp_timer_stop(timer); printf("\t\t\t\t\tCompress time (s): %lf\n", time); if (compressedBytes == 0) { printf("ERROR: Compression failed, nothing was written to bitstream\n"); return 1; } else { return 0; } } // returns 1 on failure, 0 on success static int isCompressedBitstreamChecksumsMatch(zfp_stream* stream, bitstream* bs, size_t dimLens[4], zfp_mode mode, int compressParamNum) { uint64 checksum = hashBitstream(stream_data(bs), stream_size(bs)); uint64 key1, key2; computeKey(ARRAY_TEST, COMPRESSED_BITSTREAM, dimLens, mode, compressParamNum, &key1, &key2); if (COMPARE_NEQ_CHECKSUM(DIMS, ZFP_TYPE, checksum, key1, key2)) { printf("ERROR: Compressed bitstream checksums were different: 0x%"UINT64PRIx" != 0x%"UINT64PRIx"\n", checksum, getChecksumByKey(DIMS, ZFP_TYPE, key1, key2)); return 1; } else { return 0; } } // returns 1 on failure, 0 on success static int runZfpDecompress(zfp_stream* stream, zfp_field* decompressField, zfp_timer* timer, size_t compressedBytes) { // zfp_decompress() will write to bundle->decompressedArr // assert bitstream ends in same location if (zfp_timer_start(timer)) { printf("ERROR: Unknown platform (none of linux, win, osx)\n"); return 1; } size_t result = zfp_decompress(stream, decompressField); double time = zfp_timer_stop(timer); printf("\t\t\t\t\tDecompress time (s): %lf\n", time); if (compressedBytes != result) { printf("ERROR: Decompression advanced the bitstream to a different position than after compression: %zu != %zu\n", result, compressedBytes); return 1; } else { return 0; } } // returns 1 on failure, 0 on success static int isDecompressedArrayChecksumsMatch(struct setupVars* bundle) { zfp_field* field = bundle->field; // hash decompressedArr const UInt* arr = (const UInt*)bundle->decompressedArr; ptrdiff_t strides[4] = {0, 0, 0, 0}; zfp_field_stride(field, strides); uint64 checksum = 0; switch(bundle->stride) { case REVERSED: // arr already points to last element (so strided traverse is legal) checksum = _catFunc2(hashStridedArray, SCALAR_BITS)(arr, bundle->randomGenArrSideLen, strides); break; case INTERLEAVED: checksum = _catFunc2(hashArray, SCALAR_BITS)(arr, bundle->totalRandomGenArrLen, 2); break; case PERMUTED: checksum = _catFunc2(hashStridedArray, SCALAR_BITS)(arr, bundle->randomGenArrSideLen, strides); break; case AS_IS: checksum = _catFunc2(hashArray, SCALAR_BITS)(arr, bundle->totalRandomGenArrLen, 1); break; } uint64 key1, key2; computeKey(ARRAY_TEST, DECOMPRESSED_ARRAY, bundle->dimLens, bundle->mode, bundle->compressParamNum, &key1, &key2); if (COMPARE_NEQ_CHECKSUM(DIMS, ZFP_TYPE, checksum, key1, key2)) { printf("ERROR: Decompressed array checksums were different: 0x%"UINT64PRIx" != 0x%"UINT64PRIx"\n", checksum, getChecksumByKey(DIMS, ZFP_TYPE, key1, key2)); return 1; } else { return 0; } } // returns 0 on all tests pass, 1 on test failure // will skip decompression if compression fails static int isZfpCompressDecompressChecksumsMatch(void **state, int doDecompress) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; zfp_field* field = bundle->field; zfp_timer* timer = bundle->timer; size_t compressedBytes; if (runZfpCompress(stream, field, timer, &compressedBytes) == 1) { return 1; } bitstream* bs = zfp_stream_bit_stream(stream); if (isCompressedBitstreamChecksumsMatch(stream, bs, bundle->dimLens, bundle->mode, bundle->compressParamNum) == 1) { return 1; } if (doDecompress == 0) { return 0; } // rewind stream for decompression zfp_stream_rewind(stream); if (runZfpDecompress(stream, bundle->decompressField, timer, compressedBytes) == 1) { return 1; } if (isDecompressedArrayChecksumsMatch(bundle) == 1) { return 1; } return 0; } // this test is run by itself as its own test case, so it can use fail_msg() instead of accumulating error counts // will skip decompression if compression fails static void runCompressDecompressReversible(struct setupVars* bundle, int doDecompress) { zfp_stream* stream = bundle->stream; zfp_field* field = bundle->field; zfp_timer* timer = bundle->timer; size_t compressedBytes; if (runZfpCompress(stream, field, timer, &compressedBytes) == 1) { fail_msg("Reversible test failed."); } bitstream* bs = zfp_stream_bit_stream(stream); if (isCompressedBitstreamChecksumsMatch(stream, bs, bundle->dimLens, zfp_mode_reversible, bundle->compressParamNum) == 1) { fail_msg("Reversible test failed."); } if (doDecompress == 0) { return; } // rewind stream for decompression zfp_stream_rewind(stream); if (runZfpDecompress(stream, bundle->decompressField, timer, compressedBytes) == 1) { fail_msg("Reversible test failed."); } // verify that uncompressed and decompressed arrays match bit for bit switch(bundle->stride) { case REVERSED: case INTERLEAVED: case PERMUTED: { // test one scalar at a time for bitwise equality const size_t* n = bundle->randomGenArrSideLen; ptrdiff_t strides[4]; ptrdiff_t offset = 0; size_t i, j, k, l; zfp_field_stride(field, strides); for (l = (n[3] ? n[3] : 1); l--; offset += strides[3] - n[2]*strides[2]) { for (k = (n[2] ? n[2] : 1); k--; offset += strides[2] - n[1]*strides[1]) { for (j = (n[1] ? n[1] : 1); j--; offset += strides[1] - n[0]*strides[0]) { for (i = (n[0] ? n[0] : 1); i--; offset += strides[0]) { assert_memory_equal(&bundle->compressedArr[offset], &bundle->decompressedArr[offset], sizeof(Scalar)); } } } } } break; case AS_IS: assert_memory_equal(bundle->compressedArr, bundle->decompressedArr, bundle->totalRandomGenArrLen * sizeof(Scalar)); break; } } // returns number of testcase failures // (not allowed to call fail_msg() because all tests must run before signaling test failure) static int runCompressDecompressAcrossParamsGivenMode(void** state, int doDecompress, zfp_mode mode, int numCompressParams) { struct setupVars *bundle = *state; int failures = 0; int compressParam; for (compressParam = 0; compressParam < numCompressParams; compressParam++) { if (setupCompressParam(bundle, mode, compressParam) == 1) { failures++; continue; } failures += isZfpCompressDecompressChecksumsMatch(state, doDecompress); zfp_stream_rewind(bundle->stream); memset(bundle->buffer, 0, bundle->bufsizeBytes); } return failures; } static void runCompressDecompressTests(void** state, zfp_mode mode, int numCompressParams) { if (runCompressDecompressAcrossParamsGivenMode(state, 1, mode, numCompressParams) > 0) { fail_msg("Overall compress/decompress test failure\n"); } } zfp-1.0.1/tests/src/execPolicy/000077500000000000000000000000001453723256400163605ustar00rootroot00000000000000zfp-1.0.1/tests/src/execPolicy/CMakeLists.txt000066400000000000000000000012021453723256400211130ustar00rootroot00000000000000add_executable(testOmp testOmp.c) target_link_libraries(testOmp cmocka zfp) add_test(NAME testOmp COMMAND testOmp) if(ZFP_WITH_OPENMP) target_link_libraries(testOmp OpenMP::OpenMP_C) set_property(TEST testOmp PROPERTY RUN_SERIAL TRUE) endif() if(ZFP_WITH_OPENMP) add_executable(testOmpInternal testOmpInternal.c) target_link_libraries(testOmpInternal cmocka zfp OpenMP::OpenMP_C) add_test(NAME testOmpInternal COMMAND testOmpInternal) endif() if(ZFP_WITH_CUDA AND NOT DEFINED ZFP_OMP_TESTS_ONLY) add_executable(testCuda testCuda.c) target_link_libraries(testCuda cmocka zfp) add_test(NAME testCuda COMMAND testCuda) endif() zfp-1.0.1/tests/src/execPolicy/testCuda.c000066400000000000000000000044561453723256400203110ustar00rootroot00000000000000#include "zfp.h" #include #include #include #include #include #include struct setupVars { zfp_stream* stream; zfp_field* field; bitstream* bs; void* buffer; size_t streamSize; }; static int setup(void **state) { struct setupVars *bundle = malloc(sizeof(struct setupVars)); assert_non_null(bundle); bundle->stream = zfp_stream_open(NULL); assert_non_null(bundle); /* create a bitstream with buffer */ size_t bufferSize = 50 * sizeof(int); bundle->buffer = malloc(bufferSize); assert_non_null(bundle->buffer); memset(bundle->buffer, 0, bufferSize); /* offset bitstream, so we can distinguish 0 from stream_size() returned from zfp_decompress() */ bundle->bs = stream_open(bundle->buffer, bufferSize); stream_skip(bundle->bs, stream_word_bits + 1); bundle->streamSize = stream_size(bundle->bs); assert_int_not_equal(bundle->streamSize, 0); /* set cuda policy */ assert_int_equal(1, zfp_stream_set_execution(bundle->stream, zfp_exec_cuda)); /* create 4d field */ bundle->field = zfp_field_4d(NULL, zfp_type_int32, 9, 5, 4, 4); assert_non_null(bundle->field); assert_int_equal(4, zfp_field_dimensionality(bundle->field)); *state = bundle; return 0; } static int teardown(void **state) { struct setupVars *bundle = *state; zfp_field_free(bundle->field); stream_close(bundle->bs); free(bundle->buffer); zfp_stream_close(bundle->stream); free(bundle); return 0; } static void given_withCuda_when_4dCompressCudaPolicy_expect_noop(void **state) { struct setupVars *bundle = *state; assert_int_equal(zfp_compress(bundle->stream, bundle->field), 0); assert_int_equal(stream_size(bundle->bs), bundle->streamSize); } static void given_withCuda_when_4dDecompressCudaPolicy_expect_noop(void **state) { struct setupVars *bundle = *state; assert_int_equal(zfp_decompress(bundle->stream, bundle->field), 0); assert_int_equal(stream_size(bundle->bs), bundle->streamSize); } int main() { const struct CMUnitTest tests[] = { cmocka_unit_test_setup_teardown(given_withCuda_when_4dCompressCudaPolicy_expect_noop, setup, teardown), cmocka_unit_test_setup_teardown(given_withCuda_when_4dDecompressCudaPolicy_expect_noop, setup, teardown), }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/execPolicy/testOmp.c000066400000000000000000000137231453723256400201650ustar00rootroot00000000000000#include "zfp.h" #include #include #include #include #include #include struct setupVars { zfp_stream* stream; zfp_field* field; bitstream* bs; void* buffer; size_t streamSize; }; static int setup(void **state) { struct setupVars *bundle = malloc(sizeof(struct setupVars)); assert_non_null(bundle); bundle->stream = zfp_stream_open(NULL); *state = bundle; return 0; } static int teardown(void **state) { struct setupVars *bundle = *state; zfp_stream_close(bundle->stream); free(bundle); return 0; } static int setupForCompress(void **state) { if (setup(state)) return 1; struct setupVars *bundle = *state; /* create a bitstream with buffer */ size_t bufferSize = 50 * sizeof(int); bundle->buffer = malloc(bufferSize); assert_non_null(bundle->buffer); memset(bundle->buffer, 0, bufferSize); /* offset bitstream, so we can distinguish 0 from stream_size() returned from zfp_decompress() */ bundle->bs = stream_open(bundle->buffer, bufferSize); stream_skip(bundle->bs, (uint)(stream_word_bits + 1)); bundle->streamSize = stream_size(bundle->bs); assert_int_not_equal(bundle->streamSize, 0); /* manually set omp policy (needed for tests compiled without openmp) */ bundle->stream->exec.policy = zfp_exec_omp; bundle->field = zfp_field_1d(NULL, zfp_type_int32, 9); assert_non_null(bundle->field); return 0; } static int teardownForCompress(void **state) { struct setupVars *bundle = *state; zfp_field_free(bundle->field); stream_close(bundle->bs); free(bundle->buffer); return teardown(state); } #ifdef _OPENMP static void given_withOpenMP_when_setExecutionOmp_expect_set(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; assert_int_equal(zfp_stream_set_execution(stream, zfp_exec_omp), 1); assert_int_equal(zfp_stream_execution(stream), zfp_exec_omp); } static void given_withOpenMP_when_setOmpThreads_expect_set(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; uint threads = 5; assert_int_equal(zfp_stream_set_omp_threads(stream, threads), 1); assert_int_equal(zfp_stream_omp_threads(stream), threads); } static void given_withOpenMP_serialExec_when_setOmpThreads_expect_setToExecOmp(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; assert_int_equal(zfp_stream_execution(stream), zfp_exec_serial); assert_int_equal(zfp_stream_set_omp_threads(stream, 5), 1); assert_int_equal(zfp_stream_execution(stream), zfp_exec_omp); } static void given_withOpenMP_when_setOmpChunkSize_expect_set(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; uint chunk_size = 0x2u; assert_int_equal(zfp_stream_set_omp_chunk_size(stream, chunk_size), 1); assert_int_equal(zfp_stream_omp_chunk_size(stream), chunk_size); } static void given_withOpenMP_serialExec_when_setOmpChunkSize_expect_setToExecOmp(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; assert_int_equal(zfp_stream_execution(stream), zfp_exec_serial); assert_int_equal(zfp_stream_set_omp_chunk_size(stream, 0x200u), 1); assert_int_equal(zfp_stream_execution(stream), zfp_exec_omp); } static void given_withOpenMP_whenDecompressOmpPolicy_expect_noop(void **state) { struct setupVars *bundle = *state; assert_int_equal(zfp_decompress(bundle->stream, bundle->field), 0); assert_int_equal(stream_size(bundle->bs), bundle->streamSize); } #else static void given_withoutOpenMP_when_setExecutionOmp_expect_unableTo(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; assert_int_equal(zfp_stream_set_execution(stream, zfp_exec_omp), 0); assert_int_equal(zfp_stream_execution(stream), zfp_exec_serial); } static void given_withoutOpenMP_when_setOmpParams_expect_unableTo(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; assert_int_equal(zfp_stream_set_omp_threads(stream, 5), 0); assert_int_equal(zfp_stream_set_omp_chunk_size(stream, 0x200u), 0); assert_int_equal(zfp_stream_execution(stream), zfp_exec_serial); } static void given_withoutOpenMP_whenCompressOmpPolicy_expect_noop(void **state) { struct setupVars *bundle = *state; assert_int_equal(zfp_compress(bundle->stream, bundle->field), 0); assert_int_equal(stream_size(bundle->bs), bundle->streamSize); } static void given_withoutOpenMP_whenDecompressOmpPolicy_expect_noop(void **state) { struct setupVars *bundle = *state; assert_int_equal(zfp_decompress(bundle->stream, bundle->field), 0); assert_int_equal(stream_size(bundle->bs), bundle->streamSize); } #endif int main() { const struct CMUnitTest tests[] = { #ifdef _OPENMP cmocka_unit_test_setup_teardown(given_withOpenMP_when_setExecutionOmp_expect_set, setup, teardown), cmocka_unit_test_setup_teardown(given_withOpenMP_when_setOmpThreads_expect_set, setup, teardown), cmocka_unit_test_setup_teardown(given_withOpenMP_serialExec_when_setOmpThreads_expect_setToExecOmp, setup, teardown), cmocka_unit_test_setup_teardown(given_withOpenMP_when_setOmpChunkSize_expect_set, setup, teardown), cmocka_unit_test_setup_teardown(given_withOpenMP_serialExec_when_setOmpChunkSize_expect_setToExecOmp, setup, teardown), cmocka_unit_test_setup_teardown(given_withOpenMP_whenDecompressOmpPolicy_expect_noop, setupForCompress, teardownForCompress), #else cmocka_unit_test_setup_teardown(given_withoutOpenMP_when_setExecutionOmp_expect_unableTo, setup, teardown), cmocka_unit_test_setup_teardown(given_withoutOpenMP_when_setOmpParams_expect_unableTo, setup, teardown), cmocka_unit_test_setup_teardown(given_withoutOpenMP_whenCompressOmpPolicy_expect_noop, setupForCompress, teardownForCompress), cmocka_unit_test_setup_teardown(given_withoutOpenMP_whenDecompressOmpPolicy_expect_noop, setupForCompress, teardownForCompress), #endif }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/execPolicy/testOmpInternal.c000066400000000000000000000044601453723256400216600ustar00rootroot00000000000000#include "zfp.h" #include "zfp/internal/zfp/macros.h" #include "src/share/omp.c" #include #include #include #include #include struct setupVars { zfp_stream* stream; }; static int setup(void **state) { struct setupVars *bundle = malloc(sizeof(struct setupVars)); assert_non_null(bundle); zfp_stream* stream = zfp_stream_open(NULL); bundle->stream = stream; *state = bundle; return 0; } static int teardown(void **state) { struct setupVars *bundle = *state; zfp_stream_close(bundle->stream); free(bundle); return 0; } static void given_withOpenMP_zfpStreamOmpThreadsZero_when_threadCountOmp_expect_returnsOmpMaxThreadCount(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; assert_int_equal(zfp_stream_set_omp_threads(stream, 0), 1); assert_int_equal(thread_count_omp(stream), omp_get_max_threads()); } static void given_withOpenMP_zfpStreamOmpChunkSizeZero_when_chunkCountOmp_expect_returnsOneChunkPerThread(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; uint threads = 3; assert_int_equal(zfp_stream_set_omp_threads(stream, threads), 1); uint blocks = 50; assert_int_equal(chunk_count_omp(stream, blocks, threads), threads); } static void given_withOpenMP_zfpStreamOmpChunkSizeNonzero_when_chunkCountOmp_expect_returnsNumChunks(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; uint blocks = 51; uint chunkSize = 3; assert_int_equal(zfp_stream_set_omp_chunk_size(stream, chunkSize), 1); // the MIN(chunks, blocks) will always return chunks assert_int_equal(chunk_count_omp(stream, blocks, thread_count_omp(stream)), (blocks + chunkSize - 1) / chunkSize); } int main() { const struct CMUnitTest tests[] = { cmocka_unit_test_setup_teardown(given_withOpenMP_zfpStreamOmpThreadsZero_when_threadCountOmp_expect_returnsOmpMaxThreadCount, setup, teardown), cmocka_unit_test_setup_teardown(given_withOpenMP_zfpStreamOmpChunkSizeZero_when_chunkCountOmp_expect_returnsOneChunkPerThread, setup, teardown), cmocka_unit_test_setup_teardown(given_withOpenMP_zfpStreamOmpChunkSizeNonzero_when_chunkCountOmp_expect_returnsNumChunks, setup, teardown), }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/inline/000077500000000000000000000000001453723256400155325ustar00rootroot00000000000000zfp-1.0.1/tests/src/inline/CMakeLists.txt000066400000000000000000000010021453723256400202630ustar00rootroot00000000000000add_executable(testBitstream testBitstream.c) target_link_libraries(testBitstream cmocka zfp) add_test(NAME testBitstream COMMAND testBitstream) add_executable(testBitstreamSmallWsize testBitstreamSmallWsize.c) target_link_libraries(testBitstreamSmallWsize cmocka) add_test(NAME testBitstreamSmallWsize COMMAND testBitstreamSmallWsize) add_executable(testBitstreamStrided testBitstreamStrided.c) target_link_libraries(testBitstreamStrided cmocka) add_test(NAME testBitstreamStrided COMMAND testBitstreamStrided) zfp-1.0.1/tests/src/inline/testBitstream.c000066400000000000000000000520241453723256400205330ustar00rootroot00000000000000#include #include #include #include #include "include/zfp/bitstream.h" #include "include/zfp/bitstream.inl" #define STREAM_WORD_CAPACITY 3 #define WORD_MASK ((bitstream_word)(-1)) #define WORD1 WORD_MASK #define WORD2 (0x5555555555555555 & WORD_MASK) struct setupVars { void* buffer; bitstream* b; }; static int setup(void **state) { struct setupVars *s = malloc(sizeof(struct setupVars)); assert_non_null(s); s->buffer = calloc(STREAM_WORD_CAPACITY, sizeof(bitstream_word)); assert_non_null(s->buffer); s->b = stream_open(s->buffer, STREAM_WORD_CAPACITY * sizeof(bitstream_word)); assert_non_null(s->b); *state = s; return 0; } static int teardown(void **state) { struct setupVars *s = *state; free(s->buffer); free(s->b); free(s); return 0; } static void when_StreamCopy_expect_BitsCopiedToDestBitstream(void **state) { const uint SRC_OFFSET = wsize - 6; const uint DST_OFFSET = 5; const uint COPY_BITS = wsize + 4; const uint NUM_WORD2_BITS_WRITTEN_TO_WORD = DST_OFFSET + (wsize - SRC_OFFSET); const bitstream_word EXPECTED_WRITTEN_WORD = ((WORD1 >> SRC_OFFSET) << DST_OFFSET) + (WORD2 << NUM_WORD2_BITS_WRITTEN_TO_WORD); const uint EXPECTED_BITS = (DST_OFFSET + COPY_BITS) % wsize; const bitstream_word EXPECTED_BUFFER = (WORD2 >> (NUM_WORD2_BITS_WRITTEN_TO_WORD)) & ((1u << EXPECTED_BITS) - 1); bitstream* src = ((struct setupVars *)*state)->b; stream_write_word(src, WORD1); stream_write_word(src, WORD2); stream_flush(src); stream_rseek(src, SRC_OFFSET); void* buffer = calloc(STREAM_WORD_CAPACITY, sizeof(bitstream_word)); bitstream* dst = stream_open(buffer, STREAM_WORD_CAPACITY * sizeof(bitstream_word)); stream_wseek(dst, DST_OFFSET); stream_copy(dst, src, COPY_BITS); assert_ptr_equal(dst->ptr, dst->begin + 1); assert_int_equal(dst->bits, (DST_OFFSET + COPY_BITS) % wsize); assert_int_equal(*dst->begin, EXPECTED_WRITTEN_WORD); assert_int_equal(dst->buffer, EXPECTED_BUFFER); stream_close(dst); free(buffer); } static void when_Flush_expect_PaddedWordWrittenToStream(void **state) { const uint PREV_BUFFER_BIT_COUNT = 8; bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, WORD1, wsize); stream_write_bits(s, WORD1, wsize); stream_rewind(s); stream_write_bits(s, WORD2, PREV_BUFFER_BIT_COUNT); bitstream_word *prevPtr = s->ptr; size_t padCount = stream_flush(s); assert_ptr_equal(s->ptr, prevPtr + 1); assert_int_equal(s->bits, 0); assert_int_equal(s->buffer, 0); assert_int_equal(padCount, wsize - PREV_BUFFER_BIT_COUNT); } static void given_EmptyBuffer_when_Flush_expect_NOP(void **state) { bitstream* s = ((struct setupVars *)*state)->b; bitstream_word *prevPtr = s->ptr; bitstream_count prevBits = s->bits; bitstream_word prevBuffer = s->buffer; size_t padCount = stream_flush(s); assert_ptr_equal(s->ptr, prevPtr); assert_int_equal(s->bits, prevBits); assert_int_equal(s->buffer, prevBuffer); assert_int_equal(padCount, 0); } static void when_Align_expect_BufferEmptyBitsZero(void **state) { const uint READ_BIT_COUNT = 3; bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, WORD1, wsize); stream_write_bits(s, WORD2, wsize); stream_rewind(s); stream_read_bits(s, READ_BIT_COUNT); bitstream_word *prevPtr = s->ptr; stream_align(s); assert_ptr_equal(s->ptr, prevPtr); assert_int_equal(s->bits, 0); assert_int_equal(s->buffer, 0); } static void when_SkipPastBufferEnd_expect_NewMaskedWordInBuffer(void **state) { const uint READ_BIT_COUNT = 3; const uint SKIP_COUNT = wsize + 5; const uint TOTAL_OFFSET = READ_BIT_COUNT + SKIP_COUNT; const uint EXPECTED_BITS = wsize - (TOTAL_OFFSET % wsize); const bitstream_word EXPECTED_BUFFER = WORD2 >> (TOTAL_OFFSET % wsize); bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, WORD1, wsize); stream_write_bits(s, WORD2, wsize); stream_rewind(s); stream_read_bits(s, READ_BIT_COUNT); stream_skip(s, SKIP_COUNT); assert_ptr_equal(s->ptr, s->begin + 2); assert_int_equal(s->bits, EXPECTED_BITS); assert_int_equal(s->buffer, EXPECTED_BUFFER); } static void when_SkipWithinBuffer_expect_MaskedBuffer(void **state) { const uint READ_BIT_COUNT = 3; const uint SKIP_COUNT = 5; const uint TOTAL_OFFSET = READ_BIT_COUNT + SKIP_COUNT; const uint EXPECTED_BITS = wsize - (TOTAL_OFFSET % wsize); const bitstream_word EXPECTED_BUFFER = WORD1 >> (TOTAL_OFFSET % wsize); bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, WORD1, wsize); stream_rewind(s); stream_read_bits(s, READ_BIT_COUNT); bitstream_word *prevPtr = s->ptr; stream_skip(s, SKIP_COUNT); assert_ptr_equal(s->ptr, prevPtr); assert_int_equal(s->bits, EXPECTED_BITS); assert_int_equal(s->buffer, EXPECTED_BUFFER); } static void when_SkipZeroBits_expect_NOP(void **state) { bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, WORD1, wsize); stream_write_bits(s, WORD2, wsize); stream_rewind(s); stream_read_bits(s, 2); bitstream_word* prevPtr = s->ptr; bitstream_word prevBits = s->bits; bitstream_word prevBuffer = s->buffer; stream_skip(s, 0); assert_ptr_equal(s->ptr, prevPtr); assert_int_equal(s->bits, prevBits); assert_int_equal(s->buffer, prevBuffer); } static void when_RseekToNonMultipleOfWsize_expect_MaskedWordLoadedToBuffer(void **state) { const uint BIT_OFFSET = wsize + 5; const uint EXPECTED_BITS = wsize - (BIT_OFFSET % wsize); const bitstream_word EXPECTED_BUFFER = WORD2 >> (BIT_OFFSET % wsize); bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, WORD1, wsize); stream_write_bits(s, WORD2, wsize); stream_rseek(s, BIT_OFFSET); assert_ptr_equal(s->ptr, s->begin + 2); assert_int_equal(s->bits, EXPECTED_BITS); assert_int_equal(s->buffer, EXPECTED_BUFFER); } static void when_RseekToMultipleOfWsize_expect_PtrAlignedBufferEmpty(void **state) { bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, WORD1, wsize); stream_write_bits(s, WORD2, wsize); stream_rseek(s, wsize); assert_ptr_equal(s->ptr, s->begin + 1); assert_int_equal(s->bits, 0); assert_int_equal(s->buffer, 0); } static void when_WseekToNonMultipleOfWsize_expect_MaskedWordLoadedToBuffer(void **state) { const uint BIT_OFFSET = wsize + 5; const bitstream_word MASK = 0x1f; bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, WORD1, wsize); stream_write_bits(s, WORD2, wsize); stream_wseek(s, BIT_OFFSET); assert_ptr_equal(s->ptr, s->begin + 1); assert_int_equal(s->bits, BIT_OFFSET % wsize); assert_int_equal(s->buffer, WORD2 & MASK); } static void when_WseekToMultipleOfWsize_expect_PtrAlignedBufferEmpty(void **state) { bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, WORD1, wsize); stream_write_bits(s, WORD2, wsize); stream_wseek(s, wsize); assert_ptr_equal(s->ptr, s->begin + 1); assert_int_equal(s->bits, 0); assert_int_equal(s->buffer, 0); } static void when_Rtell_expect_ReturnsReadBitCount(void **state) { const uint READ_BIT_COUNT1 = wsize - 6; const uint READ_BIT_COUNT2 = wsize; bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, WORD1, wsize); stream_write_bits(s, WORD1, wsize); stream_rewind(s); stream_read_bits(s, READ_BIT_COUNT1); stream_read_bits(s, READ_BIT_COUNT2); assert_int_equal(stream_rtell(s), READ_BIT_COUNT1 + READ_BIT_COUNT2); } static void when_Wtell_expect_ReturnsWrittenBitCount(void **state) { const uint WRITE_BIT_COUNT1 = wsize; const uint WRITE_BIT_COUNT2 = 6; bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, WORD1, WRITE_BIT_COUNT1); stream_write_bits(s, WORD1, WRITE_BIT_COUNT2); assert_int_equal(stream_wtell(s), WRITE_BIT_COUNT1 + WRITE_BIT_COUNT2); } static void when_ReadBitsSpreadsAcrossTwoWords_expect_BitsCombinedFromBothWords(void **state) { const uint READ_BIT_COUNT = wsize - 3; const uint PARTIAL_WORD_BIT_COUNT = 16; const uint NUM_OVERFLOWED_BITS = READ_BIT_COUNT - PARTIAL_WORD_BIT_COUNT; const uint EXPECTED_BUFFER_BIT_COUNT = wsize - NUM_OVERFLOWED_BITS; const bitstream_word PARTIAL_WORD1 = WORD1 & 0xffff; const bitstream_word PARTIAL_WORD2 = WORD2 & 0x1fffffffffff << PARTIAL_WORD_BIT_COUNT; bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, PARTIAL_WORD1, wsize); stream_write_bits(s, WORD2, wsize); stream_rewind(s); s->buffer = stream_read_word(s); s->bits = PARTIAL_WORD_BIT_COUNT; uint64 readBits = stream_read_bits(s, READ_BIT_COUNT); assert_int_equal(s->bits, EXPECTED_BUFFER_BIT_COUNT); assert_int_equal(readBits, PARTIAL_WORD1 + PARTIAL_WORD2); assert_int_equal(s->buffer, WORD2 >> NUM_OVERFLOWED_BITS); } static void given_BitstreamBufferEmptyWithNextWordAvailable_when_ReadBitsWsize_expect_EntireNextWordReturned(void **state) { const uint READ_BIT_COUNT = wsize; bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, 0, wsize); stream_write_bits(s, WORD1, wsize); stream_rewind(s); s->buffer = stream_read_word(s); s->bits = 0; uint64 readBits = stream_read_bits(s, READ_BIT_COUNT); assert_int_equal(s->bits, 0); assert_int_equal(readBits, WORD1); assert_int_equal(s->buffer, 0); } static void when_ReadBits_expect_BitsReadInOrderLSB(void **state) { const uint BITS_TO_READ = 2; const bitstream_word MASK = 0x3; bitstream* s = ((struct setupVars *)*state)->b; s->buffer = WORD2; s->bits = wsize; uint64 readBits = stream_read_bits(s, BITS_TO_READ); assert_int_equal(s->bits, wsize - BITS_TO_READ); assert_int_equal(readBits, WORD2 & MASK); assert_int_equal(s->buffer, WORD2 >> BITS_TO_READ); } static void when_ReadZeroBits_expect_NOP(void **state) { bitstream* s = ((struct setupVars *)*state)->b; s->buffer = WORD1; s->bits = wsize; uint64 readBits = stream_read_bits(s, 0); assert_int_equal(s->bits, wsize); assert_int_equal(readBits, 0); assert_int_equal(s->buffer, WORD1); } // overflow refers to what will land in the buffer // more significant bits than overflow are returned by stream_write_bits() static void when_WriteBitsOverflowsBuffer_expect_OverflowWrittenToNewBuffer(void **state) { const uint EXISTING_BIT_COUNT = 5; const uint NUM_BITS_TO_WRITE = wsize - 1; const uint OVERFLOW_BIT_COUNT = NUM_BITS_TO_WRITE - (wsize - EXISTING_BIT_COUNT); // 0x1101 0101 0101 ... 0101 allows stream_write_bit() to return non-zero const bitstream_word WORD_TO_WRITE = WORD2 + 0x8000000000000000; const bitstream_word OVERFLOWED_BITS = WORD_TO_WRITE >> (wsize - EXISTING_BIT_COUNT); const bitstream_word EXPECTED_BUFFER_RESULT = OVERFLOWED_BITS & 0xf; bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, WORD1, EXISTING_BIT_COUNT); uint64 remainingBits = stream_write_bits(s, WORD_TO_WRITE, NUM_BITS_TO_WRITE); assert_int_equal(s->bits, OVERFLOW_BIT_COUNT); assert_int_equal(s->buffer, EXPECTED_BUFFER_RESULT); assert_int_equal(remainingBits, WORD_TO_WRITE >> NUM_BITS_TO_WRITE); } static void when_WriteBitsFillsBufferExactly_expect_WordWrittenToStream(void **state) { const uint EXISTING_BIT_COUNT = 5; const uint NUM_BITS_TO_WRITE = wsize - EXISTING_BIT_COUNT; const bitstream_word COMPLETING_WORD = WORD2 & 0x07ffffffffffffff; bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, WORD1, EXISTING_BIT_COUNT); uint64 remainingBits = stream_write_bits(s, COMPLETING_WORD, NUM_BITS_TO_WRITE); stream_rewind(s); bitstream_word readWord = stream_read_word(s); assert_int_equal(readWord, 0x1f + 0xaaaaaaaaaaaaaaa0); assert_int_equal(remainingBits, 0); } static void when_WriteBits_expect_BitsWrittenToBufferFromLSB(void **state) { const uint NUM_BITS_TO_WRITE = 3; const uint MASK = 0x7; bitstream* s = ((struct setupVars *)*state)->b; uint64 remainingBits = stream_write_bits(s, WORD1, NUM_BITS_TO_WRITE); assert_int_equal(s->bits, NUM_BITS_TO_WRITE); assert_int_equal(s->buffer, WORD1 & MASK); assert_int_equal(remainingBits, WORD1 >> NUM_BITS_TO_WRITE); } static void when_WriteZeroBits_expect_NOP(void **state) { bitstream* s = ((struct setupVars *)*state)->b; uint64 remainingBits = stream_write_bits(s, WORD1, 0); assert_int_equal(s->bits, 0); assert_int_equal(s->buffer, 0); assert_int_equal(remainingBits, WORD1); } static void given_BitstreamWithEmptyBuffer_when_ReadBit_expect_LoadNextWordToBuffer(void **state) { bitstream* s = ((struct setupVars *)*state)->b; stream_write_word(s, 0); stream_write_word(s, WORD1); stream_rewind(s); s->buffer = stream_read_word(s); s->bits = 0; assert_int_equal(s->buffer, 0); assert_int_equal(stream_read_bit(s), 1); assert_int_equal(s->bits, wsize - 1); assert_int_equal(s->buffer, WORD1 >> 1); } static void given_BitstreamWithBitInBuffer_when_ReadBit_expect_OneBitReadFromLSB(void **state) { bitstream* s = ((struct setupVars *)*state)->b; stream_write_bit(s, 1); bitstream_count prevBits = s->bits; bitstream_word prevBuffer = s->buffer; assert_int_equal(stream_read_bit(s), 1); assert_int_equal(s->bits, prevBits - 1); assert_int_equal(s->buffer, prevBuffer >> 1); } static void given_BitstreamBufferOneBitFromFull_when_WriteBit_expect_BitWrittenToBufferWrittenToStreamAndBufferReset(void **state) { const uint PLACE = wsize - 1; bitstream* s = ((struct setupVars *)*state)->b; s->bits = PLACE; stream_write_bit(s, 1); assert_int_equal(stream_size(s), sizeof(bitstream_word)); assert_int_equal(*s->begin, (bitstream_word)1 << PLACE); assert_int_equal(s->buffer, 0); } static void when_WriteBit_expect_BitWrittenToBufferFromLSB(void **state) { const uint PLACE = 3; bitstream* s = ((struct setupVars *)*state)->b; s->bits = PLACE; stream_write_bit(s, 1); assert_int_equal(s->bits, PLACE + 1); assert_int_equal(s->buffer, (bitstream_word)1 << PLACE); } static void given_StartedBuffer_when_StreamPadOverflowsBuffer_expect_ProperWordsWritten(void **state) { const uint NUM_WORDS = 2; const uint EXISTING_BIT_COUNT = 12; const bitstream_word EXISTING_BUFFER = 0xfff; const uint PAD_AMOUNT = NUM_WORDS * wsize - EXISTING_BIT_COUNT; bitstream* s = ((struct setupVars *)*state)->b; stream_write_word(s, 0); stream_write_word(s, WORD1); stream_rewind(s); s->buffer = EXISTING_BUFFER; s->bits = EXISTING_BIT_COUNT; size_t prevStreamSize = stream_size(s); stream_pad(s, PAD_AMOUNT); assert_int_equal(stream_size(s), prevStreamSize + NUM_WORDS * sizeof(bitstream_word)); stream_rewind(s); assert_int_equal(stream_read_word(s), EXISTING_BUFFER); assert_int_equal(stream_read_word(s), 0); } static void given_StartedBuffer_when_StreamPad_expect_PaddedWordWritten(void **state) { const uint EXISTING_BIT_COUNT = 12; const bitstream_word EXISTING_BUFFER = 0xfff; bitstream* s = ((struct setupVars *)*state)->b; s->buffer = EXISTING_BUFFER; s->bits = EXISTING_BIT_COUNT; size_t prevStreamSize = stream_size(s); stream_pad(s, wsize - EXISTING_BIT_COUNT); assert_int_equal(stream_size(s), prevStreamSize + sizeof(bitstream_word)); stream_rewind(s); assert_int_equal(stream_read_word(s), EXISTING_BUFFER); } static void when_ReadTwoWords_expect_ReturnConsecutiveWordsInOrder(void **state) { bitstream* s = ((struct setupVars *)*state)->b; stream_write_word(s, WORD1); stream_write_word(s, WORD2); stream_rewind(s); assert_int_equal(stream_read_word(s), WORD1); assert_int_equal(stream_read_word(s), WORD2); } static void when_ReadWord_expect_WordReturned(void **state) { bitstream* s = ((struct setupVars *)*state)->b; stream_write_word(s, WORD1); stream_rewind(s); assert_int_equal(stream_read_word(s), WORD1); } static void given_BitstreamWithOneWrittenWordRewound_when_WriteWord_expect_NewerWordOverwrites(void **state) { bitstream* s = ((struct setupVars *)*state)->b; stream_write_word(s, WORD1); stream_rewind(s); stream_write_word(s, WORD2); assert_int_equal(*s->begin, WORD2); } static void when_WriteTwoWords_expect_WordsWrittenToStreamConsecutively(void **state) { bitstream* s = ((struct setupVars *)*state)->b; stream_write_word(s, WORD1); stream_write_word(s, WORD2); assert_int_equal(stream_size(s), sizeof(bitstream_word) * 2); assert_int_equal(*s->begin, WORD1); assert_int_equal(*(s->begin + 1), WORD2); } static void given_RewoundBitstream_when_WriteWord_expect_WordWrittenAtStreamBegin(void **state) { bitstream* s = ((struct setupVars *)*state)->b; size_t prevStreamSize = stream_size(s); stream_write_word(s, WORD1); assert_int_equal(stream_size(s), prevStreamSize + sizeof(bitstream_word)); assert_int_equal(*s->begin, WORD1); } static void when_BitstreamOpened_expect_ProperLengthAndBoundaries(void **state) { const int NUM_WORDS = 4; size_t bufferLenBytes = sizeof(bitstream_word) * NUM_WORDS; void* buffer = malloc(bufferLenBytes); bitstream* s = stream_open(buffer, bufferLenBytes); void* streamBegin = stream_data(s); void* computedStreamEnd = (bitstream_word*)streamBegin + NUM_WORDS; assert_ptr_equal(streamBegin, buffer); assert_ptr_equal(s->end, computedStreamEnd); assert_int_equal(stream_capacity(s), bufferLenBytes); stream_close(s); free(buffer); } static void when_Alignment_expect_MatchingStreamWordBits(void **state) { size_t alignment = stream_alignment(); assert_int_equal(alignment, stream_word_bits); } int main() { const struct CMUnitTest tests[] = { cmocka_unit_test(when_Alignment_expect_MatchingStreamWordBits), cmocka_unit_test(when_BitstreamOpened_expect_ProperLengthAndBoundaries), cmocka_unit_test_setup_teardown(given_RewoundBitstream_when_WriteWord_expect_WordWrittenAtStreamBegin, setup, teardown), cmocka_unit_test_setup_teardown(when_WriteTwoWords_expect_WordsWrittenToStreamConsecutively, setup, teardown), cmocka_unit_test_setup_teardown(given_BitstreamWithOneWrittenWordRewound_when_WriteWord_expect_NewerWordOverwrites, setup, teardown), cmocka_unit_test_setup_teardown(when_ReadWord_expect_WordReturned, setup, teardown), cmocka_unit_test_setup_teardown(when_ReadTwoWords_expect_ReturnConsecutiveWordsInOrder, setup, teardown), cmocka_unit_test_setup_teardown(given_StartedBuffer_when_StreamPad_expect_PaddedWordWritten, setup, teardown), cmocka_unit_test_setup_teardown(given_StartedBuffer_when_StreamPadOverflowsBuffer_expect_ProperWordsWritten, setup, teardown), cmocka_unit_test_setup_teardown(when_WriteBit_expect_BitWrittenToBufferFromLSB, setup, teardown), cmocka_unit_test_setup_teardown(given_BitstreamBufferOneBitFromFull_when_WriteBit_expect_BitWrittenToBufferWrittenToStreamAndBufferReset, setup, teardown), cmocka_unit_test_setup_teardown(given_BitstreamWithBitInBuffer_when_ReadBit_expect_OneBitReadFromLSB, setup, teardown), cmocka_unit_test_setup_teardown(given_BitstreamWithEmptyBuffer_when_ReadBit_expect_LoadNextWordToBuffer, setup, teardown), cmocka_unit_test_setup_teardown(when_WriteZeroBits_expect_NOP, setup, teardown), cmocka_unit_test_setup_teardown(when_WriteBits_expect_BitsWrittenToBufferFromLSB, setup, teardown), cmocka_unit_test_setup_teardown(when_WriteBitsFillsBufferExactly_expect_WordWrittenToStream, setup, teardown), cmocka_unit_test_setup_teardown(when_WriteBitsOverflowsBuffer_expect_OverflowWrittenToNewBuffer, setup, teardown), cmocka_unit_test_setup_teardown(when_ReadZeroBits_expect_NOP, setup, teardown), cmocka_unit_test_setup_teardown(when_ReadBits_expect_BitsReadInOrderLSB, setup, teardown), cmocka_unit_test_setup_teardown(given_BitstreamBufferEmptyWithNextWordAvailable_when_ReadBitsWsize_expect_EntireNextWordReturned, setup, teardown), cmocka_unit_test_setup_teardown(when_ReadBitsSpreadsAcrossTwoWords_expect_BitsCombinedFromBothWords, setup, teardown), cmocka_unit_test_setup_teardown(when_Wtell_expect_ReturnsWrittenBitCount, setup, teardown), cmocka_unit_test_setup_teardown(when_Rtell_expect_ReturnsReadBitCount, setup, teardown), cmocka_unit_test_setup_teardown(when_WseekToMultipleOfWsize_expect_PtrAlignedBufferEmpty, setup, teardown), cmocka_unit_test_setup_teardown(when_WseekToNonMultipleOfWsize_expect_MaskedWordLoadedToBuffer, setup, teardown), cmocka_unit_test_setup_teardown(when_RseekToMultipleOfWsize_expect_PtrAlignedBufferEmpty, setup, teardown), cmocka_unit_test_setup_teardown(when_RseekToNonMultipleOfWsize_expect_MaskedWordLoadedToBuffer, setup, teardown), cmocka_unit_test_setup_teardown(when_SkipZeroBits_expect_NOP, setup, teardown), cmocka_unit_test_setup_teardown(when_SkipWithinBuffer_expect_MaskedBuffer, setup, teardown), cmocka_unit_test_setup_teardown(when_SkipPastBufferEnd_expect_NewMaskedWordInBuffer, setup, teardown), cmocka_unit_test_setup_teardown(when_Align_expect_BufferEmptyBitsZero, setup, teardown), cmocka_unit_test_setup_teardown(given_EmptyBuffer_when_Flush_expect_NOP, setup, teardown), cmocka_unit_test_setup_teardown(when_Flush_expect_PaddedWordWrittenToStream, setup, teardown), cmocka_unit_test_setup_teardown(when_StreamCopy_expect_BitsCopiedToDestBitstream, setup, teardown), cmocka_unit_test_setup_teardown(when_StreamCopy_expect_BitsCopiedToDestBitstream, setup, teardown), }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/inline/testBitstreamSmallWsize.c000066400000000000000000000071551453723256400225530ustar00rootroot00000000000000#include #include #include #include #define BIT_STREAM_WORD_TYPE uint16 #include "include/zfp/bitstream.h" #include "include/zfp/bitstream.inl" #define STREAM_WORD_CAPACITY 4 struct setupVars { void* buffer; bitstream* b; }; static int setup(void **state) { struct setupVars *s = malloc(sizeof(struct setupVars)); assert_non_null(s); s->buffer = calloc(STREAM_WORD_CAPACITY, sizeof(bitstream_word)); assert_non_null(s->buffer); s->b = stream_open(s->buffer, STREAM_WORD_CAPACITY * sizeof(bitstream_word)); assert_non_null(s->b); *state = s; return 0; } static int teardown(void **state) { struct setupVars *s = *state; free(s->buffer); free(s->b); free(s); return 0; } static void when_ReadBitsSpreadsAcrossMultipleWords_expect_BitsCombinedFromMultipleWords(void **state) { const uint READ_BIT_COUNT = 48; const uint PARTIAL_WORD_BIT_COUNT = 8; const uint NUM_OVERFLOWED_BITS = READ_BIT_COUNT - PARTIAL_WORD_BIT_COUNT; const uint64 WRITE_BITS1 = 0x11; const uint64 WRITE_BITS2 = 0x5555; const uint64 WRITE_BITS3 = 0x9249; const uint64 WRITE_BITS4 = 0x1111 + 0x8000; bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, WRITE_BITS1, wsize); stream_write_bits(s, WRITE_BITS2, wsize); stream_write_bits(s, WRITE_BITS3, wsize); stream_write_bits(s, WRITE_BITS4, wsize); stream_rewind(s); s->buffer = stream_read_word(s); s->bits = PARTIAL_WORD_BIT_COUNT; uint64 readBits = stream_read_bits(s, READ_BIT_COUNT); assert_int_equal(s->bits, wsize - (NUM_OVERFLOWED_BITS % wsize)); assert_int_equal(readBits, WRITE_BITS1 + (WRITE_BITS2 << PARTIAL_WORD_BIT_COUNT) + (WRITE_BITS3 << (wsize + PARTIAL_WORD_BIT_COUNT)) + ((WRITE_BITS4 & 0xff) << (2*wsize + PARTIAL_WORD_BIT_COUNT))); assert_int_equal(s->buffer, (bitstream_word) (WRITE_BITS4 >> (NUM_OVERFLOWED_BITS % wsize))); } // overflow refers to what will land in the buffer // more significant bits than overflow are returned by stream_write_bits() static void when_WriteBitsOverflowsBufferByMultipleWords_expect_WordsWrittenAndRemainingOverflowInBuffer(void **state) { const uint EXISTING_BIT_COUNT = 4; const uint NUM_BITS_TO_WRITE = 40; const uint OVERFLOW_BIT_COUNT = (NUM_BITS_TO_WRITE - (wsize - EXISTING_BIT_COUNT)) % wsize; const uint64 EXISTING_BUFFER = 0xf; const uint64 WRITE_WORD1 = 0x5555; const uint64 WRITE_WORD2 = 0x9249; const uint64 WRITE_WORD3 = 0x1111 + 0x8000; const uint64 BITS_TO_WRITE = WRITE_WORD1 + (WRITE_WORD2 << wsize) + (WRITE_WORD3 << (2*wsize)); bitstream* s = ((struct setupVars *)*state)->b; stream_write_bits(s, EXISTING_BUFFER, EXISTING_BIT_COUNT); uint64 remainingWord = stream_write_bits(s, BITS_TO_WRITE, NUM_BITS_TO_WRITE); assert_int_equal(remainingWord, WRITE_WORD3 >> (3*wsize - NUM_BITS_TO_WRITE)); assert_int_equal(*s->begin, EXISTING_BUFFER + ((WRITE_WORD1 << EXISTING_BIT_COUNT) & 0xffff)); assert_int_equal(*(s->begin + 1), (WRITE_WORD1 >> (wsize - EXISTING_BIT_COUNT)) + ((WRITE_WORD2 << EXISTING_BIT_COUNT) & 0xffff)); assert_int_equal(s->bits, OVERFLOW_BIT_COUNT); assert_int_equal(s->buffer, (WRITE_WORD2 >> (wsize - EXISTING_BIT_COUNT)) + ((WRITE_WORD3 << EXISTING_BIT_COUNT) & 0x0fff)); } int main() { const struct CMUnitTest tests[] = { cmocka_unit_test_setup_teardown(when_WriteBitsOverflowsBufferByMultipleWords_expect_WordsWrittenAndRemainingOverflowInBuffer, setup, teardown), cmocka_unit_test_setup_teardown(when_ReadBitsSpreadsAcrossMultipleWords_expect_BitsCombinedFromMultipleWords, setup, teardown), }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/inline/testBitstreamStrided.c000066400000000000000000000042301453723256400220460ustar00rootroot00000000000000#include #include #include #include #define BIT_STREAM_STRIDED #include "include/zfp/bitstream.h" #include "include/zfp/bitstream.inl" // 4 words per block #define BLOCK_SIZE 4 // 16 blocks between consecutive stream-touched blocks #define DELTA 16 #define STREAM_BUFFER_LEN 3 #define STREAM_STRIDED_LEN (STREAM_BUFFER_LEN * BLOCK_SIZE * DELTA) struct setupVars { void* buffer; bitstream* b; }; static int setup(void **state) { struct setupVars *s = malloc(sizeof(struct setupVars)); assert_non_null(s); s->buffer = calloc(STREAM_STRIDED_LEN, sizeof(bitstream_word)); assert_non_null(s->buffer); s->b = stream_open(s->buffer, STREAM_STRIDED_LEN * sizeof(bitstream_word)); assert_non_null(s->b); assert_true(stream_set_stride(s->b, BLOCK_SIZE, DELTA)); *state = s; return 0; } static int teardown(void **state) { struct setupVars *s = *state; free(s->buffer); free(s->b); free(s); return 0; } static void given_Strided_when_ReadWordCompletesBlock_expect_PtrAdvancedByStrideLen(void **state) { bitstream* s = ((struct setupVars *)*state)->b; bitstream_word* prevPtr = s->ptr; int i; for (i = 0; i < BLOCK_SIZE - 1; i++) { stream_read_word(s); assert_ptr_equal(s->ptr, prevPtr + 1); prevPtr = s->ptr; } stream_read_word(s); assert_ptr_equal(s->ptr, (prevPtr + 1) + DELTA * BLOCK_SIZE); } static void given_Strided_when_WriteWordCompletesBlock_expect_PtrAdvancedByStrideLen(void **state) { bitstream* s = ((struct setupVars *)*state)->b; bitstream_word* prevPtr = s->ptr; int i; for (i = 0; i < BLOCK_SIZE - 1; i++) { stream_write_word(s, 0); assert_ptr_equal(s->ptr, prevPtr + 1); prevPtr = s->ptr; } stream_write_word(s, 0); assert_ptr_equal(s->ptr, (prevPtr + 1) + DELTA * BLOCK_SIZE); } int main() { const struct CMUnitTest tests[] = { cmocka_unit_test_setup_teardown(given_Strided_when_WriteWordCompletesBlock_expect_PtrAdvancedByStrideLen, setup, teardown), cmocka_unit_test_setup_teardown(given_Strided_when_ReadWordCompletesBlock_expect_PtrAdvancedByStrideLen, setup, teardown), }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/misc/000077500000000000000000000000001453723256400152075ustar00rootroot00000000000000zfp-1.0.1/tests/src/misc/CMakeLists.txt000066400000000000000000000033401453723256400177470ustar00rootroot00000000000000add_executable(testZfpHeader testZfpHeader.c) target_link_libraries(testZfpHeader cmocka zfp) add_test(NAME testZfpHeader COMMAND testZfpHeader) add_executable(testZfpStream testZfpStream.c) target_link_libraries(testZfpStream cmocka zfp) add_test(NAME testZfpStream COMMAND testZfpStream) add_executable(testZfpPromote testZfpPromote.c) target_link_libraries(testZfpPromote cmocka zfp) add_test(NAME testZfpPromote COMMAND testZfpPromote) add_executable(testZfpField1f testZfpField1f.c) target_link_libraries(testZfpField1f cmocka zfp) add_test(NAME testZfpField1f COMMAND testZfpField1f) add_executable(testZfpField2f testZfpField2f.c) target_link_libraries(testZfpField2f cmocka zfp) add_test(NAME testZfpField2f COMMAND testZfpField2f) add_executable(testZfpField3f testZfpField3f.c) target_link_libraries(testZfpField3f cmocka zfp) add_test(NAME testZfpField3f COMMAND testZfpField3f) add_executable(testZfpField4f testZfpField4f.c) target_link_libraries(testZfpField4f cmocka zfp) add_test(NAME testZfpField4f COMMAND testZfpField4f) add_executable(testZfpField1d testZfpField1d.c) target_link_libraries(testZfpField1d cmocka zfp) add_test(NAME testZfpField1d COMMAND testZfpField1d) add_executable(testZfpField2d testZfpField2d.c) target_link_libraries(testZfpField2d cmocka zfp) add_test(NAME testZfpField2d COMMAND testZfpField2d) add_executable(testZfpField3d testZfpField3d.c) target_link_libraries(testZfpField3d cmocka zfp) add_test(NAME testZfpField3d COMMAND testZfpField3d) add_executable(testZfpField4d testZfpField4d.c) target_link_libraries(testZfpField4d cmocka zfp) add_test(NAME testZfpField4d COMMAND testZfpField4d) if(HAVE_LIBM_MATH) target_link_libraries(testZfpHeader m) target_link_libraries(testZfpStream m) endif() zfp-1.0.1/tests/src/misc/testZfpField1d.c000066400000000000000000000005101453723256400201770ustar00rootroot00000000000000#include "zfp.h" #include #include #include #include #include #include #define DIMS 1 #define ZFP_TYPE zfp_type_double #define SCALAR double #define NX 20 #define SX 2 #include "zfpFieldBase.c" #undef DIMS #undef ZFP_TYPE #undef SCALAR #undef NX #undef SX zfp-1.0.1/tests/src/misc/testZfpField1f.c000066400000000000000000000005061453723256400202060ustar00rootroot00000000000000#include "zfp.h" #include #include #include #include #include #include #define DIMS 1 #define ZFP_TYPE zfp_type_float #define SCALAR float #define NX 20 #define SX 2 #include "zfpFieldBase.c" #undef DIMS #undef ZFP_TYPE #undef SCALAR #undef NX #undef SX zfp-1.0.1/tests/src/misc/testZfpField2d.c000066400000000000000000000005671453723256400202140ustar00rootroot00000000000000#include "zfp.h" #include #include #include #include #include #include #define DIMS 2 #define ZFP_TYPE zfp_type_double #define SCALAR double #define NX 20 #define NY 21 #define SX 2 #define SY 3 #include "zfpFieldBase.c" #undef DIMS #undef ZFP_TYPE #undef SCALAR #undef NX #undef NY #undef SX #undef SY zfp-1.0.1/tests/src/misc/testZfpField2f.c000066400000000000000000000005651453723256400202140ustar00rootroot00000000000000#include "zfp.h" #include #include #include #include #include #include #define DIMS 2 #define ZFP_TYPE zfp_type_float #define SCALAR float #define NX 20 #define NY 21 #define SX 2 #define SY 3 #include "zfpFieldBase.c" #undef DIMS #undef ZFP_TYPE #undef SCALAR #undef NX #undef NY #undef SX #undef SY zfp-1.0.1/tests/src/misc/testZfpField3d.c000066400000000000000000000006461453723256400202130ustar00rootroot00000000000000#include "zfp.h" #include #include #include #include #include #include #define DIMS 3 #define ZFP_TYPE zfp_type_double #define SCALAR double #define NX 20 #define NY 21 #define NZ 12 #define SX 2 #define SY 3 #define SZ 4 #include "zfpFieldBase.c" #undef DIMS #undef ZFP_TYPE #undef SCALAR #undef NX #undef NY #undef NZ #undef SX #undef SY #undef SZ zfp-1.0.1/tests/src/misc/testZfpField3f.c000066400000000000000000000006441453723256400202130ustar00rootroot00000000000000#include "zfp.h" #include #include #include #include #include #include #define DIMS 3 #define ZFP_TYPE zfp_type_float #define SCALAR float #define NX 20 #define NY 21 #define NZ 12 #define SX 2 #define SY 3 #define SZ 4 #include "zfpFieldBase.c" #undef DIMS #undef ZFP_TYPE #undef SCALAR #undef NX #undef NY #undef NZ #undef SX #undef SY #undef SZ zfp-1.0.1/tests/src/misc/testZfpField4d.c000066400000000000000000000007241453723256400202110ustar00rootroot00000000000000#include "zfp.h" #include #include #include #include #include #include #define DIMS 4 #define ZFP_TYPE zfp_type_double #define SCALAR double #define NX 20 #define NY 21 #define NZ 12 #define NW 6 #define SX 2 #define SY 3 #define SZ 4 #define SW 2 #include "zfpFieldBase.c" #undef DIMS #undef ZFP_TYPE #undef SCALAR #undef NX #undef NY #undef NZ #undef NW #undef SX #undef SY #undef SZ #undef SW zfp-1.0.1/tests/src/misc/testZfpField4f.c000066400000000000000000000007221453723256400202110ustar00rootroot00000000000000#include "zfp.h" #include #include #include #include #include #include #define DIMS 4 #define ZFP_TYPE zfp_type_float #define SCALAR float #define NX 20 #define NY 21 #define NZ 12 #define NW 6 #define SX 2 #define SY 3 #define SZ 4 #define SW 2 #include "zfpFieldBase.c" #undef DIMS #undef ZFP_TYPE #undef SCALAR #undef NX #undef NY #undef NZ #undef NW #undef SX #undef SY #undef SZ #undef SW zfp-1.0.1/tests/src/misc/testZfpHeader.c000066400000000000000000000412141453723256400201250ustar00rootroot00000000000000#include "src/encode1d.c" #include "constants/1dDouble.h" #include #include #include #include #include #define FIELD_X_LEN 33 #define FIELD_Y_LEN 401 // custom compression parameters #define MIN_BITS 11u #define MAX_BITS 1001u #define MAX_PREC 52u #define MIN_EXP (-1000) #define PREC 44 #define ACC 1e-4 struct setupVars { void* buffer; zfp_stream* stream; zfp_field* field; }; static int setup(void **state) { struct setupVars *bundle = malloc(sizeof(struct setupVars)); assert_non_null(bundle); zfp_type type = ZFP_TYPE; zfp_field* field = zfp_field_2d(NULL, type, FIELD_X_LEN, FIELD_Y_LEN); zfp_stream* stream = zfp_stream_open(NULL); zfp_stream_set_rate(stream, ZFP_RATE_PARAM_BITS, type, DIMS, zfp_false); size_t bufsizeBytes = zfp_stream_maximum_size(stream, field); bundle->buffer = calloc(bufsizeBytes, sizeof(char)); assert_non_null(bundle->buffer); bitstream* s = stream_open(bundle->buffer, bufsizeBytes); assert_non_null(s); zfp_stream_set_bit_stream(stream, s); zfp_stream_rewind(stream); bundle->stream = stream; bundle->field = field; *state = bundle; return 0; } static int teardown(void **state) { struct setupVars *bundle = *state; stream_close(bundle->stream->stream); zfp_stream_close(bundle->stream); zfp_field_free(bundle->field); free(bundle->buffer); free(bundle); return 0; } static void when_zfpFieldMetadataCalled_expect_LSB2BitsEncodeScalarType(void **state) { struct setupVars *bundle = *state; zfp_field* field = bundle->field; uint64 metadata = zfp_field_metadata(field); uint zfpType = (metadata & 0x3u) + 1; assert_int_equal(zfpType, ZFP_TYPE); } static void when_zfpFieldMetadataCalled_expect_LSBBits3To4EncodeDimensionality(void **state) { struct setupVars *bundle = *state; zfp_field* field = bundle->field; uint64 metadata = zfp_field_metadata(field); uint dimensionality = ((metadata >> 2) & 0x3u) + 1; // setup uses a 2d field assert_int_equal(dimensionality, 2); } static void when_zfpFieldMetadataCalled_expect_LSBBits5To53EncodeArrayDimensions(void **state) { uint MASK_24_BITS = 0xffffffu; uint64 MASK_48_BITS = 0xffffffffffffu; struct setupVars *bundle = *state; zfp_field* field = bundle->field; uint64 metadata = zfp_field_metadata(field); // setup uses a 2d field uint64 metadataEncodedDims = (metadata >> 4) & MASK_48_BITS; uint nx = (uint)((metadataEncodedDims & MASK_24_BITS) + 1); metadataEncodedDims >>= 24; uint ny = (uint)((metadataEncodedDims & MASK_24_BITS) + 1); assert_int_equal(nx, FIELD_X_LEN); assert_int_equal(ny, FIELD_Y_LEN); } static void when_zfpFieldSetMetadataCalled_expect_scalarTypeSet(void **state) { struct setupVars *bundle = *state; zfp_field* field = bundle->field; uint64 metadata = zfp_field_metadata(field); // reset field parameter field->type = zfp_type_none; zfp_field_set_metadata(field, metadata); assert_int_equal(field->type, ZFP_TYPE); } static void when_zfpFieldSetMetadataCalled_expect_arrayDimensionsSet(void **state) { struct setupVars *bundle = *state; zfp_field* field = bundle->field; uint64 metadata = zfp_field_metadata(field); // reset dimension values zfp_field_set_size_3d(field, 0, 0, 0); zfp_field_set_metadata(field, metadata); // setup uses a 2d field assert_int_equal(field->nx, FIELD_X_LEN); assert_int_equal(field->ny, FIELD_Y_LEN); assert_int_equal(field->nz, 0); } static void when_zfpFieldMetadataCalled_onInvalidSize_expect_ZFP_META_NULL(void **state) { struct setupVars *bundle = *state; zfp_field* field = bundle->field; uint64 metadata = zfp_field_metadata(field); // setup uses a 2d field field->nx = 1 << 25; field->ny = 1 << 25; uint64 meta = zfp_field_metadata(field); assert_int_equal(meta, ZFP_META_NULL); } static void when_zfpFieldSetMetadataCalled_forInvalidMeta_expect_false(void **state) { struct setupVars *bundle = *state; zfp_field* field = bundle->field; uint64 meta = 1ULL << (ZFP_META_BITS + 1); zfp_bool status = zfp_field_set_metadata(field, meta); assert_int_equal(status, zfp_false); } static void when_zfpWriteHeaderMagic_expect_numBitsWrittenEqualToZFP_MAGIC_BITS(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; assert_int_equal(zfp_write_header(stream, bundle->field, ZFP_HEADER_MAGIC), ZFP_MAGIC_BITS); // check bitstream buffer bitstream* s = zfp_stream_bit_stream(stream); assert_int_equal(s->bits, ZFP_MAGIC_BITS); } static void when_zfpWriteHeaderMagic_expect_24BitsAreCharsZfpFollowedBy8BitsZfpCodecVersion(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; assert_int_equal(zfp_write_header(stream, bundle->field, ZFP_HEADER_MAGIC), ZFP_MAGIC_BITS); zfp_stream_flush(stream); zfp_stream_rewind(stream); bitstream* s = zfp_stream_bit_stream(stream); uint64 char1 = stream_read_bits(s, 8); uint64 char2 = stream_read_bits(s, 8); uint64 char3 = stream_read_bits(s, 8); uint64 zfp_codec_version = stream_read_bits(s, 8); assert_int_equal(char1, 'z'); assert_int_equal(char2, 'f'); assert_int_equal(char3, 'p'); assert_int_equal(zfp_codec_version, ZFP_CODEC); } static void when_zfpWriteHeaderMetadata_expect_numBitsWrittenEqualToZFP_META_BITS(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; assert_int_equal(zfp_write_header(stream, bundle->field, ZFP_HEADER_META), ZFP_META_BITS); } static void given_fixedRate_when_zfpWriteHeaderMode_expect_12BitsWrittenToBitstream(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; // setup uses fixed rate assert_int_equal(zfp_write_header(stream, bundle->field, ZFP_HEADER_MODE), ZFP_MODE_SHORT_BITS); } static void given_fixedPrecision_when_zfpWriteHeaderMode_expect_12BitsWrittenToBitstream(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; zfp_stream_set_precision(stream, PREC); assert_int_equal(zfp_write_header(stream, bundle->field, ZFP_HEADER_MODE), ZFP_MODE_SHORT_BITS); } static void given_fixedAccuracy_when_zfpWriteHeaderMode_expect_12BitsWrittenToBitstream(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; zfp_stream_set_accuracy(stream, ACC); assert_int_equal(zfp_write_header(stream, bundle->field, ZFP_HEADER_MODE), ZFP_MODE_SHORT_BITS); } static void given_customCompressParamsSet_when_zfpWriteHeaderMode_expect_64BitsWrittenToBitstream(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; assert_int_equal(zfp_stream_set_params(stream, MIN_BITS, MAX_BITS, MAX_PREC, MIN_EXP), 1); assert_int_equal(zfp_write_header(stream, bundle->field, ZFP_HEADER_MODE), ZFP_MODE_LONG_BITS); } static void setupAndAssertProperNumBitsRead(void **state, uint mask, size_t expectedWrittenBits, size_t expectedReadBits) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; assert_int_equal(zfp_write_header(stream, bundle->field, mask), expectedWrittenBits); zfp_stream_flush(stream); zfp_stream_rewind(stream); assert_int_equal(zfp_read_header(stream, bundle->field, mask), expectedReadBits); // check bitstream buffer bitstream* s = zfp_stream_bit_stream(stream); // use expectedWrittenBits because when zfp_read_header() returns 0, the bitstream is still displaced assert_int_equal(s->bits, wsize - expectedWrittenBits); } static void when_zfpReadHeaderMagic_expect_properNumBitsRead(void **state) { setupAndAssertProperNumBitsRead(state, ZFP_HEADER_MAGIC, ZFP_MAGIC_BITS, ZFP_MAGIC_BITS); } static void given_improperHeader_when_zfpReadHeaderMagic_expect_returnsZero(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; // bitstream is zeros assert_int_equal(zfp_read_header(stream, bundle->field, ZFP_HEADER_MAGIC), 0); assert_int_equal(zfp_stream_bit_stream(stream)->bits, 64 - 8); } static void when_zfpReadHeaderMetadata_expect_properNumBitsRead(void **state) { setupAndAssertProperNumBitsRead(state, ZFP_HEADER_META, ZFP_META_BITS, ZFP_META_BITS); } static void given_properHeader_when_zfpReadHeaderMetadata_expect_fieldArrayDimsSet(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; zfp_field* field = bundle->field; size_t nx = field->nx; size_t ny = field->ny; size_t nz = field->nz; // write header to bitstream assert_int_equal(zfp_write_header(stream, bundle->field, ZFP_HEADER_META), ZFP_META_BITS); zfp_stream_flush(stream); zfp_stream_rewind(stream); // reset field->nx, ny, nz zfp_field_set_size_3d(field, 0, 0, 0); assert_int_equal(zfp_read_header(stream, bundle->field, ZFP_HEADER_META), ZFP_META_BITS); assert_int_equal(field->nx, nx); assert_int_equal(field->ny, ny); assert_int_equal(field->nz, nz); } static void given_properHeaderFixedRate_when_zfpReadHeaderMode_expect_properNumBitsRead(void **state) { setupAndAssertProperNumBitsRead(state, ZFP_HEADER_MODE, ZFP_MODE_SHORT_BITS, ZFP_MODE_SHORT_BITS); } static void given_properHeaderFixedPrecision_when_zfpReadHeaderMode_expect_properNumBitsRead(void **state) { struct setupVars *bundle = *state; zfp_stream_set_precision(bundle->stream, PREC); setupAndAssertProperNumBitsRead(state, ZFP_HEADER_MODE, ZFP_MODE_SHORT_BITS, ZFP_MODE_SHORT_BITS); } static void given_properHeaderFixedAccuracy_when_zfpReadHeaderMode_expect_properNumBitsRead(void **state) { struct setupVars *bundle = *state; zfp_stream_set_accuracy(bundle->stream, ACC); setupAndAssertProperNumBitsRead(state, ZFP_HEADER_MODE, ZFP_MODE_SHORT_BITS, ZFP_MODE_SHORT_BITS); } static void given_customCompressParamsSet_when_zfpReadHeaderMode_expect_properNumBitsRead(void **state) { struct setupVars *bundle = *state; assert_int_equal(zfp_stream_set_params(bundle->stream, MIN_BITS, MAX_BITS, MAX_PREC, MIN_EXP), 1); setupAndAssertProperNumBitsRead(state, ZFP_HEADER_MODE, ZFP_MODE_LONG_BITS, ZFP_MODE_LONG_BITS); } static void setInvalidCompressParams(zfp_stream* stream) { assert_int_equal(zfp_stream_set_params(stream, MAX_BITS + 1, MAX_BITS, MAX_PREC, MIN_EXP), 0); stream->minbits = MAX_BITS + 1; stream->maxbits = MAX_BITS; stream->maxprec = MAX_PREC; stream->minexp = MIN_EXP; } static void given_invalidCompressParamsInHeader_when_zfpReadHeaderMode_expect_properNumBitsRead(void **state) { struct setupVars *bundle = *state; setInvalidCompressParams(bundle->stream); setupAndAssertProperNumBitsRead(state, ZFP_HEADER_MODE, ZFP_MODE_LONG_BITS, 0); } static void assertCompressParamsBehaviorWhenReadHeader(void **state, int expectedWrittenBits, int expectedReadBits) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; zfp_field* field = bundle->field; uint minBits, maxBits, maxPrec; int minExp; zfp_stream_params(stream, &minBits, &maxBits, &maxPrec, &minExp); assert_int_equal(zfp_write_header(stream, field, ZFP_HEADER_MODE), expectedWrittenBits); zfp_stream_flush(stream); zfp_stream_rewind(stream); assert_int_equal(zfp_stream_set_params(stream, ZFP_MIN_BITS, ZFP_MAX_BITS, ZFP_MAX_PREC, ZFP_MIN_EXP), 1); assert_int_equal(zfp_read_header(stream, field, ZFP_HEADER_MODE), expectedReadBits); if (!expectedReadBits) { // expect params were not set assert_int_not_equal(stream->minbits, minBits); assert_int_not_equal(stream->maxbits, maxBits); assert_int_not_equal(stream->maxprec, maxPrec); assert_int_not_equal(stream->minexp, minExp); } else { assert_int_equal(stream->minbits, minBits); assert_int_equal(stream->maxbits, maxBits); assert_int_equal(stream->maxprec, maxPrec); assert_int_equal(stream->minexp, minExp); } } static void given_properHeaderFixedRate_when_zfpReadHeaderMode_expect_streamParamsSet(void **state) { assertCompressParamsBehaviorWhenReadHeader(state, ZFP_MODE_SHORT_BITS, ZFP_MODE_SHORT_BITS); } static void given_properHeaderFixedPrecision_when_zfpReadHeaderMode_expect_streamParamsSet(void **state) { struct setupVars *bundle = *state; zfp_stream_set_precision(bundle->stream, PREC); assertCompressParamsBehaviorWhenReadHeader(state, ZFP_MODE_SHORT_BITS, ZFP_MODE_SHORT_BITS); } static void given_properHeaderFixedAccuracy_when_zfpReadHeaderMode_expect_streamParamsSet(void **state) { struct setupVars *bundle = *state; zfp_stream_set_accuracy(bundle->stream, ACC); assertCompressParamsBehaviorWhenReadHeader(state, ZFP_MODE_SHORT_BITS, ZFP_MODE_SHORT_BITS); } static void given_customCompressParamsAndProperHeader_when_zfpReadHeaderMode_expect_streamParamsSet(void **state) { struct setupVars *bundle = *state; assert_int_equal(zfp_stream_set_params(bundle->stream, MIN_BITS, MAX_BITS, MAX_PREC, MIN_EXP), 1); assertCompressParamsBehaviorWhenReadHeader(state, ZFP_MODE_LONG_BITS, ZFP_MODE_LONG_BITS); } static void given_invalidCompressParamsInHeader_when_zfpReadHeaderMode_expect_streamParamsNotSet(void **state) { struct setupVars *bundle = *state; setInvalidCompressParams(bundle->stream); assertCompressParamsBehaviorWhenReadHeader(state, ZFP_MODE_LONG_BITS, 0); } int main() { const struct CMUnitTest tests[] = { // (non zfp_stream) functions involved in zfp header cmocka_unit_test_setup_teardown(when_zfpFieldMetadataCalled_expect_LSB2BitsEncodeScalarType, setup, teardown), cmocka_unit_test_setup_teardown(when_zfpFieldMetadataCalled_expect_LSBBits3To4EncodeDimensionality, setup, teardown), cmocka_unit_test_setup_teardown(when_zfpFieldMetadataCalled_expect_LSBBits5To53EncodeArrayDimensions, setup, teardown), cmocka_unit_test_setup_teardown(when_zfpFieldSetMetadataCalled_expect_scalarTypeSet, setup, teardown), cmocka_unit_test_setup_teardown(when_zfpFieldSetMetadataCalled_expect_arrayDimensionsSet, setup, teardown), // write header cmocka_unit_test_setup_teardown(when_zfpWriteHeaderMagic_expect_numBitsWrittenEqualToZFP_MAGIC_BITS, setup, teardown), cmocka_unit_test_setup_teardown(when_zfpFieldMetadataCalled_onInvalidSize_expect_ZFP_META_NULL, setup, teardown), cmocka_unit_test_setup_teardown(when_zfpFieldSetMetadataCalled_forInvalidMeta_expect_false, setup, teardown), cmocka_unit_test_setup_teardown(when_zfpWriteHeaderMagic_expect_24BitsAreCharsZfpFollowedBy8BitsZfpCodecVersion, setup, teardown), cmocka_unit_test_setup_teardown(when_zfpWriteHeaderMetadata_expect_numBitsWrittenEqualToZFP_META_BITS, setup, teardown), cmocka_unit_test_setup_teardown(given_fixedRate_when_zfpWriteHeaderMode_expect_12BitsWrittenToBitstream, setup, teardown), cmocka_unit_test_setup_teardown(given_fixedPrecision_when_zfpWriteHeaderMode_expect_12BitsWrittenToBitstream, setup, teardown), cmocka_unit_test_setup_teardown(given_fixedAccuracy_when_zfpWriteHeaderMode_expect_12BitsWrittenToBitstream, setup, teardown), cmocka_unit_test_setup_teardown(given_customCompressParamsSet_when_zfpWriteHeaderMode_expect_64BitsWrittenToBitstream, setup, teardown), // read header cmocka_unit_test_setup_teardown(when_zfpReadHeaderMagic_expect_properNumBitsRead, setup, teardown), cmocka_unit_test_setup_teardown(given_improperHeader_when_zfpReadHeaderMagic_expect_returnsZero, setup, teardown), cmocka_unit_test_setup_teardown(when_zfpReadHeaderMetadata_expect_properNumBitsRead, setup, teardown), cmocka_unit_test_setup_teardown(given_properHeader_when_zfpReadHeaderMetadata_expect_fieldArrayDimsSet, setup, teardown), cmocka_unit_test_setup_teardown(given_properHeaderFixedRate_when_zfpReadHeaderMode_expect_properNumBitsRead, setup, teardown), cmocka_unit_test_setup_teardown(given_properHeaderFixedPrecision_when_zfpReadHeaderMode_expect_properNumBitsRead, setup, teardown), cmocka_unit_test_setup_teardown(given_properHeaderFixedAccuracy_when_zfpReadHeaderMode_expect_properNumBitsRead, setup, teardown), cmocka_unit_test_setup_teardown(given_properHeaderFixedRate_when_zfpReadHeaderMode_expect_streamParamsSet, setup, teardown), cmocka_unit_test_setup_teardown(given_properHeaderFixedPrecision_when_zfpReadHeaderMode_expect_streamParamsSet, setup, teardown), cmocka_unit_test_setup_teardown(given_properHeaderFixedAccuracy_when_zfpReadHeaderMode_expect_streamParamsSet, setup, teardown), cmocka_unit_test_setup_teardown(given_customCompressParamsSet_when_zfpReadHeaderMode_expect_properNumBitsRead, setup, teardown), cmocka_unit_test_setup_teardown(given_customCompressParamsAndProperHeader_when_zfpReadHeaderMode_expect_streamParamsSet, setup, teardown), cmocka_unit_test_setup_teardown(given_invalidCompressParamsInHeader_when_zfpReadHeaderMode_expect_properNumBitsRead, setup, teardown), cmocka_unit_test_setup_teardown(given_invalidCompressParamsInHeader_when_zfpReadHeaderMode_expect_streamParamsNotSet, setup, teardown), }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/misc/testZfpPromote.c000066400000000000000000000061541453723256400203660ustar00rootroot00000000000000#include "zfp.h" #include #include #include #include #include #include #include #include #include static void given_int8_when_promoteToInt32_expect_demoteToInt8Matches(void **state) { uint dims = 3; uint sz = 1u << (2 * dims); int8* iblock8 = (int8*)malloc(sizeof(int8)*sz); int8* oblock8 = (int8*)calloc(sz, sizeof(int8)); int32* block32 = (int32*)malloc(sizeof(int32)*sz); assert_non_null(iblock8); assert_non_null(oblock8); assert_non_null(block32); uint i; for (i = 0; i < sz; i++) iblock8[i] = (int8)i; zfp_promote_int8_to_int32(block32, iblock8, dims); zfp_demote_int32_to_int8(oblock8, block32, dims); for (i = 0; i < sz; i++) assert_int_equal(iblock8[i], oblock8[i]); } static void given_uint8_when_promoteToInt32_expect_demoteToUInt8Matches(void **state) { uint dims = 3; uint sz = 1u << (2 * dims); uint8* iblock8 = (uint8*)malloc(sizeof(uint8)*sz); uint8* oblock8 = (uint8*)calloc(sz, sizeof(uint8)); int32* block32 = (int32*)malloc(sizeof(int32)*sz); assert_non_null(iblock8); assert_non_null(oblock8); assert_non_null(block32); uint i; for (i = 0; i < sz; i++) iblock8[i] = (uint8)i; zfp_promote_uint8_to_int32(block32, iblock8, dims); zfp_demote_int32_to_uint8(oblock8, block32, dims); for (i = 0; i < sz; i++) assert_int_equal(iblock8[i], oblock8[i]); } static void given_int16_when_promoteToInt32_expect_demoteToInt16Matches(void **state) { uint dims = 3; uint sz = 1u << (2 * dims); int16* iblock16 = (int16*)malloc(sizeof(int16)*sz); int16* oblock16 = (int16*)calloc(sz, sizeof(int16)); int32* block32 = (int32*)malloc(sizeof(int32)*sz); assert_non_null(iblock16); assert_non_null(oblock16); assert_non_null(block32); uint i; for (i = 0; i < sz; i++) iblock16[i] = (int16)i; zfp_promote_int16_to_int32(block32, iblock16, dims); zfp_demote_int32_to_int16(oblock16, block32, dims); for (i = 0; i < sz; i++) assert_int_equal(iblock16[i], oblock16[i]); } static void given_uint16_when_promoteToInt32_expect_demoteToUInt16Matches(void **state) { uint dims = 3; uint sz = 1u << (2 * dims); uint16* iblock16 = (uint16*)malloc(sizeof(uint16)*sz); uint16* oblock16 = (uint16*)calloc(sz, sizeof(uint16)); int32* block32 = (int32*)malloc(sizeof(int32)*sz); assert_non_null(iblock16); assert_non_null(oblock16); assert_non_null(block32); uint i; for (i = 0; i < sz; i++) iblock16[i] = (uint16)i; zfp_promote_uint16_to_int32(block32, iblock16, dims); zfp_demote_int32_to_uint16(oblock16, block32, dims); for (i = 0; i < sz; i++) assert_int_equal(iblock16[i], oblock16[i]); } int main() { const struct CMUnitTest tests[] = { cmocka_unit_test(given_int8_when_promoteToInt32_expect_demoteToInt8Matches), cmocka_unit_test(given_uint8_when_promoteToInt32_expect_demoteToUInt8Matches), cmocka_unit_test(given_int16_when_promoteToInt32_expect_demoteToInt16Matches), cmocka_unit_test(given_uint16_when_promoteToInt32_expect_demoteToUInt16Matches), }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/misc/testZfpStream.c000066400000000000000000001031231453723256400201660ustar00rootroot00000000000000#include "zfp.h" #include #include #include #include #include #include #include #include #include // expert mode compression parameters #define MIN_BITS 11u #define MAX_BITS 1001u #define MAX_PREC 52u #define MIN_EXP (-1000) #define MAX_EXP 1023 struct setupVars { zfp_stream* stream; }; static int setup(void **state) { struct setupVars *bundle = malloc(sizeof(struct setupVars)); assert_non_null(bundle); zfp_stream* stream = zfp_stream_open(NULL); bundle->stream = stream; *state = bundle; return 0; } static int teardown(void **state) { struct setupVars *bundle = *state; zfp_stream_close(bundle->stream); free(bundle); return 0; } static void given_openedZfpStream_when_zfpStreamCompressionMode_expect_returnsExpertEnum(void **state) { struct setupVars *bundle = *state; // default values imply expert mode assert_int_equal(zfp_stream_compression_mode(bundle->stream), zfp_mode_expert); } static void given_zfpStreamSetWithInvalidParams_when_zfpStreamCompressionMode_expect_returnsNullEnum(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; assert_int_equal(zfp_stream_compression_mode(stream), zfp_mode_expert); // ensure this config would be rejected by zfp_stream_set_params() assert_int_equal(zfp_stream_set_params(stream, stream->maxbits + 1, stream->maxbits, stream->maxprec, stream->minexp), 0); stream->minbits = stream->maxbits + 1; assert_int_equal(zfp_stream_compression_mode(stream), zfp_mode_null); } static void setNonExpertMode(zfp_stream* stream) { zfp_stream_set_precision(stream, ZFP_MAX_PREC - 2); assert_int_not_equal(zfp_stream_compression_mode(stream), zfp_mode_expert); } static void setDefaultCompressionParams(zfp_stream* stream) { /* reset to expert mode */ assert_int_equal(zfp_stream_set_params(stream, ZFP_MIN_BITS, ZFP_MAX_BITS, ZFP_MAX_PREC, ZFP_MIN_EXP), 1); assert_int_equal(zfp_stream_compression_mode(stream), zfp_mode_expert); } static void given_zfpStreamSetWithFixedRate_when_zfpStreamCompressionMode_expect_returnsFixedRateEnum(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; zfp_type zfpType; uint dims; int rate; int align; for (zfpType = (zfp_type)1; zfpType <= (zfp_type)4; zfpType++) { for (dims = 1; dims <= 4; dims++) { for (rate = 1; rate <= ((zfpType % 2) ? 32 : 64); rate++) { for (align = 0; align <= 1; align++) { setDefaultCompressionParams(stream); /* set fixed-rate, assert fixed-rate identified */ zfp_stream_set_rate(stream, rate, zfpType, dims, (zfp_bool)align); zfp_mode mode = zfp_stream_compression_mode(stream); if (mode != zfp_mode_fixed_rate) { fail_msg("Setting zfp_stream with zfp_type %u, fixed rate %d, align = %d, in %u dimensions returned zfp_mode enum %u", zfpType, rate, align, dims, mode); } } } } } } static void given_zfpStreamSetWithFixedRate_when_zfpStreamRate_expect_returnsSameRate(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; zfp_type zfpType; uint dims; double rate, set_rate, actual_rate; int align; int i; for (zfpType = (zfp_type)1; zfpType <= (zfp_type)4; zfpType++) { for (dims = 1; dims <= 4; dims++) { for (i = 1; i <= 4; i++) { rate = (double)zfp_type_size(zfpType) * CHAR_BIT * i / 4; for (align = 0; align <= 1; align++) { setDefaultCompressionParams(stream); /* set fixed-rate, assert same rate identified */ set_rate = zfp_stream_set_rate(stream, rate, zfpType, dims, (zfp_bool)align); actual_rate = zfp_stream_rate(stream, dims); if (actual_rate != set_rate) { fail_msg("Setting zfp_stream with zfp_type %u, fixed rate %g, obtained rate %g, align = %d, in %u dimensions returned rate %g", zfpType, rate, set_rate, align, dims, actual_rate); } } } } } } static void given_zfpStreamSetWithFixedPrecision_when_zfpStreamCompressionMode_expect_returnsFixedPrecisionEnum(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; uint prec; /* float/int32 technically sees no improvement in compression for prec>32 */ /* (prec=ZFP_MAX_PREC handled in next test case) */ for (prec = 1; prec < ZFP_MAX_PREC; prec++) { setDefaultCompressionParams(stream); /* set fixed-precision, assert fixed-precision identified */ zfp_stream_set_precision(stream, prec); zfp_mode mode = zfp_stream_compression_mode(stream); if (mode != zfp_mode_fixed_precision) { fail_msg("Setting zfp_stream with fixed precision %u returned zfp_mode enum %u", prec, mode); } } } /* compression params equivalent to default, which are defined as expert mode */ static void given_zfpStreamSetWithMaxPrecision_when_zfpStreamCompressionMode_expect_returnsExpertModeEnum(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; setDefaultCompressionParams(stream); zfp_stream_set_precision(stream, ZFP_MAX_PREC); assert_int_equal(zfp_stream_compression_mode(stream), zfp_mode_expert); } static void given_zfpStreamSetWithFixedPrecision_when_zfpStreamPrecision_expect_returnsSamePrecision(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; uint prec, actual_prec; /* float/int32 technically sees no improvement in compression for prec>32 */ /* (prec=ZFP_MAX_PREC handled in next test case) */ for (prec = 1; prec < ZFP_MAX_PREC; prec++) { setDefaultCompressionParams(stream); /* set fixed-precision, assert fixed-precision identified */ zfp_stream_set_precision(stream, prec); actual_prec = zfp_stream_precision(stream); if (prec != actual_prec) { fail_msg("Setting zfp_stream with fixed precision %u returned precision %u", prec, actual_prec); } } } static void given_zfpStreamSetWithFixedAccuracy_when_zfpStreamCompressionMode_expect_returnsFixedAccuracyEnum(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; int accExp; /* using ZFP_MIN_EXP implies expert mode (all default values) */ for (accExp = MAX_EXP; (accExp > ZFP_MIN_EXP) && (ldexp(1., accExp) != 0.); accExp--) { setDefaultCompressionParams(stream); /* set fixed-accuracy, assert fixed-accuracy identified */ zfp_stream_set_accuracy(stream, ldexp(1., accExp)); zfp_mode mode = zfp_stream_compression_mode(stream); if (mode != zfp_mode_fixed_accuracy) { fail_msg("Setting zfp_stream with fixed accuracy 2^(%d) returned zfp_mode enum %u", accExp, mode); } } } static void given_zfpStreamSetWithFixedAccuracy_when_zfpStreamAccuracy_expect_returnsSameAccuracy(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; double tol, actual_tol; int accExp; /* using ZFP_MIN_EXP implies expert mode (all default values) */ for (accExp = MAX_EXP; (accExp > ZFP_MIN_EXP) && (ldexp(1., accExp) != 0.); accExp--) { setDefaultCompressionParams(stream); /* set fixed-accuracy, assert fixed-accuracy identified */ tol = ldexp(1., accExp); zfp_stream_set_accuracy(stream, tol); actual_tol = zfp_stream_accuracy(stream); if (tol != actual_tol) { fail_msg("Setting zfp_stream with fixed accuracy %g returned accuracy %g", tol, actual_tol); } } } static void given_zfpStreamSetWithReversible_when_zfpStreamCompressionMode_expect_returnsReversibleEnum(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; setDefaultCompressionParams(stream); /* set reversible, assert reversible identified */ zfp_stream_set_reversible(stream); zfp_mode mode = zfp_stream_compression_mode(stream); if (mode != zfp_mode_reversible) { fail_msg("Setting zfp_stream with reversible returned zfp_mode enum %u", mode); } } static void given_zfpStreamSetWithExpertParams_when_zfpStreamCompressionMode_expect_returnsExpertEnum(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; setNonExpertMode(stream); /* successfully set custom expert params, assert change */ assert_int_equal(zfp_stream_set_params(stream, MIN_BITS, MAX_BITS, MAX_PREC, MIN_EXP), 1); assert_int_equal(zfp_stream_compression_mode(stream), zfp_mode_expert); } static void given_zfpStreamDefaultModeVal_when_zfpStreamSetMode_expect_returnsExpertMode_and_compressParamsConserved(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; /* get mode and compression params */ uint64 mode = zfp_stream_mode(stream); uint minbits = stream->minbits; uint maxbits = stream->maxbits; uint maxprec = stream->maxprec; int minexp = stream->minexp; setNonExpertMode(stream); /* see that mode is updated correctly */ assert_int_equal(zfp_stream_set_mode(stream, mode), zfp_mode_expert); /* see that compression params conserved */ if (stream->minbits != minbits || stream->maxbits != maxbits || stream->maxprec != maxprec || stream->minexp != minexp) { printf("Using default params, zfp_stream_set_mode() incorrectly set compression params when fed zfp_stream_mode() = %"UINT64PRIx"\n", mode); fail_msg("The zfp_stream had (minbits, maxbits, maxprec, minexp) = (%u, %u, %u, %d), but was expected to equal (%u, %u, %u, %d)", stream->minbits, stream->maxbits, stream->maxprec, stream->minexp, minbits, maxbits, maxprec, minexp); } } static void given_zfpStreamSetRateModeVal_when_zfpStreamSetMode_expect_returnsFixedRate_and_compressParamsConserved(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; zfp_type zfpType; uint dims; int rate; int align; for (zfpType = (zfp_type)1; zfpType <= (zfp_type)4; zfpType++) { for (dims = 1; dims <= 4; dims++) { for (rate = 1; rate <= ((zfpType % 2) ? 32 : 64); rate++) { for (align = 0; align <= 1; align++) { /* set fixed-rate mode */ zfp_stream_set_rate(stream, rate, zfpType, dims, (zfp_bool)align); assert_int_equal(zfp_stream_compression_mode(stream), zfp_mode_fixed_rate); /* get mode and compression params */ uint64 mode = zfp_stream_mode(stream); uint minbits = stream->minbits; uint maxbits = stream->maxbits; uint maxprec = stream->maxprec; int minexp = stream->minexp; /* set expert mode */ setDefaultCompressionParams(stream); /* see that mode is updated correctly */ zfp_mode zfpMode = zfp_stream_set_mode(stream, mode); if (zfpMode != zfp_mode_fixed_rate) { fail_msg("Using fixed rate %d, align %d, zfp_type %u, in %u dimensions, zfp_stream_compression_mode() incorrectly returned %u", rate, align, zfpType, dims, zfpMode); } /* see that compression params conserved */ if (stream->minbits != minbits || stream->maxbits != maxbits || stream->maxprec != maxprec || stream->minexp != minexp) { printf("Using fixed rate %d, align %d, zfp_type %u, in %u dimensions, zfp_stream_set_mode() incorrectly set compression params when fed zfp_stream_mode() = %"UINT64PRIx"\n", rate, align, zfpType, dims, mode); fail_msg("The zfp_stream had (minbits, maxbits, maxprec, minexp) = (%u, %u, %u, %d), but was expected to equal (%u, %u, %u, %d)", stream->minbits, stream->maxbits, stream->maxprec, stream->minexp, minbits, maxbits, maxprec, minexp); } } } } } } static void given_zfpStreamSetPrecisionModeVal_when_zfpStreamSetMode_expect_returnsFixedPrecision_and_compressParamsConserved(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; uint prec; /* ZFP_MAX_PREC considered expert mode */ for (prec = 1; prec < ZFP_MAX_PREC; prec++) { zfp_stream_set_precision(stream, prec); assert_int_equal(zfp_stream_compression_mode(stream), zfp_mode_fixed_precision); /* get mode and compression params */ uint64 mode = zfp_stream_mode(stream); uint minbits = stream->minbits; uint maxbits = stream->maxbits; uint maxprec = stream->maxprec; int minexp = stream->minexp; /* set expert mode */ setDefaultCompressionParams(stream); /* see that mode is updated correctly */ zfp_mode zfpMode = zfp_stream_set_mode(stream, mode); if (zfpMode != zfp_mode_fixed_precision) { fail_msg("Using fixed precision %u, zfp_stream_compression_mode() incorrectly returned %u", prec, zfpMode); } /* see that compression params conserved */ if (stream->minbits != minbits || stream->maxbits != maxbits || stream->maxprec != maxprec || stream->minexp != minexp) { printf("Using fixed precision %u, zfp_stream_set_mode() incorrectly set compression params when fed zfp_stream_mode() = %"UINT64PRIx"\n", prec, mode); fail_msg("The zfp_stream had (minbits, maxbits, maxprec, minexp) = (%u, %u, %u, %d), but was expected to equal (%u, %u, %u, %d)", stream->minbits, stream->maxbits, stream->maxprec, stream->minexp, minbits, maxbits, maxprec, minexp); } } } /* using precision ZFP_MAX_PREC sets compression params equivalent to default values (expert mode) */ static void given_fixedPrecisionMaxPrecModeVal_when_zfpStreamSetMode_expect_returnsExpert_and_compressParamsConserved(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; zfp_stream_set_precision(stream, ZFP_MAX_PREC); assert_int_equal(zfp_stream_compression_mode(stream), zfp_mode_expert); uint64 mode = zfp_stream_mode(stream); /* set non-expert mode */ zfp_stream_set_precision(stream, ZFP_MAX_PREC - 2); assert_int_not_equal(zfp_stream_compression_mode(stream), zfp_mode_expert); /* see that mode is updated correctly */ assert_int_equal(zfp_stream_set_mode(stream, mode), zfp_mode_expert); /* see that compression params conserved */ assert_int_equal(stream->minbits, ZFP_MIN_BITS); assert_int_equal(stream->maxbits, ZFP_MAX_BITS); assert_int_equal(stream->maxprec, ZFP_MAX_PREC); assert_int_equal(stream->minexp, ZFP_MIN_EXP); } static void given_zfpStreamSetAccuracyModeVal_when_zfpStreamSetMode_expect_returnsFixedAccuracy_and_compressParamsConserved(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; int accExp; for (accExp = MAX_EXP; (accExp > ZFP_MIN_EXP) && (ldexp(1., accExp) != 0.); accExp--) { zfp_stream_set_accuracy(stream, ldexp(1., accExp)); assert_int_equal(zfp_stream_compression_mode(stream), zfp_mode_fixed_accuracy); /* get mode and compression params */ uint64 mode = zfp_stream_mode(stream); uint minbits = stream->minbits; uint maxbits = stream->maxbits; uint maxprec = stream->maxprec; int minexp = stream->minexp; /* set expert mode */ setDefaultCompressionParams(stream); /* see that mode is updated correctly */ zfp_mode zfpMode = zfp_stream_set_mode(stream, mode); if (zfpMode != zfp_mode_fixed_accuracy) { fail_msg("Using fixed accuracy 2^(%d), zfp_stream_compression_mode() incorrectly returned %u", accExp, zfpMode); } /* see that compression params conserved */ if (stream->minbits != minbits || stream->maxbits != maxbits || stream->maxprec != maxprec || stream->minexp != minexp) { printf("Using fixed accuracy 2^(%d), zfp_stream_set_mode() incorrectly set compression params when fed zfp_stream_mode() = %"UINT64PRIx"\n", accExp, mode); fail_msg("The zfp_stream had (minbits, maxbits, maxprec, minexp) = (%u, %u, %u, %d), but was expected to equal (%u, %u, %u, %d)", stream->minbits, stream->maxbits, stream->maxprec, stream->minexp, minbits, maxbits, maxprec, minexp); } } } static void given_zfpStreamSetReversibleModeVal_when_zfpStreamSetMode_expect_returnsReversible_and_compressParamsConserved(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; zfp_stream_set_reversible(stream); assert_int_equal(zfp_stream_compression_mode(stream), zfp_mode_reversible); /* get mode and compression params */ uint64 mode = zfp_stream_mode(stream); uint minbits = stream->minbits; uint maxbits = stream->maxbits; uint maxprec = stream->maxprec; int minexp = stream->minexp; /* set expert mode */ setDefaultCompressionParams(stream); /* see that mode is updated correctly */ zfp_mode zfpMode = zfp_stream_set_mode(stream, mode); if (zfpMode != zfp_mode_reversible) { fail_msg("Using reversible mode, zfp_stream_compression_mode() incorrectly returned %u", zfpMode); } /* see that compression params conserved */ if (stream->minbits != minbits || stream->maxbits != maxbits || stream->maxprec != maxprec || stream->minexp != minexp) { printf("Using reversible mode, zfp_stream_set_mode() incorrectly set compression params when fed zfp_stream_mode() = %"UINT64PRIx"\n", mode); fail_msg("The zfp_stream had (minbits, maxbits, maxprec, minexp) = (%u, %u, %u, %d), but was expected to equal (%u, %u, %u, %d)", stream->minbits, stream->maxbits, stream->maxprec, stream->minexp, minbits, maxbits, maxprec, minexp); } } static void assertCompressParamsBehaviorThroughSetMode(void **state, zfp_mode expectedMode) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; // grab existing values uint minBits = stream->minbits; uint maxBits = stream->maxbits; uint maxPrec = stream->maxprec; int minExp = stream->minexp; uint64 mode = zfp_stream_mode(stream); // reset params assert_int_equal(zfp_stream_set_params(stream, ZFP_MIN_BITS, ZFP_MAX_BITS, ZFP_MAX_PREC, ZFP_MIN_EXP), 1); assert_int_equal(zfp_stream_set_mode(stream, mode), expectedMode); if (expectedMode == zfp_mode_null) { assert_int_not_equal(stream->minbits, minBits); assert_int_not_equal(stream->maxbits, maxBits); assert_int_not_equal(stream->maxprec, maxPrec); assert_int_not_equal(stream->minexp, minExp); } else { assert_int_equal(stream->minbits, minBits); assert_int_equal(stream->maxbits, maxBits); assert_int_equal(stream->maxprec, maxPrec); assert_int_equal(stream->minexp, minExp); } } static void given_customCompressParamsModeVal_when_zfpStreamSetMode_expect_returnsExpert_and_compressParamsConserved(void **state) { struct setupVars *bundle = *state; assert_int_equal(zfp_stream_set_params(bundle->stream, MIN_BITS, MAX_BITS, MAX_PREC, MIN_EXP), 1); assertCompressParamsBehaviorThroughSetMode(state, zfp_mode_expert); } static void given_invalidCompressParamsModeVal_when_zfpStreamSetMode_expect_returnsNullMode_and_paramsNotSet(void **state) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; /* set invalid compress params */ assert_int_equal(zfp_stream_set_params(stream, MAX_BITS + 1, MAX_BITS, MAX_PREC, MIN_EXP), 0); stream->minbits = MAX_BITS + 1; stream->maxbits = MAX_BITS; stream->maxprec = MAX_PREC; stream->minexp = MIN_EXP; assertCompressParamsBehaviorThroughSetMode(state, zfp_mode_null); } static void testStreamAlignSizeMatches(void **state, int dim, zfp_type type) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; zfp_field* field; size_t arrsize = 4 << 2*(dim-1); size_t dimsize = 4; size_t flushsize; size_t alignsize; if (type == zfp_type_float) { float* array; float* block = (float*)calloc(arrsize, sizeof(float)); if (dim == 1) { array = (float*)calloc(dimsize, sizeof(float)); field = zfp_field_1d(array, type, dimsize); } else if (dim == 2) { array = (float*)calloc(dimsize*dimsize, sizeof(float)); field = zfp_field_2d(array, type, dimsize, dimsize); } else if (dim == 3) { array = (float*)calloc(dimsize*dimsize*dimsize, sizeof(float)); field = zfp_field_3d(array, type, dimsize, dimsize, dimsize); } else if (dim == 4) { array = (float*)calloc(dimsize*dimsize*dimsize*dimsize, sizeof(float)); field = zfp_field_4d(array, type, dimsize, dimsize, dimsize, dimsize); } size_t bufsize = zfp_stream_maximum_size(stream, field); void* buffer = malloc(bufsize); bitstream* s = stream_open(buffer, bufsize); zfp_stream_set_bit_stream(stream, s); zfp_stream_rewind(stream); if (dim == 1) { zfp_encode_block_float_1(stream, block); flushsize = zfp_stream_flush(stream); zfp_stream_rewind(stream); zfp_decode_block_float_1(stream, block); alignsize = zfp_stream_align(stream); } else if (dim == 2) { zfp_encode_block_float_2(stream, block); flushsize = zfp_stream_flush(stream); zfp_stream_rewind(stream); zfp_decode_block_float_2(stream, block); alignsize = zfp_stream_align(stream); } else if (dim == 3) { zfp_encode_block_float_3(stream, block); flushsize = zfp_stream_flush(stream); zfp_stream_rewind(stream); zfp_decode_block_float_3(stream, block); alignsize = zfp_stream_align(stream); } else if (dim == 4) { zfp_encode_block_float_4(stream, block); flushsize = zfp_stream_flush(stream); zfp_stream_rewind(stream); zfp_decode_block_float_4(stream, block); alignsize = zfp_stream_align(stream); } free(array); free(block); } else if (type == zfp_type_double) { double* array; double* block = (double*)calloc(arrsize, sizeof(double)); if (dim == 1) { array = (double*)calloc(dimsize, sizeof(double)); field = zfp_field_1d(array, type, dimsize); } else if (dim == 2) { array = (double*)calloc(dimsize*dimsize, sizeof(double)); field = zfp_field_2d(array, type, dimsize, dimsize); } else if (dim == 3) { array = (double*)calloc(dimsize*dimsize*dimsize, sizeof(double)); field = zfp_field_3d(array, type, dimsize, dimsize, dimsize); } else if (dim == 4) { array = (double*)calloc(dimsize*dimsize*dimsize*dimsize, sizeof(double)); field = zfp_field_4d(array, type, dimsize, dimsize, dimsize, dimsize); } size_t bufsize = zfp_stream_maximum_size(stream, field); void* buffer = malloc(bufsize); bitstream* s = stream_open(buffer, bufsize); zfp_stream_set_bit_stream(stream, s); zfp_stream_rewind(stream); if (dim == 1) { zfp_encode_block_double_1(stream, block); flushsize = zfp_stream_flush(stream); zfp_stream_rewind(stream); zfp_decode_block_double_1(stream, block); alignsize = zfp_stream_align(stream); } else if (dim == 2) { zfp_encode_block_double_2(stream, block); flushsize = zfp_stream_flush(stream); zfp_stream_rewind(stream); zfp_decode_block_double_2(stream, block); alignsize = zfp_stream_align(stream); } else if (dim == 3) { zfp_encode_block_double_3(stream, block); flushsize = zfp_stream_flush(stream); zfp_stream_rewind(stream); zfp_decode_block_double_3(stream, block); alignsize = zfp_stream_align(stream); } else if (dim == 4) { zfp_encode_block_double_4(stream, block); flushsize = zfp_stream_flush(stream); zfp_stream_rewind(stream); zfp_decode_block_double_4(stream, block); alignsize = zfp_stream_align(stream); } free(array); free(block); } assert_true(flushsize > 0); assert_true(flushsize == alignsize); } static void given_block1f_when_StreamFlush_expect_StreamAlignSizeMatches(void **state) { testStreamAlignSizeMatches(state, 1, zfp_type_float); } static void given_block2f_when_StreamFlush_expect_StreamAlignSizeMatches(void **state) { testStreamAlignSizeMatches(state, 2, zfp_type_float); } static void given_block3f_when_StreamFlush_expect_StreamAlignSizeMatches(void **state) { testStreamAlignSizeMatches(state, 3, zfp_type_float); } static void given_block4f_when_StreamFlush_expect_StreamAlignSizeMatches(void **state) { testStreamAlignSizeMatches(state, 4, zfp_type_float); } static void given_block1d_when_StreamFlush_expect_StreamAlignSizeMatches(void **state) { testStreamAlignSizeMatches(state, 1, zfp_type_double); } static void given_block2d_when_StreamFlush_expect_StreamAlignSizeMatches(void **state) { testStreamAlignSizeMatches(state, 2, zfp_type_double); } static void given_block3d_when_StreamFlush_expect_StreamAlignSizeMatches(void **state) { testStreamAlignSizeMatches(state, 3, zfp_type_double); } static void given_block4d_when_StreamFlush_expect_StreamAlignSizeMatches(void **state) { testStreamAlignSizeMatches(state, 4, zfp_type_double); } static void testStreamCompressedSizeIncreasedCorrectly(void **state, int dim, zfp_type type) { struct setupVars *bundle = *state; zfp_stream* stream = bundle->stream; zfp_field* field; /* use fixed rate mode to simplify size calculation */ double rate = zfp_stream_set_rate(stream, 64, type, dim, 0); size_t blocksize = 4 << 2*(dim-1); size_t dimsize = 4; size_t startsize; size_t endsize; if (type == zfp_type_float) { float* array = (float*)calloc(blocksize, sizeof(float)); float* block = (float*)calloc(blocksize, sizeof(float)); if (dim == 1) field = zfp_field_1d(array, type, dimsize); else if (dim == 2) field = zfp_field_2d(array, type, dimsize, dimsize); else if (dim == 3) field = zfp_field_3d(array, type, dimsize, dimsize, dimsize); else if (dim == 4) field = zfp_field_4d(array, type, dimsize, dimsize, dimsize, dimsize); size_t bufsize = zfp_stream_maximum_size(stream, field); void* buffer = malloc(bufsize); bitstream* s = stream_open(buffer, bufsize); zfp_stream_set_bit_stream(stream, s); zfp_stream_rewind(stream); startsize = zfp_stream_compressed_size(stream); if (dim == 1) zfp_encode_block_float_1(stream, block); else if (dim == 2) zfp_encode_block_float_2(stream, block); else if (dim == 3) zfp_encode_block_float_3(stream, block); else if (dim == 4) zfp_encode_block_float_4(stream, block); endsize = zfp_stream_compressed_size(stream); free(array); free(block); } else if (type == zfp_type_double) { double* array = (double*)calloc(blocksize, sizeof(double)); double* block = (double*)calloc(blocksize, sizeof(double)); if (dim == 1) field = zfp_field_1d(array, type, dimsize); else if (dim == 2) field = zfp_field_2d(array, type, dimsize, dimsize); else if (dim == 3) field = zfp_field_3d(array, type, dimsize, dimsize, dimsize); else if (dim == 4) field = zfp_field_4d(array, type, dimsize, dimsize, dimsize, dimsize); size_t bufsize = zfp_stream_maximum_size(stream, field); void* buffer = malloc(bufsize); bitstream* s = stream_open(buffer, bufsize); zfp_stream_set_bit_stream(stream, s); zfp_stream_rewind(stream); startsize = zfp_stream_compressed_size(stream); if (dim == 1) zfp_encode_block_double_1(stream, block); else if (dim == 2) zfp_encode_block_double_2(stream, block); else if (dim == 3) zfp_encode_block_double_3(stream, block); else if (dim == 4) zfp_encode_block_double_4(stream, block); endsize = zfp_stream_compressed_size(stream); free(array); free(block); } assert_true(endsize > 0); assert_true(endsize == startsize + blocksize * (size_t)(rate/8)); } static void given_block1f_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly(void **state) { testStreamCompressedSizeIncreasedCorrectly(state, 1, zfp_type_float); } static void given_block2f_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly(void **state) { testStreamCompressedSizeIncreasedCorrectly(state, 2, zfp_type_float); } static void given_block3f_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly(void **state) { testStreamCompressedSizeIncreasedCorrectly(state, 3, zfp_type_float); } static void given_block4f_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly(void **state) { testStreamCompressedSizeIncreasedCorrectly(state, 4, zfp_type_float); } static void given_block1d_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly(void **state) { testStreamCompressedSizeIncreasedCorrectly(state, 1, zfp_type_double); } static void given_block2d_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly(void **state) { testStreamCompressedSizeIncreasedCorrectly(state, 2, zfp_type_double); } static void given_block3d_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly(void **state) { testStreamCompressedSizeIncreasedCorrectly(state, 3, zfp_type_double); } static void given_block4d_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly(void **state) { testStreamCompressedSizeIncreasedCorrectly(state, 4, zfp_type_double); } int main() { const struct CMUnitTest tests[] = { /* test zfp_stream_compression_mode() */ cmocka_unit_test_setup_teardown(given_openedZfpStream_when_zfpStreamCompressionMode_expect_returnsExpertEnum, setup, teardown), cmocka_unit_test_setup_teardown(given_zfpStreamSetWithInvalidParams_when_zfpStreamCompressionMode_expect_returnsNullEnum, setup, teardown), cmocka_unit_test_setup_teardown(given_zfpStreamSetWithFixedRate_when_zfpStreamCompressionMode_expect_returnsFixedRateEnum, setup, teardown), cmocka_unit_test_setup_teardown(given_zfpStreamSetWithFixedRate_when_zfpStreamRate_expect_returnsSameRate, setup, teardown), cmocka_unit_test_setup_teardown(given_zfpStreamSetWithFixedPrecision_when_zfpStreamCompressionMode_expect_returnsFixedPrecisionEnum, setup, teardown), cmocka_unit_test_setup_teardown(given_zfpStreamSetWithMaxPrecision_when_zfpStreamCompressionMode_expect_returnsExpertModeEnum, setup, teardown), cmocka_unit_test_setup_teardown(given_zfpStreamSetWithFixedPrecision_when_zfpStreamPrecision_expect_returnsSamePrecision, setup, teardown), cmocka_unit_test_setup_teardown(given_zfpStreamSetWithFixedAccuracy_when_zfpStreamCompressionMode_expect_returnsFixedAccuracyEnum, setup, teardown), cmocka_unit_test_setup_teardown(given_zfpStreamSetWithFixedAccuracy_when_zfpStreamAccuracy_expect_returnsSameAccuracy, setup, teardown), cmocka_unit_test_setup_teardown(given_zfpStreamSetWithReversible_when_zfpStreamCompressionMode_expect_returnsReversibleEnum, setup, teardown), cmocka_unit_test_setup_teardown(given_zfpStreamSetWithExpertParams_when_zfpStreamCompressionMode_expect_returnsExpertEnum, setup, teardown), /* test zfp_stream_set_mode() */ cmocka_unit_test_setup_teardown(given_zfpStreamDefaultModeVal_when_zfpStreamSetMode_expect_returnsExpertMode_and_compressParamsConserved, setup, teardown), cmocka_unit_test_setup_teardown(given_zfpStreamSetRateModeVal_when_zfpStreamSetMode_expect_returnsFixedRate_and_compressParamsConserved, setup, teardown), cmocka_unit_test_setup_teardown(given_zfpStreamSetPrecisionModeVal_when_zfpStreamSetMode_expect_returnsFixedPrecision_and_compressParamsConserved, setup, teardown), cmocka_unit_test_setup_teardown(given_fixedPrecisionMaxPrecModeVal_when_zfpStreamSetMode_expect_returnsExpert_and_compressParamsConserved, setup, teardown), cmocka_unit_test_setup_teardown(given_zfpStreamSetAccuracyModeVal_when_zfpStreamSetMode_expect_returnsFixedAccuracy_and_compressParamsConserved, setup, teardown), cmocka_unit_test_setup_teardown(given_zfpStreamSetReversibleModeVal_when_zfpStreamSetMode_expect_returnsReversible_and_compressParamsConserved, setup, teardown), cmocka_unit_test_setup_teardown(given_customCompressParamsModeVal_when_zfpStreamSetMode_expect_returnsExpert_and_compressParamsConserved, setup, teardown), cmocka_unit_test_setup_teardown(given_invalidCompressParamsModeVal_when_zfpStreamSetMode_expect_returnsNullMode_and_paramsNotSet, setup, teardown), /* test other zfp_stream_align() */ cmocka_unit_test_setup_teardown(given_block1f_when_StreamFlush_expect_StreamAlignSizeMatches, setup, teardown), cmocka_unit_test_setup_teardown(given_block2f_when_StreamFlush_expect_StreamAlignSizeMatches, setup, teardown), cmocka_unit_test_setup_teardown(given_block3f_when_StreamFlush_expect_StreamAlignSizeMatches, setup, teardown), cmocka_unit_test_setup_teardown(given_block4f_when_StreamFlush_expect_StreamAlignSizeMatches, setup, teardown), cmocka_unit_test_setup_teardown(given_block1d_when_StreamFlush_expect_StreamAlignSizeMatches, setup, teardown), cmocka_unit_test_setup_teardown(given_block2d_when_StreamFlush_expect_StreamAlignSizeMatches, setup, teardown), cmocka_unit_test_setup_teardown(given_block3d_when_StreamFlush_expect_StreamAlignSizeMatches, setup, teardown), cmocka_unit_test_setup_teardown(given_block4d_when_StreamFlush_expect_StreamAlignSizeMatches, setup, teardown), /* test zfp_stream_compressed_size() */ cmocka_unit_test_setup_teardown(given_block1f_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly, setup, teardown), cmocka_unit_test_setup_teardown(given_block2f_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly, setup, teardown), cmocka_unit_test_setup_teardown(given_block3f_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly, setup, teardown), cmocka_unit_test_setup_teardown(given_block4f_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly, setup, teardown), cmocka_unit_test_setup_teardown(given_block1d_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly, setup, teardown), cmocka_unit_test_setup_teardown(given_block2d_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly, setup, teardown), cmocka_unit_test_setup_teardown(given_block3d_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly, setup, teardown), cmocka_unit_test_setup_teardown(given_block4d_when_WriteBlock_expect_StreamCompressedSizeIncreasedCorrectly, setup, teardown), }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/src/misc/zfpFieldBase.c000066400000000000000000000172071453723256400177200ustar00rootroot00000000000000struct setupVars { zfp_field* field; SCALAR* data; }; static int setupBasic(void **state) { struct setupVars *bundle = malloc(sizeof(struct setupVars)); assert_non_null(bundle); #if DIMS == 1 zfp_field* field = zfp_field_1d(NULL, ZFP_TYPE, NX); #elif DIMS == 2 zfp_field* field = zfp_field_2d(NULL, ZFP_TYPE, NX, NY); #elif DIMS == 3 zfp_field* field = zfp_field_3d(NULL, ZFP_TYPE, NX, NY, NZ); #elif DIMS == 4 zfp_field* field = zfp_field_4d(NULL, ZFP_TYPE, NX, NY, NZ, NW); #endif bundle->field = field; bundle->data = NULL; *state = bundle; return 0; } static int setupContiguous(void **state) { struct setupVars *bundle = malloc(sizeof(struct setupVars)); assert_non_null(bundle); #if DIMS == 1 zfp_field* field = zfp_field_1d(NULL, ZFP_TYPE, NX); SCALAR* data = (SCALAR*)malloc(sizeof(SCALAR)*NX); #elif DIMS == 2 zfp_field* field = zfp_field_2d(NULL, ZFP_TYPE, NX, NY); SCALAR* data = (SCALAR*)malloc(sizeof(SCALAR)*NX*NY); #elif DIMS == 3 zfp_field* field = zfp_field_3d(NULL, ZFP_TYPE, NX, NY, NZ); SCALAR* data = (SCALAR*)malloc(sizeof(SCALAR)*NX*NY*NZ); #elif DIMS == 4 zfp_field* field = zfp_field_4d(NULL, ZFP_TYPE, NX, NY, NZ, NW); SCALAR* data = (SCALAR*)malloc(sizeof(SCALAR)*NX*NY*NZ*NW); #endif assert_non_null(data); zfp_field_set_pointer(field, data); bundle->field = field; bundle->data = data; *state = bundle; return 0; } static int setupStrided(void **state) { struct setupVars *bundle = malloc(sizeof(struct setupVars)); assert_non_null(bundle); #if DIMS == 1 zfp_field* field = zfp_field_1d(NULL, ZFP_TYPE, NX); zfp_field_set_stride_1d(field, SX); SCALAR* data = (SCALAR*)malloc(sizeof(SCALAR) * ((SX*(NX-1)) + 1)); #elif DIMS == 2 zfp_field* field = zfp_field_2d(NULL, ZFP_TYPE, NX, NY); zfp_field_set_stride_2d(field, SX, SY); SCALAR* data = (SCALAR*)malloc(sizeof(SCALAR) * ((SX*(NX-1)) + (SY*(NY-1)) + 1)); #elif DIMS == 3 zfp_field* field = zfp_field_3d(NULL, ZFP_TYPE, NX, NY, NZ); zfp_field_set_stride_3d(field, SX, SY, SZ); SCALAR* data = (SCALAR*)malloc(sizeof(SCALAR) * ((SX*(NX-1)) + (SY*(NY-1)) + (SZ*(NZ-1)) + 1)); #elif DIMS == 4 zfp_field* field = zfp_field_4d(NULL, ZFP_TYPE, NX, NY, NZ, NW); zfp_field_set_stride_4d(field, SX, SY, SZ, SW); SCALAR* data = (SCALAR*)malloc(sizeof(SCALAR) * ((SX*(NX-1)) + (SY*(NY-1)) + (SZ*(NZ-1)) + (SW*(NW-1)) + 1)); #endif assert_non_null(data); zfp_field_set_pointer(field, data); bundle->field = field; bundle->data = data; *state = bundle; return 0; } static int setupNegativeStrided(void **state) { struct setupVars *bundle = malloc(sizeof(struct setupVars)); assert_non_null(bundle); #if DIMS == 1 zfp_field* field = zfp_field_1d(NULL, ZFP_TYPE, NX); zfp_field_set_stride_1d(field, -SX); SCALAR* data = (SCALAR*)malloc(sizeof(SCALAR) * ((SX*(NX-1)) + 1)); #elif DIMS == 2 zfp_field* field = zfp_field_2d(NULL, ZFP_TYPE, NX, NY); zfp_field_set_stride_2d(field, -SX, -SY); SCALAR* data = (SCALAR*)malloc(sizeof(SCALAR) * ((SX*(NX-1)) + (SY*(NY-1)) + 1)); #elif DIMS == 3 zfp_field* field = zfp_field_3d(NULL, ZFP_TYPE, NX, NY, NZ); zfp_field_set_stride_3d(field, -SX, -SY, -SZ); SCALAR* data = (SCALAR*)malloc(sizeof(SCALAR) * ((SX*(NX-1)) + (SY*(NY-1)) + (SZ*(NZ-1)) + 1)); #elif DIMS == 4 zfp_field* field = zfp_field_4d(NULL, ZFP_TYPE, NX, NY, NZ, NW); zfp_field_set_stride_4d(field, -SX, -SY, -SZ, -SW); SCALAR* data = (SCALAR*)malloc(sizeof(SCALAR) * ((SX*(NX-1)) + (SY*(NY-1)) + (SZ*(NZ-1)) + (SW*(NW-1)) + 1)); #endif assert_non_null(data); zfp_field_set_pointer(field, data); bundle->field = field; bundle->data = data; *state = bundle; return 0; } static int teardown(void **state) { struct setupVars *bundle = *state; zfp_field_free(bundle->field); if (bundle->data != NULL) free(bundle->data); free(bundle); return 0; } static void given_contiguousData_isContiguousReturnsTrue(void **state) { struct setupVars *bundle = *state; zfp_field* field = bundle->field; assert_true(zfp_field_is_contiguous(field)); } static void given_noncontiguousData_isContiguousReturnsFalse(void **state) { struct setupVars *bundle = *state; zfp_field* field = bundle->field; assert_false(zfp_field_is_contiguous(field)); } static void when_noFieldData_fieldBeginReturnsNull(void **state) { struct setupVars *bundle = *state; zfp_field* field = bundle->field; assert_null(zfp_field_begin(field)); } static void when_contiguousData_fieldBeginsAtDataPointer(void **state) { struct setupVars *bundle = *state; zfp_field* field = bundle->field; assert_true(zfp_field_begin(field) == zfp_field_pointer(field)); } static void when_noncontiguousDataWithNegativeStride_fieldBeginsAtCorrectLocation(void **state) { struct setupVars *bundle = *state; zfp_field* field = bundle->field; #if DIMS == 1 ptrdiff_t min = ((int)-SX * (ptrdiff_t)(NX - 1)); #elif DIMS == 2 ptrdiff_t min = ((int)-SX * (ptrdiff_t)(NX - 1)) + ((int)-SY * (ptrdiff_t)(NY - 1)); #elif DIMS == 3 ptrdiff_t min = ((int)-SX * (ptrdiff_t)(NX - 1)) + ((int)-SY * (ptrdiff_t)(NY - 1)) + ((int)-SZ * (ptrdiff_t)(NZ - 1)); #elif DIMS == 4 ptrdiff_t min = ((int)-SX * (ptrdiff_t)(NX - 1)) + ((int)-SY * (ptrdiff_t)(NY - 1)) + ((int)-SZ * (ptrdiff_t)(NZ - 1)) + ((int)-SW * (ptrdiff_t)(NW - 1)); #endif void* begin = (void*)((uchar*)field->data + min * (ptrdiff_t)zfp_type_size(field->type)); assert_true(zfp_field_begin(field) == begin); } static void given_field_precisionCorrect(void **state) { struct setupVars *bundle = *state; zfp_field* field = bundle->field; assert_true(zfp_field_precision(field) == sizeof(SCALAR) * CHAR_BIT); } static void given_contiguousData_fieldSizeBytesCorrect(void **state) { struct setupVars *bundle = *state; zfp_field* field = bundle->field; #if DIMS == 1 assert_true(zfp_field_size_bytes(field) == NX * sizeof(SCALAR)); #elif DIMS == 2 assert_true(zfp_field_size_bytes(field) == NX * NY * sizeof(SCALAR)); #elif DIMS == 3 assert_true(zfp_field_size_bytes(field) == NX * NY * NZ * sizeof(SCALAR)); #elif DIMS == 4 assert_true(zfp_field_size_bytes(field) == NX * NY * NZ * NW * sizeof(SCALAR)); #endif } static void given_noncontiguousData_fieldSizeBytesCorrect(void **state) { struct setupVars *bundle = *state; zfp_field* field = bundle->field; #if DIMS == 1 assert_true(zfp_field_size_bytes(field) == ((SX*(NX-1) + 1) * sizeof(SCALAR))); #elif DIMS == 2 assert_true(zfp_field_size_bytes(field) == ((SX*(NX-1) + SY*(NY-1) + 1) * sizeof(SCALAR))); #elif DIMS == 3 assert_true(zfp_field_size_bytes(field) == ((SX*(NX-1) + SY*(NY-1) + SZ*(NZ-1) + 1) * sizeof(SCALAR))); #elif DIMS == 4 assert_true(zfp_field_size_bytes(field) == ((SX*(NX-1) + SY*(NY-1) + SZ*(NZ-1) + SW*(NW-1) + 1) * sizeof(SCALAR))); #endif } int main() { const struct CMUnitTest tests[] = { cmocka_unit_test_setup_teardown(given_contiguousData_isContiguousReturnsTrue, setupContiguous, teardown), cmocka_unit_test_setup_teardown(given_noncontiguousData_isContiguousReturnsFalse, setupStrided, teardown), cmocka_unit_test_setup_teardown(when_noFieldData_fieldBeginReturnsNull, setupBasic, teardown), cmocka_unit_test_setup_teardown(when_contiguousData_fieldBeginsAtDataPointer, setupContiguous, teardown), cmocka_unit_test_setup_teardown(when_noncontiguousDataWithNegativeStride_fieldBeginsAtCorrectLocation, setupNegativeStrided, teardown), cmocka_unit_test_setup_teardown(given_field_precisionCorrect, setupBasic, teardown), cmocka_unit_test_setup_teardown(given_contiguousData_fieldSizeBytesCorrect, setupContiguous, teardown), cmocka_unit_test_setup_teardown(given_noncontiguousData_fieldSizeBytesCorrect, setupStrided, teardown), }; return cmocka_run_group_tests(tests, NULL, NULL); } zfp-1.0.1/tests/testviews.cpp000066400000000000000000000177701453723256400162420ustar00rootroot00000000000000#include #include #include #include #include "zfp/array2.hpp" #include "zfp/array3.hpp" #ifdef _OPENMP #include #endif #define EPSILON 1e-3 // random integer in {begin, ..., end} static size_t rand(size_t begin, size_t end) { return begin + size_t(rand()) % (end - begin + 1); } // ensure f and g are sufficiently close static void verify(double f, double g) { if (std::fabs(f - g) > EPSILON) { #ifdef _OPENMP #pragma omp critical #endif std::cerr << "error: " << f << " != " << g << std::endl; exit(EXIT_FAILURE); } } static int usage() { std::cerr << "Usage: testviews [nx ny nz [x0 y0 z0 mx my mz]]" << std::endl; return EXIT_FAILURE; } int main(int argc, char* argv[]) { size_t nx = 8; size_t ny = 48; size_t nz = 32; size_t x0, y0, z0; size_t mx, my, mz; double rate = 16; // parse command-line arguments switch (argc) { case 10: if ((std::istringstream(argv[4]) >> x0).fail() || (std::istringstream(argv[5]) >> y0).fail() || (std::istringstream(argv[6]) >> z0).fail() || (std::istringstream(argv[7]) >> mx).fail() || !mx || (std::istringstream(argv[8]) >> my).fail() || !my || (std::istringstream(argv[9]) >> mz).fail() || !mz) return usage(); // FALLTHROUGH case 4: if ((std::istringstream(argv[1]) >> nx).fail() || !nx || (std::istringstream(argv[2]) >> ny).fail() || !ny || (std::istringstream(argv[3]) >> nz).fail() || !nz) return usage(); // FALLTHROUGH case 1: break; default: return usage(); } if (argc < 10) { // generate random view x0 = rand(0, nx - 1); y0 = rand(0, ny - 1); z0 = rand(0, nz - 1); mx = rand(1, nx - x0); my = rand(1, ny - y0); mz = rand(1, nz - z0); } // validate arguments if (x0 + mx > nx || y0 + my > ny || z0 + mz > nz) { std::cerr << "invalid view parameters" << std::endl; return EXIT_FAILURE; } std::cout << "a(" << nx << ", " << ny << ", " << nz << ")" << std::endl; std::cout << "v(" << mx << ", " << my << ", " << mz << ") + (" << x0 << ", " << y0 << ", " << z0 << ")" << std::endl; // initialize 3D array to linear function zfp::array3 a(nx, ny, nz, rate); for (size_t z = 0; z < nz; z++) for (size_t y = 0; y < ny; y++) for (size_t x = 0; x < nx; x++) a(x, y, z) = static_cast(x + nx * (y + ny * z)); // rectangular view into a std::cout << std::endl << "3D view" << std::endl; zfp::array3::view v(&a, x0, y0, z0, mx, my, mz); for (size_t z = 0; z < v.size_z(); z++) for (size_t y = 0; y < v.size_y(); y++) for (size_t x = 0; x < v.size_x(); x++) { std::cout << x << " " << y << " " << z << ": " << a(x0 + x, y0 + y, z0 + z) << " " << v(x, y, z) << std::endl; verify(a(x0 + x, y0 + y, z0 + z), v(x, y, z)); } // flat view of all of a std::cout << std::endl << "3D flat view" << std::endl; zfp::array3::flat_view fv(&a); for (size_t z = 0; z < fv.size_z(); z++) for (size_t y = 0; y < fv.size_y(); y++) for (size_t x = 0; x < fv.size_x(); x++) { std::cout << x << " " << y << " " << z << ": " << a(x, y, z) << " " << fv[fv.index(x, y, z)] << std::endl; verify(a(x, y, z), fv[fv.index(x, y, z)]); } // nested view of all of a std::cout << std::endl << "3D nested view" << std::endl; zfp::array3::nested_view nv(&a); for (size_t z = 0; z < nv.size_z(); z++) for (size_t y = 0; y < nv.size_y(); y++) for (size_t x = 0; x < nv.size_x(); x++) { std::cout << x << " " << y << " " << z << ": " << a(x, y, z) << " " << nv[z][y][x] << std::endl; verify(a(x, y, z), nv[z][y][x]); } // pointers and iterators into a via view v std::cout << std::endl << "3D view pointers and iterators" << std::endl; zfp::array3::view::const_reference vr = v(0, 0, 0); zfp::array3::view::const_pointer p = &vr; p = &v(0, 0, 0); for (zfp::array3::view::const_iterator it = v.begin(); it != v.end(); it++) { size_t x = it.i(); size_t y = it.j(); size_t z = it.k(); std::cout << x << " " << y << " " << z << std::endl; std::cout << mx << " " << my << " " << std::endl; verify(*it, p[x + mx * (y + my * z)]); } // pointers and iterators into a via flat view fv std::cout << std::endl << "3D flat view pointers and iterators" << std::endl; zfp::array3::flat_view::const_reference fvr = fv[0]; zfp::array3::flat_view::const_pointer fp = &fvr; fp = &fv(0, 0, 0); for (zfp::array3::flat_view::const_iterator it = fv.begin(); it != fv.end(); it++) { size_t x = it.i(); size_t y = it.j(); size_t z = it.k(); verify(*it, fp[x + nx * (y + ny * z)]); } // 2D slice of a std::cout << std::endl << "2D slice" << std::endl; size_t z = rand(0, nv.size_z() - 1); zfp::array3::nested_view2 slice2(nv[z]); for (size_t y = 0; y < slice2.size_y(); y++) for (size_t x = 0; x < slice2.size_x(); x++) { std::cout << x << " " << y << " " << z << ": " << a(x, y, z) << " " << slice2[y][x] << std::endl; verify(a(x, y, z), slice2[y][x]); } // 2D array constructed from 2D slice (exercises deep copy via iterator) std::cout << std::endl << "2D array from 2D slice" << std::endl; zfp::array2 b(slice2); for (size_t y = 0; y < b.size_y(); y++) for (size_t x = 0; x < b.size_x(); x++) { std::cout << x << " " << y << ": " << b(x, y) << " " << slice2[y][x] << std::endl; verify(b(x, y), slice2[y][x]); } // 1D slice of a std::cout << std::endl << "1D slice" << std::endl; size_t y = rand(0, slice2.size_y() - 1); zfp::array3::nested_view1 slice1 = slice2[y]; for (size_t x = 0; x < slice1.size_x(); x++) { std::cout << x << " " << y << " " << z << ": " << a(x, y, z) << " " << slice1[x] << std::endl; verify(a(x, y, z), slice1[x]); } // 2D array constructed from 2D slice of 3D array (exercises deep copy via iterator) std::cout << std::endl << "2D array from 2D slice of 3D array" << std::endl; zfp::array2 c(slice2); for (size_t y = 0; y < c.size_y(); y++) for (size_t x = 0; x < c.size_x(); x++) { std::cout << x << " " << y << ": " << c(x, y) << " " << slice2[y][x] << std::endl; verify(c(x, y), slice2[y][x]); } // 2D thread-safe read-only view of c std::cout << std::endl << "2D private read-only view" << std::endl; zfp::array2::private_const_view d(&c); for (size_t y = 0; y < c.size_y(); y++) for (size_t x = 0; x < c.size_x(); x++) { std::cout << x << " " << y << ": " << c(x, y) << " " << d(x, y) << std::endl; verify(c(x, y), d(x, y)); } #ifdef _OPENMP std::cout << std::endl << "multithreaded 2D private read-only views" << std::endl; // copy c for verification; direct accesses to c are not thread-safe double* data = new double[c.size()]; c.get(data); #pragma omp parallel { // make a thread-local view into c zfp::array2::private_const_view d(&c); for (size_t y = 0; y < d.size_y(); y++) for (size_t x = 0; x < d.size_x(); x++) { double val = data[x + nx * y]; if (omp_get_thread_num() == 0) std::cout << x << " " << y << ": " << val << " " << d(x, y) << std::endl; verify(val, d(x, y)); } } std::cout << std::endl << "multithreaded 2D private read-write views" << std::endl; #pragma omp parallel { // partition c into disjoint views zfp::array2::private_view d(&c); d.partition(omp_get_thread_num(), omp_get_num_threads()); for (size_t j = 0; j < d.size_y(); j++) for (size_t i = 0; i < d.size_x(); i++) { d(i, j) += 1; size_t x = d.global_x(i); size_t y = d.global_y(j); double val = data[x + nx * y] + 1; if (omp_get_thread_num() == 0) std::cout << x << " " << y << ": " << val << " " << d(i, j) << std::endl; verify(val, d(i, j)); } } delete[] data; #endif std::cout << std::endl << "all tests passed" << std::endl; return 0; } zfp-1.0.1/tests/testzfp.cpp000066400000000000000000001023211453723256400156670ustar00rootroot00000000000000#include #include #include #include #include #include #include #include #include #include #include #include #include "zfp.h" #include "zfp/array1.hpp" #include "zfp/array2.hpp" #include "zfp/array3.hpp" #include "zfp/array4.hpp" enum ArraySize { Small = 0, // 2^12 = 4096 scalars (2^12 = (2^6)^2 = (2^4)^3 = (2^3)^4) Large = 1 // 2^24 = 16 M scalars (2^24 = (2^12)^2 = (2^8)^3 = (2^6)^4) }; enum ScalarType { Float = 0, // 32-bit single precision Double = 1 // 64-bit double precision }; static const int width = 72; // characters per line inline uint mask(uint i) { return 1u << i; } inline uint test_size(ArraySize size) { return 2u << size; } // refine 1D array f[m] to g[2m] inline void refine1d(int* g, const int* f, size_t m) { const int weight[4] = { -1, 9, 9, -1 }; const size_t n = 2 * m; for (size_t x = 0; x < n; x++) { int s = 0; for (size_t i = 0; i < 4; i++) { size_t xx = x & 1u ? (x / 2 + i - 1 + m) % m : x / 2; s += weight[i] * f[xx]; } g[x] = s / 16; } } // refine 2D array f[m][m] to g[2m][2m] inline void refine2d(int* g, const int* f, size_t m) { const int weight[4] = { -1, 9, 9, -1 }; const size_t n = 2 * m; for (size_t y = 0; y < n; y++) for (size_t x = 0; x < n; x++) { int s = 0; for (size_t j = 0; j < 4; j++) { size_t yy = y & 1u ? (y / 2 + j - 1 + m) % m : y / 2; for (size_t i = 0; i < 4; i++) { size_t xx = x & 1u ? (x / 2 + i - 1 + m) % m : x / 2; s += weight[i] * weight[j] * f[xx + m * yy]; } } g[x + n * y] = s / (16 * 16); } } // refine 3D array f[m][m][m] to g[2m][2m][2m] inline void refine3d(int* g, const int* f, size_t m) { const int weight[4] = { -1, 9, 9, -1 }; const size_t n = 2 * m; for (size_t z = 0; z < n; z++) for (size_t y = 0; y < n; y++) for (size_t x = 0; x < n; x++) { int s = 0; for (size_t k = 0; k < 4; k++) { size_t zz = z & 1u ? (z / 2 + k - 1 + m) % m : z / 2; for (size_t j = 0; j < 4; j++) { size_t yy = y & 1u ? (y / 2 + j - 1 + m) % m : y / 2; for (size_t i = 0; i < 4; i++) { size_t xx = x & 1u ? (x / 2 + i - 1 + m) % m : x / 2; s += weight[i] * weight[j] * weight[k] * f[xx + m * (yy + m * zz)]; } } } g[x + n * (y + n * z)] = s / (16 * 16 * 16); } } // refine 4D array f[m][m][m][m] to g[2m][2m][2m][2m] inline void refine4d(int* g, const int* f, size_t m) { const int weight[4] = { -1, 9, 9, -1 }; const size_t n = 2 * m; for (size_t w = 0; w < n; w++) for (size_t z = 0; z < n; z++) for (size_t y = 0; y < n; y++) for (size_t x = 0; x < n; x++) { int s = 0; for (size_t l = 0; l < 4; l++) { size_t ww = w & 1u ? (w / 2 + l - 1 + m) % m : w / 2; for (size_t k = 0; k < 4; k++) { size_t zz = z & 1u ? (z / 2 + k - 1 + m) % m : z / 2; for (size_t j = 0; j < 4; j++) { size_t yy = y & 1u ? (y / 2 + j - 1 + m) % m : y / 2; for (size_t i = 0; i < 4; i++) { size_t xx = x & 1u ? (x / 2 + i - 1 + m) % m : x / 2; s += weight[i] * weight[j] * weight[k] * weight[l] * f[xx + m * (yy + m * (zz + m * ww))]; } } } } g[x + n * (y + n * (z + n * w))] = s / (16 * 16 * 16 * 16); } } template inline void convert_ints_to_reals(real* data, const int* f, size_t n) { for (size_t i = 0; i < n; i++) data[i] = std::ldexp(real(f[i]), -12); } // generate 1D test array of size n template inline bool gen_array_1d(real* data, size_t n) { // ensure n >= 4 is a power of two if (n < 4 || n & (n - 1)) return false; // initialize 4-element integer array int* f = new int[n]; std::fill(f, f + 4, 0); for (uint x = 1; x < 3; x++) f[x] = 0x10000 * (1 - 2 * int(x & 1u)); // refine to n-element array int* g = new int[n]; for (size_t m = 4; m < n; m *= 2) { refine1d(g, f, m); std::swap(f, g); } delete[] g; // convert ints to real type convert_ints_to_reals(data, f, n); delete[] f; return true; } // generate 2D test array of size n^2 template inline bool gen_array_2d(real* data, size_t n) { // ensure n >= 4 is a power of two if (n < 4 || n & (n - 1)) return false; // initialize 4x4 integer array int* f = new int[n * n]; std::fill(f, f + 4 * 4, 0); for (uint y = 1; y < 3; y++) for (uint x = 1; x < 3; x++) f[x + 4 * y] = 0x10000 * (1 - 2 * int((x ^ y) & 1u)); // refine to n^2 array int* g = new int[n * n]; for (size_t m = 4; m < n; m *= 2) { refine2d(g, f, m); std::swap(f, g); } delete[] g; // convert ints to real type convert_ints_to_reals(data, f, n * n); delete[] f; return true; } // generate 3D test array of size n^3 template inline bool gen_array_3d(real* data, size_t n) { // ensure n >= 4 is a power of two if (n < 4 || n & (n - 1)) return false; // initialize 4x4x4 integer array int* f = new int[n * n * n]; std::fill(f, f + 4 * 4 * 4, 0); for (uint z = 1; z <= 2u; z++) for (uint y = 1; y <= 2u; y++) for (uint x = 1; x <= 2u; x++) f[x + 4 * (y + 4 * z)] = 0x10000 * (1 - 2 * int((x ^ y ^ z) & 1u)); // refine to n^3 array int* g = new int[n * n * n]; for (size_t m = 4; m < n; m *= 2) { refine3d(g, f, m); std::swap(f, g); } delete[] g; // convert ints to real type convert_ints_to_reals(data, f, n * n * n); delete[] f; return true; } // generate 4D test array of size n^4 template inline bool gen_array_4d(real* data, size_t n) { // ensure n >= 4 is a power of two if (n < 4 || n & (n - 1)) return false; // initialize 4x4x4x4 integer array int* f = new int[n * n * n * n]; std::fill(f, f + 4 * 4 * 4 * 4, 0); for (uint w = 1; w < 3; w++) for (uint z = 1; z < 3; z++) for (uint y = 1; y < 3; y++) for (uint x = 1; x < 3; x++) f[x + 4 * (y + 4 * (z + 4 * w))] = 0x10000 * (1 - 2 * int((x ^ y ^ z ^ w) & 1u)); // refine to n^4 array int* g = new int[n * n * n * n]; for (size_t m = 4; m < n; m *= 2) { refine4d(g, f, m); std::swap(f, g); } delete[] g; // convert ints to real type convert_ints_to_reals(data, f, n * n * n * n); delete[] f; return true; } // initialize array template inline void initialize(Scalar* p, uint dims, ArraySize array_size) { size_t size = size_t(1) << ((array_size == Small ? 12 : 24) / dims); switch (dims) { default: case 1: gen_array_1d(p, size); break; case 2: gen_array_2d(p, size); break; case 3: gen_array_3d(p, size); break; case 4: gen_array_4d(p, size); break; } } // compute checksum inline uint32 hash(const void* p, size_t n) { uint32 h = 0; for (const uchar* q = static_cast(p); n; q++, n--) { // Jenkins one-at-a-time hash; see http://www.burtleburtle.net/bob/hash/doobs.html h += *q; h += h << 10; h ^= h >> 6; } h += h << 3; h ^= h >> 11; h += h << 15; return h; } // test fixed-rate mode template inline uint test_rate(zfp_stream* stream, const zfp_field* input, double rate, Scalar tolerance, bool timings = false) { uint failures = 0; size_t n = zfp_field_size(input, NULL); uint dims = zfp_field_dimensionality(input); zfp_type type = zfp_field_type(input); // allocate memory for compressed data rate = zfp_stream_set_rate(stream, rate, type, dims, zfp_false); size_t bufsize = zfp_stream_maximum_size(stream, input); uchar* buffer = new uchar[bufsize]; bitstream* s = stream_open(buffer, bufsize); zfp_stream_set_bit_stream(stream, s); // perform compression test std::ostringstream status; status << " compress: "; status << " rate=" << std::fixed << std::setprecision(0) << std::setw(2) << rate; clock_t c = clock(); zfp_stream_rewind(stream); size_t outsize = zfp_compress(stream, input); double time = double(clock() - c) / CLOCKS_PER_SEC; double throughput = (n * sizeof(Scalar)) / (0x100000 * time); if (timings) status << " throughput=" << std::setprecision(1) << std::setw(6) << throughput << " MB/s"; bool pass = true; // make sure compressed size matches rate size_t bytes = (size_t)floor(rate * zfp_field_size(input, NULL) / CHAR_BIT + 0.5); if (outsize != bytes) { status << " [" << outsize << " != " << bytes << "]"; pass = false; } std::cout << std::setw(width) << std::left << status.str() << (pass ? " OK " : "FAIL") << std::endl; if (!pass) failures++; // perform decompression test status.str(""); status << " decompress:"; status << " rate=" << std::fixed << std::setprecision(0) << std::setw(2) << rate; Scalar* g = new Scalar[n]; zfp_field* output = zfp_field_alloc(); *output = *input; zfp_field_set_pointer(output, g); c = clock(); zfp_stream_rewind(stream); pass = !!zfp_decompress(stream, output); if (!pass) status << " [decompression failed]"; else { double time = double(clock() - c) / CLOCKS_PER_SEC; double throughput = (n * sizeof(Scalar)) / (0x100000 * time); if (timings) status << " throughput=" << std::setprecision(1) << std::setw(6) << throughput << " MB/s"; // compute max error Scalar* f = static_cast(zfp_field_pointer(input)); Scalar emax = 0; for (uint i = 0; i < n; i++) emax = std::max(emax, std::abs(f[i] - g[i])); status << std::scientific; status.precision(3); // make sure max error is within tolerance if (emax <= tolerance) status << " " << emax << " <= " << tolerance; else { status << " [" << emax << " > " << tolerance << "]"; pass = false; } } zfp_field_free(output); delete[] g; stream_close(s); delete[] buffer; std::cout << std::setw(width) << std::left << status.str() << (pass ? " OK " : "FAIL") << std::endl; if (!pass) failures++; return failures; } // test fixed-precision mode template inline uint test_precision(zfp_stream* stream, const zfp_field* input, uint precision, size_t bytes) { uint failures = 0; size_t n = zfp_field_size(input, NULL); // allocate memory for compressed data zfp_stream_set_precision(stream, precision); size_t bufsize = zfp_stream_maximum_size(stream, input); uchar* buffer = new uchar[bufsize]; bitstream* s = stream_open(buffer, bufsize); zfp_stream_set_bit_stream(stream, s); // perform compression test std::ostringstream status; status << " compress: "; status << " precision=" << std::setw(2) << precision; zfp_stream_rewind(stream); size_t outsize = zfp_compress(stream, input); double ratio = double(n * sizeof(Scalar)) / outsize; status << " ratio=" << std::fixed << std::setprecision(3) << std::setw(7) << ratio; bool pass = true; // make sure compressed size agrees if (outsize != bytes) { status << " [" << outsize << " != " << bytes << "]"; pass = false; } std::cout << std::setw(width) << std::left << status.str() << (pass ? " OK " : "FAIL") << std::endl; if (!pass) failures++; // perform decompression test status.str(""); status << " decompress:"; status << " precision=" << std::setw(2) << precision; Scalar* g = new Scalar[n]; zfp_field* output = zfp_field_alloc(); *output = *input; zfp_field_set_pointer(output, g); zfp_stream_rewind(stream); pass = !!zfp_decompress(stream, output); if (!pass) status << " [decompression failed]"; zfp_field_free(output); delete[] g; stream_close(s); delete[] buffer; std::cout << std::setw(width) << std::left << status.str() << (pass ? " OK " : "FAIL") << std::endl; if (!pass) failures++; return failures; } // test fixed-accuracy mode template inline uint test_accuracy(zfp_stream* stream, const zfp_field* input, Scalar tolerance, size_t bytes) { uint failures = 0; size_t n = zfp_field_size(input, NULL); // allocate memory for compressed data tolerance = static_cast(zfp_stream_set_accuracy(stream, tolerance)); size_t bufsize = zfp_stream_maximum_size(stream, input); uchar* buffer = new uchar[bufsize]; bitstream* s = stream_open(buffer, bufsize); zfp_stream_set_bit_stream(stream, s); // perform compression test std::ostringstream status; status << " compress: "; status << " tolerance=" << std::scientific << std::setprecision(3) << tolerance; zfp_stream_rewind(stream); size_t outsize = zfp_compress(stream, input); double ratio = double(n * sizeof(Scalar)) / outsize; status << " ratio=" << std::fixed << std::setprecision(3) << std::setw(7) << ratio; bool pass = true; // make sure compressed size agrees if (outsize != bytes) { status << " [" << outsize << " != " << bytes << "]"; pass = false; } std::cout << std::setw(width) << std::left << status.str() << (pass ? " OK " : "FAIL") << std::endl; if (!pass) failures++; // perform decompression test status.str(""); status << " decompress:"; status << " tolerance=" << std::scientific << std::setprecision(3) << tolerance; Scalar* g = new Scalar[n]; zfp_field* output = zfp_field_alloc(); *output = *input; zfp_field_set_pointer(output, g); zfp_stream_rewind(stream); pass = !!zfp_decompress(stream, output); if (!pass) status << " [decompression failed]"; else { // compute max error Scalar* f = static_cast(zfp_field_pointer(input)); Scalar emax = 0; for (uint i = 0; i < n; i++) emax = std::max(emax, std::abs(f[i] - g[i])); status << std::scientific << std::setprecision(3) << " "; // make sure max error is within tolerance if (emax <= tolerance) status << emax << " <= " << tolerance; else if (tolerance == 0) status << "(" << emax << " > 0)"; else { status << "[" << emax << " > " << tolerance << "]"; pass = false; } } zfp_field_free(output); delete[] g; stream_close(s); delete[] buffer; std::cout << std::setw(width) << std::left << status.str() << (pass ? " OK " : "FAIL") << std::endl; if (!pass) failures++; return failures; } // test reversible mode template inline uint test_reversible(zfp_stream* stream, const zfp_field* input, size_t bytes) { uint failures = 0; size_t n = zfp_field_size(input, NULL); // allocate memory for compressed data zfp_stream_set_reversible(stream); size_t bufsize = zfp_stream_maximum_size(stream, input); uchar* buffer = new uchar[bufsize]; bitstream* s = stream_open(buffer, bufsize); zfp_stream_set_bit_stream(stream, s); // perform compression test std::ostringstream status; status << " compress: "; status << " reversible"; zfp_stream_rewind(stream); size_t outsize = zfp_compress(stream, input); double ratio = double(n * sizeof(Scalar)) / outsize; status << " ratio=" << std::fixed << std::setprecision(3) << std::setw(7) << ratio; bool pass = true; // make sure compressed size agrees if (outsize != bytes) { status << " [" << outsize << " != " << bytes << "]"; pass = false; } std::cout << std::setw(width) << std::left << status.str() << (pass ? " OK " : "FAIL") << std::endl; if (!pass) failures++; // perform decompression test status.str(""); status << " decompress:"; status << " reversible"; Scalar* g = new Scalar[n]; zfp_field* output = zfp_field_alloc(); *output = *input; zfp_field_set_pointer(output, g); zfp_stream_rewind(stream); pass = !!zfp_decompress(stream, output); if (!pass) status << " [decompression failed]"; else { // make sure reconstruction is bit-for-bit exact pass = !memcmp(zfp_field_pointer(input), zfp_field_pointer(output), n * sizeof(Scalar)); if (!pass) status << " [reconstruction differs]"; } zfp_field_free(output); delete[] g; stream_close(s); delete[] buffer; std::cout << std::setw(width) << std::left << status.str() << (pass ? " OK " : "FAIL") << std::endl; if (!pass) failures++; return failures; } // perform 1D differencing template inline void update_array1(zfp::array1& a) { for (uint i = 0; i < a.size() - 1; i++) a(i) -= a(i + 1); for (uint i = 0; i < a.size() - 1; i++) a(0) = std::max(a(0), a(i)); } // perform 2D differencing template inline void update_array2(zfp::array2& a) { for (uint j = 0; j < a.size_y(); j++) for (uint i = 0; i < a.size_x() - 1; i++) a(i, j) -= a(i + 1, j); for (uint j = 0; j < a.size_y() - 1; j++) for (uint i = 0; i < a.size_x(); i++) a(i, j) -= a(i, j + 1); for (uint j = 0; j < a.size_y() - 1; j++) for (uint i = 0; i < a.size_x() - 1; i++) a(0, 0) = std::max(a(0, 0), a(i, j)); } // perform 3D differencing template inline void update_array3(zfp::array3& a) { for (uint k = 0; k < a.size_z(); k++) for (uint j = 0; j < a.size_y(); j++) for (uint i = 0; i < a.size_x() - 1; i++) a(i, j, k) -= a(i + 1, j, k); for (uint k = 0; k < a.size_z(); k++) for (uint j = 0; j < a.size_y() - 1; j++) for (uint i = 0; i < a.size_x(); i++) a(i, j, k) -= a(i, j + 1, k); for (uint k = 0; k < a.size_z() - 1; k++) for (uint j = 0; j < a.size_y(); j++) for (uint i = 0; i < a.size_x(); i++) a(i, j, k) -= a(i, j, k + 1); for (uint k = 0; k < a.size_z() - 1; k++) for (uint j = 0; j < a.size_y() - 1; j++) for (uint i = 0; i < a.size_x() - 1; i++) a(0, 0, 0) = std::max(a(0, 0, 0), a(i, j, k)); } // perform 4D differencing template inline void update_array4(zfp::array4& a) { for (uint l = 0; l < a.size_w(); l++) for (uint k = 0; k < a.size_z(); k++) for (uint j = 0; j < a.size_y(); j++) for (uint i = 0; i < a.size_x() - 1; i++) a(i, j, k, l) -= a(i + 1, j, k, l); for (uint l = 0; l < a.size_w(); l++) for (uint k = 0; k < a.size_z(); k++) for (uint j = 0; j < a.size_y() - 1; j++) for (uint i = 0; i < a.size_x(); i++) a(i, j, k, l) -= a(i, j + 1, k, l); for (uint l = 0; l < a.size_w(); l++) for (uint k = 0; k < a.size_z() - 1; k++) for (uint j = 0; j < a.size_y(); j++) for (uint i = 0; i < a.size_x(); i++) a(i, j, k, l) -= a(i, j, k + 1, l); for (uint l = 0; l < a.size_w() - 1; l++) for (uint k = 0; k < a.size_z(); k++) for (uint j = 0; j < a.size_y(); j++) for (uint i = 0; i < a.size_x(); i++) a(i, j, k, l) -= a(i, j, k, l + 1); for (uint l = 0; l < a.size_w() - 1; l++) for (uint k = 0; k < a.size_z() - 1; k++) for (uint j = 0; j < a.size_y() - 1; j++) for (uint i = 0; i < a.size_x() - 1; i++) a(0, 0, 0, 0) = std::max(a(0, 0, 0, 0), a(i, j, k, l)); } template inline void update_array(Array& a); template <> inline void update_array(zfp::array1& a) { update_array1(a); } template <> inline void update_array(zfp::array1& a) { update_array1(a); } template <> inline void update_array(zfp::array2& a) { update_array2(a); } template <> inline void update_array(zfp::array2& a) { update_array2(a); } template <> inline void update_array(zfp::array3& a) { update_array3(a); } template <> inline void update_array(zfp::array3& a) { update_array3(a); } template <> inline void update_array(zfp::array4& a) { update_array4(a); } template <> inline void update_array(zfp::array4& a) { update_array4(a); } // test random-accessible array primitive template inline uint test_array(Array& a, const Scalar* f, uint n, double tolerance, double dfmax) { uint failures = 0; // test construction std::ostringstream status; status << " construct: "; Scalar emax = 0; for (uint i = 0; i < n; i++) emax = std::max(emax, std::abs(f[i] - a[i])); status << std::scientific; status.precision(3); // make sure max error is within tolerance bool pass = true; if (emax <= tolerance) status << " " << emax << " <= " << tolerance; else { status << " [" << emax << " > " << tolerance << "]"; pass = false; } std::cout << std::setw(width) << std::left << status.str() << (pass ? " OK " : "FAIL") << std::endl; if (!pass) failures++; // test array updates status.str(""); status << " update: "; update_array(a); Scalar amax = a[0]; pass = true; if (std::abs(amax - dfmax) <= 1e-3 * dfmax) status << " " << amax << " ~ " << dfmax; else { status << " [" << amax << " != " << dfmax << "]"; pass = false; } std::cout << std::setw(width) << std::left << status.str() << (pass ? " OK " : "FAIL") << std::endl; if (!pass) failures++; return failures; } // test small or large d-dimensional arrays of type Scalar template inline uint test(uint dims, ArraySize array_size) { uint failures = 0; uint m = test_size(array_size); uint n = m * m * m * m * m * m * m * m * m * m * m * m; Scalar* f = new Scalar[n]; // determine array size uint nx, ny, nz, nw; zfp_field* field = zfp_field_alloc(); zfp_field_set_type(field, zfp::internal::trait::type); zfp_field_set_pointer(field, f); switch (dims) { case 1: nx = n; ny = nz = nw = 0; zfp_field_set_size_1d(field, nx); break; case 2: nx = ny = m * m * m * m * m * m; nz = nw = 0; zfp_field_set_size_2d(field, nx, ny); break; case 3: nx = ny = nz = m * m * m * m; nw = 0; zfp_field_set_size_3d(field, nx, ny, nz); break; case 4: nx = ny = nz = nw = m * m * m; zfp_field_set_size_4d(field, nx, ny, nz, nw); break; default: std::cout << "invalid dimensions " << dims << std::endl; return 1; } initialize(f, dims, array_size); uint t = (zfp_field_type(field) == zfp_type_float ? 0 : 1); std::cout << "testing " << dims << "D array of " << (t == 0 ? "floats" : "doubles") << std::endl; // test data integrity uint32 checksum[2][2][4] = { // [size][type][dims] // small {{ 0x54174c44u, 0x86609589u, 0xfc0a6a76u, 0xa3481e00u }, { 0x7d257bb6u, 0x294bb210u, 0x68614d26u, 0xf6bd3a21u }}, // large {{ 0xd1ce1aceu, 0x644274dau, 0xc0ad63fau, 0x700de480u }, { 0xc3ed7116u, 0x644e2117u, 0xd7464b07u, 0x2516382eu }}, }; uint32 h = hash(f, n * sizeof(Scalar)); if (h != checksum[array_size][t][dims - 1]) std::cout << "warning: test data checksum " << std::hex << h << " != " << checksum[array_size][t][dims - 1] << "; tests below may fail" << std::endl; // open compressed stream zfp_stream* stream = zfp_stream_open(0); // test fixed rate for (uint rate = 2u >> t, i = 0; rate <= 32 * (t + 1); rate *= 4, i++) { // expected max errors double emax[2][2][4][4] = { // [size][type][dims][rate] // small { { {1.627e+01, 8.277e-02, 0.000e+00}, {1.500e+00, 3.663e-03, 0.000e+00}, {1.500e+00, 9.583e-03, 0.000e+00}, {1.373e+01, 6.633e-01, 0.000e+00}, }, { {1.627e+01, 1.601e+01, 1.832e-04, 0.000e+00}, {2.376e+01, 1.797e-01, 8.584e-06, 0.000e+00}, {5.210e+00, 2.002e-01, 3.338e-05, 0.000e+00}, {1.016e+01, 8.985e+00, 3.312e-03, 0.000e+00}, }, }, // large { { {1.627e+01, 2.100e-02, 0.000e+00}, {1.624e-01, 7.439e-05, 0.000e+00}, {1.001e-02, 7.248e-05, 0.000e+00}, {2.527e-02, 2.460e-04, 0.000e+00}, }, { {1.627e+01, 1.601e+01, 2.289e-05, 0.000e+00}, {1.607e+01, 2.076e-03, 0.000e+00, 0.000e+00}, {1.407e-01, 7.344e-04, 0.000e+00, 0.000e+00}, {1.436e-01, 2.659e-03, 8.801e-08, 0.000e+00}, } } }; failures += test_rate(stream, field, rate, static_cast(emax[array_size][t][dims - 1][i]), array_size == Large); } if (stream_word_bits != 64) std::cout << "warning: stream word size is smaller than 64; tests below may fail" << std::endl; // test fixed precision for (uint prec = 4u << t, i = 0; i < 3; prec *= 2, i++) { // expected compressed sizes size_t bytes[2][2][4][3] = { // [size][type][dims][prec] // small { { {2192, 3280, 6328}, { 592, 1328, 4384}, { 152, 1040, 4600}, { 64, 1760, 5856}, }, { {3664, 6712, 14104}, {1424, 4480, 12616}, {1064, 4624, 12808}, {1768, 5864, 14056}, }, }, // large { { {8965672, 13160560, 21835352}, {2235560, 3512848, 10309240}, { 568456, 1361056, 8759696}, { 134344, 739632, 8896360}, }, { {14733112, 23407904, 44997832}, { 3905240, 10701640, 40856544}, { 1458368, 8857008, 41270184}, { 763928, 8920656, 41574712}, }, } }; failures += test_precision(stream, field, prec, bytes[array_size][t][dims - 1][i]); } // test fixed accuracy for (uint i = 0; i < 3; i++) { Scalar tol[] = { Scalar(1e-3), 2 * std::numeric_limits::epsilon(), 0 }; // expected compressed sizes size_t bytes[2][2][4][3] = { // [size][type][dims][tol] // small { { {6328, 11944, 13720}, {4936, 11064, 12520}, {6104, 11752, 12784}, {9440, 14048, 14048}, }, { {6712, 25888, 29064}, {5032, 26016, 28984}, {6128, 27120, 29192}, {9448, 30440, 30440}, }, }, // large { { {21815976, 38285256, 43425280}, { 9187232, 32695984, 40464144}, { 8914336, 33364208, 41172864}, {12109200, 35921784, 41550416}, }, { {23388528, 79426016, 88659304}, { 9579632, 89770896, 103388072}, { 9011648, 94009072, 107606336}, {12133496, 97126288, 107911568}, }, } }; failures += test_accuracy(stream, field, tol[i], bytes[array_size][t][dims - 1][i]); } // test reversible { // expected compressed sizes size_t bytes[2][2][4] = { // [size][type][dims] // small { { 7272, 5104, 6096, 6864, }, { 7784, 5232, 6128, 6872, }, }, // large { { 25037288, 12792440, 14187128, 17135704, }, { 27134024, 13315632, 14316880, 17168096, }, } }; failures += test_reversible(stream, field, bytes[array_size][t][dims - 1]); } // test compressed array support double emax[2][2][4] = { // [size][type][dims] (construct test) // small { {4.578e-05, 7.630e-06, 3.148e-05, 3.598e-03}, {1.832e-04, 8.584e-06, 3.338e-05, 3.312e-03}, }, // large { {0.000e+00, 0.000e+00, 0.000e+00, 1.193e-07}, {2.289e-05, 0.000e+00, 0.000e+00, 8.801e-08}, } }; double dfmax[2][2][4] = { // [size][type][dims] (update test) // small { {2.155e-02, 3.755e-01, 1.846e+00, 4.843e+01}, {2.155e-02, 3.755e-01, 1.846e+00, 4.844e+01}, }, // large { {2.441e-04, 4.883e-04, 1.222e-03, 2.567e-02}, {2.670e-04, 4.883e-04, 1.222e-03, 2.567e-02}, } }; double rate = 16; switch (dims) { case 1: { zfp::array1 a(nx, rate, f); failures += test_array(a, f, n, static_cast(emax[array_size][t][dims - 1]), static_cast(dfmax[array_size][t][dims - 1])); } break; case 2: { zfp::array2 a(nx, ny, rate, f); failures += test_array(a, f, n, static_cast(emax[array_size][t][dims - 1]), static_cast(dfmax[array_size][t][dims - 1])); } break; case 3: { zfp::array3 a(nx, ny, nz, rate, f); failures += test_array(a, f, n, static_cast(emax[array_size][t][dims - 1]), static_cast(dfmax[array_size][t][dims - 1])); } break; case 4: { zfp::array4 a(nx, ny, nz, nw, rate, f); failures += test_array(a, f, n, static_cast(emax[array_size][t][dims - 1]), static_cast(dfmax[array_size][t][dims - 1])); } break; } std::cout << std::endl; zfp_stream_close(stream); zfp_field_free(field); delete[] f; return failures; } // various library and compiler sanity checks inline uint common_tests() { uint failures = 0; uint warnings = 0; // test library version if (zfp_codec_version != ZFP_CODEC || zfp_library_version != ZFP_VERSION) { std::cout << "library header and binary version mismatch" << std::endl; failures++; } // ensure integer type sizes are correct if (CHAR_BIT != 8) { std::cout << "byte type is not 8 bits wide" << std::endl; failures++; } if (sizeof(int8) != 1u || sizeof(uint8) != 1u) { std::cout << "8-bit integer type is not one byte wide" << std::endl; failures++; } if (sizeof(int16) != 2u || sizeof(uint16) != 2u) { std::cout << "16-bit integer type is not two bytes wide" << std::endl; failures++; } if (sizeof(int32) != 4u || sizeof(uint32) != 4u) { std::cout << "32-bit integer type is not four bytes wide" << std::endl; failures++; } if (sizeof(int64) != 8u || sizeof(uint64) != 8u) { std::cout << "64-bit integer type is not eight bytes wide" << std::endl; failures++; } // ensure signed right shifts are arithmetic int32 x32 = -2; if ((x32 >> 1) != -1 || (x32 >> 2) != -1) { std::cout << "32-bit arithmetic right shift not supported" << std::endl; failures++; } int64 x64 = -2; if ((x64 >> 1) != INT64C(-1) || (x64 >> 2) != INT64C(-1)) { std::cout << "64-bit arithmetic right shift not supported" << std::endl; failures++; } // testing requires default (64-bit) stream words if (stream_word_bits != 64) { std::cout << "regression testing requires BIT_STREAM_WORD_TYPE=uint64" << std::endl; failures++; } // warn if non-default compiler options are used #if ZFP_ROUNDING_MODE != 0 std::cout << "warning: selected ZFP_ROUNDING_MODE may break tests" << std::endl; warnings++; #ifdef ZFP_WITH_TIGHT_ERROR std::cout << "warning: ZFP_WITH_TIGHT_ERROR option may break tests" << std::endl; warnings++; #endif #endif #ifdef ZFP_WITH_DAZ std::cout << "warning: ZFP_WITH_DAZ option may break tests" << std::endl; warnings++; #endif if (failures || warnings) std::cout << std::endl; return failures; } int main(int argc, char* argv[]) { std::cout << zfp_version_string << std::endl; std::cout << "library version " << zfp_library_version << std::endl; std::cout << "CODEC version " << zfp_codec_version << std::endl; std::cout << "data model "; size_t model = ((sizeof(uint64) - 1) << 12) + ((sizeof(void*) - 1) << 8) + ((sizeof(unsigned long int) - 1) << 4) + ((sizeof(unsigned int) - 1) << 0); switch (model) { case 0x7331u: std::cout << "LP32"; break; case 0x7333u: std::cout << "ILP32"; break; case 0x7733u: std::cout << "LLP64"; break; case 0x7773u: std::cout << "LP64"; break; case 0x7777u: std::cout << "ILP64"; break; default: std::cout << "unknown (0x" << std::hex << model << ")"; break; } std::cout << std::endl; std::cout << std::endl; uint sizes = 0; uint types = 0; uint dims = 0; for (int i = 1; i < argc; i++) if (std::string(argv[i]) == "small") sizes |= mask(Small); else if (std::string(argv[i]) == "large") sizes |= mask(Large); else if (std::string(argv[i]) == "float" || std::string(argv[i]) == "fp32") types |= mask(Float); else if (std::string(argv[i]) == "double" || std::string(argv[i]) == "fp64") types |= mask(Double); else if (std::string(argv[i]) == "1d") dims |= mask(1); else if (std::string(argv[i]) == "2d") dims |= mask(2); else if (std::string(argv[i]) == "3d") dims |= mask(3); else if (std::string(argv[i]) == "4d") dims |= mask(4); else if (std::string(argv[i]) == "all") { sizes |= mask(Small) | mask(Large); types |= mask(Float) | mask(Double); dims |= mask(1) | mask(2) | mask(3) | mask(4); } else { std::cerr << "Usage: testzfp [all] [small|large] [fp32|fp64|float|double] [1d|2d|3d|4d]" << std::endl; return EXIT_FAILURE; } // use defaults if not specified if (!sizes) sizes = mask(Small); if (!types) types = mask(Float) | mask(Double); if (!dims) dims = mask(1) | mask(2) | mask(3) | mask(4); // test library and compiler uint failures = common_tests(); if (failures) return EXIT_FAILURE; // test arrays for (int size = Small; size <= Large; size++) if (sizes & mask(ArraySize(size))) { for (uint d = 1; d <= 4; d++) if (dims & mask(d)) { if (types & mask(Float)) failures += test(d, ArraySize(size)); if (types & mask(Double)) failures += test(d, ArraySize(size)); } } if (failures) std::cout << failures << " test(s) failed" << std::endl; else std::cout << "all tests passed" << std::endl; return failures ? EXIT_FAILURE : EXIT_SUCCESS; } zfp-1.0.1/tests/utils/000077500000000000000000000000001453723256400146255ustar00rootroot00000000000000zfp-1.0.1/tests/utils/CMakeLists.txt000066400000000000000000000025061453723256400173700ustar00rootroot00000000000000# libraries used by tests # seeded random number generators add_library(rand32Lib rand32.c rand32.h) add_library(rand64Lib rand64.c rand64.h) # hashing add_library(zfpHashLib zfpHash.c zfpHash.h) if(CMAKE_C_COMPILER_ID STREQUAL "GNU") target_compile_options(zfpHashLib PUBLIC $<$:-Wno-pointer-sign>) endif() # fixed point add_library(fixedpoint96Lib fixedpoint96.c fixedpoint96.h) # [seeded] random correlated array generator add_library(genSmoothRandNumsLib genSmoothRandNums.c genSmoothRandNums.h) target_link_libraries(genSmoothRandNumsLib PRIVATE rand64Lib fixedpoint96Lib) # strided array operations add_library(stridedOperationsLib stridedOperations.c stridedOperations.h) target_link_libraries(stridedOperationsLib PRIVATE zfp) # compute zfp compression parameters add_library(zfpCompressionParamsLib zfpCompressionParams.c zfpCompressionParams.h) # timer add_library(zfpTimerLib zfpTimer.c zfpTimer.h) # checksums API add_library(zfpChecksumsLib zfpChecksums.c zfpChecksums.h) if(PRINT_CHECKSUMS) target_compile_definitions(zfpChecksumsLib PUBLIC PRINT_CHECKSUMS) endif() if(HAVE_LIBM_MATH) target_link_libraries(rand32Lib PRIVATE m) target_link_libraries(rand64Lib PRIVATE m) target_link_libraries(genSmoothRandNumsLib PRIVATE m) target_link_libraries(zfpCompressionParamsLib PRIVATE m) endif() zfp-1.0.1/tests/utils/fixedpoint96.c000066400000000000000000000157451453723256400173350ustar00rootroot00000000000000#include #include "fixedpoint96.h" void initFixedPt(int64 i, uint32 f, fixedPt* result) { result->i = i; result->f = f; } // logical shift static void shiftRightSigned(int64 input, uint shiftAmount, int64* result) { if (input < 0) { *result = ~(~input >> shiftAmount); } else { *result = input >> shiftAmount; } } // split 64 bit unsigned into two 32 bit unsigned parts // both parts live in the lowest 32 bits of the uint64 static void splitUnsigned(uint64 input, uint64* upper, uint64* lower) { *upper = input >> 32; *lower = input - (*upper << 32); } // split 64 bit signed into two 32 bit parts // both parts live in the lowest 32 bits of the 64 bit int // upper keeps the sign // lower is unsigned static void splitSigned(int64 input, int64* upper, uint64* lower) { shiftRightSigned(input, 32, upper); *lower = (uint64)(input - (*upper << 32)); } static void addFractional(uint32 a, uint32 b, uint32* result, uint32* carry) { uint64 a64 = (uint64)a; uint64 b64 = (uint64)b; uint64 carry64, result64; splitUnsigned(a64 + b64, &carry64, &result64); // carry is 0 or 1 *carry = (uint32)carry64; *result = (uint32)result64; } // returns 1 if sum overflows static int addSignedIntegers(int64 a, int64 b, int64* result) { if (b >= 0 && a > LLONG_MAX - b) { return 1; } else if (b < 0 && a < LLONG_MIN - b) { return 1; } *result = a + b; return 0; } int roundFixedPt(fixedPt* fp, int64* result) { return addSignedIntegers(fp->i, (int64)(fp->f >= 0x80000000), result); } // returns 0 if successful, 1 otherwise int add(fixedPt* a, fixedPt* b, fixedPt* result) { uint32 carry; addFractional(a->f, b->f, &result->f, &carry); // detect overflow while trying each combination: 3 terms, 2 operations int64 val; // (a + carry) + b if (addSignedIntegers(a->i, (int64)carry, &val) == 0) { if (addSignedIntegers(val, b->i, &result->i) == 0) { return 0; } } // a + (carry + b) if (addSignedIntegers((int64)carry, b->i, &val) == 0) { if (addSignedIntegers(a->i, val, &result->i) == 0) { return 0; } } // (a + b) + carry if (addSignedIntegers(a->i, b->i, &val) == 0) { if (addSignedIntegers(val, (int64)carry, &result->i) == 0) { return 0; } } // unavoidable overflow return 1; } // always successful // subtract borrow from a's next MSB [integer] part static void subtractFractional(uint32 a, uint32 b, uint32* result, int64* borrow) { *result = a - b; *borrow = (a < b) ? 1 : 0; } // returns 1 if subtraction goes out of range static int subtractSignedIntegers(int64 a, int64 b, int64* result) { if (b < 0 && a > LLONG_MAX + b) { return 1; } else if (b >= 0 && a < LLONG_MIN + b) { return 1; } *result = a - b; return 0; } // returns 1 if result would go out of range int subtract(fixedPt* a, fixedPt* b, fixedPt* result) { int64 borrow; subtractFractional(a->f, b->f, &result->f, &borrow); // detect overflow while trying each combination: 3 terms, 2 operations int64 val; // (a - borrow) - b if (subtractSignedIntegers(a->i, borrow, &val) == 0) { if (subtractSignedIntegers(val, b->i, &result->i) == 0) { return 0; } } // a - (borrow + b) if (addSignedIntegers(borrow, b->i, &val) == 0) { if (subtractSignedIntegers(a->i, val, &result->i) == 0) { return 0; } } // (a - b) - borrow if (subtractSignedIntegers(a->i, b->i, &val) == 0) { if (subtractSignedIntegers(val, borrow, &result->i) == 0) { return 0; } } // unavoidable overflow return 1; } // returns 1 if integer part overflows // fractional part is truncated int multiply(fixedPt* a, fixedPt* b, fixedPt* result) { // split everything into 32 bit values, stored in 64 bit types // that way, multiplying 2 32 bit values will fit in 64 bits // also, uint64 to int64 casts will be safe uint64 af, bf, rf; af = (uint64)a->f; bf = (uint64)b->f; uint64 ai0, bi0, ri0; int64 ai1, bi1, ri1; splitSigned(a->i, &ai1, &ai0); splitSigned(b->i, &bi1, &bi0); // actual values: // a = (2^32)*ai1 + ai0 + (2^-32)*af // b = (2^32)*bi1 + bi0 + (2^-32)*bf // // r = a*b = // A (2^64) * ai1*bi1 // B + (2^32) * (ai1*bi0 + ai0*bi1) // C + (ai0*bi0 + ai1*bf + af*bi1) // D + (2^-32) * (ai0*bf + af*bi0) // E + (2^-64) * af*bf // // // (MSB) (LSB) // -----fixedPt----- // a*b= _____|_____|_ri1_|_ri0_|_rf__|_____ // -----A----- // -----B----- // -----C----- // -----D----- // -----E----- // perform sum from LSB to MSB // - store 32 bit result // - carry overflow to next, more significant 32 bit chunk // naming // highA : 32 MSB of A stored in 32 LSB of highA // lowA : 32 LSB of A stored in 32 LSB of lowA // (2^-64) * E uint64 E = af * bf; uint64 highE = E >> 32; // omit lowE (truncated) // D = (2^-32) * (D1 + D2) uint64 highD1, lowD1, highD2, lowD2; splitUnsigned(ai0 * bf, &highD1, &lowD1); splitUnsigned(af * bi0, &highD2, &lowD2); // highD -> result LSB integer part // lowD -> result fractional part uint64 highD, uCarryD; splitUnsigned(lowD1 + lowD2 + highE, &uCarryD, &rf); splitUnsigned(highD1 + highD2 + uCarryD, &uCarryD, &highD); // C = C1 + C2 + C3 uint64 highC1; int64 highC2, highC3; uint64 lowC1, lowC2, lowC3; // C1 is unsigned (uint32 * uint32 only fits in uint64) // uint32 * int32 fits in int64 splitUnsigned(ai0 * bi0, &highC1, &lowC1); splitSigned(ai1 * (int64)bf, &highC2, &lowC2); splitSigned((int64)af * bi1, &highC3, &lowC3); // highC -> MSB integer part // lowC -> LSB integer part int64 sCarryC; uint64 highC; splitSigned((int64)lowC1 + (int64)lowC2 + (int64)lowC3 + (int64)highD, &sCarryC, &ri0); splitSigned((int64)highC1 + highC2 + highC3 + (int64)uCarryD + sCarryC, &sCarryC, &highC); // B = (2^32) * (B1 + B2) int64 highB1, highB2; uint64 lowB1, lowB2; splitSigned(ai1 * (int64)bi0, &highB1, &lowB1); splitSigned((int64)ai0 * bi1, &highB2, &lowB2); // lowB -> MSB integer part // highB -> more significant 32 bits than we can hold in fixedPt uint64 ri1Unsigned; int64 sCarryB; splitSigned((int64)lowB1 + (int64)lowB2 + (int64)highC, &sCarryB, &ri1Unsigned); int64 highB = highB1 + highB2 + sCarryC + sCarryB; // MSB of overall product keeps sign int64 A = ai1 * bi1 + highB; // check ri1Unsigned with A's sign is in range of int64 ri1Unsigned <<= 32; uint64 leftmostBitSetVal = (uint64)1 << 63; if (A == -1) { // result < 0 if (ri1Unsigned <= LLONG_MAX) { return 1; } // cast ri1Unsigned safely (set MSB to 1) ri1 = (int64)(ri1Unsigned - leftmostBitSetVal) - leftmostBitSetVal; } else if (A == 0){ // result >= 0 if (ri1Unsigned > LLONG_MAX) { return 1; } ri1 = (int64)ri1Unsigned; } else { return 1; } result->f = (uint32)rf; result->i = ri1 + ri0; return 0; } zfp-1.0.1/tests/utils/fixedpoint96.h000066400000000000000000000011021453723256400173200ustar00rootroot00000000000000#ifndef FIXEDPT_H #define FIXEDPT_H #include "include/zfp/internal/zfp/types.h" typedef struct { // the number represented = i + (2^-32)*f // integer part int64 i; // fractional part uint32 f; } fixedPt; void initFixedPt(int64 i, uint32 f, fixedPt* result); // functions with int return type: // return 0 if successful // return 1 if errored int roundFixedPt(fixedPt* fp, int64* result); int add(fixedPt* a, fixedPt* b, fixedPt* result); int subtract(fixedPt* a, fixedPt* b, fixedPt* result); int multiply(fixedPt* a, fixedPt* b, fixedPt* result); #endif zfp-1.0.1/tests/utils/genChecksums.sh000077500000000000000000000026761453723256400176160ustar00rootroot00000000000000#!/usr/bin/env bash set -ex MAX_DIM=4 SCALAR_TYPES=( "Float" "Double" "Int32" "Int64" ) mkdir -p checksumGenBuild cd checksumGenBuild cmake ../../.. -DZFP_WITH_OPENMP=OFF -DPRINT_CHECKSUMS=1 cmake --build . -- -j for DIM in $(seq 1 $MAX_DIM); do DIM_STR="${DIM}d" for SCALAR_STR in "${SCALAR_TYPES[@]}" do TEST_OUTPUT_FILE="test_output" TEMP_FILE="temp" TEMP_CHECKSUMS_FILE="temp_checksums" OUTPUT_FILE="${DIM_STR}${SCALAR_STR}.h" ctest -V -R "testZfpEncodeBlock${DIM_STR}${SCALAR_STR}" -O $TEMP_FILE cat "$TEMP_FILE" >> "$TEST_OUTPUT_FILE" ctest -V -R "testZfpEncodeBlockStrided${DIM_STR}${SCALAR_STR}" -O $TEMP_FILE cat "$TEMP_FILE" >> "$TEST_OUTPUT_FILE" ctest -V -R "testZfpDecodeBlock${DIM_STR}${SCALAR_STR}" -O $TEMP_FILE cat "$TEMP_FILE" >> "$TEST_OUTPUT_FILE" ctest -V -R "testZfpDecodeBlockStrided${DIM_STR}${SCALAR_STR}" -O $TEMP_FILE cat "$TEMP_FILE" >> "$TEST_OUTPUT_FILE" ctest -V -R "testZfpSerial${DIM_STR}${SCALAR_STR}" -O $TEMP_FILE cat "$TEMP_FILE" >> "$TEST_OUTPUT_FILE" grep -o '{UINT64C(0x.*' $TEST_OUTPUT_FILE > $TEMP_CHECKSUMS_FILE NUM_CHECKSUMS=$(wc -l < "$TEMP_CHECKSUMS_FILE") # create valid .h file echo "static const checksum_tuples _${DIM_STR}${SCALAR_STR}Checksums[${NUM_CHECKSUMS}] = {" > $OUTPUT_FILE cat $TEMP_CHECKSUMS_FILE >> $OUTPUT_FILE echo "};" >> $OUTPUT_FILE rm $TEST_OUTPUT_FILE $TEMP_FILE $TEMP_CHECKSUMS_FILE done done zfp-1.0.1/tests/utils/genSmoothRandNums.c000066400000000000000000000652661453723256400204230ustar00rootroot00000000000000#include #include #include #include "genSmoothRandNums.h" #include "fixedpoint96.h" #include "rand64.h" #define FLOAT_MANTISSA_BITS 23 #define DOUBLE_MANTISSA_BITS 52 size_t intPow(size_t base, int exponent) { size_t result = 1; int i; for (i = 0; i < exponent; i++) { result *= base; } return result; } static size_t computeOffset(size_t l, size_t k, size_t j, size_t i, size_t sideLen, int numDims) { size_t result = 0; switch (numDims) { case 4: result += l * sideLen * sideLen * sideLen; case 3: result += k * sideLen * sideLen; case 2: result += j * sideLen; case 1: result += i; } return result; } static void generateWeights(fixedPt* f, fixedPt weights[4]) { fixedPt oneHalf = {0, (uint32)0x80000000}; fixedPt one = {1, 0}; fixedPt nine = {9, 0}; fixedPt oneSixteenth = {0, (uint32)0x10000000}; weights[0] = (fixedPt){0, nextRand32()}; subtract(weights, &oneHalf, weights); multiply(weights, f, weights); subtract(weights, &one, weights); multiply(weights, &oneSixteenth, weights); weights[1] = (fixedPt){0, nextRand32()}; subtract(weights+1, &oneHalf, weights+1); multiply(weights+1, f, weights+1); add(weights+1, &nine, weights+1); multiply(weights+1, &oneSixteenth, weights+1); weights[2] = (fixedPt){0, nextRand32()}; subtract(weights+2, &oneHalf, weights+2); multiply(weights+2, f, weights+2); add(weights+2, &nine, weights+2); multiply(weights+2, &oneSixteenth, weights+2); weights[3] = (fixedPt){1, 0}; subtract(weights+3, weights, weights+3); subtract(weights+3, weights+1, weights+3); subtract(weights+3, weights+2, weights+3); } static void computeTensorProductDouble(fixedPt* initialVec, size_t initialVecLen, int numDims, fixedPt** outputArrPtr) { size_t i, j, k, l, index; size_t outputArrLen = intPow(initialVecLen, numDims); *outputArrPtr = malloc(outputArrLen * sizeof(fixedPt)); switch(numDims) { case 1: for (i = 0; i < initialVecLen; i++) { (*outputArrPtr)[i] = initialVec[i]; } break; case 2: for (j = 0; j < initialVecLen; j++) { for (i = 0; i < initialVecLen; i++) { index = computeOffset(0, 0, j, i, initialVecLen, 2); fixedPt* fp = (*outputArrPtr) + index; *fp = initialVec[i]; multiply(fp, initialVec + j, fp); } } break; case 3: for (k = 0; k < initialVecLen; k++) { for (j = 0; j < initialVecLen; j++) { for (i = 0; i < initialVecLen; i++) { index = computeOffset(0, k, j, i, initialVecLen, 3); fixedPt* fp = (*outputArrPtr) + index; *fp = initialVec[i]; multiply(fp, initialVec + j, fp); multiply(fp, initialVec + k, fp); } } } break; case 4: for (l = 0; l < initialVecLen; l++) { for (k = 0; k < initialVecLen; k++) { for (j = 0; j < initialVecLen; j++) { for (i = 0; i < initialVecLen; i++) { index = computeOffset(l, k, j, i, initialVecLen, 4); fixedPt* fp = (*outputArrPtr) + index; *fp = initialVec[i]; multiply(fp, initialVec + j, fp); multiply(fp, initialVec + k, fp); multiply(fp, initialVec + l, fp); } } } } break; } } // returns the length of the resulting array static size_t computeTensorProduct(int64* initialVec, size_t initialVecLen, int numDims, int64** outputArrPtr) { size_t i, j, k, l, index; size_t outputArrLen = intPow(initialVecLen, numDims); *outputArrPtr = malloc(outputArrLen * sizeof(int64)); switch(numDims) { case 1: for (i = 0; i < initialVecLen; i++) { (*outputArrPtr)[i] = initialVec[i]; } break; case 2: for (j = 0; j < initialVecLen; j++) { for (i = 0; i < initialVecLen; i++) { index = computeOffset(0, 0, j, i, initialVecLen, 2); (*outputArrPtr)[index] = initialVec[i] * initialVec[j]; } } break; case 3: for (k = 0; k < initialVecLen; k++) { for (j = 0; j < initialVecLen; j++) { for (i = 0; i < initialVecLen; i++) { index = computeOffset(0, k, j, i, initialVecLen, 3); (*outputArrPtr)[index] = initialVec[i] * initialVec[j] * initialVec[k]; } } } break; case 4: for (l = 0; l < initialVecLen; l++) { for (k = 0; k < initialVecLen; k++) { for (j = 0; j < initialVecLen; j++) { for (i = 0; i < initialVecLen; i++) { index = computeOffset(l, k, j, i, initialVecLen, 4); (*outputArrPtr)[index] = initialVec[i] * initialVec[j] * initialVec[k] * initialVec[l]; } } } } break; } return outputArrLen; } static void generateGridWeights(fixedPt* f, fixedPt** gridWeights) { fixedPt fourWeights[4]; generateWeights(f, fourWeights); computeTensorProductDouble(fourWeights, 4, 2, gridWeights); } static void generateCubeWeights(fixedPt* f, fixedPt** cubeWeights) { fixedPt fourWeights[4]; generateWeights(f, fourWeights); computeTensorProductDouble(fourWeights, 4, 3, cubeWeights); } static void generateHyperCubeWeights(fixedPt* f, fixedPt** hyperCubeWeights) { fixedPt fourWeights[4]; generateWeights(f, fourWeights); computeTensorProductDouble(fourWeights, 4, 4, hyperCubeWeights); } // displace val by 2*(distance out of bounds), only if out of bounds static int64 knockBack(int64 val, uint64 amplitude) { int64 maxBound = (int64)amplitude; int64 minBound = -maxBound; if (val > maxBound) { val -= 2 * (val - maxBound); } else if (val < minBound) { val += 2 * (minBound - val); } return val; } // uses 4 points: a dot b // a[] is strided static void dotProd1d(int64* a, size_t stride, fixedPt b[4], uint64 amplitude, int64* result) { fixedPt acc = {0, 0}; int i; for (i = 0; i < 4; i++) { fixedPt val = {a[i*stride], 0}; multiply(&val, b + i, &val); add(&acc, &val, &acc); } roundFixedPt(&acc, result); } // uses 4x4 points: a dot b // a[] is strided: strideI < strideJ static void dotProd2d(int64* a, size_t strideI, size_t strideJ, fixedPt b[16], uint64 amplitude, int64* result) { fixedPt acc = {0, 0}; int i, j; for (j = 0; j < 4; j++) { for (i = 0; i < 4; i++) { size_t aOffset = j*strideJ + i*strideI; fixedPt val = {a[aOffset], 0}; size_t bOffset = computeOffset(0, 0, j, i, 4, 2); multiply(&val, b + bOffset, &val); add(&acc, &val, &acc); } } roundFixedPt(&acc, result); } // uses 4x4x4 points: a dot b // a[] is strided: strideI < strideJ < strideK static void dotProd3d(int64* a, size_t strideI, size_t strideJ, size_t strideK, fixedPt b[64], uint64 amplitude, int64* result) { fixedPt acc = {0, 0}; int i, j, k; for (k = 0; k < 4; k++) { for (j = 0; j < 4; j++) { for (i = 0; i < 4; i++) { size_t aOffset = k*strideK + j*strideJ + i*strideI; fixedPt val = {a[aOffset], 0}; size_t bOffset = computeOffset(0, k, j, i, 4, 3); multiply(&val, b + bOffset, &val); add(&acc, &val, &acc); } } } roundFixedPt(&acc, result); } // uses 4x4x4x4 points: a dot b // a[] is strided: strideI < strideJ < strideK < strideL static void dotProd4d(int64* a, size_t strideI, size_t strideJ, size_t strideK, size_t strideL, fixedPt b[256], uint64 amplitude, int64* result) { fixedPt acc = {0, 0}; int i, j, k, l; for (l = 0; l < 4; l++) { for (k = 0; k < 4; k++) { for (j = 0; j < 4; j++) { for (i = 0; i < 4; i++) { size_t aOffset = l*strideL + k*strideK + j*strideJ + i*strideI; fixedPt val = {a[aOffset], 0}; size_t bOffset = computeOffset(l, k, j, i, 4, 4); multiply(&val, b + bOffset, &val); add(&acc, &val, &acc); } } } } roundFixedPt(&acc, result); } // uses 4 points static void edgeWeightedSum(int64* data, size_t stride, fixedPt* f, uint64 amplitude, int64* result) { fixedPt weights[4]; generateWeights(f, weights); int64 val; dotProd1d(data, stride, weights, amplitude, &val); *result = knockBack(val, amplitude); } // uses 4x4 points static void faceWeightedSum(int64* data, size_t strideI, size_t strideJ, fixedPt* f, uint64 amplitude, int64* result) { fixedPt* weights; generateGridWeights(f, &weights); int64 val; dotProd2d(data, strideI, strideJ, weights, amplitude, &val); free(weights); *result = knockBack(val, amplitude); } // uses 4x4x4 points static void cubeWeightedSum(int64* data, size_t strideI, size_t strideJ, size_t strideK, fixedPt* f, uint64 amplitude, int64* result) { fixedPt* weights; generateCubeWeights(f, &weights); int64 val; dotProd3d(data, strideI, strideJ, strideK, weights, amplitude, &val); free(weights); *result = knockBack(val, amplitude); } // uses 4x4x4x4 points static void hyperCubeWeightedSum(int64* data, size_t strideI, size_t strideJ, size_t strideK, size_t strideL, fixedPt* f, uint64 amplitude, int64* result) { fixedPt* weights; generateHyperCubeWeights(f, &weights); int64 val; dotProd4d(data, strideI, strideJ, strideK, strideL, weights, amplitude, &val); free(weights); *result = knockBack(val, amplitude); } // resulting array: [0 (inputArr) 0] // size n -> (n+2) static void createPadded1dArray(int64* inputArr, size_t inputSideLen, int64* paddedArr) { memcpy(paddedArr + 1, inputArr, inputSideLen * sizeof(int64)); paddedArr[0] = 0; paddedArr[inputSideLen + 1] = 0; } // resulting array's outermost rows and columns are zero // size m*n -> (m+2)*(n+2) static void createPadded2dArray(int64* inputArr, size_t inputSideLen, int64* paddedArr) { size_t paddedSideLen = inputSideLen + 2; size_t i, j; for (j = 0; j < paddedSideLen; j++) { for (i = 0; i < paddedSideLen; i++) { int64 val; if (j == 0 || j == (paddedSideLen-1) || i == 0 || i == (paddedSideLen-1)) { val = 0; } else { size_t inputIndex = computeOffset(0, 0, j-1, i-1, inputSideLen, 2); val = inputArr[inputIndex]; } size_t paddedIndex = computeOffset(0, 0, j, i, paddedSideLen, 2); paddedArr[paddedIndex] = val; } } } // resulting array's outermost entries are zero // size m*n*p -> (m+2)*(n+2)*(p+2) static void createPadded3dArray(int64* inputArr, size_t inputSideLen, int64* paddedArr) { size_t paddedSideLen = inputSideLen + 2; size_t i, j, k; for (k = 0; k < paddedSideLen; k++) { for (j = 0; j < paddedSideLen; j++) { for (i = 0; i < paddedSideLen; i++) { int64 val; if (k == 0 || k == (paddedSideLen-1) || j == 0 || j == (paddedSideLen-1) || i == 0 || i == (paddedSideLen-1)) { val = 0; } else { size_t inputIndex = computeOffset(0, k-1, j-1, i-1, inputSideLen, 3); val = inputArr[inputIndex]; } size_t paddedIndex = computeOffset(0, k, j, i, paddedSideLen, 3); paddedArr[paddedIndex] = val; } } } } // resulting array's outermost entries are zero // size m*n*p*q -> (m+2)*(n+2)*(p+2)*(q+2) static void createPadded4dArray(int64* inputArr, size_t inputSideLen, int64* paddedArr) { size_t paddedSideLen = inputSideLen + 2; size_t i, j, k, l; for (l = 0; l < paddedSideLen; l++) { for (k = 0; k < paddedSideLen; k++) { for (j = 0; j < paddedSideLen; j++) { for (i = 0; i < paddedSideLen; i++) { int64 val; if (l == 0 || l == (paddedSideLen-1) || k == 0 || k == (paddedSideLen-1) || j == 0 || j == (paddedSideLen-1) || i == 0 || i == (paddedSideLen-1)) { val = 0; } else { size_t inputIndex = computeOffset(l-1, k-1, j-1, i-1, inputSideLen, 4); val = inputArr[inputIndex]; } size_t paddedIndex = computeOffset(l, k, j, i, paddedSideLen, 4); paddedArr[paddedIndex] = val; } } } } } // Generate a larger array containing all the original array's points // plus entries in between adjacent points from the original array // // These new entries are computed as weighted sums from // its local neighborhood , plus some random noise static void produceLargerNoisedArray(int64* inputArr, size_t inputSideLen, int numDims, uint64 amplitude, fixedPt* f, int64* outputArr) { // pad (border/enclose) inputArr with zeros size_t paddedSideLen = inputSideLen + 2; size_t paddedTotalLen = intPow(paddedSideLen, numDims); int64* paddedInputArr = malloc(paddedTotalLen * sizeof(int64)); size_t outputSideLen = 2*inputSideLen - 1; size_t maxI = outputSideLen, maxJ = 1, maxK = 1, maxL = 1; switch (numDims) { case 1: createPadded1dArray(inputArr, inputSideLen, paddedInputArr); break; case 2: createPadded2dArray(inputArr, inputSideLen, paddedInputArr); maxJ = outputSideLen; break; case 3: createPadded3dArray(inputArr, inputSideLen, paddedInputArr); maxJ = outputSideLen; maxK = outputSideLen; break; case 4: createPadded4dArray(inputArr, inputSideLen, paddedInputArr); maxJ = outputSideLen; maxK = outputSideLen; maxL = outputSideLen; break; } size_t outI, outJ, outK, outL; for (outL = 0; outL < maxL; outL++) { size_t inL = outL / 2; for (outK = 0; outK < maxK; outK++) { size_t inK = outK / 2; for (outJ = 0; outJ < maxJ; outJ++) { size_t inJ = outJ / 2; for (outI = 0; outI < maxI; outI++) { size_t inI = outI / 2; int64* firstElementPtr = paddedInputArr; size_t stride; int64 val; if (outL % 2 == 0) { if (outK % 2 == 0) { if (outJ % 2 == 0) { if (outI % 2 == 0) { // (0000) vertex size_t inputIndex = computeOffset(inL, inK, inJ, inI, inputSideLen, numDims); val = inputArr[inputIndex]; } else { // (0001) edge centered point (i-direction) firstElementPtr += computeOffset(inL+1, inK+1, inJ+1, inI, paddedSideLen, numDims); edgeWeightedSum(firstElementPtr, 1, f, amplitude, &val); } } else { if (outI % 2 == 0) { // (0010) edge centered point (j-direction) firstElementPtr += computeOffset(inL+1, inK+1, inJ, inI+1, paddedSideLen, numDims); stride = paddedSideLen; edgeWeightedSum(firstElementPtr, stride, f, amplitude, &val); } else { // (0011) face centered point (ij plane) firstElementPtr += computeOffset(inL+1, inK+1, inJ, inI, paddedSideLen, numDims); size_t secondStride = paddedSideLen; faceWeightedSum(firstElementPtr, 1, secondStride, f, amplitude, &val); } } } else { if (outJ % 2 == 0) { if (outI % 2 == 0) { // (0100) edge centered point (k-direction) firstElementPtr += computeOffset(inL+1, inK, inJ+1, inI+1, paddedSideLen, numDims); stride = intPow(paddedSideLen, 2); edgeWeightedSum(firstElementPtr, stride, f, amplitude, &val); } else { // (0101) face centered point (ik plane) firstElementPtr += computeOffset(inL+1, inK, inJ+1, inI, paddedSideLen, numDims); size_t secondStride = intPow(paddedSideLen, 2); faceWeightedSum(firstElementPtr, 1, secondStride, f, amplitude, &val); } } else { if (outI % 2 == 0) { // (0110) face centered point (jk plane) firstElementPtr += computeOffset(inL+1, inK, inJ, inI+1, paddedSideLen, numDims); stride = paddedSideLen; size_t secondStride = intPow(paddedSideLen, 2); faceWeightedSum(firstElementPtr, stride, secondStride, f, amplitude, &val); } else { // (0111) cube centered point (ijk) firstElementPtr += computeOffset(inL+1, inK, inJ, inI, paddedSideLen, numDims); size_t secondStride = paddedSideLen; size_t thirdStride = intPow(paddedSideLen, 2); cubeWeightedSum(firstElementPtr, 1, secondStride, thirdStride, f, amplitude, &val); } } } } else { if (outK % 2 == 0) { if (outJ % 2 == 0) { if (outI % 2 == 0) { // (1000) edge centered point (l-direction) firstElementPtr += computeOffset(inL, inK+1, inJ+1, inI+1, paddedSideLen, numDims); stride = intPow(paddedSideLen, 3); edgeWeightedSum(firstElementPtr, stride, f, amplitude, &val); } else { // (1001) face centered point (il plane) firstElementPtr += computeOffset(inL, inK+1, inJ+1, inI, paddedSideLen, numDims); stride = 1; size_t secondStride = intPow(paddedSideLen, 3); faceWeightedSum(firstElementPtr, stride, secondStride, f, amplitude, &val); } } else { if (outI % 2 == 0) { // (1010) face centered point (jl plane) firstElementPtr += computeOffset(inL, inK+1, inJ, inI+1, paddedSideLen, numDims); stride = paddedSideLen; size_t secondStride = intPow(paddedSideLen, 3); faceWeightedSum(firstElementPtr, stride, secondStride, f, amplitude, &val); } else { // (1011) cube centered point (ijl) firstElementPtr += computeOffset(inL, inK+1, inJ, inI, paddedSideLen, numDims); size_t secondStride = paddedSideLen; size_t thirdStride = intPow(paddedSideLen, 3); cubeWeightedSum(firstElementPtr, 1, secondStride, thirdStride, f, amplitude, &val); } } } else { if (outJ % 2 == 0) { if (outI % 2 == 0) { // (1100) face centered point (kl plane) firstElementPtr += computeOffset(inL, inK, inJ+1, inI+1, paddedSideLen, numDims); stride = intPow(paddedSideLen, 2); size_t secondStride = intPow(paddedSideLen, 3); faceWeightedSum(firstElementPtr, stride, secondStride, f, amplitude, &val); } else { // (1101) cube centered point (ikl) firstElementPtr += computeOffset(inL, inK, inJ+1, inI, paddedSideLen, numDims); size_t secondStride = intPow(paddedSideLen, 2); size_t thirdStride = intPow(paddedSideLen, 3); cubeWeightedSum(firstElementPtr, 1, secondStride, thirdStride, f, amplitude, &val); } } else { if (outI % 2 == 0) { // (1110) cube centered point (jkl) firstElementPtr += computeOffset(inL, inK, inJ, inI+1, paddedSideLen, numDims); stride = paddedSideLen; size_t secondStride = intPow(paddedSideLen, 2); size_t thirdStride = intPow(paddedSideLen, 3); cubeWeightedSum(firstElementPtr, stride, secondStride, thirdStride, f, amplitude, &val); } else { // (1111) hyper-cube centered point (ijkl) firstElementPtr += computeOffset(inL, inK, inJ, inI, paddedSideLen, numDims); size_t secondStride = paddedSideLen; size_t thirdStride = intPow(paddedSideLen, 2); size_t fourthStride = intPow(paddedSideLen, 3); hyperCubeWeightedSum(firstElementPtr, 1, secondStride, thirdStride, fourthStride, f, amplitude, &val); } } } } size_t outputIndex = computeOffset(outL, outK, outJ, outI, outputSideLen, numDims); outputArr[outputIndex] = val; } } } } free(paddedInputArr); } // if vals are outside [-amplitude, amplitude], then set them to the boundary value // *this function should do nothing* static void clampValsIntoRange(int64* arr, size_t n, uint64 amplitude) { int64 maxBound = (int64)amplitude; int64 minBound = -maxBound; size_t i; for (i = 0; i < n; i++) { if (arr[i] < minBound) { arr[i] = minBound; } else if (arr[i] > maxBound) { arr[i] = maxBound; } } } static void copyArraySubset(int64* inputArr, size_t inputSideLen, int numDims, int64* outputArr, size_t outputSideLen) { size_t i, j, k, l; switch(numDims) { case 1: memcpy(outputArr, inputArr, outputSideLen * sizeof(int64)); break; case 2: for (j = 0; j < outputSideLen; j++) { for (i = 0; i < outputSideLen; i++) { size_t outputIndex = computeOffset(0, 0, j, i, outputSideLen, 2); size_t inputIndex = computeOffset(0, 0, j, i, inputSideLen, 2); outputArr[outputIndex] = inputArr[inputIndex]; } } break; case 3: for (k = 0; k < outputSideLen; k++) { for (j = 0; j < outputSideLen; j++) { for (i = 0; i < outputSideLen; i++) { size_t outputIndex = computeOffset(0, k, j, i, outputSideLen, 3); size_t inputIndex = computeOffset(0, k, j, i, inputSideLen, 3); outputArr[outputIndex] = inputArr[inputIndex]; } } } break; case 4: for (l = 0; l < outputSideLen; l++) { for (k = 0; k < outputSideLen; k++) { for (j = 0; j < outputSideLen; j++) { for (i = 0; i < outputSideLen; i++) { size_t outputIndex = computeOffset(l, k, j, i, outputSideLen, 4); size_t inputIndex = computeOffset(l, k, j, i, inputSideLen, 4); outputArr[outputIndex] = inputArr[inputIndex]; } } } } break; } } // this will destroy (free) inputArr static void generateNRandInts(int64* inputArr, size_t inputSideLen, size_t minTotalElements, int numDims, uint64 amplitude, int64** outputArrPtr, size_t* outputSideLen, size_t* outputTotalLen) { // parameters used for random noise fixedPt f = {7, 0}; fixedPt scaleFVal = {0, 0xaaaaaaaa}; int64* currArr = inputArr; size_t currSideLen = inputSideLen; size_t currTotalLen = intPow(inputSideLen, numDims); int64* nextArr = NULL; size_t nextSideLen = 0, nextTotalLen = 0; while(currTotalLen < minTotalElements) { nextSideLen = 2*currSideLen - 1; nextTotalLen = intPow(nextSideLen, numDims); nextArr = malloc(nextTotalLen * sizeof(int64)); produceLargerNoisedArray(currArr, currSideLen, numDims, amplitude, &f, nextArr); free(currArr); currArr = nextArr; currSideLen = nextSideLen; currTotalLen = nextTotalLen; // reduce random noise multiplier multiply(&f, &scaleFVal, &f); } // for safety (expected nop) clampValsIntoRange(nextArr, nextTotalLen, amplitude); // initialize output data *outputSideLen = nextSideLen; *outputTotalLen = nextTotalLen; *outputArrPtr = malloc(*outputTotalLen * sizeof(int64)); // store output data copyArraySubset(nextArr, nextSideLen, numDims, *outputArrPtr, *outputSideLen); free(nextArr); } static void cast64ArrayTo32(int64* inputArr, size_t arrLen, int32* outputArr) { size_t i; for (i = 0; i < arrLen; i++) { outputArr[i] = (int32)inputArr[i]; } } static void convertIntArrToFloatArr(int64* inputArr, size_t arrLen, float* outputArr) { size_t i; for (i = 0; i < arrLen; i++) { outputArr[i] = ldexpf((float)inputArr[i], -12); } } static void convertIntArrToDoubleArr(int64* inputArr, size_t arrLen, double* outputArr) { size_t i; for (i = 0; i < arrLen; i++) { outputArr[i] = ldexp((double)inputArr[i], -26); } } // generate array that will be initially fed into generateNRandInts() static void generateInitialArray(int64* initialVec, size_t initialVecLen, int numDims, uint64 amplitude, int64** outputArrPtr) { size_t totalLen = computeTensorProduct(initialVec, initialVecLen, numDims, outputArrPtr); // compute signed amplitudes int64 positiveAmp = (int64)amplitude; int64 negativeAmp = -positiveAmp; // set non-zero values to signed amplitude size_t i; for (i = 0; i < totalLen; i++) { if ((*outputArrPtr)[i] > 0) { (*outputArrPtr)[i] = positiveAmp; } else if ((*outputArrPtr)[i] < 0) { (*outputArrPtr)[i] = negativeAmp; } } } void generateSmoothRandInts64(size_t minTotalElements, int numDims, int amplitudeExp, int64** outputArrPtr, size_t* outputSideLen, size_t* outputTotalLen) { uint64 amplitude = ((uint64)1 << amplitudeExp) - 1; // initial vector for tensor product (will be scaled to amplitude) size_t initialSideLen = 5; int64* initialVec = malloc(initialSideLen * sizeof(int64)); initialVec[0] = 0; initialVec[1] = 1; initialVec[2] = 0; initialVec[3] = -1; initialVec[4] = 0; // initial array (tensor product of initial vector, also scaled to amplitude) int64* inputArr; generateInitialArray(initialVec, initialSideLen, numDims, amplitude, &inputArr); free(initialVec); resetRandGen(); // generate data (always done with int64) // inputArr is free'd inside function generateNRandInts(inputArr, initialSideLen, minTotalElements, numDims, amplitude, outputArrPtr, outputSideLen, outputTotalLen); } void generateSmoothRandInts32(size_t minTotalElements, int numDims, int amplitudeExp, int32** outputArr32Ptr, size_t* outputSideLen, size_t* outputTotalLen) { int64* randArr64; generateSmoothRandInts64(minTotalElements, numDims, amplitudeExp, &randArr64, outputSideLen, outputTotalLen); *outputArr32Ptr = calloc(*outputTotalLen, sizeof(int32)); cast64ArrayTo32(randArr64, *outputTotalLen, *outputArr32Ptr); free(randArr64); } void generateSmoothRandFloats(size_t minTotalElements, int numDims, float** outputArrPtr, size_t* outputSideLen, size_t* outputTotalLen) { int64* intArr; generateSmoothRandInts64(minTotalElements, numDims, FLOAT_MANTISSA_BITS, &intArr, outputSideLen, outputTotalLen); *outputArrPtr = calloc(*outputTotalLen, sizeof(float)); convertIntArrToFloatArr(intArr, *outputTotalLen, *outputArrPtr); free(intArr); } void generateSmoothRandDoubles(size_t minTotalElements, int numDims, double** outputArrPtr, size_t* outputSideLen, size_t* outputTotalLen) { int64* intArr; generateSmoothRandInts64(minTotalElements, numDims, DOUBLE_MANTISSA_BITS, &intArr, outputSideLen, outputTotalLen); *outputArrPtr = calloc(*outputTotalLen, sizeof(double)); convertIntArrToDoubleArr(intArr, *outputTotalLen, *outputArrPtr); free(intArr); } zfp-1.0.1/tests/utils/genSmoothRandNums.h000066400000000000000000000023441453723256400204140ustar00rootroot00000000000000#ifndef GEN_SMOOTH_RAND_INTS_H #define GEN_SMOOTH_RAND_INTS_H #include "zfp/internal/zfp/types.h" // used to compute (square) array sizes size_t intPow(size_t base, int exponent); // a double pointer is passed because memory allocation // is taken care of within the functions // generate randomly correlated integers in range: // [-(2^amplitudeExp - 1), 2^amplitudeExp - 1] (64 bit) void generateSmoothRandInts64(size_t minTotalElements, int numDims, int amplitudeExp, int64** outputArr, size_t* outputSideLen, size_t* outputTotalLen); // generate randomly correlated integers in range: // [-(2^amplitudeExp - 1), 2^amplitudeExp - 1] (32 bit) void generateSmoothRandInts32(size_t minTotalElements, int numDims, int amplitudeExp, int32** outputArr32Ptr, size_t* outputSideLen, size_t* outputTotalLen); // generate randomly correlated floats in range: // [-(2^11), 2^11 - 2^(-12)] void generateSmoothRandFloats(size_t minTotalElements, int numDims, float** outputArrPtr, size_t* outputSideLen, size_t* outputTotalLen); // generate randomly correlated doubles in range: // [-(2^26), 2^26 - 2^(-26)] void generateSmoothRandDoubles(size_t minTotalElements, int numDims, double** outputArrPtr, size_t* outputSideLen, size_t* outputTotalLen); #endif zfp-1.0.1/tests/utils/rand32.c000066400000000000000000000013431453723256400160630ustar00rootroot00000000000000#include #include "rand32.h" #define SEED 5 // POSIX rand48 #define MULTIPLIER 0x5deece66d #define INCREMENT 0xb #define MODULO ((uint64)1 << 48) #define MASK_31 (0x7fffffffu) static uint64 X; void resetRandGen() { X = SEED; } // returns integer [0, 2^31 - 1] uint32 nextUnsignedRand() { X = (MULTIPLIER*X + INCREMENT) % MODULO; return (uint32)((X >> 16) & MASK_31); } // returns integer [-(2^30), 2^30 - 1] int32 nextSignedRandInt() { return (int32)nextUnsignedRand() - 0x40000000; } // returns float [-(2^11), 2^11 - 2^(-12)] float nextSignedRandFlPt() { // 23 bit signed number uint32 uVal = (nextUnsignedRand() >> 7) & 0x00ffffff; int32 sVal = (int32)uVal - 0x800000; return ldexpf((float)sVal, -12); } zfp-1.0.1/tests/utils/rand32.h000066400000000000000000000005051453723256400160670ustar00rootroot00000000000000#ifndef RAND_32_H #define RAND_32_H #include "include/zfp/internal/zfp/types.h" // reset seed void resetRandGen(); // returns integer [0, 2^31 - 1] uint32 nextUnsignedRand(); // returns integer [-(2^30), 2^30 - 1] int32 nextSignedRandInt(); // returns float [-(2^11), 2^11 - 2^(-12)] float nextSignedRandFlPt(); #endif zfp-1.0.1/tests/utils/rand64.c000066400000000000000000000016651453723256400160770ustar00rootroot00000000000000#include #include "rand64.h" #define SEED 5 // https://nuclear.llnl.gov/CNP/rng/rngman/node4.html #define MULTIPLIER (2862933555777941757uLL) #define INCREMENT (3037000493uLL) #define MAX_RAND_63 (0x7fffffffffffffffuLL) static uint64 X; void resetRandGen() { X = SEED; } // returns integer [0, 2^63 - 1] uint64 nextUnsignedRand() { // (mod 2^64) X = MULTIPLIER*X + INCREMENT; return (uint64)(X & MAX_RAND_63); } // returns integer [-(2^62), 2^62 - 1] int64 nextSignedRandInt() { uint64 uDisplace = (uint64)1 << 62; return (int64)nextUnsignedRand() - (int64)uDisplace; } // returns double [-(2^26), 2^26 - 2^(-26)] double nextSignedRandFlPt() { // 52 bit signed number uint64 uVal = (nextUnsignedRand() >> 11) & 0x1fffffffffffff; int64 sVal = (int64)uVal - 0x10000000000000; return ldexp((double)sVal, -26); } // returns integer [0, 2^32 - 1] uint32 nextRand32() { return (uint32)(nextUnsignedRand() >> 31); } zfp-1.0.1/tests/utils/rand64.h000066400000000000000000000005761453723256400161040ustar00rootroot00000000000000#ifndef RAND_64_H #define RAND_64_H #include "include/zfp/internal/zfp/types.h" // reset seed void resetRandGen(); // returns integer [0, 2^63 - 1] uint64 nextUnsignedRand(); // returns integer [-(2^62), 2^62 - 1] int64 nextSignedRandInt(); // returns double [-(2^26), 2^26 - 2^(-26)] double nextSignedRandFlPt(); // returns integer [0, 2^32 - 1] uint32 nextRand32(); #endif zfp-1.0.1/tests/utils/stridedOperations.c000066400000000000000000000070711453723256400205000ustar00rootroot00000000000000#include #include "stridedOperations.h" // reversed array ([inputArrLen - 1], [inputArrLen - 2], ..., [1], [0]) void reverseArray(void* inputArr, void* outputArr, size_t inputArrLen, zfp_type zfpType) { const size_t elementSizeBytes = zfp_type_size(zfpType); // move ptr to last element inputArr = (char *)inputArr + elementSizeBytes * (inputArrLen - 1); size_t i; for (i = 0; i < inputArrLen; i++) { memcpy(outputArr, inputArr, elementSizeBytes); outputArr = (char *)outputArr + elementSizeBytes; inputArr = (char *)inputArr - elementSizeBytes; } } // interleaved array ([0], [0], [1], [1], [2], ...) void interleaveArray(void* inputArr, void* outputArr, size_t inputArrLen, zfp_type zfpType) { const size_t elementSizeBytes = zfp_type_size(zfpType); size_t i; for (i = 0; i < inputArrLen; i++) { memcpy(outputArr, inputArr, elementSizeBytes); memcpy((char *)outputArr + elementSizeBytes, inputArr, elementSizeBytes); inputArr = (char *)inputArr + elementSizeBytes; outputArr = (char *)outputArr + 2 * elementSizeBytes; } } int permuteSquareArray(void* inputArr, void* outputArr, size_t sideLen, int dims, zfp_type zfpType) { const size_t elementSizeBytes = zfp_type_size(zfpType); size_t i, j, k, l; switch(dims) { case 4: // permute ijkl lkji for (l = 0; l < sideLen; l++) { for (k = 0; k < sideLen; k++) { for (j = 0; j < sideLen; j++) { for (i = 0; i < sideLen; i++) { size_t index = l*sideLen*sideLen*sideLen + k*sideLen*sideLen + j*sideLen + i; size_t transposedIndex = i*sideLen*sideLen*sideLen + j*sideLen*sideLen + k*sideLen + l; memcpy((char *)outputArr + elementSizeBytes * index, (char *)inputArr + elementSizeBytes * transposedIndex, elementSizeBytes); } } } } break; case 3: // permute ijk to kji for (k = 0; k < sideLen; k++) { for (j = 0; j < sideLen; j++) { for (i = 0; i < sideLen; i++) { size_t index = k*sideLen*sideLen + j*sideLen + i; size_t transposedIndex = i*sideLen*sideLen + j*sideLen + k; memcpy((char *)outputArr + elementSizeBytes * index, (char *)inputArr + elementSizeBytes * transposedIndex, elementSizeBytes); } } } break; case 2: // permute ij to ji for (j = 0; j < sideLen; j++) { for (i = 0; i < sideLen; i++) { size_t index = j*sideLen + i; size_t transposedIndex = i*sideLen + j; memcpy((char *)outputArr + elementSizeBytes * index, (char *)inputArr + elementSizeBytes * transposedIndex, elementSizeBytes); } } break; // considered an error if requested to permute a 1 dimensional array case 1: default: return 1; } return 0; } static void completeStrides(int dims, size_t n[4], ptrdiff_t s[4]) { int i; for (i = 1; i < dims; i++) { s[i] = s[i-1] * (ptrdiff_t)n[i-1]; } } void getReversedStrides(int dims, size_t n[4], ptrdiff_t s[4]) { s[0] = -1; completeStrides(dims, n, s); } void getInterleavedStrides(int dims, size_t n[4], ptrdiff_t s[4]) { s[0] = 2; completeStrides(dims, n, s); } void getPermutedStrides(int dims, size_t n[4], ptrdiff_t s[4]) { if (dims == 4) { s[0] = (ptrdiff_t)(n[0] * n[1] * n[2]); s[1] = (ptrdiff_t)(n[0] * n[1]); s[2] = (ptrdiff_t)n[0]; s[3] = 1; } else if (dims == 3) { s[0] = (ptrdiff_t)(n[0] * n[1]); s[1] = (ptrdiff_t)n[0]; s[2] = 1; } else if (dims == 2) { s[0] = (ptrdiff_t)n[0]; s[1] = 1; } } zfp-1.0.1/tests/utils/stridedOperations.h000066400000000000000000000016361453723256400205060ustar00rootroot00000000000000#ifndef STRIDED_OPERATIONS_H #define STRIDED_OPERATIONS_H #include #include "zfp.h" typedef enum { AS_IS = 0, PERMUTED = 1, INTERLEAVED = 2, REVERSED = 3, } stride_config; // reversed array ([inputLen - 1], [inputLen - 2], ..., [1], [0]) void reverseArray(void* inputArr, void* outputArr, size_t inputArrLen, zfp_type zfpType); // interleaved array ([0], [0], [1], [1], [2], ...) void interleaveArray(void* inputArr, void* outputArr, size_t inputArrLen, zfp_type zfpType); // ijkl -> lkji, or for lower dims (ex. ij -> ji) // returns 0 on success, 1 on failure // (defined to fail if dims == 1) int permuteSquareArray(void* inputArr, void* outputArr, size_t sideLen, int dims, zfp_type zfpType); void getReversedStrides(int dims, size_t n[4], ptrdiff_t s[4]); void getInterleavedStrides(int dims, size_t n[4], ptrdiff_t s[4]); void getPermutedStrides(int dims, size_t n[4], ptrdiff_t s[4]); #endif zfp-1.0.1/tests/utils/testMacros.h000066400000000000000000000037021453723256400171240ustar00rootroot00000000000000// generate test function names containing macros #define _catFuncStr2(x, y) x ## y #define _catFunc2(x, y) _catFuncStr2(x, y) #define _catFuncStr3(x, y, z) x ## y ## z #define _catFunc3(x, y, z) _catFuncStr3(x, y, z) #define _cat_cmocka_unit_test(x) cmocka_unit_test(x) #define _cmocka_unit_test(x) _cat_cmocka_unit_test(x) #define _cat_cmocka_unit_test_setup_teardown(x, y, z) cmocka_unit_test_setup_teardown(x, y, z) #define _cmocka_unit_test_setup_teardown(x, y, z) _cat_cmocka_unit_test_setup_teardown(x, y, z) #ifdef PRINT_CHECKSUMS #include #include "zfpChecksums.h" // for both, x is freshly computed checksum from current compression-lib implementation // where-as y is the stored constant checksum // a triplet (key1, key2, value) is printed // key1: identifies what kind of compression occurred, on what input, etc // key2: identifies array dimensions // value: checksum // (macro substitutes "printf() && 0" because we want conditional to fail after executing printf) #define ASSERT_EQ_CHECKSUM(dims, zfpType, computedChecksum, key1, key2) printf("{UINT64C(0x%" PRIx64 "), UINT64C(0x%" PRIx64 "), UINT64C(0x%" PRIx64 ")},\n", key1, key2, computedChecksum) #define COMPARE_NEQ_CHECKSUM(dims, zfpType, computedChecksum, key1, key2) printf("{UINT64C(0x%" PRIx64 "), UINT64C(0x%" PRIx64 "), UINT64C(0x%" PRIx64 ")},\n", key1, key2, computedChecksum) && 0 #else #define ASSERT_EQ_CHECKSUM(dims, zfpType, computedChecksum, key1, key2) assert_int_equal(computedChecksum, getChecksumByKey(dims, zfpType, key1, key2)) #define COMPARE_NEQ_CHECKSUM(dims, zfpType, computedChecksum, key1, key2) (computedChecksum != getChecksumByKey(dims, zfpType, key1, key2)) #endif // for condensing repeat tests across different dimensionalities into singular tests #define _repeat_arg(x, n) _repeatN(x, n) #define _repeatN(x, n) _repeat ## n ( x ) #define _repeat1(x) x #define _repeat2(x) x, x #define _repeat3(x) x, x, x #define _repeat4(x) x, x, x, x zfp-1.0.1/tests/utils/zfpChecksums.c000066400000000000000000000076231453723256400174460ustar00rootroot00000000000000#include "zfp/internal/zfp/types.h" #include "zfpChecksums.h" #define NUM_INT_CHECKSUMS 19 #define NUM_FL_PT_CHECKSUMS 35 #define FAILED_CHECKSUM (UINT64C(0xffffffffffffffff)) #ifndef PRINT_CHECKSUMS // raw checksums as static arrays #include "constants/checksums/1dDouble.h" #include "constants/checksums/1dFloat.h" #include "constants/checksums/1dInt32.h" #include "constants/checksums/1dInt64.h" #include "constants/checksums/2dDouble.h" #include "constants/checksums/2dFloat.h" #include "constants/checksums/2dInt32.h" #include "constants/checksums/2dInt64.h" #include "constants/checksums/3dDouble.h" #include "constants/checksums/3dFloat.h" #include "constants/checksums/3dInt32.h" #include "constants/checksums/3dInt64.h" #include "constants/checksums/4dDouble.h" #include "constants/checksums/4dFloat.h" #include "constants/checksums/4dInt32.h" #include "constants/checksums/4dInt64.h" // [dimensionality][zfp_type] static const checksum_tuples* checksums[4][4] = { { _1dInt32Checksums, _1dInt64Checksums, _1dFloatChecksums, _1dDoubleChecksums, }, { _2dInt32Checksums, _2dInt64Checksums, _2dFloatChecksums, _2dDoubleChecksums, }, { _3dInt32Checksums, _3dInt64Checksums, _3dFloatChecksums, _3dDoubleChecksums, }, { _4dInt32Checksums, _4dInt64Checksums, _4dFloatChecksums, _4dDoubleChecksums, }, }; static const checksum_tuples* getChecksumPtr(int dims, zfp_type type) { return checksums[dims - 1][type - zfp_type_int32]; } #endif void computeKeyOriginalInput(test_type tt, size_t n[4], uint64* key1, uint64* key2) { computeKey(tt, ORIGINAL_INPUT, n, zfp_mode_null, 0, key1, key2); } void computeKey(test_type tt, subject sjt, size_t n[4], zfp_mode mode, int miscParam, uint64* key1, uint64* key2) { uint64 result = 0; // block-level test (low-level api: full/partial block) vs calling zfp_compress/decompress(), 2 bits result += (uint64)tt; // subject is 2 bits (3 possible values) // when subject is ORIGINAL_ARRAY, no compression applied, zeroes passed in for mode, miscParam result <<= 2; result += (uint64)sjt; // mode is 3 bits // passing zfp_mode_null implies no compression applied result <<= 3; result += mode; // miscParam is either specialValueIndex (for block tests), or compressParamNum (for endtoend tests) // reserve 4 bits // specialValueIndex is in [0, 9] inclusive (testing 10 different special values) // compressParamNum is in [0, 2] inclusive (testing 3 compression parameters, per fixed-* mode) result <<= 4; result += miscParam; *key1 = result; // key2 stores dimensions only (64 bits total, like zfp_field_metadata() result = 0; uint dims = n[1] ? n[2] ? n[3] ? 4 : 3 : 2 : 1; switch (dims) { case 1: result += n[0] - 1; break; case 2: result += n[0] - 1; result <<= 24; result += n[1] - 1; break; case 3: result += n[0] - 1; result <<= 16; result += n[1] - 1; result <<= 16; result += n[2] - 1; break; case 4: result += n[0] - 1; result <<= 12; result += n[1] - 1; result <<= 12; result += n[2] - 1; result <<= 12; result += n[3] - 1; break; } *key2 = result; } uint64 getChecksumByKey(int dims, zfp_type type, uint64 key1, uint64 key2) { #ifndef PRINT_CHECKSUMS const checksum_tuples* keyChecksumsArr = getChecksumPtr(dims, type); size_t arrLen; switch (type) { case zfp_type_int32: case zfp_type_int64: arrLen = NUM_INT_CHECKSUMS; break; case zfp_type_float: case zfp_type_double: arrLen = NUM_FL_PT_CHECKSUMS; break; default: return FAILED_CHECKSUM; } size_t i; for (i = 0; i < arrLen; i++) { if (keyChecksumsArr[i].key1 == key1 && keyChecksumsArr[i].key2 == key2) { return keyChecksumsArr[i].checksum; } } return FAILED_CHECKSUM; #else return FAILED_CHECKSUM; #endif } zfp-1.0.1/tests/utils/zfpChecksums.h000066400000000000000000000013011453723256400174360ustar00rootroot00000000000000#ifndef ZFP_CHECKSUMS_H #define ZFP_CHECKSUMS_H #include "zfp.h" typedef enum { BLOCK_FULL_TEST = 0, BLOCK_PARTIAL_TEST = 1, ARRAY_TEST = 2, } test_type; typedef enum { ORIGINAL_INPUT = 0, COMPRESSED_BITSTREAM = 1, DECOMPRESSED_ARRAY = 2, } subject; // key1 holds data about test type // key2 holds dimension lengths typedef struct { uint64 key1; uint64 key2; uint64 checksum; } checksum_tuples; void computeKeyOriginalInput(test_type tt, size_t n[4], uint64* key1, uint64* key2); void computeKey(test_type tt, subject sjt, size_t n[4], zfp_mode mode, int miscParam, uint64* key1, uint64* key2); uint64 getChecksumByKey(int dims, zfp_type type, uint64 key1, uint64 key2); #endif zfp-1.0.1/tests/utils/zfpCompressionParams.c000066400000000000000000000004561453723256400211630ustar00rootroot00000000000000#include #include "utils/zfpCompressionParams.h" int computeFixedPrecisionParam(int param) { return 1u << (param + 3); } size_t computeFixedRateParam(int param) { return (size_t)(1u << (param + 3)); } double computeFixedAccuracyParam(int param) { return ldexp(1.0, -(1u << param)); } zfp-1.0.1/tests/utils/zfpCompressionParams.h000066400000000000000000000003431453723256400211630ustar00rootroot00000000000000#ifndef ZFP_COMPRESSION_PARAMS_H #define ZFP_COMPRESSION_PARAMS_H #include int computeFixedPrecisionParam(int param); size_t computeFixedRateParam(int param); double computeFixedAccuracyParam(int param); #endif zfp-1.0.1/tests/utils/zfpHash.c000066400000000000000000000051161453723256400163770ustar00rootroot00000000000000#include "zfpHash.h" #define MASK_32 (0xffffffff) // Jenkins one-at-a-time hash; see http://www.burtleburtle.net/bob/hash/doobs.html static void hashValue(uint32 val, uint32* h) { *h += val; *h += *h << 10; *h ^= *h >> 6; } static uint32 hashFinish(uint32 h) { h += h << 3; h ^= h >> 11; h += h << 15; return h; } static void hashValue64(uint64 val, uint32* h1, uint32* h2) { uint32 val1 = (uint32)(val & MASK_32); hashValue(val1, h1); uint32 val2 = (uint32)((val >> 32) & MASK_32); hashValue(val2, h2); } uint64 hashBitstream(uint64* ptrStart, size_t bufsizeBytes) { size_t nx = bufsizeBytes / sizeof(uint64); uint32 h1 = 0; uint32 h2 = 0; for (; nx--; ptrStart++) { hashValue64(*ptrStart, &h1, &h2); } uint64 result1 = (uint64)hashFinish(h1); uint64 result2 = (uint64)hashFinish(h2); return result1 + (result2 << 32); } // hash 32-bit valued arrays (int32, float) uint32 hashArray32(const uint32* arr, size_t nx, ptrdiff_t sx) { uint32 h = 0; for (; nx--; arr += sx) { hashValue(*arr, &h); } return hashFinish(h); } // unused n[] entries are 0 uint32 hashStridedArray32(const uint32* arr, size_t n[4], ptrdiff_t s[4]) { uint32 h = 0; size_t i, j, k, l; for (l = 0; l < (n[3] ? n[3] : 1); arr += (s[3] - (ptrdiff_t)n[2]*s[2]), l++) { for (k = 0; k < (n[2] ? n[2] : 1); arr += (s[2] - (ptrdiff_t)n[1]*s[1]), k++) { for (j = 0; j < (n[1] ? n[1] : 1); arr += (s[1] - (ptrdiff_t)n[0]*s[0]), j++) { for (i = 0; i < (n[0] ? n[0] : 1); arr += s[0], i++) { hashValue(*arr, &h); } } } } return hashFinish(h); } // hash 64-bit valued arrays (int64, double) uint64 hashArray64(const uint64* arr, size_t nx, ptrdiff_t sx) { uint32 h1 = 0; uint32 h2 = 0; for (; nx--; arr += sx) { hashValue64(*arr, &h1, &h2); } uint64 result1 = (uint64)hashFinish(h1); uint64 result2 = (uint64)hashFinish(h2); return result1 + (result2 << 32); } // unused n[] entries are 0 uint64 hashStridedArray64(const uint64* arr, size_t n[4], ptrdiff_t s[4]) { uint32 h1 = 0; uint32 h2 = 0; size_t i, j, k, l; for (l = 0; l < (n[3] ? n[3] : 1); arr += (s[3] - (ptrdiff_t)n[2]*s[2]), l++) { for (k = 0; k < (n[2] ? n[2] : 1); arr += (s[2] - (ptrdiff_t)n[1]*s[1]), k++) { for (j = 0; j < (n[1] ? n[1] : 1); arr += (s[1] - (ptrdiff_t)n[0]*s[0]), j++) { for (i = 0; i < (n[0] ? n[0] : 1); arr += s[0], i++) { hashValue64(*arr, &h1, &h2); } } } } uint64 result1 = (uint64)hashFinish(h1); uint64 result2 = (uint64)hashFinish(h2); return result1 + (result2 << 32); } zfp-1.0.1/tests/utils/zfpHash.h000066400000000000000000000010421453723256400163760ustar00rootroot00000000000000#ifndef ZFP_HASH_H #define ZFP_HASH_H #include #include "include/zfp/internal/zfp/types.h" uint64 hashBitstream(uint64* ptrStart, size_t bufsizeBytes); // hash 32-bit valued arrays (int32, float) uint32 hashArray32(const uint32* arr, size_t nx, ptrdiff_t sx); uint32 hashStridedArray32(const uint32* arr, size_t n[4], ptrdiff_t s[4]); // hash 64-bit valued arrays (int64, double) uint64 hashArray64(const uint64* arr, size_t nx, ptrdiff_t sx); uint64 hashStridedArray64(const uint64* arr, size_t n[4], ptrdiff_t s[4]); #endif zfp-1.0.1/tests/utils/zfpTimer.c000066400000000000000000000020351453723256400165710ustar00rootroot00000000000000#include "zfpTimer.h" #include struct zfp_timer { #if defined(__unix__) || defined(_WIN32) clock_t timeStart, timeEnd; #elif defined(__MACH__) uint64_t timeStart, timeEnd; #endif }; zfp_timer* zfp_timer_alloc() { return malloc(sizeof(zfp_timer)); } void zfp_timer_free(zfp_timer* timer) { free(timer); } int zfp_timer_start(zfp_timer* timer) { #if defined(__unix__) || defined(_WIN32) timer->timeStart = clock(); #elif defined(__MACH__) timer->timeStart = mach_absolute_time(); #else return 1; #endif return 0; } double zfp_timer_stop(zfp_timer* timer) { double time; // stop timer, compute elapsed time #if defined(__unix__) || defined(_WIN32) timer->timeEnd = clock(); time = (double)((timer->timeEnd) - (timer->timeStart)) / CLOCKS_PER_SEC; #elif defined(__MACH__) timer->timeEnd = mach_absolute_time(); mach_timebase_info_data_t tb = {0}; mach_timebase_info(&tb); double timebase = tb.numer / tb.denom; time = ((timer->timeEnd) - (timer->timeStart)) * timebase * (1E-9); #endif return time; } zfp-1.0.1/tests/utils/zfpTimer.h000066400000000000000000000005511453723256400165770ustar00rootroot00000000000000#ifndef ZFP_TIMER_H #define ZFP_TIMER_H #if defined(__unix__) || defined(_WIN32) #include #elif defined(__MACH__) #include #endif typedef struct zfp_timer zfp_timer; zfp_timer* zfp_timer_alloc(); void zfp_timer_free(zfp_timer* timer); int zfp_timer_start(zfp_timer* timer); double zfp_timer_stop(zfp_timer* timer); #endif zfp-1.0.1/utils/000077500000000000000000000000001453723256400134635ustar00rootroot00000000000000zfp-1.0.1/utils/CMakeLists.txt000066400000000000000000000007651453723256400162330ustar00rootroot00000000000000add_executable(zfpcmd zfp.c) # protect against LNK1114: cannot overwrite the original file 'lib/Release/zfp.lib'; error code 32; # rationale: linker can't handle the case of an executable file having the same name as a library file if(NOT MSVC) set_property(TARGET zfpcmd PROPERTY OUTPUT_NAME zfp) endif() target_link_libraries(zfpcmd zfp) if(HAVE_LIBM_MATH) target_link_libraries(zfpcmd m) endif() if(BUILD_UTILITIES) install(TARGETS zfpcmd DESTINATION "${CMAKE_INSTALL_BINDIR}") endif() zfp-1.0.1/utils/Makefile000066400000000000000000000003721453723256400151250ustar00rootroot00000000000000include ../Config TARGET = ../bin/zfp INCS = -I../include LIBS = -L../lib -lzfp $(LDFLAGS) -lm all: $(TARGET) $(TARGET): zfp.c ../lib/$(LIBZFP) mkdir -p ../bin $(CC) $(CFLAGS) $(INCS) zfp.c $(LIBS) -o $(TARGET) clean: rm -f $(TARGET) fields.o zfp-1.0.1/utils/zfp.c000066400000000000000000000467431453723256400144440ustar00rootroot00000000000000#include #include #include #include #include #include #include "zfp.h" #include "zfp/internal/zfp/macros.h" /* File I/O is done using the following combinations of i, o, s, and z: - i : read uncompressed - z : read compressed - i, s: read uncompressed, print stats - i, o: read and write uncompressed - i, z: read uncompressed, write compressed - z, o: read compressed, write uncompressed The 7 major tasks to be accomplished are: - read uncompressed: i - read compressed: !i - compress: i - write compressed: i && z - decompress: o || s || (!i && z) - write uncompressed: o - compute stats: s */ /* compute and print reconstruction error */ static void print_error(const void* fin, const void* fout, zfp_type type, size_t n) { const int32* i32i = (const int32*)fin; const int64* i64i = (const int64*)fin; const float* f32i = (const float*)fin; const double* f64i = (const double*)fin; const int32* i32o = (const int32*)fout; const int64* i64o = (const int64*)fout; const float* f32o = (const float*)fout; const double* f64o = (const double*)fout; double fmin = +DBL_MAX; double fmax = -DBL_MAX; double erms = 0; double ermsn = 0; double emax = 0; double psnr = 0; size_t i; for (i = 0; i < n; i++) { double d, val; switch (type) { case zfp_type_int32: d = fabs((double)(i32i[i] - i32o[i])); val = (double)i32i[i]; break; case zfp_type_int64: d = fabs((double)(i64i[i] - i64o[i])); val = (double)i64i[i]; break; case zfp_type_float: d = fabs((double)(f32i[i] - f32o[i])); val = (double)f32i[i]; break; case zfp_type_double: d = fabs(f64i[i] - f64o[i]); val = f64i[i]; break; default: return; } emax = MAX(emax, d); erms += d * d; fmin = MIN(fmin, val); fmax = MAX(fmax, val); } erms = sqrt(erms / n); ermsn = erms / (fmax - fmin); psnr = 20 * log10((fmax - fmin) / (2 * erms)); fprintf(stderr, " rmse=%.4g nrmse=%.4g maxe=%.4g psnr=%.2f", erms, ermsn, emax, psnr); } static void usage(void) { fprintf(stderr, "%s\n", zfp_version_string); fprintf(stderr, "Usage: zfp \n"); fprintf(stderr, "General options:\n"); fprintf(stderr, " -h : read/write array and compression parameters from/to compressed header\n"); fprintf(stderr, " -q : quiet mode; suppress output\n"); fprintf(stderr, " -s : print error statistics\n"); fprintf(stderr, "Input and output:\n"); fprintf(stderr, " -i : uncompressed binary input file (\"-\" for stdin)\n"); fprintf(stderr, " -o : decompressed binary output file (\"-\" for stdout)\n"); fprintf(stderr, " -z : compressed input (w/o -i) or output file (\"-\" for stdin/stdout)\n"); fprintf(stderr, "Array type and dimensions (needed with -i):\n"); fprintf(stderr, " -f : single precision (float type)\n"); fprintf(stderr, " -d : double precision (double type)\n"); fprintf(stderr, " -t : integer or floating scalar type\n"); fprintf(stderr, " -1 : dimensions for 1D array a[nx]\n"); fprintf(stderr, " -2 : dimensions for 2D array a[ny][nx]\n"); fprintf(stderr, " -3 : dimensions for 3D array a[nz][ny][nx]\n"); fprintf(stderr, " -4 : dimensions for 4D array a[nw][nz][ny][nx]\n"); fprintf(stderr, "Compression parameters (needed with -i):\n"); fprintf(stderr, " -R : reversible (lossless) compression\n"); fprintf(stderr, " -r : fixed rate (# compressed bits per floating-point value)\n"); fprintf(stderr, " -p : fixed precision (# uncompressed bits per value)\n"); fprintf(stderr, " -a : fixed accuracy (absolute error tolerance)\n"); fprintf(stderr, " -c : advanced usage\n"); fprintf(stderr, " minbits : min # bits per 4^d values in d dimensions\n"); fprintf(stderr, " maxbits : max # bits per 4^d values in d dimensions (0 for unlimited)\n"); fprintf(stderr, " maxprec : max # bits of precision per value (0 for full)\n"); fprintf(stderr, " minexp : min bit plane # coded (-1074 for all bit planes)\n"); fprintf(stderr, "Execution parameters:\n"); fprintf(stderr, " -x serial : serial compression (default)\n"); fprintf(stderr, " -x omp[=threads[,chunk_size]] : OpenMP parallel compression\n"); fprintf(stderr, " -x cuda : CUDA fixed rate parallel compression/decompression\n"); fprintf(stderr, "Examples:\n"); fprintf(stderr, " -i file : read uncompressed file and compress to memory\n"); fprintf(stderr, " -z file : read compressed file and decompress to memory\n"); fprintf(stderr, " -i ifile -z zfile : read uncompressed ifile, write compressed zfile\n"); fprintf(stderr, " -z zfile -o ofile : read compressed zfile, write decompressed ofile\n"); fprintf(stderr, " -i ifile -o ofile : read ifile, compress, decompress, write ofile\n"); fprintf(stderr, " -i file -s : read uncompressed file, compress to memory, print stats\n"); fprintf(stderr, " -i - -o - -s : read stdin, compress, decompress, write stdout, print stats\n"); fprintf(stderr, " -f -3 100 100 100 -r 16 : 2x fixed-rate compression of 100x100x100 floats\n"); fprintf(stderr, " -d -1 1000000 -r 32 : 2x fixed-rate compression of 1M doubles\n"); fprintf(stderr, " -d -2 1000 1000 -p 32 : 32-bit precision compression of 1000x1000 doubles\n"); fprintf(stderr, " -d -1 1000000 -a 1e-9 : compression of 1M doubles with < 1e-9 max error\n"); fprintf(stderr, " -d -1 1000000 -c 64 64 0 -1074 : 4x fixed-rate compression of 1M doubles\n"); fprintf(stderr, " -x omp=16,256 : parallel compression with 16 threads, 256-block chunks\n"); exit(EXIT_FAILURE); } int main(int argc, char* argv[]) { /* default settings */ zfp_type type = zfp_type_none; size_t typesize = 0; uint dims = 0; size_t nx = 0; size_t ny = 0; size_t nz = 0; size_t nw = 0; size_t count = 0; double rate = 0; uint precision = 0; double tolerance = 0; uint minbits = ZFP_MIN_BITS; uint maxbits = ZFP_MAX_BITS; uint maxprec = ZFP_MAX_PREC; int minexp = ZFP_MIN_EXP; zfp_bool header = zfp_false; zfp_bool quiet = zfp_false; zfp_bool stats = zfp_false; char* inpath = 0; char* zfppath = 0; char* outpath = 0; char mode = 0; zfp_exec_policy exec = zfp_exec_serial; uint threads = 0; uint chunk_size = 0; /* local variables */ int i; zfp_field* field = NULL; zfp_stream* zfp = NULL; bitstream* stream = NULL; void* fi = NULL; void* fo = NULL; void* buffer = NULL; size_t rawsize = 0; size_t zfpsize = 0; size_t bufsize = 0; if (argc == 1) usage(); /* parse command-line arguments */ for (i = 1; i < argc; i++) { if (argv[i][0] != '-' || argv[i][2]) usage(); switch (argv[i][1]) { case '1': if (++i == argc || sscanf(argv[i], "%zu", &nx) != 1) usage(); ny = nz = nw = 1; dims = 1; break; case '2': if (++i == argc || sscanf(argv[i], "%zu", &nx) != 1 || ++i == argc || sscanf(argv[i], "%zu", &ny) != 1) usage(); nz = nw = 1; dims = 2; break; case '3': if (++i == argc || sscanf(argv[i], "%zu", &nx) != 1 || ++i == argc || sscanf(argv[i], "%zu", &ny) != 1 || ++i == argc || sscanf(argv[i], "%zu", &nz) != 1) usage(); nw = 1; dims = 3; break; case '4': if (++i == argc || sscanf(argv[i], "%zu", &nx) != 1 || ++i == argc || sscanf(argv[i], "%zu", &ny) != 1 || ++i == argc || sscanf(argv[i], "%zu", &nz) != 1 || ++i == argc || sscanf(argv[i], "%zu", &nw) != 1) usage(); dims = 4; break; case 'a': if (++i == argc || sscanf(argv[i], "%lf", &tolerance) != 1) usage(); mode = 'a'; break; case 'c': if (++i == argc || sscanf(argv[i], "%u", &minbits) != 1 || ++i == argc || sscanf(argv[i], "%u", &maxbits) != 1 || ++i == argc || sscanf(argv[i], "%u", &maxprec) != 1 || ++i == argc || sscanf(argv[i], "%d", &minexp) != 1) usage(); mode = 'c'; break; case 'd': type = zfp_type_double; break; case 'f': type = zfp_type_float; break; case 'h': header = zfp_true; break; case 'i': if (++i == argc) usage(); inpath = argv[i]; break; case 'o': if (++i == argc) usage(); outpath = argv[i]; break; case 'p': if (++i == argc || sscanf(argv[i], "%u", &precision) != 1) usage(); mode = 'p'; break; case 'q': quiet = zfp_true; break; case 'r': if (++i == argc || sscanf(argv[i], "%lf", &rate) != 1) usage(); mode = 'r'; break; case 'R': mode = 'R'; break; case 's': stats = zfp_true; break; case 't': if (++i == argc) usage(); if (!strcmp(argv[i], "i32")) type = zfp_type_int32; else if (!strcmp(argv[i], "i64")) type = zfp_type_int64; else if (!strcmp(argv[i], "f32")) type = zfp_type_float; else if (!strcmp(argv[i], "f64")) type = zfp_type_double; else usage(); break; case 'x': if (++i == argc) usage(); if (!strcmp(argv[i], "serial")) exec = zfp_exec_serial; else if (sscanf(argv[i], "omp=%u,%u", &threads, &chunk_size) == 2) exec = zfp_exec_omp; else if (sscanf(argv[i], "omp=%u", &threads) == 1) { exec = zfp_exec_omp; chunk_size = 0; } else if (!strcmp(argv[i], "omp")) { exec = zfp_exec_omp; threads = 0; chunk_size = 0; } else if (!strcmp(argv[i], "cuda")) exec = zfp_exec_cuda; else usage(); break; case 'z': if (++i == argc) usage(); zfppath = argv[i]; break; default: usage(); break; } } typesize = zfp_type_size(type); count = nx * ny * nz * nw; /* make sure one of the array dimensions is not zero */ if (!count && dims) { fprintf(stderr, "array size must be nonzero\n"); return EXIT_FAILURE; } /* make sure we have an input file */ if (!inpath && !zfppath) { fprintf(stderr, "must specify uncompressed or compressed input file via -i or -z\n"); return EXIT_FAILURE; } /* make sure we (will) know scalar type */ if (!typesize) { if (inpath) { fprintf(stderr, "must specify scalar type via -f, -d, or -t to compress\n"); return EXIT_FAILURE; } else if (!header) { fprintf(stderr, "must specify scalar type via -f, -d, or -t or header via -h to decompress\n"); return EXIT_FAILURE; } } /* make sure we (will) know array dimensions */ if (!dims) { if (inpath) { fprintf(stderr, "must specify array dimensions via -1, -2, -3, or -4 to compress\n"); return EXIT_FAILURE; } else if (!header) { fprintf(stderr, "must specify array dimensions via -1, -2, -3, or -4 or header via -h to decompress\n"); return EXIT_FAILURE; } } /* make sure we (will) know (de)compression mode and parameters */ if (!mode) { if (inpath) { fprintf(stderr, "must specify compression parameters via -a, -c, -p, or -r to compress\n"); return EXIT_FAILURE; } else if (!header) { fprintf(stderr, "must specify compression parameters via -a, -c, -p, or -r or header via -h to decompress\n"); return EXIT_FAILURE; } } /* make sure we have input file for stats */ if (stats && !inpath) { fprintf(stderr, "must specify input file via -i to compute stats\n"); return EXIT_FAILURE; } /* make sure meta data comes from header or command line, not both */ if (!inpath && zfppath && header && (typesize || dims)) { fprintf(stderr, "cannot specify both field type/size and header\n"); return EXIT_FAILURE; } zfp = zfp_stream_open(NULL); field = zfp_field_alloc(); /* read uncompressed or compressed file */ if (inpath) { /* read uncompressed input file */ FILE* file = !strcmp(inpath, "-") ? stdin : fopen(inpath, "rb"); if (!file) { fprintf(stderr, "cannot open input file\n"); return EXIT_FAILURE; } rawsize = typesize * count; fi = malloc(rawsize); if (!fi) { fprintf(stderr, "cannot allocate memory\n"); return EXIT_FAILURE; } if (fread(fi, typesize, count, file) != count) { fprintf(stderr, "cannot read input file\n"); return EXIT_FAILURE; } fclose(file); zfp_field_set_pointer(field, fi); } else { /* read compressed input file in increasingly large chunks */ FILE* file = !strcmp(zfppath, "-") ? stdin : fopen(zfppath, "rb"); if (!file) { fprintf(stderr, "cannot open compressed file\n"); return EXIT_FAILURE; } bufsize = 0x100; do { bufsize *= 2; buffer = realloc(buffer, bufsize); if (!buffer) { fprintf(stderr, "cannot allocate memory\n"); return EXIT_FAILURE; } zfpsize += fread((uchar*)buffer + zfpsize, 1, bufsize - zfpsize, file); } while (zfpsize == bufsize); if (ferror(file)) { fprintf(stderr, "cannot read compressed file\n"); return EXIT_FAILURE; } fclose(file); /* associate bit stream with buffer */ stream = stream_open(buffer, bufsize); if (!stream) { fprintf(stderr, "cannot open compressed stream\n"); return EXIT_FAILURE; } zfp_stream_set_bit_stream(zfp, stream); } /* set field dimensions and (de)compression parameters */ if (inpath || !header) { /* initialize uncompressed field */ zfp_field_set_type(field, type); switch (dims) { case 1: zfp_field_set_size_1d(field, nx); break; case 2: zfp_field_set_size_2d(field, nx, ny); break; case 3: zfp_field_set_size_3d(field, nx, ny, nz); break; case 4: zfp_field_set_size_4d(field, nx, ny, nz, nw); break; } /* set (de)compression mode */ switch (mode) { case 'R': zfp_stream_set_reversible(zfp); break; case 'a': zfp_stream_set_accuracy(zfp, tolerance); break; case 'p': zfp_stream_set_precision(zfp, precision); break; case 'r': zfp_stream_set_rate(zfp, rate, type, dims, zfp_false); break; case 'c': if (!maxbits) maxbits = ZFP_MAX_BITS; if (!maxprec) maxprec = zfp_field_precision(field); if (!zfp_stream_set_params(zfp, minbits, maxbits, maxprec, minexp)) { fprintf(stderr, "invalid compression parameters\n"); return EXIT_FAILURE; } break; } } /* specify execution policy */ switch (exec) { case zfp_exec_cuda: if (!zfp_stream_set_execution(zfp, exec)) { fprintf(stderr, "cuda execution not available\n"); return EXIT_FAILURE; } break; case zfp_exec_omp: if (!zfp_stream_set_execution(zfp, exec) || !zfp_stream_set_omp_threads(zfp, threads) || !zfp_stream_set_omp_chunk_size(zfp, chunk_size)) { fprintf(stderr, "OpenMP execution not available\n"); return EXIT_FAILURE; } break; case zfp_exec_serial: default: if (!zfp_stream_set_execution(zfp, exec)) { fprintf(stderr, "serial execution not available\n"); return EXIT_FAILURE; } break; } /* compress input file if provided */ if (inpath) { /* allocate buffer for compressed data */ bufsize = zfp_stream_maximum_size(zfp, field); if (!bufsize) { fprintf(stderr, "invalid compression parameters\n"); return EXIT_FAILURE; } buffer = malloc(bufsize); if (!buffer) { fprintf(stderr, "cannot allocate memory\n"); return EXIT_FAILURE; } /* associate compressed bit stream with memory buffer */ stream = stream_open(buffer, bufsize); if (!stream) { fprintf(stderr, "cannot open compressed stream\n"); return EXIT_FAILURE; } zfp_stream_set_bit_stream(zfp, stream); /* optionally write header */ if (header && !zfp_write_header(zfp, field, ZFP_HEADER_FULL)) { fprintf(stderr, "cannot write header\n"); return EXIT_FAILURE; } /* compress data */ zfpsize = zfp_compress(zfp, field); if (zfpsize == 0) { fprintf(stderr, "compression failed\n"); return EXIT_FAILURE; } /* optionally write compressed data */ if (zfppath) { FILE* file = !strcmp(zfppath, "-") ? stdout : fopen(zfppath, "wb"); if (!file) { fprintf(stderr, "cannot create compressed file\n"); return EXIT_FAILURE; } if (fwrite(buffer, 1, zfpsize, file) != zfpsize) { fprintf(stderr, "cannot write compressed file\n"); return EXIT_FAILURE; } fclose(file); } } /* decompress data if necessary */ if ((!inpath && zfppath) || outpath || stats) { /* obtain metadata from header when present */ zfp_stream_rewind(zfp); if (header) { if (!zfp_read_header(zfp, field, ZFP_HEADER_FULL)) { fprintf(stderr, "incorrect or missing header\n"); return EXIT_FAILURE; } type = field->type; typesize = zfp_type_size(type); if (!typesize) { fprintf(stderr, "unsupported type\n"); return EXIT_FAILURE; } nx = MAX(field->nx, 1u); ny = MAX(field->ny, 1u); nz = MAX(field->nz, 1u); nw = MAX(field->nw, 1u); count = nx * ny * nz * nw; } /* allocate memory for decompressed data */ rawsize = typesize * count; fo = malloc(rawsize); if (!fo) { fprintf(stderr, "cannot allocate memory\n"); return EXIT_FAILURE; } zfp_field_set_pointer(field, fo); /* decompress data */ while (!zfp_decompress(zfp, field)) { /* fall back on serial decompression if execution policy not supported */ if (inpath && zfp_stream_execution(zfp) != zfp_exec_serial) { if (!zfp_stream_set_execution(zfp, zfp_exec_serial)) { fprintf(stderr, "cannot change execution policy\n"); return EXIT_FAILURE; } } else { fprintf(stderr, "decompression failed\n"); return EXIT_FAILURE; } } /* optionally write reconstructed data */ if (outpath) { FILE* file = !strcmp(outpath, "-") ? stdout : fopen(outpath, "wb"); if (!file) { fprintf(stderr, "cannot create output file\n"); return EXIT_FAILURE; } if (fwrite(fo, typesize, count, file) != count) { fprintf(stderr, "cannot write output file\n"); return EXIT_FAILURE; } fclose(file); } } /* print compression and error statistics */ if (!quiet) { const char* type_name[] = { "int32", "int64", "float", "double" }; fprintf(stderr, "type=%s nx=%zu ny=%zu nz=%zu nw=%zu", type_name[type - zfp_type_int32], nx, ny, nz, nw); fprintf(stderr, " raw=%lu zfp=%lu ratio=%.3g rate=%.4g", (unsigned long)rawsize, (unsigned long)zfpsize, (double)rawsize / zfpsize, CHAR_BIT * (double)zfpsize / count); if (stats) print_error(fi, fo, type, count); fprintf(stderr, "\n"); } /* free allocated storage */ zfp_field_free(field); zfp_stream_close(zfp); stream_close(stream); free(buffer); free(fi); free(fo); return EXIT_SUCCESS; } zfp-1.0.1/zfp-config-version.cmake.in000066400000000000000000000011341453723256400174560ustar00rootroot00000000000000set(PACKAGE_VERSION_MAJOR @ZFP_VERSION_MAJOR@) set(PACKAGE_VERSION_MINOR @ZFP_VERSION_MINOR@) set(PACKAGE_VERSION_PATCH @ZFP_VERSION_PATCH@) set(PACKAGE_VERSION_TWEAK @ZFP_VERSION_TWEAK@) set(PACKAGE_VERSION @ZFP_VERSION@) # Check whether the requested PACKAGE_FIND_VERSION is compatible if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION OR PACKAGE_VERSION_MAJOR GREATER PACKAGE_FIND_VERSION_MAJOR) set(PACKAGE_VERSION_COMPATIBLE FALSE) else() set(PACKAGE_VERSION_COMPATIBLE TRUE) if(PACKAGE_VERSION VERSION_EQUAL PACKAGE_FIND_VERSION) set(PACKAGE_VERSION_EXACT TRUE) endif() endif() zfp-1.0.1/zfp-config.cmake.in000066400000000000000000000030071453723256400157740ustar00rootroot00000000000000# - Config file for the zfp package # # It defines the following variables # ZFP_INCLUDE_DIRS - include directories for zfp # ZFP_LIBRARIES - libraries to link against # ZFP_WITH_OPENMP - indicates if the zfp library has been built with OpenMP support # ZFP_WITH_CUDA - indicates if the zfp library has been built with CUDA support # ZFP_CFP_ENABLED - indicated if the cfp library has been built # # And the following imported targets: # zfp::zfp # # If cfp is enabled the following variabled are also defined # CFP_INCLUDE_DIRS - include directories for cfp # CFP_LIBRARIES - libraries to link against (cfp only) # # As well as the following imported targets: # zfp::cfp include("${CMAKE_CURRENT_LIST_DIR}/zfp-config-version.cmake") include(FindPackageHandleStandardArgs) set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG "${CMAKE_CURRENT_LIST_FILE}") find_package_handle_standard_args(${CMAKE_FIND_PACKAGE_NAME} CONFIG_MODE) if(NOT TARGET zfp::zfp) include("${CMAKE_CURRENT_LIST_DIR}/zfp-targets.cmake") set(ZFP_LIBRARIES "zfp::zfp") get_target_property(ZFP_INCLUDE_DIRS zfp::zfp INTERFACE_INCLUDE_DIRECTORIES) endif() set(ZFP_CFP_ENABLED @BUILD_CFP@) if(ZFP_CFP_ENABLED AND NOT TARGET zfp::cfp) include("${CMAKE_CURRENT_LIST_DIR}/cfp-targets.cmake") set(CFP_LIBRARIES "zfp::cfp") get_target_property(CFP_INCLUDE_DIRS zfp::cfp INTERFACE_INCLUDE_DIRECTORIES) endif() set(ZFP_WITH_OPENMP @ZFP_WITH_OPENMP@) if(ZFP_WITH_OPENMP) find_package(OpenMP REQUIRED COMPONENTS C) endif() set(ZFP_WITH_CUDA @ZFP_WITH_CUDA@)