text:
/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2015 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#ifndef MAPNIK_WELL_KNOWN_SRS_HPP
#define MAPNIK_WELL_KNOWN_SRS_HPP

// mapnik
#include <mapnik/global.hpp> // for M_PI on windows
#include <mapnik/enumeration.hpp>
#include <mapnik/geometry.hpp>

#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/optional.hpp>
#pragma GCC diagnostic pop

// stl
#include <cmath>

namespace mapnik {

enum well_known_srs_enum : std::uint8_t {
    WGS_84,
    G_MERC,
    well_known_srs_enum_MAX
};

DEFINE_ENUM( well_known_srs_e, well_known_srs_enum );

static const double EARTH_RADIUS = 6378137.0;
static const double EARTH_DIAMETER = EARTH_RADIUS * 2.0;
static const double EARTH_CIRCUMFERENCE = EARTH_DIAMETER * M_PI;
static const double MAXEXTENT = EARTH_CIRCUMFERENCE / 2.0;
static const double M_PI_by2 = M_PI / 2;
static const double D2R = M_PI / 180;
static const double R2D = 180 / M_PI;
static const double M_PIby360 = M_PI / 360;
static const double MAXEXTENTby180 = MAXEXTENT / 180;
static const double MAX_LATITUDE = R2D * (2 * std::atan(std::exp(180 * D2R)) - M_PI_by2);
static const std::string MAPNIK_LONGLAT_PROJ = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";
static const std::string MAPNIK_GMERC_PROJ = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over";

boost::optional<well_known_srs_e> is_well_known_srs(std::string const& srs);

boost::optional<bool> is_known_geographic(std::string const& srs);

static inline bool lonlat2merc(double * x, double * y , int point_count)
{
    for(int i=0; i<point_count; ++i)
    {
        if (x[i] > 180) x[i] = 180;
        else if (x[i] < -180) x[i] = -180;
        if (y[i] > MAX_LATITUDE) y[i] = MAX_LATITUDE;
        else if (y[i] < -MAX_LATITUDE) y[i] = -MAX_LATITUDE;
        x[i] = x[i] * MAXEXTENTby180;
        y[i] = std::log(std::tan((90 + y[i]) * M_PIby360)) * R2D;
        y[i] = y[i] * MAXEXTENTby180;
    }
    return true;
}

static inline bool merc2lonlat(double * x, double * y , int point_count)
{
    for(int i=0; i<point_count; i++)
    {
        if (x[i] > MAXEXTENT) x[i] = MAXEXTENT;
        else if (x[i] < -MAXEXTENT) x[i] = -MAXEXTENT;
        if (y[i] > MAXEXTENT) y[i] = MAXEXTENT;
        else if (y[i] < -MAXEXTENT) y[i] = -MAXEXTENT;
        x[i] = (x[i] / MAXEXTENT) * 180;
        y[i] = (y[i] / MAXEXTENT) * 180;
        y[i] = R2D * (2 * std::atan(std::exp(y[i] * D2R)) - M_PI_by2);
    }
    return true;
}

static inline bool lonlat2merc(geometry::line_string<double> & ls)
{
    for(auto & p : ls)
    {
        if (p.x > 180) p.x = 180;
        else if (p.x < -180) p.x = -180;
        if (p.y > MAX_LATITUDE) p.y = MAX_LATITUDE;
        else if (p.y < -MAX_LATITUDE) p.y = -MAX_LATITUDE;
        p.x = p.x * MAXEXTENTby180;
        p.y = std::log(std::tan((90 + p.y) * M_PIby360)) * R2D;
        p.y = p.y * MAXEXTENTby180;
    }
    return true;
}

static inline bool merc2lonlat(geometry::line_string<double> & ls)
{
    for (auto & p : ls)
    {
        if (p.x > MAXEXTENT) p.x = MAXEXTENT;
        else if (p.x < -MAXEXTENT) p.x = -MAXEXTENT;
        if (p.y > MAXEXTENT) p.y = MAXEXTENT;
        else if (p.y < -MAXEXTENT) p.y = -MAXEXTENT;
        p.x = (p.x / MAXEXTENT) * 180;
        p.y = (p.y / MAXEXTENT) * 180;
        p.y = R2D * (2 * std::atan(std::exp(p.y * D2R)) - M_PI_by2);
    }
    return true;
}

}

#endif // MAPNIK_WELL_KNOWN_SRS_HPP


text:
#ifndef RISCV_VP_WS2812SERVER_H
#define RISCV_VP_WS2812SERVER_H

#include <atomic>
#include <boost/asio.hpp>
#include <thread>

struct LED{
	uint8_t port;
	uint64_t lastRisingEdgeCycle;
	uint64_t lastFallingEdgeCycle;
	std::vector<bool> ledbits;
	bool latch = true;

};

class WS2812Server{
   public:
	WS2812Server();
	~WS2812Server();
	void notifyEdge(int port, bool isRising, uint64_t cycle);
	void cycleUpdate(uint64_t cycle);

private:
	boost::asio::io_service m_io_service;
	boost::asio::ip::tcp::acceptor m_acceptor;
	boost::asio::ip::tcp::socket m_socket;
	std::unique_ptr<std::thread> m_thread;
	std::atomic<bool> m_stop;
	bool checkinRange(uint16_t value, uint16_t lower, uint16_t upper);
	int sendLEDs(uint32_t pin, std::vector<uint8_t> leds);
	std::vector<uint8_t> bufferFromLED(LED led);
	std::map<uint8_t, LED> m_LEDs;
	static uint8_t const BIT_PER_BYTE = 8;
	static uint8_t const BYTE_PER_PIXEL = 3;

	static uint8_t const T0H_MIN = 8;
	static uint8_t const T0H_MAX = 10;

	static uint8_t const T0L_MIN = 15;
	static uint8_t const T0L_MAX = 19;

	static uint8_t const T1H_MIN = 15;
	static uint8_t const T1H_MAX = 19;

	static uint8_t const T1L_MIN = 8;
	static uint8_t const T1L_MAX = 10;

	static uint16_t const LATCH_MIN = 1050;
	static uint16_t const DIFF_PIXEL_MAX= 200;

};

#endif  // RISCV_VP_FREQMODSERVER_H

ext: hpp


text: #include <boost/cstdlib.hpp>

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
#include <sstream>
#include <string>
#include <vector>

class Example {
public:
    Example() {}
    void add(const std::string& s)
    {
        mS.push_back(s);
    }

    std::vector<std::string>::iterator begin()
    {
        return mS.begin();
    }
    std::vector<std::string>::iterator end()
    {
        return mS.end();
    }

private:
    std::vector<std::string> mS;
};

#include <boost/python.hpp>
using namespace boost::python;

BOOST_PYTHON_MODULE(iterators)
{
    class_<Example>("Example")
        .def("strings", range(&Example::begin, &Example::end))
        .def("add", &Example::add)
    ;
}

ext: cpp

max_stars_repo_name: SafinaM/boost-python-examples

max_issues_repo_name: SafinaM/boost-python-examples

max_forks_repo_name: SafinaM/boost-python-examples


text:
#ifndef ENGINE_GUIDANCE_SEGMENT_LIST_HPP_
#define ENGINE_GUIDANCE_SEGMENT_LIST_HPP_

#include "osrm/coordinate.hpp"

#include "engine/douglas_peucker.hpp"
#include "engine/internal_route_result.hpp"
#include "engine/phantom_node.hpp"
#include "engine/segment_information.hpp"
#include "util/integer_range.hpp"
#include "util/coordinate_calculation.hpp"
#include "util/for_each_pair.hpp"
#include "extractor/turn_instructions.hpp"

#include <boost/assert.hpp>

#include <cmath>
#include <cstdint>
#include <cstddef>
#include <limits>
#include <vector>

