Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: You can not borrow a temporary array. #1971

Merged
merged 1 commit into from
Jun 10, 2017

Conversation

boeddeker
Copy link
Contributor

When np.ascontiguousarray is called a temporary array is created. This will be deleted after the function and cntk can not borrow the array without holding the object.

Here some example code to produce the bug (may need more the one execution):

import cntk
import numpy as np

np_array = np.ones((6, 400, 513))
y = cntk.cntk_py.NDArrayView(np_array, cntk.device.use_default_device(), False, True)

del np_array

from time import sleep
sleep(0.05)

print(y.to_ndarray())

The error happen, when the input for a cntk function is not c contiguous.

@boeddeker
Copy link
Contributor Author

I have a better idea to fix this bug.
Store the numpy array as a property of the view. In this way it is guarantied, that the live time of the array is long enough and there is no copy overhead.

import numpy as np
from cntk.core import NDArrayView
x0 = np.ones(shape=(1000))
v = NDArrayView.from_dense(x0, borrow=True)
v.ndarray = x0  # store the numpy array as property of the view. 
del x0
import time
time.sleep(0.1)
v.asarray().tolist()  # always a one array
x0 = np.ones(shape=(1000))
v = NDArrayView.from_dense(x0, borrow=True)
# v.ndarray = x0
del x0
import time
time.sleep(0.1)
v.asarray().tolist()  # the first values are always wrong

@cha-zhang cha-zhang merged commit 40eb91e into microsoft:master Jun 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants