<commit_before>/*
 * DynamicMat.cpp
 *
 *  Created on: Nov 10, 2013
 *      Author: andresf
 */

#include <stdexcept>

#include <DynamicMat.hpp>
#include <FileUtils.hpp>

// --------------------------------------------------------------------------

DynamicMat::DynamicMat() :
		m_descriptorsIndex(DEFAULT_INDICES), m_descriptorsFilenames(
				DEFAULT_FILENAMES), m_cachedMat(cv::Mat()), m_cachedMatStartIdx(
				-1), m_memoryCount(0), m_descriptorType(-1), rows(0), cols(0) {
#if DYNMATVERBOSE
	printf("[DynamicMat] Initializing empty\n");
#endif
}

// --------------------------------------------------------------------------

DynamicMat::DynamicMat(const DynamicMat& other) {

#if DYNMATVERBOSE
	printf("[DynamicMat] Initializing by copy\n");
#endif

	m_descriptorsIndex = other.getDescriptorsIndex();
	m_descriptorsFilenames = other.getDescriptorsFilenames();
	std::vector<cv::Mat>(m_descriptorsIndex.size(), cv::Mat()).swap(
			m_descriptorsCache);
	m_cachedMat = cv::Mat();
	m_cachedMatStartIdx = -1;
	m_cachingOrder = std::queue<int>();
	m_memoryCount = other.m_memoryCount;
	m_descriptorType = other.type();
	rows = other.rows;
	cols = other.cols;
}

// --------------------------------------------------------------------------

DynamicMat& DynamicMat::operator=(const DynamicMat& other) {

#if DYNMATVERBOSE
	printf("[DynamicMat] Initializing by assignment\n");
#endif

	m_descriptorsIndex = other.getDescriptorsIndex();
	m_descriptorsFilenames = other.getDescriptorsFilenames();
	std::vector<cv::Mat>(m_descriptorsIndex.size(), cv::Mat()).swap(
			m_descriptorsCache);
	m_cachedMat = cv::Mat();
	m_cachedMatStartIdx = -1;
	m_cachingOrder = std::queue<int>();
	m_memoryCount = other.m_memoryCount;
	m_descriptorType = other.type();
	rows = other.rows;
	cols = other.cols;

	return *this;
}

// --------------------------------------------------------------------------

