<commit_before>#ifndef DUNE_DETAILED_DISCRETIZATIONS_DISCRETEFUNCTIONSPACE_CONTINUOUS_LAGRANGE_HH
#define DUNE_DETAILED_DISCRETIZATIONS_DISCRETEFUNCTIONSPACE_CONTINUOUS_LAGRANGE_HH

// system
#include <map>
#include <set>

// dune-common
#include <dune/common/shared_ptr.hh>

// dune-fem includes
#include <dune/fem/space/lagrangespace.hh>
#include <dune/fem/gridpart/gridpartview.hh>

// dune-detailed-discretizations includes
#include <dune/detailed/discretizations/basefunctionset/continuous/lagrange.hh>
#include <dune/detailed/discretizations/mapper/continuous/lagrange.hh>

namespace Dune {

namespace Detailed {

namespace Discretizations {

namespace DiscreteFunctionSpace {

namespace Continuous {

template <class FunctionSpaceImp, class GridPartImp, int polOrder>
class Lagrange
{
public:
  typedef FunctionSpaceImp FunctionSpaceType;

  typedef GridPartImp GridPartType;

  typedef Dune::GridPartView<GridPartType> GridViewType;

  enum
  {
    polynomialOrder = polOrder
  };

  typedef Lagrange<FunctionSpaceType, GridPartType, polynomialOrder> ThisType;

  typedef Dune::Detailed::Discretizations::Mapper::Continuous::Lagrange<FunctionSpaceType, GridPartType,
                                                                        polynomialOrder> MapperType;

  typedef Dune::Detailed::Discretizations::BaseFunctionSet::Continuous::Lagrange<ThisType> BaseFunctionSetType;

  typedef typename FunctionSpaceType::DomainFieldType DomainFieldType;

  typedef typename FunctionSpaceType::DomainType DomainType;

  typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;

  typedef typename FunctionSpaceType::RangeType RangeType;

  typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;

  typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;

  static const unsigned int dimDomain = FunctionSpaceType::dimDomain;

  static const unsigned int dimRange = FunctionSpaceType::dimRange;

  typedef std::map<unsigned int, std::set<unsigned int>> PatternType;

  /**
      @name Convenience typedefs
      @{
   **/
  typedef typename GridPartType::template Codim<0>::IteratorType IteratorType;

  typedef typename IteratorType::Entity EntityType;
  /**
      @}
   **/

  Lagrange(const GridPartType& gridPart)
    : gridPart_(gridPart)
    , gridView_(gridPart_)
    , mapper_(gridPart_)
    , baseFunctionSet_(*this)
  {
  }

private:
  //! copy constructor
  Lagrange(const ThisType& other);

public:
  const GridPartType& gridPart() const
  {
    return gridPart_;
  }

  const GridViewType& gridView() const
  {
    return gridView_;
  }

  const MapperType& map() const
  {
    return mapper_;
  }

  const BaseFunctionSetType& baseFunctionSet() const
  {
    return baseFunctionSet_;
  }

  int order() const
  {
    return polynomialOrder;
  }

  bool continuous() const
  {
    if (order() > 0)
      return false;
    else
      return true;
  }

  /**
      @name Convenience methods
      @{
   **/
  IteratorType begin() const
  {
    return gridPart_.template begin<0>();
  }

  IteratorType end() const
  {
    return gridPart_.template end<0>();
  }
  /**
      @}
   **/

  template <class OtherDiscreteFunctionSpaceType>
  PatternType computePattern(const OtherDiscreteFunctionSpaceType& other) const
  {
    std::map<unsigned int, std::set<unsigned int>> ret;
    // generate sparsity pattern
    for (IteratorType it = begin(); it != end(); ++it) {
      const EntityType& entity = *it;
      for (unsigned int i = 0; i < baseFunctionSet().local(entity).size(); ++i) {
        for (unsigned int j = 0; j < other.baseFunctionSet().local(entity).size(); ++j) {
          const unsigned int globalI                                      = map().toGlobal(entity, i);
          const unsigned int globalJ                                      = other.map().toGlobal(entity, j);
          std::map<unsigned int, std::set<unsigned int>>::iterator result = ret.find(globalI);
          if (result == ret.end())
            ret.insert(std::pair<unsigned int, std::set<unsigned int>>(globalI, std::set<unsigned int>()));
          result = ret.find(globalI);
          assert(result != ret.end());
          result->second.insert(globalJ);
        }
      }
    } // generate sparsity pattern
    return ret;
  } // PatternType computePattern(const OtherDiscreteFunctionSpaceType& other) const

  PatternType computePattern() const
  {
    return computePattern(*this);
  }

protected:
  //! assignment operator
  ThisType& operator=(const ThisType&);

  const GridPartType& gridPart_;
  const GridViewType gridView_;
  const MapperType mapper_;
  const BaseFunctionSetType baseFunctionSet_;
}; // end class Lagrange

} // end namespace Continuous

} // end namespace DiscreteFunctionSpace

} // namespace Discretizations

} // namespace Detailed

} // end namespace Dune

#endif // DUNE_DETAILED_DISCRETIZATIONS_DISCRETEFUNCTIONSPACE_CONTINUOUS_LAGRANGE_HH
<commit_msg>[discretefunctionspace.continuous.lagrange] minor change (should perform better)<commit_after>#ifndef DUNE_DETAILED_DISCRETIZATIONS_DISCRETEFUNCTIONSPACE_CONTINUOUS_LAGRANGE_HH
#define DUNE_DETAILED_DISCRETIZATIONS_DISCRETEFUNCTIONSPACE_CONTINUOUS_LAGRANGE_HH

// system
#include <map>
#include <set>

// dune-common
#include <dune/common/shared_ptr.hh>

// dune-fem includes
#include <dune/fem/space/lagrangespace.hh>
#include <dune/fem/gridpart/gridpartview.hh>

// dune-detailed-discretizations includes
#include <dune/detailed/discretizations/basefunctionset/continuous/lagrange.hh>
#include <dune/detailed/discretizations/mapper/continuous/lagrange.hh>

namespace Dune {

namespace Detailed {

namespace Discretizations {

namespace DiscreteFunctionSpace {

namespace Continuous {

template <class FunctionSpaceImp, class GridPartImp, int polOrder>
class Lagrange
{
public:
  typedef FunctionSpaceImp FunctionSpaceType;

  typedef GridPartImp GridPartType;

  typedef Dune::GridPartView<GridPartType> GridViewType;

  enum
  {
    polynomialOrder = polOrder
  };

  typedef Lagrange<FunctionSpaceType, GridPartType, polynomialOrder> ThisType;

  typedef Dune::Detailed::Discretizations::Mapper::Continuous::Lagrange<FunctionSpaceType, GridPartType,
                                                                        polynomialOrder> MapperType;

  typedef Dune::Detailed::Discretizations::BaseFunctionSet::Continuous::Lagrange<ThisType> BaseFunctionSetType;

  typedef typename FunctionSpaceType::DomainFieldType DomainFieldType;

  typedef typename FunctionSpaceType::DomainType DomainType;

  typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;

  typedef typename FunctionSpaceType::RangeType RangeType;

  typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;

  typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;

  static const unsigned int dimDomain = FunctionSpaceType::dimDomain;

  static const unsigned int dimRange = FunctionSpaceType::dimRange;

  typedef std::map<unsigned int, std::set<unsigned int>> PatternType;

  /**
      @name Convenience typedefs
      @{
   **/
  typedef typename GridPartType::template Codim<0>::IteratorType IteratorType;

  typedef typename IteratorType::Entity EntityType;
  /**
      @}
   **/

  Lagrange(const GridPartType& gridPart)
    : gridPart_(gridPart)
    , gridView_(gridPart_)
    , mapper_(gridPart_)
    , baseFunctionSet_(*this)
  {
  }

private:
  //! copy constructor
  Lagrange(const ThisType& other);

public:
  const GridPartType& gridPart() const
  {
    return gridPart_;
  }

  const GridViewType& gridView() const
  {
    return gridView_;
  }

  const MapperType& map() const
  {
    return mapper_;
  }

  const BaseFunctionSetType& baseFunctionSet() const
  {
    return baseFunctionSet_;
  }

  int order() const
  {
    return polynomialOrder;
  }

  bool continuous() const
  {
    if (order() > 0)
      return false;
    else
      return true;
  }

  /**
      @name Convenience methods
      @{
   **/
  IteratorType begin() const
  {
    return gridPart_.template begin<0>();
  }

  IteratorType end() const
  {
    return gridPart_.template end<0>();
  }
  /**
      @}
   **/

  template <class OtherDiscreteFunctionSpaceType>
  PatternType computePattern(const OtherDiscreteFunctionSpaceType& other) const
  {
    std::map<unsigned int, std::set<unsigned int>> ret;
    // generate sparsity pattern
    for (IteratorType it = begin(); it != end(); ++it) {
      const EntityType& entity = *it;
      for (unsigned int i = 0; i < baseFunctionSet().local(entity).size(); ++i) {
        const unsigned int globalI                                      = map().toGlobal(entity, i);
        std::map<unsigned int, std::set<unsigned int>>::iterator result = ret.find(globalI);
        if (result == ret.end())
          ret.insert(std::pair<unsigned int, std::set<unsigned int>>(globalI, std::set<unsigned int>()));
        result = ret.find(globalI);
        assert(result != ret.end());
        for (unsigned int j = 0; j < other.baseFunctionSet().local(entity).size(); ++j) {
          const unsigned int globalJ = other.map().toGlobal(entity, j);
          result->second.insert(globalJ);
        }
      }
    } // generate sparsity pattern
    return ret;
  } // PatternType computePattern(const OtherDiscreteFunctionSpaceType& other) const

