Skip to content

Commit

Permalink
fix: buffer.clear function missing
Browse files Browse the repository at this point in the history
buffer.clear added back in to repo
  • Loading branch information
Peter-Barrow committed Jun 14, 2024
1 parent 6a0cdb8 commit e8edd83
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 16 deletions.
1 change: 1 addition & 0 deletions tangy/_tangy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ class TangyBuffer:
def slice_from_pointers(self, length: u64n, channels: None, timestamps: None = None, clocks: None = None, deltas: None = None) -> _tangy.tangy_field_ptrs: ...
def pull(self, start: u64n, stop: u64n): ...
def push(self, channels: None, timetags: None | tuple[None, None]): ...
def clear(self) -> None: ...
def lower_bound(self, time: float) -> int:
''' Find the position in the buffer that gives the last "time" seconds in the buffer
Expand Down
2 changes: 2 additions & 0 deletions tangy_src/_tangy.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ cdef extern from "./src/tangy.h":

u64 tangy_bins_from_time(tangy_buffer* t_buf, f64 time)

void tangy_clear_buffer(tangy_buffer* t_buf)

u64 tangy_buffer_slice(tangy_buffer* t_buf,
tangy_field_ptrs* ptrs,
u64 start,
Expand Down
4 changes: 4 additions & 0 deletions tangy_src/_tangy.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,10 @@ def push(self, channels: ndarray(u8n),

return count_pushed

@cython.ccall
def clear(self):
_tangy.tangy_clear_buffer(self._ptr_buf)

@cython.ccall
def lower_bound(self, time: float) -> int:
""" Find the position in the buffer that gives the last "time" seconds\
Expand Down
2 changes: 2 additions & 0 deletions tangy_src/src/analysis_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ JOIN(stub, buffer_map_size)(u64 num_elements) {
return size_context + (size_elems * num_elements);
}

void JOIN(stub, clear_buffer)(ring_buffer* buffer, slice* data);

// buffer access methods

slice JOIN(stub, init_base_ptrs)(ring_buffer* buf);
Expand Down
11 changes: 11 additions & 0 deletions tangy_src/src/analysis_impl_clocked.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ clk_size_of() {
return elem_size;
}

inline void
clk_clear_buffer(ring_buffer* buf, clk_slice* data) {
u64 capacity = rb_get_capacity(buf);
for (u64 i = 0; i < capacity; i++) {
data->channel[i] = 0;
data->timestamp[i].clock = 0;
data->timestamp[i].delta = 0;
}
rb_set_count(buf, 0);
}

inline clk_slice
clk_init_base_ptrs(ring_buffer* buf) {
clk_slice slice = { 0 };
Expand Down
42 changes: 26 additions & 16 deletions tangy_src/src/analysis_impl_standard.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ std_size_of() {
return elem_size;
}

inline void
std_clear_buffer(ring_buffer* buf, std_slice* data) {
u64 capacity = rb_get_capacity(buf);
for (u64 i = 0; i < capacity; i++) {
data->channel[i] = 0;
data->timestamp[i] = 0;
}
rb_set_count(buf, 0);
}

inline std_slice
std_init_base_ptrs(ring_buffer* buf) {
std_slice slice = { 0 };
Expand Down Expand Up @@ -75,8 +85,8 @@ std_channel_at(const std_slice* data, u64 absolute_index) {

inline u64
std_arrival_time_at(const std_slice* data,
u64 conversion_factor,
u64 absolute_index) {
u64 conversion_factor,
u64 absolute_index) {
return data->timestamp[absolute_index];
}

Expand All @@ -92,10 +102,10 @@ std_as_bins(std_timetag record, u64 conversion_factor) {

inline u64
std_buffer_slice(ring_buffer* const buf,
const std_slice* const data,
std_slice* ptrs,
u64 start,
u64 stop) {
const std_slice* const data,
std_slice* ptrs,
u64 start,
u64 stop) {

if (ptrs->length == 0) {
return 0;
Expand Down Expand Up @@ -125,10 +135,10 @@ std_buffer_slice(ring_buffer* const buf,

inline u64
std_buffer_push(ring_buffer* const buf,
const std_slice* const data,
std_slice* ptrs,
u64 start,
u64 stop) {
const std_slice* const data,
std_slice* ptrs,
u64 start,
u64 stop) {

if (ptrs->length == 0) {
return 0;
Expand Down Expand Up @@ -185,10 +195,10 @@ std_records_copy(vec_std_timetag* records, std_slice* data) {

histogram2D_coords
std_joint_histogram_position(const std_slice* data,
const u8 ch_idx_idler,
const u8 ch_idx_signal,
const u8 ch_idx_clock,
const std_timetag* timetags) {
const u8 ch_idx_idler,
const u8 ch_idx_signal,
const u8 ch_idx_clock,
const std_timetag* timetags) {

u64 arrival_clock = timetags[ch_idx_clock];
u64 arrival_signal = timetags[ch_idx_signal];
Expand All @@ -199,8 +209,8 @@ std_joint_histogram_position(const std_slice* data,
: arrival_idler - arrival_clock;

u64 delta_signal = (arrival_clock > arrival_signal)
? arrival_clock - arrival_signal
: arrival_signal - arrival_clock;
? arrival_clock - arrival_signal
: arrival_signal - arrival_clock;

histogram2D_coords point = { .x = delta_idler, .y = delta_signal };

Expand Down
11 changes: 11 additions & 0 deletions tangy_src/src/tangy.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ tangy_buffer_connect(char* name, tangy_buffer* t_buf) {
return result;
}

static inline void tangy_clear_buffer(tangy_buffer* t_buf) {
switch (t_buf->format) {
case STANDARD:
std_clear_buffer(&t_buf->buffer, &t_buf->slice.standard);
break;
case CLOCKED:
clk_clear_buffer(&t_buf->buffer, &t_buf->slice.clocked);
break;
}
}

// buffer access

// conversions
Expand Down

0 comments on commit e8edd83

Please sign in to comment.