diff --git a/doc/fluid/api/dygraph.rst b/doc/fluid/api/dygraph.rst index 0559cd477cfc169506a382ac7e50fe0f1cc621ca..ac8ca052197935c9d23f2bab10ed5ceb26fa7f4b 100644 --- a/doc/fluid/api/dygraph.rst +++ b/doc/fluid/api/dygraph.rst @@ -7,7 +7,6 @@ fluid.dygraph dygraph/BackwardStrategy.rst dygraph/BatchNorm.rst - dygraph/BCELoss.rst dygraph/BilinearTensorProduct.rst dygraph/Conv2D.rst dygraph/Conv2DTranspose.rst @@ -28,22 +27,17 @@ fluid.dygraph dygraph/ExponentialDecay.rst dygraph/grad.rst dygraph/GroupNorm.rst - dygraph/GRUCell.rst dygraph/GRUUnit.rst dygraph/guard.rst dygraph/InstanceNorm.rst dygraph/InverseTimeDecay.rst - dygraph/L1Loss.rst dygraph/Layer.rst dygraph/LayerList.rst dygraph/LayerNorm.rst dygraph/Linear.rst dygraph/load_dygraph.rst - dygraph/LSTMCell.rst - dygraph/MSELoss.rst dygraph/NaturalExpDecay.rst dygraph/NCE.rst - dygraph/NLLLoss.rst dygraph/no_grad.rst dygraph/NoamDecay.rst dygraph/ParallelEnv.rst diff --git a/doc/fluid/api/dygraph/BCELoss.rst b/doc/fluid/api/dygraph/BCELoss.rst deleted file mode 100644 index 9e4e9a78f4a9ebd75f1ff01ca1d007f2d7378910..0000000000000000000000000000000000000000 --- a/doc/fluid/api/dygraph/BCELoss.rst +++ /dev/null @@ -1,12 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_dygraph_BCELoss: - -BCELoss -------- - -.. autoclass:: paddle.fluid.dygraph.BCELoss - :members: - :noindex: - diff --git a/doc/fluid/api/dygraph/InstanceNorm.rst b/doc/fluid/api/dygraph/InstanceNorm.rst deleted file mode 100644 index 548185e89faae02aa8fb5e96a391e569b5480d9b..0000000000000000000000000000000000000000 --- a/doc/fluid/api/dygraph/InstanceNorm.rst +++ /dev/null @@ -1,12 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_dygraph_InstanceNorm: - -InstanceNorm ------------- - -.. autoclass:: paddle.fluid.dygraph.InstanceNorm - :members: - :noindex: - diff --git a/doc/fluid/api/dygraph/MSELoss.rst b/doc/fluid/api/dygraph/MSELoss.rst deleted file mode 100644 index 054080b7ad50f6dd6ec37918b18337c55838bf53..0000000000000000000000000000000000000000 --- a/doc/fluid/api/dygraph/MSELoss.rst +++ /dev/null @@ -1,12 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_dygraph_MSELoss: - -MSELoss -------- - -.. autoclass:: paddle.fluid.dygraph.MSELoss - :members: - :noindex: - diff --git a/doc/fluid/api/dygraph/NLLLoss.rst b/doc/fluid/api/dygraph/NLLLoss.rst deleted file mode 100644 index f40437cd0e9e0d336fcd512e15162149ae78f118..0000000000000000000000000000000000000000 --- a/doc/fluid/api/dygraph/NLLLoss.rst +++ /dev/null @@ -1,12 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_dygraph_NLLLoss: - -NLLLoss -------- - -.. autoclass:: paddle.fluid.dygraph.NLLLoss - :members: - :noindex: - diff --git a/doc/fluid/api/dygraph/ProgramTranslator.rst b/doc/fluid/api/dygraph/ProgramTranslator.rst deleted file mode 100644 index ac995abd210c9c74545ca7ac47c3d7d0460e17b2..0000000000000000000000000000000000000000 --- a/doc/fluid/api/dygraph/ProgramTranslator.rst +++ /dev/null @@ -1,12 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_dygraph_ProgramTranslator: - -ProgramTranslator ------------------ - -.. autoclass:: paddle.fluid.dygraph.ProgramTranslator - :members: - :noindex: - diff --git a/doc/fluid/api/dygraph/declarative.rst b/doc/fluid/api/dygraph/declarative.rst deleted file mode 100644 index 4d603e862973002734b740b036496d0c5eb94958..0000000000000000000000000000000000000000 --- a/doc/fluid/api/dygraph/declarative.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_dygraph_declarative: - -declarative ------------ - -.. autofunction:: paddle.fluid.dygraph.declarative - :noindex: - diff --git a/doc/fluid/api/fluid/ComplexVariable.rst b/doc/fluid/api/fluid/ComplexVariable.rst deleted file mode 100644 index 071457e8ce7fd30541027cb556f780b82aa01393..0000000000000000000000000000000000000000 --- a/doc/fluid/api/fluid/ComplexVariable.rst +++ /dev/null @@ -1,13 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_ComplexVariable: - -ComplexVariable ---------------- - -.. autoclass:: paddle.fluid.ComplexVariable - :members: - :inherited-members: - :noindex: - diff --git a/doc/fluid/api/gen_doc.sh b/doc/fluid/api/gen_doc.sh index 19c07cc216301c03f19ffb9c34159f923a09faa1..4f549e17ca72c74edf0c8dc70692651c2a414165 100644 --- a/doc/fluid/api/gen_doc.sh +++ b/doc/fluid/api/gen_doc.sh @@ -10,6 +10,33 @@ done python gen_doc.py --module_name "" --module_prefix "" --output fluid --output_name fluid --to_multiple_files True python gen_module_index.py fluid fluid +# tensor +for module in math random stat +do + python gen_doc.py --module_name ${module} --module_prefix ${module} --output ${module} --output_name tensor --to_multiple_files True --output_dir tensor + python gen_module_index.py tensor.${module} ${module} +done + +python gen_module_index.py tensor paddle.tensor + +for module in math manipulation +do + python gen_doc.py --module_name tensor.${module} --module_prefix tensor.${module} --output tensor/${module} --output_name complex --to_multiple_files True --output_dir complex + python gen_module_index.py complex.tensor.${module} ${module} +done + +python gen_module_index.py complex.tensor tensor +python gen_module_index.py complex paddle.complex + +# nn +for module in loss +do + python gen_doc.py --module_name ${module} --module_prefix ${module} --output ${module} --output_name nn --to_multiple_files True --output_dir nn + python gen_module_index.py nn.${module} ${module} +done + +python gen_doc.py --module_name "" --module_prefix "" --output nn --output_name nn --to_multiple_files True +python gen_module_index.py nn paddle.nn # index.rst python gen_index.py diff --git a/doc/fluid/api/index_en.rst b/doc/fluid/api/index_en.rst index dce0d7cf9679ca2b47fd2a2713c31d5538b6a61c..fee4b69e3e8430f1f1d9953d57c1c96f92a91e0c 100644 --- a/doc/fluid/api/index_en.rst +++ b/doc/fluid/api/index_en.rst @@ -6,6 +6,9 @@ API Reference :maxdepth: 1 ../api_guides/index_en.rst + complex.rst + nn.rst + tensor.rst fluid.rst backward.rst clip.rst @@ -14,6 +17,7 @@ API Reference dataset.rst dygraph.rst executor.rst + index.rst initializer.rst io.rst layers.rst diff --git a/doc/fluid/api/layers.rst b/doc/fluid/api/layers.rst index 9244c5c116ff4fc8a335af42690292b01e24142a..3ad2eeaa2941b7a0b6df18eb51aaf7b3691504b5 100644 --- a/doc/fluid/api/layers.rst +++ b/doc/fluid/api/layers.rst @@ -11,13 +11,9 @@ fluid.layers layers/adaptive_pool2d.rst layers/adaptive_pool3d.rst layers/add_position_encoding.rst - layers/addcmul.rst - layers/addmm.rst layers/affine_channel.rst layers/affine_grid.rst - layers/allclose.rst layers/anchor_generator.rst - layers/arange.rst layers/argmax.rst layers/argmin.rst layers/argsort.rst @@ -36,7 +32,6 @@ fluid.layers layers/BeamSearchDecoder.rst layers/bilinear_tensor_product.rst layers/bipartite_match.rst - layers/bmm.rst layers/box_clip.rst layers/box_coder.rst layers/box_decoder_and_assign.rst @@ -48,7 +43,6 @@ fluid.layers layers/ceil.rst layers/center_loss.rst layers/chunk_eval.rst - layers/clamp.rst layers/clip.rst layers/clip_by_norm.rst layers/collect_fpn_proposals.rst @@ -70,7 +64,6 @@ fluid.layers layers/crf_decoding.rst layers/crop.rst layers/crop_tensor.rst - layers/cross.rst layers/cross_entropy.rst layers/ctc_greedy_decoder.rst layers/cumsum.rst @@ -83,11 +76,8 @@ fluid.layers layers/density_prior_box.rst layers/detection_output.rst layers/diag.rst - layers/diag_embed.rst layers/dice_loss.rst - layers/dist.rst layers/distribute_fpn_proposals.rst - layers/dot.rst layers/double_buffer.rst layers/dropout.rst layers/dynamic_decode.rst @@ -98,7 +88,6 @@ fluid.layers layers/edit_distance.rst layers/elementwise_add.rst layers/elementwise_div.rst - layers/elementwise_equal.rst layers/elementwise_floordiv.rst layers/elementwise_max.rst layers/elementwise_min.rst @@ -120,11 +109,8 @@ fluid.layers layers/fill_constant_batch_size_like.rst layers/filter_by_instag.rst layers/flatten.rst - layers/flip.rst layers/floor.rst layers/fsp_matrix.rst - layers/full.rst - layers/full_like.rst layers/gather.rst layers/gather_nd.rst layers/gather_tree.rst @@ -155,16 +141,13 @@ fluid.layers layers/image_resize.rst layers/image_resize_short.rst layers/increment.rst - layers/index_select.rst layers/inplace_abn.rst layers/instance_norm.rst - layers/interpolate.rst layers/inverse_time_decay.rst layers/iou_similarity.rst layers/is_empty.rst layers/isfinite.rst layers/kldiv_loss.rst - layers/kron.rst layers/l2_normalize.rst layers/label_smooth.rst layers/layer_norm.rst @@ -179,15 +162,12 @@ fluid.layers layers/lod_append.rst layers/lod_reset.rst layers/log.rst - layers/log1p.rst layers/log_loss.rst - layers/log_softmax.rst layers/logical_and.rst layers/logical_not.rst layers/logical_or.rst layers/logical_xor.rst layers/logsigmoid.rst - layers/logsumexp.rst layers/lrn.rst layers/lstm.rst layers/lstm_unit.rst @@ -198,7 +178,6 @@ fluid.layers layers/mean.rst layers/mean_iou.rst layers/merge_selected_rows.rst - layers/meshgrid.rst layers/mse_loss.rst layers/mul.rst layers/multi_box_head.rst @@ -208,7 +187,6 @@ fluid.layers layers/natural_exp_decay.rst layers/nce.rst layers/noam_decay.rst - layers/nonzero.rst layers/Normal.rst layers/not_equal.rst layers/npair_loss.rst @@ -232,10 +210,7 @@ fluid.layers layers/psroi_pool.rst layers/py_func.rst layers/py_reader.rst - layers/randint.rst - layers/randn.rst layers/random_crop.rst - layers/randperm.rst layers/range.rst layers/rank.rst layers/rank_loss.rst @@ -263,7 +238,6 @@ fluid.layers layers/roi_align.rst layers/roi_perspective_transform.rst layers/roi_pool.rst - layers/roll.rst layers/round.rst layers/row_conv.rst layers/rpn_target_assign.rst @@ -327,7 +301,6 @@ fluid.layers layers/swish.rst layers/Switch.rst layers/switch_case.rst - layers/t.rst layers/tanh.rst layers/tanh_shrink.rst layers/target_assign.rst @@ -336,11 +309,8 @@ fluid.layers layers/tensor_array_to_tensor.rst layers/thresholded_relu.rst layers/topk.rst - layers/trace.rst layers/TrainingHelper.rst layers/transpose.rst - layers/tril.rst - layers/triu.rst layers/unfold.rst layers/Uniform.rst layers/uniform_random.rst diff --git a/doc/fluid/api/layers/addcmul.rst b/doc/fluid/api/layers/addcmul.rst deleted file mode 100644 index 834cb76eafc19da96ae753cc26d033c6641f5253..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/addcmul.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_addcmul: - -addcmul -------- - -.. autofunction:: paddle.fluid.layers.addcmul - :noindex: - diff --git a/doc/fluid/api/layers/addmm.rst b/doc/fluid/api/layers/addmm.rst deleted file mode 100644 index 509c5fb3735961065acf1f857d57bd9112b79d6a..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/addmm.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_addmm: - -addmm ------ - -.. autofunction:: paddle.fluid.layers.addmm - :noindex: - diff --git a/doc/fluid/api/layers/allclose.rst b/doc/fluid/api/layers/allclose.rst deleted file mode 100644 index 8f8758be629d9f6b315e4915c222dd9d72b76f1a..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/allclose.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_allclose: - -allclose --------- - -.. autofunction:: paddle.fluid.layers.allclose - :noindex: - diff --git a/doc/fluid/api/layers/arange.rst b/doc/fluid/api/layers/arange.rst deleted file mode 100644 index 8a0e51627ba3dd5555ba754e27034db8d990b63c..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/arange.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_arange: - -arange ------- - -.. autofunction:: paddle.fluid.layers.arange - :noindex: - diff --git a/doc/fluid/api/layers/clamp.rst b/doc/fluid/api/layers/clamp.rst deleted file mode 100644 index e5cdcc61198ee1afdb205015f64b7acdea1c9b04..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/clamp.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_clamp: - -clamp ------ - -.. autofunction:: paddle.fluid.layers.clamp - :noindex: - diff --git a/doc/fluid/api/layers/cross.rst b/doc/fluid/api/layers/cross.rst deleted file mode 100644 index 1d147d8e829f383a1ea9b8c7fecee608a7049925..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/cross.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_cross: - -cross ------ - -.. autofunction:: paddle.fluid.layers.cross - :noindex: - diff --git a/doc/fluid/api/layers/diag_embed.rst b/doc/fluid/api/layers/diag_embed.rst deleted file mode 100644 index 1fbbb99adf48c82b0b9f83f63f903ae776cb4671..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/diag_embed.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_diag_embed: - -diag_embed ----------- - -.. autofunction:: paddle.fluid.layers.diag_embed - :noindex: - diff --git a/doc/fluid/api/layers/elementwise_equal.rst b/doc/fluid/api/layers/elementwise_equal.rst deleted file mode 100644 index 25671bec7b84b5fe6db1d27cbd1d8d82c997c5ac..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/elementwise_equal.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_elementwise_equal: - -elementwise_equal ------------------ - -.. autofunction:: paddle.fluid.layers.elementwise_equal - :noindex: - diff --git a/doc/fluid/api/layers/full_like.rst b/doc/fluid/api/layers/full_like.rst deleted file mode 100644 index 9d27a022850c1935679e19e803ea2f10c3862b5c..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/full_like.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_full_like: - -full_like ---------- - -.. autofunction:: paddle.fluid.layers.full_like - :noindex: - diff --git a/doc/fluid/api/layers/index_select.rst b/doc/fluid/api/layers/index_select.rst deleted file mode 100644 index b91f1d60531662ab040d61a8b84fdd7247eb43c8..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/index_select.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_index_select: - -index_select ------------- - -.. autofunction:: paddle.fluid.layers.index_select - :noindex: - diff --git a/doc/fluid/api/layers/interpolate.rst b/doc/fluid/api/layers/interpolate.rst deleted file mode 100644 index 4dae3a131592dcbb688919f66a6925c027919f88..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/interpolate.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_interpolate: - -interpolate ------------ - -.. autofunction:: paddle.fluid.layers.interpolate - :noindex: - diff --git a/doc/fluid/api/layers/log1p.rst b/doc/fluid/api/layers/log1p.rst deleted file mode 100644 index 315d3e50b2b799b70a191d6c7c3880061f110ac2..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/log1p.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_log1p: - -log1p ------ - -.. autofunction:: paddle.fluid.layers.log1p - :noindex: - diff --git a/doc/fluid/api/layers/log_softmax.rst b/doc/fluid/api/layers/log_softmax.rst deleted file mode 100644 index 15aee0302c9896bf7563e24f34dc23c989da5f92..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/log_softmax.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_log_softmax: - -log_softmax ------------ - -.. autofunction:: paddle.fluid.layers.log_softmax - :noindex: - diff --git a/doc/fluid/api/layers/logsumexp.rst b/doc/fluid/api/layers/logsumexp.rst deleted file mode 100644 index 57c366f8e42a87031b98d736e86624fa39a3e49a..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/logsumexp.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_logsumexp: - -logsumexp ---------- - -.. autofunction:: paddle.fluid.layers.logsumexp - :noindex: - diff --git a/doc/fluid/api/layers/nonzero.rst b/doc/fluid/api/layers/nonzero.rst deleted file mode 100644 index 7eef8c358a0774a01a0c79d05bb0b626eba1a382..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/nonzero.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_nonzero: - -nonzero -------- - -.. autofunction:: paddle.fluid.layers.nonzero - :noindex: - diff --git a/doc/fluid/api/layers/randn.rst b/doc/fluid/api/layers/randn.rst deleted file mode 100644 index b58b052d4e63ec8319187c52bdac2146b5608783..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/randn.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_randn: - -randn ------ - -.. autofunction:: paddle.fluid.layers.randn - :noindex: - diff --git a/doc/fluid/api/layers/roll.rst b/doc/fluid/api/layers/roll.rst deleted file mode 100644 index f6744e12a237fcdc93bdde18b9ae5272dea29128..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/roll.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_roll: - -roll ----- - -.. autofunction:: paddle.fluid.layers.roll - :noindex: - diff --git a/doc/fluid/api/layers/trace.rst b/doc/fluid/api/layers/trace.rst deleted file mode 100644 index b189e1782fec49d30e47940f4ae04e2236ec4bc9..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/trace.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_trace: - -trace ------ - -.. autofunction:: paddle.fluid.layers.trace - :noindex: - diff --git a/doc/fluid/api/layers/tril.rst b/doc/fluid/api/layers/tril.rst deleted file mode 100644 index e9e4a88f06968f8a69b1952d2d31acfe67fb230a..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/tril.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_tril: - -tril ----- - -.. autofunction:: paddle.fluid.layers.tril - :noindex: - diff --git a/doc/fluid/api/layers/triu.rst b/doc/fluid/api/layers/triu.rst deleted file mode 100644 index 25d6a074ec6f3f7bdc4f88f24a826d5ebc6aabd4..0000000000000000000000000000000000000000 --- a/doc/fluid/api/layers/triu.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` - !DO NOT EDIT THIS FILE MANUALLY! - -.. _api_fluid_layers_triu: - -triu ----- - -.. autofunction:: paddle.fluid.layers.triu - :noindex: - diff --git a/doc/fluid/api/nn.rst b/doc/fluid/api/nn.rst new file mode 100644 index 0000000000000000000000000000000000000000..362b033a8d8d7bfd58bc4a8bb035c66db3db2d2c --- /dev/null +++ b/doc/fluid/api/nn.rst @@ -0,0 +1,8 @@ +========= +paddle.nn +========= + +.. toctree:: + :maxdepth: 1 + + nn/loss.rst diff --git a/doc/fluid/api/nn/loss.rst b/doc/fluid/api/nn/loss.rst new file mode 100644 index 0000000000000000000000000000000000000000..bbbf4faa1d34c1c01f90d25356971b87c68ad6b3 --- /dev/null +++ b/doc/fluid/api/nn/loss.rst @@ -0,0 +1,12 @@ +==== +loss +==== + +.. toctree:: + :maxdepth: 1 + + loss/BCELoss.rst + loss/CrossEntropyLoss.rst + loss/L1Loss.rst + loss/MSELoss.rst + loss/NLLLoss.rst diff --git a/doc/fluid/api/dygraph/L1Loss.rst b/doc/fluid/api/nn/loss/L1Loss.rst similarity index 60% rename from doc/fluid/api/dygraph/L1Loss.rst rename to doc/fluid/api/nn/loss/L1Loss.rst index 2d0f7c81fbd75abe45e34cee88c0a0c2ddb61e9a..161cb38c80a87c4ba38ed685133a705811ec9103 100644 --- a/doc/fluid/api/dygraph/L1Loss.rst +++ b/doc/fluid/api/nn/loss/L1Loss.rst @@ -1,12 +1,13 @@ .. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` !DO NOT EDIT THIS FILE MANUALLY! -.. _api_fluid_dygraph_L1Loss: +.. _api_nn_loss_L1Loss: L1Loss ------ -.. autoclass:: paddle.fluid.dygraph.L1Loss +.. autoclass:: paddle.nn.loss.L1Loss :members: + :inherited-members: :noindex: diff --git a/doc/fluid/api/tensor.rst b/doc/fluid/api/tensor.rst new file mode 100644 index 0000000000000000000000000000000000000000..c9b3bac88098133656aa67d2a257eb50bc5fcd2f --- /dev/null +++ b/doc/fluid/api/tensor.rst @@ -0,0 +1,11 @@ +============= +paddle.tensor +============= + +.. toctree:: + :maxdepth: 1 + + tensor/linalg.rst + tensor/math.rst + tensor/random.rst + tensor/stat.rst diff --git a/doc/fluid/api/tensor/linalg.rst b/doc/fluid/api/tensor/linalg.rst new file mode 100644 index 0000000000000000000000000000000000000000..08cabf1c4bfb9ee5be5b8d843ce0936707c8a50c --- /dev/null +++ b/doc/fluid/api/tensor/linalg.rst @@ -0,0 +1,8 @@ +====== +linalg +====== + +.. toctree:: + :maxdepth: 1 + + linalg/dist.rst diff --git a/doc/fluid/api/layers/meshgrid.rst b/doc/fluid/api/tensor/linalg/dist.rst similarity index 56% rename from doc/fluid/api/layers/meshgrid.rst rename to doc/fluid/api/tensor/linalg/dist.rst index d81b95c0ca6038ac4101fc8a44b0be621bc4ae8c..6ca92b5366fcfc3cae450ab8790b0773d276a57c 100644 --- a/doc/fluid/api/layers/meshgrid.rst +++ b/doc/fluid/api/tensor/linalg/dist.rst @@ -1,11 +1,11 @@ .. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` !DO NOT EDIT THIS FILE MANUALLY! -.. _api_fluid_layers_meshgrid: +.. _api_tensor_linalg_dist: -meshgrid +dist -------- -.. autofunction:: paddle.fluid.layers.meshgrid +.. autofunction:: paddle.tensor.linalg.dist :noindex: diff --git a/doc/fluid/api/tensor/math.rst b/doc/fluid/api/tensor/math.rst new file mode 100644 index 0000000000000000000000000000000000000000..0e0218b0351e9c7d90ec9637c6b12f4dd0297c59 --- /dev/null +++ b/doc/fluid/api/tensor/math.rst @@ -0,0 +1,25 @@ +==== +math +==== + +.. toctree:: + :maxdepth: 1 + + math/add.rst + math/addcmul.rst + math/addmm.rst + math/atan.rst + math/clamp.rst + math/div.rst + math/elementwise_sum.rst + math/log1p.rst + math/logsumexp.rst + math/max.rst + math/min.rst + math/mm.rst + math/mul.rst + math/pow.rst + math/sin.rst + math/sqrt.rst + math/sum.rst + math/tanh.rst diff --git a/doc/fluid/api/layers/dot.rst b/doc/fluid/api/tensor/math/add.rst similarity index 59% rename from doc/fluid/api/layers/dot.rst rename to doc/fluid/api/tensor/math/add.rst index 995066917ae5a050445ef92a4de345e498fba7c4..0b604ac2d1805066bfa24f8a12c8fbed36b14d0d 100644 --- a/doc/fluid/api/layers/dot.rst +++ b/doc/fluid/api/tensor/math/add.rst @@ -1,11 +1,11 @@ .. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` !DO NOT EDIT THIS FILE MANUALLY! -.. _api_fluid_layers_dot: +.. _api_tensor_math_add: -dot +add --- -.. autofunction:: paddle.fluid.layers.dot +.. autofunction:: paddle.tensor.math.add :noindex: diff --git a/doc/fluid/api/layers/dist.rst b/doc/fluid/api/tensor/math/atan.rst similarity index 58% rename from doc/fluid/api/layers/dist.rst rename to doc/fluid/api/tensor/math/atan.rst index d7cf6d5e2c44c20a0142b17a45ca64bffcc34ed8..31b11dbbe4fbc39d7f5c472478cea1544edfefe7 100644 --- a/doc/fluid/api/layers/dist.rst +++ b/doc/fluid/api/tensor/math/atan.rst @@ -1,11 +1,11 @@ .. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` !DO NOT EDIT THIS FILE MANUALLY! -.. _api_fluid_layers_dist: +.. _api_tensor_math_atan: -dist +atan ---- -.. autofunction:: paddle.fluid.layers.dist +.. autofunction:: paddle.tensor.math.atan :noindex: diff --git a/doc/fluid/api/layers/bmm.rst b/doc/fluid/api/tensor/math/div.rst similarity index 59% rename from doc/fluid/api/layers/bmm.rst rename to doc/fluid/api/tensor/math/div.rst index b78ec587edb0cdcab0af37e0f6b71194b4f7b1f2..cf8397dbffc36f895319dced427487e7f3851d40 100644 --- a/doc/fluid/api/layers/bmm.rst +++ b/doc/fluid/api/tensor/math/div.rst @@ -1,11 +1,11 @@ .. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` !DO NOT EDIT THIS FILE MANUALLY! -.. _api_fluid_layers_bmm: +.. _api_tensor_math_div: -bmm +div --- -.. autofunction:: paddle.fluid.layers.bmm +.. autofunction:: paddle.tensor.math.div :noindex: diff --git a/doc/fluid/api/tensor/math/elementwise_sum.rst b/doc/fluid/api/tensor/math/elementwise_sum.rst new file mode 100644 index 0000000000000000000000000000000000000000..05acb3f78f66192b5eea938cdd528b56da247a22 --- /dev/null +++ b/doc/fluid/api/tensor/math/elementwise_sum.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_math_elementwise_sum: + +elementwise_sum +--------------- + +.. autofunction:: paddle.tensor.math.elementwise_sum + :noindex: + diff --git a/doc/fluid/api/layers/t.rst b/doc/fluid/api/tensor/math/mm.rst similarity index 59% rename from doc/fluid/api/layers/t.rst rename to doc/fluid/api/tensor/math/mm.rst index 6a52eade10e87993bb85a242ffb972bb9bd4918c..8668c44055f25025ae080b3a08cce39919cd888b 100644 --- a/doc/fluid/api/layers/t.rst +++ b/doc/fluid/api/tensor/math/mm.rst @@ -1,11 +1,11 @@ .. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` !DO NOT EDIT THIS FILE MANUALLY! -.. _api_fluid_layers_t: +.. _api_tensor_math_mm: -t -- +mm +-- -.. autofunction:: paddle.fluid.layers.t +.. autofunction:: paddle.tensor.math.mm :noindex: diff --git a/doc/fluid/api/tensor/math/mul.rst b/doc/fluid/api/tensor/math/mul.rst new file mode 100644 index 0000000000000000000000000000000000000000..9b14559a4a35c701b8169cf425c1e8787db3561c --- /dev/null +++ b/doc/fluid/api/tensor/math/mul.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_math_mul: + +mul +--- + +.. autofunction:: paddle.tensor.math.mul + :noindex: + diff --git a/doc/fluid/api/tensor/math/pow.rst b/doc/fluid/api/tensor/math/pow.rst new file mode 100644 index 0000000000000000000000000000000000000000..5d0da558dd738aee845ef01c14d62ba4f023e921 --- /dev/null +++ b/doc/fluid/api/tensor/math/pow.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_math_pow: + +pow +--- + +.. autofunction:: paddle.tensor.math.pow + :noindex: + diff --git a/doc/fluid/api/tensor/math/sin.rst b/doc/fluid/api/tensor/math/sin.rst new file mode 100644 index 0000000000000000000000000000000000000000..862334131da6f38a853fcff1ed5860db625561ae --- /dev/null +++ b/doc/fluid/api/tensor/math/sin.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_math_sin: + +sin +--- + +.. autofunction:: paddle.tensor.math.sin + :noindex: + diff --git a/doc/fluid/api/layers/full.rst b/doc/fluid/api/tensor/math/sqrt.rst similarity index 58% rename from doc/fluid/api/layers/full.rst rename to doc/fluid/api/tensor/math/sqrt.rst index 5cec242c22bb8a5ac9434741ad8d60c79972881d..c0ad257993458844e18e514731f988b289a8e73f 100644 --- a/doc/fluid/api/layers/full.rst +++ b/doc/fluid/api/tensor/math/sqrt.rst @@ -1,11 +1,11 @@ .. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` !DO NOT EDIT THIS FILE MANUALLY! -.. _api_fluid_layers_full: +.. _api_tensor_math_sqrt: -full +sqrt ---- -.. autofunction:: paddle.fluid.layers.full +.. autofunction:: paddle.tensor.math.sqrt :noindex: diff --git a/doc/fluid/api/tensor/math/sum.rst b/doc/fluid/api/tensor/math/sum.rst new file mode 100644 index 0000000000000000000000000000000000000000..8946b3aa5056818046793ac856962c6ee4e0d175 --- /dev/null +++ b/doc/fluid/api/tensor/math/sum.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_math_sum: + +sum +--- + +.. autofunction:: paddle.tensor.math.sum + :noindex: + diff --git a/doc/fluid/api/layers/flip.rst b/doc/fluid/api/tensor/math/tanh.rst similarity index 58% rename from doc/fluid/api/layers/flip.rst rename to doc/fluid/api/tensor/math/tanh.rst index ad7f9c805026da2e72373d69f5b969df26fd88a9..ceb5971e0c3e51565f9fedec4df881eab5f86396 100644 --- a/doc/fluid/api/layers/flip.rst +++ b/doc/fluid/api/tensor/math/tanh.rst @@ -1,11 +1,11 @@ .. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` !DO NOT EDIT THIS FILE MANUALLY! -.. _api_fluid_layers_flip: +.. _api_tensor_math_tanh: -flip +tanh ---- -.. autofunction:: paddle.fluid.layers.flip +.. autofunction:: paddle.tensor.math.tanh :noindex: diff --git a/doc/fluid/api/tensor/random.rst b/doc/fluid/api/tensor/random.rst new file mode 100644 index 0000000000000000000000000000000000000000..687c6d5af6475436efc4c12c5ff93023cb32d526 --- /dev/null +++ b/doc/fluid/api/tensor/random.rst @@ -0,0 +1,10 @@ +====== +random +====== + +.. toctree:: + :maxdepth: 1 + + random/randint.rst + random/randn.rst + random/randperm.rst diff --git a/doc/fluid/api/layers/kron.rst b/doc/fluid/api/tensor/random/rand.rst similarity index 58% rename from doc/fluid/api/layers/kron.rst rename to doc/fluid/api/tensor/random/rand.rst index 90f24343a486953eabe3f872ff7853b88bfc6f83..7ad959e99d516a080f7e65f66eb385f6e4fe495b 100644 --- a/doc/fluid/api/layers/kron.rst +++ b/doc/fluid/api/tensor/random/rand.rst @@ -1,11 +1,11 @@ .. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` !DO NOT EDIT THIS FILE MANUALLY! -.. _api_fluid_layers_kron: +.. _api_tensor_random_rand: -kron +rand ---- -.. autofunction:: paddle.fluid.layers.kron +.. autofunction:: paddle.tensor.random.rand :noindex: diff --git a/doc/fluid/api/layers/randint.rst b/doc/fluid/api/tensor/random/randint.rst similarity index 60% rename from doc/fluid/api/layers/randint.rst rename to doc/fluid/api/tensor/random/randint.rst index 4cccc52e4471e787249fe914b3840994798667bb..e5a9d6139f425536ef05ab9ef28f3fba625ce7ad 100644 --- a/doc/fluid/api/layers/randint.rst +++ b/doc/fluid/api/tensor/random/randint.rst @@ -1,11 +1,11 @@ .. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` !DO NOT EDIT THIS FILE MANUALLY! -.. _api_fluid_layers_randint: +.. _api_tensor_random_randint: randint ------- -.. autofunction:: paddle.fluid.layers.randint +.. autofunction:: paddle.tensor.random.randint :noindex: diff --git a/doc/fluid/api/layers/randperm.rst b/doc/fluid/api/tensor/random/randperm.rst similarity index 59% rename from doc/fluid/api/layers/randperm.rst rename to doc/fluid/api/tensor/random/randperm.rst index 523a3b7a56b80c2ef2e55a9ff8ef1cc7581332fa..0aa4cc612db88a78abc8b3bb91fc347bed5b6f5a 100644 --- a/doc/fluid/api/layers/randperm.rst +++ b/doc/fluid/api/tensor/random/randperm.rst @@ -1,11 +1,11 @@ .. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` !DO NOT EDIT THIS FILE MANUALLY! -.. _api_fluid_layers_randperm: +.. _api_tensor_random_randperm: randperm -------- -.. autofunction:: paddle.fluid.layers.randperm +.. autofunction:: paddle.tensor.random.randperm :noindex: diff --git a/doc/fluid/api_cn/dygraph_cn.rst b/doc/fluid/api_cn/dygraph_cn.rst index 2e840f59c18153388800fd1c6fce8e82a3bc3199..09ebf3fa4ed02774b469d98c7527895aa14f9cb9 100644 --- a/doc/fluid/api_cn/dygraph_cn.rst +++ b/doc/fluid/api_cn/dygraph_cn.rst @@ -10,7 +10,6 @@ fluid.dygraph dygraph_cn/BackwardStrategy_cn.rst dygraph_cn/BatchNorm_cn.rst - dygraph_cn/BCELoss_cn.rst dygraph_cn/BilinearTensorProduct_cn.rst dygraph_cn/Conv2D_cn.rst dygraph_cn/Conv2DTranspose_cn.rst @@ -18,7 +17,6 @@ fluid.dygraph dygraph_cn/Conv3DTranspose_cn.rst dygraph_cn/CosineDecay_cn.rst dygraph_cn/Dropout_cn.rst - dygraph_cn/declarative_cn.rst dygraph_cn/Embedding_cn.rst dygraph_cn/ExponentialDecay_cn.rst dygraph_cn/FC_cn.rst @@ -26,18 +24,14 @@ fluid.dygraph dygraph_cn/GroupNorm_cn.rst dygraph_cn/GRUUnit_cn.rst dygraph_cn/guard_cn.rst - dygraph_cn/InstanceNorm_cn.rst dygraph_cn/InverseTimeDecay_cn.rst - dygraph_cn/L1Loss_cn.rst dygraph_cn/Layer_cn.rst dygraph_cn/LayerList_cn.rst dygraph_cn/LayerNorm_cn.rst dygraph_cn/Linear_cn.rst dygraph_cn/load_dygraph_cn.rst - dygraph_cn/MSELoss_cn.rst dygraph_cn/NaturalExpDecay_cn.rst dygraph_cn/NCE_cn.rst - dygraph_cn/NLLLoss_cn.rst dygraph_cn/NoamDecay_cn.rst dygraph_cn/ParallelEnv_cn.rst dygraph_cn/ParameterList_cn.rst @@ -47,7 +41,6 @@ fluid.dygraph dygraph_cn/Pool2D_cn.rst dygraph_cn/PRelu_cn.rst dygraph_cn/prepare_context_cn.rst - dygraph_cn/ProgramTranslator_cn.rst dygraph_cn/save_dygraph_cn.rst dygraph_cn/Sequential_cn.rst dygraph_cn/SpectralNorm_cn.rst diff --git a/doc/fluid/api_cn/dygraph_cn/L1Loss_cn.rst b/doc/fluid/api_cn/dygraph_cn/L1Loss_cn.rst deleted file mode 100644 index 408ba588726b54f8419b134ee91bb2d717c6264e..0000000000000000000000000000000000000000 --- a/doc/fluid/api_cn/dygraph_cn/L1Loss_cn.rst +++ /dev/null @@ -1,60 +0,0 @@ -L1Loss -------------------------------- - -.. py:function:: paddle.fluid.layers.L1Loss(reduction='mean') -该接口用于创建一个L1Loss的可调用类,L1Loss计算输入input和标签label间的 `L1 loss` 损失。 - -该损失函数的数学计算公式如下: - -当 `reduction` 设置为 ``'none'`` 时, - - .. math:: - Out = |input - label| -当 `reduction` 设置为 ``'mean'`` 时, - - .. math:: - Out = MEAN(|input - label|) -当 `reduction` 设置为 ``'sum'`` 时, - - .. math:: - Out = SUM(|input - label|) -输入input和标签label的维度是[N, *], 其中N是batch_size, `*` 是任意其他维度。 -如果 :attr:`reduction` 是 ``'none'``, 则输出Loss的维度为 [N, *], 与输入input相同。 -如果 :attr:`reduction` 是 ``'mean'`` 或 ``'sum'``, 则输出Loss的维度为 [1]。 - -参数: - - **reduction** (string, 可选): - 指定应用于输出结果的计算方式,可选值有: ``'none'``, ``'mean'``, ``'sum'`` 。默认为 ``'mean'``,计算 `L1Loss` 的均值;设置为 ``'sum'`` 时,计算 `L1Loss` 的总和;设置为 ``'none'`` 时,则返回L1Loss。数据类型为string。 - -返回:返回计算L1Loss的可调用对象。 - -**代码示例** - -.. code-block:: python - # declarative mode - import paddle.fluid as fluid - import numpy as np - import paddle - input = fluid.data(name="input", shape=[1]) - label = fluid.data(name="label", shape=[1]) - l1_loss = fluid.layers.L1Loss(reduction='mean') - output = l1_loss(input,label) - place = fluid.CPUPlace() - exe = fluid.Executor(place) - exe.run(fluid.default_startup_program()) - input_data = np.array([1.5]).astype("float32") - label_data = np.array([1.7]).astype("float32") - output_data = exe.run(fluid.default_main_program(), - feed={"input":input_data, "label":label_data}, - fetch_list=[output], - return_numpy=True) - print(output_data) # [array([0.2], dtype=float32)] - - # imperative mode - import paddle.fluid.dygraph as dg - with dg.guard(place) as g: - input = dg.to_variable(input_data) - label = dg.to_variable(label_data) - l1_loss = fluid.layers.L1Loss(reduction='mean') - output = l1_loss(input,label) - print(output.numpy()) # [0.2] - diff --git a/doc/fluid/api_cn/dygraph_cn/NLLLoss_cn.rst b/doc/fluid/api_cn/dygraph_cn/NLLLoss_cn.rst index 1436eeb08bf1057ad6cd1dd44b1a313dbe5daa1b..9b42b49d36ab32b8c07a7509a94134b708ba5513 100644 --- a/doc/fluid/api_cn/dygraph_cn/NLLLoss_cn.rst +++ b/doc/fluid/api_cn/dygraph_cn/NLLLoss_cn.rst @@ -1,3 +1,75 @@ NLLLoss ------------------------------- -**版本升级,文档正在开发中** + +.. py:function:: paddle.fluid.dygraph.NLLLoss(weight=None, reduction='mean', ignore_index=-100) + +该OP计算输入input和标签label间的 `negative log likelihood loss` 损失 ,可用于训练一个 `n` 类分类器。 + +如果提供 `weight` 参数的话,它是一个 `1-D` 的tensor, 里面的值对应类别的权重。当你的训练集样本 +不均衡的话,使用这个参数是非常有用的。 + +该损失函数的数学计算公式如下: + +当 `reduction` 设置为 `none` 时,损失函数的数学计算公式为: + + .. math:: + \ell(x, y) = L = \{l_1,\dots,l_N\}^\top, \quad + l_n = - w_{y_n} x_{n,y_n}, \quad + w_{c} = \text{weight}[c] \cdot \mathbb{1}\{c \not= \text{ignore_index}\}, + +其中 `N` 表示 `batch_size` 。如果 `reduction` 的值不是 `none` (默认为 `mean`),那么此时损失函数 +的数学计算公式为: + + .. math:: + \ell(x, y) = \begin{cases} + \sum_{n=1}^N \frac{1}{\sum_{n=1}^N w_{y_n}} l_n, & + \text{if reduction} = \text{'mean';}\\ + \sum_{n=1}^N l_n, & + \text{if reduction} = \text{'sum'.} + \end{cases} + +参数: + - **input** (Variable): - 输入 `Tensor`, 其形状为 :math:`[N, C]` , 其中 `C` 为类别数。但是对于多维度的情形下,它的形状为 :math:`[N, C, d_1, d_2, ..., d_K]` 。数据类型为float32或float64。 + - **label** (Variable): - 输入input对应的标签值。其形状为 :math:`[N,]` 或者 :math:`[N, d_1, d_2, ..., d_K]`, 数据类型为int64。 + - **weight** (Variable, 可选): - 手动指定每个类别的权重。其默认为 `None` 。如果提供该参数的话,长度必须为 `num_classes` 。数据类型为float32或float64。 + - **reduction** (string, 可选): - 指定应用于输出结果的计算方式,可选值有: `none`, `mean`, `sum` 。默认为 `mean` ,计算 `mini-batch` loss均值。设置为 `sum` 时,计算 `mini-batch` loss的总和。设置为 `none` 时,则返回loss Tensor。数据类型为string。 + - **ignore_index** (int64, 可选): - 指定一个忽略的标签值,此标签值不参与计算。默认值为-100。数据类型为int64。 + +返回:返回存储表示 `negative log likihood loss` 的损失值。 + +返回类型:Variable + +**代码示例** + +.. code-block:: python + + # declarative mode + import paddle.fluid as fluid + import numpy as np + import paddle + input_np = np.random.random(size=(10, 10)).astype(np.float32) + label_np = np.random.randint(0, 10, size=(10,)).astype(np.int64) + prog = fluid.Program() + startup_prog = fluid.Program() + place = fluid.CPUPlace() + with fluid.program_guard(prog, startup_prog): + input = fluid.data(name='input', shape=[10, 10], dtype='float32') + label = fluid.data(name='label', shape=[10], dtype='int64') + nll_loss = fluid.dygraph.NLLLoss() + res = nll_loss(input, label) + exe = fluid.Executor(place) + static_result = exe.run( + prog, + feed={"input": input_np, + "label": label_np}, + fetch_list=[res]) + print(static_result) + + # imperative mode + import paddle.fluid.dygraph as dg + with dg.guard(place) as g: + input = dg.to_variable(input_np) + label = dg.to_variable(label_np) + output = nll_loss(input, label) + print(output.numpy()) + diff --git a/doc/fluid/api_cn/dygraph_cn/ProgramTranslator_cn.rst b/doc/fluid/api_cn/dygraph_cn/ProgramTranslator_cn.rst deleted file mode 100644 index 3b6eae3613fce1d78224f5e752421977de516019..0000000000000000000000000000000000000000 --- a/doc/fluid/api_cn/dygraph_cn/ProgramTranslator_cn.rst +++ /dev/null @@ -1,3 +0,0 @@ -ProgramTranslator -------------------------------- -**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/dygraph_cn/declarative_cn.txt b/doc/fluid/api_cn/dygraph_cn/declarative_cn.txt deleted file mode 100644 index 44a8e4b937bf75889226ea82ec6285ad63229730..0000000000000000000000000000000000000000 --- a/doc/fluid/api_cn/dygraph_cn/declarative_cn.txt +++ /dev/null @@ -1,3 +0,0 @@ -declarative -------------------------------- -**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/framework_cn.rst b/doc/fluid/api_cn/framework_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..71126981addd3b108ac677feb4910a0225009547 --- /dev/null +++ b/doc/fluid/api_cn/framework_cn.rst @@ -0,0 +1,13 @@ +======================= +paddle.framework +======================= + + + + +.. toctree:: + :maxdepth: 1 + + framework_cn/get_default_dtype_cn.rst + framework_cn/manual_seed_cn.rst + framework_cn/set_default_dtype_cn.rst diff --git a/doc/fluid/api_cn/framework_cn/get_default_dtype_cn.rst b/doc/fluid/api_cn/framework_cn/get_default_dtype_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..2a3de92563fc77e44e372830f03f2405fc05104b --- /dev/null +++ b/doc/fluid/api_cn/framework_cn/get_default_dtype_cn.rst @@ -0,0 +1,3 @@ +get +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/framework_cn/manual_seed_cn.rst b/doc/fluid/api_cn/framework_cn/manual_seed_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..cd11ecacafe3e4791bce42a28207fbf91ef087dc --- /dev/null +++ b/doc/fluid/api_cn/framework_cn/manual_seed_cn.rst @@ -0,0 +1,3 @@ +manual +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/framework_cn/set_default_dtype_cn.rst b/doc/fluid/api_cn/framework_cn/set_default_dtype_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..3d7928489a3288e0865dda6e89804d7e997d0d21 --- /dev/null +++ b/doc/fluid/api_cn/framework_cn/set_default_dtype_cn.rst @@ -0,0 +1,3 @@ +set +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/index_cn.rst b/doc/fluid/api_cn/index_cn.rst index 8599fb58c60845168918446808735b2cec68951d..f13a423209b95bf5b1e3b0471b36bfaaa45f9000 100644 --- a/doc/fluid/api_cn/index_cn.rst +++ b/doc/fluid/api_cn/index_cn.rst @@ -6,6 +6,9 @@ API Reference :maxdepth: 1 ../api_guides/index_cn.rst + framework_cn.rst + nn_cn.rst + tensor_cn.rst fluid_cn.rst api_tree_cn.rst backward_cn.rst @@ -21,5 +24,6 @@ API Reference optimizer_cn.rst profiler_cn.rst regularizer_cn.rst + tensor_cn.rst transpiler_cn.rst unique_name_cn.rst diff --git a/doc/fluid/api_cn/layers_cn.rst b/doc/fluid/api_cn/layers_cn.rst index 05188d0925841e001a1d413746c25cbb248a6250..dd94cfc4144521b82672148802cc450b0a42feeb 100644 --- a/doc/fluid/api_cn/layers_cn.rst +++ b/doc/fluid/api_cn/layers_cn.rst @@ -16,13 +16,9 @@ fluid.layers layers_cn/adaptive_pool2d_cn.rst layers_cn/adaptive_pool3d_cn.rst layers_cn/add_position_encoding_cn.rst - layers_cn/addcmul_cn.rst - layers_cn/addmm_cn.rst layers_cn/affine_channel_cn.rst layers_cn/affine_grid_cn.rst - layers_cn/allclose_cn.rst layers_cn/anchor_generator_cn.rst - layers_cn/arange_cn.rst layers_cn/argmax_cn.rst layers_cn/argmin_cn.rst layers_cn/argsort_cn.rst @@ -39,7 +35,6 @@ fluid.layers layers_cn/beam_search_decode_cn.rst layers_cn/bilinear_tensor_product_cn.rst layers_cn/bipartite_match_cn.rst - layers_cn/bmm_cn.rst layers_cn/box_clip_cn.rst layers_cn/box_coder_cn.rst layers_cn/box_decoder_and_assign_cn.rst @@ -52,7 +47,6 @@ fluid.layers layers_cn/ceil_cn.rst layers_cn/center_loss_cn.rst layers_cn/chunk_eval_cn.rst - layers_cn/clamp_cn.rst layers_cn/clip_by_norm_cn.rst layers_cn/clip_cn.rst layers_cn/collect_fpn_proposals_cn.rst @@ -74,7 +68,6 @@ fluid.layers layers_cn/crf_decoding_cn.rst layers_cn/crop_cn.rst layers_cn/crop_tensor_cn.rst - layers_cn/cross_cn.rst layers_cn/cross_entropy_cn.rst layers_cn/ctc_greedy_decoder_cn.rst layers_cn/cumsum_cn.rst @@ -85,11 +78,8 @@ fluid.layers layers_cn/density_prior_box_cn.rst layers_cn/detection_output_cn.rst layers_cn/diag_cn.rst - layers_cn/diag_embed_cn.rst layers_cn/dice_loss_cn.rst - layers_cn/dist_cn.rst layers_cn/distribute_fpn_proposals_cn.rst - layers_cn/dot_cn.rst layers_cn/double_buffer_cn.rst layers_cn/dropout_cn.rst layers_cn/dynamic_gru_cn.rst @@ -101,7 +91,6 @@ fluid.layers layers_cn/edit_distance_cn.rst layers_cn/elementwise_add_cn.rst layers_cn/elementwise_div_cn.rst - layers_cn/elementwise_equal_cn.rst layers_cn/elementwise_floordiv_cn.rst layers_cn/elementwise_max_cn.rst layers_cn/elementwise_min_cn.rst @@ -122,11 +111,8 @@ fluid.layers layers_cn/fill_constant_cn.rst layers_cn/filter_by_instag_cn.rst layers_cn/flatten_cn.rst - layers_cn/flip_cn.rst layers_cn/floor_cn.rst layers_cn/fsp_matrix_cn.rst - layers_cn/full_cn.rst - layers_cn/full_like_cn.rst layers_cn/gather_cn.rst layers_cn/gather_nd_cn.rst layers_cn/gather_tree_cn.rst @@ -156,14 +142,11 @@ fluid.layers layers_cn/image_resize_short_cn.rst layers_cn/increment_cn.rst layers_cn/inverse_time_decay_cn.rst - layers_cn/index_select_cn.rst layers_cn/instance_norm_cn.rst - layers_cn/interpolate_cn.rst layers_cn/iou_similarity_cn.rst layers_cn/is_empty_cn.rst layers_cn/isfinite_cn.rst layers_cn/kldiv_loss_cn.rst - layers_cn/kron_cn.rst layers_cn/l2_normalize_cn.rst layers_cn/label_smooth_cn.rst layers_cn/layer_norm_cn.rst @@ -177,15 +160,12 @@ fluid.layers layers_cn/lod_append_cn.rst layers_cn/lod_reset_cn.rst layers_cn/log_cn.rst - layers_cn/log1p_cn.rst layers_cn/log_loss_cn.rst - layers_cn/log_softmax_cn.rst layers_cn/logical_and_cn.rst layers_cn/logical_not_cn.rst layers_cn/logical_or_cn.rst layers_cn/logical_xor_cn.rst layers_cn/logsigmoid_cn.rst - layers_cn/logsumexp_cn.rst layers_cn/lrn_cn.rst layers_cn/lstm_cn.rst layers_cn/lstm_unit_cn.rst @@ -197,7 +177,6 @@ fluid.layers layers_cn/mean_cn.rst layers_cn/mean_iou_cn.rst layers_cn/merge_selected_rows_cn.rst - layers_cn/meshgrid_cn.rst layers_cn/mse_loss_cn.rst layers_cn/mul_cn.rst layers_cn/multi_box_head_cn.rst @@ -207,7 +186,6 @@ fluid.layers layers_cn/natural_exp_decay_cn.rst layers_cn/nce_cn.rst layers_cn/noam_decay_cn.rst - layers_cn/nonzero_cn.rst layers_cn/Normal_cn.rst layers_cn/not_equal_cn.rst layers_cn/npair_loss_cn.rst @@ -232,10 +210,8 @@ fluid.layers layers_cn/py_func_cn.rst layers_cn/py_reader_cn.rst layers_cn/randint_cn.rst - layers_cn/randn_cn.rst layers_cn/random_crop_cn.rst layers_cn/range_cn.rst - layers_cn/randperm_cn.rst layers_cn/rank_cn.rst layers_cn/rank_loss_cn.rst layers_cn/read_file_cn.rst @@ -261,7 +237,6 @@ fluid.layers layers_cn/roi_align_cn.rst layers_cn/roi_perspective_transform_cn.rst layers_cn/roi_pool_cn.rst - layers_cn/roll_cn.rst layers_cn/round_cn.rst layers_cn/row_conv_cn.rst layers_cn/rpn_target_assign_cn.rst @@ -325,7 +300,6 @@ fluid.layers layers_cn/swish_cn.rst layers_cn/Switch_cn.rst layers_cn/switch_case_cn.rst - layers_cn/t_cn.rst layers_cn/tanh_cn.rst layers_cn/tanh_shrink_cn.rst layers_cn/target_assign_cn.rst @@ -334,10 +308,7 @@ fluid.layers layers_cn/tensor_array_to_tensor_cn.rst layers_cn/thresholded_relu_cn.rst layers_cn/topk_cn.rst - layers_cn/trace_cn.rst layers_cn/transpose_cn.rst - layers_cn/tril_cn.rst - layers_cn/triu_cn.rst layers_cn/unfold_cn.rst layers_cn/Uniform_cn.rst layers_cn/uniform_random_cn.rst diff --git a/doc/fluid/api_cn/layers_cn/randint_cn.rst b/doc/fluid/api_cn/layers_cn/randint_cn.rst index c12490bfdaf2f4ed246b99361f871caa42266f34..49460b063f1c6b9ba12cd70c3b311e4474a20b72 100644 --- a/doc/fluid/api_cn/layers_cn/randint_cn.rst +++ b/doc/fluid/api_cn/layers_cn/randint_cn.rst @@ -1,3 +1,56 @@ +.. _cn_api_fluid_layers_randint: + randint ------------------------------- -**版本升级,文档正在开发中** + +.. py:function:: paddle.fluid.layers.randint(low, high=None, shape=None, out=None, dtype=None, device=None, stop_gradient=False, seed=0, name=None) + +该OP使用从区间[low,high)内均匀分布采样的随机整数初始化一个Tensor。当high为None时(默认),均匀采样的区间为[0,low)。 + +参数: + - **low** (int)-要生成的随机值范围的下限,low包含在范围中。当high为None时,均匀采样的区间为[0,low)。 + - **high** (int,可选)-要生成的随机值范围的上限,high不包含在范围中。默认值为None。 + - **shape** (list|tuple|Variable,可选)-输出Tensor的维度,shape类型支持list,tuple,Variable。如果shape类型是list或者tuple,它的元素可以是整数或者形状为[1]的Tensor,其中整数的数据类型为int,Tensor的数据类型为int32或int64。如果shape的类型是Variable,则是1D的Tensor,Tensor的数据类型为int32或int64。如果shape为None,则会将shape设置为[1]。默认值为None。 + - **out** (Variable,可选)-用于存储创建的Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。 + - **dtype** (np.dtype|core.VarDesc.VarType|str,可选)- 输出Tensor的数据类型,支持数据类型为int32,int64。如果dtype为None,则会将dtype设置为int64。默认值为None。 + - **device** (str, 可选)-指定在GPU或CPU上创建Tensor。如果device为None,则将选择运行Paddle程序的设备,默认为None。 + - **stop_gradient** (bool,可选)-指定是否停止梯度计算,默认值为False。 + - **seed** (int,可选)-随机种子,用于生成样本。0表示使用系统生成的种子。注意如果种子不为0,该操作符每次都生成同样的随机数。默认为 0。 + - **name** (str,可选)-具体用法请参见:ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回:表示一个随机初始化结果的Tensor,该Tensor的数据类型由dtype参数决定,该Tensor的维度由shape参数决定。 + +返回类型:Variable + +抛出异常: + - :code:`TypeError`: shape的类型应该是list、tuple 或 Variable。 + - :code:`TypeError`: dtype的类型应该是int32或int64。 + - :code:`ValueError`: 该OP的high必须大于low(high为None时,则会先将high设置为low,将low设置为0,再判断low和high的大小关系)。 + +**代码示例**: + +.. code-block:: python + + import paddle.fluid as fluid + + # example 1: + # attr shape is a list which doesn't contain tensor Variable. + result_1 = fluid.layers.randint(low=-5, high=5, shape=[3, 4], dtype="int64") + + # example 2: + # attr shape is a list which contains tensor Variable. + dim_1 = fluid.layers.fill_constant([1],"int64",3) + dim_2 = fluid.layers.fill_constant([1],"int32",5) + result_2 = fluid.layers.randint(low=-5, high=5, shape=[dim_1, dim_2], dtype="int32") + + # example 3: + # attr shape is a Variable, the data type must be int64 or int32. + var_shape = fluid.data(name='var_shape', shape=[2], dtype="int64") + result_3 = fluid.layers.randint(low=-5, high=5, shape=var_shape, dtype="int32") + var_shape_int32 = fluid.data(name='var_shape_int32', shape=[2], dtype="int32") + result_4 = fluid.layers.randint(low=-5, high=5, shape=var_shape_int32, dtype="int64") + + # example 4: + # Input only one parameter + # low=0, high=10, shape=[1], dtype='int64' + result_4 = fluid.layers.randint(10) diff --git a/doc/fluid/api_cn/layers_cn/trace_cn.rst b/doc/fluid/api_cn/layers_cn/trace_cn.rst deleted file mode 100644 index d1973d297594d7b11697b1528fc4fe3695b6c5ca..0000000000000000000000000000000000000000 --- a/doc/fluid/api_cn/layers_cn/trace_cn.rst +++ /dev/null @@ -1,5 +0,0 @@ -trace -------------------------------- -**版本升级,文档正在开发中** - - diff --git a/doc/fluid/api_cn/nn_cn.rst b/doc/fluid/api_cn/nn_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..16f0da5958fabd448c95f5c4e7af3e64fb9b58c7 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn.rst @@ -0,0 +1,20 @@ +======================= +paddle.nn +======================= + + + + +.. toctree:: + :maxdepth: 1 + + nn_cn/Conv1D_cn.rst + nn_cn/Conv2D_cn.rst + nn_cn/diag_embed_cn.rst + nn_cn/interpolate_cn.rst + nn_cn/Linear_cn.rst + nn_cn/log_softmax_cn.rst + nn_cn/ReLU_cn.rst + nn_cn/Upsample_cn.rst + nn_cn/activation_cn.rst + nn_cn/loss_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/Conv1D_cn.rst b/doc/fluid/api_cn/nn_cn/Conv1D_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..c4273335337c0b600b685ba953c4588b5020a406 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/Conv1D_cn.rst @@ -0,0 +1,3 @@ +Conv1D +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/nn_cn/Conv2D_cn.rst b/doc/fluid/api_cn/nn_cn/Conv2D_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..24c985affffcb4467bbf8d0474fe4b00bb60dabf --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/Conv2D_cn.rst @@ -0,0 +1,3 @@ +Conv2D +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/nn_cn/Linear_cn.rst b/doc/fluid/api_cn/nn_cn/Linear_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..2ffaf0736ee7903844d716d26b6d2cb35831cacf --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/Linear_cn.rst @@ -0,0 +1,3 @@ +Linear +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/nn_cn/ReLU_cn.rst b/doc/fluid/api_cn/nn_cn/ReLU_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..687436b737f3e9f6ee2f645af84b3091fa2ad146 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/ReLU_cn.rst @@ -0,0 +1,3 @@ +ReLU +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/nn_cn/Upsample_cn.rst b/doc/fluid/api_cn/nn_cn/Upsample_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..c9257d1de9d6369f2277fee23bbe50999f625c74 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/Upsample_cn.rst @@ -0,0 +1,3 @@ +Upsample +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/nn_cn/activation_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..9bd3fa86689a40936ccccd5acae95a6ab433c2cd --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/activation_cn.rst @@ -0,0 +1,11 @@ +======================= +activation +======================= + + + + +.. toctree:: + :maxdepth: 1 + + activation_cn/Sigmoid_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/activation_cn/Sigmoid_cn.rst b/doc/fluid/api_cn/nn_cn/activation_cn/Sigmoid_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..0754265b2131c42b1d2e0a910e89163f4681f903 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/activation_cn/Sigmoid_cn.rst @@ -0,0 +1,3 @@ +Sigmoid +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/layers_cn/diag_embed_cn.rst b/doc/fluid/api_cn/nn_cn/diag_embed_cn.rst similarity index 100% rename from doc/fluid/api_cn/layers_cn/diag_embed_cn.rst rename to doc/fluid/api_cn/nn_cn/diag_embed_cn.rst diff --git a/doc/fluid/api_cn/layers_cn/interpolate_cn.rst b/doc/fluid/api_cn/nn_cn/interpolate_cn.rst similarity index 100% rename from doc/fluid/api_cn/layers_cn/interpolate_cn.rst rename to doc/fluid/api_cn/nn_cn/interpolate_cn.rst diff --git a/doc/fluid/api_cn/layers_cn/log_softmax_cn.rst b/doc/fluid/api_cn/nn_cn/log_softmax_cn.rst similarity index 100% rename from doc/fluid/api_cn/layers_cn/log_softmax_cn.rst rename to doc/fluid/api_cn/nn_cn/log_softmax_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/loss_cn.rst b/doc/fluid/api_cn/nn_cn/loss_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..3c4c2c33fbb37343f91713b25bba8af86f8943a5 --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/loss_cn.rst @@ -0,0 +1,15 @@ +======================= +loss +======================= + + + + +.. toctree:: + :maxdepth: 1 + + loss_cn/BCELoss_cn.rst + loss_cn/CrossEntropyLoss_cn.rst + loss_cn/L1Loss_cn.rst + loss_cn/MSELoss_cn.rst + loss_cn/NLLLoss_cn.rst diff --git a/doc/fluid/api_cn/dygraph_cn/BCELoss_cn.rst b/doc/fluid/api_cn/nn_cn/loss_cn/BCELoss_cn.rst similarity index 100% rename from doc/fluid/api_cn/dygraph_cn/BCELoss_cn.rst rename to doc/fluid/api_cn/nn_cn/loss_cn/BCELoss_cn.rst diff --git a/doc/fluid/api_cn/dygraph_cn/InstanceNorm_cn.rst b/doc/fluid/api_cn/nn_cn/loss_cn/CrossEntropyLoss_cn.rst similarity index 81% rename from doc/fluid/api_cn/dygraph_cn/InstanceNorm_cn.rst rename to doc/fluid/api_cn/nn_cn/loss_cn/CrossEntropyLoss_cn.rst index 15496466d42b647ac6b98f0a97630c824bb4c618..1e6a928c8db98b0ead6882b2577e01b545428ba1 100644 --- a/doc/fluid/api_cn/dygraph_cn/InstanceNorm_cn.rst +++ b/doc/fluid/api_cn/nn_cn/loss_cn/CrossEntropyLoss_cn.rst @@ -1,3 +1,3 @@ -InstanceNorm +CrossEntropyLoss ------------------------------- **版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/nn_cn/loss_cn/L1Loss_cn.rst b/doc/fluid/api_cn/nn_cn/loss_cn/L1Loss_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..b637fb12c6c1d29c2e494a7f9419a5d1d8f16bbe --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/loss_cn/L1Loss_cn.rst @@ -0,0 +1,3 @@ +L1Loss +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/dygraph_cn/MSELoss_cn.rst b/doc/fluid/api_cn/nn_cn/loss_cn/MSELoss_cn.rst similarity index 100% rename from doc/fluid/api_cn/dygraph_cn/MSELoss_cn.rst rename to doc/fluid/api_cn/nn_cn/loss_cn/MSELoss_cn.rst diff --git a/doc/fluid/api_cn/nn_cn/loss_cn/NLLLoss_cn.rst b/doc/fluid/api_cn/nn_cn/loss_cn/NLLLoss_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..1436eeb08bf1057ad6cd1dd44b1a313dbe5daa1b --- /dev/null +++ b/doc/fluid/api_cn/nn_cn/loss_cn/NLLLoss_cn.rst @@ -0,0 +1,3 @@ +NLLLoss +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/tensor_cn/add_cn.rst b/doc/fluid/api_cn/tensor_cn/add_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..bace507c210a62d8e6c1b4784434fbcb5b35c992 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/add_cn.rst @@ -0,0 +1,173 @@ +.. _cn_api_tensor_add: + +add +------------------------------- + +.. py:function:: paddle.add(x, y, alpha=1, out=None, name=None) + +该OP是逐元素相加算子,输入 ``x`` 与输入 ``y`` 逐元素相加,并将各个位置的输出元素保存到返回结果中。 + +等式为: + +.. math:: + Out = X + Y + +- :math:`X` :多维Tensor。 +- :math:`Y` :维度必须小于等于X维度的Tensor。 + +对于这个运算算子有2种情况: + 1. :math:`Y` 的 ``shape`` 与 :math:`X` 相同。 + 2. :math:`Y` 的 ``shape`` 是 :math:`X` 的连续子序列。 + +对于情况2: + 1. 用 :math:`Y` 匹配 :math:`X` 的形状(shape),其中 ``axis`` 是 :math:`Y` 在 :math:`X` 上的起始维度的位置。 + 2. 如果 ``axis`` 为-1(默认值),则 :math:`axis= rank(X)-rank(Y)` 。 + 3. 考虑到子序列, :math:`Y` 的大小为1的尾部维度将被忽略,例如shape(Y)=(2,1)=>(2)。 + +例如: + +.. code-block:: text + + shape(X) = (2, 3, 4, 5), shape(Y) = (,) + shape(X) = (2, 3, 4, 5), shape(Y) = (5,) + shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5), with axis=-1(default) or axis=2 + shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1 + shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0 + shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0 + +参数: + - **x** (Variable)- 多维 ``Tensor`` 或 ``LoDTensor`` 。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64``。 + - **y** (Variable)- 多维 ``Tensor`` 或 ``LoDTensor`` 。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64``。 + - **alpha** (int|float,可选)- 输入y的缩放因子。默认值为1. 如果alpha不为1,本api计算公式变为 :math:`Out = X + alpha * Y` + - **out** (Variable,可选)- 指定存储运算结果的 ``Tensor`` 。如果设置为None或者不设置,将创建新的 ``Tensor`` 存储运算结果,默认值为None。 + - **name** (str,可选)- 输出的名字。默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。 + + +返回: 多维 ``Tensor`` 或 ``LoDTensor`` ,维度和数据类型都与 ``x`` 相同。 + +返回类型: Variable + +**代码示例 1** + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + import numpy as np + + def gen_data(): + return { + "x": np.array([2, 3, 4]).astype('float32'), + "y": np.array([1, 5, 2]).astype('float32') + } + + x = fluid.data(name="x", shape=[3], dtype='float32') + y = fluid.data(name="y", shape=[3], dtype='float32') + z1 = paddle.add(x, y) + z2 = paddle.add(x, y, alpha=10) + # z = x + y + + place = fluid.CPUPlace() + exe = fluid.Executor(place) + z_value = exe.run(feed=gen_data(), + fetch_list=[z1.name, z2.name]) + + print(z_value[0]) # [3., 8., 6.] + print(z_value[1]) # [12. 53. 24.] + +**代码示例 2** + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + import numpy as np + + def gen_data(): + return { + "x": np.ones((2, 3, 4, 5)).astype('float32'), + "y": np.zeros((4, 5)).astype('float32') + } + + x = fluid.data(name="x", shape=[2, 3, 4, 5], dtype='float32') + y = fluid.data(name="y", shape=[4, 5], dtype='float32') + z = paddle.add(x, y, name='z') + # z = x + y + + place = fluid.CPUPlace() + exe = fluid.Executor(place) + + z_value = exe.run(feed=gen_data(), + fetch_list=[z.name]) + + print(z_value[0]) + print(z_value[0].shape) # z.shape=[2,3,4,5] + +**代码示例 3** + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + import numpy as np + + def gen_data(): + return { + "x": np.random.randint(1, 5, size=[2, 3, 4, 5]).astype('float32'), + "y": np.random.randint(1, 5, size=[5]).astype('float32') + } + + x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32') + y = fluid.data(name="y", shape=[5], dtype='float32') + z = paddle.add(x, y) + # z = x / y + + place = fluid.CPUPlace() + exe = fluid.Executor(place) + + z_value = exe.run(feed=gen_data(), + fetch_list=[z.name]) + print(z_value[0]) + print(z_value[0].shape) # z.shape=[2,3,4,5] + + +**代码示例 4** + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + import numpy as np + + x = fluid.data(name="x", shape=[3], dtype="float32") + y = fluid.data(name='y', shape=[3], dtype='float32') + + output = fluid.data(name="output", shape=[3], dtype="float32") + z = paddle.add(x, y, out=output) + + place = fluid.CPUPlace() + exe = fluid.Executor(place) + data1 = np.array([2, 3, 4], dtype='float32') + data2 = np.array([1, 5, 2], dtype='float32') + z_value = exe.run(feed={'x': data1, + 'y': data2}, + fetch_list=[z]) + print(z_value[0]) # [3. 8. 6.] + + +**代码示例 5(动态图)** + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + import numpy as np + + with fluid.dygraph.guard(): + np_x = np.array([2, 3, 4]).astype('float64') + np_y = np.array([1, 5, 2]).astype('float64') + x = fluid.dygraph.to_variable(np_x) + y = fluid.dygraph.to_variable(np_y) + z = paddle.add(x, y, alpha=-0.5) + np_z = z.numpy() + print(np_z) # [1.5, 0.5, 3. ] diff --git a/doc/fluid/api_cn/layers_cn/addcmul_cn.rst b/doc/fluid/api_cn/tensor_cn/addcmul_cn.rst similarity index 90% rename from doc/fluid/api_cn/layers_cn/addcmul_cn.rst rename to doc/fluid/api_cn/tensor_cn/addcmul_cn.rst index a985221e9370a2397c994d9ad7b023ed72335587..5c03e1e134f5887af72530e13bd5dee6190c8274 100644 --- a/doc/fluid/api_cn/layers_cn/addcmul_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/addcmul_cn.rst @@ -3,7 +3,7 @@ addcmul ------------------------------- -.. py:function:: paddle.fluid.layers.addcmul(input, tensor1, tensor2, value=1.0, out=None, name=None) +.. py:function:: paddle.addcmul(input, tensor1, tensor2, value=1.0, out=None, name=None) 计算tensor1和tensor2的逐元素乘积,然后将结果乘以标量value,再加到input上输出。其中input, tensor1, tensor2的维度必须是可广播的。 @@ -33,5 +33,5 @@ addcmul input = fluid.data(name='input', dtype='float32', shape=[3, 4]) tensor1 = fluid.data(name='tenosr1', dtype='float32', shape=[1, 4]) tensor2 = fluid.data(name='tensor2', dtype='float32', shape=[3, 4]) - data = fluid.layers.addcmul(input, tensor1, tensor2, value=1.0) + data = paddle.addcmul(input, tensor1, tensor2, value=1.0) diff --git a/doc/fluid/api_cn/layers_cn/addmm_cn.rst b/doc/fluid/api_cn/tensor_cn/addmm_cn.rst similarity index 100% rename from doc/fluid/api_cn/layers_cn/addmm_cn.rst rename to doc/fluid/api_cn/tensor_cn/addmm_cn.rst diff --git a/doc/fluid/api_cn/layers_cn/allclose_cn.rst b/doc/fluid/api_cn/tensor_cn/allclose_cn.rst similarity index 100% rename from doc/fluid/api_cn/layers_cn/allclose_cn.rst rename to doc/fluid/api_cn/tensor_cn/allclose_cn.rst diff --git a/doc/fluid/api_cn/layers_cn/arange_cn.rst b/doc/fluid/api_cn/tensor_cn/arange_cn.rst similarity index 88% rename from doc/fluid/api_cn/layers_cn/arange_cn.rst rename to doc/fluid/api_cn/tensor_cn/arange_cn.rst index 66092397384df5edb17302be595239eb6553ff81..e79a1fa7454762fcc8ab8025e6b18b9ab4eccf33 100644 --- a/doc/fluid/api_cn/layers_cn/arange_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/arange_cn.rst @@ -3,7 +3,7 @@ arange ------------------------------- -.. py:function:: paddle.fluid.layers.arange(start, end, step=1, dtype=None, name=None) +.. py:function:: paddle.tensor.arange(start, end, step=1, dtype=None, name=None) 该API根据step均匀分隔给定数值区间[start, end),并返回该分隔结果。 @@ -24,6 +24,6 @@ arange import paddle import paddle.fluid as fluid with fluid.dygraph.guard(): - x = fluid.layers.arange(0, 6, 2) + x = paddle.arange(0, 6, 2) # x: [0, 2, 4] # x dtype: float32 diff --git a/doc/fluid/api_cn/tensor_cn/argmax_cn.rst b/doc/fluid/api_cn/tensor_cn/argmax_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..a5bf212ec6674afd15b012ba7e2460116e195acd --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/argmax_cn.rst @@ -0,0 +1,63 @@ +.. _cn_api_tensor_argmax: + +argmax +------------------------------- + +.. py:function:: paddle.argmax(input, axis=None, dtype=None, out=None, keepdims=False, name=None) + + +该OP沿 ``axis`` 计算输入 ``input`` 的最大元素的索引。 + +参数: + - **input** (Variable) - 输入的多维 ``Tensor`` ,支持的数据类型:float32、float64、int8、int16、int32、int64。 + - **axis** (int,可选) - 指定对输入Tensor进行运算的轴, ``axis`` 的有效范围是[-R, R),R是输入 ``input`` 的Rank, ``axis`` -R与绝对值相同的R等价。默认值为0。 + - **dtype** (np.dtype|core.VarDesc.VarType|str)- 输出Tensor的数据类型,可选值为int32,int64,默认值为None,将返回int64类型的结果。 + - **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。 + - **keepdims** (bool,可选)- 是否保留进行max index操作的维度,默认值为False。 + - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回: ``Tensor`` ,数据类型int64 + +返回类型:Variable + +**代码示例**: + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + import numpy as np + + in1 = np.array([[[5,8,9,5], + [0,0,1,7], + [6,9,2,4]], + [[5,2,4,2], + [4,7,7,9], + [1,7,0,6]]]) + with fluid.dygraph.guard(): + x = fluid.dygraph.to_variable(in1) + out1 = paddle.argmax(input=x, axis=-1) + out2 = paddle.argmax(input=x, axis=0) + out3 = paddle.argmax(input=x, axis=1) + out4 = paddle.argmax(input=x, axis=2) + out5 = paddle.argmax(input=x, axis=2, keepdims=True) + print(out1.numpy()) + # [[2 3 1] + # [0 3 1]] + print(out2.numpy()) + # [[0 0 0 0] + # [1 1 1 1] + # [0 0 0 1]] + print(out3.numpy()) + # [[2 2 0 1] + # [0 1 1 1]] + print(out4.numpy()) + # [[2 3 1] + # [0 3 1]] + print(out5.numpy()) + #array([[[2], + # [3], + # [1]], + # [[0], + # [3], + # [1]]]) diff --git a/doc/fluid/api_cn/tensor_cn/atan_cn.rst b/doc/fluid/api_cn/tensor_cn/atan_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..382f6b09b17eefdb766665dd5f21857c3fda9822 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/atan_cn.rst @@ -0,0 +1,38 @@ +.. _cn_api_tensor_atan: + +atan +------------------------------- + +.. py:function:: paddle.atan(x, name=None, out=None) + +arctanh 激活函数。 + +.. math:: + out = tanh^{-1}(x) + +参数: + - **x(Variable)** - atan的输入Tensor,数据类型为 float32 或 float64 + - **name** (str|None) – 具体用法请参见 :ref:`cn_api_guide_Name` ,一般无需设置,默认值为None。 + - **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。 + +返回:返回类型为Variable(Tensor|LoDTensor), 数据类型同输入一致。 + +**代码示例**: + +.. code-block:: python + + import numpy as np + import paddle + import paddle.fluid as fluid + + inputs = fluid.layers.data(name="x", shape = [3], dtype='float32') + output = paddle.atan(inputs) + + exe = fluid.Executor(fluid.CPUPlace()) + exe.run(fluid.default_startup_program()) + + img = np.array([-0.8183, 0.4912, -0.6444, 0.0371]).astype(np.float32) + + res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output]) + print(res) + #[array([-0.6858003, 0.45658287, -0.5724284, 0.03708299], dtype=float32)] diff --git a/doc/fluid/api_cn/layers_cn/bmm_cn.rst b/doc/fluid/api_cn/tensor_cn/bmm_cn.rst similarity index 93% rename from doc/fluid/api_cn/layers_cn/bmm_cn.rst rename to doc/fluid/api_cn/tensor_cn/bmm_cn.rst index c6fbf50a18c9828c6722f8781a04ef1db8171479..330d70956cf193738a116936885e7de824fcb48f 100644 --- a/doc/fluid/api_cn/layers_cn/bmm_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/bmm_cn.rst @@ -3,7 +3,7 @@ bmm ------------------------------- -.. py:function:: paddle.fluid.layers.bmm(x, y, name=None): +.. py:function:: paddle.tensor.bmm(x, y, name=None): 对输入x及输入y进行矩阵相乘。 @@ -38,7 +38,7 @@ bmm with fluid.dygraph.guard(): x = fluid.dygraph.to_variable(input1) y = fluid.dygraph.to_variable(input2) - out = fluid.layers.bmm(x, y) + out = paddle.bmm(x, y) #output size: (2, 2, 2) #output value: #[[[6.0, 6.0],[12.0, 12.0]],[[45.0, 45.0],[60.0, 60.0]]] diff --git a/doc/fluid/api_cn/tensor_cn/cholesky_cn.rst b/doc/fluid/api_cn/tensor_cn/cholesky_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..c318bf86b40804b91304deea716292d4b34dad03 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/cholesky_cn.rst @@ -0,0 +1,3 @@ +cholesky +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/layers_cn/clamp_cn.rst b/doc/fluid/api_cn/tensor_cn/clamp_cn.rst similarity index 89% rename from doc/fluid/api_cn/layers_cn/clamp_cn.rst rename to doc/fluid/api_cn/tensor_cn/clamp_cn.rst index 8a2c42cdb74111976ef637d62604f574b9c493c7..066fb3869117f70bbc0e27e826bcc5fd90b233c4 100644 --- a/doc/fluid/api_cn/layers_cn/clamp_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/clamp_cn.rst @@ -3,7 +3,7 @@ clamp ------------------------------- -.. py:function:: paddle.fluid.layers.clamp(input, min=None, max=None, output=None, name=None) +.. py:function:: paddle.clamp(input, min=None, max=None, output=None, name=None) 该OP将输入的所有元素进行剪裁,使得输出元素限制在[min, max]内,具体公式如下: @@ -34,8 +34,8 @@ clamp [4.5,6.4]]).astype('float32') with fluid.dygraph.guard(): x1 = fluid.dygraph.to_variable(in1) - out1 = fluid.layers.clamp(x1, min=3.5, max=5.0) - out2 = fluid.layers.clamp(x1, min=2.5) + out1 = paddle.tensor.clamp(x1, min=3.5, max=5.0) + out2 = paddle.tensor.clamp(x1, min=2.5) print(out1.numpy()) # [[3.5, 3.5] # [4.5, 5.0]] diff --git a/doc/fluid/api_cn/tensor_cn/concat_cn.rst b/doc/fluid/api_cn/tensor_cn/concat_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..e439959e9f07df7ad3bcafc6269692485b9d9958 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/concat_cn.rst @@ -0,0 +1,3 @@ +concat +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/layers_cn/cross_cn.rst b/doc/fluid/api_cn/tensor_cn/cross_cn.rst similarity index 89% rename from doc/fluid/api_cn/layers_cn/cross_cn.rst rename to doc/fluid/api_cn/tensor_cn/cross_cn.rst index b2786c32ba0478cb74c6fd2be1889706253d7fcc..f8e4d6771793d1e9b1f2f2c8cbd087a0f104c292 100644 --- a/doc/fluid/api_cn/layers_cn/cross_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/cross_cn.rst @@ -3,7 +3,7 @@ cross ------------------------------- -.. py:function:: paddle.fluid.layers.cross(input, other, dim=None) +.. py:function:: paddle.cross(input, other, dim=None) 该OP返回在 ``dim`` 维度上,两个张量 ``input`` 和 ``other`` 的向量积(叉积)。 ``input`` 和 ``other`` 必须有相同的形状, 且指定的 ``dim`` 维上 ``size`` 必须为3,如果 ``dim`` 未指定,默认选取第一个 ``size`` 等于3的维度。 @@ -34,12 +34,12 @@ cross with fluid.dygraph.guard(): x = fluid.dygraph.to_variable(data_x) y = fluid.dygraph.to_variable(data_y) - out_z1 = fluid.layers.cross(x, y) + out_z1 = paddle.cross(x, y) print(out_z1.numpy()) #[[-1. -1. -1.] # [ 2. 2. 2.] # [-1. -1. -1.]] - out_z2 = fluid.layers.cross(x, y, dim=1) + out_z2 = paddle.cross(x, y, dim=1) print(out_z2.numpy()) #[[0. 0. 0.] # [0. 0. 0.] diff --git a/doc/fluid/api_cn/layers_cn/dist_cn.rst b/doc/fluid/api_cn/tensor_cn/dist_cn.rst similarity index 91% rename from doc/fluid/api_cn/layers_cn/dist_cn.rst rename to doc/fluid/api_cn/tensor_cn/dist_cn.rst index fbf5f5d08e81237a52078b46dd4cd46d39f9d9f6..1b4bb827f3ff1f73292bab1d1fcd885a70b7a8b4 100644 --- a/doc/fluid/api_cn/layers_cn/dist_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/dist_cn.rst @@ -3,7 +3,7 @@ dist ------------------------------- -.. py:function:: paddle.fluid.layers.linalg.dist(x, y, p=2) +.. py:function:: paddle.tensor.linalg.dist(x, y, p=2) 该OP用于计算 `(x-y)` 的 p 范数(p-norm),需要注意这不是严格意义上的范数,仅作为距离的度量。输入 `x` 和 `y` 的形状(shape)必须是可广播的(broadcastable)。其含义如下,详情请参考 `numpy的广播概念 `_ : @@ -65,11 +65,11 @@ z (4-D Tensor): 8 x 7 x 6 x 5 with fluid.dygraph.guard(): x = fluid.dygraph.to_variable(np.array([[3, 3],[3, 3]]).astype(np.float32)) y = fluid.dygraph.to_variable(np.array([[3, 3],[3, 1]]).astype(np.float32)) - out = fluid.layers.dist(x, y, 0) + out = paddle.dist(x, y, 0) print(out.numpy()) # out = [1.] - out = fluid.layers.dist(x, y, 2) + out = paddle.dist(x, y, 2) print(out.numpy()) # out = [2.] - out = fluid.layers.dist(x, y, float("inf")) + out = paddle.dist(x, y, float("inf")) print(out.numpy()) # out = [2.] - out = fluid.layers.dist(x, y, float("-inf")) + out = paddle.dist(x, y, float("-inf")) print(out.numpy()) # out = [0.] diff --git a/doc/fluid/api_cn/tensor_cn/div_cn.rst b/doc/fluid/api_cn/tensor_cn/div_cn.rst new file mode 100755 index 0000000000000000000000000000000000000000..e69bb84801dfaee4fd979bfd0a37c0c6769af887 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/div_cn.rst @@ -0,0 +1,154 @@ +.. _cn_api_tensor_div: + +div +------------------------------- + +.. py:function:: paddle.div(x, y, out=None, name=None) + +该OP是逐元素相除算子,输入 ``x`` 与输入 ``y`` 逐元素相除,并将各个位置的输出元素保存到返回结果中。 + +等式是: + +.. math:: + Out = X / Y + +- :math:`X` :多维Tensor。 +- :math:`Y` :维度必须小于等于X维度的Tensor。 + +对于这个运算算子有2种情况: + 1. :math:`Y` 的 ``shape`` 与 :math:`X` 相同。 + 2. :math:`Y` 的 ``shape`` 是 :math:`X` 的连续子序列。 + +对于情况2: + 1. 用 :math:`Y` 匹配 :math:`X` 的形状(shape),其中 ``axis`` 是 :math:`Y` 在 :math:`X` 上的起始维度的位置。 + 2. 如果 ``axis`` 为-1(默认值),则 :math:`axis= rank(X)-rank(Y)` 。 + 3. 考虑到子序列, :math:`Y` 的大小为1的尾部维度将被忽略,例如shape(Y)=(2,1)=>(2)。 + +例如: + +.. code-block:: text + + shape(X) = (2, 3, 4, 5), shape(Y) = (,) + shape(X) = (2, 3, 4, 5), shape(Y) = (5,) + shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5), with axis=-1(default) or axis=2 + shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1 + shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0 + shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0 + +参数: + - **x** (Variable)- 多维 ``Tensor`` 或 ``LoDTensor`` 。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64``。 + - **y** (Variable)- 多维 ``Tensor`` 或 ``LoDTensor`` 。数据类型为 ``float32`` 、 ``float64`` 、 ``int32`` 或 ``int64``。 + - **out** (Variable,可选)- 指定存储运算结果的 ``Tensor`` 。如果设置为None或者不设置,将创建新的 ``Tensor`` 存储运算结果,默认值为None。 + - **name** (str,可选)- 输出的名字。默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。 + + +返回: 多维 ``Tensor`` 或 ``LoDTensor`` , 维度和数据类型都与 ``x`` 相同。 + +返回类型: Variable + +**代码示例 1** + +.. code-block:: python + + + import paddle + import paddle.fluid as fluid + import numpy as np + + def gen_data(): + return { + "x": np.array([2, 3, 4]).astype('float32'), + "y": np.array([1, 5, 2]).astype('float32') + } + + x = fluid.data(name="x", shape=[3], dtype='float32') + y = fluid.data(name="y", shape=[3], dtype='float32') + z = paddle.div(x, y) + # z = x / y + + place = fluid.CPUPlace() + exe = fluid.Executor(place) + z_value = exe.run(feed=gen_data(), + fetch_list=[z.name]) + + print(z_value) # [2., 0.6, 2.] + + +**代码示例 2** + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + import numpy as np + + def gen_data(): + return { + "x": np.ones((2, 3, 4, 5)).astype('float32'), + "y": np.zeros((4, 5)).astype('float32') + } + + x = fluid.data(name="x", shape=[2, 3, 4, 5], dtype='float32') + y = fluid.data(name="y", shape=[4, 5], dtype='float32') + z = paddle.div(x, y, name='z') + # z = x / y + + place = fluid.CPUPlace() + exe = fluid.Executor(place) + + z_value = exe.run(feed=gen_data(), + fetch_list=[z.name]) + + print(z_value[0]) + print(z_value[0].shape) # z.shape=[2,3,4,5] + + +**代码示例 3** + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + import numpy as np + + def gen_data(): + return { + "x": np.random.randint(1, 5, size=[2, 3, 4, 5]).astype('float32'), + "y": np.random.randint(1, 5, size=[5]).astype('float32') + } + + x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32') + y = fluid.data(name="y", shape=[5], dtype='float32') + output = fluid.data(name="output", shape=[2,3,4,5], dtype="float32") + z = paddle.div(x, y, out=output) + # z = x / y + + place = fluid.CPUPlace() + exe = fluid.Executor(place) + + z_value = exe.run(feed=gen_data(), + fetch_list=[z.name]) + print(z_value[0]) + print(z_value[0].shape) # z.shape=[2,3,4,5] + + +**代码示例 4(动态图)** + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + import numpy as np + + with fluid.dygraph.guard(fluid.CPUPlace()): + np_x = np.array([2, 3, 4]).astype('float64') + np_y = np.array([1, 5, 2]).astype('float64') + x = fluid.dygraph.to_variable(np_x) + y = fluid.dygraph.to_variable(np_y) + z = paddle.div(x, y) + np_z = z.numpy() + print(np_z) # [2., 0.6, 2.] + + + + diff --git a/doc/fluid/api_cn/layers_cn/dot_cn.rst b/doc/fluid/api_cn/tensor_cn/dot_cn.rst similarity index 92% rename from doc/fluid/api_cn/layers_cn/dot_cn.rst rename to doc/fluid/api_cn/tensor_cn/dot_cn.rst index f2f01acb702da02daae68c2426e0632cee763915..37c5e3a21f3060df083c3136ec49d7472b06c7ce 100644 --- a/doc/fluid/api_cn/layers_cn/dot_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/dot_cn.rst @@ -3,7 +3,7 @@ dot ------------------------------- -.. py:function:: paddle.fluid.layers.dot(x, y, name=None) +.. py:function:: paddle.tensor.linalg.dot(x, y, name=None) 该OP计算向量的内积 @@ -31,7 +31,7 @@ dot with fluid.dygraph.guard(): x = fluid.dygraph.to_variable(np.random.uniform(0.1, 1, [10]).astype(np.float32)) y = fluid.dygraph.to_variable(np.random.uniform(1, 3, [10]).astype(np.float32)) - z = fluid.layers.dot(x, y) + z = paddle.dot(x, y) print(z.numpy()) diff --git a/doc/fluid/api_cn/tensor_cn/einsum_cn.rst b/doc/fluid/api_cn/tensor_cn/einsum_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..7ea2cdba41f1769bee383153f5969f527b0e9baa --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/einsum_cn.rst @@ -0,0 +1,3 @@ +einsum +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/layers_cn/elementwise_equal_cn.rst b/doc/fluid/api_cn/tensor_cn/elementwise_equal_cn.rst similarity index 85% rename from doc/fluid/api_cn/layers_cn/elementwise_equal_cn.rst rename to doc/fluid/api_cn/tensor_cn/elementwise_equal_cn.rst index d7228e76bb862c9a93ff555320cac2cceffe70f2..5c45f74152b32db54fe8bde10a390ba424530b6c 100644 --- a/doc/fluid/api_cn/layers_cn/elementwise_equal_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/elementwise_equal_cn.rst @@ -3,7 +3,7 @@ elementwise_equal ------------------------------- -.. py:function:: paddle.fluid.layers.elementwise_equal(x, y, name=None) +.. py:function:: paddle.elementwise_equal(x, y, name=None) 该OP返回 :math:`x==y` 逐元素比较x和y是否相等。 @@ -26,4 +26,4 @@ elementwise_equal label = fluid.layers.assign(np.array([3, 3], dtype="int32")) limit = fluid.layers.assign(np.array([3, 2], dtype="int32")) - out1 = fluid.layers.elementwise_equal(x=label, y=limit) #out1=[True, False] + out1 = paddle.elementwise_equal(x=label, y=limit) #out1=[True, False] diff --git a/doc/fluid/api_cn/tensor_cn/elementwise_sum_cn.rst b/doc/fluid/api_cn/tensor_cn/elementwise_sum_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..705d9d01f0b709f918d7d6a92c8514e153ece443 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/elementwise_sum_cn.rst @@ -0,0 +1,75 @@ +.. _cn_api_tensor_elementwise_sum: + +elementwise_sum +------------------------------- + +.. py:function:: paddle.elementwise_sum(inputs, name=None) + +该OP用于对输入的一至多个Tensor或LoDTensor求和。如果输入的是LoDTensor,输出仅与第一个输入共享LoD信息(序列信息)。 + +例1: +:: + 输入: + input.shape = [2, 3] + input = [[1, 2, 3], + [4, 5, 6]] + + 输出: + output.shape = [2, 3] + output = [[1, 2, 3], + [4, 5, 6]] + +例2: +:: + 输入: + 第一个输入: + input1.shape = [2, 3] + input1 = [[1, 2, 3], + [4, 5, 6]] + + 第二个输入: + input2.shape = [2, 3] + input2 = [[7, 8, 9], + [10, 11, 12]] + + 输出: + output.shape = [2, 3] + output = [[8, 10, 12], + [14, 16, 18]] + +参数: + - **inputs** (Variable|list(Variable)) - 输入的一至多个Variable。如果输入了多个Variable,则不同Variable间的shape和数据类型应保持一致。Variable为多维Tensor或LoDTensor,数据类型支持:float32,float64,int32,int64。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回:对输入 ``inputs`` 中的Variable求和后的结果,shape和数据类型与 ``inputs`` 一致。 + +返回类型:Variable + + +**代码示例:** + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + input0 = fluid.layers.fill_constant(shape=[2, 3], dtype='int64', value=5) + input1 = fluid.layers.fill_constant(shape=[2, 3], dtype='int64', value=3) + sum = paddle.elementwise_sum([input0, input1]) + + #用户可以通过executor打印出求和的结果 + out = fluid.layers.Print(sum, message="the sum of input0 and input1: ") + exe = fluid.Executor(fluid.CPUPlace()) + exe.run(fluid.default_main_program()) + + #打印出的数据为: + 1570701754 the sum of input0 and input1: The place is:CPUPlace + Tensor[elementwise_sum_0.tmp_0] + shape: [2,3,] + dtype: l + data: 8,8,8,8,8,8, + + #输出了shape为[2,3]的Tensor,与输入的shape一致 + #dtype为对应C++数据类型,在不同环境下可能显示值不同,但本质相同 + #例如:如果Tensor中数据类型是int64,则对应的C++数据类型为int64_t,所以dtype值为typeid(int64_t).name(), + # 其在MacOS下为'x',linux下为'l',Windows下为'__int64',都表示64位整型变量 + diff --git a/doc/fluid/api_cn/tensor_cn/equal_cn.rst b/doc/fluid/api_cn/tensor_cn/equal_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..428d1aabaa75b4e3ac02ab3ad61774f96dab40a9 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/equal_cn.rst @@ -0,0 +1,3 @@ +equal +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/tensor_cn/erf_cn.rst b/doc/fluid/api_cn/tensor_cn/erf_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..ca07a4a13cd0a231390b25f47cbc4410df6e151e --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/erf_cn.rst @@ -0,0 +1,3 @@ +erf +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/tensor_cn/eye_cn.rst b/doc/fluid/api_cn/tensor_cn/eye_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..7eca6037cb766dcacade10ce79427edb20949569 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/eye_cn.rst @@ -0,0 +1,38 @@ +.. _cn_api_paddle_tensor_eye: + +eye +------------------------------- + +.. py:function:: paddle.tensor.eye(num_rows, num_columns=None, out=None, dtype='float32', stop_gradient=True, name=None) + +该OP用来构建单位矩阵。 + +参数: + - **num_rows** (int) - 生成单位矩阵的行数,数据类型为非负int32。 + - **num_columns** (int) - 生成单位矩阵的列数,数据类型为非负int32。若为None,则默认等于num_rows。 + - **out** (Variable, 可选) - 指定算子输出结果的LoDTensor/Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。 + - **dtype** (string, 可选) - 返回张量的数据类型,可为int32,int64,float16,float32,float64。 + - **stop_gradient** (bool, 可选) - 是否对此OP停止计算梯度,默认值为False。 + - **name** (str, 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回:shape为 [num_rows, num_columns]的张量。 + +返回类型:Variable(Tensor|LoDTensor)数据类型为int32,int64,float16,float32,float64的Tensor或者LoDTensor。 + +**代码示例**: + +.. code-block:: python + + import paddle + data = paddle.eye(3, dtype='int32') # paddle.eye 等价于 paddle.tensor.eye + # [[1, 0, 0] + # [0, 1, 0] + # [0, 0, 1]] + data = paddle.eye(2, 3, dtype='int32') + # [[1, 0, 0] + # [0, 1, 0]] + + + + + diff --git a/doc/fluid/api_cn/layers_cn/flip_cn.rst b/doc/fluid/api_cn/tensor_cn/flip_cn.rst similarity index 93% rename from doc/fluid/api_cn/layers_cn/flip_cn.rst rename to doc/fluid/api_cn/tensor_cn/flip_cn.rst index bbaf71640cd6b16d72c8762c30cbc011fec43ed0..0d16bc7d6ccd6d9b17392489878fb919004cdb9e 100644 --- a/doc/fluid/api_cn/layers_cn/flip_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/flip_cn.rst @@ -3,7 +3,7 @@ flip ------------------------------- -.. py:function:: paddle.fluid.layers.flip(input, dims, name=None): +.. py:function:: paddle.flip(input, dims, name=None): 该OP沿指定轴反转n维tensor. @@ -45,6 +45,6 @@ flip img = np.arange(12).reshape((3,2,2)).astype(np.float32) with fluid.dygraph.guard(): inputs = fluid.dygraph.to_variable(img) - ret = fluid.layers.flip(inputs, [0, 1]) + ret = paddle.flip(inputs, [0, 1]) print(ret.numpy()) # [[[10,11][8, 9]],[[6, 7],[4, 5]] [[2, 3],[0, 1]]] diff --git a/doc/fluid/api_cn/layers_cn/full_cn.rst b/doc/fluid/api_cn/tensor_cn/full_cn.rst similarity index 100% rename from doc/fluid/api_cn/layers_cn/full_cn.rst rename to doc/fluid/api_cn/tensor_cn/full_cn.rst diff --git a/doc/fluid/api_cn/layers_cn/full_like_cn.rst b/doc/fluid/api_cn/tensor_cn/full_like_cn.rst similarity index 91% rename from doc/fluid/api_cn/layers_cn/full_like_cn.rst rename to doc/fluid/api_cn/tensor_cn/full_like_cn.rst index 0d02b9b74f4e633161fc4a7a57c5e79da6ce5997..2fb1309fd8869ac22e343aa5641d47cd2fcafa0f 100644 --- a/doc/fluid/api_cn/layers_cn/full_like_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/full_like_cn.rst @@ -3,7 +3,7 @@ full_like ------------------------------- -.. py:function:: paddle.fluid.layers.full_like(input, fill_value, out=None, dtype=None, device=None, stop_gradient=True, name=None) +.. py:function:: paddle.full_like(input, fill_value, out=None, dtype=None, device=None, stop_gradient=True, name=None) 该OP创建一个和input具有相同的形状和数据类型的Tensor,其中元素值均为fill_value。 @@ -28,7 +28,7 @@ full_like import paddle.fluid as fluid import numpy as np input = fluid.data(name='input', dtype='float32', shape=[2, 3]) - output = fluid.layers..full_like(input, 2.0) + output = paddle.full_like(input, 2.0) exe = fluid.Executor(fluid.CPUPlace()) exe.run(fluid.default_startup_program()) img=np.array([[1, 2, 3], [4, 5, 6]]).astype(np.float32) diff --git a/doc/fluid/api_cn/tensor_cn/gather_cn.rst b/doc/fluid/api_cn/tensor_cn/gather_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..430dd7ac8bfccd997acb1686d15bcdfe5a9e9fb5 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/gather_cn.rst @@ -0,0 +1,35 @@ +.. _cn_api_paddle_tensor_gather +gather +------------------------------- + +.. py:function:: paddle.tensor.gather(input, index, overwrite=True) + +根据索引 index 获取输入(input)的最外层维度的条目,并将它们拼接在一起。 + +.. math:: + + Out=X[Index] + +**参数**: + - **input** (Variable) - 输入, 秩 ``rank >= 1`` , 支持的数据类型包括 int32、int64、float32、float64 和 uint8 (CPU)、float16(GPU) 。 + - **index** (Variable) - 索引,秩 ``rank = 1``, 数据类型为 int32 或 int64。 + - **overwrite** (bool) - 具有相同索引时在反向更新梯度的模式。如果为 ``True`` ,则使用覆盖模式更新相同索引的梯度;如果为 ``False`` ,则使用累积模式更新相同索引的梯度。默认值为 ``True`` 。 + +**返回**:和输入的秩相同的输出张量。 + +**返回类型**:Variable + +**代码示例**: + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + import numpy as np + with fluid.dygraph.guard(): + input_1 = np.array([[1,2,3],[4,5,6],[7,8,9]]) + index_1 = np.array([0,1]) + input = fluid.dygraph.to_variable(input_1) + index = fluid.dygraph.to_variable(index_1) + output = paddle.fluid.layers.gather(input, index) + # expected output: [[1, 2, 3],[4, 5, 6]] diff --git a/doc/fluid/api_cn/layers_cn/index_select_cn.rst b/doc/fluid/api_cn/tensor_cn/index_select_cn.rst similarity index 88% rename from doc/fluid/api_cn/layers_cn/index_select_cn.rst rename to doc/fluid/api_cn/tensor_cn/index_select_cn.rst index 1b581b6e4f560741c2c6967ab48283802efc2383..61883ac082fc3cd43c7a1fc553849b8d2472c5e3 100644 --- a/doc/fluid/api_cn/layers_cn/index_select_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/index_select_cn.rst @@ -3,7 +3,7 @@ index_select ------------------------------- -.. py:function:: paddle.fluid.layers.index_select(input, index, dim=0) +.. py:function:: paddle.index_select(input, index, dim=0) 该OP沿着指定维度 ``dim`` 对输入 ``input`` 进行索引,取 ``index`` 中指定的相应项,然后返回到一个新的张量。这里 ``index`` 是一个 ``1-D`` 张量。除 ``dim`` 维外,返回的张量其余维度大小同输入 ``input`` , ``dim`` 维大小等于 ``index`` 的大小。 @@ -31,12 +31,12 @@ index_select with fluid.dygraph.guard(): x = fluid.dygraph.to_variable(data) index = fluid.dygraph.to_variable(data_index) - out_z1 = fluid.layers.index_select(x, index) + out_z1 = paddle.index_select(x, index) print(out_z1.numpy()) #[[1. 2. 3. 4.] # [5. 6. 7. 8.] # [5. 6. 7. 8.]] - out_z2 = fluid.layers.index_select(x, index, dim=1) + out_z2 = paddle.index_select(x, index, dim=1) print(out_z2.numpy()) #[[ 1. 2. 2.] # [ 5. 6. 6.] diff --git a/doc/fluid/api_cn/tensor_cn/inverse_cn.rst b/doc/fluid/api_cn/tensor_cn/inverse_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..ca3442242922ea75def0c9fc9c5f2ffe85ebbd45 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/inverse_cn.rst @@ -0,0 +1,3 @@ +inverse +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/tensor_cn/isnan_cn.rst b/doc/fluid/api_cn/tensor_cn/isnan_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..2f22289cc74472058687a5ace267fc7ff66ebe00 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/isnan_cn.rst @@ -0,0 +1,3 @@ +isnan +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/layers_cn/kron_cn.rst b/doc/fluid/api_cn/tensor_cn/kron_cn.rst similarity index 95% rename from doc/fluid/api_cn/layers_cn/kron_cn.rst rename to doc/fluid/api_cn/tensor_cn/kron_cn.rst index fb5129e2d4b8fdb08ea906494268ed3b56a25972..375bb480419fd2b9ad2bd90c487a479988272843 100644 --- a/doc/fluid/api_cn/layers_cn/kron_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/kron_cn.rst @@ -3,7 +3,7 @@ kron ------------------------------- -.. py:function:: paddle.fluid.layers.kron(x, y, out=None, name=None) +.. py:function:: paddle.tensor.kron(x, y, out=None, name=None) Kronecker Product 算子。 @@ -61,7 +61,7 @@ Kronecker Product 算子。 with dg.guard(place): a_var = dg.to_variable(a) b_var = dg.to_variable(b) - c_var = fluid.layers.kron(a_var, b_var) + c_var = paddle.kron(a_var, b_var) c_np = c_var.numpy() print(c_np) diff --git a/doc/fluid/api_cn/tensor_cn/linspace_cn.rst b/doc/fluid/api_cn/tensor_cn/linspace_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..62f4bd6bd70859819935e20a13972fc580872b6f --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/linspace_cn.rst @@ -0,0 +1,3 @@ +linspace +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/layers_cn/log1p_cn.rst b/doc/fluid/api_cn/tensor_cn/log1p_cn.rst similarity index 90% rename from doc/fluid/api_cn/layers_cn/log1p_cn.rst rename to doc/fluid/api_cn/tensor_cn/log1p_cn.rst index 282c3d018941e4a9d7e335678cb821331d046a57..32be102c8ac8017e6a20075e4f3da5f0e5c5f06a 100644 --- a/doc/fluid/api_cn/layers_cn/log1p_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/log1p_cn.rst @@ -3,7 +3,7 @@ log1p ------------------------------- -.. py:function:: paddle.fluid.layers.log1p(x, out=None, name=None) +.. py:function:: paddle.tensor.log1p(x, out=None, name=None) 该OP计算Log1p(加一的自然对数)结果。 @@ -31,7 +31,7 @@ log1p import numpy as np x = fluid.data(name="x", shape=[2,1], dtype="float32") - res = fluid.layers.log1p(x) + res = paddle.log1p(x) # paddle.log1p等价于 paddle.tensor.log1p # 举例选择CPU计算环境 exe = fluid.Executor(fluid.CPUPlace()) diff --git a/doc/fluid/api_cn/layers_cn/logsumexp_cn.rst b/doc/fluid/api_cn/tensor_cn/logsumexp_cn.rst similarity index 86% rename from doc/fluid/api_cn/layers_cn/logsumexp_cn.rst rename to doc/fluid/api_cn/tensor_cn/logsumexp_cn.rst index 83d65a08f9ee546d955c376523141afbff300fb2..2ee70212ebcaded751e74ffb3c6b92f99735f9e1 100644 --- a/doc/fluid/api_cn/layers_cn/logsumexp_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/logsumexp_cn.rst @@ -3,7 +3,7 @@ logsumexp ------------------------------- -.. py:function:: paddle.fluid.layers.logsumexp(x, dim=None, keepdim=False, out=None, name=None) +.. py:function:: paddle.tensor.math.logsumexp(x, dim=None, keepdim=False, out=None, name=None) 该OP对输入Tensor的元素以e为底做指数运算,然后根据指定维度做求和之后取自然对数 @@ -32,7 +32,7 @@ logsumexp with fluid.dygraph.guard(): np_x = np.random.uniform(0.1, 1, [10]).astype(np.float32) x = fluid.dygraph.to_variable(np_x) - print(fluid.layers.logsumexp(x).numpy()) + print(paddle.logsumexp(x).numpy()) **代码示例2** @@ -45,5 +45,5 @@ logsumexp with fluid.dygraph.guard(): np_x = np.random.uniform(0.1, 1, [2, 3, 4]).astype(np.float32) x = fluid.dygraph.to_variable(np_x) - print(fluid.layers.logsumexp(x, dim=1).numpy()) - print(fluid.layers.logsumexp(x, dim=[0, 2]).numpy()) + print(paddle.logsumexp(x, dim=1).numpy()) + print(paddle.logsumexp(x, dim=[0, 2]).numpy()) diff --git a/doc/fluid/api_cn/tensor_cn/math_cn.rst b/doc/fluid/api_cn/tensor_cn/math_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..d16bb3003b2ae0b2aa4fe65255a045fc4a1f420a --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/math_cn.rst @@ -0,0 +1,3 @@ +math +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/tensor_cn/matmul_cn.rst b/doc/fluid/api_cn/tensor_cn/matmul_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..80abf76a37e6a946d709188ff2739ca59b5998c3 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/matmul_cn.rst @@ -0,0 +1,3 @@ +matmul +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/tensor_cn/max_cn.rst b/doc/fluid/api_cn/tensor_cn/max_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..b1023bf6c00767a9d02fc49cf770b64e3be02779 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/max_cn.rst @@ -0,0 +1,54 @@ + +.. _cn_api_paddle_tensor_max: + +max +------------------------------- + +.. py:function:: paddle.tensor.max(input, dim=None, keep_dim=False, out=None, name=None) + +该OP是对指定维度上的Tensor元素求最大值运算,并输出相应的计算结果。等价于 :ref:`cn_api_fluid_layers_reduce_max` + +参数: + - **input** (Variable)- 输入变量为多维Tensor或LoDTensor,支持数据类型为float32,float64,int32,int64。 + - **dim** (list | int ,可选)- 求最大值运算的维度。如果为None,则计算所有元素的最大值并返回包含单个元素的Tensor变量,否则必须在 :math:`[−rank(input),rank(input)]` 范围内。如果 :math:`dim [i] <0` ,则维度将变为 :math:`rank+dim[i]` ,默认值为None。 + - **keep_dim** (bool)- 是否在输出Tensor中保留减小的维度。如 keep_dim 为true,否则结果张量的维度将比输入张量小,默认值为False。 + - **out** (Variable, 可选) - 指定算子输出结果的LoDTensor/Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。 + - **name** (str, 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回: 在指定dim上进行求最大值运算的Tensor,数据类型和输入数据类型一致。 + +返回类型: 变量(Variable) + +**代码示例** + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + # x是一个Tensor,元素如下: + # [[0.2, 0.3, 0.5, 0.9] + # [0.1, 0.2, 0.6, 0.7]] + # 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。 + x = fluid.data(name='x', shape=[2, 4], dtype='float32') + # paddle.max 等价于 paddle.tensor.max + paddle.max(x) # [0.9] + paddle.max(x, dim=0) # [0.2, 0.3, 0.6, 0.9] + paddle.max(x, dim=-1) # [0.9, 0.7] + paddle.max(x, dim=1, keep_dim=True) # [[0.9], [0.7]] + + # y是一个shape为[2, 2, 2]的Tensor,元素如下: + # [[[1.0, 2.0], [3.0, 4.0]], + # [[5.0, 6.0], [7.0, 8.0]]] + # 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。 + y = fluid.data(name='y', shape=[2, 2, 2], dtype='float32') + paddle.max(y, dim=[1, 2]) # [4.0, 8.0] + paddle.max(y, dim=[0, 1]) # [7.0, 8.0] + + + + + + + + + diff --git a/doc/fluid/api_cn/layers_cn/meshgrid_cn.rst b/doc/fluid/api_cn/tensor_cn/meshgrid_cn.rst similarity index 100% rename from doc/fluid/api_cn/layers_cn/meshgrid_cn.rst rename to doc/fluid/api_cn/tensor_cn/meshgrid_cn.rst diff --git a/doc/fluid/api_cn/tensor_cn/min_cn.rst b/doc/fluid/api_cn/tensor_cn/min_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..b7b8838ff9be4473437d8d5d521bb2cd4e9ce805 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/min_cn.rst @@ -0,0 +1,53 @@ +.. _cn_api_paddle_tensor_min: + +min +------------------------------- + +.. py:function:: paddle.tensor.min(input, dim=None, keep_dim=False, out=None, name=None) + +该OP是对指定维度上的Tensor元素求最小值运算,并输出相应的计算结果。等价于 :ref:`cn_api_fluid_layers_reduce_min` + +参数: + - **input** (Variable)- 输入变量为多维Tensor或LoDTensor,支持数据类型为float32,float64,int32,int64。 + - **dim** (list | int ,可选)- 求最小值运算的维度。如果为None,则计算所有元素的最小值并返回包含单个元素的Tensor变量,否则必须在 :math:`[−rank(input),rank(input)]` 范围内。如果 :math:`dim [i] <0` ,则维度将变为 :math:`rank+dim[i]` ,默认值为None。 + - **keep_dim** (bool)- 是否在输出Tensor中保留减小的维度。如 keep_dim 为true,否则结果张量的维度将比输入张量小,默认值为False。 + - **out** (Variable, 可选) - 指定算子输出结果的LoDTensor/Tensor,可以是程序中已经创建的任何Variable。默认值为None,此时将创建新的Variable来保存输出结果。 + - **name** (str, 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回: 在指定dim上进行求最小值运算的Tensor,数据类型和输入数据类型一致。 + +返回类型: 变量(Variable) + +**代码示例** + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + # x是一个Tensor,元素如下: + # [[0.2, 0.3, 0.5, 0.9] + # [0.1, 0.2, 0.6, 0.7]] + # 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。 + x = fluid.data(name='x', shape=[2, 4], dtype='float32') + # paddle.min 等价于 paddle.tensor.min + paddle.min(x) # [0.1] + paddle.min(x, dim=0) # [0.1, 0.2, 0.5, 0.7] + paddle.min(x, dim=-1) # [0.2, 0.1] + paddle.min(x, dim=1, keep_dim=True) # [[0.2], [0.1]] + + # y是一个shape为[2, 2, 2]的Tensor,元素如下: + # [[[1.0, 2.0], [3.0, 4.0]], + # [[5.0, 6.0], [7.0, 8.0]]] + # 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。 + y = fluid.data(name='y', shape=[2, 2, 2], dtype='float32') + paddle.min(y, dim=[1, 2]) # [1.0, 5.0] + paddle.min(y, dim=[0, 1]) # [1.0, 2.0] + + + + + + + + + diff --git a/doc/fluid/api_cn/tensor_cn/mm_cn.rst b/doc/fluid/api_cn/tensor_cn/mm_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..3f32a20a2efe5797ce3c6857797872a98cee7347 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/mm_cn.rst @@ -0,0 +1,74 @@ +.. _cn_api_tensor_mm: + +mm +------------------------------- + +.. py:function:: paddle.mm(input, mat2, out=None, name=None) + +用于两个输入矩阵的相乘。 + +两个输入的形状可为任意维度,但当任一输入维度大于3时,两个输入的维度必须相等。 + +如果原始 Tensor input 或 mat2 的秩为 1 且未转置,则矩阵相乘后的前置或附加维度 1 将移除。 + +参数: + - **input** (Variable) : 输入变量,类型为 Tensor 或 LoDTensor。 + - **mat2** (Variable) : 输入变量,类型为 Tensor 或 LoDTensor。 + - **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回: + - Variable (Tensor / LoDTensor),矩阵相乘后的结果。 + +返回类型: + - Variable(变量)。 + +:: + + * 例 1: + + input: [B, ..., M, K], mat2: [B, ..., K, N] + out: [B, ..., M, N] + + * 例 2: + + input: [B, M, K], mat2: [B, K, N] + out: [B, M, N] + + * 例 3: + + input: [B, M, K], mat2: [K, N] + out: [B, M, N] + + * 例 4: + + input: [M, K], mat2: [K, N] + out: [M, N] + + * 例 5: + + input: [B, M, K], mat2: [K] + out: [B, M] + + * 例 6: + + input: [K], mat2: [K] + out: [1] + + * 例 7: + + input: [M], mat2: [N] + out: [M, N] + + +**代码示例**: + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + + input = fluid.data(name='input', shape=[2, 3], dtype='float32') + mat2 = fluid.data(name='mat2', shape=[3, 2], dtype='float32') + out = paddle.mm(input, mat2) # out shape is [2, 2] + diff --git a/doc/fluid/api_cn/tensor_cn/mul_cn.rst b/doc/fluid/api_cn/tensor_cn/mul_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..00c305590a018bbfdac250fb755685326faa531c --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/mul_cn.rst @@ -0,0 +1,45 @@ +.. _cn_api_tensor_argmax: + +mul +------------------------------- + +.. py:function:: paddle.mul(x, y, x_num_col_dims=1, y_num_col_dims=1, out=None, name=None) + + +mul算子 +此运算是用于对输入x和y执行矩阵乘法。 +公式是: + +.. math:: + out = x * y + +输入x和y都可以携带LoD(详细程度)信息。但输出仅与输入x共享LoD信息。 + +参数: + - **x** (Variable) - 乘法运算的第一个输入张量Tensor/LoDTensor。 + - **y** (Variable) - 乘法运算的第二个输入张量Tensor/LoDTensor。 + - **x_num_col_dims** (int,可选) - 默认值1, 可以将具有两个以上维度的张量作为输入。如果输入x是具有多于两个维度的张量,则输入x将先展平为二维矩阵。展平规则是:前 ``num_col_dims`` 将被展平成最终矩阵的第一个维度(矩阵的高度),其余的 rank(x) - num_col_dims 维度被展平成最终矩阵的第二个维度(矩阵的宽度)。结果是展平矩阵的高度等于x的前 ``x_num_col_dims`` 维数的乘积,展平矩阵的宽度等于x的最后一个 rank(x)- ``num_col_dims`` 个剩余维度的维数的乘积。例如,假设x是一个5-D张量,形状为(2,3,4,5,6),并且 ``x_num_col_dims`` 的值为3。 则扁平化后的张量具有的形即为(2x3x4,5x6)=(24,30)。 + - **y_num_col_dims** (int,可选) - 默认值1, 可以将具有两个以上维度的张量作为输入。如果输入y是具有多于两个维度的张量,则y将首先展平为二维矩阵。 ``y_num_col_dims`` 属性确定y的展平方式。有关更多详细信息,请参阅 ``x_num_col_dims`` 的注释。 + - **out** (Variable, 可选) - 默认值None,如果out不为空,则矩阵乘法运算结果存储在out变量中。 + - **name** (str,可选) - 默认值None,输出的名称。该参数供开发人员打印调试信息时使用,具体用法参见 :ref:`api_guide_name`。当out和name同时不为空时,结果输出变量名与out保持一致。 + +返回:Variable(Tensor)乘法运算输出张量。 + +返回类型:变量(Variable)。 + +**代码示例** + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + dataX = fluid.data(name="dataX", shape=[2, 5], dtype="float32") + dataY = fluid.data(name="dataY", shape=[5, 3], dtype="float32") + + res = fluid.data(name="output", shape=[2, 3], dtype="float32") + output = paddle.mul(dataX, dataY, + x_num_col_dims = 1, + y_num_col_dims = 1, + out=res) + + diff --git a/doc/fluid/api_cn/layers_cn/nonzero_cn.rst b/doc/fluid/api_cn/tensor_cn/nonzero_cn.rst similarity index 83% rename from doc/fluid/api_cn/layers_cn/nonzero_cn.rst rename to doc/fluid/api_cn/tensor_cn/nonzero_cn.rst index 27c5ec992e8bbbfc52d6db11ec1ab30f11341753..8a4be36cd00a4c09923843e2e0f517dac00bf886 100644 --- a/doc/fluid/api_cn/layers_cn/nonzero_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/nonzero_cn.rst @@ -3,7 +3,7 @@ nonzero ------------------------------- -.. py:function:: paddle.fluid.layers.nonzero(input, as_tuple=False) +.. py:function:: paddle.nonzero(input, as_tuple=False) 该OP返回输入 ``input`` 中非零元素的坐标。如果输入 ``input`` 有 ``n`` 维,共包含 ``z`` 个非零元素,当 ``as_tuple = False`` 时, 返回结果是一个 ``shape`` 等于 ``[z x n]`` 的 ``Tensor`` , 第 ``i`` 行代表输入中第 ``i`` 个非零元素的坐标;当 ``as_tuple = True`` 时, @@ -33,12 +33,12 @@ nonzero x1 = fluid.dygraph.to_variable(data1) x2 = fluid.dygraph.to_variable(data2) x3 = fluid.dygraph.to_variable(data3) - out_z1 = fluid.layers.nonzero(x1) + out_z1 = paddle.nonzero(x1) print(out_z1.numpy()) #[[0 0] # [1 1] # [2 2]] - out_z1_tuple = fluid.layers.nonzero(x1, as_tuple=True) + out_z1_tuple = paddle.nonzero(x1, as_tuple=True) for out in out_z1_tuple: print(out.numpy()) #[[0] @@ -47,19 +47,19 @@ nonzero #[[0] # [1] # [2]] - out_z2 = fluid.layers.nonzero(x2) + out_z2 = paddle.nonzero(x2) print(out_z2.numpy()) #[[1] # [3]] - out_z2_tuple = fluid.layers.nonzero(x2, as_tuple=True) + out_z2_tuple = paddle.nonzero(x2, as_tuple=True) for out in out_z2_tuple: print(out.numpy()) #[[1] # [3]] - out_z3 = fluid.layers.nonzero(x3) + out_z3 = paddle.nonzero(x3) print(out_z3.numpy()) #[] - out_z3_tuple = fluid.layers.nonzero(x3, as_tuple=True) + out_z3_tuple = paddle.nonzero(x3, as_tuple=True) for out in out_z3_tuple: print(out.numpy()) #[] diff --git a/doc/fluid/api_cn/tensor_cn/norm_cn.rst b/doc/fluid/api_cn/tensor_cn/norm_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..10c2254c6ed752abdce2947293fcdaaefd54bf8a --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/norm_cn.rst @@ -0,0 +1,38 @@ +.. _cn_api_tensor_norm: + +norm +------------------------------- + +.. py:function:: paddle.norm(input, p='fro', axis=None, keepdim=False, out=None, name=None): + +该OP将计算给定Tensor的矩阵范数(Frobenius 范数)和向量范数(向量1范数、2范数、或者通常的p范数). + +参数: + - **input** (Variable) - 输入Tensor。维度为多维,数据类型为float32或float64。 + - **p** (float|string, 可选) - 范数的种类。目前支持的值为 `fro`、 `1`、 `2`,和任何正实数p对应的p范数。 + - **axis** (int|list, 可选) - 使用范数计算的轴。如果 ``axis`` 为int或者只有一个元素的list,``norm`` API会计算输入Tensor的向量范数。如果axis为包含两个元素的list,API会计算输入Tensor的矩阵范数。 当 ``axis < 0`` 时,实际的计算维度为 rank(input) + axis。 + - **keepdim** (bool,可选) - 是否在输出的Tensor中保留和输入一样的维度,默认值为False。当 :attr:`keepdim` 为False时,输出的Tensor会比输入 :attr:`input` 的维度少一些。 + - **out** (Variable,可选) - 指定输出的Tensor,默认值为None。out的数据类型必须与输入 ``input`` 一致。 + - **name** (str|None) - 该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。默认值为None。 + + 返回:在指定axis上进行范数计算的Tensor,与输入input数据类型相同。 + + 返回类型:Variable,与输入input数据类型相同。 + +抛出异常: + - ``TypeError`` - 当输出 ``out`` 和输入 ``input`` 数据类型不一致时候。 + - ``ValueError`` - 当参数 ``p`` 或者 ``axis`` 不合法时。 + +**代码示例**: + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + x = fluid.data(name='x', shape=[2, 3, 5], dtype='float64') + + # compute frobenius norm along last two dimensions. + out_fro = paddle.norm(x, p='fro', axis=[1,2]) + + # compute 2-order vector norm along last dimension. + out_pnorm = paddle.norm(x, p=2, axis=-1) diff --git a/doc/fluid/api_cn/tensor_cn/ones_cn.rst b/doc/fluid/api_cn/tensor_cn/ones_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..86bfc73ea43be7a0e9c8af836ad23695505628e0 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/ones_cn.rst @@ -0,0 +1,28 @@ +.. _cn_api_tensor_ones: + +ones +------------------------------- + +.. py:function:: paddle.ones(shape, dtype, out=None, device=None) + + +该OP创建形状为 ``shape`` 、数据类型为 ``dtype`` 且值全为1的Tensor。 + +参数: + - **shape** (tuple|list) - 输出Tensor的形状。 + - **dtype** (np.dtype|core.VarDesc.VarType|str) - 输出Tensor的数据类型,数据类型必须为float16、float32、float64、int32或int64。 + - **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。 + - **device** (str,可选) – 选择在哪个设备运行该操作,可选值包括None,'cpu'和'gpu'。如果 ``device`` 为None,则将选择运行Paddle程序的设备,默认为None。 + +返回:值全为1的Tensor,数据类型和 ``dtype`` 定义的类型一致。 + +返回类型:Variable + +**代码示例**: + +.. code-block:: python + + import paddle + data = paddle.ones(shape=[3, 2], dtype='float32') # [[1., 1.], [1., 1.], [1., 1.]] + data = paddle.ones(shape=[2, 2], dtype='float32', device='cpu') # [[1., 1.], [1., 0.]] + diff --git a/doc/fluid/api_cn/tensor_cn/ones_like_cn.rst b/doc/fluid/api_cn/tensor_cn/ones_like_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..f373a61f1f3dde872af85c3c431d3252b27e5676 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/ones_like_cn.rst @@ -0,0 +1,29 @@ +.. _cn_api_tensor_ones_like: + +ones_like +------------------------------- + +.. py:function:: paddle.ones_like(input, dtype=None, device=None, name=None) + + +该OP创建一个和input具有相同的形状和数据类型的全1Tensor。 + +参数: + - **input** (Variable) – 指定输入为一个多维的Tensor,数据类型可以是bool,float32,float64,int32,int64。 + - **dtype** (np.dtype|core.VarDesc.VarType|str, 可选)- 输出变量的数据类型。若参数为空,则输出变量的数据类型和输入变量相同,默认值为None。 + - **device** (str,可选) – 选择在哪个设备运行该操作,可选值包括None,'cpu'和'gpu'。如果 ``device`` 为None,则将选择运行Paddle程序的设备,默认为None。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回:返回一个存储结果的Tensor。 + +返回类型:Variable + +**代码示例**: + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + x = fluid.data(name='x', dtype='float32', shape=[3]) + data = paddle.ones_like(x) # data=[1.0, 1.0, 1.0] + data1 = paddle.ones_like(input=x, device="gpu") # data1=[1.0, 1.0. 1.0] diff --git a/doc/fluid/api_cn/tensor_cn/pow_cn.rst b/doc/fluid/api_cn/tensor_cn/pow_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..8a354bff543c75d5d8fd6d0e8dcd510daa3f9aa9 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/pow_cn.rst @@ -0,0 +1,41 @@ +.. _cn_api_tensor_argmax: + +pow +------------------------------- + +.. py:function:: paddle.pow(input, exponent, out=None, name=None): + +该OP是指数激活算子: + +.. math:: + out = x^{exponent} + +参数: + - **x** (Variable)- 多维 ``Tensor`` 或 ``LoDTensor`` ,数据类型为 ``float32`` 或 ``float64`` 。 + - **exponent** (float32|Variable,可选)- ``float32`` 或形状为[1]的 ``Tensor`` 或 ``LoDTensor``,数据类型为 ``float32``。Pow OP的指数因子。默认值:1.0。 + - **out** (Variable, 可选) - 默认值None,如果out不为空,则该运算结果存储在out变量中。 + - **name** (str,可选) - 默认值None,输出的名称。该参数供开发人员打印调试信息时使用,具体用法参见 :ref:`api_guide_name`。当out和name同时不为空时,结果输出变量名与out保持一致。 + +返回:维度与输入 `x` 相同的 ``Tensor`` 或 ``LoDTensor``,数据类型与 ``x`` 相同。 + +返回类型:Variable。 + + +**代码示例:** + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + x = fluid.data(name="x", shape=[32,32], dtype="float32") + + # 示例1: 参数exponent是个浮点数 + res = fluid.data(name="output", shape=[32,32], dtype="float32") + y_1 = paddle.pow(x, 2.0, out=res) + # y_1 is x^{2.0} + + # 示例2: 参数exponent是个变量 + exponent_tensor = fluid.layers.fill_constant([1], "float32", 3.0) + res = fluid.data(name="output", shape=[32,32], dtype="float32") + y_2 = paddle.pow(x, exponent_tensor, out=res) + # y_2 is x^{3.0} \ No newline at end of file diff --git a/doc/fluid/api_cn/tensor_cn/rand_cn.rst b/doc/fluid/api_cn/tensor_cn/rand_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..b1c5e32b1a5779506d4f962463f561e890b15211 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/rand_cn.rst @@ -0,0 +1,3 @@ +rand +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/tensor_cn/randint_cn.rst b/doc/fluid/api_cn/tensor_cn/randint_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..c12490bfdaf2f4ed246b99361f871caa42266f34 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/randint_cn.rst @@ -0,0 +1,3 @@ +randint +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/layers_cn/randn_cn.rst b/doc/fluid/api_cn/tensor_cn/randn_cn.rst similarity index 91% rename from doc/fluid/api_cn/layers_cn/randn_cn.rst rename to doc/fluid/api_cn/tensor_cn/randn_cn.rst index 9a6a8633e1f6e7d428668a76b3ef973f6f3b97f0..d7faca9d0747380f7bdf226dbe95ff77df99c42f 100644 --- a/doc/fluid/api_cn/layers_cn/randn_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/randn_cn.rst @@ -3,7 +3,7 @@ randn ------------------------------- -.. py:function:: paddle.fluid.layers.randn(shape, out=None, dtype=None, device=None, stop_gradient=True, name=None) +.. py:function:: paddle.tensor.random.randn(shape, out=None, dtype=None, device=None, stop_gradient=True, name=None) 该 API 用于生成数据符合标准正态随机分布(均值为 0,方差为 1 的正态随机分布)的 Tensor。 @@ -26,7 +26,7 @@ randn # declarative mode import paddle import paddle.fluid as fluid - data = fluid.layers.randn([2, 4]) + data = paddle.randn([2, 4]) place = fluid.CPUPlace() exe = fluid.Executor(place) res, = exe.run(fluid.default_main_program(), feed={}, fetch_list=[data]) @@ -42,7 +42,7 @@ randn import paddle.fluid.dygraph as dg place = fluid.CPUPlace() with dg.guard(place) as g: - x = fluid.layers.randn([2, 4]) + x = paddle.randn([2, 4]) x_np = x.numpy() print(x_np) # [[ 1.5149173 -0.26234224 -0.592486 1.4523455 ] diff --git a/doc/fluid/api_cn/layers_cn/randperm_cn.rst b/doc/fluid/api_cn/tensor_cn/randperm_cn.rst similarity index 84% rename from doc/fluid/api_cn/layers_cn/randperm_cn.rst rename to doc/fluid/api_cn/tensor_cn/randperm_cn.rst index 1caa51914d382c60df1dd6edac48389c8191c894..baaae52c55a21179f1e05e40cb3bf727de257b3b 100644 --- a/doc/fluid/api_cn/layers_cn/randperm_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/randperm_cn.rst @@ -3,7 +3,7 @@ randperm ------------------------------- -.. py:function:: paddle.fluid.layers.randperm(n, out=None, dtype="int64", device=None, stop_gradient=True, seed=0) +.. py:function:: paddle.tensor.random.randperm(n, out=None, dtype="int64", device=None, stop_gradient=True, seed=0) 该OP返回一个数值在0到n-1、顺序随机的整数排列。 @@ -31,16 +31,16 @@ randperm # the random seed in computer, so the output in the next example # will be change. with fluid.dygraph.guard(): - out_1 = fluid.layers.randperm(6) + out_1 = paddle.randperm(6) print(out_1.numpy()) # Random permutation, for example [2 4 5 0 3 1] out_2 = fluid.dygraph.to_variable( np.array([0, 1, 2, 3])).astype(np.int64) - fluid.layers.randperm(6, out_2) + paddle.randperm(6, out_2) print(out_2.numpy()) # Random permutation, for example [5 0 2 4 1 3] - out_3 = fluid.layers.randperm(6, dtype="int32", device="cpu") + out_3 = paddle.randperm(6, dtype="int32", device="cpu") print(out_3.numpy()) # Random permutation, for example [3 1 4 2 5 0] - out_4 = fluid.layers.randperm(6, device="cpu", stop_gradient=True) + out_4 = paddle.randperm(6, device="cpu", stop_gradient=True) print(out_4.numpy()) # Random permutation, for example [3 1 5 2 0 4] diff --git a/doc/fluid/api_cn/layers_cn/roll_cn.rst b/doc/fluid/api_cn/tensor_cn/roll_cn.rst similarity index 88% rename from doc/fluid/api_cn/layers_cn/roll_cn.rst rename to doc/fluid/api_cn/tensor_cn/roll_cn.rst index 258c0c9e91b0e9eb9a675b0249daf97a77f4c225..9998b68522f168b53825827c6df407fb9a2ee770 100644 --- a/doc/fluid/api_cn/layers_cn/roll_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/roll_cn.rst @@ -3,7 +3,7 @@ roll ------------------------------- -.. py:function:: paddle.fluid.layers.roll(input, shifts, dims=None): +.. py:function:: paddle.roll(input, shifts, dims=None): 该OP沿着指定维度对输入 ``input`` 进行循环滚动,当元素移动到最后位置时,会从第一个位置重新插入。如果 ``dims`` 为 ``None`` ,则输入在被循环滚动之前,会先展平成 ``1-D Tensor`` ,滚动操作完成后恢复成原来的形状。 @@ -28,12 +28,12 @@ roll [7.0, 8.0, 9.0]]) with fluid.dygraph.guard(): x = fluid.dygraph.to_variable(data) - out_z1 = fluid.layers.roll(x, shifts=1) + out_z1 = paddle.roll(x, shifts=1) print(out_z1.numpy()) #[[9. 1. 2.] # [3. 4. 5.] # [6. 7. 8.]] - out_z2 = fluid.layers.roll(x, shifts=1, dims=0) + out_z2 = paddle.roll(x, shifts=1, dims=0) print(out_z2.numpy()) #[[7. 8. 9.] # [1. 2. 3.] diff --git a/doc/fluid/api_cn/tensor_cn/sin_cn.rst b/doc/fluid/api_cn/tensor_cn/sin_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..7a94b3fbdfa5bb508807b6c9c70222d272e31cf1 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/sin_cn.rst @@ -0,0 +1,38 @@ +.. _cn_api_tensor_sin: + +sin +------------------------------- + +.. py:function:: paddle.sin(x, name=None, out=None) + +计算输入的正弦值。 + +.. math:: + out = sin(x) + +参数: + - **x** (Variable) - 支持任意维度的Tensor。数据类型为float32,float64或float16。 + - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + - **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。 + +返回:返回类型为Variable(Tensor|LoDTensor), 数据类型同输入一致。 + +**代码示例**: + +.. code-block:: python + + import numpy as np + import paddle + import paddle.fluid as fluid + + inputs = fluid.layers.data(name="x", shape = [3], dtype='float32') + output = paddle.sin(inputs) + + exe = fluid.Executor(fluid.CPUPlace()) + exe.run(fluid.default_startup_program()) + + img = np.array([0, 45, 90]).astype(np.float32) + + res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output]) + print(res) + # [array([0. , 0.8509035 , 0.89399666], dtype=float32)] diff --git a/doc/fluid/api_cn/tensor_cn/sort_cn.rst b/doc/fluid/api_cn/tensor_cn/sort_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..52bb75ec975ae81fdd578a028474ce13bc15a21e --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/sort_cn.rst @@ -0,0 +1,69 @@ +.. _cn_api_tensor_sort: + +sort +------------------------------- + +.. py:function:: paddle.sort(input, axis=-1, descending=False, out=None, name=None) + +对输入变量沿给定轴进行排序,输出排序好的数据和相应的索引,其维度和输入相同。**默认升序排列,如果需要降序排列设置** ``descending=True`` 。 + + +参数: + - **input** (Variable) - 输入的多维 ``Tensor`` ,支持的数据类型:float32、float64、int16、int32、int64、uint8。 + - **axis** (int,可选) - 指定对输入Tensor进行运算的轴, ``axis`` 的有效范围是[-R, R),R是输入 ``x`` 的Rank, ``axis`` 为负时与 ``axis`` +R 等价。默认值为0。 + - **descending** (bool,可选) - 指定算法排序的方向。如果设置为True,算法按照降序排序。如果设置为False或者不设置,按照升序排序。默认值为False。 + - **out** (Variable, 可选) – 指定存储运算结果的Tensor(与 ``input`` 维度相同、数据类型相同)。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。 + - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回:一组已排序的输出(与 ``input`` 维度相同、数据类型相同)和索引(数据类型为int64)。 + +返回类型:tuple[Variable] + +**代码示例**: + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + import numpy as np + + in1 = np.array([[[5,8,9,5], + [0,0,1,7], + [6,9,2,4]], + [[5,2,4,2], + [4,7,7,9], + [1,7,0,6]]]).astype(np.float32) + with fluid.dygraph.guard(): + x = fluid.dygraph.to_variable(in1) + out1 = paddle.sort(input=x, axis=-1) # same as axis==2 + out2 = paddle.sort(input=x, axis=0) + out3 = paddle.sort(input=x, axis=1) + print(out1[0].numpy()) + # [[[5. 5. 8. 9.] + # [0. 0. 1. 7.] + # [2. 4. 6. 9.]] + # [[2. 2. 4. 5.] + # [4. 7. 7. 9.] + # [0. 1. 6. 7.]]] + print(out1[1].numpy()) + # [[[0 3 1 2] + # [0 1 2 3] + # [2 3 0 1]] + # [[1 3 2 0] + # [0 1 2 3] + # [2 0 3 1]]] + print(out2[0].numpy()) + # [[[5. 2. 4. 2.] + # [0. 0. 1. 7.] + # [1. 7. 0. 4.]] + # [[5. 8. 9. 5.] + # [4. 7. 7. 9.] + # [6. 9. 2. 6.]]] + print(out3[0].numpy()) + # [[[0. 0. 1. 4.] + # [5. 8. 2. 5.] + # [6. 9. 9. 7.]] + # [[1. 2. 0. 2.] + # [4. 7. 4. 6.] + # [5. 7. 7. 9.]]] + diff --git a/doc/fluid/api_cn/tensor_cn/split_cn.rst b/doc/fluid/api_cn/tensor_cn/split_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..a225766036eee6b917f0a14978b9de37407f35ea --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/split_cn.rst @@ -0,0 +1,34 @@ +.. _cn_api_paddle_tensor_split +split +------------------------------- + +.. py:function:: paddle.tensor.split(input, num_or_sections, dim=-1, name=None) + +该OP将输入Tensor分割成多个子Tensor。 + +**参数**: + - **input** (Variable) - 输入变量,数据类型为float32,float64,int32,int64的多维Tensor或者LoDTensor。 + - **num_or_sections** (int|list|tuple) - 如果 num_or_sections 是一个整数,则表示Tensor平均划分为相同大小子Tensor的数量。如果 num_or_sections 是一个list或tuple,那么它的长度代表子Tensor的数量,它的元素可以是整数或者形状为[1]的Tensor,依次代表子Tensor需要分割成的维度的大小。list或tuple的长度不能超过输入Tensor待分割的维度的大小。在list或tuple中,至多有一个元素值为-1,表示该值是由input的维度和其他num_or_sections中元素推断出来的。例如对一个维度为[4,6,6]Tensor的第三维进行分割时,指定num_or_sections=[2,-1,1],输出的三个Tensor维度分别为:[4,6,2],[4,6,3],[4,6,1]。 + - **dim** (int|Variable,可选) - 整数或者形状为[1]的Tensor,数据类型为int32或int64。表示需要分割的维度。如果dim < 0,则划分的维度为rank(input) + dim。默认值为-1。 + - **name** (str,可选) - 一般无需设置,默认值为None。 + +**返回**:分割后的Tensor列表。 + +**返回类型**:列表(Variable(Tensor|LoDTensor)),数据类型为int32,int64,float32,float64。 + +**代码示例**: + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + import numpy as np + with fluid.dygraph.guard(): + input_1 = np.random.random([4, 6, 6]).astype("int32") + # input is a variable which shape is [4, 6, 6] + input = fluid.dygraph.to_variable(input_1) + + x0, x1, x2 = paddle.split(input, num_or_sections= 3, dim=1) + # x0.shape [4, 2, 6] + # x1.shape [4, 2, 6] + # x2.shape [4, 2, 6] diff --git a/doc/fluid/api_cn/tensor_cn/sqrt_cn.rst b/doc/fluid/api_cn/tensor_cn/sqrt_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..b8a5a2b9391072b669dc7d7e79ca975665a0a6ac --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/sqrt_cn.rst @@ -0,0 +1,42 @@ +.. _cn_api_tensor_sqrt: + +sqrt +------------------------------- + +.. py:function:: paddle.sqrt(x, name=None, out=None) + +计算输入的算数平方根。 + +.. math:: + out=\sqrt x=x^{1/2} + +.. note:: + 请确保输入中的数值是非负数。 + +参数: + + - **x** (Variable) - 支持任意维度的Tensor。数据类型为float32,float64或float16。 + - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + - **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。 + +返回:返回类型为Variable(Tensor|LoDTensor), 数据类型同输入一致。 + +**代码示例**: + +.. code-block:: python + + import numpy as np + import paddle + import paddle.fluid as fluid + + inputs = fluid.layers.data(name="x", shape = [3], dtype='float32') + output = paddle.sqrt(inputs) + + exe = fluid.Executor(fluid.CPUPlace()) + exe.run(fluid.default_startup_program()) + + img = np.array([0, 9, 36]).astype(np.float32) + + res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output]) + print(res) + # [array([0., 3., 6.], dtype=float32)] diff --git a/doc/fluid/api_cn/tensor_cn/squeeze_cn.rst b/doc/fluid/api_cn/tensor_cn/squeeze_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..795cf298a0dbec5314e44e751fea283c202578a3 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/squeeze_cn.rst @@ -0,0 +1,31 @@ +.. _cn_api_paddle_tensor_squeeze +squeeze +------------------------------- + +.. py:function:: paddle.tensor.squeeze(input, zxes, name=None) + +该OP会根据axes压缩输入Tensor的维度。如果指定了axes,则会删除axes中指定的维度,axes指定的维度要等于1。如果没有指定axes,那么所有等于1的维度都会被删除。 + +**参数**: + - **input** (Variable) - 输入任意维度的Tensor。 支持的数据类型:float32,float64,int8,int32,int64。 + - **axes** (list) - 输入一个或一列整数,代表要压缩的轴。axes的范围: [−rank(input),rank(input))] 。 axes为负数时, axes=axes+rank(input) 。 + - **name** (str,可选) - 一般无需设置,默认值为None。 + +**返回**:返回对维度进行压缩后的Tensor。数据类型与输入Tensor一致。 + +**返回类型**:Variable + +**代码示例**: + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + import numpy as np + with fluid.dygraph.guard(): + input_1 = np.random.random([5, 1, 10]).astype("int32") + # input is a variable which shape is [5, 1, 10] + input = fluid.dygraph.to_variable(input_1) + + output = paddle.fluid.layers.squeeze(input, axes=[1]) + # output.shape [5, 10] diff --git a/doc/fluid/api_cn/tensor_cn/stack_cn.rst b/doc/fluid/api_cn/tensor_cn/stack_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..0351b65a4af7a74bc94dd5abf615e2c14729c204 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/stack_cn.rst @@ -0,0 +1,36 @@ +.. _cn_api_paddle_tensor_arange +stack +------------------------------- + +.. py:function:: paddle.tensor.stack(x, axis=0) + +该OP沿 axis 轴对输入 x 进行堆叠操作。 + +**参数**: + - **x** (Variable|list(Variable)) – 输入 x 可以是单个Tensor,或是多个Tensor组成的列表。如果 x 是一个列表,那么这些Tensor的维度必须相同。 假设输入是N维Tensor [d0,d1,...,dn−1],则输出变量的维度为N+1维 [d0,d1,...daxis−1,len(x),daxis...,dn−1] 。支持的数据类型: float32,float64,int32,int64。 + + - **axis** (int, 可选) – 指定对输入Tensor进行堆叠运算的轴,有效 axis 的范围是: [−(R+1),R+1)],R是输入中第一个Tensor的rank。如果 axis < 0,则 axis=axis+rank(x[0])+1 。axis默认值为0。 + +**返回**:堆叠运算后的Tensor,数据类型与输入Tensor相同。输出维度等于 rank(x[0])+1 维。 + +**返回类型**:Variable + +**代码示例**: + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + import numpy as np + data1 = np.array([[1.0, 2.0,3.0]]) + data2 = np.array([[3.0, 4.0, 5.0]]) + data3 = np.array([[5.0, 6.0,7.0]]) + with fluid.dygraph.guard(): + x1 = fluid.dygraph.to_variable(data1) + x2 = fluid.dygraph.to_variable(data2) + x3 = fluid.dygraph.to_variable(data3) + result = paddle.stack([x1, x2, x3], axis=2) + # result shape: [3, 1, 2] + # result value: [[[1.0, 2.0]], + # [[3.0, 4.0]], + # [[5.0, 6.0]]] diff --git a/doc/fluid/api_cn/tensor_cn/std_cn.rst b/doc/fluid/api_cn/tensor_cn/std_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..46b22e08e5f45541d5b73ef21645d71eabeb21a0 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/std_cn.rst @@ -0,0 +1,3 @@ +std +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/tensor_cn/sum_cn.rst b/doc/fluid/api_cn/tensor_cn/sum_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..7b7f576282085c8dc10a53a0999cf58d7bf5a04f --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/sum_cn.rst @@ -0,0 +1,43 @@ +.. _cn_api_tensor_sum: + +sum +------------------------------- + +.. py:function:: paddle.sum(input, dim=None, dtype=None, keep_dim=False, name=None) + +该OP是对指定维度上的Tensor元素进行求和运算,并输出相应的计算结果。 + +参数: + - **input** (Variable)- 输入变量为多维Tensor或LoDTensor,支持数据类型为float32,float64,int32,int64。 + - **dim** (list | int ,可选)- 求和运算的维度。如果为None,则计算所有元素的和并返回包含单个元素的Tensor变量,否则必须在 :math:`[−rank(input),rank(input)]` 范围内。如果 :math:`dim [i] <0` ,则维度将变为 :math:`rank+dim[i]` ,默认值为None。 + - **dtype** (str , 可选)- 输出变量的数据类型。若参数为空,则输出变量的数据类型和输入变量相同,默认值为None。 + - **keep_dim** (bool)- 是否在输出Tensor中保留减小的维度。如 keep_dim 为true,否则结果张量的维度将比输入张量小,默认值为False。 + - **name** (str , 可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回: 在指定dim上进行求和运算的Tensor,数据类型和输入数据类型一致。 + +返回类型: 变量(Variable) + +**代码示例** + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + # x是一个Tensor,元素如下: + # [[0.2, 0.3, 0.5, 0.9] + # [0.1, 0.2, 0.6, 0.7]] + # 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。 + x = fluid.data(name='x', shape=[2, 4], dtype='float32') + out1 = paddle.sum(x) # [3.5] + out2 = paddle.sum(x, dim=0) # [0.3, 0.5, 1.1, 1.6] + out3 = paddle.sum(x, dim=-1) # [1.9, 1.6] + out4 = paddle.sum(x, dim=1, keep_dim=True) # [[1.9], [1.6]] + + # y 是一个shape为[2, 2, 2]的Tensor元素如下: + # [[[1, 2], [3, 4]], + # [[5, 6], [7, 8]]] + # 接下来的示例中,我们在每处函数调用后面都标注出了它的结果张量。 + y = fluid.data(name='y', shape=[2, 2, 2], dtype='float32') + out5 = paddle.sum(y, dim=[1, 2]) # [10, 26] + out6 = paddle.sum(y, dim=[0, 1]) # [16, 20] diff --git a/doc/fluid/api_cn/layers_cn/t_cn.rst b/doc/fluid/api_cn/tensor_cn/t_cn.rst similarity index 80% rename from doc/fluid/api_cn/layers_cn/t_cn.rst rename to doc/fluid/api_cn/tensor_cn/t_cn.rst index 051a1144c0b25ccd13e2f3f0ac99a9a111b6b900..4625ef7063422069f13e35153579c90edc37522d 100644 --- a/doc/fluid/api_cn/layers_cn/t_cn.rst +++ b/doc/fluid/api_cn/tensor_cn/t_cn.rst @@ -3,7 +3,7 @@ t ------------------------------- -.. py:function:: paddle.fluid.layers.t(input, name=None) +.. py:function:: paddle.tensor.t(input, name=None) 该OP对小于等于2维的Tensor进行数据转置。0维和1维Tensor返回本身,2维Tensor等价于perm设置为0,1的 :ref:`cn_api_fluid_layers_transpose` 函数。 @@ -21,16 +21,16 @@ t # 例1 (0-D tensor) x = tensor([0.79]) - fluid.layers.t(x) = tensor([0.79]) + paddle.t(x) = tensor([0.79]) # 例2 (1-D tensor) x = tensor([0.79, 0.84, 0.32]) - fluid.layers.t(x) = tensor([0.79, 0.84, 0.32]) + paddle.t(x) = tensor([0.79, 0.84, 0.32]) # 例3 (2-D tensor) x = tensor([0.79, 0.84, 0.32], [0.64, 0.14, 0.57]) - fluid.layers.t(x) = tensor([0.79, 0.64], + paddle.t(x) = tensor([0.79, 0.64], [0.84, 0.14], [0.32, 0.57]) @@ -42,7 +42,7 @@ t import paddle import paddle.fluid as fluid x = fluid.data(name='x', shape=[2, 3], dtype='float32') - x_transposed = fluid.layers.t(x) # paddle.t 等价于 paddle.tensor.t + x_transposed = paddle.t(x) # paddle.t 等价于 paddle.tensor.t print(x_transposed.shape) #(3L, 2L) diff --git a/doc/fluid/api_cn/tensor_cn/tanh_cn.rst b/doc/fluid/api_cn/tensor_cn/tanh_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..c36b1200aa76596c3a8b5bf007301b4b38d4f400 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/tanh_cn.rst @@ -0,0 +1,40 @@ +.. _cn_api_tensor_tanh: + +tanh +------------------------------- + +.. py:function:: paddle.tanh(x, name=None, out=None) + +tanh 激活函数 + +.. math:: + out = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}} + + +参数: + + - **x** (Variable) - 支持任意维度的Tensor。数据类型为float32,float64或float16。 + - **name** (str,可选) – 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + - **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。 + +返回:返回类型为Variable(Tensor|LoDTensor), 数据类型同输入一致。 + +**代码示例**: + +.. code-block:: python + + import numpy as np + import paddle + import paddle.fluid as fluid + + inputs = fluid.layers.data(name="x", shape = [3], dtype='float32') + output = paddle.tanh(inputs) + + exe = fluid.Executor(fluid.CPUPlace()) + exe.run(fluid.default_startup_program()) + + img = np.array([0, 0.5, 0.3]).astype(np.float32) + + res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output]) + print(res) + # [array([0., 0.46211717, 0.2913126], dtype=float32)] diff --git a/doc/fluid/api_cn/tensor_cn/tensordot_cn.rst b/doc/fluid/api_cn/tensor_cn/tensordot_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..c6fc45ede4fe40099f5b3a0e1876728c1ad92f6b --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/tensordot_cn.rst @@ -0,0 +1,3 @@ +tensordot +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/tensor_cn/transpose_cn.rst b/doc/fluid/api_cn/tensor_cn/transpose_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..7ade0a6924cb2857cac0104137db82c026753cf9 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/transpose_cn.rst @@ -0,0 +1,3 @@ +transpose +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/layers_cn/tril_cn.rst b/doc/fluid/api_cn/tensor_cn/tril_cn.rst similarity index 100% rename from doc/fluid/api_cn/layers_cn/tril_cn.rst rename to doc/fluid/api_cn/tensor_cn/tril_cn.rst diff --git a/doc/fluid/api_cn/layers_cn/triu_cn.rst b/doc/fluid/api_cn/tensor_cn/triu_cn.rst similarity index 100% rename from doc/fluid/api_cn/layers_cn/triu_cn.rst rename to doc/fluid/api_cn/tensor_cn/triu_cn.rst diff --git a/doc/fluid/api_cn/tensor_cn/unbind_cn.rst b/doc/fluid/api_cn/tensor_cn/unbind_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..c5b287c1fa0aa71b2af1e5569587b474131cba9a --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/unbind_cn.rst @@ -0,0 +1,3 @@ +unbind +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/tensor_cn/unsqueeze_cn.rst b/doc/fluid/api_cn/tensor_cn/unsqueeze_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..6b1face4840a3f167fa8a2c48c443201f57d49c3 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/unsqueeze_cn.rst @@ -0,0 +1,31 @@ +.. _cn_api_paddle_tensor_unsqueeze +unsqueeze +------------------------------- + +.. py:function:: paddle.tensor.unsqueeze(input, axes, name=None) + +该OP向输入(input)的shape中一个或多个位置(axes)插入维度。 + +**参数**: + - **input** (Variable)- 多维 Tensor,数据类型为 float32, float64, int8, int32,或 int64。 + - **axes** (int|list|tuple|Variable) - 表示要插入维度的位置。数据类型是 int32 。如果 axes 的类型是 list 或 tuple,它的元素可以是整数或者形状为[1]的 Tensor 。如果 axes 的类型是 Variable,则是1-D Tensor。 + - **name** (str,可选)- 一般无需设置。默认值: None。 + +**返回**:扩展维度后的多维Tensor + +**返回类型**:Variable + +**代码示例**: + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + import numpy as np + with fluid.dygraph.guard(): + input_1 = np.random.random([5, 10]).astype("int32") + # input is a variable which shape is [5, 1, 10] + input = fluid.dygraph.to_variable(input_1) + + output = paddle.unsqueeze(input, axes=[1]) + # output.shape [5, 1, 10] diff --git a/doc/fluid/api_cn/tensor_cn/var_cn.rst b/doc/fluid/api_cn/tensor_cn/var_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..93c13b558843a982cb13806355840c0ab6066c7f --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/var_cn.rst @@ -0,0 +1,3 @@ +var +------------------------------- +**版本升级,文档正在开发中** diff --git a/doc/fluid/api_cn/tensor_cn/zeros_cn.rst b/doc/fluid/api_cn/tensor_cn/zeros_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..681d45fe5605cebfe2edf423ac171e4de7faac67 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/zeros_cn.rst @@ -0,0 +1,27 @@ +.. _cn_api_tensor_zeros: + +zeros +------------------------------- + +.. py:function:: paddle.zeros(shape, dtype, out=None, device=None) + +该OP创建形状为 ``shape`` 、数据类型为 ``dtype`` 且值全为0的Tensor。 + +参数: + - **shape** (tuple|list) - 输出Tensor的形状。 + - **dtype** (np.dtype|core.VarDesc.VarType|str) - 输出Tensor的数据类型,数据类型必须为float16、float32、float64、int32或int64。 + - **out** (Variable, 可选) – 指定存储运算结果的Tensor。如果设置为None或者不设置,将创建新的Tensor存储运算结果,默认值为None。 + - **device** (str,可选) – 选择在哪个设备运行该操作,可选值包括None,'cpu'和'gpu'。如果 ``device`` 为None,则将选择运行Paddle程序的设备,默认为None。 + +返回:值全为0的Tensor,数据类型和 ``dtype`` 定义的类型一致。 + +返回类型:Variable + +**代码示例**: + +.. code-block:: python + + import paddle + data = paddle.zeros(shape=[3, 2], dtype='float32') # [[0., 0.], [0., 0.], [0., 0.]] + data = paddle.zeros(shape=[2, 2], dtype='float32', device='cpu') # [[0., 0.], [0., 0.]] + diff --git a/doc/fluid/api_cn/tensor_cn/zeros_like_cn.rst b/doc/fluid/api_cn/tensor_cn/zeros_like_cn.rst new file mode 100644 index 0000000000000000000000000000000000000000..babee57d21cf954efa5ec50d272c85de177c30c9 --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/zeros_like_cn.rst @@ -0,0 +1,29 @@ +.. _cn_api_tensor_zeros_like: + +zeros_like +------------------------------- + +.. py:function:: paddle.zeros_like(input, dtype=None, device=None, name=None) + + +该OP创建一个和input具有相同的形状和数据类型的全零Tensor。 + +参数: + - **input** (Variable) – 指定输入为一个多维的Tensor,数据类型可以是bool,float32,float64,int32,int64。 + - **dtype** (np.dtype|core.VarDesc.VarType|str, 可选)- 输出变量的数据类型。若参数为空,则输出变量的数据类型和输入变量相同,默认值为None。 + - **device** (str,可选) – 选择在哪个设备运行该操作,可选值包括None,'cpu'和'gpu'。如果 ``device`` 为None,则将选择运行Paddle程序的设备,默认为None。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回:返回一个存储结果的Tensor。 + +返回类型:Variable + +**代码示例**: + +.. code-block:: python + + import paddle + import paddle.fluid as fluid + x = fluid.data(name='x', dtype='float32', shape=[3]) + data1 = paddle.ones_like(input=x, device="gpu") # data1=[1.0, 1.0. 1.0] +