  PatternType computePattern() const
  {
    return computePattern(*this);
  }

protected:
  //! assignment operator
  ThisType& operator=(const ThisType&);

  const GridPartType& gridPart_;
  const GridViewType gridView_;
  const MapperType mapper_;
  const BaseFunctionSetType baseFunctionSet_;
}; // end class Lagrange

} // end namespace Continuous

} // end namespace DiscreteFunctionSpace

} // namespace Discretizations

} // namespace Detailed

} // end namespace Dune

#endif // DUNE_DETAILED_DISCRETIZATIONS_DISCRETEFUNCTIONSPACE_CONTINUOUS_LAGRANGE_HH
<|endoftext|>


<commit_before>/** \file   FullTextCache.cc
 *  \brief  Implementation of functions relating to our full-text cache.
 *  \author Dr. Johannes Ruscheinski (johannes.ruscheinski@uni-tuebingen.de)
 *
 *  \copyright 2017 Universitätsbibliothek Tübingen.  All rights reserved.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program 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 Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "FullTextCache.h"
#include "SqlUtil.h"
#include <ctime>
#include <kchashdb.h>
#include "Compiler.h"
#include "DbRow.h"
#include "Random.h"
#include "util.h"

namespace FullTextCache {

const unsigned MIN_CACHE_EXPIRE_TIME(84600 *  60); // About 2 months in seconds.
const unsigned MAX_CACHE_EXPIRE_TIME(84600 * 120); // About 4 months in seconds.

bool CacheExpired(DbConnection * const db_connection, const std::string &full_text_db_path, const std::string &id) {
    db_connection->queryOrDie("SELECT expiration FROM full_text_cache WHERE id=\"" + db_connection->escapeString(id)
                              + "\"");
    DbResultSet result_set(db_connection->getLastResultSet());
    if (result_set.empty())
        return true;

    const DbRow row(result_set.getNextRow());
    const time_t expiration(SqlUtil::DatetimeToTimeT(row["expiration"]));
    const time_t now(std::time(nullptr));

    if (expiration < now)
        return false;

    kyotocabinet::HashDB db;
    if (not db.open(full_text_db_path, kyotocabinet::HashDB::OCREATE))
        Error("in FullTextCache::CacheExpired: Failed to open database \"" + full_text_db_path + "\" for writing ("
              + std::string(db.error().message()) + ")!");
    db.remove(id);

    db_connection->queryOrDie("DELETE FROM full_text_cache WHERE id=\"" + db_connection->escapeString(id) + "\"");
    return true;
}

void InsertIntoCache(DbConnection * const db_connection, const std::string &full_text_db_path,
                     const std::string &key, const std::string &data)
{
    if (not data.empty()) {
        kyotocabinet::HashDB db;
        if (not db.open(full_text_db_path, kyotocabinet::HashDB::OCREATE))
            Error("in FullTextCache::InsertIntoCache: Failed to open database \"" + full_text_db_path
                  + "\" for writing (" + std::string(db.error().message()) + ")!");
        if (unlikely(not db.set(key, data)))
            Error("in FullTextCache::InsertIntoCache: Failed to insert into database \"" + full_text_db_path + "\" ("
                  + std::string(db.error().message()) + ")!");
    }

    const time_t now(std::time(nullptr));
    Random::Rand rand(now);
    const time_t expiration(now + MIN_CACHE_EXPIRE_TIME + rand(MAX_CACHE_EXPIRE_TIME - MIN_CACHE_EXPIRE_TIME));
    db_connection->queryOrDie("REPLACE INTO full_text_cache SET id=\"" + db_connection->escapeString(key)
                              + "\",expiration=\"" + SqlUtil::TimeTToDatetime(expiration) + "\"");
}

} // namespace FullTextCache
<commit_msg>I don't know why, but it seems to work.<commit_after>/** \file   FullTextCache.cc
 *  \brief  Implementation of functions relating to our full-text cache.
 *  \author Dr. Johannes Ruscheinski (johannes.ruscheinski@uni-tuebingen.de)
 *
 *  \copyright 2017 Universitätsbibliothek Tübingen.  All rights reserved.
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program 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 Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "FullTextCache.h"
#include "SqlUtil.h"
#include <ctime>
#include <kchashdb.h>
#include "Compiler.h"
#include "DbRow.h"
#include "Random.h"
#include "util.h"

namespace FullTextCache {

const unsigned MIN_CACHE_EXPIRE_TIME(84600 *  60); // About 2 months in seconds.
const unsigned MAX_CACHE_EXPIRE_TIME(84600 * 120); // About 4 months in seconds.

bool CacheExpired(DbConnection * const db_connection, const std::string &full_text_db_path, const std::string &id) {
    db_connection->queryOrDie("SELECT expiration FROM full_text_cache WHERE id=\"" + db_connection->escapeString(id)
                              + "\"");
    DbResultSet result_set(db_connection->getLastResultSet());
    if (result_set.empty())
        return true;

    const DbRow row(result_set.getNextRow());
    const time_t expiration(SqlUtil::DatetimeToTimeT(row["expiration"]));
    const time_t now(std::time(nullptr));

    if (expiration < now)
        return false;

    kyotocabinet::HashDB db;
    if (not db.open(full_text_db_path, kyotocabinet::HashDB::OCREATE | kyotocabinet::HashDB::OWRITER))
        Error("in FullTextCache::CacheExpired: Failed to open database \"" + full_text_db_path + "\" for writing ("
              + std::string(db.error().message()) + ")!");
    db.remove(id);

    db_connection->queryOrDie("DELETE FROM full_text_cache WHERE id=\"" + db_connection->escapeString(id) + "\"");
    return true;
}

void InsertIntoCache(DbConnection * const db_connection, const std::string &full_text_db_path,
                     const std::string &key, const std::string &data)
{
    if (not data.empty()) {
        kyotocabinet::HashDB db;
        if (not db.open(full_text_db_path, kyotocabinet::HashDB::OCREATE | kyotocabinet::HashDB::OWRITER))
            Error("in FullTextCache::InsertIntoCache: Failed to open database \"" + full_text_db_path
                  + "\" for writing (" + std::string(db.error().message()) + ")!");
        if (unlikely(not db.set(key, data)))
            Error("in FullTextCache::InsertIntoCache: Failed to insert into database \"" + full_text_db_path + "\" ("
                  + std::string(db.error().message()) + ")!");
    }

    const time_t now(std::time(nullptr));
    Random::Rand rand(now);
    const time_t expiration(now + MIN_CACHE_EXPIRE_TIME + rand(MAX_CACHE_EXPIRE_TIME - MIN_CACHE_EXPIRE_TIME));
    db_connection->queryOrDie("REPLACE INTO full_text_cache SET id=\"" + db_connection->escapeString(key)
                              + "\",expiration=\"" + SqlUtil::TimeTToDatetime(expiration) + "\"");
}

} // namespace FullTextCache
<|endoftext|>


<commit_before>/*
 * ping_pong_impl.cpp
 *
 *  Created on: May 6, 2016
 *      Author: zmij
 */

#include "ping_pong_impl.hpp"

#include <wire/core/invocation.hpp>
#include <iostream>

namespace wire {
namespace test {

static_assert(!core::detail::is_sync_dispatch<decltype(&::test::ping_pong::test_string)>::value,
        "test_string is async");
static_assert(core::detail::is_sync_dispatch<decltype(&::test::ping_pong::test_int)>::value,
        "test_int is sync");
static_assert(!core::detail::is_sync_dispatch<decltype(&::test::ping_pong::async_error)>::value,
        "test_string is async");
static_assert(::std::is_same<
        ::psst::meta::function_traits<decltype(&::test::ping_pong::async_error)>::class_type,
        ::test::ping_pong>::value, "Correct class owner");

::std::int32_t
ping_pong_server::test_int(::std::int32_t val, ::wire::core::current const&) const
{
    ::std::ostringstream os;
    os << ::getpid() << " " << __FUNCTION__ << "\n";
    ::std::cerr << os.str();
    return val;
}

void
ping_pong_server::test_string(::std::string const& val,
        test_string_return_callback __resp,
        ::wire::core::functional::exception_callback __exception,
        ::wire::core::current const&)
{
    ::std::ostringstream os;
    os << ::getpid() << __FUNCTION__ << "\n";
    ::std::cerr << os.str();
    __resp(val);
}

void
ping_pong_server::test_struct(::test::data const& val,
        test_struct_return_callback __resp,
        ::wire::core::functional::exception_callback __exception,
        ::wire::core::current const&) const
{
    ::std::ostringstream os;
    os << ::getpid() << __FUNCTION__ << " " << val << "\n";
    ::std::cerr << os.str();
    __resp(val);
}

void
ping_pong_server::test_callback(::test::ping_pong::callback_prx cb,
        test_callback_return_callback __resp,
        ::wire::core::functional::exception_callback __exception,
        ::wire::core::current const&)
{
    ::std::ostringstream os;
    os << ::getpid() << __FUNCTION__ << " " << *cb << "\n";
    ::std::cerr << os.str();
    __resp(cb);
}

void
ping_pong_server::test_ball(::test::ball_ptr b,
            test_ball_return_callback __resp,
            ::wire::core::functional::exception_callback __exception,
            ::wire::core::current const&)
{
    ::std::ostringstream os;
    os << ::getpid() << __FUNCTION__ << " ";
    ::std::cerr << os.str();
    if (b) {
        ::std::ostringstream os;
        os << ::getpid() << "Ball size " << b->size << "\n";
        ::std::cerr << os.str();
    } else {
        ::std::ostringstream os;
        os << ::getpid() << "No ball\n";
        ::std::cerr << os.str();
    }
    __resp(b);
}

void
ping_pong_server::error(::wire::core::current const&)
{
    throw ::test::oops{ "Shit happens!" };
}

void
ping_pong_server::async_error(::wire::core::functional::void_callback __resp,
        ::wire::core::functional::exception_callback __exception,
        ::wire::core::current const&) const
{
    ::std::ostringstream os;
    os << ::getpid() << __FUNCTION__ << "\n";
    ::std::cerr << os.str();
    __exception(::std::make_exception_ptr(::test::oops{ "Async shit happens!" }));
}

void
ping_pong_server::stop(::wire::core::functional::void_callback __resp,
        ::wire::core::functional::exception_callback __exception,
        ::wire::core::current const&)
{
    ::std::ostringstream os;
    os << ::getpid() << __FUNCTION__ << "\n";
    ::std::cerr << os.str();
    __resp();
    if (on_stop_)
        on_stop_();
}

}  /* namespace test */
}  /* namespace wire */

