text:
#include "htmlparser.h"

#include <boost/make_shared.hpp>
#include <regex>

namespace nc
{

boost::shared_ptr<IHtmlParser> IHtmlParser::create()
{
	return boost::make_shared<HtmlParser>();
}

class HtmlParser::impl
{
	friend class HtmlParser;

public:
	impl();

private:
	std::string buffer_;
	std::regex regex_;
};

HtmlParser::impl::impl()
	: regex_("<title>(((?!</title>).)*)(</title>)?", std::regex_constants::icase)
{

}

HtmlParser::HtmlParser()
	: pimpl_(std::make_unique<impl>())
{}

HtmlParser::~HtmlParser()
{}

std::string HtmlParser::parseTitle(const char* buffer, size_t length)
{
	// NOTE I know, regex for html and xml is bad thing, buf in this case works fine

	std::cmatch results;

	if (std::regex_search(buffer, buffer + length, results, pimpl_->regex_))
	{
		std::string closingTag = results.str(3);

		if (closingTag.empty())
			throw HtmlParserPartialTagException();

		return results.str(1);
	}

	throw HtmlParserNotFoundException();
}

}

ext: cpp

max_stars_repo_name: SteaveP/UrlTitleCollector

max_stars_repo_licenses: OpenSSL MIT

max_issues_repo_name: SteaveP/UrlTitleCollector

max_issues_repo_licenses: OpenSSL MIT

max_forks_repo_name: SteaveP/UrlTitleCollector

max_forks_repo_licenses: OpenSSL MIT


text:
/*****************************************************************************
*
* Copyright (c) 2003-2018 by The University of Queensland
* http://www.uq.edu.au
*
* Primary Business: Queensland, Australia
* Licensed under the Apache License, version 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Development until 2012 by Earth Systems Science Computational Center (ESSCC)
* Development 2012-2013 by School of Earth Sciences
* Development from 2014 by Centre for Geoscience Computing (GeoComp)
*
*****************************************************************************/

#include "DudleyDomain.h"
#include "IndexList.h"

#include <boost/scoped_array.hpp>

namespace dudley {

/// optimizes the labeling of the DOFs on each processor
void DudleyDomain::optimizeDOFLabeling(const IndexVector& distribution)
{
    // this method relies on Pattern::reduceBandwidth so requires PASO
    // at the moment
#ifdef ESYS_HAVE_PASO
    const int myRank = m_mpiInfo->rank;
    const int mpiSize = m_mpiInfo->size;
    const index_t myFirstVertex = distribution[myRank];
    const index_t myLastVertex = distribution[myRank+1];
    const dim_t myNumVertices = myLastVertex-myFirstVertex;
    dim_t len = 0;
    for (int p=0; p<mpiSize; ++p)
        len=std::max(len, distribution[p+1]-distribution[p]);

    boost::scoped_array<IndexList> index_list(new IndexList[myNumVertices]);
    boost::scoped_array<index_t> newGlobalDOFID(new index_t[len]);

    // create the adjacency structure xadj and adjncy
#pragma omp parallel
    {
        // insert contributions from element matrices into columns index
        IndexList_insertElementsWithRowRangeNoMainDiagonal(index_list.get(),
            myFirstVertex, myLastVertex, m_elements,
            m_nodes->globalDegreesOfFreedom);
        IndexList_insertElementsWithRowRangeNoMainDiagonal(index_list.get(),
            myFirstVertex, myLastVertex, m_faceElements,
            m_nodes->globalDegreesOfFreedom);
        IndexList_insertElementsWithRowRangeNoMainDiagonal(index_list.get(),
            myFirstVertex, myLastVertex, m_points,
            m_nodes->globalDegreesOfFreedom);
    }
    // create the local matrix pattern
    paso::Pattern_ptr pattern = paso::Pattern::fromIndexListArray(0,
            myNumVertices, index_list.get(), myFirstVertex, myLastVertex,
            -myFirstVertex);

    pattern->reduceBandwidth(&newGlobalDOFID[0]);

    // shift new labeling to create a global id
#pragma omp parallel for
    for (index_t i = 0; i < myNumVertices; ++i)
        newGlobalDOFID[i] += myFirstVertex;

    // distribute new labeling to other processors
#ifdef ESYS_MPI
    const int dest = m_mpiInfo->mod_rank(myRank + 1);
    const int source = m_mpiInfo->mod_rank(myRank - 1);
#endif
    int current_rank = myRank;
    for (int p = 0; p < mpiSize; ++p) {
        const index_t firstVertex = distribution[current_rank];
        const index_t lastVertex = distribution[current_rank + 1];
#pragma omp parallel for
        for (index_t i = 0; i < m_nodes->getNumNodes(); ++i) {
            const index_t k = m_nodes->globalDegreesOfFreedom[i];
            if (firstVertex <= k && k < lastVertex) {
                m_nodes->globalDegreesOfFreedom[i] =
                                            newGlobalDOFID[k-firstVertex];
            }
        }

        if (p < mpiSize - 1) { // the final send can be skipped
#ifdef ESYS_MPI
            MPI_Status status;
            MPI_Sendrecv_replace(&newGlobalDOFID[0], len, MPI_DIM_T, dest,
                                 m_mpiInfo->counter(), source,
                                 m_mpiInfo->counter(), m_mpiInfo->comm, &status);
            m_mpiInfo->incCounter();
#endif
            current_rank = m_mpiInfo->mod_rank(current_rank - 1);
        }
    }
#if 0
    for (index_t i = 0; i < m_nodes->getNumNodes(); ++i)
        std::cout << m_nodes->globalDegreesOfFreedom[i] << " ";
    std::cout << std::endl;
#endif
#endif // ESYS_HAVE_PASO
}

} // namespace dudley


