Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 471

xiongying/Paddle

forked from PaddlePaddle/Paddle
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
develop
Branches (296)
Tags (62)
develop
fix_tensor_type
release/2.3
dingjiaweiww-patch-1
revert-41065-revert-40993-mv_ele_floordiv_pow
revert-41068-revert-40790-phi_new
prv-onednn-2.5
fix_rnn_docs
add_some_yaml_config
move_slice_to_pten
enable_eager_model_test
move_yolo_box_to_phi
move_sgd_to_phi
move_embedding_to_phi
release/2.2
incubate/infrt
release/1.8
ascendrelease
release/2.1
release/2.0
v2.2.2
v2.2.1
v2.2.0
v2.2.0-bak0
v2.2.0-rc0
v2.1.3
v2.1.2
v2.1.1
v2.1.0
v2.1.0-rc0
v2.0.2
v2.0.1
v2.0.0
v2.0.0-rc1
v2.0.0-rc0
v1.8.5
v2.0.0-beta0
v1.8.4
v1.8.3
v1.8.2
develop
Branches (296)
Tags (62)
develop
fix_tensor_type
release/2.3
dingjiaweiww-patch-1
revert-41065-revert-40993-mv_ele_floordiv_pow
revert-41068-revert-40790-phi_new
prv-onednn-2.5
fix_rnn_docs
add_some_yaml_config
move_slice_to_pten
enable_eager_model_test
move_yolo_box_to_phi
move_sgd_to_phi
move_embedding_to_phi
release/2.2
incubate/infrt
release/1.8
ascendrelease
release/2.1
release/2.0
v2.2.2
v2.2.1
v2.2.0
v2.2.0-bak0
v2.2.0-rc0
v2.1.3
v2.1.2
v2.1.1
v2.1.0
v2.1.0-rc0
v2.0.2
v2.0.1
v2.0.0
v2.0.0-rc1
v2.0.0-rc0
v1.8.5
v2.0.0-beta0
v1.8.4
v1.8.3
v1.8.2
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
develop
Branches (296)
Tags (62)
develop
fix_tensor_type
release/2.3
dingjiaweiww-patch-1
revert-41065-revert-40993-mv_ele_floordiv_pow
revert-41068-revert-40790-phi_new
prv-onednn-2.5
fix_rnn_docs
add_some_yaml_config
move_slice_to_pten
enable_eager_model_test
move_yolo_box_to_phi
move_sgd_to_phi
move_embedding_to_phi
release/2.2
incubate/infrt
release/1.8
ascendrelease
release/2.1
release/2.0
v2.2.2
v2.2.1
v2.2.0
v2.2.0-bak0
v2.2.0-rc0
v2.1.3
v2.1.2
v2.1.1
v2.1.0
v2.1.0-rc0
v2.0.2
v2.0.1
v2.0.0
v2.0.0-rc1
v2.0.0-rc0
v1.8.5
v2.0.0-beta0
v1.8.4
v1.8.3
v1.8.2
array.py 5.27 KB
Copy Edit Raw Blame History
# Copyright (c) 2020 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.
# Define functions about array.
from ..fluid import layers
__all__ = []
def array_length(array):
"""
This OP is used to get the length of the input array.
Args:
array (list|Tensor): The input array that will be used to compute the length. In dynamic mode, ``array`` is a Python list. But in static mode, array is a Tensor whose VarType is LOD_TENSOR_ARRAY.
Returns:
Tensor: 1-D Tensor with shape [1], which is the length of array.
Examples:
.. code-block:: python
import paddle
arr = paddle.tensor.create_array(dtype='float32')
x = paddle.full(shape=[3, 3], fill_value=5, dtype="float32")
i = paddle.zeros(shape=[1], dtype="int32")
arr = paddle.tensor.array_write(x, i, array=arr)
arr_len = paddle.tensor.array_length(arr)
print(arr_len) # 1
"""
return layers.array_length(array)
def array_read(array, i):
"""
This OP is used to read data at the specified position from the input array.
Case:
.. code-block:: text
Input:
The shape of first three tensors are [1], and that of the last one is [1,2]:
array = ([0.6], [0.1], [0.3], [0.4, 0.2])
And:
i = [3]
Output:
output = [0.4, 0.2]
Args:
array (list|Tensor): The input array. In dynamic mode, ``array`` is a Python list. But in static mode, array is a Tensor whose ``VarType`` is ``LOD_TENSOR_ARRAY``.
i (Tensor): 1-D Tensor, whose shape is [1] and dtype is int64. It represents the
specified read position of ``array``.
Returns:
Tensor: A Tensor that is read at the specified position of ``array``.
Examples:
.. code-block:: python
import paddle
arr = paddle.tensor.create_array(dtype="float32")
x = paddle.full(shape=[1, 3], fill_value=5, dtype="float32")
i = paddle.zeros(shape=[1], dtype="int32")
arr = paddle.tensor.array_write(x, i, array=arr)
item = paddle.tensor.array_read(arr, i)
print(item) # [[5., 5., 5.]]
"""
return layers.array_read(array, i)
def array_write(x, i, array=None):
"""
This OP writes the input ``x`` into the i-th position of the ``array`` returns the modified array.
If ``array`` is none, a new array will be created and returned.
Args:
x (Tensor): The input data to be written into array. It's multi-dimensional
Tensor or LoDTensor. Data type: float32, float64, int32, int64 and bool.
i (Tensor): 1-D Tensor with shape [1], which represents the position into which
``x`` is written.
array (list|Tensor, optional): The array into which ``x`` is written. The default value is None,
when a new array will be created and returned as a result. In dynamic mode, ``array`` is a Python list.
But in static mode, array is a Tensor whose ``VarType`` is ``LOD_TENSOR_ARRAY``.
Returns:
list|Tensor: The input ``array`` after ``x`` is written into.
Examples:
.. code-block:: python
import paddle
arr = paddle.tensor.create_array(dtype="float32")
x = paddle.full(shape=[1, 3], fill_value=5, dtype="float32")
i = paddle.zeros(shape=[1], dtype="int32")
arr = paddle.tensor.array_write(x, i, array=arr)
item = paddle.tensor.array_read(arr, i)
print(item) # [[5., 5., 5.]]
"""
return layers.array_write(x, i, array)
def create_array(dtype, initialized_list=None):
"""
This OP creates an array. It is used as the input of :ref:`api_paddle_tensor_array_array_read` and
:ref:`api_paddle_tensor_array_array_write`.
Args:
dtype (str): The data type of the elements in the array. Support data type: float32, float64, int32, int64 and bool.
initialized_list(list): Used to initialize as default value for created array.
All values in initialized list should be a Tensor.
Returns:
list|Tensor: An empty array. In dynamic mode, ``array`` is a Python list. But in static mode, array is a Tensor
whose ``VarType`` is ``LOD_TENSOR_ARRAY``.
Examples:
.. code-block:: python
import paddle
arr = paddle.tensor.create_array(dtype="float32")
x = paddle.full(shape=[1, 3], fill_value=5, dtype="float32")
i = paddle.zeros(shape=[1], dtype="int32")
arr = paddle.tensor.array_write(x, i, array=arr)
item = paddle.tensor.array_read(arr, i)
print(item) # [[5., 5., 5.]]
"""
return layers.create_array(dtype, initialized_list)
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

PaddlePaddle (PArallel Distributed Deep LEarning 并行分布式深度学习)是百度研发的深度学习平台,具有易用,高效,灵活和可伸缩等特点,为百度内部多项产品提供深度学习算法支持
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/VisionDeveloper/Paddle.git
git@gitee.com:VisionDeveloper/Paddle.git
VisionDeveloper
Paddle
Paddle
develop
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /