text:
#if 0
#include <stdexcept>
#include <iostream>
#include <sstream>

#include <boost/optional.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/optional.hpp>

struct Foo
{
    Foo(int aBar) :
        mBar(aBar)
    {
        if (mBar > 10)
        {
            throw std::logic_error("too big bar");
        }
    }
    int bar() const
    {
        return mBar;
    }
    bool operator==(const Foo & rhs) const {
        return mBar == rhs.mBar;
    }
private:
    int mBar;
};

namespace boost {
namespace serialization {

template<class Archive>
inline void serialize(Archive & ar, Foo& foo, const unsigned int /*version*/)
{
    std::cout << __FUNCTION__ << " called" << std::endl;
}

template<class Archive>
inline void save_construct_data(Archive & ar, const Foo* foo, const unsigned int /*version*/)
{
    std::cout << __FUNCTION__ << " called" << std::endl;
    ar & foo->bar();
}

template<class Archive>
inline void load_construct_data(Archive & ar, Foo* foo, const unsigned int /*version*/)
{
    std::cout << __FUNCTION__ << " called" << std::endl;
    int bar;
    ar & bar;
    ::new(foo) Foo(bar);
}

} // serialization
} // boost

int main()
{
    boost::optional<Foo> oldFoo = Foo(10);
    std::ostringstream outStream;
    boost::archive::text_oarchive outArchive(outStream);
    outArchive & oldFoo;

    boost::optional<Foo> newFoo;
    std::istringstream inStream(outStream.str());
    boost::archive::text_iarchive inArchive(inStream);
    inArchive & newFoo;

    return !(newFoo == oldFoo);
}

#elif 0
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// test_optional.cpp

// (C) Copyright 2004 Pavel Vozenilek
// Use, modification and distribution is 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)

// should pass compilation and execution

#include <cstddef> // NULL
#include <cstdio> // remove
#include <fstream>

#include <boost/config.hpp>

#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
    using ::remove;
}
#endif

#include <boost/archive/archive_exception.hpp>

#define BOOST_ARCHIVE_TEST xml_archive.hpp

#include "test_tools.hpp"

#include <boost/serialization/optional.hpp>

#include "A.hpp"
#include "A.ipp"

int test_main( int /* argc */, char* /* argv */[] )
{
    const char * testfile = boost::archive::tmpnam(NULL);
    BOOST_REQUIRE(NULL != testfile);

    const boost::optional<int> aoptional1;
    const boost::optional<int> aoptional2(123);
    {
        test_ostream os(testfile, TEST_STREAM_FLAGS);
        test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
        //oa << boost::serialization::make_nvp("aoptional1",aoptional1);
        //oa << boost::serialization::make_nvp("aoptional2",aoptional2);
    }
    /*
    boost::optional<int> aoptional1a(999);
    boost::optional<int> aoptional2a;
    {
        test_istream is(testfile, TEST_STREAM_FLAGS);
        test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
        ia >> boost::serialization::make_nvp("aoptional1",aoptional1a);
        ia >> boost::serialization::make_nvp("aoptional2",aoptional2a);
    }
    BOOST_CHECK(aoptional1 == aoptional1a);
    BOOST_CHECK(aoptional2 == aoptional2a);
    */
    std::remove(testfile);
    return EXIT_SUCCESS;
}

// EOF

#elif 0

#include <fstream>

#include <boost/archive/xml_woarchive.hpp>
#include <boost/archive/xml_wiarchive.hpp>
#include <boost/serialization/string.hpp>

#include "test_tools.hpp"

int test_main(int, char *argv[])
{
    const char * testfile = boost::archive::tmpnam(NULL);
	std::string s1 = "kkkabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
	std::wstring w1 = L"kkk";
	std::wstring w2 = L"апр"; // some non-latin (for example russians) letters
    {
        std::wofstream ofs(testfile);
        {
            boost::archive::xml_woarchive oa(ofs);
            oa << boost::serialization::make_nvp("key1", s1);
            //oa << boost::serialization::make_nvp("key2", w1);
            //oa << boost::serialization::make_nvp("key3", w2); // here exception is thrown
        }
    }
    std::string new_s1;
    //std::wstring new_w1;
    //std::wstring new_w2;
    {
        std::wifstream ifs(testfile);
        {
            boost::archive::xml_wiarchive ia(ifs);
            ia >> boost::serialization::make_nvp("key1", new_s1);
            //ia >> boost::serialization::make_nvp("key2", new_w1);
            //ia >> boost::serialization::make_nvp("key3", new_w2); // here exception is thrown
        }
    }
    BOOST_CHECK(s1 == new_s1);
    //BOOST_CHECK(w1 == new_w1);
    //BOOST_CHECK(w2 == new_w2);
	return 0;
}

#elif 0

#include <boost/archive/xml_oarchive.hpp>
#include <boost/serialization/nvp.hpp>

#include <iostream>

int main() {
        boost::archive::xml_oarchive oa( std::cerr );
        int bob = 3;
        oa << boost::serialization::make_nvp( "bob", bob );
}

#elif 0

#include <fstream>
#include <vector>
#include <iostream>

//#include <boost/shared_ptr.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/vector.hpp>

struct boxed_int
{
    boxed_int() : i(0) {}
    boxed_int(int i) : i(i) {}
    int i;
    template<class Archive>
    void serialize(Archive &ar, unsigned version)
    {
        ar & BOOST_SERIALIZATION_NVP(i);
    }
};
typedef boost::shared_ptr<boxed_int> pi;

void go(std::istream &is) {
    std::vector<pi> vv;
    try
    {
        boost::archive::binary_iarchive ia(is);
        ia & vv;
    }
    catch(std::exception &e) {}
}

int main(int argc, char **argv) {
    if(argc > 1) {
        std::ifstream is(argv[1]);
        go(is);
    } else {
        go(std::cin);
    }

    return 0;
}

#elif 0

#include <cassert>
#include <string>

#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/transform_width.hpp>

namespace bai = boost::archive::iterators;
int main()
{
    std::string input =
        "A large rose-tree stood near the entrance of the garden: the roses growing on it were white, but there were "
        "three gardeners at it, busily painting them red. Alice thought this a very curious thing, and she went nearer "
        "to watch them, and just as she came up to them she heard one of them say, 'Look out now, Five! Don't go "
        "splashing paint over me like that!''I couldn't help it,' said Five, in a sulky tone; 'Seven jogged my "
        "elbow.'On which Seven looked up and said, 'That's right, Five! Always lay the blame on others!''You'd better "
        "not talk!' said Five. 'I heard the Queen say only yesterday you deserved to be beheaded!''What for?' said the "
        "one who had spoken first.'That's none of your business, Two!' said Seven.'Yes, it is his business!' said "
        "Five, 'and I'll tell him—it was for bringing the cook tulip-roots instead of onions.'Seven flung down his "
        "brush, and had just begun 'Well, of all the unjust things—' when his eye chanced to fall upon Alice, as she "
        "stood watching them, and he checked himself suddenly: the others looked round also, and all of them bowed "
        "low.'Would you tell me,' said Alice, a little timidly, 'why you are painting those roses?'Five and Seven said "
        "nothing, but looked at Two. Two began in a low voice, 'Why the fact is, you see, Miss, this here ought to "
        "have been a red rose-tree, and we put a white one in by mistake; and if the Queen was to find it out, we "
        "should all have our heads cut off, you know. So you see, Miss, we're doing our best, afore she comes, to—' At "
        "this moment Five, who had been anxiously looking across the garden, called out 'The Queen! The Queen!' and "
        "the three gardeners instantly threw themselves flat upon their faces. There was a sound of many footsteps, "
        "and Alice looked round, eager to see the Queen.First came ten soldiers carrying clubs; these were all shaped "
        "like the three gardeners, oblong and flat, with their hands and feet at the corners: next the ten courtiers; "
        "these were ornamented all over with diamonds, and walked two and two, as the soldiers did. After these came "
        "the royal children; there were ten of them, and the little dears came jumping merrily along hand in hand, in "
        "couples: they were all ornamented with hearts. Next came the guests, mostly Kings and Queens, and among them "
        "Alice recognised the White Rabbit: it was talking in a hurried nervous manner, smiling at everything that was "
        "said, and went by without noticing her. Then followed the Knave of Hearts, carrying the King's crown on a "
        "crimson velvet cushion; and, last of all this grand procession, came THE KING AND QUEEN OF HEARTS.Alice was "
        "rather doubtful whether she ought not to lie down on her face like the three gardeners, but she could not "
        "remember ever having heard of such a rule at processions; 'and besides, what would be the use of a "
        "procession,' thought she, 'if people had all to lie down upon their faces, so that they couldn't see it?' So "
        "she stood still where she was, and waited.When the procession came opposite to Alice, they all stopped and "
        "looked at her, and the Queen said severely 'Who is this?' She said it to the Knave of Hearts, who only bowed "
        "and smiled in reply.'Idiot!' said the Queen, tossing her head impatiently; and, turning to Alice, she went "
        "on, 'What's your name, child?''My name is Alice, so please your Majesty,' said Alice very politely; but she "
        "added, to herself, 'Why, they're only a pack of cards, after all. I needn't be afraid of them!''And who are "
        "these?' said the Queen, pointing to the three gardeners who were lying round the rosetree; for, you see, as "
        "they were lying on their faces, and the pattern on their backs was the same as the rest of the pack, she "
        "could not tell whether they were gardeners, or soldiers, or courtiers, or three of her own children.'How "
        "should I know?' said Alice, surprised at her own courage. 'It's no business of mine.'The Queen turned crimson "
        "with fury, and, after glaring at her for a moment like a wild beast, screamed 'Off with her head! "
        "Off—''Nonsense!' said Alice, very loudly and decidedly, and the Queen was silent.The King laid his hand upon "
        "her arm, and timidly said 'Consider, my dear: she is only a child!'The Queen turned angrily away from him, "
        "and said to the Knave 'Turn them over!'The Knave did so, very carefully, with one foot.'Get up!' said the "
        "Queen, in a shrill, loud voice, and the three gardeners instantly jumped up, and began bowing to the King, "
        "the Queen, the royal children, and everybody else.'Leave off that!' screamed the Queen. 'You make me giddy.' "
        "And then, turning to the rose-tree, she went on, 'What have you been doing here?''May it please your "
        "Majesty,' said Two, in a very humble tone, going down on one knee as he spoke, 'we were trying—''I see!' said "
        "the Queen, who had meanwhile been examining the roses. 'Off with their heads!' and the procession moved on, "
        "three of the soldiers remaining behind to execute the unfortunate gardeners, who ran to Alice for "
        "protection.'You shan't be beheaded!' said Alice, and she put them into a large flower-pot that stood near. "
        "The three soldiers wandered about for a minute or two, looking for them, and then quietly marched off after "
        "the others.'Are their heads off?' shouted the Queen.'Their heads are gone, if it please your Majesty!' the "
        "soldiers shouted in reply.'That's right!' shouted the Queen. 'Can you play croquet?'The soldiers were silent, "
        "and looked at Alice, as the question was evidently meant for her.'Yes!' shouted Alice.'Come on, then!' roared "
        "the Queen, and Alice joined the procession, wondering very much what would happen next.'It's—it's a very fine "
        "day!' said a timid voice at her side. She was walking by the White Rabbit, who was peeping anxiously into her "
        "face.'Very,' said Alice: '—where's the Duchess?''Hush! Hush!' said the Rabbit in a low, hurried tone. He "
        "looked anxiously over his shoulder as he spoke, and then raised himself upon tiptoe, put his mouth close to "
        "her ear, and whispered 'She's under sentence of execution.''What for?' said Alice.'Did you say \"What a "
        "pity!\"?' the Rabbit asked.'No, I didn't,' said Alice: 'I don't think it's at all a pity. I said \"What "
        "for?\"''She boxed the Queen's ears—' the Rabbit began. Alice gave a little scream of laughter. 'Oh, hush!' "
        "the Rabbit whispered in a frightened tone. 'The Queen will hear you! You see, she came rather late, and the "
        "Queen said—''Get to your places!' shouted the Queen in a voice of thunder, and people began running about in "
        "all directions, tumbling up against each other; however, they got settled down in a minute or two, and the "
        "game began. Alice thought she had never seen such a curious croquet-ground in her life; it was all ridges and "
        "furrows; the balls were live hedgehogs, the mallets live flamingoes, and the soldiers had to double "
        "themselves up and to stand on their hands and feet, to make the arches.The chief difficulty Alice found at "
        "first was in managing her flamingo: she succeeded in getting its body tucked away, comfortably enough, under "
        "her arm, with its legs hanging down, but generally, just as she had got its neck nicely straightened out, and "
        "was going to give the hedgehog a blow with its head, it would twist itself round and look up in her face, "
        "with such a puzzled expression that she could not help bursting out laughing: and when she had got its head "
        "down, and was going to begin again, it was very provoking to find that the hedgehog had unrolled itself, and "
        "was in the act of crawling away: besides all this, there was generally a ridge or furrow in the way wherever "
        "she wanted to send the hedgehog to, and, as the doubled-up soldiers were always getting up and walking off to "
        "other parts of the ground, Alice soon came to the conclusion that it was a very difficult game indeed.The "
        "players all played at once without waiting for turns, quarrelling all the while, and fighting for the "
        "hedgehogs; and in a very short time the Queen was in a furious passion, and went stamping about, and shouting "
        "'Off with his head!' or 'Off with her head!' about once in a minute.Alice began to feel very uneasy: to be "
        "sure, she had not as yet had any dispute with the Queen, but she knew that it might happen any minute, 'and "
        "then,' thought she, 'what would become of me? They're dreadfully fond of beheading people here; the great "
        "wonder is, that there's any one left alive!'She was looking about for some way of escape, and wondering "
        "whether she could get away without being seen, when she noticed a curious appearance in the air: it puzzled "
        "her very much at first, but, after watching it a minute or two, she made it out to be a grin, and she said to "
        "herself 'It's the Cheshire Cat: now I shall have somebody to talk to.''How are you getting on?' said the Cat, "
        "as soon as there was mouth enough for it to speak with.Alice waited till the eyes appeared, and then nodded. "
        "'It's no use speaking to it,' she thought, 'till its ears have come, or at least one of them.' In another "
        "minute the whole head appeared, and then Alice put down her flamingo, and began an account of the game, "
        "feeling very glad she had someone to listen to her. The Cat seemed to think that there was enough of it now "
        "in sight, and no more of it appeared.'I don't think they play at all fairly,' Alice began, in rather a "
        "complaining tone, 'and they all quarrel so dreadfully one can't hear oneself speak—and they don't seem to "
        "have any rules in particular; at least, if there are, nobody attends to them—and you've no idea how confusing "
        "it is all the things being alive; for instance, there's the arch I've got to go through next walking about at "
        "the other end of the ground—and I should have croqueted the Queen's hedgehog just now, only it ran away when "
        "it saw mine coming!''How do you like the Queen?' said the Cat in a low voice.'Not at all,' said Alice: 'she's "
        "so extremely—' Just then she noticed that the Queen was close behind her, listening: so she went on, '—likely "
        "to win, that it's hardly worth while finishing the game.'The Queen smiled and passed on.'Who are you talking "
        "to?' said the King, going up to Alice, and looking at the Cat's head with great curiosity.'It's a friend of "
        "mine—a Cheshire Cat,' said Alice: 'allow me to introduce it.''I don't like the look of it at all,' said the "
        "King: 'however, it may kiss my hand if it likes.''I'd rather not,' the Cat remarked.'Don't be impertinent,' "
        "said the King, 'and don't look at me like that!' He got behind Alice as he spoke.'A cat may look at a king,' "
        "said Alice. 'I've read that in some book, but I don't remember where.''Well, it must be removed,' said the "
        "King very decidedly, and he called the Queen, who was passing at the moment, 'My dear! I wish you would have "
        "this cat removed!'The Queen had only one way of settling all difficulties, great or small. 'Off with his "
        "head!' she said, without even looking round.'I'll fetch the executioner myself,' said the King eagerly, and "
        "he hurried off.Alice thought she might as well go back, and see how the game was going on, as she heard the "
        "Queen's voice in the distance, screaming with passion. She had already heard her sentence three of the "
        "players to be executed for having missed their turns, and she did not like the look of things at all, as the "
        "game was in such confusion that she never knew whether it was her turn or not. So she went in search of her "
        "hedgehog.The hedgehog was engaged in a fight with another hedgehog, which seemed to Alice an excellent "
        "opportunity for croqueting one of them with the other: the only difficulty was, that her flamingo was gone "
        "across to the other side of the garden, where Alice could see it trying in a helpless sort of way to fly up "
        "into a tree.By the time she had caught the flamingo and brought it back, the fight was over, and both the "
        "hedgehogs were out of sight: 'but it doesn't matter much,' thought Alice, 'as all the arches are gone from "
        "this side of the ground.' So she tucked it away under her arm, that it might not escape again, and went back "
        "for a little more conversation with her friend.When she got back to the Cheshire Cat, she was surprised to "
        "find quite a large crowd collected round it: there was a dispute going on between the executioner, the King, "
        "and the Queen, who were all talking at once, while all the rest were quite silent, and looked very "
        "uncomfortable.The moment Alice appeared, she was appealed to by all three to settle the question, and they "
        "repeated their arguments to her, though, as they all spoke at once, she found it very hard indeed to make out "
        "exactly what they said.The executioner's argument was, that you couldn't cut off a head unless there was a "
        "body to cut it off from: that he had never had to do such a thing before, and he wasn't going to begin at his "
        "time of life.The King's argument was, that anything that had a head could be beheaded, and that you weren't "
        "to talk nonsense.The Queen's argument was, that if something wasn't done about it in less than no time she'd "
        "have everybody executed, all round. (It was this last remark that had made the whole party look so grave and "
        "anxious.)Alice could think of nothing else to say but 'It belongs to the Duchess: you'd better ask her about "
        "it.''She's in prison,' the Queen said to the executioner: 'fetch her here.' And the executioner went off like "
        "an arrow.The Cat's head began fading away the moment he was gone, and, by the time he had come back with the "
        "Duchess, it had entirely disappeared; so the King and the executioner ran wildly up and down looking for it, "
        "while the rest of the party went back to the game.";
    std::string output =
        "QSBsYXJnZSByb3NlLXRyZWUgc3Rvb2QgbmVhciB0aGUgZW50cmFuY2Ugb2YgdGhlIGdhcmRlbjogdGhlIHJvc2VzIGdyb3dpbmcgb24gaXQgd2"
        "VyZSB3aGl0ZSwgYnV0IHRoZXJlIHdlcmUgdGhyZWUgZ2FyZGVuZXJzIGF0IGl0LCBidXNpbHkgcGFpbnRpbmcgdGhlbSByZWQuIEFsaWNlIHRo"
        "b3VnaHQgdGhpcyBhIHZlcnkgY3VyaW91cyB0aGluZywgYW5kIHNoZSB3ZW50IG5lYXJlciB0byB3YXRjaCB0aGVtLCBhbmQganVzdCBhcyBzaG"
        "UgY2FtZSB1cCB0byB0aGVtIHNoZS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IHZlcnkgc2hvcnQgdGltZSB0aGUgUXVlZW4g"
        "d2FzIGluIGEgZnVyaW91cyBwYXNzaW9uLCBhbmQgd2VudCBzdGFtcGluZyBhYm91dCwgYW5kIHNob3V0aW5nICdPZmYgd2l0aCBoaXMgaGVhZC"
        "EnIG9yICdPZmYgd2l0aCBoZXIgaGVhZCEnIGFib3V0IG9uY2UgaW4gYSBtaW51dGUuQWxpY2UgYmVnYW4gdG8gZmVlbCB2ZXJ5IHVuZWFzeTog"
        "dG8gYmUgc3VyZSwgc2hlIGhhZCBub3QgYXMgeWV0IGhhZCBhbnkgZGlzcHV0ZSB3aXRoIHRoZSBRdWVlbiwgYnV0IHNoZSBrbmV3IHRoYXQgaX"
        "QgbWlnaHQgaGFwcGVuIGFueSBtaW51dGUsICdhbmQgdGhlbiwnIHRob3VnaHQgc2hlLCAnd2hhdCB3b3VsZCBiZWNvbWUgb2YgbWU/"
        "IFRoZXkncmUgZHJlYWRmdWxseSBmb25kIG9mIGJlaGVhZGluZyBwZW9wbGUgaGVyZTsgdGhlIGdyZWF0IHdvbmRlciBpcywgdGhhdCB0aGVyZS"
        "dzIGFueSBvbmUgbGVmdCBhbGl2ZSEnU2hlIHdhcyBsb29raW5nIGFib3V0IGZvciBzb21lIHdheSBvZiBlc2NhcGUsIGFuZCB3b25kZXJpbmcg"
        "d2hldGhlciBzaGUgY291bGQgZ2V0IGF3YXkgd2l0aG91dCBiZWluZyBzZWVuLCB3aGVuIHNoZSBub3RpY2VkIGEgY3VyaW91cyBhcHBlYXJhbm"
        "NlIGluIHRoZSBhaXI6IGl0IHB1enpsZWQgaGVyIHZlcnkgbXVjaCBhdCBmaXJzdCwgYnV0LCBhZnRlciB3YXRjaGluZyBpdCBhIG1pbnV0ZSBv"
        "ciB0d28sIHNoZSBtYWRlIGl0IG91dCB0byBiZSBhIGdyaW4sIGFuZCBzaGUgc2FpZCB0byBoZXJzZWxmICdJdCdzIHRoZSBDaGVzaGlyZSBDYX"
        "Q6IG5vd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WVlbiBzYWlkIHRvIHRoZSBleGVjdXRpb25lcjogJ2ZldGNoIGhlciBoZXJlLicgQW5kIHRoZSBleGVjdXRpb25lciB3ZW50IG9mZi"
        "BsaWtlIGFuIGFycm93LlRoZSBDYXQncyBoZWFkIGJlZ2FuIGZhZGluZyBhd2F5IHRoZSBtb21lbnQgaGUgd2FzIGdvbmUsIGFuZCwgYnkgdGhl"
        "IHRpbWUgaGUgaGFkIGNvbWUgYmFjayB3aXRoIHRoZSBEdWNoZXNzLCBpdCBoYWQgZW50aXJlbHkgZGlzYXBwZWFyZWQ7IHNvIHRoZSBLaW5nIG"
        "FuZCB0aGUgZXhlY3V0aW9uZXIgcmFuIHdpbGRseSB1cCBhbmQgZG93biBsb29raW5nIGZvciBpdCwgd2hpbGUgdGhlIHJlc3Qgb2YgdGhlIHBh"
        "cnR5IHdlbnQgYmFjayB0byB0aGUgZ2FtZS4=";
    using it_base64_t = bai::base64_from_binary<bai::transform_width<std::string::const_iterator, 6, 8>>;

    auto writePaddChars = (3 - input.length() % 3) % 3;
    std::string base64(it_base64_t(input.begin()), it_base64_t(input.end()));
    base64.append(writePaddChars, '=');
    assert(base64 == output);
    return 0;
}
#elif 0