text: #include <boost/preprocessor/repetition/repeat.hpp>

ext: hpp

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
// Copyright (c) 2012-2013 The Bitcoin Core developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "util.h"

#include <string>
#include <vector>

#include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>

#include <Settings.h>

struct SettingsTestContainer
{
    CopyableSettings settings;

    SettingsTestContainer(
        ): settings()
    {

    }
};

BOOST_FIXTURE_TEST_SUITE(getarg_tests, SettingsTestContainer)

static void ResetArgs(CopyableSettings& settings, const std::string& commandLineArguments)
{
    std::vector<std::string> vecArg;
    if (commandLineArguments.size())
      boost::split(vecArg, commandLineArguments, boost::is_space(), boost::token_compress_on);

    // Insert dummy executable name:
    vecArg.insert(vecArg.begin(), "testbitcoin");

    // Convert to char*:
    std::vector<const char*> vecChar;
    BOOST_FOREACH(std::string& s, vecArg)
        vecChar.push_back(s.c_str());

    settings.ParseParameters(vecChar.size(), &vecChar[0]);
}

BOOST_AUTO_TEST_CASE(boolarg)
{
    ResetArgs(settings, "-foo");
    BOOST_CHECK(settings.GetBoolArg("-foo", false));
    BOOST_CHECK(settings.GetBoolArg("-foo", true));

    BOOST_CHECK(!settings.GetBoolArg("-fo", false));
    BOOST_CHECK(settings.GetBoolArg("-fo", true));

    BOOST_CHECK(!settings.GetBoolArg("-fooo", false));
    BOOST_CHECK(settings.GetBoolArg("-fooo", true));

    ResetArgs( settings, "-foo=0");
    BOOST_CHECK(!settings.GetBoolArg("-foo", false));
    BOOST_CHECK(!settings.GetBoolArg("-foo", true));

    ResetArgs( settings, "-foo=1");
    BOOST_CHECK(settings.GetBoolArg("-foo", false));
    BOOST_CHECK(settings.GetBoolArg("-foo", true));

    // New 0.6 feature: auto-map -nosomething to !-something:
    ResetArgs( settings, "-nofoo");
    BOOST_CHECK(!settings.GetBoolArg("-foo", false));
    BOOST_CHECK(!settings.GetBoolArg("-foo", true));

    ResetArgs( settings, "-nofoo=1");
    BOOST_CHECK(!settings.GetBoolArg("-foo", false));
    BOOST_CHECK(!settings.GetBoolArg("-foo", true));

    ResetArgs( settings, "-foo -nofoo");  // -nofoo should win
    BOOST_CHECK(!settings.GetBoolArg("-foo", false));
    BOOST_CHECK(!settings.GetBoolArg("-foo", true));

    ResetArgs( settings, "-foo=1 -nofoo=1");  // -nofoo should win
    BOOST_CHECK(!settings.GetBoolArg("-foo", false));
    BOOST_CHECK(!settings.GetBoolArg("-foo", true));

    ResetArgs( settings, "-foo=0 -nofoo=0");  // -nofoo=0 should win
    BOOST_CHECK(settings.GetBoolArg("-foo", false));
    BOOST_CHECK(settings.GetBoolArg("-foo", true));

    // New 0.6 feature: treat -- same as -:
    ResetArgs( settings, "--foo=1");
    BOOST_CHECK(settings.GetBoolArg("-foo", false));
    BOOST_CHECK(settings.GetBoolArg("-foo", true));

    ResetArgs( settings, "--nofoo=1");
    BOOST_CHECK(!settings.GetBoolArg("-foo", false));
    BOOST_CHECK(!settings.GetBoolArg("-foo", true));

}