<commit_msg>Reduce logs in tests<commit_after>/*
 * ping_pong_impl.cpp
 *
 *  Created on: May 6, 2016
 *      Author: zmij
 */

#include "ping_pong_impl.hpp"

#include <wire/core/invocation.hpp>
#include <iostream>

namespace wire {
namespace test {

static_assert(!core::detail::is_sync_dispatch<decltype(&::test::ping_pong::test_string)>::value,
        "test_string is async");
static_assert(core::detail::is_sync_dispatch<decltype(&::test::ping_pong::test_int)>::value,
        "test_int is sync");
static_assert(!core::detail::is_sync_dispatch<decltype(&::test::ping_pong::async_error)>::value,
        "test_string is async");
static_assert(::std::is_same<
        ::psst::meta::function_traits<decltype(&::test::ping_pong::async_error)>::class_type,
        ::test::ping_pong>::value, "Correct class owner");

::std::int32_t
ping_pong_server::test_int(::std::int32_t val, ::wire::core::current const&) const
{
    #if DEBUG_OUTPUT >= 3
    ::std::ostringstream os;
    os << ::getpid() << " " << __FUNCTION__ << "\n";
    ::std::cerr << os.str();
    #endif
    return val;
}

void
ping_pong_server::test_string(::std::string const& val,
        test_string_return_callback __resp,
        ::wire::core::functional::exception_callback __exception,
        ::wire::core::current const&)
{
    #if DEBUG_OUTPUT >= 3
    ::std::ostringstream os;
    os << ::getpid() << " " << __FUNCTION__ << "\n";
    ::std::cerr << os.str();
    #endif
    __resp(val);
}

void
ping_pong_server::test_struct(::test::data const& val,
        test_struct_return_callback __resp,
        ::wire::core::functional::exception_callback __exception,
        ::wire::core::current const&) const
{
    #if DEBUG_OUTPUT >= 3
    ::std::ostringstream os;
    os << ::getpid() << " " << __FUNCTION__ << " " << val << "\n";
    ::std::cerr << os.str();
    #endif
    __resp(val);
}

void
ping_pong_server::test_callback(::test::ping_pong::callback_prx cb,
        test_callback_return_callback __resp,
        ::wire::core::functional::exception_callback __exception,
        ::wire::core::current const&)
{
    #if DEBUG_OUTPUT >= 3
    ::std::ostringstream os;
    os << ::getpid() << " " << __FUNCTION__ << " " << *cb << "\n";
    ::std::cerr << os.str();
    #endif
    __resp(cb);
}

void
ping_pong_server::test_ball(::test::ball_ptr b,
            test_ball_return_callback __resp,
            ::wire::core::functional::exception_callback __exception,
            ::wire::core::current const&)
{
    ::std::ostringstream os;
    #if DEBUG_OUTPUT >= 3
    os << ::getpid() << " " << __FUNCTION__ << " ";
    ::std::cerr << os.str();
    if (b) {
        ::std::ostringstream os;
        os << ::getpid() << " Ball size " << b->size << "\n";
        ::std::cerr << os.str();
    } else {
        ::std::ostringstream os;
        os << ::getpid() << " No ball\n";
        ::std::cerr << os.str();
    }
    #endif
    __resp(b);
}

void
ping_pong_server::error(::wire::core::current const&)
{
    throw ::test::oops{ "Shit happens!" };
}

void
ping_pong_server::async_error(::wire::core::functional::void_callback __resp,
        ::wire::core::functional::exception_callback __exception,
        ::wire::core::current const&) const
{
    #if DEBUG_OUTPUT >= 3
    ::std::ostringstream os;
    os << ::getpid() << " " << __FUNCTION__ << "\n";
    ::std::cerr << os.str();
    #endif
    __exception(::std::make_exception_ptr(::test::oops{ "Async shit happens!" }));
}

void
ping_pong_server::stop(::wire::core::functional::void_callback __resp,
        ::wire::core::functional::exception_callback __exception,
        ::wire::core::current const&)
{
    #if DEBUG_OUTPUT >= 3
    ::std::ostringstream os;
    os << ::getpid() << " " << __FUNCTION__ << "\n";
    ::std::cerr << os.str();
    #endif
    __resp();
    if (on_stop_)
        on_stop_();
}

}  /* namespace test */
}  /* namespace wire */

<|endoftext|>


<commit_before>#include "util/cowvector/cowvector.h"
#include "util/Assert.h"
using namespace std;

namespace srch2is = srch2::instantsearch;
using namespace srch2is;

void* writer(void* arg);
void* reader(void* arg);

void* writer2(void* arg);
void* reader2(void* arg);

void* writer3(void* arg);
void* reader3(void* arg);

cowvector<int> cowv;

// test type of vectorview
// main logic: it first push_back 10 elements [0,9] in the writeview and commit it.
// then it will check the writeview type it should be true(writeview), and readview type, it should be false(readview).
// And it will test needToFreeOldArray, it should be false
// it will further push_back 10 elements [0,9] and test needToFreeOldArray, it should be true.
void test1()
{
    vectorview<int>* &write = cowv.getWriteView();
    for (int i= 0; i< 10; i++) {
        write->push_back(i);
    }
    cowv.commit();
    ASSERT(write->isWriteView() == true);
    ASSERT(write->isReadView() == false);
    ASSERT(write->getNeedToFreeOldArray() == false);
    shared_ptr<vectorview<int> > read;
    cowv.getReadView(read);
    ASSERT(read->isWriteView() == false);
    ASSERT(read->isReadView() == true);
    for (int i= 0; i< 10; i++) {
        write->push_back(i);
    }
    ASSERT(write->getNeedToFreeOldArray() == true);
}

// single reader and single writer
// main logic: it will first push_back 10 elements [0,9] and commit
// then it will start two threads. One for reader, one for writer.
// the writer will first forceCreateCopy and do a modification, at the same time the reader will read it.
// the reader will not see the change until the writer commits the change(it change the 3 element to be 100).
// the writer will then push_back 90 elements. After it do the commit, the reader will detect it(it will find there are 100 elements in the vecterview).
// the writer will then push_back 1000 elements. After it do the commit, the reader will detect it(it will find 1100 elements in the vecterview).
void test2() {
    pthread_t  t1,t2 ;
    vectorview<int>* &write = cowv.getWriteView();

    write->clear();
    cowv.commit();
    write = cowv.getWriteView();

    for (int i= 0; i< 10; i++) {
        write->push_back(i);
    }
    cowv.commit();

    int create1 = pthread_create( &t1, NULL, writer, NULL);
    if (create1 != 0) cout << "error" << endl;
    int create2 = pthread_create( &t2, NULL, reader, NULL);
    if (create2 != 0) cout << "error" << endl;
    pthread_join(t1,NULL) ;
    pthread_join(t2,NULL) ;
}

// write view test at operation
void* writer(void* arg) {
    vectorview<int>* &write = cowv.getWriteView();
    write->forceCreateCopy();
    sleep(1);
    // do change
    write->at(3) = 100;
    sleep(2);
    // commit the change
    cowv.commit();
    sleep(2);
    // push_back 90 elements with wirteview and commit
    write = cowv.getWriteView();
    for(int i = 0; i < 90; i++)
        write->push_back(i);
    cowv.commit();
    sleep(2);
    // push_back 1000 elements with wirteview and commit
    for(int i = 0; i < 1000; i++)
        write->push_back(i);
    cowv.commit();
    return NULL;
}

//read view test at operation
void* reader(void* arg) {
    shared_ptr<vectorview<int> > read;
    cowv.getReadView(read);
    //check the reader with no change
    for (int i = 0; i< read->size(); i++) {
        ASSERT(i == read->at(i));
    }
    sleep(2);
    //do not change before commit
    for (int i = 0; i< read->size(); i++) {
        ASSERT(i == read->at(i));
    }
    sleep(2);
    // see the change after commit
    cowv.getReadView(read);
    cout << read->at(3) << endl;
    ASSERT(read->at(3) == 100);
    sleep(2);
    // see the change of new insert item
    cowv.getReadView(read);
    cout << read->size() << endl;
    ASSERT(read->size() == 100);
    sleep(2);
    // see the change of further insert item
    cowv.getReadView(read);
    cout << read->size() << endl;
    ASSERT(read->size() == 1100);
    return NULL;
}

