Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1b293e81
提交
1b293e81
authored
9月 05, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
var->data var->base to PyArray_{DATA,BYTES,BASE}
small fix.
上级
5178e406
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
77 行增加
和
77 行删除
+77
-77
basic.py
theano/tensor/basic.py
+6
-6
blas.py
theano/tensor/blas.py
+16
-16
blas_c.py
theano/tensor/blas_c.py
+30
-30
elemwise.py
theano/tensor/elemwise.py
+2
-2
elemwise_cgen.py
theano/tensor/elemwise_cgen.py
+3
-3
Conv3D.py
theano/tensor/nnet/Conv3D.py
+1
-1
ConvGrad3D.py
theano/tensor/nnet/ConvGrad3D.py
+3
-3
ConvTransp3D.py
theano/tensor/nnet/ConvTransp3D.py
+3
-3
nnet.py
theano/tensor/nnet/nnet.py
+13
-13
没有找到文件。
theano/tensor/basic.py
浏览文件 @
1b293e81
...
@@ -1972,7 +1972,7 @@ class ScalarFromTensor(Op):
...
@@ -1972,7 +1972,7 @@ class ScalarFromTensor(Op):
z
,
=
outputs
z
,
=
outputs
fail
=
sub
[
'fail'
]
fail
=
sub
[
'fail'
]
return
"""
return
"""
%(z)
s = ((dtype_
%(x)
s*)(
%(x)
s->data
))[0];
%(z)
s = ((dtype_
%(x)
s*)(
PyArray_DATA(
%(x)
s)
))[0];
"""
%
locals
()
"""
%
locals
()
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
...
@@ -3087,7 +3087,7 @@ class Alloc(gof.Op):
...
@@ -3087,7 +3087,7 @@ class Alloc(gof.Op):
# Initialize shape
# Initialize shape
for
i
,
shp_i
in
enumerate
(
inp
[
1
:]):
for
i
,
shp_i
in
enumerate
(
inp
[
1
:]):
code
+=
"""
code
+=
"""
shape[
%(i)
s] = ((dtype_
%(shp_i)
s*)
%(shp_i)
s->data
)[0];
shape[
%(i)
s] = ((dtype_
%(shp_i)
s*)
PyArray_DATA(
%(shp_i)
s)
)[0];
"""
%
dict
(
i
=
i
,
shp_i
=
shp_i
)
"""
%
dict
(
i
=
i
,
shp_i
=
shp_i
)
code
+=
"""
code
+=
"""
...
@@ -4049,7 +4049,7 @@ class Subtensor(Op):
...
@@ -4049,7 +4049,7 @@ class Subtensor(Op):
%(view_ndim)
s,
%(view_ndim)
s,
PyArray_DIMS(
%(x)
s),
PyArray_DIMS(
%(x)
s),
PyArray_STRIDES(
%(x)
s),
PyArray_STRIDES(
%(x)
s),
%(x)
s->data
,
PyArray_DATA(
%(x)
s)
,
%(x)
s->flags,
%(x)
s->flags,
NULL);
NULL);
if (!xview)
if (!xview)
...
@@ -4203,7 +4203,7 @@ class Subtensor(Op):
...
@@ -4203,7 +4203,7 @@ class Subtensor(Op):
part1
=
"""
part1
=
"""
if (
%(z)
s) Py_DECREF(
%(z)
s);
if (
%(z)
s) Py_DECREF(
%(z)
s);
Py_INCREF(py_
%(x)
s);
Py_INCREF(py_
%(x)
s);
xview->base
= py_
%(x)
s;
PyArray_BASE(xview)
= py_
%(x)
s;
assert(py_
%(x)
s == (PyObject*)
%(x)
s);
assert(py_
%(x)
s == (PyObject*)
%(x)
s);
%(z)
s = xview;
%(z)
s = xview;
"""
%
locals
()
"""
%
locals
()
...
@@ -4529,7 +4529,7 @@ class IncSubtensor(Op):
...
@@ -4529,7 +4529,7 @@ class IncSubtensor(Op):
if (add_rval)
if (add_rval)
{
{
assert (PyArray_Check((PyObject*)add_rval));
assert (PyArray_Check((PyObject*)add_rval));
assert (
add_rval->data == xview->data
);
assert (
PyArray_DATA(add_rval) == PyArray_DATA(xview)
);
Py_DECREF(add_rval);
Py_DECREF(add_rval);
}
}
else
else
...
@@ -5385,7 +5385,7 @@ class Reshape(Op):
...
@@ -5385,7 +5385,7 @@ class Reshape(Op):
// -- will err if this will downcast. This could happen if the
// -- will err if this will downcast. This could happen if the
// -- user pass an int64 dtype, but npy_intp endup being int32.
// -- user pass an int64 dtype, but npy_intp endup being int32.
new_dims[ii] = ((dtype_
%(shp)
s*)(
new_dims[ii] = ((dtype_
%(shp)
s*)(
%(shp)
s->data
+ ii * PyArray_STRIDES(
%(shp)
s)[0]))[0];
PyArray_DATA(
%(shp)
s)
+ ii * PyArray_STRIDES(
%(shp)
s)[0]))[0];
}
}
Py_XDECREF(
%(z)
s);
Py_XDECREF(
%(z)
s);
%(z)
s = (PyArrayObject *) PyArray_Newshape(
%(x)
s, &newshape,
%(z)
s = (PyArrayObject *) PyArray_Newshape(
%(x)
s, &newshape,
...
...
theano/tensor/blas.py
浏览文件 @
1b293e81
...
@@ -921,10 +921,10 @@ class Gemm(GemmRelated):
...
@@ -921,10 +921,10 @@ class Gemm(GemmRelated):
if (
%(_zout)
s->descr->type_num == NPY_FLOAT)
if (
%(_zout)
s->descr->type_num == NPY_FLOAT)
{
{
float * zoutdata = (float*)
%(_zout)
s->data
;
float * zoutdata = (float*)
PyArray_DATA(
%(_zout)
s)
;
int zoi = Sz[0] / sizeof(float);
int zoi = Sz[0] / sizeof(float);
int zoj = Sz[1] / sizeof(float);
int zoj = Sz[1] / sizeof(float);
const float * zdata = (float*)
%(_z)
s->data
;
const float * zdata = (float*)
PyArray_DATA(
%(_z)
s)
;
int zi = PyArray_STRIDES(
%(_z)
s)[0]/sizeof(float);
int zi = PyArray_STRIDES(
%(_z)
s)[0]/sizeof(float);
int zj = PyArray_STRIDES(
%(_z)
s)[1]/sizeof(float);
int zj = PyArray_STRIDES(
%(_z)
s)[1]/sizeof(float);
for (int i = 0; i < Nz[0]; ++i)
for (int i = 0; i < Nz[0]; ++i)
...
@@ -937,10 +937,10 @@ class Gemm(GemmRelated):
...
@@ -937,10 +937,10 @@ class Gemm(GemmRelated):
}
}
else if (
%(_zout)
s->descr->type_num == NPY_DOUBLE)
else if (
%(_zout)
s->descr->type_num == NPY_DOUBLE)
{
{
double * zoutdata = (double*)
%(_zout)
s->data
;
double * zoutdata = (double*)
PyArray_DATA(
%(_zout)
s)
;
int zoi = Sz[0] / sizeof(double);
int zoi = Sz[0] / sizeof(double);
int zoj = Sz[1] / sizeof(double);
int zoj = Sz[1] / sizeof(double);
const double * zdata = (double*)
%(_z)
s->data
;
const double * zdata = (double*)
PyArray_DATA(
%(_z)
s)
;
int zi = PyArray_STRIDES(
%(_z)
s)[0]/sizeof(double);
int zi = PyArray_STRIDES(
%(_z)
s)[0]/sizeof(double);
int zj = PyArray_STRIDES(
%(_z)
s)[1]/sizeof(double);
int zj = PyArray_STRIDES(
%(_z)
s)[1]/sizeof(double);
for (int i = 0; i < Nz[0]; ++i)
for (int i = 0; i < Nz[0]; ++i)
...
@@ -962,21 +962,21 @@ class Gemm(GemmRelated):
...
@@ -962,21 +962,21 @@ class Gemm(GemmRelated):
case_float_ab_constants
=
"""
case_float_ab_constants
=
"""
#define REAL float
#define REAL float
float a = (
%(_a)
s->descr->type_num == NPY_FLOAT)
float a = (
%(_a)
s->descr->type_num == NPY_FLOAT)
? (REAL)(((float*)
%(_a)
s->data
)[0])
? (REAL)(((float*)
PyArray_DATA(
%(_a)
s)
)[0])
: (REAL)(((double*)
%(_a)
s->data
)[0]);
: (REAL)(((double*)
PyArray_DATA(
%(_a)
s)
)[0]);
float b = (
%(_b)
s->descr->type_num == NPY_FLOAT) ?
float b = (
%(_b)
s->descr->type_num == NPY_FLOAT) ?
(REAL)(((float*)
%(_b)
s->data
)[0])
(REAL)(((float*)
PyArray_DATA(
%(_b)
s)
)[0])
: (REAL)(((double*)
%(_b)
s->data
)[0]);
: (REAL)(((double*)
PyArray_DATA(
%(_b)
s)
)[0]);
#undef REAL
#undef REAL
"""
"""
case_double_ab_constants
=
"""
case_double_ab_constants
=
"""
#define REAL double
#define REAL double
double a = (
%(_a)
s->descr->type_num == NPY_FLOAT)
double a = (
%(_a)
s->descr->type_num == NPY_FLOAT)
? (REAL)(((float*)
%(_a)
s->data
)[0])
? (REAL)(((float*)
PyArray_DATA(
%(_a)
s)
)[0])
: (REAL)(((double*)
%(_a)
s->data
)[0]);
: (REAL)(((double*)
PyArray_DATA(
%(_a)
s)
)[0]);
double b = (
%(_b)
s->descr->type_num == NPY_FLOAT) ?
double b = (
%(_b)
s->descr->type_num == NPY_FLOAT) ?
(REAL)(((float*)
%(_b)
s->data
)[0])
(REAL)(((float*)
PyArray_DATA(
%(_b)
s)
)[0])
: (REAL)(((double*)
%(_b)
s->data
)[0]);
: (REAL)(((double*)
PyArray_DATA(
%(_b)
s)
)[0]);
#undef REAL
#undef REAL
"""
"""
...
@@ -1762,8 +1762,8 @@ class Dot22Scalar(GemmRelated):
...
@@ -1762,8 +1762,8 @@ class Dot22Scalar(GemmRelated):
case_float_ab_constants
=
"""
case_float_ab_constants
=
"""
#define REAL float
#define REAL float
float a = (
%(_a)
s->descr->type_num == NPY_FLOAT)
float a = (
%(_a)
s->descr->type_num == NPY_FLOAT)
? (REAL)(((float*)
%(_a)
s->data
)[0])
? (REAL)(((float*)
PyArray_DATA(
%(_a)
s)
)[0])
: (REAL)(((double*)
%(_a)
s->data
)[0]);
: (REAL)(((double*)
PyArray_DATA(
%(_a)
s)
)[0]);
#undef REAL
#undef REAL
float b = 0.0;
float b = 0.0;
"""
"""
...
@@ -1771,8 +1771,8 @@ class Dot22Scalar(GemmRelated):
...
@@ -1771,8 +1771,8 @@ class Dot22Scalar(GemmRelated):
case_double_ab_constants
=
"""
case_double_ab_constants
=
"""
#define REAL double
#define REAL double
double a = (
%(_a)
s->descr->type_num == NPY_FLOAT)
double a = (
%(_a)
s->descr->type_num == NPY_FLOAT)
? (REAL)(((float*)
%(_a)
s->data
)[0])
? (REAL)(((float*)
PyArray_DATA(
%(_a)
s)
)[0])
: (REAL)(((double*)
%(_a)
s->data
)[0]);
: (REAL)(((double*)
PyArray_DATA(
%(_a)
s)
)[0]);
#undef REAL
#undef REAL
double b = 0.0;
double b = 0.0;
"""
"""
...
...
theano/tensor/blas_c.py
浏览文件 @
1b293e81
...
@@ -103,8 +103,8 @@ def ger_c_code(A, a, x, y, Z, destructive, fail):
...
@@ -103,8 +103,8 @@ def ger_c_code(A, a, x, y, Z, destructive, fail):
}
}
if (
%(Z)
s->descr->type_num == NPY_FLOAT)
if (
%(Z)
s->descr->type_num == NPY_FLOAT)
{
{
float * zoutdata = (float*)
%(Z)
s->data
;
float * zoutdata = (float*)
PyArray_DATA(
%(Z)
s)
;
const float * zdata = (float*)
%(A)
s->data
;
const float * zdata = (float*)
PyArray_DATA(
%(A)
s)
;
int Ai = PyArray_STRIDES(
%(A)
s)[0]/sizeof(float);
int Ai = PyArray_STRIDES(
%(A)
s)[0]/sizeof(float);
int Aj = PyArray_STRIDES(
%(A)
s)[1]/sizeof(float);
int Aj = PyArray_STRIDES(
%(A)
s)[1]/sizeof(float);
int Zi = PyArray_STRIDES(
%(Z)
s)[0]/sizeof(float);
int Zi = PyArray_STRIDES(
%(Z)
s)[0]/sizeof(float);
...
@@ -119,8 +119,8 @@ def ger_c_code(A, a, x, y, Z, destructive, fail):
...
@@ -119,8 +119,8 @@ def ger_c_code(A, a, x, y, Z, destructive, fail):
}
}
else if (
%(Z)
s->descr->type_num == NPY_DOUBLE)
else if (
%(Z)
s->descr->type_num == NPY_DOUBLE)
{
{
double * zoutdata = (double*)
%(Z)
s->data
;
double * zoutdata = (double*)
PyArray_DATA(
%(Z)
s)
;
const double * zdata = (double*)
%(A)
s->data
;
const double * zdata = (double*)
PyArray_DATA(
%(A)
s)
;
int Ai = PyArray_STRIDES(
%(A)
s)[0]/sizeof(double);
int Ai = PyArray_STRIDES(
%(A)
s)[0]/sizeof(double);
int Aj = PyArray_STRIDES(
%(A)
s)[1]/sizeof(double);
int Aj = PyArray_STRIDES(
%(A)
s)[1]/sizeof(double);
int Zi = PyArray_STRIDES(
%(Z)
s)[0]/sizeof(double);
int Zi = PyArray_STRIDES(
%(Z)
s)[0]/sizeof(double);
...
@@ -166,8 +166,8 @@ def ger_c_code(A, a, x, y, Z, destructive, fail):
...
@@ -166,8 +166,8 @@ def ger_c_code(A, a, x, y, Z, destructive, fail):
int Sz0 = (Nz0 > 1) ? (PyArray_STRIDES(
%(Z)
s)[0] / elemsize) : (Nz1 + 1);
int Sz0 = (Nz0 > 1) ? (PyArray_STRIDES(
%(Z)
s)[0] / elemsize) : (Nz1 + 1);
int Sz1 = (Nz1 > 1) ? (PyArray_STRIDES(
%(Z)
s)[1] / elemsize) : (Nz0 + 1);
int Sz1 = (Nz1 > 1) ? (PyArray_STRIDES(
%(Z)
s)[1] / elemsize) : (Nz0 + 1);
dtype_
%(x)
s* x_data = (dtype_
%(x)
s*)
%(x)
s->data
;
dtype_
%(x)
s* x_data = (dtype_
%(x)
s*)
PyArray_DATA(
%(x)
s)
;
dtype_
%(y)
s* y_data = (dtype_
%(y)
s*)
%(y)
s->data
;
dtype_
%(y)
s* y_data = (dtype_
%(y)
s*)
PyArray_DATA(
%(y)
s)
;
// gemv expects pointers to the beginning of memory arrays,
// gemv expects pointers to the beginning of memory arrays,
// but numpy provides provides a pointer to the first element,
// but numpy provides provides a pointer to the first element,
// so when the stride is negative, we need to get the last one.
// so when the stride is negative, we need to get the last one.
...
@@ -181,19 +181,19 @@ def ger_c_code(A, a, x, y, Z, destructive, fail):
...
@@ -181,19 +181,19 @@ def ger_c_code(A, a, x, y, Z, destructive, fail):
if (
%(Z)
s->descr->type_num == NPY_FLOAT)
if (
%(Z)
s->descr->type_num == NPY_FLOAT)
{
{
//fprintf(stderr, "A
\\
n");
//fprintf(stderr, "A
\\
n");
float alpha = ((dtype_
%(a)
s*)
%(a)
s->data
)[0];
float alpha = ((dtype_
%(a)
s*)
PyArray_DATA(
%(a)
s)
)[0];
sger_(&Nz0, &Nz1, &alpha,
sger_(&Nz0, &Nz1, &alpha,
(float*)x_data, &Sx,
(float*)x_data, &Sx,
(float*)y_data, &Sy,
(float*)y_data, &Sy,
(float*)(
%(Z)
s->data
), &Sz1);
(float*)(
PyArray_DATA(
%(Z)
s)
), &Sz1);
}
}
else if (
%(Z)
s->descr->type_num == NPY_DOUBLE)
else if (
%(Z)
s->descr->type_num == NPY_DOUBLE)
{
{
double alpha = ((dtype_
%(a)
s*)
%(a)
s->data
)[0];
double alpha = ((dtype_
%(a)
s*)
PyArray_DATA(
%(a)
s)
)[0];
dger_(&Nz0, &Nz1, &alpha,
dger_(&Nz0, &Nz1, &alpha,
(double*)x_data, &Sx,
(double*)x_data, &Sx,
(double*)y_data, &Sy,
(double*)y_data, &Sy,
(double*)(
%(Z)
s->data
), &Sz1);
(double*)(
PyArray_DATA(
%(Z)
s)
), &Sz1);
}
}
else {
else {
PyErr_SetString(PyExc_NotImplementedError,
PyErr_SetString(PyExc_NotImplementedError,
...
@@ -206,21 +206,21 @@ def ger_c_code(A, a, x, y, Z, destructive, fail):
...
@@ -206,21 +206,21 @@ def ger_c_code(A, a, x, y, Z, destructive, fail):
if (
%(Z)
s->descr->type_num == NPY_FLOAT)
if (
%(Z)
s->descr->type_num == NPY_FLOAT)
{
{
//fprintf(stderr, "B
%%
i
%%
i
%%
i
%%
i
\\
n", Nz0, Nz1, Sz0, Sz1);
//fprintf(stderr, "B
%%
i
%%
i
%%
i
%%
i
\\
n", Nz0, Nz1, Sz0, Sz1);
float alpha = ((dtype_
%(a)
s*)(
%(a)
s->data
))[0];
float alpha = ((dtype_
%(a)
s*)(
PyArray_DATA(
%(a)
s)
))[0];
//fprintf(stderr, "alpha=
%%
f
\\
n", alpha);
//fprintf(stderr, "alpha=
%%
f
\\
n", alpha);
//fprintf(stderr, "sx sy
%%
i
%%
i
\\
n", Sx, Sy);
//fprintf(stderr, "sx sy
%%
i
%%
i
\\
n", Sx, Sy);
sger_(&Nz1, &Nz0, &alpha,
sger_(&Nz1, &Nz0, &alpha,
(float*)y_data, &Sy,
(float*)y_data, &Sy,
(float*)x_data, &Sx,
(float*)x_data, &Sx,
(float*)(
%(Z)
s->data
), &Sz0);
(float*)(
PyArray_DATA(
%(Z)
s)
), &Sz0);
}
}
else if (
%(Z)
s->descr->type_num == NPY_DOUBLE)
else if (
%(Z)
s->descr->type_num == NPY_DOUBLE)
{
{
double alpha = ((dtype_
%(a)
s*)
%(a)
s->data
)[0];
double alpha = ((dtype_
%(a)
s*)
PyArray_DATA(
%(a)
s)
)[0];
dger_(&Nz1, &Nz0, &alpha,
dger_(&Nz1, &Nz0, &alpha,
(double*)y_data, &Sy,
(double*)y_data, &Sy,
(double*)x_data, &Sx,
(double*)x_data, &Sx,
(double*)(
%(Z)
s->data
), &Sz0);
(double*)(
PyArray_DATA(
%(Z)
s)
), &Sz0);
}
}
else
else
{
{
...
@@ -341,7 +341,7 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
...
@@ -341,7 +341,7 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
%(fail)
s;
%(fail)
s;
}
}
fbeta = dbeta = ((dtype_
%(beta)
s*)
%(beta)
s->data
)[0];
fbeta = dbeta = ((dtype_
%(beta)
s*)
PyArray_DATA(
%(beta)
s)
)[0];
// copy aa if not destructive
// copy aa if not destructive
if (!
%(destructive)
s)
if (!
%(destructive)
s)
...
@@ -367,8 +367,8 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
...
@@ -367,8 +367,8 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
{
{
if (
%(zz)
s->descr->type_num == NPY_FLOAT)
if (
%(zz)
s->descr->type_num == NPY_FLOAT)
{
{
float * zoutdata = (float*)
%(zz)
s->data
;
float * zoutdata = (float*)
PyArray_DATA(
%(zz)
s)
;
const float * zdata = (float*)
%(aa)
s->data
;
const float * zdata = (float*)
PyArray_DATA(
%(aa)
s)
;
int Ai = PyArray_STRIDES(
%(aa)
s)[0]/sizeof(float);
int Ai = PyArray_STRIDES(
%(aa)
s)[0]/sizeof(float);
int Zi = PyArray_STRIDES(
%(zz)
s)[0]/sizeof(float);
int Zi = PyArray_STRIDES(
%(zz)
s)[0]/sizeof(float);
for (int i = 0; i < PyArray_DIMS(
%(aa)
s)[0]; ++i)
for (int i = 0; i < PyArray_DIMS(
%(aa)
s)[0]; ++i)
...
@@ -378,8 +378,8 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
...
@@ -378,8 +378,8 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
}
}
else if (
%(xx)
s->descr->type_num == NPY_DOUBLE)
else if (
%(xx)
s->descr->type_num == NPY_DOUBLE)
{
{
double * zoutdata = (double*)
%(zz)
s->data
;
double * zoutdata = (double*)
PyArray_DATA(
%(zz)
s)
;
const double * zdata = (double*)
%(aa)
s->data
;
const double * zdata = (double*)
PyArray_DATA(
%(aa)
s)
;
int Ai = PyArray_STRIDES(
%(aa)
s)[0]/sizeof(double);
int Ai = PyArray_STRIDES(
%(aa)
s)[0]/sizeof(double);
int Zi = PyArray_STRIDES(
%(zz)
s)[0]/sizeof(double);
int Zi = PyArray_STRIDES(
%(zz)
s)[0]/sizeof(double);
for (int i = 0; i < PyArray_DIMS(
%(aa)
s)[0]; ++i)
for (int i = 0; i < PyArray_DIMS(
%(aa)
s)[0]; ++i)
...
@@ -421,8 +421,8 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
...
@@ -421,8 +421,8 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
int Sz = PyArray_STRIDES(
%(zz)
s)[0] / elemsize;
int Sz = PyArray_STRIDES(
%(zz)
s)[0] / elemsize;
int Sy = PyArray_STRIDES(
%(yy)
s)[0] / elemsize;
int Sy = PyArray_STRIDES(
%(yy)
s)[0] / elemsize;
dtype_
%(yy)
s* yy_data = (dtype_
%(yy)
s*)
%(yy)
s->data
;
dtype_
%(yy)
s* yy_data = (dtype_
%(yy)
s*)
PyArray_DATA(
%(yy)
s)
;
dtype_
%(zz)
s* zz_data = (dtype_
%(zz)
s*)
%(zz)
s->data
;
dtype_
%(zz)
s* zz_data = (dtype_
%(zz)
s*)
PyArray_DATA(
%(zz)
s)
;
// gemv expects pointers to the beginning of memory arrays,
// gemv expects pointers to the beginning of memory arrays,
// but numpy provides provides a pointer to the first element,
// but numpy provides provides a pointer to the first element,
// so when the stride is negative, we need to get the last one.
// so when the stride is negative, we need to get the last one.
...
@@ -463,20 +463,20 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
...
@@ -463,20 +463,20 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
if (
%(xx)
s->descr->type_num == NPY_FLOAT)
if (
%(xx)
s->descr->type_num == NPY_FLOAT)
{
{
//fprintf(stderr, "A
\\
n");
//fprintf(stderr, "A
\\
n");
float alpha = ((dtype_
%(alpha)
s*)
%(alpha)
s->data
)[0];
float alpha = ((dtype_
%(alpha)
s*)
PyArray_DATA(
%(alpha)
s)
)[0];
sgemv_(&NOTRANS, &Nx0, &Nx1,
sgemv_(&NOTRANS, &Nx0, &Nx1,
&alpha,
&alpha,
(float*)(
%(xx)
s->data
), &Sx1,
(float*)(
PyArray_DATA(
%(xx)
s)
), &Sx1,
(float*)yy_data, &Sy,
(float*)yy_data, &Sy,
&fbeta,
&fbeta,
(float*)zz_data, &Sz);
(float*)zz_data, &Sz);
}
}
else if (
%(xx)
s->descr->type_num == NPY_DOUBLE)
else if (
%(xx)
s->descr->type_num == NPY_DOUBLE)
{
{
double alpha = ((dtype_
%(alpha)
s*)
%(alpha)
s->data
)[0];
double alpha = ((dtype_
%(alpha)
s*)
PyArray_DATA(
%(alpha)
s)
)[0];
dgemv_(&NOTRANS, &Nx0, &Nx1,
dgemv_(&NOTRANS, &Nx0, &Nx1,
&alpha,
&alpha,
(double*)(
%(xx)
s->data
), &Sx1,
(double*)(
PyArray_DATA(
%(xx)
s)
), &Sx1,
(double*)yy_data, &Sy,
(double*)yy_data, &Sy,
&dbeta,
&dbeta,
(double*)zz_data, &Sz);
(double*)zz_data, &Sz);
...
@@ -494,22 +494,22 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
...
@@ -494,22 +494,22 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
{
{
//fprintf(stderr, "B
%%
i
%%
i
%%
i
%%
i
\\
n",
//fprintf(stderr, "B
%%
i
%%
i
%%
i
%%
i
\\
n",
// Nz0, Nz1, Sz0, Sz1);
// Nz0, Nz1, Sz0, Sz1);
float alpha = ((dtype_
%(alpha)
s*)
%(alpha)
s->data
)[0];
float alpha = ((dtype_
%(alpha)
s*)
PyArray_DATA(
%(alpha)
s)
)[0];
//fprintf(stderr, "alpha=
%%
f
\\
n", alpha);
//fprintf(stderr, "alpha=
%%
f
\\
n", alpha);
//fprintf(stderr, "sx sy
%%
i
%%
i
\\
n", Sx, Sy);
//fprintf(stderr, "sx sy
%%
i
%%
i
\\
n", Sx, Sy);
sgemv_(&TRANS, &Nx1, &Nx0,
sgemv_(&TRANS, &Nx1, &Nx0,
&alpha,
&alpha,
(float*)(
%(xx)
s->data
), &Sx0,
(float*)(
PyArray_DATA(
%(xx)
s)
), &Sx0,
(float*)yy_data, &Sy,
(float*)yy_data, &Sy,
&fbeta,
&fbeta,
(float*)zz_data, &Sz);
(float*)zz_data, &Sz);
}
}
else if (
%(xx)
s->descr->type_num == NPY_DOUBLE)
else if (
%(xx)
s->descr->type_num == NPY_DOUBLE)
{
{
double alpha = ((dtype_
%(alpha)
s*)
%(alpha)
s->data
)[0];
double alpha = ((dtype_
%(alpha)
s*)
PyArray_DATA(
%(alpha)
s)
)[0];
dgemv_(&TRANS, &Nx1, &Nx0,
dgemv_(&TRANS, &Nx1, &Nx0,
&alpha,
&alpha,
(double*)(
%(xx)
s->data
), &Sx0,
(double*)(
PyArray_DATA(
%(xx)
s)
), &Sx0,
(double*)yy_data, &Sy,
(double*)yy_data, &Sy,
&dbeta,
&dbeta,
(double*)zz_data, &Sz);
(double*)zz_data, &Sz);
...
@@ -534,7 +534,7 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
...
@@ -534,7 +534,7 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail):
// the matrix has at least one dim of length 0
// the matrix has at least one dim of length 0
// so we do this loop, which either iterates over 0 elements
// so we do this loop, which either iterates over 0 elements
// or else it does the right thing for length-0 x.
// or else it does the right thing for length-0 x.
dtype_
%(zz)
s * zptr = (dtype_
%(zz)
s*)(
%(zz)
s->data
);
dtype_
%(zz)
s * zptr = (dtype_
%(zz)
s*)(
PyArray_DATA(
%(zz)
s)
);
for (int i = 0; i < Nx0; ++i)
for (int i = 0; i < Nx0; ++i)
{
{
zptr[i * Sz] *= dbeta;
zptr[i * Sz] *= dbeta;
...
...
theano/tensor/elemwise.py
浏览文件 @
1b293e81
...
@@ -326,14 +326,14 @@ class DimShuffle(Op):
...
@@ -326,14 +326,14 @@ class DimShuffle(Op):
(
'
%(res)
s = (PyArrayObject*)PyArray_New(&PyArray_Type, '
(
'
%(res)
s = (PyArrayObject*)PyArray_New(&PyArray_Type, '
''
+
str
(
nd_out
)
+
', dimensions, '
''
+
str
(
nd_out
)
+
', dimensions, '
'PyArray_TYPE(
%(basename)
s), strides, '
'PyArray_TYPE(
%(basename)
s), strides, '
'
%(basename)
s->data
, PyArray_ITEMSIZE(
%(basename)
s), '
'
PyArray_DATA(
%(basename)
s)
, PyArray_ITEMSIZE(
%(basename)
s), '
#borrow only the writable flag from the base
#borrow only the writable flag from the base
# the NPY_OWNDATA flag will default to 0.
# the NPY_OWNDATA flag will default to 0.
'(NPY_WRITEABLE*PyArray_ISWRITEABLE(
%(basename)
s)), NULL)'
),
'(NPY_WRITEABLE*PyArray_ISWRITEABLE(
%(basename)
s)), NULL)'
),
#recalculate flags: CONTIGUOUS, FORTRAN, ALIGNED
#recalculate flags: CONTIGUOUS, FORTRAN, ALIGNED
'PyArray_UpdateFlags(
%(res)
s, NPY_UPDATE_ALL)'
,
'PyArray_UpdateFlags(
%(res)
s, NPY_UPDATE_ALL)'
,
#we are making a view in both inplace and non-inplace cases
#we are making a view in both inplace and non-inplace cases
'
%(res)
s->base
= (PyObject*)
%(basename)
s'
,
'
PyArray_BASE(
%(res)
s)
= (PyObject*)
%(basename)
s'
,
'}'
]
'}'
]
full_code
=
statements
(
check_input_nd
full_code
=
statements
(
check_input_nd
...
...
theano/tensor/elemwise_cgen.py
浏览文件 @
1b293e81
...
@@ -215,11 +215,11 @@ def make_loop(loop_orders, dtypes, loop_tasks, sub):
...
@@ -215,11 +215,11 @@ def make_loop(loop_orders, dtypes, loop_tasks, sub):
for
j
,
index
in
enumerate
(
loop_order
):
for
j
,
index
in
enumerate
(
loop_order
):
if
index
!=
'x'
:
if
index
!=
'x'
:
preloops
.
setdefault
(
j
,
""
)
preloops
.
setdefault
(
j
,
""
)
preloops
[
j
]
+=
(
"
%%
(lv
%(i)
s)s_iter = (
%(dtype)
s*)(
%%
(lv
%(i)
s)s->data
);
\n
"
%
locals
())
%
sub
preloops
[
j
]
+=
(
"
%%
(lv
%(i)
s)s_iter = (
%(dtype)
s*)(
PyArray_DATA(
%%
(lv
%(i)
s)s)
);
\n
"
%
locals
())
%
sub
break
break
else
:
# all broadcastable
else
:
# all broadcastable
preloops
.
setdefault
(
0
,
""
)
preloops
.
setdefault
(
0
,
""
)
preloops
[
0
]
+=
(
"
%%
(lv
%(i)
s)s_iter = (
%(dtype)
s*)(
%%
(lv
%(i)
s)s->data
);
\n
"
%
locals
())
%
sub
preloops
[
0
]
+=
(
"
%%
(lv
%(i)
s)s_iter = (
%(dtype)
s*)(
PyArray_DATA(
%%
(lv
%(i)
s)s)
);
\n
"
%
locals
())
%
sub
if
len
(
loop_tasks
)
==
1
:
if
len
(
loop_tasks
)
==
1
:
s
=
preloops
.
get
(
0
,
""
)
s
=
preloops
.
get
(
0
,
""
)
...
@@ -375,7 +375,7 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub):
...
@@ -375,7 +375,7 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub):
declare_iter
=
""
declare_iter
=
""
for
i
,
dtype
in
enumerate
(
dtypes
):
for
i
,
dtype
in
enumerate
(
dtypes
):
var
=
sub
[
"lv
%
i"
%
i
]
var
=
sub
[
"lv
%
i"
%
i
]
declare_iter
+=
"
%(var)
s_iter = (
%(dtype)
s*)(
%(var)
s->data
);
\n
"
%
locals
()
declare_iter
+=
"
%(var)
s_iter = (
%(dtype)
s*)(
PyArray_DATA(
%(var)
s)
);
\n
"
%
locals
()
loop
=
inner_task
loop
=
inner_task
for
i
in
reversed
(
range
(
nnested
)):
for
i
in
reversed
(
range
(
nnested
)):
...
...
theano/tensor/nnet/Conv3D.py
浏览文件 @
1b293e81
...
@@ -305,7 +305,7 @@ class Conv3D(theano.Op):
...
@@ -305,7 +305,7 @@ class Conv3D(theano.Op):
{ // extra scope so fail works
{ // extra scope so fail works
#define ELEM_AT(x, i) * ( dtype_ ## x *) (
x->data
+ (i) )
#define ELEM_AT(x, i) * ( dtype_ ## x *) (
PyArray_BYTES(x)
+ (i) )
const int ws0 = PyArray_STRIDES(
%(W)
s)[0];
const int ws0 = PyArray_STRIDES(
%(W)
s)[0];
...
...
theano/tensor/nnet/ConvGrad3D.py
浏览文件 @
1b293e81
...
@@ -142,7 +142,7 @@ class ConvGrad3D(theano.Op):
...
@@ -142,7 +142,7 @@ class ConvGrad3D(theano.Op):
}
}
{ //extra scope so that fail will not jump over declarations
{ //extra scope so that fail will not jump over declarations
dtype_
%(WShape)
s * WShape = (dtype_
%(WShape)
s *)
%(WShape)
s->data
;
dtype_
%(WShape)
s * WShape = (dtype_
%(WShape)
s *)
PyArray_DATA(
%(WShape)
s)
;
const int outputChannels = WShape[0];
const int outputChannels = WShape[0];
const int inputChannels = PyArray_DIMS(
%(V)
s)[4];
const int inputChannels = PyArray_DIMS(
%(V)
s)[4];
if (WShape[4] != inputChannels)
if (WShape[4] != inputChannels)
...
@@ -226,9 +226,9 @@ class ConvGrad3D(theano.Op):
...
@@ -226,9 +226,9 @@ class ConvGrad3D(theano.Op):
}
}
{ //extra scope so fail works
{ //extra scope so fail works
#define ELEM5(x, i,j,k,l,m) * ( dtype_ ## x *) (
x->data
+ (i)*PyArray_STRIDES(x)[0]+(j)*PyArray_STRIDES(x)[1]+(k)*PyArray_STRIDES(x)[2]+(l)*PyArray_STRIDES(x)[3]+(m)*PyArray_STRIDES(x)[4] )
#define ELEM5(x, i,j,k,l,m) * ( dtype_ ## x *) (
PyArray_DATA(x)
+ (i)*PyArray_STRIDES(x)[0]+(j)*PyArray_STRIDES(x)[1]+(k)*PyArray_STRIDES(x)[2]+(l)*PyArray_STRIDES(x)[3]+(m)*PyArray_STRIDES(x)[4] )
#define ELEM_AT(x, i) * ( dtype_ ## x *) (
x->data
+ (i) )
#define ELEM_AT(x, i) * ( dtype_ ## x *) (
PyArray_BYTES(x)
+ (i) )
const int dhs3 = PyArray_STRIDES(
%(dCdH)
s)[3];
const int dhs3 = PyArray_STRIDES(
%(dCdH)
s)[3];
const int dtvs3 = dt * PyArray_STRIDES(
%(V)
s)[3];
const int dtvs3 = dt * PyArray_STRIDES(
%(V)
s)[3];
...
...
theano/tensor/nnet/ConvTransp3D.py
浏览文件 @
1b293e81
...
@@ -237,12 +237,12 @@ class ConvTransp3D(theano.Op):
...
@@ -237,12 +237,12 @@ class ConvTransp3D(theano.Op):
{ // for fail 6
{ // for fail 6
#define ELEM5(x, i,j,k,l,m) * ( dtype_ ## x *) (
x->data
+ (i)*PyArray_STRIDES(x)[0]+(j)*PyArray_STRIDES(x)[1]+(k)*PyArray_STRIDES(x)[2]+(l)*PyArray_STRIDES(x)[3]+(m)*PyArray_STRIDES(x)[4] )
#define ELEM5(x, i,j,k,l,m) * ( dtype_ ## x *) (
PyArray_DATA(x)
+ (i)*PyArray_STRIDES(x)[0]+(j)*PyArray_STRIDES(x)[1]+(k)*PyArray_STRIDES(x)[2]+(l)*PyArray_STRIDES(x)[3]+(m)*PyArray_STRIDES(x)[4] )
#define ELEM_AT(x, i) * ( dtype_ ## x *) (
x->data
+ (i) )
#define ELEM_AT(x, i) * ( dtype_ ## x *) (
PyArray_BYTES(x)
+ (i) )
dtype_
%(b)
s * b = (dtype_
%(b)
s *)
%(b)
s->data
;
dtype_
%(b)
s * b = (dtype_
%(b)
s *)
PyArray_DATA(
%(b)
s)
;
int rs4 = PyArray_STRIDES(
%(R)
s)[4];
int rs4 = PyArray_STRIDES(
%(R)
s)[4];
int ws0 = PyArray_STRIDES(
%(W)
s)[0];
int ws0 = PyArray_STRIDES(
%(W)
s)[0];
...
...
theano/tensor/nnet/nnet.py
浏览文件 @
1b293e81
...
@@ -159,9 +159,9 @@ class SoftmaxWithBias(gof.Op):
...
@@ -159,9 +159,9 @@ class SoftmaxWithBias(gof.Op):
double sum = 0.0;
double sum = 0.0;
bool discount_max = false;
bool discount_max = false;
const dtype_
%(x)
s* __restrict__ x_i = (dtype_
%(x)
s*)(
%(x)
s->data
+ PyArray_STRIDES(
%(x)
s)[0] * i);
const dtype_
%(x)
s* __restrict__ x_i = (dtype_
%(x)
s*)(
PyArray_DATA(
%(x)
s)
+ PyArray_STRIDES(
%(x)
s)[0] * i);
const dtype_
%(b)
s* __restrict__ b_i = (dtype_
%(b)
s*)(
%(b)
s->data
);
const dtype_
%(b)
s* __restrict__ b_i = (dtype_
%(b)
s*)(
PyArray_DATA(
%(b)
s)
);
dtype_
%(sm)
s* __restrict__ sm_i = (dtype_
%(sm)
s*)(
%(sm)
s->data
+ PyArray_STRIDES(
%(sm)
s)[0] * i);
dtype_
%(sm)
s* __restrict__ sm_i = (dtype_
%(sm)
s*)(
PyArray_DATA(
%(sm)
s)
+ PyArray_STRIDES(
%(sm)
s)[0] * i);
"""
"""
inside_row_loop
=
"""
inside_row_loop
=
"""
...
@@ -306,11 +306,11 @@ class SoftmaxGrad(gof.Op):
...
@@ -306,11 +306,11 @@ class SoftmaxGrad(gof.Op):
for (size_t i = 0; i < PyArray_DIMS(
%(dx)
s)[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
+ PyArray_STRIDES(
%(dy)
s)[0] * i);
const dtype_
%(dy)
s* __restrict__ dy_i = (dtype_
%(dy)
s*) (
PyArray_DATA(
%(dy)
s)
+ PyArray_STRIDES(
%(dy)
s)[0] * i);
npy_intp Sdy = PyArray_STRIDES(
%(dy)
s)[1]/sizeof(dtype_
%(dy)
s);
npy_intp Sdy = PyArray_STRIDES(
%(dy)
s)[1]/sizeof(dtype_
%(dy)
s);
const dtype_
%(sm)
s* __restrict__ sm_i = (dtype_
%(sm)
s*) (
%(sm)
s->data
+ PyArray_STRIDES(
%(sm)
s)[0] * i);
const dtype_
%(sm)
s* __restrict__ sm_i = (dtype_
%(sm)
s*) (
PyArray_DATA(
%(sm)
s)
+ PyArray_STRIDES(
%(sm)
s)[0] * i);
npy_intp Ssm = PyArray_STRIDES(
%(sm)
s)[1]/sizeof(dtype_
%(sm)
s);
npy_intp Ssm = PyArray_STRIDES(
%(sm)
s)[1]/sizeof(dtype_
%(sm)
s);
dtype_
%(dx)
s* __restrict__ dx_i = (dtype_
%(dx)
s*) (
%(dx)
s->data
+ PyArray_STRIDES(
%(dx)
s)[0] * i);
dtype_
%(dx)
s* __restrict__ dx_i = (dtype_
%(dx)
s*) (
PyArray_DATA(
%(dx)
s)
+ PyArray_STRIDES(
%(dx)
s)[0] * i);
npy_intp Sdx = PyArray_STRIDES(
%(dx)
s)[1]/sizeof(dtype_
%(dx)
s);
npy_intp Sdx = PyArray_STRIDES(
%(dx)
s)[1]/sizeof(dtype_
%(dx)
s);
double sum_dy_times_sm = 0.;
double sum_dy_times_sm = 0.;
...
@@ -825,9 +825,9 @@ class CrossentropySoftmaxArgmax1HotWithBias(gof.Op):
...
@@ -825,9 +825,9 @@ class CrossentropySoftmaxArgmax1HotWithBias(gof.Op):
"""
,
"""
,
begin_row_loop
,
begin_row_loop
,
"""
"""
const
%(y_idx_type)
s y_i = ((
%(y_idx_type)
s*)(
%(y_idx)
s->data
+ PyArray_STRIDES(
%(y_idx)
s)[0] * i))[0];
const
%(y_idx_type)
s y_i = ((
%(y_idx_type)
s*)(
PyArray_DATA(
%(y_idx)
s)
+ PyArray_STRIDES(
%(y_idx)
s)[0] * i))[0];
dtype_
%(nll)
s* __restrict__ nll_i = (dtype_
%(nll)
s*)(
%(nll)
s->data
+ PyArray_STRIDES(
%(nll)
s)[0] * i);
dtype_
%(nll)
s* __restrict__ nll_i = (dtype_
%(nll)
s*)(
PyArray_DATA(
%(nll)
s)
+ PyArray_STRIDES(
%(nll)
s)[0] * i);
%(am_type)
s* __restrict__ am_i = (
%(am_type)
s*) (
%(am)
s->data
+ PyArray_STRIDES(
%(am)
s)[0] * i);
%(am_type)
s* __restrict__ am_i = (
%(am_type)
s*) (
PyArray_DATA(
%(am)
s)
+ PyArray_STRIDES(
%(am)
s)[0] * i);
"""
,
"""
,
inside_row_loop
,
inside_row_loop
,
"""
"""
...
@@ -977,14 +977,14 @@ class CrossentropySoftmax1HotWithBiasDx (gof.Op):
...
@@ -977,14 +977,14 @@ class CrossentropySoftmax1HotWithBiasDx (gof.Op):
for (size_t i = 0; i < PyArray_DIMS(
%(dx)
s)[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
+ PyArray_STRIDES(
%(dnll)
s)[0] * i))[0];
const dtype_
%(dnll)
s dnll_i = ((dtype_
%(dnll)
s*)(
PyArray_DATA(
%(dnll)
s)
+ PyArray_STRIDES(
%(dnll)
s)[0] * i))[0];
const
%(y_idx_type)
s y_i = ((
%(y_idx_type)
s*)(
%(y_idx)
s->data
+ PyArray_STRIDES(
%(y_idx)
s)[0] * i))[0];
const
%(y_idx_type)
s y_i = ((
%(y_idx_type)
s*)(
PyArray_DATA(
%(y_idx)
s)
+ PyArray_STRIDES(
%(y_idx)
s)[0] * i))[0];
const dtype_
%(sm)
s* __restrict__ sm_i = (dtype_
%(sm)
s*)(
%(sm)
s->data
+ PyArray_STRIDES(
%(sm)
s)[0] * i);
const dtype_
%(sm)
s* __restrict__ sm_i = (dtype_
%(sm)
s*)(
PyArray_DATA(
%(sm)
s)
+ PyArray_STRIDES(
%(sm)
s)[0] * i);
npy_intp Ssm = PyArray_STRIDES(
%(sm)
s)[1]/sizeof(dtype_
%(sm)
s);
npy_intp Ssm = PyArray_STRIDES(
%(sm)
s)[1]/sizeof(dtype_
%(sm)
s);
dtype_
%(dx)
s* __restrict__ dx_i = (dtype_
%(dx)
s*)(
%(dx)
s->data
+ PyArray_STRIDES(
%(dx)
s)[0] * i);
dtype_
%(dx)
s* __restrict__ dx_i = (dtype_
%(dx)
s*)(
PyArray_DATA(
%(dx)
s)
+ PyArray_STRIDES(
%(dx)
s)[0] * i);
npy_intp Sdx = PyArray_STRIDES(
%(dx)
s)[1]/sizeof(dtype_
%(dx)
s);
npy_intp Sdx = PyArray_STRIDES(
%(dx)
s)[1]/sizeof(dtype_
%(dx)
s);
for (size_t j = 0; j < PyArray_DIMS(
%(dx)
s)[1]; ++j)
for (size_t j = 0; j < PyArray_DIMS(
%(dx)
s)[1]; ++j)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论