BOOST_AUTO_TEST_CASE(stringarg)
{
    ResetArgs( settings, "");
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", ""), "");
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", "eleven"), "eleven");

    ResetArgs( settings, "-foo -bar");
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", ""), "");
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", "eleven"), "");

    ResetArgs( settings, "-foo=");
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", ""), "");
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", "eleven"), "");

    ResetArgs( settings, "-foo=11");
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", ""), "11");
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", "eleven"), "11");

    ResetArgs( settings, "-foo=eleven");
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", ""), "eleven");
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", "eleven"), "eleven");

}

BOOST_AUTO_TEST_CASE(intarg)
{
    ResetArgs( settings, "");
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", 11), 11);
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", 0), 0);

    ResetArgs( settings, "-foo -bar");
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", 11), 0);
    BOOST_CHECK_EQUAL(settings.GetArg("-bar", 11), 0);

    ResetArgs( settings, "-foo=11 -bar=12");
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", 0), 11);
    BOOST_CHECK_EQUAL(settings.GetArg("-bar", 11), 12);

    ResetArgs( settings, "-foo=NaN -bar=NotANumber");
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", 1), 0);
    BOOST_CHECK_EQUAL(settings.GetArg("-bar", 11), 0);
}

BOOST_AUTO_TEST_CASE(doubledash)
{
    ResetArgs( settings, "--foo");
    BOOST_CHECK_EQUAL(settings.GetBoolArg("-foo", false), true);

    ResetArgs( settings, "--foo=verbose --bar=1");
    BOOST_CHECK_EQUAL(settings.GetArg("-foo", ""), "verbose");
    BOOST_CHECK_EQUAL(settings.GetArg("-bar", 0), 1);
}

BOOST_AUTO_TEST_CASE(boolargno)
{
    ResetArgs( settings, "-nofoo");
    BOOST_CHECK(!settings.GetBoolArg("-foo", true));
    BOOST_CHECK(!settings.GetBoolArg("-foo", false));

    ResetArgs( settings, "-nofoo=1");
    BOOST_CHECK(!settings.GetBoolArg("-foo", true));
    BOOST_CHECK(!settings.GetBoolArg("-foo", false));

    ResetArgs( settings, "-nofoo=0");
    BOOST_CHECK(settings.GetBoolArg("-foo", true));
    BOOST_CHECK(settings.GetBoolArg("-foo", false));

    ResetArgs( settings, "-foo --nofoo"); // --nofoo should win
    BOOST_CHECK(!settings.GetBoolArg("-foo", true));
    BOOST_CHECK(!settings.GetBoolArg("-foo", false));

    ResetArgs( settings, "-nofoo -foo"); // foo always wins:
    BOOST_CHECK(settings.GetBoolArg("-foo", true));
    BOOST_CHECK(settings.GetBoolArg("-foo", false));
}

BOOST_AUTO_TEST_CASE(util_ParseParameters)
{
    const char *argv_test[] = {"-ignored", "-a", "-b", "-ccc=argument", "-ccc=multiple", "f", "-d=e"};

    settings.ParseParameters(0, (char**)argv_test);
    BOOST_CHECK(settings.NumerOfParameters() == 0u && settings.NumerOfMultiParameters() == 0u);

    settings.ParseParameters(1, (char**)argv_test);
    BOOST_CHECK(settings.NumerOfParameters() == 0u && settings.NumerOfMultiParameters() == 0u);

    settings.ParseParameters(5, (char**)argv_test);
    // expectation: -ignored is ignored (program name argument),
    // -a, -b and -ccc end up in map, -d ignored because it is after
    // a non-option argument (non-GNU option parsing)
    BOOST_CHECK(settings.NumerOfParameters() == 3u && settings.NumerOfMultiParameters() == 3u);
    BOOST_CHECK(settings.ParameterIsSet("-a") && settings.ParameterIsSet("-b") && settings.ParameterIsSet("-ccc")
                && !settings.ParameterIsSet("f") && !settings.ParameterIsSet("-d"));
    BOOST_CHECK(settings.ParameterIsSetForMultiArgs("-a") && settings.ParameterIsSetForMultiArgs("-b") && settings.ParameterIsSetForMultiArgs("-ccc")
                && !settings.ParameterIsSetForMultiArgs("f") && !settings.ParameterIsSetForMultiArgs("-d"));

    BOOST_CHECK(settings.GetParameter("-a") == "" && settings.GetParameter("-ccc") == "multiple");
    BOOST_CHECK(settings.GetMultiParameter("-ccc").size() == 2);
}

