-
Notifications
You must be signed in to change notification settings - Fork 637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
MAINT: shims for array copy semantics #4482
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ cdef class ArrayWrapper: | |
self.data_type = data_type | ||
self.ndim = ndim | ||
|
||
def __array__(self): | ||
def __array__(self, copy=None): | ||
""" Here we use the __array__ method, that is called when numpy | ||
tries to get an array from the object.""" | ||
ndarray = cnp.PyArray_SimpleNewFromData(self.ndim, | ||
|
@@ -110,7 +110,11 @@ cdef cnp.ndarray ptr_to_ndarray(void* data_ptr, cnp.int64_t[:] dim, int data_typ | |
array_wrapper = ArrayWrapper() | ||
array_wrapper.set_data(<void*> data_ptr, <int*> &dim[0], dim.size, data_type) | ||
|
||
cdef cnp.ndarray ndarray = np.array(array_wrapper, copy=False) | ||
if np.__version__[0] == "2": | ||
copy = None | ||
else: | ||
copy = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A more concise/idiomatic upstream approach was applied in the revised version of my patch in case we care about that: https://github.com/scipy/scipy/pull/20172/files#diff-d28fbb0be287769c763ce61b0695feb0a6ca0e67b28bafee20526b46be7aaa84R59 Basically, abstracting the check to avoid duplication and using |
||
cdef cnp.ndarray ndarray = np.array(array_wrapper, copy=copy) | ||
# Assign our object to the 'base' of the ndarray object | ||
ndarray[:] = array_wrapper.__array__() | ||
# Increment the reference count, as the above assignement was done in | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -325,8 +325,12 @@ | |
M = np.identity(4) | ||
M[:3, :3] = R | ||
if point is not None: | ||
if np.__version__[0] == "2": | ||
copy = None | ||
else: | ||
copy = False | ||
# rotation not around origin | ||
point = np.array(point[:3], dtype=np.float64, copy=False) | ||
point = np.array(point[:3], dtype=np.float64, copy=copy) | ||
M[:3, 3] = point - np.dot(R, point) | ||
return M | ||
|
||
|
@@ -497,7 +501,11 @@ | |
|
||
""" | ||
M = np.identity(4) | ||
point = np.array(point[:3], dtype=np.float64, copy=False) | ||
if np.__version__[0] == "2": | ||
copy = None | ||
else: | ||
copy = False | ||
point = np.array(point[:3], dtype=np.float64, copy=copy) | ||
normal = unit_vector(normal[:3]) | ||
if perspective is not None: | ||
# perspective projection | ||
|
@@ -515,7 +523,7 @@ | |
M[3, 3] = np.dot(perspective, normal) | ||
elif direction is not None: | ||
# parallel projection | ||
direction = np.array(direction[:3], dtype=np.float64, copy=False) | ||
direction = np.array(direction[:3], dtype=np.float64, copy=copy) | ||
scale = np.dot(direction, normal) | ||
M[:3, :3] -= np.outer(direction, normal) / scale | ||
M[:3, 3] = direction * (np.dot(point, normal) / scale) | ||
|
@@ -970,8 +978,12 @@ | |
True | ||
|
||
""" | ||
v0 = np.array(v0, dtype=np.float64, copy=False)[:3] | ||
v1 = np.array(v1, dtype=np.float64, copy=False)[:3] | ||
if np.__version__[0] == "2": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to wrap this in a helper routine to avoid repetition eg: v0 = np.array(v0, dtype=np.float64, copy=no_copy_shim())[:3]
def no_copy_shim():
if np.__version__[0] == "2":
copy=None
else:
copy=False
... Ill leave it up to you @tylerjereddy? |
||
copy = None | ||
else: | ||
copy = False | ||
v0 = np.array(v0, dtype=np.float64, copy=copy)[:3] | ||
v1 = np.array(v1, dtype=np.float64, copy=copy)[:3] | ||
|
||
if v0.shape != v1.shape or v0.shape[1] < 3: | ||
raise ValueError("vector sets are of wrong shape or type") | ||
|
@@ -1314,7 +1326,11 @@ | |
True | ||
|
||
""" | ||
M = np.array(matrix, dtype=np.float64, copy=False)[:4, :4] | ||
if np.__version__[0] == "2": | ||
copy = None | ||
else: | ||
copy = False | ||
M = np.array(matrix, dtype=np.float64, copy=copy)[:4, :4] | ||
if isprecise: | ||
q = np.empty((4, ), dtype=np.float64) | ||
t = np.trace(M) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here and elswhere we should probably also add
dtype=None
beforecopy=None
, similar to the revisions added in my PR upstream at: scipy/scipy#20172It doesn't seem to matter for testing purposes at the moment, but adding the
dtype=None
is more formally correct now.