提交 5e51a8f2 authored 作者: Razvan Pascanu's avatar Razvan Pascanu

move the extract_constant outside the canonical_form function so that I can

re-use it for other optimizations.
上级 553c304b
...@@ -2607,18 +2607,7 @@ def get_idx_list(inputs, idx_list): ...@@ -2607,18 +2607,7 @@ def get_idx_list(inputs, idx_list):
return cdata return cdata
def extract_constant(x):
def get_canonical_form_slice(theslice, length):
'''
Given a slice [start:stop:step] transform it into a canonical form
that respects the conventions imposed by python and numpy.
In a canonical form a slice is represented by a canonical form slice,
in which the start <= stop and step >0 and a flag which says if the
resulting set of numbers needs to be reversed or not.
'''
def extract_constant(x):
''' '''
This function is basically a call to tensor.get_constant_value. The This function is basically a call to tensor.get_constant_value. The
main difference is the behaviour in case of failure. While main difference is the behaviour in case of failure. While
...@@ -2637,6 +2626,18 @@ def get_canonical_form_slice(theslice, length): ...@@ -2637,6 +2626,18 @@ def get_canonical_form_slice(theslice, length):
x = tensor.tensor_from_scalar(x) x = tensor.tensor_from_scalar(x)
return x return x
def get_canonical_form_slice(theslice, length):
'''
Given a slice [start:stop:step] transform it into a canonical form
that respects the conventions imposed by python and numpy.
In a canonical form a slice is represented by a canonical form slice,
in which the start <= stop and step >0 and a flag which says if the
resulting set of numbers needs to be reversed or not.
'''
if isinstance(theslice,slice): if isinstance(theslice,slice):
start = extract_constant(theslice.start) start = extract_constant(theslice.start)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论