// multi reader and single writer
// main logic: we will first push_back 10 elemnts [0,9] and commit it. After that we will start 11 threads.
// 10 of the threads is reader, and one is a writer.
// the reader will not see the change before the writer commit it(it change the 3 element to be 100).
void test3() {
    pthread_t  t1,t2[10];
    vectorview<int>* &write = cowv.getWriteView();

    write->clear();
    cowv.commit();

    write = cowv.getWriteView();

    for (int i= 0; i< 10; i++) {
        write->push_back(i);
    }
    cowv.commit();
    cout << write->size()<<endl;

    int create1 = pthread_create( &t1, NULL, writer2, NULL);

    if (create1 != 0) cout << "error" << endl;

    for (int i = 0; i< 10; i++) {
        int create2 = pthread_create( &t2[i], NULL, reader2, NULL);
        if (create2 != 0) cout << "error" << endl;
    }

    pthread_join(t1,NULL) ;
    for (int i = 0; i< 10; i++)
        pthread_join(t2[i],NULL) ;
}

//read view test push_back operation
void* reader2(void* arg) {
    shared_ptr<vectorview<int> > read;
    cowv.getReadView(read);
    sleep(1);
    //do not change before commit
    //cout << read->size() << endl;
    for (int i = 0; i< read->size(); i++) {
        ASSERT(i == read->at(i));
    }
    return NULL;
}

// write view test push_back operation
void* writer2(void* arg) {
    vectorview<int>* &write = cowv.getWriteView();
    write->push_back(100);
    sleep(1);
    cowv.commit();
    return NULL;
}

// multi reader and single writer for larger data
// main logic: the logic is the same with test 2, we test the 1 writer and 10 reader for larger data size(all the size is multiple 1000).
void test4() {
    pthread_t  t1,t2[10];
    vectorview<int>* &write = cowv.getWriteView();

    write->clear();
    cowv.commit();

    write = cowv.getWriteView();

    for (int i= 0; i< 10000; i++) {
        write->push_back(i);
    }
    cowv.commit();
    cout << write->size()<<endl;

    int create1 = pthread_create( &t1, NULL, writer3, NULL);

    if (create1 != 0) cout << "error" << endl;

    for (int i = 0; i< 10; i++) {
        int create2 = pthread_create( &t2[i], NULL, reader3, NULL);
        if (create2 != 0) cout << "error" << endl;
    }

    pthread_join(t1,NULL) ;
    for (int i = 0; i< 10; i++)
        pthread_join(t2[i],NULL) ;
}

// write view test at operation
void* writer3(void* arg) {
    vectorview<int>* &write = cowv.getWriteView();
    write->forceCreateCopy();
    sleep(1);
    // do change
    write->at(3) = 100;
    write->at(200) = 100;
    write->at(1000) = 100;
    write->at(9999) = 100;
    sleep(2);
    // commit the change
    cowv.commit();
    sleep(2);
    // push_back 90 elements with wirteview and commit
    write = cowv.getWriteView();
    for(int i = 0; i < 90000; i++)
        write->push_back(i);
    cowv.commit();
    sleep(2);
    // push_back 1000 elements with wirteview and commit
    for(int i = 0; i < 1000000; i++)
        write->push_back(i);
    cowv.commit();
    return NULL;
}

//read view test at operation
void* reader3(void* arg) {
    shared_ptr<vectorview<int> > read;
    cowv.getReadView(read);
    //check the reader with no change
    for (int i = 0; i< read->size(); i++) {
        ASSERT(i == read->at(i));
    }
    sleep(2);
    //do not change before commit
    for (int i = 0; i< read->size(); i++) {
        ASSERT(i == read->at(i));
    }
    sleep(2);
    // see the change after commit
    cowv.getReadView(read);
    cout << read->at(3) << endl;
    ASSERT(read->at(3) == 100);
    ASSERT(read->at(200) == 100);
    ASSERT(read->at(1000) == 100);
    ASSERT(read->at(9999) == 100);
    sleep(2);
    // see the change of new insert item
    cowv.getReadView(read);
    cout << read->size() << endl;
    ASSERT(read->size() == 100000);
    sleep(2);
    // see the change of further insert item
    cowv.getReadView(read);
    cout << read->size() << endl;
    ASSERT(read->size() == 1100000);
    return NULL;
}

int main( void ) {
    test1();
    test2();
    test3();
    test4();
    return 0;
}

<commit_msg>Polished by Chen<commit_after>#include "util/cowvector/cowvector.h"
#include "util/Assert.h"
using namespace std;

namespace srch2is = srch2::instantsearch;
using namespace srch2is;

void* writer(void* arg);
void* reader(void* arg);

void* writer2(void* arg);
void* reader2(void* arg);

void* writer3(void* arg);
void* reader3(void* arg);

cowvector<int> cowv;

// Main logic of this test case: it first uses push_back()
// to add 10 elements (0, 1, ..., 90 to the writeview and commits.
// Then it checks the vector view type, which should be a writeview.
// And it tests the needToFreeOldArray flag, it should be false.
// It will again call push_back() to add 10 elements (0, 1, ..., 9)
// and test the needToFreeOldArray flag. The flag should be true,
// since we have reallocated the memory of the array due to the more pushback calls.
void test1()
{
    vectorview<int>* &write = cowv.getWriteView();
    for (int i= 0; i< 10; i++) {
        write->push_back(i);
    }
    cowv.commit();
    ASSERT(write->isWriteView() == true);
    ASSERT(write->isReadView() == false);
    ASSERT(write->getNeedToFreeOldArray() == false);
    shared_ptr<vectorview<int> > read;
    cowv.getReadView(read);
    ASSERT(read->isWriteView() == false);
    ASSERT(read->isReadView() == true);
    for (int i= 0; i< 10; i++) {
        write->push_back(i);
    }
    ASSERT(write->getNeedToFreeOldArray() == true);
}

// single reader and single writer
// main logic: it will first push_back 10 elements [0,9] and commit
// then it will start two threads. One for reader, one for writer.
// the writer will first forceCreateCopy and do a modification by changing the element 3 to 100, at the same time the reader will read it.
// the reader will not see the change until the writer commits the change.
// the writer will then push_back 90 elements. After it does the commit, the reader will detect it(it will find there are 100 elements in the vecterview).
// the writer will then push_back 1000 elements. After it does the commit, the reader will detect it(it will find 1100 elements in the vecterview).
void test2() {
    pthread_t  t1,t2 ;
    vectorview<int>* &write = cowv.getWriteView();

    write->clear();
    cowv.commit();
    write = cowv.getWriteView();

    for (int i= 0; i< 10; i++) {
        write->push_back(i);
    }
    cowv.commit();

    int create1 = pthread_create( &t1, NULL, writer, NULL);
    if (create1 != 0) cout << "error" << endl;
    int create2 = pthread_create( &t2, NULL, reader, NULL);
    if (create2 != 0) cout << "error" << endl;
    pthread_join(t1,NULL) ;
    pthread_join(t2,NULL) ;
}

// write view test at operation
void* writer(void* arg) {
    vectorview<int>* &write = cowv.getWriteView();
    write->forceCreateCopy();
    sleep(1);
    // do change
    write->at(3) = 100;
    sleep(2);
    // commit the change
    cowv.commit();
    sleep(2);
    // push_back 90 elements with wirteview and commit
    write = cowv.getWriteView();
    for(int i = 0; i < 90; i++)
        write->push_back(i);
    cowv.commit();
    sleep(2);
    // push_back 1000 elements with wirteview and commit
    for(int i = 0; i < 1000; i++)
        write->push_back(i);
    cowv.commit();
    return NULL;
}

//read view test at operation
void* reader(void* arg) {
    shared_ptr<vectorview<int> > read;
    cowv.getReadView(read);
    //check the reader with no change
    for (int i = 0; i< read->size(); i++) {
        ASSERT(i == read->at(i));
    }
    sleep(2);
    //do not change before commit
    for (int i = 0; i< read->size(); i++) {
        ASSERT(i == read->at(i));
    }
    sleep(2);
    // see the change after commit
    cowv.getReadView(read);
    cout << read->at(3) << endl;
    ASSERT(read->at(3) == 100);
    sleep(2);
    // see the change of new insert item
    cowv.getReadView(read);
    cout << read->size() << endl;
    ASSERT(read->size() == 100);
    sleep(2);
    // see the change of further insert item
    cowv.getReadView(read);
    cout << read->size() << endl;
    ASSERT(read->size() == 1100);
    return NULL;
}

// multi reader and single writer
// main logic: we will first push_back 10 elements [0,9] and commit it. After that we will start 11 threads.
// 10 of the threads are readers, and one is a writer.
// the readers will not see the change made by the writer (element 3 -> 100) before the writer commits it.
void test3() {
    pthread_t  t1,t2[10];
    vectorview<int>* &write = cowv.getWriteView();

    write->clear();
    cowv.commit();

    write = cowv.getWriteView();

    for (int i= 0; i< 10; i++) {
        write->push_back(i);
    }
    cowv.commit();
    cout << write->size()<<endl;

    int create1 = pthread_create( &t1, NULL, writer2, NULL);

    if (create1 != 0) cout << "error" << endl;

    for (int i = 0; i< 10; i++) {
        int create2 = pthread_create( &t2[i], NULL, reader2, NULL);
        if (create2 != 0) cout << "error" << endl;
    }

    pthread_join(t1,NULL) ;
    for (int i = 0; i< 10; i++)
        pthread_join(t2[i],NULL) ;
}

//read view test push_back operation
void* reader2(void* arg) {
    shared_ptr<vectorview<int> > read;
    cowv.getReadView(read);
    sleep(1);
    //do not change before commit
    //cout << read->size() << endl;
    for (int i = 0; i< read->size(); i++) {
        ASSERT(i == read->at(i));
    }
    return NULL;
}

// write view test push_back operation
void* writer2(void* arg) {
    vectorview<int>* &write = cowv.getWriteView();
    write->push_back(100);
    sleep(1);
    cowv.commit();
    return NULL;
}

