<commit_before>/*
 * This file is part of the CN24 semantic segmentation software,
 * copyright (C) 2015 <NAME> (ikosa dot de at gmail dot com).
 *
 * For licensing information, see the LICENSE file included with this project.
 */

#include <sstream>
#include "Log.h"

#include "NetGraph.h"

namespace Conv {

void NetGraph::AddNode(NetGraphNode* node) {
	if (node == nullptr) {
		LOGERROR << "Tried to add null-pointer node!";
		return;
	}
	node->unique_id = ++last_uid;
	nodes_.push_back(node);
}

bool NetGraph::IsComplete() const {
	bool is_complete = true;
	for (NetGraphNode* node : nodes_) {
		bool node_okay = true;
		if (node != nullptr) {
			if (node->layer != nullptr) {
				for (NetGraphConnection connection : node->input_connections) {
					if (connection.node != nullptr) {
						if (std::find(nodes_.begin(), nodes_.end(), node) == nodes_.end()) {
							LOGWARN << "Node has out-of-network connection: " << node->layer->GetLayerDescription();
						}
						else {
							if (connection.buffer >= connection.node->output_buffers.size()) {
								LOGWARN << "Node's connection points to invalid buffer: " << node->layer->GetLayerDescription();
								node_okay = false;
							}
						}
					}
					else {
						LOGWARN << "Node has null-pointer connection: " << node->layer->GetLayerDescription();
						node_okay = false;
					}
				}
			}<commit_msg>NetGraph: Added null-layer check and custom node UID to AddNode()<commit_after>/*
 * This file is part of the CN24 semantic segmentation software,
 * copyright (C) 2015 <NAME> (ikosa dot de at gmail dot com).
 *
 * For licensing information, see the LICENSE file included with this project.
 */

#include <sstream>
#include "Log.h"

#include "NetGraph.h"

namespace Conv {

void NetGraph::AddNode(NetGraphNode* node) {
	// Validate node
	if (node == nullptr)
		FATAL("Tried to add null-pointer node!");

	if (node->layer == nullptr)
		FATAL("Tried to add layerless node!");

	// We don't check the node's connections at this time because we can't expect
	// the user to sort the nodes before adding. NetGraph::IsComplete() contains
	// all necessary checks.

	// Assign the node a new unique ID if it doesn't have one already
	if (node->unique_id == -1)
		node->unique_id = ++last_uid;

	nodes_.push_back(node);
}

bool NetGraph::IsComplete() const {
	bool is_complete = true;
	for (NetGraphNode* node : nodes_) {
		bool node_okay = true;
		if (node != nullptr) {
			if (node->layer != nullptr) {
				for (NetGraphConnection connection : node->input_connections) {
					if (connection.node != nullptr) {
						if (std::find(nodes_.begin(), nodes_.end(), node) == nodes_.end()) {
							LOGWARN << "Node has out-of-network connection: " << node->layer->GetLayerDescription();
						}
						else {
							if (connection.buffer >= connection.node->output_buffers.size()) {
								LOGWARN << "Node's connection points to invalid buffer: " << node->layer->GetLayerDescription();
								node_okay = false;
							}
						}
					}
					else {
						LOGWARN << "Node has null-pointer connection: " << node->layer->GetLayerDescription();
						node_okay = false;
					}
				}
			}
{'fraction_non_alphanumeric': 0.13553929366846962, 'fraction_numerical': 0.004136175628380528, 'mean_word_length': 3.242914979757085, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1737634', 'n_tokens_mistral': 1171, 'n_tokens_neox': 952, 'n_words': 293}