未验证 提交 4621f82f 编写于 作者: F feifei-111 提交者: GitHub

[API] added 'place' dummy interface for variable (#45877)

* place

* add test

* fix spell and test

* fix anno

* code style
上级 2c687df0
......@@ -132,21 +132,33 @@ def monkey_patch_variable():
@static_only
def cpu(self):
"""
Variable should not have cpu() and cuda() interface.
But this interface can greatly facilitate dy2static.
We do nothing here.
Variable should not have cpu() and cuda() interface.
But this interface can greatly facilitate dy2static.
We do nothing here.
"""
return self
@static_only
def cuda(self):
"""
Variable should not have cpu() and cuda() interface.
But this interface can greatly facilitate dy2static.
We do nothing here.
Variable should not have cpu() and cuda() interface.
But this interface can greatly facilitate dy2static.
We do nothing here.
"""
return self
@static_only
def place(self):
"""
Variable don't have 'place' interface in static mode
But this interface can greatly facilitate dy2static.
So we give a warnning here and return None.
"""
warnings.warn(
"Variable do not have 'place' interface for static mode, try not to use it. None will be returned."
)
return None
def astype(self, dtype):
"""
**Notes**:
......@@ -427,6 +439,7 @@ def monkey_patch_variable():
('astype', astype),
('cpu', cpu),
('cuda', cuda),
('place', place),
('append', append),
('item', _item),
('pop', pop),
......
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import numpy as np
import paddle
import unittest
class TestPlace(unittest.TestCase):
def test_place(self):
paddle.enable_static()
x = paddle.to_tensor([1, 2, 3, 4])
self.assertTrue(x.place() == None)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册