Skip to content

Commit 857cdfa

Browse files
committed
FastDSS: respect order and tweak handling of complex numbers
1 parent 87ea39a commit 857cdfa

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

src/_fastdss.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ static PyObject *AltDSS_PyGRGetter_call(AltDSS_PyGRGetterObject *f, PyObject *ar
459459
{
460460
PyObject *result = NULL;
461461
PyObject *item = NULL;
462+
NPY_ORDER order = NPY_ANYORDER;
462463
double float64Arg1, float64Arg2;
463464
int argValue = 0;
464465
int32_t resType = f->resType;
@@ -523,14 +524,22 @@ static PyObject *AltDSS_PyGRGetter_call(AltDSS_PyGRGetterObject *f, PyObject *ar
523524
}
524525

525526
nitems = f->countPtr[0];
526-
if ((f->countPtr[2] == 0) || ((settings & FastDSSSettings_AdvancedTypes) == 0))
527+
if (((settings & FastDSSSettings_AdvancedTypes) == 0))
527528
{
528529
dims[0] = nitems;
529530
if (resType == fastdss_types_gr_z128s)
530531
{
531532
resType = fastdss_types_gr_f64s;
532533
}
533534
}
535+
else if (f->countPtr[2] == 0)
536+
{
537+
if (resType == fastdss_types_gr_z128s)
538+
{
539+
nitems /= 2;
540+
}
541+
dims[0] = nitems;
542+
}
534543
else
535544
{
536545
nd = 2;
@@ -540,6 +549,7 @@ static PyObject *AltDSS_PyGRGetter_call(AltDSS_PyGRGetterObject *f, PyObject *ar
540549
{
541550
nitems /= 2;
542551
}
552+
order = NPY_FORTRANORDER;
543553
}
544554

545555
if (!(settings & FastDSSSettings_UseLists))
@@ -559,7 +569,7 @@ static PyObject *AltDSS_PyGRGetter_call(AltDSS_PyGRGetterObject *f, PyObject *ar
559569
PyErr_SetString(PyExc_RuntimeError, "Unexpected number of elements returned by API (array of complex numbers).");
560570
return NULL;
561571
}
562-
result = PyArray_SimpleNew(nd, dims, NPY_COMPLEX128);
572+
result = PyArray_EMPTY(nd, dims, NPY_COMPLEX128, order);
563573
if (result == NULL)
564574
{
565575
return NULL;
@@ -570,7 +580,7 @@ static PyObject *AltDSS_PyGRGetter_call(AltDSS_PyGRGetterObject *f, PyObject *ar
570580
memcpy(data, *(double**)f->dataPtr, 2 * sizeof(double) * nitems);
571581
return result;
572582
case fastdss_types_gr_f64s:
573-
result = PyArray_SimpleNew(nd, dims, NPY_FLOAT64);
583+
result = PyArray_EMPTY(nd, dims, NPY_FLOAT64, order);
574584
if (result == NULL)
575585
{
576586
return NULL;
@@ -581,12 +591,12 @@ static PyObject *AltDSS_PyGRGetter_call(AltDSS_PyGRGetterObject *f, PyObject *ar
581591
memcpy(data, *(double**)f->dataPtr, sizeof(double) * nitems);
582592
return result;
583593
// case fastdss_types_f32:
584-
// result = PyArray_SimpleNew(nd, dims, NPY_FLOAT32);
594+
// result = PyArray_EMPTY(nd, dims, NPY_FLOAT32, order);
585595
// memcpy(data, f->dataPtr[0], *(float**)f->dataPtr, sizeof(float) * nitems);
586596
// data = PyArray_DATA(result);
587597
// return result;
588598
case fastdss_types_gr_i32s:
589-
result = PyArray_SimpleNew(nd, dims, NPY_INT32);
599+
result = PyArray_EMPTY(nd, dims, NPY_INT32, order);
590600
if (result == NULL)
591601
{
592602
return NULL;
@@ -597,7 +607,7 @@ static PyObject *AltDSS_PyGRGetter_call(AltDSS_PyGRGetterObject *f, PyObject *ar
597607
memcpy(data, *(int32_t**)f->dataPtr, sizeof(int32_t) * nitems);
598608
return result;
599609
case fastdss_types_gr_i8s:
600-
result = PyArray_SimpleNew(nd, dims, NPY_INT8);
610+
result = PyArray_EMPTY(nd, dims, NPY_INT8, order);
601611
if (result == NULL)
602612
{
603613
return NULL;

0 commit comments

Comments
 (0)