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

Constructor & Destructor Documentation

◆ Descriptor() [1/3]

Descriptor ( )
inline

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

587 { }

◆ Descriptor() [2/3]

Descriptor ( const Descriptor other)
inline

Copy constructor.

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

589 { *this = other; }

◆ Descriptor() [3/3]

Descriptor ( const std::vector< SumDescriptor *> &  parts)
inline

Takes ownership of pointers in "parts".

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

593  :
594  parts_(parts) { }
std::vector< SumDescriptor * > parts_

◆ ~Descriptor()

~Descriptor ( )
inline

Destructor.

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

Member Function Documentation

◆ Destroy()

void Destroy ( )
private

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

References rnnlm::i.

525  {
526  for (size_t i = 0; i < parts_.size(); i++)
527  delete parts_[i];
528  parts_.clear();
529 }
std::vector< SumDescriptor * > parts_

◆ Dim()

int32 Dim ( const Nnet nnet) const

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

References ConstantSumDescriptor::Dim(), and KALDI_ASSERT.

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

531  {
532  int32 num_parts = parts_.size();
533  int32 dim = 0;
534  for (int32 part = 0; part < num_parts; part++)
535  dim += parts_[part]->Dim(nnet);
536  KALDI_ASSERT(dim > 0);
537  return dim;
538 }
std::vector< SumDescriptor * > parts_
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
int32 Dim(const Nnet &nnet) const

◆ GetDependencies()

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_

◆ GetNodeDependencies()

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

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

References ConstantSumDescriptor::GetNodeDependencies(), and rnnlm::i.

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

577  {
578  node_indexes->clear();
579  for (size_t i = 0; i < parts_.size(); i++)
580  parts_[i]->GetNodeDependencies(node_indexes);
581 }
void GetNodeDependencies(std::vector< int32 > *node_indexes) const
std::vector< SumDescriptor * > parts_

◆ IsComputable()

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

References rnnlm::i, and ConstantSumDescriptor::IsComputable().

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

558  {
559  if (input_terms)
560  input_terms->clear();
561  for (size_t i = 0; i < parts_.size(); i++) {
562  // if any of the parts is not computable, the whole is not computable.
563  if (!parts_[i]->IsComputable(ind, cindex_set, input_terms)) {
564  if (input_terms)
565  input_terms->clear();
566  return false;
567  }
568  }
569  return true;
570 }
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...

◆ Modulus()

int32 Modulus ( ) const

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

References rnnlm::i, kaldi::Lcm(), and ConstantSumDescriptor::Modulus().

Referenced by Nnet::Modulus().

548  {
549  int32 ans = 1;
550  for (size_t i = 0; i < parts_.size(); i++)
551  ans = Lcm(ans, parts_[i]->Modulus());
552  return ans;
553 }
std::vector< SumDescriptor * > parts_
kaldi::int32 int32
I Lcm(I m, I n)
Returns the least common multiple of two integers.
Definition: kaldi-math.h:318

◆ NumParts()

int32 NumParts ( ) const
inline

Returns the number of parts that are concatenated over.

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

References rnnlm::n.

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

583 { return parts_.size(); }
std::vector< SumDescriptor * > parts_

◆ operator=()

Descriptor & operator= ( const Descriptor other)

Assignment operator.

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

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

541  {
542  Destroy();
543  for (size_t i = 0; i < other.parts_.size(); i++)
544  parts_.push_back(other.parts_[i]->Copy());
545  return *this;
546 }
std::vector< SumDescriptor * > parts_

◆ Parse()

bool Parse ( const std::vector< std::string > &  node_names,
const std::string **  next_token 
)

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

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

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

492  {
493  GeneralDescriptor *gen_desc;
494  try {
495  gen_desc = GeneralDescriptor::Parse(node_names,
496  next_token);
497  } catch (...) {
498  return false;
499  }
500  if (**next_token != "end of input")
501  KALDI_ERR << "Parsing Descriptor, expected end of input but got "
502  << "'" << **next_token << "'";
503  Descriptor *desc = gen_desc->ConvertToDescriptor();
504  *this = *desc;
505  delete desc;
506  delete gen_desc;
507  return true;
508 }
static GeneralDescriptor * Parse(const std::vector< std::string > &node_names, const std::string **next_token)
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ Part()

const SumDescriptor & Part ( int32  n) const

returns the n'th part.

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

References KALDI_ASSERT, and rnnlm::n.

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

572  {
573  KALDI_ASSERT(static_cast<size_t>(n) < parts_.size());
574  return *(parts_[n]);
575 }
std::vector< SumDescriptor * > parts_
struct rnnlm::@11::@12 n
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ WriteConfig()

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

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

References rnnlm::i, KALDI_ASSERT, and ConstantSumDescriptor::WriteConfig().

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

511  {
512  KALDI_ASSERT(parts_.size() > 0);
513  if (parts_.size() == 1)
514  parts_[0]->WriteConfig(os, node_names);
515  else {
516  os << "Append(";
517  for (size_t i = 0; i < parts_.size(); i++) {
518  parts_[i]->WriteConfig(os, node_names);
519  if (i + 1 < parts_.size())
520  os << ", ";
521  }
522  os << ")";
523  }
524 }
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:185

Member Data Documentation

◆ parts_

std::vector<SumDescriptor*> parts_
private

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

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


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