All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BinarySumDescriptor Class Reference

BinarySumDescriptor can represent either A + B, or (A if defined, else B). More...

#include <nnet-descriptor.h>

Inheritance diagram for BinarySumDescriptor:
Collaboration diagram for BinarySumDescriptor:

Public Types

enum  Operation { kSum, kFailover }
 

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
 
virtual int32 Modulus () const
 
virtual void WriteConfig (std::ostream &os, const std::vector< std::string > &node_names) const
 Written form is: if op_ == kSum then "Sum(<src1>, <src2>)"; if op_ == kFailover, then "Failover(<src1>, <src2>)" If you need more than binary operations, just use Sum(a, Sum(b, c)). More...
 
virtual SumDescriptorCopy () const
 
 BinarySumDescriptor (Operation op, SumDescriptor *src1, SumDescriptor *src2)
 
virtual ~BinarySumDescriptor ()
 
- Public Member Functions inherited from SumDescriptor
virtual ~SumDescriptor ()
 

Private Attributes

Operation op_
 
SumDescriptorsrc1_
 
SumDescriptorsrc2_
 

Detailed Description

BinarySumDescriptor can represent either A + B, or (A if defined, else B).

Other expressions such as A + (B if defined, else zero), (A if defined, else zero) + (B if defined, else zero), and (A if defined, else B if defined, else zero) can be expressed using combinations of the two provided options for BinarySumDescriptor and the variant

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

Member Enumeration Documentation

enum Operation
Enumerator
kSum 
kFailover 

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

403  {
404  kSum, // A + B
405  kFailover, // A if defined, else B.
406  };

Constructor & Destructor Documentation

BinarySumDescriptor ( Operation  op,
SumDescriptor src1,
SumDescriptor src2 
)
inline

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

Referenced by BinarySumDescriptor::Copy().

424  :
425  op_(op), src1_(src1), src2_(src2) {}
virtual ~BinarySumDescriptor ( )
inlinevirtual

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

References BinarySumDescriptor::src1_, and BinarySumDescriptor::src2_.

426 { delete src1_; delete src2_; }

Member Function Documentation

SumDescriptor * Copy ( ) const
virtual

Implements SumDescriptor.

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

References BinarySumDescriptor::BinarySumDescriptor(), SumDescriptor::Copy(), BinarySumDescriptor::op_, BinarySumDescriptor::src1_, and BinarySumDescriptor::src2_.

357  {
358  return new BinarySumDescriptor(op_, src1_->Copy(), src2_->Copy());
359 }
virtual SumDescriptor * Copy() const =0
BinarySumDescriptor(Operation op, SumDescriptor *src1, SumDescriptor *src2)
int32 Dim ( const Nnet nnet) const
virtual

Implements SumDescriptor.

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

References SumDescriptor::Dim(), KALDI_ERR, BinarySumDescriptor::kSum, BinarySumDescriptor::op_, BinarySumDescriptor::src1_, and BinarySumDescriptor::src2_.

338  {
339  int32 dim1 = src1_->Dim(nnet), dim2 = src2_->Dim(nnet);
340  if (dim1 != dim2)
341  KALDI_ERR << "Neural net contains " << (op_ == kSum ? "Sum" : "Failover")
342  << " expression with inconsistent dimension: " << dim1
343  << " vs. " << dim2;
344  return dim1;
345 }
#define KALDI_ERR
Definition: kaldi-error.h:127
virtual int32 Dim(const Nnet &nnet) const =0
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 291 of file nnet-descriptor.cc.

References SumDescriptor::GetDependencies(), BinarySumDescriptor::src1_, and BinarySumDescriptor::src2_.

292  {
293  src1_->GetDependencies(ind, dependencies);
294  src2_->GetDependencies(ind, dependencies);
295 }
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...
void GetNodeDependencies ( std::vector< int32 > *  node_indexes) const
virtual

Implements SumDescriptor.

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

References SumDescriptor::GetNodeDependencies(), BinarySumDescriptor::src1_, and BinarySumDescriptor::src2_.

348  {
349  src1_->GetNodeDependencies(node_indexes);
350  src2_->GetNodeDependencies(node_indexes);
351 }
virtual void GetNodeDependencies(std::vector< int32 > *node_indexes) const =0
bool IsComputable ( const Index ind,
const CindexSet cindex_set,
std::vector< Cindex > *  used_inputs 
) const
virtual

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

References SumDescriptor::IsComputable(), KALDI_ASSERT, KALDI_PARANOID_ASSERT, BinarySumDescriptor::kFailover, BinarySumDescriptor::kSum, BinarySumDescriptor::op_, BinarySumDescriptor::src1_, and BinarySumDescriptor::src2_.

300  {
302  std::vector<Cindex> src1_inputs, src2_inputs;
303  bool r = (used_inputs != NULL);
304  bool src1_computable = src1_->IsComputable(ind, cindex_set,
305  r ? &src1_inputs: NULL),
306  src2_computable = src2_->IsComputable(ind, cindex_set,
307  r ? &src2_inputs : NULL);
308  if (op_ == kSum) {
309  if (src1_computable && src2_computable) {
310  if (r) {
311  used_inputs->insert(used_inputs->end(),
312  src1_inputs.begin(), src1_inputs.end());
313  used_inputs->insert(used_inputs->end(),
314  src2_inputs.begin(), src2_inputs.end());
315  }
316  return true;
317  } else {
318  return false;
319  }
320  } else {
322  if (src1_computable) {
323  if (r)
324  used_inputs->insert(used_inputs->end(),
325  src1_inputs.begin(), src1_inputs.end());
326  return true;
327  } else if (src2_computable) {
328  if (r)
329  used_inputs->insert(used_inputs->end(),
330  src2_inputs.begin(), src2_inputs.end());
331  return true;
332  } else {
333  return false;
334  }
335  }
336 }
#define KALDI_PARANOID_ASSERT(cond)
Definition: kaldi-error.h:182
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.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
int32 Modulus ( ) const
virtual

Implements SumDescriptor.

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

References kaldi::Lcm(), SumDescriptor::Modulus(), BinarySumDescriptor::src1_, and BinarySumDescriptor::src2_.

353  {
354  return Lcm(src1_->Modulus(), src2_->Modulus());
355 }
virtual int32 Modulus() const =0
I Lcm(I m, I n)
Returns the least common multiple of two integers.
Definition: kaldi-math.h:315
void WriteConfig ( std::ostream &  os,
const std::vector< std::string > &  node_names 
) const
virtual

Written form is: if op_ == kSum then "Sum(<src1>, <src2>)"; if op_ == kFailover, then "Failover(<src1>, <src2>)" If you need more than binary operations, just use Sum(a, Sum(b, c)).

Implements SumDescriptor.

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

References KALDI_ASSERT, BinarySumDescriptor::kFailover, BinarySumDescriptor::kSum, BinarySumDescriptor::op_, BinarySumDescriptor::src1_, BinarySumDescriptor::src2_, and SumDescriptor::WriteConfig().

363  {
364  KALDI_ASSERT(op_ == kSum || op_ == kFailover);
365  if (op_ == kSum) os << "Sum(";
366  if (op_ == kFailover) os << "Failover(";
367  src1_->WriteConfig(os, node_names);
368  os << ", ";
369  src2_->WriteConfig(os, node_names);
370  os << ")";
371 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
virtual void WriteConfig(std::ostream &os, const std::vector< std::string > &node_names) const =0
Write in config-file format.

Member Data Documentation


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