// multi reader and single writer for larger data
// The main logic is the same as test 2. We have 1 writer and 10 readers for a larger data size (1000 times larger).
void test4() {
    pthread_t  t1,t2[10];
    vectorview<int>* &write = cowv.getWriteView();

    write->clear();
    cowv.commit();

    write = cowv.getWriteView();

    for (int i= 0; i< 10000; i++) {
        write->push_back(i);
    }
    cowv.commit();
    cout << write->size()<<endl;

    int create1 = pthread_create( &t1, NULL, writer3, NULL);

    if (create1 != 0) cout << "error" << endl;

    for (int i = 0; i< 10; i++) {
        int create2 = pthread_create( &t2[i], NULL, reader3, NULL);
        if (create2 != 0) cout << "error" << endl;
    }

    pthread_join(t1,NULL) ;
    for (int i = 0; i< 10; i++)
        pthread_join(t2[i],NULL) ;
}

// write view test at operation
void* writer3(void* arg) {
    vectorview<int>* &write = cowv.getWriteView();
    write->forceCreateCopy();
    sleep(1);
    // do change
    write->at(3) = 100;
    write->at(200) = 100;
    write->at(1000) = 100;
    write->at(9999) = 100;
    sleep(2);
    // commit the change
    cowv.commit();
    sleep(2);
    // push_back 90 elements with wirteview and commit
    write = cowv.getWriteView();
    for(int i = 0; i < 90000; i++)
        write->push_back(i);
    cowv.commit();
    sleep(2);
    // push_back 1000 elements with wirteview and commit
    for(int i = 0; i < 1000000; i++)
        write->push_back(i);
    cowv.commit();
    return NULL;
}

//read view test at operation
void* reader3(void* arg) {
    shared_ptr<vectorview<int> > read;
    cowv.getReadView(read);
    //check the reader with no change
    for (int i = 0; i< read->size(); i++) {
        ASSERT(i == read->at(i));
    }
    sleep(2);
    //do not change before commit
    for (int i = 0; i< read->size(); i++) {
        ASSERT(i == read->at(i));
    }
    sleep(2);
    // see the change after commit
    cowv.getReadView(read);
    cout << read->at(3) << endl;
    ASSERT(read->at(3) == 100);
    ASSERT(read->at(200) == 100);
    ASSERT(read->at(1000) == 100);
    ASSERT(read->at(9999) == 100);
    sleep(2);
    // see the change of new insert item
    cowv.getReadView(read);
    cout << read->size() << endl;
    ASSERT(read->size() == 100000);
    sleep(2);
    // see the change of further insert item
    cowv.getReadView(read);
    cout << read->size() << endl;
    ASSERT(read->size() == 1100000);
    return NULL;
}

int main( void ) {
    test1();
    test2();
    test3();
    test4();
    return 0;
}

<|endoftext|>


<commit_before>// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
// XFAIL: *

template <typename T, typename U>
struct same_type { static const bool value = false; };
template <typename T>
struct same_type<T, T> { static const bool value = true; };

namespace std {
  typedef decltype(sizeof(int)) size_t;

  // libc++'s implementation
  template <class _E>
  class initializer_list
  {
    const _E* __begin_;
    size_t    __size_;

    initializer_list(const _E* __b, size_t __s)
      : __begin_(__b),
        __size_(__s)
    {}

  public:
    typedef _E        value_type;
    typedef const _E& reference;
    typedef const _E& const_reference;
    typedef size_t    size_type;

    typedef const _E* iterator;
    typedef const _E* const_iterator;

    initializer_list() : __begin_(nullptr), __size_(0) {}

    size_t    size()  const {return __size_;}
    const _E* begin() const {return __begin_;}
    const _E* end()   const {return __begin_ + __size_;}
  };
}

namespace integral {

  void initialization() {
    { const int a{}; static_assert(a == 0, ""); }
    { const int a = {}; static_assert(a == 0, ""); }
    { const int a{1}; static_assert(a == 1, ""); }
    { const int a = {1}; static_assert(a == 1, ""); }
    { const int a{1, 2}; } // expected-error {{excess elements}}
    { const int a = {1, 2}; } // expected-error {{excess elements}}
    { const short a{100000}; } // expected-error {{narrowing conversion}}
    { const short a = {100000}; } // expected-error {{narrowing conversion}}
  }

  int function_call() {
    void takes_int(int);
    takes_int({1});

    int ar[10];
    (void) ar[{1}]; // expected-error {{initializer list is illegal with the built-in index operator}}

    return {1};
  }

  void inline_init() {
    (void) int{1};
    (void) new int{1};
  }

  void initializer_list() {
    auto l = {1, 2, 3, 4};
    static_assert(same_type<decltype(l), std::initializer_list<int>>::value, "");

    for (int i : {1, 2, 3, 4}) {}
  }

  struct A {
    int i;
    A() : i{1} {}
  };

}

namespace objects {

  template <int N>
  struct A {
    A() { static_assert(N == 0, ""); }
    A(int, double) { static_assert(N == 1, ""); }
    A(int, int) { static_assert(N == 2, ""); }
    A(std::initializer_list<int>) { static_assert(N == 3, ""); }
  };

  void initialization() {
    // FIXME: how to ensure correct overloads are called?
    { A<0> a{}; }
    { A<0> a = {}; }
    { A<1> a{1, 1.0}; }
    { A<1> a = {1, 1.0}; }
    { A<3> a{1, 2, 3, 4, 5, 6, 7, 8}; }
    { A<3> a = {1, 2, 3, 4, 5, 6, 7, 8}; }
    { A<3> a{1, 2, 3, 4, 5, 6, 7, 8}; }
    { A<3> a{1, 2}; }
  }

  struct C {
    C();
    C(int, double);
    C(int, int);
    C(std::initializer_list<int>);

    int operator[](C);
  };

  C function_call() {
    void takes_C(C);
    takes_C({1, 1.0});

    C c;
    c[{1, 1.0}];

    return {1, 1.0};
  }

  void inline_init() {
    (void) A<1>{1, 1.0};
    (void) new A<1>{1, 1.0};
  }

  struct B {
    B(C, int, C);
  };

  void nested_init() {
    B b{{1, 1.0}, 2, {3, 4, 5, 6, 7}};
  }
}

namespace litb {

  // invalid
  struct A { int a[2]; A():a({1, 2}) { } }; // expected-error {{}}

  // invalid
  int a({0}); // expected-error {{}}

  // invalid
  int const &b({0}); // expected-error {{}}

  struct C { explicit C(int, int); C(int, long); };

  // invalid
  C c({1, 2}); // expected-error {{}}

  // valid (by copy constructor).
  C d({1, 2L}); // expected-error {{}}

  // valid
  C e{1, 2};

  struct B {
    template<typename ...T>
    B(std::initializer_list<int>, T ...);
  };

  // invalid (the first phase only considers init-list ctors)
  // (for the second phase, no constructor is viable)
  B f{1, 2, 3};

  // valid (T deduced to <>).
  B g({1, 2, 3});

}
<commit_msg>More std::initializer_list tests.<commit_after>// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s
// XFAIL: *

template <typename T, typename U>
struct same_type { static const bool value = false; };
template <typename T>
struct same_type<T, T> { static const bool value = true; };

namespace std {
  typedef decltype(sizeof(int)) size_t;

  // libc++'s implementation
  template <class _E>
  class initializer_list
  {
    const _E* __begin_;
    size_t    __size_;

    initializer_list(const _E* __b, size_t __s)
      : __begin_(__b),
        __size_(__s)
    {}

  public:
    typedef _E        value_type;
    typedef const _E& reference;
    typedef const _E& const_reference;
    typedef size_t    size_type;

    typedef const _E* iterator;
    typedef const _E* const_iterator;

    initializer_list() : __begin_(nullptr), __size_(0) {}

    size_t    size()  const {return __size_;}
    const _E* begin() const {return __begin_;}
    const _E* end()   const {return __begin_ + __size_;}
  };
}

namespace integral {

  void initialization() {
    { const int a{}; static_assert(a == 0, ""); }
    { const int a = {}; static_assert(a == 0, ""); }
    { const int a{1}; static_assert(a == 1, ""); }
    { const int a = {1}; static_assert(a == 1, ""); }
    { const int a{1, 2}; } // expected-error {{excess elements}}
    { const int a = {1, 2}; } // expected-error {{excess elements}}
    { const short a{100000}; } // expected-error {{narrowing conversion}}
    { const short a = {100000}; } // expected-error {{narrowing conversion}}
  }

  int function_call() {
    void takes_int(int);
    takes_int({1});

    int ar[10];
    (void) ar[{1}]; // expected-error {{initializer list is illegal with the built-in index operator}}

    return {1};
  }

  void inline_init() {
    (void) int{1};
    (void) new int{1};
  }

  void initializer_list() {
    std::initializer_list<int> il = { 1, 2, 3 };
    std::initializer_list<double> dl = { 1.0, 2.0, 3 };
    auto l = {1, 2, 3, 4};
    static_assert(same_type<decltype(l), std::initializer_list<int>>::value, "");
    auto bl = {1, 2.0}; // expected-error {{cannot deduce}}

    for (int i : {1, 2, 3, 4}) {}
  }

  struct A {
    int i;
    A() : i{1} {}
  };

}

namespace objects {

  template <int N>
  struct A {
    A() { static_assert(N == 0, ""); }
    A(int, double) { static_assert(N == 1, ""); }
    A(int, int) { static_assert(N == 2, ""); }
    A(std::initializer_list<int>) { static_assert(N == 3, ""); }
  };

  void initialization() {
    { A<0> a{}; }
    { A<0> a = {}; }
    { A<1> a{1, 1.0}; }
    { A<1> a = {1, 1.0}; }
    { A<3> a{1, 2, 3, 4, 5, 6, 7, 8}; }
    { A<3> a = {1, 2, 3, 4, 5, 6, 7, 8}; }
    { A<3> a{1, 2, 3, 4, 5, 6, 7, 8}; }
    { A<3> a{1, 2}; }
  }

