Skip to content

Commit 7fa8299

Browse files
authored
Merge pull request #9 from seberg/mpfdtype
BUG: (mpfdtype) The copyswap did not fix internal ref
2 parents eae6240 + ec19661 commit 7fa8299

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

mpfdtype/mpfdtype/src/casts.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ mpf_to_mpf_resolve_descriptors(
5151

5252

5353
static int
54-
mpf_to_mof_strided_loop(PyArrayMethod_Context *context,
54+
mpf_to_mpf_strided_loop(PyArrayMethod_Context *context,
5555
char *const data[], npy_intp const dimensions[],
5656
npy_intp const strides[], void *NPY_UNUSED(auxdata))
5757
{
@@ -395,9 +395,9 @@ init_casts_internal(void)
395395
PyType_Slot *mpf2mpf_slots = new PyType_Slot [4]{
396396
{NPY_METH_resolve_descriptors,
397397
(void *)&mpf_to_mpf_resolve_descriptors},
398-
{NPY_METH_strided_loop, (void *)&mpf_to_mof_strided_loop},
398+
{NPY_METH_strided_loop, (void *)&mpf_to_mpf_strided_loop},
399399
/* We don't actually support unaligned access... */
400-
{NPY_METH_unaligned_strided_loop, (void *)&mpf_to_mof_strided_loop},
400+
{NPY_METH_unaligned_strided_loop, (void *)&mpf_to_mpf_strided_loop},
401401
{0, nullptr}
402402
};
403403

mpfdtype/mpfdtype/src/terrible_hacks.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ copyswap_mpf(char *dst, char *src, int swap, PyArrayObject *ap)
2727
/* Note that it is probably better to only get the descr from `ap` */
2828
PyArray_Descr *descr = PyArray_DESCR(ap);
2929

30+
/* copy data and then fix significand (could also do same as cast...) */
3031
memcpy(dst, src, descr->elsize);
32+
// TODO: To support unaligned data, only need to do this if it is aligned:
33+
mpfr_custom_move((mpfr_ptr)dst, ((mpf_field *)dst)->significand);
3134
}
3235

3336

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
3+
import sys
4+
import numpy as np
5+
import operator
6+
from numpy.testing import assert_array_equal
7+
8+
from mpfdtype import MPFDType, MPFloat
9+
10+
11+
def test_advanced_indexing():
12+
# As of writing the test, this relies on copyswap
13+
arr = np.arange(100).astype(MPFDType(100))
14+
orig = np.arange(100).astype(MPFDType(100)) # second one, not a copy
15+
16+
b = arr[[1, 2, 3, 4]]
17+
b[...] = 5 # does not mutate arr (internal references not broken)
18+
assert_array_equal(arr, orig)

0 commit comments

Comments
 (0)