OptionalSumDescriptor Class Reference

This is the case of class SumDescriptor, in which we contain just one term, and that term is optional (an IfDefined() expression). More...

#include <nnet-descriptor.h>

Inheritance diagram for OptionalSumDescriptor:
Collaboration diagram for OptionalSumDescriptor:

Public Member Functions

virtual void GetDependencies (const Index &ind, std::vector< Cindex > *dependencies) const
 Given an Index at the output of this Descriptor, append to "dependencies" a list of Cindexes that describes what inputs we potentially depend on. More...
 
virtual bool IsComputable (const Index &ind, const CindexSet &cindex_set, std::vector< Cindex > *used_inputs) const
 This function exists to enable us to manage optional dependencies, i.e. More...
 
virtual int32 Dim (const Nnet &nnet) const
 
virtual void GetNodeDependencies (std::vector< int32 > *node_indexes) const
 This function appends to "node_indexes" a list (not necessarily sorted or unique) of all the node indexes that this descriptor may forward data from. More...
 
virtual BaseFloat GetScaleForNode (int32 node_index) const
 This function returns the scale on the node-index 'node_index' when it appears in expressions inside this descriptor. More...
 
virtual int32 Modulus () const
 
virtual void WriteConfig (std::ostream &os, const std::vector< std::string > &node_names) const
 written form is: if required_ == true, "<written-form-of-src>" else "IfDefined(<written-form-of-src>)". More...
 
virtual SumDescriptorCopy () const
 
 OptionalSumDescriptor (SumDescriptor *src)
 
virtual ~OptionalSumDescriptor ()
 
- Public Member Functions inherited from SumDescriptor
virtual ~SumDescriptor ()
 

Private Attributes

SumDescriptorsrc_
 

Detailed Description

This is the case of class SumDescriptor, in which we contain just one term, and that term is optional (an IfDefined() expression).

That term is a general SumDescriptor. The written form is: `IfDefined(<descriptor>)`, e.g. `IfDefined(Offset(lstm2.s, -3))`

Definition at line 383 of file nnet-descriptor.h.

Constructor & Destructor Documentation

◆ OptionalSumDescriptor()

Definition at line 406 of file nnet-descriptor.h.

406 : src_(src) { }

◆ ~OptionalSumDescriptor()

virtual ~OptionalSumDescriptor ( )
inlinevirtual

Definition at line 407 of file nnet-descriptor.h.

407 { delete src_; }

Member Function Documentation

◆ Copy()

SumDescriptor * Copy ( ) const
virtual

Implements SumDescriptor.

Definition at line 253 of file nnet-descriptor.cc.

253  {
254  return new OptionalSumDescriptor(src_->Copy());
255 }
virtual SumDescriptor * Copy() const =0
OptionalSumDescriptor(SumDescriptor *src)

◆ Dim()

int32 Dim ( const Nnet nnet) const
virtual

Implements SumDescriptor.

Definition at line 271 of file nnet-descriptor.cc.

271  {
272  return src_->Dim(nnet);
273 }
virtual int32 Dim(const Nnet &nnet) const =0

◆ GetDependencies()

void GetDependencies ( const Index ind,
std::vector< Cindex > *  dependencies 
) const
virtual

Given an Index at the output of this Descriptor, append to "dependencies" a list of Cindexes that describes what inputs we potentially depend on.

The output list is not necessarily sorted, and this function doesn't make sure that it's unique.

Implements SumDescriptor.

Definition at line 257 of file nnet-descriptor.cc.

259  {
260  src_->GetDependencies(ind, dependencies);
261 }
virtual void GetDependencies(const Index &ind, std::vector< Cindex > *dependencies) const =0
Given an Index at the output of this Descriptor, append to "dependencies" a list of Cindexes that des...

◆ GetNodeDependencies()

void GetNodeDependencies ( std::vector< int32 > *  node_indexes) const
virtual

This function appends to "node_indexes" a list (not necessarily sorted or unique) of all the node indexes that this descriptor may forward data from.

Implements SumDescriptor.

Definition at line 289 of file nnet-descriptor.cc.

290  {
291  src_->GetNodeDependencies(node_indexes);
292 }
virtual void GetNodeDependencies(std::vector< int32 > *node_indexes) const =0
This function appends to "node_indexes" a list (not necessarily sorted or unique) of all the node ind...

