Skip to content

Commit ed808f5

Browse files
authored
Merge pull request #1251 from reyoung/feature/add_override_to_layer_init
Using override keyword in Layer
2 parents b9dfe8e + e7419d6 commit ed808f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+369
-300
lines changed

paddle/gserver/gradientmachines/RecurrentGradientMachine.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ class BootBiasLayer : public Layer {
155155
public:
156156
explicit BootBiasLayer(const LayerConfig& config) : Layer(config) {}
157157

158-
bool init(const LayerMap& layerMap, const ParameterMap& parameterMap) {
158+
bool init(const LayerMap& layerMap,
159+
const ParameterMap& parameterMap) override {
159160
if (!Layer::init(layerMap, parameterMap)) return false;
160161

161162
if (biasParameter_) {
@@ -174,15 +175,15 @@ class BootBiasLayer : public Layer {
174175
}
175176
}
176177

177-
virtual void forward(PassType passType) {
178+
void forward(PassType passType) override {
178179
if (biases_) {
179180
MatrixPtr outV = getOutputValue();
180181
outV->addBias(*(biases_->getW()), 1);
181182
forwardActivation();
182183
}
183184
}
184185

185-
virtual void backward(const UpdateCallback& callback) {
186+
void backward(const UpdateCallback& callback) override {
186187
if (biases_) {
187188
backwardActivation();
188189
biases_->getWGrad()->collectBias(*getOutputGrad(), 1);

paddle/gserver/layers/AddtoLayer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,20 @@ class AddtoLayer : public Layer {
4444
/**
4545
* Intialization of AddtoLayer.
4646
*/
47-
bool init(const LayerMap& layerMap, const ParameterMap& parameterMap);
47+
bool init(const LayerMap& layerMap,
48+
const ParameterMap& parameterMap) override;
4849

4950
/**
5051
* Forward propagation.
5152
* @note There is no weight matrix for each input,
5253
* because it just a simple add operation.
5354
*/
54-
void forward(PassType passType);
55+
void forward(PassType passType) override;
5556

5657
/**
5758
* Backward propagation.
5859
*/
59-
void backward(const UpdateCallback& callback = nullptr);
60+
void backward(const UpdateCallback& callback = nullptr) override;
6061
};
6162

6263
} // namespace paddle

paddle/gserver/layers/AgentLayer.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class AgentLayer : public Layer {
3535

3636
~AgentLayer() {}
3737

38-
bool init(const LayerMap& layerMap, const ParameterMap& parameterMap);
38+
bool init(const LayerMap& layerMap,
39+
const ParameterMap& parameterMap) override;
3940

4041
// if *numSamples* set,
4142
// real layer output will only use first *numSamples* rows
@@ -44,8 +45,8 @@ class AgentLayer : public Layer {
4445
numSamples_ = numSamples;
4546
}
4647

47-
void forward(PassType passType);
48-
void backward(const UpdateCallback& callback = nullptr) {}
48+
void forward(PassType passType) override;
49+
void backward(const UpdateCallback& callback = nullptr) override {}
4950
};
5051

5152
/**
@@ -56,8 +57,8 @@ class SequenceAgentLayer : public AgentLayer {
5657
explicit SequenceAgentLayer(const LayerConfig& config) : AgentLayer(config) {}
5758
~SequenceAgentLayer() {}
5859

59-
void forward(PassType passType);
60-
void backward(const UpdateCallback& callback = nullptr) {}
60+
void forward(PassType passType) override;
61+
void backward(const UpdateCallback& callback = nullptr) override {}
6162
};
6263

6364
/**
@@ -78,7 +79,8 @@ class GatherAgentLayer : public Layer {
7879

7980
virtual ~GatherAgentLayer() {}
8081

81-
bool init(const LayerMap& layerMap, const ParameterMap& parameterMap);
82+
bool init(const LayerMap& layerMap,
83+
const ParameterMap& parameterMap) override;
8284

8385
// call before addRealLayer
8486
void copyIdAndSequenceInfo(const Argument& input,
@@ -88,8 +90,8 @@ class GatherAgentLayer : public Layer {
8890
// add one real layer, can call many times
8991
void addRealLayer(LayerPtr layer) { realLayers_.push_back(layer); }
9092

91-
void forward(PassType passType);
92-
void backward(const UpdateCallback& callback);
93+
void forward(PassType passType) override;
94+
void backward(const UpdateCallback& callback) override;
9395
};
9496

9597
/**
@@ -133,7 +135,8 @@ class ScatterAgentLayer : public Layer {
133135

134136
virtual ~ScatterAgentLayer() {}
135137

136-
bool init(const LayerMap& layerMap, const ParameterMap& parameterMap);
138+
bool init(const LayerMap& layerMap,
139+
const ParameterMap& parameterMap) override;
137140

138141
/**
139142
* @brief set real layer in generation
@@ -182,8 +185,8 @@ class ScatterAgentLayer : public Layer {
182185
numSequences_ = numSequences;
183186
}
184187

185-
void forward(PassType passType);
186-
void backward(const UpdateCallback& callback);
188+
void forward(PassType passType) override;
189+
void backward(const UpdateCallback& callback) override;
187190
};
188191

189192
/**

paddle/gserver/layers/AverageLayer.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ class AverageLayer : public SequencePoolLayer {
3838
explicit AverageLayer(const LayerConfig& config)
3939
: SequencePoolLayer(config) {}
4040

41-
~AverageLayer() {}
41+
bool init(const LayerMap& layerMap,
42+
const ParameterMap& parameterMap) override;
4243

43-
bool init(const LayerMap& layerMap, const ParameterMap& parameterMap);
44-
45-
void forward(PassType passType);
46-
void backward(const UpdateCallback& callback = nullptr);
44+
void forward(PassType passType) override;
45+
void backward(const UpdateCallback& callback = nullptr) override;
4746

4847
protected:
4948
MatrixPtr outMtx_;

paddle/gserver/layers/BatchNormBaseLayer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class BatchNormBaseLayer : public Layer {
5252
*/
5353
static Layer* create(const LayerConfig& config);
5454

55-
virtual bool init(const LayerMap& layerMap, const ParameterMap& parameterMap);
55+
bool init(const LayerMap& layerMap,
56+
const ParameterMap& parameterMap) override;
5657

5758
/**
5859
* @brief Calculate feature map size. Some input uses frameHeight and

paddle/gserver/layers/BatchNormalizationLayer.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ class BatchNormalizationLayer : public BatchNormBaseLayer {
3333

3434
~BatchNormalizationLayer() {}
3535

36-
bool init(const LayerMap& layerMap, const ParameterMap& parameterMap);
37-
void forward(PassType passType);
38-
void backward(const UpdateCallback& callback = nullptr);
36+
bool init(const LayerMap& layerMap,
37+
const ParameterMap& parameterMap) override;
38+
void forward(PassType passType) override;
39+
void backward(const UpdateCallback& callback = nullptr) override;
3940

4041
protected:
4142
/// Epsilon value used in the batch normalization formula.
@@ -58,7 +59,7 @@ class BatchNormalizationLayer : public BatchNormBaseLayer {
5859
/// to batch, channels* imagePixels.
5960
void shrinkMat(const MatrixPtr& in, MatrixPtr& out);
6061

61-
void onPassEnd() { firstTest_ = true; }
62+
void onPassEnd() override { firstTest_ = true; }
6263

6364
MatrixPtr tmpMat_, tmpGrad_;
6465
MatrixPtr expandedIn_, expandedOut_;

paddle/gserver/layers/BilinearInterpLayer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ class BilinearInterpLayer : public Layer {
3838
virtual ~BilinearInterpLayer() {}
3939

4040
size_t getSize();
41-
bool init(const LayerMap& layerMap, const ParameterMap& parameterMap);
42-
void forward(PassType passType);
43-
void backward(const UpdateCallback& callback = nullptr);
41+
bool init(const LayerMap& layerMap,
42+
const ParameterMap& parameterMap) override;
43+
void forward(PassType passType) override;
44+
void backward(const UpdateCallback& callback = nullptr) override;
4445
};
4546

4647
} // namespace paddle

paddle/gserver/layers/BlockExpandLayer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ class BlockExpandLayer : public Layer {
5858

5959
~BlockExpandLayer() {}
6060

61-
virtual bool init(const LayerMap& layerMap, const ParameterMap& parameterMap);
61+
bool init(const LayerMap& layerMap,
62+
const ParameterMap& parameterMap) override;
6263

63-
virtual void forward(PassType passType);
64-
virtual void backward(const UpdateCallback& callback = nullptr);
64+
void forward(PassType passType) override;
65+
void backward(const UpdateCallback& callback = nullptr) override;
6566
};
6667

6768
} // namespace paddle

paddle/gserver/layers/CRFDecodingLayer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ namespace paddle {
3232
class CRFDecodingLayer : public CRFLayer {
3333
public:
3434
explicit CRFDecodingLayer(const LayerConfig& config) : CRFLayer(config) {}
35-
virtual bool init(const LayerMap& layerMap, const ParameterMap& parameterMap);
36-
virtual void forward(PassType passType);
37-
virtual void backward(const UpdateCallback& callback);
35+
bool init(const LayerMap& layerMap,
36+
const ParameterMap& parameterMap) override;
37+
void forward(PassType passType) override;
38+
void backward(const UpdateCallback& callback) override;
3839

3940
protected:
4041
std::unique_ptr<LinearChainCRF> crf_;

paddle/gserver/layers/CRFLayer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ namespace paddle {
2929
class CRFLayer : public Layer {
3030
public:
3131
explicit CRFLayer(const LayerConfig& config) : Layer(config) {}
32-
virtual bool init(const LayerMap& layerMap, const ParameterMap& parameterMap);
33-
virtual void forward(PassType passType);
34-
virtual void backward(const UpdateCallback& callback);
32+
bool init(const LayerMap& layerMap,
33+
const ParameterMap& parameterMap) override;
34+
void forward(PassType passType) override;
35+
void backward(const UpdateCallback& callback) override;
3536

3637
protected:
3738
size_t numClasses_;

0 commit comments

Comments
 (0)