#include <memory>
#include <sstream>

#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/shared_ptr.hpp>

struct S
{
	int i;
	char c;

	template <class Archive>
	void serialize(Archive & ar, const unsigned int version)
	{
		ar & i;
		ar & c;
	}
};

int main()
{
	const auto s0 = std::make_shared<S>();
	s0->i = 42;
	s0->c = 'c';

	std::stringstream ss;

	{
		boost::archive::text_oarchive oa(ss);
		oa << s0;
	}

	std::shared_ptr<S> s1;
	{
		boost::archive::text_iarchive ia(ss);
		ia >> s1;
	}

	return 0;
}

#else
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <sstream>
#include <vector>

void f()
{
  std::stringstream iss;
  boost::archive::binary_iarchive ar(iss);
  std::vector<int> out;
  ar >> out;
}

int main(int argc, char* argv[])
{
  return 0;
}
#endif

max_stars_repo_name: pdu/boost

max_issues_repo_name: pdu/boost

max_forks_repo_name: pdu/boost


text:
#include <boost/test/unit_test.hpp>
#include "utils/normalizations.h"
#include "inputs/minmax.h"
#include "inputs/zmaxnorm.h"
#include "inputs/znorm.h"
#include "inputs/column.h"
#include "utils/algorithms.hpp"
#include <boost/range/algorithm/sort.hpp>

BOOST_AUTO_TEST_CASE(test_znorm)
{
    const std::vector<double> test_data(std::begin(data_mapstd), std::end(data_mapstd));
    auto after_norm{utils::z_normalization(test_data)};
    BOOST_TEST_REQUIRE(after_norm.size() == test_data.size());
    BOOST_TEST_REQUIRE(after_norm.size() == utils::size(expected_first_mapstd));
    std::vector<double> expected(std::begin(expected_first_mapstd), std::end(expected_first_mapstd));
    boost::sort(after_norm);
    boost::sort(expected);
    auto ex_begin = std::begin(expected);
    for (auto n_begin = std::begin(after_norm); n_begin != std::end(after_norm); ++n_begin, ++ex_begin) {
        BOOST_TEST(round_cmp(*n_begin, *ex_begin, 0.0001), "value after the norm "<<*n_begin<<" != expected "<<*ex_begin);
    }

}

BOOST_AUTO_TEST_CASE(test_minmax_norm)
{
    const std::vector<double> test_data(std::begin(min_max_data), std::end(min_max_data));
    double min_val = PsY[0];
    double max_val = PsY[1];
    auto after_norm = utils::min_max_normalization(test_data, min_val, max_val);
    auto found = std::none_of(std::begin(after_norm), std::end(after_norm),
                        [min_val, max_val](auto v)
                        {
                            return v < min_val || v > max_val;
                        }
                    );
    BOOST_TEST_REQUIRE(found,
            "we don't expect to have any value after norm that is less than "
            <<min_val<<" or larger than "<<max_val);
    BOOST_TEST_REQUIRE(after_norm.size() == utils::size(expected_first),
            "the size of the norm output "<<after_norm.size()<<" not the same as the size "<<
            utils::size(expected_first)<<" that we are expecting");
    std::vector<double> expected(std::begin(expected_first), std::end(expected_first));
    boost::sort(after_norm);
    boost::sort(expected);
    auto expect_begin = std::begin(expected);
    for (auto norm_begin = std::begin(after_norm); norm_begin != std::end(after_norm); ++norm_begin, ++expect_begin) {
        BOOST_TEST(round_cmp(*norm_begin, *expect_begin, 0.0001), "value for "<<*norm_begin<<" != expected "<<*expect_begin);
    }
}
BOOST_AUTO_TEST_CASE(test_minmax_norm_second)
{
    const std::vector<double> test_data(std::begin(min_max_data), std::end(min_max_data));
    double min_val = PsY2[0];
    double max_val = PsY2[1];
    auto after_norm = utils::min_max_normalization(test_data, min_val, max_val);
    auto found = std::none_of(std::begin(after_norm), std::end(after_norm),
                        [min_val, max_val](auto v)
                        {
                            return v < min_val || v > max_val;
                        }
                    );
    BOOST_TEST_REQUIRE(found,
            "we don't expect to have any value after norm that is less than "
            <<min_val<<" or larger than "<<max_val);
    BOOST_TEST_REQUIRE(after_norm.size() == utils::size(expected_second),
            "the size of the norm output "<<after_norm.size()<<" not the same as the size "<<
            utils::size(expected_second)<<" that we are expecting");
    std::vector<double> expected(std::begin(expected_second), std::end(expected_second));
    boost::sort(after_norm);
    boost::sort(expected);
    auto expect_begin = std::begin(expected);
    for (auto norm_begin = std::begin(after_norm); norm_begin != std::end(after_norm); ++norm_begin, ++expect_begin) {
        BOOST_TEST(round_cmp(*norm_begin, *expect_begin, 0.0001), "value for "<<*norm_begin<<" != expected "<<*expect_begin);
    }
}