DynamicMat::DynamicMat(std::vector<std::string>& descriptorsFilenames) :
		m_descriptorsFilenames(descriptorsFilenames), m_cachedMatStartIdx(-1) {

#if DYNMATVERBOSE
	printf("[DynamicMat] Initializing using filenames\n");
#endif

	cv::Mat imgDescriptors;

	m_descriptorsIndex.clear();

	int descCount = 0, descLen = 0, descType = -1, imgIdx = 0;

	double mytime = cv::getTickCount();

	// Initialize descriptors index
	for (std::string descriptorsFilename : descriptorsFilenames) {

#if DYNMATVERBOSE
		printf("[DynamicMat] Loading descriptors file [%d/%lu]\n", imgIdx + 1, descriptorsFilenames.size());
#endif

		// Clear descriptors matrix
		imgDescriptors = cv::Mat();

		// Load descriptors
		FileUtils::loadDescriptors(descriptorsFilename, imgDescriptors);

		if (imgDescriptors.empty() == false) {
			for (size_t i = 0; (int) i < imgDescriptors.rows; i++) {
				image img;
				img.imgIdx = imgIdx;
				img.startIdx = descCount;
				m_descriptorsIndex.push_back(img);
			}
			// Increase descriptors counter
			descCount += imgDescriptors.rows;

			// If initialized check descriptors length
			if (descLen != 0) {
				// Recall that all descriptors must be of the same length
				CV_Assert(descLen == imgDescriptors.cols);
			} else {
				descLen = imgDescriptors.cols;
			}<commit_msg>Common/src/DynamicMat.cpp * Removed preprocessor directive controlling compilation of output status message.<commit_after>/*
 * DynamicMat.cpp
 *
 *  Created on: Nov 10, 2013
 *      Author: andresf
 */

#include <stdexcept>

#include <DynamicMat.hpp>
#include <FileUtils.hpp>

// --------------------------------------------------------------------------

DynamicMat::DynamicMat() :
		m_descriptorsIndex(DEFAULT_INDICES), m_descriptorsFilenames(
				DEFAULT_FILENAMES), m_cachedMat(cv::Mat()), m_cachedMatStartIdx(
				-1), m_memoryCount(0), m_descriptorType(-1), rows(0), cols(0) {
#if DYNMATVERBOSE
	printf("[DynamicMat] Initializing empty\n");
#endif
}

// --------------------------------------------------------------------------

DynamicMat::DynamicMat(const DynamicMat& other) {

#if DYNMATVERBOSE
	printf("[DynamicMat] Initializing by copy\n");
#endif

	m_descriptorsIndex = other.getDescriptorsIndex();
	m_descriptorsFilenames = other.getDescriptorsFilenames();
	std::vector<cv::Mat>(m_descriptorsIndex.size(), cv::Mat()).swap(
			m_descriptorsCache);
	m_cachedMat = cv::Mat();
	m_cachedMatStartIdx = -1;
	m_cachingOrder = std::queue<int>();
	m_memoryCount = other.m_memoryCount;
	m_descriptorType = other.type();
	rows = other.rows;
	cols = other.cols;
}

// --------------------------------------------------------------------------

DynamicMat& DynamicMat::operator=(const DynamicMat& other) {

#if DYNMATVERBOSE
	printf("[DynamicMat] Initializing by assignment\n");
#endif

	m_descriptorsIndex = other.getDescriptorsIndex();
	m_descriptorsFilenames = other.getDescriptorsFilenames();
	std::vector<cv::Mat>(m_descriptorsIndex.size(), cv::Mat()).swap(
			m_descriptorsCache);
	m_cachedMat = cv::Mat();
	m_cachedMatStartIdx = -1;
	m_cachingOrder = std::queue<int>();
	m_memoryCount = other.m_memoryCount;
	m_descriptorType = other.type();
	rows = other.rows;
	cols = other.cols;

	return *this;
}

// --------------------------------------------------------------------------

DynamicMat::DynamicMat(std::vector<std::string>& descriptorsFilenames) :
		m_descriptorsFilenames(descriptorsFilenames), m_cachedMatStartIdx(-1) {

#if DYNMATVERBOSE
	printf("[DynamicMat] Initializing using filenames\n");
#endif

	cv::Mat imgDescriptors;

	m_descriptorsIndex.clear();

	int descCount = 0, descLen = 0, descType = -1, imgIdx = 0;

	double mytime = cv::getTickCount();

	// Initialize descriptors index
	for (std::string descriptorsFilename : descriptorsFilenames) {

		printf("[DynamicMat] Loading descriptors file [%d/%lu]\n", imgIdx + 1,
				descriptorsFilenames.size());

		// Clear descriptors matrix
		imgDescriptors = cv::Mat();

		// Load descriptors
		FileUtils::loadDescriptors(descriptorsFilename, imgDescriptors);

		if (imgDescriptors.empty() == false) {
			for (size_t i = 0; (int) i < imgDescriptors.rows; i++) {
				image img;
				img.imgIdx = imgIdx;
				img.startIdx = descCount;
				m_descriptorsIndex.push_back(img);
			}
			// Increase descriptors counter
			descCount += imgDescriptors.rows;

			// If initialized check descriptors length
			if (descLen != 0) {
				// Recall that all descriptors must be of the same length
				CV_Assert(descLen == imgDescriptors.cols);
			} else {
				descLen = imgDescriptors.cols;
			}
{'fraction_non_alphanumeric': 0.21573208722741433, 'fraction_numerical': 0.0065420560747663555, 'mean_word_length': 3.1002554278416348, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, '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': '206752', 'n_tokens_mistral': 2156, 'n_tokens_neox': 2021, 'n_words': 398}