ConstantSumDescriptor Class Reference

This is an alternative base-case of SumDescriptor (an alternative to SimpleSumDescriptor) which represents a constant term, e.g. More...

#include <nnet-descriptor.h>

Inheritance diagram for ConstantSumDescriptor:
Collaboration diagram for ConstantSumDescriptor:

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 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 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 int32 Modulus () const
 
virtual void WriteConfig (std::ostream &os, const std::vector< std::string > &node_names) const
 The written form is: `Const(, <dimension>)`, e.g. More...
 
virtual SumDescriptorCopy () const
 
 ConstantSumDescriptor (BaseFloat value, int32 dim)
 
virtual ~ConstantSumDescriptor ()
 
- Public Member Functions inherited from SumDescriptor
virtual ~SumDescriptor ()
 

Private Attributes

BaseFloat value_
 
int32 dim_
 

Detailed Description

This is an alternative base-case of SumDescriptor (an alternative to SimpleSumDescriptor) which represents a constant term, e.g.

`Const(1.0, 512)`. Note that this is not allowed to appear inside conditionals such as IfDefined() or Failover(); this is enforced in the parsing code involving class GeneralDescriptor. The written form is: `Const(

, <dimension>)`, e.g. `Const(-1.0, 512)`

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

Constructor & Destructor Documentation

◆ ConstantSumDescriptor()

ConstantSumDescriptor ( BaseFloat  value,
int32  dim 
)

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

References KALDI_ASSERT.

Referenced by GeneralDescriptor::ConvertToSumDescriptor().

350  :
351  value_(value), dim_(dim) {
352  KALDI_ASSERT(dim > 0 && (value - value == 0.0));
353 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ~ConstantSumDescriptor()

virtual ~ConstantSumDescriptor ( )
inlinevirtual

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

476 {}

Member Function Documentation

◆ Copy()

SumDescriptor * Copy ( ) const
virtual

Implements SumDescriptor.

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

◆ Dim()

virtual int32 Dim ( const Nnet nnet) const
inlinevirtual

Implements SumDescriptor.

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

References ForwardingDescriptor::GetScaleForNode().

Referenced by Descriptor::Dim().

◆ GetDependencies()

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

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 457 of file nnet-descriptor.h.

458  { }

◆ GetNodeDependencies()

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

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 467 of file nnet-descriptor.h.

Referenced by Descriptor::GetNodeDependencies().

467 { }

◆ 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 335 of file nnet-descriptor.cc.

335  {
336  if (node_index < 0) return value_;
337  else return std::numeric_limits<BaseFloat>::infinity();
338 }

◆ 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 459 of file nnet-descriptor.h.

Referenced by Descriptor::IsComputable().

461  {
462  return true;
463  }

◆ Modulus()

virtual int32 Modulus ( ) const
inlinevirtual

◆ WriteConfig()

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

The written form is: `Const(, <dimension>)`, e.g.

`Const(-1.0, 512)`

Implements SumDescriptor.

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

Referenced by Descriptor::WriteConfig().

341  {
342  os << "Const(" << value_ << ", " << dim_ << ')';
343 }

Member Data Documentation

◆ dim_

int32 dim_
private

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

◆ value_

BaseFloat value_
private

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


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