From 4b1bc6815e81b8370ce373b58fb4db1affdec029 Mon Sep 17 00:00:00 2001 From: hedaoyuan Date: Tue, 1 Aug 2017 11:45:49 +0800 Subject: [PATCH] Fix comments of slice_projection, and add unit test of SliceProjection. --- paddle/gserver/tests/test_LayerGrad.cpp | 20 +++++++++++++++++++ .../paddle/trainer_config_helpers/layers.py | 6 +++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/paddle/gserver/tests/test_LayerGrad.cpp b/paddle/gserver/tests/test_LayerGrad.cpp index 0975c3bc9..00ca4982e 100644 --- a/paddle/gserver/tests/test_LayerGrad.cpp +++ b/paddle/gserver/tests/test_LayerGrad.cpp @@ -152,6 +152,26 @@ TEST(Projection, identity) { } } +TEST(Projection, slice) { + ProjectionConfig conf; + conf.set_type("slice"); + conf.set_input_size(100); + SliceConfig& slice1 = *conf.add_slices(); + slice1.set_start(10); + slice1.set_end(20); + SliceConfig& slice2 = *conf.add_slices(); + slice2.set_start(50); + slice2.set_end(70); + conf.set_output_size(30); + for (auto useGpu : {false, true}) { + testProjectionGrad(conf, + INPUT_DATA, + /* parameterSize */ 0, + /* batchSize */ 100, + useGpu); + } +} + TEST(Projection, scaling) { ProjectionConfig conf; conf.set_type("scaling"); diff --git a/python/paddle/trainer_config_helpers/layers.py b/python/paddle/trainer_config_helpers/layers.py index d1c2cecc6..204523352 100755 --- a/python/paddle/trainer_config_helpers/layers.py +++ b/python/paddle/trainer_config_helpers/layers.py @@ -539,11 +539,11 @@ def identity_projection(input, offset=None, size=None): def slice_projection(input, slices): """ - slice_projection can get multiple outputs, and each output is a slice - of the input. + slice_projection can slice the input value into multiple parts, + and then select some of them to merge into a new output. .. math:: - output[i] = input.slice(slices[i]) + output = [input.slices()] The example usage is: -- GitLab