BOOST_AUTO_TEST_CASE(test_max_norm)
{
    const std::vector<double> test_data(std::begin(data_zmax), std::end(data_zmax));
    auto after_norm{utils::max_normalization(test_data)};
    BOOST_TEST_REQUIRE(after_norm.size() == test_data.size());
    BOOST_TEST_REQUIRE(after_norm.size() == utils::size(expected_zmax));
    std::vector<double> expected(std::begin(expected_zmax), std::end(expected_zmax));
    auto f = std::all_of(std::begin(after_norm), std::end(after_norm), [](auto val) {
                return val >= 0 && val <= 1;
            }
    );
    BOOST_TEST_REQUIRE(f, "we have value that is bigger than 1 or smaller than 0");
    //return;
    boost::sort(after_norm);
    boost::sort(expected);
    auto ex_begin = std::begin(expected);
    for (auto n_begin = std::begin(after_norm); n_begin != std::end(after_norm); ++n_begin, ++ex_begin) {
        BOOST_TEST(round_cmp(*n_begin, *ex_begin, 0.0001), "value after the norm "<<*n_begin<<" != expected "<<*ex_begin);
    }
}
BOOST_AUTO_TEST_CASE(test_nan_issue)
{
    const std::vector<double> test_data(std::begin(column_values), std::end(column_values));
    auto after_norm{utils::min_max_normalization(test_data, 0, 1)};
    BOOST_TEST(std::none_of(std::begin(after_norm), std::end(after_norm), [](auto val) {
                        if (std::isnan(val) || std::isinf(val)) {
                            BOOST_TEST(false, "value "<<val<<" is not valid");
                            return true;
                        }
                        return false;
                    }
            )
    );
}

ext: cpp


text:
/*
Copyright (c) 2017-2018, Battelle Memorial Institute
All rights reserved.

This software was co-developed by Pacific Northwest National Laboratory, operated by the Battelle Memorial
Institute; the National Renewable Energy Laboratory, operated by the Alliance for Sustainable Energy, LLC; and the
Lawrence Livermore National Laboratory, operated by Lawrence Livermore National Security, LLC.
*/

#include "ctestFixtures.hpp"
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/floating_point_comparison.hpp>

#include <future>
/** these test cases test out the message federates
 */

namespace bdata = boost::unit_test::data;
namespace utf = boost::unit_test;

BOOST_FIXTURE_TEST_SUITE (filter_tests_cpp, FederateTestFixture, *utf::label("ci"))

/** test registration of filters*/

BOOST_TEST_DECORATOR (*utf::timeout (12))
BOOST_DATA_TEST_CASE (message_filter_registration, bdata::make (core_types), core_type)
{
    auto broker = AddBroker (core_type, 2);
    AddFederates (helicsCreateMessageFederate, core_type, 1, broker, helics_time_zero, "filter");
    AddFederates (helicsCreateMessageFederate, core_type, 1, broker, helics_time_zero, "message");

    auto fFed = GetFederateAt (0);
    auto mFed = GetFederateAt (1);

    helicsFederateRegisterGlobalEndpoint (mFed, "port1", "");
    helicsFederateRegisterGlobalEndpoint (mFed, "port2", NULL);

    auto f1 = helicsFederateRegisterSourceFilter (fFed, helics_custom_filter, "filter1", "port1");
    BOOST_CHECK (f1 != NULL);
    auto f2 = helicsFederateRegisterDestinationFilter (fFed, helics_custom_filter, "filter2", "port2");
    BOOST_CHECK (f2 != f1);
    auto ep1 = helicsFederateRegisterEndpoint (fFed, "fout", "");
    BOOST_CHECK (ep1 != NULL);
    auto f3 = helicsFederateRegisterSourceFilter (fFed, helics_custom_filter, "", "filter0/fout");
    BOOST_CHECK (f3 != f2);
    CE (helicsFederateFinalize (mFed));
    CE (helicsFederateFinalize (fFed));
    federate_state state;
    CE (helicsFederateGetState (fFed, &state));
    BOOST_CHECK (state == helics_finalize_state);
}

/** test a filter operator
The filter operator delays the message by 2.5 seconds meaning it should arrive by 3 sec into the simulation
*/

BOOST_TEST_DECORATOR (*utf::timeout (12))
BOOST_DATA_TEST_CASE (message_filter_function, bdata::make (core_types), core_type)
{
    auto broker = AddBroker (core_type, 2);
    AddFederates (helicsCreateMessageFederate, core_type, 1, broker, 1.0, "filter");
    AddFederates (helicsCreateMessageFederate, core_type, 1, broker, 1.0, "message");

    auto fFed = GetFederateAt (0);
    auto mFed = GetFederateAt (1);

    auto p1 = helicsFederateRegisterGlobalEndpoint (mFed, "port1", "");
    auto p2 = helicsFederateRegisterGlobalEndpoint (mFed, "port2", "");

    auto f1 = helicsFederateRegisterSourceFilter (fFed, helics_delay_filter, "port1", "filter1");
    BOOST_CHECK (f1 != NULL);
    CE (helicsFilterSet (f1, "delay", 2.5));

    CE (helicsFederateEnterExecutionModeAsync (fFed));
    CE (helicsFederateEnterExecutionMode (mFed));
    CE (helicsFederateEnterExecutionModeComplete (fFed));

    federate_state state;
    CE (helicsFederateGetState (fFed, &state));
    BOOST_CHECK (state == helics_execution_state);
    std::string data (500, 'a');
    CE (helicsEndpointSendMessageRaw (p1, "port2", data.c_str (), static_cast<int> (data.size ())));

    helics_time_t timeOut;
    CE (helicsFederateRequestTimeAsync (mFed, 1.0));
    CE (helicsFederateRequestTime (fFed, 1.0, &timeOut));
    CE (helicsFederateRequestTimeComplete (mFed, &timeOut));

    auto res = helicsFederateHasMessage (mFed);
    BOOST_CHECK (!res);

    CE (helicsFederateRequestTimeAsync (mFed, 2.0));
    CE (helicsFederateRequestTime (fFed, 2.0, &timeOut));
    CE (helicsFederateRequestTimeComplete (mFed, &timeOut));
    BOOST_REQUIRE (!helicsEndpointHasMessage (p2));

    CE (helicsFederateRequestTimeAsync (fFed, 3.0));
    CE (helicsFederateRequestTime (mFed, 3.0, &timeOut));

    BOOST_REQUIRE (helicsEndpointHasMessage (p2));

    auto m2 = helicsEndpointGetMessage (p2);
    BOOST_CHECK_EQUAL (m2.source, "port1");
    BOOST_CHECK_EQUAL (m2.original_source, "port1");
    BOOST_CHECK_EQUAL (m2.dest, "port2");
    BOOST_CHECK_EQUAL (m2.length, static_cast<int64_t> (data.size ()));
    BOOST_CHECK_EQUAL (m2.time, 2.5);

    CE (helicsFederateRequestTime (mFed, 3.0, &timeOut));
    CE (helicsFederateRequestTimeComplete (fFed, &timeOut));
    CE (helicsFederateFinalize (mFed));
    CE (helicsFederateFinalize (fFed));
    CE (helicsFederateGetState (fFed, &state));
    BOOST_CHECK (state == helics_finalize_state);
}

/** test a filter operator
The filter operator delays the message by 2.5 seconds meaning it should arrive by 3 sec into the simulation
*/

BOOST_TEST_DECORATOR (*utf::timeout (20))
BOOST_DATA_TEST_CASE (message_filter_function_two_stage, bdata::make (core_types), core_type)
{
    auto broker = AddBroker (core_type, 3);
    AddFederates (helicsCreateMessageFederate, core_type, 1, broker, 1.0, "filter");
    AddFederates (helicsCreateMessageFederate, core_type, 1, broker, 1.0, "filter2");
    AddFederates (helicsCreateMessageFederate, core_type, 1, broker, 1.0, "message");

    auto fFed = GetFederateAt (0);
    auto fFed2 = GetFederateAt (1);
    auto mFed = GetFederateAt (2);

    auto p1 = helicsFederateRegisterGlobalEndpoint (mFed, "port1", "");
    auto p2 = helicsFederateRegisterGlobalEndpoint (mFed, "port2", "");

    auto f1 = helicsFederateRegisterSourceFilter (fFed, helics_delay_filter, "port1", "filter1");
    BOOST_CHECK (f1 != NULL);
    CE (helicsFilterSet (f1, "delay", 1.25));

    auto f2 = helicsFederateRegisterSourceFilter (fFed, helics_delay_filter, "port1", "filter2");
    BOOST_CHECK (f2 != NULL);
    CE (helicsFilterSet (f2, "delay", 1.25));

    CE (helicsFederateEnterExecutionModeAsync (fFed));
    CE (helicsFederateEnterExecutionModeAsync (fFed2));
    CE (helicsFederateEnterExecutionMode (mFed));
    CE (helicsFederateEnterExecutionModeComplete (fFed));
    CE (helicsFederateEnterExecutionModeComplete (fFed2));

    federate_state state;
    CE (helicsFederateGetState (fFed, &state));
    BOOST_CHECK (state == helics_execution_state);
    std::string data (500, 'a');
    CE (helicsEndpointSendMessageRaw (p1, "port2", data.c_str (), static_cast<int> (data.size ())));

    helics_time_t timeOut;
    CE (helicsFederateRequestTimeAsync (mFed, .0));
    CE (helicsFederateRequestTimeAsync (fFed, 1.0));
    CE (helicsFederateRequestTime (fFed2, 1.0, &timeOut));
    CE (helicsFederateRequestTimeComplete (mFed, &timeOut));
    CE (helicsFederateRequestTimeComplete (fFed, &timeOut));
    auto res = helicsFederateHasMessage (mFed);
    BOOST_CHECK (!res);

    CE (helicsFederateRequestTimeAsync (mFed, .0));
    CE (helicsFederateRequestTimeAsync (fFed2, 2.0));
    CE (helicsFederateRequestTime (fFed, 2.0, &timeOut));
    CE (helicsFederateRequestTimeComplete (mFed, &timeOut));
    CE (helicsFederateRequestTimeComplete (fFed2, &timeOut));
    BOOST_REQUIRE (!helicsEndpointHasMessage (p2));

    CE (helicsFederateRequestTimeAsync (fFed, 3.0));
    CE (helicsFederateRequestTimeAsync (fFed2, 3.0));
    CE (helicsFederateRequestTime (mFed, 3.0, &timeOut));
    if (!helicsEndpointHasMessage (p2))
    {
        printf ("missing message\n");
    }
    BOOST_REQUIRE (helicsEndpointHasMessage (p2));

    auto m2 = helicsEndpointGetMessage (p2);
    BOOST_CHECK_EQUAL (m2.source, "port1");
    BOOST_CHECK_EQUAL (m2.original_source, "port1");
    BOOST_CHECK_EQUAL (m2.dest, "port2");
    BOOST_CHECK_EQUAL (m2.length, static_cast<int64_t> (data.size ()));
    BOOST_CHECK_EQUAL (m2.time, 2.5);

    CE (helicsFederateRequestTimeComplete (fFed, &timeOut));
    CE (helicsFederateRequestTimeComplete (fFed2, &timeOut));
    CE (helicsFederateFinalize (mFed));
    CE (helicsFederateFinalize (fFed));
    CE (helicsFederateFinalize (fFed2));
    CE (helicsFederateGetState (fFed, &state));
    BOOST_CHECK (state == helics_finalize_state);
}