BOOST_AUTO_TEST_CASE(util_GetArg)
{
    settings.SetParameter("strtest1", "string...");
    // strtest2 undefined on purpose
    settings.SetParameter("inttest1", "12345");
    settings.SetParameter("inttest2", "81985529216486895");
    // inttest3 undefined on purpose
    settings.SetParameter("booltest1", "");
    // booltest2 undefined on purpose
    settings.SetParameter("booltest3", "0");
    settings.SetParameter("booltest4", "1");

    BOOST_CHECK_EQUAL(settings.GetArg("strtest1", "default"), "string...");
    BOOST_CHECK_EQUAL(settings.GetArg("strtest2", "default"), "default");
    BOOST_CHECK_EQUAL(settings.GetArg("inttest1", -1), 12345);
    BOOST_CHECK_EQUAL(settings.GetArg("inttest2", -1), 81985529216486895LL);
    BOOST_CHECK_EQUAL(settings.GetArg("inttest3", -1), -1);
    BOOST_CHECK_EQUAL(settings.GetBoolArg("booltest1", false), true);
    BOOST_CHECK_EQUAL(settings.GetBoolArg("booltest2", false), false);
    BOOST_CHECK_EQUAL(settings.GetBoolArg("booltest3", false), false);
    BOOST_CHECK_EQUAL(settings.GetBoolArg("booltest4", false), true);
}

BOOST_AUTO_TEST_SUITE_END()


text:
#include "DisplayableGridPoints.h"

#include <osg/Geode>
#include <osg/Material>
#include <osg/Shape>
#include <osg/ShapeDrawable>

#include <boost/qvm/all.hpp>

#include "qvm_eigen.h"
#include "qvm_osg.h"
#include "GridPoints.h"

DisplayableGridPoints::DisplayableGridPoints(const GridPoints & grid, double pointSize) :
	m_grid(grid),
	m_pointSize(pointSize)
{
	// empty
}

osg::ref_ptr<osg::Group> DisplayableGridPoints::getGeometry() const
{
	osg::ref_ptr<osg::Geode> pointsGroup = new osg::Geode();

	osg::ref_ptr<osg::Material> material = new osg::Material();
	//material->setDiffuse(osg::Material::FRONT, osg::Vec4(0.5f, 0.5f, 0.5f, 1.0f));
	//material->setSpecular(osg::Material::FRONT, osg::Vec4(0.1f, 0.1f, 0.1f, 1.0f));
	//material->setAmbient(osg::Material::FRONT, osg::Vec4(0.5f, 0.5f, 0.5f, 1.0f));
	material->setEmission(osg::Material::FRONT, osg::Vec4(0.7f, 0.0f, 0.0f, 1.0f));
	//material->setShininess(osg::Material::FRONT, 25.0);

	pointsGroup->getOrCreateStateSet()->setAttribute(material);

	for (const auto & v : m_grid.getPoints())
	{
		const osg::Vec3 position = boost::qvm::convert_to<osg::Vec3>(v.get());

		osg::ref_ptr<osg::Sphere> sphere = new osg::Sphere(position, m_pointSize);
		osg::ref_ptr<osg::ShapeDrawable> sd = new osg::ShapeDrawable(sphere);

		sd->setColor(osg::Vec4(1, 1, 0, 0.5));

		pointsGroup->addDrawable(sd);
	}

	return pointsGroup;
}

max_stars_repo_name: MatthiasMichael/SparsityDrivenDetector

max_issues_repo_name: MatthiasMichael/SparsityDrivenDetector

max_forks_repo_name: MatthiasMichael/SparsityDrivenDetector


