Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Change] 不再兼容旧格式示例代码 #56573

Merged
merged 10 commits into from
Aug 25, 2023
24 changes: 22 additions & 2 deletions python/paddle/tensor/creation.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看起来已经没什么问题了,相关测试修改要恢复么

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

# TODO: define functions to get create a tensor

# TODO: just for test

import math
import re
import warnings
Expand Down Expand Up @@ -67,6 +69,8 @@ def create_global_var(
shape, value, dtype, persistable=False, force_cpu=False, name=None
):
"""
# TODO: just for test

This function creates a new tensor variable with value in the global block(block 0).

Args:
Expand All @@ -92,6 +96,8 @@ def create_global_var(
var = paddle.static.create_global_var(shape=[2,3], value=1.0, dtype='float32',
persistable=True, force_cpu=True, name='new_var')
"""
# TODO: just for test

check_type(shape, 'shape', (list, tuple, np.ndarray), 'create_global_var')
for item in shape:
check_type(
Expand Down Expand Up @@ -148,6 +154,8 @@ def create_parameter(
shape, dtype, name=None, attr=None, is_bias=False, default_initializer=None
):
"""
# TODO: just for test

This function creates a parameter. The parameter is a learnable variable, which can have
gradient, and can be optimized.

Expand Down Expand Up @@ -176,6 +184,8 @@ def create_parameter(
paddle.enable_static()
W = paddle.create_parameter(shape=[784, 200], dtype='float32')
"""
# TODO: just for test

check_type(shape, 'shape', (list, tuple, np.ndarray), 'create_parameter')
for item in shape:
check_type(
Expand Down Expand Up @@ -227,6 +237,8 @@ def create_parameter(

def create_tensor(dtype, name=None, persistable=False):
"""
# TODO: just for test

Create a variable, which will hold a Tensor with data type dtype.

Args:
Expand All @@ -243,9 +255,11 @@ def create_tensor(dtype, name=None, persistable=False):
Examples:
.. code-block:: python

import paddle
tensor = paddle.tensor.create_tensor(dtype='float32')
>>> import paddle
>>> tensor = paddle.tensor.create_tensor(dtype='float32')
"""
# TODO: just for test

check_dtype(
dtype,
'dtype',
Expand Down Expand Up @@ -1199,6 +1213,7 @@ def _check_attr(attr, message):

def full(shape, fill_value, dtype=None, name=None):
"""
TODO(megemini): just for test

Return a Tensor with the ``fill_value`` which size is same as ``shape``.

Expand Down Expand Up @@ -1248,6 +1263,7 @@ def full(shape, fill_value, dtype=None, name=None):
# [2. 2.]
# [2. 2.]]
"""
# TODO: just for test

if dtype is None:
dtype = 'float32'
Expand All @@ -1257,6 +1273,8 @@ def full(shape, fill_value, dtype=None, name=None):

def arange(start=0, end=None, step=1, dtype=None, name=None):
"""
# TODO: just for test

Returns a 1-D Tensor with spaced values within a given interval.

Values are generated into the half-open interval [``start``, ``end``) with
Expand Down Expand Up @@ -1309,6 +1327,8 @@ def arange(start=0, end=None, step=1, dtype=None, name=None):
# [3, 4, 5, 6]

"""
# TODO: just for test

if end is None:
end = start
start = 0
Expand Down
Loading