/** test two filter operators
The filter operator delays the message by 2.5 seconds meaning it should arrive by 3 sec into the simulation
*/

BOOST_TEST_DECORATOR (*utf::timeout (12))
BOOST_DATA_TEST_CASE (message_filter_function2, bdata::make (core_types), core_type)
{
    auto broker = AddBroker (core_type, 2);
    AddFederates (helicsCreateMessageFederate, core_type, 1, broker, 1.0, "filter");
    AddFederates (helicsCreateMessageFederate, core_type, 1, broker, 1.0, "message");

    auto fFed = GetFederateAt (0);
    auto mFed = GetFederateAt (1);

    auto p1 = helicsFederateRegisterGlobalEndpoint (mFed, "port1", "");
    auto p2 = helicsFederateRegisterGlobalEndpoint (mFed, "port2", "");

    auto f1 = helicsFederateRegisterSourceFilter (fFed, helics_delay_filter, "port1", "filter1");
    BOOST_CHECK (f1 != NULL);
    CE (helicsFilterSet (f1, "delay", 2.5));

    auto f2 = helicsFederateRegisterSourceFilter (fFed, helics_delay_filter, "port2", "filter2");
    BOOST_CHECK (f2 != NULL);
    CE (helicsFilterSet (f2, "delay", 2.5));

    CE (helicsFederateEnterExecutionModeAsync (fFed));
    CE (helicsFederateEnterExecutionMode (mFed));
    CE (helicsFederateEnterExecutionModeComplete (fFed));

    federate_state state;
    CE (helicsFederateGetState (fFed, &state));
    BOOST_CHECK (state == helics_execution_state);
    std::string data (500, 'a');
    CE (helicsEndpointSendMessageRaw (p1, "port2", data.c_str (), static_cast<int> (data.size ())));

    helics_time_t timeOut;
    CE (helicsFederateRequestTimeAsync (mFed, 1.0));
    CE (helicsFederateRequestTime (fFed, 1.0, &timeOut));
    CE (helicsFederateRequestTimeComplete (mFed, &timeOut));

    auto res = helicsFederateHasMessage (mFed);
    BOOST_CHECK (!res);
    CE (helicsEndpointSendMessageRaw (p2, "port1", data.c_str (), static_cast<int> (data.size ())));
    CE (helicsFederateRequestTimeAsync (mFed, 2.0));
    CE (helicsFederateRequestTime (fFed, 2.0, &timeOut));
    CE (helicsFederateRequestTimeComplete (mFed, &timeOut));
    BOOST_REQUIRE (!helicsEndpointHasMessage (p2));
    // there may be something wrong here yet but this test isn't the one to find it and
    // this may prevent spurious errors for now.
    std::this_thread::yield ();
    CE (helicsFederateRequestTime (mFed, 3.0, &timeOut));

    BOOST_REQUIRE (helicsEndpointHasMessage (p2));

    auto m2 = helicsEndpointGetMessage (p2);
    BOOST_CHECK_EQUAL (m2.source, "port1");
    BOOST_CHECK_EQUAL (m2.original_source, "port1");
    BOOST_CHECK_EQUAL (m2.dest, "port2");
    BOOST_CHECK_EQUAL (m2.length, static_cast<int64_t> (data.size ()));
    BOOST_CHECK_EQUAL (m2.time, 2.5);

    BOOST_CHECK (!helicsEndpointHasMessage (p1));
    CE (helicsFederateRequestTime (mFed, 4.0, &timeOut));
    BOOST_CHECK (helicsEndpointHasMessage (p1));
    CE (helicsFederateFinalize (mFed));
    CE (helicsFederateFinalize (fFed));
    CE (helicsFederateGetState (fFed, &state));
    BOOST_CHECK (state == helics_finalize_state);
}

BOOST_AUTO_TEST_CASE (message_clone_test)
{
    auto broker = AddBroker ("test", 3);
    AddFederates (helicsCreateMessageFederate, "test", 1, broker, 1.0, "source");
    AddFederates (helicsCreateMessageFederate, "test", 1, broker, 1.0, "dest");
    AddFederates (helicsCreateMessageFederate, "test", 1, broker, 1.0, "dest_clone");

    auto sFed = GetFederateAt (0);
    auto dFed = GetFederateAt (1);
    auto dcFed = GetFederateAt (2);

    auto p1 = helicsFederateRegisterGlobalEndpoint (sFed, "src", "");
    auto p2 = helicsFederateRegisterGlobalEndpoint (dFed, "dest", "");
    auto p3 = helicsFederateRegisterGlobalEndpoint (dcFed, "cm", "");

    auto f1 = helicsFederateRegisterCloningFilter (dcFed, "cm");
    CE (helicsFilterAddSourceTarget (f1, "src"));

    CE (helicsFederateEnterExecutionModeAsync (sFed));
    CE (helicsFederateEnterExecutionModeAsync (dcFed));
    CE (helicsFederateEnterExecutionMode (dFed));
    CE (helicsFederateEnterExecutionModeComplete (sFed));
    CE (helicsFederateEnterExecutionModeComplete (dcFed));

    federate_state state;
    CE (helicsFederateGetState (sFed, &state));
    BOOST_CHECK (state == helics_execution_state);
    std::string data (500, 'a');
    CE (helicsEndpointSendMessageRaw (p1, "dest", data.c_str (), static_cast<int> (data.size ())));

    helics_time_t timeOut;
    CE (helicsFederateRequestTimeAsync (sFed, 1.0));
    CE (helicsFederateRequestTimeAsync (dcFed, 1.0));
    CE (helicsFederateRequestTime (dFed, 1.0, &timeOut));
    CE (helicsFederateRequestTimeComplete (sFed, &timeOut));
    CE (helicsFederateRequestTimeComplete (dcFed, &timeOut));

    auto res = helicsFederateHasMessage (dFed);
    BOOST_CHECK (res);

    if (res)
    {
        auto m2 = helicsEndpointGetMessage (p2);
        BOOST_CHECK_EQUAL (m2.source, "src");
        BOOST_CHECK_EQUAL (m2.original_source, "src");
        BOOST_CHECK_EQUAL (m2.dest, "dest");
        BOOST_CHECK_EQUAL (m2.length, static_cast<int64_t> (data.size ()));
    }

    // now check the message clone
    res = helicsFederateHasMessage (dcFed);
    BOOST_CHECK (res);

    if (res)
    {
        auto m2 = helicsEndpointGetMessage (p3);
        BOOST_CHECK_EQUAL (m2.source, "src");
        BOOST_CHECK_EQUAL (m2.original_source, "src");
        BOOST_CHECK_EQUAL (m2.dest, "cm");
        BOOST_CHECK_EQUAL (m2.original_dest, "dest");
        BOOST_CHECK_EQUAL (m2.length, static_cast<int64_t> (data.size ()));
    }

    CE (helicsFederateFinalize (sFed));
    CE (helicsFederateFinalize (dFed));
    CE (helicsFederateFinalize (dcFed));
    CE (helicsFederateGetState (sFed, &state));
    BOOST_CHECK (state == helics_finalize_state);
}

