mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-02-03 15:18:38 +01:00
added tests and features to load full file
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "aare/FileInterface.hpp"
|
||||
#include "aare/NumpyHelpers.hpp"
|
||||
#include "aare/DType.hpp"
|
||||
#include "aare/defs.hpp"
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
@@ -45,6 +46,18 @@ class NumpyFile : public FileInterface {
|
||||
ssize_t cols() const override { return m_header.shape[2]; }
|
||||
ssize_t bitdepth() const override { return m_header.dtype.bitdepth(); }
|
||||
|
||||
DType dtype() const { return m_header.dtype; }
|
||||
std::vector<size_t> shape() const { return m_header.shape; }
|
||||
|
||||
//load the full numpy file into a NDArray
|
||||
template<typename T, size_t NDim>
|
||||
NDArray<T,NDim> load(){
|
||||
NDArray<T,NDim> arr(make_shape<NDim>(m_header.shape));
|
||||
fseek(fp, header_size, SEEK_SET);
|
||||
fread(arr.data(), sizeof(T), arr.size(), fp);
|
||||
return arr;
|
||||
}
|
||||
|
||||
~NumpyFile();
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "aare/DType.hpp"
|
||||
#include "aare/defs.hpp"
|
||||
|
||||
using shape_t = std::vector<uint64_t>;
|
||||
using shape_t = std::vector<size_t>;
|
||||
|
||||
struct header_t {
|
||||
header_t() : dtype(aare::DType(aare::DType::ERROR)), fortran_order(false), shape(shape_t()){};
|
||||
@@ -53,7 +53,7 @@ std::string get_value_from_map(const std::string &mapstr);
|
||||
|
||||
std::unordered_map<std::string, std::string> parse_dict(std::string in, const std::vector<std::string> &keys);
|
||||
|
||||
template <typename T, size_t N> inline bool in_array(T val, const std::array<T, N> &arr) {
|
||||
template <typename T, size_t N> bool in_array(T val, const std::array<T, N> &arr) {
|
||||
return std::find(std::begin(arr), std::end(arr), val) != std::end(arr);
|
||||
}
|
||||
bool is_digits(const std::string &str);
|
||||
|
||||
Reference in New Issue
Block a user