Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/danielhrisca/asammdf
Browse files Browse the repository at this point in the history
…into tests
  • Loading branch information
FillBk committed Jan 12, 2024
2 parents 535a91b + 23c6ae1 commit 9fd3321
Show file tree
Hide file tree
Showing 32 changed files with 866 additions and 508 deletions.
156 changes: 101 additions & 55 deletions src/asammdf/blocks/cutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "numpy/ndarrayobject.h"
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <time.h>

#define PY_PRINTF(o) \
Expand Down Expand Up @@ -272,9 +273,9 @@ static PyObject* extract(PyObject* self, PyObject* args)
size = calc_size(&buf[offset]);
memcpy(addr2, &buf[offset+4], size);
}
Py_XDECREF(offsets_list);
}
}
Py_XDECREF(offsets_list);
}

return (PyObject *) vals;
Expand Down Expand Up @@ -352,8 +353,7 @@ static PyObject* get_vlsd_max_sample_size(PyObject* self, PyObject* args)
{
int i = 0;
Py_ssize_t count = 0;
PyObject* data, * offsets, * result;
npy_intp dim[1];
PyObject* data, * offsets;
unsigned long long max_size = 0;
unsigned long vlsd_size = 0;
char* inptr=NULL, *data_end=NULL, *current_position=NULL;
Expand All @@ -367,7 +367,7 @@ static PyObject* get_vlsd_max_sample_size(PyObject* self, PyObject* args)
}
else
{
offsets_array = (unsigned long long*)PyArray_GETPTR1(offsets, 0);
offsets_array = (unsigned long long*)PyArray_GETPTR1((PyArrayObject *)offsets, 0);
inptr = PyBytes_AsString(data);
data_end = inptr + PyBytes_GET_SIZE(data);

Expand All @@ -394,15 +394,15 @@ void positions_char(PyObject* samples, PyObject* timestamps, PyObject* plot_samp
long* outdata;
int pos_min = 0, pos_max = 0;

indata = (char*)PyArray_GETPTR1(samples, 0);
outdata = (long*)PyArray_GETPTR1(result, 0);
indata = (char*)PyArray_GETPTR1((PyArrayObject *)samples, 0);
outdata = (long*)PyArray_GETPTR1((PyArrayObject *)result, 0);

char * ps;
double tmin, tmax, * ts, *pt;

ps = (char*)PyArray_GETPTR1(plot_samples, 0);
pt = (double*)PyArray_GETPTR1(plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1(timestamps, 0);
ps = (char*)PyArray_GETPTR1((PyArrayObject *)plot_samples, 0);
pt = (double*)PyArray_GETPTR1((PyArrayObject *)plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1((PyArrayObject *)timestamps, 0);

int current_pos = 0, stop_index=count-1;
for (int i = 0; i < (int)count; i++) {
Expand Down Expand Up @@ -464,15 +464,15 @@ void positions_short(PyObject* samples, PyObject* timestamps, PyObject* plot_sam
long* outdata;
int pos_min = 0, pos_max = 0;

indata = (short*)PyArray_GETPTR1(samples, 0);
outdata = (long*)PyArray_GETPTR1(result, 0);
indata = (short*)PyArray_GETPTR1((PyArrayObject *)samples, 0);
outdata = (long*)PyArray_GETPTR1((PyArrayObject *)result, 0);

short * ps;
double tmin, tmax, * ts, *pt;

ps = (short*)PyArray_GETPTR1(plot_samples, 0);
pt = (double*)PyArray_GETPTR1(plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1(timestamps, 0);
ps = (short*)PyArray_GETPTR1((PyArrayObject *)plot_samples, 0);
pt = (double*)PyArray_GETPTR1((PyArrayObject *)plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1((PyArrayObject *)timestamps, 0);

int current_pos = 0, stop_index = count - 1;
for (int i = 0; i < (int)count; i++) {
Expand Down Expand Up @@ -534,15 +534,15 @@ void positions_long(PyObject* samples, PyObject* timestamps, PyObject* plot_samp
long* outdata;
int pos_min = 0, pos_max = 0;

indata = (long*)PyArray_GETPTR1(samples, 0);
outdata = (long*)PyArray_GETPTR1(result, 0);
indata = (long*)PyArray_GETPTR1((PyArrayObject *)samples, 0);
outdata = (long*)PyArray_GETPTR1((PyArrayObject *)result, 0);

long * ps;
double tmin, tmax, * ts, *pt;

ps = (long*)PyArray_GETPTR1(plot_samples, 0);
pt = (double*)PyArray_GETPTR1(plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1(timestamps, 0);
ps = (long*)PyArray_GETPTR1((PyArrayObject *)plot_samples, 0);
pt = (double*)PyArray_GETPTR1((PyArrayObject *)plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1((PyArrayObject *)timestamps, 0);

int current_pos = 0, stop_index = count - 1;
for (int i = 0; i < (int)count; i++) {
Expand Down Expand Up @@ -604,15 +604,15 @@ void positions_long_long(PyObject* samples, PyObject* timestamps, PyObject* plot
long* outdata;
int pos_min = 0, pos_max = 0;

indata = (long long*)PyArray_GETPTR1(samples, 0);
outdata = (long*)PyArray_GETPTR1(result, 0);
indata = (long long*)PyArray_GETPTR1((PyArrayObject *)samples, 0);
outdata = (long*)PyArray_GETPTR1((PyArrayObject *)result, 0);

long long * ps;
double tmin, tmax, * ts, * pt;

ps = (long long*)PyArray_GETPTR1(plot_samples, 0);
pt = (double*)PyArray_GETPTR1(plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1(timestamps, 0);
ps = (long long*)PyArray_GETPTR1((PyArrayObject *)plot_samples, 0);
pt = (double*)PyArray_GETPTR1((PyArrayObject *)plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1((PyArrayObject *)timestamps, 0);

int current_pos = 0, stop_index = count - 1;
for (int i = 0; i < (int)count; i++) {
Expand Down Expand Up @@ -674,15 +674,15 @@ void positions_unsigned_char(PyObject* samples, PyObject* timestamps, PyObject*
long* outdata;
int pos_min = 0, pos_max = 0;

indata = (unsigned char*)PyArray_GETPTR1(samples, 0);
outdata = (long*)PyArray_GETPTR1(result, 0);
indata = (unsigned char*)PyArray_GETPTR1((PyArrayObject *)samples, 0);
outdata = (long*)PyArray_GETPTR1((PyArrayObject *)result, 0);

unsigned char* ps;
double tmin, tmax, * ts, * pt;

ps = (unsigned char*)PyArray_GETPTR1(plot_samples, 0);
pt = (double*)PyArray_GETPTR1(plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1(timestamps, 0);
ps = (unsigned char*)PyArray_GETPTR1((PyArrayObject *)plot_samples, 0);
pt = (double*)PyArray_GETPTR1((PyArrayObject *)plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1((PyArrayObject *)timestamps, 0);

int current_pos = 0, stop_index = count - 1;
for (int i = 0; i < (int)count; i++) {
Expand Down Expand Up @@ -744,15 +744,15 @@ void positions_unsigned_short(PyObject* samples, PyObject* timestamps, PyObject*
long* outdata;
int pos_min = 0, pos_max = 0;

indata = (unsigned short *)PyArray_GETPTR1(samples, 0);
outdata = (long*)PyArray_GETPTR1(result, 0);
indata = (unsigned short *)PyArray_GETPTR1((PyArrayObject *)samples, 0);
outdata = (long*)PyArray_GETPTR1((PyArrayObject *)result, 0);

unsigned short* ps;
double tmin, tmax, * ts, * pt;

ps = (unsigned short*)PyArray_GETPTR1(plot_samples, 0);
pt = (double*)PyArray_GETPTR1(plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1(timestamps, 0);
ps = (unsigned short*)PyArray_GETPTR1((PyArrayObject *)plot_samples, 0);
pt = (double*)PyArray_GETPTR1((PyArrayObject *)plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1((PyArrayObject *)timestamps, 0);

int current_pos = 0, stop_index = count - 1;
for (int i = 0; i < (int)count; i++) {
Expand Down Expand Up @@ -814,15 +814,15 @@ void positions_unsigned_long(PyObject* samples, PyObject* timestamps, PyObject*
long* outdata;
int pos_min = 0, pos_max = 0;

indata = (unsigned long*)PyArray_GETPTR1(samples, 0);
outdata = (long*)PyArray_GETPTR1(result, 0);
indata = (unsigned long*)PyArray_GETPTR1((PyArrayObject *)samples, 0);
outdata = (long*)PyArray_GETPTR1((PyArrayObject *)result, 0);

unsigned long* ps;
double tmin, tmax, * ts, * pt;

ps = (unsigned long*)PyArray_GETPTR1(plot_samples, 0);
pt = (double*)PyArray_GETPTR1(plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1(timestamps, 0);
ps = (unsigned long*)PyArray_GETPTR1((PyArrayObject *)plot_samples, 0);
pt = (double*)PyArray_GETPTR1((PyArrayObject *)plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1((PyArrayObject *)timestamps, 0);

int current_pos = 0, stop_index = count - 1;
for (int i = 0; i < (int)count; i++) {
Expand Down Expand Up @@ -884,15 +884,15 @@ void positions_unsigned_long_long(PyObject* samples, PyObject* timestamps, PyObj
long* outdata;
int pos_min = 0, pos_max = 0;

indata = (unsigned long long *)PyArray_GETPTR1(samples, 0);
outdata = (long*)PyArray_GETPTR1(result, 0);
indata = (unsigned long long *)PyArray_GETPTR1((PyArrayObject *)samples, 0);
outdata = (long*)PyArray_GETPTR1((PyArrayObject *)result, 0);

unsigned long long* ps;
double tmin, tmax, * ts, * pt;

ps = (unsigned long long*)PyArray_GETPTR1(plot_samples, 0);
pt = (double*)PyArray_GETPTR1(plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1(timestamps, 0);
ps = (unsigned long long*)PyArray_GETPTR1((PyArrayObject *)plot_samples, 0);
pt = (double*)PyArray_GETPTR1((PyArrayObject *)plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1((PyArrayObject *)timestamps, 0);

int current_pos = 0, stop_index = count - 1;
for (int i = 0; i < (int)count; i++) {
Expand Down Expand Up @@ -954,15 +954,15 @@ void positions_float(PyObject* samples, PyObject* timestamps, PyObject* plot_sam
long* outdata= NULL;
int pos_min = 0, pos_max = 0;

indata = (float*)PyArray_GETPTR1(samples, 0);
outdata = (long*)PyArray_GETPTR1(result, 0);
indata = (float*)PyArray_GETPTR1((PyArrayObject *)samples, 0);
outdata = (long*)PyArray_GETPTR1((PyArrayObject *)result, 0);

float* ps;
double tmin, tmax, * ts, * pt;

ps = (float*)PyArray_GETPTR1(plot_samples, 0);
pt = (double*)PyArray_GETPTR1(plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1(timestamps, 0);
ps = (float*)PyArray_GETPTR1((PyArrayObject *)plot_samples, 0);
pt = (double*)PyArray_GETPTR1((PyArrayObject *)plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1((PyArrayObject *)timestamps, 0);

int current_pos = 0, stop_index = count - 1;
for (int i = 0; i < (int)count; i++) {
Expand Down Expand Up @@ -1020,19 +1020,19 @@ void positions_float(PyObject* samples, PyObject* timestamps, PyObject* plot_sam

void positions_double(PyObject* samples, PyObject* timestamps, PyObject* plot_samples, PyObject* plot_timestamps, PyObject* result, long step, long count, long last)
{
double min, max, val, * indata=NULL;
double min, max, * indata=NULL;
long* outdata = NULL;
int pos_min = 0, pos_max = 0;

indata = (double*)PyArray_GETPTR1(samples, 0);
outdata = (long*)PyArray_GETPTR1(result, 0);
indata = (double*)PyArray_GETPTR1((PyArrayObject *)samples, 0);
outdata = (long*)PyArray_GETPTR1((PyArrayObject *)result, 0);

double* ps = NULL;
double tmin, tmax, * ts = NULL, * pt = NULL;

ps = (double*)PyArray_GETPTR1(plot_samples, 0);
pt = (double*)PyArray_GETPTR1(plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1(timestamps, 0);
ps = (double*)PyArray_GETPTR1((PyArrayObject *)plot_samples, 0);
pt = (double*)PyArray_GETPTR1((PyArrayObject *)plot_timestamps, 0);
ts = (double*)PyArray_GETPTR1((PyArrayObject *)timestamps, 0);

int current_pos = 0, stop_index = count - 1;
for (int i = 0; i < (int)count; i++) {
Expand Down Expand Up @@ -1251,6 +1251,50 @@ static PyObject* data_block_from_arrays(PyObject* self, PyObject* args)
}
}

static PyObject* get_idx_with_edges(PyObject* self, PyObject* args)
{
int i = 0;
PyObject *idx=NULL;
PyArrayObject *result=NULL;

uint8_t *out_array, * idx_array, previous=1, current=0;


if (!PyArg_ParseTuple(args, "O", &idx))
{
return 0;
}
else
{
npy_intp dims[1], count;
count = PyArray_SIZE((PyArrayObject *)idx);
dims[0] = count;
result = PyArray_ZEROS(1, dims, NPY_BOOL, 0);

idx_array = (uint8_t *)PyArray_GETPTR1((PyArrayObject *)idx, 0);
out_array = (uint8_t *)PyArray_GETPTR1(result, 0);

for (i = 0; i < count; i++, idx_array++, out_array++)
{
current = *idx_array;
if (current) {
if (current != previous) {
*(out_array-1) = 1;
}
*out_array = 1;
}
else {
if (current != previous && i) {
*(out_array-1) = 0;
}
}
previous = current;
}
}

return (PyObject *) result;
}


// Our Module's Function Definition struct
// We require this `NULL` to signal the end of our method
Expand All @@ -1265,6 +1309,8 @@ static PyMethodDef myMethods[] =
{ "positions", positions, METH_VARARGS, "positions" },
{ "get_channel_raw_bytes", get_channel_raw_bytes, METH_VARARGS, "get_channel_raw_bytes" },
{ "data_block_from_arrays", data_block_from_arrays, METH_VARARGS, "data_block_from_arrays" },
{ "get_idx_with_edges", get_idx_with_edges, METH_VARARGS, "get_idx_with_edges" },


{ NULL, NULL, 0, NULL }
};
Expand Down
2 changes: 1 addition & 1 deletion src/asammdf/blocks/mdf_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -7989,7 +7989,7 @@ def _yield_selected_signals(
if group_index == index:
master_index = idx

encodings = {group_index: [None] for groups_index in groups}
encodings = {group_index: [None] for group_index in groups}

self._set_temporary_master(None)
idx = 0
Expand Down
6 changes: 3 additions & 3 deletions src/asammdf/blocks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ def components(

values = channel[name]
if values.dtype.byteorder not in target_byte_order:
values = values.byteswap().newbyteorder()
values = values.view(values.dtype.newbyteorder())

if len(values.shape) > 1:
values = Series(
Expand All @@ -1406,7 +1406,7 @@ def components(
values = channel[name]

if values.dtype.byteorder not in target_byte_order:
values = values.byteswap().newbyteorder()
values = values.view(values.dtype.newbyteorder())

if not only_basenames:
axis_name = unique_names.get_unique_name(f"{name_}.{name}")
Expand Down Expand Up @@ -1442,7 +1442,7 @@ def components(

else:
if values.dtype.byteorder not in target_byte_order:
values = values.byteswap().newbyteorder()
values = values.view(values.dtype.newbyteorder())

if not only_basenames:
name_ = unique_names.get_unique_name(
Expand Down
8 changes: 4 additions & 4 deletions src/asammdf/blocks/v4_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3129,7 +3129,7 @@ def convert(self, values, as_object=False, as_bytes=False, ignore_value2text_con
vals = vals * a
if b:
vals += b
values = np.core.records.fromarrays(
values = np.rec.fromarrays(
[vals] + [values[name] for name in names[1:]],
dtype=[(name, vals.dtype, vals.shape[1:])]
+ [(name, values[name].dtype, values[name].shape[1:]) for name in names[1:]],
Expand Down Expand Up @@ -3167,7 +3167,7 @@ def convert(self, values, as_object=False, as_bytes=False, ignore_value2text_con
except TypeError:
vals = (P1 * X**2 + P2 * X + P3) / (P4 * X**2 + P5 * X + P6)

values = np.core.records.fromarrays(
values = np.rec.fromarrays(
[vals] + [values[name] for name in names[1:]],
dtype=[(name, vals.dtype, vals.shape[1:])]
+ [(name, values[name].dtype, values[name].shape[1:]) for name in names[1:]],
Expand Down Expand Up @@ -3349,7 +3349,7 @@ def convert(self, values, as_object=False, as_bytes=False, ignore_value2text_con
ret = ret.astype(bytes)

ret = ret.reshape(shape)
values = np.core.records.fromarrays(
values = np.rec.fromarrays(
[ret] + [values[name] for name in names[1:]],
dtype=[(name, ret.dtype, ret.shape[1:])]
+ [(name, values[name].dtype, values[name].shape[1:]) for name in names[1:]],
Expand Down Expand Up @@ -3521,7 +3521,7 @@ def convert(self, values, as_object=False, as_bytes=False, ignore_value2text_con
ret = np.array(ret, dtype=bytes)

ret = ret.reshape(shape)
values = np.core.records.fromarrays(
values = np.rec.fromarrays(
[ret] + [values[name] for name in names[1:]],
dtype=[(name, ret.dtype, ret.shape[1:])]
+ [(name, values[name].dtype, values[name].shape[1:]) for name in names[1:]],
Expand Down
6 changes: 6 additions & 0 deletions src/asammdf/gui/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
import os

os.environ["QT_API"] = "pyside6"
os.environ["PYQTGRAPH_QT_LIB"] = "PySide6"

if "QT_ENABLE_HIGHDPI_SCALING" not in os.environ:
os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "1"
Loading

0 comments on commit 9fd3321

Please sign in to comment.