BOOST_AUTO_TEST_CASE (message_multi_clone_test)
{
    auto broker = AddBroker ("test", 4);
    AddFederates (helicsCreateMessageFederate, "test", 2, broker, 1.0, "source");
    AddFederates (helicsCreateMessageFederate, "test", 1, broker, 1.0, "dest");
    AddFederates (helicsCreateMessageFederate, "test", 1, broker, 1.0, "dest_clone");

    auto sFed = GetFederateAt (0);
    auto sFed2 = GetFederateAt (1);
    auto dFed = GetFederateAt (2);
    auto dcFed = GetFederateAt (3);

    auto p1 = helicsFederateRegisterGlobalEndpoint (sFed, "src", "");
    auto p2 = helicsFederateRegisterGlobalEndpoint (sFed2, "src2", "");
    auto p3 = helicsFederateRegisterGlobalEndpoint (dFed, "dest", "");
    auto p4 = helicsFederateRegisterGlobalEndpoint (dcFed, "cm", "");

    auto f1 = helicsFederateRegisterCloningFilter (dcFed, "cm");
    CE (helicsFilterAddSourceTarget (f1, "src"));
    CE (helicsFilterAddSourceTarget (f1, "src2"));

    CE (helicsFederateEnterExecutionModeAsync (sFed));
    CE (helicsFederateEnterExecutionModeAsync (sFed2));
    CE (helicsFederateEnterExecutionModeAsync (dcFed));
    CE (helicsFederateEnterExecutionMode (dFed));
    CE (helicsFederateEnterExecutionModeComplete (sFed));
    CE (helicsFederateEnterExecutionModeComplete (sFed2));
    CE (helicsFederateEnterExecutionModeComplete (dcFed));

    federate_state state;
    CE (helicsFederateGetState (sFed, &state));
    BOOST_CHECK (state == helics_execution_state);
    std::string data (500, 'a');
    std::string data2 (400, 'b');
    CE (helicsEndpointSendMessageRaw (p1, "dest", data.c_str (), static_cast<int> (data.size ())));
    CE (helicsEndpointSendMessageRaw (p2, "dest", data2.c_str (), static_cast<int> (data2.size ())));

    helics_time_t timeOut;
    CE (helicsFederateRequestTimeAsync (sFed, 1.0));
    CE (helicsFederateRequestTimeAsync (sFed2, 1.0));
    CE (helicsFederateRequestTimeAsync (dcFed, 1.0));
    CE (helicsFederateRequestTime (dFed, 1.0, &timeOut));
    CE (helicsFederateRequestTimeComplete (sFed, &timeOut));
    CE (helicsFederateRequestTimeComplete (sFed2, &timeOut));
    CE (helicsFederateRequestTimeComplete (dcFed, &timeOut));

    auto mcnt = helicsEndpointReceiveCount (p3);
    BOOST_CHECK_EQUAL (mcnt, 2);
    auto res = helicsFederateHasMessage (dFed);
    BOOST_CHECK (res);

    if (res)
    {
        auto m2 = helicsEndpointGetMessage (p3);
        BOOST_CHECK_EQUAL (m2.source, "src");
        BOOST_CHECK_EQUAL (m2.original_source, "src");
        BOOST_CHECK_EQUAL (m2.dest, "dest");
        BOOST_CHECK_EQUAL (m2.length, static_cast<int64_t> (data.size ()));
        res = helicsFederateHasMessage (dFed);
        BOOST_CHECK (res);

        if (res)
        {
            m2 = helicsFederateGetMessage (dFed);
            BOOST_CHECK_EQUAL (m2.source, "src2");
            BOOST_CHECK_EQUAL (m2.original_source, "src2");
            BOOST_CHECK_EQUAL (m2.dest, "dest");
            BOOST_CHECK_EQUAL (m2.length, static_cast<int64_t> (data2.size ()));
        }
    }

    // now check the message clone
    mcnt = helicsEndpointReceiveCount (p4);
    BOOST_CHECK_EQUAL (mcnt, 2);
    res = helicsFederateHasMessage (dcFed);
    BOOST_CHECK (res);

    if (res)
    {
        auto m2 = helicsFederateGetMessage (dcFed);
        BOOST_CHECK_EQUAL (m2.source, "src");
        BOOST_CHECK_EQUAL (m2.original_source, "src");
        BOOST_CHECK_EQUAL (m2.dest, "cm");
        BOOST_CHECK_EQUAL (m2.original_dest, "dest");
        BOOST_CHECK_EQUAL (m2.length, static_cast<int64_t> (data.size ()));
        res = helicsFederateHasMessage (dcFed);
        BOOST_CHECK (res);

        if (res)
        {
            m2 = helicsFederateGetMessage (dcFed);
            BOOST_CHECK_EQUAL (m2.source, "src2");
            BOOST_CHECK_EQUAL (m2.original_source, "src2");
            BOOST_CHECK_EQUAL (m2.dest, "cm");
            BOOST_CHECK_EQUAL (m2.original_dest, "dest");
            BOOST_CHECK_EQUAL (m2.length, static_cast<int64_t> (data2.size ()));
        }
    }

    CE (helicsFederateFinalize (sFed));
    CE (helicsFederateFinalize (sFed2));
    CE (helicsFederateFinalize (dFed));
    CE (helicsFederateFinalize (dcFed));
    CE (helicsFederateGetState (sFed, &state));
    BOOST_CHECK (state == helics_finalize_state);
}

BOOST_AUTO_TEST_CASE (test_file_load)
{
    std::string filename = std::string (TEST_DIR) + "/test_files/example_filters.json";
    auto mFed = helicsCreateMessageFederateFromJson (filename.c_str ());

    char name[HELICS_SIZE_MAX];
    CE (helicsFederateGetName (mFed, name, HELICS_SIZE_MAX));
    BOOST_CHECK_EQUAL (name, "filterFed");

    BOOST_CHECK_EQUAL (helicsFederateGetEndpointCount (mFed), 3);
    helicsFederateFinalize (mFed);
    helicsFederateFree (mFed);
    // auto id = mFed.getEndpointId ("ept1");
    // BOOST_CHECK_EQUAL (mFed.getEndpointType (id), "genmessage");

    // BOOST_CHECK_EQUAL (mFed.filterObjectCount (), 3);

    // auto filt = mFed.getFilterObject (2);

    // auto cloneFilt = std::dynamic_pointer_cast<helics::CloningFilter> (filt);
    // BOOST_CHECK (cloneFilt);
    // mFed.disconnect ();
}
BOOST_AUTO_TEST_SUITE_END ()


text:
#pragma once

#include <vector>
#include <chrono>
#include <mutex>
#include <functional>
#include <initializer_list>
#include <thread>
#include <map>
#include <list>

#include <boost/accumulators/accumulators.hpp>
#include <boost/any.hpp>

class Stats
{
public:
    class TimeValueDatum
    {
    public:
        TimeValueDatum(const boost::any& value) : time(std::chrono::steady_clock::now()), value(value) {}
		const std::chrono::steady_clock::time_point time;
        const boost::any value;
    };

    class StatVal
    {
    public:
        template <typename Feature>
        static StatVal makeStatVal(std::function<bool (const TimeValueDatum&)>   filter,
                                   std::function<double (const TimeValueDatum&)> accessor,
                                   const Feature&                                  accumulator,
                                   const std::string&                              name)
        {
            auto filterAccExtractorMaker = [filter, accessor]()
            {
                auto acc = new boost::accumulators::accumulator_set<double, boost::accumulators::features<Feature> >();

                auto filterAcc = [acc, filter, accessor](const Stats::TimeValueDatum& datum)
                {
                    if (filter(datum))
                    {
                        (*acc)(accessor(datum.value));
                    }
                };

                auto extractor = [acc]()
                {
                    boost::accumulators::extractor<Feature> ex;
                    return ex(*acc);
                };

				return FilterAccExtractor(filterAcc, extractor);
            };

            return StatVal(filterAccExtractorMaker, name);
        }

    private:
        friend class Stats;

        typedef std::pair<std::function<void (const Stats::TimeValueDatum&)>, std::function<double ()> > FilterAccExtractor;
        typedef std::function<FilterAccExtractor ()> FilterAccExtractorMaker;

        StatVal(FilterAccExtractorMaker filterAccExtractorMaker,
                const std::string& name)
                :
                filterAccExtractorMaker(filterAccExtractorMaker),
                name(name) {}

        FilterAccExtractorMaker filterAccExtractorMaker;
        std::string name;
    };

    Stats();

    // events
    void store(const boost::any& datum);

    // utility

    typedef std::function<void(std::map<std::string, double>&)> PostProcessor;
    typedef std::function<std::list<Stats::StatVal>(std::chrono::microseconds,
		                                              std::chrono::steady_clock::time_point)> StatValsMaker;
    typedef std::function<PostProcessor(std::chrono::microseconds,
		                                  std::chrono::steady_clock::time_point)> PostProcessorMaker;

	std::string summary(std::chrono::microseconds window,
		                StatValsMaker               statValsMaker,
		                PostProcessorMaker          postProcessorMaker,
		                const std::string&          format);
    void autoSummary(std::chrono::microseconds frequency,
					 StatValsMaker               statValsMaker,
					 PostProcessorMaker          postProcessorMaker,
                     const std::string&          format);
	void stopAutoSummary();

private:
    std::list<TimeValueDatum>* activeStorage;
    std::list<TimeValueDatum>* processingStorage;

    std::list<TimeValueDatum> storage1;
    std::list<TimeValueDatum> storage2;

    std::map<std::string, double> query(std::initializer_list<StatVal>                         statVals,
                                        std::function<void (std::map<std::string, double>&)> postCalculator);
	std::map<std::string, double> query(std::list<StatVal>                                    statVals,
                                        std::function<void(std::map<std::string, double>&)> postCalculator);

    std::string formatDuration(std::chrono::microseconds duration);

    std::mutex mutex;
    std::thread autoSummaryThread;
	bool stopAutoSummary_;
    void autoSummaryLoop(std::chrono::microseconds frequency,
						 StatValsMaker               statValsMaker,
						 PostProcessorMaker          postProcessorMaker,
						 const std::string&          format);
};

ext: hpp

max_stars_repo_name: AlloSphere-Research-Group/AlloStreamer

max_issues_repo_name: AlloSphere-Research-Group/AlloStreamer

max_forks_repo_name: AlloSphere-Research-Group/AlloStreamer


text:
/**
 * @file ItemCFTest.cpp
 * @author Jun Jiang
 * @date 2011-06-17
 */