// transfers the internal edge based data structures to a more useable format
namespace osrm
{
namespace engine
{
namespace guidance
{
template <typename DataFacadeT> class SegmentList
{
  public:
    using DataFacade = DataFacadeT;
    SegmentList(const InternalRouteResult &raw_route,
                const bool extract_alternative,
                const unsigned zoom_level,
                const bool allow_simplification,
                const DataFacade *facade);

    const std::vector<std::uint32_t> &GetViaIndices() const;
    std::uint32_t GetDistance() const;
    std::uint32_t GetDuration() const;

    const std::vector<SegmentInformation> &Get() const;

  private:
    void InitRoute(const PhantomNode &phantom_node, const bool traversed_in_reverse);
    void AddLeg(const std::vector<PathData> &leg_data,
                const PhantomNode &target_node,
                const bool traversed_in_reverse,
                const bool is_via_leg,
                const DataFacade *facade);

    void AppendSegment(const FixedPointCoordinate coordinate, const PathData &path_point);
    void Finalize(const bool extract_alternative,
                  const InternalRouteResult &raw_route,
                  const unsigned zoom_level,
                  const bool allow_simplification);

    // journey length in tenth of a second
    std::uint32_t total_distance;
    // journey distance in meter (TODO: verify)
    std::uint32_t total_duration;

    // segments that are required to keep
    std::vector<std::uint32_t> via_indices;

    // a list of node based segments
    std::vector<SegmentInformation> segments;
};

template <typename DataFacadeT>
SegmentList<DataFacadeT>::SegmentList(const InternalRouteResult &raw_route,
                                      const bool extract_alternative,
                                      const unsigned zoom_level,
                                      const bool allow_simplification,
                                      const DataFacade *facade)
    : total_distance(0), total_duration(0)
{
    if (!raw_route.is_valid())
    {
        return;
    }

    if (extract_alternative)
    {
        BOOST_ASSERT(raw_route.has_alternative());
        InitRoute(raw_route.segment_end_coordinates.front().source_phantom,
                  raw_route.alt_source_traversed_in_reverse.front());
        AddLeg(raw_route.unpacked_alternative,
               raw_route.segment_end_coordinates.back().target_phantom,
               raw_route.alt_source_traversed_in_reverse.back(), false, facade);
    }
    else
    {
        InitRoute(raw_route.segment_end_coordinates.front().source_phantom,
                  raw_route.source_traversed_in_reverse.front());
        for (std::size_t raw_index = 0; raw_index < raw_route.segment_end_coordinates.size();
             ++raw_index)
        {
            AddLeg(raw_route.unpacked_path_segments[raw_index],
                   raw_route.segment_end_coordinates[raw_index].target_phantom,
                   raw_route.target_traversed_in_reverse[raw_index],
                   raw_route.is_via_leg(raw_index), facade);
            if (raw_route.is_via_leg(raw_index))
            {
                const auto &source_phantom =
                    raw_route.segment_end_coordinates[raw_index].target_phantom;
                if (raw_route.target_traversed_in_reverse[raw_index] !=
                    raw_route.source_traversed_in_reverse[raw_index + 1])
                {
                    bool traversed_in_reverse = raw_route.target_traversed_in_reverse[raw_index];
                    const extractor::TravelMode travel_mode =
                        (traversed_in_reverse ? source_phantom.backward_travel_mode
                                              : source_phantom.forward_travel_mode);
                    const bool constexpr IS_NECESSARY = true;
                    const bool constexpr IS_VIA_LOCATION = true;
                    segments.emplace_back(source_phantom.location, source_phantom.name_id, 0, 0.f,
                                          extractor::TurnInstruction::UTurn, IS_NECESSARY,
                                          IS_VIA_LOCATION, travel_mode);
                }
            }
        }
    }

    if (!allow_simplification)
    {
        // to prevent any simplifications, we mark all segments as necessary
        for (auto &segment : segments)
        {
            segment.necessary = true;
        }
    }

    Finalize(extract_alternative, raw_route, zoom_level, allow_simplification);
}

template <typename DataFacadeT>
void SegmentList<DataFacadeT>::InitRoute(const PhantomNode &node, const bool traversed_in_reverse)
{
    const auto segment_duration =
        (traversed_in_reverse ? node.reverse_weight : node.forward_weight);
    const auto travel_mode =
        (traversed_in_reverse ? node.backward_travel_mode : node.forward_travel_mode);

    AppendSegment(node.location, PathData(0, node.name_id, extractor::TurnInstruction::HeadOn,
                                          segment_duration, travel_mode));
}

template <typename DataFacadeT>
void SegmentList<DataFacadeT>::AddLeg(const std::vector<PathData> &leg_data,
                                      const PhantomNode &target_node,
                                      const bool traversed_in_reverse,
                                      const bool is_via_leg,
                                      const DataFacade *facade)
{
    for (const auto &path_data : leg_data)
    {
        AppendSegment(facade->GetCoordinateOfNode(path_data.node), path_data);
    }

    const EdgeWeight segment_duration =
        (traversed_in_reverse ? target_node.reverse_weight : target_node.forward_weight);
    const extractor::TravelMode travel_mode =
        (traversed_in_reverse ? target_node.backward_travel_mode : target_node.forward_travel_mode);
    const bool constexpr IS_NECESSARY = true;
    const bool constexpr IS_VIA_LOCATION = true;
    segments.emplace_back(target_node.location, target_node.name_id, segment_duration, 0.f,
                          is_via_leg ? extractor::TurnInstruction::ReachViaLocation
                                     : extractor::TurnInstruction::NoTurn,
                          IS_NECESSARY, IS_VIA_LOCATION, travel_mode);
}

template <typename DataFacadeT> std::uint32_t SegmentList<DataFacadeT>::GetDistance() const
{
    return total_distance;
}
template <typename DataFacadeT> std::uint32_t SegmentList<DataFacadeT>::GetDuration() const
{
    return total_duration;
}

template <typename DataFacadeT>
std::vector<std::uint32_t> const &SegmentList<DataFacadeT>::GetViaIndices() const
{
    return via_indices;
}

template <typename DataFacadeT>
std::vector<SegmentInformation> const &SegmentList<DataFacadeT>::Get() const
{
    return segments;
}

template <typename DataFacadeT>
void SegmentList<DataFacadeT>::AppendSegment(const FixedPointCoordinate coordinate,
                                             const PathData &path_point)
{
    const auto turn = path_point.turn_instruction;

    segments.emplace_back(coordinate, path_point.name_id, path_point.segment_duration, 0.f, turn,
                          path_point.travel_mode);
}

template <typename DataFacadeT>
void SegmentList<DataFacadeT>::Finalize(const bool extract_alternative,
                                        const InternalRouteResult &raw_route,
                                        const unsigned zoom_level,
                                        const bool allow_simplification)
{
    if (segments.empty())
        return;

    // check if first two segments can be merged
    BOOST_ASSERT(segments.size() >= 2);
    if (segments[0].location == segments[1].location &&
        segments[1].turn_instruction == extractor::TurnInstruction::NoTurn)
    {
        segments[0].travel_mode = segments[1].travel_mode;
        segments[0].name_id = segments[1].name_id;
        // Other data??
        segments.erase(segments.begin() + 1);
    }

    // announce mode changes
    for (std::size_t i = 0; i + 1 < segments.size(); ++i)
    {
        auto &segment = segments[i];
        const auto next_mode = segments[i + 1].travel_mode;
        if (segment.travel_mode != next_mode &&
            segment.turn_instruction == extractor::TurnInstruction::NoTurn)
        {
            segment.turn_instruction = extractor::TurnInstruction::GoStraight;
            segment.necessary = true;
        }
    }

    segments[0].length = 0.f;
    for (const auto i : util::irange<std::size_t>(1, segments.size()))
    {
        // move down names by one, q&d hack
        segments[i - 1].name_id = segments[i].name_id;
        segments[i].length = util::coordinate_calculation::greatCircleDistance(
            segments[i - 1].location, segments[i].location);
    }

    float segment_length = 0.;
    EdgeWeight segment_duration = 0;
    std::size_t segment_start_index = 0;

    double path_length = 0;

    for (const auto i : util::irange<std::size_t>(1, segments.size()))
    {
        path_length += segments[i].length;
        segment_length += segments[i].length;
        segment_duration += segments[i].duration;
        segments[segment_start_index].length = segment_length;
        segments[segment_start_index].duration = segment_duration;

        if (extractor::TurnInstruction::NoTurn != segments[i].turn_instruction)
        {
            BOOST_ASSERT(segments[i].necessary);
            segment_length = 0;
            segment_duration = 0;
            segment_start_index = i;

            if (segments[i].turn_instruction == extractor::TurnInstruction::NameChanges)
            {
                segments[i].turn_instruction =
                    extractor::TurnInstruction::GoStraight; // to not break the api
            }
        }
    }

    total_distance = static_cast<std::uint32_t>(std::round(path_length));
    total_duration = static_cast<std::uint32_t>(std::round(
        (extract_alternative ? raw_route.alternative_path_length : raw_route.shortest_path_length) /
        10.));

    // Post-processing to remove empty or nearly empty path segments
    if (segments.size() > 2 && std::numeric_limits<float>::epsilon() > segments.back().length &&
        !(segments.end() - 2)->is_via_location)
    {
        segments.pop_back();
        segments.back().necessary = true;
        segments.back().turn_instruction = extractor::TurnInstruction::NoTurn;
    }

    if (segments.size() > 2 && std::numeric_limits<float>::epsilon() > segments.front().length &&
        !(segments.begin() + 1)->is_via_location)
    {
        segments.erase(segments.begin());
        segments.front().turn_instruction = extractor::TurnInstruction::HeadOn;
        segments.front().necessary = true;
    }

    if (allow_simplification)
    {
        douglasPeucker(segments, zoom_level);
    }

    std::uint32_t necessary_segments = 0; // a running index that counts the necessary pieces
    via_indices.push_back(0);
    const auto markNecessarySegments = [this, &necessary_segments](SegmentInformation &first,
                                                                   const SegmentInformation &second)
    {
        if (!first.necessary)
            return;

        // mark the end of a leg (of several segments)
        if (first.is_via_location)
            via_indices.push_back(necessary_segments);

        const double post_turn_bearing =
            util::coordinate_calculation::bearing(first.location, second.location);
        const double pre_turn_bearing =
            util::coordinate_calculation::bearing(second.location, first.location);
        first.post_turn_bearing = static_cast<short>(post_turn_bearing * 10);
        first.pre_turn_bearing = static_cast<short>(pre_turn_bearing * 10);

        ++necessary_segments;
    };

    // calculate which segments are necessary and update segments for bearings
    util::for_each_pair(segments, markNecessarySegments);
    via_indices.push_back(necessary_segments);

    BOOST_ASSERT(via_indices.size() >= 2);
}

template <typename DataFacadeT>
SegmentList<DataFacadeT> MakeSegmentList(const InternalRouteResult &raw_route,
                                         const bool extract_alternative,
                                         const unsigned zoom_level,
                                         const bool allow_simplification,
                                         const DataFacadeT *facade)
{
    return SegmentList<DataFacadeT>(raw_route, extract_alternative, zoom_level,
                                    allow_simplification, facade);
}

} // namespace guidance
} // namespace engine
} // namespace osrm

#endif // ENGINE_GUIDANCE_SEGMENT_LIST_HPP_

max_stars_repo_name: mortada/osrm-backend

max_issues_repo_name: mortada/osrm-backend

max_forks_repo_name: mortada/osrm-backend


text:
#include <cctbx/boost_python/flex_fwd.h>

#include <cctbx/miller/index_span.h>
#include <boost/python/class.hpp>

namespace cctbx { namespace miller { namespace boost_python {

namespace {

  struct index_span_wrappers
  {
    typedef index_span w_t;

    static void
    wrap()
    {
      using namespace boost::python;
      class_<w_t>("index_span", no_init)
        .def(init<af::const_ref<index<> > const&>())
        .def("min", &w_t::min)
        .def("max", &w_t::max)
        .def("abs_range", &w_t::abs_range)
        .def("map_grid", &w_t::map_grid)
        .def("is_in_domain", &w_t::is_in_domain)
        .def("pack",
          (af::shared<std::size_t>(w_t::*)
           (af::const_ref<index<> > const& miller_indices) const) &w_t::pack)
      ;
    }
  };

} // namespace <anoymous>

  void wrap_index_span()
  {
    index_span_wrappers::wrap();
  }

}}} // namespace cctbx::miller::boost_python


text:
/**
 * \file libs/numeric/ublasx/cumsum.cpp
 *
 * \brief Test suite for the \c cumsum operation.
 *
 * Copyright (c) 2010, Marco Guazzone
 *
 * 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)
 *
 * \author Marco Guazzone, marco.guazzone@gmail.com
 */

#include <boost/numeric/ublas/fwd.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_expression.hpp>
#include <boost/numeric/ublas/traits.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/vector_expression.hpp>
#include <boost/numeric/ublasx/operation/cumsum.hpp>
#include <boost/numeric/ublasx/tags.hpp>
#include <functional>
#include <iostream>
#include "libs/numeric/ublasx/test/utils.hpp"

static const double tol = 1.0e-5;

namespace ublas = ::boost::numeric::ublas;
namespace ublasx = ::boost::numeric::ublasx;

