Skip to content

Commit 2b9a482

Browse files
add Tensor.dtype docs (PaddlePaddle#7376)
1 parent d7c6433 commit 2b9a482

File tree

1 file changed

+204
-0
lines changed

1 file changed

+204
-0
lines changed

docs/api/paddle/Tensor_cn.rst

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,210 @@ astype(dtype)
685685
print("original tensor's dtype is: {}".format(x.dtype))
686686
print("new tensor's dtype is: {}".format(x.astype('float64').dtype))
687687
688+
bfloat16()
689+
:::::::::
690+
691+
如果当前 Tensor 已经是 ``bfloat16`` 类型,则返回该 Tensor。否则,返回一个新的 ``bfloat16`` 类型的 Tensor 副本。
692+
693+
返回: 转换后的 Tensor
694+
695+
返回类型:Tensor
696+
697+
**代码示例**
698+
.. code-block:: python
699+
700+
import paddle
701+
x = paddle.to_tensor(1.0)
702+
print("original tensor's dtype is: {}".format(x.dtype))
703+
print("new tensor's dtype is: {}".format(x.bfloat16().dtype))
704+
705+
bool()
706+
:::::::::
707+
708+
如果当前 Tensor 已经是 ``bool`` 类型,则返回该 Tensor。否则,返回一个新的 ``bool`` 类型的 Tensor 副本。
709+
710+
返回: 转换后的 Tensor
711+
712+
返回类型:Tensor
713+
714+
**代码示例**
715+
.. code-block:: python
716+
717+
import paddle
718+
x = paddle.to_tensor(1.0)
719+
print("original tensor's dtype is: {}".format(x.dtype))
720+
print("new tensor's dtype is: {}".format(x.bool().dtype))
721+
722+
byte()
723+
:::::::::
724+
725+
如果当前 Tensor 已经是 ``byte`` 类型,则返回该 Tensor。否则,返回一个新的 ``byte`` 类型的 Tensor 副本。
726+
727+
返回: 转换后的 Tensor
728+
729+
返回类型:Tensor
730+
731+
**代码示例**
732+
.. code-block:: python
733+
734+
import paddle
735+
x = paddle.to_tensor(1.0)
736+
print("original tensor's dtype is: {}".format(x.dtype))
737+
print("new tensor's dtype is: {}".format(x.byte().dtype))
738+
739+
char()
740+
:::::::::
741+
742+
如果当前 Tensor 已经是 ``char`` 类型,则返回该 Tensor。否则,返回一个新的 ``char`` 类型的 Tensor 副本。
743+
744+
返回: 转换后的 Tensor
745+
746+
返回类型:Tensor
747+
748+
**代码示例**
749+
.. code-block:: python
750+
751+
import paddle
752+
x = paddle.to_tensor(1.0)
753+
print("original tensor's dtype is: {}".format(x.dtype))
754+
print("new tensor's dtype is: {}".format(x.char().dtype))
755+
756+
double()
757+
:::::::::
758+
759+
如果当前 Tensor 已经是 ``double`` 类型,则返回该 Tensor。否则,返回一个新的 ``double`` 类型的 Tensor 副本。
760+
761+
返回: 转换后的 Tensor
762+
763+
返回类型:Tensor
764+
765+
**代码示例**
766+
.. code-block:: python
767+
768+
import paddle
769+
x = paddle.to_tensor(1.0)
770+
print("original tensor's dtype is: {}".format(x.dtype))
771+
print("new tensor's dtype is: {}".format(x.double().dtype))
772+
773+
float()
774+
:::::::::
775+
776+
如果当前 Tensor 已经是 ``float`` 类型,则返回该 Tensor。否则,返回一个新的 ``float`` 类型的 Tensor 副本。
777+
778+
返回: 转换后的 Tensor
779+
780+
返回类型:Tensor
781+
782+
**代码示例**
783+
.. code-block:: python
784+
785+
import paddle
786+
x = paddle.to_tensor(1.0)
787+
print("original tensor's dtype is: {}".format(x.dtype))
788+
print("new tensor's dtype is: {}".format(x.float().dtype))
789+
790+
half()
791+
:::::::::
792+
793+
如果当前 Tensor 已经是 ``half`` 类型,则返回该 Tensor。否则,返回一个新的 ``half`` 类型的 Tensor 副本。
794+
795+
返回: 转换后的 Tensor
796+
797+
返回类型:Tensor
798+
799+
**代码示例**
800+
.. code-block:: python
801+
802+
import paddle
803+
x = paddle.to_tensor(1.0)
804+
print("original tensor's dtype is: {}".format(x.dtype))
805+
print("new tensor's dtype is: {}".format(x.half().dtype))
806+
807+
int()
808+
:::::::::
809+
810+
如果当前 Tensor 已经是 ``int`` 类型,则返回该 Tensor。否则,返回一个新的 ``int`` 类型的 Tensor 副本。
811+
812+
返回: 转换后的 Tensor
813+
814+
返回类型:Tensor
815+
816+
**代码示例**
817+
.. code-block:: python
818+
819+
import paddle
820+
x = paddle.to_tensor(1.0)
821+
print("original tensor's dtype is: {}".format(x.dtype))
822+
print("new tensor's dtype is: {}".format(x.int().dtype))
823+
824+
long()
825+
:::::::::
826+
827+
如果当前 Tensor 已经是 ``long`` 类型,则返回该 Tensor。否则,返回一个新的 ``long`` 类型的 Tensor 副本。
828+
829+
返回: 转换后的 Tensor
830+
831+
返回类型:Tensor
832+
833+
**代码示例**
834+
.. code-block:: python
835+
836+
import paddle
837+
x = paddle.to_tensor(1.0)
838+
print("original tensor's dtype is: {}".format(x.dtype))
839+
print("new tensor's dtype is: {}".format(x.long().dtype))
840+
841+
short()
842+
:::::::::
843+
844+
如果当前 Tensor 已经是 ``short`` 类型,则返回该 Tensor。否则,返回一个新的 ``short`` 类型的 Tensor 副本。
845+
846+
返回: 转换后的 Tensor
847+
848+
返回类型:Tensor
849+
850+
**代码示例**
851+
.. code-block:: python
852+
853+
import paddle
854+
x = paddle.to_tensor(1.0)
855+
print("original tensor's dtype is: {}".format(x.dtype))
856+
print("new tensor's dtype is: {}".format(x.short().dtype))
857+
858+
cfloat()
859+
:::::::::
860+
861+
如果当前 Tensor 已经是 ``cfloat`` 类型,则返回该 Tensor。否则,返回一个新的 ``cfloat`` 类型的 Tensor 副本。
862+
863+
返回: 转换后的 Tensor
864+
865+
返回类型:Tensor
866+
867+
**代码示例**
868+
.. code-block:: python
869+
870+
import paddle
871+
x = paddle.to_tensor(1.0)
872+
print("original tensor's dtype is: {}".format(x.dtype))
873+
print("new tensor's dtype is: {}".format(x.cfloat().dtype))
874+
875+
cdouble()
876+
:::::::::
877+
878+
如果当前 Tensor 已经是 ``cdouble`` 类型,则返回该 Tensor。否则,返回一个新的 ``cdouble`` 类型的 Tensor 副本。
879+
880+
返回: 转换后的 Tensor
881+
882+
返回类型:Tensor
883+
884+
**代码示例**
885+
.. code-block:: python
886+
887+
import paddle
888+
x = paddle.to_tensor(1.0)
889+
print("original tensor's dtype is: {}".format(x.dtype))
890+
print("new tensor's dtype is: {}".format(x.cdouble().dtype))
891+
688892
atan(name=None)
689893
:::::::::
690894

0 commit comments

Comments
 (0)