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

#include <nnet-descriptor.h>

Collaboration diagram for Descriptor:

Public Member Functions

int32 Dim (const Nnet &nnet) const
 
bool Parse (const std::vector< std::string > &node_names, const std::string **next_token)
 
void WriteConfig (std::ostream &os, const std::vector< std::string > &node_names) const
 
void GetDependencies (const Index &index, std::vector< Cindex > *used_inputs) const
 This function exists to enable us to manage optional dependencies, i.e. More...
 
bool IsComputable (const Index &ind, const CindexSet &cindex_set, std::vector< Cindex > *used_inputs) const
 Has the same purpose and interface as the IsComputable function of the SumDescriptor function. More...
 
void GetNodeDependencies (std::vector< int32 > *node_indexes) const
 
int32 Modulus () const
 
int32 NumParts () const
 Returns the number of parts that are concatenated over. More...
 
const SumDescriptorPart (int32 n) const
 returns the n'th part. More...
 
 Descriptor ()
 
 Descriptor (const Descriptor &other)
 Copy constructor. More...
 
Descriptoroperator= (const Descriptor &other)
 Assignment operator. More...
 
 Descriptor (const std::vector< SumDescriptor * > &parts)
 Takes ownership of pointers in "parts". More...
 
 ~Descriptor ()
 Destructor. More...
 

Private Member Functions

void Destroy ()
 

Private Attributes

std::vector< SumDescriptor * > parts_
 

Detailed Description

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

Constructor & Destructor Documentation

Descriptor ( )
inline

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

500 { }
Descriptor ( const Descriptor other)
inline

Copy constructor.

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

502 { *this = other; }
Descriptor ( const std::vector< SumDescriptor * > &  parts)
inline

Takes ownership of pointers in "parts".

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

506  :
507  parts_(parts) { }
std::vector< SumDescriptor * > parts_
~Descriptor ( )
inline

Destructor.

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

References Descriptor::Destroy().

Member Function Documentation

void Destroy ( )
private

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

References rnnlm::i, and Descriptor::parts_.

Referenced by Descriptor::operator=(), and Descriptor::~Descriptor().

414  {
415  for (size_t i = 0; i < parts_.size(); i++)
416  delete parts_[i];
417  parts_.clear();
418 }
std::vector< SumDescriptor * > parts_
int32 Dim ( const Nnet nnet) const

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

References KALDI_ASSERT, and Descriptor::parts_.

Referenced by Compiler::CreateStepInfo(), and NetworkNode::Dim().

420  {
421  int32 num_parts = parts_.size();
422  int32 dim = 0;
423  for (int32 part = 0; part < num_parts; part++)
424  dim += parts_[part]->Dim(nnet);
425  KALDI_ASSERT(dim > 0);
426  return dim;
427 }
std::vector< SumDescriptor * > parts_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
int32 Dim(const Nnet &nnet) const
void GetDependencies ( const Index index,
std::vector< Cindex > *  used_inputs 
) const

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 (not necessarily unique) that this expression will include. Otherwise it will return false and set used_inputs to the empty vector.

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.

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

References Descriptor::parts_.

Referenced by ComputationGraphBuilder::AddDependencies(), and kaldi::nnet3::ComputeComputationGraph().

70  {
71  dependencies->clear();
72  std::vector<SumDescriptor*>::const_iterator sum_iter = parts_.begin(),
73  sum_end = parts_.end();
74  std::vector<Cindex> this_part;
75  for (; sum_iter != sum_end; ++sum_iter)
76  (*sum_iter)->GetDependencies(index, dependencies);
77 }
std::vector< SumDescriptor * > parts_
void GetNodeDependencies ( std::vector< int32 > *  node_indexes) const

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

References rnnlm::i, and Descriptor::parts_.

Referenced by Nnet::Check(), and kaldi::nnet3::NnetToDirectedGraph().

466  {
467  node_indexes->clear();
468  for (size_t i = 0; i < parts_.size(); i++)
469  parts_[i]->GetNodeDependencies(node_indexes);
470 }
std::vector< SumDescriptor * > parts_
void GetNodeDependencies(std::vector< int32 > *node_indexes) const
bool IsComputable ( const Index ind,
const CindexSet cindex_set,
std::vector< Cindex > *  used_inputs 
) const

Has the same purpose and interface as the IsComputable function of the SumDescriptor function.

Outputs to used_inputs rather than appending to it, though. used_inputs will not be sorted or have repeats removed.

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

References rnnlm::i, and Descriptor::parts_.