text:
/*
 * Copyright 2014 Open Connectome Project (http://openconnecto.me)
 * Written by Da Zheng (zhengda1936@gmail.com)
 *
 * This file is part of FlashMatrix.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <boost/format.hpp>

#include "common.h"
#include "thread.h"

#include "vector.h"
#include "data_frame.h"
#include "local_vec_store.h"
#include "mem_worker_thread.h"
#include "dense_matrix.h"
#include "bulk_operate_ext.h"
#include "local_matrix_store.h"
#include "dense_matrix.h"

namespace fm
{

vector::ptr vector::create(size_t length, const scalar_type &type,
		int num_nodes, bool in_mem, const set_vec_operate &op)
{
	detail::vec_store::ptr vec = detail::vec_store::create(length, type,
			num_nodes, in_mem);
	vec->set_data(op);
	return ptr(new vector(vec));
}

bool vector::verify_groupby(
		const gr_apply_operate<local_vec_store> &op) const
{
	if (op.get_key_type() != get_type()) {
		BOOST_LOG_TRIVIAL(error)
			<< "the operator's key type is incompatible with the vector";
		return false;
	}

	return true;
}

namespace
{

class local_groupby_task: public thread_task
{
	local_vec_store::const_ptr sub_vec;
	const gr_apply_operate<local_vec_store> &op;
	std::vector<data_frame::ptr> &sub_results;
	bool with_val;
	off_t idx;
public:
	local_groupby_task(local_vec_store::const_ptr sub_vec,
			const gr_apply_operate<local_vec_store> &_op,
			bool with_val, std::vector<data_frame::ptr> &_sub_results,
			off_t idx): op(_op), sub_results(_sub_results) {
		this->sub_vec = sub_vec;
		this->with_val = with_val;
		this->idx = idx;
	}

	void run() {
		sub_results[idx] = sub_vec->groupby(op, with_val);
	}
};

}

/*
 * Partition the vector into multiple partitions of relatively equal size.
 * It is guaranteed that the same values are all split into the same partition.
 * It returns a vector with `num_parts' + 1 elements. Each element except
 * the last indicates the start location of a partition in the vector.
 * The last element indicates the end of the vector.
 */
std::vector<off_t> partition_vector(const detail::mem_vec_store &sorted_vec,
		int num_parts)
{
	agg_operate::const_ptr find_next
		= sorted_vec.get_type().get_agg_ops().get_find_next();
	std::vector<off_t> par_starts(num_parts + 1);
	for (int i = 0; i < num_parts; i++) {
		off_t start = sorted_vec.get_length() / num_parts * i;
		// This returns the relative start location of the next value.
		find_next->runAgg(sorted_vec.get_length() - start,
				sorted_vec.get_raw_arr() + sorted_vec.get_entry_size() * start,
				&par_starts[i]);
		// This is the absolute start location of this partition.
		par_starts[i] += start;
	}
	par_starts[0] = 0;
	par_starts[num_parts] = sorted_vec.get_length();
	return par_starts;
}

data_frame::ptr vector::groupby(
		const gr_apply_operate<local_vec_store> &op, bool with_val) const
{
	if (!verify_groupby(op))
		return data_frame::ptr();

	// If the vector hasn't been sorted, we need to sort it.
	detail::mem_vec_store::const_ptr sorted_vec;
	if (!this->is_sorted()) {
		// We don't want groupby changes the original vector.
		detail::vec_store::ptr tmp = get_data().deep_copy();
		tmp->sort();
		sorted_vec = detail::mem_vec_store::cast(tmp);
	}
	else
		sorted_vec = detail::mem_vec_store::cast(this->get_raw_store());

	// We need to find the start location for each thread.
	// The start location is where the value in the sorted array
	// first appears.
	// TODO this only works for vectors stored contiguously in memory.
	// It doesn't work for NUMA vector.
	detail::mem_thread_pool::ptr mem_threads
		= detail::mem_thread_pool::get_global_mem_threads();
	int num_threads = mem_threads->get_num_threads();
	std::vector<off_t> par_starts = partition_vector(*sorted_vec, num_threads);

	// It's possible that two partitions end up having the same start location
	// because the vector is small or a partition has only one value.
	assert(std::is_sorted(par_starts.begin(), par_starts.end()));
	auto end_par_starts = std::unique(par_starts.begin(), par_starts.end());
	int num_parts = end_par_starts - par_starts.begin() - 1;
	std::vector<data_frame::ptr> sub_results(num_parts);
	for (int i = 0; i < num_parts; i++) {
		off_t start = par_starts[i];
		off_t end = par_starts[i + 1];
		local_vec_store::const_ptr sub_vec = sorted_vec->get_portion(
				start, end - start);

		int node_id = sub_vec->get_node_id();
		if (node_id < 0)
			node_id = i % mem_threads->get_num_nodes();
		mem_threads->process_task(node_id, new local_groupby_task(sub_vec, op,
					with_val, sub_results, i));
	}
	mem_threads->wait4complete();

	if (num_parts == 1)
		return sub_results[0];
	else {
		std::vector<data_frame::const_ptr> const_sub_results(
				sub_results.begin(), sub_results.end());
		return merge_data_frame(const_sub_results, true);
	}
}

