未验证 提交 f0a40630 编写于 作者: J Jiaqi Liu 提交者: GitHub

supports string var lod_level property (#39077)

上级 3bf3a6ee
...@@ -1763,7 +1763,10 @@ class Variable(object): ...@@ -1763,7 +1763,10 @@ class Variable(object):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
paddle.enable_static()
cur_program = fluid.Program() cur_program = fluid.Program()
cur_block = cur_program.current_block() cur_block = cur_program.current_block()
new_variable = cur_block.create_var(name="X", new_variable = cur_block.create_var(name="X",
...@@ -1773,7 +1776,8 @@ class Variable(object): ...@@ -1773,7 +1776,8 @@ class Variable(object):
""" """
if self.type == core.VarDesc.VarType.SELECTED_ROWS: if self.type == core.VarDesc.VarType.SELECTED_ROWS:
raise Exception("SelectedRows DO NOT supprt lod") raise Exception("SelectedRows DO NOT supprt lod")
if self.type == core.VarDesc.VarType.STRINGS:
return None
return self.desc.lod_level() return self.desc.lod_level()
@property @property
......
...@@ -63,6 +63,12 @@ class TestVariable(unittest.TestCase): ...@@ -63,6 +63,12 @@ class TestVariable(unittest.TestCase):
self.assertRaises(ValueError, self.assertRaises(ValueError,
lambda: b.create_var(name="fc.w", shape=(24, 100))) lambda: b.create_var(name="fc.w", shape=(24, 100)))
w = b.create_var(
dtype=paddle.fluid.core.VarDesc.VarType.STRINGS,
shape=[1],
name="str_var")
self.assertEqual(None, w.lod_level)
def test_element_size(self): def test_element_size(self):
with fluid.program_guard(Program(), Program()): with fluid.program_guard(Program(), Program()):
x = paddle.static.data(name='x1', shape=[2], dtype='bool') x = paddle.static.data(name='x1', shape=[2], dtype='bool')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册