  struct C {
    C();
    C(int, double);
    C(int, int);
    C(std::initializer_list<int>);

    int operator[](C);
  };

  C function_call() {
    void takes_C(C);
    takes_C({1, 1.0});

    C c;
    c[{1, 1.0}];

    return {1, 1.0};
  }

  void inline_init() {
    (void) A<1>{1, 1.0};
    (void) new A<1>{1, 1.0};
  }

  struct B {
    B(C, int, C);
  };

  void nested_init() {
    B b{{1, 1.0}, 2, {3, 4, 5, 6, 7}};
  }
}

namespace litb {

  // invalid
  struct A { int a[2]; A():a({1, 2}) { } }; // expected-error {{}}

  // invalid
  int a({0}); // expected-error {{}}

  // invalid
  int const &b({0}); // expected-error {{}}

  struct C { explicit C(int, int); C(int, long); };

  // invalid
  C c({1, 2}); // expected-error {{}}

  // valid (by copy constructor).
  C d({1, 2L}); // expected-error {{}}

  // valid
  C e{1, 2};

  struct B {
    template<typename ...T>
    B(std::initializer_list<int>, T ...);
  };

  // invalid (the first phase only considers init-list ctors)
  // (for the second phase, no constructor is viable)
  B f{1, 2, 3};

  // valid (T deduced to <>).
  B g({1, 2, 3});

}
<|endoftext|>


<commit_before>#include <stan/math/mix/mat.hpp>
#include <gtest/gtest.h>
#include <test/unit/math/rev/prob/lkj_corr_cholesky_test_functors.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/math/distributions.hpp>
#include <test/unit/math/mix/mat/prob/higher_order_utils.hpp>
#include <vector>

TEST(ProbDistributionsLkjCorr, fvar_var) {
  using stan::math::fvar;
  using stan::math::var;
  boost::random::mt19937 rng;
  int K = 4;
  Eigen::Matrix<fvar<var>, Eigen::Dynamic, Eigen::Dynamic> Sigma(K, K);
  Sigma.setZero();
  Sigma.diagonal().setOnes();
  for (int i = 0; i < K * K; i++)
    Sigma(i).d_ = 1.0;
  fvar<var> eta = stan::math::uniform_rng(0, 2, rng);
  fvar<var> f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(f.val_.val(),
                  stan::math::lkj_corr_log(Sigma, eta).val_.val());
  EXPECT_FLOAT_EQ(2.5177896, stan::math::lkj_corr_log(Sigma, eta).d_.val());
  eta = 1.0;
  f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(f.val_.val(),
                  stan::math::lkj_corr_log(Sigma, eta).val_.val());
  EXPECT_FLOAT_EQ(f.d_.val(), stan::math::lkj_corr_log(Sigma, eta).d_.val());
}

TEST(ProbDistributionsLkjCorrCholesky, fvar_var) {
  using stan::math::fvar;
  using stan::math::var;
  boost::random::mt19937 rng;
  int K = 4;
  Eigen::Matrix<fvar<var>, Eigen::Dynamic, Eigen::Dynamic> Sigma(K, K);
  Sigma.setZero();
  Sigma.diagonal().setOnes();
  for (int i = 0; i < K * K; i++)
    Sigma(i).d_ = 1.0;
  fvar<var> eta = stan::math::uniform_rng(0, 2, rng);
  fvar<var> f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(f.val_.val(),
                  stan::math::lkj_corr_cholesky_log(Sigma, eta).val_.val());
  EXPECT_FLOAT_EQ(6.7766843,
                  stan::math::lkj_corr_cholesky_log(Sigma, eta).d_.val());
  eta = 1.0;
  f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(f.val_.val(),
                  stan::math::lkj_corr_cholesky_log(Sigma, eta).val_.val());
  EXPECT_FLOAT_EQ(3, stan::math::lkj_corr_cholesky_log(Sigma, eta).d_.val());
}

TEST(ProbDistributionsLkjCorr, fvar_fvar_var) {
  using stan::math::fvar;
  using stan::math::var;
  boost::random::mt19937 rng;
  int K = 4;
  Eigen::Matrix<fvar<fvar<var> >, Eigen::Dynamic, Eigen::Dynamic> Sigma(K, K);
  Sigma.setZero();
  Sigma.diagonal().setOnes();
  for (int i = 0; i < K * K; i++)
    Sigma(i).d_.val_ = 1.0;
  fvar<fvar<var> > eta = stan::math::uniform_rng(0, 2, rng);
  fvar<fvar<var> > f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(f.val_.val_.val(),
                  stan::math::lkj_corr_log(Sigma, eta).val_.val_.val());
  EXPECT_FLOAT_EQ(2.5177896,
                  stan::math::lkj_corr_log(Sigma, eta).d_.val_.val());
  eta = 1.0;
  f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(f.val_.val_.val(),
                  stan::math::lkj_corr_log(Sigma, eta).val_.val_.val());
  EXPECT_FLOAT_EQ(f.d_.val_.val(),
                  stan::math::lkj_corr_log(Sigma, eta).d_.val_.val());
}

TEST(ProbDistributionsLkjCorrCholesky, fvar_fvar_var) {
  using stan::math::fvar;
  using stan::math::var;
  boost::random::mt19937 rng;
  int K = 4;
  Eigen::Matrix<fvar<fvar<var> >, Eigen::Dynamic, Eigen::Dynamic> Sigma(K, K);
  Sigma.setZero();
  Sigma.diagonal().setOnes();
  for (int i = 0; i < K * K; i++)
    Sigma(i).d_.val_ = 1.0;
  fvar<fvar<var> > eta = stan::math::uniform_rng(0, 2, rng);
  fvar<fvar<var> > f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(
      f.val_.val_.val(),
      stan::math::lkj_corr_cholesky_log(Sigma, eta).val_.val_.val());
  EXPECT_FLOAT_EQ(6.7766843,
                  stan::math::lkj_corr_cholesky_log(Sigma, eta).d_.val_.val());
  eta = 1.0;
  f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(
      f.val_.val_.val(),
      stan::math::lkj_corr_cholesky_log(Sigma, eta).val_.val_.val());
  EXPECT_FLOAT_EQ(3,
                  stan::math::lkj_corr_cholesky_log(Sigma, eta).d_.val_.val());
}

TEST(ProbDistributionsLkjCorrCholesky, hessian) {
  int dim_mat = 3;
  Eigen::Matrix<double, Eigen::Dynamic, 1> x1(dim_mat);
  Eigen::Matrix<double, Eigen::Dynamic, 1> x2(1);
  Eigen::Matrix<double, Eigen::Dynamic, 1> x3(dim_mat + 1);

  x2(0) = 2.0;

  for (int i = 0; i < dim_mat; ++i) {
    x1(i) = i / 10.0;
    x3(i + 1) = x1(i);
  }
  x3(0) = 0.5;

  stan::math::lkj_corr_cholesky_dc test_func_1(dim_mat);
  stan::math::lkj_corr_cholesky_cd test_func_2(dim_mat);
  stan::math::lkj_corr_cholesky_dd test_func_3(dim_mat);

  using stan::math::finite_diff_hessian;
  using stan::math::hessian;

  Eigen::Matrix<double, Eigen::Dynamic, 1> grad_hess_3;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_3;
  double fx_hess_3;
  Eigen::Matrix<double, Eigen::Dynamic, 1> grad_hess_ad_3;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_ad_3;
  double fx_hess_ad_3;

  finite_diff_hessian(test_func_3, x3, fx_hess_3, grad_hess_3, hess_3);
  hessian(test_func_3, x3, fx_hess_ad_3, grad_hess_ad_3, hess_ad_3);

  test_hess_eq(hess_3, hess_ad_3);
  EXPECT_FLOAT_EQ(fx_hess_3, fx_hess_ad_3);

  Eigen::Matrix<double, Eigen::Dynamic, 1> grad_hess_2;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_2;
  double fx_hess_2;
  Eigen::Matrix<double, Eigen::Dynamic, 1> grad_hess_ad_2;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_ad_2;
  double fx_hess_ad_2;

  finite_diff_hessian(test_func_2, x2, fx_hess_2, grad_hess_2, hess_2);
  hessian(test_func_2, x2, fx_hess_ad_2, grad_hess_ad_2, hess_ad_2);

  test_hess_eq(hess_2, hess_ad_2);
  EXPECT_FLOAT_EQ(fx_hess_2, fx_hess_ad_2);

  Eigen::Matrix<double, Eigen::Dynamic, 1> grad_hess_1;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_1;
  double fx_hess_1;
  Eigen::Matrix<double, Eigen::Dynamic, 1> grad_hess_ad_1;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_ad_1;
  double fx_hess_ad_1;

  finite_diff_hessian(test_func_1, x1, fx_hess_1, grad_hess_1, hess_1);
  hessian(test_func_1, x1, fx_hess_ad_1, grad_hess_ad_1, hess_ad_1);

  test_hess_eq(hess_1, hess_ad_1);
  EXPECT_FLOAT_EQ(fx_hess_1, fx_hess_ad_1);
}