bool vector::equals(const vector &vec) const
{
	if (vec.get_length() != this->get_length())
		return false;
	else if (vec.get_type() != this->get_type())
		return false;
	else {
		assert(is_in_mem());
		const detail::mem_vec_store &v1
			= dynamic_cast<const detail::mem_vec_store &>(get_data());
		const detail::mem_vec_store &v2
			= dynamic_cast<const detail::mem_vec_store &>(vec.get_data());
		size_t portion_size = std::min(v1.get_portion_size(),
				v2.get_portion_size());
		for (size_t idx = 0; idx < v1.get_length(); idx += portion_size) {
			size_t llen = std::min(v1.get_length() - idx, portion_size);
			if (memcmp(v1.get_sub_arr(idx, idx + llen),
						v2.get_sub_arr(idx, idx + llen),
						llen * get_entry_size()) != 0)
				return false;
		}
		return true;
	}
}

namespace
{

class local_agg_task: public thread_task
{
	local_vec_store::const_ptr sub_vec;
	const bulk_operate &op;
	char *agg_res;
public:
	local_agg_task(local_vec_store::const_ptr sub_vec,
			const bulk_operate &_op, char *agg_res): op(_op) {
		this->sub_vec = sub_vec;
		this->agg_res = agg_res;
	}

	void run() {
		op.runAgg(sub_vec->get_length(), sub_vec->get_raw_arr(), agg_res);
	}
};

}

scalar_variable::ptr vector::aggregate(const bulk_operate &op) const
{
	scalar_variable::ptr res = op.get_output_type().create_scalar();
	size_t num_portions = get_data().get_num_portions();
	size_t portion_size = get_data().get_portion_size();
	// TODO we don't need to allocate a slot for every portion.
	std::unique_ptr<char[]> raw_res(new char[res->get_size() * num_portions]);

	detail::mem_thread_pool::ptr mem_threads
		= detail::mem_thread_pool::get_global_mem_threads();
	for (size_t i = 0; i < num_portions; i++) {
		off_t start = i * portion_size;
		size_t length = std::min(portion_size, get_length() - start);
		local_vec_store::const_ptr sub_vec
			= static_cast<const detail::mem_vec_store &>(
					get_data()).get_portion(start, length);

		int node_id = sub_vec->get_node_id();
		if (node_id < 0)
			node_id = i % mem_threads->get_num_nodes();
		mem_threads->process_task(node_id, new local_agg_task(sub_vec, op,
					raw_res.get() + i * res->get_size()));
	}
	mem_threads->wait4complete();
	char final_res[res->get_size()];
	op.runAgg(num_portions, raw_res.get(), final_res);
	res->set_raw(final_res, res->get_size());
	return res;
}

scalar_variable::ptr vector::dot_prod(const vector &vec) const
{
	if (get_type() != vec.get_type()) {
		BOOST_LOG_TRIVIAL(error) << "The type isn't compatible";
		return scalar_variable::ptr();
	}

	if (get_length() != vec.get_length()) {
		BOOST_LOG_TRIVIAL(error) << "The two vectors have different lengths";
		return scalar_variable::ptr();
	}

#if 0
	const bulk_operate &multiply = get_type().get_basic_ops().get_multiply();
	const bulk_operate &add = get_type().get_basic_ops().get_add();
	std::vector<size_t> local_lens = mapper.cal_local_lengths(get_length());
	std::unique_ptr<char[]> agg_buf(new char[data.size() * get_entry_size()]);
	// TODO this is a very inefficient implementation.
	for (size_t i = 0; i < data.size(); i++) {
		std::unique_ptr<char[]> multiply_buf(
				new char[local_lens[i] * get_entry_size()]);
		multiply.runAA(local_lens[i], data[i].get_raw(), vec.data[i].get_raw(),
				multiply_buf.get());
		add.runA(local_lens[i], multiply_buf.get(),
				agg_buf.get() + get_entry_size() * i);
	}
	char final_agg[get_entry_size()];
	add.runA(data.size(), agg_buf.get(), final_agg);
#endif

	scalar_variable::ptr res = get_type().create_scalar();
#if 0
	res->set_raw(final_agg, get_entry_size());
#endif

	return res;
}

