提交 5255f58c authored 作者: Frederic's avatar Frederic

Changed *->dimensions to PyArray_DIMS(*) to use the new numpy interface.

上级 5a48dea2
......@@ -65,21 +65,21 @@ class BROKEN_ON_PURPOSE_Add(gof.Op):
if (%(b)s->descr->type_num != NPY_DOUBLE)
{PyErr_SetString(PyExc_NotImplementedError, "b's dtype not NPY_DOUBLE"); %(fail)s;}
if (%(a)s->dimensions[0] != %(b)s->dimensions[0])
if (PyArray_DIMS(%(a)s)[0] != PyArray_DIMS(%(b)s)[0])
{PyErr_SetString(PyExc_NotImplementedError, "a and b have different lengths"); %(fail)s;}
if ((!%(z)s)
|| (%(z)s->dimensions[0] != %(b)s->dimensions[0])
|| (PyArray_DIMS(%(z)s)[0] != PyArray_DIMS(%(b)s)[0])
)
{
{Py_XDECREF(%(z)s);}
npy_intp dims[] = {0};
dims[0] = %(b)s->dimensions[0];
dims[0] = PyArray_DIMS(%(b)s)[0];
%(z)s = (PyArrayObject*) PyArray_SimpleNew(1, dims, %(b)s->descr->type_num);
}
{
for (npy_intp m = 0; m < %(z)s->dimensions[0]; ++m)
for (npy_intp m = 0; m < PyArray_DIMS(%(z)s)[0]; ++m)
{
((double*)PyArray_GETPTR1(%(z)s, m))[0]
= 0.5
......@@ -150,11 +150,11 @@ class WeirdBrokenOp(gof.Op):
else:
z_code = """
{Py_XDECREF(%(z)s);}
%(z)s = (PyArrayObject*) PyArray_SimpleNew(1, %(a)s->dimensions, %(a)s->descr->type_num);
%(z)s = (PyArrayObject*) PyArray_SimpleNew(1, PyArray_DIMS(%(a)s), %(a)s->descr->type_num);
"""
prep_vars = """
//the output array has size M x N
npy_intp M = %(a)s->dimensions[0];
npy_intp M = PyArray_DIMS(%(a)s)[0];
npy_intp Sa = %(a)s->strides[0] / %(a)s->descr->elsize;
npy_intp Sz = %(z)s->strides[0] / %(z)s->descr->elsize;
......@@ -612,13 +612,13 @@ class BrokenCImplementationAdd(gof.Op):
if (%(b)s->descr->type_num != NPY_FLOAT)
{PyErr_SetString(PyExc_NotImplementedError, "b's dtype not NPY_FLOAT"); %(fail)s;}
if (%(a)s->dimensions[0] != %(a)s->dimensions[1])
if (PyArray_DIMS(%(a)s)[0] != PyArray_DIMS(%(a)s)[1])
{PyErr_SetString(PyExc_NotImplementedError, "a is not square"); %(fail)s;}
if (%(b)s->dimensions[0] != %(b)s->dimensions[1])
if (PyArray_DIMS(%(b)s)[0] != PyArray_DIMS(%(b)s)[1])
{PyErr_SetString(PyExc_NotImplementedError, "b is not square"); %(fail)s;}
if (%(a)s->dimensions[0] != %(b)s->dimensions[0])
if (PyArray_DIMS(%(a)s)[0] != PyArray_DIMS(%(b)s)[0])
{PyErr_SetString(PyExc_NotImplementedError, "a and b have different dimensions"); %(fail)s;}
// We do not check for c_contiguous property here
......@@ -626,32 +626,32 @@ class BrokenCImplementationAdd(gof.Op):
{
if (!%(z)s)
printf("%(z)s is not there, %%p \\n", %(z)s);
else if (%(z)s->dimensions[0] != %(b)s->dimensions[0])
else if (PyArray_DIMS(%(z)s)[0] != PyArray_DIMS(%(b)s)[0])
printf("Dimension 0 mismatch for %(z)s and %(b)s\\n");
else if (%(z)s->dimensions[1] != %(b)s->dimensions[1])
else if (PyArray_DIMS(%(z)s)[1] != PyArray_DIMS(%(b)s)[1])
printf("Dimension 1 mismatch for %(z)s and %(b)s\\n");
else
printf("Reusing %(z)s\\n");
}
if ((!%(z)s)
|| (%(z)s->dimensions[0] != %(b)s->dimensions[0])
|| (%(z)s->dimensions[1] != %(b)s->dimensions[1])
|| (PyArray_DIMS(%(z)s)[0] != PyArray_DIMS(%(b)s)[0])
|| (PyArray_DIMS(%(z)s)[1] != PyArray_DIMS(%(b)s)[1])
)
{
Py_XDECREF(%(z)s);
npy_intp dims[] = {0, 0};
dims[0] = %(b)s->dimensions[0];
dims[1] = %(b)s->dimensions[1];
dims[0] = PyArray_DIMS(%(b)s)[0];
dims[1] = PyArray_DIMS(%(b)s)[1];
%(z)s = (PyArrayObject*) PyArray_SimpleNew(2, dims, %(b)s->descr->type_num);
}
// Let us assume that %(z)s is c_contiguous
{
dtype_%(z)s * z = ((dtype_%(z)s*)(PyArray_GETPTR2(%(z)s,0,0)));
for (int i=0; i<%(b)s->dimensions[0]; i++)
for (int i=0; i<PyArray_DIMS(%(b)s)[0]; i++)
{
for (int j=0; j<%(b)s->dimensions[1]; j++)
for (int j=0; j<PyArray_DIMS(%(b)s)[1]; j++)
{
*z = ((float*)PyArray_GETPTR2(%(a)s, i, j))[0] +
((float*)PyArray_GETPTR2(%(b)s, i, j))[0] ;
......
......@@ -214,7 +214,7 @@ class GpuImages2Neibs(Images2Neibs, GpuOp):
%(fail)s;
}
if (%(neib_shape)s->dimensions[0] != 2)
if (PyArray_DIMS(%(neib_shape)s)[0] != 2)
{
PyErr_Format(PyExc_ValueError,
"neib_shape has to contain two elements");
......
......@@ -66,20 +66,20 @@ class MultinomialFromUniform(Op):
%(fail)s;
}
if (%(unis)s->dimensions[0] != %(pvals)s->dimensions[0])
if (PyArray_DIMS(%(unis)s)[0] != PyArray_DIMS(%(pvals)s)[0])
{
PyErr_Format(PyExc_ValueError, "unis.shape[0] != pvals.shape[0]");
%(fail)s;
}
if ((NULL == %(z)s)
|| ((%(z)s->dimensions)[0] != (%(pvals)s->dimensions)[0])
|| ((%(z)s->dimensions)[1] != (%(pvals)s->dimensions)[1])
|| ((PyArray_DIMS(%(z)s))[0] != (PyArray_DIMS(%(pvals)s))[0])
|| ((PyArray_DIMS(%(z)s))[1] != (PyArray_DIMS(%(pvals)s))[1])
)
{
Py_XDECREF(%(z)s);
%(z)s = (PyArrayObject*) PyArray_ZEROS(2,
%(pvals)s->dimensions,
PyArray_DIMS(%(pvals)s),
type_num_%(z)s,
0);
if (!%(z)s)
......@@ -91,8 +91,8 @@ class MultinomialFromUniform(Op):
{ // NESTED SCOPE
const int nb_multi = %(pvals)s->dimensions[0];
const int nb_outcomes = %(pvals)s->dimensions[1];
const int nb_multi = PyArray_DIMS(%(pvals)s)[0];
const int nb_outcomes = PyArray_DIMS(%(pvals)s)[1];
//
// For each multinomial, loop over each possible outcome
......
......@@ -124,7 +124,7 @@ class Images2Neibs(Op):
PyErr_Format(PyExc_TypeError, "neib_shape wrong rank");
%(fail)s;
}
if ( (%(neib_shape)s->dimensions)[0] != 2)
if ( (PyArray_DIMS(%(neib_shape)s))[0] != 2)
{
PyErr_Format(PyExc_TypeError, "neib_shape wrong shape ; has to"
" contain 2 elements");
......@@ -135,7 +135,7 @@ class Images2Neibs(Op):
PyErr_Format(PyExc_TypeError, "neib_step wrong rank");
%(fail)s;
}
if ( (%(neib_step)s->dimensions)[0] != 2)
if ( (PyArray_DIMS(%(neib_step)s))[0] != 2)
{
PyErr_Format(PyExc_TypeError,
"neib_step wrong step ; has to contain 2 elements");
......@@ -154,33 +154,33 @@ class Images2Neibs(Op):
PyErr_Format(PyExc_TypeError, "Images2Neibs: in mode wrap_centered need patch with odd shapes");
%(fail)s;
}
if ( (%(ten4)s->dimensions)[2] < c || (%(ten4)s->dimensions)[3] < d)
if ( (PyArray_DIMS(%(ten4)s))[2] < c || (PyArray_DIMS(%(ten4)s))[3] < d)
{
PyErr_Format(PyExc_TypeError, "Images2Neibs: in wrap_centered mode, don't support image shapes smaller then the patch shapes: neib_shape=(%%ld,%%ld), ten4[2:]=[%%ld,%%ld]",
(long int)c, (long int)d, (long int)(%(ten4)s->dimensions[2]), (long int)(%(ten4)s->dimensions[3]));
(long int)c, (long int)d, (long int)(PyArray_DIMS(%(ten4)s)[2]), (long int)(PyArray_DIMS(%(ten4)s)[3]));
%(fail)s;
}
grid_c = CEIL_INTDIV(((%(ten4)s->dimensions)[2]),step_x);
grid_d = CEIL_INTDIV(((%(ten4)s->dimensions)[3]),step_y);
grid_c = CEIL_INTDIV(((PyArray_DIMS(%(ten4)s))[2]),step_x);
grid_d = CEIL_INTDIV(((PyArray_DIMS(%(ten4)s))[3]),step_y);
}else if ( "%(mode)s" == "valid") {
if ( ((%(ten4)s->dimensions)[2] < c) ||( (((%(ten4)s->dimensions)[2]-c) %% step_x)!=0))
if ( ((PyArray_DIMS(%(ten4)s))[2] < c) ||( (((PyArray_DIMS(%(ten4)s))[2]-c) %% step_x)!=0))
{
PyErr_Format(PyExc_TypeError, "neib_shape[0]=%%ld, neib_step[0]=%%ld and ten4.shape[2]=%%ld not consistent",
(long int)c, (long int)step_x, (long int)(%(ten4)s->dimensions[2]));
(long int)c, (long int)step_x, (long int)(PyArray_DIMS(%(ten4)s)[2]));
%(fail)s;
}
if ( ((%(ten4)s->dimensions)[3] < d) ||( (((%(ten4)s->dimensions)[3]-d) %% step_y)!=0))
if ( ((PyArray_DIMS(%(ten4)s))[3] < d) ||( (((PyArray_DIMS(%(ten4)s))[3]-d) %% step_y)!=0))
{
PyErr_Format(PyExc_TypeError, "neib_shape[1]=%%ld, neib_step[1]=%%ld and ten4.shape[3]=%%ld not consistent",
(long int)d, (long int)step_y, (long int)(%(ten4)s->dimensions[3]));
(long int)d, (long int)step_y, (long int)(PyArray_DIMS(%(ten4)s)[3]));
%(fail)s;
}
grid_c = 1+(((%(ten4)s->dimensions)[2]-c)/step_x); //number of patch in height
grid_d = 1+(((%(ten4)s->dimensions)[3]-d)/step_y); //number of patch in width
grid_c = 1+(((PyArray_DIMS(%(ten4)s))[2]-c)/step_x); //number of patch in height
grid_d = 1+(((PyArray_DIMS(%(ten4)s))[3]-d)/step_y); //number of patch in width
}else if ( "%(mode)s" == "ignore_borders") {
grid_c = 1+(((%(ten4)s->dimensions)[2]-c)/step_x); //number of patch in height
grid_d = 1+(((%(ten4)s->dimensions)[3]-d)/step_y); //number of patch in width
grid_c = 1+(((PyArray_DIMS(%(ten4)s))[2]-c)/step_x); //number of patch in height
grid_d = 1+(((PyArray_DIMS(%(ten4)s))[3]-d)/step_y); //number of patch in width
}else{
PyErr_Format(PyExc_TypeError, "Images2Neibs: unknow mode '%(mode)s'");
%(fail)s;
......@@ -190,12 +190,12 @@ class Images2Neibs(Op):
const npy_intp z_dim1 = c * d;
const npy_intp z_dim0 = grid_c
* grid_d
* (%(ten4)s->dimensions)[1]
* (%(ten4)s->dimensions)[0];
* (PyArray_DIMS(%(ten4)s))[1]
* (PyArray_DIMS(%(ten4)s))[0];
if ((NULL == %(z)s)
|| ((%(z)s->dimensions)[0] != z_dim0 )
|| ((%(z)s->dimensions)[1] != z_dim1 )
|| ((PyArray_DIMS(%(z)s))[0] != z_dim0 )
|| ((PyArray_DIMS(%(z)s))[1] != z_dim1 )
)
{
Py_XDECREF(%(z)s);
......@@ -218,10 +218,10 @@ class Images2Neibs(Op):
{ // NESTED SCOPE
const int nb_batch = (%(ten4)s->dimensions)[0];
const int nb_stack = (%(ten4)s->dimensions)[1];
const int height = (%(ten4)s->dimensions)[2];
const int width = (%(ten4)s->dimensions)[3];
const int nb_batch = (PyArray_DIMS(%(ten4)s))[0];
const int nb_stack = (PyArray_DIMS(%(ten4)s))[1];
const int height = (PyArray_DIMS(%(ten4)s))[2];
const int width = (PyArray_DIMS(%(ten4)s))[3];
// (c,d) = neib_shape
const npy_intp c = (npy_intp) *(dtype_%(neib_shape)s*) PyArray_GETPTR1(%(neib_shape)s, 0);
......
......@@ -266,10 +266,10 @@ class mrg_uniform(mrg_uniform_base):
PyErr_SetString(PyExc_ValueError, "size must be vector");
%(fail)s
}
if (%(size)s->dimensions[0] != %(ndim)s)
if (PyArray_DIMS(%(size)s)[0] != %(ndim)s)
{
PyErr_Format(PyExc_ValueError, "size must have length %%i (not %%i)",
%(ndim)s, int(%(size)s->dimensions[0]));
%(ndim)s, int(PyArray_DIMS(%(size)s)[0]));
%(fail)s
}
if (%(size)s->descr->type_num != NPY_INT32)
......@@ -281,7 +281,7 @@ class mrg_uniform(mrg_uniform_base):
{
odims[i] = ((npy_int32*)(%(size)s->data + %(size)s->strides[0] * i))[0];
n_elements *= odims[i];
must_alloc_sample = must_alloc_sample || (%(o_sample)s->dimensions[i] != odims[i]);
must_alloc_sample = must_alloc_sample || (PyArray_DIMS(%(o_sample)s)[i] != odims[i]);
//fprintf(stderr, "size %%i %%i\\n", i, (int)odims[i]);
}
if (must_alloc_sample)
......@@ -301,7 +301,7 @@ class mrg_uniform(mrg_uniform_base):
PyErr_SetString(PyExc_ValueError, "rstate must be matrix");
%(fail)s
}
if (%(o_rstate)s->dimensions[1] != 6)
if (PyArray_DIMS(%(o_rstate)s)[1] != 6)
{
PyErr_Format(PyExc_ValueError, "rstate must have 6 columns");
%(fail)s
......@@ -311,7 +311,7 @@ class mrg_uniform(mrg_uniform_base):
PyErr_SetString(PyExc_ValueError, "rstate must be int32");
%(fail)s
}
n_streams = %(o_rstate)s->dimensions[0];
n_streams = PyArray_DIMS(%(o_rstate)s)[0];
sample_data = (%(otype)s *) %(o_sample)s->data;
state_data = (npy_int32 *) %(o_rstate)s->data;
......@@ -508,10 +508,10 @@ class GPU_mrg_uniform(mrg_uniform_base, GpuOp):
PyErr_SetString(PyExc_ValueError, "size must be vector");
%(fail)s
}
if (%(size)s->dimensions[0] != %(ndim)s)
if (PyArray_DIMS(%(size)s)[0] != %(ndim)s)
{
PyErr_Format(PyExc_ValueError, "size must have length %%i (not %%i)",
%(ndim)s, %(size)s->dimensions[0]);
%(ndim)s, PyArray_DIMS(%(size)s)[0]);
%(fail)s
}
if (%(size)s->descr->type_num != NPY_INT32)
......
......@@ -3017,19 +3017,19 @@ class StructuredDotGradCSC(gof.Op):
if( %(_indptr)s->descr->type_num != NPY_INT32)
{PyErr_SetString(PyExc_NotImplementedError, "D"); %(fail)s;}
if( %(_d)s->dimensions[1] != %(_g)s->dimensions[1])
if( PyArray_DIMS(%(_d)s)[1] != PyArray_DIMS(%(_g)s)[1])
{PyErr_SetString(PyExc_NotImplementedError, "d and g have different numbers of columns"); %(fail)s;}
if (!%(_zout)s
|| (%(_zout)s->dimensions[0] != %(_indices)s->dimensions[0]))
|| (PyArray_DIMS(%(_zout)s)[0] != PyArray_DIMS(%(_indices)s)[0]))
{
Py_XDECREF(%(_zout)s);
%(_zout)s = (PyArrayObject*) PyArray_SimpleNew(1, %(_indices)s->dimensions, %(_g)s->descr->type_num);
%(_zout)s = (PyArrayObject*) PyArray_SimpleNew(1, PyArray_DIMS(%(_indices)s), %(_g)s->descr->type_num);
}
{ //makes it compile even though labels jump over variable definitions.
npy_intp nnz = %(_indices)s->dimensions[0];
npy_intp N = %(_indptr)s->dimensions[0]-1; //TODO: error checking with this
npy_intp nnz = PyArray_DIMS(%(_indices)s)[0];
npy_intp N = PyArray_DIMS(%(_indptr)s)[0]-1; //TODO: error checking with this
npy_intp Sindices = %(_indices)s->strides[0]/%(_indices)s->descr->elsize;
npy_intp Sindptr = %(_indptr)s->strides[0]/%(_indptr)s->descr->elsize;
......@@ -3037,7 +3037,7 @@ class StructuredDotGradCSC(gof.Op):
const npy_intp Sd1 = %(_d)s->strides[1]/%(_d)s->descr->elsize;
const npy_intp Sg1 = %(_g)s->strides[1]/%(_g)s->descr->elsize;
const npy_intp K = %(_d)s->dimensions[1];
const npy_intp K = PyArray_DIMS(%(_d)s)[1];
const npy_int32 * __restrict__ indptr = (npy_int32 *)%(_indptr)s->data;
const npy_int32 * __restrict__ indices = (npy_int32 *)%(_indices)s->data;
......@@ -3047,7 +3047,7 @@ class StructuredDotGradCSC(gof.Op):
{
// extract j-th row of dense matrix
const dtype_%(_d)s* __restrict__ d_row = (dtype_%(_d)s*)(%(_d)s->data + %(_d)s->strides[0] * j);
if(j >= %(_d)s->dimensions[0]) {PyErr_SetString(PyExc_NotImplementedError, "G"); %(fail)s;}
if(j >= PyArray_DIMS(%(_d)s)[0]) {PyErr_SetString(PyExc_NotImplementedError, "G"); %(fail)s;}
// for each non-null value in the sparse column
for (npy_int32 i_idx = indptr[j * Sindptr]; i_idx < indptr[(j+1) * Sindptr]; ++i_idx)
......@@ -3062,7 +3062,7 @@ class StructuredDotGradCSC(gof.Op):
// make sure that row index is not bigger than actual number of rows
// Note: wouldn't the above operation fail if that were the case ?
// when would this ever be true anyway ?
if (i >= %(_g)s->dimensions[0])
if (i >= PyArray_DIMS(%(_g)s)[0])
{PyErr_SetString(PyExc_NotImplementedError, "H"); %(fail)s;}
// perform dot product of dense and sparse rows
......@@ -3153,20 +3153,20 @@ class StructuredDotGradCSR(gof.Op):
if( %(_indptr)s->descr->type_num != NPY_INT32)
{PyErr_SetString(PyExc_NotImplementedError, "D"); %(fail)s;}
if( %(_d)s->dimensions[1] != %(_g)s->dimensions[1])
if( PyArray_DIMS(%(_d)s)[1] != PyArray_DIMS(%(_g)s)[1])
{PyErr_SetString(PyExc_NotImplementedError, "d and g have different numbers of columns"); %(fail)s;}
if (!%(_zout)s
|| (%(_zout)s->dimensions[0] != %(_indices)s->dimensions[0]))
|| (PyArray_DIMS(%(_zout)s)[0] != PyArray_DIMS(%(_indices)s)[0]))
{
Py_XDECREF(%(_zout)s);
%(_zout)s = (PyArrayObject*) PyArray_SimpleNew(1, %(_indices)s->dimensions, %(_g)s->descr->type_num);
%(_zout)s = (PyArrayObject*) PyArray_SimpleNew(1, PyArray_DIMS(%(_indices)s), %(_g)s->descr->type_num);
}
{ //makes it compile even though labels jump over variable definitions.
npy_intp nnz = %(_indices)s->dimensions[0];
npy_intp nnz = PyArray_DIMS(%(_indices)s)[0];
// extract number of rows
npy_intp N = %(_indptr)s->dimensions[0]-1; //TODO: error checking with this
npy_intp N = PyArray_DIMS(%(_indptr)s)[0]-1; //TODO: error checking with this
npy_intp Sindices = %(_indices)s->strides[0]/%(_indices)s->descr->elsize;
npy_intp Sindptr = %(_indptr)s->strides[0]/%(_indptr)s->descr->elsize;
......@@ -3174,7 +3174,7 @@ class StructuredDotGradCSR(gof.Op):
const npy_intp Sd1 = %(_d)s->strides[1]/%(_d)s->descr->elsize;
const npy_intp Sg1 = %(_g)s->strides[1]/%(_g)s->descr->elsize;
const npy_intp K = %(_d)s->dimensions[1];
const npy_intp K = PyArray_DIMS(%(_d)s)[1];
const npy_int32 * __restrict__ indptr = (npy_int32 *)%(_indptr)s->data;
const npy_int32 * __restrict__ indices = (npy_int32 *)%(_indices)s->data;
......@@ -3190,7 +3190,7 @@ class StructuredDotGradCSR(gof.Op):
// extract j-th row of dense matrix
const dtype_%(_d)s* __restrict__ d_row = (dtype_%(_d)s*)(%(_d)s->data + %(_d)s->strides[0] * j);
if(j >= %(_d)s->dimensions[0]) {PyErr_SetString(PyExc_NotImplementedError, "G"); %(fail)s;}
if(j >= PyArray_DIMS(%(_d)s)[0]) {PyErr_SetString(PyExc_NotImplementedError, "G"); %(fail)s;}
// extract corresponding row in gradient
const dtype_%(_g)s* __restrict__ g_row = (dtype_%(_g)s*)(%(_g)s->data + %(_g)s->strides[0] * i);
......@@ -3199,7 +3199,7 @@ class StructuredDotGradCSR(gof.Op):
// make sure that row index is not bigger than actual number of rows
// Note: wouldn't the above operation fail if that were the case ?
// when would this ever be true anyway ?
if (i >= %(_g)s->dimensions[0])
if (i >= PyArray_DIMS(%(_g)s)[0])
{PyErr_SetString(PyExc_NotImplementedError, "H"); %(fail)s;}
// perform dot product of dense and sparse rows
......
差异被折叠。
......@@ -3094,7 +3094,7 @@ class Alloc(gof.Op):
int need_new_out = (NULL == %(zz)s);
for (int i = 0; i < %(ndim)s; i++)
need_new_out = (need_new_out
|| (%(zz)s->dimensions[i] != shape[i]));
|| (PyArray_DIMS(%(zz)s)[i] != shape[i]));
if (need_new_out)
{
......@@ -4047,7 +4047,7 @@ class Subtensor(Op):
&PyArray_Type,
%(x)s->descr,
%(view_ndim)s,
%(x)s->dimensions,
PyArray_DIMS(%(x)s),
%(x)s->strides,
%(x)s->data,
%(x)s->flags,
......@@ -4057,17 +4057,17 @@ class Subtensor(Op):
%(fail)s;
}
if ((xview->dimensions == %(x)s->dimensions)
&& (%(x)s->dimensions != NULL))
if ((PyArray_DIMS(xview) == PyArray_DIMS(%(x)s))
&& (PyArray_DIMS(%(x)s) != NULL))
{
PyErr_Format(PyExc_ValueError, "x and xview"
"(with %%d dims) have the same dimensions"
" pointers: %%p and %%p",
PyArray_NDIM(%(x)s), xview->dimensions, %(x)s->dimensions);
PyArray_NDIM(%(x)s), PyArray_DIMS(xview), PyArray_DIMS(%(x)s));
%(fail)s;
}
if (xview->strides == %(x)s->strides
&& (%(x)s->dimensions != NULL))
&& (PyArray_DIMS(%(x)s) != NULL))
{
PyErr_Format(PyExc_ValueError, "x and xview"
"(with %%d dims) have the same strides"
......@@ -4080,7 +4080,7 @@ class Subtensor(Op):
{
if (is_slice[outer_ii])
{
npy_intp length = %(x)s->dimensions[outer_ii];
npy_intp length = PyArray_DIMS(%(x)s)[outer_ii];
npy_intp slicelength;
npy_intp start = subtensor_spec[spec_pos+0];
npy_intp stop = subtensor_spec[spec_pos+1];
......@@ -4145,7 +4145,7 @@ class Subtensor(Op):
assert (slicelength <= length);
xview->data += %(x)s->strides[outer_ii] * start;
xview->dimensions[inner_ii] = slicelength;
PyArray_DIMS(xview)[inner_ii] = slicelength;
xview->strides[inner_ii] = %(x)s->strides[outer_ii] * step;
inner_ii += 1;
......@@ -4154,10 +4154,10 @@ class Subtensor(Op):
else // tuple coord `outer_ii` is an int
{
int idx = subtensor_spec[spec_pos];
if (idx < 0) idx += %(x)s->dimensions[outer_ii];
if (idx < 0) idx += PyArray_DIMS(%(x)s)[outer_ii];
if (idx >= 0)
{
if (idx < %(x)s->dimensions[outer_ii])
if (idx < PyArray_DIMS(%(x)s)[outer_ii])
{
xview->data += %(x)s->strides[outer_ii] * idx;
}
......@@ -4180,7 +4180,7 @@ class Subtensor(Op):
while (inner_ii < PyArray_NDIM(xview))
{
assert (outer_ii < PyArray_NDIM(%(x)s));
xview->dimensions[inner_ii] = %(x)s->dimensions[outer_ii];
PyArray_DIMS(xview)[inner_ii] = PyArray_DIMS(%(x)s)[outer_ii];
xview->strides[inner_ii] = %(x)s->strides[outer_ii];
inner_ii += 1;
outer_ii += 1;
......
......@@ -496,9 +496,9 @@ class GemmRelated(Op):
int type_num = %(_x)s->descr->type_num;
int type_size = %(_x)s->descr->elsize; // in bytes
npy_intp* Nx = %(_x)s->dimensions;
npy_intp* Ny = %(_y)s->dimensions;
npy_intp* Nz = 0; //%(_zout)s->dimensions;
npy_intp* Nx = PyArray_DIMS(%(_x)s);
npy_intp* Ny = PyArray_DIMS(%(_y)s);
npy_intp* Nz = 0; //PyArray_DIMS(%(_zout)s);
npy_intp* Sx = %(_x)s->strides;
npy_intp* Sy = %(_y)s->strides;
......@@ -888,14 +888,14 @@ class Gemm(GemmRelated):
%(_zout)s = %(_z)s;
Py_INCREF(%(_zout)s);
}
Nz = %(_z)s->dimensions;
Nz = PyArray_DIMS(%(_z)s);
Sz = %(_z)s->strides;
"""
setup_z_Nz_Sz_outplace = """
if ((NULL == %(_zout)s)
|| (%(_zout)s->dimensions[0] != %(_z)s->dimensions[0])
|| (%(_zout)s->dimensions[1] != %(_z)s->dimensions[1])
|| (PyArray_DIMS(%(_zout)s)[0] != PyArray_DIMS(%(_z)s)[0])
|| (PyArray_DIMS(%(_zout)s)[1] != PyArray_DIMS(%(_z)s)[1])
|| (%(_zout)s->strides[0] <= 0)
|| (%(_zout)s->strides[1] <= 0)
|| (%(_zout)s->strides[0] MOD type_size)
......@@ -905,8 +905,8 @@ class Gemm(GemmRelated):
{
Py_XDECREF(%(_zout)s);
npy_intp dims[2];
dims[0] = %(_z)s->dimensions[0];
dims[1] = %(_z)s->dimensions[1];
dims[0] = PyArray_DIMS(%(_z)s)[0];
dims[1] = PyArray_DIMS(%(_z)s)[1];
%(_zout)s = (PyArrayObject*)PyArray_SimpleNew(2, dims,
type_num_%(_z)s);
//fprintf(stderr, "Gemm Allocating %%i %%i\\n", dims[0], dims[1]);
......@@ -916,7 +916,7 @@ class Gemm(GemmRelated):
%(fail)s
}
}
Nz = %(_zout)s->dimensions;
Nz = PyArray_DIMS(%(_zout)s);
Sz = %(_zout)s->strides;
if (%(_zout)s->descr->type_num == NPY_FLOAT)
......@@ -1479,13 +1479,13 @@ class Dot22(GemmRelated):
setup_z_Nz_Sz = """
if ((NULL == %(_zout)s)
|| (%(_zout)s->dimensions[0] != %(_x)s->dimensions[0])
|| (%(_zout)s->dimensions[1] != %(_y)s->dimensions[1]))
|| (PyArray_DIMS(%(_zout)s)[0] != PyArray_DIMS(%(_x)s)[0])
|| (PyArray_DIMS(%(_zout)s)[1] != PyArray_DIMS(%(_y)s)[1]))
{
if (NULL != %(_zout)s) Py_XDECREF(%(_zout)s);
npy_intp dims[2];
dims[0] = %(_x)s->dimensions[0];
dims[1] = %(_y)s->dimensions[1];
dims[0] = PyArray_DIMS(%(_x)s)[0];
dims[1] = PyArray_DIMS(%(_y)s)[1];
%(_zout)s = (PyArrayObject*)PyArray_SimpleNew(2, dims,
type_num_%(_x)s);
//fprintf(stderr, "Dot Allocating %%i %%i\\n", dims[0], dims[1]);
......@@ -1495,7 +1495,7 @@ class Dot22(GemmRelated):
%(fail)s
}
}
Nz = %(_zout)s->dimensions;
Nz = PyArray_DIMS(%(_zout)s);
Sz = %(_zout)s->strides;
"""
......
......@@ -47,13 +47,13 @@ def ger_c_code(A, a, x, y, Z, destructive, fail):
if (%(A)s->descr->type_num != %(y)s->descr->type_num)
{ PyErr_SetString(PyExc_TypeError, "A vs. y"); %(fail)s; }
if (%(A)s->dimensions[0] != %(x)s->dimensions[0])
if (PyArray_DIMS(%(A)s)[0] != PyArray_DIMS(%(x)s)[0])
{
PyErr_SetString(PyExc_ValueError,
"Shape mismatch: A.shape[0] != x.shape[0]");
%(fail)s;
}
if (%(A)s->dimensions[1] != %(y)s->dimensions[0])
if (PyArray_DIMS(%(A)s)[1] != PyArray_DIMS(%(y)s)[0])
{
PyErr_SetString(PyExc_ValueError,
"Shape mismatch: A.shape[1] != y.shape[0]");
......@@ -76,12 +76,12 @@ def ger_c_code(A, a, x, y, Z, destructive, fail):
&& (%(A)s->strides[1] != elemsize)))
{
npy_intp dims[2];
dims[0] = %(A)s->dimensions[0];
dims[1] = %(A)s->dimensions[1];
dims[0] = PyArray_DIMS(%(A)s)[0];
dims[1] = PyArray_DIMS(%(A)s)[1];
if ((NULL == %(Z)s)
|| (%(Z)s->dimensions[0] != %(A)s->dimensions[0])
|| (%(Z)s->dimensions[1] != %(A)s->dimensions[1])
|| (PyArray_DIMS(%(Z)s)[0] != PyArray_DIMS(%(A)s)[0])
|| (PyArray_DIMS(%(Z)s)[1] != PyArray_DIMS(%(A)s)[1])
|| (%(Z)s->strides[0] < 0)
|| (%(Z)s->strides[1] < 0)
|| ((%(Z)s->strides[0] != elemsize)
......@@ -152,8 +152,8 @@ def ger_c_code(A, a, x, y, Z, destructive, fail):
}
{
int Nz0 = %(Z)s->dimensions[0];
int Nz1 = %(Z)s->dimensions[1];
int Nz0 = PyArray_DIMS(%(Z)s)[0];
int Nz1 = PyArray_DIMS(%(Z)s)[1];
int Sx = %(x)s->strides[0] / elemsize;
int Sy = %(y)s->strides[0] / elemsize;
......@@ -321,13 +321,13 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
if (%(aa)s->descr->type_num != %(yy)s->descr->type_num)
{ PyErr_SetString(PyExc_TypeError, "Gemv: aa vs. yy"); %(fail)s; }
if (%(xx)s->dimensions[0] != %(aa)s->dimensions[0])
if (PyArray_DIMS(%(xx)s)[0] != PyArray_DIMS(%(aa)s)[0])
{
PyErr_SetString(PyExc_ValueError,
"Shape mismatch: A.shape[0] != x.shape[0]");
%(fail)s;
}
if (%(xx)s->dimensions[1] != %(yy)s->dimensions[0])
if (PyArray_DIMS(%(xx)s)[1] != PyArray_DIMS(%(yy)s)[0])
{
PyErr_SetString(PyExc_ValueError,
"Shape mismatch: A.shape[1] != y.shape[0]");
......@@ -347,11 +347,11 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
if (!%(destructive)s)
{
if ((NULL == %(zz)s)
|| (%(zz)s->dimensions[0] != %(aa)s->dimensions[0]))
|| (PyArray_DIMS(%(zz)s)[0] != PyArray_DIMS(%(aa)s)[0]))
{
if (%(zz)s) Py_XDECREF(%(zz)s);
%(zz)s = (PyArrayObject*)PyArray_SimpleNew(1,
%(aa)s->dimensions, type_num_%(aa)s);
PyArray_DIMS(%(aa)s), type_num_%(aa)s);
if(!%(zz)s) {
PyErr_SetString(PyExc_MemoryError,
"failed to alloc gemv output");
......@@ -371,7 +371,7 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
const float * zdata = (float*)%(aa)s->data;
int Ai = %(aa)s->strides[0]/sizeof(float);
int Zi = %(zz)s->strides[0]/sizeof(float);
for (int i = 0; i < %(aa)s->dimensions[0]; ++i)
for (int i = 0; i < PyArray_DIMS(%(aa)s)[0]; ++i)
{
zoutdata[Zi*i] = fbeta * zdata[Ai*i];
}
......@@ -382,7 +382,7 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
const double * zdata = (double*)%(aa)s->data;
int Ai = %(aa)s->strides[0]/sizeof(double);
int Zi = %(zz)s->strides[0]/sizeof(double);
for (int i = 0; i < %(aa)s->dimensions[0]; ++i)
for (int i = 0; i < PyArray_DIMS(%(aa)s)[0]; ++i)
{
zoutdata[Zi*i] = dbeta * zdata[Ai*i];
}
......@@ -409,8 +409,8 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
{
char TRANS = 'T';
char NOTRANS = 'N';
int Nx0 = %(xx)s->dimensions[0];
int Nx1 = %(xx)s->dimensions[1];
int Nx0 = PyArray_DIMS(%(xx)s)[0];
int Nx1 = PyArray_DIMS(%(xx)s)[1];
/* This formula is needed in the case where xx is actually a row or
* column matrix, because BLAS sometimes insists that the strides:
* - are not smaller than the number of elements in the array
......
......@@ -797,9 +797,9 @@ def ____gemm_code(check_ab, a_init, b_init):
int type_num = _x->descr->type_num;
int type_size = _x->descr->elsize; // in bytes
npy_intp* Nx = _x->dimensions;
npy_intp* Ny = _y->dimensions;
npy_intp* Nz = _z->dimensions;
npy_intp* Nx = PyArray_DIMS(_x);
npy_intp* Ny = PyArray_DIMS(_y);
npy_intp* Nz = PyArray_DIMS(_z);
npy_intp* Sx = _x->strides;
npy_intp* Sy = _y->strides;
......
......@@ -288,7 +288,7 @@ class DimShuffle(Op):
for i, o in enumerate(self.new_order):
if o != 'x':
shape_statements += [('dimensions[' + str(
i) + '] = %(basename)s->dimensions[' + str(o) + ']')]
i) + '] = PyArray_DIMS(%(basename)s)[' + str(o) + ']')]
else:
shape_statements += [('dimensions[' + str(i) + '] = 1')]
......
......@@ -67,7 +67,7 @@ def make_checks(loop_orders, dtypes, sub):
# jump = stride - adjust
jump = "(%s) - (%s)" % ("%(var)s_stride%(index)s" % locals(), adjust)
init += """
%(var)s_n%(index)s = %(var)s->dimensions[%(index)s];
%(var)s_n%(index)s = PyArray_DIMS(%(var)s)[%(index)s];
%(var)s_stride%(index)s = %(var)s->strides[%(index)s] / sizeof(%(dtype)s);
%(var)s_jump%(index)s_%(j)s = %(jump)s;
//printf("%(var)s_jump%(index)s_%(j)s is:");
......
......@@ -207,37 +207,37 @@ class Conv3D(theano.Op):
%(fail)s
}
if (%(d)s->dimensions[0] != 3)
if (PyArray_DIMS(%(d)s)[0] != 3)
{
PyErr_Format(PyExc_ValueError,"Conv3D: 3 stride length arguments expected (row, col, time) but %%li were given", (long)%(d)s->dimensions[0]);
PyErr_Format(PyExc_ValueError,"Conv3D: 3 stride length arguments expected (row, col, time) but %%li were given", (long)PyArray_DIMS(%(d)s)[0]);
%(fail)s
}
//Read and check sizes of inputs
{ // exta scope so error handler jumps don't cause errors
const int batchSize = %(V)s->dimensions[0];
const int outputChannels = %(W)s->dimensions[0];
const int inputChannels = %(V)s->dimensions[4];
const int batchSize = PyArray_DIMS(%(V)s)[0];
const int outputChannels = PyArray_DIMS(%(W)s)[0];
const int inputChannels = PyArray_DIMS(%(V)s)[4];
if (%(W)s->dimensions[4] != inputChannels)
if (PyArray_DIMS(%(W)s)[4] != inputChannels)
{
PyErr_Format(PyExc_ValueError, "Conv3D: W operates on a %%ld channel image but the image has %%d channels. Overall shape of input: (%%ld,%%ld,%%ld,%%ld,%%ld)", (long)%(W)s->dimensions[4], inputChannels, (long)%(V)s->dimensions[0], (long)%(V)s->dimensions[1], (long)%(V)s->dimensions[2], (long)%(V)s->dimensions[3], (long)%(V)s->dimensions[4]);
PyErr_Format(PyExc_ValueError, "Conv3D: W operates on a %%ld channel image but the image has %%d channels. Overall shape of input: (%%ld,%%ld,%%ld,%%ld,%%ld)", (long)PyArray_DIMS(%(W)s)[4], inputChannels, (long)PyArray_DIMS(%(V)s)[0], (long)PyArray_DIMS(%(V)s)[1], (long)PyArray_DIMS(%(V)s)[2], (long)PyArray_DIMS(%(V)s)[3], (long)PyArray_DIMS(%(V)s)[4]);
%(fail)s
}
if (%(b)s->dimensions[0] != outputChannels)
if (PyArray_DIMS(%(b)s)[0] != outputChannels)
{
PyErr_Format(PyExc_ValueError, "Conv3D: b adds to a(n) %%ld channel output image but the output has %%d channels", (long)%(b)s->dimensions[0], outputChannels);
PyErr_Format(PyExc_ValueError, "Conv3D: b adds to a(n) %%ld channel output image but the output has %%d channels", (long)PyArray_DIMS(%(b)s)[0], outputChannels);
%(fail)s
}
{ //extra scope so error handler jumps don't cause errors
const int filterHeight = %(W)s->dimensions[1];
const int filterWidth = %(W)s->dimensions[2];
const int filterDur = %(W)s->dimensions[3];
const int vidHeight = %(V)s->dimensions[1];
const int vidWidth = %(V)s->dimensions[2];
const int vidDur = %(V)s->dimensions[3];\
const int filterHeight = PyArray_DIMS(%(W)s)[1];
const int filterWidth = PyArray_DIMS(%(W)s)[2];
const int filterDur = PyArray_DIMS(%(W)s)[3];
const int vidHeight = PyArray_DIMS(%(V)s)[1];
const int vidWidth = PyArray_DIMS(%(V)s)[2];
const int vidDur = PyArray_DIMS(%(V)s)[3];\
if (vidHeight < filterHeight)
{
......@@ -290,11 +290,11 @@ class Conv3D(theano.Op):
if(!(%(H)s) || %(H)s->dimensions[0]!=dims[0] ||
%(H)s->dimensions[1]!=dims[1] ||
%(H)s->dimensions[2]!=dims[2] ||
%(H)s->dimensions[3]!=dims[3] ||
%(H)s->dimensions[4]!=dims[4]){
if(!(%(H)s) || PyArray_DIMS(%(H)s)[0]!=dims[0] ||
PyArray_DIMS(%(H)s)[1]!=dims[1] ||
PyArray_DIMS(%(H)s)[2]!=dims[2] ||
PyArray_DIMS(%(H)s)[3]!=dims[3] ||
PyArray_DIMS(%(H)s)[4]!=dims[4]){
Py_XDECREF(%(H)s);
%(H)s = (PyArrayObject *) PyArray_SimpleNew(5, dims, %(V)s->descr->type_num);
if (!(%(H)s)) {
......
......@@ -121,16 +121,16 @@ class ConvGrad3D(theano.Op):
%(fail)s
}
if (%(d)s->dimensions[0] != 3)
if (PyArray_DIMS(%(d)s)[0] != 3)
{
PyErr_Format(PyExc_ValueError,"ConvGrad3D: 3 stride length arguments expected (row, col, time) but %%li were given", (long)%(d)s->dimensions[0]);
PyErr_Format(PyExc_ValueError,"ConvGrad3D: 3 stride length arguments expected (row, col, time) but %%li were given", (long)PyArray_DIMS(%(d)s)[0]);
%(fail)s
}
{ //extra scope so that fail will not jump over declarations
//Read and check sizes of inputs
const int batchSize = %(V)s->dimensions[0];
if (%(WShape)s->dimensions[0] != 5)
const int batchSize = PyArray_DIMS(%(V)s)[0];
if (PyArray_DIMS(%(WShape)s)[0] != 5)
{
PyErr_Format(PyExc_ValueError,"ConvGrad3D: WShape must specify a 5D shape");
%(fail)s
......@@ -144,7 +144,7 @@ class ConvGrad3D(theano.Op):
{ //extra scope so that fail will not jump over declarations
dtype_%(WShape)s * WShape = (dtype_%(WShape)s *) %(WShape)s->data;
const int outputChannels = WShape[0];
const int inputChannels = %(V)s->dimensions[4];
const int inputChannels = PyArray_DIMS(%(V)s)[4];
if (WShape[4] != inputChannels)
{
PyErr_Format(PyExc_ValueError, "ConvGrad3D: W operates on a %%i channel image but the image has %%i channels",(int) WShape[1],inputChannels);
......@@ -155,9 +155,9 @@ class ConvGrad3D(theano.Op):
const int filterHeight = WShape[1];
const int filterWidth = WShape[2];
const int filterDur = WShape[3];
const int vidHeight = %(V)s->dimensions[1];
const int vidWidth = %(V)s->dimensions[2];
const int vidDur = %(V)s->dimensions[3];
const int vidHeight = PyArray_DIMS(%(V)s)[1];
const int vidWidth = PyArray_DIMS(%(V)s)[2];
const int vidDur = PyArray_DIMS(%(V)s)[3];
if (vidHeight < filterHeight)
{
PyErr_Format(PyExc_ValueError, "ConvGrad3D: W has a height of %%i but V is only %%i pixels tall", filterHeight, vidHeight);
......@@ -193,13 +193,13 @@ class ConvGrad3D(theano.Op):
if (%(dCdH)s->dimensions[0] != batchSize ||
%(dCdH)s->dimensions[4] != outputChannels ||
%(dCdH)s->dimensions[1] != outputHeight ||
%(dCdH)s->dimensions[2] != outputWidth ||
%(dCdH)s->dimensions[3] != outputDur)
if (PyArray_DIMS(%(dCdH)s)[0] != batchSize ||
PyArray_DIMS(%(dCdH)s)[4] != outputChannels ||
PyArray_DIMS(%(dCdH)s)[1] != outputHeight ||
PyArray_DIMS(%(dCdH)s)[2] != outputWidth ||
PyArray_DIMS(%(dCdH)s)[3] != outputDur)
{
PyErr_Format(PyExc_ValueError, "dCdH is the wrong size, expected (%%i,%%i,%%i,%%i,%%i), got (%%li,%%li,%%li,%%li,%%li)", batchSize, outputHeight, outputWidth, outputDur, outputChannels, (long)%(dCdH)s->dimensions[0], (long)%(dCdH)s->dimensions[1], (long)%(dCdH)s->dimensions[2], (long)%(dCdH)s->dimensions[3], (long)%(dCdH)s->dimensions[4]);
PyErr_Format(PyExc_ValueError, "dCdH is the wrong size, expected (%%i,%%i,%%i,%%i,%%i), got (%%li,%%li,%%li,%%li,%%li)", batchSize, outputHeight, outputWidth, outputDur, outputChannels, (long)PyArray_DIMS(%(dCdH)s)[0], (long)PyArray_DIMS(%(dCdH)s)[1], (long)PyArray_DIMS(%(dCdH)s)[2], (long)PyArray_DIMS(%(dCdH)s)[3], (long)PyArray_DIMS(%(dCdH)s)[4]);
%(fail)s
}
{ // extra scope for fail
......@@ -211,11 +211,11 @@ class ConvGrad3D(theano.Op):
dims[2] = filterWidth;
dims[3] = filterDur;
if(!(%(dCdW)s) || %(dCdW)s->dimensions[0]!=dims[0] ||
%(dCdW)s->dimensions[1]!=dims[1] ||
%(dCdW)s->dimensions[2]!=dims[2] ||
%(dCdW)s->dimensions[3]!=dims[3] ||
%(dCdW)s->dimensions[4]!=dims[4] ){
if(!(%(dCdW)s) || PyArray_DIMS(%(dCdW)s)[0]!=dims[0] ||
PyArray_DIMS(%(dCdW)s)[1]!=dims[1] ||
PyArray_DIMS(%(dCdW)s)[2]!=dims[2] ||
PyArray_DIMS(%(dCdW)s)[3]!=dims[3] ||
PyArray_DIMS(%(dCdW)s)[4]!=dims[4] ){
Py_XDECREF(%(dCdW)s);
%(dCdW)s = (PyArrayObject *) PyArray_SimpleNew(5, dims, %(V)s->descr->type_num);
......
......@@ -126,9 +126,9 @@ class ConvTransp3D(theano.Op):
}
//Read and check stride arguments
if (%(d)s->dimensions[0] != 3)
if (PyArray_DIMS(%(d)s)[0] != 3)
{
PyErr_Format(PyExc_ValueError, "ConvTransp3D: 3 stride length arguments expected (for row, col, and time) but %%li were given", (long)%(d)s->dimensions[0] );
PyErr_Format(PyExc_ValueError, "ConvTransp3D: 3 stride length arguments expected (for row, col, and time) but %%li were given", (long)PyArray_DIMS(%(d)s)[0] );
%(fail)s
}
......@@ -147,33 +147,33 @@ class ConvTransp3D(theano.Op):
//Read and check sizes of inputs
{ // for fail 2
const int batchSize = %(H)s->dimensions[0];
const int outputChannels = %(W)s->dimensions[0];
const int batchSize = PyArray_DIMS(%(H)s)[0];
const int outputChannels = PyArray_DIMS(%(W)s)[0];
if (%(H)s->dimensions[4] != outputChannels)
if (PyArray_DIMS(%(H)s)[4] != outputChannels)
{
PyErr_Format(PyExc_ValueError, "W produces a %%i channel image but the image has %%li channels. W.shape: (%%li, %%li, %%li, %%li, %%li) H.shape: (%%li, %%li, %%li, %%li, %%li)", outputChannels, (long)%(H)s->dimensions[4], (long)%(W)s->dimensions[0], (long)%(W)s->dimensions[1], (long)%(W)s->dimensions[2], (long)%(W)s->dimensions[3], (long)%(W)s->dimensions[4], (long)%(H)s->dimensions[0], (long)%(H)s->dimensions[1], (long)%(H)s->dimensions[2], (long)%(H)s->dimensions[3], (long)%(H)s->dimensions[4]);
PyErr_Format(PyExc_ValueError, "W produces a %%i channel image but the image has %%li channels. W.shape: (%%li, %%li, %%li, %%li, %%li) H.shape: (%%li, %%li, %%li, %%li, %%li)", outputChannels, (long)PyArray_DIMS(%(H)s)[4], (long)PyArray_DIMS(%(W)s)[0], (long)PyArray_DIMS(%(W)s)[1], (long)PyArray_DIMS(%(W)s)[2], (long)PyArray_DIMS(%(W)s)[3], (long)PyArray_DIMS(%(W)s)[4], (long)PyArray_DIMS(%(H)s)[0], (long)PyArray_DIMS(%(H)s)[1], (long)PyArray_DIMS(%(H)s)[2], (long)PyArray_DIMS(%(H)s)[3], (long)PyArray_DIMS(%(H)s)[4]);
%(fail)s
}
{ // for fail 3
const int inputChannels = %(W)s->dimensions[4];
const int inputChannels = PyArray_DIMS(%(W)s)[4];
if (%(b)s->dimensions[0] != inputChannels)
if (PyArray_DIMS(%(b)s)[0] != inputChannels)
{
PyErr_Format(PyExc_ValueError, "ConvTransp3D: b operates on a %%li channel image but the image has %%i channels", (long)%(b)s->dimensions[0], inputChannels );
PyErr_Format(PyExc_ValueError, "ConvTransp3D: b operates on a %%li channel image but the image has %%i channels", (long)PyArray_DIMS(%(b)s)[0], inputChannels );
%(fail)s
}
{ // for fail 4
const int filterHeight = %(W)s->dimensions[1];
const int filterWidth = %(W)s->dimensions[2];
const int filterDur = %(W)s->dimensions[3];
const int outputHeight = %(H)s->dimensions[1];
const int outputWidth = %(H)s->dimensions[2];
const int outputDur = %(H)s->dimensions[3];
const int filterHeight = PyArray_DIMS(%(W)s)[1];
const int filterWidth = PyArray_DIMS(%(W)s)[2];
const int filterDur = PyArray_DIMS(%(W)s)[3];
const int outputHeight = PyArray_DIMS(%(H)s)[1];
const int outputWidth = PyArray_DIMS(%(H)s)[2];
const int outputDur = PyArray_DIMS(%(H)s)[3];
int videoHeight = (outputHeight-1) * dr + filterHeight;
int videoWidth = (outputWidth-1) * dc + filterWidth;
......@@ -187,7 +187,7 @@ class ConvTransp3D(theano.Op):
%(fail)s
}
if (%(RShape)s->dimensions[0] != 3)
if (PyArray_DIMS(%(RShape)s)[0] != 3)
{
PyErr_Format(PyExc_ValueError, "RShape must specify a 3D shape ( [height,width,duration] )");
%(fail)s
......@@ -221,11 +221,11 @@ class ConvTransp3D(theano.Op):
dims[2] = videoWidth;
dims[3] = videoDur;
if(!(%(R)s) || %(R)s->dimensions[0]!=dims[0] ||
%(R)s->dimensions[1]!=dims[1] ||
%(R)s->dimensions[2]!=dims[2] ||
%(R)s->dimensions[3]!=dims[3] ||
%(R)s->dimensions[4]!=dims[4])
if(!(%(R)s) || PyArray_DIMS(%(R)s)[0]!=dims[0] ||
PyArray_DIMS(%(R)s)[1]!=dims[1] ||
PyArray_DIMS(%(R)s)[2]!=dims[2] ||
PyArray_DIMS(%(R)s)[3]!=dims[3] ||
PyArray_DIMS(%(R)s)[4]!=dims[4])
{
Py_XDECREF(%(R)s);
%(R)s = (PyArrayObject *) PyArray_SimpleNew(5, dims, %(H)s->descr->type_num);
......
差异被折叠。
......@@ -105,7 +105,7 @@ class SoftmaxWithBias(gof.Op):
#TODO: use this to accept float32 and int32: node.inputs[0].type.dtype_specs()[1]
init_decl = """
npy_intp* Nx = %(x)s->dimensions;
npy_intp* Nx = PyArray_DIMS(%(x)s);
if (PyArray_NDIM(%(x)s) != 2)
{
......@@ -129,17 +129,17 @@ class SoftmaxWithBias(gof.Op):
PyErr_SetString(PyExc_TypeError, "b not float");
%(fail)s;
}
if ((%(x)s->dimensions[1] != %(b)s->dimensions[0]))
if ((PyArray_DIMS(%(x)s)[1] != PyArray_DIMS(%(b)s)[0]))
{
PyErr_Format(PyExc_ValueError,
"number of columns in x (%%ld) does not match length of b (%%ld)",
(long int)%(x)s->dimensions[1], (long int)%(b)s->dimensions[0]);
(long int)PyArray_DIMS(%(x)s)[1], (long int)PyArray_DIMS(%(b)s)[0]);
%(fail)s;
}
if ((NULL == %(sm)s)
|| (%(sm)s->dimensions[0] != %(x)s->dimensions[0])
|| (%(sm)s->dimensions[1] != %(x)s->dimensions[1]))
|| (PyArray_DIMS(%(sm)s)[0] != PyArray_DIMS(%(x)s)[0])
|| (PyArray_DIMS(%(sm)s)[1] != PyArray_DIMS(%(x)s)[1]))
{
if (NULL != %(sm)s) Py_XDECREF(%(sm)s);
%(sm)s = (PyArrayObject*)PyArray_SimpleNew(2, PyArray_DIMS(%(x)s),
......@@ -283,14 +283,14 @@ class SoftmaxGrad(gof.Op):
PyErr_SetString(PyExc_ValueError, "rank error");
%(fail)s;
}
if (%(dy)s->dimensions[0] != %(sm)s->dimensions[0])
if (PyArray_DIMS(%(dy)s)[0] != PyArray_DIMS(%(sm)s)[0])
{
PyErr_SetString(PyExc_ValueError, "dy.shape[0] != sm.shape[0]");
%(fail)s;
}
if ((NULL == %(dx)s)
|| (%(dx)s->dimensions[0] != %(sm)s->dimensions[0])
|| (%(dx)s->dimensions[1] != %(sm)s->dimensions[1]))
|| (PyArray_DIMS(%(dx)s)[0] != PyArray_DIMS(%(sm)s)[0])
|| (PyArray_DIMS(%(dx)s)[1] != PyArray_DIMS(%(sm)s)[1]))
{
Py_XDECREF(%(dx)s);
%(dx)s = (PyArrayObject*) PyArray_SimpleNew(2,
......@@ -304,7 +304,7 @@ class SoftmaxGrad(gof.Op):
}
}
for (size_t i = 0; i < %(dx)s->dimensions[0]; ++i)
for (size_t i = 0; i < PyArray_DIMS(%(dx)s)[0]; ++i)
{
const dtype_%(dy)s* __restrict__ dy_i = (dtype_%(dy)s*) (%(dy)s->data + %(dy)s->strides[0] * i);
npy_intp Sdy = %(dy)s->strides[1]/sizeof(dtype_%(dy)s);
......@@ -314,12 +314,12 @@ class SoftmaxGrad(gof.Op):
npy_intp Sdx = %(dx)s->strides[1]/sizeof(dtype_%(dx)s);
double sum_dy_times_sm = 0.;
for (size_t j = 0; j < %(dx)s->dimensions[1]; ++j)
for (size_t j = 0; j < PyArray_DIMS(%(dx)s)[1]; ++j)
{
dx_i[j * Sdx] = dy_i[j * Sdy] * sm_i[j * Ssm];
sum_dy_times_sm += dx_i[j * Sdx];
}
for (size_t j = 0; j < %(dx)s->dimensions[1]; ++j)
for (size_t j = 0; j < PyArray_DIMS(%(dx)s)[1]; ++j)
{
dx_i[j * Sdx] -= sum_dy_times_sm * sm_i[j * Ssm];
}
......@@ -787,17 +787,17 @@ class CrossentropySoftmaxArgmax1HotWithBias(gof.Op):
"y_idx not int8, int16, int32, or int64");
%(fail)s;
}
if (%(x)s->dimensions[0] != %(y_idx)s->dimensions[0])
if (PyArray_DIMS(%(x)s)[0] != PyArray_DIMS(%(y_idx)s)[0])
{
PyErr_Format(PyExc_ValueError,
"number of rows in x (%%ld) does not match length of y (%%ld)",
(long int)%(x)s->dimensions[0],
(long int)%(y_idx)s->dimensions[0]);
(long int)PyArray_DIMS(%(x)s)[0],
(long int)PyArray_DIMS(%(y_idx)s)[0]);
%(fail)s;
}
if ((NULL == %(nll)s) //initial condition
|| (%(nll)s->dimensions[0] != %(y_idx)s->dimensions[0]))
|| (PyArray_DIMS(%(nll)s)[0] != PyArray_DIMS(%(y_idx)s)[0]))
{
if (NULL != %(nll)s) Py_XDECREF(%(nll)s);
%(nll)s = (PyArrayObject*)PyArray_SimpleNew(1,
......@@ -810,7 +810,7 @@ class CrossentropySoftmaxArgmax1HotWithBias(gof.Op):
}
}
if ((NULL == %(am)s)
|| (%(am)s->dimensions[0] != %(y_idx)s->dimensions[0]))
|| (PyArray_DIMS(%(am)s)[0] != PyArray_DIMS(%(y_idx)s)[0]))
{
Py_XDECREF(%(am)s);
%(am)s = (PyArrayObject*) PyArray_SimpleNew(1,
......@@ -831,7 +831,7 @@ class CrossentropySoftmaxArgmax1HotWithBias(gof.Op):
""",
inside_row_loop,
"""
if ((y_i >= %(x)s->dimensions[1]) || (y_i < 0))
if ((y_i >= PyArray_DIMS(%(x)s)[1]) || (y_i < 0))
{
PyErr_SetString(PyExc_ValueError, "y_i value out of bounds");
%(fail)s;
......@@ -944,25 +944,25 @@ class CrossentropySoftmax1HotWithBiasDx (gof.Op):
PyErr_SetString(PyExc_ValueError, "rank error");
%(fail)s;
}
if (%(dnll)s->dimensions[0] != %(sm)s->dimensions[0])
if (PyArray_DIMS(%(dnll)s)[0] != PyArray_DIMS(%(sm)s)[0])
{
PyErr_Format(PyExc_ValueError,
"dnll.shape[0] (%%ld) != sm.shape[0] (%%ld)",
(long int)%(dnll)s->dimensions[0],
(long int)%(sm)s->dimensions[0]);
(long int)PyArray_DIMS(%(dnll)s)[0],
(long int)PyArray_DIMS(%(sm)s)[0]);
%(fail)s;
}
if (%(dnll)s->dimensions[0] != %(y_idx)s->dimensions[0])
if (PyArray_DIMS(%(dnll)s)[0] != PyArray_DIMS(%(y_idx)s)[0])
{
PyErr_Format(PyExc_ValueError,
"dnll.shape[0] (%%ld) != y_idx.shape[0] (%%ld)",
(long int)%(dnll)s->dimensions[0],
(long int)%(y_idx)s->dimensions[0]);
(long int)PyArray_DIMS(%(dnll)s)[0],
(long int)PyArray_DIMS(%(y_idx)s)[0]);
%(fail)s;
}
if ((NULL == %(dx)s)
|| (%(dx)s->dimensions[0] != %(sm)s->dimensions[0])
|| (%(dx)s->dimensions[1] != %(sm)s->dimensions[1]))
|| (PyArray_DIMS(%(dx)s)[0] != PyArray_DIMS(%(sm)s)[0])
|| (PyArray_DIMS(%(dx)s)[1] != PyArray_DIMS(%(sm)s)[1]))
{
if (NULL != %(dx)s) Py_XDECREF(%(dx)s);
%(dx)s = (PyArrayObject*) PyArray_SimpleNew(2,
......@@ -975,7 +975,7 @@ class CrossentropySoftmax1HotWithBiasDx (gof.Op):
}
}
for (size_t i = 0; i < %(dx)s->dimensions[0]; ++i)
for (size_t i = 0; i < PyArray_DIMS(%(dx)s)[0]; ++i)
{
const dtype_%(dnll)s dnll_i = ((dtype_%(dnll)s*)(%(dnll)s->data + %(dnll)s->strides[0] * i))[0];
......@@ -987,11 +987,11 @@ class CrossentropySoftmax1HotWithBiasDx (gof.Op):
dtype_%(dx) s* __restrict__ dx_i = (dtype_%(dx)s*)(%(dx)s->data + %(dx)s->strides[0] * i);
npy_intp Sdx = %(dx)s->strides[1]/sizeof(dtype_%(dx)s);
for (size_t j = 0; j < %(dx)s->dimensions[1]; ++j)
for (size_t j = 0; j < PyArray_DIMS(%(dx)s)[1]; ++j)
{
dx_i[j * Sdx] = dnll_i * sm_i[j * Ssm];
}
if (y_i >= %(dx)s->dimensions[1])
if (y_i >= PyArray_DIMS(%(dx)s)[1])
{
PyErr_SetString(PyExc_ValueError, "y_i >= dx dimensions[1]");
%(fail)s;
......
......@@ -620,7 +620,7 @@ class Shape_i(T.Op):
return """
if(!%(out)s)
%(out)s=(PyArrayObject*)PyArray_ZEROS(0, NULL, NPY_INT64, 0);
((npy_int64*)PyArray_DATA(%(out)s))[0]=%(x)s->dimensions[%(i)s];
((npy_int64*)PyArray_DATA(%(out)s))[0]=PyArray_DIMS(%(x)s)[%(i)s];
""" % locals()
elif node.inputs[0].type.__class__.__name__ == "CudaNdarrayType":
......
......@@ -181,8 +181,8 @@ class DownsampleFactorMax(Op):
PyErr_SetString(PyExc_ValueError, "x must be a 4d ndarray");
%(fail)s;
}
z_shp0 = %(x)s->dimensions[2] / %(ds0)s;
z_shp1 = %(x)s->dimensions[3] / %(ds1)s;
z_shp0 = PyArray_DIMS(%(x)s)[2] / %(ds0)s;
z_shp1 = PyArray_DIMS(%(x)s)[3] / %(ds1)s;
if (%(ignore_border)s)
{
x_shp0_usable = z_shp0 * %(ds0)s;
......@@ -190,23 +190,23 @@ class DownsampleFactorMax(Op):
}
else
{
z_shp0 += (%(x)s->dimensions[2] %% %(ds0)s) ? 1 : 0;
z_shp1 += (%(x)s->dimensions[3] %% %(ds1)s) ? 1 : 0;
x_shp0_usable = %(x)s->dimensions[2];
x_shp1_usable = %(x)s->dimensions[3];
z_shp0 += (PyArray_DIMS(%(x)s)[2] %% %(ds0)s) ? 1 : 0;
z_shp1 += (PyArray_DIMS(%(x)s)[3] %% %(ds1)s) ? 1 : 0;
x_shp0_usable = PyArray_DIMS(%(x)s)[2];
x_shp1_usable = PyArray_DIMS(%(x)s)[3];
}
if ((!%(z)s)
|| *PyArray_DIMS(%(z)s)!=4
||(%(z)s->dimensions[0] != %(x)s->dimensions[0])
||(%(z)s->dimensions[1] != %(x)s->dimensions[1])
||(%(z)s->dimensions[2] != z_shp0)
||(%(z)s->dimensions[3] != z_shp1)
||(PyArray_DIMS(%(z)s)[0] != PyArray_DIMS(%(x)s)[0])
||(PyArray_DIMS(%(z)s)[1] != PyArray_DIMS(%(x)s)[1])
||(PyArray_DIMS(%(z)s)[2] != z_shp0)
||(PyArray_DIMS(%(z)s)[3] != z_shp1)
)
{
if (%(z)s) Py_XDECREF(%(z)s);
npy_intp dims[4] = {0,0,0,0};
dims[0]=%(x)s->dimensions[0];
dims[1]=%(x)s->dimensions[1];
dims[0]=PyArray_DIMS(%(x)s)[0];
dims[1]=PyArray_DIMS(%(x)s)[1];
dims[2]=z_shp0;
dims[3]=z_shp1;
%(z)s = (PyArrayObject*) PyArray_ZEROS(4, dims, typenum,0); //TODO: zeros not necessary
......@@ -214,8 +214,8 @@ class DownsampleFactorMax(Op):
if (z_shp0 && z_shp1)
{
for(int b=0;b<%(x)s->dimensions[0];b++){
for(int k=0;k<%(x)s->dimensions[1];k++){
for(int b=0;b<PyArray_DIMS(%(x)s)[0];b++){
for(int k=0;k<PyArray_DIMS(%(x)s)[1];k++){
int mini_i = 0;
int zi = 0;
for(int i=0;i< x_shp0_usable; i++){
......@@ -321,8 +321,8 @@ class DownsampleFactorMaxGrad(Op):
PyErr_SetString(PyExc_ValueError, "gz must be a 4d ndarray");
%(fail)s;
}
z_shp0 = %(z)s->dimensions[2];
z_shp1 = %(z)s->dimensions[3];
z_shp0 = PyArray_DIMS(%(z)s)[2];
z_shp1 = PyArray_DIMS(%(z)s)[3];
if (%(ignore_border)s)
{
x_shp0_usable = z_shp0 * %(ds0)s;
......@@ -330,23 +330,23 @@ class DownsampleFactorMaxGrad(Op):
}
else
{
x_shp0_usable = %(x)s->dimensions[2];
x_shp1_usable = %(x)s->dimensions[3];
x_shp0_usable = PyArray_DIMS(%(x)s)[2];
x_shp1_usable = PyArray_DIMS(%(x)s)[3];
}
if ((!%(gx)s)
|| *PyArray_DIMS(%(gx)s)!=4
||(%(gx)s->dimensions[0] != %(x)s->dimensions[0])
||(%(gx)s->dimensions[1] != %(x)s->dimensions[1])
||(%(gx)s->dimensions[2] != %(x)s->dimensions[2])
||(%(gx)s->dimensions[3] != %(x)s->dimensions[3])
||(PyArray_DIMS(%(gx)s)[0] != PyArray_DIMS(%(x)s)[0])
||(PyArray_DIMS(%(gx)s)[1] != PyArray_DIMS(%(x)s)[1])
||(PyArray_DIMS(%(gx)s)[2] != PyArray_DIMS(%(x)s)[2])
||(PyArray_DIMS(%(gx)s)[3] != PyArray_DIMS(%(x)s)[3])
)
{
Py_XDECREF(%(gx)s);
%(gx)s = (PyArrayObject*) PyArray_ZEROS(4, %(x)s->dimensions, x_typenum,0);
%(gx)s = (PyArrayObject*) PyArray_ZEROS(4, PyArray_DIMS(%(x)s), x_typenum,0);
}
for(int b=0;b<%(x)s->dimensions[0];b++){
for(int k=0;k<%(x)s->dimensions[1];k++){
for(int b=0;b<PyArray_DIMS(%(x)s)[0];b++){
for(int k=0;k<PyArray_DIMS(%(x)s)[1];k++){
int mini_i = 0;
int zi = 0;
for(int i=0;i< x_shp0_usable; i++){
......@@ -364,14 +364,14 @@ class DownsampleFactorMaxGrad(Op):
mini_i = (mini_i + 1 == %(ds0)s) ? 0 : mini_i+1;
zi += (mini_i == 0);
for (int j = x_shp1_usable; j < %(x)s->dimensions[3]; ++j) {
for (int j = x_shp1_usable; j < PyArray_DIMS(%(x)s)[3]; ++j) {
dtype_%(gx)s * gxp = ((dtype_%(gx)s*)(PyArray_GETPTR4(%(gx)s,b,k,i,j)));
gxp[0] = 0;
}
}//for i
for(int i = x_shp0_usable; i < %(x)s->dimensions[2]; i++){
for (int j = 0; j < %(x)s->dimensions[3]; ++j) {
for(int i = x_shp0_usable; i < PyArray_DIMS(%(x)s)[2]; i++){
for (int j = 0; j < PyArray_DIMS(%(x)s)[3]; ++j) {
dtype_%(gx)s * gxp = ((dtype_%(gx)s*)(PyArray_GETPTR4(%(gx)s,b,k,i,j)));
gxp[0] = 0;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论