Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0151c1be
提交
0151c1be
authored
5月 16, 2017
作者:
João Victor Tozatti Risso
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change npy_float to npy_float32 in order to fix error in float size
Signed-off-by:
João Victor Tozatti Risso
<
joaovictor.risso@gmail.com
>
上级
738f7b5d
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
48 行增加
和
45 行删除
+48
-45
ctc_wrapper.c
theano/tensor/nnet/ctc_wrapper.c
+48
-45
没有找到文件。
theano/tensor/nnet/ctc_wrapper.c
浏览文件 @
0151c1be
...
...
@@ -53,11 +53,11 @@ void create_flat_labels( PyArrayObject * label_matrix, int ** flat_labels,
#section support_code_apply
int
APPLY_SPECIFIC
(
ctc_cost_cpu
)(
PyArrayObject
*
activations
,
PyArrayObject
*
labels
,
PyArrayObject
*
input_lengths
,
PyArrayObject
**
costs
,
PyArrayObject
**
gradients
)
int
APPLY_SPECIFIC
(
ctc_cost_cpu
)(
PyArrayObject
*
in_
activations
,
PyArrayObject
*
in_
labels
,
PyArrayObject
*
in
_in
put_lengths
,
PyArrayObject
**
out_
costs
,
PyArrayObject
**
out_
gradients
)
{
// setup CTC computation parameters
ctcOptions
ctc_options
;
...
...
@@ -65,19 +65,19 @@ int APPLY_SPECIFIC(ctc_cost_cpu)(PyArrayObject * activations,
ctc_options
.
loc
=
CTC_CPU
;
ctc_options
.
num_threads
=
1
;
npy_float
*
f_
activations
=
NULL
;
npy_float
32
*
activations
=
NULL
;
PyArrayObject
*
activations_copy
=
NULL
;
if
(
PyArray_IS_C_CONTIGUOUS
(
activations
)
)
if
(
PyArray_IS_C_CONTIGUOUS
(
in_
activations
)
)
{
f_activations
=
(
npy_float
*
)
PyArray_DATA
(
activations
);
activations
=
(
npy_float32
*
)
PyArray_DATA
(
in_
activations
);
}
else
{
activations_copy
=
PyArray_GETCONTIGUOUS
(
activations
);
activations_copy
=
PyArray_GETCONTIGUOUS
(
in_
activations
);
if
(
NULL
!=
activations_copy
)
{
f_activations
=
(
npy_float
*
)
PyArray_DATA
(
activations_copy
);
activations
=
(
npy_float32
*
)
PyArray_DATA
(
activations_copy
);
}
else
{
...
...
@@ -87,13 +87,13 @@ int APPLY_SPECIFIC(ctc_cost_cpu)(PyArrayObject * activations,
}
}
int
*
i
_i
nput_lengths
=
NULL
,
*
i_
flat_labels
=
NULL
,
*
i_
label_lengths
=
NULL
;
int
*
input_lengths
=
NULL
,
*
flat_labels
=
NULL
,
*
label_lengths
=
NULL
;
create_contiguous_input_lengths
(
in
put_lengths
,
&
i_
input_lengths
);
create_contiguous_input_lengths
(
in
_input_lengths
,
&
input_lengths
);
if
(
NULL
==
i
_i
nput_lengths
)
if
(
NULL
==
input_lengths
)
{
PyErr_Format
(
PyExc_ValueError
,
"Could not allocate storage for input lengths"
);
...
...
@@ -101,77 +101,77 @@ int APPLY_SPECIFIC(ctc_cost_cpu)(PyArrayObject * activations,
}
// flatten labels to conform with library memory layout
create_flat_labels
(
labels
,
&
i_flat_labels
,
&
i_
label_lengths
);
create_flat_labels
(
in_labels
,
&
flat_labels
,
&
label_lengths
);
if
(
(
NULL
==
i_label_lengths
)
||
(
NULL
==
i_
flat_labels
)
)
if
(
(
NULL
==
label_lengths
)
||
(
NULL
==
flat_labels
)
)
{
PyErr_Format
(
PyExc_ValueError
,
"Could not allocate storage for labels and their lengths"
);
return
1
;
}
npy_int
minibatch_size
=
PyArray_DIMS
(
activations
)[
1
];
npy_int
alphabet_size
=
PyArray_DIMS
(
activations
)[
2
];
npy_int
minibatch_size
=
PyArray_DIMS
(
in_
activations
)[
1
];
npy_int
alphabet_size
=
PyArray_DIMS
(
in_
activations
)[
2
];
void
*
ctc_cpu_workspace
=
NULL
;
npy_float
*
f_
costs
=
NULL
;
npy_float
32
*
costs
=
NULL
;
npy_intp
cost_size
=
minibatch_size
;
if
(
NULL
==
(
*
costs
)
)
if
(
NULL
==
(
*
out_
costs
)
)
{
// Symbolic variable has no memory backing, so we create one
*
costs
=
(
PyArrayObject
*
)
PyArray_ZEROS
(
1
,
&
cost_size
,
NPY_FLOAT32
,
0
);
*
out_
costs
=
(
PyArrayObject
*
)
PyArray_ZEROS
(
1
,
&
cost_size
,
NPY_FLOAT32
,
0
);
}
else
if
(
PyArray_NDIM
(
*
costs
)
!=
1
||
PyArray_DIMS
(
*
costs
)[
0
]
!=
cost_size
)
// matrix has the wrong size
else
if
(
PyArray_NDIM
(
*
out_costs
)
!=
1
||
PyArray_DIMS
(
*
out_costs
)[
0
]
!=
cost_size
)
// matrix has the wrong size
{
Py_XDECREF
(
*
costs
);
Py_XDECREF
(
*
out_
costs
);
// Allocate new matrix
*
costs
=
(
PyArrayObject
*
)
PyArray_ZEROS
(
1
,
&
cost_size
,
NPY_FLOAT32
,
0
);
*
out_
costs
=
(
PyArrayObject
*
)
PyArray_ZEROS
(
1
,
&
cost_size
,
NPY_FLOAT32
,
0
);
}
if
(
NULL
==
(
*
costs
)
)
if
(
NULL
==
(
*
out_
costs
)
)
{
PyErr_Format
(
PyExc_ValueError
,
"Could not allocate storage for CTC costs"
);
return
1
;
}
f_costs
=
(
npy_float
*
)
PyArray_DATA
(
*
costs
);
costs
=
(
npy_float32
*
)
PyArray_DATA
(
*
out_
costs
);
if
(
NULL
==
(
*
gradients
)
)
if
(
NULL
==
(
*
out_
gradients
)
)
{
// Symbolic variable has no real backing, so create one.
*
gradients
=
(
PyArrayObject
*
)
PyArray_ZEROS
(
3
,
PyArray_DIMS
(
activations
),
*
out_gradients
=
(
PyArrayObject
*
)
PyArray_ZEROS
(
3
,
PyArray_DIMS
(
in_
activations
),
NPY_FLOAT32
,
0
);
}
else
if
(
PyArray_NDIM
(
*
gradients
)
!=
3
||
PyArray_DIMS
(
*
gradients
)[
0
]
!=
PyArray_DIMS
(
activations
)[
0
]
||
PyArray_DIMS
(
*
gradients
)[
1
]
!=
PyArray_DIMS
(
activations
)[
1
]
||
PyArray_DIMS
(
*
gradients
)[
2
]
!=
PyArray_DIMS
(
activations
)[
2
]
)
else
if
(
PyArray_NDIM
(
*
out_
gradients
)
!=
3
||
PyArray_DIMS
(
*
out_gradients
)[
0
]
!=
PyArray_DIMS
(
in_
activations
)[
0
]
||
PyArray_DIMS
(
*
out_gradients
)[
1
]
!=
PyArray_DIMS
(
in_
activations
)[
1
]
||
PyArray_DIMS
(
*
out_gradients
)[
2
]
!=
PyArray_DIMS
(
in_
activations
)[
2
]
)
{
// Existing matrix is the wrong size. Make a new one.
// Decrement ref counter to existing array
Py_XDECREF
(
*
gradients
);
Py_XDECREF
(
*
out_
gradients
);
// Allocate new array
*
gradients
=
(
PyArrayObject
*
)
PyArray_ZEROS
(
3
,
PyArray_DIMS
(
activations
),
*
out_gradients
=
(
PyArrayObject
*
)
PyArray_ZEROS
(
3
,
PyArray_DIMS
(
in_
activations
),
NPY_FLOAT32
,
0
);
}
if
(
NULL
==
(
*
gradients
)
)
if
(
NULL
==
(
*
out_
gradients
)
)
{
PyErr_Format
(
PyExc_ValueError
,
"Could not allocate storage for CTC gradients!"
);
return
1
;
}
npy_float
*
f_gradients
=
(
npy_float
*
)
PyArray_ZEROS
(
3
,
PyArray_DIMS
(
activations
),
NPY_FLOAT32
,
0
);
npy_float32
*
gradients
=
(
npy_float32
*
)
PyArray_DATA
(
*
out_gradients
);
ctcStatus_t
status
;
size_t
cpu_workspace_size
;
status
=
get_workspace_size
(
i_label_lengths
,
i_
input_lengths
,
alphabet_size
,
status
=
get_workspace_size
(
label_lengths
,
input_lengths
,
alphabet_size
,
minibatch_size
,
ctc_options
,
&
cpu_workspace_size
);
if
(
CTC_STATUS_SUCCESS
!=
status
)
...
...
@@ -183,9 +183,10 @@ int APPLY_SPECIFIC(ctc_cost_cpu)(PyArrayObject * activations,
ctc_cpu_workspace
=
malloc
(
cpu_workspace_size
);
status
=
compute_ctc_loss
(
f_activations
,
f_gradients
,
i_flat_labels
,
i_label_lengths
,
i_input_lengths
,
alphabet_size
,
minibatch_size
,
f_costs
,
ctc_cpu_workspace
,
ctc_options
);
status
=
compute_ctc_loss
(
activations
,
gradients
,
flat_labels
,
label_lengths
,
input_lengths
,
alphabet_size
,
minibatch_size
,
costs
,
ctc_cpu_workspace
,
ctc_options
);
if
(
CTC_STATUS_SUCCESS
!=
status
)
{
...
...
@@ -194,11 +195,13 @@ int APPLY_SPECIFIC(ctc_cost_cpu)(PyArrayObject * activations,
}
if
(
NULL
!=
activations_copy
)
{
Py_XDECREF
(
activations_copy
);
}
free
(
i
_i
nput_lengths
);
free
(
i_
flat_labels
);
free
(
i_
label_lengths
);
free
(
input_lengths
);
free
(
flat_labels
);
free
(
label_lengths
);
free
(
ctc_cpu_workspace
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论