提交 a14f9164 authored 作者: Ian Goodfellow's avatar Ian Goodfellow

made cnda_ensure_contiguous do more cleanup so the client doesn't have

to
上级 9b9f7afb
...@@ -4532,15 +4532,26 @@ void fprint_CudaNdarray(FILE * fd, const CudaNdarray *self) ...@@ -4532,15 +4532,26 @@ void fprint_CudaNdarray(FILE * fd, const CudaNdarray *self)
int CudaNdarray_ensure_contiguous(CudaNdarray ** arr, int nd, int CudaNdarray_ensure_contiguous(CudaNdarray ** arr, int nd,
const int * dims) const int * dims)
{ {
bool allocated = false;
if (*arr == NULL) if (*arr == NULL)
{ {
// This allocates the metadata but not the data // This allocates the metadata but not the data
*arr = (CudaNdarray *) CudaNdarray_new_nd(nd); *arr = (CudaNdarray *) CudaNdarray_new_nd(nd);
if (*arr == NULL) if (*arr == NULL)
return -1; return -1;
allocated = true;
} }
return CudaNdarray_alloc_contiguous(*arr, nd, dims); if (CudaNdarray_alloc_contiguous(*arr, nd, dims))
{
if (allocated)
{
Py_DECREF(*arr);
*arr = NULL;
}
return -1;
}
return 0;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论