vector::ptr vector::sort(bool decreasing) const
{
	// TODO it's unnecessary to copy first and sort.
	detail::vec_store::ptr vec = get_data().deep_copy();
	vec->sort();
	return vector::create(vec);
}

data_frame::ptr vector::sort_with_index(bool decreasing) const
{
	detail::vec_store::ptr vec = get_data().deep_copy();
	detail::vec_store::ptr idx = vec->sort_with_index();
	data_frame::ptr df = data_frame::create();
	df->add_vec("idx", idx);
	df->add_vec("val", vec);
	return df;
}

dense_matrix::ptr vector::conv2mat(size_t nrow, size_t ncol,
		bool byrow) const
{
	detail::matrix_store::const_ptr mat = get_data().conv2mat(nrow, ncol, byrow);
	if (mat == NULL)
		return dense_matrix::ptr();
	return dense_matrix::create(mat);
}

bool vector::export2(FILE *f) const
{
	if (!is_in_mem()) {
		BOOST_LOG_TRIVIAL(error)
			<< "Doesn't support to write an EM vector to a file";
		return false;
	}

	size_t ret = fwrite(
			dynamic_cast<const detail::mem_vec_store &>(get_data()).get_raw_arr(),
			get_length() * get_type().get_size(), 1, f);
	if (ret == 0) {
		BOOST_LOG_TRIVIAL(error) << boost::format(
				"can't write, error: %1%") % strerror(errno);
		return false;
	}
	return true;
}

}


text:
/*=============================================================================
    Copyright (c) 2001-2011 Joel de Guzman
    Copyright (c) 2007 Dan Marsden

    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#if !defined(FUSION_ALL_05052005_1237)
#define FUSION_ALL_05052005_1237

#include <boost/fusion/support/config.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/sequence/intrinsic/end.hpp>
#include <boost/fusion/iterator/advance.hpp>
#include <boost/fusion/iterator/equal_to.hpp>
#include <boost/fusion/iterator/next.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <boost/fusion/iterator/distance.hpp>

namespace boost { namespace fusion { namespace detail
{
    template <typename First, typename Last, typename F>
    BOOST_FUSION_GPU_ENABLED
    inline bool
    linear_all(First const&, Last const&, F const&, mpl::true_)
    {
        return true;
    }

    template <typename First, typename Last, typename F>
    BOOST_FUSION_GPU_ENABLED
    inline bool
    linear_all(First const& first, Last const& last, F& f, mpl::false_)
    {
        typename result_of::deref<First>::type x = *first;
        return f(x) &&
            detail::linear_all(
                fusion::next(first)
              , last
              , f
              , result_of::equal_to<typename result_of::next<First>::type, Last>());
    }

    template <typename Sequence, typename F, typename Tag>
    BOOST_FUSION_GPU_ENABLED
    inline bool
    all(Sequence const& seq, F f, Tag)
    {
        return detail::linear_all(
                fusion::begin(seq)
              , fusion::end(seq)
              , f
              , result_of::equal_to<
                    typename result_of::begin<Sequence>::type
                  , typename result_of::end<Sequence>::type>());
    }

    template<int N>
    struct unrolled_all
    {
        template <typename It, typename F>
        BOOST_FUSION_GPU_ENABLED
        static bool call(It const& it, F f)
        {
            return
                f(*it) &&
                f(*fusion::advance_c<1>(it))&&
                f(*fusion::advance_c<2>(it)) &&
                f(*fusion::advance_c<3>(it)) &&
                detail::unrolled_all<N-4>::call(fusion::advance_c<4>(it), f);
        }
    };

    template<>
    struct unrolled_all<3>
    {
        template <typename It, typename F>
        BOOST_FUSION_GPU_ENABLED
        static bool call(It const& it, F f)
        {
            return
                f(*it) &&
                f(*fusion::advance_c<1>(it)) &&
                f(*fusion::advance_c<2>(it));
        }
    };

    template<>
    struct unrolled_all<2>
    {
        template <typename It, typename F>
        BOOST_FUSION_GPU_ENABLED
        static bool call(It const& it, F f)
        {
            return
                f(*it) &&
                f(*fusion::advance_c<1>(it));
        }
    };

    template<>
    struct unrolled_all<1>
    {
        template <typename It, typename F>
        BOOST_FUSION_GPU_ENABLED
        static bool call(It const& it, F f)
        {
            return f(*it);
        }
    };

    template<>
    struct unrolled_all<0>
    {
        template <typename It, typename F>
        BOOST_FUSION_GPU_ENABLED
        static bool call(It const& /*it*/, F /*f*/)
        {
            return true;
        }
    };

    template <typename Sequence, typename F>
    BOOST_FUSION_GPU_ENABLED
    inline bool
    all(Sequence const& seq, F f, random_access_traversal_tag)
    {
        typedef typename result_of::begin<Sequence>::type begin;
        typedef typename result_of::end<Sequence>::type end;
        return detail::unrolled_all<result_of::distance<begin, end>::type::value>::call(
            fusion::begin(seq), f);
    }
}}}

