Esempio n. 1
0
Emitter& Emitter::Write(const _Tag& tag) {
  if (!good())
    return *this;

  if (m_pState->HasTag()) {
    m_pState->SetError(ErrorMsg::INVALID_TAG);
    return *this;
  }

  PrepareNode(EmitterNodeType::Property);

  bool success = false;
  if (tag.type == _Tag::Type::Verbatim)
    success = Utils::WriteTag(m_stream, tag.content, true);
  else if (tag.type == _Tag::Type::PrimaryHandle)
    success = Utils::WriteTag(m_stream, tag.content, false);
  else
    success = Utils::WriteTagWithPrefix(m_stream, tag.prefix, tag.content);

  if (!success) {
    m_pState->SetError(ErrorMsg::INVALID_TAG);
    return *this;
  }

  m_pState->SetTag();

  return *this;
}
Esempio n. 2
0
Emitter& Emitter::Write(const std::string& str) {
  if (!good())
    return *this;

  const bool escapeNonAscii = m_pState->GetOutputCharset() == EscapeNonAscii;
  const StringFormat::value strFormat =
      Utils::ComputeStringFormat(str, m_pState->GetStringFormat(),
                                 m_pState->CurGroupFlowType(), escapeNonAscii);

  if (strFormat == StringFormat::Literal)
    m_pState->SetMapKeyFormat(YAML::LongKey, FmtScope::Local);

  PrepareNode(EmitterNodeType::Scalar);

  switch (strFormat) {
    case StringFormat::Plain:
      m_stream << str;
      break;
    case StringFormat::SingleQuoted:
      Utils::WriteSingleQuotedString(m_stream, str);
      break;
    case StringFormat::DoubleQuoted:
      Utils::WriteDoubleQuotedString(m_stream, str, escapeNonAscii);
      break;
    case StringFormat::Literal:
      Utils::WriteLiteralString(m_stream, str,
                                m_pState->CurIndent() + m_pState->GetIndent());
      break;
  }

  StartedScalar();

  return *this;
}
Esempio n. 3
0
void NetGraph::FeedForward(NetGraphNode* node) {
	if (!node->flag_ff_visited) {
		// Make sure all input nodes have valid outputs
		for (NetGraphConnection connection : node->input_connections)
			FeedForward(connection.node);

		PrepareNode(node);
		// Call the Layer::FeedForward method and set the visited flag
		node->layer->FeedForward();
    if(layerview_enabled_)
      for(NetGraphBuffer buffer: node->output_buffers) {
        for(unsigned int sample = 0; sample < buffer.combined_tensor->data.samples(); sample++) {
          for(unsigned int map = 0; map < buffer.combined_tensor->data.maps(); map++) {
            std::stringstream ss;
            ss << node->unique_name << ": " << node->layer->GetLayerDescription() << ", buffer " << buffer.description;
  #ifdef BUILD_OPENCL
            buffer.combined_tensor->data.MoveToCPU();
  #endif
            viewer.show(&(buffer.combined_tensor->data), ss.str(), false, map, sample);
          }
        }
      }
    
		node->flag_ff_visited = true;
	}
}
Esempio n. 4
0
// EmitNewline
void Emitter::EmitNewline() {
  if (!good())
    return;

  PrepareNode(EmitterNodeType::None);
  m_stream << "\n";
  m_pState->SetNonContent();
}
Esempio n. 5
0
// EmitBeginMap
void Emitter::EmitBeginMap() {
  if (!good())
    return;

  PrepareNode(m_pState->NextGroupType(GroupType::Map));

  m_pState->StartedGroup(GroupType::Map);
}
Esempio n. 6
0
Emitter& Emitter::Write(char ch) {
  if (!good())
    return *this;

  PrepareNode(EmitterNodeType::Scalar);
  Utils::WriteChar(m_stream, ch);
  StartedScalar();

  return *this;
}
Esempio n. 7
0
Emitter& Emitter::Write(const Binary& binary) {
  Write(SecondaryTag("binary"));

  if (!good())
    return *this;

  PrepareNode(EmitterNodeType::Scalar);
  Utils::WriteBinary(m_stream, binary);
  StartedScalar();

  return *this;
}
Esempio n. 8
0
Emitter& Emitter::Write(const _Null& /*null*/) {
  if (!good())
    return *this;

  PrepareNode(EmitterNodeType::Scalar);

  m_stream << "~";

  StartedScalar();

  return *this;
}
Esempio n. 9
0
Emitter& Emitter::Write(const _Comment& comment) {
  if (!good())
    return *this;

  PrepareNode(EmitterNodeType::None);

  if (m_stream.col() > 0)
    m_stream << Indentation(m_pState->GetPreCommentIndent());
  Utils::WriteComment(m_stream, comment.content,
                      m_pState->GetPostCommentIndent());

  m_pState->SetNonContent();

  return *this;
}
Esempio n. 10
0
Emitter& Emitter::Write(bool b) {
  if (!good())
    return *this;

  PrepareNode(EmitterNodeType::Scalar);

  const char* name = ComputeFullBoolName(b);
  if (m_pState->GetBoolLengthFormat() == ShortBool)
    m_stream << name[0];
  else
    m_stream << name;

  StartedScalar();

  return *this;
}
Esempio n. 11
0
void NetGraph::BackPropagate(NetGraphNode* node) {
	if (!node->flag_bp_visited) {
		// Make sure all source nodes have valid gradients
		for (NetGraphBackpropConnection backprop_connection : node->backprop_connections)
			BackPropagate(backprop_connection.node);

		bool do_backprop = false;
		for (NetGraphConnection connection : node->input_connections)
			do_backprop |= connection.backprop;

		PrepareNode(node);
		node->layer->SetBackpropagationEnabled(do_backprop);
		// Call the Layer::FeedForward method and set the visited flag
		node->layer->BackPropagate();
		node->flag_bp_visited = true;
	}
}
Esempio n. 12
0
Emitter& Emitter::Write(const _Anchor& anchor) {
  if (!good())
    return *this;

  if (m_pState->HasAnchor()) {
    m_pState->SetError(ErrorMsg::INVALID_ANCHOR);
    return *this;
  }

  PrepareNode(EmitterNodeType::Property);

  if (!Utils::WriteAnchor(m_stream, anchor.content)) {
    m_pState->SetError(ErrorMsg::INVALID_ANCHOR);
    return *this;
  }

  m_pState->SetAnchor();

  return *this;
}
Esempio n. 13
0
Emitter& Emitter::Write(const _Alias& alias) {
  if (!good())
    return *this;

  if (m_pState->HasAnchor() || m_pState->HasTag()) {
    m_pState->SetError(ErrorMsg::INVALID_ALIAS);
    return *this;
  }

  PrepareNode(EmitterNodeType::Scalar);

  if (!Utils::WriteAlias(m_stream, alias.content)) {
    m_pState->SetError(ErrorMsg::INVALID_ALIAS);
    return *this;
  }

  StartedScalar();

  return *this;
}