TEST(ProbDistributionsLkjCorrCholesky, grad_hessian) {
  int dim_mat = 3;
  Eigen::Matrix<double, Eigen::Dynamic, 1> x1(dim_mat);
  Eigen::Matrix<double, Eigen::Dynamic, 1> x2(1);
  Eigen::Matrix<double, Eigen::Dynamic, 1> x3(dim_mat + 1);

  x2(0) = 2.0;

  for (int i = 0; i < dim_mat; ++i) {
    x1(i) = i / 10.0;
    x3(i + 1) = x1(i);
  }
  x3(0) = 0.5;

  stan::math::lkj_corr_cholesky_dc test_func_1(dim_mat);
  stan::math::lkj_corr_cholesky_cd test_func_2(dim_mat);
  stan::math::lkj_corr_cholesky_dd test_func_3(dim_mat);

  using stan::math::finite_diff_grad_hessian;
  using stan::math::grad_hessian;

  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_gh_3;
  std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> > gh_3;
  double fx_gh_3;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_gh_ad_3;
  std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> > gh_ad_3;
  double fx_gh_ad_3;

  finite_diff_grad_hessian(test_func_3, x3, fx_gh_3, hess_gh_3, gh_3);
  grad_hessian(test_func_3, x3, fx_gh_ad_3, hess_gh_ad_3, gh_ad_3);

  test_grad_hess_eq(gh_3, gh_ad_3);
  EXPECT_FLOAT_EQ(fx_gh_3, fx_gh_ad_3);

  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_gh_2;
  std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> > gh_2;
  double fx_gh_2;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_gh_ad_2;
  std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> > gh_ad_2;
  double fx_gh_ad_2;

  finite_diff_grad_hessian(test_func_2, x2, fx_gh_2, hess_gh_2, gh_2);
  grad_hessian(test_func_2, x2, fx_gh_ad_2, hess_gh_ad_2, gh_ad_2);

  test_grad_hess_eq(gh_2, gh_ad_2);
  EXPECT_FLOAT_EQ(fx_gh_2, fx_gh_ad_2);

  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_gh_1;
  std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> > gh_1;
  double fx_gh_1;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_gh_ad_1;
  std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> > gh_ad_1;
  double fx_gh_ad_1;

  finite_diff_grad_hessian(test_func_1, x1, fx_gh_1, hess_gh_1, gh_1);
  grad_hessian(test_func_1, x1, fx_gh_ad_1, hess_gh_ad_1, gh_ad_1);

  test_grad_hess_eq(gh_1, gh_ad_1);
  EXPECT_FLOAT_EQ(fx_gh_1, fx_gh_ad_1);
}
<commit_msg>fix includes of mix/prob<commit_after>#include <stan/math/mix/mat.hpp>
#include <gtest/gtest.h>
#include <test/unit/math/rev/prob/lkj_corr_cholesky_test_functors.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/math/distributions.hpp>
#include <test/unit/math/mix/prob/higher_order_utils.hpp>
#include <vector>

TEST(ProbDistributionsLkjCorr, fvar_var) {
  using stan::math::fvar;
  using stan::math::var;
  boost::random::mt19937 rng;
  int K = 4;
  Eigen::Matrix<fvar<var>, Eigen::Dynamic, Eigen::Dynamic> Sigma(K, K);
  Sigma.setZero();
  Sigma.diagonal().setOnes();
  for (int i = 0; i < K * K; i++)
    Sigma(i).d_ = 1.0;
  fvar<var> eta = stan::math::uniform_rng(0, 2, rng);
  fvar<var> f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(f.val_.val(),
                  stan::math::lkj_corr_log(Sigma, eta).val_.val());
  EXPECT_FLOAT_EQ(2.5177896, stan::math::lkj_corr_log(Sigma, eta).d_.val());
  eta = 1.0;
  f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(f.val_.val(),
                  stan::math::lkj_corr_log(Sigma, eta).val_.val());
  EXPECT_FLOAT_EQ(f.d_.val(), stan::math::lkj_corr_log(Sigma, eta).d_.val());
}

TEST(ProbDistributionsLkjCorrCholesky, fvar_var) {
  using stan::math::fvar;
  using stan::math::var;
  boost::random::mt19937 rng;
  int K = 4;
  Eigen::Matrix<fvar<var>, Eigen::Dynamic, Eigen::Dynamic> Sigma(K, K);
  Sigma.setZero();
  Sigma.diagonal().setOnes();
  for (int i = 0; i < K * K; i++)
    Sigma(i).d_ = 1.0;
  fvar<var> eta = stan::math::uniform_rng(0, 2, rng);
  fvar<var> f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(f.val_.val(),
                  stan::math::lkj_corr_cholesky_log(Sigma, eta).val_.val());
  EXPECT_FLOAT_EQ(6.7766843,
                  stan::math::lkj_corr_cholesky_log(Sigma, eta).d_.val());
  eta = 1.0;
  f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(f.val_.val(),
                  stan::math::lkj_corr_cholesky_log(Sigma, eta).val_.val());
  EXPECT_FLOAT_EQ(3, stan::math::lkj_corr_cholesky_log(Sigma, eta).d_.val());
}

TEST(ProbDistributionsLkjCorr, fvar_fvar_var) {
  using stan::math::fvar;
  using stan::math::var;
  boost::random::mt19937 rng;
  int K = 4;
  Eigen::Matrix<fvar<fvar<var> >, Eigen::Dynamic, Eigen::Dynamic> Sigma(K, K);
  Sigma.setZero();
  Sigma.diagonal().setOnes();
  for (int i = 0; i < K * K; i++)
    Sigma(i).d_.val_ = 1.0;
  fvar<fvar<var> > eta = stan::math::uniform_rng(0, 2, rng);
  fvar<fvar<var> > f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(f.val_.val_.val(),
                  stan::math::lkj_corr_log(Sigma, eta).val_.val_.val());
  EXPECT_FLOAT_EQ(2.5177896,
                  stan::math::lkj_corr_log(Sigma, eta).d_.val_.val());
  eta = 1.0;
  f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(f.val_.val_.val(),
                  stan::math::lkj_corr_log(Sigma, eta).val_.val_.val());
  EXPECT_FLOAT_EQ(f.d_.val_.val(),
                  stan::math::lkj_corr_log(Sigma, eta).d_.val_.val());
}

TEST(ProbDistributionsLkjCorrCholesky, fvar_fvar_var) {
  using stan::math::fvar;
  using stan::math::var;
  boost::random::mt19937 rng;
  int K = 4;
  Eigen::Matrix<fvar<fvar<var> >, Eigen::Dynamic, Eigen::Dynamic> Sigma(K, K);
  Sigma.setZero();
  Sigma.diagonal().setOnes();
  for (int i = 0; i < K * K; i++)
    Sigma(i).d_.val_ = 1.0;
  fvar<fvar<var> > eta = stan::math::uniform_rng(0, 2, rng);
  fvar<fvar<var> > f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(
      f.val_.val_.val(),
      stan::math::lkj_corr_cholesky_log(Sigma, eta).val_.val_.val());
  EXPECT_FLOAT_EQ(6.7766843,
                  stan::math::lkj_corr_cholesky_log(Sigma, eta).d_.val_.val());
  eta = 1.0;
  f = stan::math::do_lkj_constant(eta, K);
  EXPECT_FLOAT_EQ(
      f.val_.val_.val(),
      stan::math::lkj_corr_cholesky_log(Sigma, eta).val_.val_.val());
  EXPECT_FLOAT_EQ(3,
                  stan::math::lkj_corr_cholesky_log(Sigma, eta).d_.val_.val());
}

TEST(ProbDistributionsLkjCorrCholesky, hessian) {
  int dim_mat = 3;
  Eigen::Matrix<double, Eigen::Dynamic, 1> x1(dim_mat);
  Eigen::Matrix<double, Eigen::Dynamic, 1> x2(1);
  Eigen::Matrix<double, Eigen::Dynamic, 1> x3(dim_mat + 1);

  x2(0) = 2.0;

  for (int i = 0; i < dim_mat; ++i) {
    x1(i) = i / 10.0;
    x3(i + 1) = x1(i);
  }
  x3(0) = 0.5;

  stan::math::lkj_corr_cholesky_dc test_func_1(dim_mat);
  stan::math::lkj_corr_cholesky_cd test_func_2(dim_mat);
  stan::math::lkj_corr_cholesky_dd test_func_3(dim_mat);

  using stan::math::finite_diff_hessian;
  using stan::math::hessian;

  Eigen::Matrix<double, Eigen::Dynamic, 1> grad_hess_3;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_3;
  double fx_hess_3;
  Eigen::Matrix<double, Eigen::Dynamic, 1> grad_hess_ad_3;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_ad_3;
  double fx_hess_ad_3;

  finite_diff_hessian(test_func_3, x3, fx_hess_3, grad_hess_3, hess_3);
  hessian(test_func_3, x3, fx_hess_ad_3, grad_hess_ad_3, hess_ad_3);

  test_hess_eq(hess_3, hess_ad_3);
  EXPECT_FLOAT_EQ(fx_hess_3, fx_hess_ad_3);

  Eigen::Matrix<double, Eigen::Dynamic, 1> grad_hess_2;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_2;
  double fx_hess_2;
  Eigen::Matrix<double, Eigen::Dynamic, 1> grad_hess_ad_2;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_ad_2;
  double fx_hess_ad_2;

  finite_diff_hessian(test_func_2, x2, fx_hess_2, grad_hess_2, hess_2);
  hessian(test_func_2, x2, fx_hess_ad_2, grad_hess_ad_2, hess_ad_2);

  test_hess_eq(hess_2, hess_ad_2);
  EXPECT_FLOAT_EQ(fx_hess_2, fx_hess_ad_2);

  Eigen::Matrix<double, Eigen::Dynamic, 1> grad_hess_1;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_1;
  double fx_hess_1;
  Eigen::Matrix<double, Eigen::Dynamic, 1> grad_hess_ad_1;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_ad_1;
  double fx_hess_ad_1;

  finite_diff_hessian(test_func_1, x1, fx_hess_1, grad_hess_1, hess_1);
  hessian(test_func_1, x1, fx_hess_ad_1, grad_hess_ad_1, hess_ad_1);

  test_hess_eq(hess_1, hess_ad_1);
  EXPECT_FLOAT_EQ(fx_hess_1, fx_hess_ad_1);
}

TEST(ProbDistributionsLkjCorrCholesky, grad_hessian) {
  int dim_mat = 3;
  Eigen::Matrix<double, Eigen::Dynamic, 1> x1(dim_mat);
  Eigen::Matrix<double, Eigen::Dynamic, 1> x2(1);
  Eigen::Matrix<double, Eigen::Dynamic, 1> x3(dim_mat + 1);

  x2(0) = 2.0;

  for (int i = 0; i < dim_mat; ++i) {
    x1(i) = i / 10.0;
    x3(i + 1) = x1(i);
  }
  x3(0) = 0.5;

  stan::math::lkj_corr_cholesky_dc test_func_1(dim_mat);
  stan::math::lkj_corr_cholesky_cd test_func_2(dim_mat);
  stan::math::lkj_corr_cholesky_dd test_func_3(dim_mat);

  using stan::math::finite_diff_grad_hessian;
  using stan::math::grad_hessian;

  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_gh_3;
  std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> > gh_3;
  double fx_gh_3;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_gh_ad_3;
  std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> > gh_ad_3;
  double fx_gh_ad_3;

  finite_diff_grad_hessian(test_func_3, x3, fx_gh_3, hess_gh_3, gh_3);
  grad_hessian(test_func_3, x3, fx_gh_ad_3, hess_gh_ad_3, gh_ad_3);

  test_grad_hess_eq(gh_3, gh_ad_3);
  EXPECT_FLOAT_EQ(fx_gh_3, fx_gh_ad_3);

  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_gh_2;
  std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> > gh_2;
  double fx_gh_2;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_gh_ad_2;
  std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> > gh_ad_2;
  double fx_gh_ad_2;

  finite_diff_grad_hessian(test_func_2, x2, fx_gh_2, hess_gh_2, gh_2);
  grad_hessian(test_func_2, x2, fx_gh_ad_2, hess_gh_ad_2, gh_ad_2);

  test_grad_hess_eq(gh_2, gh_ad_2);
  EXPECT_FLOAT_EQ(fx_gh_2, fx_gh_ad_2);

  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_gh_1;
  std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> > gh_1;
  double fx_gh_1;
  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> hess_gh_ad_1;
  std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> > gh_ad_1;
  double fx_gh_ad_1;

  finite_diff_grad_hessian(test_func_1, x1, fx_gh_1, hess_gh_1, gh_1);
  grad_hessian(test_func_1, x1, fx_gh_ad_1, hess_gh_ad_1, gh_ad_1);

  test_grad_hess_eq(gh_1, gh_ad_1);
  EXPECT_FLOAT_EQ(fx_gh_1, fx_gh_ad_1);
}
<|endoftext|>


<commit_before><commit_msg>planning: updated pull over boundary in path_bounds_decider<commit_after><|endoftext|>


<commit_before>#include <stingray/toolkit/Factory.h>

#include <stingray/toolkit/any.h>

#include <stingray/app/application_context/AppChannel.h>
#include <stingray/app/application_context/ChannelList.h>
#include <stingray/app/scheduler/ScheduledEvents.h>
#include <stingray/app/tests/AutoFilter.h>
#include <stingray/app/zapper/User.h>
#include <stingray/hdmi/IHDMI.h>
#include <stingray/media/MediaStreamDescriptor.h>
#include <stingray/mpeg/Stream.h>
#include <stingray/parentalcontrol/AgeRating.h>
#ifdef PLATFORM_EMU
#	include <stingray/platform/emu/scanner/Channel.h>
#endif
#include <stingray/records/FileSystemRecord.h>
#include <stingray/scanner/DVBServiceId.h>
#include <stingray/scanner/DefaultDVBTBandInfo.h>
#include <stingray/scanner/DefaultMpegService.h>
#include <stingray/scanner/DefaultMpegStreamDescriptor.h>
#include <stingray/scanner/DefaultScanParams.h>
#include <stingray/scanner/IServiceId.h>
#include <stingray/scanner/TricolorGeographicRegion.h>
#include <stingray/scanner/TricolorScanParams.h>
#include <stingray/streams/RecordStreamMetaInfo.h>
#include <stingray/tuners/dvbs/Antenna.h>
#include <stingray/tuners/dvbs/DefaultDVBSTransport.h>
#include <stingray/tuners/dvbs/Satellite.h>
#include <stingray/tuners/dvbt/DefaultDVBTTransport.h>

/* WARNING! This is autogenerated file, DO NOT EDIT! */

namespace stingray { namespace Detail
{
	void Factory::RegisterTypes()
	{
#ifdef BUILD_SHARED_LIB
		/*nothing*/
#else
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::AppChannel);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(::stingray::Detail::any::ObjectHolder<stingray::app::AppChannelPtr>);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ChannelList);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::Alarm);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::CinemaHallScheduledViewing);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ContinuousScheduledEvent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::DeferredStandby);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::InfiniteScheduledEvent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ScheduledEvent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ScheduledRecord);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ScheduledViewing);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::AutoFilter);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::User);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(HDMIConfig);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MediaAudioStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MediaVideoStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(mpeg::Stream);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(AgeRating);
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::EmuServiceId);
#endif
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::RadioChannel);
#endif
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::StreamDescriptor);
#endif
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::TVChannel);
#endif
		TOOLKIT_REGISTER_CLASS_EXPLICIT(FileSystemRecord);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DVBServiceId);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultDVBTBandInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMpegRadioChannel);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMpegService);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMpegTVChannel);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMpegStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegAudioStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegPcrStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegSubtitlesStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegTeletextBasedSubtitlesStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegTeletextStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegVideoStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultScanParams);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(::stingray::Detail::any::ObjectHolder<stingray::ServiceId>);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(TricolorGeographicRegion);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(TricolorScanParams);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(RecordStreamMetaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(Antenna);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultDVBSTransport);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(Satellite);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultDVBTTransport);
#endif
	}
}}
<commit_msg>register system update actions<commit_after>#include <stingray/toolkit/Factory.h>

#include <stingray/toolkit/any.h>

#include <stingray/app/application_context/AppChannel.h>
#include <stingray/app/application_context/ChannelList.h>
#include <stingray/app/scheduler/ScheduledEvents.h>
#include <stingray/app/tests/AutoFilter.h>
#include <stingray/app/zapper/User.h>
#include <stingray/hdmi/IHDMI.h>
#include <stingray/media/MediaStreamDescriptor.h>
#include <stingray/mpeg/Stream.h>
#include <stingray/parentalcontrol/AgeRating.h>
#ifdef PLATFORM_EMU
#	include <stingray/platform/emu/scanner/Channel.h>
#endif
#include <stingray/records/FileSystemRecord.h>
#include <stingray/scanner/DVBServiceId.h>
#include <stingray/scanner/DefaultDVBTBandInfo.h>
#include <stingray/scanner/DefaultMpegService.h>
#include <stingray/scanner/DefaultMpegStreamDescriptor.h>
#include <stingray/scanner/DefaultScanParams.h>
#include <stingray/scanner/IServiceId.h>
#include <stingray/scanner/TricolorGeographicRegion.h>
#include <stingray/scanner/TricolorScanParams.h>
#include <stingray/streams/RecordStreamMetaInfo.h>
#include <stingray/tuners/dvbs/Antenna.h>
#include <stingray/tuners/dvbs/DefaultDVBSTransport.h>
#include <stingray/tuners/dvbs/Satellite.h>
#include <stingray/tuners/dvbt/DefaultDVBTTransport.h>
#include <stingray/update/system/EraseFlashPartition.h>
#include <stingray/update/system/WriteFlashPartition.h>

/* WARNING! This is autogenerated file, DO NOT EDIT! */

namespace stingray { namespace Detail
{
	void Factory::RegisterTypes()
	{
#ifdef BUILD_SHARED_LIB
		/*nothing*/
#else
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::AppChannel);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(::stingray::Detail::any::ObjectHolder<stingray::app::AppChannelPtr>);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ChannelList);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::Alarm);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::CinemaHallScheduledViewing);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ContinuousScheduledEvent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::DeferredStandby);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::InfiniteScheduledEvent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ScheduledEvent);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ScheduledRecord);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::ScheduledViewing);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::AutoFilter);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(app::User);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(HDMIConfig);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MediaAudioStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MediaVideoStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(mpeg::Stream);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(AgeRating);
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::EmuServiceId);
#endif
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::RadioChannel);
#endif
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::StreamDescriptor);
#endif
#ifdef PLATFORM_EMU
		TOOLKIT_REGISTER_CLASS_EXPLICIT(emu::TVChannel);
#endif
		TOOLKIT_REGISTER_CLASS_EXPLICIT(FileSystemRecord);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DVBServiceId);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultDVBTBandInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMpegRadioChannel);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMpegService);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMpegTVChannel);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultMpegStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegAudioStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegPcrStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegSubtitlesStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegTeletextBasedSubtitlesStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegTeletextStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(MpegVideoStreamDescriptor);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultScanParams);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(::stingray::Detail::any::ObjectHolder<stingray::ServiceId>);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(TricolorGeographicRegion);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(TricolorScanParams);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(RecordStreamMetaInfo);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(Antenna);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultDVBSTransport);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(Satellite);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(DefaultDVBTTransport);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(EraseFlashPartition);
		TOOLKIT_REGISTER_CLASS_EXPLICIT(WriteFlashPartition);
#endif
	}
}}
<|endoftext|>