Skip to content

Commit

Permalink
Merge pull request #1534 from UniQP/override
Browse files Browse the repository at this point in the history
Add missing override specifiers
  • Loading branch information
zdenop authored Apr 28, 2018
2 parents 938bba3 + 4ac3063 commit 45bb942
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 60 deletions.
31 changes: 15 additions & 16 deletions src/lstm/fullyconnected.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class FullyConnected : public Network {

// Returns the shape output from the network given an input shape (which may
// be partially unknown ie zero).
virtual StaticShape OutputShape(const StaticShape& input_shape) const;
StaticShape OutputShape(const StaticShape& input_shape) const override;

virtual STRING spec() const {
STRING spec() const override {
STRING spec;
if (type_ == NT_TANH)
spec.add_str_int("Ft", no_);
Expand Down Expand Up @@ -63,31 +63,31 @@ class FullyConnected : public Network {

// Suspends/Enables training by setting the training_ flag. Serialize and
// DeSerialize only operate on the run-time data if state is false.
virtual void SetEnableTraining(TrainingState state);
void SetEnableTraining(TrainingState state) override;

// Sets up the network for training. Initializes weights using weights of
// scale `range` picked according to the random number generator `randomizer`.
virtual int InitWeights(float range, TRand* randomizer);
int InitWeights(float range, TRand* randomizer) override;
// Recursively searches the network for softmaxes with old_no outputs,
// and remaps their outputs according to code_map. See network.h for details.
int RemapOutputs(int old_no, const std::vector<int>& code_map) override;

// Converts a float network to an int network.
virtual void ConvertToInt();
void ConvertToInt() override;

// Provides debug output on the weights.
virtual void DebugWeights();
void DebugWeights() override;

// Writes to the given file. Returns false in case of error.
virtual bool Serialize(TFile* fp) const;
bool Serialize(TFile* fp) const override;
// Reads from the given file. Returns false in case of error.
virtual bool DeSerialize(TFile* fp);
bool DeSerialize(TFile* fp) override;

// Runs forward propagation of activations on the input line.
// See Network for a detailed discussion of the arguments.
virtual void Forward(bool debug, const NetworkIO& input,
const TransposedArray* input_transpose,
NetworkScratch* scratch, NetworkIO* output);
void Forward(bool debug, const NetworkIO& input,
const TransposedArray* input_transpose, NetworkScratch* scratch,
NetworkIO* output) override;
// Components of Forward so FullyConnected can be reused inside LSTM.
void SetupForward(const NetworkIO& input,
const TransposedArray* input_transpose);
Expand All @@ -97,9 +97,8 @@ class FullyConnected : public Network {

// Runs backward propagation of errors on the deltas line.
// See Network for a detailed discussion of the arguments.
virtual bool Backward(bool debug, const NetworkIO& fwd_deltas,
NetworkScratch* scratch,
NetworkIO* back_deltas);
bool Backward(bool debug, const NetworkIO& fwd_deltas,
NetworkScratch* scratch, NetworkIO* back_deltas) override;
// Components of Backward so FullyConnected can be reused inside LSTM.
void BackwardTimeStep(const NetworkIO& fwd_deltas, int t, double* curr_errors,
TransposedArray* errors_t, double* backprop);
Expand All @@ -112,8 +111,8 @@ class FullyConnected : public Network {
// Sums the products of weight updates in *this and other, splitting into
// positive (same direction) in *same and negative (different direction) in
// *changed.
virtual void CountAlternators(const Network& other, double* same,
double* changed) const;
void CountAlternators(const Network& other, double* same,
double* changed) const override;

protected:
// Weight arrays of size [no, ni + 1].
Expand Down
31 changes: 15 additions & 16 deletions src/lstm/lstm.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class LSTM : public Network {

// Returns the shape output from the network given an input shape (which may
// be partially unknown ie zero).
virtual StaticShape OutputShape(const StaticShape& input_shape) const;
StaticShape OutputShape(const StaticShape& input_shape) const override;

virtual STRING spec() const {
STRING spec() const override {
STRING spec;
if (type_ == NT_LSTM)
spec.add_str_int("Lfx", ns_);
Expand All @@ -71,46 +71,45 @@ class LSTM : public Network {

// Suspends/Enables training by setting the training_ flag. Serialize and
// DeSerialize only operate on the run-time data if state is false.
virtual void SetEnableTraining(TrainingState state);
void SetEnableTraining(TrainingState state) override;

// Sets up the network for training. Initializes weights using weights of
// scale `range` picked according to the random number generator `randomizer`.
virtual int InitWeights(float range, TRand* randomizer);
int InitWeights(float range, TRand* randomizer) override;
// Recursively searches the network for softmaxes with old_no outputs,
// and remaps their outputs according to code_map. See network.h for details.
int RemapOutputs(int old_no, const std::vector<int>& code_map) override;

// Converts a float network to an int network.
virtual void ConvertToInt();
void ConvertToInt() override;

// Provides debug output on the weights.
virtual void DebugWeights();
void DebugWeights() override;

// Writes to the given file. Returns false in case of error.
virtual bool Serialize(TFile* fp) const;
bool Serialize(TFile* fp) const override;
// Reads from the given file. Returns false in case of error.
virtual bool DeSerialize(TFile* fp);
bool DeSerialize(TFile* fp) override;

// Runs forward propagation of activations on the input line.
// See Network for a detailed discussion of the arguments.
virtual void Forward(bool debug, const NetworkIO& input,
const TransposedArray* input_transpose,
NetworkScratch* scratch, NetworkIO* output);
void Forward(bool debug, const NetworkIO& input,
const TransposedArray* input_transpose, NetworkScratch* scratch,
NetworkIO* output) override;

// Runs backward propagation of errors on the deltas line.
// See Network for a detailed discussion of the arguments.
virtual bool Backward(bool debug, const NetworkIO& fwd_deltas,
NetworkScratch* scratch,
NetworkIO* back_deltas);
bool Backward(bool debug, const NetworkIO& fwd_deltas,
NetworkScratch* scratch, NetworkIO* back_deltas) override;
// Updates the weights using the given learning rate, momentum and adam_beta.
// num_samples is used in the adam computation iff use_adam_ is true.
void Update(float learning_rate, float momentum, float adam_beta,
int num_samples) override;
// Sums the products of weight updates in *this and other, splitting into
// positive (same direction) in *same and negative (different direction) in
// *changed.
virtual void CountAlternators(const Network& other, double* same,
double* changed) const;
void CountAlternators(const Network& other, double* same,
double* changed) const override;
// Prints the weights for debug purposes.
void PrintW();
// Prints the weight deltas for debug purposes.
Expand Down
32 changes: 16 additions & 16 deletions src/lstm/plumbing.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,63 +34,63 @@ class Plumbing : public Network {
virtual ~Plumbing();

// Returns the required shape input to the network.
virtual StaticShape InputShape() const { return stack_[0]->InputShape(); }
virtual STRING spec() const {
StaticShape InputShape() const override { return stack_[0]->InputShape(); }
STRING spec() const override {
return "Sub-classes of Plumbing must implement spec()!";
}

// Returns true if the given type is derived from Plumbing, and thus contains
// multiple sub-networks that can have their own learning rate.
virtual bool IsPlumbingType() const { return true; }
bool IsPlumbingType() const override { return true; }

// Suspends/Enables training by setting the training_ flag. Serialize and
// DeSerialize only operate on the run-time data if state is false.
virtual void SetEnableTraining(TrainingState state);
void SetEnableTraining(TrainingState state) override;

// Sets flags that control the action of the network. See NetworkFlags enum
// for bit values.
virtual void SetNetworkFlags(uint32_t flags);
void SetNetworkFlags(uint32_t flags) override;

// Sets up the network for training. Initializes weights using weights of
// scale `range` picked according to the random number generator `randomizer`.
// Note that randomizer is a borrowed pointer that should outlive the network
// and should not be deleted by any of the networks.
// Returns the number of weights initialized.
virtual int InitWeights(float range, TRand* randomizer);
int InitWeights(float range, TRand* randomizer) override;
// Recursively searches the network for softmaxes with old_no outputs,
// and remaps their outputs according to code_map. See network.h for details.
int RemapOutputs(int old_no, const std::vector<int>& code_map) override;

// Converts a float network to an int network.
virtual void ConvertToInt();
void ConvertToInt() override;

// Provides a pointer to a TRand for any networks that care to use it.
// Note that randomizer is a borrowed pointer that should outlive the network
// and should not be deleted by any of the networks.
virtual void SetRandomizer(TRand* randomizer);
void SetRandomizer(TRand* randomizer) override;

// Adds the given network to the stack.
virtual void AddToStack(Network* network);

// Sets needs_to_backprop_ to needs_backprop and returns true if
// needs_backprop || any weights in this network so the next layer forward
// can be told to produce backprop for this layer if needed.
virtual bool SetupNeedsBackprop(bool needs_backprop);
bool SetupNeedsBackprop(bool needs_backprop) override;

// Returns an integer reduction factor that the network applies to the
// time sequence. Assumes that any 2-d is already eliminated. Used for
// scaling bounding boxes of truth data.
// WARNING: if GlobalMinimax is used to vary the scale, this will return
// the last used scale factor. Call it before any forward, and it will return
// the minimum scale factor of the paths through the GlobalMinimax.
virtual int XScaleFactor() const;
int XScaleFactor() const override;

// Provides the (minimum) x scale factor to the network (of interest only to
// input units) so they can determine how to scale bounding boxes.
virtual void CacheXScaleFactor(int factor);
void CacheXScaleFactor(int factor) override;

// Provides debug output on the weights.
virtual void DebugWeights();
void DebugWeights() override;

// Returns the current stack.
const PointerVector<Network>& stack() const {
Expand All @@ -117,9 +117,9 @@ class Plumbing : public Network {
float* LayerLearningRatePtr(const char* id) const;

// Writes to the given file. Returns false in case of error.
virtual bool Serialize(TFile* fp) const;
bool Serialize(TFile* fp) const override;
// Reads from the given file. Returns false in case of error.
virtual bool DeSerialize(TFile* fp);
bool DeSerialize(TFile* fp) override;

// Updates the weights using the given learning rate, momentum and adam_beta.
// num_samples is used in the adam computation iff use_adam_ is true.
Expand All @@ -128,8 +128,8 @@ class Plumbing : public Network {
// Sums the products of weight updates in *this and other, splitting into
// positive (same direction) in *same and negative (different direction) in
// *changed.
virtual void CountAlternators(const Network& other, double* same,
double* changed) const;
void CountAlternators(const Network& other, double* same,
double* changed) const override;

protected:
// The networks.
Expand Down
23 changes: 11 additions & 12 deletions src/lstm/series.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class Series : public Plumbing {

// Returns the shape output from the network given an input shape (which may
// be partially unknown ie zero).
virtual StaticShape OutputShape(const StaticShape& input_shape) const;
StaticShape OutputShape(const StaticShape& input_shape) const override;

virtual STRING spec() const {
STRING spec() const override {
STRING spec("[");
for (int i = 0; i < stack_.size(); ++i)
spec += stack_[i]->spec();
Expand All @@ -45,39 +45,38 @@ class Series : public Plumbing {
// Sets up the network for training. Initializes weights using weights of
// scale `range` picked according to the random number generator `randomizer`.
// Returns the number of weights initialized.
virtual int InitWeights(float range, TRand* randomizer);
int InitWeights(float range, TRand* randomizer) override;
// Recursively searches the network for softmaxes with old_no outputs,
// and remaps their outputs according to code_map. See network.h for details.
int RemapOutputs(int old_no, const std::vector<int>& code_map) override;

// Sets needs_to_backprop_ to needs_backprop and returns true if
// needs_backprop || any weights in this network so the next layer forward
// can be told to produce backprop for this layer if needed.
virtual bool SetupNeedsBackprop(bool needs_backprop);
bool SetupNeedsBackprop(bool needs_backprop) override;

// Returns an integer reduction factor that the network applies to the
// time sequence. Assumes that any 2-d is already eliminated. Used for
// scaling bounding boxes of truth data.
// WARNING: if GlobalMinimax is used to vary the scale, this will return
// the last used scale factor. Call it before any forward, and it will return
// the minimum scale factor of the paths through the GlobalMinimax.
virtual int XScaleFactor() const;
int XScaleFactor() const override;

// Provides the (minimum) x scale factor to the network (of interest only to
// input units) so they can determine how to scale bounding boxes.
virtual void CacheXScaleFactor(int factor);
void CacheXScaleFactor(int factor) override;

// Runs forward propagation of activations on the input line.
// See Network for a detailed discussion of the arguments.
virtual void Forward(bool debug, const NetworkIO& input,
const TransposedArray* input_transpose,
NetworkScratch* scratch, NetworkIO* output);
void Forward(bool debug, const NetworkIO& input,
const TransposedArray* input_transpose, NetworkScratch* scratch,
NetworkIO* output) override;

// Runs backward propagation of errors on the deltas line.
// See Network for a detailed discussion of the arguments.
virtual bool Backward(bool debug, const NetworkIO& fwd_deltas,
NetworkScratch* scratch,
NetworkIO* back_deltas);
bool Backward(bool debug, const NetworkIO& fwd_deltas,
NetworkScratch* scratch, NetworkIO* back_deltas) override;

// Splits the series after the given index, returning the two parts and
// deletes itself. The first part, up to network with index last_start, goes
Expand Down

0 comments on commit 45bb942

Please sign in to comment.