Referenced by ComputationGraphBuilder::ComputeComputableInfo(), and ComputationGraphBuilder::PruneDependencies().

447  {
448  if (input_terms)
449  input_terms->clear();
450  for (size_t i = 0; i < parts_.size(); i++) {
451  // if any of the parts is not computable, the whole is not computable.
452  if (!parts_[i]->IsComputable(ind, cindex_set, input_terms)) {
453  if (input_terms)
454  input_terms->clear();
455  return false;
456  }
457  }
458  return true;
459 }
std::vector< SumDescriptor * > parts_
bool IsComputable(const Index &ind, const CindexSet &cindex_set, std::vector< Cindex > *used_inputs) const
Has the same purpose and interface as the IsComputable function of the SumDescriptor function...
int32 Modulus ( ) const

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

References rnnlm::i, kaldi::Lcm(), and Descriptor::parts_.

Referenced by Nnet::Modulus().

437  {
438  int32 ans = 1;
439  for (size_t i = 0; i < parts_.size(); i++)
440  ans = Lcm(ans, parts_[i]->Modulus());
441  return ans;
442 }
std::vector< SumDescriptor * > parts_
I Lcm(I m, I n)
Returns the least common multiple of two integers.
Definition: kaldi-math.h:315
int32 NumParts ( ) const
inline

Returns the number of parts that are concatenated over.

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

References Descriptor::parts_.

Referenced by Compiler::CreateStepInfo(), and ModelCollapser::DescriptorIsCollapsible().

496 { return parts_.size(); }
std::vector< SumDescriptor * > parts_
Descriptor & operator= ( const Descriptor other)

Assignment operator.

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

References Descriptor::Destroy(), rnnlm::i, and Descriptor::parts_.

430  {
431  Destroy();
432  for (size_t i = 0; i < other.parts_.size(); i++)
433  parts_.push_back(other.parts_[i]->Copy());
434  return *this;
435 }
std::vector< SumDescriptor * > parts_
bool Parse ( const std::vector< std::string > &  node_names,
const std::string **  next_token 
)

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

References GeneralDescriptor::ConvertToDescriptor(), KALDI_ERR, and GeneralDescriptor::Parse().

Referenced by ModelCollapser::ReplaceNodeInDescriptor(), and kaldi::nnet3::UnitTestDescriptorIo().

381  {
382  GeneralDescriptor *gen_desc;
383  try {
384  gen_desc = GeneralDescriptor::Parse(node_names,
385  next_token);
386  } catch (...) {
387  return false;
388  }
389  if (**next_token != "end of input")
390  KALDI_ERR << "Parsing Descriptor, expected end of input but got "
391  << "'" << *next_token << "'";
392  Descriptor *desc = gen_desc->ConvertToDescriptor();
393  *this = *desc;
394  delete desc;
395  delete gen_desc;
396  return true;
397 }
static GeneralDescriptor * Parse(const std::vector< std::string > &node_names, const std::string **next_token)
#define KALDI_ERR
Definition: kaldi-error.h:127
const SumDescriptor & Part ( int32  n) const

returns the n'th part.

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

References KALDI_ASSERT, rnnlm::n, and Descriptor::parts_.

Referenced by Compiler::ComputeInputLocationsList(), Compiler::CreateStepInfo(), and ModelCollapser::DescriptorIsCollapsible().

461  {
462  KALDI_ASSERT(static_cast<size_t>(n) < parts_.size());
463  return *(parts_[n]);
464 }
std::vector< SumDescriptor * > parts_
struct rnnlm::@11::@12 n
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void WriteConfig ( std::ostream &  os,
const std::vector< std::string > &  node_names 
) const

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

References rnnlm::i, KALDI_ASSERT, and Descriptor::parts_.

Referenced by kaldi::nnet3::NormalizeTextDescriptor(), ModelCollapser::ReplaceNodeInDescriptor(), kaldi::nnet3::UnitTestDescriptorIo(), and kaldi::nnet3::UnitTestGeneralDescriptor().

400  {
401  KALDI_ASSERT(parts_.size() > 0);
402  if (parts_.size() == 1)
403  parts_[0]->WriteConfig(os, node_names);
404  else {
405  os << "Append(";
406  for (size_t i = 0; i < parts_.size(); i++) {
407  parts_[i]->WriteConfig(os, node_names);
408  if (i + 1 < parts_.size())
409  os << ", ";
410  }
411  os << ")";
412  }
413 }
std::vector< SumDescriptor * > parts_
void WriteConfig(std::ostream &os, const std::vector< std::string > &node_names) const
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169

Member Data Documentation


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