#include "ItemCFTest.h"

#include <boost/test/unit_test.hpp>

#include <set>
#include <algorithm> // copy
#include <cmath> // sqrt
#include <climits> // INT_MAX
#include <cfloat> // FLT_MAX

namespace
{
std::ostream_iterator<idmlib::recommender::ItemType> COUT_IT(std::cout, ", ");

/**
 * Split string @p inputStr and append each element to iterator @p result.
 */
template <class OutputIterator>
void splitItems(
    const char* inputStr,
    OutputIterator result
)
{
    idmlib::recommender::ItemType itemId;
    std::stringstream ss(inputStr);
    while (ss >> itemId)
    {
        *result++ = itemId;
    }
}
}

NS_IDMLIB_RESYS_BEGIN

void ItemCFTest::checkVisit(
    const char* oldItemStr,
    const char* newItemStr
)
{
    list<uint32_t> oldItems;
    list<uint32_t> newItems;

    splitItems(oldItemStr, back_insert_iterator< list<uint32_t> >(oldItems));
    splitItems(newItemStr, back_insert_iterator< list<uint32_t> >(newItems));

    /*cout << "=> visit event, old items: ";
    copy(oldItems.begin(), oldItems.end(), COUT_IT);
    cout << ", new items: ";
    copy(newItems.begin(), newItems.end(), COUT_IT);
    cout << endl;*/

    updateGoldVisitMatrix_(oldItems, newItems);

    covisitation_->visit(oldItems, newItems);

    checkVisitMatrix();
}

void ItemCFTest::updateGoldVisitMatrix_(
    const std::list<uint32_t>& oldItems,
    const std::list<uint32_t>& newItems
)
{
    for (list<uint32_t>::const_iterator newIt = newItems.begin();
        newIt != newItems.end(); ++newIt)
    {
        // update 2*new*old pairs
        for (list<uint32_t>::const_iterator oldIt = oldItems.begin();
            oldIt != oldItems.end(); ++oldIt)
        {
            ++goldVisitMatrix_[*newIt][*oldIt];
            ++goldVisitMatrix_[*oldIt][*newIt];
        }

        // update new*new pairs
        for (list<uint32_t>::const_iterator newIt2 = newItems.begin();
            newIt2 != newItems.end(); ++newIt2)
        {
            ++goldVisitMatrix_[*newIt][*newIt2];
        }
    }
}

void ItemCFTest::checkVisitMatrix()
{
    for (int i=0; i<ITEM_NUM; ++i)
    {
        for (int j=0; j<ITEM_NUM; ++j)
        {
            BOOST_TEST_MESSAGE("check visit coeff [" << i << "][" << j << "]: " << goldVisitMatrix_[i][j]);
            int freq = covisitation_->matrix().elem(i, j).freq;
            BOOST_CHECK_EQUAL(freq, goldVisitMatrix_[i][j]);
        }
    }
}

void ItemCFTest::checkCoVisitResult()
{
    for (uint32_t i=0; i<ITEM_NUM; ++i)
    {
        checkCoVisitResult_(i);
    }
}

void ItemCFTest::checkCoVisitResult_(uint32_t inputItem)
{
    // get covisit items
    RecommendItemVec recItems;
    covisitation_->getCoVisitation(ITEM_NUM, inputItem, recItems);

    std::vector<float> goldWeights;
    calcCoVisitWeights_(inputItem, goldWeights);

    checkWeights_(recItems, goldWeights);
}

void ItemCFTest::calcCoVisitWeights_(
    uint32_t inputItem,
    std::vector<float>& weights
) const
{
    weights.assign(ITEM_NUM, 0);

    float total = 0;

    const std::vector<int>& goldVisitVec = goldVisitMatrix_[inputItem];
    for (unsigned int i=0; i<ITEM_NUM; ++i)
    {
        if (i == inputItem)
            continue;

        total += goldVisitVec[i];
    }

    if (total == 0)
        return;

    for (unsigned int i=0; i<ITEM_NUM; ++i)
    {
        if (i == inputItem)
            continue;

        weights[i] = goldVisitVec[i] / total;
    }
}

void ItemCFTest::checkPurchase(
    uint32_t userId,
    const char* oldItemStr,
    const char* newItemStr,
    bool rebuildSimMatrx
)
{
    list<uint32_t> oldItems;
    list<uint32_t> newItems;

    splitItems(oldItemStr, back_insert_iterator< list<uint32_t> >(oldItems));
    splitItems(newItemStr, back_insert_iterator< list<uint32_t> >(newItems));

    /*cout << "=> purchase event, userId: " << userId << ", old items: ";
    copy(oldItems.begin(), oldItems.end(), COUT_IT);
    cout << ", new items: ";
    copy(newItems.begin(), newItems.end(), COUT_IT);
    cout << endl;*/

    updateGoldVisitMatrix_(oldItems, newItems);

    if (rebuildSimMatrx)
    {
        cfManager_->updateVisitMatrix(oldItems, newItems);
        cfManager_->buildSimMatrix();
    }
    else
    {
        cfManager_->updateMatrix(oldItems, newItems);
    }

    checkVisitMatrix();
    updateGoldSimMatrix_();
    checkSimMatrix();

    std::vector<uint32_t> totalItems(oldItems.begin(), oldItems.end());
    totalItems.insert(totalItems.end(), newItems.begin(), newItems.end());

    checkRecommendItem_(totalItems);
}

void ItemCFTest::checkRecommend(const char* inputItemStr) const
{
    std::vector<uint32_t> inputItems;
    splitItems(inputItemStr, back_insert_iterator< vector<uint32_t> >(inputItems));

    checkRecommendItem_(inputItems);
}

void ItemCFTest::checkRecommendItem_(const std::vector<uint32_t>& inputItems) const
{
    // get recommend items
    RecommendItemVec recItems;
    cfManager_->recommend(ITEM_NUM, inputItems, recItems);

    /*std::list<uint32_t> recItemIDs;
    for (RecommendItemVec::const_iterator it = recItems.begin();
        it != recItems.end(); ++it)
    {
        recItemIDs.push_back(it->itemId_);
    }
    cout << "\t<= given items ";
    copy(inputItems.begin(), inputItems.end(), COUT_IT);
    cout << "recommend other items: ";
    copy(recItemIDs.begin(), recItemIDs.end(), COUT_IT);
    cout << endl;*/

    std::vector<float> goldWeights;
    calcWeights_(inputItems, goldWeights);

    checkWeights_(recItems, goldWeights);
}

void ItemCFTest::calcWeights_(
    const std::vector<uint32_t>& inputItems,
    std::vector<float>& weights
) const
{
    weights.assign(ITEM_NUM, 0);

    std::set<uint32_t> inputSet(inputItems.begin(), inputItems.end());
    for (unsigned int i=0; i<ITEM_NUM; ++i)
    {
        if (inputSet.find(i) != inputSet.end())
            continue;

        float sim = 0;
        float total = 0;
        for (unsigned int j=0; j<ITEM_NUM; ++j)
        {
            if (i == j)
                continue;

            if (inputSet.find(j) != inputSet.end())
                sim += goldSimMatrix_[i][j];

            total += goldSimMatrix_[i][j];
        }

        if (sim != 0)
        {
            assert(total != 0);
            weights[i] = sim / total;
        }
    }
}

void ItemCFTest::checkWeights_(
    const RecommendItemVec& recItems,
    std::vector<float>& goldWeights
) const
{
    // check weight in descreasing order
    float prevWeight = FLT_MAX;
    for (RecommendItemVec::const_iterator it = recItems.begin();
        it != recItems.end(); ++it)
    {
        uint32_t itemId = it->itemId_;
        float weight = it->weight_;

        //cout << "item: " << itemId << ", weight: " << weight << endl;
        BOOST_CHECK_CLOSE(weight, goldWeights[itemId], 0.0001);
        BOOST_CHECK(weight <= prevWeight);

        // reset weight value to compare with zeroWeightVec
        goldWeights[itemId] = 0;
        prevWeight = weight;
    }

    // to check all results are returned
    std::vector<float> zeroWeightVec(ITEM_NUM);
    BOOST_CHECK_EQUAL_COLLECTIONS(goldWeights.begin(), goldWeights.end(),
                                  zeroWeightVec.begin(), zeroWeightVec.end());
}

void ItemCFTest::checkWeightRecommend(const char* itemWeightPairs) const
{
    IncrementalItemCF::ItemWeightMap itemWeightMap;

    idmlib::recommender::ItemType itemId;
    float weight;
    std::stringstream ss(itemWeightPairs);
    while (ss >> itemId >> weight)
    {
        itemWeightMap[itemId] = weight;
        //std::cout << itemId << ", " << weight << std::endl;
    }

    // get recommend items
    RecommendItemVec recItems;
    cfManager_->recommend(ITEM_NUM, itemWeightMap, recItems);

    std::vector<float> goldWeights;
    calcWeights_(itemWeightMap, goldWeights);

    checkWeights_(recItems, goldWeights);
}

void ItemCFTest::calcWeights_(
    const IncrementalItemCF::ItemWeightMap& inputItemWeights,
    std::vector<float>& weights
) const
{
    weights.assign(ITEM_NUM, 0);

    for (unsigned int i=0; i<ITEM_NUM; ++i)
    {
        if (inputItemWeights.find(i) != inputItemWeights.end())
            continue;

        float sim = 0;
        float total = 0;
        for (unsigned int j=0; j<ITEM_NUM; ++j)
        {
            if (i == j)
                continue;

            IncrementalItemCF::ItemWeightMap::const_iterator findIt = inputItemWeights.find(j);
            if (findIt != inputItemWeights.end())
                sim += goldSimMatrix_[i][j] * findIt->second;

            total += goldSimMatrix_[i][j];
        }

        if (sim != 0)
        {
            assert(total != 0);
            float w = sim / total;
            if (w > 0)
                weights[i] = w;
        }
    }
}

