mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-07 13:10:42 +02:00
Merge pull request #52 from slsdetectorgroup/feature/formatting-in-cmake
add formatting as target in cmake
This commit is contained in:
commit
818ad608d9
6
.github/workflows/format.yml
vendored
6
.github/workflows/format.yml
vendored
@ -11,7 +11,11 @@ jobs:
|
|||||||
# find all examples in build/examples and run them
|
# find all examples in build/examples and run them
|
||||||
run: |
|
run: |
|
||||||
pwd
|
pwd
|
||||||
find -name "*.cpp" -not -path "./build/*" | xargs -I {} -n 1 -P 10 clang-format {} -Werror --dry-run -style='file:.clang-format'
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
cmake --build . --target=check-format
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -164,3 +164,22 @@ add_subdirectory(examples)
|
|||||||
if(AARE_PYTHON_BINDINGS)
|
if(AARE_PYTHON_BINDINGS)
|
||||||
add_subdirectory(python)
|
add_subdirectory(python)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
# custom target to run check formatting with clang-format
|
||||||
|
add_custom_target(
|
||||||
|
check-format
|
||||||
|
COMMAND find \( -name "*.cpp" -o -name "*.hpp" \) -not -path "./build/*" | xargs -I {} -n 1 -P 10 bash -c "clang-format -Werror -style=\"file:.clang-format\" {} | diff {} -"
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
COMMENT "Checking code formatting with clang-format"
|
||||||
|
VERBATIM
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_target(
|
||||||
|
format-files
|
||||||
|
COMMAND find \( -name "*.cpp" -o -name "*.hpp" \) -not -path "./build/*" | xargs -I {} -n 1 -P 10 bash -c "clang-format -i -style=\"file:.clang-format\" {}"
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
COMMENT "Formatting with clang-format"
|
||||||
|
VERBATIM
|
||||||
|
)
|
@ -17,8 +17,7 @@ template <class ItemType> class CircularFifo {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
CircularFifo() : CircularFifo(100){};
|
CircularFifo() : CircularFifo(100){};
|
||||||
CircularFifo(uint32_t size)
|
CircularFifo(uint32_t size) : fifo_size(size), free_slots(size + 1), filled_slots(size + 1) {
|
||||||
: fifo_size(size), free_slots(size+1), filled_slots(size+1) {
|
|
||||||
|
|
||||||
// TODO! how do we deal with alignment for writing? alignas???
|
// TODO! how do we deal with alignment for writing? alignas???
|
||||||
// Do we give the user a chance to provide memory locations?
|
// Do we give the user a chance to provide memory locations?
|
||||||
@ -36,7 +35,6 @@ template <class ItemType> class CircularFifo {
|
|||||||
if (!free_slots.write(std::move(it)))
|
if (!free_slots.write(std::move(it)))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~CircularFifo() {}
|
~CircularFifo() {}
|
||||||
@ -55,12 +53,9 @@ ItemType pop_free() {
|
|||||||
// return v;
|
// return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool try_pop_free(ItemType& v){
|
bool try_pop_free(ItemType &v) { return free_slots.read(v); }
|
||||||
return free_slots.read(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemType pop_value(std::chrono::nanoseconds wait,
|
ItemType pop_value(std::chrono::nanoseconds wait, std::atomic<bool> &stopped) {
|
||||||
std::atomic<bool> &stopped) {
|
|
||||||
ItemType v;
|
ItemType v;
|
||||||
while (!filled_slots.read(v) && !stopped) {
|
while (!filled_slots.read(v) && !stopped) {
|
||||||
std::this_thread::sleep_for(wait);
|
std::this_thread::sleep_for(wait);
|
||||||
@ -75,38 +70,28 @@ ItemType pop_value() {
|
|||||||
return std::move(v);
|
return std::move(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemType* frontPtr(){
|
ItemType *frontPtr() { return filled_slots.frontPtr(); }
|
||||||
return filled_slots.frontPtr();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO! Add function to move item from filled to free to be used
|
// TODO! Add function to move item from filled to free to be used
|
||||||
// with the frontPtr function
|
// with the frontPtr function
|
||||||
|
|
||||||
|
template <class... Args> void push_value(Args &&...recordArgs) {
|
||||||
template <class... Args>
|
|
||||||
void push_value(Args&&... recordArgs) {
|
|
||||||
while (!filled_slots.write(std::forward<Args>(recordArgs)...))
|
while (!filled_slots.write(std::forward<Args>(recordArgs)...))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args> bool try_push_value(Args &&...recordArgs) {
|
||||||
bool try_push_value(Args&&... recordArgs) {
|
|
||||||
return filled_slots.write(std::forward<Args>(recordArgs)...);
|
return filled_slots.write(std::forward<Args>(recordArgs)...);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args> void push_free(Args &&...recordArgs) {
|
||||||
void push_free(Args&&... recordArgs) {
|
|
||||||
while (!free_slots.write(std::forward<Args>(recordArgs)...))
|
while (!free_slots.write(std::forward<Args>(recordArgs)...))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args> bool try_push_free(Args &&...recordArgs) {
|
||||||
bool try_push_free(Args&&... recordArgs) {
|
|
||||||
return free_slots.write(std::forward<Args>(recordArgs)...);
|
return free_slots.write(std::forward<Args>(recordArgs)...);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aare
|
} // namespace aare
|
@ -4,7 +4,6 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -27,10 +26,8 @@ class Frame {
|
|||||||
Frame(std::byte *fp, ssize_t rows, ssize_t cols, ssize_t m_bitdepth);
|
Frame(std::byte *fp, ssize_t rows, ssize_t cols, ssize_t m_bitdepth);
|
||||||
std::byte *get(int row, int col);
|
std::byte *get(int row, int col);
|
||||||
|
|
||||||
|
|
||||||
// TODO! can we, or even want to remove the template?
|
// TODO! can we, or even want to remove the template?
|
||||||
template <typename T>
|
template <typename T> void set(int row, int col, T data) {
|
||||||
void set(int row, int col, T data) {
|
|
||||||
assert(sizeof(T) == m_bitdepth / 8);
|
assert(sizeof(T) == m_bitdepth / 8);
|
||||||
if (row < 0 || row >= m_rows || col < 0 || col >= m_cols) {
|
if (row < 0 || row >= m_rows || col < 0 || col >= m_cols) {
|
||||||
throw std::out_of_range("Invalid row or column index");
|
throw std::out_of_range("Invalid row or column index");
|
||||||
@ -62,20 +59,15 @@ class Frame {
|
|||||||
other.m_rows = other.m_cols = other.m_bitdepth = 0;
|
other.m_rows = other.m_cols = other.m_bitdepth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> NDView<T> view() {
|
||||||
NDView<T> view() {
|
|
||||||
std::vector<ssize_t> shape = {m_rows, m_cols};
|
std::vector<ssize_t> shape = {m_rows, m_cols};
|
||||||
T *data = reinterpret_cast<T *>(m_data);
|
T *data = reinterpret_cast<T *>(m_data);
|
||||||
return NDView<T>(data, shape);
|
return NDView<T>(data, shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> NDArray<T> image() { return NDArray<T>(this->view<T>()); }
|
||||||
NDArray<T> image() {
|
|
||||||
return NDArray<T>(this->view<T>());
|
|
||||||
}
|
|
||||||
|
|
||||||
~Frame() { delete[] m_data; }
|
~Frame() { delete[] m_data; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace aare
|
} // namespace aare
|
@ -22,19 +22,13 @@ namespace aare {
|
|||||||
|
|
||||||
template <typename T, ssize_t Ndim = 2> class NDArray {
|
template <typename T, ssize_t Ndim = 2> class NDArray {
|
||||||
public:
|
public:
|
||||||
NDArray()
|
NDArray() : shape_(), strides_(c_strides<Ndim>(shape_)), size_(0), data_(nullptr){};
|
||||||
: shape_(), strides_(c_strides<Ndim>(shape_)), size_(0),
|
|
||||||
data_(nullptr){};
|
|
||||||
|
|
||||||
explicit NDArray(std::array<ssize_t, Ndim> shape)
|
explicit NDArray(std::array<ssize_t, Ndim> shape)
|
||||||
: shape_(shape), strides_(c_strides<Ndim>(shape_)),
|
: shape_(shape), strides_(c_strides<Ndim>(shape_)),
|
||||||
size_(std::accumulate(shape_.begin(), shape_.end(), 1,
|
size_(std::accumulate(shape_.begin(), shape_.end(), 1, std::multiplies<ssize_t>())), data_(new T[size_]){};
|
||||||
std::multiplies<ssize_t>())),
|
|
||||||
data_(new T[size_]){};
|
|
||||||
|
|
||||||
NDArray(std::array<ssize_t, Ndim> shape, T value) : NDArray(shape) {
|
NDArray(std::array<ssize_t, Ndim> shape, T value) : NDArray(shape) { this->operator=(value); }
|
||||||
this->operator=(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* When constructing from a NDView we need to copy the data since
|
/* When constructing from a NDView we need to copy the data since
|
||||||
NDArray expect to own its data, and span is just a view*/
|
NDArray expect to own its data, and span is just a view*/
|
||||||
@ -45,8 +39,7 @@ template <typename T, ssize_t Ndim = 2> class NDArray {
|
|||||||
|
|
||||||
// Move constructor
|
// Move constructor
|
||||||
NDArray(NDArray &&other)
|
NDArray(NDArray &&other)
|
||||||
: shape_(other.shape_), strides_(c_strides<Ndim>(shape_)),
|
: shape_(other.shape_), strides_(c_strides<Ndim>(shape_)), size_(other.size_), data_(nullptr) {
|
||||||
size_(other.size_), data_(nullptr) {
|
|
||||||
data_ = other.data_;
|
data_ = other.data_;
|
||||||
other.reset();
|
other.reset();
|
||||||
// fmt::print("NDArray(NDArray &&other)\n");
|
// fmt::print("NDArray(NDArray &&other)\n");
|
||||||
@ -54,15 +47,12 @@ template <typename T, ssize_t Ndim = 2> class NDArray {
|
|||||||
|
|
||||||
// Copy constructor
|
// Copy constructor
|
||||||
NDArray(const NDArray &other)
|
NDArray(const NDArray &other)
|
||||||
: shape_(other.shape_), strides_(c_strides<Ndim>(shape_)),
|
: shape_(other.shape_), strides_(c_strides<Ndim>(shape_)), size_(other.size_), data_(new T[size_]) {
|
||||||
size_(other.size_), data_(new T[size_]) {
|
|
||||||
std::copy(other.data_, other.data_ + size_, data_);
|
std::copy(other.data_, other.data_ + size_, data_);
|
||||||
// fmt::print("NDArray(const NDArray &other)\n");
|
// fmt::print("NDArray(const NDArray &other)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
~NDArray() {
|
~NDArray() { delete[] data_; }
|
||||||
delete[] data_;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto begin() { return data_; }
|
auto begin() { return data_; }
|
||||||
auto end() { return data_ + size_; }
|
auto end() { return data_ + size_; }
|
||||||
@ -80,8 +70,7 @@ template <typename T, ssize_t Ndim = 2> class NDArray {
|
|||||||
NDArray &operator*=(const NDArray &other);
|
NDArray &operator*=(const NDArray &other);
|
||||||
NDArray operator/(const NDArray &other);
|
NDArray operator/(const NDArray &other);
|
||||||
// NDArray& operator/=(const NDArray& other);
|
// NDArray& operator/=(const NDArray& other);
|
||||||
template <typename V>
|
template <typename V> NDArray &operator/=(const NDArray<V, Ndim> &other) {
|
||||||
NDArray &operator/=(const NDArray<V, Ndim> &other) {
|
|
||||||
// check shape
|
// check shape
|
||||||
if (shape_ == other.shape()) {
|
if (shape_ == other.shape()) {
|
||||||
for (int i = 0; i < size_; ++i) {
|
for (int i = 0; i < size_; ++i) {
|
||||||
@ -118,21 +107,15 @@ template <typename T, ssize_t Ndim = 2> class NDArray {
|
|||||||
|
|
||||||
NDArray &operator++(); // pre inc
|
NDArray &operator++(); // pre inc
|
||||||
|
|
||||||
template <typename... Ix>
|
template <typename... Ix> typename std::enable_if<sizeof...(Ix) == Ndim, T &>::type operator()(Ix... index) {
|
||||||
typename std::enable_if<sizeof...(Ix) == Ndim, T &>::type
|
|
||||||
operator()(Ix... index) {
|
|
||||||
return data_[element_offset(strides_, index...)];
|
return data_[element_offset(strides_, index...)];
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Ix>
|
template <typename... Ix> typename std::enable_if<sizeof...(Ix) == Ndim, T &>::type operator()(Ix... index) const {
|
||||||
typename std::enable_if<sizeof...(Ix) == Ndim, T &>::type
|
|
||||||
operator()(Ix... index) const{
|
|
||||||
return data_[element_offset(strides_, index...)];
|
return data_[element_offset(strides_, index...)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename... Ix> typename std::enable_if<sizeof...(Ix) == Ndim, T>::type value(Ix... index) {
|
||||||
template <typename... Ix>
|
|
||||||
typename std::enable_if<sizeof...(Ix) == Ndim, T>::type value(Ix... index) {
|
|
||||||
return data_[element_offset(strides_, index...)];
|
return data_[element_offset(strides_, index...)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,8 +158,7 @@ template <typename T, ssize_t Ndim = 2> class NDArray {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Move assign
|
// Move assign
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> &NDArray<T, Ndim>::operator=(NDArray<T, Ndim> &&other) {
|
||||||
NDArray<T, Ndim> &NDArray<T, Ndim>::operator=(NDArray<T, Ndim> &&other) {
|
|
||||||
if (this != &other) {
|
if (this != &other) {
|
||||||
delete[] data_;
|
delete[] data_;
|
||||||
data_ = other.data_;
|
data_ = other.data_;
|
||||||
@ -188,15 +170,12 @@ NDArray<T, Ndim> &NDArray<T, Ndim>::operator=(NDArray<T, Ndim> &&other) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> NDArray<T, Ndim>::operator+(const NDArray &other) {
|
||||||
NDArray<T, Ndim> NDArray<T, Ndim>::operator+(const NDArray &other) {
|
|
||||||
NDArray result(*this);
|
NDArray result(*this);
|
||||||
result += other;
|
result += other;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> &NDArray<T, Ndim>::operator+=(const NDArray<T, Ndim> &other) {
|
||||||
NDArray<T, Ndim> &
|
|
||||||
NDArray<T, Ndim>::operator+=(const NDArray<T, Ndim> &other) {
|
|
||||||
// check shape
|
// check shape
|
||||||
if (shape_ == other.shape_) {
|
if (shape_ == other.shape_) {
|
||||||
for (int i = 0; i < size_; ++i) {
|
for (int i = 0; i < size_; ++i) {
|
||||||
@ -208,16 +187,13 @@ NDArray<T, Ndim>::operator+=(const NDArray<T, Ndim> &other) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> NDArray<T, Ndim>::operator-(const NDArray &other) {
|
||||||
NDArray<T, Ndim> NDArray<T, Ndim>::operator-(const NDArray &other) {
|
|
||||||
NDArray result{*this};
|
NDArray result{*this};
|
||||||
result -= other;
|
result -= other;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> &NDArray<T, Ndim>::operator-=(const NDArray<T, Ndim> &other) {
|
||||||
NDArray<T, Ndim> &
|
|
||||||
NDArray<T, Ndim>::operator-=(const NDArray<T, Ndim> &other) {
|
|
||||||
// check shape
|
// check shape
|
||||||
if (shape_ == other.shape_) {
|
if (shape_ == other.shape_) {
|
||||||
for (int i = 0; i < size_; ++i) {
|
for (int i = 0; i < size_; ++i) {
|
||||||
@ -228,16 +204,13 @@ NDArray<T, Ndim>::operator-=(const NDArray<T, Ndim> &other) {
|
|||||||
throw(std::runtime_error("Shape of ImageDatas must match"));
|
throw(std::runtime_error("Shape of ImageDatas must match"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> NDArray<T, Ndim>::operator*(const NDArray &other) {
|
||||||
NDArray<T, Ndim> NDArray<T, Ndim>::operator*(const NDArray &other) {
|
|
||||||
NDArray result = *this;
|
NDArray result = *this;
|
||||||
result *= other;
|
result *= other;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> &NDArray<T, Ndim>::operator*=(const NDArray<T, Ndim> &other) {
|
||||||
NDArray<T, Ndim> &
|
|
||||||
NDArray<T, Ndim>::operator*=(const NDArray<T, Ndim> &other) {
|
|
||||||
// check shape
|
// check shape
|
||||||
if (shape_ == other.shape_) {
|
if (shape_ == other.shape_) {
|
||||||
for (int i = 0; i < size_; ++i) {
|
for (int i = 0; i < size_; ++i) {
|
||||||
@ -249,15 +222,13 @@ NDArray<T, Ndim>::operator*=(const NDArray<T, Ndim> &other) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> NDArray<T, Ndim>::operator/(const NDArray &other) {
|
||||||
NDArray<T, Ndim> NDArray<T, Ndim>::operator/(const NDArray &other) {
|
|
||||||
NDArray result = *this;
|
NDArray result = *this;
|
||||||
result /= other;
|
result /= other;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> &NDArray<T, Ndim>::operator&=(const T &mask) {
|
||||||
NDArray<T, Ndim> &NDArray<T, Ndim>::operator&=(const T &mask) {
|
|
||||||
for (auto it = begin(); it != end(); ++it)
|
for (auto it = begin(); it != end(); ++it)
|
||||||
*it &= mask;
|
*it &= mask;
|
||||||
return *this;
|
return *this;
|
||||||
@ -278,8 +249,7 @@ NDArray<T, Ndim> &NDArray<T, Ndim>::operator&=(const T &mask) {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<bool, Ndim> NDArray<T, Ndim>::operator>(const NDArray &other) {
|
||||||
NDArray<bool, Ndim> NDArray<T, Ndim>::operator>(const NDArray &other) {
|
|
||||||
if (shape_ == other.shape_) {
|
if (shape_ == other.shape_) {
|
||||||
NDArray<bool> result{shape_};
|
NDArray<bool> result{shape_};
|
||||||
for (int i = 0; i < size_; ++i) {
|
for (int i = 0; i < size_; ++i) {
|
||||||
@ -291,9 +261,7 @@ NDArray<bool, Ndim> NDArray<T, Ndim>::operator>(const NDArray &other) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> &NDArray<T, Ndim>::operator=(const NDArray<T, Ndim> &other) {
|
||||||
NDArray<T, Ndim> &
|
|
||||||
NDArray<T, Ndim>::operator=(const NDArray<T, Ndim> &other) {
|
|
||||||
if (this != &other) {
|
if (this != &other) {
|
||||||
delete[] data_;
|
delete[] data_;
|
||||||
shape_ = other.shape_;
|
shape_ = other.shape_;
|
||||||
@ -305,8 +273,7 @@ NDArray<T, Ndim>::operator=(const NDArray<T, Ndim> &other) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> bool NDArray<T, Ndim>::operator==(const NDArray<T, Ndim> &other) const {
|
||||||
bool NDArray<T, Ndim>::operator==(const NDArray<T, Ndim> &other) const {
|
|
||||||
if (shape_ != other.shape_)
|
if (shape_ != other.shape_)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -317,68 +284,57 @@ bool NDArray<T, Ndim>::operator==(const NDArray<T, Ndim> &other) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> bool NDArray<T, Ndim>::operator!=(const NDArray<T, Ndim> &other) const {
|
||||||
bool NDArray<T, Ndim>::operator!=(const NDArray<T, Ndim> &other) const {
|
|
||||||
return !((*this) == other);
|
return !((*this) == other);
|
||||||
}
|
}
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> &NDArray<T, Ndim>::operator++() {
|
||||||
NDArray<T, Ndim> &NDArray<T, Ndim>::operator++() {
|
|
||||||
for (int i = 0; i < size_; ++i)
|
for (int i = 0; i < size_; ++i)
|
||||||
data_[i] += 1;
|
data_[i] += 1;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> &NDArray<T, Ndim>::operator=(const T &value) {
|
||||||
NDArray<T, Ndim> &NDArray<T, Ndim>::operator=(const T &value) {
|
|
||||||
std::fill_n(data_, size_, value);
|
std::fill_n(data_, size_, value);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> &NDArray<T, Ndim>::operator+=(const T &value) {
|
||||||
NDArray<T, Ndim> &NDArray<T, Ndim>::operator+=(const T &value) {
|
|
||||||
for (int i = 0; i < size_; ++i)
|
for (int i = 0; i < size_; ++i)
|
||||||
data_[i] += value;
|
data_[i] += value;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> NDArray<T, Ndim>::operator+(const T &value) {
|
||||||
NDArray<T, Ndim> NDArray<T, Ndim>::operator+(const T &value) {
|
|
||||||
NDArray result = *this;
|
NDArray result = *this;
|
||||||
result += value;
|
result += value;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> &NDArray<T, Ndim>::operator-=(const T &value) {
|
||||||
NDArray<T, Ndim> &NDArray<T, Ndim>::operator-=(const T &value) {
|
|
||||||
for (int i = 0; i < size_; ++i)
|
for (int i = 0; i < size_; ++i)
|
||||||
data_[i] -= value;
|
data_[i] -= value;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> NDArray<T, Ndim>::operator-(const T &value) {
|
||||||
NDArray<T, Ndim> NDArray<T, Ndim>::operator-(const T &value) {
|
|
||||||
NDArray result = *this;
|
NDArray result = *this;
|
||||||
result -= value;
|
result -= value;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> &NDArray<T, Ndim>::operator/=(const T &value) {
|
||||||
NDArray<T, Ndim> &NDArray<T, Ndim>::operator/=(const T &value) {
|
|
||||||
for (int i = 0; i < size_; ++i)
|
for (int i = 0; i < size_; ++i)
|
||||||
data_[i] /= value;
|
data_[i] /= value;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> NDArray<T, Ndim>::operator/(const T &value) {
|
||||||
NDArray<T, Ndim> NDArray<T, Ndim>::operator/(const T &value) {
|
|
||||||
NDArray result = *this;
|
NDArray result = *this;
|
||||||
result /= value;
|
result /= value;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> &NDArray<T, Ndim>::operator*=(const T &value) {
|
||||||
NDArray<T, Ndim> &NDArray<T, Ndim>::operator*=(const T &value) {
|
|
||||||
for (int i = 0; i < size_; ++i)
|
for (int i = 0; i < size_; ++i)
|
||||||
data_[i] *= value;
|
data_[i] *= value;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> NDArray<T, Ndim> NDArray<T, Ndim>::operator*(const T &value) {
|
||||||
NDArray<T, Ndim> NDArray<T, Ndim>::operator*(const T &value) {
|
|
||||||
NDArray result = *this;
|
NDArray result = *this;
|
||||||
result *= value;
|
result *= value;
|
||||||
return result;
|
return result;
|
||||||
@ -408,8 +364,7 @@ template <typename T, ssize_t Ndim> void NDArray<T, Ndim>::Print_some() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim> void save(NDArray<T, Ndim> &img, std::string pathname) {
|
||||||
void save(NDArray<T, Ndim> &img, std::string pathname) {
|
|
||||||
std::ofstream f;
|
std::ofstream f;
|
||||||
f.open(pathname, std::ios::binary);
|
f.open(pathname, std::ios::binary);
|
||||||
f.write(img.buffer(), img.size() * sizeof(T));
|
f.write(img.buffer(), img.size() * sizeof(T));
|
||||||
@ -417,8 +372,7 @@ void save(NDArray<T, Ndim> &img, std::string pathname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, ssize_t Ndim>
|
template <typename T, ssize_t Ndim>
|
||||||
NDArray<T, Ndim> load(const std::string &pathname,
|
NDArray<T, Ndim> load(const std::string &pathname, std::array<ssize_t, Ndim> shape) {
|
||||||
std::array<ssize_t, Ndim> shape) {
|
|
||||||
NDArray<T, Ndim> img{shape};
|
NDArray<T, Ndim> img{shape};
|
||||||
std::ifstream f;
|
std::ifstream f;
|
||||||
f.open(pathname, std::ios::binary);
|
f.open(pathname, std::ios::binary);
|
||||||
@ -427,5 +381,4 @@ NDArray<T, Ndim> load(const std::string &pathname,
|
|||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace aare
|
} // namespace aare
|
@ -4,16 +4,15 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <vector>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace aare {
|
namespace aare {
|
||||||
|
|
||||||
template <ssize_t Ndim> using Shape = std::array<ssize_t, Ndim>;
|
template <ssize_t Ndim> using Shape = std::array<ssize_t, Ndim>;
|
||||||
|
|
||||||
// TODO! fix mismatch between signed and unsigned
|
// TODO! fix mismatch between signed and unsigned
|
||||||
template <ssize_t Ndim>
|
template <ssize_t Ndim> Shape<Ndim> make_shape(const std::vector<size_t> &shape) {
|
||||||
Shape<Ndim> make_shape(const std::vector<size_t>& shape){
|
|
||||||
if (shape.size() != Ndim)
|
if (shape.size() != Ndim)
|
||||||
throw std::runtime_error("Shape size mismatch");
|
throw std::runtime_error("Shape size mismatch");
|
||||||
Shape<Ndim> arr;
|
Shape<Ndim> arr;
|
||||||
@ -60,7 +59,6 @@ template <typename T, ssize_t Ndim=2> class NDView {
|
|||||||
strides_ = c_strides<Ndim>(make_array<Ndim>(shape));
|
strides_ = c_strides<Ndim>(make_array<Ndim>(shape));
|
||||||
shape_ = make_array<Ndim>(shape);
|
shape_ = make_array<Ndim>(shape);
|
||||||
size_ = std::accumulate(std::begin(shape), std::end(shape), 1, std::multiplies<ssize_t>());
|
size_ = std::accumulate(std::begin(shape), std::end(shape), 1, std::multiplies<ssize_t>());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Ix> typename std::enable_if<sizeof...(Ix) == Ndim, T &>::type operator()(Ix... index) {
|
template <typename... Ix> typename std::enable_if<sizeof...(Ix) == Ndim, T &>::type operator()(Ix... index) {
|
||||||
|
@ -38,8 +38,7 @@ namespace folly {
|
|||||||
* ProducerConsumerQueue is a one producer and one consumer queue
|
* ProducerConsumerQueue is a one producer and one consumer queue
|
||||||
* without locks.
|
* without locks.
|
||||||
*/
|
*/
|
||||||
template <class T>
|
template <class T> struct ProducerConsumerQueue {
|
||||||
struct ProducerConsumerQueue {
|
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
|
|
||||||
ProducerConsumerQueue(const ProducerConsumerQueue &) = delete;
|
ProducerConsumerQueue(const ProducerConsumerQueue &) = delete;
|
||||||
@ -51,10 +50,7 @@ struct ProducerConsumerQueue {
|
|||||||
// given time is actually (size-1), so if you start with an empty queue,
|
// given time is actually (size-1), so if you start with an empty queue,
|
||||||
// isFull() will return true after size-1 insertions.
|
// isFull() will return true after size-1 insertions.
|
||||||
explicit ProducerConsumerQueue(uint32_t size)
|
explicit ProducerConsumerQueue(uint32_t size)
|
||||||
: size_(size),
|
: size_(size), records_(static_cast<T *>(std::malloc(sizeof(T) * size))), readIndex_(0), writeIndex_(0) {
|
||||||
records_(static_cast<T*>(std::malloc(sizeof(T) * size))),
|
|
||||||
readIndex_(0),
|
|
||||||
writeIndex_(0) {
|
|
||||||
assert(size >= 2);
|
assert(size >= 2);
|
||||||
if (!records_) {
|
if (!records_) {
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
@ -79,8 +75,7 @@ struct ProducerConsumerQueue {
|
|||||||
std::free(records_);
|
std::free(records_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args> bool write(Args &&...recordArgs) {
|
||||||
bool write(Args&&... recordArgs) {
|
|
||||||
auto const currentWrite = writeIndex_.load(std::memory_order_relaxed);
|
auto const currentWrite = writeIndex_.load(std::memory_order_relaxed);
|
||||||
auto nextRecord = currentWrite + 1;
|
auto nextRecord = currentWrite + 1;
|
||||||
if (nextRecord == size_) {
|
if (nextRecord == size_) {
|
||||||
@ -139,8 +134,7 @@ struct ProducerConsumerQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isEmpty() const {
|
bool isEmpty() const {
|
||||||
return readIndex_.load(std::memory_order_acquire) ==
|
return readIndex_.load(std::memory_order_acquire) == writeIndex_.load(std::memory_order_acquire);
|
||||||
writeIndex_.load(std::memory_order_acquire);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFull() const {
|
bool isFull() const {
|
||||||
@ -161,8 +155,7 @@ struct ProducerConsumerQueue {
|
|||||||
// be removing items concurrently).
|
// be removing items concurrently).
|
||||||
// * It is undefined to call this from any other thread.
|
// * It is undefined to call this from any other thread.
|
||||||
size_t sizeGuess() const {
|
size_t sizeGuess() const {
|
||||||
int ret = writeIndex_.load(std::memory_order_acquire) -
|
int ret = writeIndex_.load(std::memory_order_acquire) - readIndex_.load(std::memory_order_acquire);
|
||||||
readIndex_.load(std::memory_order_acquire);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
ret += size_;
|
ret += size_;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
#include "aare/NDArray.hpp"
|
#include "aare/NDArray.hpp"
|
||||||
|
|
||||||
const int MAX_CLUSTER_SIZE = 200;
|
const int MAX_CLUSTER_SIZE = 200;
|
||||||
@ -51,14 +50,16 @@ template <typename T> class ClusterFinder {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ClusterFinder(image_shape shape, T threshold)
|
ClusterFinder(image_shape shape, T threshold)
|
||||||
: shape_(shape), labeled_(shape, 0), peripheral_labeled_(shape, 0), binary_(shape),
|
: shape_(shape), labeled_(shape, 0), peripheral_labeled_(shape, 0), binary_(shape), threshold_(threshold) {
|
||||||
threshold_(threshold) {
|
|
||||||
hits.reserve(2000);
|
hits.reserve(2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
NDArray<int, 2> labeled() { return labeled_; }
|
NDArray<int, 2> labeled() { return labeled_; }
|
||||||
|
|
||||||
void set_noiseMap(NDView<T, 2> noise_map) { noiseMap = noise_map; use_noise_map = true; }
|
void set_noiseMap(NDView<T, 2> noise_map) {
|
||||||
|
noiseMap = noise_map;
|
||||||
|
use_noise_map = true;
|
||||||
|
}
|
||||||
void set_peripheralThresholdFactor(int factor) { peripheralThresholdFactor_ = factor; }
|
void set_peripheralThresholdFactor(int factor) { peripheralThresholdFactor_ = factor; }
|
||||||
void find_clusters(NDView<T, 2> img);
|
void find_clusters(NDView<T, 2> img);
|
||||||
void find_clusters_X(NDView<T, 2> img);
|
void find_clusters_X(NDView<T, 2> img);
|
||||||
@ -140,7 +141,6 @@ template <typename T> int ClusterFinder<T>::check_neighbours(int i, int j) {
|
|||||||
add_link(*current, *next);
|
add_link(*current, *next);
|
||||||
}
|
}
|
||||||
return neighbour_labels.back(); // already sorted
|
return neighbour_labels.back(); // already sorted
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,8 +200,7 @@ template <typename T> void ClusterFinder<T>::rec_FillHit(int clusterIndex, int i
|
|||||||
threshold_ = peripheralThresholdFactor_ * noiseMap(row, col);
|
threshold_ = peripheralThresholdFactor_ * noiseMap(row, col);
|
||||||
if (original_(row, col) > threshold_) {
|
if (original_(row, col) > threshold_) {
|
||||||
rec_FillHit(clusterIndex, row, col);
|
rec_FillHit(clusterIndex, row, col);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
// if (h_size[clusterIndex].size < MAX_CLUSTER_SIZE){
|
// if (h_size[clusterIndex].size < MAX_CLUSTER_SIZE){
|
||||||
// h_size[clusterIndex].size += 1;
|
// h_size[clusterIndex].size += 1;
|
||||||
// h_size[clusterIndex].rows[h_size[clusterIndex].size] = row;
|
// h_size[clusterIndex].rows[h_size[clusterIndex].size] = row;
|
||||||
@ -286,8 +285,7 @@ template <typename T> void ClusterFinder<T>::store_clusters() {
|
|||||||
record.rows[record.size] = i;
|
record.rows[record.size] = i;
|
||||||
record.cols[record.size] = j;
|
record.cols[record.size] = j;
|
||||||
record.enes[record.size] = original_(i, j);
|
record.enes[record.size] = original_(i, j);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
record.size += 1;
|
record.size += 1;
|
||||||
@ -304,7 +302,6 @@ template <typename T> void ClusterFinder<T>::store_clusters() {
|
|||||||
|
|
||||||
for (const auto &h : h_size)
|
for (const auto &h : h_size)
|
||||||
hits.push_back(h.second);
|
hits.push_back(h.second);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aare
|
} // namespace aare
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
|
|
||||||
// Socket to receive data from a ZMQ publisher
|
// Socket to receive data from a ZMQ publisher
|
||||||
// needs to be in sync with the main library (or maybe better use the versioning in the header)
|
// needs to be in sync with the main library (or maybe better use the versioning in the header)
|
||||||
@ -65,7 +64,6 @@ struct zmqHeader {
|
|||||||
std::array<int, 4> rx_roi{};
|
std::array<int, 4> rx_roi{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ZmqSocket {
|
class ZmqSocket {
|
||||||
void *m_context{nullptr};
|
void *m_context{nullptr};
|
||||||
void *m_socket{nullptr};
|
void *m_socket{nullptr};
|
||||||
@ -90,8 +88,6 @@ public:
|
|||||||
void set_timeout_ms(int n);
|
void set_timeout_ms(int n);
|
||||||
|
|
||||||
int receive(zmqHeader &header, std::byte *data);
|
int receive(zmqHeader &header, std::byte *data);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aare
|
} // namespace aare
|
@ -1,13 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <vector>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <string_view>
|
|
||||||
#include <string>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace aare {
|
namespace aare {
|
||||||
|
|
||||||
@ -40,25 +40,17 @@ enum class DetectorType { Jungfrau, Eiger, Mythen3, Moench,ChipTestBoard };
|
|||||||
|
|
||||||
enum class TimingMode { Auto, Trigger };
|
enum class TimingMode { Auto, Trigger };
|
||||||
|
|
||||||
template<class T>
|
template <class T> T StringTo(std::string sv) { return T(sv); }
|
||||||
T StringTo(std::string sv){
|
|
||||||
return T(sv);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T>
|
template <class T> std::string toString(T sv) { return T(sv); }
|
||||||
std::string toString(T sv){
|
|
||||||
return T(sv);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <> DetectorType StringTo(std::string);
|
template <> DetectorType StringTo(std::string);
|
||||||
template <> std::string toString(DetectorType type);
|
template <> std::string toString(DetectorType type);
|
||||||
|
|
||||||
|
|
||||||
template <> TimingMode StringTo(std::string);
|
template <> TimingMode StringTo(std::string);
|
||||||
|
|
||||||
using DataTypeVariants = std::variant<uint16_t, uint32_t>;
|
using DataTypeVariants = std::variant<uint16_t, uint32_t>;
|
||||||
|
|
||||||
|
|
||||||
struct RawFileConfig {
|
struct RawFileConfig {
|
||||||
int module_gap_row{};
|
int module_gap_row{};
|
||||||
int module_gap_col{};
|
int module_gap_col{};
|
||||||
@ -72,6 +64,4 @@ struct RawFileConfig {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace aare
|
} // namespace aare
|
@ -30,7 +30,6 @@ class File {
|
|||||||
ssize_t bitdepth() const;
|
ssize_t bitdepth() const;
|
||||||
File(File &&other);
|
File(File &&other);
|
||||||
|
|
||||||
|
|
||||||
~File();
|
~File();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "aare/DType.hpp"
|
||||||
#include "aare/Frame.hpp"
|
#include "aare/Frame.hpp"
|
||||||
#include "aare/defs.hpp"
|
#include "aare/defs.hpp"
|
||||||
#include "aare/DType.hpp"
|
|
||||||
#include "aare/utils/logger.hpp"
|
#include "aare/utils/logger.hpp"
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -96,4 +96,4 @@ class FileInterface {
|
|||||||
ssize_t m_bitdepth{};
|
ssize_t m_bitdepth{};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace aare
|
@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "aare/DType.hpp"
|
||||||
#include "aare/FileInterface.hpp"
|
#include "aare/FileInterface.hpp"
|
||||||
#include "aare/NumpyHelpers.hpp"
|
#include "aare/NumpyHelpers.hpp"
|
||||||
#include "aare/DType.hpp"
|
|
||||||
#include "aare/defs.hpp"
|
#include "aare/defs.hpp"
|
||||||
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
namespace aare {
|
namespace aare {
|
||||||
|
|
||||||
@ -26,8 +26,6 @@ class NumpyFile : public FileInterface {
|
|||||||
Frame get_frame(size_t frame_number);
|
Frame get_frame(size_t frame_number);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
NumpyFile(const std::filesystem::path &fname);
|
NumpyFile(const std::filesystem::path &fname);
|
||||||
NumpyFile(FileConfig, NumpyHeader);
|
NumpyFile(FileConfig, NumpyHeader);
|
||||||
void write(Frame &frame) override;
|
void write(Frame &frame) override;
|
||||||
@ -50,8 +48,7 @@ class NumpyFile : public FileInterface {
|
|||||||
std::vector<size_t> shape() const { return m_header.shape; }
|
std::vector<size_t> shape() const { return m_header.shape; }
|
||||||
|
|
||||||
// load the full numpy file into a NDArray
|
// load the full numpy file into a NDArray
|
||||||
template<typename T, size_t NDim>
|
template <typename T, size_t NDim> NDArray<T, NDim> load() {
|
||||||
NDArray<T,NDim> load(){
|
|
||||||
NDArray<T, NDim> arr(make_shape<NDim>(m_header.shape));
|
NDArray<T, NDim> arr(make_shape<NDim>(m_header.shape));
|
||||||
fseek(fp, header_size, SEEK_SET);
|
fseek(fp, header_size, SEEK_SET);
|
||||||
fread(arr.data(), sizeof(T), arr.size(), fp);
|
fread(arr.data(), sizeof(T), arr.size(), fp);
|
||||||
|
@ -17,7 +17,6 @@ class NumpyFileFactory : public FileFactory {
|
|||||||
NumpyFile *load_file_read() override;
|
NumpyFile *load_file_read() override;
|
||||||
NumpyFile *load_file_write(FileConfig) override;
|
NumpyFile *load_file_write(FileConfig) override;
|
||||||
void parse_fname(FileInterface *) override{};
|
void parse_fname(FileInterface *) override{};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aare
|
} // namespace aare
|
@ -54,6 +54,5 @@ aare::DType parse_descr(std::string typestring);
|
|||||||
size_t write_header(std::filesystem::path fname, const NumpyHeader &header);
|
size_t write_header(std::filesystem::path fname, const NumpyHeader &header);
|
||||||
size_t write_header(std::ostream &out, const NumpyHeader &header);
|
size_t write_header(std::ostream &out, const NumpyHeader &header);
|
||||||
|
|
||||||
|
|
||||||
} // namespace NumpyHelpers
|
} // namespace NumpyHelpers
|
||||||
} // namespace aare
|
} // namespace aare
|
@ -10,7 +10,6 @@ class RawFile : public FileInterface {
|
|||||||
|
|
||||||
using config = RawFileConfig;
|
using config = RawFileConfig;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::filesystem::path m_fname; // TO be made private!
|
std::filesystem::path m_fname; // TO be made private!
|
||||||
void write(Frame &frame) override{};
|
void write(Frame &frame) override{};
|
||||||
@ -75,4 +74,4 @@ class RawFile : public FileInterface {
|
|||||||
Frame get_frame(size_t frame_number);
|
Frame get_frame(size_t frame_number);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace aare
|
@ -10,7 +10,6 @@ class RawFileFactory : public FileFactory {
|
|||||||
void parse_raw_metadata(RawFile *file);
|
void parse_raw_metadata(RawFile *file);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RawFileFactory(std::filesystem::path fpath);
|
RawFileFactory(std::filesystem::path fpath);
|
||||||
RawFile *load_file_read() override;
|
RawFile *load_file_read() override;
|
||||||
RawFile *load_file_write(FileConfig) override { return new RawFile(); };
|
RawFile *load_file_write(FileConfig) override { return new RawFile(); };
|
||||||
@ -21,4 +20,4 @@ class RawFileFactory : public FileFactory {
|
|||||||
void find_geometry(FileInterface *);
|
void find_geometry(FileInterface *);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace aare
|
Loading…
x
Reference in New Issue
Block a user