#endif


text:
#include "gtest/gtest.h"

#include <ysu/node/common.hpp>
#include <ysu/node/logging.hpp>

#include <boost/filesystem/path.hpp>

namespace ysu
{
void cleanup_dev_directories_on_exit ();
void force_ysu_dev_network ();
boost::filesystem::path unique_path ();
}

GTEST_API_ int main (int argc, char ** argv)
{
	printf ("Running main() from core_test_main.cc\n");
	ysu::force_ysu_dev_network ();
	ysu::node_singleton_memory_pool_purge_guard memory_pool_cleanup_guard;
	// Setting up logging so that there aren't any piped to standard output.
	ysu::logging logging;
	logging.init (ysu::unique_path ());
	testing::InitGoogleTest (&argc, argv);
	auto res = RUN_ALL_TESTS ();
	ysu::cleanup_dev_directories_on_exit ();
	return res;
}

ext: cc


text:
#ifndef MUSE_MCL_2D_GRIDMAPS_LASER_CONVEX_HULL_HPP
#define MUSE_MCL_2D_GRIDMAPS_LASER_CONVEX_HULL_HPP

#include <cslibs_plugins_data/types/laserscan.hpp>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)

namespace muse_mcl_2d_gridmaps {
namespace utilty {
namespace bg = boost::geometry;

struct Point
{
    Point(double x = 0, double y = 0, std::size_t index = 0) :
        x(x),
        y(y),
        index(index)
    {
    }

    Point(const Eigen::Vector2d &p, const std::size_t index) :
      x(p(0)),
      y(p(1)),
      index(index)
    {
    }

    double      x;
    double      y;
    std::size_t index;
} __attribute__ ((aligned (32)));

using polygon_t = boost::geometry::model::polygon<Point>;
using rays_t    = cslibs_plugins_data::types::Laserscan2::rays_t;
using ray_t     = cslibs_plugins_data::types::Laserscan2::Ray;
using laserscan_t = cslibs_plugins_data::types::Laserscan2;

inline void convexHull(const laserscan_t& scan,
                       std::vector<std::size_t> &indices)
{
    const rays_t rays = scan.getRays();
    const std::size_t size = rays.size();
    const double range_min = scan.getLinearMin();
    const double range_max = scan.getLinearMax();
    const double angle_min = scan.getAngularMin();
    const double angle_max = scan.getAngularMax();

    auto valid = [range_min, range_max, angle_min, angle_max](const ray_t &r){
        return r.valid()
            && r.angle >= angle_min && r.angle <= angle_max
            && r.range >= range_min && r.range <= range_max;
    };

    polygon_t scan_poly;
    polygon_t hull_poly;
    scan_poly.outer().reserve(size);
    for(std::size_t i = 0 ; i < size ; ++i) {
        const auto &r = rays[i];
        if(valid(r)) {
            scan_polygon.outer().emplace_back(Point(r.end_point(), i));
        }
    }
    boost::geometry::convex_hull(scan_poly, hull_poly);

    indices.reserve(hull_poly.outer().size());
    for(const auto &p : hull_poly.outer()) {
      indices.emplace_back(p.index);
    }
}
}

#endif // MUSE_MCL_2D_GRIDMAPS_LASER_CONVEX_HULL_HPP