void ItemCFTest::updateGoldSimMatrix_()
{
    for (int i=0; i<ITEM_NUM; ++i)
    {
        for (int j=0; j<ITEM_NUM; ++j)
        {
            float gold = 0;
            if (i != j && goldVisitMatrix_[i][j] != 0)
            {
                gold = goldVisitMatrix_[i][j] / (sqrt(goldVisitMatrix_[i][i]) * sqrt(goldVisitMatrix_[j][j]));
            }
            goldSimMatrix_[i][j] = gold;
        }
    }
}

void ItemCFTest::checkSimMatrix()
{
    for (int i=0; i<ITEM_NUM; ++i)
    {
        for (int j=0; j<ITEM_NUM; ++j)
        {
            BOOST_TEST_MESSAGE("check similarity coeff [" << i << "][" << j << "]: " << goldSimMatrix_[i][j]);
            BOOST_CHECK_CLOSE(simMatrix_->elem(i, j), goldSimMatrix_[i][j], 0.000001);
        }
    }
}

NS_IDMLIB_RESYS_END

max_stars_repo_name: izenecloud/idmlib

max_issues_repo_name: izenecloud/idmlib

max_forks_repo_name: izenecloud/idmlib


text:
#include <armadillo>
#include <h5cpp/all>

int main(){
	// create hdf5 container/file
	hid_t fd = h5::create("arma.h5");

	arma::vec data = {1,2,3,4,5};
	hid_t ds = h5::create<float>(fd,"/arma/data",{5,5,1,2});

	// offset - where to start within the array, in this case is {0,0,0,0}
	// count  - how many elements we would like to write: {a,b,c}
	h5::write(ds, data, {0,0,0,0},{1,5,1,1} ); 			//
	// we only want 3 elements back from offset 1, the rank must be 4
	auto rvo  = h5::read<arma::mat>(ds,{0,1,0,0},{1,3,1,1});
	rvo.print();

	H5Dclose(ds);
	h5::close(fd);
}


text: #include <boost/fusion/include/ignore.hpp>

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
// Copyright 2019 Hans Dembinski
//
// 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 BOOST_HISTOGRAM_DETAIL_ACCUMULATOR_TRAITS_HPP
#define BOOST_HISTOGRAM_DETAIL_ACCUMULATOR_TRAITS_HPP

#include <boost/histogram/fwd.hpp>
#include <tuple>
#include <type_traits>

namespace boost {

namespace accumulators {
template <class, class, class>
struct accumulator_set;
}

namespace histogram {
namespace detail {

template <bool WeightSupport, class... Ts>
struct accumulator_traits_holder {
  using wsupport = std::integral_constant<bool, WeightSupport>;
  using args = std::tuple<Ts...>;
};

template <class R, class T, class U, class... Ts>
accumulator_traits_holder<true, Ts...> accumulator_traits_impl_2(
    R (T::*)(boost::histogram::weight_type<U>, Ts...));

template <class R, class T, class U, class... Ts>
accumulator_traits_holder<true, Ts...> accumulator_traits_impl_2(
    R (T::*)(boost::histogram::weight_type<U>&&, Ts...));

template <class R, class T, class U, class... Ts>
accumulator_traits_holder<true, Ts...> accumulator_traits_impl_2(
    R (T::*)(const boost::histogram::weight_type<U>&, Ts...));

template <class R, class T, class... Ts>
accumulator_traits_holder<false, Ts...> accumulator_traits_impl_2(R (T::*)(Ts...));

template <class T>
auto accumulator_traits_impl(T&)
    -> decltype(std::declval<T&>() += 0, accumulator_traits_holder<true>{});

template <class T>
auto accumulator_traits_impl(T&) -> decltype(accumulator_traits_impl_2(&T::operator()));

// for boost.accumulators compatibility
template <class S, class F, class W>
accumulator_traits_holder<false, S> accumulator_traits_impl(
    boost::accumulators::accumulator_set<S, F, W>&);

template <class T>
using accumulator_traits = decltype(accumulator_traits_impl(std::declval<T&>()));

} // namespace detail
} // namespace histogram
} // namespace boost

#endif

max_stars_repo_name: cpp-pm/boost

max_issues_repo_name: cpp-pm/boost

max_forks_repo_name: cpp-pm/boost


text:
#ifndef MATHTOOLBOX_STRONG_WOLFE_CONDITIONS_LINE_SEARCH_HPP
#define MATHTOOLBOX_STRONG_WOLFE_CONDITIONS_LINE_SEARCH_HPP

#include <Eigen/Core>
#include <cassert>
#include <functional>
#include <iostream>

#define MATHTOOLBOX_VERBOSE_LINE_SEARCH_WARNINGS

namespace mathtoolbox
{
    namespace optimization
    {
        // Algorithm 3.5: Line Search Algorithm
        //
        // This algoritmh tries to find an appropriate step size that satisfies the strong Wolfe conditions (i.e., both
        // the safficient decreasing condition and the curvature condition).
        inline double
        RunStrongWolfeConditionsLineSearch(const std::function<double(const Eigen::VectorXd&)>&          f,
                                           const std::function<Eigen::VectorXd(const Eigen::VectorXd&)>& g,
                                           const Eigen::VectorXd&                                        x,
                                           const Eigen::VectorXd&                                        p,
                                           const double                                                  alpha_init,
                                           const double alpha_max = 50.0,
                                           const double c_1       = 1e-04,
                                           const double c_2       = 0.9)
        {
            auto phi      = [&](const double alpha) { return f(x + alpha * p); };
            auto phi_grad = [&](const double alpha) { return static_cast<double>(g(x + alpha * p).transpose() * p); };

            const double phi_zero      = phi(0.0);
            const double phi_grad_zero = phi_grad(0.0);

            double alpha_prev     = 0.0;
            double alpha          = alpha_init;
            double phi_alpha_prev = phi_zero;

            bool is_first = true;

            // Algorithm 3.6: Zoom
            auto zoom = [&](double alpha_l, double alpha_h) {
                constexpr unsigned int max_num_iterations = 50;
                for (unsigned int i = 0; i < max_num_iterations; ++i)
                {
                    const double alpha_j     = 0.5 * (alpha_l + alpha_h); // TODO: Use a better strategy
                    const double phi_alpha_j = phi(alpha_j);

                    if (phi_alpha_j > phi_zero + c_1 * alpha_j * phi_grad_zero || phi_alpha_j >= phi(alpha_l))
                    {
                        alpha_h = alpha_j;
                    }
                    else
                    {
                        const double phi_grad_alpha_j = phi_grad(alpha_j);
                        if (std::abs(phi_grad_alpha_j) <= -c_2 * phi_grad_zero)
                        {
                            return alpha_j;
                        }
                        if (phi_grad_alpha_j * (alpha_h - alpha_l) >= 0.0)
                        {
                            alpha_h = alpha_l;
                        }
                        alpha_l = alpha_j;
                    }
                }
#ifdef MATHTOOLBOX_VERBOSE_LINE_SEARCH_WARNINGS
                std::cerr << "Warning: The line search did not converge." << std::endl;
#endif
                return 0.5 * (alpha_l + alpha_h);
            };

            constexpr unsigned int max_num_iterations = 50;
            for (int i = 0; i < max_num_iterations; ++i)
            {
                const double phi_alpha = phi(alpha);

                if (phi_alpha > phi_zero + c_1 * alpha * phi_grad_zero || (!is_first && (phi_alpha >= phi_alpha_prev)))
                {
                    return zoom(alpha_prev, alpha);
                }

                const double phi_grad_alpha = phi_grad(alpha);

                if (std::abs(phi_grad_alpha) <= -c_2 * phi_grad_zero)
                {
                    return alpha;
                }

                if (phi_grad_alpha >= 0.0)
                {
                    return zoom(alpha, alpha_prev);
                }

                alpha_prev     = alpha;
                phi_alpha_prev = phi_alpha;

                alpha = 0.5 * (alpha + alpha_max); // TODO: Use a better strategy
            }
#ifdef MATHTOOLBOX_VERBOSE_LINE_SEARCH_WARNINGS
            std::cerr << "Warning: The line search did not converge." << std::endl;
#endif
            return alpha_init;
        }
    } // namespace optimization
} // namespace mathtoolbox

#endif // MATHTOOLBOX_STRONG_WOLFE_CONDITIONS_LINE_SEARCH_HPP

max_stars_repo_name: yuki-koyama/mathtoolbox


text:
/*
 * Copyright 2017-present Shawn Cao
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "Errors.h"

// If NDBG is defined by build, print call stack of each exception
#ifdef NDBG
#define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED
#define BOOST_STACKTRACE_USE_ADDR2LINE
#include <boost/stacktrace.hpp>
#include <glog/logging.h>
#endif

namespace nebula {
namespace common {

NebulaException::NebulaException(const std::string& file,
                                 const uint32_t line,
                                 const std::string& method,
                                 const std::string& expr,
                                 const std::string& msg)
  : format_{ fmt::format("[{0}:{1} at function {2}] Nebula Exception={3}: {4}",
                         file, line, method, expr, msg) } {
#ifdef NDBG
  LOG(INFO) << "Exception Call Stack: " << boost::stacktrace::stacktrace();
#endif
}
} // namespace common
} // namespace nebula