BOOST_UBLASX_TEST_DEF( test_vector_container )
{
	BOOST_UBLASX_DEBUG_TRACE( "TEST Vector Container" );

	typedef double value_type;
	typedef ublas::vector<value_type> vector_type;
	typedef ublas::zero_vector<value_type> zero_vector_type;
	typedef ublas::vector_traits<vector_type>::size_type size_type;

	size_type n(5);

	vector_type v(n);

	v(0) = 0.0;
	v(1) = 0.108929;
	v(2) = 0.0;
	v(3) = 0.0;
	v(4) = 1.023787;

	zero_vector_type z(n);

	vector_type expect(n, 0);
	vector_type res(n, 0);

	// cumsum(z)
	expect = vector_type(n, 0);
	res = ublasx::cumsum(z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum(" << z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( res, expect, n, tol );

	// cumsum(v)
	expect = vector_type(n);
	expect(0) = v(0);
	expect(1) = v(0)+v(1);
	expect(2) = v(0)+v(1)+v(2);
	expect(3) = v(0)+v(1)+v(2)+v(3);
	expect(4) = v(0)+v(1)+v(2)+v(3)+v(4);
	res = ublasx::cumsum(v);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum(" << v << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( res, expect, n, tol );

	// cumsum<1>(v)
	expect = vector_type(n);
	expect(0) = v(0);
	expect(1) = v(0)+v(1);
	expect(2) = v(0)+v(1)+v(2);
	expect(3) = v(0)+v(1)+v(2)+v(3);
	expect(4) = v(0)+v(1)+v(2)+v(3)+v(4);
	res = ublasx::cumsum<1>(v);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum<1>(" << v << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( res, expect, n, tol );
}

BOOST_UBLASX_TEST_DEF( test_vector_expression )
{
	BOOST_UBLASX_DEBUG_TRACE( "TEST Vector Expression" );

	typedef double value_type;
	typedef ublas::vector<value_type> vector_type;
	typedef ublas::vector_traits<vector_type>::size_type size_type;

	size_type n(5);

	vector_type v(n);

	v(0) = 0.0;
	v(1) = 0.108929;
	v(2) = 0.0;
	v(3) = 0.0;
	v(4) = 1.023787;

	vector_type expect(n, 0);
	vector_type res(n, 0);

	// cumsum(-v)
	expect = vector_type(n);
	expect(0) = -v(0);
	expect(1) = -(v(0)+v(1));
	expect(2) = -(v(0)+v(1)+v(2));
	expect(3) = -(v(0)+v(1)+v(2)+v(3));
	expect(4) = -(v(0)+v(1)+v(2)+v(3)+v(4));
	res = ublasx::cumsum(-v);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum(" << -v << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( res, expect, n, tol );

	// cumsum<1>(-v)
	expect = vector_type(n);
	expect(0) = -v(0);
	expect(1) = -(v(0)+v(1));
	expect(2) = -(v(0)+v(1)+v(2));
	expect(3) = -(v(0)+v(1)+v(2)+v(3));
	expect(4) = -(v(0)+v(1)+v(2)+v(3)+v(4));
	res = ublasx::cumsum<1>(-v);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum<1>(" << -v << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( res, expect, n, tol );
}

BOOST_UBLASX_TEST_DEF( test_vector_reference )
{
	BOOST_UBLASX_DEBUG_TRACE( "TEST Vector Reference" );

	typedef double value_type;
	typedef ublas::vector<value_type> vector_type;
	typedef ublas::vector_reference<vector_type> vector_reference_type;
	typedef ublas::vector_traits<vector_type>::size_type size_type;

	size_type n(5);

	vector_type v(n);

	v(0) = 0.0;
	v(1) = 0.108929;
	v(2) = 0.0;
	v(3) = 0.0;
	v(4) = 1.023787;

	vector_type expect(n, 0);
	vector_type res(n, 0);

	// cumsum(ref(v))
	expect = vector_type(n);
	expect(0) = v(0);
	expect(1) = v(0)+v(1);
	expect(2) = v(0)+v(1)+v(2);
	expect(3) = v(0)+v(1)+v(2)+v(3);
	expect(4) = v(0)+v(1)+v(2)+v(3)+v(4);
	res = ublasx::cumsum(vector_reference_type(v));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum(" << vector_reference_type(v) << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( res, expect, n, tol );

	// cumsum<1>(ref(v))
	expect = vector_type(n);
	expect(0) = v(0);
	expect(1) = v(0)+v(1);
	expect(2) = v(0)+v(1)+v(2);
	expect(3) = v(0)+v(1)+v(2)+v(3);
	expect(4) = v(0)+v(1)+v(2)+v(3)+v(4);
	res = ublasx::cumsum<1>(vector_reference_type(v));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum<1>(" << vector_reference_type(v) << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( res, expect, n, tol );
}

BOOST_UBLASX_TEST_DEF( test_row_major_matrix_container )
{
	BOOST_UBLASX_DEBUG_TRACE( "TEST Row-major Matrix Container" );

	typedef double value_type;
	typedef ublas::matrix<value_type, ublas::row_major> matrix_type;
	typedef ublas::zero_matrix<value_type> zero_matrix_type;
	typedef ublas::matrix_traits<matrix_type>::size_type size_type;

	size_type nr = 5;
	size_type nc = 4;

	matrix_type A(nr, nc);

	A(0,0) = 0.0;      A(0,1) = 0.274690; A(0,2) = 0.0;      A(0,3) = 0.798938;
	A(1,0) = 0.108929; A(1,1) = 0.0;      A(1,2) = 0.891726; A(1,3) = 0.0;
	A(2,0) = 0.0;      A(2,1) = 0.0;      A(2,2) = 0.0;      A(2,3) = 0.0;
	A(3,0) = 0.0;      A(3,1) = 0.675382; A(3,2) = 0.0;      A(3,3) = 0.450332;
	A(4,0) = 1.023787; A(4,1) = 1.0;      A(4,2) = 1.231751; A(4,3) = 1.0;

	zero_matrix_type Z(nr,nc);

	matrix_type cumsum_rows(nr,nc);
	cumsum_rows(0,0) = A(0,0); cumsum_rows(0,1) = A(0,1); cumsum_rows(0,2) = A(0,2); cumsum_rows(0,3) = A(0,3);
	cumsum_rows(1,0) = A(0,0)+A(1,0); cumsum_rows(1,1) = A(0,1)+A(1,1); cumsum_rows(1,2) = A(0,2)+A(1,2); cumsum_rows(1,3) = A(0,3)+A(1,3);
	cumsum_rows(2,0) = A(0,0)+A(1,0)+A(2,0); cumsum_rows(2,1) = A(0,1)+A(1,1)+A(2,1); cumsum_rows(2,2) = A(0,2)+A(1,2)+A(2,2); cumsum_rows(2,3) = A(0,3)+A(1,3)+A(2,3);
	cumsum_rows(3,0) = A(0,0)+A(1,0)+A(2,0)+A(3,0); cumsum_rows(3,1) = A(0,1)+A(1,1)+A(2,1)+A(3,1); cumsum_rows(3,2) = A(0,2)+A(1,2)+A(2,2)+A(3,2); cumsum_rows(3,3) = A(0,3)+A(1,3)+A(2,3)+A(3,3);
	cumsum_rows(4,0) = A(0,0)+A(1,0)+A(2,0)+A(3,0)+A(4,0); cumsum_rows(4,1) = A(0,1)+A(1,1)+A(2,1)+A(3,1)+A(4,1); cumsum_rows(4,2) = A(0,2)+A(1,2)+A(2,2)+A(3,2)+A(4,2); cumsum_rows(4,3) = A(0,3)+A(1,3)+A(2,3)+A(3,3)+A(4,3);

	matrix_type cumsum_cols(nr,nc);
	cumsum_cols(0,0) = A(0,0); cumsum_cols(0,1) = A(0,0)+A(0,1); cumsum_cols(0,2) = A(0,0)+A(0,1)+A(0,2); cumsum_cols(0,3) = A(0,0)+A(0,1)+A(0,2)+A(0,3);
	cumsum_cols(1,0) = A(1,0); cumsum_cols(1,1) = A(1,0)+A(1,1); cumsum_cols(1,2) = A(1,0)+A(1,1)+A(1,2); cumsum_cols(1,3) = A(1,0)+A(1,1)+A(1,2)+A(1,3);
	cumsum_cols(2,0) = A(2,0); cumsum_cols(2,1) = A(2,0)+A(2,1); cumsum_cols(2,2) = A(2,0)+A(2,1)+A(2,2); cumsum_cols(2,3) = A(2,0)+A(2,1)+A(2,2)+A(2,3);
	cumsum_cols(3,0) = A(3,0); cumsum_cols(3,1) = A(3,0)+A(3,1); cumsum_cols(3,2) = A(3,0)+A(3,1)+A(3,2); cumsum_cols(3,3) = A(3,0)+A(3,1)+A(3,2)+A(3,3);
	cumsum_cols(4,0) = A(4,0); cumsum_cols(4,1) = A(4,0)+A(4,1); cumsum_cols(4,2) = A(4,0)+A(4,1)+A(4,2); cumsum_cols(4,3) = A(4,0)+A(4,1)+A(4,2)+A(4,3);

	matrix_type expect(nr,nc);
	matrix_type res(nr,nc);

	// cumsum(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum_rows(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum_rows(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_rows(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum_columns(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum_columns(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_columns(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<1>(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum<1>(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum<1>(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<2>(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum<2>(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum<1>(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<tag::major>(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum_by_tag<ublas::tag::major>(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::major>(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<tag::minor>(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum_by_tag<ublas::tag::minor>(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::minor>(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<tag::leading>(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum_by_tag<ublas::tag::leading>(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::leading>(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum(A)
	expect = cumsum_rows;
	res = ublasx::cumsum(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum_rows(A)
	expect = cumsum_rows;
	res = ublasx::cumsum_rows(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_rows(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum_columns(A)
	expect = cumsum_cols;
	res = ublasx::cumsum_columns(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_columns(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<1>(A)
	expect = cumsum_rows;
	res = ublasx::cumsum<1>(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum<1>(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<2>(A)
	expect = cumsum_cols;
	res = ublasx::cumsum<2>(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum<2>(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<tag::major>(A)
	expect = cumsum_rows;
	res = ublasx::cumsum_by_tag<ublasx::tag::major>(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::major>(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<tag::minor>(A)
	expect = cumsum_cols;
	res = ublasx::cumsum_by_tag<ublasx::tag::minor>(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::minor>(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<tag::leading>(A)
	expect = cumsum_cols;
	res = ublasx::cumsum_by_tag<ublasx::tag::leading>(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::leading>(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );
}

BOOST_UBLASX_TEST_DEF( test_col_major_matrix_container )
{
	BOOST_UBLASX_DEBUG_TRACE( "TEST Column-major Matrix Container" );

	typedef double value_type;
	typedef ublas::matrix<value_type, ublas::column_major> matrix_type;
	typedef ublas::zero_matrix<value_type> zero_matrix_type;
	typedef ublas::matrix_traits<matrix_type>::size_type size_type;

	size_type nr = 5;
	size_type nc = 4;

	matrix_type A(nr, nc);

	A(0,0) = 0.0;      A(0,1) = 0.274690; A(0,2) = 0.0;      A(0,3) = 0.798938;
	A(1,0) = 0.108929; A(1,1) = 0.0;      A(1,2) = 0.891726; A(1,3) = 0.0;
	A(2,0) = 0.0;      A(2,1) = 0.0;      A(2,2) = 0.0;      A(2,3) = 0.0;
	A(3,0) = 0.0;      A(3,1) = 0.675382; A(3,2) = 0.0;      A(3,3) = 0.450332;
	A(4,0) = 1.023787; A(4,1) = 1.0;      A(4,2) = 1.231751; A(4,3) = 1.0;

	zero_matrix_type Z(nr,nc);

	matrix_type cumsum_rows(nr,nc);
	cumsum_rows(0,0) = A(0,0); cumsum_rows(0,1) = A(0,1); cumsum_rows(0,2) = A(0,2); cumsum_rows(0,3) = A(0,3);
	cumsum_rows(1,0) = A(0,0)+A(1,0); cumsum_rows(1,1) = A(0,1)+A(1,1); cumsum_rows(1,2) = A(0,2)+A(1,2); cumsum_rows(1,3) = A(0,3)+A(1,3);
	cumsum_rows(2,0) = A(0,0)+A(1,0)+A(2,0); cumsum_rows(2,1) = A(0,1)+A(1,1)+A(2,1); cumsum_rows(2,2) = A(0,2)+A(1,2)+A(2,2); cumsum_rows(2,3) = A(0,3)+A(1,3)+A(2,3);
	cumsum_rows(3,0) = A(0,0)+A(1,0)+A(2,0)+A(3,0); cumsum_rows(3,1) = A(0,1)+A(1,1)+A(2,1)+A(3,1); cumsum_rows(3,2) = A(0,2)+A(1,2)+A(2,2)+A(3,2); cumsum_rows(3,3) = A(0,3)+A(1,3)+A(2,3)+A(3,3);
	cumsum_rows(4,0) = A(0,0)+A(1,0)+A(2,0)+A(3,0)+A(4,0); cumsum_rows(4,1) = A(0,1)+A(1,1)+A(2,1)+A(3,1)+A(4,1); cumsum_rows(4,2) = A(0,2)+A(1,2)+A(2,2)+A(3,2)+A(4,2); cumsum_rows(4,3) = A(0,3)+A(1,3)+A(2,3)+A(3,3)+A(4,3);

	matrix_type cumsum_cols(nr,nc);
	cumsum_cols(0,0) = A(0,0); cumsum_cols(0,1) = A(0,0)+A(0,1); cumsum_cols(0,2) = A(0,0)+A(0,1)+A(0,2); cumsum_cols(0,3) = A(0,0)+A(0,1)+A(0,2)+A(0,3);
	cumsum_cols(1,0) = A(1,0); cumsum_cols(1,1) = A(1,0)+A(1,1); cumsum_cols(1,2) = A(1,0)+A(1,1)+A(1,2); cumsum_cols(1,3) = A(1,0)+A(1,1)+A(1,2)+A(1,3);
	cumsum_cols(2,0) = A(2,0); cumsum_cols(2,1) = A(2,0)+A(2,1); cumsum_cols(2,2) = A(2,0)+A(2,1)+A(2,2); cumsum_cols(2,3) = A(2,0)+A(2,1)+A(2,2)+A(2,3);
	cumsum_cols(3,0) = A(3,0); cumsum_cols(3,1) = A(3,0)+A(3,1); cumsum_cols(3,2) = A(3,0)+A(3,1)+A(3,2); cumsum_cols(3,3) = A(3,0)+A(3,1)+A(3,2)+A(3,3);
	cumsum_cols(4,0) = A(4,0); cumsum_cols(4,1) = A(4,0)+A(4,1); cumsum_cols(4,2) = A(4,0)+A(4,1)+A(4,2); cumsum_cols(4,3) = A(4,0)+A(4,1)+A(4,2)+A(4,3);

	matrix_type expect(nr,nc);
	matrix_type res(nr,nc);

	// cumsum(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum_rows(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum_rows(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_rows(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum_columns(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum_columns(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_columns(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<1>(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum<1>(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum<1>(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<2>(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum<2>(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum<1>(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<tag::major>(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum_by_tag<ublas::tag::major>(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::major>(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<tag::minor>(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum_by_tag<ublas::tag::minor>(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::minor>(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<tag::leading>(Z)
	expect = matrix_type(nr, nc, 0);
	res = ublasx::cumsum_by_tag<ublas::tag::leading>(Z);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::leading>(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum(A)
	expect = cumsum_rows;
	res = ublasx::cumsum(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum_rows(A)
	expect = cumsum_rows;
	res = ublasx::cumsum_rows(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_rows(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum_columns(A)
	expect = cumsum_cols;
	res = ublasx::cumsum_columns(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_columns(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<1>(A)
	expect = cumsum_rows;
	res = ublasx::cumsum<1>(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum<1>(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<2>(A)
	expect = cumsum_cols;
	res = ublasx::cumsum<2>(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum<2>(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<tag::major>(A)
	expect = cumsum_cols;
	res = ublasx::cumsum_by_tag<ublasx::tag::major>(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::major>(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<tag::minor>(A)
	expect = cumsum_rows;
	res = ublasx::cumsum_by_tag<ublasx::tag::minor>(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::minor>(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<tag::leading>(A)
	expect = cumsum_rows;
	res = ublasx::cumsum_by_tag<ublasx::tag::leading>(A);
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::leading>(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );
}

BOOST_UBLASX_TEST_DEF( test_matrix_expression )
{
	BOOST_UBLASX_DEBUG_TRACE( "TEST Matrix Expression" );

	typedef double value_type;
	typedef ublas::matrix<value_type> matrix_type;
	typedef ublas::matrix_traits<matrix_type>::size_type size_type;

	size_type nr = 5;
	size_type nc = 4;

	matrix_type A(nr, nc);

	A(0,0) = 0.0;      A(0,1) = 0.274690; A(0,2) = 0.0;      A(0,3) = 0.798938;
	A(1,0) = 0.108929; A(1,1) = 0.0;      A(1,2) = 0.891726; A(1,3) = 0.0;
	A(2,0) = 0.0;      A(2,1) = 0.0;      A(2,2) = 0.0;      A(2,3) = 0.0;
	A(3,0) = 0.0;      A(3,1) = 0.675382; A(3,2) = 0.0;      A(3,3) = 0.450332;
	A(4,0) = 1.023787; A(4,1) = 1.0;      A(4,2) = 1.231751; A(4,3) = 1.0;

	matrix_type cumsum_rows(nr,nc);
	cumsum_rows(0,0) = A(0,0); cumsum_rows(0,1) = A(0,1); cumsum_rows(0,2) = A(0,2); cumsum_rows(0,3) = A(0,3);
	cumsum_rows(1,0) = A(0,0)+A(1,0); cumsum_rows(1,1) = A(0,1)+A(1,1); cumsum_rows(1,2) = A(0,2)+A(1,2); cumsum_rows(1,3) = A(0,3)+A(1,3);
	cumsum_rows(2,0) = A(0,0)+A(1,0)+A(2,0); cumsum_rows(2,1) = A(0,1)+A(1,1)+A(2,1); cumsum_rows(2,2) = A(0,2)+A(1,2)+A(2,2); cumsum_rows(2,3) = A(0,3)+A(1,3)+A(2,3);
	cumsum_rows(3,0) = A(0,0)+A(1,0)+A(2,0)+A(3,0); cumsum_rows(3,1) = A(0,1)+A(1,1)+A(2,1)+A(3,1); cumsum_rows(3,2) = A(0,2)+A(1,2)+A(2,2)+A(3,2); cumsum_rows(3,3) = A(0,3)+A(1,3)+A(2,3)+A(3,3);
	cumsum_rows(4,0) = A(0,0)+A(1,0)+A(2,0)+A(3,0)+A(4,0); cumsum_rows(4,1) = A(0,1)+A(1,1)+A(2,1)+A(3,1)+A(4,1); cumsum_rows(4,2) = A(0,2)+A(1,2)+A(2,2)+A(3,2)+A(4,2); cumsum_rows(4,3) = A(0,3)+A(1,3)+A(2,3)+A(3,3)+A(4,3);

	matrix_type cumsum_cols(nr,nc);
	cumsum_cols(0,0) = A(0,0); cumsum_cols(0,1) = A(0,0)+A(0,1); cumsum_cols(0,2) = A(0,0)+A(0,1)+A(0,2); cumsum_cols(0,3) = A(0,0)+A(0,1)+A(0,2)+A(0,3);
	cumsum_cols(1,0) = A(1,0); cumsum_cols(1,1) = A(1,0)+A(1,1); cumsum_cols(1,2) = A(1,0)+A(1,1)+A(1,2); cumsum_cols(1,3) = A(1,0)+A(1,1)+A(1,2)+A(1,3);
	cumsum_cols(2,0) = A(2,0); cumsum_cols(2,1) = A(2,0)+A(2,1); cumsum_cols(2,2) = A(2,0)+A(2,1)+A(2,2); cumsum_cols(2,3) = A(2,0)+A(2,1)+A(2,2)+A(2,3);
	cumsum_cols(3,0) = A(3,0); cumsum_cols(3,1) = A(3,0)+A(3,1); cumsum_cols(3,2) = A(3,0)+A(3,1)+A(3,2); cumsum_cols(3,3) = A(3,0)+A(3,1)+A(3,2)+A(3,3);
	cumsum_cols(4,0) = A(4,0); cumsum_cols(4,1) = A(4,0)+A(4,1); cumsum_cols(4,2) = A(4,0)+A(4,1)+A(4,2); cumsum_cols(4,3) = A(4,0)+A(4,1)+A(4,2)+A(4,3);

	matrix_type expect;
	matrix_type res;

	// cumsum(A')
	expect = ublas::trans(cumsum_cols);
	res = ublasx::cumsum(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum(" << A << "') = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nc, nr, tol );

	// cumsum_rows(A')
	expect = ublas::trans(cumsum_cols);
	res = ublasx::cumsum_rows(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_rows(" << A << "') = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nc, nr, tol );

	// cumsum_columns(A')
	expect = ublas::trans(cumsum_rows);
	res = ublasx::cumsum_columns(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_columns(" << A << "') = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nc, nr, tol );

	// cumsum<1>(A')
	expect = ublas::trans(cumsum_cols);
	res = ublasx::cumsum<1>(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum<1>(" << A << "') = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nc, nr, tol );

	// cumsum<2>(A')
	expect = ublas::trans(cumsum_rows);
	res = ublasx::cumsum<2>(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum<2>(" << A << "') = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nc, nr, tol );

	// cumsum<tag::major>(A')
	expect = ublas::trans(cumsum_rows);
	res = ublasx::cumsum_by_tag<ublasx::tag::major>(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::major>(" << A << "') = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nc, nr, tol );

	// cumsum<tag::minor>(A')
	expect = ublas::trans(cumsum_cols);
	res = ublasx::cumsum_by_tag<ublasx::tag::minor>(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::minor>(" << A << "') = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nc, nr, tol );

	// cumsum<tag::leading>(A')
	expect = ublas::trans(cumsum_cols);
	res = ublasx::cumsum_by_tag<ublasx::tag::leading>(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::leading>(" << A << "') = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nc, nr, tol );
}

BOOST_UBLASX_TEST_DEF( test_matrix_reference )
{
	BOOST_UBLASX_DEBUG_TRACE( "TEST Matrix Reference" );

	typedef double value_type;
	typedef ublas::matrix<value_type> matrix_type;
	typedef ublas::matrix_reference<matrix_type> matrix_reference_type;
	typedef ublas::matrix_traits<matrix_type>::size_type size_type;

	size_type nr = 5;
	size_type nc = 4;

	matrix_type A(nr, nc);

	A(0,0) = 0.0;      A(0,1) = 0.274690; A(0,2) = 0.0;      A(0,3) = 0.798938;
	A(1,0) = 0.108929; A(1,1) = 0.0;      A(1,2) = 0.891726; A(1,3) = 0.0;
	A(2,0) = 0.0;      A(2,1) = 0.0;      A(2,2) = 0.0;      A(2,3) = 0.0;
	A(3,0) = 0.0;      A(3,1) = 0.675382; A(3,2) = 0.0;      A(3,3) = 0.450332;
	A(4,0) = 1.023787; A(4,1) = 1.0;      A(4,2) = 1.231751; A(4,3) = 1.0;

	matrix_type cumsum_rows(nr,nc);
	cumsum_rows(0,0) = A(0,0); cumsum_rows(0,1) = A(0,1); cumsum_rows(0,2) = A(0,2); cumsum_rows(0,3) = A(0,3);
	cumsum_rows(1,0) = A(0,0)+A(1,0); cumsum_rows(1,1) = A(0,1)+A(1,1); cumsum_rows(1,2) = A(0,2)+A(1,2); cumsum_rows(1,3) = A(0,3)+A(1,3);
	cumsum_rows(2,0) = A(0,0)+A(1,0)+A(2,0); cumsum_rows(2,1) = A(0,1)+A(1,1)+A(2,1); cumsum_rows(2,2) = A(0,2)+A(1,2)+A(2,2); cumsum_rows(2,3) = A(0,3)+A(1,3)+A(2,3);
	cumsum_rows(3,0) = A(0,0)+A(1,0)+A(2,0)+A(3,0); cumsum_rows(3,1) = A(0,1)+A(1,1)+A(2,1)+A(3,1); cumsum_rows(3,2) = A(0,2)+A(1,2)+A(2,2)+A(3,2); cumsum_rows(3,3) = A(0,3)+A(1,3)+A(2,3)+A(3,3);
	cumsum_rows(4,0) = A(0,0)+A(1,0)+A(2,0)+A(3,0)+A(4,0); cumsum_rows(4,1) = A(0,1)+A(1,1)+A(2,1)+A(3,1)+A(4,1); cumsum_rows(4,2) = A(0,2)+A(1,2)+A(2,2)+A(3,2)+A(4,2); cumsum_rows(4,3) = A(0,3)+A(1,3)+A(2,3)+A(3,3)+A(4,3);

	matrix_type cumsum_cols(nr,nc);
	cumsum_cols(0,0) = A(0,0); cumsum_cols(0,1) = A(0,0)+A(0,1); cumsum_cols(0,2) = A(0,0)+A(0,1)+A(0,2); cumsum_cols(0,3) = A(0,0)+A(0,1)+A(0,2)+A(0,3);
	cumsum_cols(1,0) = A(1,0); cumsum_cols(1,1) = A(1,0)+A(1,1); cumsum_cols(1,2) = A(1,0)+A(1,1)+A(1,2); cumsum_cols(1,3) = A(1,0)+A(1,1)+A(1,2)+A(1,3);
	cumsum_cols(2,0) = A(2,0); cumsum_cols(2,1) = A(2,0)+A(2,1); cumsum_cols(2,2) = A(2,0)+A(2,1)+A(2,2); cumsum_cols(2,3) = A(2,0)+A(2,1)+A(2,2)+A(2,3);
	cumsum_cols(3,0) = A(3,0); cumsum_cols(3,1) = A(3,0)+A(3,1); cumsum_cols(3,2) = A(3,0)+A(3,1)+A(3,2); cumsum_cols(3,3) = A(3,0)+A(3,1)+A(3,2)+A(3,3);
	cumsum_cols(4,0) = A(4,0); cumsum_cols(4,1) = A(4,0)+A(4,1); cumsum_cols(4,2) = A(4,0)+A(4,1)+A(4,2); cumsum_cols(4,3) = A(4,0)+A(4,1)+A(4,2)+A(4,3);

	matrix_type expect;
	matrix_type res;

	// cumsum(ref(A))
	expect = cumsum_rows;
	res = ublasx::cumsum(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum(reference(" << A << ")) = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum_rows(ref(A))
	expect = cumsum_rows;
	res = ublasx::cumsum_rows(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_rows(reference(" << A << ")) = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum_columns(ref(A))
	expect = cumsum_cols;
	res = ublasx::cumsum_columns(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_columns(reference(" << A << ")) = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<1>(ref(A))
	expect = cumsum_rows;
	res = ublasx::cumsum<1>(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum<1>(reference(" << A << ")) = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<2>(ref(A))
	expect = cumsum_cols;
	res = ublasx::cumsum<2>(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum<2>(reference(" << A << ")) = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<tag::major>(ref(A))
	expect = cumsum_rows;
	res = ublasx::cumsum_by_tag<ublasx::tag::major>(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::major>(reference(" << A << ")) = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<tag::minor>(ref(A))
	expect = cumsum_cols;
	res = ublasx::cumsum_by_tag<ublasx::tag::minor>(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::minor>(reference(" << A << ")) = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );

	// cumsum<tag::leading>(ref(A))
	expect = cumsum_cols;
	res = ublasx::cumsum_by_tag<ublasx::tag::leading>(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "cumsum_by_tag<tag::leading>(reference(" << A << ")) = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_MATRIX_CLOSE( res, expect, nr, nc, tol );
}

int main()
{
	BOOST_UBLASX_DEBUG_TRACE("Test Suite: 'cumsum' operation");

	BOOST_UBLASX_TEST_BEGIN();

	BOOST_UBLASX_TEST_DO( test_vector_container );
	BOOST_UBLASX_TEST_DO( test_vector_expression );
	BOOST_UBLASX_TEST_DO( test_vector_reference );
	BOOST_UBLASX_TEST_DO( test_row_major_matrix_container );
	BOOST_UBLASX_TEST_DO( test_col_major_matrix_container );
	BOOST_UBLASX_TEST_DO( test_matrix_expression );
	BOOST_UBLASX_TEST_DO( test_matrix_reference );

	BOOST_UBLASX_TEST_END();
}


text:
// Copyright Nick Thompson, 2019
// Use, modification and distribution are subject to 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)

/*
 * References:
 * Ooura, Takuya, and Masatake Mori. "A robust double exponential formula for Fourier-type integrals." Journal of computational and applied mathematics 112.1-2 (1999): 229-241.
 * http://www.kurims.kyoto-u.ac.jp/~ooura/intde.html
 */
#ifndef BOOST_MATH_QUADRATURE_OOURA_FOURIER_INTEGRALS_HPP
#define BOOST_MATH_QUADRATURE_OOURA_FOURIER_INTEGRALS_HPP
#include <memory>
#include <boost/math/quadrature/detail/ooura_fourier_integrals_detail.hpp>

namespace boost { namespace math { namespace quadrature {

template<class Real>
class ooura_fourier_sin {
public:
    ooura_fourier_sin(const Real relative_error_tolerance = tools::root_epsilon<Real>(), size_t levels = sizeof(Real)) : impl_(std::make_shared<detail::ooura_fourier_sin_detail<Real>>(relative_error_tolerance, levels))
    {}

    template<class F>
    std::pair<Real, Real> integrate(F const & f, Real omega) {
        return impl_->integrate(f, omega);
    }

    // These are just for debugging/unit tests:
    std::vector<std::vector<Real>> const & big_nodes() const {
        return impl_->big_nodes();
    }

    std::vector<std::vector<Real>> const & weights_for_big_nodes() const {
        return impl_->weights_for_big_nodes();
    }

    std::vector<std::vector<Real>> const & little_nodes() const {
        return impl_->little_nodes();
    }

    std::vector<std::vector<Real>> const & weights_for_little_nodes() const {
        return impl_->weights_for_little_nodes();
    }

private:
    std::shared_ptr<detail::ooura_fourier_sin_detail<Real>> impl_;
};

template<class Real>
class ooura_fourier_cos {
public:
    ooura_fourier_cos(const Real relative_error_tolerance = tools::root_epsilon<Real>(), size_t levels = sizeof(Real)) : impl_(std::make_shared<detail::ooura_fourier_cos_detail<Real>>(relative_error_tolerance, levels))
    {}

    template<class F>
    std::pair<Real, Real> integrate(F const & f, Real omega) {
        return impl_->integrate(f, omega);
    }
private:
    std::shared_ptr<detail::ooura_fourier_cos_detail<Real>> impl_;
};

}}}
#endif


text:
/**
 * @file llfloaterspellchecksettings.h
 * @brief Spell checker settings floater
 *
* $LicenseInfo:firstyear=2011&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "llviewerprecompiledheaders.h"

#include "llcombobox.h"
#include "llfilepicker.h"
#include "llfloaterreg.h"
#include "llfloaterspellchecksettings.h"
#include "llnotificationsutil.h"
#include "llscrolllistctrl.h"
#include "llsdserialize.h"
#include "llspellcheck.h"
#include "lltrans.h"
#include "llviewercontrol.h"
#include "llviewermenufile.h" // LLFilePickerReplyThread

#include <boost/algorithm/string.hpp>

///----------------------------------------------------------------------------
/// Class LLFloaterSpellCheckerSettings
///----------------------------------------------------------------------------
LLFloaterSpellCheckerSettings::LLFloaterSpellCheckerSettings(const LLSD& key)
	: LLFloater(key)
{
}

void LLFloaterSpellCheckerSettings::draw()
{
	LLFloater::draw();

	std::vector<LLScrollListItem*> sel_items = getChild<LLScrollListCtrl>("spellcheck_available_list")->getAllSelected();
	bool enable_remove = !sel_items.empty();
	for (std::vector<LLScrollListItem*>::const_iterator sel_it = sel_items.begin(); sel_it != sel_items.end(); ++sel_it)
	{
		enable_remove &= LLSpellChecker::getInstance()->canRemoveDictionary((*sel_it)->getValue().asString());
	}
	getChild<LLUICtrl>("spellcheck_remove_btn")->setEnabled(enable_remove);
}

BOOL LLFloaterSpellCheckerSettings::postBuild(void)
{
	gSavedSettings.getControl("SpellCheck")->getSignal()->connect(boost::bind(&LLFloaterSpellCheckerSettings::refreshDictionaries, this, false));
	LLSpellChecker::setSettingsChangeCallback(boost::bind(&LLFloaterSpellCheckerSettings::onSpellCheckSettingsChange, this));
	getChild<LLUICtrl>("spellcheck_remove_btn")->setCommitCallback(boost::bind(&LLFloaterSpellCheckerSettings::onBtnRemove, this));
	getChild<LLUICtrl>("spellcheck_import_btn")->setCommitCallback(boost::bind(&LLFloaterSpellCheckerSettings::onBtnImport, this));
	getChild<LLUICtrl>("spellcheck_main_combo")->setCommitCallback(boost::bind(&LLFloaterSpellCheckerSettings::refreshDictionaries, this, false));
	getChild<LLUICtrl>("spellcheck_moveleft_btn")->setCommitCallback(boost::bind(&LLFloaterSpellCheckerSettings::onBtnMove, this, "spellcheck_active_list", "spellcheck_available_list"));
	getChild<LLUICtrl>("spellcheck_moveright_btn")->setCommitCallback(boost::bind(&LLFloaterSpellCheckerSettings::onBtnMove, this, "spellcheck_available_list", "spellcheck_active_list"));
	center();
	return true;
}

void LLFloaterSpellCheckerSettings::onBtnImport()
{
	LLFloaterReg::showInstance("prefs_spellchecker_import");
}

void LLFloaterSpellCheckerSettings::onBtnMove(const std::string& from, const std::string& to)
{
	LLScrollListCtrl* from_ctrl = findChild<LLScrollListCtrl>(from);
	LLScrollListCtrl* to_ctrl = findChild<LLScrollListCtrl>(to);

	LLSD row;
	row["columns"][0]["column"] = "name";

	std::vector<LLScrollListItem*> sel_items = from_ctrl->getAllSelected();
	std::vector<LLScrollListItem*>::const_iterator sel_it;
	for ( sel_it = sel_items.begin(); sel_it != sel_items.end(); ++sel_it)
	{
		row["value"] = (*sel_it)->getValue();
		row["columns"][0]["value"] = (*sel_it)->getColumn(0)->getValue();
		to_ctrl->addElement(row);
		to_ctrl->setSelectedByValue( (*sel_it)->getValue(), true );
	}
	from_ctrl->deleteSelectedItems();

	commitChanges();
}

void LLFloaterSpellCheckerSettings::onClose(bool app_quitting)
{
	if (app_quitting)
	{
		// don't save anything
		return;
	}
	LLFloaterReg::hideInstance("prefs_spellchecker_import");

	commitChanges();
}

void LLFloaterSpellCheckerSettings::onOpen(const LLSD& key)
{
	refreshDictionaries(true);
}

void LLFloaterSpellCheckerSettings::onBtnRemove()
{
	std::vector<LLScrollListItem*> sel_items = getChild<LLScrollListCtrl>("spellcheck_available_list")->getAllSelected();
	for (std::vector<LLScrollListItem*>::const_iterator sel_it = sel_items.begin(); sel_it != sel_items.end(); ++sel_it)
	{
		LLSpellChecker::instance().removeDictionary((*sel_it)->getValue().asString());
	}
}

void LLFloaterSpellCheckerSettings::onSpellCheckSettingsChange()
{
	refreshDictionaries(true);
}

void LLFloaterSpellCheckerSettings::refreshDictionaries(bool from_settings)
{
	bool enabled = gSavedSettings.getBOOL("SpellCheck");
	getChild<LLUICtrl>("spellcheck_moveleft_btn")->setEnabled(enabled);
	getChild<LLUICtrl>("spellcheck_moveright_btn")->setEnabled(enabled);

	// Populate the dictionary combobox
	LLComboBox* dict_combo = findChild<LLComboBox>("spellcheck_main_combo");
	std::string dict_cur = dict_combo->getSelectedItemLabel();
	if ((dict_cur.empty() || from_settings) && (LLSpellChecker::getUseSpellCheck()))
	{
		dict_cur = LLSpellChecker::instance().getPrimaryDictionary();
	}
	dict_combo->clearRows();

	const LLSD& dict_map = LLSpellChecker::getInstance()->getDictionaryMap();
	if (dict_map.size())
	{
		for (LLSD::array_const_iterator dict_it = dict_map.beginArray(); dict_it != dict_map.endArray(); ++dict_it)
		{
			const LLSD& dict = *dict_it;
			if ( (dict["installed"].asBoolean()) && (dict["is_primary"].asBoolean()) && (dict.has("language")) )
			{
				dict_combo->add(dict["language"].asString());
			}
		}
		if (!dict_combo->selectByValue(dict_cur))
		{
			dict_combo->clear();
		}
	}
	dict_combo->sortByName();
	dict_combo->setEnabled(enabled);

	// Populate the available and active dictionary list
	LLScrollListCtrl* avail_ctrl = findChild<LLScrollListCtrl>("spellcheck_available_list");
	LLScrollListCtrl* active_ctrl = findChild<LLScrollListCtrl>("spellcheck_active_list");

	LLSpellChecker::dict_list_t active_list;
	if ( ((!avail_ctrl->getItemCount()) && (!active_ctrl->getItemCount())) || (from_settings) )
	{
		if (LLSpellChecker::getUseSpellCheck())
		{
			active_list = LLSpellChecker::instance().getSecondaryDictionaries();
		}
	}
	else
	{
		std::vector<LLScrollListItem*> active_items = active_ctrl->getAllData();
		for (std::vector<LLScrollListItem*>::const_iterator item_it = active_items.begin(); item_it != active_items.end(); ++item_it)
		{
			std::string dict = (*item_it)->getValue().asString();
			if (dict_cur != dict)
			{
				active_list.push_back(dict);
			}
		}
	}

	LLSD row;
	row["columns"][0]["column"] = "name";

	active_ctrl->clearRows();
	active_ctrl->setEnabled(enabled);
	for (LLSpellChecker::dict_list_t::const_iterator it = active_list.begin(); it != active_list.end(); ++it)
	{
		const std::string language = *it;
		const LLSD dict = LLSpellChecker::getInstance()->getDictionaryData(language);
		row["value"] = language;
		row["columns"][0]["value"] = (!dict["user_installed"].asBoolean()) ? language : language + " " + LLTrans::getString("UserDictionary");
		active_ctrl->addElement(row);
	}
	active_ctrl->sortByColumnIndex(0, true);
	active_list.push_back(dict_cur);

	avail_ctrl->clearRows();
	avail_ctrl->setEnabled(enabled);
	for (LLSD::array_const_iterator dict_it = dict_map.beginArray(); dict_it != dict_map.endArray(); ++dict_it)
	{
		const LLSD& dict = *dict_it;
		const std::string language = dict["language"].asString();
		if ( (dict["installed"].asBoolean()) && (active_list.end() == std::find(active_list.begin(), active_list.end(), language)) )
		{
			row["value"] = language;
			row["columns"][0]["value"] = (!dict["user_installed"].asBoolean()) ? language : language + " " + LLTrans::getString("UserDictionary");
			avail_ctrl->addElement(row);
		}
	}
	avail_ctrl->sortByColumnIndex(0, true);
	commitChanges();
}

void LLFloaterSpellCheckerSettings::commitChanges()
{
	std::list<std::string> list_dict;

	LLComboBox* dict_combo = findChild<LLComboBox>("spellcheck_main_combo");
	const std::string dict_name = dict_combo->getSelectedItemLabel();
	if (!dict_name.empty())
	{
		list_dict.push_back(dict_name);

		LLScrollListCtrl* list_ctrl = findChild<LLScrollListCtrl>("spellcheck_active_list");
		std::vector<LLScrollListItem*> list_items = list_ctrl->getAllData();
		for (std::vector<LLScrollListItem*>::const_iterator item_it = list_items.begin(); item_it != list_items.end(); ++item_it)
		{
			const std::string language = (*item_it)->getValue().asString();
			if (LLSpellChecker::getInstance()->hasDictionary(language, true))
			{
				list_dict.push_back(language);
			}
		}
	}
	gSavedSettings.setString("SpellCheckDictionary", boost::join(list_dict, ","));
}

///----------------------------------------------------------------------------
/// Class LLFloaterSpellCheckerImport
///----------------------------------------------------------------------------
LLFloaterSpellCheckerImport::LLFloaterSpellCheckerImport(const LLSD& key)
	: LLFloater(key)
{
}

BOOL LLFloaterSpellCheckerImport::postBuild(void)
{
	getChild<LLUICtrl>("dictionary_path_browse")->setCommitCallback(boost::bind(&LLFloaterSpellCheckerImport::onBtnBrowse, this));
	getChild<LLUICtrl>("ok_btn")->setCommitCallback(boost::bind(&LLFloaterSpellCheckerImport::onBtnOK, this));
	getChild<LLUICtrl>("cancel_btn")->setCommitCallback(boost::bind(&LLFloaterSpellCheckerImport::onBtnCancel, this));
	center();
	return true;
}

void LLFloaterSpellCheckerImport::onBtnBrowse()
{
	(new LLFilePickerReplyThread(boost::bind(&LLFloaterSpellCheckerImport::importSelectedDictionary, this, _1), LLFilePicker::FFLOAD_DICTIONARY, false))->getFile();
}

void LLFloaterSpellCheckerImport::importSelectedDictionary(const std::vector<std::string>& filenames)
{
	std::string filepath = filenames[0];

	const std::string extension = gDirUtilp->getExtension(filepath);
	if ("xcu" == extension)
	{
		filepath = parseXcuFile(filepath);
		if (filepath.empty())
		{
			return;
		}
	}

	getChild<LLUICtrl>("dictionary_path")->setValue(filepath);

	mDictionaryDir = gDirUtilp->getDirName(filepath);
	mDictionaryBasename = gDirUtilp->getBaseFileName(filepath, true);
	getChild<LLUICtrl>("dictionary_name")->setValue(mDictionaryBasename);
}

void LLFloaterSpellCheckerImport::onBtnCancel()
{
	closeFloater(false);
}

void LLFloaterSpellCheckerImport::onBtnOK()
{
	const std::string dict_dic = mDictionaryDir + gDirUtilp->getDirDelimiter() + mDictionaryBasename + ".dic";
	const std::string dict_aff = mDictionaryDir + gDirUtilp->getDirDelimiter() + mDictionaryBasename + ".aff";
	std::string dict_language = getChild<LLUICtrl>("dictionary_language")->getValue().asString();
	LLStringUtil::trim(dict_language);

	bool imported = false;
	if (   dict_language.empty()
		|| mDictionaryDir.empty()
		|| mDictionaryBasename.empty()
		|| ! gDirUtilp->fileExists(dict_dic)
		)
	{
		LLNotificationsUtil::add("SpellingDictImportRequired");
	}
	else
	{
		std::string settings_dic = LLSpellChecker::getDictionaryUserPath() + mDictionaryBasename + ".dic";
		if ( LLFile::copy( dict_dic, settings_dic ) )
		{
			if (gDirUtilp->fileExists(dict_aff))
			{
				std::string settings_aff = LLSpellChecker::getDictionaryUserPath() + mDictionaryBasename + ".aff";
				if ( LLFile::copy( dict_aff, settings_aff ))
				{
					imported = true;
				}
				else
				{
					LLSD args = LLSD::emptyMap();
					args["FROM_NAME"] = dict_aff;
					args["TO_NAME"] = settings_aff;
					LLNotificationsUtil::add("SpellingDictImportFailed", args);
				}
			}
			else
			{
				LLSD args = LLSD::emptyMap();
				args["DIC_NAME"] = dict_dic;
				LLNotificationsUtil::add("SpellingDictIsSecondary", args);

				imported = true;
			}
		}
		else
		{
			LLSD args = LLSD::emptyMap();
			args["FROM_NAME"] = dict_dic;
			args["TO_NAME"] = settings_dic;
			LLNotificationsUtil::add("SpellingDictImportFailed", args);
		}
	}

	if ( imported )
	{
		LLSD custom_dict_info;
		custom_dict_info["is_primary"] = (bool)gDirUtilp->fileExists(dict_aff);
		custom_dict_info["name"] = mDictionaryBasename;
		custom_dict_info["language"] = dict_language;

		LLSD custom_dict_map;
        std::string custom_filename(LLSpellChecker::getDictionaryUserPath() + "user_dictionaries.xml");
		llifstream custom_file_in(custom_filename.c_str());
		if (custom_file_in.is_open())
		{
			LLSDSerialize::fromXMLDocument(custom_dict_map, custom_file_in);
			custom_file_in.close();
		}

		LLSD::array_iterator it = custom_dict_map.beginArray();
		for (; it != custom_dict_map.endArray(); ++it)
		{
			LLSD& dict_info = *it;
			if (dict_info["name"].asString() == mDictionaryBasename)
			{
				dict_info = custom_dict_info;
				break;
			}
		}
		if (custom_dict_map.endArray() == it)
		{
			custom_dict_map.append(custom_dict_info);
		}

		llofstream custom_file_out(custom_filename.c_str(), std::ios::trunc);
		if (custom_file_out.is_open())
		{
			LLSDSerialize::toPrettyXML(custom_dict_map, custom_file_out);
			custom_file_out.close();
		}

		LLSpellChecker::getInstance()->refreshDictionaryMap();
	}

	closeFloater(false);
}

std::string LLFloaterSpellCheckerImport::parseXcuFile(const std::string& file_path) const
{
	LLXMLNodePtr xml_root;
	if ( (!LLUICtrlFactory::getLayeredXMLNode(file_path, xml_root)) || (xml_root.isNull()) )
	{
		return LLStringUtil::null;
	}

	// Bury down to the "Dictionaries" parent node
	LLXMLNode* dict_node = NULL;
	for (LLXMLNode* outer_node = xml_root->getFirstChild(); outer_node && !dict_node; outer_node = outer_node->getNextSibling())
	{
		std::string temp;
		if ( (outer_node->getAttributeString("oor:name", temp)) && ("ServiceManager" == temp) )
		{
			for (LLXMLNode* inner_node = outer_node->getFirstChild(); inner_node && !dict_node; inner_node = inner_node->getNextSibling())
			{
				if ( (inner_node->getAttributeString("oor:name", temp)) && ("Dictionaries" == temp) )
				{
					dict_node = inner_node;
					break;
				}
			}
		}
	}

	if (dict_node)
	{
		// Iterate over all child nodes until we find one that has a <value>DICT_SPELL</value> node
		for (LLXMLNode* outer_node = dict_node->getFirstChild(); outer_node; outer_node = outer_node->getNextSibling())
		{
			std::string temp;
			LLXMLNodePtr location_node, format_node;
			for (LLXMLNode* inner_node = outer_node->getFirstChild(); inner_node; inner_node = inner_node->getNextSibling())
			{
				if (inner_node->getAttributeString("oor:name", temp))
				{
					if ("Locations" == temp)
					{
						inner_node->getChild("value", location_node, false);
					}
					else if ("Format" == temp)
					{
						inner_node->getChild("value", format_node, false);
					}
				}
			}
			if ( (format_node.isNull()) || ("DICT_SPELL" != format_node->getValue()) || (location_node.isNull()) )
			{
				continue;
			}

			// Found a list of file locations, return the .dic (if present)
			std::list<std::string> location_list;
			boost::split(location_list, location_node->getValue(), boost::is_any_of(std::string(" ")));
			for (std::list<std::string>::iterator it = location_list.begin(); it != location_list.end(); ++it)
			{
				std::string& location = *it;
				if ("\\" != gDirUtilp->getDirDelimiter())
					LLStringUtil::replaceString(location, "\\", gDirUtilp->getDirDelimiter());
				else
					LLStringUtil::replaceString(location, "/", gDirUtilp->getDirDelimiter());
				LLStringUtil::replaceString(location, "%origin%", gDirUtilp->getDirName(file_path));
				if ("dic" == gDirUtilp->getExtension(location))
				{
					return location;
				}
			}
		}
	}

	return LLStringUtil::null;
}

max_stars_repo_name: SaladDais/LLUDP-Encryption

max_issues_repo_name: bloomsirenix/Firestorm-manikineko

max_forks_repo_name: bloomsirenix/Firestorm-manikineko


text:
/* (c) Copyright 2012 Felipe Magno de Almeida
 *
 * 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)
 */

#include <morbid/orb.hpp>
#include <morbid/giop/forward_back_insert_iterator.hpp>
#include <morbid/ior/grammar/corbaloc.hpp>
#include <morbid/ior/grammar/ior.hpp>
#include <morbid/ior/grammar/tagged_profile.hpp>
#include <morbid/ior/grammar/generic_tagged_profile.hpp>
#include <morbid/ior/hex_directive.hpp>
#include <morbid/iiop/all.hpp>
#include <morbid/iiop/grammars/profile_body_1_1.hpp>

#include <boost/algorithm/hex.hpp>

#include <cstring>

namespace std {

std::ostream& operator<<(std::ostream& os, std::vector<char>::iterator i)
{
  return os << "[vector Iterator]";
}

}

namespace morbid {

ORB_ptr ORB_init(int argc, const char* argv[], const char* str_op)
{
  ORB_ptr orb(new ORB);
  return orb;
}

ORB::ORB()
{
  const char rootpoa[] = {"RootPOA"};
  String_ptr p(new char[sizeof(rootpoa)-1]);
  std::memcpy(p/*.get()*/, rootpoa, sizeof(rootpoa)-1);
  root_poa.reset(new poa::POA(p, io_service));
}

Object_ptr ORB::resolve_initial_references(const char* id)
{
  if(!std::strcmp(id, "RootPOA"))
    return Object_ptr(root_poa);
  else
    return Object_ptr();
}

String_ptr ORB::object_to_string(Object_ptr p)
{
  std::cout << "Object to string" << std::endl;
  structured_ior sior = p->_structured_ior();

  typedef giop::forward_back_insert_iterator<std::vector<char> > output_iterator_type;
  typedef structured_ior attribute_type;
  typedef ior::grammar::ior<iiop::generator_domain, output_iterator_type
                            , attribute_type>
    ior_grammar_type;

  ior::grammar::tagged_profile<iiop::generator_domain, output_iterator_type
                               , ior::tagged_profile> tagged_profile;
  iiop::grammar::profile_body_1_0<iiop::generator_domain, output_iterator_type
                                  , iiop::profile_body> profile_body;
  ior::grammar::generic_tagged_profile<iiop::generator_domain, output_iterator_type
                                       , iiop::profile_body, 0u
                                       > tagged_profile_body
    (giop::endianness[profile_body]);

  ior_grammar_type ior_grammar(tagged_profile | tagged_profile_body);

  std::vector<char> ior;
  namespace karma = boost::spirit::karma;
  output_iterator_type iterator(ior);
  if(karma::generate(iterator
                     , karma::lit("IOR:")
                     << ior::hex
                     [
                      giop::compile<iiop::generator_domain>
                      (giop::endianness(giop::native_endian)[ior_grammar])
                     ]
                     , sior))
  {
    std::cout << "Success" << std::endl;
    std::copy(ior.begin(), ior.end(), std::ostream_iterator<char>(std::cout));
    std::endl(std::cout);

    char* string = new char[ior.size()+1];
    string[ior.size()] = 0;
    std::copy(ior.begin(), ior.end(), string);
    return string;
  }
  else
  {
    std::cout << "Failed generating string for object reference" << std::endl;
    throw std::runtime_error("Failed generating string for object reference");
  }
}

Object_ptr ORB::string_to_object(const char* ref)
{
  std::cout << "string_to_object" << std::endl;
  typedef const char* iterator_type;
  typedef std::vector<char> hex_parser_container;
  typedef hex_parser_container::const_iterator hex_iterator;
  iterator_type first = ref, last = ref + std::strlen(ref);

  typedef structured_ior attribute_type;
  namespace fusion = boost::fusion;
  typedef fusion::result_of::as_vector
    <fusion::joint_view<fusion::single_view<char> // minor version
                        , iiop::profile_body> >::type profile_body_1_1_attr;

  ior::grammar::tagged_profile<iiop::parser_domain, hex_iterator
                               , ior::tagged_profile> tagged_profile;
  iiop::grammar::profile_body_1_0<iiop::parser_domain, hex_iterator
                                  , iiop::profile_body> profile_body_1_0;
  iiop::grammar::profile_body_1_1<iiop::parser_domain, hex_iterator
                                  , profile_body_1_1_attr> profile_body_1_1;
  ior::grammar::generic_tagged_profile<iiop::parser_domain, hex_iterator
                                       , boost::variant<iiop::profile_body, profile_body_1_1_attr>, 0u
                                       > tagged_profile_body
    (giop::endianness[profile_body_1_0 | profile_body_1_1]);

  typedef fusion::vector2<std::string
                  , std::vector
                   <boost::variant<iiop::profile_body, profile_body_1_1_attr, ior::tagged_profile> >
                  > result_type;
  result_type r;

  typedef ior::grammar::ior<iiop::parser_domain, hex_iterator, result_type>
    ior_grammar_type;

  ior_grammar_type ior_grammar(tagged_profile_body | tagged_profile);
  namespace qi = boost::spirit::qi;
  iterator_type first_tmp = first;
  if(qi::parse(first_tmp, last
               ,  qi::lit("IOR:")
               >> ior::hex
               [
                giop::compile<iiop::parser_domain>(giop::endianness[ior_grammar])
               ]
               , r))
  {
    std::cout << "Success" << std::endl;
    structured_ior sior = {fusion::at_c<0u>(r)};

    for(std::vector<boost::variant<iiop::profile_body, profile_body_1_1_attr, ior::tagged_profile> >::const_iterator
          first = fusion::at_c<1u>(r).begin()
          , last = fusion::at_c<1u>(r).end(); first != last; ++first)
    {
      if(iiop::profile_body const* p = boost::get<iiop::profile_body>(&*first))
        sior.structured_profiles.push_back(*p);
      else if(ior::tagged_profile const* p = boost::get<ior::tagged_profile>(&*first))
        sior.structured_profiles.push_back(*p);
      else if(profile_body_1_1_attr const* p = boost::get<profile_body_1_1_attr>(&*first))
      {
        iiop::profile_body b;
        fusion::copy(fusion::pop_front(*p), b);
        sior.structured_profiles.push_back(b);
      }
    }

    return Object_ptr(new ::morbid::remote_stub::Object(sior));
  }
  throw morbid::INVALID_PARAM();
}

void ORB::shutdown(bool wait_for_completion)
{
  io_service.stop();
}

void ORB::run()
{
  boost::asio::io_service::work w(io_service);
  io_service.run();
}

}

max_stars_repo_name: felipealmeida/mORBid

max_issues_repo_name: felipealmeida/mORBid

max_forks_repo_name: felipealmeida/mORBid


text:
#include "rbfcore.h"
#include "utility.h"
#include "Solver.h"
#include <armadillo>
#include <fstream>
#include <limits>
#include <iomanip>
#include <ctime>
#include <chrono>
#include<algorithm>

double sigma = 2.0;
double inv_sigma_squarex2 = 1 / (2 * pow(sigma, 2));

double Gaussian_Kernel(const double x_square) {
    return exp(-x_square * inv_sigma_squarex2);
}

double Gaussian_Kernel_2p(const double *p1, const double *p2) {
    return Gaussian_Kernel(MyUtility::vecSquareDist(p1, p2));
}

double Gaussian_PKernel_Dirichlet_2p(const double *p1, const double *p2) {
    double d2 = MyUtility::vecSquareDist(p1, p2);
    return (6 * sigma * sigma - d2) * sqrt(Gaussian_Kernel(d2));
}

double Gaussian_PKernel_Bending_2p(const double *p1, const double *p2) {

    double d2 = MyUtility::vecSquareDist(p1, p2);
    double d4 = d2 * d2;
    double sigma2 = sigma * sigma;
    double sigma4 = sigma2 * sigma2;
    return (60 * sigma4 - 20 * sigma2 * d2 + d4) * sqrt(Gaussian_Kernel(d2));

}

double XCube_Kernel(const double x) {

    return pow(x, 3);
}

double XCube_Kernel_2p(const double *p1, const double *p2) {

    return XCube_Kernel(MyUtility::_VerticesDistance(p1, p2));

}

void XCube_Gradient_Kernel_2p(const double *p1, const double *p2, double *G) {
    double len_dist = MyUtility::_VerticesDistance(p1, p2);
    for (int i = 0; i < 3; ++i)
        G[i] = 3 * len_dist * (p1[i] - p2[i]);
    return;

}

double XCube_GradientDot_Kernel_2p(const double *p1, const double *p2, const double *p3) {

    double G[3];
    XCube_Gradient_Kernel_2p(p1, p2, G);
    return MyUtility::dot(p3, G);

}

void XCube_Hessian_Kernel_2p(const double *p1, const double *p2, double *H) {

    double diff[3];
    for (int i = 0; i < 3; ++i)diff[i] = p1[i] - p2[i];
    double len_dist = sqrt(MyUtility::len(diff));

    if (len_dist < 1e-8) {
        for (int i = 0; i < 9; ++i)H[i] = 0;
    } else {
        for (int i = 0; i < 3; ++i) {
            H[i * 3 + i] = 3 * pow(diff[i], 2) / len_dist + 3 * len_dist;
            for (int j = i + 1; j < 3; ++j) {
                H[j * 3 + i] = H[i * 3 + j] = 3 * diff[i] * diff[j] / len_dist;
            }
        }
    }

    return;

}

void XCube_HessianDot_Kernel_2p(const double *p1, const double *p2, const double *p3, vector<double> &dotout) {

    double H[9];
    XCube_Gradient_Kernel_2p(p1, p2, H);
    dotout.resize(3);
    for (int i = 0; i < 3; ++i) {
        dotout[i] = 0;
        for (int j = 0; j < 3; ++j) {
            dotout[i] += H[i * 3 + j] * p3[j];
        }
    }

}

RBF_Core::RBF_Core() {

    Kernal_Function = Gaussian_Kernel;
    Kernal_Function_2p = Gaussian_Kernel_2p;
    P_Function_2p = Gaussian_PKernel_Dirichlet_2p;

    isHermite = false;

    mp_RBF_INITMETHOD.insert(make_pair(GT_NORMAL, "GT_NORMAL"));
    mp_RBF_INITMETHOD.insert(make_pair(GlobalEigen, "GlobalEigen"));
    mp_RBF_INITMETHOD.insert(make_pair(GlobalEigenWithMST, "GlobalEigenWithMST"));
    mp_RBF_INITMETHOD.insert(make_pair(GlobalEigenWithGT, "GlobalEigenWithGT"));
    mp_RBF_INITMETHOD.insert(make_pair(LocalEigen, "LocalEigen"));
    mp_RBF_INITMETHOD.insert(make_pair(IterativeEigen, "IterativeEigen"));
    mp_RBF_INITMETHOD.insert(make_pair(ClusterEigen, "ClusterEigen"));
    mp_RBF_INITMETHOD.insert(make_pair(Lamnbda_Search, "LamnbdaSearch"));

    mp_RBF_METHOD.insert(make_pair(Variational, "Variational"));
    mp_RBF_METHOD.insert(make_pair(Variational_P, "Variation_P"));
    mp_RBF_METHOD.insert(make_pair(LS, "LS"));
    mp_RBF_METHOD.insert(make_pair(LSinterp, "LSinterp"));
    mp_RBF_METHOD.insert(make_pair(Interp, "Interp"));
    mp_RBF_METHOD.insert(make_pair(RayleighQuotients, "Rayleigh"));
    mp_RBF_METHOD.insert(make_pair(RayleighQuotients_P, "Rayleigh_P"));
    mp_RBF_METHOD.insert(make_pair(RayleighQuotients_I, "Rayleigh_I"));
    mp_RBF_METHOD.insert(make_pair(Hermite, "Hermite"));
    mp_RBF_METHOD.insert(make_pair(Hermite_UnitNorm, "UnitNorm"));
    mp_RBF_METHOD.insert(make_pair(Hermite_UnitNormal, "UnitNormal"));
    mp_RBF_METHOD.insert(make_pair(Hermite_Tangent_UnitNorm, "T_UnitNorm"));
    mp_RBF_METHOD.insert(make_pair(Hermite_Tangent_UnitNormal, "T_UnitNormal"));

    mp_RBF_Kernal.insert(make_pair(XCube, "TriH"));
    mp_RBF_Kernal.insert(make_pair(ThinSpline, "ThinSpline"));
    mp_RBF_Kernal.insert(make_pair(XLinear, "XLinear"));
    mp_RBF_Kernal.insert(make_pair(Gaussian, "Gaussian"));

}

RBF_Core::RBF_Core(RBF_Kernal kernal) {
    isHermite = false;
    Init(kernal);
}

void RBF_Core::Init(RBF_Kernal kernal) {

    this->kernal = kernal;
    switch (kernal) {
        case Gaussian:
            Kernal_Function = Gaussian_Kernel;
            Kernal_Function_2p = Gaussian_Kernel_2p;
            P_Function_2p = Gaussian_PKernel_Dirichlet_2p;
            break;

        case XCube:
            Kernal_Function = XCube_Kernel;
            Kernal_Function_2p = XCube_Kernel_2p;
            Kernal_Gradient_Function_2p = XCube_Gradient_Kernel_2p;
            Kernal_Hessian_Function_2p = XCube_Hessian_Kernel_2p;
            break;

        default:
            break;

    }

}

void RBF_Core::SetSigma(double x) {
    sigma = x;
    inv_sigma_squarex2 = 1 / (2 * pow(sigma, 2));
}

double RBF_Core::Dist_Function(const double x, const double y, const double z) {
    return RBF_Core::Dist_Function(R3Pt(x, y, z));
}

inline double RBF_Core::Dist_Function(const double *p) {
    n_evacalls++;
    double *p_pts = pts.data();
    static arma::vec kern(npt), kb;
    if (isHermite) {
        kern.set_size(npt * 4);
        double G[3];
        for (int i = 0; i < npt; ++i) {
            kern(i) = Kernal_Function_2p(p_pts + i * 3, p);
            Kernal_Gradient_Function_2p(p, p_pts + i * 3, G);
            //for(int j=0;j<3;++j)kern(npt+i*3+j) = -G[j];
            for (int j = 0; j < 3; ++j)
                kern(npt + i * 3 + j) = G[j];
        }
    } else {
//        kern.set_size(npt);
//        for (int i = 0; i < npt; ++i)
//            kern(i) = Kernal_Function_2p(p_pts + i * 3, p);
    }

    double loc_part = dot(kern, a);

    if (polyDeg == 1) {
        //here for hermite
        kb.set_size(4);
        for (int i = 0; i < 3; ++i)
            kb(i + 1) = p[i];
        kb(0) = 1;
    } else if (polyDeg == 2) {
//        vector<double> buf(4, 1);
//        int ind = 0;
//        kb.set_size(10);
//        for (int j = 0; j < 3; ++j)buf[j + 1] = p[j];
//        for (int j = 0; j < 4; ++j)
//            for (int k = j; k < 4; ++k)
//                kb(ind++) = buf[j] * buf[k];
        // kb = 1,x,y,z,xx,xy,xz,yy,yz,zz

    }
    double poly_part = dot(kb, b);

    if (0) {
        cout << "dist: " << p[0] << ' ' << p[1] << ' ' << p[2] << ' ' << p_pts[3] << ' ' << p_pts[4] << ' ' << p_pts[5]
             << ' ' <<
             Kernal_Function_2p(p, p_pts + 3) << endl;
        for (int i = 0; i < npt; ++i)cout << kern(i) << ' ';
        for (int i = 0; i < bsize; ++i)cout << kb(i) << ' ';
        cout << endl;
    }

    double re = loc_part + poly_part;
    return re;

}

static RBF_Core *s_hrbf;

double RBF_Core::Dist_Function(const R3Pt &in_pt) {
    return s_hrbf->Dist_Function(&(in_pt[0]));
}

//FT RBF_Core::Dist_Function(const Point_3 in_pt){

//    return s_hrbf->Dist_Function(&(in_pt.x()));
//}

void RBF_Core::SetThis() {

    s_hrbf = this;
}

void RBF_Core::Write_Surface(string fname) {

    //writeObjFile(fname,finalMesh_v,finalMesh_fv);

    writePLYFile_VF(fname, finalMesh_v, finalMesh_fv);
}

/**********************************************************/

void RBF_Core::Record(RBF_METHOD method, RBF_Kernal kernal, Solution_Struct &rsol, double time) {

    npoints.push_back(npt);

    record_initmethod.push_back(mp_RBF_INITMETHOD[curInitMethod]);
    record_method.push_back(mp_RBF_METHOD[method]);
    record_kernal.push_back(mp_RBF_Kernal[kernal]);
    record_initenergy.push_back(rsol.init_energy);
    record_energy.push_back(rsol.energy);
    record_time.push_back(time);

    setup_timev.push_back(setup_time);
    init_timev.push_back(init_time);
    solve_timev.push_back(solve_time);
    callfunc_timev.push_back(callfunc_time);
    invM_timev.push_back(invM_time);
    setK_timev.push_back(setK_time);

}

void RBF_Core::Record() {

    //cout<<"record"<<endl;
    npoints.push_back(npt);

    record_initmethod.push_back(mp_RBF_INITMETHOD[curInitMethod]);
    record_method.push_back(mp_RBF_METHOD[curMethod]);
    //record_kernal.push_back(mp_RBF_Kernal[kernal]);
    record_initenergy.push_back(sol.init_energy);
    record_energy.push_back(sol.energy);
    //cout<<"record"<<endl;

//    setup_timev.push_back(setup_time);
//    init_timev.push_back(init_time);
//    solve_timev.push_back(solve_time);
//    callfunc_timev.push_back(callfunc_time);
//    invM_timev.push_back(invM_time);
//    setK_timev.push_back(setK_time);
    // cout<<"record end"<<endl;
}

void RBF_Core::AddPartition(string pname) {

    record_partition.push_back(record_method.size());
    record_partition_name.push_back(pname);
}

void RBF_Core::Print_Record() {

    cout << "Method\t\t Kernal\t\t Energy\t\t Time" << endl;
    cout << std::setprecision(8) << endl;
    if (record_partition.size() == 0) {
        for (int i = 0; i < record_method.size(); ++i) {
            cout << record_method[i] << "\t\t" << record_kernal[i] << "\t\t" << record_energy[i] << "\t\t"
                 << record_time[i] << endl;
        }
        for (int i = 0; i < setup_timev.size(); ++i) {
            cout << setup_timev[i] << "\t\t" << init_timev[i] << "\t\t" << solve_timev[i] << "\t\t" << callfunc_timev[i]
                 << "\t\t" << invM_timev[i] << "\t\t" << setK_timev[i] << endl;
        }
    } else {
        for (int j = 0; j < record_partition.size(); ++j) {
            cout << record_partition_name[j] << endl;
            for (int i = j == 0 ? 0 : record_partition[j - 1]; i < record_partition[j]; ++i) {
                cout << record_method[i] << "\t\t" << record_kernal[i] << "\t\t" << record_energy[i] << "\t\t"
                     << record_time[i] << endl;
            }
            for (int i = j == 0 ? 0 : record_partition[j - 1]; i < record_partition[j]; ++i) {
                cout << setup_timev[i] << "\t\t" << init_timev[i] << "\t\t" << solve_timev[i] << "\t\t"
                     << callfunc_timev[i] << endl;
            }
        }
    }

}

void RBF_Core::Print_TimerRecord(string fname) {

    ofstream fout(fname);
    fout << setprecision(5);
    if (!fout.fail()) {
        for (int i = 0; i < setup_timev.size(); ++i) {
            fout << npoints[i] << '\t' << setup_timev[i] << "\t" << init_timev[i] << "\t" << solve_timev[i] << "\t"
                 << callfunc_timev[i] << "\t" << invM_timev[i] << "\t" << setK_timev[i] << endl;
        }
    }
    fout.close();

}

void RBF_Core::Print_TimerRecord_Single(string fname) {

    ofstream fout(fname);
    fout << setprecision(5);
    if (!fout.fail()) {
        fout << "number of points: " << npt << endl
             << "setup_time (Compute H): " << setup_time << " s" << endl
             << "init_time (Optimize g/Eigen): " << init_time << " s" << endl
             << "solve_time (Optimize g/LBFGS): " << solve_time << " s" << endl
             << "surfacing_time: " << surf_time << " s" << endl;
    }
    fout.close();
}

void RBF_Core::Clear_TimerRecord() {
    npoints.clear();
    setup_timev.clear();
    init_timev.clear();
    solve_timev.clear();
    callfunc_timev.clear();
    invM_timev.clear();
    setK_timev.clear();

}

max_stars_repo_name: ErvinXie/VIPSS

max_issues_repo_name: ErvinXie/VIPSS

max_forks_repo_name: ErvinXie/VIPSS


text:
//
// Copyright (c) 2011-2012 Krzysztof Jusiak (krzysztof at jusiak dot net)
//
// 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)
//
#ifndef QFSM_BACK_FSMBASE_HPP
#define QFSM_BACK_FSMBASE_HPP

#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/iteration/local.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/type_traits/is_base_of.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/mpl/assert.hpp>
#include "QFsm/Back/Aux/Detail/Ctor.hpp"
#include "QFsm/Back/Aux/Detail/Trace.hpp"
#include "QFsm/Back/Aux/Internal.hpp"
#include "QFsm/Back/Aux/States.hpp"
#include "QFsm/Back/Aux/Events.hpp"
#include "QFsm/Back/Aux/FsmType.hpp"
#include "QFsm/Back/Logger.hpp"

#include "QFsm/Back/Detail/Init.hpp"
#include "QFsm/Back/Detail/HandleEvent.hpp"
#include "QFsm/Back/Detail/Transition.hpp"
#include "QFsm/Back/Detail/UnexpectedEvent.hpp"
#include "QFsm/Back/Detail/Visitor.hpp"

#if defined(QFSM_EXTENSIONS_UML)
# include "QFsm/Back/Detail/OnAction.hpp"
# include "QFsm/Back/Detail/CompletionTransition.hpp"
# include "QFsm/Back/Detail/Composite.hpp"
# include "QFsm/Back/Detail/DeferralEvent.hpp"
# include "QFsm/Back/Detail/InternalEvent.hpp"
# include "QFsm/Back/Detail/Terminate.hpp"
#endif

#if defined(QFSM_EXTENSIONS_NON_UML)
# include "QFsm/Back/Detail/Interrupt.hpp"
# include "QFsm/Back/Detail/Else.hpp"
#endif

namespace QFsm
{
namespace Back
{

template
<
    typename TFsm,
    typename TDerived,
    typename TPool,
    typename TState
>
class FsmBase : Back::Aux::FsmType, public TDerived
{
public:
    typedef TFsm Fsm;
    typedef TDerived Derived;
    typedef TState State;
    typedef typename boost::remove_reference<TPool>::type Pool;
    typedef Logger<typename TDerived::Logger> Log;

    typedef typename Aux::States<typename TDerived::TransitionTable>::type States;
    typedef typename Aux::Events<TDerived>::type Events;

    CTOR_REF(FsmBase, pool,
        {
            TRACE("transition table: %s", Aux::Detail::printType<typename TDerived::TransitionTable>().c_str());
            TRACE("initial state: %s", Aux::Detail::printType<typename TDerived::InitialState>().c_str());
            Detail::Init<FsmBase>::execute(*this);
        }
    )

    void start()
    {
       QFSM_UML_EXTENSIONS(
            Detail::OnAction<FsmBase, Front::Operations::OnEntry>::execute(*this);
            Detail::CompletionTransition<FsmBase>::execute(*this);
        )
    }

    void stop()
    {
        QFSM_UML_EXTENSIONS(
            Detail::OnAction<FsmBase, Front::Operations::OnExit>::execute(*this);
        )
    }

    template<typename Event> bool processEvent(const Event& p_event)
    {
        TRACE("[%s]", typeid(Event).name());

        BOOST_MPL_ASSERT_MSG(
            (!boost::is_base_of<Aux::Internal, Event>::value),
            INTERNAL_TYPES_ARE_NOT_ALLOWED,
            (Event)
        );

        Log::template onEventReceived<Event>(pool);

        return processEventImpl(p_event);
    }

    template<typename Visitor> void visitCurrentStates(Visitor p_visitor)
    {
        Detail::Visitor<FsmBase>::execute(*this, p_visitor);
    }

#   define BOOST_PP_LOCAL_LIMITS (1, BOOST_MPL_LIMIT_VECTOR_SIZE)
#   define FSMBASE_SET_IMPL(z, n, text) text.set<T##n>(p_arg##n);

#   define BOOST_PP_LOCAL_MACRO(n)\
        template<BOOST_PP_ENUM_PARAMS(n, typename T)> void set(BOOST_PP_ENUM_BINARY_PARAMS(n, T, p_arg))\
        {\
            BOOST_PP_REPEAT(n, FSMBASE_SET_IMPL, pool)\
        }

#   include BOOST_PP_LOCAL_ITERATE()
#   undef FSMBASE_SET_IMPL

    template<typename T> T& get() { return pool.template acquire<T>(); }

    template<typename Event> bool processEventImpl(const Event& p_event)
    {
        TRACE("process event: [%s]", typeid(Event).name());

        bool l_handled = false;

        QFSM_UML_EXTENSIONS(
            deferralEvents.init();
        )

        QFSM_UML_EXTENSIONS(
            if (!Detail::Terminate<FsmBase>::execute(*this, p_event))
            {
                return false;
            }
        )

        QFSM_NON_UML_EXTENSIONS(
            if (!Detail::Interrupt<FsmBase>::execute(*this, p_event))
            {
                return false;
            }
        )

        QFSM_UML_EXTENSIONS(
            if (Detail::Composite<FsmBase>::execute(*this, p_event))
            {
                return true;
            }
        )

        Detail::HandleEvent<FsmBase>::execute(*this, p_event, l_handled);

        QFSM_NON_UML_EXTENSIONS(
            Detail::Else<FsmBase>::execute(*this, l_handled);
        )

        QFSM_UML_EXTENSIONS(
            deferralEvents.execute(l_handled);
            internalEvents.execute(l_handled);
            Detail::CompletionTransition<FsmBase>::execute(*this, l_handled);
        )

        return Detail::UnexpectedEvent<FsmBase>::execute(*this, p_event, l_handled);
    }

    TPool pool;
    TState currentStates[OrthogonalRegions<TDerived>::NumberOfOrthogonalRegions::value];
    QFSM_UML_EXTENSIONS(Detail::DeferralEvent<FsmBase> deferralEvents;)
    QFSM_UML_EXTENSIONS(Detail::InternalEvent<FsmBase> internalEvents;)
};

} // namespace Back
} // namespace QFsm

#endif

max_stars_repo_name: krzysztof-jusiak/qfsm

max_issues_repo_name: krzysztof-jusiak/qfsm

max_forks_repo_name: krzysztof-jusiak/qfsm


text: #include <boost/python/def_visitor.hpp>


text:
#include "testsuite.h"
#include <blitz/array.h>

// test the update operators

BZ_USING_NAMESPACE(blitz)

int main()
{
  // First with scalars
  {
    Array<int,1> a(5);
    a=1;

    a+=1;
    BZTEST(all(a==2));

    a-=1;
    BZTEST(all(a==1));

    a*=8;
    BZTEST(all(a==8));

    a/=2;
    BZTEST(all(a==4));

    a%=3;
    BZTEST(all(a==1));

    a^=2;
    BZTEST(all(a==3));

    a&=6;
    BZTEST(all(a==2));

    a|=8;
    BZTEST(all(a==10));

    a<<=1;
    BZTEST(all(a==20));

    a>>=2;
    BZTEST(all(a==5));
  }

  // And now with Arrays
  {
    Array<int,1> a(5),b(5);
    a=1;

    b=1;
    a+=b;
    BZTEST(all(a==2));

    a-=b;
    BZTEST(all(a==1));

    b=8;
    a*=b;
    BZTEST(all(a==8));

    b=2;
    a/=b;
    BZTEST(all(a==4));

    b=3;
    a%=b;
    BZTEST(all(a==1));

    b=2;
    a^=b;
    BZTEST(all(a==3));

    b=6;
    a&=b;
    BZTEST(all(a==2));

    b=8;
    a|=b;
    BZTEST(all(a==10));

    b=1;
    a<<=b;
    BZTEST(all(a==20));

    b=2;
    a>>=b;
    BZTEST(all(a==5));
  }

  // And now with expressions
  {
    Array<int,1> a(5),b(5);
    a=1;

    b=1;
    a+=1*b;
    BZTEST(all(a==2));

    a-=1*b;
    BZTEST(all(a==1));

    b=8;
    a*=1*b;
    BZTEST(all(a==8));

    b=2;
    a/=1*b;
    BZTEST(all(a==4));

    b=3;
    a%=1*b;
    BZTEST(all(a==1));

    b=2;
    a^=1*b;
    BZTEST(all(a==3));

    b=6;
    a&=1*b;
    BZTEST(all(a==2));

    b=8;
    a|=1*b;
    BZTEST(all(a==10));

    b=1;
    a<<=1*b;
    BZTEST(all(a==20));

    b=2;
    a>>=1*b;
    BZTEST(all(a==5));
  }

  return 0;
}

max_stars_repo_name: fraguela/depspawn

max_issues_repo_name: MSV-Project/IBAMR

max_forks_repo_name: MSV-Project/IBAMR