◆ GetScaleForNode()

BaseFloat GetScaleForNode ( int32  node_index) const
virtual

This function returns the scale on the node-index 'node_index' when it appears in expressions inside this descriptor.

E.g. if the descriptor is just `Scale(tdnn2, 2.0)` and the node index for `tdnn2` is 4, then GetScaleForNode(4) would return 2.0. It will return +infinity if the node is >= 0 and does not appear in this descriptor. If node_index < 0, it returns the constant offset value from this descriptor, which will equal 0.0 if there is no expression like `Const(1.0, 512)` in this node. If a particular node_index > 0 appears in different sub-expressions of the descriptor with different scales it is an error (it's not supported) and this function would crash.

Implements SumDescriptor.

Definition at line 275 of file nnet-descriptor.cc.

References KALDI_ERR.

275  {
276  BaseFloat ans = src_->GetScaleForNode(node_index);
277  if (node_index < 0 && ans != 0.0) {
278  // node_index < 0 means that the user is querying about the scale this
279  // expression puts on the constant value. If there is a nonzero scale
280  // (i.e. a Const() expression) inside an IfDefined() expression, which
281  // is what OptionalSumDescriptor handles, then it is an error: the user
282  // is trying to code something that we do not currently support.
283  KALDI_ERR << "Illegal combination of IfDefined() expression and "
284  "Const() expression encountered.";
285  }
286  return ans;
287 }
virtual BaseFloat GetScaleForNode(int32 node_index) const =0
This function returns the scale on the node-index &#39;node_index&#39; when it appears in expressions inside ...
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ IsComputable()

virtual bool IsComputable ( const Index ind,
const CindexSet cindex_set,
std::vector< Cindex > *  used_inputs 
) const
inlinevirtual

This function exists to enable us to manage optional dependencies, i.e.

for making sense of expressions like (A + (B is present)) and (A if present; if not, B). Suppose we are trying to compute the index "ind", and the user represents that "cindex_set" is the set of Cindexes are available to the computation; then this function will return true if we can compute the expression given these inputs; and if so, will output to "used_inputs" the list of Cindexes that this expression will be a summation over.

Parameters
[in]indThe index that we want to compute at the output of the Descriptor.
[in]cindex_setThe set of Cindexes that are available at the input of the Descriptor.
[out]used_inputsIf non-NULL, if this function returns true then to this vector will be *appended* the inputs that will actually participate in the computation. Else (if non-NULL) it will be left unchanged.
Returns
Returns true if this output is computable given the provided inputs.

Implements SumDescriptor.

Definition at line 387 of file nnet-descriptor.h.

References ForwardingDescriptor::Dim(), ForwardingDescriptor::GetNodeDependencies(), and ForwardingDescriptor::GetScaleForNode().

389  {
390  return src_->IsComputable(ind, cindex_set, used_inputs) || true;
391  }
virtual bool IsComputable(const Index &ind, const CindexSet &cindex_set, std::vector< Cindex > *used_inputs) const =0
This function exists to enable us to manage optional dependencies, i.e.

◆ Modulus()

virtual int32 Modulus ( ) const
inlinevirtual

Implements SumDescriptor.

Definition at line 399 of file nnet-descriptor.h.

References ForwardingDescriptor::Copy(), and ForwardingDescriptor::WriteConfig().

399 { return src_->Modulus(); }
virtual int32 Modulus() const =0

◆ WriteConfig()

void WriteConfig ( std::ostream &  os,
const std::vector< std::string > &  node_names 
) const
virtual

written form is: if required_ == true, "<written-form-of-src>" else "IfDefined(<written-form-of-src>)".

Implements SumDescriptor.

Definition at line 263 of file nnet-descriptor.cc.

265  {
266  os << "IfDefined(";
267  src_->WriteConfig(os, node_names);
268  os << ")";
269 }
virtual void WriteConfig(std::ostream &os, const std::vector< std::string > &node_names) const =0
Write in config-file format.

Member Data Documentation

◆ src_

SumDescriptor* src_
private

Definition at line 409 of file nnet-descriptor.h.


The documentation for this class was generated from the following files: